sim: unify SIM_CPU definition
[deliverable/binutils-gdb.git] / sim / mn10300 / interp.c
index 1230bf55cb5eeef7b1ce86bbd14290d55b9702b8..4439ac8c481d728bd4910431fa857281d0522a72 100644 (file)
@@ -1,10 +1,10 @@
+#include "config.h"
 #include <signal.h>
 
 #include "sim-main.h"
 #include "sim-options.h"
 #include "sim-hw.h"
 
-#include "sysdep.h"
 #include "bfd.h"
 #include "sim-assert.h"
 
@@ -84,6 +84,18 @@ static const OPTION mn10300_options[] =
 /* For compatibility */
 SIM_DESC simulator;
 
+static sim_cia
+mn10300_pc_get (sim_cpu *cpu)
+{
+  return PC;
+}
+
+static void
+mn10300_pc_set (sim_cpu *cpu, sim_cia pc)
+{
+  PC = pc;
+}
+
 /* These default values correspond to expected usage for the chip.  */
 
 SIM_DESC
@@ -92,11 +104,16 @@ sim_open (SIM_OPEN_KIND kind,
          struct bfd *abfd,
          char **argv)
 {
+  int i;
   SIM_DESC sd = sim_state_alloc (kind, cb);
   mn10300_callback = cb;
 
   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;
+
   /* for compatibility */
   simulator = sd;
 
@@ -297,6 +314,15 @@ sim_open (SIM_OPEN_KIND kind,
 /*   STATE_CPU (sd, 0)->psw_mask = (PSW_NP | PSW_EP | PSW_ID | PSW_SAT */
 /*                          | PSW_CY | PSW_OV | PSW_S | PSW_Z); */
 
+  /* CPU specific initialization.  */
+  for (i = 0; i < MAX_NR_PROCESSORS; ++i)
+    {
+      SIM_CPU *cpu = STATE_CPU (sd, i);
+
+      CPU_PC_FETCH (cpu) = mn10300_pc_get;
+      CPU_PC_STORE (cpu) = mn10300_pc_set;
+    }
+
   return sd;
 }
 
@@ -320,7 +346,7 @@ sim_create_inferior (SIM_DESC sd,
   } else {
     PC = 0;
   }
-  CIA_SET (STATE_CPU (sd, 0), (unsigned64) PC);
+  CPU_PC_SET (STATE_CPU (sd, 0), (unsigned64) PC);
 
   if (STATE_ARCHITECTURE (sd)->mach == bfd_mach_am33_2)
     PSW |= PSW_FE;
@@ -328,23 +354,6 @@ sim_create_inferior (SIM_DESC sd,
   return SIM_RC_OK;
 }
 
-void
-sim_do_command (SIM_DESC sd, char *cmd)
-{
-  char *mm_cmd = "memory-map";
-  char *int_cmd = "interrupt";
-
-  if (sim_args_command (sd, cmd) != SIM_RC_OK)
-    {
-      if (strncmp (cmd, mm_cmd, strlen (mm_cmd) == 0))
-       sim_io_eprintf (sd, "`memory-map' command replaced by `sim memory'\n");
-      else if (strncmp (cmd, int_cmd, strlen (int_cmd)) == 0)
-       sim_io_eprintf (sd, "`interrupt' command replaced by `sim watch'\n");
-      else
-       sim_io_eprintf (sd, "Unknown command `%s'\n", cmd);
-    }
-}
-
 /* FIXME These would more efficient to use than load_mem/store_mem,
    but need to be changed to use the memory map.  */
 
@@ -400,7 +409,7 @@ sim_fetch_register (SIM_DESC sd,
                    int length)
 {
   put_word (memory, State.regs[rn]);
-  return -1;
+  return length;
 }
  
 int
@@ -413,7 +422,6 @@ sim_store_register (SIM_DESC sd,
   return length;
 }
 
-
 void
 mn10300_core_signal (SIM_DESC sd,
                     sim_cpu *cpu,
@@ -474,7 +482,7 @@ program_interrupt (SIM_DESC sd,
     {
       in_interrupt = 1;
       /* copy NMI handler code from dv-mn103cpu.c */
-      store_word (SP - 4, CIA_GET (cpu));
+      store_word (SP - 4, CPU_PC_GET (cpu));
       store_half (SP - 8, PSW);
 
       /* Set the SYSEF flag in NMICR by backdoor method.  See
@@ -488,7 +496,7 @@ program_interrupt (SIM_DESC sd,
 
   PSW &= ~PSW_IE;
   SP = SP - 8;
-  CIA_SET (cpu, 0x40000008);
+  CPU_PC_SET (cpu, 0x40000008);
 
   in_interrupt = 0;
   sim_engine_halt(sd, cpu, NULL, cia, sim_stopped, sig);
@@ -503,7 +511,7 @@ mn10300_cpu_exception_trigger(SIM_DESC sd, sim_cpu* cpu, address_word cia)
   if(State.exc_suspended > 0)
     sim_io_eprintf(sd, "Warning, nested exception triggered (%d)\n", State.exc_suspended); 
 
-  CIA_SET (cpu, cia);
+  CPU_PC_SET (cpu, cia);
   memcpy(State.exc_trigger_regs, State.regs, sizeof(State.exc_trigger_regs));
   State.exc_suspended = 0;
 }
@@ -519,7 +527,7 @@ mn10300_cpu_exception_suspend(SIM_DESC sd, sim_cpu* cpu, int exception)
 
   memcpy(State.exc_suspend_regs, State.regs, sizeof(State.exc_suspend_regs));
   memcpy(State.regs, State.exc_trigger_regs, sizeof(State.regs));
-  CIA_SET (cpu, PC); /* copy PC back from new State.regs */
+  CPU_PC_SET (cpu, PC); /* copy PC back from new State.regs */
   State.exc_suspended = exception;
 }
 
@@ -541,7 +549,7 @@ mn10300_cpu_exception_resume(SIM_DESC sd, sim_cpu* cpu, int exception)
                       State.exc_suspended, exception); 
       
       memcpy(State.regs, State.exc_suspend_regs, sizeof(State.regs)); 
-      CIA_SET (cpu, PC); /* copy PC back from new State.regs */
+      CPU_PC_SET (cpu, PC); /* copy PC back from new State.regs */
     }
   else if(exception != 0 && State.exc_suspended == 0)
     {
This page took 0.026198 seconds and 4 git commands to generate.