Received: from eggs.gnu.org ([140.186.70.92]:43662) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RcyHQ-0002mX-7Q for qemu-devel@nongnu.org; Tue, 20 Dec 2011 06:54:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RcyHL-0006LA-I6 for qemu-devel@nongnu.org; Tue, 20 Dec 2011 06:54:48 -0500 From: =?utf-8?Q?G=C3=B6ran?= Weinholt References: <874o2bhdv5.fsf@industria.weinholt.se> <0F9E6CB6-F6FB-4C3E-B828-370E1486B95E@suse.de> <4EEFB437.8050902@codemonkey.ws> <529972F2-0826-4716-BCD0-E425C2F49EAA@suse.de> Date: Tue, 20 Dec 2011 12:53:14 +0100 In-Reply-To: <529972F2-0826-4716-BCD0-E425C2F49EAA@suse.de> (Alexander Graf's message of "Mon, 19 Dec 2011 23:26:08 +0100") Message-ID: <87pqfja28l.fsf@industria.weinholt.se> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Subject: Re: [Qemu-devel] [PATCH v2] multiboot: Fix bss segment support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexander Graf Cc: Kevin Wolf , =?utf-8?Q?Ren=C3=A9?= Rebe , "Justin M. Forbes" , qemu-devel Developers , qemu-stable@nongnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Alexander Graf writes: > On 19.12.2011, at 23:01, Anthony Liguori wrote: > > On 12/19/2011 11:35 AM, Alexander Graf wrote: > > On 24.07.2011, at 17:55, G=C3=B6ran Weinholt wrote: > > Multiboot images can specify a bss segment. The boot loader m= ust > clear >=20=20=20=20=20=20=20=20 > the memory of the bss and ensure that no modules or structure= s are >=20=20=20=20=20=20=20=20 > allocated inside it. Several fields are provided in the Multi= boot >=20=20=20=20=20=20=20=20 > header that were previously not used properly. The header is = now > used >=20=20=20=20=20=20=20=20 > to determine how much data should be read from the image and = how > much >=20=20=20=20=20=20=20=20 > memory should be reserved to the bss segment. > > This patch breaks the OSX booter: > > http://people.exactcode.de/~rene/mac/boot > > How is this licensed? Is there source available? > > Yes, it's the XNU booter, but binaries are easier to debug when it comes = to > reading out the bootloader info: > > http://tgwbd.org/darwin/boot.html > > I don't know if the binary above is 1:1 built from those sources, but it's > definitely close enough. I was unable to build that program from source, but I found a pre-built binary that triggered the same bug. Please test the following patch. Subject: [PATCH] multiboot: mh_load_end_addr and mh_bss_end_addr may be zero There are two special cases in the address fields of the multiboot format. If mh_load_end_addr is zero then the whole image file should be loaded and if mh_bss_end_addr is zero then there is no bss segment. With this change it is again possible to boot kernels where these fields are zero. Signed-off-by: G=C3=B6ran Weinholt =2D-- hw/multiboot.c | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-) diff --git a/hw/multiboot.c b/hw/multiboot.c index b4484a3..a43d56c 100644 =2D-- a/hw/multiboot.c +++ b/hw/multiboot.c @@ -202,10 +202,21 @@ int load_multiboot(void *fw_cfg, uint32_t mh_bss_end_addr =3D ldl_p(header+i+24); mh_load_addr =3D ldl_p(header+i+16); uint32_t mb_kernel_text_offset =3D i - (mh_header_addr - mh_load_a= ddr); =2D uint32_t mb_load_size =3D mh_load_end_addr - mh_load_addr; + uint32_t mb_load_size; + + /* A load end address of zero indicates that the whole file + * should be loaded. */ + if (!mh_load_end_addr) + mh_load_end_addr =3D kernel_file_size + mh_load_addr; + + /* A bss end address of zero indicates that there is no bss + * segment. */ + if (!mh_bss_end_addr) + mh_bss_end_addr =3D mh_load_end_addr; =20 mh_entry_addr =3D ldl_p(header+i+28); mb_kernel_size =3D mh_bss_end_addr - mh_load_addr; + mb_load_size =3D mh_load_end_addr - mh_load_addr; =20 /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE. uint32_t mh_mode_type =3D ldl_p(header+i+32); =2D-=20 1.7.2.5 =2D-=20 G=C3=B6ran Weinholt --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iQIcBAEBAgAGBQJO8HcqAAoJEOM+YaLpuMOiwWwP/1Y0qwmHv35P/3/K3Sqj4Zej XTZ6Kg8k76kcNnDkyPQZYjS4pVIiwteHlQImWGykO6Sm7hvxvFC6+YL/HIgoPPuH 5I6aCv008pjyKO48jTh1mjtCHZ3oY9ZzpRhIGOzHSGqcN+T9YzsnOL0xoX7Jijz9 ltWLY8uXm6d50CKxdpuYmEADac47x3PFalUMZQ/6A9amaOxeXZYNnLND4NHIwj6c he5x9l7R1ZWzfa55IgLBF5PF3N36K/ZGWiLaFjWSoWK79Dardf7tfPhjVku0gzRG /d7RT3KSCvHcxczMwI1EMae/2OmW3mqJh3tYMgioqOUjffmtZ1Ducb+E1gVomKbs IY+EtOaW6f3YENgq51Zi/1GHT2DBST4jZLae7B0xc+tf6MnV8e7PBoQq/GzsCP23 gjx7MdS3+aJyx8F9iEbGi6RLhJ+J3MNphAUMeUWY7lo5L2DPYYXTh2H5Tj9rgKuI WiXfgwPE07WTC/KOG1iLf7fOixICG0OOk4qHIZwrRePwDoT/44MNyI9W7BIe9RPI VV5/POicqyos8b7hJFuN0yb/ss9BzWcxouARcWUsPo/ovmHe4V1LGUjUp/2H1RxR 5k+ukm5R2lbhF6d2jXC3lHpyJsZ/Jyhm/QK8CkuxdlrJM5bmesyZHwaPdVN4cNad a09OP6UocogwDqnr+OGA =puQr -----END PGP SIGNATURE----- --=-=-=--