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:
Richard Henderson 2022-05-01 12:31:08 -07:00
parent 3367d452b0
commit e7fb6f3205
4 changed files with 34 additions and 15 deletions

View file

@ -56,21 +56,23 @@ void qemu_semihosting_console_outc(CPUArchState *env, target_ulong addr)
* program is expecting more normal behaviour. This is slow but
* nothing using semihosting console reading is expecting to be fast.
*/
target_ulong qemu_semihosting_console_inc(CPUState *cs)
int qemu_semihosting_console_read(CPUState *cs, void *buf, int len)
{
uint8_t c;
int ret;
struct termios old_tio, new_tio;
/* Disable line-buffering and echo */
tcgetattr(STDIN_FILENO, &old_tio);
new_tio = old_tio;
new_tio.c_lflag &= (~ICANON & ~ECHO);
new_tio.c_cc[VMIN] = 1;
new_tio.c_cc[VTIME] = 0;
tcsetattr(STDIN_FILENO, TCSANOW, &new_tio);
c = getchar();
ret = fread(buf, 1, len, stdin);
/* restore config */
tcsetattr(STDIN_FILENO, TCSANOW, &old_tio);
return (target_ulong) c;
return ret;
}