Initial revision
[official-gcc.git] / gcc / config / m68k / aux-crt1.c
blob9ee529b053d1a53645980111c604dca11f5ba79e
1 /* Startup code for A/UX
2 Copyright (C) 1996 Free Software Foundation, Inc.
4 This file is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 2, or (at your option) any
7 later version.
9 In addition to the permissions in the GNU General Public License, the
10 Free Software Foundation gives you unlimited permission to link the
11 compiled version of this file with other programs, and to distribute
12 those programs without any restriction coming from the use of this
13 file. (The General Public License restrictions do apply in other
14 respects; for example, they cover modification of the file, and
15 distribution when not linked into another program.)
17 This file is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; see the file COPYING. If not, write to
24 the Free Software Foundation, 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. */
27 /* As a special exception, if you link this library with files
28 compiled with GCC to produce an executable, this does not cause
29 the resulting executable to be covered by the GNU General Public License.
30 This exception does not however invalidate any other reasons why
31 the executable file might be covered by the GNU General Public License. */
33 /* This file is compiled three times to produce crt1.o, mcrt1.o, and
34 maccrt1.o. The final two are created by defining MCRT1 and MACCRT1
35 respectively. */
37 #include <stdlib.h>
38 #ifdef MCRT1
39 #include <unistd.h>
40 #include <mon.h>
41 #endif
43 /* Extern function declarations */
45 extern void initfpu(void);
46 extern void __istart(void);
47 extern void __compatmode(void);
48 extern void _cleanup(void);
49 extern int main(int, char **, char **);
50 extern void exit(int) __attribute__((noreturn));
51 extern void _exit(int) __attribute__((noreturn));
53 #ifdef MACCRT1
54 extern void InitMac(void);
55 #endif
56 #ifdef MCRT1
57 static void monitor_start(void);
58 #endif
60 /* Global variables */
62 char **environ;
63 char *__splimit; /* address of top of stack */
66 /* Initialize system and run */
68 void _start() __attribute__((noreturn));
69 void _start()
71 register int *fp __asm__("%a6");
72 register char *d0 __asm__("%d0");
73 char **argv;
74 int argc;
76 __splimit = d0;
77 argc = fp[1];
78 argv = (char **)&fp[2];
79 environ = &argv[argc+1];
81 initfpu();
82 __istart();
83 __compatmode();
85 atexit(_cleanup);
86 #ifdef MCRT1
87 monitor_start();
88 #endif
89 #ifdef MACCRT1
90 InitMac();
91 #endif
93 exit(main(argc, argv, environ));
97 #ifdef MCRT1
98 /* Start/Stop program monitor */
100 extern void monitor(void *, void *, WORD *, int, int);
102 static WORD *monitor_buffer;
104 static void monitor_cleanup(void)
106 monitor(NULL, NULL, NULL, 0, 0);
107 free(monitor_buffer);
110 static void monitor_start(void)
112 extern int etext;
113 extern int stext __asm__(".text");
115 /* Choice of buffer size should be "no more than a few times
116 smaller than the program size" -- I don't believe that there
117 are any (useful) functions smaller than two insns (4 bytes)
118 so that is the scale factor used here */
119 int len = (&etext - &stext + 1) / 4;
121 monitor_buffer = (WORD *)calloc(len, sizeof(WORD));
122 if (monitor_buffer == NULL)
124 static const char msg[] = "mcrt1: could not allocate monitor buffer\n";
125 write(2, msg, sizeof(msg)-1);
126 _exit(-1);
129 /* I'm not sure why the count cap at 600 -- but that is what A/UX does */
130 monitor(&stext, &etext, monitor_buffer, len, 600);
132 atexit(monitor_cleanup);
134 #endif /* MCRT1 */