target/arm/arm-semi: Factor out implementation of SYS_ISTTY
Factor out the implementation of SYS_ISTTY via the new function tables. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-id: 20190916141544.17540-11-peter.maydell@linaro.org
This commit is contained in:
parent
2c3a09a620
commit
0213fa452f
|
@ -388,6 +388,7 @@ typedef uint32_t sys_writefn(ARMCPU *cpu, GuestFD *gf,
|
||||||
target_ulong buf, uint32_t len);
|
target_ulong buf, uint32_t len);
|
||||||
typedef uint32_t sys_readfn(ARMCPU *cpu, GuestFD *gf,
|
typedef uint32_t sys_readfn(ARMCPU *cpu, GuestFD *gf,
|
||||||
target_ulong buf, uint32_t len);
|
target_ulong buf, uint32_t len);
|
||||||
|
typedef uint32_t sys_isattyfn(ARMCPU *cpu, GuestFD *gf);
|
||||||
|
|
||||||
static uint32_t host_closefn(ARMCPU *cpu, GuestFD *gf)
|
static uint32_t host_closefn(ARMCPU *cpu, GuestFD *gf)
|
||||||
{
|
{
|
||||||
|
@ -436,6 +437,11 @@ static uint32_t host_readfn(ARMCPU *cpu, GuestFD *gf,
|
||||||
return len - ret;
|
return len - ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint32_t host_isattyfn(ARMCPU *cpu, GuestFD *gf)
|
||||||
|
{
|
||||||
|
return isatty(gf->hostfd);
|
||||||
|
}
|
||||||
|
|
||||||
static uint32_t gdb_closefn(ARMCPU *cpu, GuestFD *gf)
|
static uint32_t gdb_closefn(ARMCPU *cpu, GuestFD *gf)
|
||||||
{
|
{
|
||||||
return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd);
|
return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd);
|
||||||
|
@ -457,10 +463,16 @@ static uint32_t gdb_readfn(ARMCPU *cpu, GuestFD *gf,
|
||||||
gf->hostfd, buf, len);
|
gf->hostfd, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint32_t gdb_isattyfn(ARMCPU *cpu, GuestFD *gf)
|
||||||
|
{
|
||||||
|
return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", gf->hostfd);
|
||||||
|
}
|
||||||
|
|
||||||
typedef struct GuestFDFunctions {
|
typedef struct GuestFDFunctions {
|
||||||
sys_closefn *closefn;
|
sys_closefn *closefn;
|
||||||
sys_writefn *writefn;
|
sys_writefn *writefn;
|
||||||
sys_readfn *readfn;
|
sys_readfn *readfn;
|
||||||
|
sys_isattyfn *isattyfn;
|
||||||
} GuestFDFunctions;
|
} GuestFDFunctions;
|
||||||
|
|
||||||
static const GuestFDFunctions guestfd_fns[] = {
|
static const GuestFDFunctions guestfd_fns[] = {
|
||||||
|
@ -468,11 +480,13 @@ static const GuestFDFunctions guestfd_fns[] = {
|
||||||
.closefn = host_closefn,
|
.closefn = host_closefn,
|
||||||
.writefn = host_writefn,
|
.writefn = host_writefn,
|
||||||
.readfn = host_readfn,
|
.readfn = host_readfn,
|
||||||
|
.isattyfn = host_isattyfn,
|
||||||
},
|
},
|
||||||
[GuestFDGDB] = {
|
[GuestFDGDB] = {
|
||||||
.closefn = gdb_closefn,
|
.closefn = gdb_closefn,
|
||||||
.writefn = gdb_writefn,
|
.writefn = gdb_writefn,
|
||||||
.readfn = gdb_readfn,
|
.readfn = gdb_readfn,
|
||||||
|
.isattyfn = gdb_isattyfn,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -631,11 +645,7 @@ target_ulong do_arm_semihosting(CPUARMState *env)
|
||||||
return set_swi_errno(env, -1);
|
return set_swi_errno(env, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (use_gdb_syscalls()) {
|
return guestfd_fns[gf->type].isattyfn(cpu, gf);
|
||||||
return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", gf->hostfd);
|
|
||||||
} else {
|
|
||||||
return isatty(gf->hostfd);
|
|
||||||
}
|
|
||||||
case TARGET_SYS_SEEK:
|
case TARGET_SYS_SEEK:
|
||||||
GET_ARG(0);
|
GET_ARG(0);
|
||||||
GET_ARG(1);
|
GET_ARG(1);
|
||||||
|
|
Loading…
Reference in a new issue