]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
sim: m68hc11: convert to sim-cpu
authorMike Frysinger <vapier@gentoo.org>
Mon, 13 Apr 2015 06:07:23 +0000 (02:07 -0400)
committerMike Frysinger <vapier@gentoo.org>
Mon, 13 Apr 2015 06:07:23 +0000 (02:07 -0400)
Make cpu allocation fully dynamic so we can leverage the common
sim-cpu and its APIs.

sim/m68hc11/ChangeLog
sim/m68hc11/Makefile.in
sim/m68hc11/interp.c
sim/m68hc11/sim-main.h

index 36190a297921b2e2474dee5fc21dd289807567dd..73adccb02d6c16f9dd8917946919db1e23e2d858 100644 (file)
@@ -1,3 +1,14 @@
+2015-04-13  Mike Frysinger  <vapier@gentoo.org>
+
+       * Makefile.in (SIM_OBJS): Add sim-cpu.o.
+       * interp.c (m68hc11_pc_get, m68hc11_pc_set): New functions.
+       (sim_open): Declare new local var i.  Call sim_cpu_alloc_all.
+       Call CPU_PC_FETCH & CPU_PC_STORE for all cpus.
+       (sim_pc_get): Delete.
+       * sim-main.h (SIM_CPU): Define.
+       (STATE_CPU): Drop &.
+       (struct sim_state): Change cpu to an array of pointers.
+
 2015-04-06  Mike Frysinger  <vapier@gentoo.org>
 
        * Makefile.in (SIM_OBJS): Delete sim-engine.o and sim-hrw.o.
index 9b931a19958122e22bdb3a46a1c4c2b53cf3d6a1..7db38973c51da01e772355a0b8d11d37e6068ff5 100644 (file)
@@ -22,6 +22,7 @@ M68HC11_OBJS = interp.o m68hc11int.o m68hc12int.o \
 
 SIM_OBJS = $(M68HC11_OBJS) \
        $(SIM_NEW_COMMON_OBJS) \
+       sim-cpu.o \
        sim-load.o \
        sim-hload.o \
        sim-stop.o \
index 3100659a82626e28f5165ca5013f5d3e5d609597..659001ab013d21dfb8c91e06ce6d5e54cc6b83fe 100644 (file)
@@ -417,18 +417,39 @@ sim_prepare_for_program (SIM_DESC sd, bfd* abfd)
   return SIM_RC_OK;
 }
 
+static sim_cia
+m68hc11_pc_get (sim_cpu *cpu)
+{
+  return cpu_get_pc (cpu);
+}
+
+static void
+m68hc11_pc_set (sim_cpu *cpu, sim_cia pc)
+{
+  cpu_set_pc (cpu, pc);
+}
+
 SIM_DESC
 sim_open (SIM_OPEN_KIND kind, host_callback *callback,
           bfd *abfd, char **argv)
 {
+  int i;
   SIM_DESC sd;
   sim_cpu *cpu;
 
   sd = sim_state_alloc (kind, callback);
-  cpu = STATE_CPU (sd, 0);
 
   SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
 
+  /* The cpu data is kept in a separately allocated chunk of memory.  */
+  if (sim_cpu_alloc_all (sd, 1, /*cgen_cpu_max_extra_bytes ()*/0) != SIM_RC_OK)
+    {
+      free_state (sd);
+      return 0;
+    }
+
+  cpu = STATE_CPU (sd, 0);
+
   /* for compatibility */
   current_alignment = NONSTRICT_ALIGNMENT;
   current_target_byte_order = BIG_ENDIAN;
@@ -482,7 +503,15 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback,
       return 0;
     }      
 
-  /* Fudge our descriptor.  */
+  /* CPU specific initialization.  */
+  for (i = 0; i < MAX_NR_PROCESSORS; ++i)
+    {
+      SIM_CPU *cpu = STATE_CPU (sd, i);
+
+      CPU_PC_FETCH (cpu) = m68hc11_pc_get;
+      CPU_PC_STORE (cpu) = m68hc11_pc_set;
+    }
+
   return sd;
 }
 
@@ -679,12 +708,6 @@ sim_store_register (SIM_DESC sd, int rn, unsigned char *memory, int length)
   return 2;
 }
 
-sim_cia
-sim_pc_get (sim_cpu *cpu)
-{
-  return CIA_GET (cpu);
-}
-
 /* Halt the simulator after just one instruction */
 
 static void
index 39731594918bfa0fd69cf5a0f1f803f65baf2d08..be3fc3d8e8813377d7d4a65f6bc6cee938dfc4e4 100644 (file)
@@ -28,6 +28,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 typedef address_word sim_cia;
 
+typedef struct _sim_cpu SIM_CPU;
+
 #include "sim-signal.h"
 #include "sim-base.h"
 
@@ -576,13 +578,13 @@ extern void m68hc11cpu_set_port (struct hw *me, sim_cpu *cpu,
 #define CIA_SET(CPU,VAL)  (cpu_set_pc ((CPU), (VAL)))
 
 #if (WITH_SMP)
-#define STATE_CPU(sd,n) (&(sd)->cpu[n])
+#define STATE_CPU(sd,n) ((sd)->cpu[n])
 #else
-#define STATE_CPU(sd,n) (&(sd)->cpu[0])
+#define STATE_CPU(sd,n) ((sd)->cpu[0])
 #endif
 
 struct sim_state {
-  sim_cpu        cpu[MAX_NR_PROCESSORS];
+  sim_cpu        *cpu[MAX_NR_PROCESSORS];
   device         *devices;
   sim_state_base base;
 };