* core.c: Rename to corefile.c
authorFred Fish <fnf@specifix.com>
Sun, 5 Nov 1995 05:40:15 +0000 (05:40 +0000)
committerFred Fish <fnf@specifix.com>
Sun, 5 Nov 1995 05:40:15 +0000 (05:40 +0000)
* core.h:  Rename to corefile.h
* inline.c: Include corefile.h, renamed from core.h.
* cpu.h: Include corefile.h, renamed from core.h
* vm.c: Include corefile.h, renamed from core.h
* Makefile.in (CPU_H): Change core.h to corefile.h
(vm.o):  Change dependency to corefile.h
(LIB_SRC): Change core.c to corefile.c.
(LIB_OBJ): Change core.o to corefile.o.
(corefile.o):  Change dependencies to corefile.c, corefile.h.
* corefile.c: Include corefile.h rather than core.h
* README.psim (KNOWN PROBLEMS): Change core.* references to corefile.*
references.

sim/ppc/.Sanitize
sim/ppc/ChangeLog
sim/ppc/Makefile.in
sim/ppc/README.psim
sim/ppc/core.c [deleted file]
sim/ppc/core.h [deleted file]
sim/ppc/corefile.c [new file with mode: 0644]
sim/ppc/cpu.h
sim/ppc/inline.c [new file with mode: 0644]
sim/ppc/vm.c

index db2cd3617e59b967d0ba84594e488bb0de8c0f10..b5b07fac1402bf0ef3e801d3b9b4d668a365d74b 100644 (file)
@@ -37,8 +37,8 @@ config.make
 config.hdr
 configure
 configure.in
-core.c
-core.h
+corefile.c
+corefile.h
 core_n.h
 cpu.c
 cpu.h
index 67011519b442123e94e7a143371e0e160efcfb65..0d34501a5fad5b5ec793d6ea3536b153c33b0965 100644 (file)
@@ -1,3 +1,19 @@
+Sat Nov  4 12:29:45 1995  Fred Fish  <fnf@cygnus.com>
+
+       * core.c:  Rename to corefile.c
+       * core.h:  Rename to corefile.h
+       * inline.c: Include corefile.h, renamed from core.h.
+       * cpu.h: Include corefile.h, renamed from core.h
+       * vm.c: Include corefile.h, renamed from core.h
+       * corefile.c: Include corefile.h rather than core.h
+       * README.psim (KNOWN PROBLEMS): Change core.* references to corefile.*
+       references.
+       * Makefile.in (CPU_H): Change core.h to corefile.h
+       (vm.o):  Change dependency to corefile.h
+       (LIB_SRC): Change core.c to corefile.c.
+       (LIB_OBJ): Change core.o to corefile.o.
+       (corefile.o):  Change dependencies to corefile.c, corefile.h.
+
 Fri Nov  3 11:37:24 1995  Michael Meissner  <meissner@tiktok.cygnus.com>
 
        * ppc-instructions (data cache instructions): Make all data cache
index b56e6e50d794794f8d7bcbbf4e2197df70965217..f893ceee73de28eef478235d9c34cd0ce07e3875 100644 (file)
@@ -156,7 +156,7 @@ CPU_H = \
        $(BASICS_H) \
        $(REGISTERS_H) \
        device_tree.h \
-       core.h \
+       corefile.h \
        vm.h \
        events.h \
        interrupts.h \
@@ -191,7 +191,7 @@ LIB_SRC = \
        debug.c \
        ppc-endian.c \
        vm.c \
-       core.c \
+       corefile.c \
        events.c \
        os_emul.c \
        emul_generic.c \
@@ -220,7 +220,7 @@ LIB_OBJ = \
        emul_netbsd.o \
        registers.o \
        vm.o \
-       core.o \
+       corefile.o \
        spreg.o \
        cpu.o \
        interrupts.o \
@@ -276,9 +276,9 @@ idecode.o: idecode.c $(CPU_H) $(IDECODE_H) semantics.h
 # double.o: double.c dp-bit.c
 
 vm.o: vm.c vm.h vm_n.h $(BASICS_H) $(REGISTERS_H) \
-       device_tree.h core.h interrupts.h itable.h mon.h
+       device_tree.h corefile.h interrupts.h itable.h mon.h
 
-core.o: core.c core.h $(BASICS_H) device_tree.h
+corefile.o: corefile.c corefile.h $(BASICS_H) device_tree.h
 
 events.o: events.c events.h $(BASICS_H) 
 
index 89bf36965a4d2422e2c0df4cc3b6d7250a905fca..fe2e36fb8d1551310b65c3a7c660699e9471475e 100644 (file)
@@ -203,7 +203,7 @@ KNOWN PROBLEMS:
 
 See the ChangeLog file looking for lines taged with the word FIXME.
 
-CORE.C: The implementation of core.c (defined by core.h) isn't the
+COREFILE.C: The implementation of corefile.c (defined by corefile.h) isn't the
 best.  It is intended to be functionaly correct rather than fast.
 
 HTAB (page) code for OEA model untested.  Some of the vm code
diff --git a/sim/ppc/core.c b/sim/ppc/core.c
deleted file mode 100644 (file)
index 4acf0a3..0000000
+++ /dev/null
@@ -1,497 +0,0 @@
-/*  This file is part of the program psim.
-
-    Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
-
-    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.
-
-    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.
-    */
-
-
-#ifndef _CORE_C_
-#define _CORE_C_
-
-#ifndef STATIC_INLINE_CORE
-#define STATIC_INLINE_CORE STATIC_INLINE
-#endif
-
-
-#include "basics.h"
-#include "device_tree.h"
-#include "core.h"
-
-
-typedef struct _core_mapping core_mapping;
-struct _core_mapping {
-  /* ram map */
-  int free_buffer;
-  void *buffer;
-  /* device map */
-  const device *device;
-  device_io_read_buffer_callback *reader;
-  device_io_write_buffer_callback *writer;
-  /* common */
-  int space;
-  unsigned_word base;
-  unsigned_word bound;
-  unsigned nr_bytes;
-  core_mapping *next;
-};
-
-struct _core_map {
-  core_mapping *first;
-  core_mapping *default_map;
-};
-
-typedef enum {
-  core_read_map,
-  core_write_map,
-  core_execute_map,
-  nr_core_map_types,
-} core_map_types;
-
-struct _core {
-  core_map map[nr_core_map_types];
-};
-
-
-INLINE_CORE core *
-core_create(void)
-{
-  core *new_core = ZALLOC(core);
-  return new_core;
-}
-
-
-STATIC_INLINE_CORE void
-core_init(core *memory)
-{
-  core_map_types access_type;
-  for (access_type = 0;
-       access_type < nr_core_map_types;
-       access_type++) {
-    core_map *map = memory->map + access_type;
-    /* blow away old mappings */
-    core_mapping *curr = map->first;
-    while (curr != NULL) {
-      core_mapping *tbd = curr;
-      curr = curr->next;
-      if (tbd->free_buffer) {
-       ASSERT(tbd->buffer != NULL);
-       zfree(tbd->buffer);
-      }
-      zfree(tbd);
-    }
-    map->first = NULL;
-    /* blow away the default */
-    if (map->default_map != NULL) {
-      ASSERT(map->default_map->buffer == NULL);
-      zfree(map->default_map);
-    }
-    map->default_map = NULL;
-  }
-}
-
-
-
-/* the core has three sub mappings that the more efficient
-   read/write fixed quantity functions use */
-
-INLINE_CORE core_map *
-core_readable(core *memory)
-{
-  return memory->map + core_read_map;
-}
-
-INLINE_CORE core_map *
-core_writeable(core *memory)
-{
-  return memory->map + core_write_map;
-}
-
-INLINE_CORE core_map *
-core_executable(core *memory)
-{
-  return memory->map + core_execute_map;
-}
-
-
-
-STATIC_INLINE_CORE core_mapping *
-new_core_mapping(attach_type attach,
-                int space,
-                unsigned_word addr,
-                unsigned nr_bytes,
-                const device *device,
-                void *buffer,
-                int free_buffer)
-{
-  core_mapping *new_mapping = ZALLOC(core_mapping);
-  switch (attach) {
-  case attach_default:
-  case attach_callback:
-    new_mapping->device = device;
-    new_mapping->reader = device->callback->io_read_buffer;
-    new_mapping->writer = device->callback->io_write_buffer;
-    break;
-  case attach_raw_memory:
-    new_mapping->buffer = buffer;
-    new_mapping->free_buffer = free_buffer;
-    break;
-  default:
-    error("new_core_mapping() - internal error - unknown attach type %d\n",
-         attach);
-  }
-  /* common */
-  new_mapping->space = space;
-  new_mapping->base = addr;
-  new_mapping->nr_bytes = nr_bytes;
-  new_mapping->bound = addr + (nr_bytes - 1);
-  return new_mapping;
-}
-
-
-STATIC_INLINE_CORE void
-core_map_attach(core_map *access_map,
-               attach_type attach,
-               int space,
-               unsigned_word addr,
-               unsigned nr_bytes, /* host limited */
-               const device *device, /*callback/default*/
-               void *buffer, /*raw_memory*/
-               int free_buffer) /*raw_memory*/
-{
-  if (attach == attach_default) {
-    if (access_map->default_map != NULL)
-      error("core_map_attach() default mapping already in place\n");
-    ASSERT(buffer == NULL);
-    access_map->default_map = new_core_mapping(attach, 
-                                              space, addr, nr_bytes,
-                                              device, buffer, free_buffer);
-  }
-  else {
-    /* find the insertion point for this additional mapping and insert */
-    core_mapping *next_mapping;
-    core_mapping **last_mapping;
-
-    /* actually do occasionally get a zero size map */
-    if (nr_bytes == 0)
-      error("core_map_attach() size == 0\n");
-
-    /* find the insertion point (between last/next) */
-    next_mapping = access_map->first;
-    last_mapping = &access_map->first;
-    while(next_mapping != NULL && next_mapping->bound < addr) {
-      /* assert: next_mapping->base > all bases before next_mapping */
-      /* assert: next_mapping->bound >= all bounds before next_mapping */
-      last_mapping = &next_mapping->next;
-      next_mapping = next_mapping->next;
-    }
-
-    /* check insertion point correct */
-    if (next_mapping != NULL && next_mapping->base < (addr + (nr_bytes - 1))) {
-      error("core_map_attach() map overlap\n");
-    }
-
-    /* create/insert the new mapping */
-    *last_mapping = new_core_mapping(attach,
-                                    space, addr, nr_bytes,
-                                    device, buffer, free_buffer);
-    (*last_mapping)->next = next_mapping;
-  }
-}
-
-
-INLINE_CORE void
-core_attach(core *memory,
-           attach_type attach,
-           int space,
-           access_type access,
-           unsigned_word addr,
-           unsigned nr_bytes, /* host limited */
-           const device *device) /*callback/default*/
-{
-  core_map_types access_map;
-  int free_buffer = 0;
-  void *buffer = NULL;
-  ASSERT(attach == attach_default || nr_bytes > 0);
-  if (attach == attach_raw_memory)
-    buffer = zalloc(nr_bytes);
-  for (access_map = 0; 
-       access_map < nr_core_map_types;
-       access_map++) {
-    switch (access_map) {
-    case core_read_map:
-      if (access & access_read)
-       core_map_attach(memory->map + access_map,
-                       attach,
-                       space, addr, nr_bytes,
-                       device, buffer, !free_buffer);
-      free_buffer ++;
-      break;
-    case core_write_map:
-      if (access & access_write)
-       core_map_attach(memory->map + access_map,
-                       attach,
-                       space, addr, nr_bytes,
-                       device, buffer, !free_buffer);
-      free_buffer ++;
-      break;
-    case core_execute_map:
-      if (access & access_exec)
-       core_map_attach(memory->map + access_map,
-                       attach,
-                       space, addr, nr_bytes,
-                       device, buffer, !free_buffer);
-      free_buffer ++;
-      break;
-    default:
-      error("core_attach() internal error\n");
-      break;
-    }
-  }
-  ASSERT(free_buffer > 0); /* must attach to at least one thing */
-}
-
-
-STATIC_INLINE_CORE core_mapping *
-core_map_find_mapping(core_map *map,
-                     unsigned_word addr,
-                     unsigned nr_bytes,
-                     cpu *processor,
-                     unsigned_word cia,
-                     int abort) /*either 0 or 1 - helps inline */
-{
-  core_mapping *mapping = map->first;
-  ASSERT((addr & (nr_bytes - 1)) == 0); /* must be aligned */
-  ASSERT((addr + (nr_bytes - 1)) >= addr); /* must not wrap */
-  while (mapping != NULL) {
-    if (addr >= mapping->base
-       && (addr + (nr_bytes - 1)) <= mapping->bound)
-      return mapping;
-    mapping = mapping->next;
-  }
-  if (map->default_map != NULL)
-    return map->default_map;
-  if (abort)
-    error("core_find_mapping() - access to unmaped address, attach a default map to handle this - addr=0x%x nr_bytes=0x%x processor=0x%x cia=0x%x\n",
-         addr, nr_bytes, processor, cia);
-  return NULL;
-}
-
-
-STATIC_INLINE_CORE void *
-core_translate(core_mapping *mapping,
-                    unsigned_word addr)
-{
-  return mapping->buffer + addr - mapping->base;
-}
-
-
-INLINE_CORE unsigned
-core_map_read_buffer(core_map *map,
-                    void *buffer,
-                    unsigned_word addr,
-                    unsigned len)
-{
-  unsigned count;
-  unsigned_1 byte;
-  for (count = 0; count < len; count++) {
-    unsigned_word raddr = addr + count;
-    core_mapping *mapping =
-      core_map_find_mapping(map,
-                           raddr, 1,
-                           NULL, /*processor*/
-                           0, /*cia*/
-                           0); /*dont-abort*/
-    if (mapping == NULL)
-      break;
-    if (mapping->reader != NULL) {
-      if (mapping->reader(mapping->device,
-                         &byte,
-                         mapping->space,
-                         raddr - mapping->base,
-                         1, /* nr_bytes */
-                         0, /*processor*/
-                         0 /*cpu*/) != 1)
-       break;
-    }
-    else
-      byte = *(unsigned_1*)core_translate(mapping,
-                                               raddr);
-    ((unsigned_1*)buffer)[count] = T2H_1(byte);
-  }
-  return count;
-}
-
-
-INLINE_CORE unsigned
-core_map_write_buffer(core_map *map,
-                     const void *buffer,
-                     unsigned_word addr,
-                     unsigned len)
-{
-  unsigned count;
-  unsigned_1 byte;
-  for (count = 0; count < len; count++) {
-    unsigned_word raddr = addr + count;
-    core_mapping *mapping = core_map_find_mapping(map,
-                                                 raddr, 1,
-                                                 NULL, /*processor*/
-                                                 0, /*cia*/
-                                                 0); /*dont-abort*/
-    if (mapping == NULL)
-      break;
-    byte = H2T_1(((unsigned_1*)buffer)[count]);
-    if (mapping->writer != NULL) {
-      if (mapping->writer(mapping->device,
-                         &byte,
-                         mapping->space,
-                         raddr - mapping->base,
-                         1, /*nr_bytes*/
-                         0, /*processor*/
-                         0 /*cpu*/) != 1)
-       break;
-    }
-    else
-      *(unsigned_1*)core_translate(mapping, raddr) = byte;
-  }
-  return count;
-}
-
-
-
-/* Top level core(root) device: core@garbage
-
-   The core device captures incomming dma requests and changes them to
-   outgoing io requests. */
-
-STATIC_INLINE_CORE void
-core_init_callback(const device *me,
-                  psim *system)
-{
-  core *memory = (core*)me->data;
-  DTRACE_INIT(core);
-  core_init(memory);
-}
-
-
-STATIC_INLINE_CORE void
-core_attach_address_callback(const device *me,
-                            const char *name,
-                            attach_type attach,
-                            int space,
-                            unsigned_word addr,
-                            unsigned nr_bytes,
-                            access_type access,
-                            const device *who) /*callback/default*/
-{
-  core *memory = (core*)me->data;
-  unsigned_word device_address;
-  DTRACE_ATTACH_ADDRESS(core);
-  if (space != 0)
-    error("core_attach_address_callback() invalid address space\n");
-  core_attach(memory,
-             attach,
-             space,
-             access,
-             addr,
-             nr_bytes,
-             who);
-}
-
-
-STATIC_INLINE_CORE unsigned
-core_dma_read_buffer_callback(const device *me,
-                             void *dest,
-                             int space,
-                             unsigned_word addr,
-                             unsigned nr_bytes)
-{
-  core *memory = (core*)me->data;
-  DTRACE_DMA_READ_BUFFER(core);
-  return core_map_read_buffer(core_readable(memory),
-                             dest,
-                             addr,
-                             nr_bytes);
-}
-
-
-STATIC_INLINE_CORE unsigned
-core_dma_write_buffer_callback(const device *me,
-                              const void *source,
-                              int space,
-                              unsigned_word addr,
-                              unsigned nr_bytes,
-                              int violate_read_only_section)
-{
-  core *memory = (core*)me->data;
-  core_map *map = (violate_read_only_section
-                  ? core_readable(memory)
-                  : core_writeable(memory));
-  DTRACE_DMA_WRITE_BUFFER(core);
-  return core_map_write_buffer(map,
-                              source,
-                              addr,
-                              nr_bytes);
-}
-
-
-static device_callbacks const core_callbacks = {
-  core_init_callback,
-  core_attach_address_callback,
-  unimp_device_detach_address,
-  unimp_device_io_read_buffer,
-  unimp_device_io_write_buffer,
-  core_dma_read_buffer_callback,
-  core_dma_write_buffer_callback,
-  unimp_device_attach_interrupt,
-  unimp_device_detach_interrupt,
-  unimp_device_interrupt,
-  unimp_device_interrupt_ack,
-  unimp_device_ioctl,
-};
-
-
-INLINE_CORE const device *
-core_device_create(core *memory)
-{
-  return device_create_from("core", "/", memory, &core_callbacks, NULL);
-}
-
-
-
-/* define the read/write 1/2/4/8/word functions */
-
-#undef N
-#define N 1
-#include "core_n.h"
-
-#undef N
-#define N 2
-#include "core_n.h"
-
-#undef N
-#define N 4
-#include "core_n.h"
-
-#undef N
-#define N 8
-#include "core_n.h"
-
-#undef N
-#define N word
-#include "core_n.h"
-
-#endif /* _CORE_C_ */
diff --git a/sim/ppc/core.h b/sim/ppc/core.h
deleted file mode 100644 (file)
index 38871e6..0000000
+++ /dev/null
@@ -1,155 +0,0 @@
-/*  This file is part of the program psim.
-
-    Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
-
-    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.
-
-    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.
-    */
-
-
-#ifndef _CORE_H_
-#define _CORE_H_
-
-#ifndef INLINE_CORE
-#define INLINE_CORE
-#endif
-
-/* basic types */
-
-typedef struct _core core;
-typedef struct _core_map core_map;
-
-/* constructor */
-
-INLINE_CORE core *core_create
-(void);
-
-INLINE_CORE const device *core_device_create
-(core *);
-
-
-
-/* the core has three sub mappings that the more efficient
-   read/write fixed quantity functions use */
-
-INLINE_CORE core_map *core_readable
-(core *memory);
-
-INLINE_CORE core_map *core_writeable
-(core *memory);
-
-INLINE_CORE core_map *core_executable
-(core *memory);
-
-
-
-/* operators to add/remove a mapping in the core
-
-   callback-memory:
-
-   All access are passed onto the specified devices callback routines
-   after being `translated'.  DEFAULT indicates that the specified
-   memory should be called if all other mappings fail.
-   
-   For callback-memory, the device must be specified.
-
-   raw-memory:
-
-   While RAM could be implemented using the callback interface
-   core instead treats it as the common case including the code
-   directly in the read/write operators.
-
-   For raw-memory, the device is ignored and the core alloc's a
-   block to act as the memory.
-
-   default-memory:
-
-   Should, for the core, there be no defined mapping for a given
-   address then the default map (if present) is called.
-
-   For default-memory, the device must be specified. */
-
-INLINE_CORE void core_attach
-(core *map,
- attach_type attach,
- int address_space,
- access_type access,
- unsigned_word addr,
- unsigned nr_bytes, /* host limited */
- const device *device); /*callback/default*/
-
-INLINE_CORE void core_detach
-(core *map,
- attach_type attach,
- int address_space,
- unsigned_word addr,
- unsigned nr_bytes, /* host limited */
- access_type access,
- const device *device); /*callback/default*/
-
-
-/* Variable sized read/write:
-
-   Transfer (zero) a variable size block of data between the host and
-   target (possibly byte swapping it).  Should any problems occure,
-   the number of bytes actually transfered is returned. */
-
-INLINE_CORE unsigned core_map_read_buffer
-(core_map *map,
- void *buffer,
- unsigned_word addr,
- unsigned nr_bytes);
-
-INLINE_CORE unsigned core_map_write_buffer
-(core_map *map,
- const void *buffer,
- unsigned_word addr,
- unsigned nr_bytes);
-
-
-/* Fixed sized read/write:
-
-   Transfer a fixed amout of memory between the host and target.  The
-   memory always being translated and the operation always aborting
-   should a problem occure */
-
-#define DECLARE_CORE_WRITE_N(N) \
-INLINE_CORE void core_map_write_##N \
-(core_map *map, \
- unsigned_word addr, \
- unsigned_##N val, \
- cpu *processor, \
- unsigned_word cia);
-
-DECLARE_CORE_WRITE_N(1)
-DECLARE_CORE_WRITE_N(2)
-DECLARE_CORE_WRITE_N(4)
-DECLARE_CORE_WRITE_N(8)
-DECLARE_CORE_WRITE_N(word)
-
-#define DECLARE_CORE_READ_N(N) \
-INLINE_CORE unsigned_##N core_map_read_##N \
-(core_map *map, \
- unsigned_word addr, \
- cpu *processor, \
- unsigned_word cia);
-
-DECLARE_CORE_READ_N(1)
-DECLARE_CORE_READ_N(2)
-DECLARE_CORE_READ_N(4)
-DECLARE_CORE_READ_N(8)
-DECLARE_CORE_READ_N(word)
-
-#endif
diff --git a/sim/ppc/corefile.c b/sim/ppc/corefile.c
new file mode 100644 (file)
index 0000000..1c67357
--- /dev/null
@@ -0,0 +1,497 @@
+/*  This file is part of the program psim.
+
+    Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
+
+    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.
+
+    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.
+    */
+
+
+#ifndef _CORE_C_
+#define _CORE_C_
+
+#ifndef STATIC_INLINE_CORE
+#define STATIC_INLINE_CORE STATIC_INLINE
+#endif
+
+
+#include "basics.h"
+#include "device_tree.h"
+#include "corefile.h"
+
+
+typedef struct _core_mapping core_mapping;
+struct _core_mapping {
+  /* ram map */
+  int free_buffer;
+  void *buffer;
+  /* device map */
+  const device *device;
+  device_io_read_buffer_callback *reader;
+  device_io_write_buffer_callback *writer;
+  /* common */
+  int space;
+  unsigned_word base;
+  unsigned_word bound;
+  unsigned nr_bytes;
+  core_mapping *next;
+};
+
+struct _core_map {
+  core_mapping *first;
+  core_mapping *default_map;
+};
+
+typedef enum {
+  core_read_map,
+  core_write_map,
+  core_execute_map,
+  nr_core_map_types,
+} core_map_types;
+
+struct _core {
+  core_map map[nr_core_map_types];
+};
+
+
+INLINE_CORE core *
+core_create(void)
+{
+  core *new_core = ZALLOC(core);
+  return new_core;
+}
+
+
+STATIC_INLINE_CORE void
+core_init(core *memory)
+{
+  core_map_types access_type;
+  for (access_type = 0;
+       access_type < nr_core_map_types;
+       access_type++) {
+    core_map *map = memory->map + access_type;
+    /* blow away old mappings */
+    core_mapping *curr = map->first;
+    while (curr != NULL) {
+      core_mapping *tbd = curr;
+      curr = curr->next;
+      if (tbd->free_buffer) {
+       ASSERT(tbd->buffer != NULL);
+       zfree(tbd->buffer);
+      }
+      zfree(tbd);
+    }
+    map->first = NULL;
+    /* blow away the default */
+    if (map->default_map != NULL) {
+      ASSERT(map->default_map->buffer == NULL);
+      zfree(map->default_map);
+    }
+    map->default_map = NULL;
+  }
+}
+
+
+
+/* the core has three sub mappings that the more efficient
+   read/write fixed quantity functions use */
+
+INLINE_CORE core_map *
+core_readable(core *memory)
+{
+  return memory->map + core_read_map;
+}
+
+INLINE_CORE core_map *
+core_writeable(core *memory)
+{
+  return memory->map + core_write_map;
+}
+
+INLINE_CORE core_map *
+core_executable(core *memory)
+{
+  return memory->map + core_execute_map;
+}
+
+
+
+STATIC_INLINE_CORE core_mapping *
+new_core_mapping(attach_type attach,
+                int space,
+                unsigned_word addr,
+                unsigned nr_bytes,
+                const device *device,
+                void *buffer,
+                int free_buffer)
+{
+  core_mapping *new_mapping = ZALLOC(core_mapping);
+  switch (attach) {
+  case attach_default:
+  case attach_callback:
+    new_mapping->device = device;
+    new_mapping->reader = device->callback->io_read_buffer;
+    new_mapping->writer = device->callback->io_write_buffer;
+    break;
+  case attach_raw_memory:
+    new_mapping->buffer = buffer;
+    new_mapping->free_buffer = free_buffer;
+    break;
+  default:
+    error("new_core_mapping() - internal error - unknown attach type %d\n",
+         attach);
+  }
+  /* common */
+  new_mapping->space = space;
+  new_mapping->base = addr;
+  new_mapping->nr_bytes = nr_bytes;
+  new_mapping->bound = addr + (nr_bytes - 1);
+  return new_mapping;
+}
+
+
+STATIC_INLINE_CORE void
+core_map_attach(core_map *access_map,
+               attach_type attach,
+               int space,
+               unsigned_word addr,
+               unsigned nr_bytes, /* host limited */
+               const device *device, /*callback/default*/
+               void *buffer, /*raw_memory*/
+               int free_buffer) /*raw_memory*/
+{
+  if (attach == attach_default) {
+    if (access_map->default_map != NULL)
+      error("core_map_attach() default mapping already in place\n");
+    ASSERT(buffer == NULL);
+    access_map->default_map = new_core_mapping(attach, 
+                                              space, addr, nr_bytes,
+                                              device, buffer, free_buffer);
+  }
+  else {
+    /* find the insertion point for this additional mapping and insert */
+    core_mapping *next_mapping;
+    core_mapping **last_mapping;
+
+    /* actually do occasionally get a zero size map */
+    if (nr_bytes == 0)
+      error("core_map_attach() size == 0\n");
+
+    /* find the insertion point (between last/next) */
+    next_mapping = access_map->first;
+    last_mapping = &access_map->first;
+    while(next_mapping != NULL && next_mapping->bound < addr) {
+      /* assert: next_mapping->base > all bases before next_mapping */
+      /* assert: next_mapping->bound >= all bounds before next_mapping */
+      last_mapping = &next_mapping->next;
+      next_mapping = next_mapping->next;
+    }
+
+    /* check insertion point correct */
+    if (next_mapping != NULL && next_mapping->base < (addr + (nr_bytes - 1))) {
+      error("core_map_attach() map overlap\n");
+    }
+
+    /* create/insert the new mapping */
+    *last_mapping = new_core_mapping(attach,
+                                    space, addr, nr_bytes,
+                                    device, buffer, free_buffer);
+    (*last_mapping)->next = next_mapping;
+  }
+}
+
+
+INLINE_CORE void
+core_attach(core *memory,
+           attach_type attach,
+           int space,
+           access_type access,
+           unsigned_word addr,
+           unsigned nr_bytes, /* host limited */
+           const device *device) /*callback/default*/
+{
+  core_map_types access_map;
+  int free_buffer = 0;
+  void *buffer = NULL;
+  ASSERT(attach == attach_default || nr_bytes > 0);
+  if (attach == attach_raw_memory)
+    buffer = zalloc(nr_bytes);
+  for (access_map = 0; 
+       access_map < nr_core_map_types;
+       access_map++) {
+    switch (access_map) {
+    case core_read_map:
+      if (access & access_read)
+       core_map_attach(memory->map + access_map,
+                       attach,
+                       space, addr, nr_bytes,
+                       device, buffer, !free_buffer);
+      free_buffer ++;
+      break;
+    case core_write_map:
+      if (access & access_write)
+       core_map_attach(memory->map + access_map,
+                       attach,
+                       space, addr, nr_bytes,
+                       device, buffer, !free_buffer);
+      free_buffer ++;
+      break;
+    case core_execute_map:
+      if (access & access_exec)
+       core_map_attach(memory->map + access_map,
+                       attach,
+                       space, addr, nr_bytes,
+                       device, buffer, !free_buffer);
+      free_buffer ++;
+      break;
+    default:
+      error("core_attach() internal error\n");
+      break;
+    }
+  }
+  ASSERT(free_buffer > 0); /* must attach to at least one thing */
+}
+
+
+STATIC_INLINE_CORE core_mapping *
+core_map_find_mapping(core_map *map,
+                     unsigned_word addr,
+                     unsigned nr_bytes,
+                     cpu *processor,
+                     unsigned_word cia,
+                     int abort) /*either 0 or 1 - helps inline */
+{
+  core_mapping *mapping = map->first;
+  ASSERT((addr & (nr_bytes - 1)) == 0); /* must be aligned */
+  ASSERT((addr + (nr_bytes - 1)) >= addr); /* must not wrap */
+  while (mapping != NULL) {
+    if (addr >= mapping->base
+       && (addr + (nr_bytes - 1)) <= mapping->bound)
+      return mapping;
+    mapping = mapping->next;
+  }
+  if (map->default_map != NULL)
+    return map->default_map;
+  if (abort)
+    error("core_find_mapping() - access to unmaped address, attach a default map to handle this - addr=0x%x nr_bytes=0x%x processor=0x%x cia=0x%x\n",
+         addr, nr_bytes, processor, cia);
+  return NULL;
+}
+
+
+STATIC_INLINE_CORE void *
+core_translate(core_mapping *mapping,
+                    unsigned_word addr)
+{
+  return mapping->buffer + addr - mapping->base;
+}
+
+
+INLINE_CORE unsigned
+core_map_read_buffer(core_map *map,
+                    void *buffer,
+                    unsigned_word addr,
+                    unsigned len)
+{
+  unsigned count;
+  unsigned_1 byte;
+  for (count = 0; count < len; count++) {
+    unsigned_word raddr = addr + count;
+    core_mapping *mapping =
+      core_map_find_mapping(map,
+                           raddr, 1,
+                           NULL, /*processor*/
+                           0, /*cia*/
+                           0); /*dont-abort*/
+    if (mapping == NULL)
+      break;
+    if (mapping->reader != NULL) {
+      if (mapping->reader(mapping->device,
+                         &byte,
+                         mapping->space,
+                         raddr - mapping->base,
+                         1, /* nr_bytes */
+                         0, /*processor*/
+                         0 /*cpu*/) != 1)
+       break;
+    }
+    else
+      byte = *(unsigned_1*)core_translate(mapping,
+                                               raddr);
+    ((unsigned_1*)buffer)[count] = T2H_1(byte);
+  }
+  return count;
+}
+
+
+INLINE_CORE unsigned
+core_map_write_buffer(core_map *map,
+                     const void *buffer,
+                     unsigned_word addr,
+                     unsigned len)
+{
+  unsigned count;
+  unsigned_1 byte;
+  for (count = 0; count < len; count++) {
+    unsigned_word raddr = addr + count;
+    core_mapping *mapping = core_map_find_mapping(map,
+                                                 raddr, 1,
+                                                 NULL, /*processor*/
+                                                 0, /*cia*/
+                                                 0); /*dont-abort*/
+    if (mapping == NULL)
+      break;
+    byte = H2T_1(((unsigned_1*)buffer)[count]);
+    if (mapping->writer != NULL) {
+      if (mapping->writer(mapping->device,
+                         &byte,
+                         mapping->space,
+                         raddr - mapping->base,
+                         1, /*nr_bytes*/
+                         0, /*processor*/
+                         0 /*cpu*/) != 1)
+       break;
+    }
+    else
+      *(unsigned_1*)core_translate(mapping, raddr) = byte;
+  }
+  return count;
+}
+
+
+
+/* Top level core(root) device: core@garbage
+
+   The core device captures incomming dma requests and changes them to
+   outgoing io requests. */
+
+STATIC_INLINE_CORE void
+core_init_callback(const device *me,
+                  psim *system)
+{
+  core *memory = (core*)me->data;
+  DTRACE_INIT(core);
+  core_init(memory);
+}
+
+
+STATIC_INLINE_CORE void
+core_attach_address_callback(const device *me,
+                            const char *name,
+                            attach_type attach,
+                            int space,
+                            unsigned_word addr,
+                            unsigned nr_bytes,
+                            access_type access,
+                            const device *who) /*callback/default*/
+{
+  core *memory = (core*)me->data;
+  unsigned_word device_address;
+  DTRACE_ATTACH_ADDRESS(core);
+  if (space != 0)
+    error("core_attach_address_callback() invalid address space\n");
+  core_attach(memory,
+             attach,
+             space,
+             access,
+             addr,
+             nr_bytes,
+             who);
+}
+
+
+STATIC_INLINE_CORE unsigned
+core_dma_read_buffer_callback(const device *me,
+                             void *dest,
+                             int space,
+                             unsigned_word addr,
+                             unsigned nr_bytes)
+{
+  core *memory = (core*)me->data;
+  DTRACE_DMA_READ_BUFFER(core);
+  return core_map_read_buffer(core_readable(memory),
+                             dest,
+                             addr,
+                             nr_bytes);
+}
+
+
+STATIC_INLINE_CORE unsigned
+core_dma_write_buffer_callback(const device *me,
+                              const void *source,
+                              int space,
+                              unsigned_word addr,
+                              unsigned nr_bytes,
+                              int violate_read_only_section)
+{
+  core *memory = (core*)me->data;
+  core_map *map = (violate_read_only_section
+                  ? core_readable(memory)
+                  : core_writeable(memory));
+  DTRACE_DMA_WRITE_BUFFER(core);
+  return core_map_write_buffer(map,
+                              source,
+                              addr,
+                              nr_bytes);
+}
+
+
+static device_callbacks const core_callbacks = {
+  core_init_callback,
+  core_attach_address_callback,
+  unimp_device_detach_address,
+  unimp_device_io_read_buffer,
+  unimp_device_io_write_buffer,
+  core_dma_read_buffer_callback,
+  core_dma_write_buffer_callback,
+  unimp_device_attach_interrupt,
+  unimp_device_detach_interrupt,
+  unimp_device_interrupt,
+  unimp_device_interrupt_ack,
+  unimp_device_ioctl,
+};
+
+
+INLINE_CORE const device *
+core_device_create(core *memory)
+{
+  return device_create_from("core", "/", memory, &core_callbacks, NULL);
+}
+
+
+
+/* define the read/write 1/2/4/8/word functions */
+
+#undef N
+#define N 1
+#include "core_n.h"
+
+#undef N
+#define N 2
+#include "core_n.h"
+
+#undef N
+#define N 4
+#include "core_n.h"
+
+#undef N
+#define N 8
+#include "core_n.h"
+
+#undef N
+#define N word
+#include "core_n.h"
+
+#endif /* _CORE_C_ */
index a4e4b0222977add8a1cf0e95673e92514fdd3785..82290f6a1d65bc596a27aa9dc99680ea2417438e 100644 (file)
@@ -29,7 +29,7 @@
 #include "basics.h"
 #include "registers.h"
 #include "device_tree.h"
-#include "core.h"
+#include "corefile.h"
 #include "vm.h"
 #include "events.h"
 #include "interrupts.h"
diff --git a/sim/ppc/inline.c b/sim/ppc/inline.c
new file mode 100644 (file)
index 0000000..4ac048b
--- /dev/null
@@ -0,0 +1,81 @@
+/*  This file is part of the program psim.
+
+    Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
+
+    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.
+
+    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.
+    */
+
+
+#ifndef _PPC_INLINE_C_
+#define _PPC_INLINE_C_
+
+#if ENDIAN_INLINE
+#include "ppc-endian.c"
+#endif
+
+#if ICACHE_INLINE
+#include "icache.c"
+#endif
+
+#if CORE_INLINE
+#include "corefile.c"
+#endif
+
+#if VM_INLINE
+#include "vm.c"
+#endif
+
+#if CPU_INLINE
+#include "cpu.c"
+#endif
+
+#if EVENTS_INLINE
+#include "events.c"
+#endif
+
+#if MON_INLINE
+#include "mon.c"
+#endif
+
+#if REGISTERS_INLINE
+#include "registers.c"
+#endif
+
+#if INTERRUPTS_INLINE
+#include "interrupts.c"
+#endif
+
+#if DEVICE_TREE_INLINE
+#include "device_tree.c"
+#endif
+
+#if DEVICES_INLINE
+#include "devices.c"
+#endif
+
+#if SPREG_INLINE
+#include "spreg.c"
+#endif
+
+#if SEMANTICS_INLINE
+#include "semantics.c"
+#endif
+
+#if IDECODE_INLINE
+#include "idecode.c"
+#endif
+
+#endif
index f15e0bf8ea7bd0605f51baa76dd381b61b3d954a..269f6608d1ff290409b555deed65d80f8bc2efe9 100644 (file)
@@ -32,7 +32,7 @@
 #include "registers.h"
 
 #include "device_tree.h"
-#include "core.h"
+#include "corefile.h"
 
 #include "vm.h"