aboutsummaryrefslogtreecommitdiff
path: root/semihosting
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2022-05-01 17:21:00 -0700
committerRichard Henderson <richard.henderson@linaro.org>2022-06-28 04:36:50 +0530
commite4a4aaa51b4c71914a6f30ca504ab78e8f695aee (patch)
treeb36e1de06b9d0165a59f06d284808ef546e725eb /semihosting
parent008e147572863a7a54c54403e626aaed3e50574f (diff)
semihosting: Create qemu_semihosting_guestfd_init
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. Reviewed-by: Luc Michel <lmichel@kalray.eu> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'semihosting')
-rw-r--r--semihosting/console.c2
-rw-r--r--semihosting/guestfd.c52
2 files changed, 44 insertions, 10 deletions
diff --git a/semihosting/console.c b/semihosting/console.c
index 540aa0cd4b..955880514e 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;
}