Support for booting from virtio disks
[seabios.git] / src / post.c
index a566b34bfdb847e5b0d000a7595b899eb841818c..25535e21f2949c046e2217104bdc4420f406e167 100644 (file)
@@ -22,6 +22,8 @@
 #include "usb.h" // usb_setup
 #include "smbios.h" // smbios_init
 #include "paravirt.h" // qemu_cfg_port_probe
+#include "ps2port.h" // ps2port_setup
+#include "virtio-blk.h" // virtio_blk_setup
 
 void
 __set_irq(int vector, void *loc)
@@ -35,7 +37,7 @@ __set_irq(int vector, void *loc)
     } while (0)
 
 static void
-init_ivt()
+init_ivt(void)
 {
     dprintf(3, "init ivt\n");
 
@@ -65,6 +67,10 @@ init_ivt()
     set_irq(0x1a, entry_1a);
     set_irq(0x40, entry_40);
 
+    // INT 60h-66h reserved for user interrupt
+    for (i=0x60; i<=0x66; i++)
+        SET_IVT(i, SEGOFF(0, 0));
+
     // set vector 0x79 to zero
     // this is used by 'gardian angel' protection system
     SET_IVT(0x79, SEGOFF(0, 0));
@@ -73,7 +79,7 @@ init_ivt()
 }
 
 static void
-init_bda()
+init_bda(void)
 {
     dprintf(3, "init bda\n");
 
@@ -112,7 +118,7 @@ ram_probe(void)
 
         // Check for memory over 4Gig
         u64 high = ((inb_cmos(CMOS_MEM_HIGHMEM_LOW) << 16)
-                    | (inb_cmos(CMOS_MEM_HIGHMEM_MID) << 24)
+                    | ((u32)inb_cmos(CMOS_MEM_HIGHMEM_MID) << 24)
                     | ((u64)inb_cmos(CMOS_MEM_HIGHMEM_HIGH) << 32));
         RamSizeOver4G = high;
         add_e820(0x100000000ull, high, E820_RAM);
@@ -130,12 +136,24 @@ ram_probe(void)
              , E820_RESERVED);
     add_e820(BUILD_BIOS_ADDR, BUILD_BIOS_SIZE, E820_RESERVED);
 
-    if (kvm_para_available())
+    u32 count = qemu_cfg_e820_entries();
+    if (count) {
+        struct e820_reservation entry;
+        int i;
+
+        for (i = 0; i < count; i++) {
+            qemu_cfg_e820_load_next(&entry);
+            add_e820(entry.address, entry.length, entry.type);
+        }
+    } else if (kvm_para_available()) {
+        // Backwards compatibility - provide hard coded range.
         // 4 pages before the bios, 3 pages for vmx tss pages, the
         // other page for EPT real mode pagetable
         add_e820(0xfffbc000, 4*4096, E820_RESERVED);
+    }
 
-    dprintf(1, "Ram Size=0x%08x\n", RamSize);
+    dprintf(1, "Ram Size=0x%08x (0x%08x%08x high)\n"
+            , RamSize, (u32)(RamSizeOver4G >> 32), (u32)RamSizeOver4G);
 }
 
 static void
@@ -155,62 +173,91 @@ init_bios_tables(void)
     acpi_bios_init();
 }
 
+// Initialize hardware devices
+static void
+init_hw(void)
+{
+    usb_setup();
+    ps2port_setup();
+    lpt_setup();
+    serial_setup();
+
+    floppy_setup();
+    ata_setup();
+    ramdisk_setup();
+    virtio_blk_setup();
+}
+
 // Main setup code.
 static void
-post()
+post(void)
 {
+    // Detect and init ram.
     init_ivt();
     init_bda();
-
+    memmap_setup();
     qemu_cfg_port_probe();
+    ram_probe();
+    malloc_setup();
+    thread_setup();
 
+    // Init base pc hardware.
     pic_setup();
     timer_setup();
     mathcp_setup();
 
+    // Initialize mtrr
     smp_probe_setup();
-    memmap_setup();
-    ram_probe();
     mtrr_setup();
-    smp_probe();
-    malloc_setup();
-    pmm_setup();
 
+    // Initialize pci
     pci_setup();
     smm_init();
 
-    pnp_setup();
-    vga_setup();
+    // Initialize internal tables
+    boot_setup();
+    drive_setup();
+    cdemu_setup();
 
-    usb_setup();
+    // Start hardware initialization (if optionrom threading)
+    if (CONFIG_THREADS && CONFIG_THREAD_OPTIONROMS)
+        init_hw();
+
+    // Find and initialize other cpus
+    smp_probe();
+
+    // Setup interfaces that option roms may need
+    bios32_setup();
+    pmm_setup();
+    pnp_setup();
     kbd_setup();
-    lpt_setup();
-    serial_setup();
     mouse_setup();
-
     init_bios_tables();
 
-    boot_setup();
+    // Run vga option rom
+    vga_setup();
 
-    drive_setup();
-    cdemu_setup();
-    floppy_setup();
-    ata_setup();
-    ramdisk_setup();
+    // Do hardware initialization (if running synchronously)
+    if (!CONFIG_THREADS || !CONFIG_THREAD_OPTIONROMS) {
+        init_hw();
+        wait_threads();
+    }
 
+    // Run option roms
     optionrom_setup();
 
-    // Run BCVs
+    // Run BCVs and show optional boot menu
     boot_prep();
 
+    // Finalize data structures before boot
     pmm_finalize();
     malloc_finalize();
     memmap_finalize();
 }
 
 // 32-bit entry point.
-void VISIBLE32
-_start()
+void VISIBLE32FLAT
+_start(void)
 {
     init_dma();