From patchwork Mon Mar 26 19:27:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Moser X-Patchwork-Id: 148817 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 15259B6EEF for ; Tue, 27 Mar 2012 06:27:19 +1100 (EST) Received: from localhost ([::1]:36843 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCFZU-0002D1-Tu for incoming@patchwork.ozlabs.org; Mon, 26 Mar 2012 15:27:16 -0400 Received: from eggs.gnu.org ([208.118.235.92]:50706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCFZN-0002Ct-LW for qemu-devel@nongnu.org; Mon, 26 Mar 2012 15:27:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SCFZK-00086S-IE for qemu-devel@nongnu.org; Mon, 26 Mar 2012 15:27:09 -0400 Received: from mail-qc0-f173.google.com ([209.85.216.173]:51054) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCFZK-0007zg-BN for qemu-devel@nongnu.org; Mon, 26 Mar 2012 15:27:06 -0400 Received: by qcsc20 with SMTP id c20so3678889qcs.4 for ; Mon, 26 Mar 2012 12:27:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:x-x-sender:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version:content-type; bh=PKMYMdJYeXeW9+uzMSjjhcsrjFWFiMAVvqIkcDkFUEs=; b=Tkg8gzTWtflToyNqmrDFNXXWpnETzgXwWkKLHZQvhzXmFqWbSVmUA+p0So/kUdkOqS Be9V43pQNlk0ordUK6XmeAMIOEdVqkouYALlkt5msYnyo3Fsja2teESAfqunn+DDts35 OxPwdyqTSJhbHb9gk60gBWz5HylUJV6YpBYJeheSLhnU4Vh/a50XswHN5f3zgQmNGa3b 5FvkQE2Wp4bnrXGQwSMW1Yc8jGr3gp3zDVTcau8ZuqhJrjL3I7vBPZtK51ENyW2CCt68 Q5UAPVWPqJQLgqgdAZm+Ezv8gG7xqf0FinHVTpRFgShHfdSHhSB+eBLngUY782Q88+rr 4UoQ== Received: by 10.224.31.84 with SMTP id x20mr29659979qac.63.1332790023420; Mon, 26 Mar 2012 12:27:03 -0700 (PDT) Received: from brickies-eth0.mosers.us (d14-69-66-169.try.wideopenwest.com. [69.14.169.66]) by mx.google.com with ESMTPS id i19sm31423998qad.19.2012.03.26.12.27.01 (version=SSLv3 cipher=OTHER); Mon, 26 Mar 2012 12:27:01 -0700 (PDT) Date: Mon, 26 Mar 2012 15:27:00 -0400 (EDT) From: Scott Moser X-X-Sender: smoser@brickies To: Anthony Liguori In-Reply-To: <4F70C0E4.9000700@codemonkey.ws> Message-ID: References: <4F70C0E4.9000700@codemonkey.ws> User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.216.173 Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH] fix multiboot loading if load_end_addr == 0 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 The previous multiboot load 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. Signed-off-by: Scott Moser 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);