From mboxrd@z Thu Jan 1 00:00:00 1970 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 Message-ID: <4EF0519E.4060801@cn.fujitsu.com> Date: Tue, 20 Dec 2011 17:13:02 +0800 From: Wen Congyang MIME-Version: 1.0 References: <4EF04D58.3030900@cn.fujitsu.com> In-Reply-To: <4EF04D58.3030900@cn.fujitsu.com> Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-8859-1 Subject: [Qemu-devel] [RFC][PATCH 6/8 v3] target-i386: Add API to add extra memory mapping List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel , Jan Kiszka , Dave Anderson , HATAYAMA Daisuke 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; +} -- 1.7.1