- Made some fields used only by packet handlers type-compatible with AmigaOS.
[tangerine.git] / arch / i386-pc / dos / boot.c
blobe399c480fba9be337e77bdfeeaa2c0de933890fa
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Boot your operating system.
6 Lang: english
7 */
9 #include <exec/types.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 <utility/tagitem.h>
18 #include <aros/arossupportbase.h>
19 #include <aros/debug.h>
21 #include <proto/exec.h>
22 #include <proto/dos.h>
24 /* Require this for the stdout defn */
25 #include <stdio.h>
27 extern void AROSSupportBase_SetStdOut (void *);
28 extern int submain(struct ExecBase *, struct DosLibrary *);
30 struct emulbase
32 struct Device eb_device;
33 struct Unit *eb_stdin;
34 struct Unit *eb_stdout;
35 struct Unit *eb_stderr;
38 AROS_UFH3(void, boot,
39 AROS_UFHA(STRPTR, argString, A0),
40 AROS_UFHA(ULONG, argSize, D0),
41 AROS_UFHA(struct ExecBase *, SysBase, A6)
44 AROS_USERFUNC_INIT
45 /* We have been created as a process by DOS, we should now
46 try and boot the system. We do this by calling the submain()
47 function in arosshell.c
49 DOS has created our process, but it has not given us
50 the correct I/O Streams yet. What we have to do is
51 to (conditionally) close the old streams, and set
52 our own, which we get from emul.handler.
54 This is really only necessary if
55 a) We want to use the XTerm as our boot shell
56 b) Don't have a working console.device/CON: handler.
59 struct DosLibrary *DOSBase;
60 // struct emulbase *emulbase;
61 struct TagItem fhtags[]= { { TAG_END, 0 } };
62 // struct FileHandle *fh_stdin, *fh_stdout;
64 DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 0);
65 if( DOSBase == NULL )
67 /* BootStrap couldn't open dos.library */
68 Alert(AT_DeadEnd | AN_BootStrap | AG_OpenLib | AO_DOSLib );
72 This is quite naughty, but I know what I'm doing here, since
73 emul.handler ALWAYS exists under Unix, and it won't go away.
77 Forbid();
78 emulbase = (struct emulbase *)FindName(&SysBase->DeviceList, "emul.handler");
79 Permit();
81 if( emulbase == NULL )
84 /* BootStrap couldn't open unknown */
86 Alert(AT_DeadEnd | AN_BootStrap | AG_OpenDev | AO_Unknown );
89 fh_stdin = AllocDosObject(DOS_FILEHANDLE, fhtags);
90 fh_stdout = AllocDosObject(DOS_FILEHANDLE, fhtags);
92 if(fh_stdin == NULL || fh_stdout == NULL)
95 /* We have got some problems here. */
96 /* Alert(AT_DeadEnd | AN_BootStrap | AG_NoMemory);
99 fh_stdin->fh_Device =&emulbase->eb_device;
100 fh_stdin->fh_Unit =emulbase->eb_stdin;
101 fh_stdout->fh_Device =&emulbase->eb_device;
102 fh_stdout->fh_Unit =emulbase->eb_stdout;
104 if(Input())
105 Close(Input());
106 if(Output())
107 Close(Output());
109 SelectInput(MKBADDR(fh_stdin));
110 SelectOutput(MKBADDR(fh_stdout));
111 ((struct Process *)FindTask(NULL))->pr_CES = MKBADDR(fh_stdout);
113 AROSSupportBase_SetStdOut (stderr);
115 submain(SysBase, DOSBase);
117 /* submain() returns, when the Boot Shell Window is left with EndShell/EndCli */
119 /* To avoid that the input/output/error handles of emul.handler
120 are closed when the Boot Process dies, we set the in/out/err
121 handles of this process to 0.
125 SelectInput(0);
126 SelectOutput(0);
127 ((struct Process *)FindTask(NULL))->pr_CES = 0;
130 /* No RemTask() here, otherwise the process cleanup routines
131 are not called. And that would for example mean, that the
132 Boot Process (having a CLI) is not removed from the rootnode.
133 --> Dead stuff in there -> Crash
135 return;
136 AROS_USERFUNC_EXIT