sim: m32r: namespace Linux syscall table
[binutils-gdb.git] / sim / m32r / traps-linux.c
index ec95a6854d4a5e2f40a2c866f8f2aeddd3e0738f..d60be7ca54b92c7dd731165b72d298e04699b12b 100644 (file)
@@ -1,5 +1,5 @@
 /* m32r exception, interrupt, and trap (EIT) support
-   Copyright (C) 1998, 2003, 2007, 2008, 2009 Free Software Foundation, Inc.
+   Copyright (C) 1998-2021 Free Software Foundation, Inc.
    Contributed by Renesas.
 
    This file is part of GDB, the GNU debugger.
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
+#include "portability.h"
 #include "sim-main.h"
+#include "sim-signal.h"
+#include "sim-syscall.h"
+#include "sim/callback.h"
 #include "syscall.h"
 #include "targ-vals.h"
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <stdlib.h>
 #include <time.h>
 #include <unistd.h>
 #include <utime.h>
@@ -113,35 +121,12 @@ m32r_core_signal (SIM_DESC sd, SIM_CPU *current_cpu, sim_cia cia,
                      transfer, sig);
 }
 \f
-/* Read/write functions for system call interface.  */
-
-static int
-syscall_read_mem (host_callback *cb, struct cb_syscall *sc,
-                 unsigned long taddr, char *buf, int bytes)
-{
-  SIM_DESC sd = (SIM_DESC) sc->p1;
-  SIM_CPU *cpu = (SIM_CPU *) sc->p2;
-
-  return sim_core_read_buffer (sd, cpu, read_map, buf, taddr, bytes);
-}
-
-static int
-syscall_write_mem (host_callback *cb, struct cb_syscall *sc,
-                  unsigned long taddr, const char *buf, int bytes)
-{
-  SIM_DESC sd = (SIM_DESC) sc->p1;
-  SIM_CPU *cpu = (SIM_CPU *) sc->p2;
-
-  return sim_core_write_buffer (sd, cpu, write_map, buf, taddr, bytes);
-}
-
 /* Translate target's address to host's address.  */
 
 static void *
 t2h_addr (host_callback *cb, struct cb_syscall *sc,
           unsigned long taddr)
 {
-  extern sim_core_trans_addr (SIM_DESC, sim_cpu *, unsigned, address_word);
   void *addr;
   SIM_DESC sd = (SIM_DESC) sc->p1;
   SIM_CPU *cpu = (SIM_CPU *) sc->p2;
@@ -158,7 +143,7 @@ conv_endian (unsigned int tvalue)
   unsigned int hvalue;
   unsigned int t1, t2, t3, t4;
 
-  if (CURRENT_HOST_BYTE_ORDER == LITTLE_ENDIAN)
+  if (HOST_BYTE_ORDER == BFD_ENDIAN_LITTLE)
     {
       t1 = tvalue & 0xff000000;
       t2 = tvalue & 0x00ff0000;
@@ -182,7 +167,7 @@ conv_endian16 (unsigned short tvalue)
   unsigned short hvalue;
   unsigned short t1, t2;
 
-  if (CURRENT_HOST_BYTE_ORDER == LITTLE_ENDIAN)
+  if (HOST_BYTE_ORDER == BFD_ENDIAN_LITTLE)
     {
       t1 = tvalue & 0xff00;
       t2 = tvalue & 0x00ff;
@@ -219,44 +204,25 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
   SIM_DESC sd = CPU_STATE (current_cpu);
   host_callback *cb = STATE_CALLBACK (sd);
 
-#ifdef SIM_HAVE_BREAKPOINTS
-  /* Check for breakpoints "owned" by the simulator first, regardless
-     of --environment.  */
-  if (num == TRAP_BREAKPOINT)
-    {
-      /* First try sim-break.c.  If it's a breakpoint the simulator "owns"
-        it doesn't return.  Otherwise it returns and let's us try.  */
-      sim_handle_breakpoint (sd, current_cpu, pc);
-      /* Fall through.  */
-    }
-#endif
-
   switch (num)
     {
     case TRAP_ELF_SYSCALL :
       {
-        CB_SYSCALL s;
-        CB_SYSCALL_INIT (&s);
-        s.func = m32rbf_h_gr_get (current_cpu, 0);
-        s.arg1 = m32rbf_h_gr_get (current_cpu, 1);
-        s.arg2 = m32rbf_h_gr_get (current_cpu, 2);
-        s.arg3 = m32rbf_h_gr_get (current_cpu, 3);
-        if (s.func == TARGET_SYS_exit)
-          {
-            sim_engine_halt (sd, current_cpu, NULL, pc, sim_exited, s.arg1);
-          }
-        s.p1 = (PTR) sd;
-        s.p2 = (PTR) current_cpu;
-        s.read_mem = syscall_read_mem;
-        s.write_mem = syscall_write_mem;
-        cb_syscall (cb, &s);
-        m32rbf_h_gr_set (current_cpu, 2, s.errcode);
-        m32rbf_h_gr_set (current_cpu, 0, s.result);
-        m32rbf_h_gr_set (current_cpu, 1, s.result2);
-        break;
+       long result, result2;
+       int errcode;
+
+       sim_syscall_multi (current_cpu,
+                          m32rbf_h_gr_get (current_cpu, 0),
+                          m32rbf_h_gr_get (current_cpu, 1),
+                          m32rbf_h_gr_get (current_cpu, 2),
+                          m32rbf_h_gr_get (current_cpu, 3),
+                          m32rbf_h_gr_get (current_cpu, 4),
+                          &result, &result2, &errcode);
+
+       m32rbf_h_gr_set (current_cpu, 2, errcode);
+       m32rbf_h_gr_set (current_cpu, 0, result);
+       m32rbf_h_gr_set (current_cpu, 1, result2);
+       break;
       }
 
     case TRAP_LINUX_SYSCALL :
@@ -288,11 +254,15 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
         s.arg1 = arg1;
         s.arg2 = arg2;
         s.arg3 = arg3;
+        s.arg4 = arg4;
+        s.arg5 = arg5;
+        s.arg6 = arg6;
+        s.arg7 = arg7;
 
         s.p1 = (PTR) sd;
         s.p2 = (PTR) current_cpu;
-        s.read_mem = syscall_read_mem;
-        s.write_mem = syscall_write_mem;
+        s.read_mem = sim_syscall_read_mem;
+        s.write_mem = sim_syscall_write_mem;
 
         result = 0;
         result2 = 0;
@@ -300,52 +270,52 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
 
         switch (func)
           {
-          case __NR_exit:
+          case TARGET_LINUX_SYS_exit:
            sim_engine_halt (sd, current_cpu, NULL, pc, sim_exited, arg1);
             break;
 
-          case __NR_read:
+          case TARGET_LINUX_SYS_read:
             result = read(arg1, t2h_addr(cb, &s, arg2), arg3);
             errcode = errno;
             break;
 
-          case __NR_write:
+          case TARGET_LINUX_SYS_write:
             result = write(arg1, t2h_addr(cb, &s, arg2), arg3);
             errcode = errno;
             break;
 
-          case __NR_open:
+          case TARGET_LINUX_SYS_open:
             result = open((char *) t2h_addr(cb, &s, arg1), arg2, arg3);
             errcode = errno;
             break;
 
-          case __NR_close:
+          case TARGET_LINUX_SYS_close:
             result = close(arg1);
             errcode = errno;
             break;
 
-          case __NR_creat:
+          case TARGET_LINUX_SYS_creat:
             result = creat((char *) t2h_addr(cb, &s, arg1), arg2);
             errcode = errno;
             break;
 
-          case __NR_link:
+          case TARGET_LINUX_SYS_link:
             result = link((char *) t2h_addr(cb, &s, arg1),
                           (char *) t2h_addr(cb, &s, arg2));
             errcode = errno;
             break;
 
-          case __NR_unlink:
+          case TARGET_LINUX_SYS_unlink:
             result = unlink((char *) t2h_addr(cb, &s, arg1));
             errcode = errno;
             break;
 
-          case __NR_chdir:
+          case TARGET_LINUX_SYS_chdir:
             result = chdir((char *) t2h_addr(cb, &s, arg1));
             errcode = errno;
             break;
 
-          case __NR_time:
+          case TARGET_LINUX_SYS_time:
             {
               time_t t;
 
@@ -372,41 +342,41 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_mknod:
+          case TARGET_LINUX_SYS_mknod:
             result = mknod((char *) t2h_addr(cb, &s, arg1),
                            (mode_t) arg2, (dev_t) arg3);
             errcode = errno;
             break;
 
-          case __NR_chmod:
+          case TARGET_LINUX_SYS_chmod:
             result = chmod((char *) t2h_addr(cb, &s, arg1), (mode_t) arg2);
             errcode = errno;
             break;
 
-          case __NR_lchown32:
-          case __NR_lchown:
+          case TARGET_LINUX_SYS_lchown32:
+          case TARGET_LINUX_SYS_lchown:
             result = lchown((char *) t2h_addr(cb, &s, arg1),
                             (uid_t) arg2, (gid_t) arg3);
             errcode = errno;
             break;
 
-          case __NR_lseek:
+          case TARGET_LINUX_SYS_lseek:
             result = (int) lseek(arg1, (off_t) arg2, arg3);
             errcode = errno;
             break;
 
-          case __NR_getpid:
+          case TARGET_LINUX_SYS_getpid:
             result = getpid();
             errcode = errno;
             break;
 
-          case __NR_getuid32:
-          case __NR_getuid:
+          case TARGET_LINUX_SYS_getuid32:
+          case TARGET_LINUX_SYS_getuid:
             result = getuid();
             errcode = errno;
             break;
 
-          case __NR_utime:
+          case TARGET_LINUX_SYS_utime:
             {
               struct utimbuf buf;
 
@@ -425,12 +395,12 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_access:
+          case TARGET_LINUX_SYS_access:
             result = access((char *) t2h_addr(cb, &s, arg1), arg2);
             errcode = errno;
             break;
 
-          case __NR_ftime:
+          case TARGET_LINUX_SYS_ftime:
             {
               struct timeb t;
 
@@ -452,82 +422,82 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
                 }
             }
 
-          case __NR_sync:
+          case TARGET_LINUX_SYS_sync:
             sync();
             result = 0;
             break;
 
-          case __NR_rename:
+          case TARGET_LINUX_SYS_rename:
             result = rename((char *) t2h_addr(cb, &s, arg1),
                             (char *) t2h_addr(cb, &s, arg2));
             errcode = errno;
             break;
 
-          case __NR_mkdir:
+          case TARGET_LINUX_SYS_mkdir:
             result = mkdir((char *) t2h_addr(cb, &s, arg1), arg2);
             errcode = errno;
             break;
 
-          case __NR_rmdir:
+          case TARGET_LINUX_SYS_rmdir:
             result = rmdir((char *) t2h_addr(cb, &s, arg1));
             errcode = errno;
             break;
 
-          case __NR_dup:
+          case TARGET_LINUX_SYS_dup:
             result = dup(arg1);
             errcode = errno;
             break;
 
-          case __NR_brk:
+          case TARGET_LINUX_SYS_brk:
             result = brk((void *) arg1);
             errcode = errno;
             //result = arg1;
             break;
 
-          case __NR_getgid32:
-          case __NR_getgid:
+          case TARGET_LINUX_SYS_getgid32:
+          case TARGET_LINUX_SYS_getgid:
             result = getgid();
             errcode = errno;
             break;
 
-          case __NR_geteuid32:
-          case __NR_geteuid:
+          case TARGET_LINUX_SYS_geteuid32:
+          case TARGET_LINUX_SYS_geteuid:
             result = geteuid();
             errcode = errno;
             break;
 
-          case __NR_getegid32:
-          case __NR_getegid:
+          case TARGET_LINUX_SYS_getegid32:
+          case TARGET_LINUX_SYS_getegid:
             result = getegid();
             errcode = errno;
             break;
 
-          case __NR_ioctl:
+          case TARGET_LINUX_SYS_ioctl:
             result = ioctl(arg1, arg2, arg3);
             errcode = errno;
             break;
 
-          case __NR_fcntl:
+          case TARGET_LINUX_SYS_fcntl:
             result = fcntl(arg1, arg2, arg3);
             errcode = errno;
             break;
 
-          case __NR_dup2:
+          case TARGET_LINUX_SYS_dup2:
             result = dup2(arg1, arg2);
             errcode = errno;
             break;
 
-          case __NR_getppid:
+          case TARGET_LINUX_SYS_getppid:
             result = getppid();
             errcode = errno;
             break;
 
-          case __NR_getpgrp:
+          case TARGET_LINUX_SYS_getpgrp:
             result = getpgrp();
             errcode = errno;
             break;
 
-          case __NR_getrlimit:
+          case TARGET_LINUX_SYS_getrlimit:
             {
               struct rlimit rlim;
 
@@ -547,7 +517,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_getrusage:
+          case TARGET_LINUX_SYS_getrusage:
             {
               struct rusage usage;
 
@@ -567,7 +537,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_gettimeofday:
+          case TARGET_LINUX_SYS_gettimeofday:
             {
               struct timeval tv;
               struct timezone tz;
@@ -596,8 +566,8 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_getgroups32:
-          case __NR_getgroups:
+          case TARGET_LINUX_SYS_getgroups32:
+          case TARGET_LINUX_SYS_getgroups:
             {
               gid_t *list;
 
@@ -621,7 +591,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_select:
+          case TARGET_LINUX_SYS_select:
             {
               int n;
               fd_set readfds;
@@ -721,26 +691,26 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_symlink:
+          case TARGET_LINUX_SYS_symlink:
             result = symlink((char *) t2h_addr(cb, &s, arg1),
                              (char *) t2h_addr(cb, &s, arg2));
             errcode = errno;
             break;
 
-          case __NR_readlink:
+          case TARGET_LINUX_SYS_readlink:
             result = readlink((char *) t2h_addr(cb, &s, arg1),
                               (char *) t2h_addr(cb, &s, arg2),
                               arg3);
             errcode = errno;
             break;
 
-          case __NR_readdir:
+          case TARGET_LINUX_SYS_readdir:
             result = (int) readdir((DIR *) t2h_addr(cb, &s, arg1));
             errcode = errno;
             break;
 
 #if 0
-          case __NR_mmap:
+          case TARGET_LINUX_SYS_mmap:
             {
               result = (int) mmap((void *) t2h_addr(cb, &s, arg1),
                                   arg2, arg3, arg4, arg5, arg6);
@@ -755,7 +725,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 #endif
-          case __NR_mmap2:
+          case TARGET_LINUX_SYS_mmap2:
             {
               void *addr;
               size_t len;
@@ -782,7 +752,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_mmap:
+          case TARGET_LINUX_SYS_mmap:
             {
               void *addr;
               size_t len;
@@ -819,7 +789,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_munmap:
+          case TARGET_LINUX_SYS_munmap:
             {
             result = munmap((void *)arg1, arg2);
             errcode = errno;
@@ -830,28 +800,28 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_truncate:
+          case TARGET_LINUX_SYS_truncate:
             result = truncate((char *) t2h_addr(cb, &s, arg1), arg2);
             errcode = errno;
             break;
 
-          case __NR_ftruncate:
+          case TARGET_LINUX_SYS_ftruncate:
             result = ftruncate(arg1, arg2);
             errcode = errno;
             break;
 
-          case __NR_fchmod:
+          case TARGET_LINUX_SYS_fchmod:
             result = fchmod(arg1, arg2);
             errcode = errno;
             break;
 
-          case __NR_fchown32:
-          case __NR_fchown:
+          case TARGET_LINUX_SYS_fchown32:
+          case TARGET_LINUX_SYS_fchown:
             result = fchown(arg1, arg2, arg3);
             errcode = errno;
             break;
 
-          case __NR_statfs:
+          case TARGET_LINUX_SYS_statfs:
             {
               struct statfs statbuf;
 
@@ -871,7 +841,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_fstatfs:
+          case TARGET_LINUX_SYS_fstatfs:
             {
               struct statfs statbuf;
 
@@ -891,12 +861,12 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_syslog:
+          case TARGET_LINUX_SYS_syslog:
             result = syslog(arg1, (char *) t2h_addr(cb, &s, arg2));
             errcode = errno;
             break;
 
-          case __NR_setitimer:
+          case TARGET_LINUX_SYS_setitimer:
             {
               struct itimerval value, ovalue;
 
@@ -927,7 +897,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_getitimer:
+          case TARGET_LINUX_SYS_getitimer:
             {
               struct itimerval value;
 
@@ -947,7 +917,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_stat:
+          case TARGET_LINUX_SYS_stat:
             {
               char *buf;
               int buflen;
@@ -980,7 +950,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_lstat:
+          case TARGET_LINUX_SYS_lstat:
             {
               char *buf;
               int buflen;
@@ -1013,7 +983,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_fstat:
+          case TARGET_LINUX_SYS_fstat:
             {
               char *buf;
               int buflen;
@@ -1046,7 +1016,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_sysinfo:
+          case TARGET_LINUX_SYS_sysinfo:
             {
               struct sysinfo info;
 
@@ -1082,7 +1052,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             break;
 
 #if 0
-          case __NR_ipc:
+          case TARGET_LINUX_SYS_ipc:
             {
               result = ipc(arg1, arg2, arg3, arg4,
                            (void *) t2h_addr(cb, &s, arg5), arg6);
@@ -1091,19 +1061,19 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             break;
 #endif
 
-          case __NR_fsync:
+          case TARGET_LINUX_SYS_fsync:
             result = fsync(arg1);
             errcode = errno;
             break;
 
-          case __NR_uname:
+          case TARGET_LINUX_SYS_uname:
             /* utsname contains only arrays of char, so it is not necessary
                to translate endian. */
             result = uname((struct utsname *) t2h_addr(cb, &s, arg1));
             errcode = errno;
             break;
 
-          case __NR_adjtimex:
+          case TARGET_LINUX_SYS_adjtimex:
             {
               struct timex buf;
 
@@ -1123,30 +1093,30 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_mprotect:
+          case TARGET_LINUX_SYS_mprotect:
             result = mprotect((void *) arg1, arg2, arg3);
             errcode = errno;
             break;
 
-          case __NR_fchdir:
+          case TARGET_LINUX_SYS_fchdir:
             result = fchdir(arg1);
             errcode = errno;
             break;
 
-          case __NR_setfsuid32:
-          case __NR_setfsuid:
+          case TARGET_LINUX_SYS_setfsuid32:
+          case TARGET_LINUX_SYS_setfsuid:
             result = setfsuid(arg1);
             errcode = errno;
             break;
 
-          case __NR_setfsgid32:
-          case __NR_setfsgid:
+          case TARGET_LINUX_SYS_setfsgid32:
+          case TARGET_LINUX_SYS_setfsgid:
             result = setfsgid(arg1);
             errcode = errno;
             break;
 
 #if 0
-          case __NR__llseek:
+          case TARGET_LINUX_SYS__llseek:
             {
               loff_t buf;
 
@@ -1166,7 +1136,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_getdents:
+          case TARGET_LINUX_SYS_getdents:
             {
               struct dirent dir;
 
@@ -1189,17 +1159,17 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             break;
 #endif
 
-          case __NR_flock:
+          case TARGET_LINUX_SYS_flock:
             result = flock(arg1, arg2);
             errcode = errno;
             break;
 
-          case __NR_msync:
+          case TARGET_LINUX_SYS_msync:
             result = msync((void *) arg1, arg2, arg3);
             errcode = errno;
             break;
 
-          case __NR_readv:
+          case TARGET_LINUX_SYS_readv:
             {
               struct iovec vector;
 
@@ -1211,7 +1181,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_writev:
+          case TARGET_LINUX_SYS_writev:
             {
               struct iovec vector;
 
@@ -1223,22 +1193,22 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_fdatasync:
+          case TARGET_LINUX_SYS_fdatasync:
             result = fdatasync(arg1);
             errcode = errno;
             break;
 
-          case __NR_mlock:
+          case TARGET_LINUX_SYS_mlock:
             result = mlock((void *) t2h_addr(cb, &s, arg1), arg2);
             errcode = errno;
             break;
 
-          case __NR_munlock:
+          case TARGET_LINUX_SYS_munlock:
             result = munlock((void *) t2h_addr(cb, &s, arg1), arg2);
             errcode = errno;
             break;
 
-          case __NR_nanosleep:
+          case TARGET_LINUX_SYS_nanosleep:
             {
               struct timespec req, rem;
 
@@ -1261,13 +1231,13 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_mremap: /* FIXME */
+          case TARGET_LINUX_SYS_mremap: /* FIXME */
             result = (int) mremap((void *) t2h_addr(cb, &s, arg1), arg2, arg3, arg4); 
             errcode = errno;
             break;
 
-          case __NR_getresuid32:
-          case __NR_getresuid:
+          case TARGET_LINUX_SYS_getresuid32:
+          case TARGET_LINUX_SYS_getresuid:
             {
               uid_t ruid, euid, suid;
 
@@ -1283,7 +1253,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_poll:
+          case TARGET_LINUX_SYS_poll:
             {
               struct pollfd ufds;
 
@@ -1297,8 +1267,8 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_getresgid32:
-          case __NR_getresgid:
+          case TARGET_LINUX_SYS_getresgid32:
+          case TARGET_LINUX_SYS_getresgid:
             {
               uid_t rgid, egid, sgid;
 
@@ -1314,28 +1284,28 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_pread:
+          case TARGET_LINUX_SYS_pread:
             result =  pread(arg1, (void *) t2h_addr(cb, &s, arg2), arg3, arg4); 
             errcode = errno;
             break;
 
-          case __NR_pwrite:
+          case TARGET_LINUX_SYS_pwrite:
             result =  pwrite(arg1, (void *) t2h_addr(cb, &s, arg2), arg3, arg4); 
             errcode = errno;
             break;
 
-          case __NR_chown32:
-          case __NR_chown:
+          case TARGET_LINUX_SYS_chown32:
+          case TARGET_LINUX_SYS_chown:
             result = chown((char *) t2h_addr(cb, &s, arg1), arg2, arg3);
             errcode = errno;
             break;
 
-          case __NR_getcwd:
+          case TARGET_LINUX_SYS_getcwd:
             result = (int) getcwd((char *) t2h_addr(cb, &s, arg1), arg2);
             errcode = errno;
             break;
 
-          case __NR_sendfile:
+          case TARGET_LINUX_SYS_sendfile:
             {
               off_t offset;