blob: e4cdbbcf3347aa3c7f7b18ea2a1e050b1682326a [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//
3// Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4// 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'Connorf076a3e2008-02-25 22:25:15 -05008#include "util.h" // irq_enable
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'Connor9f4e1d92009-02-08 15:44:08 -050019
20/****************************************************************
Kevin O'Connor0a924122009-02-08 19:43:47 -050021 * IPL and BCV handlers
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050022 ****************************************************************/
23
24void
25boot_setup()
26{
27 if (! CONFIG_BOOT)
28 return;
29 dprintf(3, "init boot device ordering\n");
30
31 memset(&IPL, 0, sizeof(IPL));
32
33 // Floppy drive
Kevin O'Connor0a924122009-02-08 19:43:47 -050034 struct ipl_entry_s *ie = &IPL.bev[0];
Kevin O'Connor71f036d2009-02-08 16:57:22 -050035 ie->type = IPL_TYPE_FLOPPY;
36 ie->description = "Floppy";
37 ie++;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050038
39 // First HDD
Kevin O'Connor71f036d2009-02-08 16:57:22 -050040 ie->type = IPL_TYPE_HARDDISK;
41 ie->description = "Hard Disk";
42 ie++;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050043
44 // CDROM
45 if (CONFIG_CDROM_BOOT) {
Kevin O'Connor71f036d2009-02-08 16:57:22 -050046 ie->type = IPL_TYPE_CDROM;
47 ie->description = "CD-Rom";
48 ie++;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050049 }
50
Kevin O'Connor67823442009-04-13 14:14:51 -040051 if (CONFIG_COREBOOT_FLASH) {
52 ie->type = IPL_TYPE_CBFS;
53 ie->description = "CBFS";
54 ie++;
55 }
56
Kevin O'Connor0a924122009-02-08 19:43:47 -050057 IPL.bevcount = ie - IPL.bev;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050058 SET_EBDA(boot_sequence, 0xffff);
59 if (CONFIG_COREBOOT) {
60 // XXX - hardcode defaults for coreboot.
Kevin O'Connorff8c1412009-04-18 17:02:41 -040061 IPL.bootorder = 0x87654231;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050062 IPL.checkfloppysig = 1;
63 } else {
64 // On emulators, get boot order from nvram.
65 IPL.bootorder = (inb_cmos(CMOS_BIOS_BOOTFLAG2)
66 | ((inb_cmos(CMOS_BIOS_BOOTFLAG1) & 0xf0) << 4));
67 if (!(inb_cmos(CMOS_BIOS_BOOTFLAG1) & 1))
68 IPL.checkfloppysig = 1;
69 }
70}
71
72// Add a BEV vector for a given pnp compatible option rom.
73void
74add_bev(u16 seg, u16 bev, u16 desc)
75{
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050076 if (! CONFIG_BOOT)
77 return;
Kevin O'Connor0a924122009-02-08 19:43:47 -050078 if (IPL.bevcount >= ARRAY_SIZE(IPL.bev))
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050079 return;
80
Kevin O'Connor0a924122009-02-08 19:43:47 -050081 struct ipl_entry_s *ie = &IPL.bev[IPL.bevcount++];
Kevin O'Connor71f036d2009-02-08 16:57:22 -050082 ie->type = IPL_TYPE_BEV;
83 ie->vector = (seg << 16) | bev;
Kevin O'Connor0a924122009-02-08 19:43:47 -050084 const char *d = "Unknown";
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050085 if (desc)
Kevin O'Connor0a924122009-02-08 19:43:47 -050086 d = MAKE_FLATPTR(seg, desc);
87 ie->description = d;
88}
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050089
Kevin O'Connor0a924122009-02-08 19:43:47 -050090// Add a bcv entry for an expansion card harddrive or legacy option rom
91void
92add_bcv(u16 seg, u16 ip, u16 desc)
93{
94 if (! CONFIG_BOOT)
95 return;
96 if (IPL.bcvcount >= ARRAY_SIZE(IPL.bcv))
97 return;
98
99 struct ipl_entry_s *ie = &IPL.bcv[IPL.bcvcount++];
Kevin O'Connor51fd0a12009-09-12 13:20:14 -0400100 ie->type = BCV_TYPE_EXTERNAL;
Kevin O'Connor0a924122009-02-08 19:43:47 -0500101 ie->vector = (seg << 16) | ip;
102 const char *d = "Legacy option rom";
103 if (desc)
104 d = MAKE_FLATPTR(seg, desc);
105 ie->description = d;
106}
107
Kevin O'Connor51fd0a12009-09-12 13:20:14 -0400108// Add a bcv entry for an internal harddrive
Kevin O'Connor0a924122009-02-08 19:43:47 -0500109void
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400110add_bcv_internal(struct drive_s *drive_g)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500111{
112 if (! CONFIG_BOOT)
113 return;
114 if (IPL.bcvcount >= ARRAY_SIZE(IPL.bcv))
115 return;
116
117 struct ipl_entry_s *ie = &IPL.bcv[IPL.bcvcount++];
Kevin O'Connor51fd0a12009-09-12 13:20:14 -0400118 ie->type = BCV_TYPE_INTERNAL;
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400119 ie->vector = (u32)drive_g;
Kevin O'Connor51fd0a12009-09-12 13:20:14 -0400120 ie->description = "";
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500121}
122
123
124/****************************************************************
Kevin O'Connor0a924122009-02-08 19:43:47 -0500125 * Boot menu and BCV execution
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500126 ****************************************************************/
127
Kevin O'Connor0a924122009-02-08 19:43:47 -0500128// Show a generic menu item
129static int
130menu_show_default(struct ipl_entry_s *ie, int menupos)
131{
132 char desc[33];
133 printf("%d. %s\n", menupos
134 , strtcpy(desc, ie->description, ARRAY_SIZE(desc)));
135 return 1;
136}
137
138// Show floppy menu item - but only if there exists a floppy drive.
139static int
140menu_show_floppy(struct ipl_entry_s *ie, int menupos)
141{
Kevin O'Connorafd05202009-08-16 12:21:44 -0400142 int i;
143 for (i = 0; i < Drives.floppycount; i++) {
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400144 struct drive_s *drive_g = getDrive(EXTTYPE_FLOPPY, i);
Kevin O'Connor51fd0a12009-09-12 13:20:14 -0400145 printf("%d. Floppy [", menupos + i);
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400146 describe_drive(drive_g);
Kevin O'Connor51fd0a12009-09-12 13:20:14 -0400147 printf("]\n");
Kevin O'Connorafd05202009-08-16 12:21:44 -0400148 }
149 return Drives.floppycount;
Kevin O'Connor0a924122009-02-08 19:43:47 -0500150}
151
152// Show menu items from BCV list.
153static int
154menu_show_harddisk(struct ipl_entry_s *ie, int menupos)
155{
156 int i;
157 for (i = 0; i < IPL.bcvcount; i++) {
158 struct ipl_entry_s *ie = &IPL.bcv[i];
159 switch (ie->type) {
Kevin O'Connor51fd0a12009-09-12 13:20:14 -0400160 case BCV_TYPE_INTERNAL:
161 printf("%d. ", menupos + i);
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400162 describe_drive((void*)ie->vector);
Kevin O'Connor51fd0a12009-09-12 13:20:14 -0400163 printf("\n");
Kevin O'Connor0a924122009-02-08 19:43:47 -0500164 break;
165 default:
166 menu_show_default(ie, menupos+i);
167 break;
168 }
169 }
170 return IPL.bcvcount;
171}
172
173// Show cdrom menu item - but only if there exists a cdrom drive.
174static int
175menu_show_cdrom(struct ipl_entry_s *ie, int menupos)
176{
Kevin O'Connor7da1dcd2009-02-16 10:51:24 -0500177 int i;
Kevin O'Connorc892b132009-08-11 21:59:37 -0400178 for (i = 0; i < Drives.cdcount; i++) {
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400179 struct drive_s *drive_g = getDrive(EXTTYPE_CD, i);
Kevin O'Connor51fd0a12009-09-12 13:20:14 -0400180 printf("%d. CD-Rom [", menupos + i);
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400181 describe_drive(drive_g);
Kevin O'Connor51fd0a12009-09-12 13:20:14 -0400182 printf("]\n");
Kevin O'Connor7da1dcd2009-02-16 10:51:24 -0500183 }
Kevin O'Connorc892b132009-08-11 21:59:37 -0400184 return Drives.cdcount;
Kevin O'Connor0a924122009-02-08 19:43:47 -0500185}
186
Kevin O'Connor67823442009-04-13 14:14:51 -0400187// Show coreboot-fs menu item.
188static int
189menu_show_cbfs(struct ipl_entry_s *ie, int menupos)
190{
191 int count = 0;
Kevin O'Connor31ae6382009-09-20 15:42:39 -0400192 struct cbfs_file *file = NULL;
Kevin O'Connor67823442009-04-13 14:14:51 -0400193 for (;;) {
Kevin O'Connor1f836252009-08-16 20:17:35 -0400194 file = cbfs_findprefix("img/", file);
195 if (!file)
Kevin O'Connor67823442009-04-13 14:14:51 -0400196 break;
Kevin O'Connor1f836252009-08-16 20:17:35 -0400197 const char *filename = cbfs_filename(file);
Kevin O'Connor67823442009-04-13 14:14:51 -0400198 printf("%d. Payload [%s]\n", menupos + count, &filename[4]);
199 count++;
200 if (count > 8)
201 break;
202 }
203 return count;
204}
205
Kevin O'Connor0a924122009-02-08 19:43:47 -0500206// Show IPL option menu.
207static void
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500208interactive_bootmenu()
209{
Kevin O'Connore7cc7642009-10-04 10:05:16 -0400210 if (! CONFIG_BOOTMENU || ! qemu_cfg_show_boot_menu())
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500211 return;
212
213 while (get_keystroke(0) >= 0)
214 ;
215
216 printf("Press F12 for boot menu.\n\n");
217
Kevin O'Connor217d3632009-04-29 22:00:21 -0400218 int scan_code = get_keystroke(CONFIG_BOOTMENU_WAIT);
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500219 if (scan_code != 0x86)
220 /* not F12 */
221 return;
222
223 while (get_keystroke(0) >= 0)
224 ;
225
226 printf("Select boot device:\n\n");
227
Kevin O'Connor0a924122009-02-08 19:43:47 -0500228 int subcount[ARRAY_SIZE(IPL.bev)];
229 int menupos = 1;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500230 int i;
Kevin O'Connor0a924122009-02-08 19:43:47 -0500231 for (i = 0; i < IPL.bevcount; i++) {
232 struct ipl_entry_s *ie = &IPL.bev[i];
Kevin O'Connor31ae6382009-09-20 15:42:39 -0400233 int sc;
Kevin O'Connor0a924122009-02-08 19:43:47 -0500234 switch (ie->type) {
235 case IPL_TYPE_FLOPPY:
236 sc = menu_show_floppy(ie, menupos);
237 break;
238 case IPL_TYPE_HARDDISK:
239 sc = menu_show_harddisk(ie, menupos);
240 break;
241 case IPL_TYPE_CDROM:
242 sc = menu_show_cdrom(ie, menupos);
243 break;
Kevin O'Connor67823442009-04-13 14:14:51 -0400244 case IPL_TYPE_CBFS:
245 sc = menu_show_cbfs(ie, menupos);
246 break;
Kevin O'Connor0a924122009-02-08 19:43:47 -0500247 default:
248 sc = menu_show_default(ie, menupos);
249 break;
250 }
251 subcount[i] = sc;
252 menupos += sc;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500253 }
254
255 for (;;) {
256 scan_code = get_keystroke(1000);
257 if (scan_code == 0x01)
258 // ESC
259 break;
Kevin O'Connor0a924122009-02-08 19:43:47 -0500260 if (scan_code < 1 || scan_code > menupos)
261 continue;
262 int choice = scan_code - 1;
263
264 // Find out which IPL this was for.
265 int bev = 0;
266 while (choice > subcount[bev]) {
267 choice -= subcount[bev];
268 bev++;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500269 }
Kevin O'Connor67823442009-04-13 14:14:51 -0400270 IPL.bev[bev].subchoice = choice-1;
Kevin O'Connor0a924122009-02-08 19:43:47 -0500271
272 // Add user choice to the boot order.
273 IPL.bootorder = (IPL.bootorder << 4) | (bev+1);
274 break;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500275 }
276 printf("\n");
277}
278
Kevin O'Connor0a924122009-02-08 19:43:47 -0500279// Run the specified bcv.
280static void
281run_bcv(struct ipl_entry_s *ie)
282{
283 switch (ie->type) {
Kevin O'Connor51fd0a12009-09-12 13:20:14 -0400284 case BCV_TYPE_INTERNAL:
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400285 map_hd_drive((void*)ie->vector);
Kevin O'Connor0a924122009-02-08 19:43:47 -0500286 break;
Kevin O'Connor51fd0a12009-09-12 13:20:14 -0400287 case BCV_TYPE_EXTERNAL:
Kevin O'Connor0a924122009-02-08 19:43:47 -0500288 call_bcv(ie->vector >> 16, ie->vector & 0xffff);
289 break;
290 }
291}
292
293// Prepare for boot - show menu and run bcvs.
294void
295boot_prep()
296{
297 if (! CONFIG_BOOT)
298 return;
299
300 // Allow user to modify BCV/IPL order.
301 interactive_bootmenu();
302
Kevin O'Connorafd05202009-08-16 12:21:44 -0400303 // Setup floppy boot order
304 int override = IPL.bev[0].subchoice;
305 int tmp = Drives.idmap[EXTTYPE_FLOPPY][0];
306 Drives.idmap[EXTTYPE_FLOPPY][0] = Drives.idmap[EXTTYPE_FLOPPY][override];
307 Drives.idmap[EXTTYPE_FLOPPY][override] = tmp;
308
Kevin O'Connor0a924122009-02-08 19:43:47 -0500309 // Run BCVs
Kevin O'Connorafd05202009-08-16 12:21:44 -0400310 override = IPL.bev[1].subchoice;
Kevin O'Connor7da1dcd2009-02-16 10:51:24 -0500311 if (override < IPL.bcvcount)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500312 run_bcv(&IPL.bcv[override]);
313 int i;
314 for (i=0; i<IPL.bcvcount; i++)
315 if (i != override)
316 run_bcv(&IPL.bcv[i]);
317}
318
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500319
320/****************************************************************
321 * Boot code (int 18/19)
322 ****************************************************************/
323
Kevin O'Connor0a924122009-02-08 19:43:47 -0500324// Jump to a bootup entry point.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500325static void
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500326call_boot_entry(u16 bootseg, u16 bootip, u8 bootdrv)
327{
Kevin O'Connor91b53a72009-05-05 22:52:09 -0400328 dprintf(1, "Booting from %04x:%04x\n", bootseg, bootip);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500329
330 struct bregs br;
331 memset(&br, 0, sizeof(br));
Kevin O'Connorf8e800d2009-09-24 21:01:16 -0400332 br.flags = F_IF;
Kevin O'Connor9f985422009-09-09 11:34:39 -0400333 br.code = SEGOFF(bootseg, bootip);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500334 // Set the magic number in ax and the boot drive in dl.
335 br.dl = bootdrv;
336 br.ax = 0xaa55;
337 call16(&br);
338}
339
340// Boot from a disk (either floppy or harddrive)
341static void
342boot_disk(u8 bootdrv, int checksig)
343{
344 u16 bootseg = 0x07c0;
345
346 // Read sector
347 struct bregs br;
348 memset(&br, 0, sizeof(br));
Kevin O'Connorf8e800d2009-09-24 21:01:16 -0400349 br.flags = F_IF;
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500350 br.dl = bootdrv;
351 br.es = bootseg;
352 br.ah = 2;
353 br.al = 1;
354 br.cl = 1;
355 call16_int(0x13, &br);
356
357 if (br.flags & F_CF) {
358 printf("Boot failed: could not read the boot disk\n\n");
359 return;
360 }
361
362 if (checksig) {
363 struct mbr_s *mbr = (void*)0;
364 if (GET_FARVAR(bootseg, mbr->signature) != MBR_SIGNATURE) {
365 printf("Boot failed: not a bootable disk\n\n");
366 return;
367 }
368 }
369
370 /* Canonicalize bootseg:bootip */
371 u16 bootip = (bootseg & 0x0fff) << 4;
372 bootseg &= 0xf000;
373
374 call_boot_entry(bootseg, bootip, bootdrv);
375}
376
377// Boot from a CD-ROM
378static void
Kevin O'Connor67823442009-04-13 14:14:51 -0400379boot_cdrom(struct ipl_entry_s *ie)
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500380{
381 if (! CONFIG_CDROM_BOOT)
382 return;
Kevin O'Connor67823442009-04-13 14:14:51 -0400383 int status = cdrom_boot(ie->subchoice);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500384 if (status) {
385 printf("Boot failed: Could not read from CDROM (code %04x)\n", status);
386 return;
387 }
388
389 u16 ebda_seg = get_ebda_seg();
Kevin O'Connor669e6442009-08-11 22:36:30 -0400390 u8 bootdrv = GET_EBDA2(ebda_seg, cdemu.emulated_extdrive);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500391 u16 bootseg = GET_EBDA2(ebda_seg, cdemu.load_segment);
392 /* Canonicalize bootseg:bootip */
393 u16 bootip = (bootseg & 0x0fff) << 4;
394 bootseg &= 0xf000;
395
396 call_boot_entry(bootseg, bootip, bootdrv);
397}
398
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400399// Boot from a CBFS payload
Kevin O'Connor67823442009-04-13 14:14:51 -0400400static void
401boot_cbfs(struct ipl_entry_s *ie)
402{
403 if (! CONFIG_COREBOOT_FLASH)
404 return;
Kevin O'Connor1f836252009-08-16 20:17:35 -0400405 int count = ie->subchoice;
406 struct cbfs_file *file;
407 for (;;) {
408 file = cbfs_findprefix("img/", file);
409 if (!file)
410 return;
411 if (count--)
412 continue;
413 cbfs_run_payload(file);
414 }
Kevin O'Connor67823442009-04-13 14:14:51 -0400415}
416
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500417static void
418do_boot(u16 seq_nr)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500419{
Kevin O'Connor40967022008-07-21 22:23:05 -0400420 if (! CONFIG_BOOT)
Kevin O'Connore07e18e2009-02-08 17:07:29 -0500421 panic("Boot support not compiled in.\n");
Kevin O'Connor40967022008-07-21 22:23:05 -0400422
Kevin O'Connorc659fde2008-12-28 23:43:20 -0500423 u32 bootdev = IPL.bootorder;
Kevin O'Connor840c5342008-03-29 14:04:34 -0400424 bootdev >>= 4 * seq_nr;
425 bootdev &= 0xf;
Kevin O'Connore0113c92008-04-05 15:51:12 -0400426
Kevin O'Connorabc75972008-05-18 00:20:53 -0400427 /* Translate bootdev to an IPL table offset by subtracting 1 */
Kevin O'Connor840c5342008-03-29 14:04:34 -0400428 bootdev -= 1;
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500429
Kevin O'Connor0a924122009-02-08 19:43:47 -0500430 if (bootdev >= IPL.bevcount) {
Kevin O'Connorff8c1412009-04-18 17:02:41 -0400431 printf("No bootable device.\n");
432 // Loop with irqs enabled - this allows ctrl+alt+delete to work.
433 for (;;)
434 usleep(1000000);
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500435 }
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500436
437 /* Do the loading, and set up vector as a far pointer to the boot
438 * address, and bootdrv as the boot drive */
Kevin O'Connor0a924122009-02-08 19:43:47 -0500439 struct ipl_entry_s *ie = &IPL.bev[bootdev];
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500440 char desc[33];
441 printf("Booting from %s...\n"
442 , strtcpy(desc, ie->description, ARRAY_SIZE(desc)));
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500443
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500444 switch(ie->type) {
Kevin O'Connorf13b0082008-08-17 11:26:42 -0400445 case IPL_TYPE_FLOPPY:
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500446 boot_disk(0x00, IPL.checkfloppysig);
447 break;
Kevin O'Connorf13b0082008-08-17 11:26:42 -0400448 case IPL_TYPE_HARDDISK:
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500449 boot_disk(0x80, 1);
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500450 break;
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500451 case IPL_TYPE_CDROM:
Kevin O'Connor67823442009-04-13 14:14:51 -0400452 boot_cdrom(ie);
453 break;
454 case IPL_TYPE_CBFS:
455 boot_cbfs(ie);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500456 break;
457 case IPL_TYPE_BEV:
458 call_boot_entry(ie->vector >> 16, ie->vector & 0xffff, 0);
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500459 break;
Kevin O'Connor180a9592008-03-04 22:50:53 -0500460 }
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500461
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500462 // Boot failed: invoke the boot recovery function
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400463 struct bregs br;
464 memset(&br, 0, sizeof(br));
Kevin O'Connorf8e800d2009-09-24 21:01:16 -0400465 br.flags = F_IF;
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400466 call16_int(0x18, &br);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500467}
468
469// Boot Failure recovery: try the next device.
Kevin O'Connor44eeaf12008-07-06 10:14:49 -0400470void VISIBLE32
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500471handle_18()
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500472{
Kevin O'Connor61d6b062008-06-21 12:15:10 -0400473 debug_serial_setup();
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400474 debug_enter(NULL, DEBUG_HDL_18);
Kevin O'Connor08815372008-12-29 21:16:31 -0500475 u16 ebda_seg = get_ebda_seg();
476 u16 seq = GET_EBDA2(ebda_seg, boot_sequence) + 1;
477 SET_EBDA2(ebda_seg, boot_sequence, seq);
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400478 do_boot(seq);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500479}
480
481// INT 19h Boot Load Service Entry Point
Kevin O'Connor44eeaf12008-07-06 10:14:49 -0400482void VISIBLE32
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500483handle_19()
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500484{
Kevin O'Connor61d6b062008-06-21 12:15:10 -0400485 debug_serial_setup();
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400486 debug_enter(NULL, DEBUG_HDL_19);
Kevin O'Connor08815372008-12-29 21:16:31 -0500487 SET_EBDA(boot_sequence, 0);
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400488 do_boot(0);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500489}