semihosting: Split out semihost_sys_isatty

Split out the non-ARM specific portions of SYS_ISTTY to a
reusable function.  This handles all GuestFD.

Add a common_semi_istty_cb helper to translate the Posix
error return, 0+ENOTTY, to the Arm semihosting not-a-file
success result.

Reviewed-by: Luc Michel <lmichel@kalray.eu>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson 2022-04-28 12:31:25 -07:00
parent 9a89470449
commit a221247430
3 changed files with 53 additions and 26 deletions

View file

@ -121,6 +121,12 @@ static void gdb_lseek(CPUState *cs, gdb_syscall_complete_cb complete,
(target_ulong)gf->hostfd, off, (target_ulong)gdb_whence);
}
static void gdb_isatty(CPUState *cs, gdb_syscall_complete_cb complete,
GuestFD *gf)
{
gdb_do_syscall(complete, "isatty,%x", (target_ulong)gf->hostfd);
}
/*
* Host semihosting syscall implementations.
*/
@ -246,6 +252,13 @@ static void host_lseek(CPUState *cs, gdb_syscall_complete_cb complete,
complete(cs, ret, err);
}
static void host_isatty(CPUState *cs, gdb_syscall_complete_cb complete,
GuestFD *gf)
{
int ret = isatty(gf->hostfd);
complete(cs, ret, ret ? 0 : errno);
}
/*
* Static file semihosting syscall implementations.
*/
@ -437,3 +450,26 @@ void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete,
g_assert_not_reached();
}
}
void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete, int fd)
{
GuestFD *gf = get_guestfd(fd);
if (!gf) {
complete(cs, 0, EBADF);
return;
}
switch (gf->type) {
case GuestFDGDB:
gdb_isatty(cs, complete, gf);
break;
case GuestFDHost:
host_isatty(cs, complete, gf);
break;
case GuestFDStatic:
complete(cs, 0, ENOTTY);
break;
default:
g_assert_not_reached();
}
}