@@ -64,8 +64,6 @@
#define DPRINTF(fmt, ...)
#endif
-#define BIOS_FILENAME "bios.bin"
-
#define PC_MAX_BIOS_SIZE (4 * 1024 * 1024)
/* Leave a chunk of memory at the top of RAM for the BIOS ACPI tables. */
@@ -996,14 +994,10 @@ static void pc_memory_init(MemoryRegion *system_memory,
const char *initrd_filename,
ram_addr_t below_4g_mem_size,
ram_addr_t above_4g_mem_size,
- MemoryRegion *rom_memory,
MemoryRegion **ram_memory)
{
- char *filename;
- int ret, linux_boot, i;
- MemoryRegion *ram, *bios, *isa_bios, *option_rom_mr;
- MemoryRegion *ram_below_4g, *ram_above_4g;
- int bios_size, isa_bios_size;
+ int linux_boot, i;
+ MemoryRegion *ram, *ram_below_4g, *ram_above_4g;
void *fw_cfg;
linux_boot = (kernel_filename != NULL);
@@ -1029,58 +1023,6 @@ static void pc_memory_init(MemoryRegion *system_memory,
ram_above_4g);
}
- /* BIOS load */
- if (bios_name == NULL)
- bios_name = BIOS_FILENAME;
- filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
- if (filename) {
- bios_size = get_image_size(filename);
- } else {
- bios_size = -1;
- }
- if (bios_size <= 0 ||
- (bios_size % 65536) != 0) {
- goto bios_error;
- }
- bios = g_malloc(sizeof(*bios));
- memory_region_init_ram(bios, "pc.bios", bios_size);
- vmstate_register_ram_global(bios);
- memory_region_set_readonly(bios, true);
- ret = rom_add_file_fixed(bios_name, (uint32_t)(-bios_size), -1);
- if (ret != 0) {
- bios_error:
- fprintf(stderr, "qemu: could not load PC BIOS '%s'\n", bios_name);
- exit(1);
- }
- if (filename) {
- g_free(filename);
- }
- /* map the last 128KB of the BIOS in ISA space */
- isa_bios_size = bios_size;
- if (isa_bios_size > (128 * 1024))
- isa_bios_size = 128 * 1024;
- isa_bios = g_malloc(sizeof(*isa_bios));
- memory_region_init_alias(isa_bios, "isa-bios", bios,
- bios_size - isa_bios_size, isa_bios_size);
- memory_region_add_subregion_overlap(rom_memory,
- 0x100000 - isa_bios_size,
- isa_bios,
- 1);
- memory_region_set_readonly(isa_bios, true);
-
- option_rom_mr = g_malloc(sizeof(*option_rom_mr));
- memory_region_init_ram(option_rom_mr, "pc.rom", PC_ROM_SIZE);
- vmstate_register_ram_global(option_rom_mr);
- memory_region_add_subregion_overlap(rom_memory,
- PC_ROM_MIN_VGA,
- option_rom_mr,
- 1);
-
- /* map all the bios at the top of memory */
- memory_region_add_subregion(rom_memory,
- (uint32_t)(-bios_size),
- bios);
-
fw_cfg = bochs_bios_init();
rom_set_fw(fw_cfg);
@@ -1299,7 +1241,6 @@ static void pc_init1(MemoryRegion *system_memory,
ISADevice *floppy;
MemoryRegion *ram_memory = NULL;
MemoryRegion *pci_memory;
- MemoryRegion *rom_memory;
DeviceState *dev;
pc_cpus_init(cpu_model);
@@ -1319,10 +1260,8 @@ static void pc_init1(MemoryRegion *system_memory,
if (pci_enabled) {
pci_memory = g_new(MemoryRegion, 1);
memory_region_init(pci_memory, "pci", INT64_MAX);
- rom_memory = pci_memory;
} else {
pci_memory = NULL;
- rom_memory = system_memory;
}
/* allocate ram and load rom/bios */
@@ -1330,7 +1269,7 @@ static void pc_init1(MemoryRegion *system_memory,
pc_memory_init(system_memory,
kernel_filename, kernel_cmdline, initrd_filename,
below_4g_mem_size, above_4g_mem_size,
- pci_enabled ? rom_memory : system_memory, &ram_memory);
+ &ram_memory);
}
gsi_state = g_malloc0(sizeof(*gsi_state));
@@ -1351,7 +1290,8 @@ static void pc_init1(MemoryRegion *system_memory,
(sizeof(target_phys_addr_t) == 4
? 0
: ((uint64_t)1 << 62)),
- pci_memory, ram_memory);
+ pci_memory, ram_memory,
+ bios_name);
} else {
pci_bus = NULL;
i440fx_state = NULL;
@@ -166,7 +166,8 @@ PCIBus *i440fx_init(I440FXPMCState **pi440fx_state, int *piix_devfn,
target_phys_addr_t pci_hole64_start,
target_phys_addr_t pci_hole64_size,
MemoryRegion *pci_memory,
- MemoryRegion *ram_memory);
+ MemoryRegion *ram_memory,
+ const char *bios_name);
/* piix4.c */
extern PCIDevice *piix4_dev;
@@ -33,6 +33,10 @@
#include "hpet_emul.h"
#include "mc146818rtc.h"
#include "i8254.h"
+#include "loader.h"
+#include "sysemu.h"
+
+#define BIOS_FILENAME "bios.bin"
/*
* I440FX chipset data sheet.
@@ -122,6 +126,13 @@ typedef struct I440FXState
I440FXPMCState pmc;
PIIX3State piix3;
+
+ /* Is this more appropriate for the PMC? */
+ MemoryRegion bios;
+ MemoryRegion isa_bios;
+ MemoryRegion option_roms;
+
+ char *bios_name;
} I440FXState;
#define I440FX_PAM 0x59
@@ -266,6 +277,9 @@ static int i440fx_realize(SysBusDevice *dev)
{
I440FXState *s = I440FX(dev);
PCIHostState *h = PCI_HOST(s);
+ int bios_size, isa_bios_size;
+ char *filename;
+ int ret;
g_assert(h->address_space != NULL);
g_assert(s->address_space_io != NULL);
@@ -300,6 +314,55 @@ static int i440fx_realize(SysBusDevice *dev)
PIIX_NUM_PIRQS);
}
+ /* BIOS load */
+ filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, s->bios_name);
+ if (filename) {
+ bios_size = get_image_size(filename);
+ } else {
+ bios_size = -1;
+ }
+ if (bios_size <= 0 ||
+ (bios_size % 65536) != 0) {
+ goto bios_error;
+ }
+ memory_region_init_ram(&s->bios, "pc.bios", bios_size);
+ vmstate_register_ram_global(&s->bios);
+ memory_region_set_readonly(&s->bios, true);
+ ret = rom_add_file_fixed(s->bios_name, (uint32_t)(-bios_size), -1);
+ if (ret != 0) {
+ bios_error:
+ fprintf(stderr, "qemu: could not load PC BIOS '%s'\n", s->bios_name);
+ exit(1);
+ }
+ if (filename) {
+ g_free(filename);
+ }
+
+ /* map the last 128KB of the BIOS in ISA space */
+ isa_bios_size = bios_size;
+ if (isa_bios_size > (128 * 1024)) {
+ isa_bios_size = 128 * 1024;
+ }
+ memory_region_init_alias(&s->isa_bios, "isa-bios", &s->bios,
+ bios_size - isa_bios_size, isa_bios_size);
+ memory_region_add_subregion_overlap(&s->pci_address_space,
+ 0x100000 - isa_bios_size,
+ &s->isa_bios,
+ 1);
+ memory_region_set_readonly(&s->isa_bios, true);
+
+ memory_region_init_ram(&s->option_roms, "pc.rom", PC_ROM_SIZE);
+ vmstate_register_ram_global(&s->option_roms);
+ memory_region_add_subregion_overlap(&s->pci_address_space,
+ PC_ROM_MIN_VGA,
+ &s->option_roms,
+ 1);
+
+ /* map all the bios at the top of memory */
+ memory_region_add_subregion(&s->pci_address_space,
+ (uint32_t)(-bios_size),
+ &s->bios);
+
return 0;
}
@@ -322,6 +385,8 @@ static void i440fx_initfn(Object *obj)
}
object_property_add_child(OBJECT(s), "piix3", OBJECT(&s->piix3), NULL);
+ s->bios_name = g_strdup(BIOS_FILENAME);
+
memory_region_init(&s->pci_address_space, "pci", INT64_MAX);
}
@@ -390,8 +455,8 @@ PCIBus *i440fx_init(I440FXPMCState **pi440fx_state, int *piix3_devfn,
target_phys_addr_t pci_hole_size,
target_phys_addr_t pci_hole64_start,
target_phys_addr_t pci_hole64_size,
- MemoryRegion *pci_address_space, MemoryRegion *ram_memory)
-
+ MemoryRegion *pci_address_space, MemoryRegion *ram_memory,
+ const char *bios_name)
{
I440FXState *s;
PCIHostState *h;
@@ -403,6 +468,11 @@ PCIBus *i440fx_init(I440FXPMCState **pi440fx_state, int *piix3_devfn,
h->address_space = address_space_mem;
s->address_space_io = address_space_io;
s->piix3.pic = pic;
+ if (bios_name) {
+ g_free(s->bios_name);
+ s->bios_name = g_strdup(bios_name);
+ }
+
/* FIXME pmc should create ram_memory */
s->pmc.ram_memory = ram_memory;
s->pmc.ram_size = ram_size;
@@ -172,8 +172,6 @@ void usb_info(Monitor *mon);
void rtc_change_mon_event(struct tm *tm);
-void register_devices(void);
-
void add_boot_device_path(int32_t bootindex, DeviceState *dev,
const char *suffix);
char *get_boot_devices_list(uint32_t *size);