xref: /titanic_44/usr/src/lib/common/i386/crt1.s (revision 40e5e17b3361b3eea56a9723071c406894a20b78)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License").  You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
23 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27/*
28 * This crt1.o module is provided as the bare minimum required to build
29 * a 32-bit executable with gcc.  It is installed in /usr/lib
30 * where it will be picked up by gcc, along with crti.o and crtn.o
31 */
32
33	.ident	"%Z%%M%	%I%	%E% SMI"
34
35	.file	"crt1.s"
36
37	.globl	_start
38
39/* global entities defined elsewhere but used here */
40	.globl	main
41	.globl	__fpstart
42	.globl	exit
43	.globl	_exit
44	.weak	_DYNAMIC
45
46	.section	.data
47
48	.weak	environ
49	.set	environ,_environ
50	.globl	_environ
51	.type	_environ,@object
52	.size	_environ,4
53	.align	4
54_environ:
55	.4byte	0x0
56
57	.globl	___Argv
58	.type	___Argv,@object
59	.size	___Argv,4
60	.align	4
61___Argv:
62	.4byte	0x0
63
64	.section	.text
65	.align	4
66
67/*
68 * C language startup routine.
69 * Assume that exec code has cleared the direction flag in the TSS.
70 * Assume that %esp is set to the addr after the last word pushed.
71 * The stack contains (in order): argc, argv[],envp[],...
72 * Assume that all of the segment registers are initialized.
73 *
74 * Allocate a NULL return address and a NULL previous %ebp as if
75 * there was a genuine call to _start.
76 * sdb stack trace shows _start(argc,argv[0],argv[1],...,envp[0],...)
77 */
78	.type	_start,@function
79_start:
80	pushl	$0
81	pushl	$0
82	movl	%esp,%ebp		/* The first stack frame */
83
84	movl	$_DYNAMIC,%eax
85	testl	%eax,%eax
86	jz	1f
87	pushl	%edx			/* register rt_do_exit */
88	call	atexit
89	addl	$4,%esp
901:
91	pushl	$_fini
92	call	atexit
93	addl	$4,%esp
94
95/*
96 * The following code provides almost standard static destructor handling
97 * for systems that do not have the modified atexit processing in their
98 * system libraries.  It checks for the existence of the new routine
99 * "_get_exit_frame_monitor()", which is in libc.so when the new exit-handling
100 * code is there.  It then check for the existence of "__Crun::do_exit_code()"
101 * which will be in libCrun.so whenever the code was linked with the C++
102 * compiler.  If there is no enhanced atexit, and we do have do_exit_code,
103 * we register the latter with atexit.  There are 5 extra slots in
104 * atexit, so this will still be standard conforming.  Since the code
105 * is registered after the .fini section, it runs before the library
106 * cleanup code, leaving nothing for the calls to _do_exit_code_in_range
107 * to handle.
108 *
109 * Remove this code and the associated code in libCrun when the earliest
110 * system to be supported is Solaris 8.
111 */
112	.weak	_get_exit_frame_monitor
113	.weak	__1cG__CrunMdo_exit_code6F_v_
114
115	.section	.data
116	.align	4
117__get_exit_frame_monitor_ptr:
118	.4byte	_get_exit_frame_monitor
119	.type	__get_exit_frame_monitor_ptr,@object
120	.size	__get_exit_frame_monitor_ptr,4
121
122	.align	4
123__do_exit_code_ptr:
124	.4byte	__1cG__CrunMdo_exit_code6F_v_
125	.type	__do_exit_code_ptr,@object
126	.size	__do_exit_code_ptr,4
127
128	.section	.text
129
130	lea	__get_exit_frame_monitor_ptr, %eax
131	movl	(%eax), %eax
132	testl	%eax,%eax
133	jz	1f
134	lea	__do_exit_code_ptr, %eax
135	movl	(%eax), %eax
136	testl	%eax, %eax
137	jz	1f
138	pushl	%eax
139	call	atexit		/* atexit(__Crun::do_exit_code()) */
140	addl	$4,%esp
1411:
142
143/*
144 * End of destructor handling code
145 */
146
147/*
148 * Calculate the location of the envp array by adding the size of
149 * the argv array to the start of the argv array.
150 */
151
152	movl	8(%ebp),%eax		/* argc */
153	movl	_environ, %edx		/* fixed bug 4302802 */
154	testl	%edx, %edx		/* check if _enviorn==0 */
155	jne	1f			/* fixed bug 4203802 */
156	leal	16(%ebp,%eax,4),%edx	/* envp */
157	movl	%edx,_environ		/* copy to _environ */
1581:
159	andl	$-16,%esp
160	pushl	%edx
161	leal	12(%ebp),%edx	/* argv */
162	movl	%edx,___Argv
163	pushl	%edx
164	pushl	%eax		/* argc */
165	call	__fpstart
166	call	__fsr		/* support for ftrap/fround/fprecision  */
167	call	_init
168	call	main		/* main(argc,argv,envp) */
169	addl	$12,%esp
170	pushl	%eax		/* return value from main */
171	pushl	%eax		/* push it again (for _exit(), below) */
172	call	exit
173	addl	$4,%esp
174	call	_exit		/* if user redefined exit, call _exit */
175	addl	$4,%esp
176	hlt
177	.size	_start, .-_start
178
179#include "fsr.s"
180
181/*
182 * The following is here in case any object module compiled with cc -p
183 *	was linked into this module.
184 */
185	.section	.text
186	.align	4
187	.globl	_mcount
188	.type	_mcount,@function
189_mcount:
190	ret
191	.size	_mcount, .-_mcount
192
193	.section	.data
194
195	.globl	__longdouble_used
196	.type	__longdouble_used,@object
197	.size	__longdouble_used,4
198	.align	4
199__longdouble_used:
200	.4byte	0x0
201