From nobody Tue May 14 11:35:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1661183546; cv=none; d=zohomail.com; s=zohoarc; b=c0okc7SRd43+ZRu9+9NQDtXM/hCmgKkCMp3ISAaJpX4H+r0XUdIEUP5bQmRaVOU0UGep7pKExZebVQnvaqC8ggmc9dwBV8WmVh3BBTNCG/lAON8J66VHwwTPJMuVPvry1sqcinZTnxRX96hNXotjMEjveXqVolTnD/7sIA6NQBg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661183546; 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; bh=tgYp8pGSL/yP8rNDGx87irTnIRryu2Jy8l6csISMVyE=; b=PK1ZE+5przrA3jvq0DEcouZG9SBN1YFbfxmkIy95rweAGxtwC/W5bb5Ue0uQYBpmanBsfIHRGs07FToapuV42C5av7tbIzotMzdBpf4WvQXNFGMxFQ0bPvSLA3364sbhvG/3wl6OD3UVSwRwRPTSIjIAak3Oyq3dfuLlukIrsAo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1661183546968757.5032189675128; Mon, 22 Aug 2022 08:52:26 -0700 (PDT) Received: from localhost ([::1]:53622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQ9iy-00070W-Si for importer@patchew.org; Mon, 22 Aug 2022 11:52:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39458) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQ9Fe-0005Tn-L9 for qemu-devel@nongnu.org; Mon, 22 Aug 2022 11:22:07 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:52949) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oQ9FP-0006e3-LW for qemu-devel@nongnu.org; Mon, 22 Aug 2022 11:22:06 -0400 Received: by mail-wm1-x32d.google.com with SMTP id k17so5779113wmr.2 for ; Mon, 22 Aug 2022 08:21:51 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id bh16-20020a05600c3d1000b003a3561d4f3fsm15184908wmb.43.2022.08.22.07.12.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 07:12:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=tgYp8pGSL/yP8rNDGx87irTnIRryu2Jy8l6csISMVyE=; b=Lm6JRSzrf03gWEOeY9tdpYbqWznAzcl0TVl3ZPXX6ZmvvzpNK2//83x2aJAM06S7Av v7Qq6RQoxYu/GcVoqlaXObiLiibDw3JMnCUfwLSMl8najL6wMEpitUrx7yB9I4g8ZjDG bqyoaZ1PT926glYEuF+MVbjVZg2DWxNPNB7C2Z9JVkGDC+Rrlbqn9kyZw2JEGgH5bpMa TG/liXmWD9D6PHQQtmC+1pYZY+CfPHB9mWp8W6ejPHgtrNf0b3kojMJdOZ/PXyHsIKOL y7dxfLVtHei3pcARWlUu7m/BlxQqKfeEY99qTzB19AITeFy802GoHEbxWGG4O0B3EpW2 c9HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=tgYp8pGSL/yP8rNDGx87irTnIRryu2Jy8l6csISMVyE=; b=CU6rkHyIj8xbcZ4dgHOdq4Xs2ucE+ntYPeKgrRqHhVI3OGJ/K4S4L3V3FRX207u9bC dmOTq/eF8gPzRs48K1FStpdd8aUY180g7TujURVjgEQrTtdXyEKUHg2SSGhDjMLULrH5 xjI+JgHhBGBCZxgIah4I9Q24DmvWGNkxWw1ojrVD/1IcPnhDWfGo2e7SoCujGEVOOm0e oHpozuLLKiEVbx/sYca2WK6diVA5XgpeQK87yoLyQt8soKZs0W0RRRrUES/VjfInVhH3 IgVVRyw6vM6KfclpgE0XBgv3VIUjUwi+mL/SLf4r+cG++yFFnySYTaGR17rgD7NDinEK MbtA== X-Gm-Message-State: ACgBeo3sPx1ZBvcULzQFtZ180D//78YfEyxbjvIxU2aRmjAL+1KmakTL 9Q4t4aXhNxOU6RdFfJL2cHXde8ref2OEOw== X-Google-Smtp-Source: AA6agR5PZvvjdzG5GoUuvrb4Pkrzdh/ekcWIV3LXaDiBttEFTzawPDM3aLTbmOrlMJ/7YbXFIL9zVA== X-Received: by 2002:a05:600c:3ac9:b0:3a5:f114:1f8 with SMTP id d9-20020a05600c3ac900b003a5f11401f8mr11961417wms.204.1661177555357; Mon, 22 Aug 2022 07:12:35 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Richard Henderson , qemu-riscv@nongnu.org, Palmer Dabbelt , Bin Meng , Alistair Francis , Furquan Shaikh Subject: [PATCH v2 1/7] semihosting: Allow optional use of semihosting from userspace Date: Mon, 22 Aug 2022 15:12:24 +0100 Message-Id: <20220822141230.3658237-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220822141230.3658237-1-peter.maydell@linaro.org> References: <20220822141230.3658237-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1661183547984100001 Currently our semihosting implementations generally prohibit use of semihosting calls in system emulation from the guest userspace. This is a very long standing behaviour justified originally "to provide some semblance of security" (since code with access to the semihosting ABI can do things like read and write arbitrary files on the host system). However, it is sometimes useful to be able to run trusted guest code which performs semihosting calls from guest userspace, notably for test code. Add a command line suboption to the existing semihosting-config option group so that you can explicitly opt in to semihosting from guest userspace with -semihosting-config userspace=3Don (There is no equivalent option for the user-mode emulator, because there by definition all code runs in userspace and has access to semihosting already.) This commit adds the infrastructure for the command line option and adds a bool 'is_user' parameter to the function semihosting_userspace_enabled() that target code can use to check whether it should be permitting the semihosting call for userspace. It mechanically makes all the callsites pass 'false', so they continue checking "is semihosting enabled in general". Subsequent commits will make each target that implements semihosting honour the userspace=3Don option by passing the correct value and removing whatever "don't do this for userspace" checking they were doing by hand. Signed-off-by: Peter Maydell Acked-by: Alex Benn=C3=A9e Reviewed-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- include/semihosting/semihost.h | 10 ++++++++-- semihosting/config.c | 10 ++++++++-- softmmu/vl.c | 2 +- stubs/semihost.c | 2 +- target/arm/translate-a64.c | 2 +- target/arm/translate.c | 6 +++--- target/m68k/op_helper.c | 2 +- target/nios2/translate.c | 2 +- target/xtensa/translate.c | 6 +++--- qemu-options.hx | 11 +++++++++-- 10 files changed, 36 insertions(+), 17 deletions(-) diff --git a/include/semihosting/semihost.h b/include/semihosting/semihost.h index 93a3c21b44d..efd2efa25ae 100644 --- a/include/semihosting/semihost.h +++ b/include/semihosting/semihost.h @@ -27,7 +27,7 @@ typedef enum SemihostingTarget { } SemihostingTarget; =20 #ifdef CONFIG_USER_ONLY -static inline bool semihosting_enabled(void) +static inline bool semihosting_enabled(bool is_user) { return true; } @@ -52,7 +52,13 @@ static inline const char *semihosting_get_cmdline(void) return NULL; } #else /* !CONFIG_USER_ONLY */ -bool semihosting_enabled(void); +/** + * semihosting_enabled: + * @is_user: true if guest code is in usermode (i.e. not privileged) + * + * Return true if guest code is allowed to make semihosting calls. + */ +bool semihosting_enabled(bool is_user); SemihostingTarget semihosting_get_target(void); const char *semihosting_get_arg(int i); int semihosting_get_argc(void); diff --git a/semihosting/config.c b/semihosting/config.c index e171d4d6bc3..89a17596879 100644 --- a/semihosting/config.c +++ b/semihosting/config.c @@ -34,6 +34,9 @@ QemuOptsList qemu_semihosting_config_opts =3D { { .name =3D "enable", .type =3D QEMU_OPT_BOOL, + }, { + .name =3D "userspace", + .type =3D QEMU_OPT_BOOL, }, { .name =3D "target", .type =3D QEMU_OPT_STRING, @@ -50,6 +53,7 @@ QemuOptsList qemu_semihosting_config_opts =3D { =20 typedef struct SemihostingConfig { bool enabled; + bool userspace_enabled; SemihostingTarget target; char **argv; int argc; @@ -59,9 +63,9 @@ typedef struct SemihostingConfig { static SemihostingConfig semihosting; static const char *semihost_chardev; =20 -bool semihosting_enabled(void) +bool semihosting_enabled(bool is_user) { - return semihosting.enabled; + return semihosting.enabled && (!is_user || semihosting.userspace_enabl= ed); } =20 SemihostingTarget semihosting_get_target(void) @@ -137,6 +141,8 @@ int qemu_semihosting_config_options(const char *optarg) if (opts !=3D NULL) { semihosting.enabled =3D qemu_opt_get_bool(opts, "enable", true); + semihosting.userspace_enabled =3D qemu_opt_get_bool(opts, "userspa= ce", + false); const char *target =3D qemu_opt_get(opts, "target"); /* setup of chardev is deferred until they are initialised */ semihost_chardev =3D qemu_opt_get(opts, "chardev"); diff --git a/softmmu/vl.c b/softmmu/vl.c index 706bd7cff79..3593f1d7821 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -1822,7 +1822,7 @@ static void qemu_apply_machine_options(QDict *qdict) { object_set_properties_from_keyval(OBJECT(current_machine), qdict, fals= e, &error_fatal); =20 - if (semihosting_enabled() && !semihosting_get_argc()) { + if (semihosting_enabled(false) && !semihosting_get_argc()) { /* fall back to the -kernel/-append */ semihosting_arg_fallback(current_machine->kernel_filename, current= _machine->kernel_cmdline); } diff --git a/stubs/semihost.c b/stubs/semihost.c index f486651afbb..d65c9fd5dcf 100644 --- a/stubs/semihost.c +++ b/stubs/semihost.c @@ -23,7 +23,7 @@ QemuOptsList qemu_semihosting_config_opts =3D { }; =20 /* Queries to config status default to off */ -bool semihosting_enabled(void) +bool semihosting_enabled(bool is_user) { return false; } diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 163df8c6157..3decc8da573 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -2219,7 +2219,7 @@ static void disas_exc(DisasContext *s, uint32_t insn) * it is required for halting debug disabled: it will UNDEF. * Secondly, "HLT 0xf000" is the A64 semihosting syscall instructi= on. */ - if (semihosting_enabled() && imm16 =3D=3D 0xf000) { + if (semihosting_enabled(false) && imm16 =3D=3D 0xf000) { #ifndef CONFIG_USER_ONLY /* In system mode, don't allow userspace access to semihosting, * to provide some semblance of security (and for consistency diff --git a/target/arm/translate.c b/target/arm/translate.c index ad617b99481..b85be8a818d 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -1169,7 +1169,7 @@ static inline void gen_hlt(DisasContext *s, int imm) * semihosting, to provide some semblance of security * (and for consistency with our 32-bit semihosting). */ - if (semihosting_enabled() && + if (semihosting_enabled(false) && #ifndef CONFIG_USER_ONLY s->current_el !=3D 0 && #endif @@ -6556,7 +6556,7 @@ static bool trans_BKPT(DisasContext *s, arg_BKPT *a) /* BKPT is OK with ECI set and leaves it untouched */ s->eci_handled =3D true; if (arm_dc_feature(s, ARM_FEATURE_M) && - semihosting_enabled() && + semihosting_enabled(false) && #ifndef CONFIG_USER_ONLY !IS_USER(s) && #endif @@ -8764,7 +8764,7 @@ static bool trans_SVC(DisasContext *s, arg_SVC *a) { const uint32_t semihost_imm =3D s->thumb ? 0xab : 0x123456; =20 - if (!arm_dc_feature(s, ARM_FEATURE_M) && semihosting_enabled() && + if (!arm_dc_feature(s, ARM_FEATURE_M) && semihosting_enabled(false) && #ifndef CONFIG_USER_ONLY !IS_USER(s) && #endif diff --git a/target/m68k/op_helper.c b/target/m68k/op_helper.c index d9937ca8dc5..4b3dfec1306 100644 --- a/target/m68k/op_helper.c +++ b/target/m68k/op_helper.c @@ -203,7 +203,7 @@ static void cf_interrupt_all(CPUM68KState *env, int is_= hw) cf_rte(env); return; case EXCP_HALT_INSN: - if (semihosting_enabled() + if (semihosting_enabled(false) && (env->sr & SR_S) !=3D 0 && (env->pc & 3) =3D=3D 0 && cpu_lduw_code(env, env->pc - 4) =3D=3D 0x4e71 diff --git a/target/nios2/translate.c b/target/nios2/translate.c index 3a037a68cc4..2b556683422 100644 --- a/target/nios2/translate.c +++ b/target/nios2/translate.c @@ -818,7 +818,7 @@ static void gen_break(DisasContext *dc, uint32_t code, = uint32_t flags) #ifndef CONFIG_USER_ONLY /* The semihosting instruction is "break 1". */ R_TYPE(instr, code); - if (semihosting_enabled() && instr.imm5 =3D=3D 1) { + if (semihosting_enabled(false) && instr.imm5 =3D=3D 1) { t_gen_helper_raise_exception(dc, EXCP_SEMIHOST); return; } diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c index 70e11eeb459..dc475a4274b 100644 --- a/target/xtensa/translate.c +++ b/target/xtensa/translate.c @@ -2364,9 +2364,9 @@ static uint32_t test_exceptions_simcall(DisasContext = *dc, bool ill =3D true; #else /* Between RE.2 and RE.3 simcall opcode's become nop for the hardware.= */ - bool ill =3D dc->config->hw_version <=3D 250002 && !semihosting_enable= d(); + bool ill =3D dc->config->hw_version <=3D 250002 && !semihosting_enable= d(false); #endif - if (ill || !semihosting_enabled()) { + if (ill || !semihosting_enabled(false)) { qemu_log_mask(LOG_GUEST_ERROR, "SIMCALL but semihosting is disable= d\n"); } return ill ? XTENSA_OP_ILL : 0; @@ -2376,7 +2376,7 @@ static void translate_simcall(DisasContext *dc, const= OpcodeArg arg[], const uint32_t par[]) { #ifndef CONFIG_USER_ONLY - if (semihosting_enabled()) { + if (semihosting_enabled(false)) { gen_helper_simcall(cpu_env); } #endif diff --git a/qemu-options.hx b/qemu-options.hx index 3f23a42fa87..4e7111abe3d 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4614,12 +4614,12 @@ SRST information about the facilities this enables. ERST DEF("semihosting-config", HAS_ARG, QEMU_OPTION_semihosting_config, - "-semihosting-config [enable=3Don|off][,target=3Dnative|gdb|auto][,cha= rdev=3Did][,arg=3Dstr[,...]]\n" \ + "-semihosting-config [enable=3Don|off][,target=3Dnative|gdb|auto][,cha= rdev=3Did][,userspace=3Don|off][,arg=3Dstr[,...]]\n" \ " semihosting configuration\n", QEMU_ARCH_ARM | QEMU_ARCH_M68K | QEMU_ARCH_XTENSA | QEMU_ARCH_MIPS | QEMU_ARCH_NIOS2 | QEMU_ARCH_RISCV) SRST -``-semihosting-config [enable=3Don|off][,target=3Dnative|gdb|auto][,charde= v=3Did][,arg=3Dstr[,...]]`` +``-semihosting-config [enable=3Don|off][,target=3Dnative|gdb|auto][,charde= v=3Did][,userspace=3Don|off][,arg=3Dstr[,...]]`` Enable and configure semihosting (ARM, M68K, Xtensa, MIPS, Nios II, RI= SC-V only). =20 @@ -4646,6 +4646,13 @@ SRST Send the output to a chardev backend output for native or auto output when not in gdb =20 + ``userspace=3Don|off`` + Allows code running in guest userspace to access the semihosting + interface. The default is that only privileged guest code can + make semihosting calls. Note that setting ``userspace=3Don`` should + only be used if all guest code is trusted (for example, in + bare-metal test case code). + ``arg=3Dstr1,arg=3Dstr2,...`` Allows the user to pass input arguments, and can be used multiple times to build up a list. The old-style --=20 2.25.1 From nobody Tue May 14 11:35:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1661181434; cv=none; d=zohomail.com; s=zohoarc; b=jTKJA5DICUUbtT0cimnxkGfthLZBZMJZEgErf7kMMO+Wz9nvLppi7BVzj1w5EyxKewEo+0k+n4N5/HFA8alAQgFsacRiv5BcTw1Ib38gEq8XG2GIbGSorwHZ4KjPx+7A+dRXn7S+ir3VhHoK/hTqiGxwgbJ2exzScqc2upuQo9w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661181434; h=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; bh=6VBB9l/n2pBbDajK4ZQ84clibkYsxsKuyND2MJ/GRek=; b=cN020dfRTdVMp45P6SC0G24qE+ZKCvII+2cvI3UfromjLNM1BKjHQ3d18f8P0pMWJsMMEE0keqe7NFuY0Rb7WrLc1C3CoC416c0TXtDMoefBQRbYO5zj0qVKB7mres1sGKh2MNGi/P5pIRkC6VnJksSVw1ZXK+k0QlNrfiFKqD8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 166118143468020.63735697709808; Mon, 22 Aug 2022 08:17:14 -0700 (PDT) Received: from localhost ([::1]:52632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQ9Av-0008Sx-1g for importer@patchew.org; Mon, 22 Aug 2022 11:17:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55016) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQ95s-0001hu-BJ for qemu-devel@nongnu.org; Mon, 22 Aug 2022 11:12:02 -0400 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]:44898) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oQ95p-0004CM-DT for qemu-devel@nongnu.org; Mon, 22 Aug 2022 11:12:00 -0400 Received: by mail-ed1-x529.google.com with SMTP id t5so14338084edc.11 for ; Mon, 22 Aug 2022 08:11:56 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id bh16-20020a05600c3d1000b003a3561d4f3fsm15184908wmb.43.2022.08.22.07.12.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 07:12:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=6VBB9l/n2pBbDajK4ZQ84clibkYsxsKuyND2MJ/GRek=; b=OORXop52lSdOH4LMflg63bssXPv9O7aWUa1w6cTZjE62j94jBdRiQhF5PK3storUZ6 C1XtroImnTCN9+oxSirb65fWpxy7LpPuog2y3TFGNZom2xvvlw4Ehbzmi8pBrzbT21jT unHw9fl9qhF6wfpJC0cVm+FNPx2Z+U9Ts9r0MEmE8rUHp3qRK3SUJw9zSxwjuJVDW8yX nxE4mkFY2f6wDy7lYFT+avXSxMHDkbHOydCLQfNBSil71QLT2evXoG3mrYIgMjZMRPfQ D9DHLVmNhZDXnWgyIkgcwmWw4pCGBKexTzTblKx4uQe7hb04qT/zfc9dvXlWUlGS00X3 fjHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=6VBB9l/n2pBbDajK4ZQ84clibkYsxsKuyND2MJ/GRek=; b=B4aCvErgRjT4drJpgnMmH98xL/l7ZYqUSoialfS7twSZLIzAMQvE5H+SwHR3y/vvh+ N2rl4oHL4IBpLrNAP20goDHji4M/whdJncPPmR0vvZ0JruHtzA91tEwnI3t4mVX9Pt7z gSafdoWRubp1LWniuom8xv2v5PNEmOOBPuB4yyCJh0cBnGoOejjs95Tni7XCrj01YlBG Cet8wObV05PW8tnIJi9pg9W2HUhx/X+zH2n2Z0EkG/Q7Td8s3G0Z4ZKtL3kOmHBDz/Yo Q9mNL2ZcyZWGpeUgfFkohcu61UFOzfe6N0Ermd/Tvs6fbg/OiJTY9ArGaJCj81HGrkRU prJg== X-Gm-Message-State: ACgBeo3pFPocOypM+4Dy40E3lnZ2syvZ099wBqv/NQi+awge3wuh29qv pSekRrCOJ8TJ6vG0Fqc8ezBtsLJYDeoVbQ== X-Google-Smtp-Source: AA6agR5NnWqo0faEoytSCdzNehB1/BpYZsIE003L3ye9+dsqgXSr8fkbvWBJyrXs4oYKwgoKyXrRfg== X-Received: by 2002:adf:cd86:0:b0:225:1a3a:d984 with SMTP id q6-20020adfcd86000000b002251a3ad984mr11390880wrj.212.1661177556635; Mon, 22 Aug 2022 07:12:36 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Richard Henderson , qemu-riscv@nongnu.org, Palmer Dabbelt , Bin Meng , Alistair Francis , Furquan Shaikh Subject: [PATCH v2 2/7] target/arm: Honour -semihosting-config userspace=on Date: Mon, 22 Aug 2022 15:12:25 +0100 Message-Id: <20220822141230.3658237-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220822141230.3658237-1-peter.maydell@linaro.org> References: <20220822141230.3658237-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2a00:1450:4864:20::529; envelope-from=peter.maydell@linaro.org; helo=mail-ed1-x529.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1661181435251100001 Content-Type: text/plain; charset="utf-8" Honour the commandline -semihosting-config userspace=3Don option, instead of never permitting userspace semihosting calls in system emulation mode, by passing the correct value to the is_userspace argument of semihosting_enabled(), instead of manually checking and always forbidding semihosting if the guest is in userspace and this isn't the linux-user build. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- target/arm/translate-a64.c | 12 +----------- target/arm/translate.c | 16 ++++------------ 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 3decc8da573..9bed336b47e 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -2219,17 +2219,7 @@ static void disas_exc(DisasContext *s, uint32_t insn) * it is required for halting debug disabled: it will UNDEF. * Secondly, "HLT 0xf000" is the A64 semihosting syscall instructi= on. */ - if (semihosting_enabled(false) && imm16 =3D=3D 0xf000) { -#ifndef CONFIG_USER_ONLY - /* In system mode, don't allow userspace access to semihosting, - * to provide some semblance of security (and for consistency - * with our 32-bit semihosting). - */ - if (s->current_el =3D=3D 0) { - unallocated_encoding(s); - break; - } -#endif + if (semihosting_enabled(s->current_el =3D=3D 0) && imm16 =3D=3D 0x= f000) { gen_exception_internal_insn(s, s->pc_curr, EXCP_SEMIHOST); } else { unallocated_encoding(s); diff --git a/target/arm/translate.c b/target/arm/translate.c index b85be8a818d..54543b7c2a8 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -1169,10 +1169,7 @@ static inline void gen_hlt(DisasContext *s, int imm) * semihosting, to provide some semblance of security * (and for consistency with our 32-bit semihosting). */ - if (semihosting_enabled(false) && -#ifndef CONFIG_USER_ONLY - s->current_el !=3D 0 && -#endif + if (semihosting_enabled(s->current_el !=3D 0) && (imm =3D=3D (s->thumb ? 0x3c : 0xf000))) { gen_exception_internal_insn(s, s->pc_curr, EXCP_SEMIHOST); return; @@ -6556,10 +6553,7 @@ static bool trans_BKPT(DisasContext *s, arg_BKPT *a) /* BKPT is OK with ECI set and leaves it untouched */ s->eci_handled =3D true; if (arm_dc_feature(s, ARM_FEATURE_M) && - semihosting_enabled(false) && -#ifndef CONFIG_USER_ONLY - !IS_USER(s) && -#endif + semihosting_enabled(s->current_el =3D=3D 0) && (a->imm =3D=3D 0xab)) { gen_exception_internal_insn(s, s->pc_curr, EXCP_SEMIHOST); } else { @@ -8764,10 +8758,8 @@ static bool trans_SVC(DisasContext *s, arg_SVC *a) { const uint32_t semihost_imm =3D s->thumb ? 0xab : 0x123456; =20 - if (!arm_dc_feature(s, ARM_FEATURE_M) && semihosting_enabled(false) && -#ifndef CONFIG_USER_ONLY - !IS_USER(s) && -#endif + if (!arm_dc_feature(s, ARM_FEATURE_M) && + semihosting_enabled(s->current_el =3D=3D 0) && (a->imm =3D=3D semihost_imm)) { gen_exception_internal_insn(s, s->pc_curr, EXCP_SEMIHOST); } else { --=20 2.25.1 From nobody Tue May 14 11:35:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1661182931; cv=none; d=zohomail.com; s=zohoarc; b=Kp0TsC+DYy8l1iJbAml/VVdRMizS/hAN0oBF3LP9altY08AnlGaZcXXHn2hezUR5/vUjPLMkeGnZl/32bCbOW4WOJ1O5xWsndp9z1tDqrb4koQlJ5YFKT4LH5DbZ/jNxpQLr3Tv1FvRRP8fR+vMIEIAxBO9HkeNgN+v0kDg7pnU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661182931; h=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; bh=Fq6BeF0OgBMMAXIU+f0655F6Gy5qXiYfyygjStThzQI=; b=YGTsJ2qGfuprCRGqRgHXoThixd0GmZsn6dCdf1jUmCFbCbOyCAZomhH68rM7ayWa6+2vidfoAd6mQAcbO7XEqG2VRupQ+j8iI3/XXLDtrZa2LcfoJa7NoYBb8qVsatbMCUoZOes/dl8DGL208p/kgssunaeLVN7zniyhLVOpBSg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1661182931872563.4848016511904; Mon, 22 Aug 2022 08:42:11 -0700 (PDT) Received: from localhost ([::1]:40018 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQ9Z4-00035M-R8 for importer@patchew.org; Mon, 22 Aug 2022 11:42:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50098) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQ9At-0001Az-HY for qemu-devel@nongnu.org; Mon, 22 Aug 2022 11:17:12 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]:41865) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oQ9Ap-0005SI-3g for qemu-devel@nongnu.org; Mon, 22 Aug 2022 11:17:08 -0400 Received: by mail-wr1-x435.google.com with SMTP id h24so13626594wrb.8 for ; Mon, 22 Aug 2022 08:17:06 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id bh16-20020a05600c3d1000b003a3561d4f3fsm15184908wmb.43.2022.08.22.07.12.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 07:12:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=Fq6BeF0OgBMMAXIU+f0655F6Gy5qXiYfyygjStThzQI=; b=ybgcWLebYif+tBJ6JeqjlOf6b4MHT7ieYFepBqiNgEDC/WXAhw3zWYCzi4Up4v3fT7 IBbxCWuAcugruloARafB5v3rrBS/xUmsITLOHcN8qdoL2FDf+c/BFqyotLT4+62VqzCd /41qm73HhHrdOpLZVpsKcUKbiCGS1DbU5MJQP/LVKU8G43I+kCJf/uImCREeLTJIT+7z GLNbY8oITPsY4yiJA4faFmoACL5lnedjzBlZGidGrwsqq7iFOEUNwag3cOAFbSkvBOQT wQnHVrXsPHIsnaDZeyD14uUTzz2WSCElhkumu9+m4ztk/iRdQ36Ltdfm4uyzpgLzkzab LIhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=Fq6BeF0OgBMMAXIU+f0655F6Gy5qXiYfyygjStThzQI=; b=F7ODC+pInZB7tmyAkn94Xj8p8JvEFshhquK3MAucl2pFzxhkTFaLH8jsYdqEjCVR99 U/B9yu8Kb5GY7h7e0a8WWlYQKxUb8752OC64OqRaSDCR23Bj0BJqwE6QBVjGzJZc87o/ /v3Jdn1JD97J3bZwCPXXBBnU5+TMTUmd1uA/4v3QT7vzF7bcbdqFcPxz82aOzsYsQeUE 9Sczhhq5hE07LK+JeqeAyyq1bR3ypqkPepwrQ+DllPR6BVURKfvXGTsRzJksDSgcy3/G EVFjAFYM24jmkW+QPrvFcCo7pNB8ni3cWEtmerfRfVrT5dpw6VXM1ObA3ZZfrY0ZNT6B nKmQ== X-Gm-Message-State: ACgBeo0+y6h4CARHlvHa7hKMTVbcWzZPH+SPbNnu0PfQsxwpPkG3adgy K056Wtq36i5F5FqiEtlHiX1MbgHJ1NeFvg== X-Google-Smtp-Source: AA6agR4wTbpYRTzDYiZhHZOwhbRWzx/xxvUit48oQze1V5q6x3x6cBCkjsGJIxRcX9dsT6KyUQnJ3w== X-Received: by 2002:adf:e19b:0:b0:225:448c:9ba8 with SMTP id az27-20020adfe19b000000b00225448c9ba8mr6195503wrb.532.1661177557806; Mon, 22 Aug 2022 07:12:37 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Richard Henderson , qemu-riscv@nongnu.org, Palmer Dabbelt , Bin Meng , Alistair Francis , Furquan Shaikh Subject: [PATCH v2 3/7] target/m68k: Honour -semihosting-config userspace=on Date: Mon, 22 Aug 2022 15:12:26 +0100 Message-Id: <20220822141230.3658237-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220822141230.3658237-1-peter.maydell@linaro.org> References: <20220822141230.3658237-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x435.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1661182932699100001 Content-Type: text/plain; charset="utf-8" Honour the commandline -semihosting-config userspace=3Don option, instead of never permitting userspace semihosting calls in system emulation mode, by passing the correct value to the is_userspace argument of semihosting_enabled(), instead of manually checking and always forbidding semihosting if the guest is in userspace. (Note that target/m68k doesn't support semihosting at all in the linux-user build.) Signed-off-by: Peter Maydell Reviewed-by: Laurent Vivier Reviewed-by: Richard Henderson --- target/m68k/op_helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/target/m68k/op_helper.c b/target/m68k/op_helper.c index 4b3dfec1306..a96a0340506 100644 --- a/target/m68k/op_helper.c +++ b/target/m68k/op_helper.c @@ -203,8 +203,7 @@ static void cf_interrupt_all(CPUM68KState *env, int is_= hw) cf_rte(env); return; case EXCP_HALT_INSN: - if (semihosting_enabled(false) - && (env->sr & SR_S) !=3D 0 + if (semihosting_enabled((env->sr & SR_S) =3D=3D 0) && (env->pc & 3) =3D=3D 0 && cpu_lduw_code(env, env->pc - 4) =3D=3D 0x4e71 && cpu_ldl_code(env, env->pc) =3D=3D 0x4e7bf000) { --=20 2.25.1 From nobody Tue May 14 11:35:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1661191380; cv=none; d=zohomail.com; s=zohoarc; b=fJWxnlKF060jEDmGRVWeby79iCOksGzthXy+JikYQhAsjIiOC4lwu2j/as/WVgMKBaWvdaFluutGdtjU+f7nm5Ur7pqMh6b+iEl18OJpkGxfFbiWl0oIoDrmj+JI4E7EzIRvFZJNnLXclkzrwuwXEi7v+q+esMQabvz+xweM0DQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661191380; 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; bh=Ix5ZX0LyxSe0lq8009+k3P93c+marBxWgKkCfMS6XO4=; b=oLOolx0ZszCM6Mg4IOaOXDFlAFzfi/trGyvDnpULF6yZ3Qz3snYGRT7jEiEOWfQbTU2iQ/iZ344672aCbArhrkrsRfX6yTylNytVJKt93l0WpZh3CVw801HlJdjSzsJ6BMkWZnoTL/a7epDE17RG6ZJNaGCOGXTnlUN7fQAezhI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1661191380310143.8147199980416; Mon, 22 Aug 2022 11:03:00 -0700 (PDT) Received: from localhost ([::1]:40448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQBlK-00078t-Kc for importer@patchew.org; Mon, 22 Aug 2022 14:02:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43122) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQ9lF-0002wa-6q for qemu-devel@nongnu.org; Mon, 22 Aug 2022 11:54:45 -0400 Received: from mail-lj1-x22c.google.com ([2a00:1450:4864:20::22c]:41804) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oQ9lD-0005RY-E3 for qemu-devel@nongnu.org; Mon, 22 Aug 2022 11:54:44 -0400 Received: by mail-lj1-x22c.google.com with SMTP id l19so7882153ljg.8 for ; Mon, 22 Aug 2022 08:54:43 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id bh16-20020a05600c3d1000b003a3561d4f3fsm15184908wmb.43.2022.08.22.07.12.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 07:12:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=Ix5ZX0LyxSe0lq8009+k3P93c+marBxWgKkCfMS6XO4=; b=xqhSh/J3Amp77yha/WEPgppTr2wvu7XP+/4bmW5/gwS59Egc1iMpjHs5yd2/Ld/w5m tiG1aEIR1QCCmfdxX6keRnTd8nSY4BVJ8pd8TqUza4XGubOjSEAwgVKF2Szw3gUYy221 y8xUFR5KRtOjCGfucQYsJ4nWMY3turIQNHTLl/WalI7DYEPtVpe7gTn+goXXs1yH3v28 Pu13fbbOw4u/lXQP2zzNTgWlg4dqJ7f+SjZuREGv48W7KVV+c50PLGst/MB+mPMnr4fv 98YZEQNiz1ZfEfSYUt6omnGhnAAoZvOrO1aHGqlTN0bCJiUpLbIYOGKwoU1ujBT3Z0jD phMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=Ix5ZX0LyxSe0lq8009+k3P93c+marBxWgKkCfMS6XO4=; b=y1R8qv5Es7MpSuQJi5OU1zS/RMYFt1P2qW8WdsgeyuoUhE66m/0zlhtQrPjAORunvg eqK4aY0S/9QsfTJtlZ+BoF/cYAp+dfcMqF9QDRXjVJMGFRcxuWLJwRh/lF9mNdZ6cO4Q BMrYyT1N2IzeB5ryc8Pxhsi5VBMvV36/x0XcGI6B3zvU40UUUT/MNZhM5NwBsKRChZTz UVsJjiAGA/3ujq1GaHSTcFPwKI5ft+09dTXi1eW6Ysu/NDPVG5qCI/gNgmNE9cK/dvnE Vw+ehHIsd1VV8jpFoBw4j3iPfx7vjEngICkIpKgUKOY5Vh9wU6xnaa06i2WU+6Y5JKeK KMZA== X-Gm-Message-State: ACgBeo0ICVKzZMy5NVldgOXQHCPVtBtZB0hnzPdAbDlBaDnUTw6v7efv PTiL/kTX1/9wC0r0sUV/43w8A8DyMYWpyw== X-Google-Smtp-Source: AA6agR6UK9CYRjLszL8RAgjPVk7Y0RdS71Gjr3bIgpITeVUWzLEJL8vgq6DrnVW5wy0ncYOldHuhbQ== X-Received: by 2002:a5d:6b10:0:b0:21e:4bbd:e893 with SMTP id v16-20020a5d6b10000000b0021e4bbde893mr11085590wrw.613.1661177559213; Mon, 22 Aug 2022 07:12:39 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Richard Henderson , qemu-riscv@nongnu.org, Palmer Dabbelt , Bin Meng , Alistair Francis , Furquan Shaikh Subject: [PATCH v2 4/7] target/mips: Honour -semihosting-config userspace=on Date: Mon, 22 Aug 2022 15:12:27 +0100 Message-Id: <20220822141230.3658237-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220822141230.3658237-1-peter.maydell@linaro.org> References: <20220822141230.3658237-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2a00:1450:4864:20::22c; envelope-from=peter.maydell@linaro.org; helo=mail-lj1-x22c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1661191381679100001 Honour the commandline -semihosting-config userspace=3Don option, instead of always permitting userspace semihosting calls in system emulation mode, by passing the correct value to the is_userspace argument of semihosting_enabled(). Note that this is a behaviour change: if the user wants to do semihosting calls from userspace they must now specifically enable them on the command line. MIPS semihosting is not implemented for linux-user builds. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- target/mips/tcg/translate.c | 9 +++++---- target/mips/tcg/micromips_translate.c.inc | 6 +++--- target/mips/tcg/mips16e_translate.c.inc | 2 +- target/mips/tcg/nanomips_translate.c.inc | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c index de1511baaf8..53886618ddd 100644 --- a/target/mips/tcg/translate.c +++ b/target/mips/tcg/translate.c @@ -12082,12 +12082,13 @@ static void gen_cache_operation(DisasContext *ctx= , uint32_t op, int base, tcg_temp_free_i32(t0); } =20 -static inline bool is_uhi(int sdbbp_code) +static inline bool is_uhi(DisasContext *ctx, int sdbbp_code) { #ifdef CONFIG_USER_ONLY return false; #else - return semihosting_enabled() && sdbbp_code =3D=3D 1; + bool is_user =3D (ctx->hflags & MIPS_HFLAG_KSU) =3D=3D MIPS_HFLAG_UM; + return semihosting_enabled(is_user) && sdbbp_code =3D=3D 1; #endif } =20 @@ -13898,7 +13899,7 @@ static void decode_opc_special_r6(CPUMIPSState *env= , DisasContext *ctx) } break; case R6_OPC_SDBBP: - if (is_uhi(extract32(ctx->opcode, 6, 20))) { + if (is_uhi(ctx, extract32(ctx->opcode, 6, 20))) { ctx->base.is_jmp =3D DISAS_SEMIHOST; } else { if (ctx->hflags & MIPS_HFLAG_SBRI) { @@ -14310,7 +14311,7 @@ static void decode_opc_special2_legacy(CPUMIPSState= *env, DisasContext *ctx) gen_cl(ctx, op1, rd, rs); break; case OPC_SDBBP: - if (is_uhi(extract32(ctx->opcode, 6, 20))) { + if (is_uhi(ctx, extract32(ctx->opcode, 6, 20))) { ctx->base.is_jmp =3D DISAS_SEMIHOST; } else { /* diff --git a/target/mips/tcg/micromips_translate.c.inc b/target/mips/tcg/mi= cromips_translate.c.inc index b2c696f8916..632895cc9ef 100644 --- a/target/mips/tcg/micromips_translate.c.inc +++ b/target/mips/tcg/micromips_translate.c.inc @@ -825,7 +825,7 @@ static void gen_pool16c_insn(DisasContext *ctx) generate_exception_break(ctx, extract32(ctx->opcode, 0, 4)); break; case SDBBP16: - if (is_uhi(extract32(ctx->opcode, 0, 4))) { + if (is_uhi(ctx, extract32(ctx->opcode, 0, 4))) { ctx->base.is_jmp =3D DISAS_SEMIHOST; } else { /* @@ -941,7 +941,7 @@ static void gen_pool16c_r6_insn(DisasContext *ctx) break; case R6_SDBBP16: /* SDBBP16 */ - if (is_uhi(extract32(ctx->opcode, 6, 4))) { + if (is_uhi(ctx, extract32(ctx->opcode, 6, 4))) { ctx->base.is_jmp =3D DISAS_SEMIHOST; } else { if (ctx->hflags & MIPS_HFLAG_SBRI) { @@ -1310,7 +1310,7 @@ static void gen_pool32axf(CPUMIPSState *env, DisasCon= text *ctx, int rt, int rs) generate_exception_end(ctx, EXCP_SYSCALL); break; case SDBBP: - if (is_uhi(extract32(ctx->opcode, 16, 10))) { + if (is_uhi(ctx, extract32(ctx->opcode, 16, 10))) { ctx->base.is_jmp =3D DISAS_SEMIHOST; } else { check_insn(ctx, ISA_MIPS_R1); diff --git a/target/mips/tcg/mips16e_translate.c.inc b/target/mips/tcg/mips= 16e_translate.c.inc index 7568933e234..918b15d55ce 100644 --- a/target/mips/tcg/mips16e_translate.c.inc +++ b/target/mips/tcg/mips16e_translate.c.inc @@ -951,7 +951,7 @@ static int decode_ase_mips16e(CPUMIPSState *env, DisasC= ontext *ctx) } break; case RR_SDBBP: - if (is_uhi(extract32(ctx->opcode, 5, 6))) { + if (is_uhi(ctx, extract32(ctx->opcode, 5, 6))) { ctx->base.is_jmp =3D DISAS_SEMIHOST; } else { /* diff --git a/target/mips/tcg/nanomips_translate.c.inc b/target/mips/tcg/nan= omips_translate.c.inc index b3aff22c189..812c111e3c3 100644 --- a/target/mips/tcg/nanomips_translate.c.inc +++ b/target/mips/tcg/nanomips_translate.c.inc @@ -3694,7 +3694,7 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *en= v, DisasContext *ctx) generate_exception_end(ctx, EXCP_BREAK); break; case NM_SDBBP: - if (is_uhi(extract32(ctx->opcode, 0, 19))) { + if (is_uhi(ctx, extract32(ctx->opcode, 0, 19))) { ctx->base.is_jmp =3D DISAS_SEMIHOST; } else { if (ctx->hflags & MIPS_HFLAG_SBRI) { @@ -4633,7 +4633,7 @@ static int decode_isa_nanomips(CPUMIPSState *env, Dis= asContext *ctx) generate_exception_end(ctx, EXCP_BREAK); break; case NM_SDBBP16: - if (is_uhi(extract32(ctx->opcode, 0, 3))) { + if (is_uhi(ctx, extract32(ctx->opcode, 0, 3))) { ctx->base.is_jmp =3D DISAS_SEMIHOST; } else { if (ctx->hflags & MIPS_HFLAG_SBRI) { --=20 2.25.1 From nobody Tue May 14 11:35:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1661194349; cv=none; d=zohomail.com; s=zohoarc; b=lKIuwf96iAYXe49pYbR+kaIH5sFu+iA15tId1IYaQBfP4E0I59nkBJj7uUaVG8AE7YTRZvF/ev7Yj+1Yz7xhsatmSnjGoFO17BkfSSwA1WurjVkq1zUUO/IngbGKzy9LQObyAB0pMYUQ94VyDGp1sjGx82NZl/HBuAvXJHCODF4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661194349; h=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; bh=otAuKbBd7la4jsEiv/+EcRkvB4vfTN2cbw4MQWM69+A=; b=i2Slkhnn+b2PbbdU+RYh7nSN2fulU8RH8pNKm8sMajQ+bzOMPRH022vbpqmPshXWWoYsXqzFKGNQiuppOkoVzR63aKkvO+u4sb9WNmC9qg1EZXLE383ieuBJE9C1baYsWhEoUh1H6/e8P8CLJe75g328juGj/eWhGaOM87jPADo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1661194349147594.8439414634123; Mon, 22 Aug 2022 11:52:29 -0700 (PDT) Received: from localhost ([::1]:44048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQCXC-0000o2-5k for importer@patchew.org; Mon, 22 Aug 2022 14:52:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44684) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQ9ju-0001m3-In for qemu-devel@nongnu.org; Mon, 22 Aug 2022 11:53:24 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]:37615) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oQ9jr-0005Hl-KR for qemu-devel@nongnu.org; Mon, 22 Aug 2022 11:53:22 -0400 Received: by mail-wm1-x32e.google.com with SMTP id c187-20020a1c35c4000000b003a30d88fe8eso8030720wma.2 for ; Mon, 22 Aug 2022 08:53:19 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id bh16-20020a05600c3d1000b003a3561d4f3fsm15184908wmb.43.2022.08.22.07.12.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 07:12:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=otAuKbBd7la4jsEiv/+EcRkvB4vfTN2cbw4MQWM69+A=; b=iGrhbUTYZzSuMCovEXQuIMu2UGmKnnYiHdDlMwDoy6GlMj9NKUHv56fC0OgpwsIsKg kM5A24R7LWh2SHaQCyqJMcwFCJoO+tHHazR7NNBTQha22ewFwhETodZq+iFsNrK/DIeH Cgcwp4aFpNQM6aM0bA5aJvcyeiVly9aKJnngSdz9y7VeOBoqPgzJ8Q6+BKw+iHDT2q8o 9grvbo9KeApdAM0vA7TdBbchqEBsZkqMXqxFtEwLEx7SWJWE2qy3KOkpnmsJQIqP52L6 eKGCH2BGOcZcyQa7A3k/ZwJeDAWxzjyEC4PG4z4CDDfVXgyqO7rfitdhL/PElCh0ag2N Yafw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=otAuKbBd7la4jsEiv/+EcRkvB4vfTN2cbw4MQWM69+A=; b=1tnhG8QJl7tHaST+vzUP3cKdOf+FcGhaj+BXOYDUKSjVFrgBxch4z1vlSmUXt2xKm7 iAzrFsqDnlEf1kdOhlVCxEv5toDSme1T/o3lFazCjD4JHqJgPqIMrbXmQciyo3WYMbLp gDx6phdT6HIPXF7yT8SmG7GOCrumsYmV5lbBQ6uHMeqqkPepBoYl0tl9Jbo2ZfqQ8m5E CZspWJJR4oKqDxXYub4+hCERs/dhgd70Qf1Y7iLHaqVoLmwHd9Z3ISsHwHIE38fdWyBm s3pdmxm/uJUoJzPeblZxIU93POTTTocuKUQ32DT3nAyZjVtqhCtlNs4lpiIjmBqc4Cji uIBA== X-Gm-Message-State: ACgBeo12LlMM05UHlS4WCx+GJGgn+jSDJNOjV51B5j8+mL+rXAjfWO94 NSfbG8WOr1xxBVCp1zxHZEOBpeU2DOFODQ== X-Google-Smtp-Source: AA6agR7kfN9t5Yvi9jiAceupzqjGq+sYLW38v7WIYrUvSANg4jCdu5uM85Ee/+XIk32mpmfkvYy4fA== X-Received: by 2002:a05:600c:4f4f:b0:3a5:a530:4fd7 with SMTP id m15-20020a05600c4f4f00b003a5a5304fd7mr15782794wmq.36.1661177560235; Mon, 22 Aug 2022 07:12:40 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Richard Henderson , qemu-riscv@nongnu.org, Palmer Dabbelt , Bin Meng , Alistair Francis , Furquan Shaikh Subject: [PATCH v2 5/7] target/nios2: Honour -semihosting-config userspace=on Date: Mon, 22 Aug 2022 15:12:28 +0100 Message-Id: <20220822141230.3658237-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220822141230.3658237-1-peter.maydell@linaro.org> References: <20220822141230.3658237-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1661194351121100001 Content-Type: text/plain; charset="utf-8" Honour the commandline -semihosting-config userspace=3Don option, instead of always permitting userspace semihosting calls in system emulation mode, by passing the correct value to the is_userspace argument of semihosting_enabled(). Note that this is a behaviour change: if the user wants to do semihosting calls from userspace they must now specifically enable them on the command line. nios2 semihosting is not implemented for linux-user builds. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- target/nios2/translate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/nios2/translate.c b/target/nios2/translate.c index 2b556683422..d1786b43a69 100644 --- a/target/nios2/translate.c +++ b/target/nios2/translate.c @@ -817,8 +817,9 @@ static void gen_break(DisasContext *dc, uint32_t code, = uint32_t flags) { #ifndef CONFIG_USER_ONLY /* The semihosting instruction is "break 1". */ + bool is_user =3D FIELD_EX32(dc->tb_flags, TBFLAGS, U); R_TYPE(instr, code); - if (semihosting_enabled(false) && instr.imm5 =3D=3D 1) { + if (semihosting_enabled(is_user) && instr.imm5 =3D=3D 1) { t_gen_helper_raise_exception(dc, EXCP_SEMIHOST); return; } --=20 2.25.1 From nobody Tue May 14 11:35:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1661182017; cv=none; d=zohomail.com; s=zohoarc; b=Uf2eFW/CRrx/erY87c/HOtisVfoU/aoiHlLvXzu5gnOU/eGrLKaQRL6T1aPnsEuBWC8kPXrU7PLRNIgYkAhUwE415RjVr2iXiP7OKV0GMB70TsOAvaCS5jR0eI12rGj57v2WrisvjqtuCneB+mC01qlcOgFr/3njOYxQg0NG30w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661182017; 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; bh=r1xWEOHWHOt3MBY5xlN7HosIZZCC0kMBbMC4Q6TASCY=; b=BIKQUUKSgdOcbcq96vO58+S6eGCTjo4UZyPCUR35dwo4IOVkoNYZQYUXggc8fQZdeO/1eK6BNv6WXAvk40fUUtoIGX7LyeJ0+ud7s9sEYTRxlXfZZal3A6tECUiL5lUfngEndfsXD9mlz37rFjObzCcNoqqvoyxnsltsp1X7a6w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1661182017546449.8324705604806; Mon, 22 Aug 2022 08:26:57 -0700 (PDT) Received: from localhost ([::1]:55602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQ9KK-0004XF-5c for importer@patchew.org; Mon, 22 Aug 2022 11:26:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37968) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQ96k-0003g1-OY for qemu-devel@nongnu.org; Mon, 22 Aug 2022 11:12:56 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]:53839) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oQ96V-0004Jf-4G for qemu-devel@nongnu.org; Mon, 22 Aug 2022 11:12:54 -0400 Received: by mail-wm1-x32f.google.com with SMTP id h1so5757713wmd.3 for ; Mon, 22 Aug 2022 08:12:38 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id bh16-20020a05600c3d1000b003a3561d4f3fsm15184908wmb.43.2022.08.22.07.12.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 07:12:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=r1xWEOHWHOt3MBY5xlN7HosIZZCC0kMBbMC4Q6TASCY=; b=TtwXxZPjJkqewIsyOPEc3rczi4fDZTbgvfeIB8B62EEbFXTpX1DESdezNls8TKf6rp AIz8NvnUyYX9s77mYAiAWnFsm6feHnJAHTIrgZeXP/jkJvN5qGlba3r/zLLdJ3tDKHhA r4zBpPe8IvpNT15G8mkNcbh4q0I22fukf08/3RNhTVisZG+kOhV56wAX9vkUoG/ogTqH IACPfzUAZQlgGeYEFtVE0NauI1TnrH5MTzLuUw5gAamEtV4fiQfw05jQxc7bZPErslOb T3IP+GPs38Oaq8Qm4J2z13whK6zI9fVSj56hCs/6U0EdkMp/zpm4TyYS7SD/8UduWIZr q6ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=r1xWEOHWHOt3MBY5xlN7HosIZZCC0kMBbMC4Q6TASCY=; b=A6X0/0FG8x1TjCTfyHwCRSAgaSqv96fpX1ZDYY957A7WW7bHhtDbSRngBe7KUQtjI2 8oc014mtaz5z6jKnZ3zbz1Ta6cz2nLZMCjsupFPfmYTawlEEIxjMMvBbiY9wDnIe42wC KVZVe7OY+plRuSLzOuZsBAUU6U0TYpbGCAKeKxv0wLNcJzz2dCZG5wsp3vPF/5iwn+Kh dcP0NEMmOh8YKYbW09hSnweO7NiEyW8w6FGMMADlBQX4r3B4BHYNkp3bZv35IsBfVXYD ifPZSoPOxPG9bOOczNpdgAVfR0XJoI9bUBQ7ZVEHKMG3manpgDUkkgKYCvsNwZ92DSm8 wf8A== X-Gm-Message-State: ACgBeo2IC3cod0ODce6KNOtubHY6crEeSQNk8H3yYyePNclV2nJ4NGJT KkLFb9o1y9An9IAKzCuKMEMp69u0zUJYrA== X-Google-Smtp-Source: AA6agR6DNN0E2mWTaHDv6skaCGzHgfGGwSghUnFjG6NR8aFSURYg+71PMzOdi3dTTRsdTO0DDp0h8w== X-Received: by 2002:a1c:7c08:0:b0:3a6:2569:4986 with SMTP id x8-20020a1c7c08000000b003a625694986mr12318271wmc.117.1661177561665; Mon, 22 Aug 2022 07:12:41 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Richard Henderson , qemu-riscv@nongnu.org, Palmer Dabbelt , Bin Meng , Alistair Francis , Furquan Shaikh Subject: [PATCH v2 6/7] target/xtensa: Honour -semihosting-config userspace=on Date: Mon, 22 Aug 2022 15:12:29 +0100 Message-Id: <20220822141230.3658237-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220822141230.3658237-1-peter.maydell@linaro.org> References: <20220822141230.3658237-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1661182019221100001 Honour the commandline -semihosting-config userspace=3Don option, instead of always permitting userspace semihosting calls in system emulation mode, by passing the correct value to the is_userspace argument of semihosting_enabled(). Note that this is a behaviour change: if the user wants to do semihosting calls from userspace they must now specifically enable them on the command line. xtensa semihosting is not implemented for linux-user builds. Signed-off-by: Peter Maydell Acked-by: Max Filippov Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- target/xtensa/translate.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c index dc475a4274b..43d55989349 100644 --- a/target/xtensa/translate.c +++ b/target/xtensa/translate.c @@ -2360,13 +2360,14 @@ static uint32_t test_exceptions_simcall(DisasContex= t *dc, const OpcodeArg arg[], const uint32_t par[]) { + bool is_semi =3D semihosting_enabled(dc->cring !=3D 0); #ifdef CONFIG_USER_ONLY bool ill =3D true; #else /* Between RE.2 and RE.3 simcall opcode's become nop for the hardware.= */ - bool ill =3D dc->config->hw_version <=3D 250002 && !semihosting_enable= d(false); + bool ill =3D dc->config->hw_version <=3D 250002 && !is_semi; #endif - if (ill || !semihosting_enabled(false)) { + if (ill || !is_semi) { qemu_log_mask(LOG_GUEST_ERROR, "SIMCALL but semihosting is disable= d\n"); } return ill ? XTENSA_OP_ILL : 0; @@ -2376,7 +2377,7 @@ static void translate_simcall(DisasContext *dc, const= OpcodeArg arg[], const uint32_t par[]) { #ifndef CONFIG_USER_ONLY - if (semihosting_enabled(false)) { + if (semihosting_enabled(dc->cring !=3D 0)) { gen_helper_simcall(cpu_env); } #endif --=20 2.25.1 From nobody Tue May 14 11:35:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1661194759; cv=none; d=zohomail.com; s=zohoarc; b=ThEk7alXNrQWTL4IlpeABRK4bJhWDS/tC6/1eVCKk3/KtCoDN0bR78G4HNnnj9fHSZiRPIWv4r+OkHyQ6+gTkCVfXZZxrMmoy8jewZq/IStDKrNaZeIni+87QFvGcy4pu8KPvZ4GeKJdqscNDuMIe1JauTmANmTBJ7WVV7cB4eI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661194759; h=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; bh=tWxgdi7/uu1+ANLOaFNvQeb6l6xGI+BRWt05JvH2Mdw=; b=AybOoQGAbsRSHafi8BLJS7gUUTDxXunfaM5WuDuuBZoHBd7+8CgWb0ByJrTzvRW8psbyISG2M+ON+q726xDTh5DhO0BKEHK+MppF2lolFt58XI4BGquDz9fs5+qqLgjPq2oGTiXw1zqQ0P+df+G9XbTviG1LTsY/vy3qq6VFnCI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 166119475932353.88925616615177; Mon, 22 Aug 2022 11:59:19 -0700 (PDT) Received: from localhost ([::1]:56632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQCdp-0007CP-Mh for importer@patchew.org; Mon, 22 Aug 2022 14:59:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57800) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQ9k6-0001w4-Py for qemu-devel@nongnu.org; Mon, 22 Aug 2022 11:53:35 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]:33584) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oQ9k4-0005Ko-QF for qemu-devel@nongnu.org; Mon, 22 Aug 2022 11:53:34 -0400 Received: by mail-wm1-x331.google.com with SMTP id m3-20020a05600c3b0300b003a5e0557150so6023742wms.0 for ; Mon, 22 Aug 2022 08:53:32 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id bh16-20020a05600c3d1000b003a3561d4f3fsm15184908wmb.43.2022.08.22.07.12.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 07:12:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=tWxgdi7/uu1+ANLOaFNvQeb6l6xGI+BRWt05JvH2Mdw=; b=PPPM7Iwh7rk51D6kdOrW8D5NUAM0wdD8gGrR67J2qEpI4w3QshvOLP2tdiF61WXQXq mGqADn8bawypoSzxY6SjZGPt/OGcB8oUvemfdL3MxujGA1kbCz/cKJqNW3cTFpyOR2zl 5ltE+06aahY4veklRg6KBxm5J/HTEHia4PEAY/JgqON17/OiSD21lwN7tTX1lXwmO55x fI2ahaENOCZSTbA69mDtjc64HwJ7cInzCvrYVMc/WgCObNHqnzmily+NB41szw+5d0P5 V2tCpG06J5GPbHhMXhV1X3ZR9+90EWWYTYpHlC3KwjEzWFCnkI36wmbD+YKhkbFMoPZa 4qdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=tWxgdi7/uu1+ANLOaFNvQeb6l6xGI+BRWt05JvH2Mdw=; b=wyZP4fT/uSmReM1oJJ2L4f0FKTk5jkqvELQy/NpJvZUQyiGIlX/eHAcBXbS4AmYL8V gALspZlff38nQKcXfgFNyAYVTLx+TWUnfpX+QSFAaZ4UutzMvhf4bbst/ti/TRF96c0C D0Fa8reUPnC5PDTG5JVckXzvbH1dbeSaXTEPfDoyPzrNlPiEKMoJMrslGfGBGaiFqM5r WYpWB16fRDVcEW0MqpBKZAj4s/zm6cUIxBwyMgVsbO4S559JkuAKi3v7n0vML5UbKKAb 8SXbtt2zc9GSB5tswBQxCcaHed++2NJ+vhJYebm3mLrNjjgdN+EF1C3UY7iHx/I3v2ko 1bxQ== X-Gm-Message-State: ACgBeo3yMO2FbBAt2/Vt5JxBm21fWqBVLn8Yf1SyUDZe9BHzHGB5o1vl cMyH+SX4DetkSaR3Ud5iEQ1opbyT+bWcgw== X-Google-Smtp-Source: AA6agR6TjnePzHyEDDBx0lt4HgWmB7GrxwbakccuWJ4UlH160VcgIUAYTuqvOwd1HxVthcSTlldupA== X-Received: by 2002:a05:600c:1990:b0:3a6:2a00:3ddb with SMTP id t16-20020a05600c199000b003a62a003ddbmr11806956wmq.72.1661177562935; Mon, 22 Aug 2022 07:12:42 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Richard Henderson , qemu-riscv@nongnu.org, Palmer Dabbelt , Bin Meng , Alistair Francis , Furquan Shaikh Subject: [PATCH v2 7/7] target/riscv: Honour -semihosting-config userspace=on and enable=on Date: Mon, 22 Aug 2022 15:12:30 +0100 Message-Id: <20220822141230.3658237-8-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220822141230.3658237-1-peter.maydell@linaro.org> References: <20220822141230.3658237-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x331.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1661194760438100001 Content-Type: text/plain; charset="utf-8" The riscv target incorrectly enabled semihosting always, whether the user asked for it or not. Call semihosting_enabled() passing the correct value to the is_userspace argument, which fixes this and also handles the userspace=3Don argument. Because we do this at translate time, we no longer need to check the privilege level in riscv_cpu_do_interrupt(). Note that this is a behaviour change: we used to default to semihosting being enabled, and now the user must pass "-semihosting-config enable=3Don" if they want it. Signed-off-by: Peter Maydell Reviewed-by: Alistair Francis Reviewed-by: Richard Henderson --- target/riscv/cpu_helper.c | 9 +++------ target/riscv/translate.c | 1 + target/riscv/insn_trans/trans_privileged.c.inc | 3 ++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 59b3680b1b2..2b84febf275 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1342,12 +1342,9 @@ void riscv_cpu_do_interrupt(CPUState *cs) target_ulong mtval2 =3D 0; =20 if (cause =3D=3D RISCV_EXCP_SEMIHOST) { - if (env->priv >=3D PRV_S) { - do_common_semihosting(cs); - env->pc +=3D 4; - return; - } - cause =3D RISCV_EXCP_BREAKPOINT; + do_common_semihosting(cs); + env->pc +=3D 4; + return; } =20 if (!async) { diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 63b04e8a948..f9e6258ec5d 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -28,6 +28,7 @@ =20 #include "exec/translator.h" #include "exec/log.h" +#include "semihosting/semihost.h" =20 #include "instmap.h" #include "internals.h" diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/= insn_trans/trans_privileged.c.inc index 46f96ad74d4..3281408a874 100644 --- a/target/riscv/insn_trans/trans_privileged.c.inc +++ b/target/riscv/insn_trans/trans_privileged.c.inc @@ -52,7 +52,8 @@ static bool trans_ebreak(DisasContext *ctx, arg_ebreak *a) * that no exception will be raised when fetching them. */ =20 - if ((pre_addr & TARGET_PAGE_MASK) =3D=3D (post_addr & TARGET_PAGE_MASK= )) { + if (semihosting_enabled(ctx->mem_idx < PRV_S) && + (pre_addr & TARGET_PAGE_MASK) =3D=3D (post_addr & TARGET_PAGE_MASK= )) { pre =3D opcode_at(&ctx->base, pre_addr); ebreak =3D opcode_at(&ctx->base, ebreak_addr); post =3D opcode_at(&ctx->base, post_addr); --=20 2.25.1