]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - sim/mn10300/interp.c
sim: mn10300: delete unused memory code
[thirdparty/binutils-gdb.git] / sim / mn10300 / interp.c
index 577cc7a0d00b8359f29bfaf4942fde2ff905e669..14344fc2ecba635370a496dbcd76b449b1beca0e 100644 (file)
 
 #include "bfd.h"
 
-#ifndef INLINE
-#ifdef __GNUC__
-#define INLINE inline
-#else
-#define INLINE
-#endif
-#endif
-
 
 host_callback *mn10300_callback;
-int mn10300_debug;
 struct _state State;
 
 
@@ -84,6 +75,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 +95,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 +305,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 +337,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;
@@ -331,58 +348,18 @@ sim_create_inferior (SIM_DESC sd,
 /* FIXME These would more efficient to use than load_mem/store_mem,
    but need to be changed to use the memory map.  */
 
-uint8
-get_byte (uint8 *x)
-{
-  return *x;
-}
-
-uint16
-get_half (uint8 *x)
-{
-  uint8 *a = x;
-  return (a[1] << 8) + (a[0]);
-}
-
-uint32
-get_word (uint8 *x)
-{
-  uint8 *a = x;
-  return (a[3]<<24) + (a[2]<<16) + (a[1]<<8) + (a[0]);
-}
-
-void
-put_byte (uint8 *addr, uint8 data)
-{
-  uint8 *a = addr;
-  a[0] = data;
-}
-
-void
-put_half (uint8 *addr, uint16 data)
-{
-  uint8 *a = addr;
-  a[0] = data & 0xff;
-  a[1] = (data >> 8) & 0xff;
-}
-
-void
-put_word (uint8 *addr, uint32 data)
-{
-  uint8 *a = addr;
-  a[0] = data & 0xff;
-  a[1] = (data >> 8) & 0xff;
-  a[2] = (data >> 16) & 0xff;
-  a[3] = (data >> 24) & 0xff;
-}
-
 int
 sim_fetch_register (SIM_DESC sd,
                    int rn,
                    unsigned char *memory,
                    int length)
 {
-  put_word (memory, State.regs[rn]);
+  reg_t reg = State.regs[rn];
+  uint8 *a = memory;
+  a[0] = reg;
+  a[1] = reg >> 8;
+  a[2] = reg >> 16;
+  a[3] = reg >> 24;
   return length;
 }
  
@@ -392,11 +369,11 @@ sim_store_register (SIM_DESC sd,
                    unsigned char *memory,
                    int length)
 {
-  State.regs[rn] = get_word (memory);
+  uint8 *a = memory;
+  State.regs[rn] = (a[3] << 24) + (a[2] << 16) + (a[1] << 8) + a[0];
   return length;
 }
 
-
 void
 mn10300_core_signal (SIM_DESC sd,
                     sim_cpu *cpu,
@@ -457,7 +434,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
@@ -471,7 +448,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);
@@ -486,7 +463,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;
 }
@@ -502,7 +479,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;
 }
 
@@ -524,7 +501,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)
     {
@@ -613,7 +590,7 @@ reg2val_64 (const void *reg, sim_fpu *val)
 /* Round the given sim_fpu value to double precision, following the
    target platform rounding and denormalization conventions.  On
    AM33/2.0, round_near is the only rounding mode.  */
-int
+static int
 round_64 (sim_fpu *val)
 {
   return sim_fpu_round_64 (val, sim_fpu_round_near, sim_fpu_denorm_zero);
@@ -641,7 +618,7 @@ fp_double_prec = {
 
 /* Check whether overflow, underflow or inexact exceptions should be
    raised.  */
-int
+static int
 fpu_status_ok (sim_fpu_status stat)
 {
   if ((stat & sim_fpu_status_overflow)