From patchwork Thu May 9 16:58: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: 163728 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1244883ilr; Thu, 9 May 2019 10:06:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqyXTw0DcDxpWaUbqTysVES/AK4CKjMOARel5ZNIhoDCkn0MyAAGtJJxp08Y50j5KVUHyj49 X-Received: by 2002:a1c:4406:: with SMTP id r6mr3767652wma.130.1557421564258; Thu, 09 May 2019 10:06:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557421564; cv=none; d=google.com; s=arc-20160816; b=1Gy1ZLNsT7lbHrlkci9u862tlFcuBaXySLpSNUzb+XI3oPj6hFMNxOhZXfBZKm5UZ0 ndY4Y/9QFE7DRuAndSLDyXB0gTJq+IYmufTGhP0fhxfFpc/RPyBTdMXge0HVnA6NWV9B UwzeTR1gko5Z8jlO7DRCdpwNzEBjUDaU095xZBvG/U3088c0+s6EfbSmKfnxHtacxVfz OKa5Qgu5QG1zS8J9pYdGnkBL/eYxqRqCZokMoqCBB4bP/xMjPTwz+TrcmRf7M0t/AZzU ckgSG1DzxmiNEP8URjzMwilrKODZPqYfcOMK0vLfcGg/KyMjONkHTZlc19UtVdMT8F4h yjMQ== 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=OpvEU2mddt+GIEBclmCB/up2u9bmndzrghYWbyOx7a4=; b=wEgEKx7kWnRg/d9oySQowocdoQ2040xjemKnrmVEgFBAIefkRhCrypcX3tUhSbWvzf YScJ9TO6LOQgpRygdGUF1l+tmDkQEcj99g51KkhzU6MuSQ+3bRx2rY1m9vZUsYbpqnBR qEqoNP2vYNStfchNcrGtDxuMfWIsNASCj7hRSeoAzHAxId3lwR5wX+qDlPrI7BBD3hhD zHmDOfQaexVARpBAKnWScF7nRslVD8lAQBCTSbgJjszwsjK+Oq8XFsW75bDpMP1upC/X U0tlrjnqo46tA78L3D4HrelXnHXFO6AdsYhrMAHrTBCjVyHaa18zRTpO9a5LwmyoZcz9 pvQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=aiBWJLQZ; 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 p23si1916196wma.55.2019.05.09.10.06.03 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 10:06:04 -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=aiBWJLQZ; 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]:58079 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOmUd-0004Rd-5N for patch@linaro.org; Thu, 09 May 2019 13:06:03 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49630) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOmO8-0006zP-H6 for qemu-devel@nongnu.org; Thu, 09 May 2019 12:59:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOmO7-0004tA-0y for qemu-devel@nongnu.org; Thu, 09 May 2019 12:59:20 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:54472) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOmO6-0004s5-QP for qemu-devel@nongnu.org; Thu, 09 May 2019 12:59:18 -0400 Received: by mail-wm1-x343.google.com with SMTP id b203so4153637wmb.4 for ; Thu, 09 May 2019 09:59:18 -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=OpvEU2mddt+GIEBclmCB/up2u9bmndzrghYWbyOx7a4=; b=aiBWJLQZO3EkGYv6kP7hHdprELwVPbY0I2KN6yJXCAGigCqRp+8zJN6iqYkx7ykbX3 mfEau5E+UinD92HCzN/FsUai3ioTH9u0Je69LEg2veIiOLtXanuhwoBplRDc2rugqWEP ZuM89h+B+wObjJUxTZiooI7mWvGA58oeMSRnOMm4sR2srrzaAlV0ubgylpnhFnyU7o+G nH2EE0IkAx6pveSUov/H2IkLgd/EUdXwbrnhHBPK/TGJKKv8RQs4Qma80+dABE/FpSoN Wi9NSLDK0guWRUVRRuC9ReLLP4CzQcRDbb/l2ah45Ilpe7tg6XwbGAV7ltgxQ39EvC9i kb4A== 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=OpvEU2mddt+GIEBclmCB/up2u9bmndzrghYWbyOx7a4=; b=Rbeu6EVWmqMRT+8MgB5HKja8cRS27zKjpRSDCfcCofYM9zluAKFN2A/hbrlCUNw/kr ltRukK0eHaoyWkm8wRTu12gpAJC64XdYomJ1t6ROxWD3lB+SCkadwcG2nIaWySa1SC1I yPQ9AVQqh197en2NNigL91whhXsLf8Cv1gbKstGMl+udvpFJyum99FuCApjjpRMc4tNn IsrMYMNnmbpCJ7Cc1R9ZoxGDhaGTqgQdckBx1KrKUj2FIAfuL02usffckKL+HRhsohLR A+s+Vph594gGz2ucOOAO28APVhVX909wpxwKlD1napXUofx2M6xJqcZ2vLIAvg38HWOn DD5Q== X-Gm-Message-State: APjAAAXhq1w018xFmF5iRI8w+jPEyqwxOVdoURu2RqO3BuZIg62bwT9s +hU1UKL+s5DP+2QB/ee1FvPT2j/BUuE= X-Received: by 2002:a05:600c:d1:: with SMTP id u17mr3635272wmm.2.1557421157743; Thu, 09 May 2019 09:59:17 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id u20sm24373wmu.34.2019.05.09.09.59.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 09 May 2019 09:59:14 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 75EC81FF92; Thu, 9 May 2019 17:59:12 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 17:58:53 +0100 Message-Id: <20190509165912.10512-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190509165912.10512-1-alex.bennee@linaro.org> References: <20190509165912.10512-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] [PATCH v1 05/23] semihosting: enable chardev backed output 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?= , Paolo Bonzini Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" For running system tests we want 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 semihosting like just another character output device. Signed-off-by: Alex Bennée --- include/exec/semihost.h | 6 ++++++ qemu-options.hx | 6 ++++-- target/arm/arm-semi.c | 21 +++++++++++++++++++-- vl.c | 23 +++++++++++++++++++++++ 4 files changed, 52 insertions(+), 4 deletions(-) -- 2.20.1 diff --git a/include/exec/semihost.h b/include/exec/semihost.h index 5980939c7b8..f5cc9ad2759 100644 --- a/include/exec/semihost.h +++ b/include/exec/semihost.h @@ -51,12 +51,18 @@ static inline const char *semihosting_get_cmdline(void) { return NULL; } + +static inline Chardev *semihosting_get_chardev(void) +{ + return NULL; +} #else 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); +Chardev *semihosting_get_chardev(void); #endif #endif 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/target/arm/arm-semi.c b/target/arm/arm-semi.c index 8b5fd7bc6e3..4c326fdc2fb 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -32,6 +32,7 @@ #include "hw/arm/arm.h" #include "qemu/cutils.h" #endif +#include "chardev/char.h" #define TARGET_SYS_OPEN 0x01 #define TARGET_SYS_CLOSE 0x02 @@ -310,7 +311,15 @@ target_ulong do_arm_semihosting(CPUARMState *env) if (use_gdb_syscalls()) { return arm_gdb_syscall(cpu, arm_semi_cb, "write,2,%x,1", args); } else { - return write(STDERR_FILENO, &c, 1); +#ifdef CONFIG_SOFTMMU + Chardev *chardev = semihosting_get_chardev(); + if (chardev) { + return qemu_chr_write_all(chardev, (uint8_t *) &c, 1); + } else +#endif + { + return write(STDERR_FILENO, &c, 1); + } } } case TARGET_SYS_WRITE0: @@ -322,7 +331,15 @@ target_ulong do_arm_semihosting(CPUARMState *env) return arm_gdb_syscall(cpu, arm_semi_cb, "write,2,%x,%x", args, len); } else { - ret = write(STDERR_FILENO, s, len); +#ifdef CONFIG_SOFTMMU + Chardev *chardev = semihosting_get_chardev(); + if (chardev) { + ret = qemu_chr_write_all(chardev, (uint8_t *) s, len); + } else +#endif + { + ret = write(STDERR_FILENO, s, len); + } } unlock_user(s, args, 0); return ret; diff --git a/vl.c b/vl.c index b6709514c1b..34bbb4df865 100644 --- a/vl.c +++ b/vl.c @@ -511,6 +511,9 @@ static QemuOptsList qemu_semihosting_config_opts = { }, { .name = "target", .type = QEMU_OPT_STRING, + }, { + .name = "chardev", + .type = QEMU_OPT_STRING, }, { .name = "arg", .type = QEMU_OPT_STRING, @@ -1356,6 +1359,7 @@ static void configure_msg(QemuOpts *opts) typedef struct SemihostingConfig { bool enabled; SemihostingTarget target; + Chardev *chardev; const char **argv; int argc; const char *cmdline; /* concatenated argv */ @@ -1386,6 +1390,11 @@ int semihosting_get_argc(void) return semihosting.argc; } +Chardev *semihosting_get_chardev(void) +{ + return semihosting.chardev; +} + const char *semihosting_get_cmdline(void) { if (semihosting.cmdline == NULL && semihosting.argc > 0) { @@ -3027,6 +3036,7 @@ int main(int argc, char **argv, char **envp) int display_remote = 0; const char *log_mask = NULL; const char *log_file = NULL; + const char *semihost_chardev = NULL; char *trace_file = NULL; ram_addr_t maxram_size; uint64_t ram_slots = 0; @@ -3744,6 +3754,8 @@ int main(int argc, char **argv, char **envp) 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; @@ -4277,6 +4289,17 @@ int main(int argc, char **argv, char **envp) qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, &error_fatal); + /* 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; + } + #ifdef CONFIG_VIRTFS qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, &error_fatal);