From patchwork Wed Aug 28 16:52:59 2019 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: 172407 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1038789ily; Wed, 28 Aug 2019 10:11:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqw12cVJZgD1ZoNMkarfYM5cl9AGnT1i6A7wivvCV9uouZaIAMQY0xfHK20EOMLWjMJTjKaP X-Received: by 2002:a17:906:f2d0:: with SMTP id gz16mr4081880ejb.21.1567012311439; Wed, 28 Aug 2019 10:11:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567012311; cv=none; d=google.com; s=arc-20160816; b=HDQOP9HK7Rx7Ze+9crzEqIU9T+nbyCSnuD90ROEORT+2HcjPKh5c4+NrvNetGc7SAy BvPHIGsT//fBxEVOZInr+gVmKHviu9lUQ4uwQ32TVmFajXQwkMjmDFbpABQ5Yilis18t ZKSV7f8SO8pAZzSjCwqxNeJJpgAWpKuhw8PZBlNKq5oEG7qZuYMYzvE5DMvUjat5zsW2 k0w4wI48n8etQ2Hm8qL4hvzfIoMY8eOSI1RlyOWLn6TW6H3ItHIK9hwp+g31cgx8uAnv pzqT9Akog54KAGnHVLHI0X78zgUj39aPEG9dlot2nHzIn7XdHKTGxV2TZ9hdbAbzlW8p CpCA== 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=+VsIgRrN67nvrM6dUapwHSRZMRTN8JnYHQijkeU8PPk=; b=MYodTt09hoIboDVaWgGZXy6ZtfeI48hRenpPTxjkm0BIPMFid2vhy7Uu8ielO2++xK 0PBF0Cz4ayBSAcadfxutHqVZklOmP6LPWEP35SSWNLgz8DGj+jffptxzl6eATxrtrd5a gz29vv87A8BzzSZHrv/4JrHrMNtpzPJuFogpdrrJ4RixFgQt9exYp+kEgdiL7PWXnQAf R9NhJHLAS3HW+Ng7VY2tWZrHE5HSJjv+cfjRSydGNteB0+er1rJfs82C8RPBmsxnRZaK tJembBYvnKmkAMUyUjKR1Y1wj9OzGJSaXDS9oZavO+ZZ5/0Ey0pYkCBXG8NlEOa6lfhk Fujw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=lCK8FqcR; 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=fail (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 v8si1569142ejh.248.2019.08.28.10.11.51 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Aug 2019 10:11:51 -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=fail header.i=@linaro.org header.s=google header.b=lCK8FqcR; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:38970 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i31U6-0001Uy-8U for patch@linaro.org; Wed, 28 Aug 2019 13:11:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42344) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i31C7-0007eN-Gq for qemu-devel@nongnu.org; Wed, 28 Aug 2019 12:53:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i31C2-0000p5-Tl for qemu-devel@nongnu.org; Wed, 28 Aug 2019 12:53:14 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:36223) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i31C2-0000nz-LP for qemu-devel@nongnu.org; Wed, 28 Aug 2019 12:53:10 -0400 Received: by mail-wm1-x32d.google.com with SMTP id p13so811719wmh.1 for ; Wed, 28 Aug 2019 09:53:10 -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=+VsIgRrN67nvrM6dUapwHSRZMRTN8JnYHQijkeU8PPk=; b=lCK8FqcRx51jauPL29c8h2ZpVZ+o8lpBXnxS3n4EUFkrQXU2X2FXwu6cMwxOrkxl/9 M+ZVSrgojBpnjbjgNKDYTJ/KUYOE6qYK04ZykcpORYGup5T0oTMJgX3RpoJfPLt0xxj4 Y8moF3p7wFzxureUrdsr4S4ot5w5uqDt8GL1WVE14W/vqJQxdbMlzlaMHfQ5C9qlJ4P1 qm+2hdCKaCSfLZS6aiJjdFIEUebEOog6X21fZ8ddyXq5akBxgs2revDAi+AtbY4+NIdz sD32x0m/iF5uRs9pwJEVcNCy5GzVG8LZtb82I0Kzmt+IO4GH95bLgP+jnavVB/2Vhvdp xkpA== 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=+VsIgRrN67nvrM6dUapwHSRZMRTN8JnYHQijkeU8PPk=; b=MT9rHkyhRv/0BG3mIuAKQy0nJsFjyVddkRuTToD3YJDT1NoLeJAA5OW2/i67CBGau3 ycSwfJBm/BqFoL4JpsSMwOVy8mi//9KOyGEzW8I9P4MLdmIBLRQaJqKVh6APekD0645C gMZPf8xH9v7ppwPLVh0WIQjTh8U6HsAKs2QGNY6gIaACQawgr+1RAp4ROgi+68hmCpyh 1SPEX5iemFpomYsuO0ktvSZX5j0Ftqp0RCWOaHAUzgVzuhymDFfLvtjH5v6DKHganvS9 bbdws/Mx63w9eNFGHQ/bF+NlwshyVVn5wGG7D6B+E6xtjUEc+XTAiysGfSXSjEhB3ycI ucqw== X-Gm-Message-State: APjAAAU7bGQ7xs9nIVDEEvmSrr1qG1AWm0U/om5WCmR3keYIZWfh8JI0 EanWO7seuQOgVjOhsN7JFiDtBA== X-Received: by 2002:a1c:1a4b:: with SMTP id a72mr5066400wma.44.1567011189500; Wed, 28 Aug 2019 09:53:09 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id f197sm7699042wme.22.2019.08.28.09.53.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2019 09:53:08 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 7D8541FF8C; Wed, 28 Aug 2019 17:53:07 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 28 Aug 2019 17:52:59 +0100 Message-Id: <20190828165307.18321-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190828165307.18321-1-alex.bennee@linaro.org> References: <20190828165307.18321-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::32d Subject: [Qemu-devel] [PATCH v1 1/9] target/arm: handle M-profile semihosting at translate time X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , "open list:ARM TCG CPUs" , =?utf-8?q?Alex_Benn=C3=A9e?= , Peter Maydell Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We do this for other semihosting calls so we might as well do it for M-profile as well. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- target/arm/m_helper.c | 18 ++++++------------ target/arm/translate.c | 20 +++++++++++++++++++- 2 files changed, 25 insertions(+), 13 deletions(-) -- 2.20.1 diff --git a/target/arm/m_helper.c b/target/arm/m_helper.c index 884d35d2b02..27cd2f3f964 100644 --- a/target/arm/m_helper.c +++ b/target/arm/m_helper.c @@ -2114,19 +2114,13 @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) break; } break; + case EXCP_SEMIHOST: + qemu_log_mask(CPU_LOG_INT, + "...handling as semihosting call 0x%x\n", + env->regs[0]); + env->regs[0] = do_arm_semihosting(env); + return; case EXCP_BKPT: - if (semihosting_enabled()) { - int nr; - nr = arm_lduw_code(env, env->regs[15], arm_sctlr_b(env)) & 0xff; - if (nr == 0xab) { - env->regs[15] += 2; - qemu_log_mask(CPU_LOG_INT, - "...handling as semihosting call 0x%x\n", - env->regs[0]); - env->regs[0] = do_arm_semihosting(env); - return; - } - } armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_DEBUG, false); break; case EXCP_IRQ: diff --git a/target/arm/translate.c b/target/arm/translate.c index cbe19b7a625..259c4669b4c 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -10889,6 +10889,24 @@ illegal_op: unallocated_encoding(s); } +/* + * Thumb BKPT. On M-profile CPUs this may be a semihosting call which + * we can process much the same way as gen_hlt() above. + */ +static inline void gen_thumb_bkpt(DisasContext *s, int imm8) +{ + if (arm_dc_feature(s, ARM_FEATURE_M) && + semihosting_enabled() && +#ifndef CONFIG_USER_ONLY + s->current_el != 0 && +#endif + (imm8 == 0xab)) { + gen_exception_internal_insn(s, 0, EXCP_SEMIHOST); + return; + } + gen_exception_bkpt_insn(s, syn_aa32_bkpt(imm8, true)); +} + static void disas_thumb_insn(DisasContext *s, uint32_t insn) { uint32_t val, op, rm, rn, rd, shift, cond; @@ -11511,7 +11529,7 @@ static void disas_thumb_insn(DisasContext *s, uint32_t insn) { int imm8 = extract32(insn, 0, 8); ARCH(5); - gen_exception_bkpt_insn(s, syn_aa32_bkpt(imm8, true)); + gen_thumb_bkpt(s, imm8); break; }