more rom loader patches.
v2 cover more rom loader patches.
Hi,
A collection of rom loader bits, check individual patches for details.
New in v2: split loader-target.c into two files so we can compile it once as suggested by blueswirl.
cheers,
Gerd
PATCH v2 1/4 rom loader: use qemu_strdup.
--- hw/loader.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
hw/loader.c +1 -1
@@ -559,7 +559,7 @@ int rom_add_file(const char *file, rom->name =qemu_strdup (file); rom->path =qemu_find_file (QEMU_FILE_TYPE_BIOS , rom->name);if (rom->path ==NULL ) { - rom->path =strdup (file); + rom->path =qemu_strdup (file); } fd =open (rom->path,O_RDONLY |O_BINARY );
Signature · 1 line
1.6.2.5
PATCH v2 2/4 rom loader: make vga+rom loading target specific
In reply to Gerd HoffmannThis patch adds a loader-target.c file for target-specific rom loading functions. The rom_add_vga() and rom_add_option() macros are transformed into functions and sticked in there. They load the bios on TARGET_I386 and no nothing on other targets.
With this in place we can move the rom loading calls from pc.c to the individual drivers.
--- Makefile.hw | 7 +++++++ hw/loader-dummy.c | 18 ++++++++++++++++++ hw/loader-i386.c | 16 ++++++++++++++++ hw/loader.h | 6 ++---- 4 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 hw/loader-dummy.c create mode 100644 hw/loader-i386.c
Makefile.hw +7 -0
@@ -12,7 +12,14 @@ VPATH=$(SRC_PATH):$(SRC_PATH)/hw QEMU_CFLAGS+=-I.. -I$(SRC_PATH)/fpu obj-y = + obj-y += loader.o +ifdef TARGET_I386 +obj-y += loader-i386.o +else +obj-y += loader-dummy.o +endif + obj-y += virtio.o obj-y += fw_cfg.o obj-y += watchdog.o
hw/loader-dummy.c new file +18 -0
@@ -0,0 +1,18 @@ +/* +* target specific rom code -- dummy +*/ + +#include "hw.h" +#include "loader.h" + +int rom_add_vga (const char *file) +{ +/* nothing */ +return 0 ; +} + +int rom_add_option (const char *file) +{ +/* nothing */ +return 0 ; +}
hw/loader-i386.c new file +16 -0
@@ -0,0 +1,16 @@ +/* +* target specific rom code -- i386 +*/ + +#include "hw.h" +#include "loader.h" + +int rom_add_vga (const char *file) +{ +return rom_add_file (file,PC_ROM_MIN_VGA ,PC_ROM_MAX ,PC_ROM_ALIGN ); +} + +int rom_add_option (const char *file) +{ +return rom_add_file (file,PC_ROM_MIN_OPTION ,PC_ROM_MAX ,PC_ROM_ALIGN ); +}
hw/loader.h +2 -4
@@ -38,9 +38,7 @@ void do_info_roms(Monitor *mon);#define PC_ROM_ALIGN 0x800#define PC_ROM_SIZE (PC_ROM_MAX - PC_ROM_MIN_VGA) -#define rom_add_vga (_f) \ - rom_add_file(_f, PC_ROM_MIN_VGA, PC_ROM_MAX, PC_ROM_ALIGN) -#define rom_add_option (_f) \ - rom_add_file(_f, PC_ROM_MIN_OPTION, PC_ROM_MAX, PC_ROM_ALIGN) +int rom_add_vga (const char *file); +int rom_add_option (const char *file);#endif
Signature · 1 line
1.6.2.5
[Qemu-devel] Re: [PATCH 2/4] rom loader: make vga+rom loading target specific
Quoted 24 lines · Gerd Hoffmann
This patch adds a
loader-target.cfile for target-specific rom loading functions. Therom_add_vga()androm_add_option()macros are transformed into functions and sticked in there. They load the bios onTARGET_I386and no nothing on other targets.With this in place we can move the rom loading calls from
pc.cto the individual drivers.Signed-off-by Gerd Hoffmann <[email protected]>--- Makefile.hw | 7 +++++++ hw/loader-dummy.c | 18 ++++++++++++++++++ hw/loader-i386.c | 16 ++++++++++++++++ hw/loader.h | 6 ++---- 4 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 hw/loader-dummy.c create mode 100644 hw/loader-i386.cMakefile.hw +0
-0@@ -12,7 +12,14 @@ VPATH=$(SRC_PATH):$(SRC_PATH)/hw QEMU_CFLAGS+=-I.. -I$(SRC_PATH)/fpu
Makefile.hw VPATH=$(SRC_PATH):$(SRC_PATH)/hw · line 22
Quoted 10 lines
Makefile.hw +7
-0obj-y = + obj-y += loader.o +ifdef TARGET_I386 +obj-y += loader-i386.o +else +obj-y += loader-dummy.o +endif +
This is wrong (tm).
a- TARGET_I386 on Makefiles is only defined for 32bits, not for 64bits
(don't blame me, I just did a direct conversion of what was there).
b- TARGET_* is only defined in {i386,x86_64,...}-{softmmu,linux-user,...}
i.e. not a chance to be read at hw/Makefile.
</me does patch>
More complex that I thought:
- if you only want to compile it once, you need to compile it on Makefile, not Makefile.hw: no cookie, loader.h uses target_phys_addr.
- ok, move it to Makefile.hw -> your option didn't work (it compiles) because you allways compile loader-dummy.o, TARGET_I386 is not defined in Makefile.hw (it is hardware independent drivers after all :)
- More imagination: Use only loader-i386.c, and #ifdef TARGET_I386 to an empty macro/real thing -> no cookie either, TARGET_I386 is poisoned in Makefile.hw (*)
- define CONFIG_LOADER_I386 for I386 and X86_64.
And here is the patch. I tested that it compiles for several combinations of x86_64 and not x86_64, and that it works as expected.
<alternative>
This makes the file be compiled only once.
If you can live with file being compiled twice, it is easier to:
add to Makefile.target
obj-i386-y += loader-i386.o
s/CONFIG_LOADER_I386/TARGET_I386/ in loader.h (on my patch)
And then you don't have to define CONFIG_LOADER_I386.
You don't need to include "config-all-devices.h" if you decided this option. (*)
It makes things easier to understand, I think.
<alternative/>
I preffer very much to add the "dummy" cases in one ifdef in a header file.
Later, Juan.
(*): This is cool. Haven't noticed that feature yet.
(**): Yes, config-all-devices.h needs a better way to be included. I
didn't noticed it because by definition nothing old depended on symbols defined there. All symbols that are there were introduced to compile some devices that were compiled unconditionally before. More thought here is needed.
Quoted 1 line
From
4ea2193db8da38064787a4079b6d67536220e9f8Mon Sep 17 00:00:00 2001
From: Juan Quintela <[email protected]>
Date: Sat, 17 Oct 2009 10:43:58 +0200
Subject: [PATCH] Fix loader-i386.c compilation
--- Makefile.hw | 1 + default-configs/i386-softmmu.mak | 2 ++ default-configs/x86_64-softmmu.mak | 2 ++ hw/loader-i386.c | 17 +++++++++++++++++ hw/loader.h | 11 +++++++---- 5 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 hw/loader-i386.c
Makefile.hw +1 -0
@@ -36,6 +36,7 @@ obj-$(CONFIG_ESP) += esp.o obj-y += dma-helpers.o sysbus.o isa-bus.o obj-$(CONFIG_QDEV_ADDR) += qdev-addr.o +obj-$(CONFIG_LOADER_I386) += loader-i386.o all: $(HWLIB) # Dummy command so that make thinks it has done something
default-configs/i386-softmmu.mak +2 -0
@@ -1 +1,3 @@ # Default configuration for i386-softmmu + +CONFIG_LOADER_I386=y
default-configs/x86_64-softmmu.mak +2 -0
@@ -1 +1,3 @@ # Default configuration for x86_64-softmmu + +CONFIG_LOADER_I386=y
hw/loader-i386.c new file +17 -0
@@ -0,0 +1,17 @@ +/* +* target specific rom code -- i386 +*/ + +#include "hw.h" +#include "config-all-devices.h" +#include "loader.h" + +int rom_add_vga (const char *file) +{ +return rom_add_file (file,PC_ROM_MIN_VGA ,PC_ROM_MAX ,PC_ROM_ALIGN ); +} + +int rom_add_option (const char *file) +{ +return rom_add_file (file,PC_ROM_MIN_OPTION ,PC_ROM_MAX ,PC_ROM_ALIGN ); +}
hw/loader.h +7 -4
@@ -38,9 +38,12 @@ void do_info_roms(Monitor *mon);#define PC_ROM_ALIGN 0x800#define PC_ROM_SIZE (PC_ROM_MAX - PC_ROM_MIN_VGA) -#define rom_add_vga (_f) \ - rom_add_file(_f, PC_ROM_MIN_VGA, PC_ROM_MAX, PC_ROM_ALIGN) -#define rom_add_option (_f) \ - rom_add_file(_f, PC_ROM_MIN_OPTION, PC_ROM_MAX, PC_ROM_ALIGN) +#ifdef CONFIG_LOADER_I386 +int rom_add_vga (const char *file); +int rom_add_option (const char *file); +#else +#define rom_add_vga (_file) 0 +#define rom_add_option (_file) 0 +#endif #endif
Signature · 1 line
1.6.2.5
[Qemu-devel] Re: [PATCH 2/4] rom loader: make vga+rom loading target specific
Quoted 10 lines · Juan Quintela
Review
Quoted 6 lines
(quoted diff) +6
-0+ifdef TARGET_I386 +obj-y += loader-i386.o +else +obj-y += loader-dummy.o +endif +This is wrong (tm).
a-TARGET_I386on Makefiles is only defined for 32bits, not for 64bits
(don't blame me, I just did a direct conversion of what was there).
Oh. Joy of inconsistency ...
Quoted 8 lines
b- TARGET_* is only defined in {i386,x86_64,...}-{softmmu,linux-user,...}
i.e. not a chance to be read at hw/Makefile.</me does patch>
More complex that I thought:
- if you only want to compile it once, you need to compile it onMakefile, not Makefile.hw: no cookie,loader.husestarget_phys_addr.
Exactly. Due to target_phys_addr it must go to Makefile.hw, so I get it compiled once for 32bit targphys and once for 64bit targphys.
Quoted 3 lines
- ok, move it to Makefile.hw -> your option didn't work (it compiles) because you allways compile loader-dummy.o,
TARGET_I386is not defined in Makefile.hw (it is hardware independent drivers after all :)
Oops.
Quoted 3 lines
- More imagination: Use only
loader-i386.c, and #ifdefTARGET_I386to an empty macro/real thing -> no cookie either,TARGET_I386is poisoned in Makefile.hw (*)
Thats why I don't want #ifdef.
Quoted 1 line
- define
CONFIG_LOADER_I386for I386 andX86_64.
No. This avoids the TARGET_I386 poisoned error, but does *not* fix the underlying problem.
Quoted 2 lines
I preffer very much to add the "dummy" cases in one ifdef in a header file.
No. Any user of rom_add_option() must be compiled per target then.
Guess easierst way is the v1 patch then: Have target-specific code in loader-target.c and use #ifdefs there ...
cheers,
Gerd
PATCH v2 3/4 vga roms: move loading from pc.c to vga drivers.
In reply to Gerd Hoffmann--- hw/cirrus_vga.c | 6 +++++- hw/pc.c | 12 ------------ hw/vga-isa.c | 3 +++ hw/vga-pci.c | 4 ++++ hw/vga_int.h | 2 ++ 5 files changed, 14 insertions(+), 13 deletions(-)
hw/cirrus_vga.c +5 -1
@@ -32,6 +32,7 @@#include "console.h" #include "vga_int.h" #include "kvm.h" +#include "loader.h" /* * TODO:
@@ -3162,6 +3163,7 @@ void isa_cirrus_vga_init(void) s->vga.screen_dump, s->vga.text_update, &s->vga);vmstate_register (0 , &vmstate_cirrus_vga, s); +rom_add_vga (VGABIOS_CIRRUS_FILENAME );/* XXX ISA-LFB support */ }
@@ -3245,7 +3247,9 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev) PCI_ADDRESS_SPACE_MEM, cirrus_pci_mmio_map); }vmstate_register (0 , &vmstate_pci_cirrus_vga, d); -/* XXX: ROM BIOS */ + +/* ROM BIOS */ +rom_add_vga (VGABIOS_CIRRUS_FILENAME );return 0 ; }
hw/pc.c +0 -12
@@ -47,8 +47,6 @@//#define DEBUG_MULTIBOOT #define BIOS_FILENAME "bios.bin" -#define VGABIOS_FILENAME "vgabios.bin" -#define VGABIOS_CIRRUS_FILENAME "vgabios-cirrus.bin"#define PC_MAX_BIOS_SIZE (4 * 1024 * 1024)
@@ -1050,7 +1048,6 @@ static void pc_init1(ram_addr_t ram_size,IsaIrqState *isa_irq_state;DriveInfo *hd[MAX_IDE_BUS *MAX_IDE_DEVS ];DriveInfo *fd[MAX_FD ]; -int using_vga = cirrus_vga_enabled || std_vga_enabled || vmsvga_enabled;void *fw_cfg;if (ram_size >=0xe0000000 ) {
@@ -1140,15 +1137,6 @@ static void pc_init1(ram_addr_t ram_size, option_rom_offset =qemu_ram_alloc (PC_ROM_SIZE );cpu_register_physical_memory (PC_ROM_MIN_VGA ,PC_ROM_SIZE , option_rom_offset); -if (using_vga) { -/* VGA BIOS load */ -if (cirrus_vga_enabled) { -rom_add_vga (VGABIOS_CIRRUS_FILENAME ); - }else { -rom_add_vga (VGABIOS_FILENAME ); - } - } -/* map all the bios at the top of memory */ cpu_register_physical_memory ((uint32_t )(-bios_size), bios_size, bios_offset |IO_MEM_ROM );
hw/vga-isa.c +3 -0
@@ -27,6 +27,7 @@#include "vga_int.h" #include "pixel_ops.h" #include "qemu-timer.h" +#include "loader.h" int isa_vga_init (void ) {
@@ -46,5 +47,7 @@ int isa_vga_init(void)cpu_register_physical_memory (VBE_DISPI_LFB_PHYSICAL_ADDRESS ,VGA_RAM_SIZE , s->vram_offset);#endif +/* ROM BIOS */ +rom_add_vga (VGABIOS_FILENAME );return 0 ; }
hw/vga-pci.c +4 -0
@@ -28,6 +28,7 @@#include "vga_int.h" #include "pixel_ops.h" #include "qemu-timer.h" +#include "loader.h" typedef struct PCIVGAState { PCIDevice dev;
@@ -117,6 +118,9 @@ static int pci_vga_initfn(PCIDevice *dev)pci_register_bar (&d->dev,PCI_ROM_SLOT , bios_total_size,PCI_ADDRESS_SPACE_MEM_PREFETCH , vga_map); } + +/* ROM BIOS */ +rom_add_vga (VGABIOS_FILENAME );return 0 ; }
hw/vga_int.h +2 -0
@@ -220,6 +220,8 @@ extern const uint8_t sr_mask[8];extern const uint8_t gr_mask[16 ];#define VGA_RAM_SIZE (8192 * 1024) +#define VGABIOS_FILENAME "vgabios.bin" +#define VGABIOS_CIRRUS_FILENAME "vgabios-cirrus.bin"extern CPUReadMemoryFunc *const vga_mem_read[3 ];extern CPUWriteMemoryFunc *const vga_mem_write[3 ];
Signature · 1 line
1.6.2.5
PATCH v2 4/4 use rom loader for pc bios.
In reply to Gerd HoffmannThe pc bios shows up in 'info roms' now.
Note that the BIOS is mapped to two places: The complete rom at the top of the memory, and the first 128k at 0xe0000. Only the first place is listed in 'info roms'.
--- hw/pc.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
hw/pc.c +2 -2
@@ -1115,8 +1115,8 @@ static void pc_init1(ram_addr_t ram_size, goto bios_error; } bios_offset =qemu_ram_alloc (bios_size); - ret =load_image (filename,qemu_get_ram_ptr (bios_offset)); -if (ret != bios_size) { + ret =rom_add_file_fixed (bios_name, (uint32_t )(-bios_size)); +if (ret !=0 ) { bios_error:fprintf (stderr,"qemu: could not load PC BIOS '%s'\n" , bios_name);exit (1 );
Signature · 1 line
1.6.2.5