sim: sim-core: pass down cpu to hw accesses when available
[binutils-gdb.git] / sim / common / sim-core.c
index f40d042fa81117a09268b65e37e6abe0e9a9d4c2..68212e9c24f43efa9aed163bad41f22190f20c2b 100644 (file)
@@ -1,6 +1,6 @@
 /* The common simulator framework for GDB, the GNU Debugger.
 
-   Copyright 2002-2014 Free Software Foundation, Inc.
+   Copyright 2002-2015 Free Software Foundation, Inc.
 
    Contributed by Andrew Cagney and Red Hat.
 
@@ -28,7 +28,6 @@
 
 #if (WITH_HW)
 #include "sim-hw.h"
-#define device_error(client, ...) device_error ((device *)(client), __VA_ARGS__)
 #define device_io_read_buffer(client, ...) device_io_read_buffer ((device *)(client), __VA_ARGS__)
 #define device_io_write_buffer(client, ...) device_io_write_buffer ((device *)(client), __VA_ARGS__)
 #endif
@@ -157,10 +156,7 @@ new_sim_core_mapping (SIM_DESC sd,
   new_mapping->base = addr;
   new_mapping->nr_bytes = nr_bytes;
   new_mapping->bound = addr + (nr_bytes - 1);
-  if (modulo == 0)
-    new_mapping->mask = (unsigned) 0 - 1;
-  else
-    new_mapping->mask = modulo - 1;
+  new_mapping->mask = modulo - 1;
   new_mapping->buffer = buffer;
   new_mapping->free_buffer = free_buffer;
   new_mapping->device = device;
@@ -197,9 +193,6 @@ sim_core_map_attach (SIM_DESC sd,
   /* actually do occasionally get a zero size map */
   if (nr_bytes == 0)
     {
-#if (WITH_DEVICES)
-      device_error (client, "called on sim_core_map_attach with size zero");
-#endif
 #if (WITH_HW)
       sim_hw_abort (sd, client, "called on sim_core_map_attach with size zero");
 #endif
@@ -226,17 +219,6 @@ sim_core_map_attach (SIM_DESC sd,
   if (next_mapping != NULL && next_mapping->level == level
       && next_mapping->base < (addr + (nr_bytes - 1)))
     {
-#if (WITH_DEVICES)
-      device_error (client, "memory map %d:0x%lx..0x%lx (%ld bytes) overlaps %d:0x%lx..0x%lx (%ld bytes)",
-                   space,
-                   (long) addr,
-                   (long) (addr + nr_bytes - 1),
-                   (long) nr_bytes,
-                   next_mapping->space,
-                   (long) next_mapping->base,
-                   (long) next_mapping->bound,
-                   (long) next_mapping->nr_bytes);
-#endif
 #if WITH_HW
       sim_hw_abort (sd, client, "memory map %d:0x%lx..0x%lx (%ld bytes) overlaps %d:0x%lx..0x%lx (%ld bytes)",
                    space,
@@ -298,22 +280,8 @@ sim_core_attach (SIM_DESC sd,
   if (cpu != NULL)
     sim_io_error (sd, "sim_core_map_attach - processor specific memory map not yet supported");
 
-  /* verify modulo memory */
-  if (!WITH_MODULO_MEMORY && modulo != 0)
-    {
-#if (WITH_DEVICES)
-      device_error (client, "sim_core_attach - internal error - modulo memory disabled");
-#endif
-#if (WITH_HW)
-      sim_hw_abort (sd, client, "sim_core_attach - internal error - modulo memory disabled");
-#endif
-      sim_io_error (sd, "sim_core_attach - internal error - modulo memory disabled");
-    }
   if (client != NULL && modulo != 0)
     {
-#if (WITH_DEVICES)
-      device_error (client, "sim_core_attach - internal error - modulo and callback memory conflict");
-#endif
 #if (WITH_HW)
       sim_hw_abort (sd, client, "sim_core_attach - internal error - modulo and callback memory conflict");
 #endif
@@ -332,9 +300,6 @@ sim_core_attach (SIM_DESC sd,
        }
       if (mask != sizeof (unsigned64) - 1)
        {
-#if (WITH_DEVICES)
-         device_error (client, "sim_core_attach - internal error - modulo %lx not power of two", (long) modulo);
-#endif
 #if (WITH_HW)
          sim_hw_abort (sd, client, "sim_core_attach - internal error - modulo %lx not power of two", (long) modulo);
 #endif
@@ -345,9 +310,6 @@ sim_core_attach (SIM_DESC sd,
   /* verify consistency between device and buffer */
   if (client != NULL && optional_buffer != NULL)
     {
-#if (WITH_DEVICES)
-      device_error (client, "sim_core_attach - internal error - conflicting buffer and attach arguments");
-#endif
 #if (WITH_HW)
       sim_hw_abort (sd, client, "sim_core_attach - internal error - conflicting buffer and attach arguments");
 #endif
@@ -497,12 +459,8 @@ STATIC_INLINE_SIM_CORE\
 sim_core_translate (sim_core_mapping *mapping,
                    address_word addr)
 {
-  if (WITH_MODULO_MEMORY)
-    return (void *)((unsigned8 *) mapping->buffer
-                   + ((addr - mapping->base) & mapping->mask));
-  else
-    return (void *)((unsigned8 *) mapping->buffer
-                   + addr - mapping->base);
+  return (void *)((unsigned8 *) mapping->buffer
+                 + ((addr - mapping->base) & mapping->mask));
 }
 
 
@@ -531,7 +489,7 @@ sim_core_read_buffer (SIM_DESC sd,
     if (mapping->device != NULL)
       {
        int nr_bytes = len - count;
-       sim_cia cia = cpu ? CIA_GET (cpu) : NULL_CIA;
+       sim_cia cia = cpu ? CPU_PC_GET (cpu) : NULL_CIA;
        if (raddr + nr_bytes - 1> mapping->bound)
          nr_bytes = mapping->bound - raddr + 1;
        if (device_io_read_buffer (mapping->device,
@@ -553,11 +511,23 @@ sim_core_read_buffer (SIM_DESC sd,
        int nr_bytes = len - count;
        if (raddr + nr_bytes - 1> mapping->bound)
          nr_bytes = mapping->bound - raddr + 1;
-       if (sim_hw_io_read_buffer (sd, mapping->device,
-                                  (unsigned_1*)buffer + count,
-                                  mapping->space,
-                                  raddr,
-                                  nr_bytes) != nr_bytes)
+       /* If the access was initiated by a cpu, pass it down so errors can
+          be propagated properly.  For other sources (e.g. GDB or DMA), we
+          can only signal errors via the return value.  */
+       if (cpu)
+         {
+           sim_cia cia = cpu ? CPU_PC_GET (cpu) : NULL_CIA;
+           sim_cpu_hw_io_read_buffer (cpu, cia, mapping->device,
+                                      (unsigned_1*)buffer + count,
+                                      mapping->space,
+                                      raddr,
+                                      nr_bytes);
+         }
+       else if (sim_hw_io_read_buffer (sd, mapping->device,
+                                       (unsigned_1*)buffer + count,
+                                       mapping->space,
+                                       raddr,
+                                       nr_bytes) != nr_bytes)
          break;
        count += nr_bytes;
        continue;
@@ -594,11 +564,10 @@ sim_core_write_buffer (SIM_DESC sd,
       if (mapping == NULL)
        break;
 #if (WITH_DEVICES)
-      if (WITH_CALLBACK_MEMORY
-         && mapping->device != NULL)
+      if (mapping->device != NULL)
        {
          int nr_bytes = len - count;
-         sim_cia cia = cpu ? CIA_GET (cpu) : NULL_CIA;
+         sim_cia cia = cpu ? CPU_PC_GET (cpu) : NULL_CIA;
          if (raddr + nr_bytes - 1 > mapping->bound)
            nr_bytes = mapping->bound - raddr + 1;
          if (device_io_write_buffer (mapping->device,
@@ -615,17 +584,28 @@ sim_core_write_buffer (SIM_DESC sd,
        }
 #endif
 #if (WITH_HW)
-      if (WITH_CALLBACK_MEMORY
-         && mapping->device != NULL)
+      if (mapping->device != NULL)
        {
          int nr_bytes = len - count;
          if (raddr + nr_bytes - 1 > mapping->bound)
            nr_bytes = mapping->bound - raddr + 1;
-         if (sim_hw_io_write_buffer (sd, mapping->device,
-                                     (unsigned_1*)buffer + count,
-                                     mapping->space,
-                                     raddr,
-                                     nr_bytes) != nr_bytes)
+         /* If the access was initiated by a cpu, pass it down so errors can
+            be propagated properly.  For other sources (e.g. GDB or DMA), we
+            can only signal errors via the return value.  */
+         if (cpu)
+           {
+             sim_cia cia = cpu ? CPU_PC_GET (cpu) : NULL_CIA;
+             sim_cpu_hw_io_write_buffer (cpu, cia, mapping->device,
+                                         (unsigned_1*)buffer + count,
+                                         mapping->space,
+                                         raddr,
+                                         nr_bytes);
+           }
+         else if (sim_hw_io_write_buffer (sd, mapping->device,
+                                         (unsigned_1*)buffer + count,
+                                         mapping->space,
+                                         raddr,
+                                         nr_bytes) != nr_bytes)
            break;
          count += nr_bytes;
          continue;