diff mbox

[05/10] mips-linux-user: Fix n32 and n64 syscalls

Message ID 1360521050-29680-6-git-send-email-rth@twiddle.net
State New
Headers show

Commit Message

Richard Henderson Feb. 10, 2013, 6:30 p.m. UTC
Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 linux-user/main.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

Comments

Richard Henderson Feb. 11, 2013, 4:07 p.m. UTC | #1
On 2013-02-10 10:30, Richard Henderson wrote:
> Signed-off-by: Richard Henderson<rth@twiddle.net>
> ---
>   linux-user/main.c | 25 ++++++++++++++++++-------
>   1 file changed, 18 insertions(+), 7 deletions(-)

n32/n64 have different argument registers from o32.

In addition, use abi_long properly instead of the
host unsigned int for errno detection.


r~
Peter Maydell Feb. 11, 2013, 5:33 p.m. UTC | #2
On 10 February 2013 18:30, Richard Henderson <rth@twiddle.net> wrote:
> Signed-off-by: Richard Henderson <rth@twiddle.net>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

> -            if ((unsigned int)ret >= (unsigned int)(-1133)) {
> +            if ((abi_ulong)ret >= (abi_ulong)-1133) {
>                  env->active_tc.gpr[7] = 1; /* error flag */
>                  ret = -ret;
>              } else {

You're only changing the cast here, so this isn't something you
should feel the need to fix in this patch, but do you know what's
special about -1133 ?

-- PMM
Richard Henderson Feb. 11, 2013, 5:51 p.m. UTC | #3
On 2013-02-11 09:33, Peter Maydell wrote:
> You're only changing the cast here, so this isn't something you
> should feel the need to fix in this patch, but do you know what's
> special about -1133 ?

It does correspond to the kernel code.  C.f. EMAXERRNO.


r~
Peter Maydell Feb. 11, 2013, 6:01 p.m. UTC | #4
On 11 February 2013 17:51, Richard Henderson <rth@twiddle.net> wrote:
> On 2013-02-11 09:33, Peter Maydell wrote:
>> You're only changing the cast here, so this isn't something you
>> should feel the need to fix in this patch, but do you know what's
>> special about -1133 ?
>
> It does correspond to the kernel code.  C.f. EMAXERRNO.

Ah yes, so it does. We should probably have linux-user/mips/syscall.h
define a TARGET_EMAXERRNO so we can use it here, but as I say that's
not a job for this patch.

-- PMM
diff mbox

Patch

diff --git a/linux-user/main.c b/linux-user/main.c
index 3df8aa2..3a3be70 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -1783,8 +1783,8 @@  void cpu_loop(CPUPPCState *env)
 
 #ifdef TARGET_MIPS
 
-#define MIPS_SYS(name, args) args,
-
+# ifdef TARGET_ABI_MIPSO32
+#  define MIPS_SYS(name, args) args,
 static const uint8_t mips_syscall_args[] = {
 	MIPS_SYS(sys_syscall	, 8)	/* 4000 */
 	MIPS_SYS(sys_exit	, 1)
@@ -2130,8 +2130,8 @@  static const uint8_t mips_syscall_args[] = {
         MIPS_SYS(sys_clock_adjtime, 2)
         MIPS_SYS(sys_syncfs, 1)
 };
-
-#undef MIPS_SYS
+#  undef MIPS_SYS
+# endif /* O32 */
 
 static int do_store_exclusive(CPUMIPSState *env)
 {
@@ -2185,8 +2185,11 @@  static int do_store_exclusive(CPUMIPSState *env)
 void cpu_loop(CPUMIPSState *env)
 {
     target_siginfo_t info;
-    int trapnr, ret;
+    int trapnr;
+    abi_long ret;
+# ifdef TARGET_ABI_MIPSO32
     unsigned int syscall_num;
+# endif
 
     for(;;) {
         cpu_exec_start(env);
@@ -2194,8 +2197,9 @@  void cpu_loop(CPUMIPSState *env)
         cpu_exec_end(env);
         switch(trapnr) {
         case EXCP_SYSCALL:
-            syscall_num = env->active_tc.gpr[2] - 4000;
             env->active_tc.PC += 4;
+# ifdef TARGET_ABI_MIPSO32
+            syscall_num = env->active_tc.gpr[2] - 4000;
             if (syscall_num >= sizeof(mips_syscall_args)) {
                 ret = -TARGET_ENOSYS;
             } else {
@@ -2234,12 +2238,19 @@  void cpu_loop(CPUMIPSState *env)
                                  arg5, arg6, arg7, arg8);
             }
 done_syscall:
+# else
+            ret = do_syscall(env, env->active_tc.gpr[2],
+                             env->active_tc.gpr[4], env->active_tc.gpr[5],
+                             env->active_tc.gpr[6], env->active_tc.gpr[7],
+                             env->active_tc.gpr[8], env->active_tc.gpr[9],
+                             env->active_tc.gpr[10], env->active_tc.gpr[11]);
+# endif /* O32 */
             if (ret == -TARGET_QEMU_ESIGRETURN) {
                 /* Returning from a successful sigreturn syscall.
                    Avoid clobbering register state.  */
                 break;
             }
-            if ((unsigned int)ret >= (unsigned int)(-1133)) {
+            if ((abi_ulong)ret >= (abi_ulong)-1133) {
                 env->active_tc.gpr[7] = 1; /* error flag */
                 ret = -ret;
             } else {