multiboot: Change multiboot_info from array of bytes to a C struct
PATCH 1/1 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 | 122 ++++++++------------- hw/i386/multiboot_header.h | 265 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 313 insertions(+), 74 deletions(-) create mode 100644 hw/i386/multiboot_header.h
hw/i386/multiboot.c +48 -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,14 @@ 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 +122,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 +154,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,14 +191,14 @@ 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 ); - mh_load_addr =ldl_p (header+i+16 ); +/* 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);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) { mb_kernel_size = mh_bss_end_addr - mh_load_addr;
@@ -234,11 +208,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);
@@ -276,14 +250,14 @@ 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) {
@@ -329,22 +303,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);
@@ -353,7 +327,7 @@ int load_multiboot(FWCfgState *fw_cfg,/* save bootinfo off the stack */ mb_bootinfo_data =g_malloc (sizeof (bootinfo)); -memcpy (mb_bootinfo_data, bootinfo,sizeof (bootinfo)); +memcpy (mb_bootinfo_data, &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 +265 -0
265 lines not on this page · raw message
Signature · 1 line
2.14.0.rc0.400.g1c36432dff-goog
This series seems to have some coding style problems. See output below for more information:
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Subject: [Qemu-devel] [PATCH] multiboot: Change multiboot_info from array of bytes to a C struct
Message-id: [email protected]
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
git config --local diff.renamelimit 0
git config --local diff.renames True
commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
202968a multiboot: Change multiboot_info from array of bytes to a C struct
=== OUTPUT BEGIN ===
Checking PATCH 1/1: multiboot: Change multiboot_info from array of bytes to a C struct...
WARNING: line over 80 characters
#77: FILE: hw/i386/multiboot.c:105:
+ mod = s->mb_buf + s->offset_mbinfo + sizeof(multiboot_module_t) * s->mb_mods_count;
ERROR: line over 90 characters
#193: FILE: hw/i386/multiboot.c:260:
+ mbs.offset_cmdlines = mbs.offset_mbinfo + mbs.mb_mods_avail * sizeof(multiboot_module_t);
WARNING: line over 80 characters
#263: FILE: hw/i386/multiboot_header.h:17:
+ * DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WARNING: line over 80 characters
#265: FILE: hw/i386/multiboot_header.h:19:
+ * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ERROR: code indent should never use tabs
#272: FILE: hw/i386/multiboot_header.h:26:
+#define MULTIBOOT_SEARCH^I^I^I8192$
ERROR: code indent should never use tabs
#273: FILE: hw/i386/multiboot_header.h:27:
+#define MULTIBOOT_HEADER_ALIGN^I^I^I4$
ERROR: code indent should never use tabs
#276: FILE: hw/i386/multiboot_header.h:30:
+#define MULTIBOOT_HEADER_MAGIC^I^I^I0x1BADB002$
ERROR: code indent should never use tabs #279: FILE: hw/i386/multiboot_header.h:33:
+#define MULTIBOOT_BOOTLOADER_MAGIC^I^I0x2BADB002$
ERROR: code indent should never use tabs
#282: FILE: hw/i386/multiboot_header.h:36:
+#define MULTIBOOT_MOD_ALIGN^I^I^I0x00001000$
ERROR: code indent should never use tabs
#285: FILE: hw/i386/multiboot_header.h:39:
+#define MULTIBOOT_INFO_ALIGN^I^I^I0x00000004$
ERROR: code indent should never use tabs
#290: FILE: hw/i386/multiboot_header.h:44:
+#define MULTIBOOT_PAGE_ALIGN^I^I^I0x00000001$
ERROR: code indent should never use tabs
#293: FILE: hw/i386/multiboot_header.h:47:
+#define MULTIBOOT_MEMORY_INFO^I^I^I0x00000002$
ERROR: code indent should never use tabs
#296: FILE: hw/i386/multiboot_header.h:50:
+#define MULTIBOOT_VIDEO_MODE^I^I^I0x00000004$
ERROR: code indent should never use tabs
#299: FILE: hw/i386/multiboot_header.h:53:
+#define MULTIBOOT_AOUT_KLUDGE^I^I^I0x00010000$
ERROR: code indent should never use tabs
#304: FILE: hw/i386/multiboot_header.h:58:
+#define MULTIBOOT_INFO_MEMORY^I^I^I0x00000001$
ERROR: code indent should never use tabs
#306: FILE: hw/i386/multiboot_header.h:60:
+#define MULTIBOOT_INFO_BOOTDEV^I^I^I0x00000002$
ERROR: code indent should never use tabs
#308: FILE: hw/i386/multiboot_header.h:62:
+#define MULTIBOOT_INFO_CMDLINE^I^I^I0x00000004$
ERROR: code indent should never use tabs
#310: FILE: hw/i386/multiboot_header.h:64:
+#define MULTIBOOT_INFO_MODS^I^I^I0x00000008$
ERROR: code indent should never use tabs
#315: FILE: hw/i386/multiboot_header.h:69:
+#define MULTIBOOT_INFO_AOUT_SYMS^I^I0x00000010$
ERROR: code indent should never use tabs
#317: FILE: hw/i386/multiboot_header.h:71:
+#define MULTIBOOT_INFO_ELF_SHDR^I^I^I0X00000020$
ERROR: code indent should never use tabs
#320: FILE: hw/i386/multiboot_header.h:74:
+#define MULTIBOOT_INFO_MEM_MAP^I^I^I0x00000040$
ERROR: code indent should never use tabs
#323: FILE: hw/i386/multiboot_header.h:77:
+#define MULTIBOOT_INFO_DRIVE_INFO^I^I0x00000080$
ERROR: code indent should never use tabs #326: FILE: hw/i386/multiboot_header.h:80:
+#define MULTIBOOT_INFO_CONFIG_TABLE^I^I0x00000100$
ERROR: code indent should never use tabs
#329: FILE: hw/i386/multiboot_header.h:83:
+#define MULTIBOOT_INFO_BOOT_LOADER_NAME^I^I0x00000200$
ERROR: code indent should never use tabs
#332: FILE: hw/i386/multiboot_header.h:86:
+#define MULTIBOOT_INFO_APM_TABLE^I^I0x00000400$
ERROR: code indent should never use tabs
#335: FILE: hw/i386/multiboot_header.h:89:
+#define MULTIBOOT_INFO_VBE_INFO^I^I 0x00000800$
ERROR: code indent should never use tabs
#336: FILE: hw/i386/multiboot_header.h:90:
+#define MULTIBOOT_INFO_FRAMEBUFFER_INFO^I 0x00001000$
ERROR: open brace '{' following struct go on the same line #339: FILE: hw/i386/multiboot_header.h:93:
+struct multiboot_header
+{
ERROR: open brace '{' following struct go on the same line #365: FILE: hw/i386/multiboot_header.h:119:
+struct multiboot_aout_symbol_table
+{
ERROR: open brace '{' following struct go on the same line #375: FILE: hw/i386/multiboot_header.h:129:
+struct multiboot_elf_section_header_table
+{
WARNING: line over 80 characters
#381: FILE: hw/i386/multiboot_header.h:135:
+typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t;
ERROR: open brace '{' following struct go on the same line #384: FILE: hw/i386/multiboot_header.h:138:
+struct multiboot_info
+{
ERROR: open brace '{' following union go on the same line #403: FILE: hw/i386/multiboot_header.h:157:
+ union
+ {
ERROR: code indent should never use tabs
#440: FILE: hw/i386/multiboot_header.h:194:
+#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT^I2$
ERROR: open brace '{' following union go on the same line #443: FILE: hw/i386/multiboot_header.h:197:
+ union
+ {
ERROR: open brace '{' following struct go on the same line #445: FILE: hw/i386/multiboot_header.h:199:
+ struct
+ {
ERROR: open brace '{' following struct go on the same line #450: FILE: hw/i386/multiboot_header.h:204:
+ struct
+ {
ERROR: open brace '{' following struct go on the same line #463: FILE: hw/i386/multiboot_header.h:217:
+struct multiboot_color
+{
ERROR: open brace '{' following struct go on the same line #470: FILE: hw/i386/multiboot_header.h:224:
+struct multiboot_mmap_entry
+{
ERROR: code indent should never use tabs
#474: FILE: hw/i386/multiboot_header.h:228:
+#define MULTIBOOT_MEMORY_AVAILABLE^I^I1$
ERROR: code indent should never use tabs
#475: FILE: hw/i386/multiboot_header.h:229:
+#define MULTIBOOT_MEMORY_RESERVED^I^I2$
ERROR: open brace '{' following struct go on the same line #484: FILE: hw/i386/multiboot_header.h:238:
+struct multiboot_mod_list
+{
ERROR: open brace '{' following struct go on the same line #499: FILE: hw/i386/multiboot_header.h:253:
+struct multiboot_apm_info
+{
ERROR: Missing Signed-off-by: line(s)
total: 40 errors, 4 warnings, 479 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]
PATCH 1/1 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 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 304 insertions(+), 74 deletions(-) create mode 100644 hw/i386/multiboot_header.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,14 +192,14 @@ 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 ); - mh_load_addr =ldl_p (header+i+16 ); +/* 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);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) { mb_kernel_size = mh_bss_end_addr - mh_load_addr;
@@ -234,11 +209,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);
@@ -276,14 +251,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) {
@@ -329,22 +305,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);
@@ -353,7 +329,7 @@ int load_multiboot(FWCfgState *fw_cfg,/* save bootinfo off the stack */ mb_bootinfo_data =g_malloc (sizeof (bootinfo)); -memcpy (mb_bootinfo_data, bootinfo,sizeof (bootinfo)); +memcpy (mb_bootinfo_data, &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
Signature · 1 line
2.14.0.rc0.400.g1c36432dff-goog