From patchwork Tue May 14 15:52:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 164219 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2797195ili; Tue, 14 May 2019 08:58:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqyrES9YvxvoeX0j9S0+b3sB8KVkJIQ5+LAYxV8IcXpZtnr4+6dhDDoKtKQfLEcfYm/FmaQe X-Received: by 2002:a17:906:2ac5:: with SMTP id m5mr28740739eje.71.1557849523178; Tue, 14 May 2019 08:58:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557849523; cv=none; d=google.com; s=arc-20160816; b=lrsrlK06W6vqWT6+ECt+91VBbTqZAGoCCvl2Gqf/1use1VcnXz9UC544ufFIIIaKI1 BgCHljyJ7UQA1hW4Hx8EVwVxAVaX6SvLbkfBxQYFDUipVeSdLOaqDYvBlzy6kWywYzvP 7o6R/nC+4FcucOAL3qm59o1QGqkO9tLwutPB/xWvA4dJPpUhIWQkZ9V+im/KrASERkn+ 8RqWlavtll2wXJoYa6XRTezjU0U/3bjlDkPLe69iTQUT9uL06LoPcEFl1nU2PtnXyV4v 7NgXKDQHZ7oa16s8k1AQA7AaDME07W+JEKw4bhPstnqDyKhXtJUfAthFx1MNhY32bb4F OXbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=LkIQoYRogYWf/nAfvY/NE8geNYabwmvt63Bf8EocCfk=; b=eCe6rh/EkPFcRHpohYyf5oD65cbw6tmZRHOQ5Q4+GIQ6v0+93Km+GnGbkPlEDx6qfG oUVA5wQ34hwrcxyxCogJPk+v2ZLgasrpU/F/IE3eIRVsp3TECwncyME+dn9zraznFqgq hVnoDgxqcsgRoIjoVQJvpCHfzEDE9PYlLwKQPSatZ9+gwRn07jeq9RSLztcVzawJGQ/R p+93fJokVMmLkfCG9JFnohIduhPyfiulbAo9bvm5g4XM972Ua5IDpIIBfiq/wcSBYv7Z CjaqyQ3ZsX4o9JX/XUNLWCBv0RHRzjyxCDF0ECOhU3L6eyw3q10epN4C52jlaTsBttGE YiSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=SsInOEMT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 31si515025edr.130.2019.05.14.08.58.42 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 08:58: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=fail header.i=@linaro.org header.s=google header.b=SsInOEMT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:50240 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQZpB-0001fh-NU for patch@linaro.org; Tue, 14 May 2019 11:58:41 -0400 Received: from eggs.gnu.org ([209.51.188.92]:60351) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQZjo-0004kV-MN for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQZjm-00069l-1P for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:08 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:36186) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQZjl-00065g-MZ for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:05 -0400 Received: by mail-wr1-x443.google.com with SMTP id s17so3348368wru.3 for ; Tue, 14 May 2019 08:53:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LkIQoYRogYWf/nAfvY/NE8geNYabwmvt63Bf8EocCfk=; b=SsInOEMTAfhhaosqjO+tuCz+5/kmvYWF0lbb1gwnw36UX/r3E7OssjRY/vShLLCtTL tlqU36IYxluyPPvSJJMfqk3WDFqR/08OFccMmKJIDkwy7nwXu5BeEkYXd2L6lh0LdEth X7w7mnxymeDGvrlPChNJQgWZlvNV9oiPvqB/ZkEl7bNHvew+s+dgIFhwhy6QfqumWbw8 X49t3gUSZi2Gag+q3L2HFbc3XFVCpYNoxptekZAtJmOfM9mT+1sCmPbS1Yi1nvrYFXCO pIKa/+a4V/ng7evHaPNpirAgZ13CF+lHYbFn9kgBqrcz7RFGqTZtDpOkmqxIwmQuPEfB 7Xrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LkIQoYRogYWf/nAfvY/NE8geNYabwmvt63Bf8EocCfk=; b=ClOAyc1kOxuFUYM/0OJDqXBbaQJPh4mRItrOPIUdBC7WkAfuMi/prhe0rVQqLPWdEj P5j1bbm8KMth4EPt16czYjA1ii+VDDU9k5P3YNXD9lgpa00/l55wMogwH0Q8C9BYW5pp L+mVFFBM8jOmG+1TUk6xSo2+hufMhnRAgaDZTgnzy+/nopo0hpSLczosz9bS9cNZvKCe EfJ1aP6P2ks8B2uSLK2lL8tEgzEBunSM6CILe2nEzvll8hxJQExczjFuL7lP/sGOXNNU rjFwP9xcgJGDi3XmC2t5KzZRUpqWNghZScLytTGZIqG8ZrC0oIrzNXhlkbzdTGWN1TQI ucxQ== X-Gm-Message-State: APjAAAWKfyuODIyrq0A01Cc1rx2YJfag6Il1AEvUrya97uxZpQayTTXX mXUGNzQGa7dLQOT1hIc8MKvfZQ== X-Received: by 2002:a5d:6a52:: with SMTP id t18mr19927180wrw.146.1557849184253; Tue, 14 May 2019 08:53:04 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id t13sm25642413wra.81.2019.05.14.08.53.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 08:53:02 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 0EF161FF8C; Tue, 14 May 2019 16:53:02 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 16:52:51 +0100 Message-Id: <20190514155301.16123-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190514155301.16123-1-alex.bennee@linaro.org> References: <20190514155301.16123-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 Subject: [Qemu-devel] [RFC PATCH 01/11] semihosting: move semihosting configuration into its own directory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marek Vasut , Peter Maydell , Aleksandar Rikalo , Chris Wulff , Laurent Vivier , Max Filippov , Michael Walle , qemu-arm@nongnu.org, Aleksandar Markovic , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Aurelien Jarno Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" In preparation for having some more common semihosting code let's excise the current config magic from vl.c into its own file. We shall later add more conditionals to the build configurations so we can avoid building this if we don't need it. Signed-off-by: Alex Bennée --- gdbstub.c | 2 +- hw/Makefile.objs | 1 + hw/mips/mips_malta.c | 2 +- hw/semihosting/Makefile.objs | 1 + hw/semihosting/config.c | 160 ++++++++++++++++++++ include/{exec => hw/semihosting}/semihost.h | 10 +- include/sysemu/sysemu.h | 1 + target/arm/arm-semi.c | 2 +- target/arm/helper.c | 2 +- target/arm/translate-a64.c | 2 +- target/arm/translate.c | 2 +- target/lm32/helper.c | 2 +- target/m68k/op_helper.c | 2 +- target/mips/mips-semi.c | 2 +- target/mips/translate.c | 2 +- target/nios2/helper.c | 2 +- target/xtensa/translate.c | 2 +- target/xtensa/xtensa-semi.c | 2 +- vl.c | 126 +-------------- 19 files changed, 186 insertions(+), 139 deletions(-) create mode 100644 hw/semihosting/Makefile.objs create mode 100644 hw/semihosting/config.c rename include/{exec => hw/semihosting}/semihost.h (85%) -- 2.20.1 Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé diff --git a/gdbstub.c b/gdbstub.c index d54abd17cc2..793218bb43a 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -37,7 +37,7 @@ #include "qemu/sockets.h" #include "sysemu/hw_accel.h" #include "sysemu/kvm.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "exec/exec-all.h" #ifdef CONFIG_USER_ONLY diff --git a/hw/Makefile.objs b/hw/Makefile.objs index 82aa7fab8e4..d770926ba96 100644 --- a/hw/Makefile.objs +++ b/hw/Makefile.objs @@ -36,6 +36,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += watchdog/ devices-dirs-$(CONFIG_SOFTMMU) += xen/ devices-dirs-$(CONFIG_MEM_DEVICE) += mem/ devices-dirs-$(CONFIG_SOFTMMU) += smbios/ +devices-dirs-y += semihosting/ devices-dirs-y += core/ common-obj-y += $(devices-dirs-y) obj-y += $(devices-dirs-y) diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c index 439665ab45e..3b009fda25f 100644 --- a/hw/mips/mips_malta.c +++ b/hw/mips/mips_malta.c @@ -55,7 +55,7 @@ #include "qemu/error-report.h" #include "hw/empty_slot.h" #include "sysemu/kvm.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "hw/mips/cps.h" #define ENVP_ADDR 0x80002000l diff --git a/hw/semihosting/Makefile.objs b/hw/semihosting/Makefile.objs new file mode 100644 index 00000000000..546954f4ff4 --- /dev/null +++ b/hw/semihosting/Makefile.objs @@ -0,0 +1 @@ +common-obj-$(CONFIG_SOFTMMU) += config.o diff --git a/hw/semihosting/config.c b/hw/semihosting/config.c new file mode 100644 index 00000000000..f1d3fe1e4c6 --- /dev/null +++ b/hw/semihosting/config.c @@ -0,0 +1,160 @@ +/* + * Semihosting configuration + * + * Copyright (c) 2015 Imagination Technologies + * Copyright (c) 2019 Linaro Ltd + * + * This controls the configuration of semihosting for all guest + * targets that support it. Architecture specific handling is handled + * in target/HW/HW-semi.c + * + * Semihosting is sightly strange in that it is also supported by some + * linux-user targets. However in that use case no configuration of + * the outputs and command lines is supported. + * + * The config module is common to all softmmu targets however as vl.c + * needs to link against the helpers. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/option.h" +#include "qemu/config-file.h" +#include "qemu/error-report.h" +#include "hw/semihosting/semihost.h" + +QemuOptsList qemu_semihosting_config_opts = { + .name = "semihosting-config", + .implied_opt_name = "enable", + .head = QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts.head), + .desc = { + { + .name = "enable", + .type = QEMU_OPT_BOOL, + }, { + .name = "target", + .type = QEMU_OPT_STRING, + }, { + .name = "arg", + .type = QEMU_OPT_STRING, + }, + { /* end of list */ } + }, +}; + +typedef struct SemihostingConfig { + bool enabled; + SemihostingTarget target; + const char **argv; + int argc; + const char *cmdline; /* concatenated argv */ +} SemihostingConfig; + +static SemihostingConfig semihosting; + +bool semihosting_enabled(void) +{ + return semihosting.enabled; +} + +SemihostingTarget semihosting_get_target(void) +{ + return semihosting.target; +} + +const char *semihosting_get_arg(int i) +{ + if (i >= semihosting.argc) { + return NULL; + } + return semihosting.argv[i]; +} + +int semihosting_get_argc(void) +{ + return semihosting.argc; +} + +const char *semihosting_get_cmdline(void) +{ + if (semihosting.cmdline == NULL && semihosting.argc > 0) { + semihosting.cmdline = g_strjoinv(" ", (gchar **)semihosting.argv); + } + return semihosting.cmdline; +} + +static int add_semihosting_arg(void *opaque, + const char *name, const char *val, + Error **errp) +{ + SemihostingConfig *s = opaque; + if (strcmp(name, "arg") == 0) { + s->argc++; + /* one extra element as g_strjoinv() expects NULL-terminated array */ + s->argv = g_realloc(s->argv, (s->argc + 1) * sizeof(void *)); + s->argv[s->argc - 1] = val; + s->argv[s->argc] = NULL; + } + return 0; +} + +/* Use strings passed via -kernel/-append to initialize semihosting.argv[] */ +void semihosting_arg_fallback(const char *file, const char *cmd) +{ + char *cmd_token; + + /* argv[0] */ + add_semihosting_arg(&semihosting, "arg", file, NULL); + + /* split -append and initialize argv[1..n] */ + cmd_token = strtok(g_strdup(cmd), " "); + while (cmd_token) { + add_semihosting_arg(&semihosting, "arg", cmd_token, NULL); + cmd_token = strtok(NULL, " "); + } +} + +void qemu_semihosting_enable(void) +{ + semihosting.enabled = true; + semihosting.target = SEMIHOSTING_TARGET_AUTO; +} + +int qemu_semihosting_config_options(const char *optarg) +{ + QemuOptsList *opt_list = qemu_find_opts("semihosting-config"); + QemuOpts *opts = qemu_opts_parse_noisily(opt_list, optarg, false); + + semihosting.enabled = true; + + if (opts != NULL) { + semihosting.enabled = qemu_opt_get_bool(opts, "enable", + true); + const char *target = qemu_opt_get(opts, "target"); + if (target != NULL) { + if (strcmp("native", target) == 0) { + semihosting.target = SEMIHOSTING_TARGET_NATIVE; + } else if (strcmp("gdb", target) == 0) { + semihosting.target = SEMIHOSTING_TARGET_GDB; + } else if (strcmp("auto", target) == 0) { + semihosting.target = SEMIHOSTING_TARGET_AUTO; + } else { + error_report("unsupported semihosting-config %s", + optarg); + return 1; + } + } else { + semihosting.target = SEMIHOSTING_TARGET_AUTO; + } + /* Set semihosting argument count and vector */ + qemu_opt_foreach(opts, add_semihosting_arg, + &semihosting, NULL); + } else { + error_report("unsupported semihosting-config %s", optarg); + return 1; + } + + return 0; +} + diff --git a/include/exec/semihost.h b/include/hw/semihosting/semihost.h similarity index 85% rename from include/exec/semihost.h rename to include/hw/semihosting/semihost.h index 5980939c7b8..07ea40a322f 100644 --- a/include/exec/semihost.h +++ b/include/hw/semihosting/semihost.h @@ -51,12 +51,16 @@ static inline const char *semihosting_get_cmdline(void) { return NULL; } -#else +#else /* !CONFIG_USER_ONLY */ bool semihosting_enabled(void); SemihostingTarget semihosting_get_target(void); const char *semihosting_get_arg(int i); int semihosting_get_argc(void); const char *semihosting_get_cmdline(void); -#endif +void semihosting_arg_fallback(const char *file, const char *cmd); +/* for vl.c hooks */ +void qemu_semihosting_enable(void); +int qemu_semihosting_config_options(const char *opt); +#endif /* CONFIG_USER_ONLY */ -#endif +#endif /* SEMIHOST_H */ diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 5f133cae837..61579ae71ef 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -193,5 +193,6 @@ extern QemuOptsList qemu_nic_opts; extern QemuOptsList qemu_net_opts; extern QemuOptsList qemu_global_opts; extern QemuOptsList qemu_mon_opts; +extern QemuOptsList qemu_semihosting_config_opts; #endif diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 8b5fd7bc6e3..3273306c8ea 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -21,7 +21,7 @@ #include "qemu/osdep.h" #include "cpu.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" diff --git a/target/arm/helper.c b/target/arm/helper.c index 1e6eb0d0f36..bc20cb3b9e2 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -16,7 +16,7 @@ #include "exec/cpu_ldst.h" #include "arm_ldst.h" #include /* For crc32 */ -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "sysemu/cpus.h" #include "sysemu/kvm.h" #include "fpu/softfloat.h" diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index b7c5a928b4a..8844a75e53d 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -29,7 +29,7 @@ #include "qemu/host-utils.h" #include "qemu/qemu-print.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "exec/gen-icount.h" #include "exec/helper-proto.h" diff --git a/target/arm/translate.c b/target/arm/translate.c index dd053c80d62..f2a65c0b5b0 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -30,7 +30,7 @@ #include "qemu/bitops.h" #include "qemu/qemu-print.h" #include "arm_ldst.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "exec/helper-proto.h" #include "exec/helper-gen.h" diff --git a/target/lm32/helper.c b/target/lm32/helper.c index a039a993ffe..e83cdf43182 100644 --- a/target/lm32/helper.c +++ b/target/lm32/helper.c @@ -22,7 +22,7 @@ #include "exec/exec-all.h" #include "qemu/host-utils.h" #include "sysemu/sysemu.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "exec/log.h" int lm32_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int size, int rw, diff --git a/target/m68k/op_helper.c b/target/m68k/op_helper.c index 76f439985a0..ee578f8d60d 100644 --- a/target/m68k/op_helper.c +++ b/target/m68k/op_helper.c @@ -21,7 +21,7 @@ #include "exec/helper-proto.h" #include "exec/exec-all.h" #include "exec/cpu_ldst.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #if defined(CONFIG_USER_ONLY) diff --git a/target/mips/mips-semi.c b/target/mips/mips-semi.c index a7aefbaefc8..eac8374fb34 100644 --- a/target/mips/mips-semi.c +++ b/target/mips/mips-semi.c @@ -22,7 +22,7 @@ #include "qemu/log.h" #include "exec/helper-proto.h" #include "exec/softmmu-semi.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" typedef enum UHIOp { UHI_exit = 1, diff --git a/target/mips/translate.c b/target/mips/translate.c index f96c0d01ef1..3cd5b11b16b 100644 --- a/target/mips/translate.c +++ b/target/mips/translate.c @@ -32,7 +32,7 @@ #include "exec/helper-proto.h" #include "exec/helper-gen.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "target/mips/trace.h" #include "trace-tcg.h" diff --git a/target/nios2/helper.c b/target/nios2/helper.c index e01fc1ff3e7..a3bd93e483d 100644 --- a/target/nios2/helper.c +++ b/target/nios2/helper.c @@ -26,7 +26,7 @@ #include "exec/cpu_ldst.h" #include "exec/log.h" #include "exec/helper-proto.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #if defined(CONFIG_USER_ONLY) diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c index b063fa85f26..6bdc244b583 100644 --- a/target/xtensa/translate.c +++ b/target/xtensa/translate.c @@ -38,7 +38,7 @@ #include "qemu/qemu-print.h" #include "sysemu/sysemu.h" #include "exec/cpu_ldst.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "exec/translator.h" #include "exec/helper-proto.h" diff --git a/target/xtensa/xtensa-semi.c b/target/xtensa/xtensa-semi.c index 5f5ce4f344c..38efa3485af 100644 --- a/target/xtensa/xtensa-semi.c +++ b/target/xtensa/xtensa-semi.c @@ -29,7 +29,7 @@ #include "cpu.h" #include "chardev/char-fe.h" #include "exec/helper-proto.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "qapi/error.h" #include "qemu/log.h" #include "sysemu/sysemu.h" diff --git a/vl.c b/vl.c index b6709514c1b..fba48b565c9 100644 --- a/vl.c +++ b/vl.c @@ -116,7 +116,7 @@ int main(int argc, char **argv) #include "qapi/opts-visitor.h" #include "qapi/clone-visitor.h" #include "qom/object_interfaces.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "crypto/init.h" #include "sysemu/replay.h" #include "qapi/qapi-events-run-state.h" @@ -500,25 +500,6 @@ static QemuOptsList qemu_icount_opts = { }, }; -static QemuOptsList qemu_semihosting_config_opts = { - .name = "semihosting-config", - .implied_opt_name = "enable", - .head = QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts.head), - .desc = { - { - .name = "enable", - .type = QEMU_OPT_BOOL, - }, { - .name = "target", - .type = QEMU_OPT_STRING, - }, { - .name = "arg", - .type = QEMU_OPT_STRING, - }, - { /* end of list */ } - }, -}; - static QemuOptsList qemu_fw_cfg_opts = { .name = "fw_cfg", .implied_opt_name = "name", @@ -1350,80 +1331,6 @@ static void configure_msg(QemuOpts *opts) enable_timestamp_msg = qemu_opt_get_bool(opts, "timestamp", true); } -/***********************************************************/ -/* Semihosting */ - -typedef struct SemihostingConfig { - bool enabled; - SemihostingTarget target; - const char **argv; - int argc; - const char *cmdline; /* concatenated argv */ -} SemihostingConfig; - -static SemihostingConfig semihosting; - -bool semihosting_enabled(void) -{ - return semihosting.enabled; -} - -SemihostingTarget semihosting_get_target(void) -{ - return semihosting.target; -} - -const char *semihosting_get_arg(int i) -{ - if (i >= semihosting.argc) { - return NULL; - } - return semihosting.argv[i]; -} - -int semihosting_get_argc(void) -{ - return semihosting.argc; -} - -const char *semihosting_get_cmdline(void) -{ - if (semihosting.cmdline == NULL && semihosting.argc > 0) { - semihosting.cmdline = g_strjoinv(" ", (gchar **)semihosting.argv); - } - return semihosting.cmdline; -} - -static int add_semihosting_arg(void *opaque, - const char *name, const char *val, - Error **errp) -{ - SemihostingConfig *s = opaque; - if (strcmp(name, "arg") == 0) { - s->argc++; - /* one extra element as g_strjoinv() expects NULL-terminated array */ - s->argv = g_realloc(s->argv, (s->argc + 1) * sizeof(void *)); - s->argv[s->argc - 1] = val; - s->argv[s->argc] = NULL; - } - return 0; -} - -/* Use strings passed via -kernel/-append to initialize semihosting.argv[] */ -static inline void semihosting_arg_fallback(const char *file, const char *cmd) -{ - char *cmd_token; - - /* argv[0] */ - add_semihosting_arg(&semihosting, "arg", file, NULL); - - /* split -append and initialize argv[1..n] */ - cmd_token = strtok(g_strdup(cmd), " "); - while (cmd_token) { - add_semihosting_arg(&semihosting, "arg", cmd_token, NULL); - cmd_token = strtok(NULL, " "); - } -} /* Now we still need this for compatibility with XEN. */ bool has_igd_gfx_passthru; @@ -3733,37 +3640,10 @@ int main(int argc, char **argv, char **envp) nb_option_roms++; break; case QEMU_OPTION_semihosting: - semihosting.enabled = true; - semihosting.target = SEMIHOSTING_TARGET_AUTO; + qemu_semihosting_enable(); break; case QEMU_OPTION_semihosting_config: - semihosting.enabled = true; - opts = qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"), - optarg, false); - if (opts != NULL) { - semihosting.enabled = qemu_opt_get_bool(opts, "enable", - true); - const char *target = qemu_opt_get(opts, "target"); - if (target != NULL) { - if (strcmp("native", target) == 0) { - semihosting.target = SEMIHOSTING_TARGET_NATIVE; - } else if (strcmp("gdb", target) == 0) { - semihosting.target = SEMIHOSTING_TARGET_GDB; - } else if (strcmp("auto", target) == 0) { - semihosting.target = SEMIHOSTING_TARGET_AUTO; - } else { - error_report("unsupported semihosting-config %s", - optarg); - exit(1); - } - } else { - semihosting.target = SEMIHOSTING_TARGET_AUTO; - } - /* Set semihosting argument count and vector */ - qemu_opt_foreach(opts, add_semihosting_arg, - &semihosting, NULL); - } else { - error_report("unsupported semihosting-config %s", optarg); + if (qemu_semihosting_config_options(optarg) != 0) { exit(1); } break; From patchwork Tue May 14 15:52:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 164215 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2792213ili; Tue, 14 May 2019 08:53:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqwtC6cwCjt3NYRftESMBUssIXkYLRb5OqMC6klsm78Y7StE4SwefgeO4heN/++xw6GEBFiV X-Received: by 2002:a17:907:20ac:: with SMTP id pw12mr25250074ejb.284.1557849215362; Tue, 14 May 2019 08:53:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557849215; cv=none; d=google.com; s=arc-20160816; b=hGEkb1ebxgqO0P04Uo58Sy751wlf0944yZ3rI/SEbQA+cWMLQ1TcnqNPQMAVTGwOK3 /lp0oquYD2yTO4qYsZGm25+AGp3SZTWvi7GYfbeQQtl+lxFFLqCw96u6BFmPZGHS+XKI Lbu8orBZwXOyimtH5o7RrvkJSGAEqZHGqblpg+lQflJHHK9DXYML7B74jK/QU5t30SLe Bt96if0590eGyYekqoH4i9mPHrseDgti1LgPaG9duWsVP9kXVOoK+x3SiGyEu5yuknpe vtgjNjf6S7S8PP1ScSLTF6o43X0PTdenErrOAOI23pbm7BTnUnnee3/bLTyi3pH8QIeu yWJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=yMHrC51RIDRA86f0abxaIpsijFG/dJpE/elLKV5MXbE=; b=cE1a5eMnaAxegcYA4ysE5mSNCcncR6AwMm+mcBJW9KdnaBAzX9rz1kcdZr5mKHKDq0 kKa3mCWTdi/QV8U7K28XiZXpUQOdhDJhdjoVH0UMO2hNKBmUmvYfbPodd3i+aE2tFLFj 7pYKezlr/lt29YiuGjvkW9brsJAcF+7Mu29f2ShV4LH7x2dqsHQJNkJhI7+eyxq38aUp Gisjp+jUYlOs0E9lMET47G3vydpS4PibZdK1cXZcK69hByGglX2PrJvnl+xTY2hPZLuJ kZesnJsOSssJY8P7lOn/KmXb1BHt2hdPG7JDYqR22B/XL2rglnu+uu//63NCRX37l7Kq Y7vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=baR8og91; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x28si1185257edd.32.2019.05.14.08.53.35 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 08:53:35 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=baR8og91; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:50156 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQZkE-0004m2-62 for patch@linaro.org; Tue, 14 May 2019 11:53:34 -0400 Received: from eggs.gnu.org ([209.51.188.92]:60283) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQZjm-0004iS-HX for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQZjl-000661-06 for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:06 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:54200) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQZjk-00062W-PY for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:04 -0400 Received: by mail-wm1-x342.google.com with SMTP id 198so3424081wme.3 for ; Tue, 14 May 2019 08:53:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yMHrC51RIDRA86f0abxaIpsijFG/dJpE/elLKV5MXbE=; b=baR8og91bZp3WMsY96nXn1DD6Wggemt1aexnoT5iD6wn2xAXwUs30ljdDZvedjtktI JhVT6uNz6siLPiJoS/h4qMX3/ABIU3Ph4H8peXt64U3EzpeR5EfDk2lGUWHRwiijbS10 lK+PDrc/neQJ/OIPgL9liuzj/lEFAKYsUz0AzN217aqOdf3KTiaIqY2rkhwp6i6uN2SF A4AU0ZjfKJ2eZAOGBBZXtE2/7lQuLreyKwzxN7CLiyOA9sJEqcGVnlhCXFEwHs8fKGMm uy4Ivh3R+arVe6WSHywbZlJxqQuYmXW3cyWHsopbK+IYjWRhFBhDwTRo/HF3e7AsR39v UqGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yMHrC51RIDRA86f0abxaIpsijFG/dJpE/elLKV5MXbE=; b=SX/d2Yq1cOg2J73EE225LLNXaBqtQwYyjXslc915nJqXXQIqDprxxk0A1BMwpWUUBc OzqfqbN/odvKoMX9hFmnQ5vZIEb3SB0zbki0axsa9KszDcFz2LKY/25uVrviBGNdZJMG 9/W3SGowg2nX+wRlZQA7wbidUcJ4sNlmxPTNMK6e04N1Gy/6DyKa6ih7+NLDm/C2NCWd lfCFaJ+es62uliJkq1BOazL4Fk29JWT+ooU+Gtqo4xkayTZk+W1evpgTMkhV7WrZoVkC wKniaGPVSM6ywqGwoJtS9Add6J8ypLcN6NT/4bv16fJvbQmSpwWZsh+h3vsPpZg+C9Nj ynaQ== X-Gm-Message-State: APjAAAW/o+rnQEc290R1+be8pxbotIGUikI4CaUMF1M1Ywiu9qCV1nxc a1dijQehpSehl5PYyd92nb+dlw== X-Received: by 2002:a1c:dcc2:: with SMTP id t185mr21284424wmg.143.1557849183522; Tue, 14 May 2019 08:53:03 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id g127sm3836628wme.21.2019.05.14.08.53.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 08:53:02 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 310991FF8F; Tue, 14 May 2019 16:53:02 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 16:52:52 +0100 Message-Id: <20190514155301.16123-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190514155301.16123-1-alex.bennee@linaro.org> References: <20190514155301.16123-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 Subject: [Qemu-devel] [RFC PATCH 02/11] semihosting: introduce CONFIG_SEMIHOSTING X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marek Vasut , Aleksandar Rikalo , Chris Wulff , Max Filippov , qemu-arm@nongnu.org, Aleksandar Markovic , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Aurelien Jarno Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" There isn't much point building semihosting for platforms that don't support it. Introduce a new symbol and enable it only for the softmmu targets that need it. Signed-off-by: Alex Bennée --- default-configs/arm-softmmu.mak | 1 + default-configs/lm32-softmmu.mak | 2 + default-configs/m68k-softmmu.mak | 2 + default-configs/mips-softmmu-common.mak | 1 + default-configs/nios2-softmmu.mak | 2 + default-configs/xtensa-softmmu.mak | 2 + hw/Kconfig | 1 + hw/semihosting/Kconfig | 3 ++ hw/semihosting/Makefile.objs | 2 +- stubs/Makefile.objs | 1 + stubs/semihost.c | 66 +++++++++++++++++++++++++ 11 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 hw/semihosting/Kconfig create mode 100644 stubs/semihost.c -- 2.20.1 Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak index f23ecfd5c58..1f2e0e7fdeb 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -39,3 +39,4 @@ CONFIG_MICROBIT=y CONFIG_FSL_IMX25=y CONFIG_FSL_IMX7=y CONFIG_FSL_IMX6UL=y +CONFIG_SEMIHOSTING=y diff --git a/default-configs/lm32-softmmu.mak b/default-configs/lm32-softmmu.mak index 6d259665d60..115b3e34c98 100644 --- a/default-configs/lm32-softmmu.mak +++ b/default-configs/lm32-softmmu.mak @@ -4,6 +4,8 @@ # #CONFIG_MILKYMIST_TMU2=n # disabling it actually causes compile-time failures +CONFIG_SEMIHOSTING=y + # Boards: # CONFIG_LM32=y diff --git a/default-configs/m68k-softmmu.mak b/default-configs/m68k-softmmu.mak index e17495e2a0b..4049a8f2ba9 100644 --- a/default-configs/m68k-softmmu.mak +++ b/default-configs/m68k-softmmu.mak @@ -1,5 +1,7 @@ # Default configuration for m68k-softmmu +CONFIG_SEMIHOSTING=y + # Boards: # CONFIG_AN5206=y diff --git a/default-configs/mips-softmmu-common.mak b/default-configs/mips-softmmu-common.mak index 8e54a74b7a5..e10ac4b20c0 100644 --- a/default-configs/mips-softmmu-common.mak +++ b/default-configs/mips-softmmu-common.mak @@ -35,6 +35,7 @@ CONFIG_MIPS_CPS=y CONFIG_MIPS_ITU=y CONFIG_R4K=y CONFIG_MALTA=y +CONFIG_SEMIHOSTING=y CONFIG_PCNET_PCI=y CONFIG_MIPSSIM=y CONFIG_ACPI_SMBUS=y diff --git a/default-configs/nios2-softmmu.mak b/default-configs/nios2-softmmu.mak index e130d024e62..1bc4082ea99 100644 --- a/default-configs/nios2-softmmu.mak +++ b/default-configs/nios2-softmmu.mak @@ -1,5 +1,7 @@ # Default configuration for nios2-softmmu +CONFIG_SEMIHOSTING=y + # Boards: # CONFIG_NIOS2_10M50=y diff --git a/default-configs/xtensa-softmmu.mak b/default-configs/xtensa-softmmu.mak index 7e4d1cc0979..3aa20a47a7f 100644 --- a/default-configs/xtensa-softmmu.mak +++ b/default-configs/xtensa-softmmu.mak @@ -1,5 +1,7 @@ # Default configuration for Xtensa +CONFIG_SEMIHOSTING=y + # Boards: # CONFIG_XTENSA_SIM=y diff --git a/hw/Kconfig b/hw/Kconfig index 88b9f150070..195f541e50c 100644 --- a/hw/Kconfig +++ b/hw/Kconfig @@ -29,6 +29,7 @@ source pci/Kconfig source rdma/Kconfig source scsi/Kconfig source sd/Kconfig +source semihosting/Kconfig source smbios/Kconfig source ssi/Kconfig source timer/Kconfig diff --git a/hw/semihosting/Kconfig b/hw/semihosting/Kconfig new file mode 100644 index 00000000000..efe0a30734c --- /dev/null +++ b/hw/semihosting/Kconfig @@ -0,0 +1,3 @@ + +config SEMIHOSTING + bool diff --git a/hw/semihosting/Makefile.objs b/hw/semihosting/Makefile.objs index 546954f4ff4..09c19bf19ed 100644 --- a/hw/semihosting/Makefile.objs +++ b/hw/semihosting/Makefile.objs @@ -1 +1 @@ -common-obj-$(CONFIG_SOFTMMU) += config.o +obj-$(CONFIG_SEMIHOSTING) += config.o diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 269dfa58326..e0d4f11b348 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -39,3 +39,4 @@ stub-obj-y += xen-hvm.o stub-obj-y += pci-host-piix.o stub-obj-y += ram-block.o stub-obj-y += ramfb.o +stub-obj-$(CONFIG_SOFTMMU) += semihost.o diff --git a/stubs/semihost.c b/stubs/semihost.c new file mode 100644 index 00000000000..1a4e88e5326 --- /dev/null +++ b/stubs/semihost.c @@ -0,0 +1,66 @@ +/* + * Semihosting Stubs for SoftMMU + * + * Copyright (c) 2019 Linaro Ltd + * + * Stubs for SoftMMU targets that don't actually do semihosting. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/option.h" +#include "qemu/error-report.h" +#include "hw/semihosting/semihost.h" + +/* Empty config */ +QemuOptsList qemu_semihosting_config_opts = { + .name = "", + .head = QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts.head), + .desc = { + { /* end of list */ } + }, +}; + +/* Queries to config status default to off */ +bool semihosting_enabled(void) +{ + return false; +} + +SemihostingTarget semihosting_get_target(void) +{ + return SEMIHOSTING_TARGET_AUTO; +} + +/* + * All the rest are empty subs. We could g_assert_not_reached() but + * that adds extra weight to the final binary. Waste not want not. + */ +void qemu_semihosting_enable(void) +{ +} + +int qemu_semihosting_config_options(const char *optarg) +{ + return 1; +} + +const char *semihosting_get_arg(int i) +{ + return NULL; +} + +int semihosting_get_argc(void) +{ + return 0; +} + +const char *semihosting_get_cmdline(void) +{ + return NULL; +} + +void semihosting_arg_fallback(const char *file, const char *cmd) +{ +} From patchwork Tue May 14 15:52:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 164220 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2797322ili; Tue, 14 May 2019 08:58:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqzQcxK/BGEu6BJ6QpVbTe+vxVP4Hw4/S6eS8jST6jRMZ++TmJy6eLgRiF0ffY2J0vvtbWy7 X-Received: by 2002:a17:906:1e0f:: with SMTP id g15mr28493413ejj.241.1557849530358; Tue, 14 May 2019 08:58:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557849530; cv=none; d=google.com; s=arc-20160816; b=T3ChQIAgPJOHsHJZhzGUB1HV3gJmn4JqixNcTuJ45BrZcevq0EE5OgTpi+51k2kmt4 eynS0XKuaHVPUMv0F61FdAMCTbNHgCynByAfdt1BWbOHtN/TV+s34mGNi3aOSl11x+Br /7byxEs/DaDEsnUOaCTQTyTh+1cFrPHcSrwV5HoOMXUU/72PNiQidaOonGNsWBQYTOYx mckSjmns+TG1BXuSt8ISVDxnmCzpgAcmAzcEF37BveniIldeDuye/7QzSc018mwr3dVn W/JGVJ52TDYuiKihHpjSaj+lrN33Dyh1etLn0ikMFK/JlecD/aoODFFrKDfuXva6Ja+b GQAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=hbC6Uuy+rCphFJXRN5GPHrqZRqXnqfdaGhA8RUCMKxg=; b=nr2b44BMxvU6iwIciuT4MN7IaAdbwVaN31Mg4ffaZ4ic1tYzToV8lNR3OQK3IiyKOE HhCxnswTlCWYLiMHNmPVYRYLlfma+8TbABukq8KxDXkS6Pb9pdi7/enOsbwpvWPphKVM Dn5feITypEo34q0Ck7B6Ff9dQMuiZXPVYbXfHu0XP9bkCIzfW96QLAbYQvYa1hv52Uev HlreCPeiF1DWNKfx1ImgXRueIr/AjsOHUSipxGTQ2eMAMaDxrvp48+y39lZsCjFCyA6p XJ08X8BBRQPOImb6dRux/nktzqiRKe3TqmOjGbvk7zb5IMF1Z0UYhjd9CPOKdLegMAl7 fTXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=WUeO4dKj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w14si3813893edw.79.2019.05.14.08.58.50 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 08:58:50 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=WUeO4dKj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:50244 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQZpJ-0001mI-59 for patch@linaro.org; Tue, 14 May 2019 11:58:49 -0400 Received: from eggs.gnu.org ([209.51.188.92]:60306) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQZjn-0004jK-Ek for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQZjm-0006A2-2q for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:07 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:33920) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQZjl-00067A-RC for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:06 -0400 Received: by mail-wr1-x441.google.com with SMTP id f8so1981219wrt.1 for ; Tue, 14 May 2019 08:53:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hbC6Uuy+rCphFJXRN5GPHrqZRqXnqfdaGhA8RUCMKxg=; b=WUeO4dKj2jR9cpYA0NSwQvGZT4j8w99LEx03+eu5YZ6ZOELalepy/YcejiRAw5bCnJ ZIeHZat79geply6FbqT+jLBkVBy8a9F/FjCSsU7A773wGVsbAxh4MQIPX1KzoBGWDnu3 ApMtwEigdorhtA7a6LFjhX4dQRsEDHpIkxprVZXMoPYeHIsARWsLW+CHjl0xgCxbGLe+ HpUFrwSJfr63iMJchi9Pns9OMy6hvwy5JX/ftz8xncgpPEeswo6c7WHUqJZ94h4UhKVe jGWC73sJQpH9MshMqsEGUTpG6d75wmAE9dvgk5y+TY0gGCnZR3wlI1PL6OFkqNDplKmC vpmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hbC6Uuy+rCphFJXRN5GPHrqZRqXnqfdaGhA8RUCMKxg=; b=H7tIXpeCwpLODMGBzDCddPRbVH709Of3oICU2uNc2+63XKsj92wC35A0RdGEzhUljd HIFSrZD3n6wJQlnSLxROj0CnAGLM7fFkLw3d2BrZ8vgrDKkFZKJZlMJzq8YQ9n0mavl9 N9SvBbe/56+mJf1YmPxAKfcHrjr4M9qI5iZVHQsmKyHaj5AwMFvlupALnXX+zmtoU6qz DJcAkkcwo+9WwprsCPO8Rd5sZ5+1I1ucmW4xDpRIC6kdvUT76NuY6qD5ASWlvW2AnO8D IIbUM6/rxYWrKD2XfxR8p1D7LjmGWgFwQnUefjhIIlrTIICLeDzqGT+kT1nh5arDcrzn 9F1A== X-Gm-Message-State: APjAAAXwlgOLcCN7V+1ND6OzB/CX2EjgwNzV07wBvdL6r4NliE1rr5nI AIYmJZM2Wj8JtnTnjROO+W+44g== X-Received: by 2002:a5d:52c6:: with SMTP id r6mr22996703wrv.131.1557849184812; Tue, 14 May 2019 08:53:04 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 22sm3423359wmg.44.2019.05.14.08.53.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 08:53:02 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 4A54F1FF90; Tue, 14 May 2019 16:53:02 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 16:52:53 +0100 Message-Id: <20190514155301.16123-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190514155301.16123-1-alex.bennee@linaro.org> References: <20190514155301.16123-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [RFC PATCH 03/11] semihosting: implement a semihosting console X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-arm@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This provides two functions for handling console output that handle the common backend behaviour for semihosting. Signed-off-by: Alex Bennée --- gdbstub.c | 5 +++ hw/semihosting/Makefile.objs | 1 + hw/semihosting/console.c | 70 ++++++++++++++++++++++++++++++++ include/exec/gdbstub.h | 11 +++++ include/hw/semihosting/console.h | 38 +++++++++++++++++ 5 files changed, 125 insertions(+) create mode 100644 hw/semihosting/console.c create mode 100644 include/hw/semihosting/console.h -- 2.20.1 diff --git a/gdbstub.c b/gdbstub.c index 793218bb43a..b4334014373 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1987,6 +1987,11 @@ void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...) va_end(va); } +void gdb_do_console_out(target_ulong s, int len) +{ + gdb_do_syscall(NULL, "write,2,%x,1", s, len); +} + static void gdb_read_byte(GDBState *s, int ch) { uint8_t reply; diff --git a/hw/semihosting/Makefile.objs b/hw/semihosting/Makefile.objs index 09c19bf19ed..4ad47c05c06 100644 --- a/hw/semihosting/Makefile.objs +++ b/hw/semihosting/Makefile.objs @@ -1 +1,2 @@ obj-$(CONFIG_SEMIHOSTING) += config.o +obj-$(CONFIG_SEMIHOSTING) += console.o diff --git a/hw/semihosting/console.c b/hw/semihosting/console.c new file mode 100644 index 00000000000..ad6f67ecc71 --- /dev/null +++ b/hw/semihosting/console.c @@ -0,0 +1,70 @@ +/* + * Semihosting Console Support + * + * Copyright (c) 2015 Imagination Technologies + * Copyright (c) 2019 Linaro Ltd + * + * This provides support for outputting to a semihosting console. + * + * While most semihosting implementations support reading and writing + * to arbitrary file descriptors we treat the console as something + * specifically for debugging interaction. This means messages can be + * re-directed to gdb (if currently being used to debug) or even + * re-directed elsewhere. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "hw/semihosting/console.h" +#include "exec/gdbstub.h" +#include "qemu/log.h" + +int qemu_semihosting_log_out(const char *s, int len) +{ + return write(STDERR_FILENO, s, len); +} + +/* + * A re-implementation of lock_user_string that we can use locally + * instead of relying on softmmu-semi. Hopefully we can deprecate that + * in time. We either copy len bytes if specified or until we find a NULL. + */ +static GString *copy_user_string(CPUArchState *env, target_ulong addr, int len) +{ + CPUState *cpu = ENV_GET_CPU(env); + GString *s = g_string_sized_new(len ? len : 128); + uint8_t c; + bool done; + + do { + if (cpu_memory_rw_debug(cpu, addr++, &c, 1, 0) == 0) { + s = g_string_append_c(s, c); + done = len ? s->len == len : c == 0; + } else { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: passed inaccessible address " TARGET_FMT_lx, + __func__, addr); + done = true; + } + } while (!done); + + return s; +} + + +int qemu_semihosting_console_out(CPUArchState *env, target_ulong addr, int len) +{ + GString *s = copy_user_string(env, addr, len); + int out = s->len; + + if (use_gdb_syscalls()) { + gdb_do_console_out(addr, s->len); + } else { + out = qemu_semihosting_log_out(s->str, s->len); + } + + g_string_free(s, true); + return out; +} diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 08363969c14..b2963547c48 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -44,6 +44,17 @@ void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...); * argument list. */ void gdb_do_syscallv(gdb_syscall_complete_cb cb, const char *fmt, va_list va); +/** + * gdb_do_console_out: + * @gs: guest address of string to send + * @len: length of string + * + * Sends a string to gdb console. Unlike the system call interface + * there is no callback and we assume the system call always + * succeeds. + */ +void gdb_do_console_out(target_ulong s, int len); + int use_gdb_syscalls(void); void gdb_set_stop_cpu(CPUState *cpu); void gdb_exit(CPUArchState *, int); diff --git a/include/hw/semihosting/console.h b/include/hw/semihosting/console.h new file mode 100644 index 00000000000..30e66ae20aa --- /dev/null +++ b/include/hw/semihosting/console.h @@ -0,0 +1,38 @@ +/* + * Semihosting Console + * + * Copyright (c) 2019 Linaro Ltd + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef _SEMIHOST_CONSOLE_H_ +#define _SEMIHOST_CONSOLE_H_ + +/** + * qemu_semihosting_console_out: + * @env: CPUArchState + * @s: host address of guest string + * @len: length of string or 0 (string is null terminated) + * + * Send a guest string to the debug console. This may be the remote + * gdb session if a softmmu guest is currently being debugged. + * + * Returns: number of bytes written. + */ +int qemu_semihosting_console_out(CPUArchState *env, target_ulong s, int len); + +/** + * qemu_semihosting_log_out: + * @s: pointer to string + * @len: length of string + * + * Send a string to the debug output. Unlike console_out these strings + * can't be sent to a remote gdb instance as they don't exist in guest + * memory. + * + * Returns: number of bytes written + */ +int qemu_semihosting_log_out(const char *s, int len); + +#endif /* _SEMIHOST_CONSOLE_H_ */ From patchwork Tue May 14 15:52:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 164216 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2792300ili; Tue, 14 May 2019 08:53:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqz4tUVKWvwMwMS8IbTXlCX1dm3x0kFdLNc3D03KP++bvkSQ6n4NfcK7aYeX7yn4InHcTdg7 X-Received: by 2002:a50:8c24:: with SMTP id p33mr37486375edp.210.1557849221333; Tue, 14 May 2019 08:53:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557849221; cv=none; d=google.com; s=arc-20160816; b=ETq2n7R3Wdh27wO8zN3SLHeIxQStAgmvZ6htHQPoNj2d3zpS9UGd3HbDWMUhZT0v2W DuIvM8yJjX1/GC1OiKXH9insbApDMDxeWG168oOE55MdO0+99rlImFLhK8FuF93mL5TO nkoWjCA+BixL7sLTybAUImHAa8BxxIUdWD0wrJhdd4V6jEVFiyuFLJKH7QQUBDr5KG2+ l330z13zEaGrISeOfc7MK8/0TZy9Wi00ZSsvyRa8aVTSL4v+8JV/xTd9TlIc0EqHpGg/ z3dY/m1CWs4K3eo3Liu1PYfOa/AwtbL0VWZCKfqd0uI+mc+BvnftfJXxPbAQ3h214Q9I e9fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=0r9ufJMae12rSUNpWxfw8a5ZPlWsKe8VRtl/4yp8eAw=; b=pRePaXDwRtUGv6s6Ao1FedZJvpEP3FayOZqcU9FZRsSxO50Cx54+mYcyLzpr0TMjIE Wqxvfvpl9KVN6XfQFa4HOtRMhyskdvUSxoVmyfEAJsHmjkO5mZPxmIjrwZHz2lMugtln FdgCwusXYzHy3SBeyImzvhLYQW3Xz9NZPM+NYxfeiS4g5N9BVZujxXxp7UJh41JwGXbd CF5eYM+DdzYF3+S12RQV5RGl+ZgYLCbzU6y3JR7vtEqryxvSyG7LIgm4gAq5c72dDUvH 46v6j4BXTuCIkzlCkKU6BsA8wfQCjI9endSYqeihfQW3DJQAXVVhMm6jvU4aRg7syLoM W3YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=TOs+csmW; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y21si7767063ejc.178.2019.05.14.08.53.41 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 08:53:41 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=TOs+csmW; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:50158 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQZkK-0004tC-5m for patch@linaro.org; Tue, 14 May 2019 11:53:40 -0400 Received: from eggs.gnu.org ([209.51.188.92]:60360) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQZjo-0004kw-VU for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQZjn-0006CA-4P for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:08 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:35325) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQZjm-0006Ai-RY for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:07 -0400 Received: by mail-wr1-x443.google.com with SMTP id w12so19833306wrp.2 for ; Tue, 14 May 2019 08:53:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0r9ufJMae12rSUNpWxfw8a5ZPlWsKe8VRtl/4yp8eAw=; b=TOs+csmWpgVedvpRRe9hbcGHBcQNBNd1rj9kFqMBbMtUy3gBgYWCdSrVmCfxFVnGp9 Mc7h1UfTJLkjLmGxPBEJfLZa7ZaaPspohHLJP2DCV/KwVn6DZO9E0KjXAqGNipEVkCXr f/9+BjRHG5C5ihMQGJFCfT2WJgZmQmIafWeIGOeJpHIt5R+cwL5p7KsvRUy8cjAjb/6g xqjjIAlaC5SkmO/lX5yRgxamvOUk/jb4ip0RR2ynyYDTyZmfaBmz+o3dotIJkgnFyniB LzZM8UK8kvV3uqGLf5Jvm45UaiYLfLBSIeYR9FDpKU/UbhC7RXDRq5yn8GntTROcOjrr 96TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0r9ufJMae12rSUNpWxfw8a5ZPlWsKe8VRtl/4yp8eAw=; b=t6kG4fZSI5lwacj4mRLtfhsgZ/7hO/q4/Vu2X2IKc4hzbSTzyFfIprEaJwEuirbPRZ +PmU30yKnTOBBEmZ0kbpGG1FjliyMcjsbySuRa4HPhCNYr6mkgIhzURU8K/EH2K+r/iW YuOtO3cXLkEu/5n+HNNGZkbENIcDMnJf9aH7Ibkv8e3P/z2VbZWUCvXLkjCWJ6keS0Yo 90BKmP30lhWA9HPEb8/S0H2WeTq0YPKhfdj4FNUh/Yf6eHGEVGTlqH+mcNV8WqCWBv6w HnY7BP5TTz8e6WhX8t1O7yojhJepE6Aig8v/ySe5E3wbqxWn6dyltbNUvewyrP9GWaPV Hwmw== X-Gm-Message-State: APjAAAXpbo6DHvmEQM6mMcMdAyJE5GNBxZ/5hcloN/EPUXoQu4hyos+Y 1X6K/0DlOFq0weNJ8qB1jHjD+Q== X-Received: by 2002:a5d:6610:: with SMTP id n16mr14087056wru.250.1557849185778; Tue, 14 May 2019 08:53:05 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id d6sm16564890wrp.9.2019.05.14.08.53.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 08:53:02 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 64DB11FF91; Tue, 14 May 2019 16:53:02 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 16:52:54 +0100 Message-Id: <20190514155301.16123-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190514155301.16123-1-alex.bennee@linaro.org> References: <20190514155301.16123-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 Subject: [Qemu-devel] [RFC PATCH 04/11] semihosting: enable chardev backed output for console X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , qemu-arm@nongnu.org, =?utf-8?q?Al?= =?utf-8?q?ex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" It will be useful for a number of use-cases to be able to re-direct output to a file like we do with serial output. This does the wiring to allow us to treat then semihosting console like just another character output device. Signed-off-by: Alex Bennée --- hw/semihosting/config.c | 26 ++++++++++++++++++++++++++ hw/semihosting/console.c | 9 ++++++++- include/hw/semihosting/semihost.h | 7 +++++++ qemu-options.hx | 6 ++++-- stubs/semihost.c | 4 ++++ vl.c | 2 ++ 6 files changed, 51 insertions(+), 3 deletions(-) -- 2.20.1 diff --git a/hw/semihosting/config.c b/hw/semihosting/config.c index f1d3fe1e4c6..2a8e7e1045a 100644 --- a/hw/semihosting/config.c +++ b/hw/semihosting/config.c @@ -23,6 +23,7 @@ #include "qemu/config-file.h" #include "qemu/error-report.h" #include "hw/semihosting/semihost.h" +#include "chardev/char.h" QemuOptsList qemu_semihosting_config_opts = { .name = "semihosting-config", @@ -35,6 +36,9 @@ QemuOptsList qemu_semihosting_config_opts = { }, { .name = "target", .type = QEMU_OPT_STRING, + }, { + .name = "chardev", + .type = QEMU_OPT_STRING, }, { .name = "arg", .type = QEMU_OPT_STRING, @@ -46,12 +50,14 @@ QemuOptsList qemu_semihosting_config_opts = { typedef struct SemihostingConfig { bool enabled; SemihostingTarget target; + Chardev *chardev; const char **argv; int argc; const char *cmdline; /* concatenated argv */ } SemihostingConfig; static SemihostingConfig semihosting; +static const char *semihost_chardev; bool semihosting_enabled(void) { @@ -115,6 +121,11 @@ void semihosting_arg_fallback(const char *file, const char *cmd) } } +Chardev *semihosting_get_chardev(void) +{ + return semihosting.chardev; +} + void qemu_semihosting_enable(void) { semihosting.enabled = true; @@ -132,6 +143,8 @@ int qemu_semihosting_config_options(const char *optarg) semihosting.enabled = qemu_opt_get_bool(opts, "enable", true); const char *target = qemu_opt_get(opts, "target"); + /* setup of chardev is deferred until they are initialised */ + semihost_chardev = qemu_opt_get(opts, "chardev"); if (target != NULL) { if (strcmp("native", target) == 0) { semihosting.target = SEMIHOSTING_TARGET_NATIVE; @@ -158,3 +171,16 @@ int qemu_semihosting_config_options(const char *optarg) return 0; } +void qemu_semihosting_connect_chardevs(void) +{ + /* We had to defer this until chardevs were created */ + if (semihost_chardev) { + Chardev *chr = qemu_chr_find(semihost_chardev); + if (chr == NULL) { + error_report("semihosting chardev '%s' not found", + semihost_chardev); + exit(1); + } + semihosting.chardev = chr; + } +} diff --git a/hw/semihosting/console.c b/hw/semihosting/console.c index ad6f67ecc71..2fa440eb32a 100644 --- a/hw/semihosting/console.c +++ b/hw/semihosting/console.c @@ -17,13 +17,20 @@ #include "qemu/osdep.h" #include "cpu.h" +#include "hw/semihosting/semihost.h" #include "hw/semihosting/console.h" #include "exec/gdbstub.h" #include "qemu/log.h" +#include "chardev/char.h" int qemu_semihosting_log_out(const char *s, int len) { - return write(STDERR_FILENO, s, len); + Chardev *chardev = semihosting_get_chardev(); + if (chardev) { + return qemu_chr_write_all(chardev, (uint8_t *) s, len); + } else { + return write(STDERR_FILENO, s, len); + } } /* diff --git a/include/hw/semihosting/semihost.h b/include/hw/semihosting/semihost.h index 07ea40a322f..60fc42d851e 100644 --- a/include/hw/semihosting/semihost.h +++ b/include/hw/semihosting/semihost.h @@ -51,6 +51,11 @@ static inline const char *semihosting_get_cmdline(void) { return NULL; } + +static inline Chardev *semihosting_get_chardev(void) +{ + return NULL; +} #else /* !CONFIG_USER_ONLY */ bool semihosting_enabled(void); SemihostingTarget semihosting_get_target(void); @@ -58,9 +63,11 @@ const char *semihosting_get_arg(int i); int semihosting_get_argc(void); const char *semihosting_get_cmdline(void); void semihosting_arg_fallback(const char *file, const char *cmd); +Chardev *semihosting_get_chardev(void); /* for vl.c hooks */ void qemu_semihosting_enable(void); int qemu_semihosting_config_options(const char *opt); +void qemu_semihosting_connect_chardevs(void); #endif /* CONFIG_USER_ONLY */ #endif /* SEMIHOST_H */ diff --git a/qemu-options.hx b/qemu-options.hx index 51802cbb266..6aa3a08c2fb 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3975,12 +3975,12 @@ STEXI Enable semihosting mode (ARM, M68K, Xtensa, MIPS, Nios II only). ETEXI DEF("semihosting-config", HAS_ARG, QEMU_OPTION_semihosting_config, - "-semihosting-config [enable=on|off][,target=native|gdb|auto][,arg=str[,...]]\n" \ + "-semihosting-config [enable=on|off][,target=native|gdb|auto][,chardev=id][,arg=str[,...]]\n" \ " semihosting configuration\n", QEMU_ARCH_ARM | QEMU_ARCH_M68K | QEMU_ARCH_XTENSA | QEMU_ARCH_LM32 | QEMU_ARCH_MIPS | QEMU_ARCH_NIOS2) STEXI -@item -semihosting-config [enable=on|off][,target=native|gdb|auto][,arg=str[,...]] +@item -semihosting-config [enable=on|off][,target=native|gdb|auto][,chardev=id][,arg=str[,...]] @findex -semihosting-config Enable and configure semihosting (ARM, M68K, Xtensa, MIPS, Nios II only). @table @option @@ -3988,6 +3988,8 @@ Enable and configure semihosting (ARM, M68K, Xtensa, MIPS, Nios II only). Defines where the semihosting calls will be addressed, to QEMU (@code{native}) or to GDB (@code{gdb}). The default is @code{auto}, which means @code{gdb} during debug sessions and @code{native} otherwise. +@item chardev=@var{str1} +Send the output to a chardev backend output for native or auto output when not in gdb @item arg=@var{str1},arg=@var{str2},... Allows the user to pass input arguments, and can be used multiple times to build up a list. The old-style @code{-kernel}/@code{-append} method of passing a diff --git a/stubs/semihost.c b/stubs/semihost.c index 1a4e88e5326..4d5b3c06530 100644 --- a/stubs/semihost.c +++ b/stubs/semihost.c @@ -64,3 +64,7 @@ const char *semihosting_get_cmdline(void) void semihosting_arg_fallback(const char *file, const char *cmd) { } + +void qemu_semihosting_connect_chardevs(void) +{ +} diff --git a/vl.c b/vl.c index fba48b565c9..49878a2a1bf 100644 --- a/vl.c +++ b/vl.c @@ -4156,6 +4156,8 @@ int main(int argc, char **argv, char **envp) qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, &error_fatal); + /* now chardevs have been created we may have semihosting to connect */ + qemu_semihosting_connect_chardevs(); #ifdef CONFIG_VIRTFS qemu_opts_foreach(qemu_find_opts("fsdev"), From patchwork Tue May 14 15:52:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 164217 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2794149ili; Tue, 14 May 2019 08:55:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqxrNuKM51SDqv8w1/bpWQAp6pdZtjrrixScSn93RlkFXrxpCL+lJblBuO5zn5rdiA5dRaju X-Received: by 2002:a17:906:a4b:: with SMTP id x11mr28559604ejf.200.1557849333629; Tue, 14 May 2019 08:55:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557849333; cv=none; d=google.com; s=arc-20160816; b=AOCNsoGopnKAG05m9gLCwoAYKgDYTwI+TLVY8MVoVXUZhLtDn2sOb0USXo8RaPqTfY V/8vYmTGlV0YkWUYkP/hRFc9nXzsNIw4YzNL0uW5PTWBOMqbcJscF43X1SNddrDYisnu BTWpr2VPmVQVLUs1F2DVaj//YEihbwR0A7nZ2ek50jDO9BdbvQ8+thV4CiUidlCYnM/Y /aOnVUsSX5uZgUEIefLDRpatje7xsQfQfdSBZFDnkyTl20YrRRlS++pP03pQeveVb7FS i7UFw+4goXJUorK/zZM+QA7hg39wDduWN6lRuCNQagZX3gEpxsIzuMoNJFEmSGcRFq0/ 95cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=8P0Lit3+ogalzWIYoV9bDuQCb6yqzuLD2GL2ck9k72U=; b=nuIZO00fgp+QHZSKjkk2geOdv77STBcNz9/8l1I2aLA/ALNsjr7M0MZyDDvxlRV+Ww iu9uPFMsbbPpMwrZTN0c9kNjtsZ9SrJmIYbjL4B5GdZyWPCYaAxiHwYG22PkmBdy5AUI lNMvDvcTslkKKRTqRAgzjF9yNDnIfb7XRimMIn2BEI5KZ2FNurmyJrBUTHPaZMrFr6C9 qOoeaSulMDoFr70eRo+dYs15fYebQwbCYb4w/yIE5tMq2uNvWNsWG3UWnJtLvDMPSVGM R/U9P9SgekQpTFGLANkyK/i7lOLhXh4qaJcN1yCkmbUElAqrgyx7zXYRwBi1zQX5Dbyj LZ+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=m8XjDVZf; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t4si9927750ejq.180.2019.05.14.08.55.33 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 08:55:33 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=m8XjDVZf; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:50198 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQZm8-0006Zo-Cj for patch@linaro.org; Tue, 14 May 2019 11:55:32 -0400 Received: from eggs.gnu.org ([209.51.188.92]:60372) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQZjp-0004l8-Am for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQZjo-0006DS-0S for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:09 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:51780) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQZjn-0006C8-PX for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:07 -0400 Received: by mail-wm1-x341.google.com with SMTP id o189so3432113wmb.1 for ; Tue, 14 May 2019 08:53:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8P0Lit3+ogalzWIYoV9bDuQCb6yqzuLD2GL2ck9k72U=; b=m8XjDVZfHoOqs814AqYdCoaJljUHvUN91Ybm1Nij/tU9WxajK7mp8Ae6guBr6m6WRt zDiGm0Zaeu4suWI8/IE5WsPbTYfyfH58WZMuMhurxZKGV8zY6Gl7cu+4r2P7Bddkd52l qeoQDqk+22weMucKa66/pPwK4LLgBoQ6KSSKoAWF0khlILdnEugDDyC24CH93FucPK1s qn84AoZA/N3TNGGqByzcFZe7LzME2gYNHai3cm2yckxlVvBpjjspln5LU8pVAxoT5rwr fgFRTqPv77KiUo72SKf9TxVli8rh+a3YvDEfT+EE40Jh/i1iEDS3OVcQLE5+30dRXhr/ Wdgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8P0Lit3+ogalzWIYoV9bDuQCb6yqzuLD2GL2ck9k72U=; b=ffbMGjW+msTiyKSp+h77AQK3TUIPPP8reuxqpqU9sP9yNjGACgRPcEUfr7zH6JG2K1 xlA8kPWcFgpdLYxPQmVsTjOtSe0jiYC3vEhBvpwN5tGKwdn4F5QETGD1NNC7FI4lf5f5 aZt3sJT66NBrUYFDt+9ckuR7iHJnZJntodeLGCzYj1ht3YNORJQrKaebIfkUHS+E8Foc fzJJNcfmntVRuZsT/Wio9M0FdfRQFty0POZ+49ylSPcp7mNnjSinaS/LP5psi5LkLrHV G/TgJYCEEjloLwJQRpjdWSR59ucvCu3QK57hZD2s9lNTyyP5nUYNIiLuLl6itasK51Dl 3ACw== X-Gm-Message-State: APjAAAVjni1nXZOzQAg3yS+RPat2it10pTDaKi75S0gPq+n+nYH/65x6 opf+gIwd6ECwP109hIlLQliB8Q== X-Received: by 2002:a05:600c:551:: with SMTP id k17mr5368389wmc.119.1557849186612; Tue, 14 May 2019 08:53:06 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id g6sm14700712wro.29.2019.05.14.08.53.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 08:53:05 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 7834B1FF92; Tue, 14 May 2019 16:53:02 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 16:52:55 +0100 Message-Id: <20190514155301.16123-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190514155301.16123-1-alex.bennee@linaro.org> References: <20190514155301.16123-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 Subject: [Qemu-devel] [RFC PATCH 05/11] target/arm: fixup some of the commentary for arm-semi X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-arm@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This cleans up a number of the block comments to fit the proper style. While we are at it we also reference the official specification and document what the return register value can be. Signed-off-by: Alex Bennée --- target/arm/arm-semi.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) -- 2.20.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 3273306c8ea..9e5a414dd89 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -2,6 +2,7 @@ * Arm "Angel" semihosting syscalls * * Copyright (c) 2005, 2007 CodeSourcery. + * Copyright (c) 2019 Linaro * Written by Paul Brook. * * This program is free software; you can redistribute it and/or modify @@ -16,6 +17,10 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, see . + * + * ARM Semihosting is documented in: + * Semihosting for AArch32 and AArch64 Release 2.0 + * https://static.docs.arm.com/100863/0200/semihosting.pdf */ #include "qemu/osdep.h" @@ -240,6 +245,15 @@ static target_ulong arm_gdb_syscall(ARMCPU *cpu, gdb_syscall_complete_cb cb, put_user_u64(val, args + (n) * 8) : \ put_user_u32(val, args + (n) * 4)) +/* + * Do a semihosting call. + * + * The specification always says that the "return register" either + * returns a specific value or is corrupted, so we don't need to + * report to our caller whether we are returning a value or trying to + * leave the register unchanged. We use 0xdeadbeef as the return value + * when there isn't a defined return value for the call. + */ target_ulong do_arm_semihosting(CPUARMState *env) { ARMCPU *cpu = arm_env_get_cpu(env); @@ -510,14 +524,16 @@ target_ulong do_arm_semihosting(CPUARMState *env) output_size = ts->info->arg_end - ts->info->arg_start; if (!output_size) { - /* We special-case the "empty command line" case (argc==0). - Just provide the terminating 0. */ + /* + * We special-case the "empty command line" case (argc==0). + * Just provide the terminating 0. + */ output_size = 1; } #endif if (output_size > input_size) { - /* Not enough space to store command-line arguments. */ + /* Not enough space to store command-line arguments. */ return -1; } @@ -571,8 +587,10 @@ target_ulong do_arm_semihosting(CPUARMState *env) GET_ARG(0); #ifdef CONFIG_USER_ONLY - /* Some C libraries assume the heap immediately follows .bss, so - allocate it using sbrk. */ + /* + * Some C libraries assume the heap immediately follows .bss, so + * allocate it using sbrk. + */ if (!ts->heap_limit) { abi_ulong ret; @@ -620,7 +638,8 @@ target_ulong do_arm_semihosting(CPUARMState *env) } case TARGET_SYS_EXIT: if (is_a64(env)) { - /* The A64 version of this call takes a parameter block, + /* + * The A64 version of this call takes a parameter block, * so the application-exit type can return a subcode which * is the exit status code from the application. */ @@ -633,14 +652,17 @@ target_ulong do_arm_semihosting(CPUARMState *env) ret = 1; } } else { - /* ARM specifies only Stopped_ApplicationExit as normal - * exit, everything else is considered an error */ + /* + * ARM specifies only Stopped_ApplicationExit as normal + * exit, everything else is considered an error + */ ret = (args == ADP_Stopped_ApplicationExit) ? 0 : 1; } gdb_exit(env, ret); exit(ret); case TARGET_SYS_SYNCCACHE: - /* Clean the D-cache and invalidate the I-cache for the specified + /* + * Clean the D-cache and invalidate the I-cache for the specified * virtual address range. This is a nop for us since we don't * implement caches. This is only present on A64. */ From patchwork Tue May 14 15:52:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 164218 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2794948ili; Tue, 14 May 2019 08:56:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqxO7BymqLCc0sV3HdQYHqvEKuzz1P8aKMOoGySrpnpydb9F26KezcSHE1BOurEYFOhvor/p X-Received: by 2002:a17:906:4e56:: with SMTP id g22mr21168247ejw.51.1557849384692; Tue, 14 May 2019 08:56:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557849384; cv=none; d=google.com; s=arc-20160816; b=QY3r+noWHTTyr941T2IkjtwqjwO0zUdaJhFrrDi2s0IM84nV3kjYrnU7/bYU98LPGz W0MOpEp3z9zarMYXWgjs+jE6ydQajwT2G2dflD5CBz9k2goPi323hcFQ9BOvwsH8+pml dh1WfwwFGLRThTQbGa6Mcd6STV3iaIVCxyNaJwAmoe5A343rk0eyqRWNzDZFBZy0Vduk 0Ue8TnhBQNn7LgzU3X8LQuZCTBXWC4YZG5FsZjVCXY6pwBjgxVytoN027f24tPeWzGbl Dh5vii9FuiEXrN27JZKLeBOKwSsCKpIyur9D8lhIc1p0ycS36eR8wvmc7MHtyC61iYAf BGYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=3N082WaIffsJbYXIZ0a/9GfiR46w16xaqgWtZJxN1co=; b=TwllqLpK3TO1mmM9MKP5kHbXQQjOpD1fQH+/bLL4ahxlcisUJuNh1LEm0urIyiDt5o jXqi9povDrC4WH4OdyiEy5MdIzTs/0Mqc0zfFzxFOGCM0uOpvUs64WFBF0c7WX/flY/R nHPREgNx2aPXMnk2TCugCtptjfYh2SoeuIPBtps6xLgRxYci74YK87gz3XGmfoG/MW0f L4zMDP5HizMKpuDE5kKOElEiDZLP2GfwvJoONK+EnkLavX815OroFpjAvQ5K7mYLvXsI 382yAhpsN6fAnVlM3c1jvhy5X0zo+EYXr7qiIEGp2Cygn11VCShDpDr5fcEZ/fOfjc/7 cSVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=TWm6ndFP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a11si4550571ejn.259.2019.05.14.08.56.23 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 08:56: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=fail header.i=@linaro.org header.s=google header.b=TWm6ndFP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:50218 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQZmw-0007Uf-TC for patch@linaro.org; Tue, 14 May 2019 11:56:22 -0400 Received: from eggs.gnu.org ([209.51.188.92]:60385) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQZjp-0004mA-QZ for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQZjo-0006EP-HC for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:09 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:39284) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQZjo-0006Cw-AS for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:08 -0400 Received: by mail-wm1-x343.google.com with SMTP id n25so3320466wmk.4 for ; Tue, 14 May 2019 08:53:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3N082WaIffsJbYXIZ0a/9GfiR46w16xaqgWtZJxN1co=; b=TWm6ndFPJjrhVd500ZU3j6de33SOsREWIeUSOAwFl7svBlfqtCC5IlKv25kowmtJyN IeuQmMftUaJ00eblCmL5OCQYtn1xxUz6CtM2FilQ7FEI6bFOSeiN2sbXapAjL3K3OuJv 7qOS5903Yuu/bMfUee7i3w7SAVg1o2Pl/Ixw3sFXyZR3rpOLn1ScrUNjhfSehhUGnVTG XBj8LVQlqgatf06DtMSlxwStQHfrCzlfwKeJcbmGdHR8IUykxWK2dvVaZEyN32GhbUIT KJoqpsGL7YU4fbC8QVJeFpgJ8Zjw4VeKR2Ay0jzxIMRXe+WGgKDzp6ohKkTYUfsu6G+U EI7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3N082WaIffsJbYXIZ0a/9GfiR46w16xaqgWtZJxN1co=; b=L6Dxw2vXWWZ6oLFVxhKfG2xMPFJrx5L0MdOuGt0yJAj79fJ+1yYBsGBspm/rQrZgpf P/ZDcU8tdztOO3ZICicaoG5RZ3zoqMDn3mbMgZpFuegtu75217YmAuKuUFbSTI2s903p JBeX32IuLNVbiVyg7ICR6LnYlBMwbdzFhhdARHyPZMoOAeF9F/1LH5K0LTVZgAKAQB/X bCjl549rA7FPiwelAEMHyfn0yXI8UIrFjRpzzevNUFV/eU1PmnvvXsT6//rLNYpMu1Nt PoN/Mm+VcyxGuknkjr7b9eWC8Ec+FYKf9krbQiNQTtkIimfHZe1APOQtGRUqcUTImPPM dgmg== X-Gm-Message-State: APjAAAVqKK/zY1kvJQAW3gxwgniu+zQfW5TUi0CHaBPcFPTr4ZDuxalm je4Sn8igvunNYsXH9eGq/3iRJ5BlRwk= X-Received: by 2002:a1c:7d04:: with SMTP id y4mr18978347wmc.123.1557849187283; Tue, 14 May 2019 08:53:07 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id j9sm6786562wrr.90.2019.05.14.08.53.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 08:53:05 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 8F7AF1FF93; Tue, 14 May 2019 16:53:02 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 16:52:56 +0100 Message-Id: <20190514155301.16123-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190514155301.16123-1-alex.bennee@linaro.org> References: <20190514155301.16123-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 Subject: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semi X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Riku Voipio , qemu-arm@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Now we have a common semihosting console interface use that for our string output. However ARM is currently unique in also supporting semihosting for linux-user so we need to replicate the API in linux-user. If other architectures gain this support we can move the file later. Signed-off-by: Alex Bennée --- linux-user/Makefile.objs | 2 ++ linux-user/arm/semihost.c | 24 ++++++++++++++++++++++++ target/arm/arm-semi.c | 31 ++++++------------------------- 3 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 linux-user/arm/semihost.c -- 2.20.1 diff --git a/linux-user/Makefile.objs b/linux-user/Makefile.objs index 769b8d83362..285c5dfa17a 100644 --- a/linux-user/Makefile.objs +++ b/linux-user/Makefile.objs @@ -6,4 +6,6 @@ obj-y = main.o syscall.o strace.o mmap.o signal.o \ obj-$(TARGET_HAS_BFLT) += flatload.o obj-$(TARGET_I386) += vm86.o obj-$(TARGET_ARM) += arm/nwfpe/ +obj-$(TARGET_ARM) += arm/semihost.o +obj-$(TARGET_AARCH64) += arm/semihost.o obj-$(TARGET_M68K) += m68k-sim.o diff --git a/linux-user/arm/semihost.c b/linux-user/arm/semihost.c new file mode 100644 index 00000000000..9554102a855 --- /dev/null +++ b/linux-user/arm/semihost.c @@ -0,0 +1,24 @@ +/* + * ARM Semihosting Console Support + * + * Copyright (c) 2019 Linaro Ltd + * + * Currently ARM is unique in having support for semihosting support + * in linux-user. So for now we implement the common console API but + * just for arm linux-user. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "hw/semihosting/console.h" +#include "qemu.h" + +int qemu_semihosting_console_out(CPUArchState *env, target_ulong addr, int len) +{ + void *s = lock_user_string(addr); + len = write(STDERR_FILENO, s, len ? len : strlen(s)); + unlock_user(s, addr, 0); + return len; +} diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 9e5a414dd89..253c66b172a 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -27,6 +27,7 @@ #include "cpu.h" #include "hw/semihosting/semihost.h" +#include "hw/semihosting/console.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -314,32 +315,12 @@ target_ulong do_arm_semihosting(CPUARMState *env) return set_swi_errno(ts, close(arg0)); } case TARGET_SYS_WRITEC: - { - char c; - - if (get_user_u8(c, args)) - /* FIXME - should this error code be -TARGET_EFAULT ? */ - return (uint32_t)-1; - /* Write to debug console. stderr is near enough. */ - if (use_gdb_syscalls()) { - return arm_gdb_syscall(cpu, arm_semi_cb, "write,2,%x,1", args); - } else { - return write(STDERR_FILENO, &c, 1); - } - } + { + qemu_semihosting_console_out(env, args, 1); + return 0xdeadbeef; + } case TARGET_SYS_WRITE0: - if (!(s = lock_user_string(args))) - /* FIXME - should this error code be -TARGET_EFAULT ? */ - return (uint32_t)-1; - len = strlen(s); - if (use_gdb_syscalls()) { - return arm_gdb_syscall(cpu, arm_semi_cb, "write,2,%x,%x", - args, len); - } else { - ret = write(STDERR_FILENO, s, len); - } - unlock_user(s, args, 0); - return ret; + return qemu_semihosting_console_out(env, args, 0); case TARGET_SYS_WRITE: GET_ARG(0); GET_ARG(1); From patchwork Tue May 14 15:52:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 164221 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2798819ili; Tue, 14 May 2019 09:00:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqxXesxnBASt03IGOfJGBHKeNd9Ty61ScQGY4S+fzZT4ZlcaAg2TgBEesB0tLUMZSoHR8FWy X-Received: by 2002:a17:906:9390:: with SMTP id l16mr25950571ejx.57.1557849619331; Tue, 14 May 2019 09:00:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557849619; cv=none; d=google.com; s=arc-20160816; b=Qyk/wQ60rWCnif32KrIW8ISP5tj+Caex/cXrgfpBfy98oGXhWYnAgBtAMYImwyRwjT Y8be5wjAX4gPIJuWCTgtGwK4wV4EzYrefKfl5gM2tw6fJTwxRlXkCzrvOPy6P4gWjyH7 oPhIfdBzg1RwylTYfP4WNpZV7rYxvIKLgLLeoX5nkbi7k9dLWxSC32/hxZe2CVlGn44D b5vooGmtq7dhE9/4grHr5Hw9S2//x21/ipl+66Vm4isweCcvh9L78NjZP00zD+nDdScP Ia1+U+XStt/GOckBPXRi+7nZBBMN8cRmTzJqoxD2l962RMl8WDxro6cbV1+MLLYuhMNu hd1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=uRA15QcYpp84VA9k9wsWlnaKx7a1xt3gupbkmncewJA=; b=M/gDl5CocIkZV+7gs4iASUQ4v1uJy8UqBYfi5/J4ovrX7nrog04hr1BvO9UYxCxIMU Ook1yITEt8xlAvF7I9m96UGDXO9EcKajJbO5OY3J+2X2SSFbIUZsy6/LTlPJze5OeK8k 59PQ/JAeDMxt/HIVGUpvw7XMXeSo+j7EyFVrnwQdR1oi13TdRFaaJmo40wEN9+NUltjg mLqpNL/mi8Rvw6tUPBVvo21hKhnmT02ghN7+nvBN3Jhqy0y/Lrv6X3Q0FRMcKOlgSTBF beayrLvTZtqRv5ZTZdkCBtWhfMOmmjQatiOEDPuHJRyQBYzzWeoT5ZDqMsPYNJZqrds4 VPsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=QrqjMzK0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k23si857238edd.342.2019.05.14.09.00.19 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 09:00:19 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=QrqjMzK0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:50312 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQZqk-0003C9-6o for patch@linaro.org; Tue, 14 May 2019 12:00:18 -0400 Received: from eggs.gnu.org ([209.51.188.92]:60419) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQZjq-0004nI-HP for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQZjp-0006HR-90 for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:10 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:37625) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQZjp-0006EF-2N for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:09 -0400 Received: by mail-wm1-x341.google.com with SMTP id 7so3349126wmo.2 for ; Tue, 14 May 2019 08:53:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uRA15QcYpp84VA9k9wsWlnaKx7a1xt3gupbkmncewJA=; b=QrqjMzK05AStmW3oCrlklHRx6CfYVHGsp13bG9cRguuv9tbuIa/0+nEU4Wty82SXVm vjABYWIxmyMSqI4vNNqm9pzZQ/l+qrK7nFBscmVe8vMrrAgU2QdMdJrBX4sLr3T8M+WI sC7/HbYny2VpQoNgJC2ONGjdgYd5NabnX2W9msnuj8xqxvJ+SSuC+Mqi1Tnc/8PUwmUL nqZiwOtHvCTtNDUO/K1CWh9BdMMvhtv3B5nJDCV6v7qiOl7oF+JMVP8frg5xD2F+lJrj wWvriOy4rKg58n4Rjs41XcyiB0V9/aygEC6TIb2bCAS+k7n8M94cL4h78XfKW2Nl5i7B rcLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uRA15QcYpp84VA9k9wsWlnaKx7a1xt3gupbkmncewJA=; b=R234V+2bAz5cLZx06W0ZGgzLBMY2NErTQPUEfzhskndzZMLPBRGeUN7J+M3yZzFN0l qIoAuH9kL+hJCzCqIa+NP72EH8Vur/RAa8lewrEkMuvYvW7Bx0N36d6EJEV5GDJlEyw2 iBk1gEwSM4IgykSt8cnpTYqxHgvI4SduuM3pLWGUGBDi5hg7GBpxMTphu0tOzs6Hcydu aJBEFJ3nX1RrFKuiIvBv5LT89yyluSPe2HCo2qy88kK/8LxkNA/cejMGkRrT2n5hMoL8 apU8TM6R7Qsgh/1/Fp4KPkzWXcCOo31vARr2tMfjsvDcTbWiEeTWPeuvH8sEswKbeLR0 0scg== X-Gm-Message-State: APjAAAWiid5h5kgJW0qkwKNi4essITxAKRGkoV1dZxjFK9bGJMkJrTcV kEdsqVOkFsRikZUHmPPHvXxTaA== X-Received: by 2002:a1c:4406:: with SMTP id r6mr19995002wma.130.1557849188006; Tue, 14 May 2019 08:53:08 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id w18sm7054926wru.15.2019.05.14.08.53.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 08:53:05 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id A38941FF96; Tue, 14 May 2019 16:53:02 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 16:52:57 +0100 Message-Id: <20190514155301.16123-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190514155301.16123-1-alex.bennee@linaro.org> References: <20190514155301.16123-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 Subject: [Qemu-devel] [RFC PATCH 07/11] target/arm: add LOG_UNIMP messages to arm-semi X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-arm@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Clean-up our unimplemented bits with a proper message. Signed-off-by: Alex Bennée --- target/arm/arm-semi.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.20.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 253c66b172a..a3bbef18ef7 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -28,6 +28,7 @@ #include "cpu.h" #include "hw/semihosting/semihost.h" #include "hw/semihosting/console.h" +#include "qemu/log.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -366,7 +367,7 @@ target_ulong do_arm_semihosting(CPUARMState *env) return len - ret; } case TARGET_SYS_READC: - /* XXX: Read from debug console. Not implemented. */ + qemu_log_mask(LOG_UNIMP, "%s: SYS_READC not implemented", __func__); return 0; case TARGET_SYS_ISTTY: GET_ARG(0); @@ -400,7 +401,7 @@ target_ulong do_arm_semihosting(CPUARMState *env) return buf.st_size; } case TARGET_SYS_TMPNAM: - /* XXX: Not implemented. */ + qemu_log_mask(LOG_UNIMP, "%s: SYS_TMPNAM not implemented", __func__); return -1; case TARGET_SYS_REMOVE: GET_ARG(0); From patchwork Tue May 14 15:52:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 164222 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2800184ili; Tue, 14 May 2019 09:01:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqwduK1nrIlJT3TAQOgtCFEWCx6E/5m70kvQwM8WzThFJd+Cr9b027Sk0EStH+nl5mCZBRB1 X-Received: by 2002:adf:f74f:: with SMTP id z15mr21540435wrp.282.1557849681619; Tue, 14 May 2019 09:01:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557849681; cv=none; d=google.com; s=arc-20160816; b=Cy4cWlBIyikz23WknxGFbm5G6mAyqNwiXigRzdhkB73CDBKF3HdLIHuOSs34zhVe3u HjkIzQ9i5D2jiT1g2uZuvMXMtYMStUlWOAGne1fExbhDyZoXtU+dqktMkDdnHe2TJfjD Zq/IG3/Nnmf3XyJiYEvtyb6yWO58iTndE9FIclqIP4K9jlOrKHCDYoBCxnF1CojAX9JK 5GPh8WMhgnTYPv7FtxfEa/ZUIs1FhINBb1sQfi2C803aWrLl8+TUyh149njwxK21gQ02 IqCivWublx4JPcJtlo+WwcYkTdJp+GRO8NX/S8yib7bbUxPgX4lKyW+TuE2gW34wVl5K JX/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=l/EZtOIUyXPpqgCV5lyhmXRqV1pA86ugcjhdZROi1Z8=; b=eLhB8CCgkc3KreTVzRerbhstj9u2y7B/lO1gePveQs3WE7IQJAVOgr0QqS7tGoaQD/ tFJipkcCOc1ecYcvoqpDLWc5APWVvVToLizLJaP6Y135rMcjscttJoOzKYGLZs3yxaiS VdgWa29qNR8XKrGIKjpGYpN43N6rsgmfeFLjKbu95C+nk6rJ/qCLaX+VJmI9MxYB6AOc 0zQE0zUTXHN6rLpbw3PRd3mVCaB+QOUi2q2fDmOo/TxTMWUKGSh69AZhCd3sioEz4eoX d/3kfN3x2OECi/kl8nkWIR9DMnRWPHDUx+45Hm1go38xGUb9vHmWgNe2dCAdaQ2GNU3B PG0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=WkCkO8qK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j23si8115468eda.335.2019.05.14.09.01.21 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 09:01:21 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=WkCkO8qK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:50330 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQZrk-0003Y4-Ga for patch@linaro.org; Tue, 14 May 2019 12:01:20 -0400 Received: from eggs.gnu.org ([209.51.188.92]:60472) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQZjr-0004oK-EU for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQZjp-0006KO-V5 for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:11 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:53175) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQZjp-0006Go-MJ for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:09 -0400 Received: by mail-wm1-x341.google.com with SMTP id y3so3436936wmm.2 for ; Tue, 14 May 2019 08:53:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l/EZtOIUyXPpqgCV5lyhmXRqV1pA86ugcjhdZROi1Z8=; b=WkCkO8qKAZ0uLl0RhQASW3MB8JEW4RRqIqUsDKImnpMMIk29f3qEKUNrTYkEBZYmHr D32fT3MeKJhYM3X/GpeYf7M7p1k8CWXMIABmmZdmF3iJ35J7/edececFU7SI4PeudjoA TrtGcLb0JoqELZpEufqX8t/2mT0UzICJSO7H8Dh5CBI15Mp25cwlpSzKT2Cz4SCCZhTh XFSPpqxgdN8nmOcLJnNLV+CkAgMefNvPu7IXRgU3RbTKkdv04HgR2HqhWLysnj+yul1w ekf+F/aVMendG+tYDh0cnAtNg+AapBLAgNBnXlnalZicvcwVP3Nr2WP/WkxRooI1Awko 5PYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=l/EZtOIUyXPpqgCV5lyhmXRqV1pA86ugcjhdZROi1Z8=; b=Awt+lXwJc4cCIPVOuuvtXkkbJQd0U/CvKcuUbspuCBiraokxWDaCbeIlMJPPZz1b/X VfzhbyUBHU+PRYvhwhhnTy7yX4HNdWHY+T+usxF+cW27VSNPD/tlyIngheSls+6k+FSK IeF5DGVc0V4bBgP3panM1qWb6L0UI6GTPL/jF+j7dXk1NPYZ4OaqA8oQjDwIWOzHGK2+ L7PTZ9pz09UJEEMWqeAXoBIaZ8AH7iKzHTbRVsJXeCV7BH4NxNEaiWxyMhR7d60+e5US NCq7K+qf1K1PcCwuyvr188eTI4eGvObI5SHslvuqxyi/N+3aBt4bBFEnZR26h9Z3xis0 OHeQ== X-Gm-Message-State: APjAAAVD7bqgwExjqZSvJV+dkw3FCenjDoXWPqCl43wVcT4fF7udqEaK cMWvICnLJYVV/4NzeErypuftdQ== X-Received: by 2002:a1c:9c03:: with SMTP id f3mr20577817wme.67.1557849188513; Tue, 14 May 2019 08:53:08 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 15sm3580767wmg.36.2019.05.14.08.53.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 08:53:05 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id B877F1FF98; Tue, 14 May 2019 16:53:02 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 16:52:58 +0100 Message-Id: <20190514155301.16123-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190514155301.16123-1-alex.bennee@linaro.org> References: <20190514155301.16123-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 Subject: [Qemu-devel] [RFC PATCH 08/11] target/arm: correct return values for WRITE/READ in arm-semi X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-arm@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The documentation says the write should return the number of bytes not written on an error (0 means everything was written). Read provides a buffer length and the return value should be the buffer length - bytes actually read. Remove the incorrect FIXME's and return the correct values. Signed-off-by: Alex Bennée --- target/arm/arm-semi.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) -- 2.20.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index a3bbef18ef7..3ae8f05d51b 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -334,13 +334,15 @@ target_ulong do_arm_semihosting(CPUARMState *env) } else { s = lock_user(VERIFY_READ, arg1, len, 1); if (!s) { - /* FIXME - should this error code be -TARGET_EFAULT ? */ - return (uint32_t)-1; + /* Return bytes not written on error */ + return len; } ret = set_swi_errno(ts, write(arg0, s, len)); unlock_user(s, arg1, 0); - if (ret == (uint32_t)-1) - return -1; + if (ret == (uint32_t)-1) { + ret = 0; + } + /* Return bytes not written */ return len - ret; } case TARGET_SYS_READ: @@ -355,15 +357,17 @@ target_ulong do_arm_semihosting(CPUARMState *env) } else { s = lock_user(VERIFY_WRITE, arg1, len, 0); if (!s) { - /* FIXME - should this error code be -TARGET_EFAULT ? */ - return (uint32_t)-1; + /* return bytes not read */ + return len; } do { ret = set_swi_errno(ts, read(arg0, s, len)); } while (ret == -1 && errno == EINTR); unlock_user(s, arg1, len); - if (ret == (uint32_t)-1) - return -1; + if (ret == (uint32_t)-1) { + ret = 0; + } + /* Return bytes not read */ return len - ret; } case TARGET_SYS_READC: From patchwork Tue May 14 15:52:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 164224 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2804031ili; Tue, 14 May 2019 09:04:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqzQezaP3sr9+gQM1avo6f7MfDfUG4Gf9sN8xXPDyOtlyUJ6i4XqaLPTD9JauKNR4QDV4lg4 X-Received: by 2002:a50:87ab:: with SMTP id a40mr36010404eda.188.1557849852555; Tue, 14 May 2019 09:04:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557849852; cv=none; d=google.com; s=arc-20160816; b=H5DFLdbGUzszI0gPu0v+f3D1NW+Rh+Qx1jFpMAvMJhwzhwFtE9BnaNbSihj9ikp0a9 LKRd/jcNPPLM8S3z9d5Ys8ZBCtzD3474JmnA/vdsq3nZ+eXiQGw0c/g16UzknSd9oYzf FOrffSI36Awl5EHJ19+FCPLmwEMHXmJ6QU2T/FJqFjlF404Yhyz5VOhzWsAVLGvm0Jej 0AlGggltJh4nzIH4CL6mX2+Ro5r1bDePLkdI6CWWEiH+iXHwMDuxEQuFxNzfwWWIqv8h jF2UrEGDntsNlkboPslr8uXxR0BpRag4ujbLxPtn3pejbE6n4Y6aRPw0bMEb5JULKSdZ Wf3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=U06wLwXAasasiurhZZxcEyeJ76fELq2p37jmN4PgTWk=; b=naWCIrEmBkucbfOyjw7/3aDVrF9nqGHDBB3VfVVYKCxXkjDY4CWiGAcMmiaNmmjyi1 ZF5XB2akGdfAfz1rAaBVQpc2qytXGILzcgd91/GkXicD0+shlEH8oTU6BRinWAe/dI6L V6wAh4xrsLUJPyLjjsx1kE2wVau3/T4KNF/J7qx04WDMHmyNEdbKTHFm9Hd9zLvrZwrE VPMXIEBGBC0bst75BkHg9qCcVnB25q3vLTrWKNn00XKwnp/f5fNYyLdaZSgVqKiGVCQ9 NkH95NcE0TLdcRrRD/+kTZsa1I6dPiS/RgU8oACNgNcVwn5o2Z8gp8C6hoYcl+6yEXbs ntYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=VDpoQjdj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g29si1030088eda.138.2019.05.14.09.04.12 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 09:04:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=VDpoQjdj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:50419 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQZuV-000608-HU for patch@linaro.org; Tue, 14 May 2019 12:04:11 -0400 Received: from eggs.gnu.org ([209.51.188.92]:60487) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQZjr-0004p4-Qz for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQZjq-0006Ll-IY for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:11 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:51782) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQZjq-0006Iq-BT for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:10 -0400 Received: by mail-wm1-x342.google.com with SMTP id o189so3432238wmb.1 for ; Tue, 14 May 2019 08:53:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U06wLwXAasasiurhZZxcEyeJ76fELq2p37jmN4PgTWk=; b=VDpoQjdjJpqv+U5DNs7MC4BPRsNXGv0ozijKDokDNKL0x3caANIo9R84k8QzHa0QCh 6BmLy8z17jQKiHV5Hj7HYPHQAfqkrmgqiIqSIRUdg1+8B5QfmU1fq7b6OFyg5BvjnKHT VwJscLuuHnH5ZNUiGQ+v253h+gJFc7ukG0zmFxLSOQjYgIZyDzCJNPolJ+L60B/Vew4S UFmhECwyWsh/AcafCy6xEJ96z1df/tLcKc5G70iees5sNm2TnjWd/owiN1twiwQR3Aqv EZQ9ihWHt573Qqc/6IG/J0udH7GQERlCqO+6CLCP/SNQlC4V38LPnRIVD7j9hB+nmHHb 7VLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U06wLwXAasasiurhZZxcEyeJ76fELq2p37jmN4PgTWk=; b=VQnD88UKEM9aR9vEiN8dVBRSf7JIBuJZ/2wJuKSNFi46VQVJYXX4g2C+zcVZR8UVBk GadYAq9dlkmElyR0iEhLpylr9hMD3A3PWE+zkAY5OGwaJtwfo2kZffOHL/wykqzrj1ek bfNMP5mh2duC8Xq/64dMujanmA0MUy9VQkJAlXuA+TdmGoLHu5868xTEqCsTvkdczXCY 4QIgpkuYOFkVazegSbM3ysBswCnhko6DxrrT9WbB5oYwHjPO29LDhQ/H2Ua6P6UoIzL4 RZ1xVTdCx33/qCa347iQTu4nzU4SAfr3ADENSpZerQ4V8254XSwL/pOD8OB1ullXiH+t qzxQ== X-Gm-Message-State: APjAAAVXqga9qe5Wf7OrGHSldc7fRd7D/PHJg466VdH5vFh3gl2aUDbi Mtrbl7YcFvBHJxTgsTQfnOITsg== X-Received: by 2002:a1c:2c89:: with SMTP id s131mr19508380wms.142.1557849189250; Tue, 14 May 2019 08:53:09 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id y40sm19431367wrd.96.2019.05.14.08.53.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 08:53:05 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id CF5701FF99; Tue, 14 May 2019 16:53:02 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 16:52:59 +0100 Message-Id: <20190514155301.16123-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190514155301.16123-1-alex.bennee@linaro.org> References: <20190514155301.16123-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 Subject: [Qemu-devel] [RFC PATCH 09/11] target/mips: only build mips-semi for softmmu X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aleksandar Rikalo , qemu-arm@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Aleksandar Markovic , Aurelien Jarno Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The is_uhi gates all semihosting calls and always returns false for CONFIG_USER_ONLY builds. There is no reason to build and link mips-semi for these builds so lets fix that. Signed-off-by: Alex Bennée --- target/mips/Makefile.objs | 3 ++- target/mips/helper.h | 2 ++ target/mips/translate.c | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) -- 2.20.1 Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Aleksandar Markovic diff --git a/target/mips/Makefile.objs b/target/mips/Makefile.objs index 651f36f5176..3448ad5e193 100644 --- a/target/mips/Makefile.objs +++ b/target/mips/Makefile.objs @@ -1,4 +1,5 @@ obj-y += translate.o dsp_helper.o op_helper.o lmi_helper.o helper.o cpu.o -obj-y += gdbstub.o msa_helper.o mips-semi.o +obj-y += gdbstub.o msa_helper.o +obj-$(CONFIG_SOFTMMU) += mips-semi.o obj-$(CONFIG_SOFTMMU) += machine.o cp0_timer.o obj-$(CONFIG_KVM) += kvm.o diff --git a/target/mips/helper.h b/target/mips/helper.h index a6d687e3405..90ab03b76e3 100644 --- a/target/mips/helper.h +++ b/target/mips/helper.h @@ -2,7 +2,9 @@ DEF_HELPER_3(raise_exception_err, noreturn, env, i32, int) DEF_HELPER_2(raise_exception, noreturn, env, i32) DEF_HELPER_1(raise_exception_debug, noreturn, env) +#ifndef CONFIG_USER_ONLY DEF_HELPER_1(do_semihosting, void, env) +#endif #ifdef TARGET_MIPS64 DEF_HELPER_4(sdl, void, env, tl, tl, int) diff --git a/target/mips/translate.c b/target/mips/translate.c index 3cd5b11b16b..fb905c88b57 100644 --- a/target/mips/translate.c +++ b/target/mips/translate.c @@ -13726,6 +13726,14 @@ static inline bool is_uhi(int sdbbp_code) #endif } +#ifdef CONFIG_USER_ONLY +/* The above should dead-code away any calls to this..*/ +static inline void gen_helper_do_semihosting(void *env) +{ + g_assert_not_reached(); +} +#endif + static int decode_mips16_opc (CPUMIPSState *env, DisasContext *ctx) { int rx, ry; From patchwork Tue May 14 15:53:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 164223 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2801639ili; Tue, 14 May 2019 09:02:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqxF+MnmYfFm3mzJl9ztdmt+agxmOO2glRcji4ueX1lChqjybosR8c1iADVJpu0hCCf6JMOc X-Received: by 2002:a1c:4602:: with SMTP id t2mr19471210wma.120.1557849746702; Tue, 14 May 2019 09:02:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557849746; cv=none; d=google.com; s=arc-20160816; b=RBFnpaxdwNKdwDPkIu5gN2gcBEW2ntwB2s5+87wyKenvv45X3Rt0kAoMr/Jbfmeg0u ACGNU1lULd2+WIEbq4Wxi0rmDgZJ4dmPmZAnHbnXaNxFr2Zx29npGgtqIa84ma0kuPI0 8w0WjNs/j2CmqSbMnIUNn24f+Z+7OWe/TcH0u5Yz/+JYO5SNmVchENNDMGLsUhjFiQPl 1cOenfS3FDKVEXvXmtWIXt8nJWOI2OBEuvPm99UlykE8yWEizMXaGlzqjVJDPytmPxTO UgRqFHau9bR96kd8cEER1lzyuxkQCKZE/35qiappKRmChj/yusCTNkd0zjYo8a5ALx5o Bkjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=/LCsl9Du5Zb3JNBgOo6lbNCwiqPK/NFNHlF5WOB9yB0=; b=BmeK4F6wlR02GTf5usj/emw/EVWjmx0fkq4S42axp5j6EXnaBqYzzvcar6rq9gLaQG peDM7IlHg4cMdWE/bR95v00YIU7+LjP9Q4kaWDRgliWe5FSnOSOPu0abxElshTBOk7C/ d8wfVSv9C1yLtXNf1JtGqGk6YFRwqzaQuFkWdhcZsFEQHYUMsig9rahJsnZlFEb43L3M xEeX+N++t/OLaC2LSdufcYfXBXTLvdRc1rS34tEiriJ2opFKwwwZD6KDh+xRZJEIbuE+ pJfJ3FUEU1HqOuS0cUufhwzPB1qt2SZZ0U24t/DjrfUKsKgh1bCcIhYWocEsqUCzi9Wm eoPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=YDPRcD4T; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id p49si8252226edc.249.2019.05.14.09.02.26 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 09:02: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=fail header.i=@linaro.org header.s=google header.b=YDPRcD4T; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:50401 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQZsn-0004uR-L6 for patch@linaro.org; Tue, 14 May 2019 12:02:25 -0400 Received: from eggs.gnu.org ([209.51.188.92]:60500) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQZjs-0004pZ-7K for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQZjr-0006Mf-49 for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:12 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:41256) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQZjq-0006Ke-TG for qemu-devel@nongnu.org; Tue, 14 May 2019 11:53:11 -0400 Received: by mail-wr1-x444.google.com with SMTP id d12so19775965wrm.8 for ; Tue, 14 May 2019 08:53:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/LCsl9Du5Zb3JNBgOo6lbNCwiqPK/NFNHlF5WOB9yB0=; b=YDPRcD4TwCfdkuQSRZLeMT9Sr9bRTKQZSSJ2O7XBGrHXcItE5Dx5rpRmM/+KPbg8DT bLXx7ZJqb2CbMTPlriruH/MCzUIP9A5HntnKc/oxpREb4rwtTsuAPnBojlK5kh0Lro5a 8OYnZffrNOBSh/fr4sACpQNW5jVEuV0UDQe0bBcj9UUBiT93I0J6UDB7nt+dVW1sl77T WFhxQ5/77K3kb2IwLtj/vh20/cwP36kQ3qa2FlhCY3cxepF7s3dPd78rp5Jr5unM/E8A 0tz4npDuHpVSpBkz/UT8eRL2QGbIbUrTrcDtfpqpAvUNsu3zvCNW3cn4i6X5vQCDmbtx /gjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/LCsl9Du5Zb3JNBgOo6lbNCwiqPK/NFNHlF5WOB9yB0=; b=B5ZGN+9nubC4xZagEku+G1k9AvX5m1VM0kapepC68UEH9vdv44wV7FNkQARpWNvbQ7 6/ohILstA1BUxgITcHne5RrK2HGUHQ6eXhbZETJ3zl98j6xwQd6sLJiQLn0ibSaGo1/y ehGgcp7LJIMYkq4uAAO8g+UvoyO2tKwRor3DcHU4jqZD08FmjkOKvWgpQ+ePDxQ6htzv ZHawmyt67ifpMi6ha50R1O1AO7KihOKP0YiIbv+k5P0B/xwAaP/k7Ko6Kprtqe1bQlDp 6DRA0V13uDbpLOf5VlgljMOt69JyesQHQBtQ6LUId9yRIymhmQW+2UzqsdYkh6nb8N3J POmg== X-Gm-Message-State: APjAAAVTM0nPboQNsXKWXNgaX7v14bOjVC2enY2OTRT4xtiQFXKl8nW/ 3z0h46halO1NiWNleEPyzZMK7zJMS6c= X-Received: by 2002:a5d:4988:: with SMTP id r8mr11283170wrq.57.1557849189770; Tue, 14 May 2019 08:53:09 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id c9sm12598826wrv.62.2019.05.14.08.53.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 08:53:05 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id E24A31FF87; Tue, 14 May 2019 16:53:02 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 16:53:00 +0100 Message-Id: <20190514155301.16123-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190514155301.16123-1-alex.bennee@linaro.org> References: <20190514155301.16123-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [RFC PATCH 10/11] target/mips: convert UHI_plog to use common semihosting code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aleksandar Rikalo , qemu-arm@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Aleksandar Markovic , Aurelien Jarno Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Rather than printing directly to stdout lets use our common semihosting code. There is one minor difference in that the output currently defaults to stderr instead of stdout however this can be controlled by connecting semihosting to a chardev. Signed-off-by: Alex Bennée --- target/mips/mips-semi.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) -- 2.20.1 Reviewed-by: Aleksandar Markovic diff --git a/target/mips/mips-semi.c b/target/mips/mips-semi.c index eac8374fb34..35bdfd7c77e 100644 --- a/target/mips/mips-semi.c +++ b/target/mips/mips-semi.c @@ -23,6 +23,7 @@ #include "exec/helper-proto.h" #include "exec/softmmu-semi.h" #include "hw/semihosting/semihost.h" +#include "hw/semihosting/console.h" typedef enum UHIOp { UHI_exit = 1, @@ -329,13 +330,12 @@ void helper_do_semihosting(CPUMIPSState *env) p2 = strstr(p, "%d"); if (p2) { int char_num = p2 - p; - char *buf = g_malloc(char_num + 1); - strncpy(buf, p, char_num); - buf[char_num] = '\0'; - gpr[2] = printf("%s%d%s", buf, (int)gpr[5], p2 + 2); - g_free(buf); + GString *s = g_string_new_len(p, char_num); + g_string_append_printf(s, "%d%s", (int)gpr[5], p2 + 2); + gpr[2] = qemu_semihosting_log_out(s->str, s->len); + g_string_free(s, true); } else { - gpr[2] = printf("%s", p); + gpr[2] = qemu_semihosting_log_out(p, strlen(p)); } FREE_TARGET_STRING(p, gpr[4]); break; From patchwork Tue May 14 15:53:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 164225 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2806154ili; Tue, 14 May 2019 09:05:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqwWfZr7Dg3CIHQanlskaE4QOAEulM4ghyKQy08gAuUc+JggUd7YkV+/s7+3oee+pivw6tmj X-Received: by 2002:a17:906:d926:: with SMTP id rn6mr12122171ejb.191.1557849937301; Tue, 14 May 2019 09:05:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557849937; cv=none; d=google.com; s=arc-20160816; b=v3MIruMP4vvneweDLUM2w74a52gYFEi8rjecHQ0XYm6Y9WhK4DYzkxWa7i5ZfbjVf5 SRQkgCfIHsL/W3f7Vb94mf3gD3n+QzRl1/q8IyVyWBfwUsnsMr1M25il/ba1NKMfsECR viFFjzyIb4LJA3GqeKpP27CzW4ogSa6bBAjIUhLeUjsKWGv6nFFq+up5Py7okrlYVbcc uaDWAJVoxDH13/hVDHAqrz+ZpcMoc4x8MC9e94braXSza73WpQqCYuRrBTFx7FeWDNQp D83bu2sRu55BkCmvJBAPyQuZWjnZVh5wzXhNojy7sFzLj5TwPFsoIM8E7aCnf6KrZydg frcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=Sllw1VUnenUpn8foyb+omUx4/xqmAm1WWWMjnAQGm+o=; b=Ypdigt2OHwyYiGBZ1EAaOu1FkrapmElFnyBOfAm/1+bxMQG94HR8jE7mbxBfIiYN+M dyDVd3jJtBZn/Fmm1Wbo77XBwsAHjLUkFeT9rnkSOIC71JCqQXg+W0n0pD3GzKt27FoE epIIcTDiYKOl0ORMg7ROOU+Rl3UPzucuipnkOXhJrMKT+kzn7Ox1ZdjOOdwzERhEIjLJ Z86sk/SbtzzSQOXYtHiIKqD1VW4CMZcbj/BQMsxd0JdOYtuIrIDctz2LUmIz4/6CI5sX M+m1YPpL6Yzu9kNjkv1Lfwcxne1awnWBXaV+Rgd/gCMbz1yDmlpNnk0RVLMX+z9O7pC2 /ZJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=j7EqRFqD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n12si7233294ejh.398.2019.05.14.09.05.37 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 09:05:37 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=j7EqRFqD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:50460 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQZvs-0006yy-5r for patch@linaro.org; Tue, 14 May 2019 12:05:36 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34112) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQZqE-0002gB-E6 for qemu-devel@nongnu.org; Tue, 14 May 2019 11:59:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQZqD-00065u-Gp for qemu-devel@nongnu.org; Tue, 14 May 2019 11:59:46 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]:37404) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQZqD-00065P-AT for qemu-devel@nongnu.org; Tue, 14 May 2019 11:59:45 -0400 Received: by mail-wr1-x433.google.com with SMTP id e15so7433132wrs.4 for ; Tue, 14 May 2019 08:59:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Sllw1VUnenUpn8foyb+omUx4/xqmAm1WWWMjnAQGm+o=; b=j7EqRFqDBdumU8BKx8cZiiwsoTgIF+oRxgknzCAYsWJfPB+vg35Bh5P9i9EDWAq1RV nzVphwC2rj63evzqjGC0DvVlgtCe+EOyorFJ1ZehoebCuKFm33P3aXWG4/TJeNpD0Y+1 Q2dCw3T0Z+Lace/M577r3XVs+2iK8sH+SUd9HIc5MMe06Bbg4M6c2jlQh3YUa3kRbIZd danVeJuhWKGAixcEuzjkk0FjXtye9DUz8EO2DXh3sCyjJFKfpPJXTUhmBclw0XqnWARc Vx/z5Qzyr4HymY5SJqZNb8x0KSGwBG7DbIe0g7jTZ87JyPjKyeY5XTxV4WW3/SoKZEOX ehbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Sllw1VUnenUpn8foyb+omUx4/xqmAm1WWWMjnAQGm+o=; b=W+gSHxa8H18WwyM/BjRSDmNxptlYlX/U+LmstW1w7/gJamWp5xUK2BIMm3NsObuQ9t BS8GSHePhYsfHJaP1IPy8Z0SR46GqKcBs/xRb1tHTobOzMFmgSl2Vuuh+yIbxZC3WNRd Y8d/F2KMFYR4m32dtKya2flNxV5h7XotlKoD9xdnpkjMIonS0/AxMkqMJe3o2fPGPeRS bh9S/Y+Gb6qJmbxCGRsqPJcgucK9f2jH4Jq04h+LQ0D6UsDDRu16KERTQO48fFJUJLIq yCu+OTU2zrNCIWvZwKrZ9dJ3ozDups9cMEHxoc1Sios4Tk+awGSPB9nWX2oDzjtT4/Hj M8aw== X-Gm-Message-State: APjAAAW/NDtzPbSekAy5SDaAw7Q+dCqWnJumNIJS5w9bEMVWXJQyDDtd tCP6DaWOu5CX9WtBOePdkf7c4w== X-Received: by 2002:adf:afcd:: with SMTP id y13mr21262936wrd.270.1557849584105; Tue, 14 May 2019 08:59:44 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 6sm18365980wrd.51.2019.05.14.08.59.43 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 14 May 2019 08:59:43 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 029091FF9A; Tue, 14 May 2019 16:53:03 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 16:53:01 +0100 Message-Id: <20190514155301.16123-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190514155301.16123-1-alex.bennee@linaro.org> References: <20190514155301.16123-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::433 Subject: [Qemu-devel] [RFC PATCH 11/11] MAINTAINERS: update for semihostings new home X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-arm@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Seeing as I touched it I should at least keep an eye on it. Signed-off-by: Alex Bennée --- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+) -- 2.20.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/MAINTAINERS b/MAINTAINERS index a73a61a5465..e9050beb222 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2559,6 +2559,13 @@ F: docs/pvrdma.txt F: contrib/rdmacm-mux/* F: qapi/rdma.json +Semihosting +M: Alex Bennée +L: qemu-devel@nongnu.org +S: Maintained +F: hw/semihosting/ +F: include/hw/semihosting/ + Build and test automation ------------------------- Build and test automation