3 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
6 Desc: Common startup code
9 #include <aros/config.h>
12 #include <exec/memory.h>
13 #include <workbench/startup.h>
14 #include <proto/exec.h>
15 #include <proto/dos.h>
16 #include <aros/asmcall.h>
17 #include <aros/debug.h>
18 #include <aros/symbolsets.h>
19 #include <aros/startup.h>
23 THIS_PROGRAM_HANDLES_SYMBOLSETS
25 /* Don't define symbols before the entry point. */
26 extern struct ExecBase
*SysBase
;
27 extern struct WBStartup
*WBenchMsg
;
28 extern int main(int argc
, char ** argv
);
29 int (*__main_function_ptr
)(int argc
, char ** argv
) __attribute__((__weak__
)) = main
;
35 DECLARESET(PROGRAM_ENTRIES
);
38 This won't work for normal AmigaOS because you can't expect SysBase to be
39 in A6. The correct way is to use *(struct ExecBase **)4 and because GCC
40 emits strings for a certain function _before_ the code the program will
41 crash immediately because the first element in the code won't be valid
45 extern char *__argstr
;
46 extern ULONG __argsize
;
49 extern struct DosLibrary
*DOSBase
;
51 static struct aros_startup __aros_startup
;
53 #warning TODO: reset and initialize the FPU
54 #warning TODO: resident startup
55 AROS_UFH3(static LONG
, __startup_entry
,
56 AROS_UFHA(char *,argstr
,A0
),
57 AROS_UFHA(ULONG
,argsize
,D0
),
58 AROS_UFHA(struct ExecBase
*,sysbase
,A6
)
63 struct Process
*myproc
;
68 No one program will be able to do anything useful without the dos.library,
69 so we open it here instead of using the automatic opening system
71 DOSBase
= (struct DosLibrary
*)OpenLibrary(DOSNAME
, 39);
72 if (!DOSBase
) return RETURN_FAIL
;
77 myproc
= (struct Process
*)FindTask(NULL
);
79 GetIntETask(myproc
)->iet_startup
= &__aros_startup
;
81 /* Do we have a CLI structure? */
84 /* Workbench startup. Get WBenchMsg and pass it to main() */
86 WaitPort(&myproc
->pr_MsgPort
);
87 WBenchMsg
= (struct WBStartup
*)GetMsg(&myproc
->pr_MsgPort
);
88 __argv
= (char **) WBenchMsg
;
92 __aros_startup
.as_startup_error
= RETURN_FAIL
;
94 if (set_open_libraries())
98 setjmp(__aros_startup
.as_startup_jmp_buf
) == 0 &&
99 set_call_funcs(SETNAME(INIT
), 1, 1)
102 /* ctors/dtors get called in inverse order than init funcs */
103 set_call_funcs(SETNAME(CTORS
), -1, 0);
105 /* Invoke the main function. A weak symbol is used as function name so that
106 it can be overridden (for *nix stuff, for instance). */
107 __aros_startup
.as_startup_error
= (*__main_function_ptr
) (__argc
, __argv
);
109 set_call_funcs(SETNAME(DTORS
), 1, 0);
111 set_call_funcs(SETNAME(EXIT
), -1, 0);
113 set_close_libraries();
116 /* Reply startup message to Workbench */
119 Forbid(); /* make sure we're not UnLoadseg()ed before we're really done */
120 ReplyMsg((struct Message
*) WBenchMsg
);
123 CloseLibrary((struct Library
*)DOSBase
);
125 return __aros_startup
.as_startup_error
;
130 /* if the programmer hasn't defined a symbol with the name __nocommandline
131 then the code to handle the commandline will be included from the autoinit.lib
133 extern int __nocommandline
;
134 asm(".set __importcommandline, __nocommandline");
136 /* pass these values to the command line handling function */
140 /* the command line handling functions will pass these values back to us */
144 struct ExecBase
*SysBase
;
145 struct DosLibrary
*DOSBase
;
146 struct WBStartup
*WBenchMsg
;
152 DEFINESET(PROGRAM_ENTRIES
);
153 ADD2SET(__startup_entry
, program_entries
, 0);
157 Stub function for GCC __main().
159 The __main() function is originally used for C++ style constructors
160 and destructors in C. This replacement does nothing and gets rid of
161 linker-errors about references to __main().
163 #ifdef AROS_NEEDS___MAIN