2 Copyright 1995-2011, The AROS Development Team. All rights reserved.
5 Desc: Emergency console launcher for hosted AROS
11 #include <aros/asmcall.h>
12 #include <aros/debug.h>
13 #include <dos/dosextens.h>
14 #include <dos/stdio.h>
15 #include <exec/resident.h>
16 #include <graphics/modeid.h>
17 #include <utility/tagitem.h>
18 #include <proto/exec.h>
19 #include <proto/dos.h>
20 #include <proto/graphics.h>
22 #include "emul_intern.h"
24 #include "expansion_intern.h"
25 #include "bootflags.h"
29 static const UBYTE version
[];
30 extern const char emul_End
;
32 AROS_UFP3S(APTR
, EmulBoot
,
33 AROS_UFPA(ULONG
, dummy
, D0
),
34 AROS_UFPA(BPTR
, segList
, A0
),
35 AROS_UFPA(struct ExecBase
*, SysBase
, A6
));
37 const struct Resident EmulBoot_resident
=
40 (struct Resident
*)&EmulBoot_resident
,
51 static const UBYTE version
[] = "$VER: emul-handler emergency console v2.0";
53 AROS_UFH3(APTR
, EmulBoot
,
54 AROS_UFPA(ULONG
, dummy
, D0
),
55 AROS_UFPA(BPTR
, segList
, A0
),
56 AROS_UFPA(struct ExecBase
*, SysBase
, A6
));
60 struct emulbase
*EmulBase
;
61 struct GfxBase
*GfxBase
;
62 struct DosLibrary
*DOSBase
;
63 struct Library
*ExpansionBase
;
64 struct MsgPort
*emulport
;
66 struct FileHandle
*fh_stdin
, *fh_stdout
;
69 DOSBase
= (struct DosLibrary
*)OpenLibrary("dos.library", 36);
71 ExpansionBase
= OpenLibrary("expansion.library", 0);
74 ULONG BootFlags
= IntExpBase(ExpansionBase
)->BootFlags
;
75 if (!(BootFlags
& BF_NO_DISPLAY_DRIVERS
))
79 BPTR seg
= LoadSeg("C:AROSMonDrvs");
82 STRPTR args
= "NOCOMPOSITION";
85 oldin
= SelectInput(Open("NIL:", MODE_OLDFILE
));
86 oldout
= SelectOutput(Open("NIL:", MODE_NEWFILE
));
87 RunCommand(seg
, AROS_STACKSIZE
, args
, strlen(args
));
91 /* We don't care about the return code */
94 /* make sure the boot process doesnt try to load the drivers again.. */
95 IntExpBase(ExpansionBase
)->BootFlags
= BootFlags
| BF_NO_DISPLAY_DRIVERS
;
98 CloseLibrary(ExpansionBase
);
102 * This actually checks if we have at least one display mode in the database.
103 * This means that we actually can open a display. If not, we enter emergency
104 * shell on host's console.
106 GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library", 36);
109 ULONG displayid
= NextDisplayInfo(INVALID_ID
);
111 CloseLibrary((APTR
)GfxBase
);
112 if (displayid
!= INVALID_ID
)
115 CloseLibrary((APTR
)DOSBase
);
116 /* Everything is ok, continue booting */
122 * Set up our own console I/O and run a shell without Startup-Sequence and other stuff.
123 * A failure in the following code causes dos.library to continue booting.
124 * Without display drivers this will end up in AN_SysScrn alert.
129 EmulBase
= OpenResource("emul-handler");
133 emulport
= DeviceProc("EMU");
137 fh_stdin
= AllocDosObject(DOS_FILEHANDLE
, NULL
);
140 CloseLibrary(&DOSBase
->dl_lib
);
144 fh_stdout
= AllocDosObject(DOS_FILEHANDLE
, NULL
);
147 CloseLibrary(&DOSBase
->dl_lib
);
151 /* A little bit of magic */
152 fh_stdin
->fh_Interactive
= DOSTRUE
;
153 fh_stdin
->fh_Type
= emulport
;
154 fh_stdin
->fh_Arg1
= (SIPTR
)EmulBase
->eb_stdin
;
155 fh_stdout
->fh_Interactive
= DOSTRUE
;
156 fh_stdout
->fh_Type
= emulport
;
157 fh_stdout
->fh_Arg1
= (SIPTR
)EmulBase
->eb_stdout
;
159 SetVBuf(MKBADDR(fh_stdin
) , NULL
, BUF_LINE
, -1);
160 SetVBuf(MKBADDR(fh_stdout
), NULL
, BUF_LINE
, -1);
165 D(bug("[EmulBoot] Selecting input and output for DOS\n"));
167 SelectInput(MKBADDR(fh_stdin
));
168 SelectOutput(MKBADDR(fh_stdout
));
169 me
= (struct Process
*)FindTask(NULL
);
170 me
->pr_CES
= MKBADDR(fh_stdout
);
174 PutStr("Display driver(s) failed to initialize. Entering emergency shell.\n"
175 "EndCLI will quit AROS.\n");
177 rc
= SystemTags("", SYS_Asynch
, FALSE
, SYS_Background
, FALSE
, TAG_DONE
);
180 /* Everything is too bad */
181 PutStr("Cannot open boot console. System halted.\n");
185 ShutdownA(SD_ACTION_POWEROFF
);
187 return NULL
; /* Just shut up the compiler, we'll never get here */