Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / arch / i386-pc / alib / startup.c
blobbf8f8e483016382b0fedb91035d035c86723fbf2
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Common startup code
6 Lang: english
7 */
8 #include <aros/config.h>
9 #include <setjmp.h>
10 #include <dos/dos.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)
20 asm("
21 .text
23 move.l 4.w,a6
24 jra _entry(pc)
25 ");
26 #endif
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;
36 DECLARESET(INIT);
37 DECLARESET(EXIT);
38 DECLARESET(LIBS);
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
45 assembler code.
47 970314 ldp: It will now work because of the asm-stub above.
51 extern char *__argstr;
52 extern ULONG __argsize;
53 extern char **__argv;
54 extern int __argc;
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;
66 __argstr = argstr;
67 __argsize = argsize;
69 SysBase = *(struct ExecBase**)4UL;
71 asm("finit");
73 myproc = (struct Process *)FindTask(NULL);
75 /* Do we have a CLI structure? */
76 if (!myproc->pr_CLI)
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))
91 /* Invoke main() */
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.
103 if (WBenchMsg)
105 Forbid();
106 ReplyMsg((struct Message *)WBenchMsg);
109 return __startup_error;
110 } /* entry */
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 */
119 char *__argstr;
120 ULONG __argsize;
122 /* the command line handling functions will pass these values back to us */
123 char **__argv;
124 int __argc;
126 struct ExecBase *SysBase;
127 struct WBStartup *WBenchMsg;
128 jmp_buf __startup_jmp_buf;
129 LONG __startup_error;
131 DEFINESET(INIT);
132 DEFINESET(EXIT);
133 DEFINESET(LIBS);
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().
142 void __main(void)
144 /* Do nothing. */