From patchwork Thu Nov 8 16:33:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 150534 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1038420ljp; Thu, 8 Nov 2018 08:37:33 -0800 (PST) X-Google-Smtp-Source: AJdET5evy7v4ycWxxZIV2yGmZ7O04WwV1zchEGm98QErO3HqTopwy7ffzTHtrCYjtw7caqZSBHnn X-Received: by 2002:a0c:90a6:: with SMTP id p35mr5025788qvp.125.1541695052936; Thu, 08 Nov 2018 08:37:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541695052; cv=none; d=google.com; s=arc-20160816; b=Tbs8ZCwXMUKlhA/pib/rFz7K2LAzAxaK8s7rIzKs4KOsugP73LilJa7U4wSxWLxuOK KfHHj76E6hqnQP6I4ChnbXI8dPwU121YGvGh2U+3+4RtWYQY0MiEnmMVaUWZnUBsmiMd 7xoNwShTp20yJhyXD8boSLvCMlVy3bNL3Z84g0tMteK5NUbA1GuyBBz7ay+1fNFz8Niw Isr3IJYxut34TPFX/9VheYsW2Byls7RZtkH5WKnxwSw02WxpLCiJ7afD9Y8xwWCjTf3W QXMglCzGzfPfzTBAWetq79rLJyL10Z9iCzV7P4I8z8ZgJ6AKLTjD/nCoCu+KSJPytk6I xgkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:dkim-signature; bh=ZVCeHrA6mrSycqRGwzmYpbWPY3l4jyoiyxlbXBtrWBw=; b=gLKyjTB6VLs7aEPZHdjig4bu+LLlmlKSn/zD50NrLWAox1A7Tq2F8I+3MdXqZDdkqu +AGwKOr5R0PeWgZbXk4Xs7RW/2MX648himyDKs67pjQDsGpT9ZSu3Mk2tiU3NzZ3gMgh 1uROTEjwcw3FigOwA3FwJImwQgreBdhnWT9yGlyAs+iRHjssBFCgFHtcMWZsM/t19bWx bhIHIQgWreeP7SO4nTOXPUxRhG4nruQhlLyrXIPh07Zu8Xo2L7LhTCpaWzuv8FhUHtxU Yf0N56oD30FqNAGOGZTfjT1lR2J8dTEbzJ9VWP8sSiY/zK13GjPeycfxvGm6uirdT8aa 6m9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="Ntm/WNCQ"; 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 m189-v6si3197983qkf.6.2018.11.08.08.37.32 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 08 Nov 2018 08:37:32 -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; dkim=fail header.i=@linaro.org header.s=google header.b="Ntm/WNCQ"; 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]:57836 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKnJE-0003fX-D0 for patch@linaro.org; Thu, 08 Nov 2018 11:37:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40794) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKnFg-00083d-69 for qemu-devel@nongnu.org; Thu, 08 Nov 2018 11:33:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gKnFe-0004uH-6G for qemu-devel@nongnu.org; Thu, 08 Nov 2018 11:33:52 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:45701) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gKnFd-0004nW-VW for qemu-devel@nongnu.org; Thu, 08 Nov 2018 11:33:50 -0500 Received: by mail-wr1-x443.google.com with SMTP id k15-v6so18957750wre.12 for ; Thu, 08 Nov 2018 08:33:36 -0800 (PST) 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=ZVCeHrA6mrSycqRGwzmYpbWPY3l4jyoiyxlbXBtrWBw=; b=Ntm/WNCQ+h8DTZ6qYRlLYuMtu71ngOReYZrASRBcX/KmEMnaM3GKX5hCbQT4uyKdA1 GhIcDA6yfoO5cvXHWKejf1XTJ84cFLgTwgUHJUZUZvZRq7z4jUhzkWS/Zm90WXpL39kY cvM0UEA9NQpaZKAgWhMojc3rgnic3coIhnQto= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZVCeHrA6mrSycqRGwzmYpbWPY3l4jyoiyxlbXBtrWBw=; b=cTQaN2k67CkhAzBb4nzlWM07M+Z8OhgRF+VpJ5wDOtlLb9fjF5lWm/zsMNwpJ/wTlt OxqOUi4ToOQM6jSVXqnyBMfQtANK6vTWH7lJE4rC5PimGsfAykhaTT8vRY2FbDWVgtQe vNomPGWB6AWX4wHnNQMRugPcyHjUnpcLtldGVgq6WUijfvF3ZZnAGB//snZdkxIHR1wx M9UYpStGWw9YdytUMcbQtHN9VSuxwxYLGb+BwrcvDGeakrXVPCsT+tYxWEFlAyR9F7FI N27pTSrSBfa3BSTgYcfAC4cXw/Z9UWQeVbB2/DAf5YZx4LRD6fvLHGBiA6O2MWRb9EiT j+2w== X-Gm-Message-State: AGRZ1gKP8zIkRfKep4qMZTy+Wt6RTPRUTSBR/de0+xOj9Jne1ykxGuHI EiZwsUkiMSCceRsa3wZy/DWKvA== X-Received: by 2002:a5d:6a0e:: with SMTP id m14-v6mr4897102wru.76.1541694815197; Thu, 08 Nov 2018 08:33:35 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id e8-v6sm4243641wrw.75.2018.11.08.08.33.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 08 Nov 2018 08:33:32 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 59D063E059D; Thu, 8 Nov 2018 16:33:30 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Thu, 8 Nov 2018 16:33:29 +0000 Message-Id: <20181108163329.19940-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181108163329.19940-1-alex.bennee@linaro.org> References: <20181108163329.19940-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 Subject: [Qemu-devel] [PATCH v2 6/6] 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: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, =?utf-8?q?Alex_Benn?= =?utf-8?b?w6ll?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- target/arm/cpu.h | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) -- 2.17.1 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 1efff21a18..a6d8eb14f6 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -2764,23 +2764,33 @@ 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 (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) { + || 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; - } + /* + * 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); } - return true; + + /* 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 +2843,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) {