mirror of https://github.com/xemu-project/xemu.git
target/arm/arm-semi: Factor out implementation of SYS_SEEK
Factor out the implementation of SYS_SEEK 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-12-peter.maydell@linaro.org
This commit is contained in:
parent
0213fa452f
commit
45e88ffc76
|
@ -389,6 +389,8 @@ typedef uint32_t sys_writefn(ARMCPU *cpu, GuestFD *gf,
|
||||||
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);
|
typedef uint32_t sys_isattyfn(ARMCPU *cpu, GuestFD *gf);
|
||||||
|
typedef uint32_t sys_seekfn(ARMCPU *cpu, GuestFD *gf,
|
||||||
|
target_ulong offset);
|
||||||
|
|
||||||
static uint32_t host_closefn(ARMCPU *cpu, GuestFD *gf)
|
static uint32_t host_closefn(ARMCPU *cpu, GuestFD *gf)
|
||||||
{
|
{
|
||||||
|
@ -442,6 +444,16 @@ static uint32_t host_isattyfn(ARMCPU *cpu, GuestFD *gf)
|
||||||
return isatty(gf->hostfd);
|
return isatty(gf->hostfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint32_t host_seekfn(ARMCPU *cpu, GuestFD *gf, target_ulong offset)
|
||||||
|
{
|
||||||
|
CPUARMState *env = &cpu->env;
|
||||||
|
uint32_t ret = set_swi_errno(env, lseek(gf->hostfd, offset, SEEK_SET));
|
||||||
|
if (ret == (uint32_t)-1) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
@ -468,11 +480,18 @@ static uint32_t gdb_isattyfn(ARMCPU *cpu, GuestFD *gf)
|
||||||
return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", gf->hostfd);
|
return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", gf->hostfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint32_t gdb_seekfn(ARMCPU *cpu, GuestFD *gf, target_ulong offset)
|
||||||
|
{
|
||||||
|
return arm_gdb_syscall(cpu, arm_semi_cb, "lseek,%x,%x,0",
|
||||||
|
gf->hostfd, offset);
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
sys_isattyfn *isattyfn;
|
||||||
|
sys_seekfn *seekfn;
|
||||||
} GuestFDFunctions;
|
} GuestFDFunctions;
|
||||||
|
|
||||||
static const GuestFDFunctions guestfd_fns[] = {
|
static const GuestFDFunctions guestfd_fns[] = {
|
||||||
|
@ -481,12 +500,14 @@ static const GuestFDFunctions guestfd_fns[] = {
|
||||||
.writefn = host_writefn,
|
.writefn = host_writefn,
|
||||||
.readfn = host_readfn,
|
.readfn = host_readfn,
|
||||||
.isattyfn = host_isattyfn,
|
.isattyfn = host_isattyfn,
|
||||||
|
.seekfn = host_seekfn,
|
||||||
},
|
},
|
||||||
[GuestFDGDB] = {
|
[GuestFDGDB] = {
|
||||||
.closefn = gdb_closefn,
|
.closefn = gdb_closefn,
|
||||||
.writefn = gdb_writefn,
|
.writefn = gdb_writefn,
|
||||||
.readfn = gdb_readfn,
|
.readfn = gdb_readfn,
|
||||||
.isattyfn = gdb_isattyfn,
|
.isattyfn = gdb_isattyfn,
|
||||||
|
.seekfn = gdb_seekfn,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -656,15 +677,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].seekfn(cpu, gf, arg1);
|
||||||
return arm_gdb_syscall(cpu, arm_semi_cb, "lseek,%x,%x,0",
|
|
||||||
gf->hostfd, arg1);
|
|
||||||
} else {
|
|
||||||
ret = set_swi_errno(env, lseek(gf->hostfd, arg1, SEEK_SET));
|
|
||||||
if (ret == (uint32_t)-1)
|
|
||||||
return -1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
case TARGET_SYS_FLEN:
|
case TARGET_SYS_FLEN:
|
||||||
GET_ARG(0);
|
GET_ARG(0);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue