3 Copyright © 1995-2009, The AROS Development Team. All rights reserved.
6 Desc: Common startup code
11 #include <aros/config.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>
24 THIS_PROGRAM_HANDLES_SYMBOLSETS
26 /* pass these values to the command line handling function */
30 /* the command line handling functions will pass these values back to us */
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
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
)
89 struct Process
*myproc
;
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
;
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
;
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
];
164 __startup_entry_pos
++;
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