From patchwork Tue Sep 30 21:49:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Bellows X-Patchwork-Id: 38192 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CB70B2032C for ; Tue, 30 Sep 2014 21:57:03 +0000 (UTC) Received: by mail-wi0-f198.google.com with SMTP id hi2sf491467wib.1 for ; Tue, 30 Sep 2014 14:57:03 -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=71a33mrxnbAAv0LHNxejjYeFwo7dojmc7bRG2soP9IE=; b=Hns9IPlXSTHh4o7ScbwlkDQyWoVNbo8tvYd/Sr6r4PMSTjNRt9vu7ueMJBw2xnKsdN aMJGJ+cDAhY+jlg4yPafURqzf00HlkDOBcNpAJRhR5PImQvoTLOeIY1+7jb4nCG0nzjW wMpPRE4GUpM+ZDa9N5RYRtChk9JROAoYE+H/i5EkLUl2IzKhzbylNBblTKJTfS2BKezU WJSxZ60ZhqROskBL+OsVZt/EEbO8Tb6C5XxJsSGtAwfeD+O5wq3q6o35KsNbnu8hDclv 7hAMGwqKz9lw62cMQBayJiHxnn4eQBQrzTXCYGrSzIg4mug29RvOzrswSFV57i7sM3Fc 8cVg== X-Gm-Message-State: ALoCoQn8/E7GK2EBjGGBjAGw2z0xTnBTjCTxMqfxqhmJ0GKsSXuVs4YDXhhynnhi3wVCxPY4xb4u X-Received: by 10.180.38.11 with SMTP id c11mr1370336wik.5.1412114223062; Tue, 30 Sep 2014 14:57:03 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.19.5 with SMTP id a5ls93403lae.19.gmail; Tue, 30 Sep 2014 14:57:02 -0700 (PDT) X-Received: by 10.152.22.100 with SMTP id c4mr32165195laf.0.1412114222901; Tue, 30 Sep 2014 14:57:02 -0700 (PDT) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com [209.85.217.179]) by mx.google.com with ESMTPS id e4si23673867lbs.54.2014.09.30.14.57.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 30 Sep 2014 14:57:02 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by mail-lb0-f179.google.com with SMTP id l4so1543535lbv.10 for ; Tue, 30 Sep 2014 14:57:02 -0700 (PDT) X-Received: by 10.152.42.136 with SMTP id o8mr50241252lal.71.1412114222831; Tue, 30 Sep 2014 14:57:02 -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.130.169 with SMTP id of9csp429821lbb; Tue, 30 Sep 2014 14:57:02 -0700 (PDT) X-Received: by 10.229.46.3 with SMTP id h3mr48144373qcf.4.1412114221755; Tue, 30 Sep 2014 14:57:01 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [208.118.235.17]) by mx.google.com with ESMTPS id w98si3686782qge.12.2014.09.30.14.57.01 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 30 Sep 2014 14:57:01 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; Received: from localhost ([::1]:46582 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZ5Pp-0001c0-3a for patch@linaro.org; Tue, 30 Sep 2014 17:57:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43018) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZ5JF-0000OS-Oj for qemu-devel@nongnu.org; Tue, 30 Sep 2014 17:50:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XZ5J9-0003f2-TP for qemu-devel@nongnu.org; Tue, 30 Sep 2014 17:50:13 -0400 Received: from mail-pa0-f51.google.com ([209.85.220.51]:33664) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZ5J8-0003ZA-Kq for qemu-devel@nongnu.org; Tue, 30 Sep 2014 17:50:07 -0400 Received: by mail-pa0-f51.google.com with SMTP id lj1so5464897pab.24 for ; Tue, 30 Sep 2014 14:50:06 -0700 (PDT) X-Received: by 10.69.31.1 with SMTP id ki1mr28720629pbd.100.1412113805980; Tue, 30 Sep 2014 14:50:05 -0700 (PDT) Received: from gbellows-linaro.qualcomm.com (rrcs-67-52-129-61.west.biz.rr.com. [67.52.129.61]) by mx.google.com with ESMTPSA id qy1sm16027662pbc.27.2014.09.30.14.50.04 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 30 Sep 2014 14:50:05 -0700 (PDT) From: Greg Bellows To: qemu-devel@nongnu.org, peter.maydell@linaro.org, serge.fdrv@gmail.com, edgar.iglesias@gmail.com, aggelerf@ethz.ch Date: Tue, 30 Sep 2014 16:49:20 -0500 Message-Id: <1412113785-21525-9-git-send-email-greg.bellows@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1412113785-21525-1-git-send-email-greg.bellows@linaro.org> References: <1412113785-21525-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.220.51 Cc: Greg Bellows Subject: [Qemu-devel] [PATCH v5 08/33] target-arm: add async excp target_el function 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.217.179 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: Fabian Aggeler Adds a dedicated function for IRQ and FIQ exceptions to determine target_el and mode (Aarch32) according to tables in ARM ARMv8 and ARM ARM v7. Signed-off-by: Fabian Aggeler Signed-off-by: Greg Bellows ---------- v4 -> v5 - Simplify target EL function including removal of mode which was unused - Merged with patch that plugs in the use of the function v3 -> v4 - Fixed arm_phys_excp_target_el() 0/0/0 case to return excp_mode when EL<2 rather than ABORT. --- target-arm/cpu.h | 2 + target-arm/helper.c | 103 ++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 85 insertions(+), 20 deletions(-) diff --git a/target-arm/cpu.h b/target-arm/cpu.h index 30f57fd..601f8fe 100644 --- a/target-arm/cpu.h +++ b/target-arm/cpu.h @@ -809,6 +809,8 @@ static inline bool arm_el_is_aa64(CPUARMState *env, int el) void arm_cpu_list(FILE *f, fprintf_function cpu_fprintf); unsigned int arm_excp_target_el(CPUState *cs, unsigned int excp_idx); +inline uint32_t arm_phys_excp_target_el(CPUState *cs, uint32_t excp_idx, + uint32_t cur_el, bool secure); /* Interface between CPU and Interrupt controller. */ void armv7m_nvic_set_pending(void *opaque, int irq); diff --git a/target-arm/helper.c b/target-arm/helper.c index 7f3f049..a10f459 100644 --- a/target-arm/helper.c +++ b/target-arm/helper.c @@ -3706,6 +3706,12 @@ uint32_t HELPER(get_r13_banked)(CPUARMState *env, uint32_t mode) return 0; } +inline uint32_t arm_phys_excp_target_el(CPUState *cs, uint32_t excp_idx, + uint32_t cur_el, bool secure) +{ + return 1; +} + unsigned int arm_excp_target_el(CPUState *cs, unsigned int excp_idx) { return 1; @@ -3767,6 +3773,80 @@ void switch_mode(CPUARMState *env, int mode) } /* + * Determine the target EL for physical exceptions + */ +inline uint32_t arm_phys_excp_target_el(CPUState *cs, uint32_t excp_idx, + uint32_t cur_el, bool secure) +{ + CPUARMState *env = cs->env_ptr; + uint32_t target_el = 1; + + /* There is no SCR or HCR routing unless the respective EL3 and EL2 + * extensions are supported. This initial setting affects whether any + * other conditions matter. + */ + bool scr_routing = arm_feature(env, ARM_FEATURE_EL3); /* IRQ, FIQ, EA */ + bool hcr_routing = arm_feature(env, ARM_FEATURE_EL2); /* IMO, FMO, AMO */ + + /* Fast-path if EL2 and EL3 are not enabled */ + if (!scr_routing && !hcr_routing) { + return target_el; + } + + switch (excp_idx) { + case EXCP_IRQ: + scr_routing &= ((env->cp15.scr_el3 & SCR_IRQ) == SCR_IRQ); + hcr_routing &= ((env->cp15.hcr_el2 & HCR_IMO) == HCR_IMO); + break; + case EXCP_FIQ: + scr_routing &= ((env->cp15.scr_el3 & SCR_FIQ) == SCR_FIQ); + hcr_routing &= ((env->cp15.hcr_el2 & HCR_FMO) == HCR_FMO); + } + + /* If SCR routing is enabled we always go to EL3 regardless of EL3 + * execution state + */ + if (scr_routing) { + /* IRQ|FIQ|EA == 1 */ + return 3; + } + + /* If HCR.TGE is set all exceptions that would be routed to EL1 are + * routed to EL2 (in non-secure world). + */ + hcr_routing &= (env->cp15.hcr_el2 & HCR_TGE) == HCR_TGE; + + /* Determine target EL according to ARM ARMv8 tables G1-15 and G1-16 */ + if (arm_el_is_aa64(env, 3)) { + /* EL3 in Aarch64 */ + if (!secure) { + /* If non-secure, we may route to EL2 depending on other state. + * If we are coming from the secure world then we always route to + * EL1. + */ + if (hcr_routing || + (cur_el == 2 && !(env->cp15.scr_el3 & SCR_RW))) { + /* If HCR.FMO/IMO is set or we already in EL2 and it is not + * configured to be AArch64 then route to EL2. + */ + target_el = 2; + } + } + } else { + /* EL3 in Aarch32 */ + if (secure) { + /* If coming from secure always route to EL3 */ + target_el = 3; + } else if (hcr_routing || cur_el == 2) { + /* If HCR.FMO/IMO is set or we are already EL2 then route to EL2 */ + target_el = 2; + } + } + + return target_el; +} + +/* * Determine the target EL for a given exception type. */ unsigned int arm_excp_target_el(CPUState *cs, unsigned int excp_idx) @@ -3774,14 +3854,8 @@ unsigned int arm_excp_target_el(CPUState *cs, unsigned int excp_idx) ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; unsigned int cur_el = arm_current_el(env); - unsigned int target_el; - /* FIXME: Use actual secure state. */ - bool secure = false; - - if (!env->aarch64) { - /* TODO: Add EL2 and 3 exception handling for AArch32. */ - return 1; - } + unsigned int target_el = 1; + bool secure = arm_is_secure(env); switch (excp_idx) { case EXCP_HVC: @@ -3793,19 +3867,8 @@ unsigned int arm_excp_target_el(CPUState *cs, unsigned int excp_idx) break; case EXCP_FIQ: case EXCP_IRQ: - { - const uint64_t hcr_mask = excp_idx == EXCP_FIQ ? HCR_FMO : HCR_IMO; - const uint32_t scr_mask = excp_idx == EXCP_FIQ ? SCR_FIQ : SCR_IRQ; - - target_el = 1; - if (!secure && (env->cp15.hcr_el2 & hcr_mask)) { - target_el = 2; - } - if (env->cp15.scr_el3 & scr_mask) { - target_el = 3; - } + target_el = arm_phys_excp_target_el(cs, excp_idx, cur_el, secure); break; - } case EXCP_VIRQ: case EXCP_VFIQ: target_el = 1;