From nobody Sun May 19 10:01:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1562169495; cv=none; d=zoho.com; s=zohoarc; b=VpEGoHyjcWH4NX/jSPB2AQCvpwBsK3C/jJTAjDBMH3SJtGqvjwBolZwunBGeSaammKmdQSZG9CYQ0Hq6AIdenNuUzwQ58w2Irmt///yvdVvXO6kcBnPjyqEgVMtT41NQCnVJxtfCljBJQNa9s0tCv+kBB2PGPhvHVHUQ8B0xtXU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562169495; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=//Wpc08mM5q/cSaFPICPcz9+DodTG0MeCuuW1XebhP8=; b=isO4tFPAHanS98KqHUHNhKhnYD7mR+dwcklHeLSJI2qCtDBiIif2J0EL3oKbrj4pcmH1CXKj8+ydkvI1Bnxo+a0e2j8yQv1raOn26OKg0pgh0mpksxpefUQR2JKswGMC7O5G5yqasJQb3tSiNe/+Ph/uCRwvX879nIcEGRKLsss= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 156216949525235.41207471536359; Wed, 3 Jul 2019 08:58:15 -0700 (PDT) Received: from localhost ([::1]:37062 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hihe7-0005ED-7s for importer@patchew.org; Wed, 03 Jul 2019 11:58:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53215) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hihZS-0002iv-T6 for qemu-devel@nongnu.org; Wed, 03 Jul 2019 11:53:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hihZR-0007Co-Lb for qemu-devel@nongnu.org; Wed, 03 Jul 2019 11:53:22 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:44029) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hihZQ-0006vZ-JF for qemu-devel@nongnu.org; Wed, 03 Jul 2019 11:53:21 -0400 Received: by mail-wr1-x442.google.com with SMTP id p13so3385144wru.10 for ; Wed, 03 Jul 2019 08:52:46 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id f7sm2450062wrp.55.2019.07.03.08.52.44 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 03 Jul 2019 08:52:44 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 68D361FF8C; Wed, 3 Jul 2019 16:52:44 +0100 (BST) 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=//Wpc08mM5q/cSaFPICPcz9+DodTG0MeCuuW1XebhP8=; b=r2Tc0jV3jXYmUHw/XhFIYmFA7bk0IbvAdH+XlCTUwhKfS66u/qbq1WIh2O9aIow4sR hmhg8ZobtYV5Hm5XfHqCdh1Qs8QaQ4vv93SQA8gknih9AdeOO2rBtkxF2GX9seK+8OuJ O0NsaD7VTDG/EOSA4u1mh1kR8fYmuIDfFm3DfvbGCGXeEoHO7tAk7askTTQXxPl/GNjr tzIEILwygns2ATK8pwOevtuo3yaTwoB2jIONF26EPhP/zPS70pXl1nUTCbBx54Tqk04G fZqXY4nllVICnw+y8WWg28T7HB7ZM3m472gHA0U5HkaJZ0C578bkgsVB3OC8RNba1Swl rzJA== 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=//Wpc08mM5q/cSaFPICPcz9+DodTG0MeCuuW1XebhP8=; b=LpRchaEKUPt3TDIoJCM7Bs6y56rELkp0UbDQhkFVZPiaW5/ousX3LAygTymYO1LZ7g w1nGXU2fllN5FpCdFLoik+y7ri9EB6Y+eL5zpXDGooHx+BkjM68D50PeKdhfcUel+NkE JxhLMc8Cey31+PZAcHuYdX24AdVNkvJq9jkl4YI2tFDhH13YeSBLQSkLyLwAukE22k4I vroEMaoyIu34ZYIMdFzv/xDS7dpi2Q8C4ssIBAmy+bKrWLz60qDrcOVHVJqeCvgCUIAS SN0m/B1KoSJXW5PGaQe7Qoh5nQHHWudhU5MYYlKnZzKSQLhLSBu43DI9dEySQtDpn7Aj 5Iig== X-Gm-Message-State: APjAAAVQ7jMf56Fkodu2PcdXeFL4883momMVJSaJZkyBVExI0aGN10kI RlSYZerPYbHSlxtDk7kol0rBEw== X-Google-Smtp-Source: APXvYqxFmxNFk+kiHEsCjSgIx2+OIGhfbuM2kxAPeB1ApIoA7x/UNsPo08LIAdzgvx0j+/s3PgMk5g== X-Received: by 2002:adf:aa93:: with SMTP id h19mr27153178wrc.3.1562169165617; Wed, 03 Jul 2019 08:52:45 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 3 Jul 2019 16:52:41 +0100 Message-Id: <20190703155244.28166-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190703155244.28166-1-alex.bennee@linaro.org> References: <20190703155244.28166-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PATCH v1 1/4] 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: Peter Maydell , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We do this for other semihosting calls so we might as well do it for M-profile as well. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- target/arm/helper.c | 18 ++++++------------ target/arm/translate.c | 20 +++++++++++++++++++- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index df4276f5f6..ad29dc4072 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -9692,19 +9692,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] =3D do_arm_semihosting(env); + return; case EXCP_BKPT: - if (semihosting_enabled()) { - int nr; - nr =3D arm_lduw_code(env, env->regs[15], arm_sctlr_b(env)) & 0= xff; - if (nr =3D=3D 0xab) { - env->regs[15] +=3D 2; - qemu_log_mask(CPU_LOG_INT, - "...handling as semihosting call 0x%x\n", - env->regs[0]); - env->regs[0] =3D 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 4750b9fa1b..aaab043636 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -10977,6 +10977,24 @@ illegal_op: default_exception_el(s)); } =20 +/* + * 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 !=3D 0 && +#endif + (imm8 =3D=3D 0xab)) { + gen_exception_internal_insn(s, 0, EXCP_SEMIHOST); + return; + } + gen_exception_bkpt_insn(s, 2, syn_aa32_bkpt(imm8, true)); +} + static void disas_thumb_insn(DisasContext *s, uint32_t insn) { uint32_t val, op, rm, rn, rd, shift, cond; @@ -11605,7 +11623,7 @@ static void disas_thumb_insn(DisasContext *s, uint3= 2_t insn) { int imm8 =3D extract32(insn, 0, 8); ARCH(5); - gen_exception_bkpt_insn(s, 2, syn_aa32_bkpt(imm8, true)); + gen_thumb_bkpt(s, imm8); break; } =20 --=20 2.20.1 From nobody Sun May 19 10:01:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1562170037; cv=none; d=zoho.com; s=zohoarc; b=EEm1kLiX+qIKnYfdF4TyRo4lG1Ty671FNIeW2AsdR4dVbP/Oec+tJQ9Xi5olD7G8gTVBSUTM6dm3OJgNduQw0RczAYooguBPPp6MdlRUX3g9pmLhn8hATuD5+X8xOIZKkRJF+8sk4ACBdBOFvtBnzCeTfB/OvQ+/3YwtFJB8mps= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562170037; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=C07JYTlYo1eRUyog0KlI6elnxskISjJIiJwzTqYbA+8=; b=BzCPO5g02wHLHG4jpld7cPFhNBr5cbwH1uvd39r27PwEfq+7sWCgQWyWV/V5fAZcvsaLKg8sht+ghjXY5IBG0UuFYgKMYFFJO5XnT4ZfTNl0YievSozmpfGb+ywyJfNNbwZbukCgSrYT65Uc48Bp1n73rzoPw9noIPI/sKHKYA8= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562170037713654.4008910071935; Wed, 3 Jul 2019 09:07:17 -0700 (PDT) Received: from localhost ([::1]:37108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hihmu-0001uG-Ly for importer@patchew.org; Wed, 03 Jul 2019 12:07:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53167) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hihZK-0002hr-Lw for qemu-devel@nongnu.org; Wed, 03 Jul 2019 11:53:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hihZI-00079x-Su for qemu-devel@nongnu.org; Wed, 03 Jul 2019 11:53:13 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:45364) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hihZF-0006w6-Gh for qemu-devel@nongnu.org; Wed, 03 Jul 2019 11:53:10 -0400 Received: by mail-wr1-x443.google.com with SMTP id f9so3383636wre.12 for ; Wed, 03 Jul 2019 08:52:48 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id f204sm4014304wme.18.2019.07.03.08.52.44 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 03 Jul 2019 08:52:45 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 7BE1A1FF8F; Wed, 3 Jul 2019 16:52:44 +0100 (BST) 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=C07JYTlYo1eRUyog0KlI6elnxskISjJIiJwzTqYbA+8=; b=UtJvVyLQpFu+8IgfqaAEMNMXJWLmQyXi+bDVxiCfPuwPqgKn002GhB+RB+WCgmtwJS TsEpn8lLQnlbq2E0s9MXi1OPnHM6+alece4fBnrrIsTUvtx5zm4iTXVn8MqWyavDbZj9 8Hhn8MFlQ0GDEvlWXOAYR26dURU3/EjICp7kRcjNfiI6mXipb0qXJlefUeQdl4xlg+KW B85WWKyksDDgkPa+h2SKbTh4j5tSgonXS/KCQCs0psHRjbuib/zVXZNp307gJkvdtqre HUD/zePH4Kteu1+xOlARFpbHLJBX+lPG9/lh7tKZ15NLRpDa3Amh7tM4ZpbCmsyg+HDg aGmA== 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=C07JYTlYo1eRUyog0KlI6elnxskISjJIiJwzTqYbA+8=; b=qkppvTYUdyJ9FuTXsAaXCM3+M0Y9HtckKM66kc1NLPTkB3NedYL6YuE3jlpfR7f4Dj eZxS+aMGKc/aMNGJuHNrFffw5oJT5Ok90Mge75IiQRvd0QfdwOfyCL3vavEMZYLft3na Pst9FWSz+dEDQTWnFLb7dck5AXYsiSSvoPLdTPXEF23sk7+23IIzsSV8eQS0F/sI4d9A a7SMcBct3PNJF1IakgiiumbuCqkXytb8I6R2SfNKgI4c9tXmDB+MXG0zFNoQwD+9l6ab W+48gz8cEMsgkhkGWIrIIdwqHNVZwXoQV313vy1ZE66IUIxNdeYH3KG4qWLWI/Vn50zz WNMA== X-Gm-Message-State: APjAAAXxldG494MbW+Z5Irv25097iudtGHz3DtFY5imX7XnnJGMCpsqK OwdqzL9yH6Q4THSX635akzKszA== X-Google-Smtp-Source: APXvYqxHnJXkvGG6d8gcPOJYWDokuaIRvBf92J0NCD8K9WvytITZeLvT3IMJd96b+I5OPJCmgwZQOQ== X-Received: by 2002:adf:ed41:: with SMTP id u1mr28077120wro.162.1562169167053; Wed, 03 Jul 2019 08:52:47 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 3 Jul 2019 16:52:42 +0100 Message-Id: <20190703155244.28166-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190703155244.28166-1-alex.bennee@linaro.org> References: <20190703155244.28166-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 v1 2/4] target/arm: handle A-profile T32 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: Peter Maydell , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) As for the other semihosting calls we can resolve this at translate time. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- target/arm/translate.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/target/arm/translate.c b/target/arm/translate.c index aaab043636..8e2e955cbe 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -10995,6 +10995,24 @@ static inline void gen_thumb_bkpt(DisasContext *s,= int imm8) gen_exception_bkpt_insn(s, 2, syn_aa32_bkpt(imm8, true)); } =20 +/* + * Thumb SWI. On A-profile CPUs this may be a semihosting call. + */ +static inline void gen_thumb_swi(DisasContext *s, int imm8) +{ + if (semihosting_enabled() && +#ifndef CONFIG_USER_ONLY + s->current_el !=3D 0 && +#endif + (imm8 =3D=3D 0xab)) { + gen_exception_internal_insn(s, 0, EXCP_SEMIHOST); + return; + } + gen_set_pc_im(s, s->pc); + s->svc_imm =3D imm8; + s->base.is_jmp =3D DISAS_SWI; +} + static void disas_thumb_insn(DisasContext *s, uint32_t insn) { uint32_t val, op, rm, rn, rd, shift, cond; @@ -11752,10 +11770,8 @@ static void disas_thumb_insn(DisasContext *s, uint= 32_t insn) goto undef; =20 if (cond =3D=3D 0xf) { - /* swi */ - gen_set_pc_im(s, s->pc); - s->svc_imm =3D extract32(insn, 0, 8); - s->base.is_jmp =3D DISAS_SWI; + /* swi/svc */ + gen_thumb_swi(s, extract32(insn, 0, 8)); break; } /* generate a conditional jump to next instruction */ --=20 2.20.1 From nobody Sun May 19 10:01:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1562169517; cv=none; d=zoho.com; s=zohoarc; b=ZthBGH0CzzXlT2YmIocA2Z5UHL5cRa5TjmGh4a++DuOO0a9o5E5KSHXgwgjUe1cXkp8NICQuXVOsEIkowACOFbyz1E/0BsPYxQ7PfEtDHXqEYHn5gPFPcdvNkVceTAxvMfUFGerQbJONkByYEIyCMEoP05O9/xBGvC7nqKhF4Ew= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562169517; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=m+82LmGiTUR8ft7yGco+ML19JHV1vi8nCqyq/raGSyc=; b=BzMFkwT8PlnrKDGLms0F17fHpjnDvNJhr0FbDC31XkoIBPQqy4mb1HaAtit2cSIkJlSFM6NoQ5rym0ag8V0JLJYGe79PfaNNvqohebjCma5u1m5ASGPRzLenkhNh+OxShKfXg7Z5UdfAdJrzuXWQS8ARg8gsJTqwxFuEttRcr80= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562169517109556.9414373024008; Wed, 3 Jul 2019 08:58:37 -0700 (PDT) Received: from localhost ([::1]:37066 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hiheW-0005jM-2A for importer@patchew.org; Wed, 03 Jul 2019 11:58:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53155) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hihZI-0002hn-Tk for qemu-devel@nongnu.org; Wed, 03 Jul 2019 11:53:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hihZF-00078s-HL for qemu-devel@nongnu.org; Wed, 03 Jul 2019 11:53:12 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:39524) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hihZ8-0006vo-T4 for qemu-devel@nongnu.org; Wed, 03 Jul 2019 11:53:04 -0400 Received: by mail-wm1-x342.google.com with SMTP id z23so2960627wma.4 for ; Wed, 03 Jul 2019 08:52:47 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id z17sm2708049wrr.13.2019.07.03.08.52.44 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 03 Jul 2019 08:52:45 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 8E6791FF90; Wed, 3 Jul 2019 16:52:44 +0100 (BST) 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+82LmGiTUR8ft7yGco+ML19JHV1vi8nCqyq/raGSyc=; b=amRPd7cNQqjH1DB4/gfYLm89jy4FPHMN4SDAOTlYl49UMvlwIzlxX3i6kWzHPXmiSc DjKL/i1ujAS4CCsnKlOMTPnLlTnQHXVoF8BDVBJPFQFoUMEgaPfiDrun/2Na4t5itmvD v/6bacFZ8tKCvqrXcua92SnsoRUlVwktfxet3QTAZ4GWlLn9WLAA8oGxuU+J79DSkb7D Jt1KbOXQt2I4bI6ow2MGaVttzfG6pRVbr4cj18WVXKpeYjbk4ZkHCh56kzbaZIktY8yl M3rKxqPT6yGXUgFJfEwRsP7h0HolWwfR0eI27elV5CciYyJFvmd/mezmV9LOrVJzlYM6 eXSg== 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=m+82LmGiTUR8ft7yGco+ML19JHV1vi8nCqyq/raGSyc=; b=ocmQfh2MlBKcOfp1jdRHlUa9RIa2mq+EXhwS/9I/LG0ZcR8H+LGKh4jkM/nQB+oPph 7OWQxnmhURCHY61bPN0PJwoq1ix3DlEtU/kmGiXo1XwX49MbJsRzpwxx/Uqhmekgydw0 cI7k3cVGeA7Vt3SDrygHbLmZt95KRIYdY7XNrBzDKsfIT2aNP2l1MkPgIWtxwj9eoVN5 wIf6qwDIUVdLu4xxMOcqIAgAQ1lq0OLzBf1j+0Wn38gH1wPN8IQuJ0/+7qxP+LdZRPpd 04rZcc+ylOhw2QICDgdi2WYSg74iWUgJBKtG6sGEiESBD3HaqlBH1BeXK4UuZQwJ6OHS xDwA== X-Gm-Message-State: APjAAAXIBfCH9j+V/AHMwatsBlF70tGogiwAHkMvvx5zfi6FdSZPaln5 L6vrWEH/XQadI+aJg7K+wOKj7g== X-Google-Smtp-Source: APXvYqx5Hv2/M7GDadMZ561cW2Uzx73M+YYvMv9RY9olcnOsqdViISjtm8sENHnHp+oz9CtJmvdqow== X-Received: by 2002:a1c:7d56:: with SMTP id y83mr8879731wmc.77.1562169166227; Wed, 03 Jul 2019 08:52:46 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 3 Jul 2019 16:52:43 +0100 Message-Id: <20190703155244.28166-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190703155244.28166-1-alex.bennee@linaro.org> References: <20190703155244.28166-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 Subject: [Qemu-devel] [PATCH v1 3/4] target/arm: handle A-profile A32 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: Peter Maydell , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) As for the other semihosting calls we can resolve this at translate time. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- target/arm/translate.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/target/arm/translate.c b/target/arm/translate.c index 8e2e955cbe..139b2f6765 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -7699,6 +7699,22 @@ static void arm_skip_unless(DisasContext *s, uint32_= t cond) arm_gen_test_cc(cond ^ 1, s->condlabel); } =20 +static inline void gen_arm_swi(DisasContext *s, int imm24) +{ + if (semihosting_enabled() && +#ifndef CONFIG_USER_ONLY + s->current_el !=3D 0 && +#endif + (imm24 =3D=3D 0x123456)) { + gen_exception_internal_insn(s, 0, EXCP_SEMIHOST); + return; + } + + gen_set_pc_im(s, s->pc); + s->svc_imm =3D imm24; + s->base.is_jmp =3D DISAS_SWI; +} + static void disas_arm_insn(DisasContext *s, unsigned int insn) { unsigned int cond, val, op1, i, shift, rm, rs, rn, rd, sh; @@ -9249,9 +9265,7 @@ static void disas_arm_insn(DisasContext *s, unsigned = int insn) break; case 0xf: /* swi */ - gen_set_pc_im(s, s->pc); - s->svc_imm =3D extract32(insn, 0, 24); - s->base.is_jmp =3D DISAS_SWI; + gen_arm_swi(s, extract32(insn, 0, 24)); break; default: illegal_op: --=20 2.20.1 From nobody Sun May 19 10:01:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1562170624; cv=none; d=zoho.com; s=zohoarc; b=ZPKyRhHFE317L7+U97M5Khq6UGOk/1texD8TTePwFgNfdKYi65KF7jHllowgvr61CGwilKUsczBiiu0C2ftwMxbFjZNR9Ll/vG2KL1DD6hi6WOz2c1ddOT3z9pa/OGmB6kY8luOFdfW4Eq6Xv9HL5v+czv8hn8E2ZiKZWIzYtyk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562170624; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ovqcHq6dsGzX/8beQxDdY0vSbGoLnH7AOUmxQcUlSms=; b=TEqb3hKSqNyGgHBUbC/4lrq4/HfUhM289rfdPArkM81/RT2hw/bY+Q/rULae9vu2wD945J5Iim4s9M8loNzB+VqzRfVT2j98NZTBInwNNa8NVV0pHTP0uoKr4qzi9SinJgSu/d5ih64XYsDwcaRETnt3O3349XQFGILxAk4Oo+4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562170624552436.9649673826776; Wed, 3 Jul 2019 09:17:04 -0700 (PDT) Received: from localhost ([::1]:37274 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hihwI-0002I5-NN for importer@patchew.org; Wed, 03 Jul 2019 12:16:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53361) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hihZX-0002p4-Sz for qemu-devel@nongnu.org; Wed, 03 Jul 2019 11:53:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hihZT-0007EN-OH for qemu-devel@nongnu.org; Wed, 03 Jul 2019 11:53:25 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:34306) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hihZT-0006wJ-Gw for qemu-devel@nongnu.org; Wed, 03 Jul 2019 11:53:23 -0400 Received: by mail-wr1-x443.google.com with SMTP id u18so3432216wru.1 for ; Wed, 03 Jul 2019 08:52:48 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id p140sm1806472wme.31.2019.07.03.08.52.44 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 03 Jul 2019 08:52:45 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id A17A71FF91; Wed, 3 Jul 2019 16:52:44 +0100 (BST) 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=ovqcHq6dsGzX/8beQxDdY0vSbGoLnH7AOUmxQcUlSms=; b=S2XjhLfSLHaLbB6KoVWUmWxTCSLVAZfvdVBC2zPoO6aO/5mMhuZF1XXJDl1FswHvf/ nKa2bCFG+A2NDIa0Qg5aOAlNbpyVDvF+1nQg0tguiRRF0NzTQFBJCtqCOumJN0UTSZ1K y/vrdzEYq53Xlr32sIm0R3V1XAKwoGa09Hg18xurZOFBCH43QVIV+9ZrfnzNE/aStKwK dmz59rCzAPW0MEb7cGnHcT60i5VmYMi4F6IjAENTY3WJq8r5Q1gCSgJl0EGpyc3NhKTe pNvA5l1woBhSdVC+ZKiZTI4mREsvC29Ar6ZF7WpB0b5ZWf61+//8XJqmvxSUazHcUpTc CL8A== 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=ovqcHq6dsGzX/8beQxDdY0vSbGoLnH7AOUmxQcUlSms=; b=iMCbVWJErm04jMxn83Ns3vgtGoHRy4tvjlHADNp4poJlz5gb/9jbvtzehk/+yC3Hub LaSUaVOLhB4mP9dCaDcbLCbTob13vEccjji6luUYWr7WaiRr1SY5ypqb26oyHjYTjV/U nKGbwxv1HNm4ArEFVenGtvWAMB7OjV2MoBldfGpylGEDvdE0MRQShCYP1Rm+XBWH28cO 5+QzeXJysK/YENMkN5EJXOS+Z8t320p/BJdRV/InPFlHmCO+7SzrfrF69f/tDmw4T7KD yXVYUNkwccQ8SwCSZTolectj6+waKwZCMiD4nNTe8LXJvbdriwEAco6Uo2aOscZrJR9y lZaQ== X-Gm-Message-State: APjAAAUqHirCYtXpae1W9lOMwmlo/Yfx1QXCkRut6pr02xEeU0B+UJ5G 71fhLQn78pJrFaLNnKfZeGIXgQ== X-Google-Smtp-Source: APXvYqwNaDVV4WrWNCVdriCDmCNRcvS9ztCsEBDd6SC7NA28O7FEKO0uY+NmRvPGIdwR1U29nXqPhA== X-Received: by 2002:a5d:4609:: with SMTP id t9mr268861wrq.85.1562169167506; Wed, 03 Jul 2019 08:52:47 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 3 Jul 2019 16:52:44 +0100 Message-Id: <20190703155244.28166-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190703155244.28166-1-alex.bennee@linaro.org> References: <20190703155244.28166-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 v1 4/4] target/arm: remove run time semihosting checks 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: Peter Maydell , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Now we do all our checking and use a common EXCP_SEMIHOST for semihosting operations we can make helper code a lot simpler. Signed-off-by: Alex Benn=C3=A9e --- target/arm/helper.c | 84 +++++++++------------------------------------ 1 file changed, 17 insertions(+), 67 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index ad29dc4072..5c1f741380 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10364,83 +10364,33 @@ static void arm_cpu_do_interrupt_aarch64(CPUState= *cs) new_el, env->pc, pstate_read(env)); } =20 -static inline bool check_for_semihosting(CPUState *cs) +/* + * Check whether this exception is a semihosting call; if so + * then handle it and return true; otherwise return false. + * + * All the permission and validity checks are done at translate time. + */ +static inline bool handle_semihosting(CPUState *cs) { - /* Check whether this exception is a semihosting call; if so - * then handle it and return true; otherwise return false. - */ ARMCPU *cpu =3D ARM_CPU(cs); CPUARMState *env =3D &cpu->env; =20 - if (is_a64(env)) { - if (cs->exception_index =3D=3D EXCP_SEMIHOST) { - /* This is always the 64-bit semihosting exception. - * The "is this usermode" and "is semihosting enabled" - * checks have been done at translate time. - */ + if (cs->exception_index =3D=3D EXCP_SEMIHOST) { + if (is_a64(env)) { qemu_log_mask(CPU_LOG_INT, "...handling as semihosting call 0x%" PRIx64 "\n= ", env->xregs[0]); env->xregs[0] =3D do_arm_semihosting(env); - return true; - } - return false; - } else { - uint32_t imm; - - /* Only intercept calls from privileged modes, to provide some - * semblance of security. - */ - if (cs->exception_index !=3D EXCP_SEMIHOST && - (!semihosting_enabled() || - ((env->uncached_cpsr & CPSR_M) =3D=3D ARM_CPU_MODE_USR))) { - return false; - } - - switch (cs->exception_index) { - case EXCP_SEMIHOST: - /* This is always a semihosting call; the "is this usermode" - * and "is semihosting enabled" checks have been done at - * translate time. - */ - break; - case EXCP_SWI: - /* Check for semihosting interrupt. */ - if (env->thumb) { - imm =3D arm_lduw_code(env, env->regs[15] - 2, arm_sctlr_b(= env)) - & 0xff; - if (imm =3D=3D 0xab) { - break; - } - } else { - imm =3D arm_ldl_code(env, env->regs[15] - 4, arm_sctlr_b(e= nv)) - & 0xffffff; - if (imm =3D=3D 0x123456) { - break; - } - } - return false; - case EXCP_BKPT: - /* See if this is a semihosting syscall. */ - if (env->thumb) { - imm =3D arm_lduw_code(env, env->regs[15], arm_sctlr_b(env)) - & 0xff; - if (imm =3D=3D 0xab) { - env->regs[15] +=3D 2; - break; - } - } - return false; - default: - return false; + } else { + qemu_log_mask(CPU_LOG_INT, + "...handling as semihosting call 0x%x\n", + env->regs[0]); + env->regs[0] =3D do_arm_semihosting(env); } - - qemu_log_mask(CPU_LOG_INT, - "...handling as semihosting call 0x%x\n", - env->regs[0]); - env->regs[0] =3D do_arm_semihosting(env); return true; } + + return false; } =20 /* Handle a CPU exception for A and R profile CPUs. @@ -10476,7 +10426,7 @@ void arm_cpu_do_interrupt(CPUState *cs) * code that caused the exception, not the target exception level, * so must be handled here. */ - if (check_for_semihosting(cs)) { + if (handle_semihosting(cs)) { return; } =20 --=20 2.20.1