From nobody Sat May 18 18:27:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1603921094; cv=none; d=zohomail.com; s=zohoarc; b=CYtT5EtNi5t8wSxpxrcMe/iZwUqbYWZkjf4hxU5HR3abstVESdpEJ7aUV0cfR9l8sXn7DEGPIOFcTjY5JOsrKvCKf4u4NrUWWNHaO5ODag4Eotd2Fp/h0iHvJJx1aPSjzTYj02G79F9AoyIPoEZeDWJW9QdTFyADLZUEXw+gOBg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603921094; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=7b42cD4Y2W+g6DbXnreSnkWNq6+F+Nvtg6C/s17XWVA=; b=go/okAazMPMUwQVi3YfGcttxJn7omOEX8vaDxhwbg0+KWVbpdyciTf8ChcbmiX1U3/lthUdZ1qhntR+kqq7VS2gFP5SbX525zo86Zf4nw2V9a4QG0iXuTHYTQFOMBPNg0XRr0PA/2fNc2rQkvanE5xedFOl2XFcxoSW32k8+pas= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1603921094153731.7999743893733; Wed, 28 Oct 2020 14:38:14 -0700 (PDT) Received: from localhost ([::1]:34340 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXt93-00019S-2L for importer@patchew.org; Wed, 28 Oct 2020 17:38:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43496) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXt6M-0000SO-3N for qemu-devel@nongnu.org; Wed, 28 Oct 2020 17:35:26 -0400 Received: from home.keithp.com ([63.227.221.253]:48064 helo=elaine.keithp.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXt6I-0001KS-Th for qemu-devel@nongnu.org; Wed, 28 Oct 2020 17:35:25 -0400 Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 393FF3F2DDB5; Wed, 28 Oct 2020 14:35:20 -0700 (PDT) Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id tOwmd0NJ75hH; Wed, 28 Oct 2020 14:35:15 -0700 (PDT) Received: from keithp.com (koto.keithp.com [10.0.0.2]) by elaine.keithp.com (Postfix) with ESMTPSA id 0E2513F2DDB2; Wed, 28 Oct 2020 14:35:15 -0700 (PDT) Received: by keithp.com (Postfix, from userid 1000) id C66081582210; Wed, 28 Oct 2020 14:35:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1603920920; bh=Cc20zA94dsjlJ56GyP6sBhSgPpNZNEKP68oxX4EMpNk=; h=From:To:Cc:Subject:Date:From; b=CV4/9eKB+Msd2jpZqN8b6z4JxopVEwrlgzxqz6ZlrBIvwCzxs7yhSLAynb/QgEpa1 su0X4tqCCHK9DmA/p8uHspHoXNzlNxoF+5DLjQ3bL8Qcaq6VjTF4lvVUxBRZxTciP5 2MSN7+01dEvVCH8HggNhpLnfC4Qums4AZgxlJ96C4cgwpdCXqhEoUNt/VJFZCGa873 ELILyTU2iTLNJeJmoujHt0w8zLIjr763cZrxpU+feBsNdibffVspDkSw12hGuXaDJ7 Se9KCJnW0DNe5WDgN8Dlq+HNT0BKPZBosvXgiyU/gABnKGIwOttcVQtVxC6kbtNtj9 AvWOZbnWy3I3Q== X-Virus-Scanned: Debian amavisd-new at keithp.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1603920915; bh=Cc20zA94dsjlJ56GyP6sBhSgPpNZNEKP68oxX4EMpNk=; h=From:To:Cc:Subject:Date:From; b=wROTDxCnplkESpbfKkD6OSp7TdAH3fI/ennXJmMJUZ0xdfW10TZ0W97QlDjarKTq3 g+VXzQc+lgCKFCrQVk8TUfXPSWFSRVtwIZU2oJEmEst43Rztih0HVZuLTPfW69MP3R Mi4YYcmTmZFHDBBM9ediLDPFWiYgDEBnceSUgaJyi3P+GmfznXw4IBAPh1S0gWc7nT SDKIASTyX1ZEeoXeJxihp3l+OkA318eEgWwqxlOsTIr42CwCWhvmjtgO1+KoVa4jKX o3j1SW6vveJZZDkYstH/f6tnkGVHmRQqRMnA2C+zhXF7TEq6R09iMvbprOQKoZH7O6 WSG+4n+oiyuxw== To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini , Keith Packard Subject: [PATCH] semihosting: Merge semihosting console init functions to fix READC Date: Wed, 28 Oct 2020 14:35:12 -0700 Message-Id: <20201028213512.3002352-1-keithp@keithp.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.227.221.253; envelope-from=keithp@keithp.com; helo=elaine.keithp.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/28 17:35:20 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Keith Packard From: Keith Packard via X-ZohoMail-DKIM: fail (found 2 invalid signatures) Content-Type: text/plain; charset="utf-8" Commit 619985e937 (semihosting: defer connect_chardevs a little more to use serialx) moved the call to qemu_semihosting_connect_chardevs until after all of the serial devices were initialized to make semihosting console configuration easier. This change broke semihosting console input as the call to qemu_semihosting_console_init was now made *before* qemu_semihosting_connect_chardevs, which it requires. To fix that, and to make sure it doesn't happen in the future, I've merged these two functions together into qemu_semihosting_console_init, which finds the Chardev and then wires up console input. These were split when semihosting READC was added to control the priority of semihosting input compared with other users of a multiplexed console. With connect_chardevs now occuring much later in qemu initialization, the semihosting console input will have the same priority as it did before the referenced commit was applied. Signed-off-by: Keith Packard --- hw/semihosting/config.c | 21 ++--------- hw/semihosting/console.c | 58 ++++++++++++++++++------------- include/hw/semihosting/semihost.h | 4 +-- softmmu/vl.c | 5 +-- 4 files changed, 40 insertions(+), 48 deletions(-) diff --git a/hw/semihosting/config.c b/hw/semihosting/config.c index 9807f10cb0..1bf3125f0c 100644 --- a/hw/semihosting/config.c +++ b/hw/semihosting/config.c @@ -51,14 +51,13 @@ QemuOptsList qemu_semihosting_config_opts =3D { typedef struct SemihostingConfig { bool enabled; SemihostingTarget target; - Chardev *chardev; + const char *chardev; const char **argv; int argc; const char *cmdline; /* concatenated argv */ } SemihostingConfig; =20 static SemihostingConfig semihosting; -static const char *semihost_chardev; =20 bool semihosting_enabled(void) { @@ -122,7 +121,7 @@ void semihosting_arg_fallback(const char *file, const c= har *cmd) } } =20 -Chardev *semihosting_get_chardev(void) +const char *semihosting_get_chardev(void) { return semihosting.chardev; } @@ -145,7 +144,7 @@ int qemu_semihosting_config_options(const char *optarg) true); const char *target =3D qemu_opt_get(opts, "target"); /* setup of chardev is deferred until they are initialised */ - semihost_chardev =3D qemu_opt_get(opts, "chardev"); + semihosting.chardev =3D qemu_opt_get(opts, "chardev"); if (target !=3D NULL) { if (strcmp("native", target) =3D=3D 0) { semihosting.target =3D SEMIHOSTING_TARGET_NATIVE; @@ -171,17 +170,3 @@ int qemu_semihosting_config_options(const char *optarg) =20 return 0; } - -void qemu_semihosting_connect_chardevs(void) -{ - /* We had to defer this until chardevs were created */ - if (semihost_chardev) { - Chardev *chr =3D qemu_chr_find(semihost_chardev); - if (chr =3D=3D NULL) { - error_report("semihosting chardev '%s' not found", - semihost_chardev); - exit(1); - } - semihosting.chardev =3D chr; - } -} diff --git a/hw/semihosting/console.c b/hw/semihosting/console.c index 9b4fee9260..345f21b8e5 100644 --- a/hw/semihosting/console.c +++ b/hw/semihosting/console.c @@ -29,11 +29,23 @@ #include "qapi/error.h" #include "qemu/fifo8.h" =20 +#define FIFO_SIZE 1024 + +/* Access to this structure is protected by the BQL */ +typedef struct SemihostingConsole { + CharBackend backend; + GSList *sleeping_cpus; + bool got; + Fifo8 fifo; + Chardev *chardev; +} SemihostingConsole; + +static SemihostingConsole console; + int qemu_semihosting_log_out(const char *s, int len) { - Chardev *chardev =3D semihosting_get_chardev(); - if (chardev) { - return qemu_chr_write_all(chardev, (uint8_t *) s, len); + if (console.chardev) { + return qemu_chr_write_all(console.chardev, (uint8_t *) s, len); } else { return write(STDERR_FILENO, s, len); } @@ -107,17 +119,6 @@ void qemu_semihosting_console_outc(CPUArchState *env, = target_ulong addr) } } =20 -#define FIFO_SIZE 1024 - -/* Access to this structure is protected by the BQL */ -typedef struct SemihostingConsole { - CharBackend backend; - GSList *sleeping_cpus; - bool got; - Fifo8 fifo; -} SemihostingConsole; - -static SemihostingConsole console; =20 static int console_can_read(void *opaque) { @@ -166,15 +167,24 @@ target_ulong qemu_semihosting_console_inc(CPUArchStat= e *env) =20 void qemu_semihosting_console_init(void) { - Chardev *chr =3D semihosting_get_chardev(); - - if (chr) { - fifo8_create(&console.fifo, FIFO_SIZE); - qemu_chr_fe_init(&console.backend, chr, &error_abort); - qemu_chr_fe_set_handlers(&console.backend, - console_can_read, - console_read, - NULL, NULL, &console, - NULL, true); + const char *chardev =3D semihosting_get_chardev(); + + if (chardev =3D=3D NULL) { + return; } + + console.chardev =3D qemu_chr_find(chardev); + + if (console.chardev =3D=3D NULL) { + error_report("semihosting chardev '%s' not found", chardev); + exit(1); + } + + fifo8_create(&console.fifo, FIFO_SIZE); + qemu_chr_fe_init(&console.backend, console.chardev, &error_abort); + qemu_chr_fe_set_handlers(&console.backend, + console_can_read, + console_read, + NULL, NULL, &console, + NULL, true); } diff --git a/include/hw/semihosting/semihost.h b/include/hw/semihosting/sem= ihost.h index b8ce5117ae..bbde8bd807 100644 --- a/include/hw/semihosting/semihost.h +++ b/include/hw/semihosting/semihost.h @@ -52,7 +52,7 @@ static inline const char *semihosting_get_cmdline(void) return NULL; } =20 -static inline Chardev *semihosting_get_chardev(void) +static inline const char *semihosting_get_chardev(void) { return NULL; } @@ -66,7 +66,7 @@ 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); +const char *semihosting_get_chardev(void); /* for vl.c hooks */ void qemu_semihosting_enable(void); int qemu_semihosting_config_options(const char *opt); diff --git a/softmmu/vl.c b/softmmu/vl.c index 7c1c6d37ef..b2bad58575 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -4284,9 +4284,6 @@ void qemu_init(int argc, char **argv, char **envp) qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, &error_fatal); =20 - /* connect semihosting console input if requested */ - qemu_semihosting_console_init(); - if (foreach_device_config(DEV_SERIAL, serial_parse) < 0) exit(1); if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0) @@ -4295,7 +4292,7 @@ void qemu_init(int argc, char **argv, char **envp) exit(1); =20 /* now chardevs have been created we may have semihosting to connect */ - qemu_semihosting_connect_chardevs(); + qemu_semihosting_console_init(); =20 /* If no default VGA is requested, the default is "none". */ if (default_vga) { --=20 2.28.0