mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 00:03:54 -06:00
semihosting: Split out semihost_sys_flen
The ARM-specific SYS_FLEN isn't really something that can be reused by other semihosting apis, but there are parts that can reused for the implementation of semihost_sys_fstat. Reviewed-by: Luc Michel <lmichel@kalray.eu> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
parent
a221247430
commit
a6300ed6b7
3 changed files with 66 additions and 61 deletions
|
@ -127,6 +127,12 @@ static void gdb_isatty(CPUState *cs, gdb_syscall_complete_cb complete,
|
|||
gdb_do_syscall(complete, "isatty,%x", (target_ulong)gf->hostfd);
|
||||
}
|
||||
|
||||
static void gdb_fstat(CPUState *cs, gdb_syscall_complete_cb complete,
|
||||
GuestFD *gf, target_ulong addr)
|
||||
{
|
||||
gdb_do_syscall(complete, "fstat,%x,%x", (target_ulong)gf->hostfd, addr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Host semihosting syscall implementations.
|
||||
*/
|
||||
|
@ -259,6 +265,18 @@ static void host_isatty(CPUState *cs, gdb_syscall_complete_cb complete,
|
|||
complete(cs, ret, ret ? 0 : errno);
|
||||
}
|
||||
|
||||
static void host_flen(CPUState *cs, gdb_syscall_complete_cb complete,
|
||||
GuestFD *gf)
|
||||
{
|
||||
struct stat buf;
|
||||
|
||||
if (fstat(gf->hostfd, &buf) < 0) {
|
||||
complete(cs, -1, errno);
|
||||
} else {
|
||||
complete(cs, buf.st_size, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Static file semihosting syscall implementations.
|
||||
*/
|
||||
|
@ -311,6 +329,12 @@ static void staticfile_lseek(CPUState *cs, gdb_syscall_complete_cb complete,
|
|||
}
|
||||
}
|
||||
|
||||
static void staticfile_flen(CPUState *cs, gdb_syscall_complete_cb complete,
|
||||
GuestFD *gf)
|
||||
{
|
||||
complete(cs, gf->staticfile.len, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Syscall entry points.
|
||||
*/
|
||||
|
@ -473,3 +497,28 @@ void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete, int fd)
|
|||
g_assert_not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb,
|
||||
gdb_syscall_complete_cb flen_cb, int fd,
|
||||
target_ulong fstat_addr)
|
||||
{
|
||||
GuestFD *gf = get_guestfd(fd);
|
||||
|
||||
if (!gf) {
|
||||
flen_cb(cs, -1, EBADF);
|
||||
return;
|
||||
}
|
||||
switch (gf->type) {
|
||||
case GuestFDGDB:
|
||||
gdb_fstat(cs, fstat_cb, gf, fstat_addr);
|
||||
break;
|
||||
case GuestFDHost:
|
||||
host_flen(cs, flen_cb, gf);
|
||||
break;
|
||||
case GuestFDStatic:
|
||||
staticfile_flen(cs, flen_cb, gf);
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue