1 ! gcrt1.s for Solaris 2, x86
3 ! Copyright (C) 1993, 2008, 2009 Free Software Foundation, Inc.
4 ! Written By Fred Fish, Nov 1992
6 ! This file is free software; you can redistribute it and/or modify it
7 ! under the terms of the GNU General Public License as published by the
8 ! Free Software Foundation; either version 3, or (at your option) any
11 ! This file is distributed in the hope that it will be useful, but
12 ! WITHOUT ANY WARRANTY; without even the implied warranty of
13 ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ! General Public License for more details.
16 ! Under Section 7 of GPL version 3, you are granted additional
17 ! permissions described in the GCC Runtime Library Exception, version
18 ! 3.1, as published by the Free Software Foundation.
20 ! You should have received a copy of the GNU General Public License and
21 ! a copy of the GCC Runtime Library Exception along with this program;
22 ! see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 ! <http://www.gnu.org/licenses/>.
26 ! This file takes control of the process from the kernel, as specified
27 ! in section 3 of the System V Application Binary Interface, Intel386
28 ! Processor Supplement. It has been constructed from information obtained
29 ! from the ABI, information obtained from single stepping existing
30 ! Solaris executables through their startup code with gdb, and from
31 ! information obtained by single stepping executables on other i386 SVR4
32 ! implementations. This file is the first thing linked into any executable.
34 ! This is a modified crt1.s by J.W.Hawtin <oolon@ankh.org> 15/8/96,
35 ! to allow program profiling, by calling monstartup on entry and _mcleanup
38 .ident "GNU C gcrt1.s"
42 ! Start creating the initial frame by pushing a NULL value for the return
43 ! address of the initial frame, and mark the end of the stack frame chain
44 ! (the innermost stack frame) with a NULL value, per page 3-32 of the ABI.
45 ! Initialize the first stack frame pointer in %ebp (the contents of which
46 ! are unspecified at process initialization).
54 ! As specified per page 3-32 of the ABI, %edx contains a function
55 ! pointer that should be registered with atexit(), for proper
56 ! shared object termination. Just push it onto the stack for now
57 ! to preserve it. We want to register _cleanup() first.
61 ! Check to see if there is an _cleanup() function linked in, and if
62 ! so, register it with atexit() as the last thing to be run by
73 ! Now check to see if we have an _DYNAMIC table, and if so then
74 ! we need to register the function pointer previously in %edx, but
75 ! now conveniently saved on the stack as the argument to pass to
84 ! Register _fini() with atexit(). We will take care of calling _init()
100 ! Compute the address of the environment vector on the stack and load
101 ! it into the global variable _environ. Currently argc is at 8 off
102 ! the frame pointer. Fetch the argument count into %eax, scale by the
103 ! size of each arg (4 bytes) and compute the address of the environment
104 ! vector which is 16 bytes (the two zero words we pushed, plus argc,
105 ! plus the null word terminating the arg vector) further up the stack,
106 ! off the frame pointer (whew!).
109 leal 16(%ebp,%eax,4),%edx
112 ! Push the environment vector pointer, the argument vector pointer,
113 ! and the argument count on to the stack to set up the arguments
114 ! for _init(), _fpstart(), and main(). Note that the environment
115 ! vector pointer and the arg count were previously loaded into
116 ! %edx and %eax respectively. The only new value we need to compute
117 ! is the argument vector pointer, which is at a fixed address off
118 ! the initial frame pointer.
121 ! Make sure the stack is properly aligned.
123 andl $0xfffffff0,%esp
131 ! Call _init(argc, argv, environ), _fpstart(argc, argv, environ), and
132 ! main(argc, argv, environ).
138 ! Pop the argc, argv, and environ arguments off the stack, push the
139 ! value returned from main(), and call exit().
145 ! An inline equivalent of _exit, as specified in Figure 3-26 of the ABI.
151 ! If all else fails, just try a halt!
154 .type _start,@function
155 .size _start,.-_start