+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.
 
   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;
       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;
 }
 
   return 2;
 }
 
-sim_cia
-sim_pc_get (sim_cpu *cpu)
-{
-  return CIA_GET (cpu);
-}
-
 /* Halt the simulator after just one instruction */
 
 static void
 
 
 typedef address_word sim_cia;
 
+typedef struct _sim_cpu SIM_CPU;
+
 #include "sim-signal.h"
 #include "sim-base.h"
 
 #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;
 };