@@ -108,9 +108,12 @@ static bool translate_stat(CPUNios2State *env, target_ulong addr,
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];
+
if (put_user_u32(ret, args) ||
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];
+
if (put_user_u32(ret >> 32, args) ||
put_user_u32(ret, args + 4) ||
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
* 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)
{
+ CPUState *cs = env_cpu(env);
int nr;
uint32_t args;
target_ulong arg0, arg1, arg2, arg3;
@@ -188,7 +176,7 @@ void do_nios2_semihosting(CPUNios2State *env)
GET_ARG(2);
GET_ARG(3);
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);
return;
} else {
@@ -209,7 +197,7 @@ void do_nios2_semihosting(CPUNios2State *env)
int fd = arg0;
if (fd > 2) {
if (use_gdb_syscalls()) {
- gdb_do_syscall(nios2_semi_cb, "close,%x", arg0);
+ gdb_do_syscall(nios2_semi_u32_cb, "close,%x", arg0);
return;
} else {
result = close(fd);
@@ -225,7 +213,7 @@ void do_nios2_semihosting(CPUNios2State *env)
GET_ARG(2);
len = arg2;
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);
return;
} else {
@@ -245,7 +233,7 @@ void do_nios2_semihosting(CPUNios2State *env)
GET_ARG(2);
len = arg2;
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);
return;
} else {
@@ -268,12 +256,11 @@ void do_nios2_semihosting(CPUNios2State *env)
GET_ARG(3);
off = (uint32_t)arg2 | ((uint64_t)arg1 << 32);
if (use_gdb_syscalls()) {
- nios2_semi_is_lseek = 1;
- gdb_do_syscall(nios2_semi_cb, "lseek,%x,%lx,%x",
+ gdb_do_syscall(nios2_semi_u64_cb, "lseek,%x,%lx,%x",
arg0, off, arg3);
} else {
off = lseek(arg0, off, arg3);
- nios2_semi_return_u64(env, off, errno);
+ nios2_semi_u64_cb(cs, off, errno);
}
return;
}
@@ -283,7 +270,7 @@ void do_nios2_semihosting(CPUNios2State *env)
GET_ARG(2);
GET_ARG(3);
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);
return;
} else {
@@ -303,7 +290,7 @@ void do_nios2_semihosting(CPUNios2State *env)
GET_ARG(0);
GET_ARG(1);
if (use_gdb_syscalls()) {
- gdb_do_syscall(nios2_semi_cb, "unlink,%s",
+ gdb_do_syscall(nios2_semi_u32_cb, "unlink,%s",
arg0, (int)arg1);
return;
} else {
@@ -322,7 +309,7 @@ void do_nios2_semihosting(CPUNios2State *env)
GET_ARG(1);
GET_ARG(2);
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);
return;
} else {
@@ -345,7 +332,7 @@ void do_nios2_semihosting(CPUNios2State *env)
GET_ARG(0);
GET_ARG(1);
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);
return;
} else {
@@ -361,7 +348,7 @@ void do_nios2_semihosting(CPUNios2State *env)
/* Only the tv parameter is used. tz is assumed NULL. */
GET_ARG(0);
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);
return;
} else {
@@ -382,7 +369,7 @@ void do_nios2_semihosting(CPUNios2State *env)
case HOSTED_ISATTY:
GET_ARG(0);
if (use_gdb_syscalls()) {
- gdb_do_syscall(nios2_semi_cb, "isatty,%x", arg0);
+ gdb_do_syscall(nios2_semi_u32_cb, "isatty,%x", arg0);
return;
} else {
result = isatty(arg0);
@@ -392,7 +379,7 @@ void do_nios2_semihosting(CPUNios2State *env)
GET_ARG(0);
GET_ARG(1);
if (use_gdb_syscalls()) {
- gdb_do_syscall(nios2_semi_cb, "system,%s",
+ gdb_do_syscall(nios2_semi_u32_cb, "system,%s",
arg0, (int)arg1);
return;
} else {
@@ -412,5 +399,5 @@ void do_nios2_semihosting(CPUNios2State *env)
result = 0;
}
failed:
- nios2_semi_return_u32(env, result, errno);
+ nios2_semi_u32_cb(cs, result, errno);
}
Reorg nios2_semi_return_* to gdb_syscall_complete_cb. Use the 32-bit version normally, and the 64-bit version for HOSTED_LSEEK. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> --- target/nios2/nios2-semi.c | 59 +++++++++++++++------------------------ 1 file changed, 23 insertions(+), 36 deletions(-)