blob: ff705fd47f1f22b77320c1bbcee355768fa4371a [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'Connor4d8510c2016-02-03 01:28:20 -050013#include "hw/pcidevice.h" // struct pci_device
Kevin O'Connor8b7861c2013-09-15 02:29:06 -040014#include "hw/rtc.h" // rtc_read
Kevin O'Connor5d369d82013-09-02 20:48:46 -040015#include "hw/usb.h" // struct usbdevice_s
Kevin O'Connor446defb2013-06-08 21:50:53 -040016#include "list.h" // hlist_node
Kevin O'Connor9dea5902013-09-14 20:23:54 -040017#include "malloc.h" // free
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040018#include "output.h" // dprintf
Kevin O'Connor41639f82013-09-14 19:37:36 -040019#include "romfile.h" // romfile_loadint
Kevin O'Connor135f3f62013-09-14 23:57:26 -040020#include "std/disk.h" // struct mbr_s
Kevin O'Connorfa9c66a2013-09-14 19:10:40 -040021#include "string.h" // memset
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040022#include "util.h" // irqtimer_calc
Stefan Berger2aff1c12015-05-26 15:48:33 -040023#include "tcgbios.h" // tpm_*
Kevin O'Connorc659fde2008-12-28 23:43:20 -050024
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050025
26/****************************************************************
Kevin O'Connor031ef552010-12-27 19:26:57 -050027 * Boot priority ordering
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050028 ****************************************************************/
29
Kevin O'Connor70c94dd2013-03-08 19:39:49 -050030static char **Bootorder VARVERIFY32INIT;
Kevin O'Connor3da2c1c2010-12-29 11:37:41 -050031static int BootorderCount;
32
Kevin O'Connord1a17462010-12-24 11:17:03 -050033static void
34loadBootOrder(void)
35{
Kevin O'Connor49bf57b2011-05-10 22:08:30 -040036 if (!CONFIG_BOOTORDER)
37 return;
38
Kevin O'Connord1a17462010-12-24 11:17:03 -050039 char *f = romfile_loadfile("bootorder", NULL);
40 if (!f)
41 return;
42
Kevin O'Connor8bf55032011-01-01 11:00:42 -050043 int i = 0;
Kevin O'Connor3da2c1c2010-12-29 11:37:41 -050044 BootorderCount = 1;
Kevin O'Connord1a17462010-12-24 11:17:03 -050045 while (f[i]) {
46 if (f[i] == '\n')
Kevin O'Connor3da2c1c2010-12-29 11:37:41 -050047 BootorderCount++;
Kevin O'Connord1a17462010-12-24 11:17:03 -050048 i++;
49 }
Kevin O'Connor3da2c1c2010-12-29 11:37:41 -050050 Bootorder = malloc_tmphigh(BootorderCount*sizeof(char*));
51 if (!Bootorder) {
Kevin O'Connord1a17462010-12-24 11:17:03 -050052 warn_noalloc();
53 free(f);
Kevin O'Connor4d0c5922011-01-26 21:04:01 -050054 BootorderCount = 0;
Kevin O'Connord1a17462010-12-24 11:17:03 -050055 return;
56 }
57
Gerd Hoffmannf5beab42013-12-06 10:29:09 +010058 dprintf(1, "boot order:\n");
Kevin O'Connord1a17462010-12-24 11:17:03 -050059 i = 0;
60 do {
Kevin O'Connor3da2c1c2010-12-29 11:37:41 -050061 Bootorder[i] = f;
Kevin O'Connord1a17462010-12-24 11:17:03 -050062 f = strchr(f, '\n');
Kevin O'Connor8bf55032011-01-01 11:00:42 -050063 if (f)
64 *(f++) = '\0';
Kevin O'Connord15b0102014-01-31 19:38:36 -050065 Bootorder[i] = nullTrailingSpace(Bootorder[i]);
Gerd Hoffmannf5beab42013-12-06 10:29:09 +010066 dprintf(1, "%d: %s\n", i+1, Bootorder[i]);
Kevin O'Connor8bf55032011-01-01 11:00:42 -050067 i++;
68 } while (f);
69}
70
71// See if 'str' starts with 'glob' - if glob contains an '*' character
72// it will match any number of characters in str that aren't a '/' or
73// the next glob character.
74static char *
75glob_prefix(const char *glob, const char *str)
76{
77 for (;;) {
78 if (!*glob && (!*str || *str == '/'))
79 return (char*)str;
80 if (*glob == '*') {
81 if (!*str || *str == '/' || *str == glob[1])
82 glob++;
83 else
84 str++;
85 continue;
Kevin O'Connord1a17462010-12-24 11:17:03 -050086 }
Kevin O'Connor8bf55032011-01-01 11:00:42 -050087 if (*glob != *str)
88 return NULL;
89 glob++;
90 str++;
91 }
92}
93
94// Search the bootorder list for the given glob pattern.
95static int
96find_prio(const char *glob)
97{
98 dprintf(1, "Searching bootorder for: %s\n", glob);
99 int i;
100 for (i = 0; i < BootorderCount; i++)
101 if (glob_prefix(glob, Bootorder[i]))
102 return i+1;
103 return -1;
104}
105
106#define FW_PCI_DOMAIN "/pci@i0cf8"
107
Kevin O'Connor659c99d2011-06-20 23:29:15 -0400108static char *
109build_pci_path(char *buf, int max, const char *devname, struct pci_device *pci)
110{
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500111 // Build the string path of a bdf - for example: /pci@i0cf8/isa@1,2
112 char *p = buf;
Kevin O'Connor659c99d2011-06-20 23:29:15 -0400113 if (pci->parent) {
114 p = build_pci_path(p, max, "pci-bridge", pci->parent);
Kevin O'Connord08eb9c2011-01-10 00:48:45 -0500115 } else {
Kevin O'Connord08eb9c2011-01-10 00:48:45 -0500116 p += snprintf(p, buf+max-p, "%s", FW_PCI_DOMAIN);
Kevin O'Connor1202f032015-06-30 11:07:58 -0400117 if (pci->rootbus)
118 p += snprintf(p, buf+max-p, ",%x", pci->rootbus);
Kevin O'Connord08eb9c2011-01-10 00:48:45 -0500119 }
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500120
Kevin O'Connor659c99d2011-06-20 23:29:15 -0400121 int dev = pci_bdf_to_dev(pci->bdf), fn = pci_bdf_to_fn(pci->bdf);
Kevin O'Connord08eb9c2011-01-10 00:48:45 -0500122 p += snprintf(p, buf+max-p, "/%s@%x", devname, dev);
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500123 if (fn)
124 p += snprintf(p, buf+max-p, ",%x", fn);
125 return p;
Kevin O'Connord1a17462010-12-24 11:17:03 -0500126}
127
Kevin O'Connordc3a7d62011-07-09 14:33:56 -0400128int bootprio_find_pci_device(struct pci_device *pci)
Kevin O'Connor031ef552010-12-27 19:26:57 -0500129{
David Woodhouse118469a2013-01-25 19:46:25 -0600130 if (CONFIG_CSM)
131 return csm_bootprio_pci(pci);
Kevin O'Connor49bf57b2011-05-10 22:08:30 -0400132 if (!CONFIG_BOOTORDER)
133 return -1;
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500134 // Find pci device - for example: /pci@i0cf8/ethernet@5
135 char desc[256];
Kevin O'Connordc3a7d62011-07-09 14:33:56 -0400136 build_pci_path(desc, sizeof(desc), "*", pci);
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500137 return find_prio(desc);
Kevin O'Connor031ef552010-12-27 19:26:57 -0500138}
139
Paolo Bonzinic5c488f2012-02-27 17:22:23 +0100140int bootprio_find_scsi_device(struct pci_device *pci, int target, int lun)
141{
142 if (!CONFIG_BOOTORDER)
143 return -1;
144 if (!pci)
145 // support only pci machine for now
146 return -1;
147 // Find scsi drive - for example: /pci@i0cf8/scsi@5/channel@0/disk@1,0
148 char desc[256], *p;
149 p = build_pci_path(desc, sizeof(desc), "*", pci);
Markus Armbruster275672e2014-08-15 08:58:17 +0200150 snprintf(p, desc+sizeof(desc)-p, "/*@0/*@%x,%x", target, lun);
Paolo Bonzinic5c488f2012-02-27 17:22:23 +0100151 return find_prio(desc);
152}
153
Kevin O'Connor95b2e0c2011-07-09 14:42:11 -0400154int bootprio_find_ata_device(struct pci_device *pci, int chanid, int slave)
Kevin O'Connor031ef552010-12-27 19:26:57 -0500155{
David Woodhouse118469a2013-01-25 19:46:25 -0600156 if (CONFIG_CSM)
157 return csm_bootprio_ata(pci, chanid, slave);
Kevin O'Connor49bf57b2011-05-10 22:08:30 -0400158 if (!CONFIG_BOOTORDER)
159 return -1;
Kevin O'Connor95b2e0c2011-07-09 14:42:11 -0400160 if (!pci)
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500161 // support only pci machine for now
162 return -1;
163 // Find ata drive - for example: /pci@i0cf8/ide@1,1/drive@1/disk@0
164 char desc[256], *p;
Kevin O'Connor95b2e0c2011-07-09 14:42:11 -0400165 p = build_pci_path(desc, sizeof(desc), "*", pci);
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500166 snprintf(p, desc+sizeof(desc)-p, "/drive@%x/disk@%x", chanid, slave);
167 return find_prio(desc);
Kevin O'Connor031ef552010-12-27 19:26:57 -0500168}
169
Kevin O'Connor03e589c2011-07-09 14:35:37 -0400170int bootprio_find_fdc_device(struct pci_device *pci, int port, int fdid)
Kevin O'Connor031ef552010-12-27 19:26:57 -0500171{
David Woodhouse118469a2013-01-25 19:46:25 -0600172 if (CONFIG_CSM)
173 return csm_bootprio_fdc(pci, port, fdid);
Kevin O'Connor49bf57b2011-05-10 22:08:30 -0400174 if (!CONFIG_BOOTORDER)
175 return -1;
Kevin O'Connor03e589c2011-07-09 14:35:37 -0400176 if (!pci)
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500177 // support only pci machine for now
178 return -1;
179 // Find floppy - for example: /pci@i0cf8/isa@1/fdc@03f1/floppy@0
180 char desc[256], *p;
Kevin O'Connor03e589c2011-07-09 14:35:37 -0400181 p = build_pci_path(desc, sizeof(desc), "isa", pci);
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500182 snprintf(p, desc+sizeof(desc)-p, "/fdc@%04x/floppy@%x", port, fdid);
183 return find_prio(desc);
Kevin O'Connor031ef552010-12-27 19:26:57 -0500184}
185
Kevin O'Connorfce91892011-07-09 14:47:47 -0400186int bootprio_find_pci_rom(struct pci_device *pci, int instance)
Kevin O'Connor031ef552010-12-27 19:26:57 -0500187{
Kevin O'Connor49bf57b2011-05-10 22:08:30 -0400188 if (!CONFIG_BOOTORDER)
189 return -1;
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500190 // Find pci rom - for example: /pci@i0cf8/scsi@3:rom2
191 char desc[256], *p;
Kevin O'Connorfce91892011-07-09 14:47:47 -0400192 p = build_pci_path(desc, sizeof(desc), "*", pci);
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500193 if (instance)
Kevin O'Connore7104472014-08-15 09:52:43 -0400194 snprintf(p, desc+sizeof(desc)-p, ":rom%x", instance);
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500195 return find_prio(desc);
Kevin O'Connor031ef552010-12-27 19:26:57 -0500196}
197
198int bootprio_find_named_rom(const char *name, int instance)
199{
Kevin O'Connor49bf57b2011-05-10 22:08:30 -0400200 if (!CONFIG_BOOTORDER)
201 return -1;
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500202 // Find named rom - for example: /rom@genroms/linuxboot.bin
203 char desc[256], *p;
204 p = desc + snprintf(desc, sizeof(desc), "/rom@%s", name);
205 if (instance)
Kevin O'Connore7104472014-08-15 09:52:43 -0400206 snprintf(p, desc+sizeof(desc)-p, ":rom%x", instance);
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500207 return find_prio(desc);
Kevin O'Connor031ef552010-12-27 19:26:57 -0500208}
209
Gerd Hoffmannca9dcc22017-07-18 13:15:25 +0200210static int usb_portmap(struct usbdevice_s *usbdev)
211{
212 if (usbdev->hub->op->portmap)
213 return usbdev->hub->op->portmap(usbdev->hub, usbdev->port);
214 return usbdev->port + 1;
215}
216
Kevin O'Connorea274782012-03-08 07:49:09 -0500217static char *
218build_usb_path(char *buf, int max, struct usbhub_s *hub)
219{
220 if (!hub->usbdev)
221 // Root hub - nothing to add.
222 return buf;
223 char *p = build_usb_path(buf, max, hub->usbdev->hub);
Gerd Hoffmannca9dcc22017-07-18 13:15:25 +0200224 p += snprintf(p, buf+max-p, "/hub@%x", usb_portmap(hub->usbdev));
Kevin O'Connorea274782012-03-08 07:49:09 -0500225 return p;
226}
227
Kevin O'Connor7fa31b52012-06-13 08:47:03 -0400228int bootprio_find_usb(struct usbdevice_s *usbdev, int lun)
Kevin O'Connorc2002a12010-12-31 14:38:10 -0500229{
Kevin O'Connor49bf57b2011-05-10 22:08:30 -0400230 if (!CONFIG_BOOTORDER)
231 return -1;
Kevin O'Connor7fa31b52012-06-13 08:47:03 -0400232 // Find usb - for example: /pci@i0cf8/usb@1,2/storage@1/channel@0/disk@0,0
Kevin O'Connorc2002a12010-12-31 14:38:10 -0500233 char desc[256], *p;
Kevin O'Connorea274782012-03-08 07:49:09 -0500234 p = build_pci_path(desc, sizeof(desc), "usb", usbdev->hub->cntl->pci);
235 p = build_usb_path(p, desc+sizeof(desc)-p, usbdev->hub);
Markus Armbruster275672e2014-08-15 08:58:17 +0200236 snprintf(p, desc+sizeof(desc)-p, "/storage@%x/*@0/*@0,%x"
Gerd Hoffmannca9dcc22017-07-18 13:15:25 +0200237 , usb_portmap(usbdev), lun);
Kevin O'Connor7fa31b52012-06-13 08:47:03 -0400238 int ret = find_prio(desc);
239 if (ret >= 0)
240 return ret;
241 // Try usb-host/redir - for example: /pci@i0cf8/usb@1,2/usb-host@1
Gerd Hoffmannca9dcc22017-07-18 13:15:25 +0200242 snprintf(p, desc+sizeof(desc)-p, "/usb-*@%x", usb_portmap(usbdev));
Kevin O'Connorc2002a12010-12-31 14:38:10 -0500243 return find_prio(desc);
244}
245
Kevin O'Connor031ef552010-12-27 19:26:57 -0500246
247/****************************************************************
248 * Boot setup
249 ****************************************************************/
250
Kevin O'Connor11a72342013-03-05 17:52:21 +0800251static int BootRetryTime;
Kevin O'Connorbaaadb62010-12-29 11:18:04 -0500252static int CheckFloppySig = 1;
253
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500254#define DEFAULT_PRIO 9999
255
256static int DefaultFloppyPrio = 101;
257static int DefaultCDPrio = 102;
258static int DefaultHDPrio = 103;
259static int DefaultBEVPrio = 104;
260
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500261void
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500262boot_init(void)
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500263{
264 if (! CONFIG_BOOT)
265 return;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500266
Kevin O'Connor897fb112013-02-07 23:32:48 -0500267 if (CONFIG_QEMU) {
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500268 // On emulators, get boot order from nvram.
Kevin O'Connor8b7861c2013-09-15 02:29:06 -0400269 if (rtc_read(CMOS_BIOS_BOOTFLAG1) & 1)
Kevin O'Connorbaaadb62010-12-29 11:18:04 -0500270 CheckFloppySig = 0;
Kevin O'Connor8b7861c2013-09-15 02:29:06 -0400271 u32 bootorder = (rtc_read(CMOS_BIOS_BOOTFLAG2)
272 | ((rtc_read(CMOS_BIOS_BOOTFLAG1) & 0xf0) << 4));
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500273 DefaultFloppyPrio = DefaultCDPrio = DefaultHDPrio
274 = DefaultBEVPrio = DEFAULT_PRIO;
275 int i;
276 for (i=101; i<104; i++) {
277 u32 val = bootorder & 0x0f;
278 bootorder >>= 4;
279 switch (val) {
280 case 1: DefaultFloppyPrio = i; break;
281 case 2: DefaultHDPrio = i; break;
282 case 3: DefaultCDPrio = i; break;
283 case 4: DefaultBEVPrio = i; break;
284 }
285 }
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500286 }
Gleb Natapovb9a75912010-12-23 11:29:38 +0200287
Kevin O'Connor11a72342013-03-05 17:52:21 +0800288 BootRetryTime = romfile_loadint("etc/boot-fail-wait", 60*1000);
289
Kevin O'Connord1a17462010-12-24 11:17:03 -0500290 loadBootOrder();
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500291}
292
Kevin O'Connord1a17462010-12-24 11:17:03 -0500293
294/****************************************************************
Kevin O'Connor031ef552010-12-27 19:26:57 -0500295 * BootList handling
Kevin O'Connord1a17462010-12-24 11:17:03 -0500296 ****************************************************************/
297
Kevin O'Connor031ef552010-12-27 19:26:57 -0500298struct bootentry_s {
299 int type;
300 union {
301 u32 data;
302 struct segoff_s vector;
303 struct drive_s *drive;
304 };
305 int priority;
306 const char *description;
Kevin O'Connor446defb2013-06-08 21:50:53 -0400307 struct hlist_node node;
Kevin O'Connor031ef552010-12-27 19:26:57 -0500308};
Kevin O'Connor446defb2013-06-08 21:50:53 -0400309static struct hlist_head BootList VARVERIFY32INIT;
Kevin O'Connor031ef552010-12-27 19:26:57 -0500310
Kevin O'Connor7bb15842010-12-29 11:25:14 -0500311#define IPL_TYPE_FLOPPY 0x01
312#define IPL_TYPE_HARDDISK 0x02
313#define IPL_TYPE_CDROM 0x03
314#define IPL_TYPE_CBFS 0x20
315#define IPL_TYPE_BEV 0x80
316#define IPL_TYPE_BCV 0x81
Kevin O'Connor54ae5432013-01-12 16:36:11 -0500317#define IPL_TYPE_HALT 0xf0
Kevin O'Connor7bb15842010-12-29 11:25:14 -0500318
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500319static void
320bootentry_add(int type, int prio, u32 data, const char *desc)
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500321{
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500322 if (! CONFIG_BOOT)
323 return;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500324 struct bootentry_s *be = malloc_tmp(sizeof(*be));
325 if (!be) {
326 warn_noalloc();
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500327 return;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500328 }
329 be->type = type;
330 be->priority = prio;
331 be->data = data;
Kevin O'Connorca2bc1c2010-12-29 21:41:19 -0500332 be->description = desc ?: "?";
Kevin O'Connor8bf55032011-01-01 11:00:42 -0500333 dprintf(3, "Registering bootable: %s (type:%d prio:%d data:%x)\n"
334 , be->description, type, prio, data);
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500335
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500336 // Add entry in sorted order.
Kevin O'Connor446defb2013-06-08 21:50:53 -0400337 struct hlist_node **pprev;
338 struct bootentry_s *pos;
Kevin O'Connor030a58a2013-06-13 21:24:14 -0400339 hlist_for_each_entry_pprev(pos, pprev, &BootList, node) {
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500340 if (be->priority < pos->priority)
341 break;
342 if (be->priority > pos->priority)
343 continue;
344 if (be->type < pos->type)
345 break;
346 if (be->type > pos->type)
347 continue;
348 if (be->type <= IPL_TYPE_CDROM
349 && (be->drive->type < pos->drive->type
350 || (be->drive->type == pos->drive->type
351 && be->drive->cntl_id < pos->drive->cntl_id)))
352 break;
353 }
Kevin O'Connor446defb2013-06-08 21:50:53 -0400354 hlist_add(&be->node, pprev);
Kevin O'Connor0a924122009-02-08 19:43:47 -0500355}
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500356
Kevin O'Connor031ef552010-12-27 19:26:57 -0500357// Return the given priority if it's set - defaultprio otherwise.
358static inline int defPrio(int priority, int defaultprio) {
359 return (priority < 0) ? defaultprio : priority;
360}
361
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500362// Add a BEV vector for a given pnp compatible option rom.
Gleb Natapov4c90a202010-12-07 13:50:54 +0200363void
Kevin O'Connor031ef552010-12-27 19:26:57 -0500364boot_add_bev(u16 seg, u16 bev, u16 desc, int prio)
Gleb Natapov4c90a202010-12-07 13:50:54 +0200365{
Kevin O'Connor031ef552010-12-27 19:26:57 -0500366 bootentry_add(IPL_TYPE_BEV, defPrio(prio, DefaultBEVPrio)
367 , SEGOFF(seg, bev).segoff
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500368 , desc ? MAKE_FLATPTR(seg, desc) : "Unknown");
369 DefaultBEVPrio = DEFAULT_PRIO;
Gleb Natapov4c90a202010-12-07 13:50:54 +0200370}
371
Kevin O'Connor0a924122009-02-08 19:43:47 -0500372// Add a bcv entry for an expansion card harddrive or legacy option rom
373void
Kevin O'Connor031ef552010-12-27 19:26:57 -0500374boot_add_bcv(u16 seg, u16 ip, u16 desc, int prio)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500375{
Kevin O'Connor88e745e2012-01-14 11:58:14 -0500376 bootentry_add(IPL_TYPE_BCV, defPrio(prio, DefaultHDPrio)
Kevin O'Connor031ef552010-12-27 19:26:57 -0500377 , SEGOFF(seg, ip).segoff
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500378 , desc ? MAKE_FLATPTR(seg, desc) : "Legacy option rom");
Kevin O'Connor0a924122009-02-08 19:43:47 -0500379}
380
Kevin O'Connor0a924122009-02-08 19:43:47 -0500381void
Kevin O'Connor5e9a6d52017-07-11 11:55:49 -0400382boot_add_floppy(struct drive_s *drive, const char *desc, int prio)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500383{
Kevin O'Connor031ef552010-12-27 19:26:57 -0500384 bootentry_add(IPL_TYPE_FLOPPY, defPrio(prio, DefaultFloppyPrio)
Kevin O'Connor5e9a6d52017-07-11 11:55:49 -0400385 , (u32)drive, desc);
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500386}
Kevin O'Connor0a924122009-02-08 19:43:47 -0500387
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500388void
Kevin O'Connor5e9a6d52017-07-11 11:55:49 -0400389boot_add_hd(struct drive_s *drive, const char *desc, int prio)
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500390{
Kevin O'Connor031ef552010-12-27 19:26:57 -0500391 bootentry_add(IPL_TYPE_HARDDISK, defPrio(prio, DefaultHDPrio)
Kevin O'Connor5e9a6d52017-07-11 11:55:49 -0400392 , (u32)drive, desc);
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500393}
394
395void
Kevin O'Connor5e9a6d52017-07-11 11:55:49 -0400396boot_add_cd(struct drive_s *drive, 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_CDROM, defPrio(prio, DefaultCDPrio)
Kevin O'Connor5e9a6d52017-07-11 11:55:49 -0400399 , (u32)drive, desc);
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500400}
401
402// Add a CBFS payload entry
403void
Kevin O'Connor031ef552010-12-27 19:26:57 -0500404boot_add_cbfs(void *data, const char *desc, int prio)
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500405{
Kevin O'Connor031ef552010-12-27 19:26:57 -0500406 bootentry_add(IPL_TYPE_CBFS, defPrio(prio, DEFAULT_PRIO), (u32)data, desc);
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500407}
408
409
410/****************************************************************
Kevin O'Connor0ac5e9e2013-09-14 13:09:27 -0400411 * Keyboard calls
412 ****************************************************************/
413
414// See if a keystroke is pending in the keyboard buffer.
415static int
416check_for_keystroke(void)
417{
418 struct bregs br;
419 memset(&br, 0, sizeof(br));
420 br.flags = F_IF|F_ZF;
421 br.ah = 1;
422 call16_int(0x16, &br);
423 return !(br.flags & F_ZF);
424}
425
426// Return a keystroke - waiting forever if necessary.
427static int
428get_raw_keystroke(void)
429{
430 struct bregs br;
431 memset(&br, 0, sizeof(br));
432 br.flags = F_IF;
433 call16_int(0x16, &br);
434 return br.ah;
435}
436
437// Read a keystroke - waiting up to 'msec' milliseconds.
Stefan Berger320df852015-11-30 11:14:19 -0500438int
Kevin O'Connor0ac5e9e2013-09-14 13:09:27 -0400439get_keystroke(int msec)
440{
441 u32 end = irqtimer_calc(msec);
442 for (;;) {
443 if (check_for_keystroke())
444 return get_raw_keystroke();
445 if (irqtimer_check(end))
446 return -1;
447 yield_toirq();
448 }
449}
450
451
452/****************************************************************
Kevin O'Connor0a924122009-02-08 19:43:47 -0500453 * Boot menu and BCV execution
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500454 ****************************************************************/
455
Kevin O'Connor73023002011-07-05 20:34:34 -0400456#define DEFAULT_BOOTMENU_WAIT 2500
457
Kevin O'Connor0a924122009-02-08 19:43:47 -0500458// Show IPL option menu.
Kevin O'Connor8a0a9722013-01-21 01:53:31 -0500459void
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500460interactive_bootmenu(void)
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500461{
Kevin O'Connor8a0a9722013-01-21 01:53:31 -0500462 // XXX - show available drives?
463
Kevin O'Connor56c50892013-02-09 19:25:51 -0500464 if (! CONFIG_BOOTMENU || !romfile_loadint("etc/show-boot-menu", 1))
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500465 return;
466
467 while (get_keystroke(0) >= 0)
468 ;
469
Kevin O'Connor129f11e2013-08-02 14:13:50 -0400470 char *bootmsg = romfile_loadfile("etc/boot-menu-message", NULL);
Paolo Bonzinia1ac8862015-03-12 18:12:24 +0100471 int menukey = romfile_loadint("etc/boot-menu-key", 1);
472 printf("%s", bootmsg ?: "\nPress ESC for boot menu.\n\n");
Kevin O'Connor129f11e2013-08-02 14:13:50 -0400473 free(bootmsg);
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500474
Kevin O'Connor73023002011-07-05 20:34:34 -0400475 u32 menutime = romfile_loadint("etc/boot-menu-wait", DEFAULT_BOOTMENU_WAIT);
Kevin O'Connor9a01a9c2010-08-25 21:07:48 -0400476 enable_bootsplash();
Kevin O'Connor73023002011-07-05 20:34:34 -0400477 int scan_code = get_keystroke(menutime);
Kevin O'Connor9a01a9c2010-08-25 21:07:48 -0400478 disable_bootsplash();
Kevin O'Connor129f11e2013-08-02 14:13:50 -0400479 if (scan_code != menukey)
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500480 return;
481
482 while (get_keystroke(0) >= 0)
483 ;
484
485 printf("Select boot device:\n\n");
Kevin O'Connore438b0c2010-05-01 12:20:33 -0400486 wait_threads();
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500487
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500488 // Show menu items
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500489 int maxmenu = 0;
Kevin O'Connor446defb2013-06-08 21:50:53 -0400490 struct bootentry_s *pos;
491 hlist_for_each_entry(pos, &BootList, node) {
Kevin O'Connor6f090f82017-04-25 13:04:41 -0400492 char desc[77];
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500493 maxmenu++;
494 printf("%d. %s\n", maxmenu
495 , strtcpy(desc, pos->description, ARRAY_SIZE(desc)));
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500496 }
Stefan Berger115d0082016-01-07 12:02:49 -0500497 if (tpm_can_show_menu()) {
Stefan Berger320df852015-11-30 11:14:19 -0500498 printf("\nt. TPM Configuration\n");
499 }
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500500
Paolo Bonzini80aae262015-03-12 18:12:23 +0100501 // Get key press. If the menu key is ESC, do not restart boot unless
502 // 1.5 seconds have passed. Otherwise users (trained by years of
503 // repeatedly hitting keys to enter the BIOS) will end up hitting ESC
504 // multiple times and immediately booting the primary boot device.
505 int esc_accepted_time = irqtimer_calc(menukey == 1 ? 1500 : 0);
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500506 for (;;) {
507 scan_code = get_keystroke(1000);
Paolo Bonzini80aae262015-03-12 18:12:23 +0100508 if (scan_code == 1 && !irqtimer_check(esc_accepted_time))
509 continue;
Stefan Berger115d0082016-01-07 12:02:49 -0500510 if (tpm_can_show_menu() && scan_code == 20 /* t */) {
Stefan Berger320df852015-11-30 11:14:19 -0500511 printf("\n");
512 tpm_menu();
513 }
Kevin O'Connor551caa22010-12-29 13:25:18 -0500514 if (scan_code >= 1 && scan_code <= maxmenu+1)
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500515 break;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500516 }
517 printf("\n");
Kevin O'Connor551caa22010-12-29 13:25:18 -0500518 if (scan_code == 0x01)
519 // ESC
520 return;
521
522 // Find entry and make top priority.
523 int choice = scan_code - 1;
Kevin O'Connor446defb2013-06-08 21:50:53 -0400524 hlist_for_each_entry(pos, &BootList, node) {
525 if (! --choice)
526 break;
527 }
528 hlist_del(&pos->node);
Kevin O'Connor551caa22010-12-29 13:25:18 -0500529 pos->priority = 0;
Kevin O'Connor446defb2013-06-08 21:50:53 -0400530 hlist_add_head(&pos->node, &BootList);
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500531}
532
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500533// BEV (Boot Execution Vector) list
Kevin O'Connor7bb15842010-12-29 11:25:14 -0500534struct bev_s {
535 int type;
536 u32 vector;
537};
538static struct bev_s BEV[20];
539static int BEVCount;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500540static int HaveHDBoot, HaveFDBoot;
541
Kevin O'Connor0a924122009-02-08 19:43:47 -0500542static void
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500543add_bev(int type, u32 vector)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500544{
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500545 if (type == IPL_TYPE_HARDDISK && HaveHDBoot++)
546 return;
547 if (type == IPL_TYPE_FLOPPY && HaveFDBoot++)
548 return;
Kevin O'Connor7bb15842010-12-29 11:25:14 -0500549 if (BEVCount >= ARRAY_SIZE(BEV))
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500550 return;
Kevin O'Connor7bb15842010-12-29 11:25:14 -0500551 struct bev_s *bev = &BEV[BEVCount++];
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500552 bev->type = type;
553 bev->vector = vector;
Kevin O'Connor0a924122009-02-08 19:43:47 -0500554}
555
556// Prepare for boot - show menu and run bcvs.
557void
Kevin O'Connor8a0a9722013-01-21 01:53:31 -0500558bcv_prepboot(void)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500559{
Kevin O'Connor8a0a9722013-01-21 01:53:31 -0500560 if (! CONFIG_BOOT)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500561 return;
Kevin O'Connor0a924122009-02-08 19:43:47 -0500562
Kevin O'Connor54ae5432013-01-12 16:36:11 -0500563 int haltprio = find_prio("HALT");
564 if (haltprio >= 0)
565 bootentry_add(IPL_TYPE_HALT, haltprio, 0, "HALT");
566
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500567 // Map drives and populate BEV list
Kevin O'Connor446defb2013-06-08 21:50:53 -0400568 struct bootentry_s *pos;
569 hlist_for_each_entry(pos, &BootList, node) {
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500570 switch (pos->type) {
571 case IPL_TYPE_BCV:
572 call_bcv(pos->vector.seg, pos->vector.offset);
573 add_bev(IPL_TYPE_HARDDISK, 0);
574 break;
575 case IPL_TYPE_FLOPPY:
576 map_floppy_drive(pos->drive);
577 add_bev(IPL_TYPE_FLOPPY, 0);
578 break;
579 case IPL_TYPE_HARDDISK:
580 map_hd_drive(pos->drive);
581 add_bev(IPL_TYPE_HARDDISK, 0);
582 break;
583 case IPL_TYPE_CDROM:
584 map_cd_drive(pos->drive);
585 // NO BREAK
586 default:
587 add_bev(pos->type, pos->data);
588 break;
589 }
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500590 }
Kevin O'Connorafd05202009-08-16 12:21:44 -0400591
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500592 // If nothing added a floppy/hd boot - add it manually.
593 add_bev(IPL_TYPE_FLOPPY, 0);
594 add_bev(IPL_TYPE_HARDDISK, 0);
Kevin O'Connor0a924122009-02-08 19:43:47 -0500595}
596
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500597
598/****************************************************************
599 * Boot code (int 18/19)
600 ****************************************************************/
601
Kevin O'Connor0a924122009-02-08 19:43:47 -0500602// Jump to a bootup entry point.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500603static void
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500604call_boot_entry(struct segoff_s bootsegip, u8 bootdrv)
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500605{
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500606 dprintf(1, "Booting from %04x:%04x\n", bootsegip.seg, bootsegip.offset);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500607 struct bregs br;
608 memset(&br, 0, sizeof(br));
Kevin O'Connorf8e800d2009-09-24 21:01:16 -0400609 br.flags = F_IF;
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500610 br.code = bootsegip;
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500611 // Set the magic number in ax and the boot drive in dl.
612 br.dl = bootdrv;
613 br.ax = 0xaa55;
Kevin O'Connorc7ffbac2012-03-25 11:04:10 -0400614 farcall16(&br);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500615}
616
617// Boot from a disk (either floppy or harddrive)
618static void
619boot_disk(u8 bootdrv, int checksig)
620{
621 u16 bootseg = 0x07c0;
622
623 // Read sector
624 struct bregs br;
625 memset(&br, 0, sizeof(br));
Kevin O'Connorf8e800d2009-09-24 21:01:16 -0400626 br.flags = F_IF;
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500627 br.dl = bootdrv;
628 br.es = bootseg;
629 br.ah = 2;
630 br.al = 1;
631 br.cl = 1;
632 call16_int(0x13, &br);
633
634 if (br.flags & F_CF) {
635 printf("Boot failed: could not read the boot disk\n\n");
636 return;
637 }
638
639 if (checksig) {
640 struct mbr_s *mbr = (void*)0;
641 if (GET_FARVAR(bootseg, mbr->signature) != MBR_SIGNATURE) {
642 printf("Boot failed: not a bootable disk\n\n");
643 return;
644 }
645 }
646
Stefan Berger2aff1c12015-05-26 15:48:33 -0400647 tpm_add_bcv(bootdrv, MAKE_FLATPTR(bootseg, 0), 512);
648
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500649 /* Canonicalize bootseg:bootip */
650 u16 bootip = (bootseg & 0x0fff) << 4;
651 bootseg &= 0xf000;
652
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500653 call_boot_entry(SEGOFF(bootseg, bootip), bootdrv);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500654}
655
656// Boot from a CD-ROM
657static void
Kevin O'Connor5e9a6d52017-07-11 11:55:49 -0400658boot_cdrom(struct drive_s *drive)
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500659{
660 if (! CONFIG_CDROM_BOOT)
661 return;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500662 printf("Booting from DVD/CD...\n");
Gleb Natapov4c90a202010-12-07 13:50:54 +0200663
Kevin O'Connor5e9a6d52017-07-11 11:55:49 -0400664 int status = cdrom_boot(drive);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500665 if (status) {
Kevin O'Connorecbcf772010-12-29 13:26:01 -0500666 printf("Boot failed: Could not read from CDROM (code %04x)\n", status);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500667 return;
668 }
669
Kevin O'Connor02f76762014-05-10 01:20:46 -0400670 u8 bootdrv = CDEmu.emulated_drive;
Kevin O'Connord3140832012-05-13 22:46:12 -0400671 u16 bootseg = CDEmu.load_segment;
Stefan Berger2aff1c12015-05-26 15:48:33 -0400672
673 tpm_add_cdrom(bootdrv, MAKE_FLATPTR(bootseg, 0), 512);
674
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500675 /* Canonicalize bootseg:bootip */
676 u16 bootip = (bootseg & 0x0fff) << 4;
677 bootseg &= 0xf000;
678
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500679 call_boot_entry(SEGOFF(bootseg, bootip), bootdrv);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500680}
681
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400682// Boot from a CBFS payload
Kevin O'Connor67823442009-04-13 14:14:51 -0400683static void
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500684boot_cbfs(struct cbfs_file *file)
Kevin O'Connor67823442009-04-13 14:14:51 -0400685{
Kevin O'Connor897fb112013-02-07 23:32:48 -0500686 if (!CONFIG_COREBOOT_FLASH)
Kevin O'Connor67823442009-04-13 14:14:51 -0400687 return;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500688 printf("Booting from CBFS...\n");
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500689 cbfs_run_payload(file);
Kevin O'Connor67823442009-04-13 14:14:51 -0400690}
691
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500692// Boot from a BEV entry on an optionrom.
693static void
694boot_rom(u32 vector)
695{
696 printf("Booting from ROM...\n");
697 struct segoff_s so;
698 so.segoff = vector;
699 call_boot_entry(so, 0);
700}
701
Kevin O'Connorb8fcf462012-05-12 22:12:22 -0400702// Unable to find bootable device - warn user and eventually retry.
703static void
704boot_fail(void)
705{
Kevin O'Connor11a72342013-03-05 17:52:21 +0800706 if (BootRetryTime == (u32)-1)
Kevin O'Connorb8fcf462012-05-12 22:12:22 -0400707 printf("No bootable device.\n");
708 else
Kevin O'Connor11a72342013-03-05 17:52:21 +0800709 printf("No bootable device. Retrying in %d seconds.\n"
710 , BootRetryTime/1000);
711 // Wait for 'BootRetryTime' milliseconds and then reboot.
Kevin O'Connor95ee3822013-07-20 18:07:50 -0400712 u32 end = irqtimer_calc(BootRetryTime);
Kevin O'Connorb8fcf462012-05-12 22:12:22 -0400713 for (;;) {
Kevin O'Connor95ee3822013-07-20 18:07:50 -0400714 if (BootRetryTime != (u32)-1 && irqtimer_check(end))
Kevin O'Connorb8fcf462012-05-12 22:12:22 -0400715 break;
Kevin O'Connor94c749c2012-05-28 11:44:02 -0400716 yield_toirq();
Kevin O'Connorb8fcf462012-05-12 22:12:22 -0400717 }
718 printf("Rebooting.\n");
Kevin O'Connor43197a22014-06-06 13:49:33 -0400719 reset();
Kevin O'Connorb8fcf462012-05-12 22:12:22 -0400720}
721
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500722// Determine next boot method and attempt a boot using it.
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500723static void
Kevin O'Connor9d8e0a62012-05-13 12:23:58 -0400724do_boot(int seq_nr)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500725{
Kevin O'Connor40967022008-07-21 22:23:05 -0400726 if (! CONFIG_BOOT)
Kevin O'Connore07e18e2009-02-08 17:07:29 -0500727 panic("Boot support not compiled in.\n");
Kevin O'Connor40967022008-07-21 22:23:05 -0400728
Kevin O'Connorb8fcf462012-05-12 22:12:22 -0400729 if (seq_nr >= BEVCount)
730 boot_fail();
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500731
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500732 // Boot the given BEV type.
Kevin O'Connor7bb15842010-12-29 11:25:14 -0500733 struct bev_s *ie = &BEV[seq_nr];
Kevin O'Connorcadaf0e2010-07-26 23:47:26 -0400734 switch (ie->type) {
Kevin O'Connorf13b0082008-08-17 11:26:42 -0400735 case IPL_TYPE_FLOPPY:
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500736 printf("Booting from Floppy...\n");
Kevin O'Connorbaaadb62010-12-29 11:18:04 -0500737 boot_disk(0x00, CheckFloppySig);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500738 break;
Kevin O'Connorf13b0082008-08-17 11:26:42 -0400739 case IPL_TYPE_HARDDISK:
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500740 printf("Booting from Hard Disk...\n");
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500741 boot_disk(0x80, 1);
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500742 break;
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500743 case IPL_TYPE_CDROM:
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500744 boot_cdrom((void*)ie->vector);
Kevin O'Connor67823442009-04-13 14:14:51 -0400745 break;
746 case IPL_TYPE_CBFS:
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500747 boot_cbfs((void*)ie->vector);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500748 break;
749 case IPL_TYPE_BEV:
Kevin O'Connorf13a1802010-12-29 11:52:33 -0500750 boot_rom(ie->vector);
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500751 break;
Kevin O'Connor54ae5432013-01-12 16:36:11 -0500752 case IPL_TYPE_HALT:
753 boot_fail();
754 break;
Kevin O'Connor180a9592008-03-04 22:50:53 -0500755 }
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500756
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500757 // Boot failed: invoke the boot recovery function
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400758 struct bregs br;
759 memset(&br, 0, sizeof(br));
Kevin O'Connorf8e800d2009-09-24 21:01:16 -0400760 br.flags = F_IF;
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400761 call16_int(0x18, &br);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500762}
763
Kevin O'Connor9d8e0a62012-05-13 12:23:58 -0400764int BootSequence VARLOW = -1;
765
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500766// Boot Failure recovery: try the next device.
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500767void VISIBLE32FLAT
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500768handle_18(void)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500769{
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400770 debug_enter(NULL, DEBUG_HDL_18);
Kevin O'Connor9d8e0a62012-05-13 12:23:58 -0400771 int seq = BootSequence + 1;
772 BootSequence = seq;
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400773 do_boot(seq);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500774}
775
776// INT 19h Boot Load Service Entry Point
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500777void VISIBLE32FLAT
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500778handle_19(void)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500779{
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400780 debug_enter(NULL, DEBUG_HDL_19);
Kevin O'Connor9d8e0a62012-05-13 12:23:58 -0400781 BootSequence = 0;
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400782 do_boot(0);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500783}