From: Brian Cain <[email protected]> Add qemu_semihosting_console_has_chardev() to query whether the semihosting console is backed by a chardev, and console_guestfd() to initialize a guest file descriptor as GuestFDConsole.
These APIs enable callers to route semihosting I/O through a chardev rather than directly to host stdio. Signed-off-by: Brian Cain <[email protected]> Reviewed-by: Pierrick Bouvier <[email protected]> --- include/semihosting/console.h | 9 +++++++++ include/semihosting/guestfd.h | 9 +++++++++ semihosting/console.c | 5 +++++ semihosting/guestfd.c | 8 ++++++++ 4 files changed, 31 insertions(+) diff --git a/include/semihosting/console.h b/include/semihosting/console.h index 1c12e178ee3..d5f149e2088 100644 --- a/include/semihosting/console.h +++ b/include/semihosting/console.h @@ -54,4 +54,13 @@ void qemu_semihosting_console_block_until_ready(CPUState *cs); */ bool qemu_semihosting_console_ready(void); +/** + * qemu_semihosting_console_has_chardev: + * + * Return true if the semihosting console is backed by a chardev. + * When true, console I/O goes through the chardev rather than + * host stdio. + */ +bool qemu_semihosting_console_has_chardev(void); + #endif /* SEMIHOST_CONSOLE_H */ diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h index a7ea1041ea0..76ca0fcf1a7 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -70,6 +70,15 @@ GuestFD *get_guestfd(int guestfd); */ void associate_guestfd(int guestfd, int hostfd); +/** + * console_guestfd: + * @guestfd: GuestFD index + * + * Initialize the GuestFD for @guestfd to GuestFDConsole. + * I/O will be routed through the semihosting console chardev. + */ +void console_guestfd(int guestfd); + /** * staticfile_guestfd: * @guestfd: GuestFD index diff --git a/semihosting/console.c b/semihosting/console.c index 91e5d50d502..9d786833564 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -108,6 +108,11 @@ int qemu_semihosting_console_read(CPUState *cs, void *buf, int len) return ret; } +bool qemu_semihosting_console_has_chardev(void) +{ + return console.chr != NULL; +} + int qemu_semihosting_console_write(void *buf, int len) { if (console.chr) { diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index e8f236c690c..8b5770bab0d 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -117,6 +117,14 @@ void associate_guestfd(int guestfd, int hostfd) gf->hostfd = hostfd; } +void console_guestfd(int guestfd) +{ + GuestFD *gf = do_get_guestfd(guestfd); + + assert(gf); + gf->type = GuestFDConsole; +} + void staticfile_guestfd(int guestfd, const uint8_t *data, size_t len) { GuestFD *gf = do_get_guestfd(guestfd); -- 2.37.2
