mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-26 20:03:54 -06:00
semihosting: Expand qemu_semihosting_console_inc to read
Allow more than one character to be read at one time. Will be used by m68k and nios2 semihosting for stdio. Reviewed-by: Luc Michel <lmichel@kalray.eu> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
parent
3367d452b0
commit
e7fb6f3205
4 changed files with 34 additions and 15 deletions
|
@ -144,12 +144,14 @@ static void console_read(void *opaque, const uint8_t *buf, int size)
|
|||
c->sleeping_cpus = NULL;
|
||||
}
|
||||
|
||||
target_ulong qemu_semihosting_console_inc(CPUState *cs)
|
||||
int qemu_semihosting_console_read(CPUState *cs, void *buf, int len)
|
||||
{
|
||||
uint8_t ch;
|
||||
SemihostingConsole *c = &console;
|
||||
int ret = 0;
|
||||
|
||||
g_assert(qemu_mutex_iothread_locked());
|
||||
|
||||
/* Block if the fifo is completely empty. */
|
||||
if (fifo8_is_empty(&c->fifo)) {
|
||||
c->sleeping_cpus = g_slist_prepend(c->sleeping_cpus, cs);
|
||||
cs->halted = 1;
|
||||
|
@ -157,8 +159,14 @@ target_ulong qemu_semihosting_console_inc(CPUState *cs)
|
|||
cpu_loop_exit(cs);
|
||||
/* never returns */
|
||||
}
|
||||
ch = fifo8_pop(&c->fifo);
|
||||
return (target_ulong) ch;
|
||||
|
||||
/* Read until buffer full or fifo exhausted. */
|
||||
do {
|
||||
*(char *)(buf + ret) = fifo8_pop(&c->fifo);
|
||||
ret++;
|
||||
} while (ret < len && !fifo8_is_empty(&c->fifo));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void qemu_semihosting_console_init(void)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue