[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 41/74] semihosting: Create qemu_semihosting_guestfd_init
From: |
Richard Henderson |
Subject: |
[PATCH v2 41/74] semihosting: Create qemu_semihosting_guestfd_init |
Date: |
Tue, 3 May 2022 12:48:10 -0700 |
For arm-compat, initialize console_{in,out}_gf;
otherwise, initialize stdio file descriptors.
This will go some way to cleaning up arm-compat, and
will allow other semihosting to use normal stdio.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/semihosting/guestfd.h | 7 +++++
include/semihosting/semihost.h | 1 +
linux-user/main.c | 9 ++++++
semihosting/console.c | 2 ++
semihosting/guestfd.c | 52 +++++++++++++++++++++++++++-------
5 files changed, 61 insertions(+), 10 deletions(-)
diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h
index 5c3e7cd538..73d8235222 100644
--- a/include/semihosting/guestfd.h
+++ b/include/semihosting/guestfd.h
@@ -35,6 +35,13 @@ typedef struct GuestFD {
};
} GuestFD;
+/*
+ * For ARM semihosting, we have a separate structure for routing
+ * data for the console which is outside the guest fd address space.
+ */
+extern GuestFD console_in_gf;
+extern GuestFD console_out_gf;
+
int alloc_guestfd(void);
void dealloc_guestfd(int guestfd);
GuestFD *get_guestfd(int guestfd);
diff --git a/include/semihosting/semihost.h b/include/semihosting/semihost.h
index 5b36a76f08..93a3c21b44 100644
--- a/include/semihosting/semihost.h
+++ b/include/semihosting/semihost.h
@@ -64,5 +64,6 @@ int qemu_semihosting_config_options(const char *opt);
void qemu_semihosting_chardev_init(void);
void qemu_semihosting_console_init(Chardev *);
#endif /* CONFIG_USER_ONLY */
+void qemu_semihosting_guestfd_init(void);
#endif /* SEMIHOST_H */
diff --git a/linux-user/main.c b/linux-user/main.c
index 7ca48664e4..7faf390df9 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -54,6 +54,10 @@
#include "loader.h"
#include "user-mmap.h"
+#ifdef CONFIG_SEMIHOSTING
+#include "semihosting/semihost.h"
+#endif
+
#ifndef AT_FLAGS_PRESERVE_ARGV0
#define AT_FLAGS_PRESERVE_ARGV0_BIT 0
#define AT_FLAGS_PRESERVE_ARGV0 (1 << AT_FLAGS_PRESERVE_ARGV0_BIT)
@@ -906,6 +910,11 @@ int main(int argc, char **argv, char **envp)
}
gdb_handlesig(cpu, 0);
}
+
+#ifdef CONFIG_SEMIHOSTING
+ qemu_semihosting_guestfd_init();
+#endif
+
cpu_loop(env);
/* never exits */
return 0;
diff --git a/semihosting/console.c b/semihosting/console.c
index b6a342744d..677ec2b176 100644
--- a/semihosting/console.c
+++ b/semihosting/console.c
@@ -190,4 +190,6 @@ void qemu_semihosting_console_init(Chardev *chr)
NULL, NULL, &console,
NULL, true);
}
+
+ qemu_semihosting_guestfd_init();
}
diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c
index e3122ebba9..b05c52f26f 100644
--- a/semihosting/guestfd.c
+++ b/semihosting/guestfd.c
@@ -10,15 +10,56 @@
#include "qemu/osdep.h"
#include "exec/gdbstub.h"
+#include "semihosting/semihost.h"
#include "semihosting/guestfd.h"
#ifdef CONFIG_USER_ONLY
#include "qemu.h"
#else
#include "semihosting/softmmu-uaccess.h"
+#include CONFIG_DEVICES
#endif
static GArray *guestfd_array;
+#ifdef CONFIG_ARM_COMPATIBLE_SEMIHOSTING
+GuestFD console_in_gf;
+GuestFD console_out_gf;
+#endif
+
+void qemu_semihosting_guestfd_init(void)
+{
+ /* New entries zero-initialized, i.e. type GuestFDUnused */
+ guestfd_array = g_array_new(FALSE, TRUE, sizeof(GuestFD));
+
+#ifdef CONFIG_ARM_COMPATIBLE_SEMIHOSTING
+ /* For ARM-compat, the console is in a separate namespace. */
+ if (use_gdb_syscalls()) {
+ console_in_gf.type = GuestFDGDB;
+ console_in_gf.hostfd = 0;
+ console_out_gf.type = GuestFDGDB;
+ console_out_gf.hostfd = 2;
+ } else {
+ console_in_gf.type = GuestFDConsole;
+ console_out_gf.type = GuestFDConsole;
+ }
+#else
+ /* Otherwise, the stdio file descriptors apply. */
+ guestfd_array = g_array_set_size(guestfd_array, 3);
+#ifndef CONFIG_USER_ONLY
+ if (!use_gdb_syscalls()) {
+ GuestFD *gf = &g_array_index(guestfd_array, GuestFD, 0);
+ gf[0].type = GuestFDConsole;
+ gf[1].type = GuestFDConsole;
+ gf[2].type = GuestFDConsole;
+ return;
+ }
+#endif
+ associate_guestfd(0, 0);
+ associate_guestfd(1, 1);
+ associate_guestfd(2, 2);
+#endif
+}
+
/*
* Allocate a new guest file descriptor and return it; if we
* couldn't allocate a new fd then return -1.
@@ -30,11 +71,6 @@ int alloc_guestfd(void)
{
guint i;
- if (!guestfd_array) {
- /* New entries zero-initialized, i.e. type GuestFDUnused */
- guestfd_array = g_array_new(FALSE, TRUE, sizeof(GuestFD));
- }
-
/* SYS_OPEN should return nonzero handle on success. Start guestfd from 1
*/
for (i = 1; i < guestfd_array->len; i++) {
GuestFD *gf = &g_array_index(guestfd_array, GuestFD, i);
@@ -61,11 +97,7 @@ static void do_dealloc_guestfd(GuestFD *gf)
*/
static GuestFD *do_get_guestfd(int guestfd)
{
- if (!guestfd_array) {
- return NULL;
- }
-
- if (guestfd <= 0 || guestfd >= guestfd_array->len) {
+ if (guestfd < 0 || guestfd >= guestfd_array->len) {
return NULL;
}
--
2.34.1
- [PATCH v2 28/74] semihosting: Split out semihost_sys_flen, (continued)
- [PATCH v2 28/74] semihosting: Split out semihost_sys_flen, Richard Henderson, 2022/05/03
- [PATCH v2 34/74] gdbstub: Widen gdb_syscall_complete_cb return value, Richard Henderson, 2022/05/03
- [PATCH v2 32/74] semihosting: Create semihost_sys_{stat,fstat}, Richard Henderson, 2022/05/03
- [PATCH v2 33/74] semihosting: Create semihost_sys_gettimeofday, Richard Henderson, 2022/05/03
- [PATCH v2 35/74] semihosting: Fix docs comment for qemu_semihosting_console_inc, Richard Henderson, 2022/05/03
- [PATCH v2 38/74] semihosting: Cleanup chardev init, Richard Henderson, 2022/05/03
- [PATCH v2 37/74] semihosting: Expand qemu_semihosting_console_inc to read, Richard Henderson, 2022/05/03
- [PATCH v2 36/74] semihosting: Pass CPUState to qemu_semihosting_console_inc, Richard Henderson, 2022/05/03
- [PATCH v2 39/74] semihosting: Create qemu_semihosting_console_write, Richard Henderson, 2022/05/03
- [PATCH v2 40/74] semihosting: Add GuestFDConsole, Richard Henderson, 2022/05/03
- [PATCH v2 41/74] semihosting: Create qemu_semihosting_guestfd_init,
Richard Henderson <=
- [PATCH v2 42/74] semihosting: Use console_in_gf for SYS_READC, Richard Henderson, 2022/05/03
- [PATCH v2 46/74] semihosting: Remove qemu_semihosting_console_outs, Richard Henderson, 2022/05/03
- [PATCH v2 43/74] semihosting: Use console_out_gf for SYS_WRITEC, Richard Henderson, 2022/05/03
- [PATCH v2 44/74] semihosting: Remove qemu_semihosting_console_outc, Richard Henderson, 2022/05/03
- [PATCH v2 47/74] semihosting: Create semihost_sys_poll_one, Richard Henderson, 2022/05/03
- [PATCH v2 45/74] semihosting: Use console_out_gf for SYS_WRITE0, Richard Henderson, 2022/05/03
- [PATCH v2 48/74] target/m68k: Eliminate m68k_semi_is_fseek, Richard Henderson, 2022/05/03
- [PATCH v2 55/74] target/mips: Add UHI errno values, Richard Henderson, 2022/05/03
- [PATCH v2 49/74] target/m68k: Make semihosting system only, Richard Henderson, 2022/05/03
- [PATCH v2 52/74] target/nios2: Move nios2-semi.c to nios2_softmmu_ss, Richard Henderson, 2022/05/03