From patchwork Mon Aug 4 13:53:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 34844 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f69.google.com (mail-pa0-f69.google.com [209.85.220.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3BB1621F5F for ; Mon, 4 Aug 2014 13:57:23 +0000 (UTC) Received: by mail-pa0-f69.google.com with SMTP id kx10sf50748782pab.8 for ; Mon, 04 Aug 2014 06:57:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:mime-version: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 :content-type:content-transfer-encoding; bh=xvxo4anD1i3KaMmkYDxBpQB0EB56io6dkKv+CvEvEQg=; b=hVMTAtQUV90sCX39DtPtACH4kFrfm3k3/kUlXY3gMd9jlUBbRQGWnDzF+NWQoRozm3 fFvArt/veU5abgMxH5bQ4duAiqvWhTXelA4dQ66v/DgxomcsZCB3UBttQxMGlHRcBWB8 9oQ+BspXzyabhNrjKjbO2pgsEwW+BqcgwNe6tJNKLdcR1Ph8yeFsFDLDPBS1HYJ4IUBV m/9QA4S2IR5sP0HlBSl2fC5srTK83gknO/1Vbj58lm4BVjRl/oOxKPCwj83d8bBtdv3x brQm+KqSyeGOxSvzB+aDR5ZB23CHqNJfhsLVcnM1G0IqA2uGYJphBkXqBYA9KmlC1IAi Hd9g== X-Gm-Message-State: ALoCoQk1ze7BNRwWkFIHeIPGyDmp0ScrV+IZ/NEPoZ43LU6CW/cNMiyqZAUWgbdYlo5GtnYidvBg X-Received: by 10.66.150.225 with SMTP id ul1mr9564889pab.20.1407160642559; Mon, 04 Aug 2014 06:57:22 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.37.142 with SMTP id r14ls2167658qgr.16.gmail; Mon, 04 Aug 2014 06:57:22 -0700 (PDT) X-Received: by 10.220.166.207 with SMTP id n15mr1270879vcy.75.1407160642457; Mon, 04 Aug 2014 06:57:22 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id h6si11926361vdw.73.2014.08.04.06.57.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 04 Aug 2014 06:57:15 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id hq11so11054523vcb.2 for ; Mon, 04 Aug 2014 06:57:15 -0700 (PDT) X-Received: by 10.52.120.38 with SMTP id kz6mr1071429vdb.86.1407160635756; Mon, 04 Aug 2014 06:57:15 -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.221.37.5 with SMTP id tc5csp306385vcb; Mon, 4 Aug 2014 06:57:15 -0700 (PDT) X-Received: by 10.140.23.134 with SMTP id 6mr1294778qgp.55.1407160635142; Mon, 04 Aug 2014 06:57:15 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id f8si28621698qar.120.2014.08.04.06.57.15 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 04 Aug 2014 06:57:15 -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]:52467 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEIlG-0001NG-Ox for patch@linaro.org; Mon, 04 Aug 2014 09:57:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45349) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEIiD-00058U-Ur for qemu-devel@nongnu.org; Mon, 04 Aug 2014 09:54:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XEIi9-0007ad-MT for qemu-devel@nongnu.org; Mon, 04 Aug 2014 09:54:05 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:48908) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEIi9-0006mN-9v for qemu-devel@nongnu.org; Mon, 04 Aug 2014 09:54:01 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1XEIhd-0001Am-3K for qemu-devel@nongnu.org; Mon, 04 Aug 2014 14:53:29 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 4 Aug 2014 14:53:20 +0100 Message-Id: <1407160408-4467-5-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1407160408-4467-1-git-send-email-peter.maydell@linaro.org> References: <1407160408-4467-1-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Subject: [Qemu-devel] [PULL 04/12] target-arm: A64: Break out aarch64_save/restore_sp 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: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) 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: "Edgar E. Iglesias" Break out code to save/restore AArch64 SP into functions. Reviewed-by: Alex Bennée Signed-off-by: Edgar E. Iglesias Reviewed-by: Greg Bellows Message-id: 1402994746-8328-2-git-send-email-edgar.iglesias@gmail.com Signed-off-by: Peter Maydell --- target-arm/internals.h | 29 ++++++++++++++++++++--------- target-arm/kvm64.c | 13 +++---------- target-arm/op_helper.c | 6 +----- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/target-arm/internals.h b/target-arm/internals.h index 564b5fa..08fa697 100644 --- a/target-arm/internals.h +++ b/target-arm/internals.h @@ -105,6 +105,24 @@ enum arm_fprounding { int arm_rmode_to_sf(int rmode); +static inline void aarch64_save_sp(CPUARMState *env, int el) +{ + if (env->pstate & PSTATE_SP) { + env->sp_el[el] = env->xregs[31]; + } else { + env->sp_el[0] = env->xregs[31]; + } +} + +static inline void aarch64_restore_sp(CPUARMState *env, int el) +{ + if (env->pstate & PSTATE_SP) { + env->xregs[31] = env->sp_el[el]; + } else { + env->xregs[31] = env->sp_el[0]; + } +} + static inline void update_spsel(CPUARMState *env, uint32_t imm) { unsigned int cur_el = arm_current_pl(env); @@ -114,21 +132,14 @@ static inline void update_spsel(CPUARMState *env, uint32_t imm) if (!((imm ^ env->pstate) & PSTATE_SP)) { return; } + aarch64_save_sp(env, cur_el); env->pstate = deposit32(env->pstate, 0, 1, imm); /* We rely on illegal updates to SPsel from EL0 to get trapped * at translation time. */ assert(cur_el >= 1 && cur_el <= 3); - if (env->pstate & PSTATE_SP) { - /* Switch from using SP_EL0 to using SP_ELx */ - env->sp_el[0] = env->xregs[31]; - env->xregs[31] = env->sp_el[cur_el]; - } else { - /* Switch from SP_EL0 to SP_ELx */ - env->sp_el[cur_el] = env->xregs[31]; - env->xregs[31] = env->sp_el[0]; - } + aarch64_restore_sp(env, cur_el); } /* Valid Syndrome Register EC field values */ diff --git a/target-arm/kvm64.c b/target-arm/kvm64.c index 5d217ca..c615286 100644 --- a/target-arm/kvm64.c +++ b/target-arm/kvm64.c @@ -21,6 +21,7 @@ #include "sysemu/kvm.h" #include "kvm_arm.h" #include "cpu.h" +#include "internals.h" #include "hw/arm/arm.h" static inline void set_feature(uint64_t *features, int feature) @@ -132,11 +133,7 @@ int kvm_arch_put_registers(CPUState *cs, int level) /* KVM puts SP_EL0 in regs.sp and SP_EL1 in regs.sp_el1. On the * QEMU side we keep the current SP in xregs[31] as well. */ - if (env->pstate & PSTATE_SP) { - env->sp_el[1] = env->xregs[31]; - } else { - env->sp_el[0] = env->xregs[31]; - } + aarch64_save_sp(env, 1); reg.id = AARCH64_CORE_REG(regs.sp); reg.addr = (uintptr_t) &env->sp_el[0]; @@ -235,11 +232,7 @@ int kvm_arch_get_registers(CPUState *cs) /* KVM puts SP_EL0 in regs.sp and SP_EL1 in regs.sp_el1. On the * QEMU side we keep the current SP in xregs[31] as well. */ - if (env->pstate & PSTATE_SP) { - env->xregs[31] = env->sp_el[1]; - } else { - env->xregs[31] = env->sp_el[0]; - } + aarch64_restore_sp(env, 1); reg.id = AARCH64_CORE_REG(regs.pc); reg.addr = (uintptr_t) &env->pc; diff --git a/target-arm/op_helper.c b/target-arm/op_helper.c index 9c1ef52..90a946a 100644 --- a/target-arm/op_helper.c +++ b/target-arm/op_helper.c @@ -376,11 +376,7 @@ void HELPER(exception_return)(CPUARMState *env) uint32_t spsr = env->banked_spsr[spsr_idx]; int new_el, i; - if (env->pstate & PSTATE_SP) { - env->sp_el[cur_el] = env->xregs[31]; - } else { - env->sp_el[0] = env->xregs[31]; - } + aarch64_save_sp(env, cur_el); env->exclusive_addr = -1;