Establish boot order in post stage.
authorKevin O'Connor <kevin@koconnor.net>
Sun, 18 May 2008 04:20:53 +0000 (00:20 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Sun, 18 May 2008 04:20:53 +0000 (00:20 -0400)
Read boot order nvram fields in post stage and store in a variable.
Change boot menu to update boot order instead of using separate variables.

src/biosvar.h
src/boot.c
src/post.c
src/post_menu.c

index d2d7b9fdbde86ffab9894542c9e36f8fcc440c0b..9668f31617283ac5ae0f8298c10e18492dae8132 100644 (file)
@@ -213,7 +213,8 @@ struct ipl_s {
     struct ipl_entry_s table[8];
     u16 count;
     u16 sequence;
-    u16 bootfirst;
+    u32 bootorder;
+    u8 checkfloppysig;
 };
 
 #define IPL_TYPE_FLOPPY      0x01
index 53577ecfe3a60b5a21c18d63b2264892447522ae..12226d6eb3eb056bda3b6b8859c32d0d6d541ec7 100644 (file)
@@ -8,7 +8,6 @@
 #include "util.h" // irq_enable
 #include "biosvar.h" // struct bregs
 #include "config.h" // CONFIG_*
-#include "cmos.h" // inb_cmos
 #include "ata.h" // ata_detect
 #include "disk.h" // cdrom_boot
 
@@ -23,7 +22,7 @@ char pnp_string[] VISIBLE16 __attribute__((aligned (2))) = " $PnP";
 //--------------------------------------------------------------------------
 
 static const char drivetypes[][10]={
-    "", "Floppy","Hard Disk","CD-Rom", "Network"
+    "", "Floppy", "Hard Disk", "CD-Rom", "Network"
 };
 
 void
@@ -86,24 +85,14 @@ try_boot(u16 seq_nr)
 
     SET_EBDA(ipl.sequence, seq_nr);
 
-    u16 bootdev = inb_cmos(CMOS_BIOS_BOOTFLAG2);
-    bootdev |= ((inb_cmos(CMOS_BIOS_BOOTFLAG1) & 0xf0) << 4);
+    u32 bootdev = GET_EBDA(ipl.bootorder);
     bootdev >>= 4 * seq_nr;
     bootdev &= 0xf;
 
-    /* Read user selected device */
-    u16 bootfirst = GET_EBDA(ipl.bootfirst);
-    if (bootfirst != 0xFFFF) {
-        bootdev = bootfirst;
-        /* Reset boot sequence */
-        SET_EBDA(ipl.bootfirst, 0xFFFF);
-        SET_EBDA(ipl.sequence, 0xFFFF);
-    }
-
     if (bootdev == 0)
         BX_PANIC("No bootable device.\n");
 
-    /* Translate from CMOS runes to an IPL table offset by subtracting 1 */
+    /* Translate bootdev to an IPL table offset by subtracting 1 */
     bootdev -= 1;
 
     if (bootdev >= GET_EBDA(ipl.count)) {
@@ -142,9 +131,8 @@ try_boot(u16 seq_nr)
         }
 
         /* Always check the signature on a HDD boot sector; on FDD,
-         * only do the check if the CMOS doesn't tell us to skip it */
-        if ((type != IPL_TYPE_FLOPPY)
-            || !((inb_cmos(CMOS_BIOS_BOOTFLAG1) & 0x01))) {
+         * only do the check if configured for it */
+        if (type != IPL_TYPE_FLOPPY || GET_EBDA(ipl.checkfloppysig)) {
             if (GET_FARVAR(bootseg, *(u16*)0x1fe) != 0xaa55) {
                 print_boot_failure(type, 0);
                 return;
index 573dfc8697e27d19ae0b55da61d8a4779cd82786..1464572884ed1af9e6448ed61f4e67e9bca64d29 100644 (file)
@@ -131,7 +131,10 @@ init_boot_vectors()
 
     ebda->ipl.count = ip - ebda->ipl.table;
     ebda->ipl.sequence = 0xffff;
-    ebda->ipl.bootfirst = 0xffff;
+    ebda->ipl.bootorder = (inb_cmos(CMOS_BIOS_BOOTFLAG2)
+                           | ((inb_cmos(CMOS_BIOS_BOOTFLAG1) & 0xf0) << 4));
+    if (!(inb_cmos(CMOS_BIOS_BOOTFLAG1) & 1))
+        ebda->ipl.checkfloppysig = 1;
 }
 
 static void
index 91b18fef5e05f21315b6a22127c0635e14ae6d73..4526e44da3e5a01bd737d9acd6bdc2896f9a312e 100644 (file)
@@ -73,7 +73,10 @@ interactive_bootmenu()
             /* ESC or F12 */
             break;
         if (scan_code <= count + 1) {
-            SET_EBDA(ipl.bootfirst, scan_code - 1);
+            // Add user choice to the boot order.
+            u16 choice = scan_code - 1;
+            u32 bootorder = GET_EBDA(ipl.bootorder);
+            SET_EBDA(ipl.bootorder, (bootorder << 4) | choice);
             break;
         }
     }