From patchwork Wed Apr 22 17:09:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Bellows X-Patchwork-Id: 47426 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D871E2121F for ; Wed, 22 Apr 2015 17:14:22 +0000 (UTC) Received: by layy10 with SMTP id y10sf55885483lay.0 for ; Wed, 22 Apr 2015 10:14:21 -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=952LexAkQDWeagQoxbdV3FYf+ZZ53/V4/TXrckbAgEI=; b=iEds//yT6orVqRkS/+2hUP9uVr/sw5Sj/jlxP5w29qKrH3SFNxEH1Tnc7pd47uo2t1 SW04IUrKicoxk54p75Ry9CAdYXmzpZ1sh7A+KuTSsvwxELM2C7HpqlSGCYGQxHttyO4H 9CQiNzxqlEV+ejkfonENRzsI6B3Bnx9ix/Ik8hd4jnA3lWGeLkw/CAoWsbOEtxdIidzZ 9hnI1nSfqIuEwf301JXxOOlnIuZSGxRjkWV3h/P1vZJmB1T+9x5tI4qp/5Xl704Pb0oI jM5YsuAjwRUsoBRKJkil9q57H6yf724YNfvrlNaU8kzi/oG+9pAnCuWUn4J+1vFQKUSs jPlQ== X-Gm-Message-State: ALoCoQnscvguEgaUQKLv9Kp3b2L5AkR3cGk21YwYJA+Aaep63wDNyuG5LWdh9tlD7cm0GJw81Nzm X-Received: by 10.112.142.170 with SMTP id rx10mr11915706lbb.12.1429722861861; Wed, 22 Apr 2015 10:14:21 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.7.67 with SMTP id da3ls253120lad.49.gmail; Wed, 22 Apr 2015 10:14:21 -0700 (PDT) X-Received: by 10.152.1.70 with SMTP id 6mr25524227lak.83.1429722861719; Wed, 22 Apr 2015 10:14:21 -0700 (PDT) Received: from mail-la0-f41.google.com (mail-la0-f41.google.com. [209.85.215.41]) by mx.google.com with ESMTPS id kx6si4138511lac.141.2015.04.22.10.14.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Apr 2015 10:14:21 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) client-ip=209.85.215.41; Received: by layy10 with SMTP id y10so180056313lay.0 for ; Wed, 22 Apr 2015 10:14:21 -0700 (PDT) X-Received: by 10.152.8.78 with SMTP id p14mr25697534laa.19.1429722861586; Wed, 22 Apr 2015 10:14:21 -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.112.67.65 with SMTP id l1csp69948lbt; Wed, 22 Apr 2015 10:14:20 -0700 (PDT) X-Received: by 10.229.19.67 with SMTP id z3mr30872703qca.2.1429722859376; Wed, 22 Apr 2015 10:14:19 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id c198si5609357qka.100.2015.04.22.10.14.18 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 22 Apr 2015 10:14:19 -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]:36259 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YkyE6-0006cW-5h for patch@linaro.org; Wed, 22 Apr 2015 13:14:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yky9m-0007Pv-6o for qemu-devel@nongnu.org; Wed, 22 Apr 2015 13:09:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yky9l-0004v2-7t for qemu-devel@nongnu.org; Wed, 22 Apr 2015 13:09:50 -0400 Received: from mail-oi0-f53.google.com ([209.85.218.53]:33055) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yky9l-0004ud-2l for qemu-devel@nongnu.org; Wed, 22 Apr 2015 13:09:49 -0400 Received: by oica37 with SMTP id a37so182345706oic.0 for ; Wed, 22 Apr 2015 10:09:48 -0700 (PDT) X-Received: by 10.182.76.33 with SMTP id h1mr23757083obw.63.1429722588886; Wed, 22 Apr 2015 10:09:48 -0700 (PDT) Received: from gbellows-linaro.gateway.pace.com (99-179-1-214.lightspeed.austtx.sbcglobal.net. [99.179.1.214]) by mx.google.com with ESMTPSA id w72sm3417636oie.28.2015.04.22.10.09.47 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 22 Apr 2015 10:09:47 -0700 (PDT) From: Greg Bellows To: qemu-devel@nongnu.org, peter.maydell@linaro.org, alex.bennee@linaro.org Date: Wed, 22 Apr 2015 12:09:21 -0500 Message-Id: <1429722561-12651-10-git-send-email-greg.bellows@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1429722561-12651-1-git-send-email-greg.bellows@linaro.org> References: <1429722561-12651-1-git-send-email-greg.bellows@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.218.53 Cc: serge.fdrv@gmail.com, Greg Bellows Subject: [Qemu-devel] [PATCH v2 9/9] target-arm: Add WFx instruction trap support 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: greg.bellows@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.215.41 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 Add support for trapping WFI and WFE instructions to the proper EL when SCTLR/SCR/HCR settings apply. Signed-off-by: Greg Bellows --- v1 -> v2 - Replace check loop with simpler if checks. - Changed WFx syncdrome function to take bool - Changed return of uint32_t to int - Added cdditional comments. --- target-arm/internals.h | 2 +- target-arm/op_helper.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 74 insertions(+), 4 deletions(-) diff --git a/target-arm/internals.h b/target-arm/internals.h index de0a9c1..8e208f7 100644 --- a/target-arm/internals.h +++ b/target-arm/internals.h @@ -347,7 +347,7 @@ static inline uint32_t syn_breakpoint(int same_el) | ARM_EL_IL | 0x22; } -static inline uint32_t syn_wfx(int cv, int cond, int ti) +static inline uint32_t syn_wfx(int cv, int cond, bool ti) { return (EC_WFX_TRAP << ARM_EL_EC_SHIFT) | (cv << 24) | (cond << 20) | ti; diff --git a/target-arm/op_helper.c b/target-arm/op_helper.c index 971edc7..43aa8ef 100644 --- a/target-arm/op_helper.c +++ b/target-arm/op_helper.c @@ -223,23 +223,93 @@ uint32_t HELPER(usat16)(CPUARMState *env, uint32_t x, uint32_t shift) return res; } +/* Function checks whether WFx (WFI/WFE) instructions are set-up to be trapped. + * The function returns the target EL (1-3) if the instruction is to be trapped + * otherwise it returns 0 indicating it is not trapped. + */ +static inline int check_wfx_trap(CPUARMState *env, bool is_wfe) +{ + int cur_el = arm_current_el(env); + uint64_t mask; + + /* If we are currently in EL0 then we need to check if SCTLR is set up for + * WFx instructions being trapped to EL1. + */ + if (cur_el < 1) { + mask = is_wfe ? SCTLR_nTWE : SCTLR_nTWI; + if (arm_el_is_aa64(env, 1)) { + if (!(env->cp15.sctlr_el[1] & mask)) { + return 1; + } + } else if (arm_feature(env, ARM_FEATURE_V8)) { + /* SCTLR WFx SCTLR trap bits only exist in ARMv8 */ + if (!(A32_BANKED_CURRENT_REG_GET(env, sctlr) & mask)) { + return 1; + } + } + } + + /* We are not trapping to EL1 at this point. + * Check if we are trapping WFx to EL2 it present. + */ + if (cur_el < 2) { + if (arm_feature(env, ARM_FEATURE_EL2) && !arm_is_secure(env)) { + mask = (is_wfe) ? HCR_TWE : HCR_TWI; + if (env->cp15.hcr_el2 & mask) { + return 2; + } + } + } + + /* We are not trapping to EL1 or EL2 at this point. + * Check if we are trapping WFx to EL3 if present. + */ + if (cur_el < 3) { + if (arm_feature(env, ARM_FEATURE_EL3) && + arm_feature(env, ARM_FEATURE_V8)) { + mask = (is_wfe) ? SCR_TWE : SCR_TWI; + if (env->cp15.scr_el3 & mask) { + return 3; + } + } + } + + return 0; +} + void HELPER(wfi)(CPUARMState *env) { CPUState *cs = CPU(arm_env_get_cpu(env)); + int target_el = check_wfx_trap(env, false); - cs->exception_index = EXCP_HLT; - cs->halted = 1; + if (target_el) { + cs->exception_index = EXCP_UDEF; + env->exception.syndrome = syn_wfx(1, 0xe, false); + env->exception.target_el = target_el; + env->pc -= 4; + } else { + cs->exception_index = EXCP_HLT; + cs->halted = 1; + } cpu_loop_exit(cs); } void HELPER(wfe)(CPUARMState *env) { CPUState *cs = CPU(arm_env_get_cpu(env)); + int target_el = check_wfx_trap(env, true); /* Don't actually halt the CPU, just yield back to top * level loop */ - cs->exception_index = EXCP_YIELD; + if (target_el) { + cs->exception_index = EXCP_UDEF; + env->exception.syndrome = syn_wfx(1, 0xe, true); + env->exception.target_el = target_el; + env->pc -= 4; + } else { + cs->exception_index = EXCP_YIELD; + } cpu_loop_exit(cs); }