From patchwork Fri Mar 23 18:49:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 132365 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp955496ljb; Fri, 23 Mar 2018 11:58:59 -0700 (PDT) X-Google-Smtp-Source: AG47ELvuE7KUEBjowsL/RC+UdX5Nz0gOYpD0BjmIe8cY1qB43J3xI1P1NALxAzkXKgn34iKDYAw4 X-Received: by 10.237.48.161 with SMTP id 30mr42673519qtf.145.1521831539799; Fri, 23 Mar 2018 11:58:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521831539; cv=none; d=google.com; s=arc-20160816; b=roElZAgMbTHEhyd1O/YAfcWvTLhARX1x3SKzZhbcnKOinBVoIm7VXo5oz3+yPsIevb KpWav+9F7AuLXQHqLu2xHMWU+sMN8tChn67YHAYCw2fK8ETxKlClL++00+/AT4Iq4P+p BTVmV3D1pwlhMy4hJ+rm54Qd8Uw6W4Bd5lWuTQwdsX3BWpwsT27XdVa53uSeKjSycj1t 2S/j6bM/qfG+bUmqByNvJz1Iv2NP1Dz3wXB8AwswwNc8TbK6LG9J8QxPfp967dAZMBOH wKLMOZt7QW5hA1hY5BFFYM/6FYiIMls0UMAleBxyAuPalldwcNEFcbNsw500AMZ+xWam UY8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:arc-authentication-results; bh=XmX6hOjLsN8Zh+QaXnccJ0jUyr4BjVzBjaeaGNIHVQo=; b=j/4g+WIlQ30QKOa8aSVMWls5FAtzabB+wkc7uWclwSfTHc1Nw5bu5BfqB/b+LUQBjQ FNNLusfHwp9NElc3Q1PslkO2smFOIACd9H9xymRB+6D4zLHdZxtzB+x5+XrUyvKTl8x9 WWuQSJxOwEIF0uT2LpxrUuDFI6KzIu96eDsGGNuqLzGuO2KjW7nLHktLxAZ5YUR4TaJ1 qRREU2A0NAFydWjZOf5LAVUkRRCGY1npkbosNHZxIIEwmQqkIRqFMHJd+VdUl3/ONTV1 LY+U3tNMEPlrr61Z+FkEG33x0B71j/1TrQ1QjwbrmZivNdYm6oczwtCPZAgb+iwWhHQ5 Cblg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id w36si10425452qta.192.2018.03.23.11.58.59 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 23 Mar 2018 11:58:59 -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; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:39404 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezRtz-0007ft-8c for patch@linaro.org; Fri, 23 Mar 2018 14:58:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49178) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezRlR-00019N-C7 for qemu-devel@nongnu.org; Fri, 23 Mar 2018 14:50:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezRlO-0004Gn-HZ for qemu-devel@nongnu.org; Fri, 23 Mar 2018 14:50:07 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:40512) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ezRlO-0004FG-9u for qemu-devel@nongnu.org; Fri, 23 Mar 2018 14:50:06 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1ezRlM-0007gs-Va for qemu-devel@nongnu.org; Fri, 23 Mar 2018 18:50:04 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 23 Mar 2018 18:49:56 +0000 Message-Id: <20180323184958.14252-9-peter.maydell@linaro.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180323184958.14252-1-peter.maydell@linaro.org> References: <20180323184958.14252-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 08/10] target/arm: Factor out code to calculate FSR for debug exceptions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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" When a debug exception is taken to AArch32, it appears as a Prefetch Abort, and the Instruction Fault Status Register (IFSR) must be set. The IFSR has two possible formats, depending on whether LPAE is in use. Factor out the code in arm_debug_excp_handler() which picks an FSR value into its own utility function, update it to use arm_fi_to_lfsc() and arm_fi_to_sfsc() rather than hard-coded constants, and use the correct condition to select long or short format. In particular this fixes a bug where we could select the short format because we're at EL0 and the EL1 translation regime is not using LPAE, but then route the debug exception to EL2 because of MDCR_EL2.TDE and hand EL2 the wrong format FSR. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Message-id: 20180320134114.30418-3-peter.maydell@linaro.org --- target/arm/internals.h | 25 +++++++++++++++++++++++++ target/arm/op_helper.c | 12 ++---------- 2 files changed, 27 insertions(+), 10 deletions(-) -- 2.16.2 diff --git a/target/arm/internals.h b/target/arm/internals.h index 47cc224a46..8ce944b7a0 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -763,4 +763,29 @@ static inline bool regime_is_secure(CPUARMState *env, ARMMMUIdx mmu_idx) } } +/* Return the FSR value for a debug exception (watchpoint, hardware + * breakpoint or BKPT insn) targeting the specified exception level. + */ +static inline uint32_t arm_debug_exception_fsr(CPUARMState *env) +{ + ARMMMUFaultInfo fi = { .type = ARMFault_Debug }; + int target_el = arm_debug_target_el(env); + bool using_lpae = false; + + if (target_el == 2 || arm_el_is_aa64(env, target_el)) { + using_lpae = true; + } else { + if (arm_feature(env, ARM_FEATURE_LPAE) && + (env->cp15.tcr_el[target_el].raw_tcr & TTBCR_EAE)) { + using_lpae = true; + } + } + + if (using_lpae) { + return arm_fi_to_lfsc(&fi); + } else { + return arm_fi_to_sfsc(&fi); + } +} + #endif diff --git a/target/arm/op_helper.c b/target/arm/op_helper.c index 4b123d2bd6..75efff9edf 100644 --- a/target/arm/op_helper.c +++ b/target/arm/op_helper.c @@ -1330,11 +1330,7 @@ void arm_debug_excp_handler(CPUState *cs) cs->watchpoint_hit = NULL; - if (extended_addresses_enabled(env)) { - env->exception.fsr = (1 << 9) | 0x22; - } else { - env->exception.fsr = 0x2; - } + env->exception.fsr = arm_debug_exception_fsr(env); env->exception.vaddress = wp_hit->hitaddr; raise_exception(env, EXCP_DATA_ABORT, syn_watchpoint(same_el, 0, wnr), @@ -1354,11 +1350,7 @@ void arm_debug_excp_handler(CPUState *cs) return; } - if (extended_addresses_enabled(env)) { - env->exception.fsr = (1 << 9) | 0x22; - } else { - env->exception.fsr = 0x2; - } + env->exception.fsr = arm_debug_exception_fsr(env); /* FAR is UNKNOWN, so doesn't need setting */ raise_exception(env, EXCP_PREFETCH_ABORT, syn_breakpoint(same_el),