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 */
350 #ifdef LISP_FLOAT_TYPE
354 /* On 68000, _start pushes a6 onto stack */
357 #endif /* not ISI68k */
361 #if defined(m68k) || defined(m68000)
362 /* ignore takes care of skipping the a6 value pushed in start. */
367 start1 (ignore
, argc
, xargv
)
372 register char **argv
= &xargv
;
373 environ
= argv
+ argc
+ 1;
375 if ((char *)environ
== xargv
)
378 asm(" jsr f68881_used");
381 asm(" jsr ffpa_used");
384 asm(" jsr start_float");
386 exit (main (argc
, argv
, environ
));
389 #endif /* m68k or m68000 */
391 #endif /* not CRT0_DUMMIES */
396 #ifdef OLD_HP_ASSEMBLER
398 asm(" globl __start");
403 asm(" subq.w #0x1,d0");
404 asm(" move.w d0,float_soft");
405 asm(" move.l 0x4(a7),d0");
406 asm(" beq.s skip_1");
407 asm(" move.l d0,a0");
408 asm(" clr.l -0x4(a0)");
410 asm(" move.l a7,a0");
411 asm(" subq.l #0x8,a7");
412 asm(" move.l (a0),(a7)");
413 asm(" move.l (a0),_argc_value");
414 asm(" addq.l #0x4,a0");
415 asm(" move.l a0,0x4(a7)");
416 asm(" move.l a0,_argv_value");
419 asm(" bne.s incr_loop");
420 asm(" move.l 0x4(a7),a1");
421 asm(" cmp.l (a1),a0");
422 asm(" blt.s skip_2");
423 asm(" subq.l #0x4,a0");
425 asm(" move.l a0,0x8(a7)");
426 asm(" move.l a0,_environ");
428 asm(" addq.l #0x8,a7");
429 asm(" move.l d0,-(a7)");
431 asm(" move.w #0x1,d0");
433 asm(" comm float_soft,4");
434 /* float_soft is allocated in this way because C would
435 put an underscore character in its name otherwise. */
437 #else /* new hp assembler */
440 asm(" global float_loc");
441 asm(" set float_loc,0xFFFFB000");
442 asm(" global fpa_loc");
443 asm(" set fpa_loc,0xfff08000");
444 asm(" global __start");
445 asm(" global _exit");
446 asm(" global _main");
448 asm(" byte 0,0,0,0");
449 asm(" subq.w &1,%d0");
450 asm(" mov.w %d0,float_soft");
451 asm(" mov.w %d1,flag_68881");
453 asm(" beq.b skip_float");
454 asm(" fmov.l &0x7400,%fpcr");
455 /* asm(" fmov.l &0x7480,%fpcr"); */
456 #endif /* HPUX_68010 */
458 asm(" mov.l %a0,%d0");
459 asm(" add.l %d0,%d0");
460 asm(" subx.w %d1,%d1");
461 asm(" mov.w %d1,flag_68010");
462 asm(" add.l %d0,%d0");
463 asm(" subx.w %d1,%d1");
464 asm(" mov.w %d1,flag_fpa");
466 asm(" ble.b skip_3");
467 asm(" lsl flag_68881");
468 asm(" lsl flag_fpa");
470 asm(" mov.l 4(%a7),%d0");
471 asm(" beq.b skip_1");
472 asm(" mov.l %d0,%a0");
473 asm(" clr.l -4(%a0)");
475 asm(" mov.l %a7,%a0");
476 asm(" subq.l &8,%a7");
477 asm(" mov.l (%a0),(%a7)");
478 asm(" mov.l (%a0),_argc_value");
479 asm(" addq.l &4,%a0");
480 asm(" mov.l %a0,4(%a7)");
481 asm(" mov.l %a0,_argv_value");
483 asm(" tst.l (%a0)+");
484 asm(" bne.b incr_loop");
485 asm(" mov.l 4(%a7),%a1");
486 asm(" cmp.l %a0,(%a1)");
487 asm(" blt.b skip_2");
488 asm(" subq.l &4,%a0");
490 asm(" mov.l %a0,8(%a7)");
491 asm(" mov.l %a0,_environ");
493 asm(" addq.l &8,%a7");
494 asm(" mov.l %d0,-(%a7)");
496 asm(" mov.w &1,%d0");
498 asm(" comm float_soft, 4");
499 asm(" comm flag_68881, 4");
500 asm(" comm flag_68010, 4");
501 asm(" comm flag_68040, 4");
502 asm(" comm flag_fpa, 4");
504 #endif /* new hp assembler */
505 #endif /* hp9000s300 */
509 /* startup code has to be in near text rather
510 than fartext as allocated by the C compiler. */
513 asm(" .globl __start");
516 /* setup base register b1 (function base). */
519 /* setup base registers b3 through b7 (data references). */
520 asm(" file basevals,b3");
521 /* setup base register b2 (stack pointer); it should be
522 aligned on a 8-word boundary; but because it is pointing
523 to argc, its value should be remembered (in r5). */
526 asm(" andw #~0x1f,r4");
528 /* allocate stack frame to do some work. */
529 asm(" subea 16w,b2");
530 /* initialize signal catching for UTX/32 1.2; this is
531 necessary to make restart from saved image work. */
532 asm(" movea sigcatch,r1");
533 asm(" movw r1,8w[b2]");
535 /* setup address of argc for start1. */
536 asm(" movw r5,8w[b2]");
537 asm(" func #1,_start1");
539 /* space for ld to store base register initial values. */
542 asm(" .word __base3,__base4,__base5,__base6,__base7");
549 register char **argv
;
552 argv
= (char **)(xargc
) + 1;
553 environ
= argv
+ argc
+ 1;
557 exit (main (argc
, argv
, environ
));
564 #include <elxsi/argvcache.h>
566 extern char **environ
;
568 extern void _init_doscan(), _init_iob();
570 char *_init_brk
= end
;
574 environ
= exec_cache
.ac_envp
;
579 _exit (exit (main (exec_cache
.ac_argc
,
581 exec_cache
.ac_envp
)));
587 asm (".global __start");
591 asm (" ld [%sp + 64], %o0");
592 asm (" add %sp, 68, %o1");
593 asm (" sll %o0, 2, %o2");
594 asm (" add %o2, 4, %o2");
595 asm (" add %o1, %o2, %o2");
596 asm (" sethi %hi(_environ), %o3");
597 asm (" st %o2, [%o3+%lo(_environ)]");
598 asm (" andn %sp, 7, %sp");
600 asm (" sub %sp, 24, %sp");
601 asm (" call __exit");
610 #include <sys/param.h> /* for version number */
611 #if defined(_BSDI_VERSION) && (_BSDI_VERSION >= 199501)
614 #endif /* __bsdi__ */