From patchwork Fri May 2 19:15:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 29582 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f69.google.com (mail-yh0-f69.google.com [209.85.213.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 44E93203F3 for ; Fri, 2 May 2014 19:22:35 +0000 (UTC) Received: by mail-yh0-f69.google.com with SMTP id b6sf18304230yha.8 for ; Fri, 02 May 2014 12:22:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=JPZcMawLq/+cp3X3pkrBYgjPTNPxevGBRZZIRW/p4Ws=; b=WgOXVsMRC966HrcoXzG2IXcrn6KgKhwzVICQTIn5rndfFKf6db77YaE831E8eeEBE/ HSWyjblhHaAFKLyz6lH1ByK8QqzasE0XTYQGvrdMXOdVUl6jWU9y4eZxcEZ48Qa9T1GX UaZwF1LvQ9v1Vu+caG4/JZ3+lO4wYXLb8Xj5VEbvfmPafdx2JKFAzwiCC+nD3pkk4rv1 IGCNBJWO3APsp6rvG4k512vVJ2LxTJ4EQ79xNARYnxG6uTNE1EtjcRCPUGX89EwEfn5r ZK62JXKTczxXJLFP8gi8teqMJZwfbfOKVC82tK+qQHVsA10Mg8lNofHkDweCRK46WuR+ oNXw== X-Gm-Message-State: ALoCoQnkG1laoaEEZykJFuUcXA9r2JLv69/KgMypOyEACFL5NtsGUSCxnJAoKLz6cR66vglcftNx X-Received: by 10.236.35.33 with SMTP id t21mr8811625yha.11.1399058554694; Fri, 02 May 2014 12:22:34 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.96.8 with SMTP id j8ls1743846qge.45.gmail; Fri, 02 May 2014 12:22:34 -0700 (PDT) X-Received: by 10.58.134.101 with SMTP id pj5mr1023046veb.38.1399058554577; Fri, 02 May 2014 12:22:34 -0700 (PDT) Received: from mail-ve0-f171.google.com (mail-ve0-f171.google.com [209.85.128.171]) by mx.google.com with ESMTPS id mr9si6923010vec.173.2014.05.02.12.22.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 02 May 2014 12:22:34 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.128.171; Received: by mail-ve0-f171.google.com with SMTP id jy13so5761130veb.2 for ; Fri, 02 May 2014 12:22:34 -0700 (PDT) X-Received: by 10.220.5.129 with SMTP id 1mr41525vcv.71.1399058554502; Fri, 02 May 2014 12:22:34 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp126083vcb; Fri, 2 May 2014 12:22:34 -0700 (PDT) X-Received: by 10.224.166.201 with SMTP id n9mr25343725qay.95.1399058553985; Fri, 02 May 2014 12:22:33 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id s6si14505915qaj.85.2014.05.02.12.22.33 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 02 May 2014 12:22:33 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:46001 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WgJ2X-0001HM-Fd for patch@linaro.org; Fri, 02 May 2014 15:22:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33523) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WgIwE-00083a-R0 for qemu-devel@nongnu.org; Fri, 02 May 2014 15:16:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WgIw5-0000CZ-M3 for qemu-devel@nongnu.org; Fri, 02 May 2014 15:16:02 -0400 Received: from afflict.kos.to ([92.243.29.197]:48086) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WgIw5-0000A7-8J; Fri, 02 May 2014 15:15:53 -0400 Received: from localhost.localdomain (afflict [92.243.29.197]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by afflict.kos.to (Postfix) with ESMTPSA id 35E28264D5; Fri, 2 May 2014 21:15:51 +0200 (CEST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Fri, 2 May 2014 22:15:48 +0300 Message-Id: <24e76ff06bcd0936ee8b04b15dca42efb7d614d1.1399057853.git.riku.voipio@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 92.243.29.197 Cc: peter.maydell@linaro.org, qemu-stable@nongnu.org Subject: [Qemu-devel] [PULL 13/14] linux-user/elfload.c: Fix A64 code which was incorrectly acting like A32 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: riku.voipio@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Peter Maydell The ARM target-specific code in elfload.c was incorrectly allowing the 64-bit ARM target to use most of the existing 32-bit definitions: most noticably this meant that our HWCAP bits passed to the guest were wrong, and register handling when dumping core was totally broken. Fix this by properly separating the 64 and 32 bit code, since they have more differences than similarities. Signed-off-by: Peter Maydell Cc: qemu-stable@nongnu.org Signed-off-by: Riku Voipio --- linux-user/elfload.c | 86 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 13 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index d372300..ad07c43 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -267,17 +267,15 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *en #ifdef TARGET_ARM +#ifndef TARGET_AARCH64 +/* 32 bit ARM definitions */ + #define ELF_START_MMAP 0x80000000 #define elf_check_arch(x) ((x) == ELF_MACHINE) #define ELF_ARCH ELF_MACHINE - -#ifdef TARGET_AARCH64 -#define ELF_CLASS ELFCLASS64 -#else #define ELF_CLASS ELFCLASS32 -#endif static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop) @@ -285,10 +283,6 @@ static inline void init_thread(struct target_pt_regs *regs, abi_long stack = infop->start_stack; memset(regs, 0, sizeof(*regs)); -#ifdef TARGET_AARCH64 - regs->pc = infop->entry & ~0x3ULL; - regs->sp = stack; -#else regs->ARM_cpsr = 0x10; if (infop->entry & 1) regs->ARM_cpsr |= CPSR_T; @@ -302,7 +296,6 @@ static inline void init_thread(struct target_pt_regs *regs, /* For uClinux PIC binaries. */ /* XXX: Linux does this only on ARM with no MMU (do we care ?) */ regs->ARM_r10 = infop->start_data; -#endif } #define ELF_NREG 18 @@ -360,7 +353,6 @@ enum ARM_HWCAP_ARM_EVTSTRM = 1 << 21, }; -#ifndef TARGET_AARCH64 /* The commpage only exists for 32 bit kernels */ #define TARGET_HAS_VALIDATE_GUEST_SPACE @@ -422,7 +414,6 @@ static int validate_guest_space(unsigned long guest_base, return 1; /* All good */ } -#endif #define ELF_HWCAP get_elf_hwcap() @@ -462,7 +453,76 @@ static uint32_t get_elf_hwcap(void) return hwcaps; } -#endif +#else +/* 64 bit ARM definitions */ +#define ELF_START_MMAP 0x80000000 + +#define elf_check_arch(x) ((x) == ELF_MACHINE) + +#define ELF_ARCH ELF_MACHINE +#define ELF_CLASS ELFCLASS64 +#define ELF_PLATFORM "aarch64" + +static inline void init_thread(struct target_pt_regs *regs, + struct image_info *infop) +{ + abi_long stack = infop->start_stack; + memset(regs, 0, sizeof(*regs)); + + regs->pc = infop->entry & ~0x3ULL; + regs->sp = stack; +} + +#define ELF_NREG 34 +typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG]; + +static void elf_core_copy_regs(target_elf_gregset_t *regs, + const CPUARMState *env) +{ + int i; + + for (i = 0; i < 32; i++) { + (*regs)[i] = tswapreg(env->xregs[i]); + } + (*regs)[32] = tswapreg(env->pc); + (*regs)[33] = tswapreg(pstate_read((CPUARMState *)env)); +} + +#define USE_ELF_CORE_DUMP +#define ELF_EXEC_PAGESIZE 4096 + +enum { + ARM_HWCAP_A64_FP = 1 << 0, + ARM_HWCAP_A64_ASIMD = 1 << 1, + ARM_HWCAP_A64_EVTSTRM = 1 << 2, + ARM_HWCAP_A64_AES = 1 << 3, + ARM_HWCAP_A64_PMULL = 1 << 4, + ARM_HWCAP_A64_SHA1 = 1 << 5, + ARM_HWCAP_A64_SHA2 = 1 << 6, + ARM_HWCAP_A64_CRC32 = 1 << 7, +}; + +#define ELF_HWCAP get_elf_hwcap() + +static uint32_t get_elf_hwcap(void) +{ + ARMCPU *cpu = ARM_CPU(thread_cpu); + uint32_t hwcaps = 0; + + hwcaps |= ARM_HWCAP_A64_FP; + hwcaps |= ARM_HWCAP_A64_ASIMD; + + /* probe for the extra features */ +#define GET_FEATURE(feat, hwcap) \ + do { if (arm_feature(&cpu->env, feat)) { hwcaps |= hwcap; } } while (0) + GET_FEATURE(ARM_FEATURE_V8_AES, ARM_HWCAP_A64_PMULL); +#undef GET_FEATURE + + return hwcaps; +} + +#endif /* not TARGET_AARCH64 */ +#endif /* TARGET_ARM */ #ifdef TARGET_UNICORE32