From patchwork Mon Aug 15 19:02:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 597266 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp1758484maz; Mon, 15 Aug 2022 12:06:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR5p7ijE0pAGY8TA1csrieKJy6CAF2BHm/6+DVsz/rkx7Loo/Jodm+QttHldYUE0IkEsV7sP X-Received: by 2002:a05:6214:29e7:b0:476:c87f:1a89 with SMTP id jv7-20020a05621429e700b00476c87f1a89mr14810520qvb.32.1660590403838; Mon, 15 Aug 2022 12:06:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660590403; cv=none; d=google.com; s=arc-20160816; b=Sl60t/kLJThRrAl8sHuljdxbXWKv8Rmm3hDbUklItB82dHBEehoBczSSqT4PFq+epm kT4WZdvpI5+hD1lfhCT89xKV7B5PZlrNIfVFJ1Ia9ad7kRKyL9d9dl2RVzdQFHv4gsO0 zAMHrSmi6AtIHYhsKSe0pIBhPYZSIwACEX98mlOfJgArzD0l0bqJI2lv+l+YDtzV1mhK 4XM5RBCigqpy5G6EoTbsh7yMc4jPl5ZVzOn0UsEEV0bK2A1bFNRMRBYzKS7uBXiG6dBq 9QbYRDdKQpvvUVGmbNsvo+QrSaMuLU6hcWD3sSWP19E2k9mDFcssb8qDf9yhrn28wXDI lhbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8WWlDx3Ci11rnHN4sjEhaL2nFKXuR6a5ZYDpiFOKFcE=; b=UQRhvWSlhwGQhzORXhmjmXgCh8QKKw8Tx5D29QQPnMWtKtk9rJ3HYxDwj+8jd7Jt9a SLnKp1+loMnRFMlKO0aighQDrsbMt3Ge4vRqfR/TIUSF55BdoisxV8+O8cAzp0Xy9bB8 8nBWpRxOFC9yGXDDzS+oYl+hmA6sQDL7OOh0UUcNzrRfgGCc0TDwiaUKDuN/NqjzGUBF vlePwmC1Onmro9tSGSlfQq7igoxXJM9F81TgYZplK5INFXVwT1KOyY8AlFcp53TSOuEu MJ9OvNdybyz2PjcRTl7t5nRfIq/dK0w1Y52LQKlJbV32JSLbMVrWosvFd6LmRk1DuNfH 6dSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VzfXBo1t; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h6-20020a0562140da600b004773d7c107esi6269507qvh.145.2022.08.15.12.06.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 Aug 2022 12:06:43 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VzfXBo1t; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46500 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNfQB-0002dJ-AV for patch@linaro.org; Mon, 15 Aug 2022 15:06:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37934) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNfMm-0002ap-CA for qemu-devel@nongnu.org; Mon, 15 Aug 2022 15:03:12 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:36756) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oNfMj-0006KM-Rt for qemu-devel@nongnu.org; Mon, 15 Aug 2022 15:03:12 -0400 Received: by mail-wr1-x42f.google.com with SMTP id j7so10092726wrh.3 for ; Mon, 15 Aug 2022 12:03:09 -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=8WWlDx3Ci11rnHN4sjEhaL2nFKXuR6a5ZYDpiFOKFcE=; b=VzfXBo1tCQqZAkbWVvgEH1HsZ9UPQZVOeJDYfU1AIxdrvaApO7lJ3rUcso4dc76NCV DhpkSOrneZEbrPsfj5Ncep6b46K/DdkTVQWJNeFO6gFZSLpTuYYt62uVdVtj7zvF6QbT WOJK1/mQwINDZDGl78gSEfKeQUmKh1SYU07UvfjvJt+IAKIRk/+9R+aZszgzqqGxxwJL 9ycVceyad0I6ZkOuFTixBWxne8l2fCINAgsRQrEo8Dm0AF97eYmX8NuxiBlbhKdEby2s QrR/1NDG5ytQeKdphinGUNuCs48dw6q88jFgNTJXlVUFQa+2tA1f2sgCsFcXoeadiP5U fwpg== 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=8WWlDx3Ci11rnHN4sjEhaL2nFKXuR6a5ZYDpiFOKFcE=; b=439Stqwsrzk5EziKLcdcnS38/35r+MXPVMMyvIwB2FVCngpad7sBdOfRGB0tXomjt1 tmcqxRHBpQ+CQnYqgcuWvX1Xa6uSPIqcqvjUfUASuKzs8jgXu2p+cck4GOM8huLHP1Dg TyzHIMAX/MaL03HwyWvKwb+qdi9GBsB0SSl65Xeqf5vjJKR+nIxpMcWUF/Navi95WVyZ t32C6FAfUxKoTfu1hn/S4L2U9ta1N150h6uVdVIV5gitYNec5ULJWXHayOo4GkSw7+mf DqQHExOvcHIOgvsiIvE8G67MfMait8bO57fKpKK0tlwW2u1FDBdhWqM4tRHh0x9SMQ7e emqg== X-Gm-Message-State: ACgBeo3Q0X9jchq4qjG3g+WdlK+CCwPvGk5AAAg2wx+6b8qN1cGlEhFi acIrZF5udaVBLbalYgGp/WDpnA== X-Received: by 2002:a05:6000:1e19:b0:21f:c32:f45b with SMTP id bj25-20020a0560001e1900b0021f0c32f45bmr9712446wrb.657.1660590188362; Mon, 15 Aug 2022 12:03:08 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id u4-20020a5d5144000000b00220606afdf4sm8009162wrt.43.2022.08.15.12.03.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 12:03:07 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jiaxun Yang , Aleksandar Rikalo , Stefan Pejic , Chris Wulff , Marek Vasut , Palmer Dabbelt , Alistair Francis , Bin Meng , Max Filippov , Richard Henderson , Furquan Shaikh Subject: [PATCH 1/7] semihosting: Allow optional use of semihosting from userspace Date: Mon, 15 Aug 2022 20:02:57 +0100 Message-Id: <20220815190303.2061559-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220815190303.2061559-1-peter.maydell@linaro.org> References: <20220815190303.2061559-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42f.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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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=on (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=on 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 Reviewed-by: Philippe Mathieu-Daudé Acked-by: Alex Bennée Reviewed-by: Alistair Francis --- 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; #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 = { { .name = "enable", .type = QEMU_OPT_BOOL, + }, { + .name = "userspace", + .type = QEMU_OPT_BOOL, }, { .name = "target", .type = QEMU_OPT_STRING, @@ -50,6 +53,7 @@ QemuOptsList qemu_semihosting_config_opts = { 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; -bool semihosting_enabled(void) +bool semihosting_enabled(bool is_user) { - return semihosting.enabled; + return semihosting.enabled && (!is_user || semihosting.userspace_enabled); } SemihostingTarget semihosting_get_target(void) @@ -137,6 +141,8 @@ int qemu_semihosting_config_options(const char *optarg) if (opts != NULL) { semihosting.enabled = qemu_opt_get_bool(opts, "enable", true); + semihosting.userspace_enabled = qemu_opt_get_bool(opts, "userspace", + false); const char *target = qemu_opt_get(opts, "target"); /* setup of chardev is deferred until they are initialised */ semihost_chardev = 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, false, &error_fatal); - 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 = { }; /* 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 instruction. */ - if (semihosting_enabled() && imm16 == 0xf000) { + if (semihosting_enabled(false) && imm16 == 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 != 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 = 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 = s->thumb ? 0xab : 0x123456; - 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) != 0 && (env->pc & 3) == 0 && cpu_lduw_code(env, env->pc - 4) == 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 == 1) { + if (semihosting_enabled(false) && instr.imm5 == 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 = true; #else /* Between RE.2 and RE.3 simcall opcode's become nop for the hardware. */ - bool ill = dc->config->hw_version <= 250002 && !semihosting_enabled(); + bool ill = dc->config->hw_version <= 250002 && !semihosting_enabled(false); #endif - if (ill || !semihosting_enabled()) { + if (ill || !semihosting_enabled(false)) { qemu_log_mask(LOG_GUEST_ERROR, "SIMCALL but semihosting is disabled\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=on|off][,target=native|gdb|auto][,chardev=id][,arg=str[,...]]\n" \ + "-semihosting-config [enable=on|off][,target=native|gdb|auto][,chardev=id][,userspace=on|off][,arg=str[,...]]\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=on|off][,target=native|gdb|auto][,chardev=id][,arg=str[,...]]`` +``-semihosting-config [enable=on|off][,target=native|gdb|auto][,chardev=id][,userspace=on|off][,arg=str[,...]]`` Enable and configure semihosting (ARM, M68K, Xtensa, MIPS, Nios II, RISC-V only). @@ -4646,6 +4646,13 @@ SRST Send the output to a chardev backend output for native or auto output when not in gdb + ``userspace=on|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=on`` should + only be used if all guest code is trusted (for example, in + bare-metal test case code). + ``arg=str1,arg=str2,...`` Allows the user to pass input arguments, and can be used multiple times to build up a list. The old-style From patchwork Mon Aug 15 19:02:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 597269 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp1761972maz; Mon, 15 Aug 2022 12:12:29 -0700 (PDT) X-Google-Smtp-Source: AA6agR7JYvxl8bq1alUzPoR7OCpd/OFm2+W5i5trdwTNyPIrB3rd4Euz7M119ezidMCtbeJNrA8z X-Received: by 2002:ac8:7fd1:0:b0:343:67ec:9f9e with SMTP id b17-20020ac87fd1000000b0034367ec9f9emr15050478qtk.453.1660590749660; Mon, 15 Aug 2022 12:12:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660590749; cv=none; d=google.com; s=arc-20160816; b=WKenQBGyyKWY5HWQus2SChrypDvr8lQmBcj1F6/zftuz86biNDGY7CRQB1uMhFkG6m s5ivoMIsO7baZKkdD6hrJm8kxE23ELq/d/ZnkMMVHFU9n+Ap438TrdNYG4CVPB5wwRm/ Cn8jYq1fuhetCQ4Hp7vTewdc9x8E++tqn7QtBx7GGffGE2RbAv8JaTJQ/sUTStD7VTdK ooCovFg3Tam+sDBQbXwY5NJ4QFqFcihijpv62LoCghqVE4eROrMTO+SQ8vFCfjFbn3ap YdpzZrZxpoZkgFT9Y6RmVJpaNGexYra2dttIbRRzJ/sO0tEa42MYKF+EQxJ95EgsOJiZ Jt1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yL2kCSEaX64Q/NPJAtRoJiqW85LCPcZ6AySZ3J3a/uE=; b=0n/xxYp9qV5d86xiZV6tRaKMZpPQkrGXoQy3jM9nEzFSMb36+RGWCdbSQFGt+Fple0 9/fZH+iyNFTaQqVUACw7PYCm1HZ4/5cieZvJsk1ApBUjdLnwbkPEBlUV72A2LlwTUbtn R/Tyz2f8uICFcVzpdD9IXpnY2KURLTV7nU1fm9EC0iliRmLkiaTUTQ+rgWucdyS3vJel vdwPGslWDWFySIhjzGKSU72G3A4hCugwKQpNRymoJXG6RqddMGzjeLLQ1moYczy89RA9 PqCawCzkNwdidkQ4gV823cje8cF0Y/02kGqtq6qxNCSAvCjBxaliFuPfcEbTQEJmyWOo Toag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OrCsM1gB; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h10-20020a37de0a000000b006b921145770si4657886qkj.449.2022.08.15.12.12.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 Aug 2022 12:12:29 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OrCsM1gB; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:53464 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNfVj-00013f-JR for patch@linaro.org; Mon, 15 Aug 2022 15:12:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38216) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNfN0-0002y5-Og for qemu-devel@nongnu.org; Mon, 15 Aug 2022 15:03:26 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]:56175) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oNfMl-0006Kq-Fw for qemu-devel@nongnu.org; Mon, 15 Aug 2022 15:03:26 -0400 Received: by mail-wm1-x32e.google.com with SMTP id d5so1944860wms.5 for ; Mon, 15 Aug 2022 12:03:11 -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=yL2kCSEaX64Q/NPJAtRoJiqW85LCPcZ6AySZ3J3a/uE=; b=OrCsM1gBbnPay5eEdRjbJBP2AlvrnZEpp+mSTgO/wZSFxV6k3MEZT+wNFPoyyAvvCJ ZVyZbYwLV521HVBEJML8Ir58Qs43nc7IqnWmkY9/4vXwdgP50CaLtKW4WHM5TJgWkXY2 1lPNW7FpzR90IqAb7lCsG782CZ/1cKuZvmI9qFo68ih0z1/RmH3FZvvb+G/I9mrDJCV+ tioZJGijJBXlStK2gb22YdzHdxm9hj1C1CvOZ8csBl5aD4Xql8pfaTMyOK1uBAJQbuU9 ZZ3V1iIHK8NKYXeKrR0tkmy+9YDv7wPjC0QELHfar3DXdklqdeIEQ33ewgZdK/gwROoW YcZA== 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=yL2kCSEaX64Q/NPJAtRoJiqW85LCPcZ6AySZ3J3a/uE=; b=CUfXGS83Z2hO9NF6FyvudN+e0+Ip3lECy+IACLNgFrEpzZUBQY4Kw3wl1+eQyNZ9Ty go+HOUcE+YOBXCwTFGbIYu/Zb6Jtg9r27Fnpw1XC7YKWvwWL8VgRT6TAwk4LbFl18+YO u0iPouwF5uLrmzhffoEzMvMZGmnQy4rf6uxe2GZ6YxeixOusIYMdeasui4yZgFB9Xo4D S9yJ+KLY5ffAxvO3b0hTE46KWLTSfXaCj/iRH2CUOAt199/MOj/CVSfSMlKr1vPTBI42 uXV7/trfElPuRk4BdSUg+0JOrL0fLgsEPBcsn+igaZW1YF4Tf86Rt029kUYIv+ccWr9H pT9g== X-Gm-Message-State: ACgBeo0Z92lZqirIpWAot+m1hcMUi0YW7HgfEEnW7ykl9sz77P5woMop XhwusdDUKzkJylnQ+mGRVM/ECg== X-Received: by 2002:a05:600c:4f07:b0:3a3:2277:7064 with SMTP id l7-20020a05600c4f0700b003a322777064mr10859341wmq.181.1660590189958; Mon, 15 Aug 2022 12:03:09 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id u4-20020a5d5144000000b00220606afdf4sm8009162wrt.43.2022.08.15.12.03.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 12:03:09 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jiaxun Yang , Aleksandar Rikalo , Stefan Pejic , Chris Wulff , Marek Vasut , Palmer Dabbelt , Alistair Francis , Bin Meng , Max Filippov , Richard Henderson , Furquan Shaikh Subject: [PATCH 2/7] target/arm: Honour -semihosting-config userspace=on Date: Mon, 15 Aug 2022 20:02:58 +0100 Message-Id: <20220815190303.2061559-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220815190303.2061559-1-peter.maydell@linaro.org> References: <20220815190303.2061559-1-peter.maydell@linaro.org> MIME-Version: 1.0 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, 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Honour the commandline -semihosting-config userspace=on 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 --- 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 instruction. */ - if (semihosting_enabled(false) && imm16 == 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 == 0) { - unallocated_encoding(s); - break; - } -#endif + if (semihosting_enabled(s->current_el == 0) && imm16 == 0xf000) { 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 != 0 && -#endif + if (semihosting_enabled(s->current_el != 0) && (imm == (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 = 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 == 0) && (a->imm == 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 = s->thumb ? 0xab : 0x123456; - 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 == 0) && (a->imm == semihost_imm)) { gen_exception_internal_insn(s, s->pc_curr, EXCP_SEMIHOST); } else { From patchwork Mon Aug 15 19:02:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 597268 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp1761052maz; Mon, 15 Aug 2022 12:11:00 -0700 (PDT) X-Google-Smtp-Source: AA6agR7NKTVN06R9ricoB7ZVUuNLikvQBx9EtyP4rsaONjdOEq0Oi8/XX9PdIy0wx+tGUGxk6YcE X-Received: by 2002:a05:622a:1194:b0:343:7547:9e12 with SMTP id m20-20020a05622a119400b0034375479e12mr13361878qtk.654.1660590660259; Mon, 15 Aug 2022 12:11:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660590660; cv=none; d=google.com; s=arc-20160816; b=x6mDc4QoL/hwz6I/3wDDETHUv61LZvoRNWrqW9o9w9+DtsWxeK4+w+RCWOZyn/1tnG Q9Iltrn9/feu3aaysb4S9B/He6BSDL2TJn5E5zcQM1x/9yoJNUiGJe/fgCxDlXl1p6XR YcxOxboauI33erC1YZKCecvBryLGBCVUDs7ShchI5X1HYjv2Zaa4iDYoTJLb55SVNPKr BPzCeHNJa4Ud/7WMX3BRNGfxadXHah4K6PuUiUBm/o8DQZqdWjbJV9+SFg/4OnuAvHQQ euDCH/NQEbqNGNJB4KMO+kFhoPHP250sO/BhjMmVZT263LOhL31qkfobK3wYFK824RTi k9XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PrqYC+Ea+m5GjOCDRyOYZzhgmh4N94e3qWCRBEWRM+s=; b=u+KPC6cK1iO+2WPtsTRyXcx9sryp8jNBb7qsml28TZov0NP/2CuqcEt2NULcZEe9Uy MJubNSJT+07KW6qea6EueSj8caTEYLPxrsPgKNusU8B+l2mtRaZ7bsS2G2VsHNUU3bVt 3fhT4CIHvkx+m5COgyVt5H6OzqmkW2CWkSDAEd9qo+qtGxAe6xsfE2Iwi1v08B1jFegY 2QDUo/klHPDbx57VPRHrCqQp9m7KdxBNh+kKCy+QR1ofBqlqHPCzq91I5vb5xoMT2zIU JAdCin6SM3QTyfABZjU4/Wns5tlbAOeBQxOUY/9HgFS1+8tEYT9ylT7Li9eOmajtsdQu Gt/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DjVCRCi6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id fn9-20020ad45d69000000b00476d07f9e60si6287265qvb.336.2022.08.15.12.11.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 Aug 2022 12:11:00 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DjVCRCi6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49464 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNfUJ-0007qi-R2 for patch@linaro.org; Mon, 15 Aug 2022 15:10:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNfMp-0002fG-7U for qemu-devel@nongnu.org; Mon, 15 Aug 2022 15:03:15 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:42812) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oNfMm-0006LF-NY for qemu-devel@nongnu.org; Mon, 15 Aug 2022 15:03:14 -0400 Received: by mail-wr1-x432.google.com with SMTP id z12so10075165wrs.9 for ; Mon, 15 Aug 2022 12:03:12 -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=PrqYC+Ea+m5GjOCDRyOYZzhgmh4N94e3qWCRBEWRM+s=; b=DjVCRCi60O1vAe97iHukk9eRK7yHiuq9xuKeamidUhGOCB/NmI58spRh0s/Ki5XwwI HOxsU8cmasSptLjE8wyZH/mqIQeLlEFLU9FdWFKRQMekDyws75fLGUj42NyjwYtnbnjF pMBvvpAxoWezzsZeUaerQXRYnFeE5Le4gRGXU3WS5RPX+XdXimyBk6jeJaqXEyisPdPN PGXeq7TrhXTGjXqTpb308RNnjSOq3VbJE+0gjkowCtv2O9cMfW6sKXaecscOtuLgOFU8 tF1q4gZF9VajwtanfrWvp6bXbaXvu7ZvNUEFZZOud1+9CTgYudTsEyVxXXO2kiggEcGI FEVA== 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=PrqYC+Ea+m5GjOCDRyOYZzhgmh4N94e3qWCRBEWRM+s=; b=bThrkaVRaIZwbQFA8UXi+LRn2p57OEojOpiWGlFXOhvg+NAryRiK0O7lrFL8gr07W2 0s5UVghhsvrK1tfzkmMB19rSL3/7uhu5NzXP7plHNPq/wzVswecaxHgNvUUQOnlH9YEL o6q7yjyVsSXInNziUu4ebDrgwilLUoQw5ybeFNmRJHofhNZA7mbuI9B9YPgbbK2mVtpu QoRoWE1F5ikSaDGMLrK8vPApbSYr2q+HfzOs76WWMv3tcZKW2RJL+bmuuGJGLquGBu1j PKYwBerANSWUNBq3QzalDJiY7LzRHhLL68qzHCRoHxFjxhnzNFonL2PBuPxVzoUpPXjR DQdQ== X-Gm-Message-State: ACgBeo0aD+XWOAcRFuDkUk3Lm81wBNtx4hpdMZcxjV/Qh6+uw8Z4RgIn GpAgbakFZAO/ZCy0xDdqzqoZpQ== X-Received: by 2002:adf:e44b:0:b0:220:5bc5:e942 with SMTP id t11-20020adfe44b000000b002205bc5e942mr9410873wrm.179.1660590191359; Mon, 15 Aug 2022 12:03:11 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id u4-20020a5d5144000000b00220606afdf4sm8009162wrt.43.2022.08.15.12.03.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 12:03:10 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jiaxun Yang , Aleksandar Rikalo , Stefan Pejic , Chris Wulff , Marek Vasut , Palmer Dabbelt , Alistair Francis , Bin Meng , Max Filippov , Richard Henderson , Furquan Shaikh Subject: [PATCH 3/7] target/m68k: Honour -semihosting-config userspace=on Date: Mon, 15 Aug 2022 20:02:59 +0100 Message-Id: <20220815190303.2061559-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220815190303.2061559-1-peter.maydell@linaro.org> References: <20220815190303.2061559-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x432.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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Honour the commandline -semihosting-config userspace=on 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 --- 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) != 0 + if (semihosting_enabled((env->sr & SR_S) == 0) && (env->pc & 3) == 0 && cpu_lduw_code(env, env->pc - 4) == 0x4e71 && cpu_ldl_code(env, env->pc) == 0x4e7bf000) { From patchwork Mon Aug 15 19:03:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 597271 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp1764147maz; Mon, 15 Aug 2022 12:16:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR4VhzhDK5iiRclz20dumO+28L4fHstqYqsaGM3IIatoc5VrSnLwuSsO0dmtzDwsky8Vf9ki X-Received: by 2002:ad4:5ca9:0:b0:474:9143:6ffc with SMTP id q9-20020ad45ca9000000b0047491436ffcmr15319020qvh.19.1660590986679; Mon, 15 Aug 2022 12:16:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660590986; cv=none; d=google.com; s=arc-20160816; b=m/vP1j7ICZrS0wRASixLmYaHEuwOH0gP1F+JjZES7q6eA16k7gHlwnJalGDSYKb2zw 6UMP5Cf+8g0mUs+fpshDFuGtoA6y1fkVrq8Q2Iq6x/ZUdXnBZBihHR4AISBWGaRqTw4X 2PMxjWnicWczmM5qAsppwinp09z4iv8+47PidichRP0ht3NmyPvsGyTv+LRS1HV3Fg49 xixb+KOMZ8u0vyTaftvqPpFSQoV5WmnswO1gst3EJ1af8wlq9pWSrqJvTSGynO9EkHoz 8CgS3eURmXNh/VFbsy3Xqr4+oAxvHpTL02EJQzwL7ZpLNYQEZyd1ec9oHzi8VgUWHu2l 3sSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xcJI33C1DHi3d9nfTpTX8vbIVhI8bnlvIB9PE8+Un4Y=; b=lNOwG7C8IsvbRQ3XEMM5NGtYM4iFsJReIv0NXMSmWbBbsscakdC0UeJrBgLlBQ7gG8 1c5/XMD3ChyEays8Jpn45JlhNyshVBeebJpFDcbm/oEKACnxehf2zA/5Dyt55KcpD/hM VzRaTtfC9T+Z5/3A65eBxbq6QoyEFZ47Z7ypAzf+zxhg2iurdJoBmYebzx33USVaOcwL mnyoNZOLTAILlKxhAh+mN6hwdZ4YiSRbdAzDX6TCZpLajP85URVp6U1pM/22nfMlc5mw v0d4JIwH9BHkXdRui+EFFgxtJlrlsG6EI4BxppHSVTEu6QgTuu0wEjMPHxAMJVHrPeAx swcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fGwTRY6N; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bp44-20020a05622a1bac00b0031efceb8baesi5725962qtb.161.2022.08.15.12.16.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 Aug 2022 12:16:26 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fGwTRY6N; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNfZa-0004od-3D for patch@linaro.org; Mon, 15 Aug 2022 15:16:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38110) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNfMt-0002kH-JE for qemu-devel@nongnu.org; Mon, 15 Aug 2022 15:03:19 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]:45922) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oNfMo-0006Ls-HG for qemu-devel@nongnu.org; Mon, 15 Aug 2022 15:03:18 -0400 Received: by mail-wr1-x42b.google.com with SMTP id z16so10060677wrh.12 for ; Mon, 15 Aug 2022 12:03:14 -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=xcJI33C1DHi3d9nfTpTX8vbIVhI8bnlvIB9PE8+Un4Y=; b=fGwTRY6N33mOaaV0Po25Mvb9X9vuzlD6tq9kPDfxtmqZl5tC9EP8KW79JyrmKrMcc+ Lt+CxpdU8xluiqCMDlPlOQfGtIChUpMq7EELwW5gt6WbI71ArWbBHOXRlH5gFrH0koAX Nno2LhnrMBUf1cCkmVaZbye5CfRXffP5lhfyXMPDqiT85+qUhWBLZ4huqDo3paDvMu5f rtkf44MazwUtImHSDfd7BJIhKHa+oFHrEIN0U5u8Koj34CBUFeMg4wY0VY1+2mBcljbv LTyAOhnksTRwLFbpmHhIVjQyP6yXzNOZ84UE8PPoMhAEcqmcuzVRXc6BoacMRevttRhZ 1BWw== 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=xcJI33C1DHi3d9nfTpTX8vbIVhI8bnlvIB9PE8+Un4Y=; b=HwWny7D1E4O598JBlDrezXkVImEvR4+1wAszSSEGYHbREswXA7FJoLG5fmnoTp+52l CYY+FAp4//KX3IVC05Modli0DTul9+5UqmNPmBAHOhwL9QJyAuP8sfu6aLJ6zyD01fZT 6Y8tcDyFGAtW/4lxzbjgQauL4byZsjIPmHgZTIreOP0YAkO1dd98/x9Cphv7FiGWUxrQ 6y07Rzl/Vqpp2fSJ8zyEqEDPECR+0/wb2d8uHUJ1lTHoDuGgCk8h37TK/v6dynKnIZKj K1bIUv/giodrsXNDW7QvQT/e289b6vttRA3VB3iw7fiH0zS/nlULgFCPmhiwVPn+sA+x YYeg== X-Gm-Message-State: ACgBeo36lNSQN6S9F+G0Yg71OidbMtXtX2n/Bwb+kG8ualIOm2Bj2uHo kdEZ/3kn9+EN5kFlTOzFo4ltUA== X-Received: by 2002:a5d:5a1b:0:b0:220:638a:86c3 with SMTP id bq27-20020a5d5a1b000000b00220638a86c3mr9965862wrb.573.1660590193222; Mon, 15 Aug 2022 12:03:13 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id u4-20020a5d5144000000b00220606afdf4sm8009162wrt.43.2022.08.15.12.03.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 12:03:12 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jiaxun Yang , Aleksandar Rikalo , Stefan Pejic , Chris Wulff , Marek Vasut , Palmer Dabbelt , Alistair Francis , Bin Meng , Max Filippov , Richard Henderson , Furquan Shaikh Subject: [PATCH 4/7] target/mips: Honour -semihosting-config userspace=on Date: Mon, 15 Aug 2022 20:03:00 +0100 Message-Id: <20220815190303.2061559-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220815190303.2061559-1-peter.maydell@linaro.org> References: <20220815190303.2061559-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42b.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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Honour the commandline -semihosting-config userspace=on 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é --- 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); } -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 == 1; + bool is_user = (ctx->hflags & MIPS_HFLAG_KSU) == MIPS_HFLAG_UM; + return semihosting_enabled(is_user) && sdbbp_code == 1; #endif } @@ -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 = 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 = DISAS_SEMIHOST; } else { /* diff --git a/target/mips/tcg/micromips_translate.c.inc b/target/mips/tcg/micromips_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 = 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 = DISAS_SEMIHOST; } else { if (ctx->hflags & MIPS_HFLAG_SBRI) { @@ -1310,7 +1310,7 @@ static void gen_pool32axf(CPUMIPSState *env, DisasContext *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 = DISAS_SEMIHOST; } else { check_insn(ctx, ISA_MIPS_R1); diff --git a/target/mips/tcg/mips16e_translate.c.inc b/target/mips/tcg/mips16e_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, DisasContext *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 = DISAS_SEMIHOST; } else { /* diff --git a/target/mips/tcg/nanomips_translate.c.inc b/target/mips/tcg/nanomips_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 *env, 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 = DISAS_SEMIHOST; } else { if (ctx->hflags & MIPS_HFLAG_SBRI) { @@ -4633,7 +4633,7 @@ static int decode_isa_nanomips(CPUMIPSState *env, DisasContext *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 = DISAS_SEMIHOST; } else { if (ctx->hflags & MIPS_HFLAG_SBRI) { From patchwork Mon Aug 15 19:03:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 597267 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp1759780maz; Mon, 15 Aug 2022 12:08:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR6xDedO+KxBOXyHLARDnQy623w+bv64JKmInky1PrkOI2W86Rh5z4b77moUYgxUqpdUrS6W X-Received: by 2002:a05:622a:1789:b0:342:f439:f4b5 with SMTP id s9-20020a05622a178900b00342f439f4b5mr15396422qtk.298.1660590534154; Mon, 15 Aug 2022 12:08:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660590534; cv=none; d=google.com; s=arc-20160816; b=MIBhXZxTVrTlbP9RStWEHi6Edk2btUDmnyJn7Q+G8f2dho2TLeNKCvnZVb4yVwMTXw lZxWCfGogMCuyEekePHauiYCW07Ln1ecdOz6PKqbKv1+BJTCFOAFCRRhwTSxseGP0W1e oCUV2P9xEzl0VNXWl2NFKtKNsew/JyoB1JReEroJ/59LcZ/sgSf5a/BBZFGSwEmINU/Z 4SHF29JyRvTaisC/uIevBCMeBVY+vYubG0toxTaeLQ84ohQITCDxmxkmZfzP/OvBGPZ5 iICS50OzBBG7LOlZQU5SlM573jNXULYDU2IrnaxdBzt8bzLwOSqUOspheDXS4M9XP9Pe KOVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sjyUnMJzfq++0t8oacR/+QsHL+4P2X7RJJ6Y2pg/KDw=; b=zXyaMZCiEh6G6t1erNx18sgnJ5yPKDAQ2FEpYeuWGl8L7UvNkJGL+nQmil/IgLJ7gQ OKK/mqiE8KZAuItBP2Ljtsxet1kRoCBL7pHvxtC+bgIcN029md1Vz7t4cD/cboHDIapP lat54nK1La5A9OPCGY31yMIBHuoTeyNxnnLRNYAKR3nASjk6qChRGDhWl0fdL100n8HQ K3jZhgYodRLJdjzMO5STtry2WqAih5c7TmcmZFTcZ6TqVRXHQOgXmZ/MjnSlgBirbchQ 6Tugy9/oJPJTE0VcyTHJpAwuXJzLGTBhJ3baKW1uK7LNeFzjVY9DyvVogtU6HCtW5B0S /gNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UAj+CaFG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l12-20020ac8458c000000b00343719d1d3fsi6333643qtn.655.2022.08.15.12.08.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 Aug 2022 12:08:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UAj+CaFG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:41228 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNfSH-0005NF-Ny for patch@linaro.org; Mon, 15 Aug 2022 15:08:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38162) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNfMy-0002uL-T6 for qemu-devel@nongnu.org; Mon, 15 Aug 2022 15:03:25 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:36756) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oNfMp-0006KM-Uy for qemu-devel@nongnu.org; Mon, 15 Aug 2022 15:03:24 -0400 Received: by mail-wr1-x42f.google.com with SMTP id j7so10093024wrh.3 for ; Mon, 15 Aug 2022 12:03:15 -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=sjyUnMJzfq++0t8oacR/+QsHL+4P2X7RJJ6Y2pg/KDw=; b=UAj+CaFGYzEL5D7ZNriTDW2N797k1BN6Unm69rAFCPmO2hcVm+vkEeESdpQJ6eSDQf AFbHWqnSV/jqgkVJXkdIaFvvolSyadh41KMoII2FTx3yLWKN4Q+WY/a8snn2hc3A5HLm BRgGkdFRvSJ60eajasO4kykeAl7KzDv1TdHFXmvJNJClB1zbSTujppZ/nMfZw4KnHxb8 d8qlOnKn2f5ihClsar14O9GrtYNL0ooMGtI/vRjEb0bTsGRVR7mK7S8hUQ2053nvuMge 5QIcmJhcO9ZqM7UsODkBMXrCho6owfYQlNq+9onCMZjFg9ynF3bBepJqQ6E97fHrOI1D 1fLw== 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=sjyUnMJzfq++0t8oacR/+QsHL+4P2X7RJJ6Y2pg/KDw=; b=moWorx0d1jmC66CamXLOVQZ97tbTBbXTvVYshf1bRW+Igo++LigIdiWwtXNAwc3H3y +ZvXqbkhkmVUtEGESNcKiHJyRpU389XCE/y5YtJtDeU7t+QGF10g+AOvhXXriMp4xOwJ Ok8Xk8QRyl5oVzCWbK/sN8EbNVXY2j086zBOj+OqGPxnkNF4aorC2EljZxhr59ZHCuzs QpAk5RY4yQx0uzWqqoztKty6jKe0lthMn9It787ShBl6bNrQuojXMr7TR1HuuJRGupFs Rk+0Taf/OGJhjqHICPH9f/TeUoM9kQu6ePKLN9mfBh285qSPzv9PEG52Ve8IgxkpjcXh wJzA== X-Gm-Message-State: ACgBeo3EiU/RL7BqmMc+PeKjkBm8d3eLwhe+EHNZbu/X5DJ8RcNeFJpG xVsf3HfTnct5zW/p/q5o5+uWnA== X-Received: by 2002:adf:f7c7:0:b0:21e:fc10:b81b with SMTP id a7-20020adff7c7000000b0021efc10b81bmr9854483wrq.51.1660590195164; Mon, 15 Aug 2022 12:03:15 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id u4-20020a5d5144000000b00220606afdf4sm8009162wrt.43.2022.08.15.12.03.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 12:03:14 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jiaxun Yang , Aleksandar Rikalo , Stefan Pejic , Chris Wulff , Marek Vasut , Palmer Dabbelt , Alistair Francis , Bin Meng , Max Filippov , Richard Henderson , Furquan Shaikh Subject: [PATCH 5/7] target/nios2: Honour -semihosting-config userspace=on Date: Mon, 15 Aug 2022 20:03:01 +0100 Message-Id: <20220815190303.2061559-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220815190303.2061559-1-peter.maydell@linaro.org> References: <20220815190303.2061559-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42f.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=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=no 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Honour the commandline -semihosting-config userspace=on 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 --- 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 = FIELD_EX32(dc->tb_flags, TBFLAGS, U); R_TYPE(instr, code); - if (semihosting_enabled(false) && instr.imm5 == 1) { + if (semihosting_enabled(is_user) && instr.imm5 == 1) { t_gen_helper_raise_exception(dc, EXCP_SEMIHOST); return; } From patchwork Mon Aug 15 19:03:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 597272 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp1766954maz; Mon, 15 Aug 2022 12:21:32 -0700 (PDT) X-Google-Smtp-Source: AA6agR48I7ImhHb7Yo1xzxNKbodEzPMRnMbAeS5kxEBKmSOdHQbmPaP91DV2aHETzKD7SOiVCtcS X-Received: by 2002:a05:622a:392:b0:343:738e:6f6b with SMTP id j18-20020a05622a039200b00343738e6f6bmr14138768qtx.174.1660591292179; Mon, 15 Aug 2022 12:21:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660591292; cv=none; d=google.com; s=arc-20160816; b=OAgayxfAtR1ugubSXoDQ94UshMpbc8M0b+8WktOM47dwGaCBoOM4pJyzNl8NP3aySA iZviNCTRMbLLyc5o1p6cbiZUZ8uluWlAA29L9NTretTiOqaRw8xu6+r2Oqm72jBn1mte 4IMHLb4rj26oXl4xZAUadlzR/YY+Z20XIVLvO+Azq3ae8cUOqDQal6c+znBL7AATbxhe vRjgn2jpyEwDub9XKdqmOq2g/cVBPxVpiJDFk48uDJe2lGA7vrBMNrdzpN66VrU3Eefe LEvibDjY7lbwDVVtw8UzVsmZLcy4cAB/8I4AbD4iIs0jo8+W3+K5cex5x/4vcC8elg/A tzlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5A8TTs3Va2xGJWkOhhlXWoJrKWuE9dh71r64qnA1hXg=; b=oAKPBsNWg6Ve+gFITmbf+c6PIfCevaVemTc84z8wRwXaSXExnR5cgTBkS9JxWGCNTA 2HQKHiBqNy7lvhcOH3M0SQO7j5saQqUxHVoYvJiYbN9OVHQkxICPMUKJAAiGNWIN5ZuS awb/rW7pOd6N2NgvwqBuYfcKjEEZNWS4SRUMxry/mc/wa/u1iKmaK0bS9sE2+X9jm9JI dtwMgQ9VT0b+86OPwn+bbpSvGW7GuDkM/sFA5ATmQbBzuwLTUqSpuaKifwPewG/7wQZZ vT3Dan47YXWXj1rXQ0AdUPpMV2YIb5IYykNcroOWm/oCO8wkaiuLO3W9XsmdHT0vi/Lm 419w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TeWQ0uXT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d2-20020a05621421c200b00476f452b40esi7076618qvh.532.2022.08.15.12.21.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 Aug 2022 12:21:32 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TeWQ0uXT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:36356 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNfeV-0000pm-Pa for patch@linaro.org; Mon, 15 Aug 2022 15:21:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38220) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNfN0-0002yN-TY for qemu-devel@nongnu.org; Mon, 15 Aug 2022 15:03:26 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:38770) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oNfMr-0006K9-MY for qemu-devel@nongnu.org; Mon, 15 Aug 2022 15:03:26 -0400 Received: by mail-wr1-x432.google.com with SMTP id bv3so10096671wrb.5 for ; Mon, 15 Aug 2022 12:03:17 -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=5A8TTs3Va2xGJWkOhhlXWoJrKWuE9dh71r64qnA1hXg=; b=TeWQ0uXTpUmhrYxNlSOllS4QmD8AgsYS2jCWVfMlAFYXcQg2q8CEwCvzAKIYG86x1g uhlmYiGFqLV0s2WRElGq4bgYA/Xs2y1MIEoJPuwfB7ZSaZ5u/hrzSiEbfRDSXu1jYuU4 ORn50gpZ/884Cr0T9N0zuAoYGNpSM3I+3PE32sDYDc2aq+xzV4Gj2uKyV2YVBgwrsGf2 E4GycyuDeNprCM8ZAfVYFljaGEvUg8Ba++BKffpBcHQR7RSLpAyjm3wFszg0IjxfLQwD CFabguJUycjq5iVdrNRfLdbbls0bRnAxaidcXMaEFrINbd2oYydBtmLnt0eX87esq+qC rlLQ== 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=5A8TTs3Va2xGJWkOhhlXWoJrKWuE9dh71r64qnA1hXg=; b=hKg0WGjBZ1hcZ3+WLZVrA6EOkkf9BROjNOwwiIsvUdgVtfNlGuIjrjcOdlqTMfK+j+ Yjjpqifh1B3KE1CMzltaKo664e8WYnD7IaCR8674mOIPN0eL5oP5jA3k5lXV+VdsTMZ/ tcNj4zvUI/sgBpGkvExeehZ+00pY3XAAVagxY0JBfjdp/Vg0zBeFmSvmdAWYCgXz0JGg ZE/4kuc9/J/GosDtBA7fPNwc9KxCjnbrycKDLBCOmIezumM83xOkWDjqIBuLW3AxOX15 f2P3N9GtrJ+0eTIVteeyR3bdhA/GmtJlHcXCKScTLRSg1i9CDx5xvNknTo8L4ksPWRP4 yZAg== X-Gm-Message-State: ACgBeo1piEC5s6I6U5fJXN9oXQnj70iLIqRMbuRmICcBqXqbBsRarqj9 wuUXW9+9Zvt1wiHXkcdUgFNfjA== X-Received: by 2002:adf:a448:0:b0:223:a061:521b with SMTP id e8-20020adfa448000000b00223a061521bmr9765234wra.695.1660590196996; Mon, 15 Aug 2022 12:03:16 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id u4-20020a5d5144000000b00220606afdf4sm8009162wrt.43.2022.08.15.12.03.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 12:03:16 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jiaxun Yang , Aleksandar Rikalo , Stefan Pejic , Chris Wulff , Marek Vasut , Palmer Dabbelt , Alistair Francis , Bin Meng , Max Filippov , Richard Henderson , Furquan Shaikh Subject: [PATCH 6/7] target/xtensa: Honour -semihosting-config userspace=on Date: Mon, 15 Aug 2022 20:03:02 +0100 Message-Id: <20220815190303.2061559-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220815190303.2061559-1-peter.maydell@linaro.org> References: <20220815190303.2061559-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x432.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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Honour the commandline -semihosting-config userspace=on 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é --- 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(DisasContext *dc, const OpcodeArg arg[], const uint32_t par[]) { + bool is_semi = semihosting_enabled(dc->cring != 0); #ifdef CONFIG_USER_ONLY bool ill = true; #else /* Between RE.2 and RE.3 simcall opcode's become nop for the hardware. */ - bool ill = dc->config->hw_version <= 250002 && !semihosting_enabled(false); + bool ill = dc->config->hw_version <= 250002 && !is_semi; #endif - if (ill || !semihosting_enabled(false)) { + if (ill || !is_semi) { qemu_log_mask(LOG_GUEST_ERROR, "SIMCALL but semihosting is disabled\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 != 0)) { gen_helper_simcall(cpu_env); } #endif From patchwork Mon Aug 15 19:03:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 597270 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp1762469maz; Mon, 15 Aug 2022 12:13:24 -0700 (PDT) X-Google-Smtp-Source: AA6agR6mF7zEGlVSesBKlka9jsMjOO9p2XblW+OiIsIyrJpDFQNaC739jw3VLmI5lOaiVdWtUH7V X-Received: by 2002:ac8:5f08:0:b0:344:5cbe:c0f5 with SMTP id x8-20020ac85f08000000b003445cbec0f5mr5691752qta.356.1660590804065; Mon, 15 Aug 2022 12:13:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660590804; cv=none; d=google.com; s=arc-20160816; b=vyA0wjSR+7c6zRJv4OWPUGJVAVnKihDSaEvHlaAmoGzKKS2l4nUN6Zfgztnm8LLlFi DFCEhvvKNMxUuY6jm2ogj3q6V5kBistG8UJ8UxKtRMzC/b2UghFoYHTxTaw5SJRplhfF iNA8lEIL675YZX2P90RDWjyLc1UNl2ccc2FPjgifT99ebjCklNAjt24z6zyQckK/FE2r Or1SZpcs2GHxOx98tJZA3mD/KA6oruklxNb4EJDJdCAKz6viSJ1uXUvQXeMm0RCDL0uA bKx7hO4jbJILIBQV583BAd+i4D7t8aWdC+CvYNJL0b9fbanwg6auw9DjAeypsDz+PQ84 9JOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OGTDkR4LI4GDhkjGHuX42mV1KlnJTimkQ9agW47gbZY=; b=cj/NoGmW9JuuQ4YZeYR/cPIzOA/gUs/8VvF/tBYfSnARhmZSI3QRVM65edzwo5gLGR iiNpUQWQeyxUB12mnKLzXyKVf/43R4O6TBOMVV/0KIpMnoFHQ/RgPvYTBb3XavxOD1nm S8qRUFx7Lwj9oDznKXhxSqnQrkJQ75HgZ9g67xXD3rF4X7QW9foeXPonASyFtJe0CKhr MIlS7t8zpp3nuiuHWyvdC3vMnJaS47DuXOFaIzuv6dch5ufsmaaNoKr/QZlrXu7kxqbg qNjSEOM86S7sSWXuJeuUzB1CZYd+WxyU4ORjPtl7+GDlwKFbAZMhP/uqK3hvexAP2nM9 A5ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jknClf+t; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id hu9-20020a056214234900b00476f63f614esi6094953qvb.227.2022.08.15.12.13.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 Aug 2022 12:13:24 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jknClf+t; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNfWd-0001yq-Hc for patch@linaro.org; Mon, 15 Aug 2022 15:13:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38266) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNfN2-00031z-5g for qemu-devel@nongnu.org; Mon, 15 Aug 2022 15:03:28 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]:41952) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oNfMt-0006K7-7E for qemu-devel@nongnu.org; Mon, 15 Aug 2022 15:03:27 -0400 Received: by mail-wr1-x435.google.com with SMTP id p10so10089810wru.8 for ; Mon, 15 Aug 2022 12:03:18 -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=OGTDkR4LI4GDhkjGHuX42mV1KlnJTimkQ9agW47gbZY=; b=jknClf+toYIvPEkgUrydqqr9UCEeCEr58GLRzowOM/IR+L5/RRiMyasTBBMRmmqRh+ VXmtjuUtV6pE17LQfKKL1GbOlJaW2ahc7y2BGrrhYaOsBJt9c+92OFP70Cj8GUH4cpjt FP+5S80H/lA3PfnsxbmYnpY4GG0F1g+qU5vO2TzsFXTvUY77ZLJIIbo/FeIaxLDF36xv a2R0r4ph5J4G45NgcdWOmn1wde72VHauCcdnjAES4VC1OApf+xdpoHJrnLBL4816MbHb KfF6rPf/qLx6WS2D4wOZsqK+d6jo6DcvcytgBHs1PuU0pgP5sxVqEV35A3KcyEKUgdq8 ljuw== 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=OGTDkR4LI4GDhkjGHuX42mV1KlnJTimkQ9agW47gbZY=; b=Lm1OEQhN+aEeP02Min4lhcJ8fl9Rkq6NHiPivdwK4+XLvrhjWswRU/WaBrFtu4j/h+ QhYDijkLfwYwQRaqDQXU/QqfDXAzrZ2GKWsaqimmpB8rPjsDf58W4C4U5ZjWPx1GgPSx RkvI0ZPvoXrF2unHarDLso0cO7mvGs0ynsHm6o6X29FgVFyHnbfHplRu7Rx9/8YTqSKr HsF+J21rs0pTnl8u/+D1/RB/W7Ys7x5cellf9RMXrs/Z9g7ktqHH0pbKnWfOOdke5x4w g1axd780TvwGmYJma7ufKhoLHyBi8+AOskRgLBcuogSb6YvpWM6qxlJg82NQOh/l4hE0 qjwg== X-Gm-Message-State: ACgBeo0CVhQjr5XFEmP0LOESpz0XIBYxToYHKCjsyUdwdURH8LAH4jqR TwphGE7/7LpeniM6lFg1O3HOsGONa8JH/Q== X-Received: by 2002:a5d:6047:0:b0:220:6dc5:73ee with SMTP id j7-20020a5d6047000000b002206dc573eemr9634750wrt.213.1660590198464; Mon, 15 Aug 2022 12:03:18 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id u4-20020a5d5144000000b00220606afdf4sm8009162wrt.43.2022.08.15.12.03.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 12:03:18 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jiaxun Yang , Aleksandar Rikalo , Stefan Pejic , Chris Wulff , Marek Vasut , Palmer Dabbelt , Alistair Francis , Bin Meng , Max Filippov , Richard Henderson , Furquan Shaikh Subject: [PATCH 7/7] target/riscv: Honour -semihosting-config userspace=on and enable=on Date: Mon, 15 Aug 2022 20:03:03 +0100 Message-Id: <20220815190303.2061559-8-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220815190303.2061559-1-peter.maydell@linaro.org> References: <20220815190303.2061559-1-peter.maydell@linaro.org> MIME-Version: 1.0 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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=on argument. Note that this is a behaviour change: we used to default to semihosting being enabled, and now the user must pass "-semihosting-config enable=on" if they want it. Signed-off-by: Peter Maydell Reviewed-by: Alistair Francis --- target/riscv/cpu_helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 59b3680b1b2..49c4ea98ac9 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -24,6 +24,7 @@ #include "exec/exec-all.h" #include "tcg/tcg-op.h" #include "trace.h" +#include "semihosting/semihost.h" #include "semihosting/common-semi.h" int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch) @@ -1342,7 +1343,7 @@ void riscv_cpu_do_interrupt(CPUState *cs) target_ulong mtval2 = 0; if (cause == RISCV_EXCP_SEMIHOST) { - if (env->priv >= PRV_S) { + if (semihosting_enabled(env->priv < PRV_S)) { do_common_semihosting(cs); env->pc += 4; return;