2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Common startup code
8 #include <aros/config.h>
11 #include <exec/memory.h>
12 #include <workbench/startup.h>
13 #include <proto/exec.h>
14 #include <proto/dos.h>
15 #include <aros/asmcall.h>
16 #include <aros/debug.h>
17 #include <aros/symbolsets.h>
19 #if (AROS_FLAVOUR & AROS_FLAVOUR_NATIVE)
28 /* Don't define symbols before the entry point. */
29 extern struct ExecBase
* SysBase
;
30 extern struct WBStartup
*WBenchMsg
;
31 extern int main (int argc
, char ** argv
);
33 extern jmp_buf __startup_jmp_buf
;
34 extern LONG __startup_error
;
41 This won't work for normal AmigaOS because you can't expect SysBase to be
42 in A6. The correct way is to use *(struct ExecBase **)4 and because gcc
43 emits strings for a certain function _before_ the code the program will
44 crash immediately because the first element in the code won't be valid
47 970314 ldp: It will now work because of the asm-stub above.
51 extern char *__argstr
;
52 extern ULONG __argsize
;
56 #warning TODO: reset and initialize the FPU
57 #warning TODO: resident startup
58 AROS_UFH3(LONG
, entry
,
59 AROS_UFHA(char *,argstr
,A0
),
60 AROS_UFHA(ULONG
,argsize
,D0
),
61 AROS_UFHA(struct ExecBase
*,sysbase
,A6
)
64 struct Process
*myproc
;
69 SysBase
= *(struct ExecBase
**)4UL;
73 myproc
= (struct Process
*)FindTask(NULL
);
75 /* Do we have a CLI structure? */
78 /* Workbench startup. Get WBenchMsg and pass it to main() */
80 WaitPort(&myproc
->pr_MsgPort
);
81 WBenchMsg
= (struct WBStartup
*)GetMsg(&myproc
->pr_MsgPort
);
82 __argv
= (char **)WBenchMsg
;
87 !(__startup_error
= set_open_libraries(SETNAME(LIBS
))) &&
88 !(__startup_error
= set_call_funcs(SETNAME(INIT
), 1))
92 if (!setjmp(__startup_jmp_buf
))
93 __startup_error
= main (__argc
, __argv
);
97 set_call_funcs(SETNAME(EXIT
), -1);
98 set_close_libraries(SETNAME(LIBS
));
100 /* Reply startup message to Workbench.
101 * We Forbid() to avoid being UnLoadSeg()ed before we're really finished.
106 ReplyMsg((struct Message
*)WBenchMsg
);
109 return __startup_error
;
112 /* if the programmer hasn't defined a symbol with the name __nocommandline
113 then the code to handle the commandline will be included from the autoinit.lib
115 extern void __nocommandline(void);
116 static void (*__importcommandline
) = &__nocommandline
;
118 /* pass these values to the command line handling function */
122 /* the command line handling functions will pass these values back to us */
126 struct ExecBase
*SysBase
;
127 struct WBStartup
*WBenchMsg
;
128 jmp_buf __startup_jmp_buf
;
129 LONG __startup_error
;
135 /* Stub function for GCC __main().
137 The __main() function is originally used for C++ style constructors
138 and destructors in C. This replacement does nothing and gets rid of
139 linker-errors about references to __main().