blob: d37e10fa872c242aca03ae5fad471715cac1731e [file] [log] [blame]
Kevin O'Connorf13b0082008-08-17 11:26:42 -04001// Code to load disk image and start system boot.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05002//
Kevin O'Connorcadaf0e2010-07-26 23:47:26 -04003// Copyright (C) 2008-2010 Kevin O'Connor <kevin@koconnor.net>
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05004// Copyright (C) 2002 MandrakeSoft S.A.
5//
Kevin O'Connorb1b7c2a2009-01-15 20:52:58 -05006// This file may be distributed under the terms of the GNU LGPLv3 license.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05007
Kevin O'Connor10ad7992009-10-24 11:06:08 -04008#include "util.h" // dprintf
Kevin O'Connor9521e262008-07-04 13:04:29 -04009#include "biosvar.h" // GET_EBDA
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050010#include "config.h" // CONFIG_*
Kevin O'Connor180a9592008-03-04 22:50:53 -050011#include "disk.h" // cdrom_boot
Kevin O'Connor9521e262008-07-04 13:04:29 -040012#include "bregs.h" // struct bregs
Kevin O'Connorc659fde2008-12-28 23:43:20 -050013#include "boot.h" // struct ipl_s
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050014#include "cmos.h" // inb_cmos
Kevin O'Connore7cc7642009-10-04 10:05:16 -040015#include "paravirt.h"
Kevin O'Connorc659fde2008-12-28 23:43:20 -050016
17struct ipl_s IPL;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050018
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050019
20/****************************************************************
Kevin O'Connor031ef552010-12-27 19:26:57 -050021 * Boot priority ordering
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050022 ****************************************************************/
23
Kevin O'Connord1a17462010-12-24 11:17:03 -050024static void
25loadBootOrder(void)
26{
27 char *f = romfile_loadfile("bootorder", NULL);
28 if (!f)
29 return;
30
31 int i;
32 IPL.fw_bootorder_count = 1;
33 while (f[i]) {
34 if (f[i] == '\n')
35 IPL.fw_bootorder_count++;
36 i++;
37 }
38 IPL.fw_bootorder = malloc_tmphigh(IPL.fw_bootorder_count*sizeof(char*));
39 if (!IPL.fw_bootorder) {
40 warn_noalloc();
41 free(f);
42 return;
43 }
44
45 dprintf(3, "boot order:\n");
46 i = 0;
47 do {
48 IPL.fw_bootorder[i] = f;
49 f = strchr(f, '\n');
50 if (f) {
51 *f = '\0';
52 f++;
53 dprintf(3, "%d: %s\n", i, IPL.fw_bootorder[i]);
54 i++;
55 }
56 } while(f);
57}
58
Kevin O'Connor031ef552010-12-27 19:26:57 -050059int bootprio_find_pci_device(int bdf)
60{
61 return -1;
62}
63
64int bootprio_find_ata_device(int bdf, int chanid, int slave)
65{
66 return -1;
67}
68
69int bootprio_find_fdc_device(int bfd, int port, int fdid)
70{
71 return -1;
72}
73
74int bootprio_find_pci_rom(int bdf, int instance)
75{
76 return -1;
77}
78
79int bootprio_find_named_rom(const char *name, int instance)
80{
81 return -1;
82}
83
84
85/****************************************************************
86 * Boot setup
87 ****************************************************************/
88
Kevin O'Connor72eee3e2010-12-27 19:07:49 -050089#define DEFAULT_PRIO 9999
90
91static int DefaultFloppyPrio = 101;
92static int DefaultCDPrio = 102;
93static int DefaultHDPrio = 103;
94static int DefaultBEVPrio = 104;
95
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050096void
Kevin O'Connor1ca05b02010-01-03 17:43:37 -050097boot_setup(void)
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050098{
99 if (! CONFIG_BOOT)
100 return;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500101
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500102 SET_EBDA(boot_sequence, 0xffff);
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500103 IPL.checkfloppysig = 1;
104
105 if (!CONFIG_COREBOOT) {
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500106 // On emulators, get boot order from nvram.
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500107 if (inb_cmos(CMOS_BIOS_BOOTFLAG1) & 1)
108 IPL.checkfloppysig = 0;
109 u32 bootorder = (inb_cmos(CMOS_BIOS_BOOTFLAG2)
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500110 | ((inb_cmos(CMOS_BIOS_BOOTFLAG1) & 0xf0) << 4));
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500111 DefaultFloppyPrio = DefaultCDPrio = DefaultHDPrio
112 = DefaultBEVPrio = DEFAULT_PRIO;
113 int i;
114 for (i=101; i<104; i++) {
115 u32 val = bootorder & 0x0f;
116 bootorder >>= 4;
117 switch (val) {
118 case 1: DefaultFloppyPrio = i; break;
119 case 2: DefaultHDPrio = i; break;
120 case 3: DefaultCDPrio = i; break;
121 case 4: DefaultBEVPrio = i; break;
122 }
123 }
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500124 }
Gleb Natapovb9a75912010-12-23 11:29:38 +0200125
Kevin O'Connord1a17462010-12-24 11:17:03 -0500126 loadBootOrder();
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500127}
128
Kevin O'Connord1a17462010-12-24 11:17:03 -0500129
130/****************************************************************
Kevin O'Connor031ef552010-12-27 19:26:57 -0500131 * BootList handling
Kevin O'Connord1a17462010-12-24 11:17:03 -0500132 ****************************************************************/
133
Kevin O'Connor031ef552010-12-27 19:26:57 -0500134struct bootentry_s {
135 int type;
136 union {
137 u32 data;
138 struct segoff_s vector;
139 struct drive_s *drive;
140 };
141 int priority;
142 const char *description;
143 struct bootentry_s *next;
144};
145
146static struct bootentry_s *BootList;
147
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500148static void
149bootentry_add(int type, int prio, u32 data, const char *desc)
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500150{
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500151 if (! CONFIG_BOOT)
152 return;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500153 struct bootentry_s *be = malloc_tmp(sizeof(*be));
154 if (!be) {
155 warn_noalloc();
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500156 return;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500157 }
158 be->type = type;
159 be->priority = prio;
160 be->data = data;
161 be->description = desc;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500162
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500163 // Add entry in sorted order.
164 struct bootentry_s **pprev;
165 for (pprev = &BootList; *pprev; pprev = &(*pprev)->next) {
166 struct bootentry_s *pos = *pprev;
167 if (be->priority < pos->priority)
168 break;
169 if (be->priority > pos->priority)
170 continue;
171 if (be->type < pos->type)
172 break;
173 if (be->type > pos->type)
174 continue;
175 if (be->type <= IPL_TYPE_CDROM
176 && (be->drive->type < pos->drive->type
177 || (be->drive->type == pos->drive->type
178 && be->drive->cntl_id < pos->drive->cntl_id)))
179 break;
180 }
181 be->next = *pprev;
182 *pprev = be;
Kevin O'Connor0a924122009-02-08 19:43:47 -0500183}
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500184
Kevin O'Connor031ef552010-12-27 19:26:57 -0500185// Return the given priority if it's set - defaultprio otherwise.
186static inline int defPrio(int priority, int defaultprio) {
187 return (priority < 0) ? defaultprio : priority;
188}
189
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500190// Add a BEV vector for a given pnp compatible option rom.
Gleb Natapov4c90a202010-12-07 13:50:54 +0200191void
Kevin O'Connor031ef552010-12-27 19:26:57 -0500192boot_add_bev(u16 seg, u16 bev, u16 desc, int prio)
Gleb Natapov4c90a202010-12-07 13:50:54 +0200193{
Kevin O'Connor031ef552010-12-27 19:26:57 -0500194 bootentry_add(IPL_TYPE_BEV, defPrio(prio, DefaultBEVPrio)
195 , SEGOFF(seg, bev).segoff
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500196 , desc ? MAKE_FLATPTR(seg, desc) : "Unknown");
197 DefaultBEVPrio = DEFAULT_PRIO;
Gleb Natapov4c90a202010-12-07 13:50:54 +0200198}
199
Kevin O'Connor0a924122009-02-08 19:43:47 -0500200// Add a bcv entry for an expansion card harddrive or legacy option rom
201void
Kevin O'Connor031ef552010-12-27 19:26:57 -0500202boot_add_bcv(u16 seg, u16 ip, u16 desc, int prio)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500203{
Kevin O'Connor031ef552010-12-27 19:26:57 -0500204 bootentry_add(IPL_TYPE_BCV, defPrio(prio, DEFAULT_PRIO)
205 , SEGOFF(seg, ip).segoff
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500206 , desc ? MAKE_FLATPTR(seg, desc) : "Legacy option rom");
Kevin O'Connor0a924122009-02-08 19:43:47 -0500207}
208
Kevin O'Connor0a924122009-02-08 19:43:47 -0500209void
Kevin O'Connor031ef552010-12-27 19:26:57 -0500210boot_add_floppy(struct drive_s *drive_g, int prio)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500211{
Kevin O'Connor031ef552010-12-27 19:26:57 -0500212 bootentry_add(IPL_TYPE_FLOPPY, defPrio(prio, DefaultFloppyPrio)
213 , (u32)drive_g, drive_g->desc);
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500214}
Kevin O'Connor0a924122009-02-08 19:43:47 -0500215
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500216void
Kevin O'Connor031ef552010-12-27 19:26:57 -0500217boot_add_hd(struct drive_s *drive_g, int prio)
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500218{
Kevin O'Connor031ef552010-12-27 19:26:57 -0500219 bootentry_add(IPL_TYPE_HARDDISK, defPrio(prio, DefaultHDPrio)
220 , (u32)drive_g, drive_g->desc);
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500221}
222
223void
Kevin O'Connor031ef552010-12-27 19:26:57 -0500224boot_add_cd(struct drive_s *drive_g, int prio)
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500225{
Kevin O'Connor031ef552010-12-27 19:26:57 -0500226 bootentry_add(IPL_TYPE_CDROM, defPrio(prio, DefaultCDPrio)
227 , (u32)drive_g, drive_g->desc);
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500228}
229
230// Add a CBFS payload entry
231void
Kevin O'Connor031ef552010-12-27 19:26:57 -0500232boot_add_cbfs(void *data, const char *desc, int prio)
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500233{
Kevin O'Connor031ef552010-12-27 19:26:57 -0500234 bootentry_add(IPL_TYPE_CBFS, defPrio(prio, DEFAULT_PRIO), (u32)data, desc);
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500235}
236
237
238/****************************************************************
Kevin O'Connor0a924122009-02-08 19:43:47 -0500239 * Boot menu and BCV execution
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500240 ****************************************************************/
241
Kevin O'Connor0a924122009-02-08 19:43:47 -0500242// Show IPL option menu.
243static void
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500244interactive_bootmenu(void)
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500245{
Kevin O'Connore7cc7642009-10-04 10:05:16 -0400246 if (! CONFIG_BOOTMENU || ! qemu_cfg_show_boot_menu())
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500247 return;
248
249 while (get_keystroke(0) >= 0)
250 ;
251
252 printf("Press F12 for boot menu.\n\n");
253
Kevin O'Connor9a01a9c2010-08-25 21:07:48 -0400254 enable_bootsplash();
Kevin O'Connor217d3632009-04-29 22:00:21 -0400255 int scan_code = get_keystroke(CONFIG_BOOTMENU_WAIT);
Kevin O'Connor9a01a9c2010-08-25 21:07:48 -0400256 disable_bootsplash();
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500257 if (scan_code != 0x86)
258 /* not F12 */
259 return;
260
261 while (get_keystroke(0) >= 0)
262 ;
263
264 printf("Select boot device:\n\n");
Kevin O'Connore438b0c2010-05-01 12:20:33 -0400265 wait_threads();
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500266
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500267 // Show menu items
268 struct bootentry_s *pos = BootList;
269 int maxmenu = 0;
270 while (pos) {
271 char desc[60];
272 maxmenu++;
273 printf("%d. %s\n", maxmenu
274 , strtcpy(desc, pos->description, ARRAY_SIZE(desc)));
275 pos = pos->next;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500276 }
277
278 for (;;) {
279 scan_code = get_keystroke(1000);
280 if (scan_code == 0x01)
281 // ESC
282 break;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500283 if (scan_code < 1 || scan_code > maxmenu+1)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500284 continue;
285 int choice = scan_code - 1;
286
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500287 // Find entry and make top priority.
288 struct bootentry_s **pprev = &BootList;
289 while (--choice)
290 pprev = &(*pprev)->next;
291 pos = *pprev;
292 *pprev = pos->next;
293 pos->next = BootList;
294 BootList = pos;
295 pos->priority = 0;
Kevin O'Connor0a924122009-02-08 19:43:47 -0500296 break;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500297 }
298 printf("\n");
299}
300
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500301static int HaveHDBoot, HaveFDBoot;
302
Kevin O'Connor0a924122009-02-08 19:43:47 -0500303static void
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500304add_bev(int type, u32 vector)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500305{
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500306 if (type == IPL_TYPE_HARDDISK && HaveHDBoot++)
307 return;
308 if (type == IPL_TYPE_FLOPPY && HaveFDBoot++)
309 return;
310 if (IPL.bevcount >= ARRAY_SIZE(IPL.bev))
311 return;
312 struct ipl_entry_s *bev = &IPL.bev[IPL.bevcount++];
313 bev->type = type;
314 bev->vector = vector;
Kevin O'Connor0a924122009-02-08 19:43:47 -0500315}
316
317// Prepare for boot - show menu and run bcvs.
318void
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500319boot_prep(void)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500320{
Kevin O'Connore438b0c2010-05-01 12:20:33 -0400321 if (! CONFIG_BOOT) {
322 wait_threads();
Kevin O'Connor0a924122009-02-08 19:43:47 -0500323 return;
Kevin O'Connore438b0c2010-05-01 12:20:33 -0400324 }
Kevin O'Connor0a924122009-02-08 19:43:47 -0500325
Kevin O'Connora5826b52009-10-24 17:57:29 -0400326 // XXX - show available drives?
327
Kevin O'Connor0a924122009-02-08 19:43:47 -0500328 // Allow user to modify BCV/IPL order.
329 interactive_bootmenu();
Kevin O'Connore438b0c2010-05-01 12:20:33 -0400330 wait_threads();
Kevin O'Connor0a924122009-02-08 19:43:47 -0500331
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500332 // Map drives and populate BEV list
333 struct bootentry_s *pos = BootList;
334 while (pos) {
335 switch (pos->type) {
336 case IPL_TYPE_BCV:
337 call_bcv(pos->vector.seg, pos->vector.offset);
338 add_bev(IPL_TYPE_HARDDISK, 0);
339 break;
340 case IPL_TYPE_FLOPPY:
341 map_floppy_drive(pos->drive);
342 add_bev(IPL_TYPE_FLOPPY, 0);
343 break;
344 case IPL_TYPE_HARDDISK:
345 map_hd_drive(pos->drive);
346 add_bev(IPL_TYPE_HARDDISK, 0);
347 break;
348 case IPL_TYPE_CDROM:
349 map_cd_drive(pos->drive);
350 // NO BREAK
351 default:
352 add_bev(pos->type, pos->data);
353 break;
354 }
355 pos = pos->next;
356 }
Kevin O'Connorafd05202009-08-16 12:21:44 -0400357
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500358 // If nothing added a floppy/hd boot - add it manually.
359 add_bev(IPL_TYPE_FLOPPY, 0);
360 add_bev(IPL_TYPE_HARDDISK, 0);
Kevin O'Connor0a924122009-02-08 19:43:47 -0500361}
362
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500363
364/****************************************************************
365 * Boot code (int 18/19)
366 ****************************************************************/
367
Kevin O'Connor0a924122009-02-08 19:43:47 -0500368// Jump to a bootup entry point.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500369static void
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500370call_boot_entry(u16 bootseg, u16 bootip, u8 bootdrv)
371{
Kevin O'Connorcadaf0e2010-07-26 23:47:26 -0400372 dprintf(1, "Booting from %04x:%04x\n", bootseg, bootip);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500373 struct bregs br;
374 memset(&br, 0, sizeof(br));
Kevin O'Connorf8e800d2009-09-24 21:01:16 -0400375 br.flags = F_IF;
Kevin O'Connor9f985422009-09-09 11:34:39 -0400376 br.code = SEGOFF(bootseg, bootip);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500377 // Set the magic number in ax and the boot drive in dl.
378 br.dl = bootdrv;
379 br.ax = 0xaa55;
380 call16(&br);
381}
382
383// Boot from a disk (either floppy or harddrive)
384static void
385boot_disk(u8 bootdrv, int checksig)
386{
387 u16 bootseg = 0x07c0;
388
389 // Read sector
390 struct bregs br;
391 memset(&br, 0, sizeof(br));
Kevin O'Connorf8e800d2009-09-24 21:01:16 -0400392 br.flags = F_IF;
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500393 br.dl = bootdrv;
394 br.es = bootseg;
395 br.ah = 2;
396 br.al = 1;
397 br.cl = 1;
398 call16_int(0x13, &br);
399
400 if (br.flags & F_CF) {
401 printf("Boot failed: could not read the boot disk\n\n");
402 return;
403 }
404
405 if (checksig) {
406 struct mbr_s *mbr = (void*)0;
407 if (GET_FARVAR(bootseg, mbr->signature) != MBR_SIGNATURE) {
408 printf("Boot failed: not a bootable disk\n\n");
409 return;
410 }
411 }
412
413 /* Canonicalize bootseg:bootip */
414 u16 bootip = (bootseg & 0x0fff) << 4;
415 bootseg &= 0xf000;
416
417 call_boot_entry(bootseg, bootip, bootdrv);
418}
419
420// Boot from a CD-ROM
421static void
Kevin O'Connor67823442009-04-13 14:14:51 -0400422boot_cdrom(struct ipl_entry_s *ie)
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500423{
424 if (! CONFIG_CDROM_BOOT)
425 return;
Gleb Natapov4c90a202010-12-07 13:50:54 +0200426
427 if (!ie->vector)
428 return;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500429 printf("Booting from DVD/CD...\n");
Gleb Natapov4c90a202010-12-07 13:50:54 +0200430
431 struct drive_s *drive_g = (void*)ie->vector;
432 int status = cdrom_boot(drive_g);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500433 if (status) {
Gleb Natapov4c90a202010-12-07 13:50:54 +0200434 printf("Boot failed: Could not read from CDROM %s (code %04x)\n", drive_g->desc, status);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500435 return;
436 }
437
438 u16 ebda_seg = get_ebda_seg();
Kevin O'Connor669e6442009-08-11 22:36:30 -0400439 u8 bootdrv = GET_EBDA2(ebda_seg, cdemu.emulated_extdrive);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500440 u16 bootseg = GET_EBDA2(ebda_seg, cdemu.load_segment);
441 /* Canonicalize bootseg:bootip */
442 u16 bootip = (bootseg & 0x0fff) << 4;
443 bootseg &= 0xf000;
444
445 call_boot_entry(bootseg, bootip, bootdrv);
446}
447
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400448// Boot from a CBFS payload
Kevin O'Connor67823442009-04-13 14:14:51 -0400449static void
450boot_cbfs(struct ipl_entry_s *ie)
451{
Kevin O'Connord9c93612010-03-20 11:00:45 -0400452 if (!CONFIG_COREBOOT || !CONFIG_COREBOOT_FLASH)
Kevin O'Connor67823442009-04-13 14:14:51 -0400453 return;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500454 printf("Booting from CBFS...\n");
455 cbfs_run_payload((void*)ie->vector);
Kevin O'Connor67823442009-04-13 14:14:51 -0400456}
457
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500458static void
459do_boot(u16 seq_nr)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500460{
Kevin O'Connor40967022008-07-21 22:23:05 -0400461 if (! CONFIG_BOOT)
Kevin O'Connore07e18e2009-02-08 17:07:29 -0500462 panic("Boot support not compiled in.\n");
Kevin O'Connor40967022008-07-21 22:23:05 -0400463
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500464 if (seq_nr >= IPL.bevcount) {
Kevin O'Connorff8c1412009-04-18 17:02:41 -0400465 printf("No bootable device.\n");
466 // Loop with irqs enabled - this allows ctrl+alt+delete to work.
467 for (;;)
Kevin O'Connor9c447c32010-05-23 10:24:22 -0400468 wait_irq();
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500469 }
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500470
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500471 // Boot the given BEV type.
472 struct ipl_entry_s *ie = &IPL.bev[seq_nr];
Kevin O'Connorcadaf0e2010-07-26 23:47:26 -0400473 switch (ie->type) {
Kevin O'Connorf13b0082008-08-17 11:26:42 -0400474 case IPL_TYPE_FLOPPY:
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500475 printf("Booting from Floppy...\n");
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500476 boot_disk(0x00, IPL.checkfloppysig);
477 break;
Kevin O'Connorf13b0082008-08-17 11:26:42 -0400478 case IPL_TYPE_HARDDISK:
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500479 printf("Booting from Hard Disk...\n");
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500480 boot_disk(0x80, 1);
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500481 break;
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500482 case IPL_TYPE_CDROM:
Kevin O'Connor67823442009-04-13 14:14:51 -0400483 boot_cdrom(ie);
484 break;
485 case IPL_TYPE_CBFS:
486 boot_cbfs(ie);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500487 break;
488 case IPL_TYPE_BEV:
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500489 printf("Booting from ROM...\n");
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500490 call_boot_entry(ie->vector >> 16, ie->vector & 0xffff, 0);
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500491 break;
Kevin O'Connor180a9592008-03-04 22:50:53 -0500492 }
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500493
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500494 // Boot failed: invoke the boot recovery function
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400495 struct bregs br;
496 memset(&br, 0, sizeof(br));
Kevin O'Connorf8e800d2009-09-24 21:01:16 -0400497 br.flags = F_IF;
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400498 call16_int(0x18, &br);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500499}
500
501// Boot Failure recovery: try the next device.
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500502void VISIBLE32FLAT
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500503handle_18(void)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500504{
Kevin O'Connor61d6b062008-06-21 12:15:10 -0400505 debug_serial_setup();
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400506 debug_enter(NULL, DEBUG_HDL_18);
Kevin O'Connor08815372008-12-29 21:16:31 -0500507 u16 ebda_seg = get_ebda_seg();
508 u16 seq = GET_EBDA2(ebda_seg, boot_sequence) + 1;
509 SET_EBDA2(ebda_seg, boot_sequence, seq);
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400510 do_boot(seq);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500511}
512
513// INT 19h Boot Load Service Entry Point
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500514void VISIBLE32FLAT
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500515handle_19(void)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500516{
Kevin O'Connor61d6b062008-06-21 12:15:10 -0400517 debug_serial_setup();
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400518 debug_enter(NULL, DEBUG_HDL_19);
Kevin O'Connor08815372008-12-29 21:16:31 -0500519 SET_EBDA(boot_sequence, 0);
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400520 do_boot(0);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500521}