target/nios2: Eliminate nios2_semi_is_lseek

Reorg nios2_semi_return_* to gdb_syscall_complete_cb.
Use the 32-bit version normally, and the 64-bit version
for HOSTED_LSEEK.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson 2022-04-29 16:49:20 -07:00
parent 6863e92d04
commit 79cc9724c2

View File

@ -108,9 +108,12 @@ static bool translate_stat(CPUNios2State *env, target_ulong addr,
return true; return true;
} }
static void nios2_semi_return_u32(CPUNios2State *env, uint32_t ret, int err) static void nios2_semi_u32_cb(CPUState *cs, uint64_t ret, int err)
{ {
Nios2CPU *cpu = NIOS2_CPU(cs);
CPUNios2State *env = &cpu->env;
target_ulong args = env->regs[R_ARG1]; target_ulong args = env->regs[R_ARG1];
if (put_user_u32(ret, args) || if (put_user_u32(ret, args) ||
put_user_u32(err, args + 4)) { put_user_u32(err, args + 4)) {
/* /*
@ -123,9 +126,12 @@ static void nios2_semi_return_u32(CPUNios2State *env, uint32_t ret, int err)
} }
} }
static void nios2_semi_return_u64(CPUNios2State *env, uint64_t ret, int err) static void nios2_semi_u64_cb(CPUState *cs, uint64_t ret, int err)
{ {
Nios2CPU *cpu = NIOS2_CPU(cs);
CPUNios2State *env = &cpu->env;
target_ulong args = env->regs[R_ARG1]; target_ulong args = env->regs[R_ARG1];
if (put_user_u32(ret >> 32, args) || if (put_user_u32(ret >> 32, args) ||
put_user_u32(ret, args + 4) || put_user_u32(ret, args + 4) ||
put_user_u32(err, args + 8)) { put_user_u32(err, args + 8)) {
@ -135,25 +141,6 @@ static void nios2_semi_return_u64(CPUNios2State *env, uint64_t ret, int err)
} }
} }
static int nios2_semi_is_lseek;
static void nios2_semi_cb(CPUState *cs, uint64_t ret, int err)
{
Nios2CPU *cpu = NIOS2_CPU(cs);
CPUNios2State *env = &cpu->env;
if (nios2_semi_is_lseek) {
/*
* FIXME: We've already lost the high bits of the lseek
* return value.
*/
nios2_semi_return_u64(env, ret, err);
nios2_semi_is_lseek = 0;
} else {
nios2_semi_return_u32(env, ret, err);
}
}
/* /*
* Read the input value from the argument block; fail the semihosting * Read the input value from the argument block; fail the semihosting
* call if the memory read fails. * call if the memory read fails.
@ -168,6 +155,7 @@ static void nios2_semi_cb(CPUState *cs, uint64_t ret, int err)
void do_nios2_semihosting(CPUNios2State *env) void do_nios2_semihosting(CPUNios2State *env)
{ {
CPUState *cs = env_cpu(env);
int nr; int nr;
uint32_t args; uint32_t args;
target_ulong arg0, arg1, arg2, arg3; target_ulong arg0, arg1, arg2, arg3;
@ -188,7 +176,7 @@ void do_nios2_semihosting(CPUNios2State *env)
GET_ARG(2); GET_ARG(2);
GET_ARG(3); GET_ARG(3);
if (use_gdb_syscalls()) { if (use_gdb_syscalls()) {
gdb_do_syscall(nios2_semi_cb, "open,%s,%x,%x", arg0, (int)arg1, gdb_do_syscall(nios2_semi_u32_cb, "open,%s,%x,%x", arg0, (int)arg1,
arg2, arg3); arg2, arg3);
return; return;
} else { } else {
@ -209,7 +197,7 @@ void do_nios2_semihosting(CPUNios2State *env)
int fd = arg0; int fd = arg0;
if (fd > 2) { if (fd > 2) {
if (use_gdb_syscalls()) { if (use_gdb_syscalls()) {
gdb_do_syscall(nios2_semi_cb, "close,%x", arg0); gdb_do_syscall(nios2_semi_u32_cb, "close,%x", arg0);
return; return;
} else { } else {
result = close(fd); result = close(fd);
@ -225,7 +213,7 @@ void do_nios2_semihosting(CPUNios2State *env)
GET_ARG(2); GET_ARG(2);
len = arg2; len = arg2;
if (use_gdb_syscalls()) { if (use_gdb_syscalls()) {
gdb_do_syscall(nios2_semi_cb, "read,%x,%x,%x", gdb_do_syscall(nios2_semi_u32_cb, "read,%x,%x,%x",
arg0, arg1, len); arg0, arg1, len);
return; return;
} else { } else {
@ -245,7 +233,7 @@ void do_nios2_semihosting(CPUNios2State *env)
GET_ARG(2); GET_ARG(2);
len = arg2; len = arg2;
if (use_gdb_syscalls()) { if (use_gdb_syscalls()) {
gdb_do_syscall(nios2_semi_cb, "write,%x,%x,%x", gdb_do_syscall(nios2_semi_u32_cb, "write,%x,%x,%x",
arg0, arg1, len); arg0, arg1, len);
return; return;
} else { } else {
@ -268,12 +256,11 @@ void do_nios2_semihosting(CPUNios2State *env)
GET_ARG(3); GET_ARG(3);
off = (uint32_t)arg2 | ((uint64_t)arg1 << 32); off = (uint32_t)arg2 | ((uint64_t)arg1 << 32);
if (use_gdb_syscalls()) { if (use_gdb_syscalls()) {
nios2_semi_is_lseek = 1; gdb_do_syscall(nios2_semi_u64_cb, "lseek,%x,%lx,%x",
gdb_do_syscall(nios2_semi_cb, "lseek,%x,%lx,%x",
arg0, off, arg3); arg0, off, arg3);
} else { } else {
off = lseek(arg0, off, arg3); off = lseek(arg0, off, arg3);
nios2_semi_return_u64(env, off, errno); nios2_semi_u64_cb(cs, off, errno);
} }
return; return;
} }
@ -283,7 +270,7 @@ void do_nios2_semihosting(CPUNios2State *env)
GET_ARG(2); GET_ARG(2);
GET_ARG(3); GET_ARG(3);
if (use_gdb_syscalls()) { if (use_gdb_syscalls()) {
gdb_do_syscall(nios2_semi_cb, "rename,%s,%s", gdb_do_syscall(nios2_semi_u32_cb, "rename,%s,%s",
arg0, (int)arg1, arg2, (int)arg3); arg0, (int)arg1, arg2, (int)arg3);
return; return;
} else { } else {
@ -303,7 +290,7 @@ void do_nios2_semihosting(CPUNios2State *env)
GET_ARG(0); GET_ARG(0);
GET_ARG(1); GET_ARG(1);
if (use_gdb_syscalls()) { if (use_gdb_syscalls()) {
gdb_do_syscall(nios2_semi_cb, "unlink,%s", gdb_do_syscall(nios2_semi_u32_cb, "unlink,%s",
arg0, (int)arg1); arg0, (int)arg1);
return; return;
} else { } else {
@ -322,7 +309,7 @@ void do_nios2_semihosting(CPUNios2State *env)
GET_ARG(1); GET_ARG(1);
GET_ARG(2); GET_ARG(2);
if (use_gdb_syscalls()) { if (use_gdb_syscalls()) {
gdb_do_syscall(nios2_semi_cb, "stat,%s,%x", gdb_do_syscall(nios2_semi_u32_cb, "stat,%s,%x",
arg0, (int)arg1, arg2); arg0, (int)arg1, arg2);
return; return;
} else { } else {
@ -345,7 +332,7 @@ void do_nios2_semihosting(CPUNios2State *env)
GET_ARG(0); GET_ARG(0);
GET_ARG(1); GET_ARG(1);
if (use_gdb_syscalls()) { if (use_gdb_syscalls()) {
gdb_do_syscall(nios2_semi_cb, "fstat,%x,%x", gdb_do_syscall(nios2_semi_u32_cb, "fstat,%x,%x",
arg0, arg1); arg0, arg1);
return; return;
} else { } else {
@ -361,7 +348,7 @@ void do_nios2_semihosting(CPUNios2State *env)
/* Only the tv parameter is used. tz is assumed NULL. */ /* Only the tv parameter is used. tz is assumed NULL. */
GET_ARG(0); GET_ARG(0);
if (use_gdb_syscalls()) { if (use_gdb_syscalls()) {
gdb_do_syscall(nios2_semi_cb, "gettimeofday,%x,%x", gdb_do_syscall(nios2_semi_u32_cb, "gettimeofday,%x,%x",
arg0, 0); arg0, 0);
return; return;
} else { } else {
@ -382,7 +369,7 @@ void do_nios2_semihosting(CPUNios2State *env)
case HOSTED_ISATTY: case HOSTED_ISATTY:
GET_ARG(0); GET_ARG(0);
if (use_gdb_syscalls()) { if (use_gdb_syscalls()) {
gdb_do_syscall(nios2_semi_cb, "isatty,%x", arg0); gdb_do_syscall(nios2_semi_u32_cb, "isatty,%x", arg0);
return; return;
} else { } else {
result = isatty(arg0); result = isatty(arg0);
@ -392,7 +379,7 @@ void do_nios2_semihosting(CPUNios2State *env)
GET_ARG(0); GET_ARG(0);
GET_ARG(1); GET_ARG(1);
if (use_gdb_syscalls()) { if (use_gdb_syscalls()) {
gdb_do_syscall(nios2_semi_cb, "system,%s", gdb_do_syscall(nios2_semi_u32_cb, "system,%s",
arg0, (int)arg1); arg0, (int)arg1);
return; return;
} else { } else {
@ -412,5 +399,5 @@ void do_nios2_semihosting(CPUNios2State *env)
result = 0; result = 0;
} }
failed: failed:
nios2_semi_return_u32(env, result, errno); nios2_semi_u32_cb(cs, result, errno);
} }