Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/ata.c | 1 - src/clock.c | 5 ++--- src/cmos.h | 12 ++++-------- src/floppy.c | 21 ++++++--------------- src/paravirt.c | 31 +++++++++++++++++++++++++++++++ 5 files changed, 43 insertions(+), 27 deletions(-)
diff --git a/src/ata.c b/src/ata.c index 59ae765..9909fb8 100644 --- a/src/ata.c +++ b/src/ata.c @@ -9,7 +9,6 @@ #include "ioport.h" // inb #include "util.h" // dprintf #include "byteorder.h" // be16_to_cpu -#include "cmos.h" // inb_cmos #include "pic.h" // enable_hwirq #include "biosvar.h" // GET_GLOBAL #include "pci.h" // foreachpci diff --git a/src/clock.c b/src/clock.c index bbcafd7..c84882d 100644 --- a/src/clock.c +++ b/src/clock.c @@ -300,9 +300,8 @@ timer_setup(void) SET_BDA(timer_counter, ticks);
// Setup Century storage - if (CONFIG_QEMU) { - Century = inb_cmos(CMOS_CENTURY); - } else { + Century = romfile_loadint("etc/century", 0); + if (!Century) { // Infer current century from the year. u8 year = inb_cmos(CMOS_RTC_YEAR); if (year > 0x80) diff --git a/src/cmos.h b/src/cmos.h index e4b6462..df1d465 100644 --- a/src/cmos.h +++ b/src/cmos.h @@ -6,6 +6,7 @@ #ifndef __CMOS_H #define __CMOS_H
+// Standard BIOS RTC chip entries #define CMOS_RTC_SECONDS 0x00 #define CMOS_RTC_SECONDS_ALARM 0x01 #define CMOS_RTC_MINUTES 0x02 @@ -21,6 +22,9 @@ #define CMOS_STATUS_C 0x0c #define CMOS_STATUS_D 0x0d #define CMOS_RESET_CODE 0x0f + +// QEMU cmos config fields. DO NOT ADD MORE. (All new content should +// be passed via the fw_cfg "file" interface.) #define CMOS_FLOPPY_DRIVE_TYPE 0x10 #define CMOS_DISK_DATA 0x12 #define CMOS_EQUIPMENT_INFO 0x14 @@ -41,14 +45,6 @@ #define CMOS_MEM_HIGHMEM_HIGH 0x5d #define CMOS_BIOS_SMP_COUNT 0x5f
-// CMOS_FLOPPY_DRIVE_TYPE bitdefs -#define CFD_NO_DRIVE 0 -#define CFD_360KB 1 -#define CFD_12MB 2 -#define CFD_720KB 3 -#define CFD_144MB 4 -#define CFD_288MB 5 - #ifndef __ASSEMBLY__
#include "ioport.h" // inb, outb diff --git a/src/floppy.c b/src/floppy.c index 2887e78..00b57c1 100644 --- a/src/floppy.c +++ b/src/floppy.c @@ -10,7 +10,6 @@ #include "config.h" // CONFIG_FLOPPY #include "biosvar.h" // SET_BDA #include "util.h" // dprintf -#include "cmos.h" // inb_cmos #include "pic.h" // eoi_pic1 #include "bregs.h" // struct bregs #include "boot.h" // boot_add_floppy @@ -125,20 +124,12 @@ floppy_setup(void) return; dprintf(3, "init floppy drives\n");
- if (CONFIG_QEMU) { - u8 type = inb_cmos(CMOS_FLOPPY_DRIVE_TYPE); - if (type & 0xf0) - addFloppy(0, type >> 4); - if (type & 0x0f) - addFloppy(1, type & 0x0f); - } else { - u8 type = romfile_loadint("etc/floppy0", 0); - if (type) - addFloppy(0, type); - type = romfile_loadint("etc/floppy1", 0); - if (type) - addFloppy(1, type); - } + u8 type = romfile_loadint("etc/floppy0", 0); + if (type) + addFloppy(0, type); + type = romfile_loadint("etc/floppy1", 0); + if (type) + addFloppy(1, type);
outb(0x02, PORT_DMA1_MASK_REG);
diff --git a/src/paravirt.c b/src/paravirt.c index aa4a421..0cf5149 100644 --- a/src/paravirt.c +++ b/src/paravirt.c @@ -132,6 +132,31 @@ qemu_cfg_read_entry(void *buf, int e, int len) }
static int +qemu_value_read_file(struct romfile_s *file, void *dst, u32 maxlen) +{ + if (file->size > maxlen) + return -1; + memcpy(dst, &file->rawsize, file->size); + return file->size; +} + +static void +qemu_value_add(char *name, int value) +{ + struct romfile_s *file = malloc_tmp(sizeof(*file)); + if (!file) { + warn_noalloc(); + return; + } + memset(file, 0, sizeof(*file)); + strtcpy(file->name, name, sizeof(file->name)); + file->rawsize = value; // Use rawsize to store the value. + file->size = 4; + file->copy = qemu_value_read_file; + romfile_add(file); +} + +static int qemu_cfg_read_file(struct romfile_s *file, void *dst, u32 maxlen) { if (file->size > maxlen) @@ -180,6 +205,12 @@ struct qemu_smbios_header { static void qemu_cfg_legacy(void) { + // Misc cmos items. + qemu_value_add("etc/century", inb_cmos(CMOS_CENTURY)); + u8 floppy = inb_cmos(CMOS_FLOPPY_DRIVE_TYPE); + qemu_value_add("etc/floppy0", floppy >> 4); + qemu_value_add("etc/floppy1", floppy & 0x0f); + // Misc config items. qemu_romfile_add("etc/show-boot-menu", QEMU_CFG_BOOT_MENU, 0, 2); qemu_romfile_add("etc/irq0-override", QEMU_CFG_IRQ0_OVERRIDE, 0, 1);