- Set a default PCM volume so that something can be heard when driver is
[AROS.git] / compiler / startup / startup.c
blobc686bf24ae943a24392ce09b1c25f96412c0ccc4
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/debug.h>
19 #include <aros/symbolsets.h>
20 #include <aros/startup.h>
22 THIS_PROGRAM_HANDLES_SYMBOLSETS
24 struct ExecBase *SysBase;
25 struct DosLibrary *DOSBase;
27 extern int main(int argc, char ** argv);
28 int (*__main_function_ptr)(int argc, char ** argv) __attribute__((__weak__)) = main;
30 /* if the programmer hasn't defined a symbol with the name __nocommandline
31 then the code to handle the commandline will be included from the autoinit.lib
33 extern int __nocommandline;
34 asm(".set __importcommandline, __nocommandline");
36 /* if the programmer hasn't defined a symbol with the name __nostdiowin
37 then the code to open a window for stdio will be included from the autoinit.lib
39 extern int __nostdiowin;
40 asm(".set __importstdiowin, __nostdiowin");
42 /* if the programmer hasn't defined a symbol with the name __nowbsupport
43 then the code to handle support for programs started from WB will be included from
44 the autoinit.lib
46 extern int __nowbsupport;
47 asm(".set __importnowbsupport, __nowbsupport");
49 /* if the programmer hasn't defined a symbol with the name __noinitexitsets
50 then the code to handle support for calling the INIT, EXIT symbolset functions
51 and the autoopening of libraries is called from the autoinit.lib
53 extern int __noinitexitsets;
54 asm(".set __importnoinitexitsets, __noinitexitsets");
56 extern void __startup_entries_init(void);
58 /* Guarantee that __startup_entry is placed at the beginning of the binary */
59 #if (AROS_FLAVOUR & AROS_FLAVOUR_BINCOMPAT)
60 /* On AmigaOS, A6 is *not* SysBase on entry. */
61 AROS_UFP2(LONG, __startup_entry,
62 AROS_UFHA(char *,argstr,A0),
63 AROS_UFHA(ULONG,argsize,D0)
64 ) __attribute__((section(".aros.startup")));
66 AROS_UFH2(LONG, __startup_entry,
67 AROS_UFHA(char *,argstr,A0),
68 AROS_UFHA(ULONG,argsize,D0)
71 AROS_USERFUNC_INIT
73 struct ExecBase *sysbase = *((APTR *)4);
74 #else
75 AROS_UFP3(LONG, __startup_entry,
76 AROS_UFHA(char *,argstr,A0),
77 AROS_UFHA(ULONG,argsize,D0),
78 AROS_UFHA(struct ExecBase *,sysbase,A6)
79 ) __attribute__((section(".aros.startup")));
81 /* TODO: reset and initialize the FPU */
82 /* TODO: resident startup */
83 AROS_UFH3(LONG, __startup_entry,
84 AROS_UFHA(char *,argstr,A0),
85 AROS_UFHA(ULONG,argsize,D0),
86 AROS_UFHA(struct ExecBase *,sysbase,A6)
89 AROS_USERFUNC_INIT
90 #endif
92 SysBase = sysbase;
94 D(bug("Entering __startup_entry(\"%s\", %d, %x)\n", argstr, argsize, SysBase));
97 No one program will be able to do anything useful without the dos.library,
98 so we open it here instead of using the automatic opening system
100 DOSBase = (struct DosLibrary *)OpenLibrary(DOSNAME, 39);
101 if (!DOSBase) return RETURN_FAIL;
103 __argstr = argstr;
104 __argsize = argsize;
105 __startup_error = RETURN_FAIL;
107 __startup_entries_init();
108 __startup_entries_next();
110 CloseLibrary((struct Library *)DOSBase);
112 D(bug("Leaving __startup_entry\n"));
114 return __startup_error;
116 AROS_USERFUNC_EXIT
117 } /* entry */
120 static void __startup_main(void)
122 D(bug("Entering __startup_main\n"));
124 /* Invoke the main function. A weak symbol is used as function name so that
125 it can be overridden (for *nix stuff, for instance). */
126 __startup_error = (*__main_function_ptr) (__argc, __argv);
128 D(bug("Leaving __startup_main\n"));
131 ADD2SET(__startup_main, program_entries, 127);
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().
141 #ifdef AROS_NEEDS___MAIN
142 void __main(void)
144 /* Do nothing. */
146 #endif