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
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 into combinations with other programs,
12 and to distribute those combinations without any restriction coming
13 from the use of this file. (The General Public License restrictions
14 do apply in other respects; for example, they cover modification of
15 the file, and distribution when not linked into a combine
18 This file is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; see the file COPYING. If not, write to
25 the Free Software Foundation, 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. */
28 /* This file is compiled three times to produce crt1.o, mcrt1.o, and
29 maccrt1.o. The final two are created by defining MCRT1 and MACCRT1
38 /* Extern function declarations */
40 extern void initfpu(void);
41 extern void __istart(void);
42 extern void __compatmode(void);
43 extern void _cleanup(void);
44 extern int main(int, char **, char **);
45 extern void exit(int) __attribute__((noreturn));
46 extern void _exit(int) __attribute__((noreturn));
49 extern void InitMac(void);
52 static void monitor_start(void);
55 /* Global variables */
58 char *__splimit; /* address of top of stack */
61 /* Initialize system and run */
63 void _start() __attribute__((noreturn));
66 register int *fp __asm__("%a6");
67 register char *d0 __asm__("%d0");
73 argv = (char **)&fp[2];
74 environ = &argv[argc+1];
88 exit(main(argc, argv, environ));
93 /* Start/Stop program monitor */
95 extern void monitor(void *, void *, WORD *, int, int);
97 static WORD *monitor_buffer;
99 static void monitor_cleanup(void)
101 monitor(NULL, NULL, NULL, 0, 0);
102 free(monitor_buffer);
105 static void monitor_start(void)
108 extern int stext __asm__(".text");
110 /* Choice of buffer size should be "no more than a few times
111 smaller than the program size" -- I don't believe that there
112 are any (useful) functions smaller than two insns (4 bytes)
113 so that is the scale factor used here */
114 int len = (&etext - &stext + 1) / 4;
116 monitor_buffer = (WORD *)calloc(len, sizeof(WORD));
117 if (monitor_buffer == NULL)
119 static const char msg[] = "mcrt1: could not allocate monitor buffer\n";
120 write(2, msg, sizeof(msg)-1);
124 /* I'm not sure why the count cap at 600 -- but that is what A/UX does */
125 monitor(&stext, &etext, monitor_buffer, len, 600);
127 atexit(monitor_cleanup);