sim: m32r: namespace Linux syscall table
[binutils-gdb.git] / sim / m32r / traps-linux.c
index 9220451734769b112eaf7fe4ffbc6fa8534e3610..d60be7ca54b92c7dd731165b72d298e04699b12b 100644 (file)
@@ -1,5 +1,5 @@
 /* m32r exception, interrupt, and trap (EIT) support
-   Copyright (C) 1998-2016 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>
@@ -136,7 +143,7 @@ conv_endian (unsigned int tvalue)
   unsigned int hvalue;
   unsigned int t1, t2, t3, t4;
 
-  if (CURRENT_HOST_BYTE_ORDER == BFD_ENDIAN_LITTLE)
+  if (HOST_BYTE_ORDER == BFD_ENDIAN_LITTLE)
     {
       t1 = tvalue & 0xff000000;
       t2 = tvalue & 0x00ff0000;
@@ -160,7 +167,7 @@ conv_endian16 (unsigned short tvalue)
   unsigned short hvalue;
   unsigned short t1, t2;
 
-  if (CURRENT_HOST_BYTE_ORDER == BFD_ENDIAN_LITTLE)
+  if (HOST_BYTE_ORDER == BFD_ENDIAN_LITTLE)
     {
       t1 = tvalue & 0xff00;
       t2 = tvalue & 0x00ff;
@@ -247,6 +254,10 @@ 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;
@@ -259,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;
 
@@ -331,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;
 
@@ -384,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;
 
@@ -411,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;
 
@@ -506,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;
 
@@ -526,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;
@@ -555,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;
 
@@ -580,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;
@@ -680,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);
@@ -714,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;
@@ -741,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;
@@ -778,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;
@@ -789,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;
 
@@ -830,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;
 
@@ -850,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;
 
@@ -886,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;
 
@@ -906,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;
@@ -939,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;
@@ -972,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;
@@ -1005,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;
 
@@ -1041,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);
@@ -1050,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;
 
@@ -1082,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;
 
@@ -1125,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;
 
@@ -1148,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;
 
@@ -1170,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;
 
@@ -1182,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;
 
@@ -1220,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;
 
@@ -1242,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;
 
@@ -1256,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;
 
@@ -1273,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;