From patchwork Fri Jun 10 16:07:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 580616 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5806:0:0:0:0 with SMTP id j6csp1898673max; Fri, 10 Jun 2022 09:26:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIn7ZukgWDzECBVck5XojNRH396t6xsk53ILA8jgomf3m0UaAk/duHJcxWCR5ZxfihMXpt X-Received: by 2002:a37:a9d2:0:b0:6a6:a4ce:a565 with SMTP id s201-20020a37a9d2000000b006a6a4cea565mr25649188qke.201.1654878384006; Fri, 10 Jun 2022 09:26:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654878384; cv=none; d=google.com; s=arc-20160816; b=lQZEa3nbaHFPe3T+QOSecErb9EVFf/lHn4fjIvYlWRPjKqc++tdQ/bm6C7e97gpKgH ydR/pTeTleFzi5MyIs03fpMGep7WNAaP8cyR2f0QwkiftaRmp1TXPLx9hKk8M/Nka9/k 0jnLaccltYNaPvotLmaknnpImkv/sKFl1GN6x9XsBIZZZQYE9I5DlpBOs1qabuSS5BgM fi/ErJlhKpkpRjgfzRoW68jarhAOeI8b/j9/DxCWWyFZCwxhTfiENsk6CsOfg2ohjXkK qGUhiAPo0C9u59xbdmgZsW0HJr1xbVGM3Z1jNQrjOEjZu240TWl6sbp/AQt6XZO+8TSE 0hIg== 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=+MoErnjm74ckDgy5tbZNnxq6pI/QlmDb72blZJEpgZc=; b=PHGAU63PCFGvhy9+UV3cWZHy+dWmHukuK64bp0HALiVtQe36UScdGOmaJzW+a8BHoR gNb2NljLLtY0pWJxdejhQgLsv46zLsvqozATGsCBqOr28fkzgBy+BcP1QuxxSHKCPJpz 97rrABbNFGvndRWOiVDTMJV2e5r8Fw/cUeJWvH2nAnVnMEBPTek2h2093R+qCzFnf72A 3EIcf76wO/ObM5yhcAWLXZ9cRTT37AM1me0priG2mbq6dnyTwlv+ar4NDGnpjIhdkekZ D9z4EKA4lITQrVD+lYu9tKr20yjk6ZzAJz36yf70MenkpOY0LisxI2/K1D2Pucdw74GR eabQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="owxmShK/"; 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 gy6-20020a056214242600b0045a827ef0cbsi5858988qvb.571.2022.06.10.09.26.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 10 Jun 2022 09:26:23 -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="owxmShK/"; 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]:41828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzhSp-0005Tu-Ix for patch@linaro.org; Fri, 10 Jun 2022 12:26:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzhAu-0007QC-Vr for qemu-devel@nongnu.org; Fri, 10 Jun 2022 12:07:53 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:35483) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nzhAp-0007F7-UI for qemu-devel@nongnu.org; Fri, 10 Jun 2022 12:07:49 -0400 Received: by mail-wr1-x42c.google.com with SMTP id a15so28618256wrh.2 for ; Fri, 10 Jun 2022 09:07:47 -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=+MoErnjm74ckDgy5tbZNnxq6pI/QlmDb72blZJEpgZc=; b=owxmShK/qzhxJm8LCIBJ+uC8VPjoKDes8mKgCincgeiYua23u8bdd/aasFPTsFDXHC BsHNxG3MJOF06KMXLRRxQqEprbVsQKNJKJax6n3QmV1966FZbiEGekB4+gvGSR5px4Zh A6m8G5q2y5w39c/3LXdBTNGRyH7j43hd6lHVcn8mPYBgt0j2tiKuoCn+GQ28g0vQMUB1 0xwtgzxb+ID4p8suu7LNRwCWZ6vXJ2PcpS3il+SeRpe5BRyFUUy/eW+aLc8tq5gOnZuI drXaw3FU6UQq0rr/1Ch2BweDDT0/V7T2VFjfbwO4tmNqq6WHcj+49jdVTKfVFlADGBp2 bwMQ== 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=+MoErnjm74ckDgy5tbZNnxq6pI/QlmDb72blZJEpgZc=; b=ZulAPTxNX34aXxX7YqHND64GlwC7cHodG+0Jc2jh/XrmgYFHDJHrDzSJOl+G1uu2l6 OntIvSW9+ghuRQD8Pak3FL1zXI6KYATdkVCwQHs3zpajcPzZy5876DzdOpupHUVI2wUC kXiNTEJGQRGkQpXcoco5SChdqQ9nHxsHcPCEJSZnfESWq8+h3iP8UvoLbXY9YzLU3iZW FglQkG7zSjUEtTYNKeADmKuDF85Umf/X0789pgUjLafKZXvEkBXlbL3q6rJEbYcsvs51 ijLmPKOJYKmnBgB5tWu4HEEm6sUITyMfvFS1D6cKMQksmdUyuO9dTjMTooDHCxLXC8OF pOMg== X-Gm-Message-State: AOAM532RNLzM56/8flNZ5mRVvZ4P402VmsVWEn0QptfVifTdnfUzEJBi I1jdX+cd3+6KitHbtERMXU7S8sNvkFXpQg== X-Received: by 2002:adf:e70e:0:b0:210:2b0f:723 with SMTP id c14-20020adfe70e000000b002102b0f0723mr44369149wrm.47.1654877266277; Fri, 10 Jun 2022 09:07:46 -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.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jun 2022 09:07:45 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 05/28] target/arm: Move arm_generate_debug_exceptions out of line Date: Fri, 10 Jun 2022 17:07:15 +0100 Message-Id: <20220610160738.2230762-6-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_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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 arm_generate_debug_exceptions and its two subroutines, {aa32,aa64}_generate_debug_exceptions into debug_helper.c, and the one interface declaration to internals.h. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson Message-id: 20220609202901.1177572-6-richard.henderson@linaro.org Signed-off-by: Peter Maydell --- target/arm/cpu.h | 91 ------------------------------------- target/arm/internals.h | 1 + target/arm/debug_helper.c | 94 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 91 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index bb1dc3289a2..50b5a9c9fd0 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3015,97 +3015,6 @@ static inline bool arm_v7m_csselr_razwi(ARMCPU *cpu) return (cpu->clidr & R_V7M_CLIDR_CTYPE_ALL_MASK) != 0; } -/* See AArch64.GenerateDebugExceptionsFrom() in ARM ARM pseudocode */ -static inline bool aa64_generate_debug_exceptions(CPUARMState *env) -{ - int cur_el = arm_current_el(env); - int debug_el; - - if (cur_el == 3) { - return false; - } - - /* MDCR_EL3.SDD disables debug events from Secure state */ - if (arm_is_secure_below_el3(env) - && extract32(env->cp15.mdcr_el3, 16, 1)) { - return false; - } - - /* - * Same EL to same EL debug exceptions need MDSCR_KDE enabled - * while not masking the (D)ebug bit in DAIF. - */ - debug_el = arm_debug_target_el(env); - - if (cur_el == debug_el) { - return extract32(env->cp15.mdscr_el1, 13, 1) - && !(env->daif & PSTATE_D); - } - - /* Otherwise the debug target needs to be a higher EL */ - return debug_el > cur_el; -} - -static inline bool aa32_generate_debug_exceptions(CPUARMState *env) -{ - int el = arm_current_el(env); - - if (el == 0 && arm_el_is_aa64(env, 1)) { - return aa64_generate_debug_exceptions(env); - } - - if (arm_is_secure(env)) { - int spd; - - if (el == 0 && (env->cp15.sder & 1)) { - /* SDER.SUIDEN means debug exceptions from Secure EL0 - * are always enabled. Otherwise they are controlled by - * SDCR.SPD like those from other Secure ELs. - */ - return true; - } - - spd = extract32(env->cp15.mdcr_el3, 14, 2); - switch (spd) { - case 1: - /* SPD == 0b01 is reserved, but behaves as 0b00. */ - case 0: - /* For 0b00 we return true if external secure invasive debug - * is enabled. On real hardware this is controlled by external - * signals to the core. QEMU always permits debug, and behaves - * as if DBGEN, SPIDEN, NIDEN and SPNIDEN are all tied high. - */ - return true; - case 2: - return false; - case 3: - return true; - } - } - - return el != 2; -} - -/* Return true if debugging exceptions are currently enabled. - * This corresponds to what in ARM ARM pseudocode would be - * if UsingAArch32() then - * return AArch32.GenerateDebugExceptions() - * else - * return AArch64.GenerateDebugExceptions() - * We choose to push the if() down into this function for clarity, - * since the pseudocode has it at all callsites except for the one in - * CheckSoftwareStep(), where it is elided because both branches would - * always return the same value. - */ -static inline bool arm_generate_debug_exceptions(CPUARMState *env) -{ - if (env->aarch64) { - return aa64_generate_debug_exceptions(env); - } else { - return aa32_generate_debug_exceptions(env); - } -} - static inline bool arm_sctlr_b(CPUARMState *env) { return diff --git a/target/arm/internals.h b/target/arm/internals.h index 64e2c1dfad4..02fa70f75ae 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -1326,6 +1326,7 @@ bool el_is_in_host(CPUARMState *env, int el); void aa32_max_features(ARMCPU *cpu); int exception_target_el(CPUARMState *env); bool arm_singlestep_active(CPUARMState *env); +bool arm_generate_debug_exceptions(CPUARMState *env); /* Powers of 2 for sve_vq_map et al. */ #define SVE_VQ_POW2_MAP \ diff --git a/target/arm/debug_helper.c b/target/arm/debug_helper.c index 1abf41c5f85..20a0e4261ad 100644 --- a/target/arm/debug_helper.c +++ b/target/arm/debug_helper.c @@ -12,6 +12,100 @@ #include "exec/helper-proto.h" +/* See AArch64.GenerateDebugExceptionsFrom() in ARM ARM pseudocode */ +static bool aa64_generate_debug_exceptions(CPUARMState *env) +{ + int cur_el = arm_current_el(env); + int debug_el; + + if (cur_el == 3) { + return false; + } + + /* MDCR_EL3.SDD disables debug events from Secure state */ + if (arm_is_secure_below_el3(env) + && extract32(env->cp15.mdcr_el3, 16, 1)) { + return false; + } + + /* + * Same EL to same EL debug exceptions need MDSCR_KDE enabled + * while not masking the (D)ebug bit in DAIF. + */ + debug_el = arm_debug_target_el(env); + + if (cur_el == debug_el) { + return extract32(env->cp15.mdscr_el1, 13, 1) + && !(env->daif & PSTATE_D); + } + + /* Otherwise the debug target needs to be a higher EL */ + return debug_el > cur_el; +} + +static bool aa32_generate_debug_exceptions(CPUARMState *env) +{ + int el = arm_current_el(env); + + if (el == 0 && arm_el_is_aa64(env, 1)) { + return aa64_generate_debug_exceptions(env); + } + + if (arm_is_secure(env)) { + int spd; + + if (el == 0 && (env->cp15.sder & 1)) { + /* + * SDER.SUIDEN means debug exceptions from Secure EL0 + * are always enabled. Otherwise they are controlled by + * SDCR.SPD like those from other Secure ELs. + */ + return true; + } + + spd = extract32(env->cp15.mdcr_el3, 14, 2); + switch (spd) { + case 1: + /* SPD == 0b01 is reserved, but behaves as 0b00. */ + case 0: + /* + * For 0b00 we return true if external secure invasive debug + * is enabled. On real hardware this is controlled by external + * signals to the core. QEMU always permits debug, and behaves + * as if DBGEN, SPIDEN, NIDEN and SPNIDEN are all tied high. + */ + return true; + case 2: + return false; + case 3: + return true; + } + } + + return el != 2; +} + +/* + * Return true if debugging exceptions are currently enabled. + * This corresponds to what in ARM ARM pseudocode would be + * if UsingAArch32() then + * return AArch32.GenerateDebugExceptions() + * else + * return AArch64.GenerateDebugExceptions() + * We choose to push the if() down into this function for clarity, + * since the pseudocode has it at all callsites except for the one in + * CheckSoftwareStep(), where it is elided because both branches would + * always return the same value. + */ +bool arm_generate_debug_exceptions(CPUARMState *env) +{ + if (env->aarch64) { + return aa64_generate_debug_exceptions(env); + } else { + return aa32_generate_debug_exceptions(env); + } +} + /* * Is single-stepping active? (Note that the "is EL_D AArch64?" check * implicitly means this always returns false in pre-v8 CPUs.)