blob: 62d6487709eae27551aa5a8ec0ef8b6a41ff52ff [file] [log] [blame]
Kevin O'Connorf13b0082008-08-17 11:26:42 -04001// Code to load disk image and start system boot.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05002//
Kevin O'Connorcadaf0e2010-07-26 23:47:26 -04003// Copyright (C) 2008-2010 Kevin O'Connor <kevin@koconnor.net>
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05004// Copyright (C) 2002 MandrakeSoft S.A.
5//
Kevin O'Connorb1b7c2a2009-01-15 20:52:58 -05006// This file may be distributed under the terms of the GNU LGPLv3 license.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05007
Kevin O'Connor10ad7992009-10-24 11:06:08 -04008#include "util.h" // dprintf
Kevin O'Connor9521e262008-07-04 13:04:29 -04009#include "biosvar.h" // GET_EBDA
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050010#include "config.h" // CONFIG_*
Kevin O'Connor180a9592008-03-04 22:50:53 -050011#include "disk.h" // cdrom_boot
Kevin O'Connor9521e262008-07-04 13:04:29 -040012#include "bregs.h" // struct bregs
Kevin O'Connorc659fde2008-12-28 23:43:20 -050013#include "boot.h" // struct ipl_s
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050014#include "cmos.h" // inb_cmos
Kevin O'Connore7cc7642009-10-04 10:05:16 -040015#include "paravirt.h"
Kevin O'Connorc659fde2008-12-28 23:43:20 -050016
17struct ipl_s IPL;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050018
Kevin O'Connor72eee3e2010-12-27 19:07:49 -050019struct bootentry_s {
20 int type;
21 union {
22 u32 data;
23 struct segoff_s vector;
24 struct drive_s *drive;
25 };
26 int priority;
27 const char *description;
28 struct bootentry_s *next;
29};
30
31static struct bootentry_s *BootList;
32
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050033
34/****************************************************************
Kevin O'Connord1a17462010-12-24 11:17:03 -050035 * Boot setup
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050036 ****************************************************************/
37
Kevin O'Connord1a17462010-12-24 11:17:03 -050038static void
39loadBootOrder(void)
40{
41 char *f = romfile_loadfile("bootorder", NULL);
42 if (!f)
43 return;
44
45 int i;
46 IPL.fw_bootorder_count = 1;
47 while (f[i]) {
48 if (f[i] == '\n')
49 IPL.fw_bootorder_count++;
50 i++;
51 }
52 IPL.fw_bootorder = malloc_tmphigh(IPL.fw_bootorder_count*sizeof(char*));
53 if (!IPL.fw_bootorder) {
54 warn_noalloc();
55 free(f);
56 return;
57 }
58
59 dprintf(3, "boot order:\n");
60 i = 0;
61 do {
62 IPL.fw_bootorder[i] = f;
63 f = strchr(f, '\n');
64 if (f) {
65 *f = '\0';
66 f++;
67 dprintf(3, "%d: %s\n", i, IPL.fw_bootorder[i]);
68 i++;
69 }
70 } while(f);
71}
72
Kevin O'Connor72eee3e2010-12-27 19:07:49 -050073#define DEFAULT_PRIO 9999
74
75static int DefaultFloppyPrio = 101;
76static int DefaultCDPrio = 102;
77static int DefaultHDPrio = 103;
78static int DefaultBEVPrio = 104;
79
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050080void
Kevin O'Connor1ca05b02010-01-03 17:43:37 -050081boot_setup(void)
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050082{
83 if (! CONFIG_BOOT)
84 return;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050085
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050086 SET_EBDA(boot_sequence, 0xffff);
Kevin O'Connor72eee3e2010-12-27 19:07:49 -050087 IPL.checkfloppysig = 1;
88
89 if (!CONFIG_COREBOOT) {
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050090 // On emulators, get boot order from nvram.
Kevin O'Connor72eee3e2010-12-27 19:07:49 -050091 if (inb_cmos(CMOS_BIOS_BOOTFLAG1) & 1)
92 IPL.checkfloppysig = 0;
93 u32 bootorder = (inb_cmos(CMOS_BIOS_BOOTFLAG2)
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050094 | ((inb_cmos(CMOS_BIOS_BOOTFLAG1) & 0xf0) << 4));
Kevin O'Connor72eee3e2010-12-27 19:07:49 -050095 DefaultFloppyPrio = DefaultCDPrio = DefaultHDPrio
96 = DefaultBEVPrio = DEFAULT_PRIO;
97 int i;
98 for (i=101; i<104; i++) {
99 u32 val = bootorder & 0x0f;
100 bootorder >>= 4;
101 switch (val) {
102 case 1: DefaultFloppyPrio = i; break;
103 case 2: DefaultHDPrio = i; break;
104 case 3: DefaultCDPrio = i; break;
105 case 4: DefaultBEVPrio = i; break;
106 }
107 }
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500108 }
Gleb Natapovb9a75912010-12-23 11:29:38 +0200109
Kevin O'Connord1a17462010-12-24 11:17:03 -0500110 loadBootOrder();
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500111}
112
Kevin O'Connord1a17462010-12-24 11:17:03 -0500113
114/****************************************************************
115 * IPL and BCV handlers
116 ****************************************************************/
117
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500118static void
119bootentry_add(int type, int prio, u32 data, const char *desc)
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500120{
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500121 if (! CONFIG_BOOT)
122 return;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500123 struct bootentry_s *be = malloc_tmp(sizeof(*be));
124 if (!be) {
125 warn_noalloc();
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500126 return;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500127 }
128 be->type = type;
129 be->priority = prio;
130 be->data = data;
131 be->description = desc;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500132
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500133 // Add entry in sorted order.
134 struct bootentry_s **pprev;
135 for (pprev = &BootList; *pprev; pprev = &(*pprev)->next) {
136 struct bootentry_s *pos = *pprev;
137 if (be->priority < pos->priority)
138 break;
139 if (be->priority > pos->priority)
140 continue;
141 if (be->type < pos->type)
142 break;
143 if (be->type > pos->type)
144 continue;
145 if (be->type <= IPL_TYPE_CDROM
146 && (be->drive->type < pos->drive->type
147 || (be->drive->type == pos->drive->type
148 && be->drive->cntl_id < pos->drive->cntl_id)))
149 break;
150 }
151 be->next = *pprev;
152 *pprev = be;
Kevin O'Connor0a924122009-02-08 19:43:47 -0500153}
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500154
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500155// Add a BEV vector for a given pnp compatible option rom.
Gleb Natapov4c90a202010-12-07 13:50:54 +0200156void
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500157boot_add_bev(u16 seg, u16 bev, u16 desc)
Gleb Natapov4c90a202010-12-07 13:50:54 +0200158{
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500159 bootentry_add(IPL_TYPE_BEV, DefaultBEVPrio, SEGOFF(seg, bev).segoff
160 , desc ? MAKE_FLATPTR(seg, desc) : "Unknown");
161 DefaultBEVPrio = DEFAULT_PRIO;
Gleb Natapov4c90a202010-12-07 13:50:54 +0200162}
163
Kevin O'Connor0a924122009-02-08 19:43:47 -0500164// Add a bcv entry for an expansion card harddrive or legacy option rom
165void
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500166boot_add_bcv(u16 seg, u16 ip, u16 desc)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500167{
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500168 bootentry_add(IPL_TYPE_BCV, DEFAULT_PRIO, SEGOFF(seg, ip).segoff
169 , desc ? MAKE_FLATPTR(seg, desc) : "Legacy option rom");
Kevin O'Connor0a924122009-02-08 19:43:47 -0500170}
171
Kevin O'Connor0a924122009-02-08 19:43:47 -0500172void
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500173boot_add_floppy(struct drive_s *drive_g)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500174{
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500175 bootentry_add(IPL_TYPE_FLOPPY, DefaultFloppyPrio, (u32)drive_g
176 , drive_g->desc);
177}
Kevin O'Connor0a924122009-02-08 19:43:47 -0500178
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500179void
180boot_add_hd(struct drive_s *drive_g)
181{
182 bootentry_add(IPL_TYPE_HARDDISK, DefaultHDPrio, (u32)drive_g
183 , drive_g->desc);
184}
185
186void
187boot_add_cd(struct drive_s *drive_g)
188{
189 bootentry_add(IPL_TYPE_CDROM, DefaultCDPrio, (u32)drive_g
190 , drive_g->desc);
191}
192
193// Add a CBFS payload entry
194void
195boot_add_cbfs(void *data, const char *desc)
196{
197 bootentry_add(IPL_TYPE_CBFS, DEFAULT_PRIO, (u32)data, desc);
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500198}
199
200
201/****************************************************************
Kevin O'Connor0a924122009-02-08 19:43:47 -0500202 * Boot menu and BCV execution
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500203 ****************************************************************/
204
Kevin O'Connor0a924122009-02-08 19:43:47 -0500205// Show IPL option menu.
206static void
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500207interactive_bootmenu(void)
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500208{
Kevin O'Connore7cc7642009-10-04 10:05:16 -0400209 if (! CONFIG_BOOTMENU || ! qemu_cfg_show_boot_menu())
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500210 return;
211
212 while (get_keystroke(0) >= 0)
213 ;
214
215 printf("Press F12 for boot menu.\n\n");
216
Kevin O'Connor9a01a9c2010-08-25 21:07:48 -0400217 enable_bootsplash();
Kevin O'Connor217d3632009-04-29 22:00:21 -0400218 int scan_code = get_keystroke(CONFIG_BOOTMENU_WAIT);
Kevin O'Connor9a01a9c2010-08-25 21:07:48 -0400219 disable_bootsplash();
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500220 if (scan_code != 0x86)
221 /* not F12 */
222 return;
223
224 while (get_keystroke(0) >= 0)
225 ;
226
227 printf("Select boot device:\n\n");
Kevin O'Connore438b0c2010-05-01 12:20:33 -0400228 wait_threads();
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500229
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500230 // Show menu items
231 struct bootentry_s *pos = BootList;
232 int maxmenu = 0;
233 while (pos) {
234 char desc[60];
235 maxmenu++;
236 printf("%d. %s\n", maxmenu
237 , strtcpy(desc, pos->description, ARRAY_SIZE(desc)));
238 pos = pos->next;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500239 }
240
241 for (;;) {
242 scan_code = get_keystroke(1000);
243 if (scan_code == 0x01)
244 // ESC
245 break;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500246 if (scan_code < 1 || scan_code > maxmenu+1)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500247 continue;
248 int choice = scan_code - 1;
249
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500250 // Find entry and make top priority.
251 struct bootentry_s **pprev = &BootList;
252 while (--choice)
253 pprev = &(*pprev)->next;
254 pos = *pprev;
255 *pprev = pos->next;
256 pos->next = BootList;
257 BootList = pos;
258 pos->priority = 0;
Kevin O'Connor0a924122009-02-08 19:43:47 -0500259 break;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500260 }
261 printf("\n");
262}
263
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500264static int HaveHDBoot, HaveFDBoot;
265
Kevin O'Connor0a924122009-02-08 19:43:47 -0500266static void
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500267add_bev(int type, u32 vector)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500268{
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500269 if (type == IPL_TYPE_HARDDISK && HaveHDBoot++)
270 return;
271 if (type == IPL_TYPE_FLOPPY && HaveFDBoot++)
272 return;
273 if (IPL.bevcount >= ARRAY_SIZE(IPL.bev))
274 return;
275 struct ipl_entry_s *bev = &IPL.bev[IPL.bevcount++];
276 bev->type = type;
277 bev->vector = vector;
Kevin O'Connor0a924122009-02-08 19:43:47 -0500278}
279
280// Prepare for boot - show menu and run bcvs.
281void
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500282boot_prep(void)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500283{
Kevin O'Connore438b0c2010-05-01 12:20:33 -0400284 if (! CONFIG_BOOT) {
285 wait_threads();
Kevin O'Connor0a924122009-02-08 19:43:47 -0500286 return;
Kevin O'Connore438b0c2010-05-01 12:20:33 -0400287 }
Kevin O'Connor0a924122009-02-08 19:43:47 -0500288
Kevin O'Connora5826b52009-10-24 17:57:29 -0400289 // XXX - show available drives?
290
Kevin O'Connor0a924122009-02-08 19:43:47 -0500291 // Allow user to modify BCV/IPL order.
292 interactive_bootmenu();
Kevin O'Connore438b0c2010-05-01 12:20:33 -0400293 wait_threads();
Kevin O'Connor0a924122009-02-08 19:43:47 -0500294
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500295 // Map drives and populate BEV list
296 struct bootentry_s *pos = BootList;
297 while (pos) {
298 switch (pos->type) {
299 case IPL_TYPE_BCV:
300 call_bcv(pos->vector.seg, pos->vector.offset);
301 add_bev(IPL_TYPE_HARDDISK, 0);
302 break;
303 case IPL_TYPE_FLOPPY:
304 map_floppy_drive(pos->drive);
305 add_bev(IPL_TYPE_FLOPPY, 0);
306 break;
307 case IPL_TYPE_HARDDISK:
308 map_hd_drive(pos->drive);
309 add_bev(IPL_TYPE_HARDDISK, 0);
310 break;
311 case IPL_TYPE_CDROM:
312 map_cd_drive(pos->drive);
313 // NO BREAK
314 default:
315 add_bev(pos->type, pos->data);
316 break;
317 }
318 pos = pos->next;
319 }
Kevin O'Connorafd05202009-08-16 12:21:44 -0400320
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500321 // If nothing added a floppy/hd boot - add it manually.
322 add_bev(IPL_TYPE_FLOPPY, 0);
323 add_bev(IPL_TYPE_HARDDISK, 0);
Kevin O'Connor0a924122009-02-08 19:43:47 -0500324}
325
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500326
327/****************************************************************
328 * Boot code (int 18/19)
329 ****************************************************************/
330
Kevin O'Connor0a924122009-02-08 19:43:47 -0500331// Jump to a bootup entry point.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500332static void
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500333call_boot_entry(u16 bootseg, u16 bootip, u8 bootdrv)
334{
Kevin O'Connorcadaf0e2010-07-26 23:47:26 -0400335 dprintf(1, "Booting from %04x:%04x\n", bootseg, bootip);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500336 struct bregs br;
337 memset(&br, 0, sizeof(br));
Kevin O'Connorf8e800d2009-09-24 21:01:16 -0400338 br.flags = F_IF;
Kevin O'Connor9f985422009-09-09 11:34:39 -0400339 br.code = SEGOFF(bootseg, bootip);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500340 // Set the magic number in ax and the boot drive in dl.
341 br.dl = bootdrv;
342 br.ax = 0xaa55;
343 call16(&br);
344}
345
346// Boot from a disk (either floppy or harddrive)
347static void
348boot_disk(u8 bootdrv, int checksig)
349{
350 u16 bootseg = 0x07c0;
351
352 // Read sector
353 struct bregs br;
354 memset(&br, 0, sizeof(br));
Kevin O'Connorf8e800d2009-09-24 21:01:16 -0400355 br.flags = F_IF;
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500356 br.dl = bootdrv;
357 br.es = bootseg;
358 br.ah = 2;
359 br.al = 1;
360 br.cl = 1;
361 call16_int(0x13, &br);
362
363 if (br.flags & F_CF) {
364 printf("Boot failed: could not read the boot disk\n\n");
365 return;
366 }
367
368 if (checksig) {
369 struct mbr_s *mbr = (void*)0;
370 if (GET_FARVAR(bootseg, mbr->signature) != MBR_SIGNATURE) {
371 printf("Boot failed: not a bootable disk\n\n");
372 return;
373 }
374 }
375
376 /* Canonicalize bootseg:bootip */
377 u16 bootip = (bootseg & 0x0fff) << 4;
378 bootseg &= 0xf000;
379
380 call_boot_entry(bootseg, bootip, bootdrv);
381}
382
383// Boot from a CD-ROM
384static void
Kevin O'Connor67823442009-04-13 14:14:51 -0400385boot_cdrom(struct ipl_entry_s *ie)
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500386{
387 if (! CONFIG_CDROM_BOOT)
388 return;
Gleb Natapov4c90a202010-12-07 13:50:54 +0200389
390 if (!ie->vector)
391 return;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500392 printf("Booting from DVD/CD...\n");
Gleb Natapov4c90a202010-12-07 13:50:54 +0200393
394 struct drive_s *drive_g = (void*)ie->vector;
395 int status = cdrom_boot(drive_g);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500396 if (status) {
Gleb Natapov4c90a202010-12-07 13:50:54 +0200397 printf("Boot failed: Could not read from CDROM %s (code %04x)\n", drive_g->desc, status);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500398 return;
399 }
400
401 u16 ebda_seg = get_ebda_seg();
Kevin O'Connor669e6442009-08-11 22:36:30 -0400402 u8 bootdrv = GET_EBDA2(ebda_seg, cdemu.emulated_extdrive);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500403 u16 bootseg = GET_EBDA2(ebda_seg, cdemu.load_segment);
404 /* Canonicalize bootseg:bootip */
405 u16 bootip = (bootseg & 0x0fff) << 4;
406 bootseg &= 0xf000;
407
408 call_boot_entry(bootseg, bootip, bootdrv);
409}
410
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400411// Boot from a CBFS payload
Kevin O'Connor67823442009-04-13 14:14:51 -0400412static void
413boot_cbfs(struct ipl_entry_s *ie)
414{
Kevin O'Connord9c93612010-03-20 11:00:45 -0400415 if (!CONFIG_COREBOOT || !CONFIG_COREBOOT_FLASH)
Kevin O'Connor67823442009-04-13 14:14:51 -0400416 return;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500417 printf("Booting from CBFS...\n");
418 cbfs_run_payload((void*)ie->vector);
Kevin O'Connor67823442009-04-13 14:14:51 -0400419}
420
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500421static void
422do_boot(u16 seq_nr)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500423{
Kevin O'Connor40967022008-07-21 22:23:05 -0400424 if (! CONFIG_BOOT)
Kevin O'Connore07e18e2009-02-08 17:07:29 -0500425 panic("Boot support not compiled in.\n");
Kevin O'Connor40967022008-07-21 22:23:05 -0400426
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500427 if (seq_nr >= IPL.bevcount) {
Kevin O'Connorff8c1412009-04-18 17:02:41 -0400428 printf("No bootable device.\n");
429 // Loop with irqs enabled - this allows ctrl+alt+delete to work.
430 for (;;)
Kevin O'Connor9c447c32010-05-23 10:24:22 -0400431 wait_irq();
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500432 }
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500433
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500434 // Boot the given BEV type.
435 struct ipl_entry_s *ie = &IPL.bev[seq_nr];
Kevin O'Connorcadaf0e2010-07-26 23:47:26 -0400436 switch (ie->type) {
Kevin O'Connorf13b0082008-08-17 11:26:42 -0400437 case IPL_TYPE_FLOPPY:
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500438 printf("Booting from Floppy...\n");
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500439 boot_disk(0x00, IPL.checkfloppysig);
440 break;
Kevin O'Connorf13b0082008-08-17 11:26:42 -0400441 case IPL_TYPE_HARDDISK:
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500442 printf("Booting from Hard Disk...\n");
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500443 boot_disk(0x80, 1);
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500444 break;
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500445 case IPL_TYPE_CDROM:
Kevin O'Connor67823442009-04-13 14:14:51 -0400446 boot_cdrom(ie);
447 break;
448 case IPL_TYPE_CBFS:
449 boot_cbfs(ie);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500450 break;
451 case IPL_TYPE_BEV:
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500452 printf("Booting from ROM...\n");
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500453 call_boot_entry(ie->vector >> 16, ie->vector & 0xffff, 0);
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500454 break;
Kevin O'Connor180a9592008-03-04 22:50:53 -0500455 }
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500456
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500457 // Boot failed: invoke the boot recovery function
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400458 struct bregs br;
459 memset(&br, 0, sizeof(br));
Kevin O'Connorf8e800d2009-09-24 21:01:16 -0400460 br.flags = F_IF;
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400461 call16_int(0x18, &br);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500462}
463
464// Boot Failure recovery: try the next device.
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500465void VISIBLE32FLAT
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500466handle_18(void)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500467{
Kevin O'Connor61d6b062008-06-21 12:15:10 -0400468 debug_serial_setup();
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400469 debug_enter(NULL, DEBUG_HDL_18);
Kevin O'Connor08815372008-12-29 21:16:31 -0500470 u16 ebda_seg = get_ebda_seg();
471 u16 seq = GET_EBDA2(ebda_seg, boot_sequence) + 1;
472 SET_EBDA2(ebda_seg, boot_sequence, seq);
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400473 do_boot(seq);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500474}
475
476// INT 19h Boot Load Service Entry Point
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500477void VISIBLE32FLAT
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500478handle_19(void)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500479{
Kevin O'Connor61d6b062008-06-21 12:15:10 -0400480 debug_serial_setup();
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400481 debug_enter(NULL, DEBUG_HDL_19);
Kevin O'Connor08815372008-12-29 21:16:31 -0500482 SET_EBDA(boot_sequence, 0);
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400483 do_boot(0);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500484}