From patchwork Thu Feb 9 03:24:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 140297 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 2D5EDB6FA4 for ; Thu, 9 Feb 2012 14:21:44 +1100 (EST) Received: from localhost ([::1]:46358 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RvKZq-0007rl-5U for incoming@patchwork.ozlabs.org; Wed, 08 Feb 2012 22:21:42 -0500 Received: from eggs.gnu.org ([140.186.70.92]:43287) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RvKZi-0007rg-IO for qemu-devel@nongnu.org; Wed, 08 Feb 2012 22:21:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RvKZe-0001ZR-Ln for qemu-devel@nongnu.org; Wed, 08 Feb 2012 22:21:34 -0500 Received: from [222.73.24.84] (port=55858 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RvKZe-0001ZD-76 for qemu-devel@nongnu.org; Wed, 08 Feb 2012 22:21:30 -0500 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 1B59E170126; Thu, 9 Feb 2012 11:21:29 +0800 (CST) Received: from mailserver.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 q193LSBq000387; Thu, 9 Feb 2012 11:21:28 +0800 Received: from [10.167.225.226] ([10.167.225.226]) by mailserver.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.1FP4) with ESMTP id 2012020911200058-576876 ; Thu, 9 Feb 2012 11:20:00 +0800 Message-ID: <4F333C82.4070003@cn.fujitsu.com> Date: Thu, 09 Feb 2012 11:24:50 +0800 From: Wen Congyang User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100413 Fedora/3.0.4-2.fc13 Thunderbird/3.0.4 MIME-Version: 1.0 To: qemu-devel , Jan Kiszka , Dave Anderson , HATAYAMA Daisuke , Luiz Capitulino , Eric Blake References: <4F333AAA.1070601@cn.fujitsu.com> In-Reply-To: <4F333AAA.1070601@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2012-02-09 11:20:00, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2012-02-09 11:20:00, Serialize complete at 2012-02-09 11:20:00 X-detected-operating-system: by eggs.gnu.org: FreeBSD 6.x (1) X-Received-From: 222.73.24.84 Subject: [Qemu-devel] [RFC][PATCH 07/16 v6] target-i386: Add API to add extra memory mapping 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 Crash needs extra memory mapping to determine phys_base. Signed-off-by: Wen Congyang --- cpu-all.h | 2 ++ target-i386/arch-dump.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 0 deletions(-) diff --git a/cpu-all.h b/cpu-all.h index efb5ba3..290c43a 100644 --- a/cpu-all.h +++ b/cpu-all.h @@ -530,10 +530,12 @@ int cpu_write_elf64_note(int fd, CPUState *env, int cpuid, target_phys_addr_t *offset); int cpu_write_elf32_note(int fd, CPUState *env, int cpuid, target_phys_addr_t *offset); +int cpu_add_extra_memory_mapping(MemoryMappingList *list); #else #define cpu_get_memory_mapping(list, env) #define cpu_write_elf64_note(fd, env, cpuid, offset) ({ -1; }) #define cpu_write_elf32_note(fd, env, cpuid, offset) ({ -1; }) +#define cpu_add_extra_memory_mapping(list) ({ 0; }) #endif #endif /* CPU_ALL_H */ diff --git a/target-i386/arch-dump.c b/target-i386/arch-dump.c index 4c0ff77..d96f6ae 100644 --- a/target-i386/arch-dump.c +++ b/target-i386/arch-dump.c @@ -495,3 +495,46 @@ int cpu_write_elf32_note(int fd, CPUState *env, int cpuid, { return x86_write_elf32_note(fd, env, cpuid, offset); } + +/* This function is copied from crash */ +static target_ulong get_phys_base_addr(CPUState *env, target_ulong *base_vaddr) +{ + int i; + target_ulong kernel_base = -1; + target_ulong last, mask; + + for (i = 30, last = -1; (kernel_base == -1) && (i >= 20); i--) { + mask = ~((1LL << i) - 1); + *base_vaddr = env->idt.base & mask; + if (*base_vaddr == last) { + continue; + } + + kernel_base = cpu_get_phys_page_debug(env, *base_vaddr); + last = *base_vaddr; + } + + return kernel_base; +} + +int cpu_add_extra_memory_mapping(MemoryMappingList *list) +{ +#ifdef TARGET_X86_64 + target_phys_addr_t kernel_base = -1; + target_ulong base_vaddr; + bool lma = !!(first_cpu->hflags & HF_LMA_MASK); + + if (!lma) { + return 0; + } + + kernel_base = get_phys_base_addr(first_cpu, &base_vaddr); + if (kernel_base == -1) { + return -1; + } + + create_new_memory_mapping_head(list, kernel_base, base_vaddr, + TARGET_PAGE_SIZE); +#endif + return 0; +}