Received: from eggs.gnu.org ([140.186.70.92]:36553) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ql12P-0005OU-Kk for qemu-devel@nongnu.org; Sun, 24 Jul 2011 11:56:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ql12O-0001uG-BQ for qemu-devel@nongnu.org; Sun, 24 Jul 2011 11:56:17 -0400 Received: from gula.weinholt.se ([95.80.32.2]:33554 helo=mail.weinholt.se) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ql12N-0001u7-Jm for qemu-devel@nongnu.org; Sun, 24 Jul 2011 11:56:16 -0400 From: =?utf-8?Q?G=C3=B6ran?= Weinholt Date: Sun, 24 Jul 2011 17:55:58 +0200 Message-ID: <874o2bhdv5.fsf@industria.weinholt.se> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v2] multiboot: Fix bss segment support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Multiboot images can specify a bss segment. The boot loader must clear the memory of the bss and ensure that no modules or structures are allocated inside it. Several fields are provided in the Multiboot header that were previously not used properly. The header is now used to determine how much data should be read from the image and how much memory should be reserved to the bss segment. Signed-off-by: G=C3=B6ran Weinholt --- hw/multiboot.c | 14 +++++++++----- 1 files changed, 9 insertions(+), 5 deletions(-) diff --git a/hw/multiboot.c b/hw/multiboot.c index 2426e84..a1d3f41 100644 --- a/hw/multiboot.c +++ b/hw/multiboot.c @@ -198,11 +198,14 @@ int load_multiboot(void *fw_cfg, } else { /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_ADDR. */ uint32_t mh_header_addr =3D ldl_p(header+i+12); + uint32_t mh_load_end_addr =3D ldl_p(header+i+20); + 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); + uint32_t mb_load_size =3D mh_load_end_addr - mh_load_addr; =20 mh_entry_addr =3D ldl_p(header+i+28); - mb_kernel_size =3D kernel_file_size - mb_kernel_text_offset; + mb_kernel_size =3D mh_bss_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); @@ -212,17 +215,18 @@ int load_multiboot(void *fw_cfg, =20 mb_debug("multiboot: mh_header_addr =3D %#x\n", mh_header_addr); mb_debug("multiboot: mh_load_addr =3D %#x\n", mh_load_addr); - mb_debug("multiboot: mh_load_end_addr =3D %#x\n", ldl_p(header+i+2= 0)); - mb_debug("multiboot: mh_bss_end_addr =3D %#x\n", ldl_p(header+i+24= )); + mb_debug("multiboot: mh_load_end_addr =3D %#x\n", mh_load_end_addr= ); + mb_debug("multiboot: mh_bss_end_addr =3D %#x\n", mh_bss_end_addr); mb_debug("qemu: loading multiboot kernel (%#x bytes) at %#x\n", - mb_kernel_size, mh_load_addr); + mb_load_size, mh_load_addr); =20 mbs.mb_buf =3D qemu_malloc(mb_kernel_size); fseek(f, mb_kernel_text_offset, SEEK_SET); - if (fread(mbs.mb_buf, 1, mb_kernel_size, f) !=3D mb_kernel_size) { + if (fread(mbs.mb_buf, 1, mb_load_size, f) !=3D mb_load_size) { fprintf(stderr, "fread() failed\n"); exit(1); } + memset(mbs.mb_buf + mb_load_size, 0, mb_kernel_size - mb_load_size= ); fclose(f); } =20 --=20 1.7.2.5