summary refs log tree commit diff stats
path: root/hw
diff options
context:
space:
mode:
Diffstat (limited to 'hw')
-rw-r--r--hw/hw.h6
-rw-r--r--hw/pc.c29
2 files changed, 35 insertions, 0 deletions
diff --git a/hw/hw.h b/hw/hw.h
index 3589adee37..2a461026e1 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -92,6 +92,12 @@ typedef void QEMUResetHandler(void *opaque);
 
 void qemu_register_reset(QEMUResetHandler *func, void *opaque);
 
+/* handler to set the boot_device for a specific type of QEMUMachine */
+/* return 0 if success */
+typedef int QEMUBootSetHandler(const char *boot_device);
+extern QEMUBootSetHandler *qemu_boot_set_handler;
+void qemu_register_boot_set(QEMUBootSetHandler *func);
+
 /* These should really be in isa.h, but are here to make pc.h happy.  */
 typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data);
 typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address);
diff --git a/hw/pc.c b/hw/pc.c
index 5d5a764bb2..265ced4809 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -189,6 +189,33 @@ static int boot_device2nibble(char boot_device)
     return 0;
 }
 
+/* copy/pasted from cmos_init, should be made a general function
+ and used there as well */
+int pc_boot_set(const char *boot_device)
+{
+#define PC_MAX_BOOT_DEVICES 3
+    RTCState *s = rtc_state;
+    int nbds, bds[3] = { 0, };
+    int i;
+
+    nbds = strlen(boot_device);
+    if (nbds > PC_MAX_BOOT_DEVICES) {
+        term_printf("Too many boot devices for PC\n");
+        return(1);
+    }
+    for (i = 0; i < nbds; i++) {
+        bds[i] = boot_device2nibble(boot_device[i]);
+        if (bds[i] == 0) {
+            term_printf("Invalid boot device for PC: '%c'\n",
+                    boot_device[i]);
+            return(1);
+        }
+    }
+    rtc_set_memory(s, 0x3d, (bds[1] << 4) | bds[0]);
+    rtc_set_memory(s, 0x38, (bds[2] << 4));
+    return(0);
+}
+
 /* hd_table must contain 4 block drivers */
 static void cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
                       const char *boot_device, BlockDriverState **hd_table)
@@ -713,6 +740,8 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size,
         below_4g_mem_size = ram_size;
     }
 
+    qemu_register_boot_set(pc_boot_set);
+
     linux_boot = (kernel_filename != NULL);
 
     /* init CPUs */