preserve partition table when using -linux option
[qemu] / hw / pc.c
diff --git a/hw/pc.c b/hw/pc.c
index e62d56d..d0fcb0f 100644 (file)
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -76,6 +76,10 @@ static void cmos_init(int ram_size, int boot_device)
     /* various important CMOS locations needed by PC/Bochs bios */
 
     /* memory size */
+    val = 640; /* base memory in K */
+    rtc_set_memory(s, 0x15, val);
+    rtc_set_memory(s, 0x16, val >> 8);
+
     val = (ram_size / 1024) - 1024;
     if (val > 65535)
         val = 65535;
@@ -302,12 +306,14 @@ void pc_init(int ram_size, int vga_ram_size, int boot_device,
     
     /* setup basic memory access */
     cpu_register_physical_memory(0xc0000, 0x10000, 0xc0000 | IO_MEM_ROM);
+    cpu_register_physical_memory(0xd0000, 0x20000, IO_MEM_UNASSIGNED);
     cpu_register_physical_memory(0xf0000, 0x10000, 0xf0000 | IO_MEM_ROM);
     
     bochs_bios_init();
 
     if (linux_boot) {
         uint8_t bootsect[512];
+        uint8_t old_bootsect[512];
 
         if (bs_table[0] == NULL) {
             fprintf(stderr, "A disk image must be given for 'hda' when booting a Linux kernel\n");
@@ -321,6 +327,11 @@ void pc_init(int ram_size, int vga_ram_size, int boot_device,
             exit(1);
         }
 
+        if (bdrv_read(bs_table[0], 0, old_bootsect, 1) >= 0) {
+            /* copy the MSDOS partition table */
+            memcpy(bootsect + 0x1be, old_bootsect + 0x1be, 0x40);
+        }
+
         bdrv_set_boot_sector(bs_table[0], bootsect, sizeof(bootsect));
 
         /* now we can load the kernel */