diff mbox

multiboot: Fix module loading and setting of mmap

Message ID 20091118140207.GB31670@os.inf.tu-dresden.de
State New
Headers show

Commit Message

Adam Lackorzynski Nov. 18, 2009, 2:02 p.m. UTC
Hi,

I need to following to fix multiboot booting for me.

Should linuxboot.bin and multiboot.bin end up in pc-bios instead of
pc-bios/optionrom?


Signed-off-by: Adam Lackorzynski <adam@os.inf.tu-dresden.de>
---
 hw/pc.c                       |    4 ++--
 pc-bios/optionrom/multiboot.S |    5 ++++-
 2 files changed, 6 insertions(+), 3 deletions(-)

Comments

Alexander Graf Nov. 18, 2009, 2:33 p.m. UTC | #1
Adam Lackorzynski wrote:
> Hi,
>
> I need to following to fix multiboot booting for me.
>
> Should linuxboot.bin and multiboot.bin end up in pc-bios instead of
> pc-bios/optionrom?
>
>
> Signed-off-by: Adam Lackorzynski <adam@os.inf.tu-dresden.de>
> ---
>  hw/pc.c                       |    4 ++--
>  pc-bios/optionrom/multiboot.S |    5 ++++-
>  2 files changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/hw/pc.c b/hw/pc.c
> index 7c791c4..1c8f95c 100644
> --- a/hw/pc.c
> +++ b/hw/pc.c
> @@ -661,7 +661,7 @@ static int load_multiboot(void *fw_cfg,
>  
>              /* append module data at the end of last module */
>              mb_kernel_data = qemu_realloc(mb_kernel_data,
> -                                          mh_load_addr - mb_mod_end);
> +                                          mb_mod_end - mh_load_addr);
>   

Right. I wonder why it worked for me before?

>              load_image(initrd_filename,
>                         mb_kernel_data + mb_mod_start - mh_load_addr);
>  
> @@ -720,7 +720,7 @@ static int load_multiboot(void *fw_cfg,
>      fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, mb_bootinfo_data,
>                       sizeof(bootinfo));
>  
> -    option_rom[nb_option_roms] = "multiboot.bin";
> +    option_rom[nb_option_roms] = "optionrom/multiboot.bin";
>   

This is wrong. The .bin file should be in pc-bios. It just doesn't get
copied over as part of the build process, but instead relies on the
committer to make sure the binary is updated on every source change.

>      nb_option_roms++;
>  
>      return 1; /* yes, we are multiboot */
> diff --git a/pc-bios/optionrom/multiboot.S b/pc-bios/optionrom/multiboot.S
> index be5c9fc..9131837 100644
> --- a/pc-bios/optionrom/multiboot.S
> +++ b/pc-bios/optionrom/multiboot.S
> @@ -62,6 +62,9 @@ run_multiboot:
>  	add		%eax, %ebx
>  	movl		%ebx, %gs:GS_GDT_DESC + 2
>  
> +	xor		%eax, %eax
> +	mov		%eax, %es
> +
>   

Ack. %es could be in any state here.

>  	/* Read the bootinfo struct into RAM */
>  	read_fw_blob(FW_CFG_INITRD)
>  
> @@ -71,7 +74,7 @@ run_multiboot:
>  	mov		%ax, %fs
>  
>  	/* ES = mmap_addr */
> -	mov		%eax, %fs:0x48
> +	mov 		%fs:48, %eax
>   

Right...


Thanks for catching those!

Alex
Anthony Liguori Nov. 18, 2009, 2:35 p.m. UTC | #2
Adam Lackorzynski wrote:
> Hi,
>
> I need to following to fix multiboot booting for me.
>
> Should linuxboot.bin and multiboot.bin end up in pc-bios instead of
> pc-bios/optionrom?
>
>
> Signed-off-by: Adam Lackorzynski <adam@os.inf.tu-dresden.de>
> ---
>  hw/pc.c                       |    4 ++--
>  pc-bios/optionrom/multiboot.S |    5 ++++-
>  2 files changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/hw/pc.c b/hw/pc.c
> index 7c791c4..1c8f95c 100644
> --- a/hw/pc.c
> +++ b/hw/pc.c
> @@ -661,7 +661,7 @@ static int load_multiboot(void *fw_cfg,
>  
>              /* append module data at the end of last module */
>              mb_kernel_data = qemu_realloc(mb_kernel_data,
> -                                          mh_load_addr - mb_mod_end);
> +                                          mb_mod_end - mh_load_addr);
>   

That bit looks right.

>              load_image(initrd_filename,
>                         mb_kernel_data + mb_mod_start - mh_load_addr);
>  
> @@ -720,7 +720,7 @@ static int load_multiboot(void *fw_cfg,
>      fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, mb_bootinfo_data,
>                       sizeof(bootinfo));
>  
> -    option_rom[nb_option_roms] = "multiboot.bin";
> +    option_rom[nb_option_roms] = "optionrom/multiboot.bin";
>      nb_option_roms++;

This bit doesn't.  multiboot.bin gets installed in ${prefix}/share/.   
There is a blob shipped in pc-bios/ so if you do -L $srcdir/pc-bios it 
should work.  However, if you did -L $objdir/pc-bios where $objdir != 
$srcdir, it would not work without your patch.  The same is true for 
seabios and the other roms.

Your patch would break the first two though.  I'm not sure we have a 
great solution.

>  
>      return 1; /* yes, we are multiboot */
> diff --git a/pc-bios/optionrom/multiboot.S b/pc-bios/optionrom/multiboot.S
> index be5c9fc..9131837 100644
> --- a/pc-bios/optionrom/multiboot.S
> +++ b/pc-bios/optionrom/multiboot.S
> @@ -62,6 +62,9 @@ run_multiboot:
>  	add		%eax, %ebx
>  	movl		%ebx, %gs:GS_GDT_DESC + 2
>  
> +	xor		%eax, %eax
> +	mov		%eax, %es
> +
>  	/* Read the bootinfo struct into RAM */
>  	read_fw_blob(FW_CFG_INITRD)
>  
> @@ -71,7 +74,7 @@ run_multiboot:
>  	mov		%ax, %fs
>  
>  	/* ES = mmap_addr */
> -	mov		%eax, %fs:0x48
> +	mov 		%fs:48, %eax
>  	shr		$4, %eax
>  	mov		%ax, %es
>   

This bit needs to be reviewed/acked by Alex.

Regards,

Anthony Liguori
diff mbox

Patch

diff --git a/hw/pc.c b/hw/pc.c
index 7c791c4..1c8f95c 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -661,7 +661,7 @@  static int load_multiboot(void *fw_cfg,
 
             /* append module data at the end of last module */
             mb_kernel_data = qemu_realloc(mb_kernel_data,
-                                          mh_load_addr - mb_mod_end);
+                                          mb_mod_end - mh_load_addr);
             load_image(initrd_filename,
                        mb_kernel_data + mb_mod_start - mh_load_addr);
 
@@ -720,7 +720,7 @@  static int load_multiboot(void *fw_cfg,
     fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, mb_bootinfo_data,
                      sizeof(bootinfo));
 
-    option_rom[nb_option_roms] = "multiboot.bin";
+    option_rom[nb_option_roms] = "optionrom/multiboot.bin";
     nb_option_roms++;
 
     return 1; /* yes, we are multiboot */
diff --git a/pc-bios/optionrom/multiboot.S b/pc-bios/optionrom/multiboot.S
index be5c9fc..9131837 100644
--- a/pc-bios/optionrom/multiboot.S
+++ b/pc-bios/optionrom/multiboot.S
@@ -62,6 +62,9 @@  run_multiboot:
 	add		%eax, %ebx
 	movl		%ebx, %gs:GS_GDT_DESC + 2
 
+	xor		%eax, %eax
+	mov		%eax, %es
+
 	/* Read the bootinfo struct into RAM */
 	read_fw_blob(FW_CFG_INITRD)
 
@@ -71,7 +74,7 @@  run_multiboot:
 	mov		%ax, %fs
 
 	/* ES = mmap_addr */
-	mov		%eax, %fs:0x48
+	mov 		%fs:48, %eax
 	shr		$4, %eax
 	mov		%ax, %es