]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - sim/mcore/interp.c
Update years in copyright notice for the GDB files.
[thirdparty/binutils-gdb.git] / sim / mcore / interp.c
index 810bb0698355faff1f915034b07658b08ca306b8..5a880bf376ce70a864cd1a45ef0db920161d6d28 100644 (file)
@@ -1,32 +1,32 @@
-/* Simulator for Motorolla's MCore processor
-   Copyright (C) 1999 Free Software Foundation, Inc.
+/* Simulator for Motorola's MCore processor
+   Copyright (C) 1999-2013 Free Software Foundation, Inc.
    Contributed by Cygnus Solutions.
 
 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 "config.h"
 #include <signal.h>
 #include "sysdep.h"
 #include <sys/times.h>
 #include <sys/param.h>
 #include <netinet/in.h>        /* for byte ordering macros */
 #include "bfd.h"
-#include "callback.h"
+#include "gdb/callback.h"
 #include "libiberty.h"
-#include "remote-sim.h"
+#include "gdb/remote-sim.h"
 
 #ifndef NUM_ELEM
 #define NUM_ELEM(A) (sizeof (A) / sizeof (A)[0])
@@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 typedef long int           word;
 typedef unsigned long int  uword;
 
+static int            target_big_endian = 0;
 static unsigned long  heap_ptr = 0;
 host_callback *       callback;
 
@@ -58,6 +59,12 @@ mcore_extract_unsigned_integer (addr, len)
      the least significant.  */
   retval = 0;
 
+  if (! target_big_endian)
+    {
+      for (p = endaddr; p > startaddr;)
+       retval = (retval << 8) | * -- p;
+    }
+  else
     {
       for (p = startaddr; p < endaddr;)
        retval = (retval << 8) | * p ++;
@@ -76,6 +83,15 @@ mcore_store_unsigned_integer (addr, len, val)
   unsigned char * startaddr = (unsigned char *)addr;
   unsigned char * endaddr = startaddr + len;
 
+  if (! target_big_endian)
+    {
+      for (p = startaddr; p < endaddr;)
+       {
+         * p ++ = val & 0xff;
+         val >>= 8;
+       }
+    }
+  else
     {
       for (p = endaddr; p > startaddr;)
        {
@@ -92,7 +108,7 @@ mcore_store_unsigned_integer (addr, len, val)
    Keeping this data in target byte order simplifies the register
    read/write functions.  Keeping this data in native order improves
    the performance of the simulator.  Simulation speed is deemed more
-   important. */
+   important.  */
 
 /* The ordering of the mcore_regset structure is matched in the
    gdb/config/mcore/tm-mcore.h file in the REGISTER_NAMES macro.  */
@@ -216,6 +232,14 @@ wlat (x, v)
       
          cpu.asregs.exception = SIGBUS;
        }
+      else if (! target_big_endian)
+       {
+         unsigned char * p = cpu.mem + x;
+         p[3] = v >> 24;
+         p[2] = v >> 16;
+         p[1] = v >> 8;
+         p[0] = v;
+       }
       else
        {
          unsigned char * p = cpu.mem + x;
@@ -248,6 +272,12 @@ what (x, v)
       
          cpu.asregs.exception = SIGBUS;
        }
+      else if (! target_big_endian)
+       {
+         unsigned char * p = cpu.mem + x;
+         p[1] = v >> 8;
+         p[0] = v;
+       }
       else
        {
          unsigned char * p = cpu.mem + x;
@@ -257,7 +287,7 @@ what (x, v)
     }
 }
 
-/* Read functions */
+/* Read functions */
 static int INLINE 
 rbat (x)
      word x;
@@ -299,6 +329,11 @@ rlat (x)
          cpu.asregs.exception = SIGBUS;
          return 0;
        }
+      else if (! target_big_endian)
+       {
+         unsigned char * p = cpu.mem + x;
+         return (p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0];
+       }
       else
        {
          unsigned char * p = cpu.mem + x;
@@ -329,6 +364,11 @@ rhat (x)
          cpu.asregs.exception = SIGBUS;
          return 0;
        }
+      else if (! target_big_endian)
+       {
+         unsigned char * p = cpu.mem + x;
+         return (p[1] << 8) | p[0];
+       }
       else
        {
          unsigned char * p = cpu.mem + x;
@@ -349,7 +389,7 @@ IOMEM (addr, write, value)
 {
 }
 
-/* default to a 8 Mbyte (== 2^23) memory space */
+/* Default to a 8 Mbyte (== 2^23) memory space.  */
 static int sim_memory_size = 23;
 
 #define        MEM_SIZE_FLOOR  64
@@ -363,9 +403,9 @@ sim_size (power)
   if (cpu.mem)
     free (cpu.mem);
 
-  /* watch out for the '0 count' problem. There's probably a better
-     way.. e.g., why do we use 64 here? */
-  if (cpu.asregs.msize < 64)   /* ensure a boundary */
+  /* Watch out for the '0 count' problem. There's probably a better
+     way.. e.g., why do we use 64 here?  */
+  if (cpu.asregs.msize < 64)   /* Ensure a boundary.  */
     cpu.mem = (unsigned char *) calloc (64, (64 + cpu.asregs.msize) / 64);
   else
     cpu.mem = (unsigned char *) calloc (64, cpu.asregs.msize / 64);
@@ -505,7 +545,7 @@ handle_trap1 ()
       break;
       
     case 6:
-      a[0] = (unsigned long) (cpu.gr[4]);
+      a[0] = (unsigned long) (cpu.gr[PARM1]);
       /* Watch out for debugger's files. */
       if (is_opened (a[0]))
        {
@@ -762,11 +802,17 @@ sim_resume (sd, step, siggnal)
       
       if (pc & 02)
        {
+         if (! target_big_endian)
+           inst = ibuf >> 16;
+         else
            inst = ibuf & 0xFFFF;
          needfetch = 1;
        }
       else
        {
+         if (! target_big_endian)
+           inst = ibuf & 0xFFFF;
+         else
            inst = ibuf >> 16;
        }
 
@@ -1181,7 +1227,9 @@ sim_resume (sd, step, siggnal)
            unsigned long dst, src;
            dst = cpu.gr[RD];
            src = cpu.gr[RS];
-           dst = dst >> src;   
+           /* We must not rely solely upon the native shift operations, since they
+              may not match the M*Core's behaviour on boundary conditions.  */
+           dst = src > 31 ? 0 : dst >> src;
            cpu.gr[RD] = dst;
          }
          break;
@@ -1256,11 +1304,18 @@ sim_resume (sd, step, siggnal)
          break;
 
        case 0x1A:                                      /* asr */
-         cpu.gr[RD] = (long)cpu.gr[RD] >> cpu.gr[RS];
+         /* We must not rely solely upon the native shift operations, since they
+            may not match the M*Core's behaviour on boundary conditions.  */
+         if (cpu.gr[RS] > 30)
+           cpu.gr[RD] = ((long) cpu.gr[RD]) < 0 ? -1 : 0;
+         else
+           cpu.gr[RD] = (long) cpu.gr[RD] >> cpu.gr[RS];
          break;
 
        case 0x1B:                                      /* lsl */
-         cpu.gr[RD] = cpu.gr[RD] << cpu.gr[RS];
+         /* We must not rely solely upon the native shift operations, since they
+            may not match the M*Core's behaviour on boundary conditions.  */
+         cpu.gr[RD] = cpu.gr[RS] > 31 ? 0 : cpu.gr[RD] << cpu.gr[RS];
          break;
 
        case 0x1C:                                      /* addu */
@@ -1663,7 +1718,7 @@ int
 sim_write (sd, addr, buffer, size)
      SIM_DESC sd;
      SIM_ADDR addr;
-     unsigned char * buffer;
+     const unsigned char * buffer;
      int size;
 {
   int i;
@@ -1846,7 +1901,7 @@ SIM_DESC
 sim_open (kind, cb, abfd, argv)
      SIM_OPEN_KIND kind;
      host_callback * cb;
-     struct _bfd * abfd;
+     struct bfd * abfd;
      char ** argv;
 {
   int osize = sim_memory_size;
@@ -1926,9 +1981,11 @@ sim_load (sd, prog, abfd, from_tty)
     /* figure the end of the bss section */
 #if 0
     printf ("bss section at 0x%08x for 0x%08x bytes\n",
-       (unsigned long) s_bss->vma , (unsigned long) s_bss->_cooked_size);
+           (unsigned long) bfd_get_section_vma (handle, s_bss),
+           (unsigned long) bfd_section_size (handle, s_bss));
 #endif
-    heap_ptr = (unsigned long) s_bss->vma + (unsigned long) s_bss->_cooked_size;
+    heap_ptr = ((unsigned long) bfd_get_section_vma (handle, s_bss)
+               + (unsigned long) bfd_section_size (handle, s_bss));
 
     /* Clean up after ourselves.  */
     bfd_close (handle);
@@ -1943,6 +2000,7 @@ sim_load (sd, prog, abfd, from_tty)
   if (prog_bfd == NULL)
     return SIM_RC_FAIL;
   
+  target_big_endian = bfd_big_endian (prog_bfd);
     
   if (abfd == NULL)
     bfd_close (prog_bfd);
@@ -1953,7 +2011,7 @@ sim_load (sd, prog, abfd, from_tty)
 SIM_RC
 sim_create_inferior (sd, prog_bfd, argv, env)
      SIM_DESC sd;
-     struct _bfd * prog_bfd;
+     struct bfd * prog_bfd;
      char ** argv;
      char ** env;
 {