Add optionrom compatible with fw_cfg DMA version
v7 cover Add optionrom compatible with fw_cfg DMA version
v6 -> v7:
- This version compiles and works with both GCC (tested 6.1.1) and with Clang (tested 3.8.0).
- Uses -m16 mode on both compilers to generate i8086 code.
- The signrom.py script has been modified so it can (optionally) generate the size field in the header.
- Tested with both a small (libguestfs) and large (Fedora 23) initrd.
Rich.
PATCH v7 1/2 scripts/signrom.py: Allow option ROM checksum script to write the size header.
Modify the signrom.py script so that if the size byte in the header is 0 (ie. not set) then the script will set the size. If the size byte is non-zero then we do the same as before, so this doesn't require changes to any existing ROM sourcecode.
--- scripts/signrom.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
scripts/signrom.py +22 -3
@@ -18,10 +18,29 @@ fin = open(sys.argv[1], 'rb') fout = open(sys.argv[2], 'wb') fin.seek(2) -size = ord(fin.read(1)) * 512 - 1 - +size_byte = ord(fin.read(1)) fin.seek(0) -data = fin.read(size) + +if size_byte == 0: + # If the caller left the size field blank then we will fill it in, + # also rounding the whole input to a multiple of 512 bytes. + data = fin.read() + # +1 because we need a byte to store the checksum. + size = len(data) + 1 + # Round up to next multiple of 512. + size += 511 + size -= size % 512 + if size >= 65536: + sys.exit("%s: option ROM size too large" % sys.argv[1]) + # size-1 because a final byte is added below to store the checksum. + data = data.ljust(size-1, '\0') + data = data[:2] + chr(size/512) + data[3:] +else: + # Otherwise the input file specifies the size so use it. + # -1 because we overwrite the last byte of the file with the checksum. + size = size_byte * 512 - 1 + data = fin.read(size) + fout.write(data) checksum = 0
Signature · 1 line
2.7.4
PATCH v7 2/2 Add optionrom compatible with fw_cfg DMA version
In reply to Richard W.M. JonesFrom: Marc Marí <[email protected]>
This optionrom is based on linuxboot.S.
--- .gitignore | 4 + hw/i386/pc.c | 10 +- hw/nvram/fw_cfg.c | 2 +- include/hw/nvram/fw_cfg.h | 1 + pc-bios/optionrom/Makefile | 13 +- pc-bios/optionrom/linuxboot_dma.c | 291 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 316 insertions(+), 5 deletions(-) create mode 100644 pc-bios/optionrom/linuxboot_dma.c
.gitignore +4 -0
@@ -94,6 +94,10 @@ /pc-bios/optionrom/linuxboot.bin /pc-bios/optionrom/linuxboot.raw /pc-bios/optionrom/linuxboot.img +/pc-bios/optionrom/linuxboot_dma.asm +/pc-bios/optionrom/linuxboot_dma.bin +/pc-bios/optionrom/linuxboot_dma.raw +/pc-bios/optionrom/linuxboot_dma.img /pc-bios/optionrom/multiboot.asm /pc-bios/optionrom/multiboot.bin /pc-bios/optionrom/multiboot.raw
hw/i386/pc.c +8 -2
@@ -999,8 +999,13 @@ static void load_linux(PCMachineState *pcms,fw_cfg_add_i32 (fw_cfg,FW_CFG_SETUP_SIZE , setup_size);fw_cfg_add_bytes (fw_cfg,FW_CFG_SETUP_DATA , setup, setup_size); - option_rom[nb_option_roms].name ="linuxboot.bin" ; - option_rom[nb_option_roms].bootindex =0 ; +if (fw_cfg_dma_enabled (fw_cfg)) { + option_rom[nb_option_roms].name ="linuxboot_dma.bin" ; + option_rom[nb_option_roms].bootindex =0 ; + }else { + option_rom[nb_option_roms].name ="linuxboot.bin" ; + option_rom[nb_option_roms].bootindex =0 ; + } nb_option_roms++; }
@@ -1263,6 +1268,7 @@ void xen_load_linux(PCMachineState *pcms)load_linux (pcms, fw_cfg);for (i =0 ; i < nb_option_roms; i++) {assert (!strcmp (option_rom[i].name,"linuxboot.bin" ) || + !strcmp (option_rom[i].name,"linuxboot_dma.bin" ) || !strcmp (option_rom[i].name,"multiboot.bin" ));rom_add_option (option_rom[i].name, option_rom[i].bootindex); }
hw/nvram/fw_cfg.c +1 -1
@@ -551,7 +551,7 @@ static bool is_version_1(void *opaque, int version_id)return version_id ==1 ; } -static bool fw_cfg_dma_enabled (void *opaque) +bool fw_cfg_dma_enabled (void *opaque) {FWCfgState *s = opaque;
include/hw/nvram/fw_cfg.h +1 -0
@@ -182,5 +182,6 @@ FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr, hwaddr dma_addr, AddressSpace *dma_as);FWCfgState *fw_cfg_find (void ); +bool fw_cfg_dma_enabled (void *opaque);#endif
pc-bios/optionrom/Makefile +11 -2
@@ -13,15 +13,24 @@ CFLAGS := -Wall -Wstrict-prototypes -Werror -fomit-frame-pointer -fno-builtin CFLAGS += -I$(SRC_PATH) CFLAGS += $(call cc-option, $(CFLAGS), -fno-stack-protector) CFLAGS += $(CFLAGS_NOPIE) +CFLAGS += -m16 QEMU_CFLAGS = $(CFLAGS) -build-all: multiboot.bin linuxboot.bin kvmvapic.bin +ASFLAGS += -32 + +build-all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin # suppress auto-removal of intermediate files .SECONDARY: +ifdef CONFIG_WIN32 +LD_EMULATION = i386pe +else +LD_EMULATION = elf_i386 +endif + %.img: %.o - $(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -Ttext 0 -e _start -s -o $@ $<," Building $(TARGET_DIR)$@") + $(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -m $(LD_EMULATION) -Ttext 0 -e _start -s -o $@ $<," Building $(TARGET_DIR)$@") %.raw: %.img $(call quiet-command,$(OBJCOPY) -O binary -j .text $< $@," Building $(TARGET_DIR)$@")
pc-bios/optionrom/linuxboot_dma.c new file +291 -0
291 lines not on this page · raw message
Signature · 1 line
2.7.4
Quoted 4 lines · Richard W.M. Jones
pc-bios/optionrom/linuxboot_dma.c new file +4
-0+ +#ifdef __clang__ +#define ADDR32 +#else
pc-bios/optionrom/linuxboot_dma.c line 107
Quoted 10 lines
pc-bios/optionrom/linuxboot_dma.c new file +10
-0+#define ADDR32 "addr32 " +#endif + +static inline uint16_t readw_es (uint16_t offset) +{ +uint16_t val; + asm(ADDR32 "movw %%es:(%1), %0" :"=r" (val) :"r" ((uint32_t )offset)); +barrier (); +return val; +}
Please check that the output is the same byte-by-byte for this asm.
I guess this is okay if we have a guarantee from clang that the asm block stays at the beginning. Perhaps check for the 0x55 0xaa signature in signrom.py?
Thanks,
Paolo
Quoted 19 lines · Paolo Bonzini
Quoted 4 lines · Richard W.M. Jones
pc-bios/optionrom/linuxboot_dma.c new file +4
-0+ +#ifdef __clang__ +#define ADDR32 +#else pc-bios/optionrom/linuxboot_dma.c line 107
Quoted 10 lines
pc-bios/optionrom/linuxboot_dma.c new file +10
-0+#define ADDR32 "addr32 " +#endif + +static inline uint16_t readw_es (uint16_t offset) +{ +uint16_t val; + asm(ADDR32 "movw %%es:(%1), %0" :"=r" (val) :"r" ((uint32_t )offset)); +barrier (); +return val; +}Please check that the output is the same byte-by-byte for this asm.
For this function, clang emits:
647: 26 67 8b 08 mov %es:(%eax),%cx
GCC emits:
b3: 26 67 8b 00 mov %es:(%eax),%ax
So yes these are byte for byte identical (except for the MOD R/M byte because of the different target register).
Quoted 3 lines
I guess this is okay if we have a guarantee from clang that the asm block stays at the beginning. Perhaps check for the
0x550xaasignature insignrom.py?
Good idea, I'll add this in the next version.
Thanks,
Rich.
Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top