1 /* C code startup routine.
2 Copyright (C) 1985, 1986, 1992 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* The standard Vax 4.2 Unix crt0.c cannot be used for Emacs
23 because it makes `environ' an initialized variable.
24 It is easiest to have a special crt0.c on all machines
25 though I don't know whether other machines actually need it. */
27 /* On the vax and 68000, in BSD4.2 and USG5.2,
28 this is the data format on startup:
29 (vax) ap and fp are unpredictable as far as I know; don't use them.
30 sp -> word containing argc
31 word pointing to first arg string
32 [word pointing to next arg string]... 0 or more times
35 [word pointing to environment variable]... 1 or more times
40 [next arg string]... 0 or more times
43 /* On the 16000, at least in the one 4.2 system I know about,
44 the initial data format is
45 sp -> word containing argc
47 word pointing to first arg string, and so on as above
54 /* ******** WARNING ********
55 Do not insert any data definitions before data_start!
56 Since this is the first file linked, the address of the following
57 variable should correspond to the start of initialized data space.
58 On some systems this is a constant that is independent of the text
59 size for shared executables. On others, it is a function of the
60 text size. In short, this seems to be the most portable way to
61 discover the start of initialized data space dynamically at runtime,
62 for either shared or unshared executables, on either swapping or
63 virtual systems. It only requires that the linker allocate objects
64 in the order encountered, a reasonable model for most Unix systems.
65 Similarly, note that the address of _start() should be the start
66 of text space. Fred Fish, UniSoft Systems Inc. */
74 #ifndef DONT_NEED_ENVIRON
79 /* On systems where the static storage class is usable, this function
80 should be declared as static. Otherwise, the static keyword has
81 been defined to be something else, and code for those systems must
82 take care of this declaration appropriately. */
87 extern char *malloc(), *realloc(), *(*_libc_malloc
) (), *(*_libc_realloc
)();
88 extern void free(), (*_libc_free
) (); extern int main();
89 std_$call
void unix_$
main();
93 _libc_malloc
= malloc
;
94 _libc_realloc
= realloc
;
96 unix_$
main(main
); /* no return */
100 #if defined(orion) || defined(pyramid) || defined(celerity) || defined(ALLIANT) || defined(clipper) || defined(sps7)
102 #if defined(sps7) && defined(V3x)
108 /* _start must initialize _curbrk and _minbrk on the first startup;
109 when starting up after dumping, it must initialize them to what they were
110 before the dumping, since they are in the shared library and
111 are not dumped. See ADJUST_EXEC_HEADER in m-alliant.h. */
112 extern unsigned char *_curbrk
, *_minbrk
;
113 extern unsigned char end
;
114 unsigned char *_setbrk
= &end
;
116 unsigned char *_end
= &end
;
124 _start (DUMMIES argc
, argv
, envp
)
140 exit (main (argc
, argv
, envp
));
143 #endif /* orion or pyramid or celerity or alliant or clipper */
145 #if defined (ns16000) && !defined (sequent) && !defined (UMAX) && !defined (CRT0_DUMMIES)
149 /* On 16000, _start pushes fp onto stack */
153 /* ignore takes care of skipping the fp value pushed in start. */
155 start1 (ignore
, argc
, argv
)
158 register char **argv
;
160 environ
= argv
+ argc
+ 1;
162 if (environ
== *argv
)
164 exit (main (argc
, argv
, environ
));
166 #endif /* ns16000, not sequent and not UMAX, and not the CRT0_DUMMIES method */
171 asm(" exit [] # undo enter");
172 asm(" .set exitsc,1");
173 asm(" .set sigcatchall,0x400");
175 asm(" .globl _exit");
176 asm(" .globl start");
177 asm(" .globl __start");
178 asm(" .globl _main");
179 asm(" .globl _environ");
180 asm(" .globl _sigvec");
181 asm(" .globl sigentry");
186 asm(" .double p_glbl,0,0xf00000,0");
190 asm(" movd 8(sp),0(sp) # argc");
191 asm(" addr 12(sp),r0");
192 asm(" movd r0,4(sp) # argv");
196 asm(" cmpqd $0,0(r1) # null args term ?");
198 asm(" cmpd r0,0(4(sp)) # end of 'env' or 'argv' ?");
200 asm(" addqd $-4,r0 # envp's are in list");
202 asm(" movd r0,8(sp) # env");
203 asm(" movd r0,@_environ # indir is 0 if no env ; not 0 if env");
204 asm(" movqd $0,tos # setup intermediate signal handler");
205 asm(" addr @sv,tos");
206 asm(" movzwd $sigcatchall,tos");
207 asm(" jsr @_sigvec");
214 asm(" addr @exitsc,r0");
216 asm(" .align 4 # sigvec arg");
218 asm(" .double sigentry");
222 asm(" .comm p_glbl,1");
228 /* Define symbol "start": here; some systems want that symbol. */
229 #ifdef DOT_GLOBAL_START
231 asm(" .globl start ");
233 #endif /* DOT_GLOBAL_START */
235 #ifdef NODOT_GLOBAL_START
237 asm(" global start ");
239 #endif /* NODOT_GLOBAL_START */
243 /* GCC 2.1, when optimization is turned off, seems to want to push a
244 word of garbage on the stack, which screws up the CRT0_DUMMIES
245 hack. So we hand-code _start in assembly language. */
248 asm(".globl __start ");
251 asm(" jbsr _start1 ");
255 #else /* not m68000 */
259 /* On vax, nothing is pushed here */
260 /* On sequent, bogus fp is pushed here */
264 #endif /* possibly m68000 */
267 start1 (CRT0_DUMMIES argc
, xargv
)
271 register char **argv
= &xargv
;
272 environ
= argv
+ argc
+ 1;
274 if ((char *)environ
== xargv
)
276 exit (main (argc
, argv
, environ
));
278 /* Refer to `start1' so GCC will not think it is never called
279 and optimize it out. */
282 #else /* not CRT0_DUMMIES */
284 /* "m68k" and "m68000" both stand for m68000 processors,
285 but with different program-entry conventions.
286 This is a kludge. Now that the CRT0_DUMMIES mechanism above exists,
287 most of these machines could use the vax code above
288 with some suitable definition of CRT0_DUMMIES.
289 Then the symbol m68k could be flushed.
290 But I don't want to risk breaking these machines
291 in a version 17 patch release, so that change is being put off. */
293 #ifdef m68k /* Can't do it all from C */
294 asm (" global _start");
299 asm (" comm havefpu%,2");
300 #else /* m68k, not STRIDE */
301 asm (" comm splimit%,4");
303 asm (" global exit");
307 asm (" mov.w %d0,havefpu%");
308 #else /* m68k, not STRIDE */
309 asm (" mov.l %d0,splimit%");
313 asm (" mov.l %d0,(%sp)");
315 asm (" mov.l &1,%d0"); /* d0 = 1 => exit */
317 #else /* m68000, not m68k */
322 /* Added by ESM Sun May 24 12:44:02 1987 to get new ISI library to work */
323 /* Edited by Ray Mon May 15 15:59:56 EST 1989 so we can compile with gcc */
324 #if defined(BSD4_3) && !defined(__GNUC__)
327 asm (" .globl is68020");
330 asm (" .long 0x00000000");
331 asm (" .long 0xffffffff");
332 /* End of stuff added by ESM */
335 asm (" .globl __start");
339 asm (" jbsr _start1");
342 #if defined(BSD4_3) && !defined(__GNUC__)
345 #else /* not ISI68K */
352 /* On 68000, _start pushes a6 onto stack */
355 #endif /* not ISI68k */
359 #if defined(m68k) || defined(m68000)
360 /* ignore takes care of skipping the a6 value pushed in start. */
365 start1 (ignore
, argc
, xargv
)
370 register char **argv
= &xargv
;
371 environ
= argv
+ argc
+ 1;
373 if ((char *)environ
== xargv
)
376 asm(" jsr f68881_used");
379 asm(" jsr ffpa_used");
382 asm(" jsr start_float");
384 exit (main (argc
, argv
, environ
));
387 #endif /* m68k or m68000 */
389 #endif /* not CRT0_DUMMIES */
394 #ifdef OLD_HP_ASSEMBLER
396 asm(" globl __start");
401 asm(" subq.w #0x1,d0");
402 asm(" move.w d0,float_soft");
403 asm(" move.l 0x4(a7),d0");
404 asm(" beq.s skip_1");
405 asm(" move.l d0,a0");
406 asm(" clr.l -0x4(a0)");
408 asm(" move.l a7,a0");
409 asm(" subq.l #0x8,a7");
410 asm(" move.l (a0),(a7)");
411 asm(" move.l (a0),_argc_value");
412 asm(" addq.l #0x4,a0");
413 asm(" move.l a0,0x4(a7)");
414 asm(" move.l a0,_argv_value");
417 asm(" bne.s incr_loop");
418 asm(" move.l 0x4(a7),a1");
419 asm(" cmp.l (a1),a0");
420 asm(" blt.s skip_2");
421 asm(" subq.l #0x4,a0");
423 asm(" move.l a0,0x8(a7)");
424 asm(" move.l a0,_environ");
426 asm(" addq.l #0x8,a7");
427 asm(" move.l d0,-(a7)");
429 asm(" move.w #0x1,d0");
431 asm(" comm float_soft,4");
432 /* float_soft is allocated in this way because C would
433 put an underscore character in its name otherwise. */
435 #else /* new hp assembler */
438 asm(" global float_loc");
439 asm(" set float_loc,0xFFFFB000");
440 asm(" global fpa_loc");
441 asm(" set fpa_loc,0xfff08000");
442 asm(" global __start");
443 asm(" global _exit");
444 asm(" global _main");
446 asm(" byte 0,0,0,0");
447 asm(" subq.w &1,%d0");
448 asm(" mov.w %d0,float_soft");
449 asm(" mov.w %d1,flag_68881");
451 asm(" beq.b skip_float");
452 asm(" fmov.l &0x7400,%fpcr");
453 /* asm(" fmov.l &0x7480,%fpcr"); */
454 #endif /* HPUX_68010 */
456 asm(" mov.l %a0,%d0");
457 asm(" add.l %d0,%d0");
458 asm(" subx.w %d1,%d1");
459 asm(" mov.w %d1,flag_68010");
460 asm(" add.l %d0,%d0");
461 asm(" subx.w %d1,%d1");
462 asm(" mov.w %d1,flag_fpa");
464 asm(" ble.b skip_3");
465 asm(" lsl flag_68881");
466 asm(" lsl flag_fpa");
468 asm(" mov.l 4(%a7),%d0");
469 asm(" beq.b skip_1");
470 asm(" mov.l %d0,%a0");
471 asm(" clr.l -4(%a0)");
473 asm(" mov.l %a7,%a0");
474 asm(" subq.l &8,%a7");
475 asm(" mov.l (%a0),(%a7)");
476 asm(" mov.l (%a0),_argc_value");
477 asm(" addq.l &4,%a0");
478 asm(" mov.l %a0,4(%a7)");
479 asm(" mov.l %a0,_argv_value");
481 asm(" tst.l (%a0)+");
482 asm(" bne.b incr_loop");
483 asm(" mov.l 4(%a7),%a1");
484 asm(" cmp.l %a0,(%a1)");
485 asm(" blt.b skip_2");
486 asm(" subq.l &4,%a0");
488 asm(" mov.l %a0,8(%a7)");
489 asm(" mov.l %a0,_environ");
491 asm(" addq.l &8,%a7");
492 asm(" mov.l %d0,-(%a7)");
494 asm(" mov.w &1,%d0");
496 asm(" comm float_soft, 4");
497 asm(" comm flag_68881, 4");
498 asm(" comm flag_68010, 4");
499 asm(" comm flag_68040, 4");
500 asm(" comm flag_fpa, 4");
502 #endif /* new hp assembler */
503 #endif /* hp9000s300 */
507 /* startup code has to be in near text rather
508 than fartext as allocated by the C compiler. */
511 asm(" .globl __start");
514 /* setup base register b1 (function base). */
517 /* setup base registers b3 through b7 (data references). */
518 asm(" file basevals,b3");
519 /* setup base register b2 (stack pointer); it should be
520 aligned on a 8-word boundary; but because it is pointing
521 to argc, its value should be remembered (in r5). */
524 asm(" andw #~0x1f,r4");
526 /* allocate stack frame to do some work. */
527 asm(" subea 16w,b2");
528 /* initialize signal catching for UTX/32 1.2; this is
529 necessary to make restart from saved image work. */
530 asm(" movea sigcatch,r1");
531 asm(" movw r1,8w[b2]");
533 /* setup address of argc for start1. */
534 asm(" movw r5,8w[b2]");
535 asm(" func #1,_start1");
537 /* space for ld to store base register initial values. */
540 asm(" .word __base3,__base4,__base5,__base6,__base7");
547 register char **argv
;
550 argv
= (char **)(xargc
) + 1;
551 environ
= argv
+ argc
+ 1;
555 exit (main (argc
, argv
, environ
));
562 #include <elxsi/argvcache.h>
564 extern char **environ
;
566 extern void _init_doscan(), _init_iob();
568 char *_init_brk
= end
;
572 environ
= exec_cache
.ac_envp
;
577 _exit (exit (main (exec_cache
.ac_argc
,
579 exec_cache
.ac_envp
)));
585 asm (".global __start");
589 asm (" ld [%sp + 64], %o0");
590 asm (" add %sp, 68, %o1");
591 asm (" sll %o0, 2, %o2");
592 asm (" add %o2, 4, %o2");
593 asm (" add %o1, %o2, %o2");
594 asm (" sethi %hi(_environ), %o3");
595 asm (" st %o2, [%o3+%lo(_environ)]");
596 asm (" andn %sp, 7, %sp");
598 asm (" sub %sp, 24, %sp");
599 asm (" call __exit");
608 #include <sys/param.h> /* for version number */
609 #if defined(_BSDI_VERSION) && (_BSDI_VERSION >= 199501)
612 #endif /* __bsdi__ */