ne2000 savevm support (Johannes Schindelin)
[qemu] / hw / pc.c
diff --git a/hw/pc.c b/hw/pc.c
index 233f028..305ea1f 100644 (file)
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -136,7 +136,10 @@ static void cmos_init(int ram_size, int boot_device)
     rtc_set_memory(s, 0x30, val);
     rtc_set_memory(s, 0x31, val >> 8);
 
-    val = (ram_size / 65536) - ((16 * 1024 * 1024) / 65536);
+    if (ram_size > (16 * 1024 * 1024))
+        val = (ram_size / 65536) - ((16 * 1024 * 1024) / 65536);
+    else
+        val = 0;
     if (val > 65535)
         val = 65535;
     rtc_set_memory(s, 0x34, val);
@@ -280,7 +283,7 @@ int load_kernel(const char *filename, uint8_t *addr,
     int fd, size;
     int setup_sects;
 
-    fd = open(filename, O_RDONLY);
+    fd = open(filename, O_RDONLY | O_BINARY);
     if (fd < 0)
         return -1;
 
@@ -311,9 +314,12 @@ static const int ide_irq[2] = { 14, 15 };
 
 #define NE2000_NB_MAX 6
 
-static uint32_t ne2000_io[NE2000_NB_MAX] = { 0x300, 0x320, 0x340, 0x360, 0x280, 0x380 };
+static int ne2000_io[NE2000_NB_MAX] = { 0x300, 0x320, 0x340, 0x360, 0x280, 0x380 };
 static int ne2000_irq[NE2000_NB_MAX] = { 9, 10, 11, 3, 4, 5 };
 
+static int serial_io[MAX_SERIAL_PORTS] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
+static int serial_irq[MAX_SERIAL_PORTS] = { 4, 3, 4, 3 };
+
 /* PC hardware initialisation */
 void pc_init(int ram_size, int vga_ram_size, int boot_device,
              DisplayState *ds, const char **fd_filename, int snapshot,
@@ -321,10 +327,11 @@ void pc_init(int ram_size, int vga_ram_size, int boot_device,
              const char *initrd_filename)
 {
     char buf[1024];
-    int ret, linux_boot, initrd_size, i, nb_nics1, fd;
+    int ret, linux_boot, initrd_size, i, nb_nics1;
     unsigned long bios_offset, vga_bios_offset;
     int bios_size, isa_bios_size;
-
+    PCIBus *pci_bus;
+    
     linux_boot = (kernel_filename != NULL);
 
     /* allocate RAM */
@@ -432,8 +439,10 @@ void pc_init(int ram_size, int vga_ram_size, int boot_device,
     }
 
     if (pci_enabled) {
-        i440fx_init();
-        piix3_init();
+        pci_bus = i440fx_init();
+        piix3_init(pci_bus);
+    } else {
+        pci_bus = NULL;
     }
 
     /* init basic PC hardware */
@@ -443,15 +452,16 @@ void pc_init(int ram_size, int vga_ram_size, int boot_device,
 
     if (cirrus_vga_enabled) {
         if (pci_enabled) {
-            pci_cirrus_vga_init(ds, phys_ram_base + ram_size, ram_size, 
+            pci_cirrus_vga_init(pci_bus, 
+                                ds, phys_ram_base + ram_size, ram_size, 
                                 vga_ram_size);
         } else {
             isa_cirrus_vga_init(ds, phys_ram_base + ram_size, ram_size, 
                                 vga_ram_size);
         }
     } else {
-        vga_initialize(ds, phys_ram_base + ram_size, ram_size, 
-                       vga_ram_size, pci_enabled);
+        vga_initialize(pci_bus, ds, phys_ram_base + ram_size, ram_size, 
+                       vga_ram_size);
     }
 
     rtc_state = rtc_init(0x70, 8);
@@ -464,14 +474,17 @@ void pc_init(int ram_size, int vga_ram_size, int boot_device,
     pic_init();
     pit = pit_init(0x40, 0);
 
-    fd = serial_open_device();
-    serial_init(0x3f8, 4, fd);
+    for(i = 0; i < MAX_SERIAL_PORTS; i++) {
+        if (serial_hds[i]) {
+            serial_init(serial_io[i], serial_irq[i], serial_hds[i]);
+        }
+    }
 
     if (pci_enabled) {
         for(i = 0; i < nb_nics; i++) {
-            pci_ne2000_init(&nd_table[i]);
+            pci_ne2000_init(pci_bus, &nd_table[i]);
         }
-        pci_piix3_ide_init(bs_table);
+        pci_piix3_ide_init(pci_bus, bs_table);
     } else {
         nb_nics1 = nb_nics;
         if (nb_nics1 > NE2000_NB_MAX)