]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - sim/common/sim-core.c
Update years in copyright notice for the GDB files.
[thirdparty/binutils-gdb.git] / sim / common / sim-core.c
index e3e34360807274a65dcfb43553947485c8af2f9d..f7a07fd55d8f6eb82be08aaed5b5b03894e9f4b9 100644 (file)
@@ -1,48 +1,50 @@
-/*  This file is part of the program psim.
+/* The common simulator framework for GDB, the GNU Debugger.
 
-    Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
+   Copyright 2002-2013 Free Software Foundation, Inc.
 
-    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 of the License, or
-    (at your option) any later version.
+   Contributed by Andrew Cagney and Red Hat.
 
-    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.
-    */
+   This file is part of GDB.
 
+   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 3 of the License, or
+   (at your option) any later version.
 
-#ifndef _SIM_CORE_C_
-#define _SIM_CORE_C_
+   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, see <http://www.gnu.org/licenses/>.  */
+
+
+#ifndef SIM_CORE_C
+#define SIM_CORE_C
 
-#include "libiberty.h"
 #include "sim-main.h"
 #include "sim-assert.h"
 
+#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
+
 /* "core" module install handler.
 
-   This is called via sim_module_install to install the "core" subsystem
-   into the simulator.  */
+   This is called via sim_module_install to install the "core"
+   subsystem into the simulator.  */
 
+#if EXTERN_SIM_CORE_P
 static MODULE_INIT_FN sim_core_init;
 static MODULE_UNINSTALL_FN sim_core_uninstall;
-
-#if (WITH_DEVICES)
-/* TODO: create sim/common/device.h */
-void device_error (device *me, char* message, ...);
-int device_io_read_buffer(device *me, void *dest, int space, address_word addr, unsigned nr_bytes, sim_cpu *processor, sim_cia cia);
-int device_io_write_buffer(device *me, const void *source, int space, address_word addr, unsigned nr_bytes, sim_cpu *processor, sim_cia cia);
 #endif
 
-EXTERN_SIM_CORE\
-(SIM_RC)
+#if EXTERN_SIM_CORE_P
+SIM_RC
 sim_core_install (SIM_DESC sd)
 {
   SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
@@ -54,53 +56,57 @@ sim_core_install (SIM_DESC sd)
   /* establish any initial data structures - none */
   return SIM_RC_OK;
 }
+#endif
 
 
 /* Uninstall the "core" subsystem from the simulator.  */
 
-STATIC_SIM_CORE\
-(void)
+#if EXTERN_SIM_CORE_P
+static void
 sim_core_uninstall (SIM_DESC sd)
 {
-  sim_core *core = STATE_CORE(sd);
-  sim_core_maps map;
+  sim_core *core = STATE_CORE (sd);
+  unsigned map;
   /* blow away any mappings */
-  for (map = 0; map < nr_sim_core_maps; map++) {
+  for (map = 0; map < nr_maps; map++) {
     sim_core_mapping *curr = core->common.map[map].first;
     while (curr != NULL) {
       sim_core_mapping *tbd = curr;
       curr = curr->next;
       if (tbd->free_buffer != NULL) {
-       SIM_ASSERT(tbd->buffer != NULL);
-       zfree(tbd->free_buffer);
+       SIM_ASSERT (tbd->buffer != NULL);
+       free (tbd->free_buffer);
       }
-      zfree(tbd);
+      free (tbd);
     }
     core->common.map[map].first = NULL;
   }
 }
+#endif
 
 
-STATIC_SIM_CORE\
-(SIM_RC)
+#if EXTERN_SIM_CORE_P
+static SIM_RC
 sim_core_init (SIM_DESC sd)
 {
   /* Nothing to do */
   return SIM_RC_OK;
 }
+#endif
 
 
 
 #ifndef SIM_CORE_SIGNAL
 #define SIM_CORE_SIGNAL(SD,CPU,CIA,MAP,NR_BYTES,ADDR,TRANSFER,ERROR) \
 sim_core_signal ((SD), (CPU), (CIA), (MAP), (NR_BYTES), (ADDR), (TRANSFER), (ERROR))
+#endif
 
-STATIC_SIM_CORE\
-(void)
+#if EXTERN_SIM_CORE_P
+void
 sim_core_signal (SIM_DESC sd,
                 sim_cpu *cpu,
                 sim_cia cia,
-                sim_core_maps map,
+                unsigned map,
                 int nr_bytes,
                 address_word addr,
                 transfer_type transfer,
@@ -128,33 +134,23 @@ sim_core_signal (SIM_DESC sd,
 #endif
 
 
-EXTERN_SIM_CORE\
-(const char *)
-sim_core_map_to_str (sim_core_maps map)
-{
-  switch (map)
-    {
-    case sim_core_read_map: return "read";
-    case sim_core_write_map: return "write";
-    case sim_core_execute_map: return "exec";
-    default: return "(invalid-map)";
-    }
-}
-
-
-STATIC_SIM_CORE\
-(sim_core_mapping *)
+#if EXTERN_SIM_CORE_P
+static sim_core_mapping *
 new_sim_core_mapping (SIM_DESC sd,
                      int level,
                      int space,
                      address_word addr,
                      address_word nr_bytes,
                      unsigned modulo,
+#if WITH_HW
+                     struct hw *device,
+#else
                      device *device,
+#endif
                      void *buffer,
                      void *free_buffer)
 {
-  sim_core_mapping *new_mapping = ZALLOC(sim_core_mapping);
+  sim_core_mapping *new_mapping = ZALLOC (sim_core_mapping);
   /* common */
   new_mapping->level = level;
   new_mapping->space = space;
@@ -170,10 +166,11 @@ new_sim_core_mapping (SIM_DESC sd,
   new_mapping->device = device;
   return new_mapping;
 }
+#endif
 
 
-STATIC_SIM_CORE\
-(void)
+#if EXTERN_SIM_CORE_P
+static void
 sim_core_map_attach (SIM_DESC sd,
                     sim_core_map *access_map,
                     int level,
@@ -181,7 +178,11 @@ sim_core_map_attach (SIM_DESC sd,
                     address_word addr,
                     address_word nr_bytes,
                     unsigned modulo,
+#if WITH_HW
+                    struct hw *client, /*callback/default*/
+#else
                     device *client, /*callback/default*/
+#endif
                     void *buffer, /*raw_memory*/
                     void *free_buffer) /*raw_memory*/
 {
@@ -197,16 +198,18 @@ sim_core_map_attach (SIM_DESC sd,
   if (nr_bytes == 0)
     {
 #if (WITH_DEVICES)
-      device_error(client, "called on sim_core_map_attach with size zero");
-#else
-      sim_io_error (sd, "called on sim_core_map_attach with size zero");
+      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
+      sim_io_error (sd, "called on sim_core_map_attach with size zero");
     }
 
   /* find the insertion point (between last/next) */
   next_mapping = access_map->first;
   last_mapping = &access_map->first;
-  while(next_mapping != NULL
+  while (next_mapping != NULL
        && (next_mapping->level < level
            || (next_mapping->level == level
                && next_mapping->bound < addr)))
@@ -217,7 +220,7 @@ sim_core_map_attach (SIM_DESC sd,
       last_mapping = &next_mapping->next;
       next_mapping = next_mapping->next;
     }
-  
+
   /* check insertion point correct */
   SIM_ASSERT (next_mapping == NULL || next_mapping->level >= level);
   if (next_mapping != NULL && next_mapping->level == level
@@ -227,61 +230,67 @@ sim_core_map_attach (SIM_DESC sd,
       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,
+                   (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);
-#else
+#endif
       sim_io_error (sd, "memory map %d:0x%lx..0x%lx (%ld bytes) overlaps %d:0x%lx..0x%lx (%ld bytes)",
                    space,
                    (long) addr,
-                   (long) nr_bytes,
                    (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
   }
 
   /* create/insert the new mapping */
-  *last_mapping = new_sim_core_mapping(sd,
-                                      level,
-                                      space, addr, nr_bytes, modulo,
-                                      client, buffer, free_buffer);
+  *last_mapping = new_sim_core_mapping (sd,
+                                       level,
+                                       space, addr, nr_bytes, modulo,
+                                       client, buffer, free_buffer);
   (*last_mapping)->next = next_mapping;
 }
+#endif
+
 
 /* Attach memory or a memory mapped device to the simulator.
-   LEVEL is ... ?
-   ACCESS is the kind of access to grant (some collection of r/w/x).
-   SPACE is ... ?
-   ADDR is the starting address of the section.
-   NR_BYTES is the size of the section.
-   MODULO is non-zero if this the section is to be split into several MODULO
-   sized identical chunks.
-   CLIENT is non-zero for devices, otherwise NULL.
-   OPTIONAL_BUFFER is the address of a pre-allocated buffer to use.
-   OPTIONAL_BUFFER is a sub-optimal hook that allows clients to do nasty
-   things that the interface doesn't accomodate.  */
-
-EXTERN_SIM_CORE\
-(void)
+   See sim-core.h for a full description.  */
+
+#if EXTERN_SIM_CORE_P
+void
 sim_core_attach (SIM_DESC sd,
                 sim_cpu *cpu,
                 int level,
-                access_type access,
+                unsigned mapmask,
                 int space,
                 address_word addr,
                 address_word nr_bytes,
                 unsigned modulo,
+#if WITH_HW
+                struct hw *client,
+#else
                 device *client,
+#endif
                 void *optional_buffer)
 {
-  sim_core *memory = STATE_CORE(sd);
-  sim_core_maps map;
+  sim_core *memory = STATE_CORE (sd);
+  unsigned map;
   void *buffer;
   void *free_buffer;
 
@@ -289,32 +298,26 @@ sim_core_attach (SIM_DESC sd,
   if (cpu != NULL)
     sim_io_error (sd, "sim_core_map_attach - processor specific memory map not yet supported");
 
-  if ((access & access_read_write_exec) == 0
-      || (access & ~access_read_write_exec) != 0)
-    {
-#if (WITH_DEVICES)
-      device_error(client, "invalid access for core attach");
-#else
-      sim_io_error (sd, "invalid access for core attach");
-#endif
-    }
-
   /* verify modulo memory */
   if (!WITH_MODULO_MEMORY && modulo != 0)
     {
 #if (WITH_DEVICES)
       device_error (client, "sim_core_attach - internal error - modulo memory disabled");
-#else
-      sim_io_error (sd, "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");
-#else
-      sim_io_error (sd, "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
+      sim_io_error (sd, "sim_core_attach - internal error - modulo and callback memory conflict");
     }
   if (modulo != 0)
     {
@@ -331,9 +334,11 @@ sim_core_attach (SIM_DESC sd,
        {
 #if (WITH_DEVICES)
          device_error (client, "sim_core_attach - internal error - modulo %lx not power of two", (long) modulo);
-#else
-         sim_io_error (sd, "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
+         sim_io_error (sd, "sim_core_attach - internal error - modulo %lx not power of two", (long) modulo);
        }
     }
 
@@ -342,19 +347,19 @@ sim_core_attach (SIM_DESC sd,
     {
 #if (WITH_DEVICES)
       device_error (client, "sim_core_attach - internal error - conflicting buffer and attach arguments");
-#else
-      sim_io_error (sd, "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
+      sim_io_error (sd, "sim_core_attach - internal error - conflicting buffer and attach arguments");
     }
   if (client == NULL)
     {
       if (optional_buffer == NULL)
        {
          int padding = (addr % sizeof (unsigned64));
-         unsigned int bytes = (modulo == 0 ? nr_bytes : modulo) + padding;
-         free_buffer = xmalloc (bytes);
-         /* #if WITH_DETERMINISTIC_SIMULATION? */
-         memset (free_buffer, 0xa5, bytes);
+         unsigned long bytes = (modulo == 0 ? nr_bytes : modulo) + padding;
+         free_buffer = zalloc (bytes);
          buffer = (char*) free_buffer + padding;
        }
       else
@@ -371,39 +376,19 @@ sim_core_attach (SIM_DESC sd,
     }
 
   /* attach the region to all applicable access maps */
-  for (map = 0; 
-       map < nr_sim_core_maps;
+  for (map = 0;
+       map < nr_maps;
        map++)
     {
-      switch (map)
+      if (mapmask & (1 << map))
        {
-       case sim_core_read_map:
-         if (access & access_read)
-           sim_core_map_attach (sd, &memory->common.map[map],
-                                level, space, addr, nr_bytes, modulo,
-                                client, buffer, free_buffer);
-         free_buffer = NULL;
-         break;
-       case sim_core_write_map:
-         if (access & access_write)
-           sim_core_map_attach (sd, &memory->common.map[map],
-                                level, space, addr, nr_bytes, modulo,
-                                client, buffer, free_buffer);
-         free_buffer = NULL;
-         break;
-       case sim_core_execute_map:
-         if (access & access_exec)
-           sim_core_map_attach (sd, &memory->common.map[map],
-                                level, space, addr, nr_bytes, modulo,
-                                client, buffer, free_buffer);
+         sim_core_map_attach (sd, &memory->common.map[map],
+                              level, space, addr, nr_bytes, modulo,
+                              client, buffer, free_buffer);
          free_buffer = NULL;
-         break;
-       default:
-         sim_io_error (sd, "sim_core_attach - internal error - bad switch");
-         break;
        }
     }
-  
+
   /* Just copy this map to each of the processor specific data structures.
      FIXME - later this will be replaced by true processor specific
      maps. */
@@ -415,11 +400,12 @@ sim_core_attach (SIM_DESC sd,
       }
   }
 }
+#endif
 
 
 /* Remove any memory reference related to this address */
-STATIC_INLINE_SIM_CORE\
-(void)
+#if EXTERN_SIM_CORE_P
+static void
 sim_core_map_detach (SIM_DESC sd,
                     sim_core_map *access_map,
                     int level,
@@ -439,14 +425,15 @@ sim_core_map_detach (SIM_DESC sd,
          (*entry) = dead->next;
          if (dead->free_buffer != NULL)
            free (dead->free_buffer);
-         zfree (dead);
+         free (dead);
          return;
        }
     }
 }
+#endif
 
-EXTERN_SIM_CORE\
-(void)
+#if EXTERN_SIM_CORE_P
+void
 sim_core_detach (SIM_DESC sd,
                 sim_cpu *cpu,
                 int level,
@@ -454,8 +441,8 @@ sim_core_detach (SIM_DESC sd,
                 address_word addr)
 {
   sim_core *memory = STATE_CORE (sd);
-  sim_core_maps map;
-  for (map = 0; map < nr_sim_core_maps; map++)
+  unsigned map;
+  for (map = 0; map < nr_maps; map++)
     {
       sim_core_map_detach (sd, &memory->common.map[map],
                           level, address_space, addr);
@@ -471,18 +458,19 @@ sim_core_detach (SIM_DESC sd,
       }
   }
 }
+#endif
 
 
 STATIC_INLINE_SIM_CORE\
 (sim_core_mapping *)
-sim_core_find_mapping(sim_core_common *core,
-                     sim_core_maps map,
-                     address_word addr,
-                     unsigned nr_bytes,
-                     transfer_type transfer,
-                     int abort, /*either 0 or 1 - hint to inline/-O */
-                     sim_cpu *cpu, /* abort => cpu != NULL */
-                     sim_cia cia)
+sim_core_find_mapping (sim_core_common *core,
+                      unsigned map,
+                      address_word addr,
+                      unsigned nr_bytes,
+                      transfer_type transfer,
+                      int abort, /*either 0 or 1 - hint to inline/-O */
+                      sim_cpu *cpu, /* abort => cpu != NULL */
+                      sim_cia cia)
 {
   sim_core_mapping *mapping = core->map[map].first;
   ASSERT ((addr & (nr_bytes - 1)) == 0); /* must be aligned */
@@ -518,103 +506,142 @@ sim_core_translate (sim_core_mapping *mapping,
 }
 
 
-EXTERN_SIM_CORE\
-(unsigned)
+#if EXTERN_SIM_CORE_P
+unsigned
 sim_core_read_buffer (SIM_DESC sd,
                      sim_cpu *cpu,
-                     sim_core_maps map,
+                     unsigned map,
                      void *buffer,
                      address_word addr,
                      unsigned len)
 {
   sim_core_common *core = (cpu == NULL ? &STATE_CORE (sd)->common : &CPU_CORE (cpu)->common);
   unsigned count = 0;
-  while (count < len) {
-    unsigned_word raddr = addr + count;
+  while (count < len)
+ {
+    address_word raddr = addr + count;
     sim_core_mapping *mapping =
-      sim_core_find_mapping(core, map,
+      sim_core_find_mapping (core, map,
                            raddr, /*nr-bytes*/1,
                            read_transfer,
                            0 /*dont-abort*/, NULL, NULL_CIA);
     if (mapping == NULL)
       break;
 #if (WITH_DEVICES)
-    if (mapping->device != NULL) {
-      int nr_bytes = len - count;
-      if (raddr + nr_bytes - 1> mapping->bound)
-       nr_bytes = mapping->bound - raddr + 1;
-      if (device_io_read_buffer(mapping->device,
-                               (unsigned_1*)buffer + count,
-                               mapping->space,
-                               raddr,
-                               nr_bytes, 
-                               cpu, 
-                               CIA_GET(cpu)) != nr_bytes)
-       break;
-      count += nr_bytes;
-    }
-    else
+    if (mapping->device != NULL)
+      {
+       int nr_bytes = len - count;
+       sim_cia cia = cpu ? CIA_GET (cpu) : NULL_CIA;
+       if (raddr + nr_bytes - 1> mapping->bound)
+         nr_bytes = mapping->bound - raddr + 1;
+       if (device_io_read_buffer (mapping->device,
+                                  (unsigned_1*)buffer + count,
+                                  mapping->space,
+                                  raddr,
+                                  nr_bytes,
+                                  sd,
+                                  cpu,
+                                  cia) != nr_bytes)
+         break;
+       count += nr_bytes;
+       continue;
+      }
 #endif
+#if (WITH_HW)
+    if (mapping->device != NULL)
       {
-       ((unsigned_1*)buffer)[count] =
-         *(unsigned_1*)sim_core_translate(mapping, raddr);
-       count += 1;
+       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)
+         break;
+       count += nr_bytes;
+       continue;
       }
-  }
+#endif
+    ((unsigned_1*)buffer)[count] =
+      *(unsigned_1*)sim_core_translate (mapping, raddr);
+    count += 1;
+ }
   return count;
 }
+#endif
 
 
-EXTERN_SIM_CORE\
-(unsigned)
+#if EXTERN_SIM_CORE_P
+unsigned
 sim_core_write_buffer (SIM_DESC sd,
                       sim_cpu *cpu,
-                      sim_core_maps map,
+                      unsigned map,
                       const void *buffer,
                       address_word addr,
                       unsigned len)
 {
   sim_core_common *core = (cpu == NULL ? &STATE_CORE (sd)->common : &CPU_CORE (cpu)->common);
   unsigned count = 0;
-  while (count < len) {
-    unsigned_word raddr = addr + count;
-    sim_core_mapping *mapping =
-      sim_core_find_mapping(core, map,
-                           raddr, /*nr-bytes*/1,
-                           write_transfer,
-                           0 /*dont-abort*/, NULL, NULL_CIA);
-    if (mapping == NULL)
-      break;
-#if (WITH_DEVICES)
-    if (WITH_CALLBACK_MEMORY
-       && mapping->device != NULL) {
-      int nr_bytes = len - count;
-      if (raddr + nr_bytes - 1 > mapping->bound)
-       nr_bytes = mapping->bound - raddr + 1;
-      if (device_io_write_buffer(mapping->device,
-                                (unsigned_1*)buffer + count,
-                                mapping->space,
-                                raddr,
-                                nr_bytes,
-                                cpu, 
-                                CIA_GET(cpu)) != nr_bytes)
+  while (count < len)
+    {
+      address_word raddr = addr + count;
+      sim_core_mapping *mapping =
+       sim_core_find_mapping (core, map,
+                              raddr, /*nr-bytes*/1,
+                              write_transfer,
+                              0 /*dont-abort*/, NULL, NULL_CIA);
+      if (mapping == NULL)
        break;
-      count += nr_bytes;
-    }
-    else
+#if (WITH_DEVICES)
+      if (WITH_CALLBACK_MEMORY
+         && mapping->device != NULL)
+       {
+         int nr_bytes = len - count;
+         sim_cia cia = cpu ? CIA_GET (cpu) : NULL_CIA;
+         if (raddr + nr_bytes - 1 > mapping->bound)
+           nr_bytes = mapping->bound - raddr + 1;
+         if (device_io_write_buffer (mapping->device,
+                                     (unsigned_1*)buffer + count,
+                                     mapping->space,
+                                     raddr,
+                                     nr_bytes,
+                                     sd,
+                                     cpu,
+                                     cia) != nr_bytes)
+           break;
+         count += nr_bytes;
+         continue;
+       }
 #endif
-      {
-       *(unsigned_1*)sim_core_translate(mapping, raddr) =
-         ((unsigned_1*)buffer)[count];
-       count += 1;
-      }
-  }
+#if (WITH_HW)
+      if (WITH_CALLBACK_MEMORY
+         && 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)
+           break;
+         count += nr_bytes;
+         continue;
+       }
+#endif
+      *(unsigned_1*)sim_core_translate (mapping, raddr) =
+       ((unsigned_1*)buffer)[count];
+      count += 1;
+    }
   return count;
 }
+#endif
 
 
-EXTERN_SIM_CORE\
-(void)
+#if EXTERN_SIM_CORE_P
+void
 sim_core_set_xor (SIM_DESC sd,
                  sim_cpu *cpu,
                  int is_xor)
@@ -645,18 +672,20 @@ sim_core_set_xor (SIM_DESC sd,
            core->byte_xor = WITH_XOR_ENDIAN - 1;
          else
            core->byte_xor = 0;
-       }         
+       }
     }
   }
   else {
     if (is_xor)
-      sim_engine_abort (sd, cpu, NULL_CIA,
+      sim_engine_abort (sd, NULL, NULL_CIA,
                        "Attempted to enable xor-endian mode when permenantly disabled.");
   }
 }
+#endif
 
-STATIC_INLINE_SIM_CORE\
-(void)
+
+#if EXTERN_SIM_CORE_P
+static void
 reverse_n (unsigned_1 *dest,
           const unsigned_1 *src,
           int nr_bytes)
@@ -667,13 +696,14 @@ reverse_n (unsigned_1 *dest,
       dest [nr_bytes - i - 1] = src [i];
     }
 }
+#endif
 
 
-EXTERN_SIM_CORE\
-(unsigned)
+#if EXTERN_SIM_CORE_P
+unsigned
 sim_core_xor_read_buffer (SIM_DESC sd,
                          sim_cpu *cpu,
-                         sim_core_maps map,
+                         unsigned map,
                          void *buffer,
                          address_word addr,
                          unsigned nr_bytes)
@@ -718,13 +748,14 @@ sim_core_xor_read_buffer (SIM_DESC sd,
       return nr_bytes;
     }
 }
-  
-  
-EXTERN_SIM_CORE\
-(unsigned)
+#endif
+
+
+#if EXTERN_SIM_CORE_P
+unsigned
 sim_core_xor_write_buffer (SIM_DESC sd,
                           sim_cpu *cpu,
-                          sim_core_maps map,
+                          unsigned map,
                           const void *buffer,
                           address_word addr,
                           unsigned nr_bytes)
@@ -769,6 +800,26 @@ sim_core_xor_write_buffer (SIM_DESC sd,
       return nr_bytes;
     }
 }
+#endif
+
+#if EXTERN_SIM_CORE_P
+void *
+sim_core_trans_addr (SIM_DESC sd,
+                     sim_cpu *cpu,
+                     unsigned map,
+                     address_word addr)
+{
+  sim_core_common *core = (cpu == NULL ? &STATE_CORE (sd)->common : &CPU_CORE (cpu)->common);
+  sim_core_mapping *mapping =
+    sim_core_find_mapping (core, map,
+                           addr, /*nr-bytes*/1,
+                           write_transfer,
+                           0 /*dont-abort*/, NULL, NULL_CIA);
+  if (mapping == NULL)
+    return NULL;
+  return sim_core_translate (mapping, addr);
+}
+#endif