semihosting: Cleanup chardev init

Rename qemu_semihosting_connect_chardevs to
qemu_semihosting_chardev_init; pass the result
directly to qemu_semihosting_console_init.

Store the chardev in SemihostingConsole instead
of SemihostingConfig, which lets us drop
semihosting_get_chardev.

Reviewed-by: Luc Michel <lmichel@kalray.eu>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson 2022-05-01 16:59:06 -07:00
parent e7fb6f3205
commit fb08790b35
5 changed files with 26 additions and 44 deletions

View File

@ -51,14 +51,6 @@ static inline const char *semihosting_get_cmdline(void)
{ {
return NULL; return NULL;
} }
static inline Chardev *semihosting_get_chardev(void)
{
return NULL;
}
static inline void qemu_semihosting_console_init(void)
{
}
#else /* !CONFIG_USER_ONLY */ #else /* !CONFIG_USER_ONLY */
bool semihosting_enabled(void); bool semihosting_enabled(void);
SemihostingTarget semihosting_get_target(void); SemihostingTarget semihosting_get_target(void);
@ -66,12 +58,11 @@ const char *semihosting_get_arg(int i);
int semihosting_get_argc(void); int semihosting_get_argc(void);
const char *semihosting_get_cmdline(void); const char *semihosting_get_cmdline(void);
void semihosting_arg_fallback(const char *file, const char *cmd); void semihosting_arg_fallback(const char *file, const char *cmd);
Chardev *semihosting_get_chardev(void);
/* for vl.c hooks */ /* for vl.c hooks */
void qemu_semihosting_enable(void); void qemu_semihosting_enable(void);
int qemu_semihosting_config_options(const char *opt); int qemu_semihosting_config_options(const char *opt);
void qemu_semihosting_connect_chardevs(void); void qemu_semihosting_chardev_init(void);
void qemu_semihosting_console_init(void); void qemu_semihosting_console_init(Chardev *);
#endif /* CONFIG_USER_ONLY */ #endif /* CONFIG_USER_ONLY */
#endif /* SEMIHOST_H */ #endif /* SEMIHOST_H */

View File

@ -51,7 +51,6 @@ QemuOptsList qemu_semihosting_config_opts = {
typedef struct SemihostingConfig { typedef struct SemihostingConfig {
bool enabled; bool enabled;
SemihostingTarget target; SemihostingTarget target;
Chardev *chardev;
char **argv; char **argv;
int argc; int argc;
const char *cmdline; /* concatenated argv */ const char *cmdline; /* concatenated argv */
@ -122,11 +121,6 @@ void semihosting_arg_fallback(const char *file, const char *cmd)
} }
} }
Chardev *semihosting_get_chardev(void)
{
return semihosting.chardev;
}
void qemu_semihosting_enable(void) void qemu_semihosting_enable(void)
{ {
semihosting.enabled = true; semihosting.enabled = true;
@ -172,16 +166,19 @@ int qemu_semihosting_config_options(const char *optarg)
return 0; return 0;
} }
void qemu_semihosting_connect_chardevs(void) /* We had to defer this until chardevs were created */
void qemu_semihosting_chardev_init(void)
{ {
/* We had to defer this until chardevs were created */ Chardev *chr = NULL;
if (semihost_chardev) { if (semihost_chardev) {
Chardev *chr = qemu_chr_find(semihost_chardev); chr = qemu_chr_find(semihost_chardev);
if (chr == NULL) { if (chr == NULL) {
error_report("semihosting chardev '%s' not found", error_report("semihosting chardev '%s' not found",
semihost_chardev); semihost_chardev);
exit(1); exit(1);
} }
semihosting.chardev = chr;
} }
qemu_semihosting_console_init(chr);
} }

View File

@ -27,11 +27,21 @@
#include "qapi/error.h" #include "qapi/error.h"
#include "qemu/fifo8.h" #include "qemu/fifo8.h"
/* Access to this structure is protected by the BQL */
typedef struct SemihostingConsole {
CharBackend backend;
Chardev *chr;
GSList *sleeping_cpus;
bool got;
Fifo8 fifo;
} SemihostingConsole;
static SemihostingConsole console;
int qemu_semihosting_log_out(const char *s, int len) int qemu_semihosting_log_out(const char *s, int len)
{ {
Chardev *chardev = semihosting_get_chardev(); if (console.chr) {
if (chardev) { return qemu_chr_write_all(console.chr, (uint8_t *) s, len);
return qemu_chr_write_all(chardev, (uint8_t *) s, len);
} else { } else {
return write(STDERR_FILENO, s, len); return write(STDERR_FILENO, s, len);
} }
@ -106,16 +116,6 @@ void qemu_semihosting_console_outc(CPUArchState *env, target_ulong addr)
#define FIFO_SIZE 1024 #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;
static int console_can_read(void *opaque) static int console_can_read(void *opaque)
{ {
SemihostingConsole *c = opaque; SemihostingConsole *c = opaque;
@ -169,10 +169,9 @@ int qemu_semihosting_console_read(CPUState *cs, void *buf, int len)
return ret; return ret;
} }
void qemu_semihosting_console_init(void) void qemu_semihosting_console_init(Chardev *chr)
{ {
Chardev *chr = semihosting_get_chardev(); console.chr = chr;
if (chr) { if (chr) {
fifo8_create(&console.fifo, FIFO_SIZE); fifo8_create(&console.fifo, FIFO_SIZE);
qemu_chr_fe_init(&console.backend, chr, &error_abort); qemu_chr_fe_init(&console.backend, chr, &error_abort);

View File

@ -1917,8 +1917,7 @@ static void qemu_create_late_backends(void)
exit(1); exit(1);
/* now chardevs have been created we may have semihosting to connect */ /* now chardevs have been created we may have semihosting to connect */
qemu_semihosting_connect_chardevs(); qemu_semihosting_chardev_init();
qemu_semihosting_console_init();
} }
static void qemu_resolve_machine_memdev(void) static void qemu_resolve_machine_memdev(void)

View File

@ -65,10 +65,6 @@ void semihosting_arg_fallback(const char *file, const char *cmd)
{ {
} }
void qemu_semihosting_connect_chardevs(void) void qemu_semihosting_chardev_init(void)
{
}
void qemu_semihosting_console_init(void)
{ {
} }