2008-11-18 Kai Tietz <kai.tietz@onevision.com>
[official-gcc.git] / gcc / config / i386 / sol2-gc1.asm
blob994326a6b00812ced84729757e07def8019c851b
1 ! gcrt1.s for Solaris 2, x86
3 ! Copyright (C) 1993 Free Software Foundation, Inc.
4 ! Written By Fred Fish, Nov 1992
5 !
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 2, or (at your option) any
9 ! later version.
11 ! In addition to the permissions in the GNU General Public License, the
12 ! Free Software Foundation gives you unlimited permission to link the
13 ! compiled version of this file with other programs, and to distribute
14 ! those programs without any restriction coming from the use of this
15 ! file. (The General Public License restrictions do apply in other
16 ! respects; for example, they cover modification of the file, and
17 ! distribution when not linked into another program.)
19 ! This file is distributed in the hope that it will be useful, but
20 ! WITHOUT ANY WARRANTY; without even the implied warranty of
21 ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ! General Public License for more details.
24 ! You should have received a copy of the GNU General Public License
25 ! along with this program; see the file COPYING. If not, write to
26 ! the Free Software Foundation, 51 Franklin Street, Fifth Floor,
27 ! Boston, MA 02110-1301, USA.
29 ! As a special exception, if you link this library with files
30 ! compiled with GCC to produce an executable, this does not cause
31 ! the resulting executable to be covered by the GNU General Public License.
32 ! This exception does not however invalidate any other reasons why
33 ! the executable file might be covered by the GNU General Public License.
36 ! This file takes control of the process from the kernel, as specified
37 ! in section 3 of the System V Application Binary Interface, Intel386
38 ! Processor Supplement. It has been constructed from information obtained
39 ! from the ABI, information obtained from single stepping existing
40 ! Solaris executables through their startup code with gdb, and from
41 ! information obtained by single stepping executables on other i386 SVR4
42 ! implementations. This file is the first thing linked into any executable.
44 ! This is a modified crt1.s by J.W.Hawtin <oolon@ankh.org> 15/8/96,
45 ! to allow program profiling, by calling monstartup on entry and _mcleanup
46 ! on exit
48 .ident "GNU C gcrt1.s"
49 .weak _DYNAMIC
50 .text
52 ! Start creating the initial frame by pushing a NULL value for the return
53 ! address of the initial frame, and mark the end of the stack frame chain
54 ! (the innermost stack frame) with a NULL value, per page 3-32 of the ABI.
55 ! Initialize the first stack frame pointer in %ebp (the contents of which
56 ! are unspecified at process initialization).
58 .globl _start
59 _start:
60 pushl $0x0
61 pushl $0x0
62 movl %esp,%ebp
64 ! As specified per page 3-32 of the ABI, %edx contains a function
65 ! pointer that should be registered with atexit(), for proper
66 ! shared object termination. Just push it onto the stack for now
67 ! to preserve it. We want to register _cleanup() first.
69 pushl %edx
71 ! Check to see if there is an _cleanup() function linked in, and if
72 ! so, register it with atexit() as the last thing to be run by
73 ! atexit().
75 movl $_mcleanup,%eax
76 testl %eax,%eax
77 je .L1
78 pushl $_mcleanup
79 call atexit
80 addl $0x4,%esp
81 .L1:
83 ! Now check to see if we have an _DYNAMIC table, and if so then
84 ! we need to register the function pointer previously in %edx, but
85 ! now conveniently saved on the stack as the argument to pass to
86 ! atexit().
88 movl $_DYNAMIC,%eax
89 testl %eax,%eax
90 je .L2
91 call atexit
92 .L2:
94 ! Register _fini() with atexit(). We will take care of calling _init()
95 ! directly.
97 pushl $_fini
98 call atexit
100 ! Start profiling
102 pushl %ebp
103 movl %esp,%ebp
104 pushl $_etext
105 pushl $_start
106 call monstartup
107 addl $8,%esp
108 popl %ebp
110 ! Compute the address of the environment vector on the stack and load
111 ! it into the global variable _environ. Currently argc is at 8 off
112 ! the frame pointer. Fetch the argument count into %eax, scale by the
113 ! size of each arg (4 bytes) and compute the address of the environment
114 ! vector which is 16 bytes (the two zero words we pushed, plus argc,
115 ! plus the null word terminating the arg vector) further up the stack,
116 ! off the frame pointer (whew!).
118 movl 8(%ebp),%eax
119 leal 16(%ebp,%eax,4),%edx
120 movl %edx,_environ
122 ! Push the environment vector pointer, the argument vector pointer,
123 ! and the argument count on to the stack to set up the arguments
124 ! for _init(), _fpstart(), and main(). Note that the environment
125 ! vector pointer and the arg count were previously loaded into
126 ! %edx and %eax respectively. The only new value we need to compute
127 ! is the argument vector pointer, which is at a fixed address off
128 ! the initial frame pointer.
131 ! Make sure the stack is properly aligned.
133 andl $0xfffffff0,%esp
134 subl $4,%esp
136 pushl %edx
137 leal 12(%ebp),%edx
138 pushl %edx
139 pushl %eax
141 ! Call _init(argc, argv, environ), _fpstart(argc, argv, environ), and
142 ! main(argc, argv, environ).
144 call _init
145 call __fpstart
146 call main
148 ! Pop the argc, argv, and environ arguments off the stack, push the
149 ! value returned from main(), and call exit().
151 addl $12,%esp
152 pushl %eax
153 call exit
155 ! An inline equivalent of _exit, as specified in Figure 3-26 of the ABI.
157 pushl $0x0
158 movl $0x1,%eax
159 lcall $7,$0
161 ! If all else fails, just try a halt!
164 .type _start,@function
165 .size _start,.-_start