blob: a251eb4938f70b9c46958d66698e6d2d51b4b211 [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'Connor0ac5e9e2013-09-14 13:09:27 -04003// Copyright (C) 2008-2013 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'Connor135f3f62013-09-14 23:57:26 -04008#include "block.h" // struct drive_s
Kevin O'Connor2d2fa312013-09-14 21:55:26 -04009#include "bregs.h" // struct bregs
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050010#include "config.h" // CONFIG_*
Kevin O'Connorccee6e82013-09-02 21:25:21 -040011#include "fw/paravirt.h" // qemu_cfg_show_boot_menu
Kevin O'Connor5d369d82013-09-02 20:48:46 -040012#include "hw/pci.h" // pci_bdf_to_*
Kevin O'Connor8b7861c2013-09-15 02:29:06 -040013#include "hw/rtc.h" // rtc_read
Kevin O'Connor5d369d82013-09-02 20:48:46 -040014#include "hw/usb.h" // struct usbdevice_s
Kevin O'Connor446defb2013-06-08 21:50:53 -040015#include "list.h" // hlist_node
Kevin O'Connor9dea5902013-09-14 20:23:54 -040016#include "malloc.h" // free
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040017#include "output.h" // dprintf
Kevin O'Connor41639f82013-09-14 19:37:36 -040018#include "romfile.h" // romfile_loadint
Kevin O'Connor135f3f62013-09-14 23:57:26 -040019#include "std/disk.h" // struct mbr_s
Kevin O'Connorfa9c66a2013-09-14 19:10:40 -040020#include "string.h" // memset
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040021#include "util.h" // irqtimer_calc
Stefan Berger2aff1c12015-05-26 15:48:33 -040022#include "tcgbios.h" // tpm_*
Kevin O'Connorc659fde2008-12-28 23:43:20 -050023
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050024
25/****************************************************************
Kevin O'Connor031ef552010-12-27 19:26:57 -050026 * Boot priority ordering
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050027 ****************************************************************/
28
Kevin O'Connor70c94dd2013-03-08 19:39:49 -050029static char **Bootorder VARVERIFY32INIT;
Kevin O'Connor3da2c1c2010-12-29 11:37:41 -050030static int BootorderCount;
31
Kevin O'Connord1a17462010-12-24 11:17:03 -050032static void
33loadBootOrder(void)
34{
Kevin O'Connor49bf57b2011-05-10 22:08:30 -040035 if (!CONFIG_BOOTORDER)
36 return;
37
Kevin O'Connord1a17462010-12-24 11:17:03 -050038 char *f = romfile_loadfile("bootorder", NULL);
39 if (!f)
40 return;
41
Kevin O'Connor8bf55032011-01-01 11:00:42 -050042 int i = 0;
Kevin O'Connor3da2c1c2010-12-29 11:37:41 -050043 BootorderCount = 1;
Kevin O'Connord1a17462010-12-24 11:17:03 -050044 while (f[i]) {
45 if (f[i] == '\n')
Kevin O'Connor3da2c1c2010-12-29 11:37:41 -050046 BootorderCount++;
Kevin O'Connord1a17462010-12-24 11:17:03 -050047 i++;
48 }
Kevin O'Connor3da2c1c2010-12-29 11:37:41 -050049 Bootorder = malloc_tmphigh(BootorderCount*sizeof(char*));
50 if (!Bootorder) {
Kevin O'Connord1a17462010-12-24 11:17:03 -050051 warn_noalloc();
52 free(f);
Kevin O'Connor4d0c5922011-01-26 21:04:01 -050053 BootorderCount = 0;
Kevin O'Connord1a17462010-12-24 11:17:03 -050054 return;
55 }
56
Gerd Hoffmannf5beab42013-12-06 10:29:09 +010057 dprintf(1, "boot order:\n");
Kevin O'Connord1a17462010-12-24 11:17:03 -050058 i = 0;
59 do {
Kevin O'Connor3da2c1c2010-12-29 11:37:41 -050060 Bootorder[i] = f;
Kevin O'Connord1a17462010-12-24 11:17:03 -050061 f = strchr(f, '\n');
Kevin O'Connor8bf55032011-01-01 11:00:42 -050062 if (f)
63 *(f++) = '\0';
Kevin O'Connord15b0102014-01-31 19:38:36 -050064 Bootorder[i] = nullTrailingSpace(Bootorder[i]);
Gerd Hoffmannf5beab42013-12-06 10:29:09 +010065 dprintf(1, "%d: %s\n", i+1, Bootorder[i]);
Kevin O'Connor8bf55032011-01-01 11:00:42 -050066 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.
73static char *
74glob_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;
Kevin O'Connord1a17462010-12-24 11:17:03 -050085 }
Kevin O'Connor8bf55032011-01-01 11:00:42 -050086 if (*glob != *str)
87 return NULL;
88 glob++;
89 str++;
90 }
91}
92
93// Search the bootorder list for the given glob pattern.
94static int
95find_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
Kevin O'Connor659c99d2011-06-20 23:29:15 -0400107static char *
108build_pci_path(char *buf, int max, const char *devname, struct pci_device *pci)
109{
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500110 // Build the string path of a bdf - for example: /pci@i0cf8/isa@1,2
111 char *p = buf;
Kevin O'Connor659c99d2011-06-20 23:29:15 -0400112 if (pci->parent) {
113 p = build_pci_path(p, max, "pci-bridge", pci->parent);
Kevin O'Connord08eb9c2011-01-10 00:48:45 -0500114 } else {
Kevin O'Connord08eb9c2011-01-10 00:48:45 -0500115 p += snprintf(p, buf+max-p, "%s", FW_PCI_DOMAIN);
Kevin O'Connor1202f032015-06-30 11:07:58 -0400116 if (pci->rootbus)
117 p += snprintf(p, buf+max-p, ",%x", pci->rootbus);
Kevin O'Connord08eb9c2011-01-10 00:48:45 -0500118 }
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500119
Kevin O'Connor659c99d2011-06-20 23:29:15 -0400120 int dev = pci_bdf_to_dev(pci->bdf), fn = pci_bdf_to_fn(pci->bdf);
Kevin O'Connord08eb9c2011-01-10 00:48:45 -0500121 p += snprintf(p, buf+max-p, "/%s@%x", devname, dev);
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500122 if (fn)
123 p += snprintf(p, buf+max-p, ",%x", fn);
124 return p;
Kevin O'Connord1a17462010-12-24 11:17:03 -0500125}
126
Kevin O'Connordc3a7d62011-07-09 14:33:56 -0400127int bootprio_find_pci_device(struct pci_device *pci)
Kevin O'Connor031ef552010-12-27 19:26:57 -0500128{
David Woodhouse118469a2013-01-25 19:46:25 -0600129 if (CONFIG_CSM)
130 return csm_bootprio_pci(pci);
Kevin O'Connor49bf57b2011-05-10 22:08:30 -0400131 if (!CONFIG_BOOTORDER)
132 return -1;
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500133 // Find pci device - for example: /pci@i0cf8/ethernet@5
134 char desc[256];
Kevin O'Connordc3a7d62011-07-09 14:33:56 -0400135 build_pci_path(desc, sizeof(desc), "*", pci);
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500136 return find_prio(desc);
Kevin O'Connor031ef552010-12-27 19:26:57 -0500137}
138
Paolo Bonzinic5c488f2012-02-27 17:22:23 +0100139int 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);
Markus Armbruster275672e2014-08-15 08:58:17 +0200149 snprintf(p, desc+sizeof(desc)-p, "/*@0/*@%x,%x", target, lun);
Paolo Bonzinic5c488f2012-02-27 17:22:23 +0100150 return find_prio(desc);
151}
152
Kevin O'Connor95b2e0c2011-07-09 14:42:11 -0400153int bootprio_find_ata_device(struct pci_device *pci, int chanid, int slave)
Kevin O'Connor031ef552010-12-27 19:26:57 -0500154{
David Woodhouse118469a2013-01-25 19:46:25 -0600155 if (CONFIG_CSM)
156 return csm_bootprio_ata(pci, chanid, slave);
Kevin O'Connor49bf57b2011-05-10 22:08:30 -0400157 if (!CONFIG_BOOTORDER)
158 return -1;
Kevin O'Connor95b2e0c2011-07-09 14:42:11 -0400159 if (!pci)
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500160 // 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;
Kevin O'Connor95b2e0c2011-07-09 14:42:11 -0400164 p = build_pci_path(desc, sizeof(desc), "*", pci);
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500165 snprintf(p, desc+sizeof(desc)-p, "/drive@%x/disk@%x", chanid, slave);
166 return find_prio(desc);
Kevin O'Connor031ef552010-12-27 19:26:57 -0500167}
168
Kevin O'Connor03e589c2011-07-09 14:35:37 -0400169int bootprio_find_fdc_device(struct pci_device *pci, int port, int fdid)
Kevin O'Connor031ef552010-12-27 19:26:57 -0500170{
David Woodhouse118469a2013-01-25 19:46:25 -0600171 if (CONFIG_CSM)
172 return csm_bootprio_fdc(pci, port, fdid);
Kevin O'Connor49bf57b2011-05-10 22:08:30 -0400173 if (!CONFIG_BOOTORDER)
174 return -1;
Kevin O'Connor03e589c2011-07-09 14:35:37 -0400175 if (!pci)
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500176 // 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;
Kevin O'Connor03e589c2011-07-09 14:35:37 -0400180 p = build_pci_path(desc, sizeof(desc), "isa", pci);
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500181 snprintf(p, desc+sizeof(desc)-p, "/fdc@%04x/floppy@%x", port, fdid);
182 return find_prio(desc);
Kevin O'Connor031ef552010-12-27 19:26:57 -0500183}
184
Kevin O'Connorfce91892011-07-09 14:47:47 -0400185int bootprio_find_pci_rom(struct pci_device *pci, int instance)
Kevin O'Connor031ef552010-12-27 19:26:57 -0500186{
Kevin O'Connor49bf57b2011-05-10 22:08:30 -0400187 if (!CONFIG_BOOTORDER)
188 return -1;
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500189 // Find pci rom - for example: /pci@i0cf8/scsi@3:rom2
190 char desc[256], *p;
Kevin O'Connorfce91892011-07-09 14:47:47 -0400191 p = build_pci_path(desc, sizeof(desc), "*", pci);
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500192 if (instance)
Kevin O'Connore7104472014-08-15 09:52:43 -0400193 snprintf(p, desc+sizeof(desc)-p, ":rom%x", instance);
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500194 return find_prio(desc);
Kevin O'Connor031ef552010-12-27 19:26:57 -0500195}
196
197int bootprio_find_named_rom(const char *name, int instance)
198{
Kevin O'Connor49bf57b2011-05-10 22:08:30 -0400199 if (!CONFIG_BOOTORDER)
200 return -1;
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500201 // 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)
Kevin O'Connore7104472014-08-15 09:52:43 -0400205 snprintf(p, desc+sizeof(desc)-p, ":rom%x", instance);
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500206 return find_prio(desc);
Kevin O'Connor031ef552010-12-27 19:26:57 -0500207}
208
Kevin O'Connorea274782012-03-08 07:49:09 -0500209static char *
210build_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
Kevin O'Connor7fa31b52012-06-13 08:47:03 -0400220int bootprio_find_usb(struct usbdevice_s *usbdev, int lun)
Kevin O'Connorc2002a12010-12-31 14:38:10 -0500221{
Kevin O'Connor49bf57b2011-05-10 22:08:30 -0400222 if (!CONFIG_BOOTORDER)
223 return -1;
Kevin O'Connor7fa31b52012-06-13 08:47:03 -0400224 // Find usb - for example: /pci@i0cf8/usb@1,2/storage@1/channel@0/disk@0,0
Kevin O'Connorc2002a12010-12-31 14:38:10 -0500225 char desc[256], *p;
Kevin O'Connorea274782012-03-08 07:49:09 -0500226 p = build_pci_path(desc, sizeof(desc), "usb", usbdev->hub->cntl->pci);
227 p = build_usb_path(p, desc+sizeof(desc)-p, usbdev->hub);
Markus Armbruster275672e2014-08-15 08:58:17 +0200228 snprintf(p, desc+sizeof(desc)-p, "/storage@%x/*@0/*@0,%x"
Kevin O'Connor7fa31b52012-06-13 08:47:03 -0400229 , 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);
Kevin O'Connorc2002a12010-12-31 14:38:10 -0500235 return find_prio(desc);
236}
237
Kevin O'Connor031ef552010-12-27 19:26:57 -0500238
239/****************************************************************
240 * Boot setup
241 ****************************************************************/
242
Kevin O'Connor11a72342013-03-05 17:52:21 +0800243static int BootRetryTime;
Kevin O'Connorbaaadb62010-12-29 11:18:04 -0500244static int CheckFloppySig = 1;
245
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500246#define DEFAULT_PRIO 9999
247
248static int DefaultFloppyPrio = 101;
249static int DefaultCDPrio = 102;
250static int DefaultHDPrio = 103;
251static int DefaultBEVPrio = 104;
252
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500253void
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500254boot_init(void)
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500255{
256 if (! CONFIG_BOOT)
257 return;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500258
Kevin O'Connor897fb112013-02-07 23:32:48 -0500259 if (CONFIG_QEMU) {
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500260 // On emulators, get boot order from nvram.
Kevin O'Connor8b7861c2013-09-15 02:29:06 -0400261 if (rtc_read(CMOS_BIOS_BOOTFLAG1) & 1)
Kevin O'Connorbaaadb62010-12-29 11:18:04 -0500262 CheckFloppySig = 0;
Kevin O'Connor8b7861c2013-09-15 02:29:06 -0400263 u32 bootorder = (rtc_read(CMOS_BIOS_BOOTFLAG2)
264 | ((rtc_read(CMOS_BIOS_BOOTFLAG1) & 0xf0) << 4));
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500265 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 }
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500278 }
Gleb Natapovb9a75912010-12-23 11:29:38 +0200279
Kevin O'Connor11a72342013-03-05 17:52:21 +0800280 BootRetryTime = romfile_loadint("etc/boot-fail-wait", 60*1000);
281
Kevin O'Connord1a17462010-12-24 11:17:03 -0500282 loadBootOrder();
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500283}
284
Kevin O'Connord1a17462010-12-24 11:17:03 -0500285
286/****************************************************************
Kevin O'Connor031ef552010-12-27 19:26:57 -0500287 * BootList handling
Kevin O'Connord1a17462010-12-24 11:17:03 -0500288 ****************************************************************/
289
Kevin O'Connor031ef552010-12-27 19:26:57 -0500290struct 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;
Kevin O'Connor446defb2013-06-08 21:50:53 -0400299 struct hlist_node node;
Kevin O'Connor031ef552010-12-27 19:26:57 -0500300};
Kevin O'Connor446defb2013-06-08 21:50:53 -0400301static struct hlist_head BootList VARVERIFY32INIT;
Kevin O'Connor031ef552010-12-27 19:26:57 -0500302
Kevin O'Connor7bb15842010-12-29 11:25:14 -0500303#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
Kevin O'Connor54ae5432013-01-12 16:36:11 -0500309#define IPL_TYPE_HALT 0xf0
Kevin O'Connor7bb15842010-12-29 11:25:14 -0500310
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500311static void
312bootentry_add(int type, int prio, u32 data, const char *desc)
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500313{
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500314 if (! CONFIG_BOOT)
315 return;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500316 struct bootentry_s *be = malloc_tmp(sizeof(*be));
317 if (!be) {
318 warn_noalloc();
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500319 return;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500320 }
321 be->type = type;
322 be->priority = prio;
323 be->data = data;
Kevin O'Connorca2bc1c2010-12-29 21:41:19 -0500324 be->description = desc ?: "?";
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500325 dprintf(3, "Registering bootable: %s (type:%d prio:%d data:%x)\n"
326 , be->description, type, prio, data);
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500327
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500328 // Add entry in sorted order.
Kevin O'Connor446defb2013-06-08 21:50:53 -0400329 struct hlist_node **pprev;
330 struct bootentry_s *pos;
Kevin O'Connor030a58a2013-06-13 21:24:14 -0400331 hlist_for_each_entry_pprev(pos, pprev, &BootList, node) {
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500332 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 }
Kevin O'Connor446defb2013-06-08 21:50:53 -0400346 hlist_add(&be->node, pprev);
Kevin O'Connor0a924122009-02-08 19:43:47 -0500347}
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500348
Kevin O'Connor031ef552010-12-27 19:26:57 -0500349// Return the given priority if it's set - defaultprio otherwise.
350static inline int defPrio(int priority, int defaultprio) {
351 return (priority < 0) ? defaultprio : priority;
352}
353
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500354// Add a BEV vector for a given pnp compatible option rom.
Gleb Natapov4c90a202010-12-07 13:50:54 +0200355void
Kevin O'Connor031ef552010-12-27 19:26:57 -0500356boot_add_bev(u16 seg, u16 bev, u16 desc, int prio)
Gleb Natapov4c90a202010-12-07 13:50:54 +0200357{
Kevin O'Connor031ef552010-12-27 19:26:57 -0500358 bootentry_add(IPL_TYPE_BEV, defPrio(prio, DefaultBEVPrio)
359 , SEGOFF(seg, bev).segoff
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500360 , desc ? MAKE_FLATPTR(seg, desc) : "Unknown");
361 DefaultBEVPrio = DEFAULT_PRIO;
Gleb Natapov4c90a202010-12-07 13:50:54 +0200362}
363
Kevin O'Connor0a924122009-02-08 19:43:47 -0500364// Add a bcv entry for an expansion card harddrive or legacy option rom
365void
Kevin O'Connor031ef552010-12-27 19:26:57 -0500366boot_add_bcv(u16 seg, u16 ip, u16 desc, int prio)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500367{
Kevin O'Connor88e745e2012-01-14 11:58:14 -0500368 bootentry_add(IPL_TYPE_BCV, defPrio(prio, DefaultHDPrio)
Kevin O'Connor031ef552010-12-27 19:26:57 -0500369 , SEGOFF(seg, ip).segoff
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500370 , desc ? MAKE_FLATPTR(seg, desc) : "Legacy option rom");
Kevin O'Connor0a924122009-02-08 19:43:47 -0500371}
372
Kevin O'Connor0a924122009-02-08 19:43:47 -0500373void
Kevin O'Connorca2bc1c2010-12-29 21:41:19 -0500374boot_add_floppy(struct drive_s *drive_g, const char *desc, int prio)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500375{
Kevin O'Connor031ef552010-12-27 19:26:57 -0500376 bootentry_add(IPL_TYPE_FLOPPY, defPrio(prio, DefaultFloppyPrio)
Kevin O'Connorca2bc1c2010-12-29 21:41:19 -0500377 , (u32)drive_g, desc);
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500378}
Kevin O'Connor0a924122009-02-08 19:43:47 -0500379
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500380void
Kevin O'Connorca2bc1c2010-12-29 21:41:19 -0500381boot_add_hd(struct drive_s *drive_g, const char *desc, int prio)
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500382{
Kevin O'Connor031ef552010-12-27 19:26:57 -0500383 bootentry_add(IPL_TYPE_HARDDISK, defPrio(prio, DefaultHDPrio)
Kevin O'Connorca2bc1c2010-12-29 21:41:19 -0500384 , (u32)drive_g, desc);
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500385}
386
387void
Kevin O'Connorca2bc1c2010-12-29 21:41:19 -0500388boot_add_cd(struct drive_s *drive_g, const char *desc, int prio)
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500389{
Kevin O'Connor031ef552010-12-27 19:26:57 -0500390 bootentry_add(IPL_TYPE_CDROM, defPrio(prio, DefaultCDPrio)
Kevin O'Connorca2bc1c2010-12-29 21:41:19 -0500391 , (u32)drive_g, desc);
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500392}
393
394// Add a CBFS payload entry
395void
Kevin O'Connor031ef552010-12-27 19:26:57 -0500396boot_add_cbfs(void *data, const char *desc, int prio)
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500397{
Kevin O'Connor031ef552010-12-27 19:26:57 -0500398 bootentry_add(IPL_TYPE_CBFS, defPrio(prio, DEFAULT_PRIO), (u32)data, desc);
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500399}
400
401
402/****************************************************************
Kevin O'Connor0ac5e9e2013-09-14 13:09:27 -0400403 * Keyboard calls
404 ****************************************************************/
405
406// See if a keystroke is pending in the keyboard buffer.
407static int
408check_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.
419static int
420get_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.
Stefan Berger320df852015-11-30 11:14:19 -0500430int
Kevin O'Connor0ac5e9e2013-09-14 13:09:27 -0400431get_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/****************************************************************
Kevin O'Connor0a924122009-02-08 19:43:47 -0500445 * Boot menu and BCV execution
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500446 ****************************************************************/
447
Kevin O'Connor73023002011-07-05 20:34:34 -0400448#define DEFAULT_BOOTMENU_WAIT 2500
449
Kevin O'Connor0a924122009-02-08 19:43:47 -0500450// Show IPL option menu.
Kevin O'Connor8a0a9722013-01-21 01:53:31 -0500451void
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500452interactive_bootmenu(void)
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500453{
Kevin O'Connor8a0a9722013-01-21 01:53:31 -0500454 // XXX - show available drives?
455
Kevin O'Connor56c50892013-02-09 19:25:51 -0500456 if (! CONFIG_BOOTMENU || !romfile_loadint("etc/show-boot-menu", 1))
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500457 return;
458
459 while (get_keystroke(0) >= 0)
460 ;
461
Kevin O'Connor129f11e2013-08-02 14:13:50 -0400462 char *bootmsg = romfile_loadfile("etc/boot-menu-message", NULL);
Paolo Bonzinia1ac8862015-03-12 18:12:24 +0100463 int menukey = romfile_loadint("etc/boot-menu-key", 1);
464 printf("%s", bootmsg ?: "\nPress ESC for boot menu.\n\n");
Kevin O'Connor129f11e2013-08-02 14:13:50 -0400465 free(bootmsg);
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500466
Kevin O'Connor73023002011-07-05 20:34:34 -0400467 u32 menutime = romfile_loadint("etc/boot-menu-wait", DEFAULT_BOOTMENU_WAIT);
Kevin O'Connor9a01a9c2010-08-25 21:07:48 -0400468 enable_bootsplash();
Kevin O'Connor73023002011-07-05 20:34:34 -0400469 int scan_code = get_keystroke(menutime);
Kevin O'Connor9a01a9c2010-08-25 21:07:48 -0400470 disable_bootsplash();
Kevin O'Connor129f11e2013-08-02 14:13:50 -0400471 if (scan_code != menukey)
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500472 return;
473
474 while (get_keystroke(0) >= 0)
475 ;
476
477 printf("Select boot device:\n\n");
Kevin O'Connore438b0c2010-05-01 12:20:33 -0400478 wait_threads();
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500479
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500480 // Show menu items
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500481 int maxmenu = 0;
Kevin O'Connor446defb2013-06-08 21:50:53 -0400482 struct bootentry_s *pos;
483 hlist_for_each_entry(pos, &BootList, node) {
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500484 char desc[60];
485 maxmenu++;
486 printf("%d. %s\n", maxmenu
487 , strtcpy(desc, pos->description, ARRAY_SIZE(desc)));
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500488 }
Stefan Berger320df852015-11-30 11:14:19 -0500489 if (tpm_is_working()) {
490 printf("\nt. TPM Configuration\n");
491 }
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500492
Paolo Bonzini80aae262015-03-12 18:12:23 +0100493 // Get key press. If the menu key is ESC, do not restart boot unless
494 // 1.5 seconds have passed. Otherwise users (trained by years of
495 // repeatedly hitting keys to enter the BIOS) will end up hitting ESC
496 // multiple times and immediately booting the primary boot device.
497 int esc_accepted_time = irqtimer_calc(menukey == 1 ? 1500 : 0);
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500498 for (;;) {
499 scan_code = get_keystroke(1000);
Paolo Bonzini80aae262015-03-12 18:12:23 +0100500 if (scan_code == 1 && !irqtimer_check(esc_accepted_time))
501 continue;
Stefan Berger320df852015-11-30 11:14:19 -0500502 if (tpm_is_working() && scan_code == 20 /* t */) {
503 printf("\n");
504 tpm_menu();
505 }
Kevin O'Connor551caa22010-12-29 13:25:18 -0500506 if (scan_code >= 1 && scan_code <= maxmenu+1)
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500507 break;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500508 }
509 printf("\n");
Kevin O'Connor551caa22010-12-29 13:25:18 -0500510 if (scan_code == 0x01)
511 // ESC
512 return;
513
514 // Find entry and make top priority.
515 int choice = scan_code - 1;
Kevin O'Connor446defb2013-06-08 21:50:53 -0400516 hlist_for_each_entry(pos, &BootList, node) {
517 if (! --choice)
518 break;
519 }
520 hlist_del(&pos->node);
Kevin O'Connor551caa22010-12-29 13:25:18 -0500521 pos->priority = 0;
Kevin O'Connor446defb2013-06-08 21:50:53 -0400522 hlist_add_head(&pos->node, &BootList);
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500523}
524
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500525// BEV (Boot Execution Vector) list
Kevin O'Connor7bb15842010-12-29 11:25:14 -0500526struct bev_s {
527 int type;
528 u32 vector;
529};
530static struct bev_s BEV[20];
531static int BEVCount;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500532static int HaveHDBoot, HaveFDBoot;
533
Kevin O'Connor0a924122009-02-08 19:43:47 -0500534static void
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500535add_bev(int type, u32 vector)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500536{
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500537 if (type == IPL_TYPE_HARDDISK && HaveHDBoot++)
538 return;
539 if (type == IPL_TYPE_FLOPPY && HaveFDBoot++)
540 return;
Kevin O'Connor7bb15842010-12-29 11:25:14 -0500541 if (BEVCount >= ARRAY_SIZE(BEV))
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500542 return;
Kevin O'Connor7bb15842010-12-29 11:25:14 -0500543 struct bev_s *bev = &BEV[BEVCount++];
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500544 bev->type = type;
545 bev->vector = vector;
Kevin O'Connor0a924122009-02-08 19:43:47 -0500546}
547
548// Prepare for boot - show menu and run bcvs.
549void
Kevin O'Connor8a0a9722013-01-21 01:53:31 -0500550bcv_prepboot(void)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500551{
Kevin O'Connor8a0a9722013-01-21 01:53:31 -0500552 if (! CONFIG_BOOT)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500553 return;
Kevin O'Connor0a924122009-02-08 19:43:47 -0500554
Kevin O'Connor54ae5432013-01-12 16:36:11 -0500555 int haltprio = find_prio("HALT");
556 if (haltprio >= 0)
557 bootentry_add(IPL_TYPE_HALT, haltprio, 0, "HALT");
558
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500559 // Map drives and populate BEV list
Kevin O'Connor446defb2013-06-08 21:50:53 -0400560 struct bootentry_s *pos;
561 hlist_for_each_entry(pos, &BootList, node) {
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500562 switch (pos->type) {
563 case IPL_TYPE_BCV:
564 call_bcv(pos->vector.seg, pos->vector.offset);
565 add_bev(IPL_TYPE_HARDDISK, 0);
566 break;
567 case IPL_TYPE_FLOPPY:
568 map_floppy_drive(pos->drive);
569 add_bev(IPL_TYPE_FLOPPY, 0);
570 break;
571 case IPL_TYPE_HARDDISK:
572 map_hd_drive(pos->drive);
573 add_bev(IPL_TYPE_HARDDISK, 0);
574 break;
575 case IPL_TYPE_CDROM:
576 map_cd_drive(pos->drive);
577 // NO BREAK
578 default:
579 add_bev(pos->type, pos->data);
580 break;
581 }
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500582 }
Kevin O'Connorafd05202009-08-16 12:21:44 -0400583
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500584 // If nothing added a floppy/hd boot - add it manually.
585 add_bev(IPL_TYPE_FLOPPY, 0);
586 add_bev(IPL_TYPE_HARDDISK, 0);
Kevin O'Connor0a924122009-02-08 19:43:47 -0500587}
588
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500589
590/****************************************************************
591 * Boot code (int 18/19)
592 ****************************************************************/
593
Kevin O'Connor0a924122009-02-08 19:43:47 -0500594// Jump to a bootup entry point.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500595static void
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500596call_boot_entry(struct segoff_s bootsegip, u8 bootdrv)
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500597{
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500598 dprintf(1, "Booting from %04x:%04x\n", bootsegip.seg, bootsegip.offset);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500599 struct bregs br;
600 memset(&br, 0, sizeof(br));
Kevin O'Connorf8e800d2009-09-24 21:01:16 -0400601 br.flags = F_IF;
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500602 br.code = bootsegip;
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500603 // Set the magic number in ax and the boot drive in dl.
604 br.dl = bootdrv;
605 br.ax = 0xaa55;
Kevin O'Connorc7ffbac2012-03-25 11:04:10 -0400606 farcall16(&br);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500607}
608
609// Boot from a disk (either floppy or harddrive)
610static void
611boot_disk(u8 bootdrv, int checksig)
612{
613 u16 bootseg = 0x07c0;
614
615 // Read sector
616 struct bregs br;
617 memset(&br, 0, sizeof(br));
Kevin O'Connorf8e800d2009-09-24 21:01:16 -0400618 br.flags = F_IF;
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500619 br.dl = bootdrv;
620 br.es = bootseg;
621 br.ah = 2;
622 br.al = 1;
623 br.cl = 1;
624 call16_int(0x13, &br);
625
626 if (br.flags & F_CF) {
627 printf("Boot failed: could not read the boot disk\n\n");
628 return;
629 }
630
631 if (checksig) {
632 struct mbr_s *mbr = (void*)0;
633 if (GET_FARVAR(bootseg, mbr->signature) != MBR_SIGNATURE) {
634 printf("Boot failed: not a bootable disk\n\n");
635 return;
636 }
637 }
638
Stefan Berger2aff1c12015-05-26 15:48:33 -0400639 tpm_add_bcv(bootdrv, MAKE_FLATPTR(bootseg, 0), 512);
640
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500641 /* Canonicalize bootseg:bootip */
642 u16 bootip = (bootseg & 0x0fff) << 4;
643 bootseg &= 0xf000;
644
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500645 call_boot_entry(SEGOFF(bootseg, bootip), bootdrv);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500646}
647
648// Boot from a CD-ROM
649static void
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500650boot_cdrom(struct drive_s *drive_g)
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500651{
652 if (! CONFIG_CDROM_BOOT)
653 return;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500654 printf("Booting from DVD/CD...\n");
Gleb Natapov4c90a202010-12-07 13:50:54 +0200655
Gleb Natapov4c90a202010-12-07 13:50:54 +0200656 int status = cdrom_boot(drive_g);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500657 if (status) {
Kevin O'Connorecbcf772010-12-29 13:26:01 -0500658 printf("Boot failed: Could not read from CDROM (code %04x)\n", status);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500659 return;
660 }
661
Kevin O'Connor02f76762014-05-10 01:20:46 -0400662 u8 bootdrv = CDEmu.emulated_drive;
Kevin O'Connord3140832012-05-13 22:46:12 -0400663 u16 bootseg = CDEmu.load_segment;
Stefan Berger2aff1c12015-05-26 15:48:33 -0400664
665 tpm_add_cdrom(bootdrv, MAKE_FLATPTR(bootseg, 0), 512);
666
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500667 /* Canonicalize bootseg:bootip */
668 u16 bootip = (bootseg & 0x0fff) << 4;
669 bootseg &= 0xf000;
670
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500671 call_boot_entry(SEGOFF(bootseg, bootip), bootdrv);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500672}
673
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400674// Boot from a CBFS payload
Kevin O'Connor67823442009-04-13 14:14:51 -0400675static void
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500676boot_cbfs(struct cbfs_file *file)
Kevin O'Connor67823442009-04-13 14:14:51 -0400677{
Kevin O'Connor897fb112013-02-07 23:32:48 -0500678 if (!CONFIG_COREBOOT_FLASH)
Kevin O'Connor67823442009-04-13 14:14:51 -0400679 return;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500680 printf("Booting from CBFS...\n");
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500681 cbfs_run_payload(file);
Kevin O'Connor67823442009-04-13 14:14:51 -0400682}
683
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500684// Boot from a BEV entry on an optionrom.
685static void
686boot_rom(u32 vector)
687{
688 printf("Booting from ROM...\n");
689 struct segoff_s so;
690 so.segoff = vector;
691 call_boot_entry(so, 0);
692}
693
Kevin O'Connorb8fcf462012-05-12 22:12:22 -0400694// Unable to find bootable device - warn user and eventually retry.
695static void
696boot_fail(void)
697{
Kevin O'Connor11a72342013-03-05 17:52:21 +0800698 if (BootRetryTime == (u32)-1)
Kevin O'Connorb8fcf462012-05-12 22:12:22 -0400699 printf("No bootable device.\n");
700 else
Kevin O'Connor11a72342013-03-05 17:52:21 +0800701 printf("No bootable device. Retrying in %d seconds.\n"
702 , BootRetryTime/1000);
703 // Wait for 'BootRetryTime' milliseconds and then reboot.
Kevin O'Connor95ee3822013-07-20 18:07:50 -0400704 u32 end = irqtimer_calc(BootRetryTime);
Kevin O'Connorb8fcf462012-05-12 22:12:22 -0400705 for (;;) {
Kevin O'Connor95ee3822013-07-20 18:07:50 -0400706 if (BootRetryTime != (u32)-1 && irqtimer_check(end))
Kevin O'Connorb8fcf462012-05-12 22:12:22 -0400707 break;
Kevin O'Connor94c749c2012-05-28 11:44:02 -0400708 yield_toirq();
Kevin O'Connorb8fcf462012-05-12 22:12:22 -0400709 }
710 printf("Rebooting.\n");
Kevin O'Connor43197a22014-06-06 13:49:33 -0400711 reset();
Kevin O'Connorb8fcf462012-05-12 22:12:22 -0400712}
713
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500714// Determine next boot method and attempt a boot using it.
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500715static void
Kevin O'Connor9d8e0a62012-05-13 12:23:58 -0400716do_boot(int seq_nr)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500717{
Kevin O'Connor40967022008-07-21 22:23:05 -0400718 if (! CONFIG_BOOT)
Kevin O'Connore07e18e2009-02-08 17:07:29 -0500719 panic("Boot support not compiled in.\n");
Kevin O'Connor40967022008-07-21 22:23:05 -0400720
Kevin O'Connorb8fcf462012-05-12 22:12:22 -0400721 if (seq_nr >= BEVCount)
722 boot_fail();
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500723
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500724 // Boot the given BEV type.
Kevin O'Connor7bb15842010-12-29 11:25:14 -0500725 struct bev_s *ie = &BEV[seq_nr];
Kevin O'Connorcadaf0e2010-07-26 23:47:26 -0400726 switch (ie->type) {
Kevin O'Connorf13b0082008-08-17 11:26:42 -0400727 case IPL_TYPE_FLOPPY:
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500728 printf("Booting from Floppy...\n");
Kevin O'Connorbaaadb62010-12-29 11:18:04 -0500729 boot_disk(0x00, CheckFloppySig);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500730 break;
Kevin O'Connorf13b0082008-08-17 11:26:42 -0400731 case IPL_TYPE_HARDDISK:
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500732 printf("Booting from Hard Disk...\n");
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500733 boot_disk(0x80, 1);
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500734 break;
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500735 case IPL_TYPE_CDROM:
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500736 boot_cdrom((void*)ie->vector);
Kevin O'Connor67823442009-04-13 14:14:51 -0400737 break;
738 case IPL_TYPE_CBFS:
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500739 boot_cbfs((void*)ie->vector);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500740 break;
741 case IPL_TYPE_BEV:
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500742 boot_rom(ie->vector);
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500743 break;
Kevin O'Connor54ae5432013-01-12 16:36:11 -0500744 case IPL_TYPE_HALT:
745 boot_fail();
746 break;
Kevin O'Connor180a9592008-03-04 22:50:53 -0500747 }
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500748
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500749 // Boot failed: invoke the boot recovery function
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400750 struct bregs br;
751 memset(&br, 0, sizeof(br));
Kevin O'Connorf8e800d2009-09-24 21:01:16 -0400752 br.flags = F_IF;
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400753 call16_int(0x18, &br);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500754}
755
Kevin O'Connor9d8e0a62012-05-13 12:23:58 -0400756int BootSequence VARLOW = -1;
757
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500758// Boot Failure recovery: try the next device.
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500759void VISIBLE32FLAT
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500760handle_18(void)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500761{
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400762 debug_enter(NULL, DEBUG_HDL_18);
Kevin O'Connor9d8e0a62012-05-13 12:23:58 -0400763 int seq = BootSequence + 1;
764 BootSequence = seq;
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400765 do_boot(seq);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500766}
767
768// INT 19h Boot Load Service Entry Point
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500769void VISIBLE32FLAT
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500770handle_19(void)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500771{
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400772 debug_enter(NULL, DEBUG_HDL_19);
Kevin O'Connor9d8e0a62012-05-13 12:23:58 -0400773 BootSequence = 0;
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400774 do_boot(0);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500775}