added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / arch / all-unix / dos / boot.c
blobffd14f5b4d9d6d26d690bb831fb66da78ae70ad8
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 /* We have been created as a process by DOS, we should now
45 try and boot the system. We do this by calling the submain()
46 function in arosshell.c
48 DOS has created our process, but it has not given us
49 the correct I/O Streams yet. What we have to do is
50 to (conditionally) close the old streams, and set
51 our own, which we get from emul.handler.
53 This is really only necessary if
54 a) We want to use the XTerm as our boot shell
55 b) Don't have a working console.device/CON: handler.
58 AROS_USERFUNC_INIT
60 struct DosLibrary *DOSBase;
61 struct emulbase *emulbase;
62 struct TagItem fhtags[]= { { TAG_END, 0 } };
63 struct FileHandle *fh_stdin, *fh_stdout;
65 DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 0);
66 if( DOSBase == NULL )
68 /* BootStrap couldn't open dos.library */
69 Alert(AT_DeadEnd | AN_BootStrap | AG_OpenLib | AO_DOSLib );
73 This is quite naughty, but I know what I'm doing here, since
74 emul.handler ALWAYS exists under Unix, and it won't go away.
76 Forbid();
77 emulbase = (struct emulbase *)FindName(&SysBase->DeviceList, "emul.handler");
78 Permit();
80 if( emulbase == NULL )
82 /* BootStrap couldn't open unknown */
83 Alert(AT_DeadEnd | AN_BootStrap | AG_OpenDev | AO_Unknown );
86 fh_stdin = AllocDosObject(DOS_FILEHANDLE, fhtags);
87 fh_stdout = AllocDosObject(DOS_FILEHANDLE, fhtags);
89 if(fh_stdin == NULL || fh_stdout == NULL)
91 /* We have got some problems here. */
92 Alert(AT_DeadEnd | AN_BootStrap | AG_NoMemory);
95 fh_stdin->fh_Device =&emulbase->eb_device;
96 fh_stdin->fh_Unit =emulbase->eb_stdin;
97 fh_stdout->fh_Device =&emulbase->eb_device;
98 fh_stdout->fh_Unit =emulbase->eb_stdout;
100 if(Input())
101 Close(Input());
102 if(Output())
103 Close(Output());
105 SelectInput(MKBADDR(fh_stdin));
106 SelectOutput(MKBADDR(fh_stdout));
107 ((struct Process *)FindTask(NULL))->pr_CES = MKBADDR(fh_stdout);
109 AROSSupportBase_SetStdOut (stderr);
111 submain(SysBase, DOSBase);
113 /* submain() returns, when the Boot Shell Window is left with EndShell/EndCli */
115 /* To avoid that the input/output/error handles of emul.handler
116 are closed when the Boot Process dies, we set the in/out/err
117 handles of this process to 0.
120 SelectInput(0);
121 SelectOutput(0);
122 ((struct Process *)FindTask(NULL))->pr_CES = 0;
124 /* No RemTask() here, otherwise the process cleanup routines
125 are not called. And that would for example mean, that the
126 Boot Process (having a CLI) is not removed from the rootnode.
127 --> Dead stuff in there -> Crash
130 AROS_USERFUNC_EXIT