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 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
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
));
54 extern void InitMac(void);
57 static void monitor_start(void);
60 /* Global variables */
63 char *__splimit
; /* address of top of stack */
66 /* Initialize system and run */
68 void _start() __attribute__((noreturn
));
71 register int *fp
__asm__("%a6");
72 register char *d0
__asm__("%d0");
78 argv
= (char **)&fp
[2];
79 environ
= &argv
[argc
+1];
93 exit(main(argc
, argv
, environ
));
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)
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);
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
);