gdb: Convert language la_value_print field to a method
[deliverable/binutils-gdb.git] / sim / ft32 / interp.c
index 931ad2b5cc78bac8692b839b6f36843e0425d80a..d9ff14babb7c7dfdf7ecea306b12074ab72c736c 100644 (file)
@@ -1,6 +1,6 @@
 /* Simulator for the FT32 processor
 
-   Copyright (C) 2008-2015 Free Software Foundation, Inc.
+   Copyright (C) 2008-2020 Free Software Foundation, Inc.
    Contributed by FTDI <support@ftdichip.com>
 
    This file is part of simulators.
@@ -110,7 +110,7 @@ static uint32_t
 ft32_read_item (SIM_DESC sd, int dw, uint32_t ea)
 {
   sim_cpu *cpu = STATE_CPU (sd, 0);
-  address_word cia = CIA_GET (cpu);
+  address_word cia = CPU_PC_GET (cpu);
   uint8_t byte[4];
   uint32_t r;
 
@@ -133,7 +133,7 @@ static void
 ft32_write_item (SIM_DESC sd, int dw, uint32_t ea, uint32_t v)
 {
   sim_cpu *cpu = STATE_CPU (sd, 0);
-  address_word cia = CIA_GET (cpu);
+  address_word cia = CPU_PC_GET (cpu);
   uint8_t byte[4];
 
   ea = ft32_align (dw, ea);
@@ -169,6 +169,8 @@ static uint32_t cpu_mem_read (SIM_DESC sd, uint32_t dw, uint32_t ea)
       /* Simulate some IO devices */
       switch (ea)
        {
+       case 0x10000:
+         return getchar ();
        case 0x1fff4:
          /* Read the simulator cycle timer.  */
          return cpu->state.cycles / 100;
@@ -203,8 +205,12 @@ static void cpu_mem_write (SIM_DESC sd, uint32_t dw, uint32_t ea, uint32_t d)
          cpu->state.pm_addr = d;
          break;
        case 0x1fc88:
-         /* Write to PM */
-         ft32_write_item (sd, dw, cpu->state.pm_addr, d);
+         if (cpu->state.pm_unlock)
+           {
+             /* Write to PM.  */
+             ft32_write_item (sd, dw, cpu->state.pm_addr, d);
+             cpu->state.pm_addr += 4;
+           }
          break;
        case 0x1fffc:
          /* Normal exit.  */
@@ -311,7 +317,7 @@ static void
 step_once (SIM_DESC sd)
 {
   sim_cpu *cpu = STATE_CPU (sd, 0);
-  address_word cia = CIA_GET (cpu);
+  address_word cia = CPU_PC_GET (cpu);
   uint32_t inst;
   uint32_t dw;
   uint32_t cb;
@@ -326,7 +332,7 @@ step_once (SIM_DESC sd)
   uint32_t pa;
   uint32_t aa;
   uint32_t k16;
-  uint32_t k8;
+  uint32_t k15;
   uint32_t al;
   uint32_t r_1v;
   uint32_t rimmv;
@@ -334,16 +340,24 @@ step_once (SIM_DESC sd)
   uint32_t bit_len;
   uint32_t upper;
   uint32_t insnpc;
+  unsigned int sc[2];
+  int isize;
 
-  if (cpu->state.cycles >= cpu->state.next_tick_cycle)
-    {
-      cpu->state.next_tick_cycle += 100000;
-      ft32_push (sd, cpu->state.pc);
-      cpu->state.pc = 12;  /* interrupt 1.  */
-    }
   inst = ft32_read_item (sd, 2, cpu->state.pc);
   cpu->state.cycles += 1;
 
+  if ((STATE_ARCHITECTURE (sd)->mach == bfd_mach_ft32b)
+      && ft32_decode_shortcode (cpu->state.pc, inst, sc))
+    {
+      if ((cpu->state.pc & 3) == 0)
+        inst = sc[0];
+      else
+        inst = sc[1];
+      isize = 2;
+    }
+  else
+    isize = 4;
+
   /* Handle "call 8" (which is FT32's "break" equivalent) here.  */
   if (inst == 0x00340002)
     {
@@ -366,7 +380,11 @@ step_once (SIM_DESC sd)
   pa   =              (inst >> FT32_FLD_PA_BIT) & LSBS (FT32_FLD_PA_SIZ);
   aa   =              (inst >> FT32_FLD_AA_BIT) & LSBS (FT32_FLD_AA_SIZ);
   k16  =              (inst >> FT32_FLD_K16_BIT) & LSBS (FT32_FLD_K16_SIZ);
-  k8   = nsigned (8,  (inst >> FT32_FLD_K8_BIT) & LSBS (FT32_FLD_K8_SIZ));
+  k15  =              (inst >> FT32_FLD_K15_BIT) & LSBS (FT32_FLD_K15_SIZ);
+  if (k15 & 0x80)
+    k15 ^= 0x7f00;
+  if (k15 & 0x4000)
+    k15 -= 0x8000;
   al   =              (inst >> FT32_FLD_AL_BIT) & LSBS (FT32_FLD_AL_SIZ);
 
   r_1v = cpu->state.regs[r_1];
@@ -380,7 +398,7 @@ step_once (SIM_DESC sd)
   upper = (inst >> 27);
 
   insnpc = cpu->state.pc;
-  cpu->state.pc += 4;
+  cpu->state.pc += isize;
   switch (upper)
     {
     case FT32_PAT_TOC:
@@ -493,7 +511,7 @@ step_once (SIM_DESC sd)
       break;
 
     case FT32_PAT_LPMI:
-      cpu->state.regs[r_d] = ft32_read_item (sd, dw, cpu->state.regs[r_1] + k8);
+      cpu->state.regs[r_d] = ft32_read_item (sd, dw, cpu->state.regs[r_1] + k15);
       cpu->state.cycles += 1;
       break;
 
@@ -502,7 +520,7 @@ step_once (SIM_DESC sd)
       break;
 
     case FT32_PAT_STI:
-      cpu_mem_write (sd, dw, cpu->state.regs[r_d] + k8, cpu->state.regs[r_1]);
+      cpu_mem_write (sd, dw, cpu->state.regs[r_d] + k15, cpu->state.regs[r_1]);
       break;
 
     case FT32_PAT_LDA:
@@ -511,7 +529,7 @@ step_once (SIM_DESC sd)
       break;
 
     case FT32_PAT_LDI:
-      cpu->state.regs[r_d] = cpu_mem_read (sd, dw, cpu->state.regs[r_1] + k8);
+      cpu->state.regs[r_d] = cpu_mem_read (sd, dw, cpu->state.regs[r_1] + k15);
       cpu->state.cycles += 1;
       break;
 
@@ -528,8 +546,8 @@ step_once (SIM_DESC sd)
     case FT32_PAT_EXI:
       {
        uint32_t tmp;
-       tmp = cpu_mem_read (sd, dw, cpu->state.regs[r_1] + k8);
-       cpu_mem_write (sd, dw, cpu->state.regs[r_1] + k8, cpu->state.regs[r_d]);
+       tmp = cpu_mem_read (sd, dw, cpu->state.regs[r_1] + k15);
+       cpu_mem_write (sd, dw, cpu->state.regs[r_1] + k15, cpu->state.regs[r_d]);
        cpu->state.regs[r_d] = tmp;
        cpu->state.cycles += 1;
       }
@@ -596,7 +614,7 @@ step_once (SIM_DESC sd)
            uint32_t src = r_1v;
            uint32_t dst = cpu->state.regs[r_d];
            uint32_t i;
-           for (i = 0; i < rimmv; i++)
+           for (i = 0; i < (rimmv & 0x7fff); i++)
              PUT_BYTE (dst + i, GET_BYTE (src + i));
          }
          break;
@@ -615,7 +633,7 @@ step_once (SIM_DESC sd)
            /* memset instruction.  */
            uint32_t dst = cpu->state.regs[r_d];
            uint32_t i;
-           for (i = 0; i < rimmv; i++)
+           for (i = 0; i < (rimmv & 0x7fff); i++)
              PUT_BYTE (dst + i, r_1v);
          }
          break;
@@ -688,28 +706,6 @@ sim_engine_run (SIM_DESC sd,
     }
 }
 
-int
-sim_write (SIM_DESC sd,
-          SIM_ADDR addr,
-          const unsigned char *buffer,
-          int size)
-{
-  sim_cpu *cpu = STATE_CPU (sd, 0);
-
-  return sim_core_write_buffer (sd, cpu, write_map, buffer, addr, size);
-}
-
-int
-sim_read (SIM_DESC sd,
-         SIM_ADDR addr,
-         unsigned char *buffer,
-         int size)
-{
-  sim_cpu *cpu = STATE_CPU (sd, 0);
-
-  return sim_core_read_buffer (sd, cpu, read_map, buffer, addr, size);
-}
-
 static uint32_t *
 ft32_lookup_register (SIM_CPU *cpu, int nr)
 {
@@ -780,7 +776,7 @@ ft32_reg_fetch (SIM_CPU *cpu,
 static sim_cia
 ft32_pc_get (SIM_CPU *cpu)
 {
-  return 32;
+  return cpu->state.pc;
 }
 
 static void
@@ -804,7 +800,7 @@ SIM_DESC
 sim_open (SIM_OPEN_KIND kind,
          host_callback *cb,
          struct bfd *abfd,
-         char **argv)
+         char * const *argv)
 {
   char c;
   size_t i;
@@ -823,9 +819,7 @@ sim_open (SIM_OPEN_KIND kind,
       return 0;
     }
 
-  /* getopt will print the error message so we just have to exit if this fails.
-     FIXME: Hmmm...  in the case of gdb we need getopt to call
-     print_filtered.  */
+  /* The parser will print an error message for us, so we silently return.  */
   if (sim_parse_args (sd, argv) != SIM_RC_OK)
     {
       free_state (sd);
@@ -878,17 +872,11 @@ sim_open (SIM_OPEN_KIND kind,
   return sd;
 }
 
-void
-sim_close (SIM_DESC sd, int quitting)
-{
-  sim_module_uninstall (sd);
-}
-
 SIM_RC
 sim_create_inferior (SIM_DESC sd,
                     struct bfd *abfd,
-                    char **argv,
-                    char **env)
+                    char * const *argv,
+                    char * const *env)
 {
   uint32_t addr;
   sim_cpu *cpu = STATE_CPU (sd, 0);
@@ -899,7 +887,11 @@ sim_create_inferior (SIM_DESC sd,
   else
     addr = 0;
 
-  if (STATE_OPEN_KIND (sd) == SIM_OPEN_DEBUG)
+  /* Standalone mode (i.e. `run`) will take care of the argv for us in
+     sim_open() -> sim_parse_args().  But in debug mode (i.e. 'target sim'
+     with `gdb`), we need to handle it because the user can change the
+     argv on the fly via gdb's 'run'.  */
+  if (STATE_PROG_ARGV (sd) != argv)
     {
       freeargv (STATE_PROG_ARGV (sd));
       STATE_PROG_ARGV (sd) = dupargv (argv);
This page took 0.042118 seconds and 4 git commands to generate.