From patchwork Fri Jun 10 16:07:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 580606 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5806:0:0:0:0 with SMTP id j6csp1891810max; Fri, 10 Jun 2022 09:17:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6sRLSfElTPpdsEGk7hnlrQXDsOpn4Wx4Qx+RjXDAFjXkYkvtIRTKnazTE4axoTQHDVGFU X-Received: by 2002:a37:bb41:0:b0:6a6:48f4:2814 with SMTP id l62-20020a37bb41000000b006a648f42814mr31191696qkf.421.1654877839851; Fri, 10 Jun 2022 09:17:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654877839; cv=none; d=google.com; s=arc-20160816; b=lpGKK4TxBgtkiINXkGCEsdlp+GlVSKhnG3jJPHI8pJQ0ZNjFo4qIIwi60T+Jmn9+5d xpMySHdiQFtm1riHEl0CChBFHQnw3StF4E65saaQnGLojbj4XvZNnKyXxZh7bOe65OXA SAbBf+SNZEIQvw7ms77f5ll+wIle1dtNE/kp5CddkLgbCwlrKHTMWSwFZwPsOMGBd4Iu rCMcqlff+kZYrm6XSzFY1uIifBdBQGyxWoRzktrcDTKhcl7X90lB29+z1HC0KQIJo2b6 ztWzHhHXvS4tC7MgVMqKQPEikSQ41YSS1ftkGHlz2uHSGLf3y7f1P9bRXEpbJbMvYhhb 1Brg== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=kfpJqM/vTQKkaI6WcdqgObmH1bKNzodG8GQonjvolGM=; b=eTLGo3e01LfQghGEeE+7hOIq0JYVr0kOIMDS/shkZyFJdrKPvBly7N2IYP6G0s0lPB HGNu3P3eljKd2H4eSNJDQYIMj16HXsPZYVFn7KZCiy9vYOHxDmiwkrh8d6Gs5Ey5oumZ 0JDoi7G/lIKLQOFT0flBHkfyn19j/qioREosCLwgaM4J2i3Tt8uVR9W177BYlDKi90Fp 95KfqllthdNBeoeglAzr2nyMCDPULUUHsxU6vcpAq+/dCZ3hcoNvOJKg1Kx2Cx4HYxce w/hbvN/dmc0T00aZaPL4ZJuo/2jRWWJYxxUBWLCSLMsdC6+/tJqaT5nTXZOWMkc4mg0Y ahlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iritQDSZ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s8-20020a05622a018800b00304e9cc7298si9308647qtw.703.2022.06.10.09.17.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 10 Jun 2022 09:17:19 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iritQDSZ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:45974 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzhK3-0005jC-6v for patch@linaro.org; Fri, 10 Jun 2022 12:17:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37414) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzhB1-0007iO-TW for qemu-devel@nongnu.org; Fri, 10 Jun 2022 12:08:03 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:37688) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nzhAw-0007GG-7K for qemu-devel@nongnu.org; Fri, 10 Jun 2022 12:07:59 -0400 Received: by mail-wr1-x42c.google.com with SMTP id o16so3416935wra.4 for ; Fri, 10 Jun 2022 09:07:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=kfpJqM/vTQKkaI6WcdqgObmH1bKNzodG8GQonjvolGM=; b=iritQDSZDNRG2EhlK6StycOvmxM9U+meK6Sm4nrlTINi0SmAkU+Ftjc5mJLFv5T5Ck x1iVYf4Nnr17qIHMHtZ2iIUtAytDcUKxmBISP5zS/HNcBqjko/P1vTJSLhKLSgNkn97m daXruySuhY7Pfpx5WsTDafh9QymUF+7gmm5ctnDWakO8itTZBEWmUO75AjIvX63bpSq8 Gpw06HG8Gs0IkPZXXuotvpXULZFwHfwKpGBCSwU3Lw+CNPIjXCzpfTAGe81XoCI0NvXY fRE4FH4fRv42uGMKJBO/UFOGOlp9/M6djNg3oI4SE55SFEuvSbJrIou6b1xK+Zm6tUcx Nplw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kfpJqM/vTQKkaI6WcdqgObmH1bKNzodG8GQonjvolGM=; b=Fo9wNRE6D4eMgbCulm7uFZDWZQMEMfn7DTm2ensFOv84goPFNAtOlwsAzb23X5qK83 2AiKgQm3npNlwOflH84XZ9bFxlxQpqyuGj0QOpCLUEYUu9qDhn9U5/XjtgvYRRtC65lf RGBIHXUL8SXorVXm6u3f/17HpsVAtatXAq80rZ2Qwg4nG/WYTu3D6TDCklvxLlK0Updb KSnBuIfT1sWlWe28EeJmYL4xmNiOvtKvAS3T8BL7OV7/qWFuT/GNlPMDeIUFIwdtcKgb /QX5ZRj5mUoJKkmL0hhYMOiBFuntCxVgaeppDV6CasZ5WvF59eDyLQjDWQJcbpcBKgDq TqbA== X-Gm-Message-State: AOAM532fODgD8s8D5ixkS5Co30SceBbkvpSb3skCZIDex4701Wfb+E8F x6JCrXgxa8Q7wLA6j+hGSAK0XrDBAL10UQ== X-Received: by 2002:a5d:638b:0:b0:218:54a2:71d0 with SMTP id p11-20020a5d638b000000b0021854a271d0mr19299256wru.36.1654877272786; Fri, 10 Jun 2022 09:07:52 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id bp11-20020a5d5a8b000000b0020c5253d926sm14276053wrb.114.2022.06.10.09.07.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jun 2022 09:07:52 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 13/28] target/arm: Create helper_exception_swstep Date: Fri, 10 Jun 2022 17:07:23 +0100 Message-Id: <20220610160738.2230762-14-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220610160738.2230762-1-peter.maydell@linaro.org> References: <20220610160738.2230762-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" From: Richard Henderson Move the computation from gen_swstep_exception into a helper. This fixes a bug when: - MDSCR_EL1.KDE == 1 to enable debug exceptions within EL_D itself - we singlestep an ERET from EL_D to some lower EL Previously we were computing 'same el' based on the EL which executed the ERET instruction, whereas it ought to be computed based on the EL to which ERET returned. This happens naturally with the new helper, which runs after EL has been changed. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson Message-id: 20220609202901.1177572-14-richard.henderson@linaro.org Signed-off-by: Peter Maydell --- target/arm/helper.h | 1 + target/arm/translate.h | 12 +++--------- target/arm/debug_helper.c | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/target/arm/helper.h b/target/arm/helper.h index 5a6802e3fac..db7447d233e 100644 --- a/target/arm/helper.h +++ b/target/arm/helper.h @@ -47,6 +47,7 @@ DEF_HELPER_FLAGS_3(sel_flags, TCG_CALL_NO_RWG_SE, DEF_HELPER_2(exception_internal, noreturn, env, i32) DEF_HELPER_4(exception_with_syndrome_el, noreturn, env, i32, i32, i32) DEF_HELPER_2(exception_bkpt_insn, noreturn, env, i32) +DEF_HELPER_2(exception_swstep, noreturn, env, i32) DEF_HELPER_2(exception_pc_alignment, noreturn, env, tl) DEF_HELPER_1(setend, void, env) DEF_HELPER_2(wfi, void, env, i32) diff --git a/target/arm/translate.h b/target/arm/translate.h index 4575af6e1c9..890e73194c3 100644 --- a/target/arm/translate.h +++ b/target/arm/translate.h @@ -341,15 +341,9 @@ static inline void gen_exception(int excp, uint32_t syndrome, /* Generate an architectural singlestep exception */ static inline void gen_swstep_exception(DisasContext *s, int isv, int ex) { - bool same_el = (s->debug_target_el == s->current_el); - - /* - * If singlestep is targeting a lower EL than the current one, - * then s->ss_active must be false and we can never get here. - */ - assert(s->debug_target_el >= s->current_el); - - gen_exception(EXCP_UDEF, syn_swstep(same_el, isv, ex), s->debug_target_el); + /* Fill in the same_el field of the syndrome in the helper. */ + uint32_t syn = syn_swstep(false, isv, ex); + gen_helper_exception_swstep(cpu_env, tcg_constant_i32(syn)); } /* diff --git a/target/arm/debug_helper.c b/target/arm/debug_helper.c index a743061e89b..a3a1b98de28 100644 --- a/target/arm/debug_helper.c +++ b/target/arm/debug_helper.c @@ -487,6 +487,22 @@ void HELPER(exception_bkpt_insn)(CPUARMState *env, uint32_t syndrome) raise_exception(env, EXCP_BKPT, syndrome, debug_el); } +void HELPER(exception_swstep)(CPUARMState *env, uint32_t syndrome) +{ + int debug_el = arm_debug_target_el(env); + int cur_el = arm_current_el(env); + + /* + * If singlestep is targeting a lower EL than the current one, then + * DisasContext.ss_active must be false and we can never get here. + */ + assert(debug_el >= cur_el); + if (debug_el == cur_el) { + syndrome |= 1 << ARM_EL_EC_SHIFT; + } + raise_exception(env, EXCP_UDEF, syndrome, debug_el); +} + #if !defined(CONFIG_USER_ONLY) vaddr arm_adjust_watchpoint_address(CPUState *cs, vaddr addr, int len)