sim: convert to bfd_endian
[deliverable/binutils-gdb.git] / sim / m32r / traps-linux.c
index a6362c1f1d967ae20e8add61fee28644ecfacbe0..9220451734769b112eaf7fe4ffbc6fa8534e3610 100644 (file)
@@ -1,24 +1,24 @@
 /* m32r exception, interrupt, and trap (EIT) support
-   Copyright (C) 1998, 2003 Free Software Foundation, Inc.
+   Copyright (C) 1998-2016 Free Software Foundation, Inc.
    Contributed by Renesas.
 
    This file is part of GDB, the GNU debugger.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation, Inc.,
-   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "sim-main.h"
+#include "sim-syscall.h"
 #include "syscall.h"
 #include "targ-vals.h"
 #include <dirent.h>
@@ -114,35 +114,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;
@@ -159,7 +136,7 @@ conv_endian (unsigned int tvalue)
   unsigned int hvalue;
   unsigned int t1, t2, t3, t4;
 
-  if (CURRENT_HOST_BYTE_ORDER == LITTLE_ENDIAN)
+  if (CURRENT_HOST_BYTE_ORDER == BFD_ENDIAN_LITTLE)
     {
       t1 = tvalue & 0xff000000;
       t2 = tvalue & 0x00ff0000;
@@ -183,7 +160,7 @@ conv_endian16 (unsigned short tvalue)
   unsigned short hvalue;
   unsigned short t1, t2;
 
-  if (CURRENT_HOST_BYTE_ORDER == LITTLE_ENDIAN)
+  if (CURRENT_HOST_BYTE_ORDER == BFD_ENDIAN_LITTLE)
     {
       t1 = tvalue & 0xff00;
       t2 = tvalue & 0x00ff;
@@ -220,44 +197,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 :
@@ -292,8 +250,8 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
 
         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;
@@ -384,6 +342,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             errcode = errno;
             break;
 
+          case __NR_lchown32:
           case __NR_lchown:
             result = lchown((char *) t2h_addr(cb, &s, arg1),
                             (uid_t) arg2, (gid_t) arg3);
@@ -400,6 +359,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             errcode = errno;
             break;
 
+          case __NR_getuid32:
           case __NR_getuid:
             result = getuid();
             errcode = errno;
@@ -483,16 +443,19 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             //result = arg1;
             break;
 
+          case __NR_getgid32:
           case __NR_getgid:
             result = getgid();
             errcode = errno;
             break;
 
+          case __NR_geteuid32:
           case __NR_geteuid:
             result = geteuid();
             errcode = errno;
             break;
 
+          case __NR_getegid32:
           case __NR_getegid:
             result = getegid();
             errcode = errno;
@@ -592,6 +555,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
+          case __NR_getgroups32:
           case __NR_getgroups:
             {
               gid_t *list;
@@ -750,6 +714,33 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 #endif
+          case __NR_mmap2:
+            {
+              void *addr;
+              size_t len;
+              int prot, flags, fildes;
+              off_t off;
+              
+              addr   = (void *)  t2h_addr(cb, &s, arg1);
+              len    = arg2;
+              prot   = arg3;
+              flags  = arg4;
+              fildes = arg5;
+              off    = arg6 << 12;
+
+             result = (int) mmap(addr, len, prot, flags, fildes, off);
+              errcode = errno;
+              if (result != -1)
+                {
+                  char c;
+                 if (sim_core_read_buffer (sd, NULL, read_map, &c, result, 1) == 0)
+                    sim_core_attach (sd, NULL,
+                                     0, access_read_write_exec, 0,
+                                     result, len, 0, NULL, NULL);
+                }
+            }
+            break;
+
           case __NR_mmap:
             {
               void *addr;
@@ -813,6 +804,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             errcode = errno;
             break;
 
+          case __NR_fchown32:
           case __NR_fchown:
             result = fchown(arg1, arg2, arg3);
             errcode = errno;
@@ -1100,11 +1092,13 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             errcode = errno;
             break;
 
+          case __NR_setfsuid32:
           case __NR_setfsuid:
             result = setfsuid(arg1);
             errcode = errno;
             break;
 
+          case __NR_setfsgid32:
           case __NR_setfsgid:
             result = setfsgid(arg1);
             errcode = errno;
@@ -1231,6 +1225,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             errcode = errno;
             break;
 
+          case __NR_getresuid32:
           case __NR_getresuid:
             {
               uid_t ruid, euid, suid;
@@ -1261,6 +1256,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
+          case __NR_getresgid32:
           case __NR_getresgid:
             {
               uid_t rgid, egid, sgid;
@@ -1287,6 +1283,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             errcode = errno;
             break;
 
+          case __NR_chown32:
           case __NR_chown:
             result = chown((char *) t2h_addr(cb, &s, arg1), arg2, arg3);
             errcode = errno;
This page took 0.027332 seconds and 4 git commands to generate.