Updated PCI IDs to latest snapshot.
[tangerine.git] / arch / all-hosted / dosboot / boot.c
blobefd7bd594970169b3058d272f620615a7ff196ac
1 /*
2 Copyright 1995-2001, The AROS Development Team. All rights reserved.
3 $Id: boot.c 29897 2008-10-27 09:27:10Z sonic $
5 Desc: Boot your operating system.
6 Lang: english
7 */
8 #define DEBUG 0
10 #include <exec/types.h>
11 #include <exec/alerts.h>
12 #include <exec/libraries.h>
13 #include <exec/devices.h>
14 #include <exec/execbase.h>
15 #include <aros/libcall.h>
16 #include <aros/asmcall.h>
17 #include <dos/dosextens.h>
18 #include <dos/filesystem.h>
19 #include <dos/stdio.h>
20 #include <libraries/expansionbase.h>
21 #include <utility/tagitem.h>
22 #include <aros/arossupportbase.h>
23 #include <aros/debug.h>
25 #include <proto/exec.h>
26 #include <proto/dos.h>
28 struct emulbase
30 struct Device eb_device;
31 APTR eb_stdin;
32 APTR eb_stdout;
33 APTR eb_stderr;
36 void __dosboot_Boot(struct ExecBase *SysBase, BOOL hidds_ok)
38 /* We have been created as a process by DOS, we should now
39 try and boot the system. We do this by calling the submain()
40 function in arosshell.c
42 DOS has created our process, but it has not given us
43 the correct I/O Streams yet. What we have to do is
44 to (conditionally) close the old streams, and set
45 our own, which we get from emul.handler.
47 This is really only necessary if
48 a) We want to use the host console as our boot shell
49 b) Don't have a working console.device/CON: handler.
52 struct DosLibrary *DOSBase;
53 struct emulbase *emulbase;
54 struct TagItem fhtags[]= { { TAG_END, 0 } };
55 struct FileHandle *fh_stdin, *fh_stdout;
56 struct TagItem tags[] =
58 { SYS_Asynch, TRUE }, /* 0 */
59 { SYS_Background, FALSE }, /* 1 */
60 { SYS_ScriptInput, 0 }, /* 2 */
61 { SYS_Input, 0 }, /* 3 */
62 { SYS_Output, 0 }, /* 4 */
63 { SYS_Error, 0 }, /* 5 */
64 { TAG_DONE, 0 }
66 BPTR cis = NULL;
67 BPTR sseq = NULL;
68 LONG rc = RETURN_FAIL;
70 D(bug("[DOSBoot.hosted] __dosboot_Boot()\n"));
72 DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 0);
73 if( DOSBase == NULL )
75 /* BootStrap couldn't open dos.library */
76 Alert(AT_DeadEnd | AN_BootStrap | AG_OpenLib | AO_DOSLib );
80 This is quite naughty, but I know what I'm doing here, since
81 emul.handler ALWAYS exists under Unix, and it won't go away.
83 Forbid();
84 emulbase = (struct emulbase *)FindName(&SysBase->DeviceList, "emul.handler");
85 Permit();
86 D(bug("[DOSBoot.hosted] __dosboot_Boot: emulbase = 0x%08lX\n", emulbase));
88 if( emulbase == NULL )
90 /* BootStrap couldn't open unknown */
91 Alert(AT_DeadEnd | AN_BootStrap | AG_OpenDev | AO_Unknown );
94 fh_stdin = AllocDosObject(DOS_FILEHANDLE, fhtags);
95 fh_stdout = AllocDosObject(DOS_FILEHANDLE, fhtags);
97 if(fh_stdin == NULL || fh_stdout == NULL)
99 /* We have got some problems here. */
100 Alert(AT_DeadEnd | AN_BootStrap | AG_NoMemory);
103 fh_stdin->fh_Device =&emulbase->eb_device;
104 fh_stdin->fh_Unit =emulbase->eb_stdin;
105 fh_stdout->fh_Device =&emulbase->eb_device;
106 fh_stdout->fh_Unit =emulbase->eb_stdout;
107 SetVBuf(fh_stdin, NULL, BUF_LINE, -1);
108 SetVBuf(fh_stdout, NULL, BUF_LINE, -1);
110 if(Input())
111 Close(Input());
112 if(Output())
113 Close(Output());
115 D(bug("[DOSBoot.hosted] __dosboot_Boot: Selecting input and output for DOS\n"));
116 SelectInput(MKBADDR(fh_stdin));
117 SelectOutput(MKBADDR(fh_stdout));
118 SelectError(MKBADDR(fh_stdout));
120 D(bug("[DOSBoot.hosted] __dosboot_Boot: Selecting output for AROSSupport\n"));
121 ((struct AROSSupportBase *)(SysBase->DebugAROSBase))->StdOut = fh_stdout;
123 if (hidds_ok) {
124 D(bug("[DOSBoot.hosted] __dosboot_Boot: Opening boot shell\n"));
125 cis = Open("CON:20/20///Boot Shell/AUTO", FMF_READ);
126 } else
127 PutStr("Failed to load system HIDDs\n");
128 if (cis)
130 struct ExpansionBase *ExpansionBase;
131 BOOL opensseq = TRUE;
133 D(bug("[DOSBoot.hosted] __dosboot_Boot: Boot shell opened\n"));
134 if ((ExpansionBase = (struct ExpansionBase *)OpenLibrary("expansion.library", 0)) != NULL)
136 opensseq = !(ExpansionBase->Flags & EBF_DOSFLAG);
137 CloseLibrary((struct Library *)ExpansionBase);
140 D(bug("[DOSBoot.hosted] __dosboot_Boot: Open Startup Sequence = %d\n", opensseq));
142 if (opensseq)
144 sseq = Open("S:Startup-Sequence", FMF_READ);
145 tags[2].ti_Data = (IPTR)sseq;
147 tags[3].ti_Data = (IPTR)cis;
148 } else {
149 tags[3].ti_Tag = TAG_DONE;
150 PutStr("Entering emergency shell\n");
152 rc = SystemTagList("", tags);
153 if (rc != -1)
155 cis = NULL;
156 sseq = NULL;
158 else {
159 PutStr("Cannot open boot console\n");
160 rc = RETURN_FAIL;
162 if (sseq)
163 Close(sseq);
164 if (cis)
165 Close(cis);
167 /* We get here when the Boot Shell Window is left with EndShell/EndCli.
168 To avoid that the input/output/error handles of emul.handler
169 are closed when the Boot Process dies, we set the in/out/err
170 handles of this process to 0.
173 SelectInput(0);
174 SelectOutput(0);
175 ((struct Process *)FindTask(NULL))->pr_CES = 0;
177 /* No RemTask() here, otherwise the process cleanup routines
178 are not called. And that would for example mean, that the
179 Boot Process (having a CLI) is not removed from the rootnode.
180 --> Dead stuff in there -> Crash