From patchwork Tue Jun 7 02:47:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 579310 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5806:0:0:0:0 with SMTP id j6csp4675595max; Mon, 6 Jun 2022 20:10:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPOk3bW5wCB71iOKDg4OcUvmb73JAMjzsCEkYsj5styLWgwy/ykWoDL759JYqbT5HnhRwd X-Received: by 2002:a05:6214:21c7:b0:464:4a7b:31e3 with SMTP id d7-20020a05621421c700b004644a7b31e3mr34348435qvh.44.1654571459613; Mon, 06 Jun 2022 20:10:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654571459; cv=none; d=google.com; s=arc-20160816; b=ASQpDfuSgvzt7XkJ9jzJ3hojMgqiHcvM6m1T6ZJI8Ee1EiI2sc4/Er47WymboDBHCI ash01pjubj/eSrmGYWAVLYdyxVCj7zP0YaZ3Q4N+1HiXYqv4zGOXQQJraxNHQ8qWQpoX vcLVGMhIMyuXVGIs3th0H+3HLIcv5oWhJdFZgd8i1/X2v26BfHHwVpUP2f7yRkpzjzxA w+DIl208yrK6opEH8urg21Qg9btaURWePPOM+AMyujuolI6TRmJoYuz+vQ1umLQc+qib mMVIt30j11oBxZjfw5GljaJ5SDj1aMgRRlPwpdFEzL2O0YHusFHWsk6GPpp5fFb/k6c0 QzyA== 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:cc:to :from:dkim-signature; bh=M/oXSdjZYbwmqBajIXGiCmaX0gX1NZRS+oLXplWu0qM=; b=b2SWCtso222bdx+qCRkKe+sWrbetIatNHBYmBFR/KJj2AUco5pMRrwPO3mF9sYa/XJ 20uHJzDFFs3bbBa9KE1QqmURky1CP608Q9NpwcGKxOs7qkmsBWVFbn9ToMxvRVy8kHHF A3ghFZtC2V8wXVR9P9GA4qR6i+NTAXocj2Hw5nLikxA0cSoBgQuP32ZTt4aSKJ3M80tv 7GnNvK3vApFWcGdOwVfTt61fzmFHASjUTBnIqDxif1ns1tfys9CMevDYzxhYNgNq7AvQ CbI6lkzPzTJ25l1K03bTKhFW4zdgYx29NyvKJuUfOk6XUUTuohH+4Tip+pMcNXxzgKIA OS5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B5ckQxBr; 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 bs41-20020a05620a472900b0069c5493e748si10200622qkb.45.2022.06.06.20.10.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 06 Jun 2022 20:10:59 -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=B5ckQxBr; 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]:46110 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyPcR-0007nC-6l for patch@linaro.org; Mon, 06 Jun 2022 23:10:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33434) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyPG9-0007Mk-V7 for qemu-devel@nongnu.org; Mon, 06 Jun 2022 22:47:57 -0400 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]:37635) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nyPG8-0000P3-6P for qemu-devel@nongnu.org; Mon, 06 Jun 2022 22:47:57 -0400 Received: by mail-pg1-x52b.google.com with SMTP id h192so7759991pgc.4 for ; Mon, 06 Jun 2022 19:47:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M/oXSdjZYbwmqBajIXGiCmaX0gX1NZRS+oLXplWu0qM=; b=B5ckQxBr8yKhdl2yn0HNxyZvPq7eyHKoXSQH9IPmQh8AC/fvYPI0lzio4FefGZGqN6 hDUHLy0WQPu7t6Qjm0wyt4pF2M2DhL/04LaSQgJsLZ36XAZdfXKbtOgNehMhulR28RmI 2xMrmGM1j+ugRe4maTqMMk+7Gex8nkZ5aegliUXStgr03ctjIJBgQrjddkdXr9EBnt6q GwSCZtk77Era62eH18ckKe9g/jWs+jJ50e3aJtyWI6cyLKNe5GVIouNdRk5FZazUVhWX 625mdPpmt83Kg4jqbsktgF6WxrF7QMpZJowZJkkX1+zn8E/cs1oScLexthDszJ0WvOew 80KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M/oXSdjZYbwmqBajIXGiCmaX0gX1NZRS+oLXplWu0qM=; b=G0tYoU5v9ZZLu7oCev1XsC6CAj/x/xcov8tYDRPJ57UF0m1G+pB72r2IIS6obhXjX0 0emcjRPmKHjsy0NthMAPLXHJSz57WXUt/FyJt7r7K1hjlvgGq5gYZUfc6Txr4xaKW9VP fZsFal9xujc6wGSvmxMONf7zX8or08AsRxkNiEW83sd7kEatXW+Hjmkju57+kgHGFfCE VOmcJ1bLPqBDRKO2SPOUItSy3uHykKq3VPgYjQJaECWQIVIX5QHeurn5xIx7+w2i67B9 N4X1Sh/KY08XqUcpbQog7RjljDY1R6sh7+yBZCxw7K448ny6ssuRMWED0uU7F5rFYxTK 5szw== X-Gm-Message-State: AOAM53056R1Tz/tHbSYvbXtMTDSRsWxJ+KbpGbcbOTsnI03D4DV0i4up OZObGcQNZfLOq2rszMQPGIEXNRP6EQ+wSQ== X-Received: by 2002:a63:6306:0:b0:3fc:7529:7688 with SMTP id x6-20020a636306000000b003fc75297688mr24011902pgb.252.1654570074807; Mon, 06 Jun 2022 19:47:54 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:d3db:cca:e5c9:6531]) by smtp.gmail.com with ESMTPSA id y26-20020aa7805a000000b0051876d83714sm7476904pfm.196.2022.06.06.19.47.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 19:47:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v2 22/25] target/arm: Create raise_exception_debug Date: Mon, 6 Jun 2022 19:47:31 -0700 Message-Id: <20220607024734.541321-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220607024734.541321-1-richard.henderson@linaro.org> References: <20220607024734.541321-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52b; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52b.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=unavailable 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" Handle the debug vs current el exception test in one place. Leave EXCP_BKPT alone, since that treats debug < current differently. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- target/arm/debug_helper.c | 44 +++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/target/arm/debug_helper.c b/target/arm/debug_helper.c index a3a1b98de2..26004df99b 100644 --- a/target/arm/debug_helper.c +++ b/target/arm/debug_helper.c @@ -12,6 +12,26 @@ #include "exec/helper-proto.h" +/* + * Raise an exception to the debug target el. + * Modify syndrome to indicate when origin and target EL are the same. + */ +G_NORETURN static void +raise_exception_debug(CPUARMState *env, uint32_t excp, 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. + * Similarly for watchpoint and breakpoint matches. + */ + assert(debug_el >= cur_el); + syndrome |= (debug_el == cur_el) << ARM_EL_EC_SHIFT; + raise_exception(env, excp, syndrome, debug_el); +} + /* See AArch64.GenerateDebugExceptionsFrom() in ARM ARM pseudocode */ static bool aa64_generate_debug_exceptions(CPUARMState *env) { @@ -418,19 +438,16 @@ void arm_debug_excp_handler(CPUState *cs) if (wp_hit) { if (wp_hit->flags & BP_CPU) { bool wnr = (wp_hit->flags & BP_WATCHPOINT_HIT_WRITE) != 0; - bool same_el = arm_debug_target_el(env) == arm_current_el(env); cs->watchpoint_hit = NULL; 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), - arm_debug_target_el(env)); + raise_exception_debug(env, EXCP_DATA_ABORT, + syn_watchpoint(0, 0, wnr)); } } else { uint64_t pc = is_a64(env) ? env->pc : env->regs[15]; - bool same_el = (arm_debug_target_el(env) == arm_current_el(env)); /* * (1) GDB breakpoints should be handled first. @@ -450,9 +467,7 @@ void arm_debug_excp_handler(CPUState *cs) * exception/security level. */ env->exception.vaddress = 0; - raise_exception(env, EXCP_PREFETCH_ABORT, - syn_breakpoint(same_el), - arm_debug_target_el(env)); + raise_exception_debug(env, EXCP_PREFETCH_ABORT, syn_breakpoint(0)); } } @@ -489,18 +504,7 @@ void HELPER(exception_bkpt_insn)(CPUARMState *env, uint32_t syndrome) 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); + raise_exception_debug(env, EXCP_UDEF, syndrome); } #if !defined(CONFIG_USER_ONLY)