graphics.library: Fix ReadPixel() on BE machines.
[AROS.git] / compiler / startup / startup.c
blobd23d7aad9578083cfbcc120523e6b7caff96b3ec
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/libcall.h>
19 #include <aros/debug.h>
20 #include <aros/symbolsets.h>
21 #include <aros/startup.h>
23 THIS_PROGRAM_HANDLES_SYMBOLSETS
25 struct ExecBase *SysBase;
26 struct DosLibrary *DOSBase;
28 extern int main(int argc, char ** argv);
29 int (*__main_function_ptr)(int argc, char ** argv) __attribute__((__weak__)) = main;
31 /* if the programmer hasn't defined a symbol with the name __nocommandline
32 then the code to handle the commandline will be included from the autoinit.lib
34 extern int __nocommandline;
35 asm(".set __importcommandline, __nocommandline");
37 /* if the programmer hasn't defined a symbol with the name __nostdiowin
38 then the code to open a window for stdio will be included from the autoinit.lib
40 extern int __nostdiowin;
41 asm(".set __importstdiowin, __nostdiowin");
43 /* if the programmer hasn't defined a symbol with the name __nowbsupport
44 then the code to handle support for programs started from WB will be included from
45 the autoinit.lib
47 extern int __nowbsupport;
48 asm(".set __importnowbsupport, __nowbsupport");
50 /* if the programmer hasn't defined a symbol with the name __noinitexitsets
51 then the code to handle support for calling the INIT, EXIT symbolset functions
52 and the autoopening of libraries is called from the autoinit.lib
54 extern int __noinitexitsets;
55 asm(".set __importnoinitexitsets, __noinitexitsets");
57 extern void __startup_entries_init(void);
59 /* Guarantee that __startup_entry is placed at the beginning of the binary */
60 #if (AROS_FLAVOUR & AROS_FLAVOUR_BINCOMPAT)
61 /* On AmigaOS, A6 is *not* SysBase on entry. */
62 AROS_UFP2(LONG, __startup_entry,
63 AROS_UFHA(char *,argstr,A0),
64 AROS_UFHA(ULONG,argsize,D0)
65 ) __attribute__((section(".aros.startup")));
67 AROS_UFH2(LONG, __startup_entry,
68 AROS_UFHA(char *,argstr,A0),
69 AROS_UFHA(ULONG,argsize,D0)
72 AROS_USERFUNC_INIT
74 struct ExecBase *sysbase = *((APTR *)4);
75 #else
76 AROS_UFP3(LONG, __startup_entry,
77 AROS_UFHA(char *,argstr,A0),
78 AROS_UFHA(ULONG,argsize,D0),
79 AROS_UFHA(struct ExecBase *,sysbase,A6)
80 ) __attribute__((section(".aros.startup")));
82 /* TODO: reset and initialize the FPU */
83 /* TODO: resident startup */
84 AROS_UFH3(LONG, __startup_entry,
85 AROS_UFHA(char *,argstr,A0),
86 AROS_UFHA(ULONG,argsize,D0),
87 AROS_UFHA(struct ExecBase *,sysbase,A6)
90 AROS_USERFUNC_INIT
91 #endif
93 SysBase = sysbase;
95 D(bug("Entering __startup_entry(\"%s\", %d, %x)\n", argstr, argsize, SysBase));
98 No one program will be able to do anything useful without the dos.library,
99 so we open it here instead of using the automatic opening system
101 DOSBase = (struct DosLibrary *)OpenLibrary(DOSNAME, 39);
102 if (!DOSBase) return RETURN_FAIL;
104 __argstr = argstr;
105 __argsize = argsize;
106 __startup_error = RETURN_FAIL;
108 __startup_entries_init();
109 __startup_entries_next();
111 CloseLibrary((struct Library *)DOSBase);
113 D(bug("Leaving __startup_entry\n"));
115 return __startup_error;
117 AROS_USERFUNC_EXIT
118 } /* entry */
121 static void __startup_main(void)
123 D(bug("Entering __startup_main\n"));
125 /* Invoke the main function. A weak symbol is used as function name so that
126 it can be overridden (for *nix stuff, for instance). */
127 __startup_error = (*__main_function_ptr) (__argc, __argv);
129 D(bug("Leaving __startup_main\n"));
132 ADD2SET(__startup_main, program_entries, 127);
136 Stub function for GCC __main().
138 The __main() function is originally used for C++ style constructors
139 and destructors in C. This replacement does nothing and gets rid of
140 linker-errors about references to __main().
142 #ifdef AROS_NEEDS___MAIN
143 void __main(void)
145 /* Do nothing. */
147 #endif