added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / arch / .unmaintained / arm-all / dos / boot.c
blob0af8673f1fd7557c4072cfeeaeb4eed77a9a7c7f
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 struct DosLibrary *DOSBase;
59 // struct emulbase *emulbase;
60 // struct TagItem fhtags[]= { { TAG_END, 0 } };
61 // struct FileHandle *fh_stdin, *fh_stdout;
63 DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 0);
64 if( DOSBase == NULL )
66 /* BootStrap couldn't open dos.library */
67 Alert(AT_DeadEnd | AN_BootStrap | AG_OpenLib | AO_DOSLib );
71 This is quite naughty, but I know what I'm doing here, since
72 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 )
83 /* BootStrap couldn't open unknown */
85 Alert(AT_DeadEnd | AN_BootStrap | AG_OpenDev | AO_Unknown );
88 fh_stdin = AllocDosObject(DOS_FILEHANDLE, fhtags);
89 fh_stdout = AllocDosObject(DOS_FILEHANDLE, fhtags);
91 if(fh_stdin == NULL || fh_stdout == NULL)
94 /* We have got some problems here. */
95 /* Alert(AT_DeadEnd | AN_BootStrap | AG_NoMemory);
98 fh_stdin->fh_Device =&emulbase->eb_device;
99 fh_stdin->fh_Unit =emulbase->eb_stdin;
100 fh_stdout->fh_Device =&emulbase->eb_device;
101 fh_stdout->fh_Unit =emulbase->eb_stdout;
103 if(Input())
104 Close(Input());
105 if(Output())
106 Close(Output());
108 SelectInput(MKBADDR(fh_stdin));
109 SelectOutput(MKBADDR(fh_stdout));
110 ((struct Process *)FindTask(NULL))->pr_CES = MKBADDR(fh_stdout);
112 AROSSupportBase_SetStdOut (stderr);
114 submain(SysBase, DOSBase);
116 /* submain() returns, when the Boot Shell Window is left with EndShell/EndCli */
118 /* To avoid that the input/output/error handles of emul.handler
119 are closed when the Boot Process dies, we set the in/out/err
120 handles of this process to 0.
124 SelectInput(0);
125 SelectOutput(0);
126 ((struct Process *)FindTask(NULL))->pr_CES = 0;
129 /* No RemTask() here, otherwise the process cleanup routines
130 are not called. And that would for example mean, that the
131 Boot Process (having a CLI) is not removed from the rootnode.
132 --> Dead stuff in there -> Crash