2012-02-22 07:18:51 +00:00
|
|
|
/*
|
|
|
|
* QEMU PC System Firmware
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2004 Fabrice Bellard
|
|
|
|
* Copyright (c) 2011-2012 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2012-02-22 07:18:52 +00:00
|
|
|
#include "sysbus.h"
|
|
|
|
#include "hw.h"
|
2012-02-22 07:18:51 +00:00
|
|
|
#include "pc.h"
|
|
|
|
#include "loader.h"
|
|
|
|
#include "sysemu.h"
|
|
|
|
|
|
|
|
#define BIOS_FILENAME "bios.bin"
|
|
|
|
|
2012-02-22 07:18:52 +00:00
|
|
|
typedef struct PcSysFwDevice {
|
|
|
|
SysBusDevice busdev;
|
|
|
|
uint8_t rom_only;
|
|
|
|
} PcSysFwDevice;
|
|
|
|
|
2012-02-22 07:18:51 +00:00
|
|
|
static void pc_system_rom_init(MemoryRegion *rom_memory)
|
|
|
|
{
|
|
|
|
char *filename;
|
|
|
|
MemoryRegion *bios, *isa_bios;
|
|
|
|
int bios_size, isa_bios_size;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
|
|
|
/* map all the bios at the top of memory */
|
|
|
|
memory_region_add_subregion(rom_memory,
|
|
|
|
(uint32_t)(-bios_size),
|
|
|
|
bios);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pc_system_firmware_init(MemoryRegion *rom_memory)
|
|
|
|
{
|
2012-02-22 07:18:52 +00:00
|
|
|
PcSysFwDevice *sysfw_dev;
|
|
|
|
|
|
|
|
sysfw_dev = (PcSysFwDevice*) qdev_create(NULL, "pc-sysfw");
|
|
|
|
|
2012-02-22 07:18:51 +00:00
|
|
|
pc_system_rom_init(rom_memory);
|
|
|
|
}
|
|
|
|
|
2012-02-22 07:18:52 +00:00
|
|
|
static Property pcsysfw_properties[] = {
|
|
|
|
DEFINE_PROP_UINT8("rom_only", PcSysFwDevice, rom_only, 1),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void pcsysfw_class_init (ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS (klass);
|
|
|
|
|
|
|
|
dc->desc = "PC System Firmware";
|
|
|
|
dc->props = pcsysfw_properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
static TypeInfo pcsysfw_info = {
|
|
|
|
.name = "pc-sysfw",
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof (PcSysFwDevice),
|
|
|
|
.class_init = pcsysfw_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void pcsysfw_register (void)
|
|
|
|
{
|
|
|
|
type_register_static (&pcsysfw_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init (pcsysfw_register);
|
2012-02-22 07:18:51 +00:00
|
|
|
|