multiboot: Change multiboot_info from array of bytes to a C struct
PATCH 1/4 multiboot: Change multiboot_info from array of bytes to a C struct
Using C structs makes the code more readable and prevents type conversion errors.
Borrow multiboot1 header from GRUB project.
--- hw/i386/multiboot.c | 124 +++++++++------------ hw/i386/multiboot_header.h | 254 ++++++++++++++++++++++++++++++++++++++++++++ tests/multiboot/mmap.c | 14 +-- tests/multiboot/mmap.out | 10 ++ tests/multiboot/modules.c | 12 ++- tests/multiboot/modules.out | 10 ++ tests/multiboot/multiboot.h | 66 ------------ 7 files changed, 339 insertions(+), 151 deletions(-) create mode 100644 hw/i386/multiboot_header.h delete mode 100644 tests/multiboot/multiboot.h
hw/i386/multiboot.c +50 -74
@@ -28,6 +28,7 @@#include "hw/hw.h" #include "hw/nvram/fw_cfg.h" #include "multiboot.h" +#include "multiboot_header.h" #include "hw/loader.h" #include "elf.h" #include "sysemu/sysemu.h"
@@ -47,39 +48,9 @@#error multiboot struct needs to fit in 16 bit real mode#endif -enum { -/* Multiboot info */ -MBI_FLAGS =0 , -MBI_MEM_LOWER =4 , -MBI_MEM_UPPER =8 , -MBI_BOOT_DEVICE =12 , -MBI_CMDLINE =16 , -MBI_MODS_COUNT =20 , -MBI_MODS_ADDR =24 , -MBI_MMAP_ADDR =48 , -MBI_BOOTLOADER =64 , - -MBI_SIZE =88 , - -/* Multiboot modules */ -MB_MOD_START =0 , -MB_MOD_END =4 , -MB_MOD_CMDLINE =8 , - -MB_MOD_SIZE =16 , - -/* Region offsets */ -ADDR_E820_MAP =MULTIBOOT_STRUCT_ADDR +0 , -ADDR_MBI =ADDR_E820_MAP +0x500 , - -/* Multiboot flags */ -MULTIBOOT_FLAGS_MEMORY =1 <<0 , -MULTIBOOT_FLAGS_BOOT_DEVICE =1 <<1 , -MULTIBOOT_FLAGS_CMDLINE =1 <<2 , -MULTIBOOT_FLAGS_MODULES =1 <<3 , -MULTIBOOT_FLAGS_MMAP =1 <<6 , -MULTIBOOT_FLAGS_BOOTLOADER =1 <<9 , -}; +/* Region offsets */ +#define ADDR_E820_MAP MULTIBOOT_STRUCT_ADDR +#define ADDR_MBI (ADDR_E820_MAP + 0x500) typedef struct { /* buffer holding kernel, cmdlines and mb_infos */
@@ -128,14 +99,15 @@ static void mb_add_mod(MultibootState *s, hwaddr start, hwaddr end, hwaddr cmdline_phys) { - char *p; + multiboot_module_t *mod;assert (s->mb_mods_count < s->mb_mods_avail); - p = (char *)s->mb_buf + s->offset_mbinfo +MB_MOD_SIZE * s->mb_mods_count; + mod = s->mb_buf + s->offset_mbinfo + +sizeof (multiboot_module_t) * s->mb_mods_count; -stl_p (p +MB_MOD_START , start); -stl_p (p +MB_MOD_END , end); -stl_p (p +MB_MOD_CMDLINE , cmdline_phys); +stl_p (&mod->mod_start, start); +stl_p (&mod->mod_end, end); +stl_p (&mod->cmdline, cmdline_phys);mb_debug ("mod%02d: " TARGET_FMT_plx" - " TARGET_FMT_plx"\n" , s->mb_mods_count, start, end);
@@ -151,26 +123,29 @@ int load_multiboot(FWCfgState *fw_cfg,int kernel_file_size, uint8_t *header) { - int i, is_multiboot = 0; + int i; +bool is_multiboot = false;uint32_t flags =0 ;uint32_t mh_entry_addr;uint32_t mh_load_addr;uint32_t mb_kernel_size;MultibootState mbs; -uint8_t bootinfo[MBI_SIZE ]; +multiboot_info_t bootinfo;uint8_t *mb_bootinfo_data;uint32_t cmdline_len; +struct multiboot_header *multiboot_header;/* Ok, let's see if it is a multiboot image. The header is 12x32bit long, so the latest entry may be 8192 - 48. */ for (i =0 ; i < (8192 -48 ); i +=4 ) { -if (ldl_p (header+i) ==0x1BADB002 ) { -uint32_t checksum =ldl_p (header+i+8 ); - flags =ldl_p (header+i+4 ); + multiboot_header = (struct multiboot_header *)(header + i); +if (ldl_p (&multiboot_header->magic) ==MULTIBOOT_HEADER_MAGIC ) { +uint32_t checksum =ldl_p (&multiboot_header->checksum); + flags =ldl_p (&multiboot_header->flags); checksum += flags; - checksum += (uint32_t )0x1BADB002 ; + checksum += (uint32_t )MULTIBOOT_HEADER_MAGIC ;if (!checksum) { - is_multiboot =1 ; + is_multiboot = true;break ; } }
@@ -180,13 +155,13 @@ int load_multiboot(FWCfgState *fw_cfg,return 0 ;/* no multiboot */ mb_debug ("qemu: I believe we found a multiboot image!\n" ); -memset (bootinfo,0 ,sizeof (bootinfo)); +memset (&bootinfo,0 ,sizeof (bootinfo));memset (&mbs,0 ,sizeof (mbs)); -if (flags &0x00000004 ) {/* MULTIBOOT_HEADER_HAS_VBE */ +if (flags &MULTIBOOT_VIDEO_MODE ) {fprintf (stderr,"qemu: multiboot knows VBE. we don't.\n" ); } -if (!(flags &0x00010000 )) {/* MULTIBOOT_HEADER_HAS_ADDR */ +if (!(flags &MULTIBOOT_AOUT_KLUDGE )) {uint64_t elf_entry;uint64_t elf_low, elf_high;int kernel_size;
@@ -217,12 +192,12 @@ int load_multiboot(FWCfgState *fw_cfg,mb_debug ("qemu: loading multiboot-elf kernel (%#x bytes) with entry %#zx\n" , mb_kernel_size, (size_t )mh_entry_addr); }else { -/* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_ADDR. */ -uint32_t mh_header_addr =ldl_p (header+i+12 ); -uint32_t mh_load_end_addr =ldl_p (header+i+20 ); -uint32_t mh_bss_end_addr =ldl_p (header+i+24 ); +/* Valid if mh_flags sets MULTIBOOT_AOUT_KLUDGE. */ +uint32_t mh_header_addr =ldl_p (&multiboot_header->header_addr); +uint32_t mh_load_end_addr =ldl_p (&multiboot_header->load_end_addr); +uint32_t mh_bss_end_addr =ldl_p (&multiboot_header->bss_end_addr); + mh_load_addr =ldl_p (&multiboot_header->load_addr); - mh_load_addr =ldl_p (header+i+16 );if (mh_header_addr < mh_load_addr) {fprintf (stderr,"invalid mh_load_addr address\n" );exit (1 );
@@ -230,7 +205,7 @@ int load_multiboot(FWCfgState *fw_cfg,uint32_t mb_kernel_text_offset = i - (mh_header_addr - mh_load_addr);uint32_t mb_load_size =0 ; - mh_entry_addr =ldl_p (header+i+28 ); + mh_entry_addr =ldl_p (&multiboot_header->entry_addr);if (mh_load_end_addr) {if (mh_bss_end_addr < mh_load_addr) {
@@ -253,11 +228,11 @@ int load_multiboot(FWCfgState *fw_cfg, mb_load_size = mb_kernel_size; } -/* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE. -uint32_t mh_mode_type = ldl_p(header+i+32); -uint32_t mh_width = ldl_p(header+i+36); -uint32_t mh_height = ldl_p(header+i+40); -uint32_t mh_depth = ldl_p(header+i+44); */ +/* Valid if mh_flags sets MULTIBOOT_VIDEO_MODE. +uint32_t mh_mode_type = ldl_p(&multiboot_header->mode_type); +uint32_t mh_width = ldl_p(&multiboot_header->width); +uint32_t mh_height = ldl_p(&multiboot_header->height); +uint32_t mh_depth = ldl_p(&multiboot_header->depth); */ mb_debug ("multiboot: mh_header_addr = %#x\n" , mh_header_addr);mb_debug ("multiboot: mh_load_addr = %#x\n" , mh_load_addr);
@@ -295,14 +270,15 @@ int load_multiboot(FWCfgState *fw_cfg, } mbs.mb_buf_size += cmdline_len; - mbs.mb_buf_size +=MB_MOD_SIZE * mbs.mb_mods_avail; + mbs.mb_buf_size +=sizeof (multiboot_module_t) * mbs.mb_mods_avail; mbs.mb_buf_size +=strlen (bootloader_name) +1 ; mbs.mb_buf_size =TARGET_PAGE_ALIGN (mbs.mb_buf_size);/* enlarge mb_buf to hold cmdlines, bootloader, mb-info structs */ mbs.mb_buf =g_realloc (mbs.mb_buf, mbs.mb_buf_size); - mbs.offset_cmdlines = mbs.offset_mbinfo + mbs.mb_mods_avail *MB_MOD_SIZE ; + mbs.offset_cmdlines = mbs.offset_mbinfo + + mbs.mb_mods_avail *sizeof (multiboot_module_t); mbs.offset_bootloader = mbs.offset_cmdlines + cmdline_len;if (initrd_filename) {
@@ -348,22 +324,22 @@ int load_multiboot(FWCfgState *fw_cfg,char kcmdline[strlen (kernel_filename) +strlen (kernel_cmdline) +2 ];snprintf (kcmdline,sizeof (kcmdline),"%s %s" , kernel_filename, kernel_cmdline); -stl_p (bootinfo +MBI_CMDLINE ,mb_add_cmdline (&mbs, kcmdline)); +stl_p (&bootinfo.cmdline,mb_add_cmdline (&mbs, kcmdline)); -stl_p (bootinfo +MBI_BOOTLOADER ,mb_add_bootloader (&mbs, bootloader_name)); +stl_p (&bootinfo.boot_loader_name,mb_add_bootloader (&mbs, bootloader_name)); -stl_p (bootinfo +MBI_MODS_ADDR , mbs.mb_buf_phys + mbs.offset_mbinfo); -stl_p (bootinfo +MBI_MODS_COUNT , mbs.mb_mods_count);/* mods_count */ +stl_p (&bootinfo.mods_addr, mbs.mb_buf_phys + mbs.offset_mbinfo); +stl_p (&bootinfo.mods_count, mbs.mb_mods_count);/* mods_count */ /* the kernel is where we want it to be now */ -stl_p (bootinfo +MBI_FLAGS ,MULTIBOOT_FLAGS_MEMORY - |MULTIBOOT_FLAGS_BOOT_DEVICE - |MULTIBOOT_FLAGS_CMDLINE - |MULTIBOOT_FLAGS_MODULES - |MULTIBOOT_FLAGS_MMAP - |MULTIBOOT_FLAGS_BOOTLOADER ); -stl_p (bootinfo +MBI_BOOT_DEVICE ,0x8000ffff );/* XXX: use the -boot switch? */ -stl_p (bootinfo +MBI_MMAP_ADDR ,ADDR_E820_MAP ); +stl_p (&bootinfo.flags,MULTIBOOT_INFO_MEMORY + |MULTIBOOT_INFO_BOOTDEV + |MULTIBOOT_INFO_CMDLINE + |MULTIBOOT_INFO_MODS + |MULTIBOOT_INFO_MEM_MAP + |MULTIBOOT_INFO_BOOT_LOADER_NAME ); +stl_p (&bootinfo.boot_device,0x8000ffff );/* XXX: use the -boot switch? */ +stl_p (&bootinfo.mmap_addr,ADDR_E820_MAP );mb_debug ("multiboot: mh_entry_addr = %#x\n" , mh_entry_addr);mb_debug (" mb_buf_phys = " TARGET_FMT_plx"\n" , mbs.mb_buf_phys);
@@ -371,7 +347,7 @@ int load_multiboot(FWCfgState *fw_cfg,mb_debug (" mb_mods_count = %d\n" , mbs.mb_mods_count);/* save bootinfo off the stack */ - mb_bootinfo_data =g_memdup (bootinfo,sizeof (bootinfo)); + mb_bootinfo_data =g_memdup (&bootinfo,sizeof (bootinfo));/* Pass variables to option rom */ fw_cfg_add_i32 (fw_cfg,FW_CFG_KERNEL_ENTRY , mh_entry_addr);
hw/i386/multiboot_header.h new file +254 -0
254 lines not on this page · raw message
tests/multiboot/mmap.c +8 -6
@@ -21,15 +21,17 @@*/ #include "libc.h" -#include "multiboot.h" +#include "../../hw/i386/multiboot_header.h" -int test_main (uint32_t magic,struct mb_info *mbi) +int test_main (uint32_t magic,struct multiboot_info *mbi) {uintptr_t entry_addr; -struct mb_mmap_entry *entry; +struct multiboot_mmap_entry *entry; (void ) magic; +printf ("Multiboot header at %x\n\n" , mbi); +printf ("Lower memory: %dk\n" , mbi->mem_lower);printf ("Upper memory: %dk\n" , mbi->mem_upper);
@@ -39,11 +41,11 @@ int test_main(uint32_t magic, struct mb_info *mbi) entry_addr < mbi->mmap_addr + mbi->mmap_length; entry_addr += entry->size + 4) { - entry = (struct mb_mmap_entry *) entry_addr; + entry = (struct multiboot_mmap_entry *) entry_addr;printf ("%#llx - %#llx: type %d [entry size: %d]\n" , - entry->base_addr, - entry->base_addr + entry->length, + entry->addr, + entry->addr + entry->len, entry->type, entry->size); }
tests/multiboot/mmap.out +10 -0
@@ -3,6 +3,8 @@ === Running test case: mmap.elf === +Multiboot header at 9500 + Lower memory: 639k Upper memory: 129920k
@@ -21,6 +23,8 @@ real mmap end: 0x9090 === Running test case: mmap.elf -m 1.1M === +Multiboot header at 9500 + Lower memory: 639k Upper memory: 104k
@@ -38,6 +42,8 @@ real mmap end: 0x9078 === Running test case: mmap.elf -m 2G === +Multiboot header at 9500 + Lower memory: 639k Upper memory: 2096000k
@@ -56,6 +62,8 @@ real mmap end: 0x9090 === Running test case: mmap.elf -m 4G === +Multiboot header at 9500 + Lower memory: 639k Upper memory: 3144576k
@@ -75,6 +83,8 @@ real mmap end: 0x90a8 === Running test case: mmap.elf -m 8G === +Multiboot header at 9500 + Lower memory: 639k Upper memory: 3144576k
tests/multiboot/modules.c +7 -5
@@ -21,19 +21,21 @@*/ #include "libc.h" -#include "multiboot.h" +#include "../../hw/i386/multiboot_header.h" -int test_main (uint32_t magic,struct mb_info *mbi) +int test_main (uint32_t magic,struct multiboot_info *mbi) { -struct mb_module *mod; +struct multiboot_mod_list *mod;unsigned int i; (void ) magic; +printf ("Multiboot header at %x\n\n" , mbi); +printf ("Module list with %d entries at %x\n" , mbi->mods_count, mbi->mods_addr); -for (i =0 , mod = (struct mb_module *) mbi->mods_addr; +for (i =0 , mod = (struct multiboot_mod_list *) mbi->mods_addr; i < mbi->mods_count; i++, mod++) {
@@ -41,7 +43,7 @@ int test_main(uint32_t magic, struct mb_info *mbi)unsigned int size = mod->mod_end - mod->mod_start;printf ("[%p] Module: %x - %x (%d bytes) '%s'\n" , - mod, mod->mod_start, mod->mod_end, size, mod->string); + mod, mod->mod_start, mod->mod_end, size, mod->cmdline);/* Print test file, but remove the newline at the end */ if (size <sizeof (buf)) {
tests/multiboot/modules.out +10 -0
@@ -3,11 +3,15 @@ === Running test case: modules.elf === +Multiboot header at 9500 + Module list with 0 entries at 102000 === Running test case: modules.elf -initrd module.txt === +Multiboot header at 9500 + Module list with 1 entries at 102000 [102000] Module: 103000 - 103038 (56 bytes) 'module.txt' Content: 'This is a test file that is used as a multiboot module.'
@@ -15,6 +19,8 @@ Module list with 1 entries at 102000 === Running test case: modules.elf -initrd module.txt argument === +Multiboot header at 9500 + Module list with 1 entries at 102000 [102000] Module: 103000 - 103038 (56 bytes) 'module.txt argument' Content: 'This is a test file that is used as a multiboot module.'
@@ -22,6 +28,8 @@ Module list with 1 entries at 102000 === Running test case: modules.elf -initrd module.txt argument,,with,,commas === +Multiboot header at 9500 + Module list with 1 entries at 102000 [102000] Module: 103000 - 103038 (56 bytes) 'module.txt argument,with,commas' Content: 'This is a test file that is used as a multiboot module.'
@@ -29,6 +37,8 @@ Module list with 1 entries at 102000 === Running test case: modules.elf -initrd module.txt,module.txt argument,module.txt === +Multiboot header at 9500 + Module list with 3 entries at 102000 [102000] Module: 103000 - 103038 (56 bytes) 'module.txt' Content: 'This is a test file that is used as a multiboot module.'
tests/multiboot/multiboot.h deleted +0 -66
66 lines not on this page · raw message
Signature · 1 line
2.16.0.rc1.238.g530d649a79-goog
PATCH 2/4 multiboot: load elf sections and section headers
Multiboot may load section headers and all sections (even those that are not part of any segment) to target memory.
Tested with an ELF application that uses data from strings table section.
--- hw/core/loader.c | 8 +-- hw/i386/multiboot.c | 17 +++-- hw/s390x/ipl.c | 2 +- include/hw/elf_ops.h | 110 +++++++++++++++++++++++++++++-- include/hw/loader.h | 11 +++- tests/multiboot/Makefile | 8 ++- tests/multiboot/generate_sections_out.py | 33 ++++++++++ tests/multiboot/modules.out | 22 +++---- tests/multiboot/run_test.sh | 6 +- tests/multiboot/sections.c | 57 ++++++++++++++++ tests/multiboot/start.S | 2 +- 11 files changed, 248 insertions(+), 28 deletions(-) create mode 100755 tests/multiboot/generate_sections_out.py create mode 100644 tests/multiboot/sections.c
hw/core/loader.c +4 -4
@@ -439,7 +439,7 @@ int load_elf_as(const char *filename, {return load_elf_ram (filename, translate_fn, translate_opaque, pentry, lowaddr, highaddr, big_endian, elf_machine, - clear_lsb, data_swab, as, true); + clear_lsb, data_swab, as, true,NULL ); }/* return < 0 if error, otherwise the number of bytes loaded in memory */
@@ -448,7 +448,7 @@ int load_elf_ram(const char *filename, void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr, int big_endian, int elf_machine, int clear_lsb, int data_swab, AddressSpace *as, - bool load_rom) + bool load_rom, SectionsData *sections) { int fd, data_order, target_data_order, must_swab, ret = ELF_LOAD_FAILED;uint8_t e_ident[EI_NIDENT ];
@@ -488,11 +488,11 @@ int load_elf_ram(const char *filename,if (e_ident[EI_CLASS ] ==ELFCLASS64 ) { ret =load_elf64 (filename, fd, translate_fn, translate_opaque, must_swab, pentry, lowaddr, highaddr, elf_machine, clear_lsb, - data_swab, as, load_rom); + data_swab, as, load_rom, sections); }else { ret =load_elf32 (filename, fd, translate_fn, translate_opaque, must_swab, pentry, lowaddr, highaddr, elf_machine, clear_lsb, - data_swab, as, load_rom); + data_swab, as, load_rom, sections); } fail:
hw/i386/multiboot.c +13 -4
@@ -125,7 +125,7 @@ int load_multiboot(FWCfgState *fw_cfg, {int i;bool is_multiboot = false; -uint32_t flags =0 ; +uint32_t flags =0 , bootinfo_flags =0 ;uint32_t mh_entry_addr;uint32_t mh_load_addr;uint32_t mb_kernel_size;
@@ -134,6 +134,7 @@ int load_multiboot(FWCfgState *fw_cfg,uint8_t *mb_bootinfo_data;uint32_t cmdline_len;struct multiboot_header *multiboot_header; +SectionsData sections;/* Ok, let's see if it is a multiboot image. The header is 12x32bit long, so the latest entry may be 8192 - 48. */
@@ -172,9 +173,9 @@ int load_multiboot(FWCfgState *fw_cfg,exit (1 ); } - kernel_size =load_elf (kernel_filename,NULL ,NULL , &elf_entry, + kernel_size =load_elf_ram (kernel_filename,NULL ,NULL , &elf_entry, &elf_low, &elf_high,0 ,I386_ELF_MACHINE , -0 ,0 ); +0 ,0 ,NULL , true, §ions);if (kernel_size <0 ) {fprintf (stderr,"Error while loading elf kernel\n" );exit (1 );
@@ -191,6 +192,13 @@ int load_multiboot(FWCfgState *fw_cfg,mb_debug ("qemu: loading multiboot-elf kernel (%#x bytes) with entry %#zx\n" , mb_kernel_size, (size_t )mh_entry_addr); + +stl_p (&bootinfo.u.elf_sec.num, sections.num); +stl_p (&bootinfo.u.elf_sec.size, sections.size); +stl_p (&bootinfo.u.elf_sec.addr, sections.addr); +stl_p (&bootinfo.u.elf_sec.shndx, sections.shndx); + + bootinfo_flags |=MULTIBOOT_INFO_ELF_SHDR ; }else {/* Valid if mh_flags sets MULTIBOOT_AOUT_KLUDGE. */ uint32_t mh_header_addr =ldl_p (&multiboot_header->header_addr);
@@ -332,7 +340,8 @@ int load_multiboot(FWCfgState *fw_cfg,stl_p (&bootinfo.mods_count, mbs.mb_mods_count);/* mods_count */ /* the kernel is where we want it to be now */ -stl_p (&bootinfo.flags,MULTIBOOT_INFO_MEMORY +stl_p (&bootinfo.flags, bootinfo_flags + |MULTIBOOT_INFO_MEMORY |MULTIBOOT_INFO_BOOTDEV |MULTIBOOT_INFO_CMDLINE | MULTIBOOT_INFO_MODS
hw/s390x/ipl.c +1 -1
@@ -327,7 +327,7 @@ static int load_netboot_image(Error **errp) } img_size =load_elf_ram (netboot_filename,NULL ,NULL , &ipl->start_addr, -NULL ,NULL ,1 ,EM_S390 ,0 ,0 ,NULL , false); +NULL ,NULL ,1 ,EM_S390 ,0 ,0 ,NULL , false,NULL );if (img_size <0 ) { img_size =load_image_size (netboot_filename, ram_ptr, ram_size);
include/hw/elf_ops.h +106 -4
132 lines not on this page · raw message
include/hw/loader.h +10 -1
@@ -65,6 +65,13 @@ int load_image_gzipped(const char *filename, hwaddr addr, uint64_t max_sz);#define ELF_LOAD_WRONG_ENDIAN -4const char *load_elf_strerror (int error); +typedef struct { +uint32_t num;// number of loaded sections +uint32_t size;// size of entry in sections header list +uint32_t addr;// address of loaded sections header +uint32_t shndx;// number of section that contains string table +}SectionsData ; +/** load_elf_ram: * @filename: Path of ELF file * @translate_fn: optional function to translate load addresses
@@ -82,6 +89,8 @@ const char *load_elf_strerror(int error);* @as: The AddressSpace to load the ELF to. The value of address_space_memory * is used if nothing is supplied here. * @load_rom : Load ELF binary as ROM +* @sections: If parameter is non-NULL then all ELF sections loaded into memory +* and this structure is populated. * * Load an ELF file's contents to the emulated system's address space. * Clients may optionally specify a callback to perform address
@@ -99,7 +108,7 @@ int load_elf_ram(const char *filename, void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr, int big_endian, int elf_machine, int clear_lsb, int data_swab, AddressSpace *as, - bool load_rom); + bool load_rom, SectionsData *sections);/** load_elf_as: * Same as load_elf_ram(), but always loads the elf as ROM
tests/multiboot/Makefile +7 -1
@@ -6,7 +6,7 @@ LD=ld LDFLAGS=-melf_i386 -T link.ld LIBS=$(shell $(CC) $(CCFLAGS) -print-libgcc-file-name) -all: mmap.elf modules.elf +all: mmap.elf modules.elf sections.elf sections.out mmap.elf: start.o mmap.o libc.o $(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
@@ -14,6 +14,12 @@ mmap.elf: start.o mmap.o libc.o modules.elf: start.o modules.o libc.o $(LD) $(LDFLAGS) -o $@ $^ $(LIBS) +sections.elf: start.o sections.o libc.o + $(LD) $(LDFLAGS) -o $@ $^ $(LIBS) + +sections.out: sections.elf generate_sections_out.py + python2 generate_sections_out.py $^ > $@ + %.o: %.c $(CC) $(CCFLAGS) -c -o $@ $^
tests/multiboot/generate_sections_out.py new file +33 -0
@@ -0,0 +1,33 @@ +#!/usr/bin/env python2 + +import sys + +from elftools.elf.elffile import ELFFile + +def roundup(num, align): + return (num + align - 1) / align * align + +def main(filename): + print "\n\n\n=== Running test case: sections.elf ===\n" + print "Multiboot header at 9500, ELF section headers present\n" + + with open(filename, 'rb') as f: + elf = ELFFile(f) + header = elf.header + load_addr = 0x100000 # we load image starting from 1M + sections = "" + for s in elf.iter_sections(): + align = s.header.sh_addralign + addr = 0 + if s.header.sh_type != 'SHT_NULL': + addr = s.header.sh_addr + if addr == 0: + addr = roundup(load_addr, s.header.sh_addralign) + load_addr = addr + s.header.sh_size + sections += "Elf section name=%s addr=%x size=%d\n" % (s.name, addr, s.header.sh_size) + + print "Sections list with %d entries of size %d at %x, string index %d" % (header.e_shnum, header.e_shentsize, load_addr, header.e_shstrndx) + print sections, + +if __name__ == '__main__': + main(sys.argv[1])
tests/multiboot/modules.out +11 -11
@@ -5,15 +5,15 @@ Multiboot header at 9500 -Module list with 0 entries at 102000 +Module list with 0 entries at 104000 === Running test case: modules.elf -initrd module.txt === Multiboot header at 9500 -Module list with 1 entries at 102000 -[102000] Module: 103000 - 103038 (56 bytes) 'module.txt' +Module list with 1 entries at 104000 +[104000] Module: 105000 - 105038 (56 bytes) 'module.txt' Content: 'This is a test file that is used as a multiboot module.'
@@ -21,8 +21,8 @@ Module list with 1 entries at 102000 Multiboot header at 9500 -Module list with 1 entries at 102000 -[102000] Module: 103000 - 103038 (56 bytes) 'module.txt argument' +Module list with 1 entries at 104000 +[104000] Module: 105000 - 105038 (56 bytes) 'module.txt argument' Content: 'This is a test file that is used as a multiboot module.'
@@ -30,8 +30,8 @@ Module list with 1 entries at 102000 Multiboot header at 9500 -Module list with 1 entries at 102000 -[102000] Module: 103000 - 103038 (56 bytes) 'module.txt argument,with,commas' +Module list with 1 entries at 104000 +[104000] Module: 105000 - 105038 (56 bytes) 'module.txt argument,with,commas' Content: 'This is a test file that is used as a multiboot module.'
@@ -39,10 +39,10 @@ Module list with 1 entries at 102000 Multiboot header at 9500 -Module list with 3 entries at 102000 -[102000] Module: 103000 - 103038 (56 bytes) 'module.txt' +Module list with 3 entries at 104000 +[104000] Module: 105000 - 105038 (56 bytes) 'module.txt' Content: 'This is a test file that is used as a multiboot module.' -[102010] Module: 104000 - 104038 (56 bytes) 'module.txt argument' +[104010] Module: 106000 - 106038 (56 bytes) 'module.txt argument' Content: 'This is a test file that is used as a multiboot module.' -[102020] Module: 105000 - 105038 (56 bytes) 'module.txt' +[104020] Module: 107000 - 107038 (56 bytes) 'module.txt' Content: 'This is a test file that is used as a multiboot module.'
tests/multiboot/run_test.sh +5 -1
@@ -56,9 +56,13 @@ modules() { run_qemu modules.elf -initrd "module.txt,module.txt argument,module.txt" } +sections() { + run_qemu sections.elf +} + make all -for t in mmap modules; do +for t in mmap modules sections; do echo > test.log $t
tests/multiboot/sections.c new file +57 -0
57 lines not on this page · raw message
tests/multiboot/start.S +1 -1
@@ -23,7 +23,7 @@ .section multiboot #define MB_MAGIC 0x1badb002 -#define MB_FLAGS 0x0 +#define MB_FLAGS 0x2 #define MB_CHECKSUM -(MB_MAGIC + MB_FLAGS) .align 4
Signature · 1 line
2.16.0.rc1.238.g530d649a79-goog
Re: [Qemu-devel] [PATCH 2/4] multiboot: load elf sections and section headers
Hi Anatol.
I have one comment about sections.c headers (and didn't really look further in that file), and start.S.
Comments inline...
Quoted 23 lines · Anatol Pomozov
Multiboot may load section headers and all sections (even those that are not part of any segment) to target memory.
Tested with an ELF application that uses data from strings table section.
Signed-off-by Anatol Pomozov <[email protected]>--- hw/core/loader.c | 8 +-- hw/i386/multiboot.c | 17 +++-- hw/s390x/ipl.c | 2 +- include/hw/elf_ops.h | 110 +++++++++++++++++++++++++++++-- include/hw/loader.h | 11 +++- tests/multiboot/Makefile | 8 ++- tests/multiboot/generate_sections_out.py | 33 ++++++++++ tests/multiboot/modules.out | 22 +++---- tests/multiboot/run_test.sh | 6 +- tests/multiboot/sections.c | 57 ++++++++++++++++ tests/multiboot/start.S | 2 +- 11 files changed, 248 insertions(+), 28 deletions(-)create mode 100755
tests/multiboot/generate_sections_out.pycreate mode 100644tests/multiboot/sections.c
<snip>
Quoted 20 lines
tests/multiboot/sections.c new file +14
-0@@ -0,0 +1,57 @@ +/* +* Copyright (c) 2017 Anatol Pomozov <[email protected]> +* +* 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
tests/multiboot/sections.c line 24
Quoted 10 lines
tests/multiboot/sections.c new file +10
-0+* 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. +*/ + +#include "libc.h" +#include "../../hw/i386/multiboot_header.h"
As like the first patch, I suggest creating a "multiboot" subdir in the "include" subtree and putting all multiboot header files there. Including "multiboot/multiboot_header.h" would be cleaner.
Quoted 38 lines
tests/multiboot/sections.c new file +33
-0+#include "../../include/elf.h" + +int test_main (uint32_t magic,struct multiboot_info *mbi) +{ +void *p; +unsigned int i; + + (void ) magic; +multiboot_elf_section_header_table_t shdr; + +printf ("Multiboot header at %x, ELF section headers %s\n\n" , mbi, + mbi->flags &MULTIBOOT_INFO_ELF_SHDR ?"present" :"doesn't present" ); + + shdr = mbi->u.elf_sec; +printf ("Sections list with %d entries of size %d at %x, string index %d\n" , + shdr.num, shdr.size, shdr.addr, shdr.shndx); + +const char *string_table = (char *)((Elf32_Shdr *)(uintptr_t )(shdr.addr + + shdr.shndx * shdr.size))->sh_addr; + +for (i =0 , p = (void *)shdr.addr; + i < shdr.num; + i++, p += shdr.size) + { +Elf32_Shdr *sec; + + sec = (Elf32_Shdr *)p; +printf ("Elf section name=%s addr=%lx size=%ld\n" , + string_table + sec->sh_name, sec->sh_addr, sec->sh_size); + } + +return 0 ; +}tests/multiboot/start.S +0
-0
tests/multiboot/start.S line 27
Quoted 6 lines
tests/multiboot/start.S +1
-1@@ -23,7 +23,7 @@ .section multiboot #define MB_MAGIC 0x1badb002 -#define MB_FLAGS 0x0 +#define MB_FLAGS 0x2 #define MB_CHECKSUM -(MB_MAGIC + MB_FLAGS)
C headers can be included in assembly files. Since you are bringing over multiboot_header.h, why not include it and use its values instead of re-defining them here?
Thanks,
Jack
Quoted 2 lines
tests/multiboot/start.S +0
-0.align 4
PATCH 3/4 multiboot: make tests work with clang
In reply to Anatol Pomozov * clang 3.8 enables SSE even for 32bit code. Generate code for pentium CPU to make sure no new instructions are used.
* add memset() implementation. Clang implements array zeroing in print_num() via memset() function call.
--- tests/multiboot/Makefile | 2 +- tests/multiboot/libc.c | 9 +++++++++ tests/multiboot/libc.h | 2 ++ tests/multiboot/run_test.sh | 1 + 4 files changed, 13 insertions(+), 1 deletion(-)
tests/multiboot/Makefile +1 -1
@@ -1,5 +1,5 @@ CC=gcc -CCFLAGS=-m32 -Wall -Wextra -Werror -fno-stack-protector -nostdinc -fno-builtin +CCFLAGS=-m32 -Wall -Wextra -Werror -fno-stack-protector -nostdinc -fno-builtin -march=pentium ASFLAGS=-m32 LD=ld
tests/multiboot/libc.c +9 -0
@@ -33,6 +33,15 @@ void* memcpy(void *dest, const void *src, int n)return dest; } +void *memset (void *s,int c,size_t n) +{ +size_t i; +char *d = s; +for (i =0 ; i < n; i++) { + *d++ = c; + } +return s; +}static void print_char (char c) {
tests/multiboot/libc.h +2 -0
@@ -36,6 +36,7 @@ typedef signed short int16_t;typedef signed char int8_t ;typedef uint32_t uintptr_t ; +typedef uint32_t size_t ;/* stdarg.h */
@@ -58,5 +59,6 @@ static inline void outb(uint16_t port, uint8_t data)void printf (const char *fmt, ...);void *memcpy (void *dest,const void *src,int n); +void *memset (void *s,int c,size_t n);#endif
tests/multiboot/run_test.sh +1 -0
@@ -29,6 +29,7 @@ run_qemu() { printf %b "\n\n=== Running test case: $kernel $* ===\n\n" >> test.log $QEMU \ + -cpu pentium \ -kernel $kernel \ -display none \ -device isa-debugcon,chardev=stdio \
Signature · 1 line
2.16.0.rc1.238.g530d649a79-goog
PATCH 4/4 multiboot: Make elf64 loading functionality compatible with GRUB
In reply to Anatol PomozovGRUB is a reference multiboot implementation and supports loading elf64 binaries. Make QEMU to work similar was as GRUB.
--- hw/i386/multiboot.c | 5 ----- 1 file changed, 5 deletions(-)
hw/i386/multiboot.c +0 -5
@@ -168,11 +168,6 @@ int load_multiboot(FWCfgState *fw_cfg,int kernel_size;fclose (f); -if (((struct elf64_hdr *)header)->e_machine ==EM_X86_64 ) { -fprintf (stderr,"Cannot load x86-64 image, give a 32bit one.\n" ); -exit (1 ); - } - kernel_size =load_elf_ram (kernel_filename,NULL ,NULL , &elf_entry, &elf_low, &elf_high,0 ,I386_ELF_MACHINE ,0 ,0 ,NULL , true, §ions);
Signature · 1 line
2.16.0.rc1.238.g530d649a79-goog
Hi Anatol and Kevin.
Even though I am new to Qemu, I have a patch to deliver for multiboot.c (as you know) and so I feel familiar enough to do a review of this patch. One comment is probably more for maintainers.
Comments inline...
Quoted 179 lines · Anatol Pomozov
Using C structs makes the code more readable and prevents type conversion errors.
Borrow multiboot1 header from GRUB project.
Signed-off-by Anatol Pomozov <[email protected]>--- hw/i386/multiboot.c | 124 +++++++++------------ hw/i386/multiboot_header.h | 254 ++++++++++++++++++++++++++++++++++++++++++++ tests/multiboot/mmap.c | 14 +-- tests/multiboot/mmap.out | 10 ++ tests/multiboot/modules.c | 12 ++- tests/multiboot/modules.out | 10 ++ tests/multiboot/multiboot.h | 66 ------------ 7 files changed, 339 insertions(+), 151 deletions(-)create mode 100644
hw/i386/multiboot_header.h
delete mode 100644tests/multiboot/multiboot.hhw/i386/multiboot.c +29
-54@@ -28,6 +28,7 @@#include "hw/hw.h" #include "hw/nvram/fw_cfg.h" #include "multiboot.h" +#include "multiboot_header.h" #include "hw/loader.h" #include "elf.h" #include "sysemu/sysemu.h" @@ -47,39 +48,9 @@#error multiboot struct needs to fit in 16 bit real mode#endif -enum { -/* Multiboot info */ -MBI_FLAGS =0 , -MBI_MEM_LOWER =4 , -MBI_MEM_UPPER =8 , -MBI_BOOT_DEVICE =12 , -MBI_CMDLINE =16 , -MBI_MODS_COUNT =20 , -MBI_MODS_ADDR =24 , -MBI_MMAP_ADDR =48 , -MBI_BOOTLOADER =64 , - -MBI_SIZE =88 , - -/* Multiboot modules */ -MB_MOD_START =0 , -MB_MOD_END =4 , -MB_MOD_CMDLINE =8 , - -MB_MOD_SIZE =16 , - -/* Region offsets */ -ADDR_E820_MAP =MULTIBOOT_STRUCT_ADDR +0 , -ADDR_MBI =ADDR_E820_MAP +0x500 , - -/* Multiboot flags */ -MULTIBOOT_FLAGS_MEMORY =1 <<0 , -MULTIBOOT_FLAGS_BOOT_DEVICE =1 <<1 , -MULTIBOOT_FLAGS_CMDLINE =1 <<2 , -MULTIBOOT_FLAGS_MODULES =1 <<3 , -MULTIBOOT_FLAGS_MMAP =1 <<6 , -MULTIBOOT_FLAGS_BOOTLOADER =1 <<9 , -}; +/* Region offsets */ +#define ADDR_E820_MAP MULTIBOOT_STRUCT_ADDR +#define ADDR_MBI (ADDR_E820_MAP + 0x500) typedef struct { /* buffer holding kernel, cmdlines and mb_infos */@@ -128,14 +99,15 @@ static void mb_add_mod(MultibootState *s, hwaddr start, hwaddr end, hwaddr cmdline_phys) { - char *p; + multiboot_module_t *mod;assert (s->mb_mods_count < s->mb_mods_avail); - p = (char *)s->mb_buf + s->offset_mbinfo +MB_MOD_SIZE * s->mb_mods_count; + mod = s->mb_buf + s->offset_mbinfo + +sizeof (multiboot_module_t) * s->mb_mods_count; -stl_p (p +MB_MOD_START , start); -stl_p (p +MB_MOD_END , end); -stl_p (p +MB_MOD_CMDLINE , cmdline_phys); +stl_p (&mod->mod_start, start); +stl_p (&mod->mod_end, end); +stl_p (&mod->cmdline, cmdline_phys);mb_debug ("mod%02d: " TARGET_FMT_plx" - " TARGET_FMT_plx"\n" , s->mb_mods_count, start, end);@@ -151,26 +123,29 @@ int load_multiboot(FWCfgState *fw_cfg,int kernel_file_size, uint8_t *header) { - int i, is_multiboot = 0; + int i; +bool is_multiboot = false;uint32_t flags =0 ;uint32_t mh_entry_addr;uint32_t mh_load_addr;uint32_t mb_kernel_size;MultibootState mbs; -uint8_t bootinfo[MBI_SIZE ]; +multiboot_info_t bootinfo;uint8_t *mb_bootinfo_data;uint32_t cmdline_len; +struct multiboot_header *multiboot_header;/* Ok, let's see if it is a multiboot image. The header is 12x32bit long, so the latest entry may be 8192 - 48. */ for (i =0 ; i < (8192 -48 ); i +=4 ) { -if (ldl_p (header+i) ==0x1BADB002 ) { -uint32_t checksum =ldl_p (header+i+8 ); - flags =ldl_p (header+i+4 ); + multiboot_header = (struct multiboot_header *)(header + i); +if (ldl_p (&multiboot_header->magic) ==MULTIBOOT_HEADER_MAGIC ) { +uint32_t checksum =ldl_p (&multiboot_header->checksum); + flags =ldl_p (&multiboot_header->flags); checksum += flags; - checksum += (uint32_t )0x1BADB002 ; + checksum += (uint32_t )MULTIBOOT_HEADER_MAGIC ;if (!checksum) { - is_multiboot =1 ; + is_multiboot = true;break ; } }@@ -180,13 +155,13 @@ int load_multiboot(FWCfgState *fw_cfg,return 0 ;/* no multiboot */ mb_debug ("qemu: I believe we found a multiboot image!\n" ); -memset (bootinfo,0 ,sizeof (bootinfo)); +memset (&bootinfo,0 ,sizeof (bootinfo));memset (&mbs,0 ,sizeof (mbs)); -if (flags &0x00000004 ) {/* MULTIBOOT_HEADER_HAS_VBE */ +if (flags &MULTIBOOT_VIDEO_MODE ) {fprintf (stderr,"qemu: multiboot knows VBE. we don't.\n" ); } -if (!(flags &0x00010000 )) {/* MULTIBOOT_HEADER_HAS_ADDR */ +if (!(flags &MULTIBOOT_AOUT_KLUDGE )) {uint64_t elf_entry;uint64_t elf_low, elf_high;int kernel_size;@@ -217,12 +192,12 @@ int load_multiboot(FWCfgState *fw_cfg,mb_debug ("qemu: loading multiboot-elf kernel (%#x bytes) with entry %#zx\n" , mb_kernel_size, (size_t )mh_entry_addr); }else { -/* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_ADDR. */ -uint32_t mh_header_addr =ldl_p (header+i+12 ); -uint32_t mh_load_end_addr =ldl_p (header+i+20 ); -uint32_t mh_bss_end_addr =ldl_p (header+i+24 ); +/* Valid if mh_flags sets MULTIBOOT_AOUT_KLUDGE. */ +uint32_t mh_header_addr =ldl_p (&multiboot_header->header_addr); +uint32_t mh_load_end_addr =ldl_p (&multiboot_header->load_end_addr); +uint32_t mh_bss_end_addr =ldl_p (&multiboot_header->bss_end_addr); + mh_load_addr =ldl_p (&multiboot_header->load_addr); - mh_load_addr =ldl_p (header+i+16 );if (mh_header_addr < mh_load_addr) {fprintf (stderr,"invalid mh_load_addr address\n" );exit (1 );@@ -230,7 +205,7 @@ int load_multiboot(FWCfgState *fw_cfg,uint32_t mb_kernel_text_offset = i - (mh_header_addr - mh_load_addr);uint32_t mb_load_size =0 ; - mh_entry_addr =ldl_p (header+i+28 ); + mh_entry_addr =ldl_p (&multiboot_header->entry_addr);if (mh_load_end_addr) {if (mh_bss_end_addr < mh_load_addr) {@@ -253,11 +228,11 @@ int load_multiboot(FWCfgState *fw_cfg, mb_load_size = mb_kernel_size; }
hw/i386/multiboot.c int load_multiboot(FWCfgState *fw_cfg, · line 235
Quoted 10 lines
hw/i386/multiboot.c +5
-5-/* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE. -uint32_t mh_mode_type = ldl_p(header+i+32); -uint32_t mh_width = ldl_p(header+i+36); -uint32_t mh_height = ldl_p(header+i+40); -uint32_t mh_depth = ldl_p(header+i+44); */ +/* Valid if mh_flags sets MULTIBOOT_VIDEO_MODE. +uint32_t mh_mode_type = ldl_p(&multiboot_header->mode_type); +uint32_t mh_width = ldl_p(&multiboot_header->width); +uint32_t mh_height = ldl_p(&multiboot_header->height); +uint32_t mh_depth = ldl_p(&multiboot_header->depth); */
This question is probably more for maintainers...
In the patch series I submitted, people were OK that I was going to delete these lines since they were only comments anyway. Your approach leaves these lines in and updates them even though they are comments. Which way is preferred?
Quoted 64 lines
hw/i386/multiboot.c +16
-15mb_debug ("multiboot: mh_header_addr = %#x\n" , mh_header_addr);mb_debug ("multiboot: mh_load_addr = %#x\n" , mh_load_addr);@@ -295,14 +270,15 @@ int load_multiboot(FWCfgState *fw_cfg, } mbs.mb_buf_size += cmdline_len; - mbs.mb_buf_size +=MB_MOD_SIZE * mbs.mb_mods_avail; + mbs.mb_buf_size +=sizeof (multiboot_module_t) * mbs.mb_mods_avail; mbs.mb_buf_size +=strlen (bootloader_name) +1 ; mbs.mb_buf_size =TARGET_PAGE_ALIGN (mbs.mb_buf_size);/* enlarge mb_buf to hold cmdlines, bootloader, mb-info structs */ mbs.mb_buf =g_realloc (mbs.mb_buf, mbs.mb_buf_size); - mbs.offset_cmdlines = mbs.offset_mbinfo + mbs.mb_mods_avail *MB_MOD_SIZE ; + mbs.offset_cmdlines = mbs.offset_mbinfo + + mbs.mb_mods_avail *sizeof (multiboot_module_t); mbs.offset_bootloader = mbs.offset_cmdlines + cmdline_len;if (initrd_filename) {@@ -348,22 +324,22 @@ int load_multiboot(FWCfgState *fw_cfg,char kcmdline[strlen (kernel_filename) +strlen (kernel_cmdline) +2 ];snprintf (kcmdline,sizeof (kcmdline),"%s %s" , kernel_filename, kernel_cmdline); -stl_p (bootinfo +MBI_CMDLINE ,mb_add_cmdline (&mbs, kcmdline)); +stl_p (&bootinfo.cmdline,mb_add_cmdline (&mbs, kcmdline)); -stl_p (bootinfo +MBI_BOOTLOADER ,mb_add_bootloader (&mbs, bootloader_name)); +stl_p (&bootinfo.boot_loader_name,mb_add_bootloader (&mbs, bootloader_name)); -stl_p (bootinfo +MBI_MODS_ADDR , mbs.mb_buf_phys + mbs.offset_mbinfo); -stl_p (bootinfo +MBI_MODS_COUNT , mbs.mb_mods_count);/* mods_count */ +stl_p (&bootinfo.mods_addr, mbs.mb_buf_phys + mbs.offset_mbinfo); +stl_p (&bootinfo.mods_count, mbs.mb_mods_count);/* mods_count */ /* the kernel is where we want it to be now */ -stl_p (bootinfo +MBI_FLAGS ,MULTIBOOT_FLAGS_MEMORY - |MULTIBOOT_FLAGS_BOOT_DEVICE - |MULTIBOOT_FLAGS_CMDLINE - |MULTIBOOT_FLAGS_MODULES - |MULTIBOOT_FLAGS_MMAP - |MULTIBOOT_FLAGS_BOOTLOADER ); -stl_p (bootinfo +MBI_BOOT_DEVICE ,0x8000ffff );/* XXX: use the -boot switch? */ -stl_p (bootinfo +MBI_MMAP_ADDR ,ADDR_E820_MAP ); +stl_p (&bootinfo.flags,MULTIBOOT_INFO_MEMORY + |MULTIBOOT_INFO_BOOTDEV + |MULTIBOOT_INFO_CMDLINE + |MULTIBOOT_INFO_MODS + |MULTIBOOT_INFO_MEM_MAP + |MULTIBOOT_INFO_BOOT_LOADER_NAME ); +stl_p (&bootinfo.boot_device,0x8000ffff );/* XXX: use the -boot switch? */ +stl_p (&bootinfo.mmap_addr,ADDR_E820_MAP );mb_debug ("multiboot: mh_entry_addr = %#x\n" , mh_entry_addr);mb_debug (" mb_buf_phys = " TARGET_FMT_plx"\n" , mbs.mb_buf_phys);@@ -371,7 +347,7 @@ int load_multiboot(FWCfgState *fw_cfg,mb_debug (" mb_mods_count = %d\n" , mbs.mb_mods_count);/* save bootinfo off the stack */ - mb_bootinfo_data =g_memdup (bootinfo,sizeof (bootinfo)); + mb_bootinfo_data =g_memdup (&bootinfo,sizeof (bootinfo));/* Pass variables to option rom */ fw_cfg_add_i32 (fw_cfg,FW_CFG_KERNEL_ENTRY , mh_entry_addr);
<snip>
tests/multiboot/mmap.c line 24
Quoted 10 lines
tests/multiboot/mmap.c +1
-1@@ -21,15 +21,17 @@*/ #include "libc.h" -#include "multiboot.h" +#include "../../hw/i386/multiboot_header.h"
Suggestion: create a multiboot subdir under include, and put multiboot_header.h and other multiboot includes there. This way you can just #include "multiboot/multiboot_header.h" which seems cleaner to me than "../../hw/i386/multiboot_header.h"
Quoted 29 lines
tests/multiboot/mmap.c +7
-5-int test_main (uint32_t magic,struct mb_info *mbi) +int test_main (uint32_t magic,struct multiboot_info *mbi) {uintptr_t entry_addr; -struct mb_mmap_entry *entry; +struct multiboot_mmap_entry *entry; (void ) magic; +printf ("Multiboot header at %x\n\n" , mbi); +printf ("Lower memory: %dk\n" , mbi->mem_lower);printf ("Upper memory: %dk\n" , mbi->mem_upper);@@ -39,11 +41,11 @@ int test_main(uint32_t magic, struct mb_info *mbi) entry_addr < mbi->mmap_addr + mbi->mmap_length; entry_addr += entry->size + 4) { - entry = (struct mb_mmap_entry *) entry_addr; + entry = (struct multiboot_mmap_entry *) entry_addr;printf ("%#llx - %#llx: type %d [entry size: %d]\n" , - entry->base_addr, - entry->base_addr + entry->length, + entry->addr, + entry->addr + entry->len, entry->type, entry->size); }
<snip>
tests/multiboot/modules.c line 24
Quoted 11 lines
tests/multiboot/modules.c +1
-1@@ -21,19 +21,21 @@*/ #include "libc.h" -#include "multiboot.h" +#include "../../hw/i386/multiboot_header.h"
Same comment about putting multiboot_header.h into a multiboot subdir in "include" subtree.
I have this same comment, as well as one other, for patch 2 sent separately.
Thanks,
Jack
Quoted 29 lines
tests/multiboot/modules.c +6
-4-int test_main (uint32_t magic,struct mb_info *mbi) +int test_main (uint32_t magic,struct multiboot_info *mbi) { -struct mb_module *mod; +struct multiboot_mod_list *mod;unsigned int i; (void ) magic; +printf ("Multiboot header at %x\n\n" , mbi); +printf ("Module list with %d entries at %x\n" , mbi->mods_count, mbi->mods_addr); -for (i =0 , mod = (struct mb_module *) mbi->mods_addr; +for (i =0 , mod = (struct multiboot_mod_list *) mbi->mods_addr; i < mbi->mods_count; i++, mod++) {@@ -41,7 +43,7 @@ int test_main(uint32_t magic, struct mb_info *mbi)unsigned int size = mod->mod_end - mod->mod_start;printf ("[%p] Module: %x - %x (%d bytes) '%s'\n" , - mod, mod->mod_start, mod->mod_end, size, mod->string); + mod, mod->mod_start, mod->mod_end, size, mod->cmdline);/* Print test file, but remove the newline at the end */ if (size <sizeof (buf)) {
<snip>
Am 31.01.2018 um 00:15 hat Jack Schwartz geschrieben:
Quoted 5 lines
Hi Anatol and Kevin.
Even though I am new to Qemu, I have a patch to deliver for
multiboot.c(as you know) and so I feel familiar enough to do a review of this patch. One comment is probably more for maintainers.
The Multiboot code is essentially unmaintained. It's technically part of the PC/x86 subsystem, but their maintainers don't seem to care at all. So in order to make any progress here, I decided that I will send a pull request for Multiboot once we have the patches ready (as a one-time thing, without officially making myself the maintainer).
So I am the closest thing to a maintainer that we have here, and while I'm familiar with some of the Multiboot-specific code, I don't really know the ELF code and don't have a lot of time to spend here.
Therefore it's very welcome if you review the patches of each other, even if you're not perfectly familiar with the code, as there is probably noone else who could do a better review.
Quoted 16 lines · Anatol Pomozov
hw/i386/multiboot.c int load_multiboot(FWCfgState *fw_cfg, · line 234
Quoted 13 lines
hw/i386/multiboot.c +5
-5@@ -253,11 +228,11 @@ int load_multiboot(FWCfgState *fw_cfg, mb_load_size = mb_kernel_size; } -/* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE. -uint32_t mh_mode_type = ldl_p(header+i+32); -uint32_t mh_width = ldl_p(header+i+36); -uint32_t mh_height = ldl_p(header+i+40); -uint32_t mh_depth = ldl_p(header+i+44); */ +/* Valid if mh_flags sets MULTIBOOT_VIDEO_MODE. +uint32_t mh_mode_type = ldl_p(&multiboot_header->mode_type); +uint32_t mh_width = ldl_p(&multiboot_header->width); +uint32_t mh_height = ldl_p(&multiboot_header->height); +uint32_t mh_depth = ldl_p(&multiboot_header->depth); */ This question is probably more for maintainers...
Quoted 4 lines
In the patch series I submitted, people were OK that I was going to delete these lines since they were only comments anyway. Your approach leaves these lines in and updates them even though they are comments. Which way is preferred?
As far as I am concerned, I honestly don't mind either way. It's trivial code, so we won't lose anything by removing it.
The ideal solution would be just implementing support for it, of course. If we wanted to do that, I think we would have to pass the values through fw_cfg and then set the VBE mode in the Mutiboot option rom.
Quoted 55 lines
Quoted 54 lines
hw/i386/multiboot.c +16
-15mb_debug ("multiboot: mh_header_addr = %#x\n" , mh_header_addr);mb_debug ("multiboot: mh_load_addr = %#x\n" , mh_load_addr);@@ -295,14 +270,15 @@ int load_multiboot(FWCfgState *fw_cfg, } mbs.mb_buf_size += cmdline_len; - mbs.mb_buf_size +=MB_MOD_SIZE * mbs.mb_mods_avail; + mbs.mb_buf_size +=sizeof (multiboot_module_t) * mbs.mb_mods_avail; mbs.mb_buf_size +=strlen (bootloader_name) +1 ; mbs.mb_buf_size =TARGET_PAGE_ALIGN (mbs.mb_buf_size);/* enlarge mb_buf to hold cmdlines, bootloader, mb-info structs */ mbs.mb_buf =g_realloc (mbs.mb_buf, mbs.mb_buf_size); - mbs.offset_cmdlines = mbs.offset_mbinfo + mbs.mb_mods_avail *MB_MOD_SIZE ; + mbs.offset_cmdlines = mbs.offset_mbinfo + + mbs.mb_mods_avail *sizeof (multiboot_module_t); mbs.offset_bootloader = mbs.offset_cmdlines + cmdline_len;if (initrd_filename) {@@ -348,22 +324,22 @@ int load_multiboot(FWCfgState *fw_cfg,char kcmdline[strlen (kernel_filename) +strlen (kernel_cmdline) +2 ];snprintf (kcmdline,sizeof (kcmdline),"%s %s" , kernel_filename, kernel_cmdline); -stl_p (bootinfo +MBI_CMDLINE ,mb_add_cmdline (&mbs, kcmdline)); +stl_p (&bootinfo.cmdline,mb_add_cmdline (&mbs, kcmdline)); -stl_p (bootinfo +MBI_BOOTLOADER ,mb_add_bootloader (&mbs, bootloader_name)); +stl_p (&bootinfo.boot_loader_name,mb_add_bootloader (&mbs, bootloader_name)); -stl_p (bootinfo +MBI_MODS_ADDR , mbs.mb_buf_phys + mbs.offset_mbinfo); -stl_p (bootinfo +MBI_MODS_COUNT , mbs.mb_mods_count);/* mods_count */ +stl_p (&bootinfo.mods_addr, mbs.mb_buf_phys + mbs.offset_mbinfo); +stl_p (&bootinfo.mods_count, mbs.mb_mods_count);/* mods_count */ /* the kernel is where we want it to be now */ -stl_p (bootinfo +MBI_FLAGS ,MULTIBOOT_FLAGS_MEMORY - |MULTIBOOT_FLAGS_BOOT_DEVICE - |MULTIBOOT_FLAGS_CMDLINE - |MULTIBOOT_FLAGS_MODULES - |MULTIBOOT_FLAGS_MMAP - |MULTIBOOT_FLAGS_BOOTLOADER ); -stl_p (bootinfo +MBI_BOOT_DEVICE ,0x8000ffff );/* XXX: use the -boot switch? */ -stl_p (bootinfo +MBI_MMAP_ADDR ,ADDR_E820_MAP ); +stl_p (&bootinfo.flags,MULTIBOOT_INFO_MEMORY + |MULTIBOOT_INFO_BOOTDEV + |MULTIBOOT_INFO_CMDLINE + |MULTIBOOT_INFO_MODS + |MULTIBOOT_INFO_MEM_MAP + |MULTIBOOT_INFO_BOOT_LOADER_NAME ); +stl_p (&bootinfo.boot_device,0x8000ffff );/* XXX: use the -boot switch? */ +stl_p (&bootinfo.mmap_addr,ADDR_E820_MAP );mb_debug ("multiboot: mh_entry_addr = %#x\n" , mh_entry_addr);mb_debug (" mb_buf_phys = " TARGET_FMT_plx"\n" , mbs.mb_buf_phys);@@ -371,7 +347,7 @@ int load_multiboot(FWCfgState *fw_cfg,mb_debug (" mb_mods_count = %d\n" , mbs.mb_mods_count);/* save bootinfo off the stack */ - mb_bootinfo_data =g_memdup (bootinfo,sizeof (bootinfo)); + mb_bootinfo_data =g_memdup (&bootinfo,sizeof (bootinfo));/* Pass variables to option rom */ fw_cfg_add_i32 (fw_cfg,FW_CFG_KERNEL_ENTRY , mh_entry_addr);<snip>
Quoted 13 lines
tests/multiboot/mmap.c line 23
Quoted 9 lines
tests/multiboot/mmap.c +1
-1@@ -21,15 +21,17 @@*/ #include "libc.h" -#include "multiboot.h" +#include "../../hw/i386/multiboot_header.h" Suggestion: create a multiboot subdir under include, and put
multiboot_header.hand other multiboot includes there. This way you can just #include "multiboot/multiboot_header.h" which seems cleaner to me than "../../hw/i386/multiboot_header.h"
Good point, but do we even have multiple header files for Multiboot to justify a whole subdirectory?
There is include/hw/loader.h and include/elf.h, so I would suggest that we add the new header as either include/hw/multiboot.h or directly include/multiboot.h.
Kevin
Hi
Quoted 37 lines · Kevin Wolf
Am 31.01.2018 um 00:15 hat Jack Schwartz geschrieben:
Quoted 5 lines
Hi Anatol and Kevin.
Even though I am new to Qemu, I have a patch to deliver for
multiboot.c(as you know) and so I feel familiar enough to do a review of this patch. One comment is probably more for maintainers.The Multiboot code is essentially unmaintained. It's technically part of the PC/x86 subsystem, but their maintainers don't seem to care at all. So in order to make any progress here, I decided that I will send a pull request for Multiboot once we have the patches ready (as a one-time thing, without officially making myself the maintainer).
So I am the closest thing to a maintainer that we have here, and while I'm familiar with some of the Multiboot-specific code, I don't really know the ELF code and don't have a lot of time to spend here.
Therefore it's very welcome if you review the patches of each other, even if you're not perfectly familiar with the code, as there is probably noone else who could do a better review.
Quoted 16 lines · Anatol Pomozov
hw/i386/multiboot.c int load_multiboot(FWCfgState *fw_cfg, · line 234
Quoted 13 lines
hw/i386/multiboot.c +5
-5@@ -253,11 +228,11 @@ int load_multiboot(FWCfgState *fw_cfg, mb_load_size = mb_kernel_size; } -/* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE. -uint32_t mh_mode_type = ldl_p(header+i+32); -uint32_t mh_width = ldl_p(header+i+36); -uint32_t mh_height = ldl_p(header+i+40); -uint32_t mh_depth = ldl_p(header+i+44); */ +/* Valid if mh_flags sets MULTIBOOT_VIDEO_MODE. +uint32_t mh_mode_type = ldl_p(&multiboot_header->mode_type); +uint32_t mh_width = ldl_p(&multiboot_header->width); +uint32_t mh_height = ldl_p(&multiboot_header->height); +uint32_t mh_depth = ldl_p(&multiboot_header->depth); */ This question is probably more for maintainers...
Quoted 7 lines
Quoted 4 lines
In the patch series I submitted, people were OK that I was going to delete these lines since they were only comments anyway. Your approach leaves these lines in and updates them even though they are comments. Which way is preferred?
As far as I am concerned, I honestly don't mind either way. It's trivial code, so we won't lose anything by removing it.
This change suppose to be a refactoring and tries to avoid functional changes. I can remove it in a separate change.
Quoted 74 lines
The ideal solution would be just implementing support for it, of course. If we wanted to do that, I think we would have to pass the values through
fw_cfgand then set the VBE mode in the Mutiboot option rom.Quoted 55 lines
Quoted 54 lines
hw/i386/multiboot.c +16
-15mb_debug ("multiboot: mh_header_addr = %#x\n" , mh_header_addr);mb_debug ("multiboot: mh_load_addr = %#x\n" , mh_load_addr);@@ -295,14 +270,15 @@ int load_multiboot(FWCfgState *fw_cfg, } mbs.mb_buf_size += cmdline_len; - mbs.mb_buf_size +=MB_MOD_SIZE * mbs.mb_mods_avail; + mbs.mb_buf_size +=sizeof (multiboot_module_t) * mbs.mb_mods_avail; mbs.mb_buf_size +=strlen (bootloader_name) +1 ; mbs.mb_buf_size =TARGET_PAGE_ALIGN (mbs.mb_buf_size);/* enlarge mb_buf to hold cmdlines, bootloader, mb-info structs */ mbs.mb_buf =g_realloc (mbs.mb_buf, mbs.mb_buf_size); - mbs.offset_cmdlines = mbs.offset_mbinfo + mbs.mb_mods_avail *MB_MOD_SIZE ; + mbs.offset_cmdlines = mbs.offset_mbinfo + + mbs.mb_mods_avail *sizeof (multiboot_module_t); mbs.offset_bootloader = mbs.offset_cmdlines + cmdline_len;if (initrd_filename) {@@ -348,22 +324,22 @@ int load_multiboot(FWCfgState *fw_cfg,char kcmdline[strlen (kernel_filename) +strlen (kernel_cmdline) +2 ];snprintf (kcmdline,sizeof (kcmdline),"%s %s" , kernel_filename, kernel_cmdline); -stl_p (bootinfo +MBI_CMDLINE ,mb_add_cmdline (&mbs, kcmdline)); +stl_p (&bootinfo.cmdline,mb_add_cmdline (&mbs, kcmdline)); -stl_p (bootinfo +MBI_BOOTLOADER ,mb_add_bootloader (&mbs, bootloader_name)); +stl_p (&bootinfo.boot_loader_name,mb_add_bootloader (&mbs, bootloader_name)); -stl_p (bootinfo +MBI_MODS_ADDR , mbs.mb_buf_phys + mbs.offset_mbinfo); -stl_p (bootinfo +MBI_MODS_COUNT , mbs.mb_mods_count);/* mods_count */ +stl_p (&bootinfo.mods_addr, mbs.mb_buf_phys + mbs.offset_mbinfo); +stl_p (&bootinfo.mods_count, mbs.mb_mods_count);/* mods_count */ /* the kernel is where we want it to be now */ -stl_p (bootinfo +MBI_FLAGS ,MULTIBOOT_FLAGS_MEMORY - |MULTIBOOT_FLAGS_BOOT_DEVICE - |MULTIBOOT_FLAGS_CMDLINE - |MULTIBOOT_FLAGS_MODULES - |MULTIBOOT_FLAGS_MMAP - |MULTIBOOT_FLAGS_BOOTLOADER ); -stl_p (bootinfo +MBI_BOOT_DEVICE ,0x8000ffff );/* XXX: use the -boot switch? */ -stl_p (bootinfo +MBI_MMAP_ADDR ,ADDR_E820_MAP ); +stl_p (&bootinfo.flags,MULTIBOOT_INFO_MEMORY + |MULTIBOOT_INFO_BOOTDEV + |MULTIBOOT_INFO_CMDLINE + |MULTIBOOT_INFO_MODS + |MULTIBOOT_INFO_MEM_MAP + |MULTIBOOT_INFO_BOOT_LOADER_NAME ); +stl_p (&bootinfo.boot_device,0x8000ffff );/* XXX: use the -boot switch? */ +stl_p (&bootinfo.mmap_addr,ADDR_E820_MAP );mb_debug ("multiboot: mh_entry_addr = %#x\n" , mh_entry_addr);mb_debug (" mb_buf_phys = " TARGET_FMT_plx"\n" , mbs.mb_buf_phys);@@ -371,7 +347,7 @@ int load_multiboot(FWCfgState *fw_cfg,mb_debug (" mb_mods_count = %d\n" , mbs.mb_mods_count);/* save bootinfo off the stack */ - mb_bootinfo_data =g_memdup (bootinfo,sizeof (bootinfo)); + mb_bootinfo_data =g_memdup (&bootinfo,sizeof (bootinfo));/* Pass variables to option rom */ fw_cfg_add_i32 (fw_cfg,FW_CFG_KERNEL_ENTRY , mh_entry_addr);<snip>
Quoted 13 lines
tests/multiboot/mmap.c line 23
Quoted 9 lines
tests/multiboot/mmap.c +1
-1@@ -21,15 +21,17 @@*/ #include "libc.h" -#include "multiboot.h" +#include "../../hw/i386/multiboot_header.h" Suggestion: create a multiboot subdir under include, and put
multiboot_header.hand other multiboot includes there. This way you can just #include "multiboot/multiboot_header.h" which seems cleaner to me than "../../hw/i386/multiboot_header.h"
Quoted 2 lines
Good point, but do we even have multiple header files for Multiboot to justify a whole subdirectory?
I do not think there is a justification for it. +1 for keeping it in "/include/"
Quoted 3 lines
There is
include/hw/loader.handinclude/elf.h, so I would suggest that we add the new header as eitherinclude/hw/multiboot.hor directlyinclude/multiboot.h.
There is already ./hw/i386/multiboot.h file so it is going to be confusing to have multiple files with the same name.
I propose to rename ./hw/i386/multiboot.h to something like ./hw/i386/multiboot_loader.h or ./hw/i386/load_multiboot.h
Hi Anatol and Kevin.
Kevin and Anatol, thanks for your replies.
A few comments inline close to the bottom...
Quoted 120 lines · Anatol Pomozov
Hi
Quoted 36 lines · Kevin Wolf
Am 31.01.2018 um 00:15 hat Jack Schwartz geschrieben:
Quoted 5 lines
Hi Anatol and Kevin.
Even though I am new to Qemu, I have a patch to deliver for
multiboot.c(as you know) and so I feel familiar enough to do a review of this patch. One comment is probably more for maintainers.The Multiboot code is essentially unmaintained. It's technically part of the PC/x86 subsystem, but their maintainers don't seem to care at all. So in order to make any progress here, I decided that I will send a pull request for Multiboot once we have the patches ready (as a one-time thing, without officially making myself the maintainer).
So I am the closest thing to a maintainer that we have here, and while I'm familiar with some of the Multiboot-specific code, I don't really know the ELF code and don't have a lot of time to spend here.
Therefore it's very welcome if you review the patches of each other, even if you're not perfectly familiar with the code, as there is probably noone else who could do a better review.
Quoted 16 lines · Anatol Pomozov
hw/i386/multiboot.c int load_multiboot(FWCfgState *fw_cfg, · line 234
Quoted 13 lines
hw/i386/multiboot.c +5
-5@@ -253,11 +228,11 @@ int load_multiboot(FWCfgState *fw_cfg, mb_load_size = mb_kernel_size; } -/* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE. -uint32_t mh_mode_type = ldl_p(header+i+32); -uint32_t mh_width = ldl_p(header+i+36); -uint32_t mh_height = ldl_p(header+i+40); -uint32_t mh_depth = ldl_p(header+i+44); */ +/* Valid if mh_flags sets MULTIBOOT_VIDEO_MODE. +uint32_t mh_mode_type = ldl_p(&multiboot_header->mode_type); +uint32_t mh_width = ldl_p(&multiboot_header->width); +uint32_t mh_height = ldl_p(&multiboot_header->height); +uint32_t mh_depth = ldl_p(&multiboot_header->depth); */ This question is probably more for maintainers...
Quoted 6 lines
Quoted 4 lines
In the patch series I submitted, people were OK that I was going to delete these lines since they were only comments anyway. Your approach leaves these lines in and updates them even though they are comments. Which way is preferred?
As far as I am concerned, I honestly don't mind either way. It's trivial code, so we won't lose anything by removing it.
This change suppose to be a refactoring and tries to avoid functional changes. I can remove it in a separate change.
Quoted 72 lines
The ideal solution would be just implementing support for it, of course. If we wanted to do that, I think we would have to pass the values through
fw_cfgand then set the VBE mode in the Mutiboot option rom.Quoted 68 lines
Quoted 54 lines
hw/i386/multiboot.c +16
-15mb_debug ("multiboot: mh_header_addr = %#x\n" , mh_header_addr);mb_debug ("multiboot: mh_load_addr = %#x\n" , mh_load_addr);@@ -295,14 +270,15 @@ int load_multiboot(FWCfgState *fw_cfg, } mbs.mb_buf_size += cmdline_len; - mbs.mb_buf_size +=MB_MOD_SIZE * mbs.mb_mods_avail; + mbs.mb_buf_size +=sizeof (multiboot_module_t) * mbs.mb_mods_avail; mbs.mb_buf_size +=strlen (bootloader_name) +1 ; mbs.mb_buf_size =TARGET_PAGE_ALIGN (mbs.mb_buf_size);/* enlarge mb_buf to hold cmdlines, bootloader, mb-info structs */ mbs.mb_buf =g_realloc (mbs.mb_buf, mbs.mb_buf_size); - mbs.offset_cmdlines = mbs.offset_mbinfo + mbs.mb_mods_avail *MB_MOD_SIZE ; + mbs.offset_cmdlines = mbs.offset_mbinfo + + mbs.mb_mods_avail *sizeof (multiboot_module_t); mbs.offset_bootloader = mbs.offset_cmdlines + cmdline_len;if (initrd_filename) {@@ -348,22 +324,22 @@ int load_multiboot(FWCfgState *fw_cfg,char kcmdline[strlen (kernel_filename) +strlen (kernel_cmdline) +2 ];snprintf (kcmdline,sizeof (kcmdline),"%s %s" , kernel_filename, kernel_cmdline); -stl_p (bootinfo +MBI_CMDLINE ,mb_add_cmdline (&mbs, kcmdline)); +stl_p (&bootinfo.cmdline,mb_add_cmdline (&mbs, kcmdline)); -stl_p (bootinfo +MBI_BOOTLOADER ,mb_add_bootloader (&mbs, bootloader_name)); +stl_p (&bootinfo.boot_loader_name,mb_add_bootloader (&mbs, bootloader_name)); -stl_p (bootinfo +MBI_MODS_ADDR , mbs.mb_buf_phys + mbs.offset_mbinfo); -stl_p (bootinfo +MBI_MODS_COUNT , mbs.mb_mods_count);/* mods_count */ +stl_p (&bootinfo.mods_addr, mbs.mb_buf_phys + mbs.offset_mbinfo); +stl_p (&bootinfo.mods_count, mbs.mb_mods_count);/* mods_count */ /* the kernel is where we want it to be now */ -stl_p (bootinfo +MBI_FLAGS ,MULTIBOOT_FLAGS_MEMORY - |MULTIBOOT_FLAGS_BOOT_DEVICE - |MULTIBOOT_FLAGS_CMDLINE - |MULTIBOOT_FLAGS_MODULES - |MULTIBOOT_FLAGS_MMAP - |MULTIBOOT_FLAGS_BOOTLOADER ); -stl_p (bootinfo +MBI_BOOT_DEVICE ,0x8000ffff );/* XXX: use the -boot switch? */ -stl_p (bootinfo +MBI_MMAP_ADDR ,ADDR_E820_MAP ); +stl_p (&bootinfo.flags,MULTIBOOT_INFO_MEMORY + |MULTIBOOT_INFO_BOOTDEV + |MULTIBOOT_INFO_CMDLINE + |MULTIBOOT_INFO_MODS + |MULTIBOOT_INFO_MEM_MAP + |MULTIBOOT_INFO_BOOT_LOADER_NAME ); +stl_p (&bootinfo.boot_device,0x8000ffff );/* XXX: use the -boot switch? */ +stl_p (&bootinfo.mmap_addr,ADDR_E820_MAP );mb_debug ("multiboot: mh_entry_addr = %#x\n" , mh_entry_addr);mb_debug (" mb_buf_phys = " TARGET_FMT_plx"\n" , mbs.mb_buf_phys);@@ -371,7 +347,7 @@ int load_multiboot(FWCfgState *fw_cfg,mb_debug (" mb_mods_count = %d\n" , mbs.mb_mods_count);/* save bootinfo off the stack */ - mb_bootinfo_data =g_memdup (bootinfo,sizeof (bootinfo)); + mb_bootinfo_data =g_memdup (&bootinfo,sizeof (bootinfo));/* Pass variables to option rom */ fw_cfg_add_i32 (fw_cfg,FW_CFG_KERNEL_ENTRY , mh_entry_addr);<snip>
tests/multiboot/mmap.c line 23
Quoted 9 lines
tests/multiboot/mmap.c +1
-1@@ -21,15 +21,17 @@*/ #include "libc.h" -#include "multiboot.h" +#include "../../hw/i386/multiboot_header.h" Suggestion: create a multiboot subdir under include, and put
multiboot_header.hand other multiboot includes there. This way you can just #include "multiboot/multiboot_header.h" which seems cleaner to me than "../../hw/i386/multiboot_header.h"
Quoted 6 lines
Quoted 2 lines
Good point, but do we even have multiple header files for Multiboot to justify a whole subdirectory?
I do not think there is a justification for it. +1 for keeping it in "/include/"
Quoted 3 lines
There is
include/hw/loader.handinclude/elf.h, so I would suggest that we add the new header as eitherinclude/hw/multiboot.hor directlyinclude/multiboot.h.
OK. This makes the include list cleaner without having to add another subdirectory.
... or put both multiboot header files under include/hw/i386 to keep them together in an existing, appropriate and more specific directory.
Quoted 5 lines
Quoted 5 lines
There is already
./hw/i386/multiboot.hfile so it is going to be confusing to have multiple files with the same name.I propose to rename
./hw/i386/multiboot.hto something like./hw/i386/multiboot_loader.hor./hw/i386/load_multiboot.h
Filename change sounds good.
Also, to avoid confusion with tests/multiboot/multiboot.h, I suggest renaming that header file to tests/multiboot/multiboot_test.h
Thanks,
Jack