blob: 5ae418ca56ed26674bbeabc2da4158a842e17d53 [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'Connorbaaadb62010-12-29 11:18:04 -050089static int CheckFloppySig = 1;
90
Kevin O'Connor72eee3e2010-12-27 19:07:49 -050091#define DEFAULT_PRIO 9999
92
93static int DefaultFloppyPrio = 101;
94static int DefaultCDPrio = 102;
95static int DefaultHDPrio = 103;
96static int DefaultBEVPrio = 104;
97
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -050098void
Kevin O'Connor1ca05b02010-01-03 17:43:37 -050099boot_setup(void)
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500100{
101 if (! CONFIG_BOOT)
102 return;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500103
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500104 SET_EBDA(boot_sequence, 0xffff);
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500105
106 if (!CONFIG_COREBOOT) {
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500107 // On emulators, get boot order from nvram.
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500108 if (inb_cmos(CMOS_BIOS_BOOTFLAG1) & 1)
Kevin O'Connorbaaadb62010-12-29 11:18:04 -0500109 CheckFloppySig = 0;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500110 u32 bootorder = (inb_cmos(CMOS_BIOS_BOOTFLAG2)
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500111 | ((inb_cmos(CMOS_BIOS_BOOTFLAG1) & 0xf0) << 4));
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500112 DefaultFloppyPrio = DefaultCDPrio = DefaultHDPrio
113 = DefaultBEVPrio = DEFAULT_PRIO;
114 int i;
115 for (i=101; i<104; i++) {
116 u32 val = bootorder & 0x0f;
117 bootorder >>= 4;
118 switch (val) {
119 case 1: DefaultFloppyPrio = i; break;
120 case 2: DefaultHDPrio = i; break;
121 case 3: DefaultCDPrio = i; break;
122 case 4: DefaultBEVPrio = i; break;
123 }
124 }
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500125 }
Gleb Natapovb9a75912010-12-23 11:29:38 +0200126
Kevin O'Connord1a17462010-12-24 11:17:03 -0500127 loadBootOrder();
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500128}
129
Kevin O'Connord1a17462010-12-24 11:17:03 -0500130
131/****************************************************************
Kevin O'Connor031ef552010-12-27 19:26:57 -0500132 * BootList handling
Kevin O'Connord1a17462010-12-24 11:17:03 -0500133 ****************************************************************/
134
Kevin O'Connor031ef552010-12-27 19:26:57 -0500135struct bootentry_s {
136 int type;
137 union {
138 u32 data;
139 struct segoff_s vector;
140 struct drive_s *drive;
141 };
142 int priority;
143 const char *description;
144 struct bootentry_s *next;
145};
Kevin O'Connor031ef552010-12-27 19:26:57 -0500146static struct bootentry_s *BootList;
147
Kevin O'Connor7bb15842010-12-29 11:25:14 -0500148#define IPL_TYPE_FLOPPY 0x01
149#define IPL_TYPE_HARDDISK 0x02
150#define IPL_TYPE_CDROM 0x03
151#define IPL_TYPE_CBFS 0x20
152#define IPL_TYPE_BEV 0x80
153#define IPL_TYPE_BCV 0x81
154
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500155static void
156bootentry_add(int type, int prio, u32 data, const char *desc)
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500157{
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500158 if (! CONFIG_BOOT)
159 return;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500160 struct bootentry_s *be = malloc_tmp(sizeof(*be));
161 if (!be) {
162 warn_noalloc();
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500163 return;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500164 }
165 be->type = type;
166 be->priority = prio;
167 be->data = data;
168 be->description = desc;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500169
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500170 // Add entry in sorted order.
171 struct bootentry_s **pprev;
172 for (pprev = &BootList; *pprev; pprev = &(*pprev)->next) {
173 struct bootentry_s *pos = *pprev;
174 if (be->priority < pos->priority)
175 break;
176 if (be->priority > pos->priority)
177 continue;
178 if (be->type < pos->type)
179 break;
180 if (be->type > pos->type)
181 continue;
182 if (be->type <= IPL_TYPE_CDROM
183 && (be->drive->type < pos->drive->type
184 || (be->drive->type == pos->drive->type
185 && be->drive->cntl_id < pos->drive->cntl_id)))
186 break;
187 }
188 be->next = *pprev;
189 *pprev = be;
Kevin O'Connor0a924122009-02-08 19:43:47 -0500190}
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500191
Kevin O'Connor031ef552010-12-27 19:26:57 -0500192// Return the given priority if it's set - defaultprio otherwise.
193static inline int defPrio(int priority, int defaultprio) {
194 return (priority < 0) ? defaultprio : priority;
195}
196
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500197// Add a BEV vector for a given pnp compatible option rom.
Gleb Natapov4c90a202010-12-07 13:50:54 +0200198void
Kevin O'Connor031ef552010-12-27 19:26:57 -0500199boot_add_bev(u16 seg, u16 bev, u16 desc, int prio)
Gleb Natapov4c90a202010-12-07 13:50:54 +0200200{
Kevin O'Connor031ef552010-12-27 19:26:57 -0500201 bootentry_add(IPL_TYPE_BEV, defPrio(prio, DefaultBEVPrio)
202 , SEGOFF(seg, bev).segoff
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500203 , desc ? MAKE_FLATPTR(seg, desc) : "Unknown");
204 DefaultBEVPrio = DEFAULT_PRIO;
Gleb Natapov4c90a202010-12-07 13:50:54 +0200205}
206
Kevin O'Connor0a924122009-02-08 19:43:47 -0500207// Add a bcv entry for an expansion card harddrive or legacy option rom
208void
Kevin O'Connor031ef552010-12-27 19:26:57 -0500209boot_add_bcv(u16 seg, u16 ip, u16 desc, int prio)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500210{
Kevin O'Connor031ef552010-12-27 19:26:57 -0500211 bootentry_add(IPL_TYPE_BCV, defPrio(prio, DEFAULT_PRIO)
212 , SEGOFF(seg, ip).segoff
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500213 , desc ? MAKE_FLATPTR(seg, desc) : "Legacy option rom");
Kevin O'Connor0a924122009-02-08 19:43:47 -0500214}
215
Kevin O'Connor0a924122009-02-08 19:43:47 -0500216void
Kevin O'Connor031ef552010-12-27 19:26:57 -0500217boot_add_floppy(struct drive_s *drive_g, int prio)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500218{
Kevin O'Connor031ef552010-12-27 19:26:57 -0500219 bootentry_add(IPL_TYPE_FLOPPY, defPrio(prio, DefaultFloppyPrio)
220 , (u32)drive_g, drive_g->desc);
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500221}
Kevin O'Connor0a924122009-02-08 19:43:47 -0500222
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500223void
Kevin O'Connor031ef552010-12-27 19:26:57 -0500224boot_add_hd(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_HARDDISK, defPrio(prio, DefaultHDPrio)
227 , (u32)drive_g, drive_g->desc);
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500228}
229
230void
Kevin O'Connor031ef552010-12-27 19:26:57 -0500231boot_add_cd(struct drive_s *drive_g, int prio)
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500232{
Kevin O'Connor031ef552010-12-27 19:26:57 -0500233 bootentry_add(IPL_TYPE_CDROM, defPrio(prio, DefaultCDPrio)
234 , (u32)drive_g, drive_g->desc);
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500235}
236
237// Add a CBFS payload entry
238void
Kevin O'Connor031ef552010-12-27 19:26:57 -0500239boot_add_cbfs(void *data, const char *desc, int prio)
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500240{
Kevin O'Connor031ef552010-12-27 19:26:57 -0500241 bootentry_add(IPL_TYPE_CBFS, defPrio(prio, DEFAULT_PRIO), (u32)data, desc);
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500242}
243
244
245/****************************************************************
Kevin O'Connor0a924122009-02-08 19:43:47 -0500246 * Boot menu and BCV execution
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500247 ****************************************************************/
248
Kevin O'Connor0a924122009-02-08 19:43:47 -0500249// Show IPL option menu.
250static void
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500251interactive_bootmenu(void)
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500252{
Kevin O'Connore7cc7642009-10-04 10:05:16 -0400253 if (! CONFIG_BOOTMENU || ! qemu_cfg_show_boot_menu())
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500254 return;
255
256 while (get_keystroke(0) >= 0)
257 ;
258
259 printf("Press F12 for boot menu.\n\n");
260
Kevin O'Connor9a01a9c2010-08-25 21:07:48 -0400261 enable_bootsplash();
Kevin O'Connor217d3632009-04-29 22:00:21 -0400262 int scan_code = get_keystroke(CONFIG_BOOTMENU_WAIT);
Kevin O'Connor9a01a9c2010-08-25 21:07:48 -0400263 disable_bootsplash();
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500264 if (scan_code != 0x86)
265 /* not F12 */
266 return;
267
268 while (get_keystroke(0) >= 0)
269 ;
270
271 printf("Select boot device:\n\n");
Kevin O'Connore438b0c2010-05-01 12:20:33 -0400272 wait_threads();
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500273
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500274 // Show menu items
275 struct bootentry_s *pos = BootList;
276 int maxmenu = 0;
277 while (pos) {
278 char desc[60];
279 maxmenu++;
280 printf("%d. %s\n", maxmenu
281 , strtcpy(desc, pos->description, ARRAY_SIZE(desc)));
282 pos = pos->next;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500283 }
284
Kevin O'Connor551caa22010-12-29 13:25:18 -0500285 // Get key press
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500286 for (;;) {
287 scan_code = get_keystroke(1000);
Kevin O'Connor551caa22010-12-29 13:25:18 -0500288 if (scan_code >= 1 && scan_code <= maxmenu+1)
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500289 break;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500290 }
291 printf("\n");
Kevin O'Connor551caa22010-12-29 13:25:18 -0500292 if (scan_code == 0x01)
293 // ESC
294 return;
295
296 // Find entry and make top priority.
297 int choice = scan_code - 1;
298 struct bootentry_s **pprev = &BootList;
299 while (--choice)
300 pprev = &(*pprev)->next;
301 pos = *pprev;
302 *pprev = pos->next;
303 pos->next = BootList;
304 BootList = pos;
305 pos->priority = 0;
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500306}
307
Kevin O'Connor7bb15842010-12-29 11:25:14 -0500308struct bev_s {
309 int type;
310 u32 vector;
311};
312static struct bev_s BEV[20];
313static int BEVCount;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500314static int HaveHDBoot, HaveFDBoot;
315
Kevin O'Connor0a924122009-02-08 19:43:47 -0500316static void
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500317add_bev(int type, u32 vector)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500318{
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500319 if (type == IPL_TYPE_HARDDISK && HaveHDBoot++)
320 return;
321 if (type == IPL_TYPE_FLOPPY && HaveFDBoot++)
322 return;
Kevin O'Connor7bb15842010-12-29 11:25:14 -0500323 if (BEVCount >= ARRAY_SIZE(BEV))
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500324 return;
Kevin O'Connor7bb15842010-12-29 11:25:14 -0500325 struct bev_s *bev = &BEV[BEVCount++];
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500326 bev->type = type;
327 bev->vector = vector;
Kevin O'Connor0a924122009-02-08 19:43:47 -0500328}
329
330// Prepare for boot - show menu and run bcvs.
331void
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500332boot_prep(void)
Kevin O'Connor0a924122009-02-08 19:43:47 -0500333{
Kevin O'Connore438b0c2010-05-01 12:20:33 -0400334 if (! CONFIG_BOOT) {
335 wait_threads();
Kevin O'Connor0a924122009-02-08 19:43:47 -0500336 return;
Kevin O'Connore438b0c2010-05-01 12:20:33 -0400337 }
Kevin O'Connor0a924122009-02-08 19:43:47 -0500338
Kevin O'Connora5826b52009-10-24 17:57:29 -0400339 // XXX - show available drives?
340
Kevin O'Connor0a924122009-02-08 19:43:47 -0500341 // Allow user to modify BCV/IPL order.
342 interactive_bootmenu();
Kevin O'Connore438b0c2010-05-01 12:20:33 -0400343 wait_threads();
Kevin O'Connor0a924122009-02-08 19:43:47 -0500344
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500345 // Map drives and populate BEV list
346 struct bootentry_s *pos = BootList;
347 while (pos) {
348 switch (pos->type) {
349 case IPL_TYPE_BCV:
350 call_bcv(pos->vector.seg, pos->vector.offset);
351 add_bev(IPL_TYPE_HARDDISK, 0);
352 break;
353 case IPL_TYPE_FLOPPY:
354 map_floppy_drive(pos->drive);
355 add_bev(IPL_TYPE_FLOPPY, 0);
356 break;
357 case IPL_TYPE_HARDDISK:
358 map_hd_drive(pos->drive);
359 add_bev(IPL_TYPE_HARDDISK, 0);
360 break;
361 case IPL_TYPE_CDROM:
362 map_cd_drive(pos->drive);
363 // NO BREAK
364 default:
365 add_bev(pos->type, pos->data);
366 break;
367 }
368 pos = pos->next;
369 }
Kevin O'Connorafd05202009-08-16 12:21:44 -0400370
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500371 // If nothing added a floppy/hd boot - add it manually.
372 add_bev(IPL_TYPE_FLOPPY, 0);
373 add_bev(IPL_TYPE_HARDDISK, 0);
Kevin O'Connor0a924122009-02-08 19:43:47 -0500374}
375
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500376
377/****************************************************************
378 * Boot code (int 18/19)
379 ****************************************************************/
380
Kevin O'Connor0a924122009-02-08 19:43:47 -0500381// Jump to a bootup entry point.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500382static void
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500383call_boot_entry(u16 bootseg, u16 bootip, u8 bootdrv)
384{
Kevin O'Connorcadaf0e2010-07-26 23:47:26 -0400385 dprintf(1, "Booting from %04x:%04x\n", bootseg, bootip);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500386 struct bregs br;
387 memset(&br, 0, sizeof(br));
Kevin O'Connorf8e800d2009-09-24 21:01:16 -0400388 br.flags = F_IF;
Kevin O'Connor9f985422009-09-09 11:34:39 -0400389 br.code = SEGOFF(bootseg, bootip);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500390 // Set the magic number in ax and the boot drive in dl.
391 br.dl = bootdrv;
392 br.ax = 0xaa55;
393 call16(&br);
394}
395
396// Boot from a disk (either floppy or harddrive)
397static void
398boot_disk(u8 bootdrv, int checksig)
399{
400 u16 bootseg = 0x07c0;
401
402 // Read sector
403 struct bregs br;
404 memset(&br, 0, sizeof(br));
Kevin O'Connorf8e800d2009-09-24 21:01:16 -0400405 br.flags = F_IF;
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500406 br.dl = bootdrv;
407 br.es = bootseg;
408 br.ah = 2;
409 br.al = 1;
410 br.cl = 1;
411 call16_int(0x13, &br);
412
413 if (br.flags & F_CF) {
414 printf("Boot failed: could not read the boot disk\n\n");
415 return;
416 }
417
418 if (checksig) {
419 struct mbr_s *mbr = (void*)0;
420 if (GET_FARVAR(bootseg, mbr->signature) != MBR_SIGNATURE) {
421 printf("Boot failed: not a bootable disk\n\n");
422 return;
423 }
424 }
425
426 /* Canonicalize bootseg:bootip */
427 u16 bootip = (bootseg & 0x0fff) << 4;
428 bootseg &= 0xf000;
429
430 call_boot_entry(bootseg, bootip, bootdrv);
431}
432
433// Boot from a CD-ROM
434static void
Kevin O'Connor7bb15842010-12-29 11:25:14 -0500435boot_cdrom(struct bev_s *ie)
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500436{
437 if (! CONFIG_CDROM_BOOT)
438 return;
Gleb Natapov4c90a202010-12-07 13:50:54 +0200439
440 if (!ie->vector)
441 return;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500442 printf("Booting from DVD/CD...\n");
Gleb Natapov4c90a202010-12-07 13:50:54 +0200443
444 struct drive_s *drive_g = (void*)ie->vector;
445 int status = cdrom_boot(drive_g);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500446 if (status) {
Kevin O'Connorecbcf772010-12-29 13:26:01 -0500447 printf("Boot failed: Could not read from CDROM (code %04x)\n", status);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500448 return;
449 }
450
451 u16 ebda_seg = get_ebda_seg();
Kevin O'Connor669e6442009-08-11 22:36:30 -0400452 u8 bootdrv = GET_EBDA2(ebda_seg, cdemu.emulated_extdrive);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500453 u16 bootseg = GET_EBDA2(ebda_seg, cdemu.load_segment);
454 /* Canonicalize bootseg:bootip */
455 u16 bootip = (bootseg & 0x0fff) << 4;
456 bootseg &= 0xf000;
457
458 call_boot_entry(bootseg, bootip, bootdrv);
459}
460
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400461// Boot from a CBFS payload
Kevin O'Connor67823442009-04-13 14:14:51 -0400462static void
Kevin O'Connor7bb15842010-12-29 11:25:14 -0500463boot_cbfs(struct bev_s *ie)
Kevin O'Connor67823442009-04-13 14:14:51 -0400464{
Kevin O'Connord9c93612010-03-20 11:00:45 -0400465 if (!CONFIG_COREBOOT || !CONFIG_COREBOOT_FLASH)
Kevin O'Connor67823442009-04-13 14:14:51 -0400466 return;
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500467 printf("Booting from CBFS...\n");
468 cbfs_run_payload((void*)ie->vector);
Kevin O'Connor67823442009-04-13 14:14:51 -0400469}
470
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500471static void
472do_boot(u16 seq_nr)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500473{
Kevin O'Connor40967022008-07-21 22:23:05 -0400474 if (! CONFIG_BOOT)
Kevin O'Connore07e18e2009-02-08 17:07:29 -0500475 panic("Boot support not compiled in.\n");
Kevin O'Connor40967022008-07-21 22:23:05 -0400476
Kevin O'Connor7bb15842010-12-29 11:25:14 -0500477 if (seq_nr >= BEVCount) {
Kevin O'Connorff8c1412009-04-18 17:02:41 -0400478 printf("No bootable device.\n");
479 // Loop with irqs enabled - this allows ctrl+alt+delete to work.
480 for (;;)
Kevin O'Connor9c447c32010-05-23 10:24:22 -0400481 wait_irq();
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500482 }
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500483
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500484 // Boot the given BEV type.
Kevin O'Connor7bb15842010-12-29 11:25:14 -0500485 struct bev_s *ie = &BEV[seq_nr];
Kevin O'Connorcadaf0e2010-07-26 23:47:26 -0400486 switch (ie->type) {
Kevin O'Connorf13b0082008-08-17 11:26:42 -0400487 case IPL_TYPE_FLOPPY:
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500488 printf("Booting from Floppy...\n");
Kevin O'Connorbaaadb62010-12-29 11:18:04 -0500489 boot_disk(0x00, CheckFloppySig);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500490 break;
Kevin O'Connorf13b0082008-08-17 11:26:42 -0400491 case IPL_TYPE_HARDDISK:
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500492 printf("Booting from Hard Disk...\n");
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500493 boot_disk(0x80, 1);
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500494 break;
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500495 case IPL_TYPE_CDROM:
Kevin O'Connor67823442009-04-13 14:14:51 -0400496 boot_cdrom(ie);
497 break;
498 case IPL_TYPE_CBFS:
499 boot_cbfs(ie);
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500500 break;
501 case IPL_TYPE_BEV:
Kevin O'Connor72eee3e2010-12-27 19:07:49 -0500502 printf("Booting from ROM...\n");
Kevin O'Connor71f036d2009-02-08 16:57:22 -0500503 call_boot_entry(ie->vector >> 16, ie->vector & 0xffff, 0);
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500504 break;
Kevin O'Connor180a9592008-03-04 22:50:53 -0500505 }
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500506
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500507 // Boot failed: invoke the boot recovery function
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400508 struct bregs br;
509 memset(&br, 0, sizeof(br));
Kevin O'Connorf8e800d2009-09-24 21:01:16 -0400510 br.flags = F_IF;
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400511 call16_int(0x18, &br);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500512}
513
514// Boot Failure recovery: try the next device.
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500515void VISIBLE32FLAT
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500516handle_18(void)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500517{
Kevin O'Connor61d6b062008-06-21 12:15:10 -0400518 debug_serial_setup();
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400519 debug_enter(NULL, DEBUG_HDL_18);
Kevin O'Connor08815372008-12-29 21:16:31 -0500520 u16 ebda_seg = get_ebda_seg();
521 u16 seq = GET_EBDA2(ebda_seg, boot_sequence) + 1;
522 SET_EBDA2(ebda_seg, boot_sequence, seq);
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400523 do_boot(seq);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500524}
525
526// INT 19h Boot Load Service Entry Point
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500527void VISIBLE32FLAT
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500528handle_19(void)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500529{
Kevin O'Connor61d6b062008-06-21 12:15:10 -0400530 debug_serial_setup();
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400531 debug_enter(NULL, DEBUG_HDL_19);
Kevin O'Connor08815372008-12-29 21:16:31 -0500532 SET_EBDA(boot_sequence, 0);
Kevin O'Connor7af49bf2008-03-09 13:46:13 -0400533 do_boot(0);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500534}