These changes are the raw update to qemu-2.6.
[kvmfornfv.git] / qemu / roms / seabios / src / boot.c
1 // Code to load disk image and start system boot.
2 //
3 // Copyright (C) 2008-2013  Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2002  MandrakeSoft S.A.
5 //
6 // This file may be distributed under the terms of the GNU LGPLv3 license.
7
8 #include "block.h" // struct drive_s
9 #include "bregs.h" // struct bregs
10 #include "config.h" // CONFIG_*
11 #include "fw/paravirt.h" // qemu_cfg_show_boot_menu
12 #include "hw/pci.h" // pci_bdf_to_*
13 #include "hw/rtc.h" // rtc_read
14 #include "hw/usb.h" // struct usbdevice_s
15 #include "list.h" // hlist_node
16 #include "malloc.h" // free
17 #include "output.h" // dprintf
18 #include "romfile.h" // romfile_loadint
19 #include "std/disk.h" // struct mbr_s
20 #include "string.h" // memset
21 #include "util.h" // irqtimer_calc
22 #include "tcgbios.h" // tpm_*
23
24
25 /****************************************************************
26  * Boot priority ordering
27  ****************************************************************/
28
29 static char **Bootorder VARVERIFY32INIT;
30 static int BootorderCount;
31
32 static void
33 loadBootOrder(void)
34 {
35     if (!CONFIG_BOOTORDER)
36         return;
37
38     char *f = romfile_loadfile("bootorder", NULL);
39     if (!f)
40         return;
41
42     int i = 0;
43     BootorderCount = 1;
44     while (f[i]) {
45         if (f[i] == '\n')
46             BootorderCount++;
47         i++;
48     }
49     Bootorder = malloc_tmphigh(BootorderCount*sizeof(char*));
50     if (!Bootorder) {
51         warn_noalloc();
52         free(f);
53         BootorderCount = 0;
54         return;
55     }
56
57     dprintf(1, "boot order:\n");
58     i = 0;
59     do {
60         Bootorder[i] = f;
61         f = strchr(f, '\n');
62         if (f)
63             *(f++) = '\0';
64         Bootorder[i] = nullTrailingSpace(Bootorder[i]);
65         dprintf(1, "%d: %s\n", i+1, Bootorder[i]);
66         i++;
67     } while (f);
68 }
69
70 // See if 'str' starts with 'glob' - if glob contains an '*' character
71 // it will match any number of characters in str that aren't a '/' or
72 // the next glob character.
73 static char *
74 glob_prefix(const char *glob, const char *str)
75 {
76     for (;;) {
77         if (!*glob && (!*str || *str == '/'))
78             return (char*)str;
79         if (*glob == '*') {
80             if (!*str || *str == '/' || *str == glob[1])
81                 glob++;
82             else
83                 str++;
84             continue;
85         }
86         if (*glob != *str)
87             return NULL;
88         glob++;
89         str++;
90     }
91 }
92
93 // Search the bootorder list for the given glob pattern.
94 static int
95 find_prio(const char *glob)
96 {
97     dprintf(1, "Searching bootorder for: %s\n", glob);
98     int i;
99     for (i = 0; i < BootorderCount; i++)
100         if (glob_prefix(glob, Bootorder[i]))
101             return i+1;
102     return -1;
103 }
104
105 #define FW_PCI_DOMAIN "/pci@i0cf8"
106
107 static char *
108 build_pci_path(char *buf, int max, const char *devname, struct pci_device *pci)
109 {
110     // Build the string path of a bdf - for example: /pci@i0cf8/isa@1,2
111     char *p = buf;
112     if (pci->parent) {
113         p = build_pci_path(p, max, "pci-bridge", pci->parent);
114     } else {
115         p += snprintf(p, buf+max-p, "%s", FW_PCI_DOMAIN);
116         if (pci->rootbus)
117             p += snprintf(p, buf+max-p, ",%x", pci->rootbus);
118     }
119
120     int dev = pci_bdf_to_dev(pci->bdf), fn = pci_bdf_to_fn(pci->bdf);
121     p += snprintf(p, buf+max-p, "/%s@%x", devname, dev);
122     if (fn)
123         p += snprintf(p, buf+max-p, ",%x", fn);
124     return p;
125 }
126
127 int bootprio_find_pci_device(struct pci_device *pci)
128 {
129     if (CONFIG_CSM)
130         return csm_bootprio_pci(pci);
131     if (!CONFIG_BOOTORDER)
132         return -1;
133     // Find pci device - for example: /pci@i0cf8/ethernet@5
134     char desc[256];
135     build_pci_path(desc, sizeof(desc), "*", pci);
136     return find_prio(desc);
137 }
138
139 int bootprio_find_scsi_device(struct pci_device *pci, int target, int lun)
140 {
141     if (!CONFIG_BOOTORDER)
142         return -1;
143     if (!pci)
144         // support only pci machine for now
145         return -1;
146     // Find scsi drive - for example: /pci@i0cf8/scsi@5/channel@0/disk@1,0
147     char desc[256], *p;
148     p = build_pci_path(desc, sizeof(desc), "*", pci);
149     snprintf(p, desc+sizeof(desc)-p, "/*@0/*@%x,%x", target, lun);
150     return find_prio(desc);
151 }
152
153 int bootprio_find_ata_device(struct pci_device *pci, int chanid, int slave)
154 {
155     if (CONFIG_CSM)
156         return csm_bootprio_ata(pci, chanid, slave);
157     if (!CONFIG_BOOTORDER)
158         return -1;
159     if (!pci)
160         // support only pci machine for now
161         return -1;
162     // Find ata drive - for example: /pci@i0cf8/ide@1,1/drive@1/disk@0
163     char desc[256], *p;
164     p = build_pci_path(desc, sizeof(desc), "*", pci);
165     snprintf(p, desc+sizeof(desc)-p, "/drive@%x/disk@%x", chanid, slave);
166     return find_prio(desc);
167 }
168
169 int bootprio_find_fdc_device(struct pci_device *pci, int port, int fdid)
170 {
171     if (CONFIG_CSM)
172         return csm_bootprio_fdc(pci, port, fdid);
173     if (!CONFIG_BOOTORDER)
174         return -1;
175     if (!pci)
176         // support only pci machine for now
177         return -1;
178     // Find floppy - for example: /pci@i0cf8/isa@1/fdc@03f1/floppy@0
179     char desc[256], *p;
180     p = build_pci_path(desc, sizeof(desc), "isa", pci);
181     snprintf(p, desc+sizeof(desc)-p, "/fdc@%04x/floppy@%x", port, fdid);
182     return find_prio(desc);
183 }
184
185 int bootprio_find_pci_rom(struct pci_device *pci, int instance)
186 {
187     if (!CONFIG_BOOTORDER)
188         return -1;
189     // Find pci rom - for example: /pci@i0cf8/scsi@3:rom2
190     char desc[256], *p;
191     p = build_pci_path(desc, sizeof(desc), "*", pci);
192     if (instance)
193         snprintf(p, desc+sizeof(desc)-p, ":rom%x", instance);
194     return find_prio(desc);
195 }
196
197 int bootprio_find_named_rom(const char *name, int instance)
198 {
199     if (!CONFIG_BOOTORDER)
200         return -1;
201     // Find named rom - for example: /rom@genroms/linuxboot.bin
202     char desc[256], *p;
203     p = desc + snprintf(desc, sizeof(desc), "/rom@%s", name);
204     if (instance)
205         snprintf(p, desc+sizeof(desc)-p, ":rom%x", instance);
206     return find_prio(desc);
207 }
208
209 static char *
210 build_usb_path(char *buf, int max, struct usbhub_s *hub)
211 {
212     if (!hub->usbdev)
213         // Root hub - nothing to add.
214         return buf;
215     char *p = build_usb_path(buf, max, hub->usbdev->hub);
216     p += snprintf(p, buf+max-p, "/hub@%x", hub->usbdev->port+1);
217     return p;
218 }
219
220 int bootprio_find_usb(struct usbdevice_s *usbdev, int lun)
221 {
222     if (!CONFIG_BOOTORDER)
223         return -1;
224     // Find usb - for example: /pci@i0cf8/usb@1,2/storage@1/channel@0/disk@0,0
225     char desc[256], *p;
226     p = build_pci_path(desc, sizeof(desc), "usb", usbdev->hub->cntl->pci);
227     p = build_usb_path(p, desc+sizeof(desc)-p, usbdev->hub);
228     snprintf(p, desc+sizeof(desc)-p, "/storage@%x/*@0/*@0,%x"
229              , usbdev->port+1, lun);
230     int ret = find_prio(desc);
231     if (ret >= 0)
232         return ret;
233     // Try usb-host/redir - for example: /pci@i0cf8/usb@1,2/usb-host@1
234     snprintf(p, desc+sizeof(desc)-p, "/usb-*@%x", usbdev->port+1);
235     return find_prio(desc);
236 }
237
238
239 /****************************************************************
240  * Boot setup
241  ****************************************************************/
242
243 static int BootRetryTime;
244 static int CheckFloppySig = 1;
245
246 #define DEFAULT_PRIO           9999
247
248 static int DefaultFloppyPrio = 101;
249 static int DefaultCDPrio     = 102;
250 static int DefaultHDPrio     = 103;
251 static int DefaultBEVPrio    = 104;
252
253 void
254 boot_init(void)
255 {
256     if (! CONFIG_BOOT)
257         return;
258
259     if (CONFIG_QEMU) {
260         // On emulators, get boot order from nvram.
261         if (rtc_read(CMOS_BIOS_BOOTFLAG1) & 1)
262             CheckFloppySig = 0;
263         u32 bootorder = (rtc_read(CMOS_BIOS_BOOTFLAG2)
264                          | ((rtc_read(CMOS_BIOS_BOOTFLAG1) & 0xf0) << 4));
265         DefaultFloppyPrio = DefaultCDPrio = DefaultHDPrio
266             = DefaultBEVPrio = DEFAULT_PRIO;
267         int i;
268         for (i=101; i<104; i++) {
269             u32 val = bootorder & 0x0f;
270             bootorder >>= 4;
271             switch (val) {
272             case 1: DefaultFloppyPrio = i; break;
273             case 2: DefaultHDPrio = i;     break;
274             case 3: DefaultCDPrio = i;     break;
275             case 4: DefaultBEVPrio = i;    break;
276             }
277         }
278     }
279
280     BootRetryTime = romfile_loadint("etc/boot-fail-wait", 60*1000);
281
282     loadBootOrder();
283 }
284
285
286 /****************************************************************
287  * BootList handling
288  ****************************************************************/
289
290 struct bootentry_s {
291     int type;
292     union {
293         u32 data;
294         struct segoff_s vector;
295         struct drive_s *drive;
296     };
297     int priority;
298     const char *description;
299     struct hlist_node node;
300 };
301 static struct hlist_head BootList VARVERIFY32INIT;
302
303 #define IPL_TYPE_FLOPPY      0x01
304 #define IPL_TYPE_HARDDISK    0x02
305 #define IPL_TYPE_CDROM       0x03
306 #define IPL_TYPE_CBFS        0x20
307 #define IPL_TYPE_BEV         0x80
308 #define IPL_TYPE_BCV         0x81
309 #define IPL_TYPE_HALT        0xf0
310
311 static void
312 bootentry_add(int type, int prio, u32 data, const char *desc)
313 {
314     if (! CONFIG_BOOT)
315         return;
316     struct bootentry_s *be = malloc_tmp(sizeof(*be));
317     if (!be) {
318         warn_noalloc();
319         return;
320     }
321     be->type = type;
322     be->priority = prio;
323     be->data = data;
324     be->description = desc ?: "?";
325     dprintf(3, "Registering bootable: %s (type:%d prio:%d data:%x)\n"
326             , be->description, type, prio, data);
327
328     // Add entry in sorted order.
329     struct hlist_node **pprev;
330     struct bootentry_s *pos;
331     hlist_for_each_entry_pprev(pos, pprev, &BootList, node) {
332         if (be->priority < pos->priority)
333             break;
334         if (be->priority > pos->priority)
335             continue;
336         if (be->type < pos->type)
337             break;
338         if (be->type > pos->type)
339             continue;
340         if (be->type <= IPL_TYPE_CDROM
341             && (be->drive->type < pos->drive->type
342                 || (be->drive->type == pos->drive->type
343                     && be->drive->cntl_id < pos->drive->cntl_id)))
344             break;
345     }
346     hlist_add(&be->node, pprev);
347 }
348
349 // Return the given priority if it's set - defaultprio otherwise.
350 static inline int defPrio(int priority, int defaultprio) {
351     return (priority < 0) ? defaultprio : priority;
352 }
353
354 // Add a BEV vector for a given pnp compatible option rom.
355 void
356 boot_add_bev(u16 seg, u16 bev, u16 desc, int prio)
357 {
358     bootentry_add(IPL_TYPE_BEV, defPrio(prio, DefaultBEVPrio)
359                   , SEGOFF(seg, bev).segoff
360                   , desc ? MAKE_FLATPTR(seg, desc) : "Unknown");
361     DefaultBEVPrio = DEFAULT_PRIO;
362 }
363
364 // Add a bcv entry for an expansion card harddrive or legacy option rom
365 void
366 boot_add_bcv(u16 seg, u16 ip, u16 desc, int prio)
367 {
368     bootentry_add(IPL_TYPE_BCV, defPrio(prio, DefaultHDPrio)
369                   , SEGOFF(seg, ip).segoff
370                   , desc ? MAKE_FLATPTR(seg, desc) : "Legacy option rom");
371 }
372
373 void
374 boot_add_floppy(struct drive_s *drive_g, const char *desc, int prio)
375 {
376     bootentry_add(IPL_TYPE_FLOPPY, defPrio(prio, DefaultFloppyPrio)
377                   , (u32)drive_g, desc);
378 }
379
380 void
381 boot_add_hd(struct drive_s *drive_g, const char *desc, int prio)
382 {
383     bootentry_add(IPL_TYPE_HARDDISK, defPrio(prio, DefaultHDPrio)
384                   , (u32)drive_g, desc);
385 }
386
387 void
388 boot_add_cd(struct drive_s *drive_g, const char *desc, int prio)
389 {
390     bootentry_add(IPL_TYPE_CDROM, defPrio(prio, DefaultCDPrio)
391                   , (u32)drive_g, desc);
392 }
393
394 // Add a CBFS payload entry
395 void
396 boot_add_cbfs(void *data, const char *desc, int prio)
397 {
398     bootentry_add(IPL_TYPE_CBFS, defPrio(prio, DEFAULT_PRIO), (u32)data, desc);
399 }
400
401
402 /****************************************************************
403  * Keyboard calls
404  ****************************************************************/
405
406 // See if a keystroke is pending in the keyboard buffer.
407 static int
408 check_for_keystroke(void)
409 {
410     struct bregs br;
411     memset(&br, 0, sizeof(br));
412     br.flags = F_IF|F_ZF;
413     br.ah = 1;
414     call16_int(0x16, &br);
415     return !(br.flags & F_ZF);
416 }
417
418 // Return a keystroke - waiting forever if necessary.
419 static int
420 get_raw_keystroke(void)
421 {
422     struct bregs br;
423     memset(&br, 0, sizeof(br));
424     br.flags = F_IF;
425     call16_int(0x16, &br);
426     return br.ah;
427 }
428
429 // Read a keystroke - waiting up to 'msec' milliseconds.
430 static int
431 get_keystroke(int msec)
432 {
433     u32 end = irqtimer_calc(msec);
434     for (;;) {
435         if (check_for_keystroke())
436             return get_raw_keystroke();
437         if (irqtimer_check(end))
438             return -1;
439         yield_toirq();
440     }
441 }
442
443
444 /****************************************************************
445  * Boot menu and BCV execution
446  ****************************************************************/
447
448 #define DEFAULT_BOOTMENU_WAIT 2500
449
450 // Show IPL option menu.
451 void
452 interactive_bootmenu(void)
453 {
454     // XXX - show available drives?
455
456     if (! CONFIG_BOOTMENU || !romfile_loadint("etc/show-boot-menu", 1))
457         return;
458
459     while (get_keystroke(0) >= 0)
460         ;
461
462     char *bootmsg = romfile_loadfile("etc/boot-menu-message", NULL);
463     int menukey = romfile_loadint("etc/boot-menu-key", 1);
464     printf("%s", bootmsg ?: "\nPress ESC for boot menu.\n\n");
465     free(bootmsg);
466
467     u32 menutime = romfile_loadint("etc/boot-menu-wait", DEFAULT_BOOTMENU_WAIT);
468     enable_bootsplash();
469     int scan_code = get_keystroke(menutime);
470     disable_bootsplash();
471     if (scan_code != menukey)
472         return;
473
474     while (get_keystroke(0) >= 0)
475         ;
476
477     printf("Select boot device:\n\n");
478     wait_threads();
479
480     // Show menu items
481     int maxmenu = 0;
482     struct bootentry_s *pos;
483     hlist_for_each_entry(pos, &BootList, node) {
484         char desc[60];
485         maxmenu++;
486         printf("%d. %s\n", maxmenu
487                , strtcpy(desc, pos->description, ARRAY_SIZE(desc)));
488     }
489
490     // Get key press.  If the menu key is ESC, do not restart boot unless
491     // 1.5 seconds have passed.  Otherwise users (trained by years of
492     // repeatedly hitting keys to enter the BIOS) will end up hitting ESC
493     // multiple times and immediately booting the primary boot device.
494     int esc_accepted_time = irqtimer_calc(menukey == 1 ? 1500 : 0);
495     for (;;) {
496         scan_code = get_keystroke(1000);
497         if (scan_code == 1 && !irqtimer_check(esc_accepted_time))
498             continue;
499         if (scan_code >= 1 && scan_code <= maxmenu+1)
500             break;
501     }
502     printf("\n");
503     if (scan_code == 0x01)
504         // ESC
505         return;
506
507     // Find entry and make top priority.
508     int choice = scan_code - 1;
509     hlist_for_each_entry(pos, &BootList, node) {
510         if (! --choice)
511             break;
512     }
513     hlist_del(&pos->node);
514     pos->priority = 0;
515     hlist_add_head(&pos->node, &BootList);
516 }
517
518 // BEV (Boot Execution Vector) list
519 struct bev_s {
520     int type;
521     u32 vector;
522 };
523 static struct bev_s BEV[20];
524 static int BEVCount;
525 static int HaveHDBoot, HaveFDBoot;
526
527 static void
528 add_bev(int type, u32 vector)
529 {
530     if (type == IPL_TYPE_HARDDISK && HaveHDBoot++)
531         return;
532     if (type == IPL_TYPE_FLOPPY && HaveFDBoot++)
533         return;
534     if (BEVCount >= ARRAY_SIZE(BEV))
535         return;
536     struct bev_s *bev = &BEV[BEVCount++];
537     bev->type = type;
538     bev->vector = vector;
539 }
540
541 // Prepare for boot - show menu and run bcvs.
542 void
543 bcv_prepboot(void)
544 {
545     if (! CONFIG_BOOT)
546         return;
547
548     int haltprio = find_prio("HALT");
549     if (haltprio >= 0)
550         bootentry_add(IPL_TYPE_HALT, haltprio, 0, "HALT");
551
552     // Map drives and populate BEV list
553     struct bootentry_s *pos;
554     hlist_for_each_entry(pos, &BootList, node) {
555         switch (pos->type) {
556         case IPL_TYPE_BCV:
557             call_bcv(pos->vector.seg, pos->vector.offset);
558             add_bev(IPL_TYPE_HARDDISK, 0);
559             break;
560         case IPL_TYPE_FLOPPY:
561             map_floppy_drive(pos->drive);
562             add_bev(IPL_TYPE_FLOPPY, 0);
563             break;
564         case IPL_TYPE_HARDDISK:
565             map_hd_drive(pos->drive);
566             add_bev(IPL_TYPE_HARDDISK, 0);
567             break;
568         case IPL_TYPE_CDROM:
569             map_cd_drive(pos->drive);
570             // NO BREAK
571         default:
572             add_bev(pos->type, pos->data);
573             break;
574         }
575     }
576
577     // If nothing added a floppy/hd boot - add it manually.
578     add_bev(IPL_TYPE_FLOPPY, 0);
579     add_bev(IPL_TYPE_HARDDISK, 0);
580 }
581
582
583 /****************************************************************
584  * Boot code (int 18/19)
585  ****************************************************************/
586
587 // Jump to a bootup entry point.
588 static void
589 call_boot_entry(struct segoff_s bootsegip, u8 bootdrv)
590 {
591     dprintf(1, "Booting from %04x:%04x\n", bootsegip.seg, bootsegip.offset);
592     struct bregs br;
593     memset(&br, 0, sizeof(br));
594     br.flags = F_IF;
595     br.code = bootsegip;
596     // Set the magic number in ax and the boot drive in dl.
597     br.dl = bootdrv;
598     br.ax = 0xaa55;
599     farcall16(&br);
600 }
601
602 // Boot from a disk (either floppy or harddrive)
603 static void
604 boot_disk(u8 bootdrv, int checksig)
605 {
606     u16 bootseg = 0x07c0;
607
608     // Read sector
609     struct bregs br;
610     memset(&br, 0, sizeof(br));
611     br.flags = F_IF;
612     br.dl = bootdrv;
613     br.es = bootseg;
614     br.ah = 2;
615     br.al = 1;
616     br.cl = 1;
617     call16_int(0x13, &br);
618
619     if (br.flags & F_CF) {
620         printf("Boot failed: could not read the boot disk\n\n");
621         return;
622     }
623
624     if (checksig) {
625         struct mbr_s *mbr = (void*)0;
626         if (GET_FARVAR(bootseg, mbr->signature) != MBR_SIGNATURE) {
627             printf("Boot failed: not a bootable disk\n\n");
628             return;
629         }
630     }
631
632     tpm_add_bcv(bootdrv, MAKE_FLATPTR(bootseg, 0), 512);
633
634     /* Canonicalize bootseg:bootip */
635     u16 bootip = (bootseg & 0x0fff) << 4;
636     bootseg &= 0xf000;
637
638     call_boot_entry(SEGOFF(bootseg, bootip), bootdrv);
639 }
640
641 // Boot from a CD-ROM
642 static void
643 boot_cdrom(struct drive_s *drive_g)
644 {
645     if (! CONFIG_CDROM_BOOT)
646         return;
647     printf("Booting from DVD/CD...\n");
648
649     int status = cdrom_boot(drive_g);
650     if (status) {
651         printf("Boot failed: Could not read from CDROM (code %04x)\n", status);
652         return;
653     }
654
655     u8 bootdrv = CDEmu.emulated_drive;
656     u16 bootseg = CDEmu.load_segment;
657
658     tpm_add_cdrom(bootdrv, MAKE_FLATPTR(bootseg, 0), 512);
659
660     /* Canonicalize bootseg:bootip */
661     u16 bootip = (bootseg & 0x0fff) << 4;
662     bootseg &= 0xf000;
663
664     call_boot_entry(SEGOFF(bootseg, bootip), bootdrv);
665 }
666
667 // Boot from a CBFS payload
668 static void
669 boot_cbfs(struct cbfs_file *file)
670 {
671     if (!CONFIG_COREBOOT_FLASH)
672         return;
673     printf("Booting from CBFS...\n");
674     cbfs_run_payload(file);
675 }
676
677 // Boot from a BEV entry on an optionrom.
678 static void
679 boot_rom(u32 vector)
680 {
681     printf("Booting from ROM...\n");
682     struct segoff_s so;
683     so.segoff = vector;
684     call_boot_entry(so, 0);
685 }
686
687 // Unable to find bootable device - warn user and eventually retry.
688 static void
689 boot_fail(void)
690 {
691     if (BootRetryTime == (u32)-1)
692         printf("No bootable device.\n");
693     else
694         printf("No bootable device.  Retrying in %d seconds.\n"
695                , BootRetryTime/1000);
696     // Wait for 'BootRetryTime' milliseconds and then reboot.
697     u32 end = irqtimer_calc(BootRetryTime);
698     for (;;) {
699         if (BootRetryTime != (u32)-1 && irqtimer_check(end))
700             break;
701         yield_toirq();
702     }
703     printf("Rebooting.\n");
704     reset();
705 }
706
707 // Determine next boot method and attempt a boot using it.
708 static void
709 do_boot(int seq_nr)
710 {
711     if (! CONFIG_BOOT)
712         panic("Boot support not compiled in.\n");
713
714     if (seq_nr >= BEVCount)
715         boot_fail();
716
717     // Boot the given BEV type.
718     struct bev_s *ie = &BEV[seq_nr];
719     switch (ie->type) {
720     case IPL_TYPE_FLOPPY:
721         printf("Booting from Floppy...\n");
722         boot_disk(0x00, CheckFloppySig);
723         break;
724     case IPL_TYPE_HARDDISK:
725         printf("Booting from Hard Disk...\n");
726         boot_disk(0x80, 1);
727         break;
728     case IPL_TYPE_CDROM:
729         boot_cdrom((void*)ie->vector);
730         break;
731     case IPL_TYPE_CBFS:
732         boot_cbfs((void*)ie->vector);
733         break;
734     case IPL_TYPE_BEV:
735         boot_rom(ie->vector);
736         break;
737     case IPL_TYPE_HALT:
738         boot_fail();
739         break;
740     }
741
742     // Boot failed: invoke the boot recovery function
743     struct bregs br;
744     memset(&br, 0, sizeof(br));
745     br.flags = F_IF;
746     call16_int(0x18, &br);
747 }
748
749 int BootSequence VARLOW = -1;
750
751 // Boot Failure recovery: try the next device.
752 void VISIBLE32FLAT
753 handle_18(void)
754 {
755     debug_enter(NULL, DEBUG_HDL_18);
756     int seq = BootSequence + 1;
757     BootSequence = seq;
758     do_boot(seq);
759 }
760
761 // INT 19h Boot Load Service Entry Point
762 void VISIBLE32FLAT
763 handle_19(void)
764 {
765     debug_enter(NULL, DEBUG_HDL_19);
766     BootSequence = 0;
767     do_boot(0);
768 }