Commit | Line | Data |
---|---|---|
b8098ef8 | 1 | /* C code startup routine. |
429ab54e | 2 | Copyright (C) 1985, 1986, 1992, 2001, 2002, 2003, 2004, |
8cabe764 | 3 | 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
b8098ef8 DL |
4 | |
5 | This file is part of GNU Emacs. | |
6 | ||
9ec0b715 | 7 | GNU Emacs is free software: you can redistribute it and/or modify |
b8098ef8 | 8 | it under the terms of the GNU General Public License as published by |
9ec0b715 GM |
9 | the Free Software Foundation, either version 3 of the License, or |
10 | (at your option) any later version. | |
b8098ef8 DL |
11 | |
12 | GNU Emacs is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
9ec0b715 | 18 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
b8098ef8 DL |
19 | |
20 | ||
21 | /* The standard Vax 4.2 Unix crt0.c cannot be used for Emacs | |
22 | because it makes `environ' an initialized variable. | |
23 | It is easiest to have a special crt0.c on all machines | |
24 | though I don't know whether other machines actually need it. */ | |
25 | ||
26 | /* On the vax and 68000, in BSD4.2 and USG5.2, | |
27 | this is the data format on startup: | |
28 | (vax) ap and fp are unpredictable as far as I know; don't use them. | |
29 | sp -> word containing argc | |
30 | word pointing to first arg string | |
31 | [word pointing to next arg string]... 0 or more times | |
32 | 0 | |
33 | Optionally: | |
34 | [word pointing to environment variable]... 1 or more times | |
35 | ... | |
36 | 0 | |
37 | And always: | |
38 | first arg string | |
39 | [next arg string]... 0 or more times | |
40 | */ | |
41 | ||
42 | /* On the 16000, at least in the one 4.2 system I know about, | |
43 | the initial data format is | |
44 | sp -> word containing argc | |
45 | word containing argp | |
46 | word pointing to first arg string, and so on as above | |
47 | */ | |
48 | ||
49 | #ifdef emacs | |
50 | #include <config.h> | |
51 | #endif | |
52 | ||
53 | /* ******** WARNING ******** | |
54 | Do not insert any data definitions before data_start! | |
55 | Since this is the first file linked, the address of the following | |
56 | variable should correspond to the start of initialized data space. | |
57 | On some systems this is a constant that is independent of the text | |
58 | size for shared executables. On others, it is a function of the | |
59 | text size. In short, this seems to be the most portable way to | |
60 | discover the start of initialized data space dynamically at runtime, | |
61 | for either shared or unshared executables, on either swapping or | |
62 | virtual systems. It only requires that the linker allocate objects | |
63 | in the order encountered, a reasonable model for most Unix systems. | |
64 | Similarly, note that the address of _start() should be the start | |
65 | of text space. Fred Fish, UniSoft Systems Inc. */ | |
66 | ||
67 | int data_start = 0; | |
68 | ||
69 | #ifdef NEED_ERRNO | |
70 | int errno; | |
71 | #endif | |
72 | ||
4624371d | 73 | #ifndef MSDOS |
b8098ef8 DL |
74 | char **environ; |
75 | #endif | |
76 | ||
77 | #ifndef static | |
78 | /* On systems where the static storage class is usable, this function | |
79 | should be declared as static. Otherwise, the static keyword has | |
80 | been defined to be something else, and code for those systems must | |
81 | take care of this declaration appropriately. */ | |
82 | static start1 (); | |
83 | #endif | |
84 | ||
b8098ef8 DL |
85 | #ifdef CRT0_DUMMIES |
86 | ||
87 | /* Define symbol "start": here; some systems want that symbol. */ | |
88 | #ifdef DOT_GLOBAL_START | |
89 | asm(" .text "); | |
90 | asm(" .globl start "); | |
91 | asm(" start: "); | |
92 | #endif /* DOT_GLOBAL_START */ | |
93 | ||
94 | #ifdef NODOT_GLOBAL_START | |
95 | asm(" text "); | |
96 | asm(" global start "); | |
97 | asm(" start: "); | |
98 | #endif /* NODOT_GLOBAL_START */ | |
99 | ||
100 | #ifdef m68000 | |
101 | ||
102 | /* GCC 2.1, when optimization is turned off, seems to want to push a | |
103 | word of garbage on the stack, which screws up the CRT0_DUMMIES | |
104 | hack. So we hand-code _start in assembly language. */ | |
105 | asm(".text "); | |
106 | asm(" .even "); | |
107 | asm(".globl __start "); | |
108 | asm("__start: "); | |
109 | asm(" link a6,#0 "); | |
110 | asm(" jbsr _start1 "); | |
111 | asm(" unlk a6 "); | |
112 | asm(" rts "); | |
113 | ||
114 | #else /* not m68000 */ | |
115 | ||
116 | _start () | |
117 | { | |
118 | /* On vax, nothing is pushed here */ | |
119 | /* On sequent, bogus fp is pushed here */ | |
120 | start1 (); | |
121 | } | |
122 | ||
123 | #endif /* possibly m68000 */ | |
124 | ||
125 | static | |
126 | start1 (CRT0_DUMMIES argc, xargv) | |
127 | int argc; | |
128 | char *xargv; | |
129 | { | |
130 | register char **argv = &xargv; | |
131 | environ = argv + argc + 1; | |
132 | ||
133 | if ((char *)environ == xargv) | |
134 | environ--; | |
135 | exit (main (argc, argv, environ)); | |
136 | ||
137 | /* Refer to `start1' so GCC will not think it is never called | |
138 | and optimize it out. */ | |
139 | (void) &start1; | |
140 | } | |
141 | #else /* not CRT0_DUMMIES */ | |
142 | ||
143 | /* "m68k" and "m68000" both stand for m68000 processors, | |
144 | but with different program-entry conventions. | |
145 | This is a kludge. Now that the CRT0_DUMMIES mechanism above exists, | |
146 | most of these machines could use the vax code above | |
147 | with some suitable definition of CRT0_DUMMIES. | |
148 | Then the symbol m68k could be flushed. | |
149 | But I don't want to risk breaking these machines | |
150 | in a version 17 patch release, so that change is being put off. */ | |
151 | ||
152 | #ifdef m68k /* Can't do it all from C */ | |
153 | asm (" global _start"); | |
154 | asm (" text"); | |
155 | asm ("_start:"); | |
b8098ef8 | 156 | asm (" comm splimit%,4"); |
b8098ef8 DL |
157 | asm (" global exit"); |
158 | asm (" text"); | |
b8098ef8 | 159 | asm (" mov.l %d0,splimit%"); |
b8098ef8 DL |
160 | asm (" jsr start1"); |
161 | asm (" mov.l %d0,(%sp)"); | |
162 | asm (" jsr exit"); | |
163 | asm (" mov.l &1,%d0"); /* d0 = 1 => exit */ | |
164 | asm (" trap &0"); | |
165 | #else /* m68000, not m68k */ | |
166 | ||
167 | #ifdef m68000 | |
168 | ||
b8098ef8 DL |
169 | _start () |
170 | { | |
171 | #ifdef sun | |
b8098ef8 | 172 | finitfp_(); |
177c0ea7 | 173 | #endif |
b8098ef8 DL |
174 | /* On 68000, _start pushes a6 onto stack */ |
175 | start1 (); | |
176 | } | |
b8098ef8 DL |
177 | #endif /* m68000 */ |
178 | #endif /* m68k */ | |
179 | ||
180 | #if defined(m68k) || defined(m68000) | |
181 | /* ignore takes care of skipping the a6 value pushed in start. */ | |
182 | static | |
183 | #if defined(m68k) | |
184 | start1 (argc, xargv) | |
185 | #else | |
186 | start1 (ignore, argc, xargv) | |
187 | #endif | |
188 | int argc; | |
189 | char *xargv; | |
190 | { | |
191 | register char **argv = &xargv; | |
192 | environ = argv + argc + 1; | |
193 | ||
194 | if ((char *)environ == xargv) | |
195 | environ--; | |
b8098ef8 DL |
196 | exit (main (argc, argv, environ)); |
197 | } | |
198 | ||
199 | #endif /* m68k or m68000 */ | |
200 | ||
201 | #endif /* not CRT0_DUMMIES */ | |
202 | ||
b8098ef8 DL |
203 | #ifdef sparc |
204 | asm (".global __start"); | |
205 | asm (".text"); | |
206 | asm ("__start:"); | |
207 | asm (" mov 0, %fp"); | |
208 | asm (" ld [%sp + 64], %o0"); | |
209 | asm (" add %sp, 68, %o1"); | |
210 | asm (" sll %o0, 2, %o2"); | |
211 | asm (" add %o2, 4, %o2"); | |
212 | asm (" add %o1, %o2, %o2"); | |
213 | asm (" sethi %hi(_environ), %o3"); | |
214 | asm (" st %o2, [%o3+%lo(_environ)]"); | |
215 | asm (" andn %sp, 7, %sp"); | |
216 | asm (" call _main"); | |
217 | asm (" sub %sp, 24, %sp"); | |
218 | asm (" call __exit"); | |
219 | asm (" nop"); | |
220 | ||
221 | #endif /* sparc */ | |
222 | ||
223 | #if __FreeBSD__ == 2 | |
224 | char *__progname; | |
225 | #endif | |
ab5796a9 MB |
226 | |
227 | /* arch-tag: 4025c2fb-d6b1-4d29-b1b6-8100b6bd1e74 | |
228 | (do not change this comment) */ |