Kevin O'Connor | f13b008 | 2008-08-17 11:26:42 -0400 | [diff] [blame] | 1 | // Code to load disk image and start system boot. |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 2 | // |
| 3 | // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net> |
| 4 | // Copyright (C) 2002 MandrakeSoft S.A. |
| 5 | // |
Kevin O'Connor | b1b7c2a | 2009-01-15 20:52:58 -0500 | [diff] [blame] | 6 | // This file may be distributed under the terms of the GNU LGPLv3 license. |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 7 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 8 | #include "util.h" // irq_enable |
Kevin O'Connor | 9521e26 | 2008-07-04 13:04:29 -0400 | [diff] [blame] | 9 | #include "biosvar.h" // GET_EBDA |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 10 | #include "config.h" // CONFIG_* |
Kevin O'Connor | 180a959 | 2008-03-04 22:50:53 -0500 | [diff] [blame] | 11 | #include "disk.h" // cdrom_boot |
Kevin O'Connor | 9521e26 | 2008-07-04 13:04:29 -0400 | [diff] [blame] | 12 | #include "bregs.h" // struct bregs |
Kevin O'Connor | c659fde | 2008-12-28 23:43:20 -0500 | [diff] [blame] | 13 | #include "boot.h" // struct ipl_s |
Kevin O'Connor | 9f4e1d9 | 2009-02-08 15:44:08 -0500 | [diff] [blame] | 14 | #include "cmos.h" // inb_cmos |
Kevin O'Connor | c659fde | 2008-12-28 23:43:20 -0500 | [diff] [blame] | 15 | |
| 16 | struct ipl_s IPL; |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 17 | |
Kevin O'Connor | 9f4e1d9 | 2009-02-08 15:44:08 -0500 | [diff] [blame] | 18 | |
| 19 | /**************************************************************** |
Kevin O'Connor | 0a92412 | 2009-02-08 19:43:47 -0500 | [diff] [blame] | 20 | * IPL and BCV handlers |
Kevin O'Connor | 9f4e1d9 | 2009-02-08 15:44:08 -0500 | [diff] [blame] | 21 | ****************************************************************/ |
| 22 | |
| 23 | void |
| 24 | boot_setup() |
| 25 | { |
| 26 | if (! CONFIG_BOOT) |
| 27 | return; |
| 28 | dprintf(3, "init boot device ordering\n"); |
| 29 | |
| 30 | memset(&IPL, 0, sizeof(IPL)); |
| 31 | |
| 32 | // Floppy drive |
Kevin O'Connor | 0a92412 | 2009-02-08 19:43:47 -0500 | [diff] [blame] | 33 | struct ipl_entry_s *ie = &IPL.bev[0]; |
Kevin O'Connor | 71f036d | 2009-02-08 16:57:22 -0500 | [diff] [blame] | 34 | ie->type = IPL_TYPE_FLOPPY; |
| 35 | ie->description = "Floppy"; |
| 36 | ie++; |
Kevin O'Connor | 9f4e1d9 | 2009-02-08 15:44:08 -0500 | [diff] [blame] | 37 | |
| 38 | // First HDD |
Kevin O'Connor | 71f036d | 2009-02-08 16:57:22 -0500 | [diff] [blame] | 39 | ie->type = IPL_TYPE_HARDDISK; |
| 40 | ie->description = "Hard Disk"; |
| 41 | ie++; |
Kevin O'Connor | 9f4e1d9 | 2009-02-08 15:44:08 -0500 | [diff] [blame] | 42 | |
| 43 | // CDROM |
| 44 | if (CONFIG_CDROM_BOOT) { |
Kevin O'Connor | 71f036d | 2009-02-08 16:57:22 -0500 | [diff] [blame] | 45 | ie->type = IPL_TYPE_CDROM; |
| 46 | ie->description = "CD-Rom"; |
| 47 | ie++; |
Kevin O'Connor | 9f4e1d9 | 2009-02-08 15:44:08 -0500 | [diff] [blame] | 48 | } |
| 49 | |
Kevin O'Connor | 0a92412 | 2009-02-08 19:43:47 -0500 | [diff] [blame] | 50 | IPL.bevcount = ie - IPL.bev; |
| 51 | IPL.bcv_override = -1; |
Kevin O'Connor | 9f4e1d9 | 2009-02-08 15:44:08 -0500 | [diff] [blame] | 52 | SET_EBDA(boot_sequence, 0xffff); |
| 53 | if (CONFIG_COREBOOT) { |
| 54 | // XXX - hardcode defaults for coreboot. |
| 55 | IPL.bootorder = 0x00000231; |
| 56 | IPL.checkfloppysig = 1; |
| 57 | } else { |
| 58 | // On emulators, get boot order from nvram. |
| 59 | IPL.bootorder = (inb_cmos(CMOS_BIOS_BOOTFLAG2) |
| 60 | | ((inb_cmos(CMOS_BIOS_BOOTFLAG1) & 0xf0) << 4)); |
| 61 | if (!(inb_cmos(CMOS_BIOS_BOOTFLAG1) & 1)) |
| 62 | IPL.checkfloppysig = 1; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | // Add a BEV vector for a given pnp compatible option rom. |
| 67 | void |
| 68 | add_bev(u16 seg, u16 bev, u16 desc) |
| 69 | { |
Kevin O'Connor | 9f4e1d9 | 2009-02-08 15:44:08 -0500 | [diff] [blame] | 70 | if (! CONFIG_BOOT) |
| 71 | return; |
Kevin O'Connor | 0a92412 | 2009-02-08 19:43:47 -0500 | [diff] [blame] | 72 | if (IPL.bevcount >= ARRAY_SIZE(IPL.bev)) |
Kevin O'Connor | 9f4e1d9 | 2009-02-08 15:44:08 -0500 | [diff] [blame] | 73 | return; |
| 74 | |
Kevin O'Connor | 0a92412 | 2009-02-08 19:43:47 -0500 | [diff] [blame] | 75 | struct ipl_entry_s *ie = &IPL.bev[IPL.bevcount++]; |
Kevin O'Connor | 71f036d | 2009-02-08 16:57:22 -0500 | [diff] [blame] | 76 | ie->type = IPL_TYPE_BEV; |
| 77 | ie->vector = (seg << 16) | bev; |
Kevin O'Connor | 0a92412 | 2009-02-08 19:43:47 -0500 | [diff] [blame] | 78 | const char *d = "Unknown"; |
Kevin O'Connor | 9f4e1d9 | 2009-02-08 15:44:08 -0500 | [diff] [blame] | 79 | if (desc) |
Kevin O'Connor | 0a92412 | 2009-02-08 19:43:47 -0500 | [diff] [blame] | 80 | d = MAKE_FLATPTR(seg, desc); |
| 81 | ie->description = d; |
| 82 | } |
Kevin O'Connor | 9f4e1d9 | 2009-02-08 15:44:08 -0500 | [diff] [blame] | 83 | |
Kevin O'Connor | 0a92412 | 2009-02-08 19:43:47 -0500 | [diff] [blame] | 84 | // Add a bcv entry for an expansion card harddrive or legacy option rom |
| 85 | void |
| 86 | add_bcv(u16 seg, u16 ip, u16 desc) |
| 87 | { |
| 88 | if (! CONFIG_BOOT) |
| 89 | return; |
| 90 | if (IPL.bcvcount >= ARRAY_SIZE(IPL.bcv)) |
| 91 | return; |
| 92 | |
| 93 | struct ipl_entry_s *ie = &IPL.bcv[IPL.bcvcount++]; |
| 94 | ie->type = IPL_TYPE_BEV; |
| 95 | ie->vector = (seg << 16) | ip; |
| 96 | const char *d = "Legacy option rom"; |
| 97 | if (desc) |
| 98 | d = MAKE_FLATPTR(seg, desc); |
| 99 | ie->description = d; |
| 100 | } |
| 101 | |
| 102 | // Add a bcv entry for an ata harddrive |
| 103 | void |
| 104 | add_bcv_hd(int driveid, const char *desc) |
| 105 | { |
| 106 | if (! CONFIG_BOOT) |
| 107 | return; |
| 108 | if (IPL.bcvcount >= ARRAY_SIZE(IPL.bcv)) |
| 109 | return; |
| 110 | |
| 111 | struct ipl_entry_s *ie = &IPL.bcv[IPL.bcvcount++]; |
| 112 | ie->type = IPL_TYPE_HARDDISK; |
| 113 | ie->vector = driveid; |
| 114 | ie->description = desc; |
Kevin O'Connor | 9f4e1d9 | 2009-02-08 15:44:08 -0500 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | |
| 118 | /**************************************************************** |
Kevin O'Connor | 0a92412 | 2009-02-08 19:43:47 -0500 | [diff] [blame] | 119 | * Boot menu and BCV execution |
Kevin O'Connor | 9f4e1d9 | 2009-02-08 15:44:08 -0500 | [diff] [blame] | 120 | ****************************************************************/ |
| 121 | |
Kevin O'Connor | 0a92412 | 2009-02-08 19:43:47 -0500 | [diff] [blame] | 122 | // Show a generic menu item |
| 123 | static int |
| 124 | menu_show_default(struct ipl_entry_s *ie, int menupos) |
| 125 | { |
| 126 | char desc[33]; |
| 127 | printf("%d. %s\n", menupos |
| 128 | , strtcpy(desc, ie->description, ARRAY_SIZE(desc))); |
| 129 | return 1; |
| 130 | } |
| 131 | |
| 132 | // Show floppy menu item - but only if there exists a floppy drive. |
| 133 | static int |
| 134 | menu_show_floppy(struct ipl_entry_s *ie, int menupos) |
| 135 | { |
| 136 | if (!FloppyCount) |
| 137 | return 0; |
| 138 | return menu_show_default(ie, menupos); |
| 139 | } |
| 140 | |
| 141 | // Show menu items from BCV list. |
| 142 | static int |
| 143 | menu_show_harddisk(struct ipl_entry_s *ie, int menupos) |
| 144 | { |
| 145 | int i; |
| 146 | for (i = 0; i < IPL.bcvcount; i++) { |
| 147 | struct ipl_entry_s *ie = &IPL.bcv[i]; |
| 148 | switch (ie->type) { |
| 149 | case IPL_TYPE_HARDDISK: |
| 150 | printf("%d. ata%d-%d %s\n", menupos + i |
| 151 | , ie->vector / 2, ie->vector %2, ie->description); |
| 152 | break; |
| 153 | default: |
| 154 | menu_show_default(ie, menupos+i); |
| 155 | break; |
| 156 | } |
| 157 | } |
| 158 | return IPL.bcvcount; |
| 159 | } |
| 160 | |
| 161 | // Show cdrom menu item - but only if there exists a cdrom drive. |
| 162 | static int |
| 163 | menu_show_cdrom(struct ipl_entry_s *ie, int menupos) |
| 164 | { |
| 165 | if (!ATA.cdcount) |
| 166 | return 0; |
| 167 | return menu_show_default(ie, menupos); |
| 168 | } |
| 169 | |
| 170 | // Show IPL option menu. |
| 171 | static void |
Kevin O'Connor | 9f4e1d9 | 2009-02-08 15:44:08 -0500 | [diff] [blame] | 172 | interactive_bootmenu() |
| 173 | { |
| 174 | if (! CONFIG_BOOTMENU) |
| 175 | return; |
| 176 | |
| 177 | while (get_keystroke(0) >= 0) |
| 178 | ; |
| 179 | |
| 180 | printf("Press F12 for boot menu.\n\n"); |
| 181 | |
| 182 | int scan_code = get_keystroke(2500); |
| 183 | if (scan_code != 0x86) |
| 184 | /* not F12 */ |
| 185 | return; |
| 186 | |
| 187 | while (get_keystroke(0) >= 0) |
| 188 | ; |
| 189 | |
| 190 | printf("Select boot device:\n\n"); |
| 191 | |
Kevin O'Connor | 0a92412 | 2009-02-08 19:43:47 -0500 | [diff] [blame] | 192 | int subcount[ARRAY_SIZE(IPL.bev)]; |
| 193 | int menupos = 1; |
Kevin O'Connor | 9f4e1d9 | 2009-02-08 15:44:08 -0500 | [diff] [blame] | 194 | int i; |
Kevin O'Connor | 0a92412 | 2009-02-08 19:43:47 -0500 | [diff] [blame] | 195 | for (i = 0; i < IPL.bevcount; i++) { |
| 196 | struct ipl_entry_s *ie = &IPL.bev[i]; |
| 197 | int sc = 1; |
| 198 | switch (ie->type) { |
| 199 | case IPL_TYPE_FLOPPY: |
| 200 | sc = menu_show_floppy(ie, menupos); |
| 201 | break; |
| 202 | case IPL_TYPE_HARDDISK: |
| 203 | sc = menu_show_harddisk(ie, menupos); |
| 204 | break; |
| 205 | case IPL_TYPE_CDROM: |
| 206 | sc = menu_show_cdrom(ie, menupos); |
| 207 | break; |
| 208 | default: |
| 209 | sc = menu_show_default(ie, menupos); |
| 210 | break; |
| 211 | } |
| 212 | subcount[i] = sc; |
| 213 | menupos += sc; |
Kevin O'Connor | 9f4e1d9 | 2009-02-08 15:44:08 -0500 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | for (;;) { |
| 217 | scan_code = get_keystroke(1000); |
| 218 | if (scan_code == 0x01) |
| 219 | // ESC |
| 220 | break; |
Kevin O'Connor | 0a92412 | 2009-02-08 19:43:47 -0500 | [diff] [blame] | 221 | if (scan_code < 1 || scan_code > menupos) |
| 222 | continue; |
| 223 | int choice = scan_code - 1; |
| 224 | |
| 225 | // Find out which IPL this was for. |
| 226 | int bev = 0; |
| 227 | while (choice > subcount[bev]) { |
| 228 | choice -= subcount[bev]; |
| 229 | bev++; |
Kevin O'Connor | 9f4e1d9 | 2009-02-08 15:44:08 -0500 | [diff] [blame] | 230 | } |
Kevin O'Connor | 0a92412 | 2009-02-08 19:43:47 -0500 | [diff] [blame] | 231 | |
| 232 | // A harddrive request enables a BCV order. |
| 233 | if (IPL.bev[bev].type == IPL_TYPE_HARDDISK) |
| 234 | IPL.bcv_override = choice-1; |
| 235 | |
| 236 | // Add user choice to the boot order. |
| 237 | IPL.bootorder = (IPL.bootorder << 4) | (bev+1); |
| 238 | break; |
Kevin O'Connor | 9f4e1d9 | 2009-02-08 15:44:08 -0500 | [diff] [blame] | 239 | } |
| 240 | printf("\n"); |
| 241 | } |
| 242 | |
Kevin O'Connor | 0a92412 | 2009-02-08 19:43:47 -0500 | [diff] [blame] | 243 | // Run the specified bcv. |
| 244 | static void |
| 245 | run_bcv(struct ipl_entry_s *ie) |
| 246 | { |
| 247 | switch (ie->type) { |
| 248 | case IPL_TYPE_HARDDISK: |
| 249 | map_drive(ie->vector); |
| 250 | break; |
| 251 | case IPL_TYPE_BEV: |
| 252 | call_bcv(ie->vector >> 16, ie->vector & 0xffff); |
| 253 | break; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | // Prepare for boot - show menu and run bcvs. |
| 258 | void |
| 259 | boot_prep() |
| 260 | { |
| 261 | if (! CONFIG_BOOT) |
| 262 | return; |
| 263 | |
| 264 | // Allow user to modify BCV/IPL order. |
| 265 | interactive_bootmenu(); |
| 266 | |
| 267 | // Run BCVs |
| 268 | int override = IPL.bcv_override; |
| 269 | if (override >= 0) |
| 270 | run_bcv(&IPL.bcv[override]); |
| 271 | int i; |
| 272 | for (i=0; i<IPL.bcvcount; i++) |
| 273 | if (i != override) |
| 274 | run_bcv(&IPL.bcv[i]); |
| 275 | } |
| 276 | |
Kevin O'Connor | 9f4e1d9 | 2009-02-08 15:44:08 -0500 | [diff] [blame] | 277 | |
| 278 | /**************************************************************** |
| 279 | * Boot code (int 18/19) |
| 280 | ****************************************************************/ |
| 281 | |
Kevin O'Connor | 0a92412 | 2009-02-08 19:43:47 -0500 | [diff] [blame] | 282 | // Jump to a bootup entry point. |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 283 | static void |
Kevin O'Connor | 71f036d | 2009-02-08 16:57:22 -0500 | [diff] [blame] | 284 | call_boot_entry(u16 bootseg, u16 bootip, u8 bootdrv) |
| 285 | { |
| 286 | dprintf(1, "Booting from %x:%x\n", bootseg, bootip); |
| 287 | |
| 288 | struct bregs br; |
| 289 | memset(&br, 0, sizeof(br)); |
| 290 | br.ip = bootip; |
| 291 | br.cs = bootseg; |
| 292 | // Set the magic number in ax and the boot drive in dl. |
| 293 | br.dl = bootdrv; |
| 294 | br.ax = 0xaa55; |
| 295 | call16(&br); |
| 296 | } |
| 297 | |
| 298 | // Boot from a disk (either floppy or harddrive) |
| 299 | static void |
| 300 | boot_disk(u8 bootdrv, int checksig) |
| 301 | { |
| 302 | u16 bootseg = 0x07c0; |
| 303 | |
| 304 | // Read sector |
| 305 | struct bregs br; |
| 306 | memset(&br, 0, sizeof(br)); |
| 307 | br.dl = bootdrv; |
| 308 | br.es = bootseg; |
| 309 | br.ah = 2; |
| 310 | br.al = 1; |
| 311 | br.cl = 1; |
| 312 | call16_int(0x13, &br); |
| 313 | |
| 314 | if (br.flags & F_CF) { |
| 315 | printf("Boot failed: could not read the boot disk\n\n"); |
| 316 | return; |
| 317 | } |
| 318 | |
| 319 | if (checksig) { |
| 320 | struct mbr_s *mbr = (void*)0; |
| 321 | if (GET_FARVAR(bootseg, mbr->signature) != MBR_SIGNATURE) { |
| 322 | printf("Boot failed: not a bootable disk\n\n"); |
| 323 | return; |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | /* Canonicalize bootseg:bootip */ |
| 328 | u16 bootip = (bootseg & 0x0fff) << 4; |
| 329 | bootseg &= 0xf000; |
| 330 | |
| 331 | call_boot_entry(bootseg, bootip, bootdrv); |
| 332 | } |
| 333 | |
| 334 | // Boot from a CD-ROM |
| 335 | static void |
| 336 | boot_cdrom() |
| 337 | { |
| 338 | if (! CONFIG_CDROM_BOOT) |
| 339 | return; |
| 340 | int status = cdrom_boot(); |
| 341 | if (status) { |
| 342 | printf("Boot failed: Could not read from CDROM (code %04x)\n", status); |
| 343 | return; |
| 344 | } |
| 345 | |
| 346 | u16 ebda_seg = get_ebda_seg(); |
| 347 | u8 bootdrv = GET_EBDA2(ebda_seg, cdemu.emulated_drive); |
| 348 | u16 bootseg = GET_EBDA2(ebda_seg, cdemu.load_segment); |
| 349 | /* Canonicalize bootseg:bootip */ |
| 350 | u16 bootip = (bootseg & 0x0fff) << 4; |
| 351 | bootseg &= 0xf000; |
| 352 | |
| 353 | call_boot_entry(bootseg, bootip, bootdrv); |
| 354 | } |
| 355 | |
| 356 | static void |
| 357 | do_boot(u16 seq_nr) |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 358 | { |
Kevin O'Connor | 4096702 | 2008-07-21 22:23:05 -0400 | [diff] [blame] | 359 | if (! CONFIG_BOOT) |
Kevin O'Connor | e07e18e | 2009-02-08 17:07:29 -0500 | [diff] [blame] | 360 | panic("Boot support not compiled in.\n"); |
Kevin O'Connor | 4096702 | 2008-07-21 22:23:05 -0400 | [diff] [blame] | 361 | |
Kevin O'Connor | c659fde | 2008-12-28 23:43:20 -0500 | [diff] [blame] | 362 | u32 bootdev = IPL.bootorder; |
Kevin O'Connor | 840c534 | 2008-03-29 14:04:34 -0400 | [diff] [blame] | 363 | bootdev >>= 4 * seq_nr; |
| 364 | bootdev &= 0xf; |
Kevin O'Connor | e0113c9 | 2008-04-05 15:51:12 -0400 | [diff] [blame] | 365 | |
Kevin O'Connor | 840c534 | 2008-03-29 14:04:34 -0400 | [diff] [blame] | 366 | if (bootdev == 0) |
Kevin O'Connor | e07e18e | 2009-02-08 17:07:29 -0500 | [diff] [blame] | 367 | panic("No bootable device.\n"); |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 368 | |
Kevin O'Connor | abc7597 | 2008-05-18 00:20:53 -0400 | [diff] [blame] | 369 | /* Translate bootdev to an IPL table offset by subtracting 1 */ |
Kevin O'Connor | 840c534 | 2008-03-29 14:04:34 -0400 | [diff] [blame] | 370 | bootdev -= 1; |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 371 | |
Kevin O'Connor | 0a92412 | 2009-02-08 19:43:47 -0500 | [diff] [blame] | 372 | if (bootdev >= IPL.bevcount) { |
Kevin O'Connor | ac8df8c | 2008-05-24 23:46:33 -0400 | [diff] [blame] | 373 | dprintf(1, "Invalid boot device (0x%x)\n", bootdev); |
Kevin O'Connor | 71f036d | 2009-02-08 16:57:22 -0500 | [diff] [blame] | 374 | goto fail; |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 375 | } |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 376 | |
| 377 | /* Do the loading, and set up vector as a far pointer to the boot |
| 378 | * address, and bootdrv as the boot drive */ |
Kevin O'Connor | 0a92412 | 2009-02-08 19:43:47 -0500 | [diff] [blame] | 379 | struct ipl_entry_s *ie = &IPL.bev[bootdev]; |
Kevin O'Connor | 71f036d | 2009-02-08 16:57:22 -0500 | [diff] [blame] | 380 | char desc[33]; |
| 381 | printf("Booting from %s...\n" |
| 382 | , strtcpy(desc, ie->description, ARRAY_SIZE(desc))); |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 383 | |
Kevin O'Connor | 71f036d | 2009-02-08 16:57:22 -0500 | [diff] [blame] | 384 | switch(ie->type) { |
Kevin O'Connor | f13b008 | 2008-08-17 11:26:42 -0400 | [diff] [blame] | 385 | case IPL_TYPE_FLOPPY: |
Kevin O'Connor | 71f036d | 2009-02-08 16:57:22 -0500 | [diff] [blame] | 386 | boot_disk(0x00, IPL.checkfloppysig); |
| 387 | break; |
Kevin O'Connor | f13b008 | 2008-08-17 11:26:42 -0400 | [diff] [blame] | 388 | case IPL_TYPE_HARDDISK: |
Kevin O'Connor | 71f036d | 2009-02-08 16:57:22 -0500 | [diff] [blame] | 389 | boot_disk(0x80, 1); |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 390 | break; |
Kevin O'Connor | 71f036d | 2009-02-08 16:57:22 -0500 | [diff] [blame] | 391 | case IPL_TYPE_CDROM: |
| 392 | boot_cdrom(); |
| 393 | break; |
| 394 | case IPL_TYPE_BEV: |
| 395 | call_boot_entry(ie->vector >> 16, ie->vector & 0xffff, 0); |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 396 | break; |
Kevin O'Connor | 180a959 | 2008-03-04 22:50:53 -0500 | [diff] [blame] | 397 | } |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 398 | |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 399 | // Boot failed: invoke the boot recovery function |
Kevin O'Connor | 7af49bf | 2008-03-09 13:46:13 -0400 | [diff] [blame] | 400 | struct bregs br; |
Kevin O'Connor | 71f036d | 2009-02-08 16:57:22 -0500 | [diff] [blame] | 401 | fail: |
Kevin O'Connor | 7af49bf | 2008-03-09 13:46:13 -0400 | [diff] [blame] | 402 | memset(&br, 0, sizeof(br)); |
| 403 | call16_int(0x18, &br); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | // Boot Failure recovery: try the next device. |
Kevin O'Connor | 44eeaf1 | 2008-07-06 10:14:49 -0400 | [diff] [blame] | 407 | void VISIBLE32 |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 408 | handle_18() |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 409 | { |
Kevin O'Connor | 61d6b06 | 2008-06-21 12:15:10 -0400 | [diff] [blame] | 410 | debug_serial_setup(); |
Kevin O'Connor | 15c1f22 | 2008-06-12 22:59:43 -0400 | [diff] [blame] | 411 | debug_enter(NULL, DEBUG_HDL_18); |
Kevin O'Connor | 0881537 | 2008-12-29 21:16:31 -0500 | [diff] [blame] | 412 | u16 ebda_seg = get_ebda_seg(); |
| 413 | u16 seq = GET_EBDA2(ebda_seg, boot_sequence) + 1; |
| 414 | SET_EBDA2(ebda_seg, boot_sequence, seq); |
Kevin O'Connor | 7af49bf | 2008-03-09 13:46:13 -0400 | [diff] [blame] | 415 | do_boot(seq); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | // INT 19h Boot Load Service Entry Point |
Kevin O'Connor | 44eeaf1 | 2008-07-06 10:14:49 -0400 | [diff] [blame] | 419 | void VISIBLE32 |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 420 | handle_19() |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 421 | { |
Kevin O'Connor | 61d6b06 | 2008-06-21 12:15:10 -0400 | [diff] [blame] | 422 | debug_serial_setup(); |
Kevin O'Connor | 15c1f22 | 2008-06-12 22:59:43 -0400 | [diff] [blame] | 423 | debug_enter(NULL, DEBUG_HDL_19); |
Kevin O'Connor | 0881537 | 2008-12-29 21:16:31 -0500 | [diff] [blame] | 424 | SET_EBDA(boot_sequence, 0); |
Kevin O'Connor | 7af49bf | 2008-03-09 13:46:13 -0400 | [diff] [blame] | 425 | do_boot(0); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 426 | } |
Kevin O'Connor | cdd3d65 | 2008-07-12 14:22:14 -0400 | [diff] [blame] | 427 | |
| 428 | // Ughh - some older gcc compilers have a bug which causes VISIBLE32 |
Kevin O'Connor | f13b008 | 2008-08-17 11:26:42 -0400 | [diff] [blame] | 429 | // functions to not be exported as global variables. |
Kevin O'Connor | cdd3d65 | 2008-07-12 14:22:14 -0400 | [diff] [blame] | 430 | asm(".global handle_18, handle_19"); |