revert between 56095 -> 55830 in arch
[AROS.git] / rom / dos / boot.c
blob2cf5a457e3d1d74122e2192038627bc52ca667cc
1 /*
2 Copyright © 1995-2019, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Implements AROS's generic/amiga-like boot sequence.
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"
25 #include "../dosboot/bootflags.h"
27 #ifdef __mc68000
29 * Load DEVS:system-configuration only on m68k.
30 * Setup pre-2.0 boot disk colors and mouse cursors (for example)
32 #define USE_SYSTEM_CONFIGURATION
34 #endif
36 #ifdef USE_SYSTEM_CONFIGURATION
38 #include <proto/intuition.h>
40 static void load_system_configuration(struct DosLibrary *DOSBase)
42 BPTR fh;
43 ULONG len;
44 struct Preferences prefs;
45 struct Library *IntuitionBase;
47 fh = Open("DEVS:system-configuration", MODE_OLDFILE);
48 if (!fh)
49 return;
50 len = Read(fh, &prefs, sizeof prefs);
51 Close(fh);
52 if (len != sizeof prefs)
53 return;
54 IntuitionBase = TaggedOpenLibrary(TAGGEDOPEN_INTUITION);
55 if (IntuitionBase)
56 SetPrefs(&prefs, len, FALSE);
57 CloseLibrary(IntuitionBase);
60 #else
62 #define load_system_configuration(DOSBase) do { } while (0)
64 #endif
66 extern void BCPL_cliInit(void);
68 void __dos_Boot(struct DosLibrary *DOSBase, ULONG BootFlags, UBYTE Flags)
70 BPTR cis = BNULL;
72 /* We have been created as a process by DOS, we should now
73 try and boot the system. */
76 bug("[DOS] %s: ** starting generic boot sequence\n", __func__);
77 bug("[DOS] %s: BootFlags 0x%08X Flags 0x%02X\n", __func__, BootFlags, Flags);
78 bug("[DOS] %s: DOSBase @ 0x%p\n", __func__, DOSBase);
81 /* m68000 uses this to get the default colors and
82 * cursors for Workbench
84 load_system_configuration(DOSBase);
86 D(bug("[DOS] %s: system config loaded\n", __func__);)
89 * If needed, run the display drivers loader.
90 * In fact the system must have at least one resident driver,
91 * which will be used for bootmenu etc. However, it we somehow happen
92 * not to have it, this will be our last chance.
94 if ((BootFlags & (BF_NO_DISPLAY_DRIVERS | BF_NO_COMPOSITION)) != (BF_NO_DISPLAY_DRIVERS | BF_NO_COMPOSITION))
96 /* Check that it exists first... */
97 BPTR seg;
99 D(bug("[DOS] %s: initialising displays\n", __func__);)
101 if ((seg = LoadSeg("C:AROSMonDrvs")) != BNULL)
103 STRPTR args = "";
104 BPTR oldin, oldout;
107 * Argument strings MUST contain terminating LF because of ReadItem() bugs.
108 * Their absence causes ReadArgs() crash.
110 if (BootFlags & BF_NO_COMPOSITION)
111 args = "NOCOMPOSITION\n";
112 else if (BootFlags & BF_NO_DISPLAY_DRIVERS)
113 args = "ONLYCOMPOSITION\n";
115 D(bug("[DOS] %s: Running AROSMonDrvs %s\n", __func__, args);)
117 /* RunCommand needs a valid Input() handle
118 * for passing in its arguments.
120 oldin = SelectInput(Open("NIL:", MODE_OLDFILE));
121 oldout= SelectOutput(Open("NIL:", MODE_NEWFILE));
122 RunCommand(seg, AROS_STACKSIZE, args, strlen(args));
123 SelectInput(oldin);
124 SelectOutput(oldout);
126 /* We don't care about the return code */
127 UnLoadSeg(seg);
131 D(bug("[DOS] %s: preparing console\n", __func__);)
133 if (BootFlags & BF_EMERGENCY_CONSOLE) {
134 D(bug("[DOS] %s: (emergency console)\n", __func__);)
135 BootFlags |= BF_NO_STARTUP_SEQUENCE;
136 cis = Open("ECON:", MODE_OLDFILE);
139 if (cis == BNULL)
140 cis = Open("CON:////AROS/AUTO/CLOSE/SMART/BOOT", MODE_OLDFILE);
142 if (cis) {
143 BPTR cos = OpenFromLock(DupLockFromFH(cis));
144 BYTE const C[] = "Copyright © 1995-2019, The AROS Development Team.\n"
145 "Licensed under the AROS Public License.\n"
146 #if defined(REPOTYPE)
147 "Version " REPOTYPE "" REPOREVISION
148 #if defined(REPOID)
149 " (" REPOID ")"
150 #endif
151 "\n"
152 #endif
153 "built on " ISODATE ".\n";
155 D(bug("[DOS] %s: handle @ 0x%p (0x%p)\n", __func__, cis, cos);)
157 if (cos) {
158 BPTR cas = BNULL;
160 if (!(BootFlags & BF_NO_STARTUP_SEQUENCE))
161 cas = Open("S:Startup-Sequence", MODE_OLDFILE);
163 /* Inject the banner */
164 if (Flags & EBF_SILENTSTART) {
165 if (SetVBuf(cos, NULL, BUF_FULL, sizeof(C)) == 0) {
166 FPuts(cos, C);
167 SetVBuf(cos, NULL, BUF_LINE, -1);
169 } else {
170 FPuts(cos, C);
173 D(bug("[DOS] %s: initialising CLI\n", __func__);)
175 if (SystemTags(NULL,
176 NP_Name, "Initial CLI",
177 SYS_Background, FALSE,
178 SYS_Asynch, FALSE,
179 SYS_Input, cis,
180 SYS_Output, cos,
181 SYS_ScriptInput, cas,
182 TAG_END) == -1) {
183 D(bug("[DOS] %s: .. failed!\n", __func__);)
184 Alert(AT_DeadEnd | AN_BootStrap);
187 Close(cis);
188 #if (1)
189 /* Do not flush cos (show banner) if we got this far, we don't want to
190 * see shell window quickly opening and then immediately closing at
191 * the end of startup-sequence.
193 * There has to be less hacky way..
195 struct FileHandle *fh = ((struct FileHandle*)BADDR(cos));
196 fh->fh_Flags &= ~0x80000000;
197 #endif
198 Close(cos);
199 /* NOTE: 'cas' will already have been closed by the Shell */
201 } else {
202 D(bug("[DOS] %s: .. failed!\n", __func__);)
203 Alert(AN_NoWindow);