sim: mips: convert to sim-cpu
authorMike Frysinger <vapier@gentoo.org>
Mon, 13 Apr 2015 06:09:55 +0000 (02:09 -0400)
committerMike Frysinger <vapier@gentoo.org>
Mon, 13 Apr 2015 06:09:55 +0000 (02:09 -0400)
Make cpu allocation fully dynamic so we can leverage the common
sim-cpu and its APIs.

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

index cd655eb6b0459bcc54d985befdfe39270fbe0c19..a962f84a810b83d8ecf1be692796ebf3eef04e94 100644 (file)
@@ -1,3 +1,14 @@
+2015-04-13  Mike Frysinger  <vapier@gentoo.org>
+
+       * Makefile.in (SIM_OBJS): Add sim-cpu.o.
+       * interp.c (mips_pc_get, mips_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.
+       (struct sim_state): Change cpu to an array of pointers.
+       (STATE_CPU): Drop &.
+
 2015-04-13  Mike Frysinger  <vapier@gentoo.org>
 
        * interp.c (mips_option_handler, open_trace, sim_close,
index 17eeab6ae0e3933208b6561428da37c30f1c8821..96131ae547ce65b71c1eba4c1336421ddc7565dd 100644 (file)
@@ -46,6 +46,7 @@ SIM_OBJS = \
        cp1.o \
        mdmx.o \
        dsp.o \
+       sim-cpu.o \
        sim-main.o \
        sim-hload.o \
        sim-stop.o \
index dabd9e03174a1d5d54f4df2c32fc1874fcc9345e..d6136ab2ca01d74f4fdf23a90eed7153783a3689 100644 (file)
@@ -336,14 +336,33 @@ static void device_init(SIM_DESC sd) {
 /*-- GDB simulator interface ------------------------------------------------*/
 /*---------------------------------------------------------------------------*/
 
+static sim_cia
+mips_pc_get (sim_cpu *cpu)
+{
+  return PC;
+}
+
+static void
+mips_pc_set (sim_cpu *cpu, sim_cia pc)
+{
+  PC = pc;
+}
+
 SIM_DESC
 sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
 {
+  int i;
   SIM_DESC sd = sim_state_alloc (kind, cb);
-  sim_cpu *cpu = STATE_CPU (sd, 0); /* FIXME */
+  sim_cpu *cpu;
 
   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)
+    return 0;
+
+  cpu = STATE_CPU (sd, 0); /* FIXME */
+
   /* FIXME: watchpoints code shouldn't need this */
   STATE_WATCHPOINTS (sd)->pc = &(PC);
   STATE_WATCHPOINTS (sd)->sizeof_pc = sizeof (PC);
@@ -790,7 +809,14 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
     }
   }
 
+  /* CPU specific initialization.  */
+  for (i = 0; i < MAX_NR_PROCESSORS; ++i)
+    {
+      SIM_CPU *cpu = STATE_CPU (sd, i);
 
+      CPU_PC_FETCH (cpu) = mips_pc_get;
+      CPU_PC_STORE (cpu) = mips_pc_set;
+    }
 
   return sd;
 }
@@ -1066,12 +1092,6 @@ sim_fetch_register (SIM_DESC sd, int rn, unsigned char *memory, int length)
   return 0;
 }
 
-sim_cia
-sim_pc_get (sim_cpu *cpu)
-{
-  return PC;
-}
-
 SIM_RC
 sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char **argv, char **env)
 {
index 3c0e9bb9cbfca60f72f00ada737f8512b4ab6455..e27636c12f770f041c20db722a8a9b2ac316ed11 100644 (file)
@@ -36,6 +36,8 @@ mips_core_signal ((SD), (CPU), (CIA), (MAP), (NR_BYTES), (ADDR), (TRANSFER), (ER
 
 typedef address_word sim_cia;
 
+typedef struct _sim_cpu SIM_CPU;
+
 #include "sim-base.h"
 #include "bfd.h"
 
@@ -486,14 +488,13 @@ struct sim_state {
 
   struct swatch watch;
 
-  sim_cpu cpu[MAX_NR_PROCESSORS];
+  sim_cpu *cpu[MAX_NR_PROCESSORS];
 #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
 
-
   sim_state_base base;
 };
 
This page took 0.030705 seconds and 4 git commands to generate.