Detabbed
[AROS.git] / rom / dos / boot.c
blob62b9c843e2cbc18786b5f12f2f6a86e6ad6298fb
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Boot your operating system.
6 Lang: english
7 */
9 #include <aros/debug.h>
10 #include <exec/alerts.h>
11 #include <exec/libraries.h>
12 #include <exec/devices.h>
13 #include <exec/execbase.h>
14 #include <aros/libcall.h>
15 #include <aros/asmcall.h>
16 #include <dos/dosextens.h>
17 #include <dos/cliinit.h>
18 #include <dos/stdio.h>
19 #include <utility/tagitem.h>
20 #include <libraries/expansionbase.h>
21 #include <proto/exec.h>
22 #include <proto/dos.h>
24 #include "dos_intern.h"
26 #ifdef __mc68000
28 * Load DEVS:system-configuration only on m68k.
29 * Setup pre-2.0 boot disk colors and mouse cursors (for example)
31 #define USE_SYSTEM_CONFIGURATION
33 #endif
35 #ifdef USE_SYSTEM_CONFIGURATION
37 #include <proto/intuition.h>
39 static void load_system_configuration(struct DosLibrary *DOSBase)
41 BPTR fh;
42 ULONG len;
43 struct Preferences prefs;
44 struct Library *IntuitionBase;
46 fh = Open("DEVS:system-configuration", MODE_OLDFILE);
47 if (!fh)
48 return;
49 len = Read(fh, &prefs, sizeof prefs);
50 Close(fh);
51 if (len != sizeof prefs)
52 return;
53 IntuitionBase = TaggedOpenLibrary(TAGGEDOPEN_INTUITION);
54 if (IntuitionBase)
55 SetPrefs(&prefs, len, FALSE);
56 CloseLibrary(IntuitionBase);
59 #else
61 #define load_system_configuration(DOSBase) do { } while (0)
63 #endif
65 extern void BCPL_cliInit(void);
67 void __dos_Boot(struct DosLibrary *DOSBase, ULONG BootFlags, UBYTE Flags)
69 BPTR cis = BNULL;
71 /* We have been created as a process by DOS, we should now
72 try and boot the system. */
74 D(bug("[__dos_Boot] generic boot sequence, BootFlags 0x%08X Flags 0x%02X\n", BootFlags, Flags));
76 /* m68000 uses this to get the default colors and
77 * cursors for Workbench
79 load_system_configuration(DOSBase);
82 * If needed, run the display drivers loader.
83 * In fact the system must have at least one resident driver,
84 * which will be used for bootmenu etc. However, it we somehow happen
85 * not to have it, this will be our last chance.
87 if ((BootFlags & (BF_NO_DISPLAY_DRIVERS | BF_NO_COMPOSITION)) != (BF_NO_DISPLAY_DRIVERS | BF_NO_COMPOSITION))
89 /* Check that it exists first... */
90 BPTR seg = LoadSeg("C:AROSMonDrvs");
92 if (seg != BNULL)
94 STRPTR args = "";
95 BPTR oldin, oldout;
98 * Argument strings MUST contain terminating LF because of ReadItem() bugs.
99 * Their absence causes ReadArgs() crash.
101 if (BootFlags & BF_NO_COMPOSITION)
102 args = "NOCOMPOSITION\n";
103 else if (BootFlags & BF_NO_DISPLAY_DRIVERS)
104 args = "ONLYCOMPOSITION\n";
106 D(bug("[__dos_Boot] Running AROSMonDrvs %s\n", args));
108 /* RunCommand needs a valid Input() handle
109 * for passing in its arguments.
111 oldin = SelectInput(Open("NIL:", MODE_OLDFILE));
112 oldout= SelectOutput(Open("NIL:", MODE_NEWFILE));
113 RunCommand(seg, AROS_STACKSIZE, args, strlen(args));
114 SelectInput(oldin);
115 SelectOutput(oldout);
117 /* We don't care about the return code */
118 UnLoadSeg(seg);
122 if (BootFlags & BF_EMERGENCY_CONSOLE) {
123 BootFlags |= BF_NO_STARTUP_SEQUENCE;
124 cis = Open("ECON:", MODE_OLDFILE);
127 if (cis == BNULL)
128 cis = Open("CON:////AROS/AUTO/CLOSE/SMART", MODE_OLDFILE);
130 if (cis) {
131 BPTR cos = OpenFromLock(DupLockFromFH(cis));
132 BYTE const C[] = "Copyright © 1995-2012, The AROS Development Team.\n"
133 "Licensed under the AROS Public License.\n"
134 "Version SVN" SVNREV ", built on " ISODATE ".\n";
136 if (cos) {
137 BPTR cas = BNULL;
139 if (!(BootFlags & BF_NO_STARTUP_SEQUENCE))
140 cas = Open("S:Startup-Sequence", MODE_OLDFILE);
142 /* Inject the banner */
143 if (Flags & EBF_SILENTSTART) {
144 if (SetVBuf(cos, NULL, BUF_FULL, sizeof(C)) == 0) {
145 FPuts(cos, C);
146 SetVBuf(cos, NULL, BUF_LINE, -1);
148 } else {
149 FPuts(cos, C);
152 if (SystemTags(NULL,
153 NP_Name, "Initial CLI",
154 SYS_Background, FALSE,
155 SYS_Asynch, FALSE,
156 SYS_Input, cis,
157 SYS_Output, cos,
158 SYS_ScriptInput, cas,
159 TAG_END) == -1) {
160 Alert(AT_DeadEnd | AN_BootStrap);
162 Close(cis);
163 { /* Do not flush cos (show banner) if we got this far, we don't want to
164 * see shell window quickly opening and then immediately closing at
165 * the end of startup-sequence.
167 * There has to be less hacky way..
169 struct FileHandle *fh = ((struct FileHandle*)BADDR(cos));
170 fh->fh_Flags &= ~0x80000000;
172 Close(cos);
173 /* NOTE: 'cas' will will already have been closed by the Shell */
175 } else
176 Alert(AN_NoWindow);