public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fix multiboot loading if load_end_addr == 0
@ 2012-03-17  4:08 Scott Moser
  2012-03-17 13:27 ` Jan Kiszka
  0 siblings, 1 reply; 2+ messages in thread
From: Scott Moser @ 2012-03-17  4:08 UTC (permalink / raw)
  To: kvm

The previous code did not treat the case where load_end_addr was 0
specially.  The multiboot specification says the following:
 * load_end_addr
   Contains the physical address of the end of the data segment.
   (load_end_addr - load_addr) specifies how much data to load. This
   implies that the text and data segments must be consecutive in the
   OS image; this is true for existing a.out executable formats. If
   this field is zero, the boot loader assumes that the text and data
   segments occupy the whole OS image file.

This was raised initially as launchpad bug
https://bugs.launchpad.net/qemu/+bug/957622

diff --git a/hw/multiboot.c b/hw/multiboot.c
index b4484a3..b1e04c5 100644
--- a/hw/multiboot.c
+++ b/hw/multiboot.c
@@ -202,10 +202,16 @@ int load_multiboot(void *fw_cfg,
         uint32_t mh_bss_end_addr = ldl_p(header+i+24);
         mh_load_addr = ldl_p(header+i+16);
         uint32_t mb_kernel_text_offset = i - (mh_header_addr - mh_load_addr);
-        uint32_t mb_load_size = mh_load_end_addr - mh_load_addr;
-
+        uint32_t mb_load_size = 0;
         mh_entry_addr = ldl_p(header+i+28);
-        mb_kernel_size = mh_bss_end_addr - mh_load_addr;
+
+        if (mh_load_end_addr) {
+            mb_kernel_size = mh_bss_end_addr - mh_load_addr;
+            mb_load_size = mh_load_end_addr - mh_load_addr;
+        } else {
+            mb_kernel_size = kernel_file_size - mb_kernel_text_offset;
+            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);

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] fix multiboot loading if load_end_addr == 0
  2012-03-17  4:08 [PATCH] fix multiboot loading if load_end_addr == 0 Scott Moser
@ 2012-03-17 13:27 ` Jan Kiszka
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Kiszka @ 2012-03-17 13:27 UTC (permalink / raw)
  To: Scott Moser; +Cc: kvm

[-- Attachment #1: Type: text/plain, Size: 1841 bytes --]

On 2012-03-17 05:08, Scott Moser wrote:
> The previous code did not treat the case where load_end_addr was 0
> specially.  The multiboot specification says the following:
>  * load_end_addr
>    Contains the physical address of the end of the data segment.
>    (load_end_addr - load_addr) specifies how much data to load. This
>    implies that the text and data segments must be consecutive in the
>    OS image; this is true for existing a.out executable formats. If
>    this field is zero, the boot loader assumes that the text and data
>    segments occupy the whole OS image file.
> 
> This was raised initially as launchpad bug
> https://bugs.launchpad.net/qemu/+bug/957622
> 
> diff --git a/hw/multiboot.c b/hw/multiboot.c
> index b4484a3..b1e04c5 100644
> --- a/hw/multiboot.c
> +++ b/hw/multiboot.c
> @@ -202,10 +202,16 @@ int load_multiboot(void *fw_cfg,
>          uint32_t mh_bss_end_addr = ldl_p(header+i+24);
>          mh_load_addr = ldl_p(header+i+16);
>          uint32_t mb_kernel_text_offset = i - (mh_header_addr - mh_load_addr);
> -        uint32_t mb_load_size = mh_load_end_addr - mh_load_addr;
> -
> +        uint32_t mb_load_size = 0;
>          mh_entry_addr = ldl_p(header+i+28);
> -        mb_kernel_size = mh_bss_end_addr - mh_load_addr;
> +
> +        if (mh_load_end_addr) {
> +            mb_kernel_size = mh_bss_end_addr - mh_load_addr;
> +            mb_load_size = mh_load_end_addr - mh_load_addr;
> +        } else {
> +            mb_kernel_size = kernel_file_size - mb_kernel_text_offset;
> +            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);

Almost everything should go to upstream directly these days, including
this fix.

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-03-17 13:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-17  4:08 [PATCH] fix multiboot loading if load_end_addr == 0 Scott Moser
2012-03-17 13:27 ` Jan Kiszka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox