From patchwork Tue Dec 20 09:13:02 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 132374 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 47CDFB7038 for ; Tue, 20 Dec 2011 20:10:33 +1100 (EST) Received: from localhost ([::1]:43994 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RcviL-0002OG-RX for incoming@patchwork.ozlabs.org; Tue, 20 Dec 2011 04:10:25 -0500 Received: from eggs.gnu.org ([140.186.70.92]:52040) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rcvi8-0002I1-Oa for qemu-devel@nongnu.org; Tue, 20 Dec 2011 04:10:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rcvhz-00030z-7n for qemu-devel@nongnu.org; Tue, 20 Dec 2011 04:10:12 -0500 Received: from [222.73.24.84] (port=50027 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rcvhy-0002zx-2R for qemu-devel@nongnu.org; Tue, 20 Dec 2011 04:10:03 -0500 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id C0F15170126; Tue, 20 Dec 2011 17:09:58 +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 pBK99uaE019513; Tue, 20 Dec 2011 17:09:57 +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 2011122017091653-119448 ; Tue, 20 Dec 2011 17:09:16 +0800 Message-ID: <4EF0519E.4060801@cn.fujitsu.com> Date: Tue, 20 Dec 2011 17:13:02 +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 References: <4EF04D58.3030900@cn.fujitsu.com> In-Reply-To: <4EF04D58.3030900@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-12-20 17:09:16, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-12-20 17:09:18, Serialize complete at 2011-12-20 17:09:18 X-detected-operating-system: by eggs.gnu.org: FreeBSD 6.x (1) X-Received-From: 222.73.24.84 Subject: [Qemu-devel] [RFC][PATCH 6/8 v3] 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 | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 0 deletions(-) diff --git a/cpu-all.h b/cpu-all.h index 038934d..4d87d51 100644 --- a/cpu-all.h +++ b/cpu-all.h @@ -591,10 +591,12 @@ int cpu_write_elf64_note(Monitor *mon, int fd, CPUState *env, int cpuid, target_phys_addr_t *offset); int cpu_write_elf32_note(Monitor *mon, int fd, CPUState *env, int cpuid, target_phys_addr_t *offset); +int cpu_add_extra_memory_mapping(Monitor *mon, MemoryMappingList *list); #else #define cpu_get_memory_mapping(list, env) #define cpu_write_elf64_note(mon, fd, env, cpuid, offset) ({ -1; }) #define cpu_write_elf32_note(mon, fd, env, cpuid, offset) ({ -1; }) +#define cpu_add_extra_memory_mapping(mon, list) ({ 0; }) #endif #endif /* CPU_ALL_H */ diff --git a/target-i386/arch-dump.c b/target-i386/arch-dump.c index 4ecb981..2410c6a 100644 --- a/target-i386/arch-dump.c +++ b/target-i386/arch-dump.c @@ -498,3 +498,47 @@ int cpu_write_elf32_note(Monitor *mon, int fd, CPUState *env, int cpuid, { return x86_write_elf32_note(mon, 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(Monitor *mon, 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) { + monitor_printf(mon, "dump: can not get phys_base\n"); + return -1; + } + + create_new_memory_mapping_head(list, kernel_base, base_vaddr, + TARGET_PAGE_SIZE); +#endif + return 0; +}