00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <stdlib.h>
00033 #ifdef MCRT1
00034 #include <unistd.h>
00035 #include <mon.h>
00036 #endif
00037
00038
00039
00040 extern void initfpu(void);
00041 extern void __istart(void);
00042 extern void __compatmode(void);
00043 extern void _cleanup(void);
00044 extern int main(int, char **, char **);
00045 extern void exit(int) __attribute__((noreturn));
00046 extern void _exit(int) __attribute__((noreturn));
00047
00048 #ifdef MACCRT1
00049 extern void InitMac(void);
00050 #endif
00051 #ifdef MCRT1
00052 static void monitor_start(void);
00053 #endif
00054
00055
00056
00057 char **environ;
00058 char *__splimit;
00059
00060
00061
00062
00063 void _start() __attribute__((noreturn));
00064 void _start()
00065 {
00066 register int *fp __asm__("%a6");
00067 register char *d0 __asm__("%d0");
00068 char **argv;
00069 int argc;
00070
00071 __splimit = d0;
00072 argc = fp[1];
00073 argv = (char **)&fp[2];
00074 environ = &argv[argc+1];
00075
00076 initfpu();
00077 __istart();
00078 __compatmode();
00079
00080 atexit(_cleanup);
00081 #ifdef MCRT1
00082 monitor_start();
00083 #endif
00084 #ifdef MACCRT1
00085 InitMac();
00086 #endif
00087
00088 exit(main(argc, argv, environ));
00089 }
00090
00091
00092 #ifdef MCRT1
00093
00094
00095 extern void monitor(void *, void *, WORD *, int, int);
00096
00097 static WORD *monitor_buffer;
00098
00099 static void monitor_cleanup(void)
00100 {
00101 monitor(NULL, NULL, NULL, 0, 0);
00102 free(monitor_buffer);
00103 }
00104
00105 static void monitor_start(void)
00106 {
00107 extern int etext;
00108 extern int stext __asm__(".text");
00109
00110
00111
00112
00113
00114 int len = (&etext - &stext + 1) / 4;
00115
00116 monitor_buffer = (WORD *)calloc(len, sizeof(WORD));
00117 if (monitor_buffer == NULL)
00118 {
00119 static const char msg[] = "mcrt1: could not allocate monitor buffer\n";
00120 write(2, msg, sizeof(msg)-1);
00121 _exit(-1);
00122 }
00123
00124
00125 monitor(&stext, &etext, monitor_buffer, len, 600);
00126
00127 atexit(monitor_cleanup);
00128 }
00129 #endif