1 /* C code startup routine.
2 Copyright (C) 1985, 1986, 1992, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
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. */
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
34 [word pointing to environment variable]... 1 or more times
39 [next arg string]... 0 or more times
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
46 word pointing to first arg string, and so on as above
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. */
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. */
87 /* Define symbol "start": here; some systems want that symbol. */
88 #ifdef DOT_GLOBAL_START
90 asm(" .globl start ");
92 #endif /* DOT_GLOBAL_START */
94 #ifdef NODOT_GLOBAL_START
96 asm(" global start ");
98 #endif /* NODOT_GLOBAL_START */
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. */
107 asm(".globl __start ");
110 asm(" jbsr _start1 ");
114 #else /* not m68000 */
118 /* On vax, nothing is pushed here */
119 /* On sequent, bogus fp is pushed here */
123 #endif /* possibly m68000 */
126 start1 (CRT0_DUMMIES argc
, xargv
)
130 register char **argv
= &xargv
;
131 environ
= argv
+ argc
+ 1;
133 if ((char *)environ
== xargv
)
135 exit (main (argc
, argv
, environ
));
137 /* Refer to `start1' so GCC will not think it is never called
138 and optimize it out. */
141 #else /* not CRT0_DUMMIES */
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. */
152 #ifdef m68k /* Can't do it all from C */
153 asm (" global _start");
156 asm (" comm splimit%,4");
157 asm (" global exit");
159 asm (" mov.l %d0,splimit%");
161 asm (" mov.l %d0,(%sp)");
163 asm (" mov.l &1,%d0"); /* d0 = 1 => exit */
165 #else /* m68000, not m68k */
174 /* On 68000, _start pushes a6 onto stack */
180 #if defined(m68k) || defined(m68000)
181 /* ignore takes care of skipping the a6 value pushed in start. */
186 start1 (ignore
, argc
, xargv
)
191 register char **argv
= &xargv
;
192 environ
= argv
+ argc
+ 1;
194 if ((char *)environ
== xargv
)
196 exit (main (argc
, argv
, environ
));
199 #endif /* m68k or m68000 */
201 #endif /* not CRT0_DUMMIES */
206 #ifdef OLD_HP_ASSEMBLER
208 asm(" globl __start");
213 asm(" subq.w #0x1,d0");
214 asm(" move.w d0,float_soft");
215 asm(" move.l 0x4(a7),d0");
216 asm(" beq.s skip_1");
217 asm(" move.l d0,a0");
218 asm(" clr.l -0x4(a0)");
220 asm(" move.l a7,a0");
221 asm(" subq.l #0x8,a7");
222 asm(" move.l (a0),(a7)");
223 asm(" move.l (a0),_argc_value");
224 asm(" addq.l #0x4,a0");
225 asm(" move.l a0,0x4(a7)");
226 asm(" move.l a0,_argv_value");
229 asm(" bne.s incr_loop");
230 asm(" move.l 0x4(a7),a1");
231 asm(" cmp.l (a1),a0");
232 asm(" blt.s skip_2");
233 asm(" subq.l #0x4,a0");
235 asm(" move.l a0,0x8(a7)");
236 asm(" move.l a0,_environ");
238 asm(" addq.l #0x8,a7");
239 asm(" move.l d0,-(a7)");
241 asm(" move.w #0x1,d0");
243 asm(" comm float_soft,4");
244 /* float_soft is allocated in this way because C would
245 put an underscore character in its name otherwise. */
247 #else /* new hp assembler */
250 asm(" global float_loc");
251 asm(" set float_loc,0xFFFFB000");
252 asm(" global fpa_loc");
253 asm(" set fpa_loc,0xfff08000");
254 asm(" global __start");
255 asm(" global _exit");
256 asm(" global _main");
258 asm(" byte 0,0,0,0");
259 asm(" subq.w &1,%d0");
260 asm(" mov.w %d0,float_soft");
261 asm(" mov.w %d1,flag_68881");
263 asm(" beq.b skip_float");
264 asm(" fmov.l &0x7400,%fpcr");
265 /* asm(" fmov.l &0x7480,%fpcr"); */
266 #endif /* HPUX_68010 */
268 asm(" mov.l %a0,%d0");
269 asm(" add.l %d0,%d0");
270 asm(" subx.w %d1,%d1");
271 asm(" mov.w %d1,flag_68010");
272 asm(" add.l %d0,%d0");
273 asm(" subx.w %d1,%d1");
274 asm(" mov.w %d1,flag_fpa");
276 asm(" ble.b skip_3");
277 asm(" lsl flag_68881");
278 asm(" lsl flag_fpa");
280 asm(" mov.l 4(%a7),%d0");
281 asm(" beq.b skip_1");
282 asm(" mov.l %d0,%a0");
283 asm(" clr.l -4(%a0)");
285 asm(" mov.l %a7,%a0");
286 asm(" subq.l &8,%a7");
287 asm(" mov.l (%a0),(%a7)");
288 asm(" mov.l (%a0),_argc_value");
289 asm(" addq.l &4,%a0");
290 asm(" mov.l %a0,4(%a7)");
291 asm(" mov.l %a0,_argv_value");
293 asm(" tst.l (%a0)+");
294 asm(" bne.b incr_loop");
295 asm(" mov.l 4(%a7),%a1");
296 asm(" cmp.l %a0,(%a1)");
297 asm(" blt.b skip_2");
298 asm(" subq.l &4,%a0");
300 asm(" mov.l %a0,8(%a7)");
301 asm(" mov.l %a0,_environ");
303 asm(" addq.l &8,%a7");
304 asm(" mov.l %d0,-(%a7)");
306 asm(" mov.w &1,%d0");
308 asm(" comm float_soft, 4");
309 asm(" comm flag_68881, 4");
310 asm(" comm flag_68010, 4");
311 asm(" comm flag_68040, 4");
312 asm(" comm flag_fpa, 4");
314 #endif /* new hp assembler */
315 #endif /* hp9000s300 */
318 asm (".global __start");
322 asm (" ld [%sp + 64], %o0");
323 asm (" add %sp, 68, %o1");
324 asm (" sll %o0, 2, %o2");
325 asm (" add %o2, 4, %o2");
326 asm (" add %o1, %o2, %o2");
327 asm (" sethi %hi(_environ), %o3");
328 asm (" st %o2, [%o3+%lo(_environ)]");
329 asm (" andn %sp, 7, %sp");
331 asm (" sub %sp, 24, %sp");
332 asm (" call __exit");
341 #include <sys/param.h> /* for version number */
342 #if defined(_BSDI_VERSION) && (_BSDI_VERSION >= 199501)
345 #endif /* __bsdi__ */
347 /* arch-tag: 4025c2fb-d6b1-4d29-b1b6-8100b6bd1e74
348 (do not change this comment) */