From patchwork Mon Nov 12 17:08:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 150864 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3403557ljp; Mon, 12 Nov 2018 09:26:25 -0800 (PST) X-Google-Smtp-Source: AJdET5c6fA6GW/WahINBOkSoYMhlGmnPa8UHFD2voj+iIBMu2vav2cmhgP+CmwgPzZZ3Yi3RfdZW X-Received: by 2002:aed:3263:: with SMTP id y90mr1716219qtd.269.1542043585481; Mon, 12 Nov 2018 09:26:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542043585; cv=none; d=google.com; s=arc-20160816; b=DC4d+iGTDJIbCkDguzD5xKU/JlqUt+jOLRzG9rQtgM+UZaMGM6MBFXkTczjBdcEWEq i8Wg70VH8Yzw5GRYVg6CSTSlKJOOahtyvV7vUH1ScqFhWLAI5/iNOk8wpIx06wgay8AZ dEbNvIhZlgAjUB1LaAWJBmniGNzSwGEpgYpKx5Ewc97JAmg/QgMuRrnLgJPcSBEbPDMv BZinxJMRzlbweyPUsbA9uir2KNQz4dgl5jOIzTcX7IvoV0PdzAVtdF+EbjDgVJurBaaI iyBhc5J33Gv5XT7qNUF2wuO1H3PYh9hfw5tFtfqZEEckEi8H9wKohh6qm1TgwVWn+Fqg Yhew== 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; bh=E5M4utaQdSPOK7d/ONkJSdW7WQYb7VHB3kTyOrltaCk=; b=cTinJ/6s+Qw6jY2NapB2sj66JEe0Bw2SO/yUAAIdhYV+3r8vMDyqmtv52WjMyrwbDt orbgj5lHkM1MbhOqPOl9ILAYzfOXN4OC60PumUjjRy1v0V/FoFlG5EjEiLqi/J+FpU1m 46C+hfRInoPUQSwFOpYTAg9Wk+ZKSP5roUDXaeUVTOZ5PIWPXGqvXi8yCx53oKawtoyh 5LWUP/SMlrRdD5Yi5mqM2KVqWkmQkrDcw/yzYvXrVQWkiemgto/wDWvUCSEB4CV6H3hh 7AP0/2nilaNBBCOSkJQXdBDXxlUq2rIZFUGs5/+DjrQqAgcdkHPE84ARvjSz6mnkEKMR Gk0w== 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 m7si10076739qvq.39.2018.11.12.09.26.25 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 12 Nov 2018 09:26:25 -0800 (PST) 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]:49866 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gMFyi-0001ZY-J0 for patch@linaro.org; Mon, 12 Nov 2018 12:26:24 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60566) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gMFhq-00041G-9k for qemu-devel@nongnu.org; Mon, 12 Nov 2018 12:08:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gMFhp-0000ew-8E for qemu-devel@nongnu.org; Mon, 12 Nov 2018 12:08:58 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:52546) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gMFho-0008MG-Sl for qemu-devel@nongnu.org; Mon, 12 Nov 2018 12:08:57 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1gMFhP-0005t7-2b for qemu-devel@nongnu.org; Mon, 12 Nov 2018 17:08:31 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 12 Nov 2018 17:08:11 +0000 Message-Id: <20181112170816.500-12-peter.maydell@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181112170816.500-1-peter.maydell@linaro.org> References: <20181112170816.500-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 11/16] arm: fix aa64_generate_debug_exceptions to work with EL2 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" From: Alex Bennée The test was incomplete and incorrectly caused debug exceptions to be generated when returning to EL2 after a failed attempt to single-step an EL1 instruction. Fix this while cleaning up the function a little. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson Message-id: 20181109152119.9242-8-alex.bennee@linaro.org Signed-off-by: Peter Maydell --- target/arm/cpu.h | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) -- 2.19.1 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 1efff21a18d..814ff69bc22 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -2764,23 +2764,35 @@ 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) { - if (arm_is_secure(env)) { - /* MDCR_EL3.SDD disables debug events from Secure state */ - if (extract32(env->cp15.mdcr_el3, 16, 1) != 0 - || arm_current_el(env) == 3) { - return false; - } + int cur_el = arm_current_el(env); + int debug_el; + + if (cur_el == 3) { + return false; } - if (arm_current_el(env) == arm_debug_target_el(env)) { - if ((extract32(env->cp15.mdscr_el1, 13, 1) == 0) - || (env->daif & PSTATE_D)) { - 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; } - return true; + + /* + * 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) @@ -2833,9 +2845,6 @@ static inline bool aa32_generate_debug_exceptions(CPUARMState *env) * 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. - * - * Parts of the pseudocode relating to EL2 and EL3 are omitted because we - * don't yet implement those exception levels or their associated trap bits. */ static inline bool arm_generate_debug_exceptions(CPUARMState *env) {