-localtime option
[qemu] / hw / pc.c
diff --git a/hw/pc.c b/hw/pc.c
index e62d56d..eef120e 100644 (file)
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -39,11 +39,31 @@ int speaker_data_on;
 int dummy_refresh_clock;
 static fdctrl_t *floppy_controller;
 static RTCState *rtc_state;
+static PITState *pit;
 
 static void ioport80_write(void *opaque, uint32_t addr, uint32_t data)
 {
 }
 
+/* MSDOS compatibility mode FPU exception support */
+/* XXX: add IGNNE support */
+void cpu_set_ferr(CPUX86State *s)
+{
+    pic_set_irq(13, 1);
+}
+
+static void ioportF0_write(void *opaque, uint32_t addr, uint32_t data)
+{
+    pic_set_irq(13, 0);
+}
+
+/* TSC handling */
+
+uint64_t cpu_get_tsc(CPUX86State *env)
+{
+    return qemu_get_clock(vm_clock);
+}
+
 /* PC cmos mappings */
 
 #define REG_EQUIPMENT_BYTE          0x14
@@ -56,6 +76,30 @@ static inline int to_bcd(RTCState *s, int a)
     return ((a / 10) << 4) | (a % 10);
 }
 
+static int cmos_get_fd_drive_type(int fd0)
+{
+    int val;
+
+    switch (fd0) {
+    case 0:
+        /* 1.44 Mb 3"5 drive */
+        val = 4;
+        break;
+    case 1:
+        /* 2.88 Mb 3"5 drive */
+        val = 5;
+        break;
+    case 2:
+        /* 1.2 Mb 5"5 drive */
+        val = 2;
+        break;
+    default:
+        val = 0;
+        break;
+    }
+    return val;
+}
+
 static void cmos_init(int ram_size, int boot_device)
 {
     RTCState *s = rtc_state;
@@ -66,7 +110,10 @@ static void cmos_init(int ram_size, int boot_device)
 
     /* set the CMOS date */
     time(&ti);
-    tm = gmtime(&ti);
+    if (rtc_utc)
+        tm = gmtime(&ti);
+    else
+        tm = localtime(&ti);
     rtc_set_date(s, tm);
 
     val = to_bcd(s, (tm->tm_year / 100) + 19);
@@ -76,6 +123,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;
@@ -109,35 +160,7 @@ static void cmos_init(int ram_size, int boot_device)
     fd0 = fdctrl_get_drive_type(floppy_controller, 0);
     fd1 = fdctrl_get_drive_type(floppy_controller, 1);
 
-    val = 0;
-    switch (fd0) {
-    case 0:
-        /* 1.44 Mb 3"5 drive */
-        val |= 0x40;
-        break;
-    case 1:
-        /* 2.88 Mb 3"5 drive */
-        val |= 0x60;
-        break;
-    case 2:
-        /* 1.2 Mb 5"5 drive */
-        val |= 0x20;
-        break;
-    }
-    switch (fd1) {
-    case 0:
-        /* 1.44 Mb 3"5 drive */
-        val |= 0x04;
-        break;
-    case 1:
-        /* 2.88 Mb 3"5 drive */
-        val |= 0x06;
-        break;
-    case 2:
-        /* 1.2 Mb 5"5 drive */
-        val |= 0x02;
-        break;
-    }
+    val = (cmos_get_fd_drive_type(fd0) << 4) | cmos_get_fd_drive_type(fd1);
     rtc_set_memory(s, 0x10, val);
     
     val = 0;
@@ -165,15 +188,15 @@ static void cmos_init(int ram_size, int boot_device)
 static void speaker_ioport_write(void *opaque, uint32_t addr, uint32_t val)
 {
     speaker_data_on = (val >> 1) & 1;
-    pit_set_gate(&pit_channels[2], val & 1);
+    pit_set_gate(pit, 2, val & 1);
 }
 
 static uint32_t speaker_ioport_read(void *opaque, uint32_t addr)
 {
     int out;
-    out = pit_get_out(&pit_channels[2], qemu_get_clock(vm_clock));
+    out = pit_get_out(pit, 2, qemu_get_clock(vm_clock));
     dummy_refresh_clock ^= 1;
-    return (speaker_data_on << 1) | pit_channels[2].gate | (out << 5) |
+    return (speaker_data_on << 1) | pit_get_gate(pit, 2) | (out << 5) |
       (dummy_refresh_clock << 4);
 }
 
@@ -302,12 +325,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 +346,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 */
@@ -356,11 +386,18 @@ void pc_init(int ram_size, int vga_ram_size, int boot_device,
         stw_raw(phys_ram_base + KERNEL_PARAMS_ADDR + 0x210, 0x01);
     }
 
+    if (pci_enabled) {
+        i440fx_init();
+        piix3_init();
+    }
+
     /* init basic PC hardware */
     register_ioport_write(0x80, 1, 1, ioport80_write, NULL);
 
+    register_ioport_write(0xf0, 1, 1, ioportF0_write, NULL);
+
     vga_initialize(ds, phys_ram_base + ram_size, ram_size, 
-                   vga_ram_size);
+                   vga_ram_size, pci_enabled);
 
     rtc_state = rtc_init(0x70, 8);
     register_ioport_read(0x61, 1, 1, speaker_ioport_read, NULL);
@@ -370,32 +407,48 @@ void pc_init(int ram_size, int vga_ram_size, int boot_device,
     register_ioport_write(0x92, 1, 1, ioport92_write, NULL);
 
     pic_init();
-    pit_init(0x40, 0);
+    pit = pit_init(0x40, 0);
 
     fd = serial_open_device();
     serial_init(0x3f8, 4, fd);
 
-    nb_nics1 = nb_nics;
-    if (nb_nics1 > NE2000_NB_MAX)
-        nb_nics1 = NE2000_NB_MAX;
-    for(i = 0; i < nb_nics1; i++) {
-        ne2000_init(ne2000_io[i], ne2000_irq[i], &nd_table[i]);
-    }
+    if (pci_enabled) {
+        for(i = 0; i < nb_nics; i++) {
+            pci_ne2000_init(&nd_table[i]);
+        }
+        pci_piix3_ide_init(bs_table);
+    } else {
+        nb_nics1 = nb_nics;
+        if (nb_nics1 > NE2000_NB_MAX)
+            nb_nics1 = NE2000_NB_MAX;
+        for(i = 0; i < nb_nics1; i++) {
+            isa_ne2000_init(ne2000_io[i], ne2000_irq[i], &nd_table[i]);
+        }
 
-    for(i = 0; i < 2; i++) {
-        ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i],
-                 bs_table[2 * i], bs_table[2 * i + 1]);
+        for(i = 0; i < 2; i++) {
+            isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i],
+                         bs_table[2 * i], bs_table[2 * i + 1]);
+        }
     }
+
     kbd_init();
     DMA_init();
 
 #ifndef _WIN32
-    /* no audio supported yet for win32 */
-    AUD_init();
-    SB16_init();
+    if (audio_enabled) {
+        /* no audio supported yet for win32 */
+        AUD_init();
+        SB16_init();
+    }
 #endif
 
     floppy_controller = fdctrl_init(6, 2, 0, 0x3f0, fd_table);
 
     cmos_init(ram_size, boot_device);
+
+    /* must be done after all PCI devices are instanciated */
+    /* XXX: should be done in the Bochs BIOS */
+    if (pci_enabled) {
+        pci_bios_init();
+    }
 }