gas: run the hwcaps-bump tests with 64-bit sparc objects only.
[deliverable/binutils-gdb.git] / sim / sh / interp.c
index 13f6e65ee5c21398a940a5620f262b09a27c6aaa..32618ba4490232f04eb8544c81f7e3eefbce27a9 100644 (file)
@@ -116,11 +116,10 @@ struct loop_bounds { unsigned char *start, *end; };
 /* These variables are at file scope so that functions other than
    sim_resume can use the fetch/store macros */
 
-#define target_little_endian (CURRENT_TARGET_BYTE_ORDER == LITTLE_ENDIAN)
+#define target_little_endian (CURRENT_TARGET_BYTE_ORDER == BFD_ENDIAN_LITTLE)
 static int global_endianw, endianb;
 static int target_dsp;
-#define host_little_endian (CURRENT_HOST_BYTE_ORDER == LITTLE_ENDIAN)
-static char **prog_argv;
+#define host_little_endian (HOST_BYTE_ORDER == BFD_ENDIAN_LITTLE)
 
 static int maskw = 0;
 static int maskl = 0;
@@ -241,20 +240,6 @@ do { \
 #define FPSCR_SZ  ((GET_FPSCR () & FPSCR_MASK_SZ) != 0)
 #define FPSCR_PR  ((GET_FPSCR () & FPSCR_MASK_PR) != 0)
 
-/* Count the number of arguments in an argv.  */
-static int
-count_argc (char **argv)
-{
-  int i;
-
-  if (! argv)
-    return -1;
-
-  for (i = 0; argv[i] != NULL; ++i)
-    continue;
-  return i;
-}
-
 static void
 set_fpscr1 (int x)
 {
@@ -376,7 +361,7 @@ int valid[16];
 #define UNDEF(x)
 #endif
 
-static void parse_and_set_memory_size (const char *str);
+static void parse_and_set_memory_size (SIM_DESC sd, const char *str);
 static int IOMEM (int addr, int write, int value);
 static struct loop_bounds get_loop_bounds (int, int, unsigned char *,
                                           unsigned char *, int, int);
@@ -387,10 +372,6 @@ static int process_rlat_addr (int);
 static int process_rwat_addr (int);
 static int process_rbat_addr (int);
 
-static host_callback *callback;
-
-
-
 /* Floating point registers */
 
 #define DR(n) (get_dr (n))
@@ -577,7 +558,7 @@ rwat_fast (unsigned char *memory, int x, int maskw, int endianw)
 static INLINE int
 riat_fast (unsigned char *insn_ptr, int endianw)
 {
-  unsigned short *p = (unsigned short *) ((size_t) insn_ptr ^ endianw);
+  unsigned short *p = (unsigned short *) ((uintptr_t) insn_ptr ^ endianw);
 
   return *p;
 }
@@ -741,7 +722,7 @@ do { \
 #if defined(__GO32__)
 int sim_memory_size = 19;
 #else
-int sim_memory_size = 24;
+int sim_memory_size = 30;
 #endif
 
 static int sim_profile_size = 17;
@@ -886,9 +867,12 @@ strnswap (int str, int len)
    return offset by which to adjust pc.  */
 
 static int
-trap (int i, int *regs, unsigned char *insn_ptr, unsigned char *memory,
-      int maskl, int maskw, int endianw)
+trap (SIM_DESC sd, int i, int *regs, unsigned char *insn_ptr,
+      unsigned char *memory, int maskl, int maskw, int endianw)
 {
+  host_callback *callback = STATE_CALLBACK (sd);
+  char **prog_argv = STATE_PROG_ARGV (sd);
+
   switch (i)
     {
     case 1:
@@ -1058,16 +1042,16 @@ trap (int i, int *regs, unsigned char *insn_ptr, unsigned char *memory,
              break;
            }
          case SYS_argc:
-           regs[0] = count_argc (prog_argv);
+           regs[0] = countargv (prog_argv);
            break;
          case SYS_argnlen:
-           if (regs[5] < count_argc (prog_argv))
+           if (regs[5] < countargv (prog_argv))
              regs[0] = strlen (prog_argv[regs[5]]);
            else
              regs[0] = -1;
            break;
          case SYS_argn:
-           if (regs[5] < count_argc (prog_argv))
+           if (regs[5] < countargv (prog_argv))
              {
                /* Include the termination byte.  */
                int i = strlen (prog_argv[regs[5]]) + 1;
@@ -1201,41 +1185,19 @@ div1 (int *R, int iRn2, int iRn1/*, int T*/)
 }
 
 static void
-dmul (int sign, unsigned int rm, unsigned int rn)
+dmul_s (uint32_t rm, uint32_t rn)
 {
-  unsigned long RnL, RnH;
-  unsigned long RmL, RmH;
-  unsigned long temp0, temp1, temp2, temp3;
-  unsigned long Res2, Res1, Res0;
-
-  RnL = rn & 0xffff;
-  RnH = (rn >> 16) & 0xffff;
-  RmL = rm & 0xffff;
-  RmH = (rm >> 16) & 0xffff;
-  temp0 = RmL * RnL;
-  temp1 = RmH * RnL;
-  temp2 = RmL * RnH;
-  temp3 = RmH * RnH;
-  Res2 = 0;
-  Res1 = temp1 + temp2;
-  if (Res1 < temp1)
-    Res2 += 0x00010000;
-  temp1 = (Res1 << 16) & 0xffff0000;
-  Res0 = temp0 + temp1;
-  if (Res0 < temp0)
-    Res2 += 1;
-  Res2 += ((Res1 >> 16) & 0xffff) + temp3;
-  
-  if (sign)
-    {
-      if (rn & 0x80000000)
-       Res2 -= rm;
-      if (rm & 0x80000000)
-       Res2 -= rn;
-    }
+  int64_t res = (int64_t)(int32_t)rm * (int64_t)(int32_t)rn;
+  MACH = (uint32_t)((uint64_t)res >> 32);
+  MACL = (uint32_t)res;
+}
 
-  MACH = Res2;
-  MACL = Res0;
+static void
+dmul_u (uint32_t rm, uint32_t rn)
+{
+  uint64_t res = (uint64_t)(uint32_t)rm * (uint64_t)(uint32_t)rn;
+  MACH = (uint32_t)(res >> 32);
+  MACL = (uint32_t)res;
 }
 
 static void
@@ -1865,6 +1827,8 @@ sim_resume (SIM_DESC sd, int step, int siggnal)
 
       if (--pollcount < 0)
        {
+         host_callback *callback = STATE_CALLBACK (sd);
+
          pollcount = POLL_QUIT_INTERVAL;
          if ((*callback->poll_quit) != NULL
              && (*callback->poll_quit) (callback))
@@ -1977,8 +1941,8 @@ enum {
   REGBANK_MACL = 19
 };
 
-int
-sim_store_register (SIM_DESC sd, int rn, unsigned char *memory, int length)
+static int
+sh_reg_store (SIM_CPU *cpu, int rn, unsigned char *memory, int length)
 {
   unsigned val;
 
@@ -2150,8 +2114,8 @@ sim_store_register (SIM_DESC sd, int rn, unsigned char *memory, int length)
   return length;
 }
 
-int
-sim_fetch_register (SIM_DESC sd, int rn, unsigned char *memory, int length)
+static int
+sh_reg_fetch (SIM_CPU *cpu, int rn, unsigned char *memory, int length)
 {
   int val;
 
@@ -2345,34 +2309,43 @@ sim_info (SIM_DESC sd, int verbose)
     (double) saved_state.asregs.ticks / (double) now_persec ();
   double virttime = saved_state.asregs.cycles / 36.0e6;
 
-  callback->printf_filtered (callback, "\n\n# instructions executed  %10d\n", 
-                            saved_state.asregs.insts);
-  callback->printf_filtered (callback, "# cycles                 %10d\n",
-                            saved_state.asregs.cycles);
-  callback->printf_filtered (callback, "# pipeline stalls        %10d\n",
-                            saved_state.asregs.stalls);
-  callback->printf_filtered (callback, "# misaligned load/store  %10d\n",
-                            saved_state.asregs.memstalls);
-  callback->printf_filtered (callback, "# real time taken        %10.4f\n",
-                            timetaken);
-  callback->printf_filtered (callback, "# virtual time taken     %10.4f\n",
-                            virttime);
-  callback->printf_filtered (callback, "# profiling size         %10d\n",
-                            sim_profile_size);
-  callback->printf_filtered (callback, "# profiling frequency    %10d\n",
-                            saved_state.asregs.profile);
-  callback->printf_filtered (callback, "# profile maxpc          %10x\n",
-                            (1 << sim_profile_size) << PROFILE_SHIFT);
+  sim_io_printf (sd, "\n\n# instructions executed  %10d\n",
+                saved_state.asregs.insts);
+  sim_io_printf (sd, "# cycles                 %10d\n",
+                saved_state.asregs.cycles);
+  sim_io_printf (sd, "# pipeline stalls        %10d\n",
+                saved_state.asregs.stalls);
+  sim_io_printf (sd, "# misaligned load/store  %10d\n",
+                saved_state.asregs.memstalls);
+  sim_io_printf (sd, "# real time taken        %10.4f\n", timetaken);
+  sim_io_printf (sd, "# virtual time taken     %10.4f\n", virttime);
+  sim_io_printf (sd, "# profiling size         %10d\n", sim_profile_size);
+  sim_io_printf (sd, "# profiling frequency    %10d\n",
+                saved_state.asregs.profile);
+  sim_io_printf (sd, "# profile maxpc          %10x\n",
+                (1 << sim_profile_size) << PROFILE_SHIFT);
 
   if (timetaken != 0)
     {
-      callback->printf_filtered (callback, "# cycles/second          %10d\n", 
-                                (int) (saved_state.asregs.cycles / timetaken));
-      callback->printf_filtered (callback, "# simulation ratio       %10.4f\n", 
-                                virttime / timetaken);
+      sim_io_printf (sd, "# cycles/second          %10d\n",
+                    (int) (saved_state.asregs.cycles / timetaken));
+      sim_io_printf (sd, "# simulation ratio       %10.4f\n",
+                    virttime / timetaken);
     }
 }
 
+static sim_cia
+sh_pc_get (sim_cpu *cpu)
+{
+  return saved_state.asregs.pc;
+}
+
+static void
+sh_pc_set (sim_cpu *cpu, sim_cia pc)
+{
+  saved_state.asregs.pc = pc;
+}
+
 static void
 free_state (SIM_DESC sd)
 {
@@ -2383,7 +2356,8 @@ free_state (SIM_DESC sd)
 }
 
 SIM_DESC
-sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
+sim_open (SIM_OPEN_KIND kind, host_callback *cb,
+         struct bfd *abfd, char * const *argv)
 {
   char **p;
   int i;
@@ -2398,8 +2372,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
   SIM_DESC sd = sim_state_alloc (kind, cb);
   SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
 
-  callback = cb;
-
   /* 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)
     {
@@ -2413,9 +2385,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
       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);
@@ -2448,10 +2418,21 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
       return 0;
     }
 
+  /* CPU specific initialization.  */
+  for (i = 0; i < MAX_NR_PROCESSORS; ++i)
+    {
+      SIM_CPU *cpu = STATE_CPU (sd, i);
+
+      CPU_REG_FETCH (cpu) = sh_reg_fetch;
+      CPU_REG_STORE (cpu) = sh_reg_store;
+      CPU_PC_FETCH (cpu) = sh_pc_get;
+      CPU_PC_STORE (cpu) = sh_pc_set;
+    }
+
   for (p = argv + 1; *p != NULL; ++p)
     {
       if (isdigit (**p))
-       parse_and_set_memory_size (*p);
+       parse_and_set_memory_size (sd, *p);
     }
 
   if (abfd)
@@ -2469,25 +2450,20 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
 }
 
 static void
-parse_and_set_memory_size (const char *str)
+parse_and_set_memory_size (SIM_DESC sd, const char *str)
 {
   int n;
 
   n = strtol (str, NULL, 10);
-  if (n > 0 && n <= 24)
+  if (n > 0 && n <= 31)
     sim_memory_size = n;
   else
-    callback->printf_filtered (callback, "Bad memory size %d; must be 1 to 24, inclusive\n", n);
-}
-
-void
-sim_close (SIM_DESC sd, int quitting)
-{
-  /* nothing to do */
+    sim_io_printf (sd, "Bad memory size %d; must be 1 to 31, inclusive\n", n);
 }
 
 SIM_RC
-sim_create_inferior (SIM_DESC sd, struct bfd *prog_bfd, char **argv, char **env)
+sim_create_inferior (SIM_DESC sd, struct bfd *prog_bfd,
+                    char * const *argv, char * const *env)
 {
   /* Clear the registers. */
   memset (&saved_state, 0,
@@ -2504,9 +2480,6 @@ sim_create_inferior (SIM_DESC sd, struct bfd *prog_bfd, char **argv, char **env)
   if (prog_bfd != NULL)
     init_dsp (prog_bfd);
 
-  /* Record the program's arguments. */
-  prog_argv = argv;
-
   return SIM_RC_OK;
 }
 
@@ -2525,17 +2498,16 @@ sim_do_command (SIM_DESC sd, const char *cmd)
   if (strncmp (cmd, sms_cmd, cmdsize) == 0 
       && strchr (" \t", cmd[cmdsize]) != NULL)
     {
-      parse_and_set_memory_size (cmd + cmdsize + 1);
+      parse_and_set_memory_size (sd, cmd + cmdsize + 1);
     }
   else if (strcmp (cmd, "help") == 0)
     {
-      (callback->printf_filtered) (callback, 
-                                  "List of SH simulator commands:\n\n");
-      (callback->printf_filtered) (callback, "set-memory-size <n> -- Set the number of address bits to use\n");
-      (callback->printf_filtered) (callback, "\n");
+      sim_io_printf (sd, "List of SH simulator commands:\n\n");
+      sim_io_printf (sd, "set-memory-size <n> -- Set the number of address bits to use\n");
+      sim_io_printf (sd, "\n");
     }
   else
     {
-      (callback->printf_filtered) (callback, "Error: \"%s\" is not a valid SH simulator command.\n", cmd);
+      sim_io_printf (sd, "Error: \"%s\" is not a valid SH simulator command.\n", cmd);
     }
 }
This page took 0.027865 seconds and 4 git commands to generate.