From patchwork Fri Feb 22 04:15:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liguang X-Patchwork-Id: 222464 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 11BA82C007E for ; Fri, 22 Feb 2013 15:42:04 +1100 (EST) Received: from localhost ([::1]:41026 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8k3U-00088W-LQ for incoming@patchwork.ozlabs.org; Thu, 21 Feb 2013 23:16:16 -0500 Received: from eggs.gnu.org ([208.118.235.92]:59061) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8k2w-0006wu-QO for qemu-devel@nongnu.org; Thu, 21 Feb 2013 23:15:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U8k2t-0005Wg-KX for qemu-devel@nongnu.org; Thu, 21 Feb 2013 23:15:42 -0500 Received: from [222.73.24.84] (port=64059 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8k2t-0005WN-6z for qemu-devel@nongnu.org; Thu, 21 Feb 2013 23:15:39 -0500 X-IronPort-AV: E=Sophos;i="4.84,713,1355068800"; d="scan'208";a="6747016" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 22 Feb 2013 12:13:18 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id r1M4FNr7017380 for ; Fri, 22 Feb 2013 12:15:31 +0800 Received: from liguang.fnst.cn.fujitsu.com ([10.167.225.128]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013022212143618-334893 ; Fri, 22 Feb 2013 12:14:36 +0800 From: liguang To: qemu-devel@nongnu.org Date: Fri, 22 Feb 2013 12:15:33 +0800 Message-Id: <1361506533-28463-7-git-send-email-lig.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1361506533-28463-1-git-send-email-lig.fnst@cn.fujitsu.com> References: <1361506533-28463-1-git-send-email-lig.fnst@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/02/22 12:14:36, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/02/22 12:14:54, Serialize complete at 2013/02/22 12:14:54 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 222.73.24.84 Cc: liguang Subject: [Qemu-devel] [PATCH v2 6/6] load_linux: change kernel header size allocation 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 it's not necessary to alloc 8K bytes for kernel header, 0.5K is enough. Signed-off-by: liguang --- hw/pc.c | 14 ++++++++------ 1 files changed, 8 insertions(+), 6 deletions(-) diff --git a/hw/pc.c b/hw/pc.c index 30b3262..4f78d4f 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -637,6 +637,9 @@ static long get_file_size(FILE *f) return size; } +#define HEADER_SIZE 0x200 +#define HEADER_SIGNATURE 0x53726448 + static void load_linux(void *fw_cfg, const char *kernel_filename, const char *initrd_filename, @@ -646,7 +649,7 @@ static void load_linux(void *fw_cfg, uint16_t protocol; int setup_size, kernel_size, initrd_size = 0, cmdline_size; uint32_t initrd_max; - uint8_t header[8192], *setup, *kernel, *initrd_data; + uint8_t header[HEADER_SIZE], *setup, *kernel, *initrd_data; hwaddr real_addr, prot_addr, cmdline_addr, initrd_addr = 0; FILE *f; char *vmode; @@ -667,8 +670,7 @@ static void load_linux(void *fw_cfg, strerror(errno)); exit(1); } - if (fread(header, 1, MIN(ARRAY_SIZE(header), kernel_size), f) != - MIN(ARRAY_SIZE(header), kernel_size)) { + if (fread(header, 1, HEADER_SIZE, f) <= 0) { fprintf(stderr, "qemu: could not load kernel '%s': %s\n", kernel_filename, strerror(errno)); exit(1); @@ -678,9 +680,9 @@ static void load_linux(void *fw_cfg, #if 0 fprintf(stderr, "header magic: %#x\n", ldl_p(header+0x202)); #endif - if (ldl_p(header+0x202) == 0x53726448) - protocol = lduw_p(header+0x206); - else { + if (ldl_p(header + 0x202) == HEADER_SIGNATURE) { + protocol = lduw_p(header + 0x206); + } else { /* This looks like a multiboot kernel. If it is, let's stop treating it like a Linux kernel. */ if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename,