From patchwork Wed Sep 4 11:21:04 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: 172918 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1091842ily; Wed, 4 Sep 2019 04:22:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqxR1sLsPOOXHj2J2YVXXDmdGYbgryf7050BYMzlt1tKw0//DW5tznrUJDDgtxvEFb0dSxXf X-Received: by 2002:a50:b0e6:: with SMTP id j93mr21576061edd.169.1567596123592; Wed, 04 Sep 2019 04:22:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567596123; cv=none; d=google.com; s=arc-20160816; b=bIP1u2uhAoXMPcUTjeys3Eqz+kYFavhX2NLHRejuiRKYUFOaNl9Jfk+D0TQaEGROYp 4KAXpdvBJsNeStuJAnCB9N+W/FQIgAvpOLWl2O9aX7M66UgJUgL769TTp9g/UPY2Kodr rPo0mRFwWY9sOLgBL8gNbJM7Aofi7woZEn+XnQrKphHIYWfrVl/kdE0y38VhRd4K3Zrq A43XdC9l4Z/c6bp9+LZVeNgJ/PE86AKlUnutIrFZoUhb4jxsyI6TQWolVcOgnenZNrh1 mHZ5PPg0oExEFBjzeg13LG2cpAyKAgDb2nwa0AtP92z+8ZfmyfxdyxHarjYFsgoq5diM /DSw== 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=k8unDVXpqLg5lphwGOo47n1fiubp2aXlLo/SotwPOPg=; b=J5Ly0XBrv3hmmR1OZHop4BzNyYhfKLVNhVJq26zY3OhwyDbq2c5QLfmgw5E473NbKY PjZosbhWIBu13hK5CHRSrYWmJGecpAqaihV59sq3NWEPA7pOwgjQC3cKFR0iXn1xAjLP 91kx1GZfBG0nxCEcn5Mi479joFiEf3lOMWvcE/vzhi3lFxbzdPHLIS/UBuh2d5ZXqw3s fKbhf4m+H99bQ8KfL/SzsitvfdMOZOf8i2XeWuVrYJK1psWyEqn5SSB67TE47TX8kI1j p6mVmwLoM1IzFR3OM//umBvKmmzEJNLzim6Y6JvuyEPxRjur/FeASNWsZTtfEDVeuoYx xKnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="H7t/DE89"; 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 v4si10298435ejb.275.2019.09.04.04.22.03 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 04 Sep 2019 04:22:03 -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="H7t/DE89"; 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]:56218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5TMQ-0007VG-07 for patch@linaro.org; Wed, 04 Sep 2019 07:22:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36503) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5TLf-00076E-Pr for qemu-devel@nongnu.org; Wed, 04 Sep 2019 07:21:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i5TLd-0007E1-Fx for qemu-devel@nongnu.org; Wed, 04 Sep 2019 07:21:15 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]:37870) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i5TLd-0007Cl-8D for qemu-devel@nongnu.org; Wed, 04 Sep 2019 07:21:13 -0400 Received: by mail-wm1-x335.google.com with SMTP id r195so3238684wme.2 for ; Wed, 04 Sep 2019 04:21:13 -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=k8unDVXpqLg5lphwGOo47n1fiubp2aXlLo/SotwPOPg=; b=H7t/DE89yjsHHkLoLe7eOvU/ei+v20trln0fY4LNKV62HDVgcVHpCl9AF/cZWjBV23 6kbK3qBEt9zti5fO7MMqIyHHCBMH4dVEbM/6mD/PwnL0YBX65K18AcMyRLZcfgjHH/RR YsI8cz9c84iTUSMjB+H0W7HeG8H7tdNSQtyVjYa8eZF+9h2Rkkrhcct/5rxneVuTjpjm exJVpnc9rptHamN/Q9pl7bFcKgN1K5s+K6gQl6Gyt3No+wFLr6Jq2IvWKesCFl4PhPHO ao3hu4++24FvHJB6Nx5/xmMcQkdCm2vNG0+J3K51b3W8hcALWygKLRbCAIi1TlrIuGNb dpOw== 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=k8unDVXpqLg5lphwGOo47n1fiubp2aXlLo/SotwPOPg=; b=gCMUeH7spdsH4mjBoCDrjjcUsDoWynTmJwQX9GuTmaBbr/thzvXwJzP4Of2HB0Wgq2 4XLNQRO2f2PxHjqqNdFWEEnM73fk0qF3qooFaXeeGKhimmMBuBP3AKuwdh3wYbZlqvTo 68CfsAsasPdTZYb6dDSl6cZy9MZnYM6h2ydnXbOa4IFgyhkLrqGXX0bixm8gs+IiaJ48 0EwxYDIlK3bAJ3DoatryO+81j+dKqjV3ucYlc2zEQrss9D/QjWOmQc4YLNzGpfAMRDRJ GR7wntjhoFatkMwHzy55miuoI0dvy+iBSwYwDAvpDHEncn+UCAf5RJp/uK1RoU3BJijQ MEXg== X-Gm-Message-State: APjAAAXPHHSwkC60DGhZqQlZeHflOYgDnMa8zrn45w+PghsbJTX1CFJ/ NSaL7eKvgbZfuETLwWVjBPJgsA== X-Received: by 2002:a1c:e709:: with SMTP id e9mr3987262wmh.65.1567596072093; Wed, 04 Sep 2019 04:21:12 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id a205sm1678669wmd.44.2019.09.04.04.21.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2019 04:21:09 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 23C091FF8C; Wed, 4 Sep 2019 12:21:09 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 4 Sep 2019 12:21:04 +0100 Message-Id: <20190904112108.2341-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190904112108.2341-1-alex.bennee@linaro.org> References: <20190904112108.2341-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::335 Subject: [Qemu-devel] [PATCH v2 1/5] 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 , qemu-arm@nongnu.org, =?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 --- v2 - update for change to gen_exception_internal_insn API --- 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 615859e23c5..816d46b2205 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -10931,6 +10931,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, s->base.pc_next, 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; @@ -11553,7 +11571,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; }