OSDN Git Service

* config/xtensa/xtensa.c (xtensa_va_arg): Fix to handle arguments
[pf3gnuchains/gcc-fork.git] / gcc / config / m68k / aux-crt1.c
1 /* Startup code for A/UX
2    Copyright (C) 1996 Free Software Foundation, Inc.
3
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.
8
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
16 executable.)
17
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.
22
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.  */
27
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
30    respectively.  */
31
32 #include <stdlib.h>
33 #ifdef MCRT1
34 #include <unistd.h>
35 #include <mon.h>
36 #endif
37
38 /* Extern function declarations */
39
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));
47
48 #ifdef MACCRT1
49 extern void InitMac(void);
50 #endif
51 #ifdef MCRT1
52 static void monitor_start(void);
53 #endif
54
55 /* Global variables */
56
57 char **environ;
58 char *__splimit;                        /* address of top of stack */
59
60
61 /* Initialize system and run */
62
63 void _start() __attribute__((noreturn));
64 void _start()
65 {
66   register int *fp __asm__("%a6");
67   register char *d0 __asm__("%d0");
68   char **argv;
69   int argc;
70
71   __splimit = d0;
72   argc = fp[1];
73   argv = (char **)&fp[2];
74   environ = &argv[argc+1];
75
76   initfpu();
77   __istart();
78   __compatmode();
79
80   atexit(_cleanup);
81 #ifdef MCRT1
82   monitor_start();
83 #endif
84 #ifdef MACCRT1
85   InitMac();
86 #endif
87
88   exit(main(argc, argv, environ));
89 }
90
91
92 #ifdef MCRT1
93 /* Start/Stop program monitor */
94
95 extern void monitor(void *, void *, WORD *, int, int);
96
97 static WORD *monitor_buffer;
98
99 static void monitor_cleanup(void)
100 {
101   monitor(NULL, NULL, NULL, 0, 0);
102   free(monitor_buffer);
103 }
104
105 static void monitor_start(void)
106 {
107   extern int etext;
108   extern int stext __asm__(".text");
109
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;
115
116   monitor_buffer = (WORD *)calloc(len, sizeof(WORD));
117   if (monitor_buffer == NULL)
118     {
119       static const char msg[] = "mcrt1: could not allocate monitor buffer\n";
120       write(2, msg, sizeof(msg)-1);
121       _exit(-1);
122     }
123
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);
126
127   atexit(monitor_cleanup);
128 }
129 #endif /* MCRT1 */