summary refs log tree commit diff stats
path: root/semihosting/console.c
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2022-05-02 11:15:40 -0700
committerRichard Henderson <richard.henderson@linaro.org>2022-06-28 04:41:37 +0530
commit1b9177f7495086f1595d7c989c810013f1c9eb5a (patch)
tree41469c64b92e70a3b352c170d28cedc590e09dcc /semihosting/console.c
parent2d010c2719da360d44a5c44d279d49eca21c5de8 (diff)
downloadfocaccia-qemu-1b9177f7495086f1595d7c989c810013f1c9eb5a.tar.gz
focaccia-qemu-1b9177f7495086f1595d7c989c810013f1c9eb5a.zip
semihosting: Create semihost_sys_poll_one
This will be used for implementing the xtensa select_one
system call.  Choose "poll" over "select" so that we can
reuse Glib's g_poll constants and to avoid struct timeval.

Reviewed-by: Luc Michel <lmichel@kalray.eu>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'semihosting/console.c')
-rw-r--r--semihosting/console.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/semihosting/console.c b/semihosting/console.c
index c84ab97ab6..cda7cf1905 100644
--- a/semihosting/console.c
+++ b/semihosting/console.c
@@ -77,10 +77,17 @@ static void console_read(void *opaque, const uint8_t *buf, int size)
     c->sleeping_cpus = NULL;
 }
 
-int qemu_semihosting_console_read(CPUState *cs, void *buf, int len)
+bool qemu_semihosting_console_ready(void)
+{
+    SemihostingConsole *c = &console;
+
+    g_assert(qemu_mutex_iothread_locked());
+    return !fifo8_is_empty(&c->fifo);
+}
+
+void qemu_semihosting_console_block_until_ready(CPUState *cs)
 {
     SemihostingConsole *c = &console;
-    int ret = 0;
 
     g_assert(qemu_mutex_iothread_locked());
 
@@ -92,6 +99,14 @@ int qemu_semihosting_console_read(CPUState *cs, void *buf, int len)
         cpu_loop_exit(cs);
         /* never returns */
     }
+}
+
+int qemu_semihosting_console_read(CPUState *cs, void *buf, int len)
+{
+    SemihostingConsole *c = &console;
+    int ret = 0;
+
+    qemu_semihosting_console_block_until_ready(cs);
 
     /* Read until buffer full or fifo exhausted. */
     do {