From patchwork Sun Jul 24 15:55:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?G=C3=B6ran_Weinholt?= X-Patchwork-Id: 106522 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CB087B6F68 for ; Mon, 25 Jul 2011 01:56:26 +1000 (EST) Received: from localhost ([::1]:45889 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ql12V-0005On-0F for incoming@patchwork.ozlabs.org; Sun, 24 Jul 2011 11:56:23 -0400 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 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=weinholt.se; s=gula2011; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID:Date:Subject:To:From; bh=TZPoq2qrsstMWgYxCJKQ77obQo9p5Q10pTTm1ZFBtgE=; b=gqe2sHnj+fw6+SPZ2zOePqQMBXjcVjpM2oDFJwzU1saHhOZcwltVQcssATEEy93sqCCOHWUtN1WvmmTCmsci+taGrQUHOzNmbBJghfrg45pyW3D27D5xNrXnpBbFpuayEPq2rEOVUHadsUQzn6oeTP6MB7zWZcjm84zKkoPvXb9bOz7sGmrpDGnbcUL9rejHkjtGDftkbBypHp6axxoxMdPj7vmncJYhOWsH7WV8tGiZizn24vPQ3YUvZF3i1rV+; Received: from Uindustria by mail.weinholt.se with local-bsmtp (Exim 4.72) (envelope-from ) id 1Ql12K-0007Hk-L8; Sun, 24 Jul 2011 17:56:12 +0200 Received: from weinholt by localhost with local (Exim 4.72) (envelope-from ) id 1Ql126-0004sU-Hv; Sun, 24 Jul 2011 17:55:58 +0200 X-Hashcash: 1:20:110724:qemu-devel@nongnu.org::r/bjAFAB2yzm2irY:00000000000000000000000000000000000000001m+Z From: =?utf-8?Q?G=C3=B6ran?= Weinholt To: qemu-devel@nongnu.org Date: Sun, 24 Jul 2011 17:55:58 +0200 Message-ID: <874o2bhdv5.fsf@industria.weinholt.se> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 95.80.32.2 Subject: [Qemu-devel] [PATCH v2] multiboot: Fix bss segment support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@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öran 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 = 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); 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; mh_entry_addr = ldl_p(header+i+28); - mb_kernel_size = kernel_file_size - mb_kernel_text_offset; + mb_kernel_size = mh_bss_end_addr - mh_load_addr; /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE. uint32_t mh_mode_type = ldl_p(header+i+32); @@ -212,17 +215,18 @@ int load_multiboot(void *fw_cfg, mb_debug("multiboot: mh_header_addr = %#x\n", mh_header_addr); mb_debug("multiboot: mh_load_addr = %#x\n", mh_load_addr); - mb_debug("multiboot: mh_load_end_addr = %#x\n", ldl_p(header+i+20)); - mb_debug("multiboot: mh_bss_end_addr = %#x\n", ldl_p(header+i+24)); + mb_debug("multiboot: mh_load_end_addr = %#x\n", mh_load_end_addr); + mb_debug("multiboot: mh_bss_end_addr = %#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); mbs.mb_buf = qemu_malloc(mb_kernel_size); fseek(f, mb_kernel_text_offset, SEEK_SET); - if (fread(mbs.mb_buf, 1, mb_kernel_size, f) != mb_kernel_size) { + if (fread(mbs.mb_buf, 1, mb_load_size, f) != 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); }