define __KERNEL_STRICT_NAMES to avoid inclusion of kernel types on systems that carry...
[cake.git] / compiler / startup / startup.c
blob52e12d4d480e3e0a4c3bf5a02bb7fa777ebd7b5b
2 /*
3 Copyright © 1995-2009, The AROS Development Team. All rights reserved.
4 $Id$
6 Desc: Common startup code
7 Lang: english
8 */
9 #define DEBUG 0
11 #include <aros/config.h>
12 #include <dos/dos.h>
13 #include <exec/memory.h>
14 #include <workbench/startup.h>
15 #include <proto/exec.h>
16 #include <proto/dos.h>
17 #include <aros/asmcall.h>
18 #include <aros/debug.h>
19 #include <aros/symbolsets.h>
20 #include <aros/startup.h>
22 #include "etask.h"
24 THIS_PROGRAM_HANDLES_SYMBOLSETS
26 /* pass these values to the command line handling function */
27 char *__argstr;
28 ULONG __argsize;
30 /* the command line handling functions will pass these values back to us */
31 char **__argv;
32 int __argc;
34 struct ExecBase *SysBase;
35 struct DosLibrary *DOSBase;
37 extern int main(int argc, char ** argv);
38 int (*__main_function_ptr)(int argc, char ** argv) __attribute__((__weak__)) = main;
40 DEFINESET(PROGRAM_ENTRIES);
42 /* if the programmer hasn't defined a symbol with the name __nocommandline
43 then the code to handle the commandline will be included from the autoinit.lib
45 extern int __nocommandline;
46 asm(".set __importcommandline, __nocommandline");
48 /* if the programmer hasn't defined a symbol with the name __nostdiowin
49 then the code to open a window for stdio will be included from the autoinit.lib
51 extern int __nostdiowin;
52 asm(".set __importstdiowin, __nostdiowin");
54 /* if the programmer hasn't defined a symbol with the name __nowbsupport
55 then the code to handle support for programs started from WB will be included from
56 the autoinit.lib
58 extern int __nowbsupport;
59 asm(".set __importnowbsupport, __nowbsupport");
61 /* if the programmer hasn't defined a symbol with the name __noinitexitsets
62 then the code to handle support for calling the INIT, EXIT symbolset functions
63 and the autoopening of libraries is called from the autoinit.lib
65 extern int __noinitexitsets;
66 asm(".set __importnoinitexitsets, __noinitexitsets");
68 static void __startup_entries_init(void);
70 struct aros_startup __aros_startup;
72 /* Guarantee that __startup_entry is placed at the beginning of the binary */
73 AROS_UFP3(LONG, __startup_entry,
74 AROS_UFHA(char *,argstr,A0),
75 AROS_UFHA(ULONG,argsize,D0),
76 AROS_UFHA(struct ExecBase *,sysbase,A6)
77 ) __attribute__((section(".aros.startup")));
79 #warning TODO: reset and initialize the FPU
80 #warning TODO: resident startup
81 AROS_UFH3(LONG, __startup_entry,
82 AROS_UFHA(char *,argstr,A0),
83 AROS_UFHA(ULONG,argsize,D0),
84 AROS_UFHA(struct ExecBase *,sysbase,A6)
87 AROS_USERFUNC_INIT
89 struct Process *myproc;
91 SysBase = sysbase;
93 D(bug("Entering __startup_entry(\"%s\", %d, %x)\n", argstr, argsize, SysBase));
96 No one program will be able to do anything useful without the dos.library,
97 so we open it here instead of using the automatic opening system
99 DOSBase = (struct DosLibrary *)OpenLibrary(DOSNAME, 39);
100 if (!DOSBase) return RETURN_FAIL;
102 __argstr = argstr;
103 __argsize = argsize;
105 myproc = (struct Process *)FindTask(NULL);
106 GetIntETask(myproc)->iet_startup = &__aros_startup;
107 __aros_startup.as_startup_error = RETURN_FAIL;
109 __startup_entries_init();
110 __startup_entries_next();
112 CloseLibrary((struct Library *)DOSBase);
114 D(bug("Leaving __startup_entry\n"));
116 return __aros_startup.as_startup_error;
118 AROS_USERFUNC_EXIT
119 } /* entry */
122 static void __startup_setjmp(void)
124 D(bug("Entering __startup_setjmp\n"));
126 if (setjmp(__aros_startup.as_startup_jmp_buf) == 0)
128 __startup_entries_next();
131 D(bug("Leaving __startup_setjmp\n"));
135 static void __startup_main(void)
137 D(bug("Entering __startup_main\n"));
139 /* Invoke the main function. A weak symbol is used as function name so that
140 it can be overridden (for *nix stuff, for instance). */
141 __aros_startup.as_startup_error = (*__main_function_ptr) (__argc, __argv);
143 D(bug("Leaving __startup_main\n"));
146 ADD2SET(__startup_setjmp, program_entries, -10);
147 ADD2SET(__startup_main, program_entries, 127);
150 static int __startup_entry_pos;
152 void __startup_entries_init(void)
154 __startup_entry_pos = 1;
157 void __startup_entries_next(void)
159 void (*entry_func)(void);
161 entry_func = SETNAME(PROGRAM_ENTRIES)[__startup_entry_pos];
162 if (entry_func)
164 __startup_entry_pos++;
165 entry_func();
171 Stub function for GCC __main().
173 The __main() function is originally used for C++ style constructors
174 and destructors in C. This replacement does nothing and gets rid of
175 linker-errors about references to __main().
177 #ifdef AROS_NEEDS___MAIN
178 void __main(void)
180 /* Do nothing. */
182 #endif