Add simple cooperative threading scheme to allow parallel hw init.
[seabios.git] / src / boot.c
index b6afd351b524f9779c16d3d5e76b173c6d20757b..d80eae491c9c5ea16d9644d6d11d8d2f6ca1c052 100644 (file)
@@ -5,13 +5,14 @@
 //
 // This file may be distributed under the terms of the GNU LGPLv3 license.
 
-#include "util.h" // irq_enable
+#include "util.h" // dprintf
 #include "biosvar.h" // GET_EBDA
 #include "config.h" // CONFIG_*
 #include "disk.h" // cdrom_boot
 #include "bregs.h" // struct bregs
 #include "boot.h" // struct ipl_s
 #include "cmos.h" // inb_cmos
+#include "paravirt.h"
 
 struct ipl_s IPL;
 
@@ -106,7 +107,7 @@ add_bcv(u16 seg, u16 ip, u16 desc)
 
 // Add a bcv entry for an internal harddrive
 void
-add_bcv_internal(int driveid)
+add_bcv_internal(struct drive_s *drive_g)
 {
     if (! CONFIG_BOOT)
         return;
@@ -114,8 +115,25 @@ add_bcv_internal(int driveid)
         return;
 
     struct ipl_entry_s *ie = &IPL.bcv[IPL.bcvcount++];
+    if (CONFIG_THREADS) {
+        // Add to bcv list with assured drive order.
+        struct ipl_entry_s *end = ie;
+        for (;;) {
+            struct ipl_entry_s *prev = ie - 1;
+            if (prev < IPL.bcv || prev->type != BCV_TYPE_INTERNAL)
+                break;
+            struct drive_s *prevdrive = (void*)prev->vector;
+            if (prevdrive->type < drive_g->type
+                || (prevdrive->type == drive_g->type
+                    && prevdrive->cntl_id < drive_g->cntl_id))
+                break;
+            ie--;
+        }
+        if (ie != end)
+            memmove(ie+1, ie, (void*)end-(void*)ie);
+    }
     ie->type = BCV_TYPE_INTERNAL;
-    ie->vector = driveid;
+    ie->vector = (u32)drive_g;
     ie->description = "";
 }
 
@@ -140,9 +158,9 @@ menu_show_floppy(struct ipl_entry_s *ie, int menupos)
 {
     int i;
     for (i = 0; i < Drives.floppycount; i++) {
-        int driveid = Drives.idmap[EXTTYPE_FLOPPY][i];
+        struct drive_s *drive_g = getDrive(EXTTYPE_FLOPPY, i);
         printf("%d. Floppy [", menupos + i);
-        describe_drive(driveid);
+        describe_drive(drive_g);
         printf("]\n");
     }
     return Drives.floppycount;
@@ -158,7 +176,7 @@ menu_show_harddisk(struct ipl_entry_s *ie, int menupos)
         switch (ie->type) {
         case BCV_TYPE_INTERNAL:
             printf("%d. ", menupos + i);
-            describe_drive(ie->vector);
+            describe_drive((void*)ie->vector);
             printf("\n");
             break;
         default:
@@ -175,9 +193,9 @@ menu_show_cdrom(struct ipl_entry_s *ie, int menupos)
 {
     int i;
     for (i = 0; i < Drives.cdcount; i++) {
-        int driveid = Drives.idmap[EXTTYPE_CD][i];
+        struct drive_s *drive_g = getDrive(EXTTYPE_CD, i);
         printf("%d. CD-Rom [", menupos + i);
-        describe_drive(driveid);
+        describe_drive(drive_g);
         printf("]\n");
     }
     return Drives.cdcount;
@@ -206,7 +224,7 @@ menu_show_cbfs(struct ipl_entry_s *ie, int menupos)
 static void
 interactive_bootmenu()
 {
-    if (! CONFIG_BOOTMENU)
+    if (! CONFIG_BOOTMENU || ! qemu_cfg_show_boot_menu())
         return;
 
     while (get_keystroke(0) >= 0)
@@ -281,7 +299,7 @@ run_bcv(struct ipl_entry_s *ie)
 {
     switch (ie->type) {
     case BCV_TYPE_INTERNAL:
-        map_hd_drive(ie->vector);
+        map_hd_drive((void*)ie->vector);
         break;
     case BCV_TYPE_EXTERNAL:
         call_bcv(ie->vector >> 16, ie->vector & 0xffff);
@@ -296,6 +314,8 @@ boot_prep()
     if (! CONFIG_BOOT)
         return;
 
+    // XXX - show available drives?
+
     // Allow user to modify BCV/IPL order.
     interactive_bootmenu();
 
@@ -328,6 +348,7 @@ call_boot_entry(u16 bootseg, u16 bootip, u8 bootdrv)
 
     struct bregs br;
     memset(&br, 0, sizeof(br));
+    br.flags = F_IF;
     br.code = SEGOFF(bootseg, bootip);
     // Set the magic number in ax and the boot drive in dl.
     br.dl = bootdrv;
@@ -344,6 +365,7 @@ boot_disk(u8 bootdrv, int checksig)
     // Read sector
     struct bregs br;
     memset(&br, 0, sizeof(br));
+    br.flags = F_IF;
     br.dl = bootdrv;
     br.es = bootseg;
     br.ah = 2;
@@ -428,7 +450,7 @@ do_boot(u16 seq_nr)
         printf("No bootable device.\n");
         // Loop with irqs enabled - this allows ctrl+alt+delete to work.
         for (;;)
-            usleep(1000000);
+            biosusleep(1000000);
     }
 
     /* Do the loading, and set up vector as a far pointer to the boot
@@ -459,6 +481,7 @@ do_boot(u16 seq_nr)
     // Boot failed: invoke the boot recovery function
     struct bregs br;
     memset(&br, 0, sizeof(br));
+    br.flags = F_IF;
     call16_int(0x18, &br);
 }