]> Git Repo - binutils.git/blobdiff - sim/m32c/gdb-if.c
Automatic date update in version.in
[binutils.git] / sim / m32c / gdb-if.c
index 5ef1487be942cc49fc291ee820230372beceb6d7..2b33f40306b85453f418b31ce06c13e730145be9 100644 (file)
@@ -1,6 +1,6 @@
 /* gdb.c --- sim interface to GDB.
 
 /* gdb.c --- sim interface to GDB.
 
-Copyright (C) 2005, 2007 Free Software Foundation, Inc.
+Copyright (C) 2005-2022 Free Software Foundation, Inc.
 Contributed by Red Hat, Inc.
 
 This file is part of the GNU simulators.
 Contributed by Red Hat, Inc.
 
 This file is part of the GNU simulators.
@@ -18,16 +18,20 @@ GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include <stdio.h>
 #include <assert.h>
 #include <signal.h>
 
 #include <stdio.h>
 #include <assert.h>
 #include <signal.h>
+#include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
 
 #include "ansidecl.h"
 #include <string.h>
 #include <ctype.h>
 
 #include "ansidecl.h"
-#include "gdb/callback.h"
-#include "gdb/remote-sim.h"
+#include "libiberty.h"
+#include "sim/callback.h"
+#include "sim/sim.h"
 #include "gdb/signals.h"
 #include "gdb/sim-m32c.h"
 
 #include "gdb/signals.h"
 #include "gdb/sim-m32c.h"
 
@@ -35,6 +39,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "mem.h"
 #include "load.h"
 #include "syscalls.h"
 #include "mem.h"
 #include "load.h"
 #include "syscalls.h"
+#ifdef TIMER_A
+#include "timer_a.h"
+#endif
 
 /* I don't want to wrap up all the minisim's data structures in an
    object and pass that around.  That'd be a big change, and neither
 
 /* I don't want to wrap up all the minisim's data structures in an
    object and pass that around.  That'd be a big change, and neither
@@ -51,14 +58,15 @@ static struct sim_state the_minisim = {
   "This is the sole m32c minisim instance.  See libsim.a's global variables."
 };
 
   "This is the sole m32c minisim instance.  See libsim.a's global variables."
 };
 
-static int open;
+static int is_open;
 
 SIM_DESC
 sim_open (SIM_OPEN_KIND kind,
          struct host_callback_struct *callback,
 
 SIM_DESC
 sim_open (SIM_OPEN_KIND kind,
          struct host_callback_struct *callback,
-         struct bfd *abfd, char **argv)
+         struct bfd *abfd, char * const *argv)
 {
 {
-  if (open)
+  setbuf (stdout, 0);
+  if (is_open)
     fprintf (stderr, "m32c minisim: re-opened sim\n");
 
   /* The 'run' interface doesn't use this function, so we don't care
     fprintf (stderr, "m32c minisim: re-opened sim\n");
 
   /* The 'run' interface doesn't use this function, so we don't care
@@ -80,7 +88,7 @@ sim_open (SIM_OPEN_KIND kind,
   init_mem ();
   init_regs ();
 
   init_mem ();
   init_regs ();
 
-  open = 1;
+  is_open = 1;
   return &the_minisim;
 }
 
   return &the_minisim;
 }
 
@@ -99,7 +107,7 @@ sim_close (SIM_DESC sd, int quitting)
   /* Not much to do.  At least free up our memory.  */
   init_mem ();
 
   /* Not much to do.  At least free up our memory.  */
   init_mem ();
 
-  open = 0;
+  is_open = 0;
 }
 
 static bfd *
 }
 
 static bfd *
@@ -124,7 +132,7 @@ open_objfile (const char *filename)
 
 
 SIM_RC
 
 
 SIM_RC
-sim_load (SIM_DESC sd, char *prog, struct bfd *abfd, int from_tty)
+sim_load (SIM_DESC sd, const char *prog, struct bfd * abfd, int from_tty)
 {
   check_desc (sd);
 
 {
   check_desc (sd);
 
@@ -139,7 +147,8 @@ sim_load (SIM_DESC sd, char *prog, struct bfd *abfd, int from_tty)
 }
 
 SIM_RC
 }
 
 SIM_RC
-sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char **argv, char **env)
+sim_create_inferior (SIM_DESC sd, struct bfd * abfd,
+                    char * const *argv, char * const *env)
 {
   check_desc (sd);
 
 {
   check_desc (sd);
 
@@ -150,7 +159,7 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char **argv, char **env)
 }
 
 int
 }
 
 int
-sim_read (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
+sim_read (SIM_DESC sd, SIM_ADDR mem, void *buf, int length)
 {
   check_desc (sd);
 
 {
   check_desc (sd);
 
@@ -163,7 +172,7 @@ sim_read (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
 }
 
 int
 }
 
 int
-sim_write (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
+sim_write (SIM_DESC sd, SIM_ADDR mem, const void *buf, int length)
 {
   check_desc (sd);
 
 {
   check_desc (sd);
 
@@ -175,7 +184,7 @@ sim_write (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
 
 /* Read the LENGTH bytes at BUF as an little-endian value.  */
 static DI
 
 /* Read the LENGTH bytes at BUF as an little-endian value.  */
 static DI
-get_le (unsigned char *buf, int length)
+get_le (const unsigned char *buf, int length)
 {
   DI acc = 0;
   while (--length >= 0)
 {
   DI acc = 0;
   while (--length >= 0)
@@ -282,7 +291,7 @@ reg_size (enum m32c_sim_reg regno)
 }
 
 int
 }
 
 int
-sim_fetch_register (SIM_DESC sd, int regno, unsigned char *buf, int length)
+sim_fetch_register (SIM_DESC sd, int regno, void *buf, int length)
 {
   size_t size;
 
 {
   size_t size;
 
@@ -394,14 +403,14 @@ sim_fetch_register (SIM_DESC sd, int regno, unsigned char *buf, int length)
 }
 
 int
 }
 
 int
-sim_store_register (SIM_DESC sd, int regno, unsigned char *buf, int length)
+sim_store_register (SIM_DESC sd, int regno, const void *buf, int length)
 {
   size_t size;
 
   check_desc (sd);
 
   if (!check_regno (regno))
 {
   size_t size;
 
   check_desc (sd);
 
   if (!check_regno (regno))
-    return 0;
+    return -1;
 
   size = reg_size (regno);
 
 
   size = reg_size (regno);
 
@@ -498,73 +507,48 @@ sim_store_register (SIM_DESC sd, int regno, unsigned char *buf, int length)
        default:
          fprintf (stderr, "m32c minisim: unrecognized register number: %d\n",
                   regno);
        default:
          fprintf (stderr, "m32c minisim: unrecognized register number: %d\n",
                   regno);
-         return -1;
+         return 0;
        }
     }
 
   return size;
 }
 
        }
     }
 
   return size;
 }
 
-void
-sim_info (SIM_DESC sd, int verbose)
-{
-  check_desc (sd);
-
-  printf ("The m32c minisim doesn't collect any statistics.\n");
-}
-
 static volatile int stop;
 static enum sim_stop reason;
 static volatile int stop;
 static enum sim_stop reason;
-int siggnal;
+static int siggnal;
 
 
 /* Given a signal number used by the M32C bsp (that is, newlib),
 
 
 /* Given a signal number used by the M32C bsp (that is, newlib),
-   return a host signal number.  (Oddly, the gdb/sim interface uses
-   host signal numbers...)  */
-int
-m32c_signal_to_host (int m32c)
+   return a target signal number used by GDB.  */
+static int
+m32c_signal_to_target (int m32c)
 {
   switch (m32c)
     {
     case 4:
 {
   switch (m32c)
     {
     case 4:
-#ifdef SIGILL
-      return SIGILL;
-#else
-      return SIGSEGV;
-#endif
+      return GDB_SIGNAL_ILL;
 
     case 5:
 
     case 5:
-      return SIGTRAP;
+      return GDB_SIGNAL_TRAP;
 
     case 10:
 
     case 10:
-#ifdef SIGBUS
-      return SIGBUS;
-#else
-      return SIGSEGV;
-#endif
+      return GDB_SIGNAL_BUS;
 
     case 11:
 
     case 11:
-      return SIGSEGV;
+      return GDB_SIGNAL_SEGV;
 
     case 24:
 
     case 24:
-#ifdef SIGXCPU
-      return SIGXCPU;
-#else
-      break;
-#endif
+      return GDB_SIGNAL_XCPU;
 
     case 2:
 
     case 2:
-      return SIGINT;
+      return GDB_SIGNAL_INT;
 
     case 8:
 
     case 8:
-#ifdef SIGFPE
-      return SIGFPE;
-#else
-      break;
-#endif
+      return GDB_SIGNAL_FPE;
 
     case 6:
 
     case 6:
-      return SIGABRT;
+      return GDB_SIGNAL_ABRT;
     }
 
   return 0;
     }
 
   return 0;
@@ -573,18 +557,18 @@ m32c_signal_to_host (int m32c)
 
 /* Take a step return code RC and set up the variables consulted by
    sim_stop_reason appropriately.  */
 
 /* Take a step return code RC and set up the variables consulted by
    sim_stop_reason appropriately.  */
-void
+static void
 handle_step (int rc)
 {
   if (M32C_STEPPED (rc) || M32C_HIT_BREAK (rc))
     {
       reason = sim_stopped;
 handle_step (int rc)
 {
   if (M32C_STEPPED (rc) || M32C_HIT_BREAK (rc))
     {
       reason = sim_stopped;
-      siggnal = TARGET_SIGNAL_TRAP;
+      siggnal = GDB_SIGNAL_TRAP;
     }
   else if (M32C_STOPPED (rc))
     {
       reason = sim_stopped;
     }
   else if (M32C_STOPPED (rc))
     {
       reason = sim_stopped;
-      siggnal = m32c_signal_to_host (M32C_STOP_SIG (rc));
+      siggnal = m32c_signal_to_target (M32C_STOP_SIG (rc));
     }
   else
     {
     }
   else
     {
@@ -608,7 +592,12 @@ sim_resume (SIM_DESC sd, int step, int sig_to_deliver)
     }
 
   if (step)
     }
 
   if (step)
-    handle_step (decode_opcode ());
+    {
+      handle_step (decode_opcode ());
+#ifdef TIMER_A
+      update_timer_a ();
+#endif
+    }
   else
     {
       /* We don't clear 'stop' here, because then we would miss
   else
     {
       /* We don't clear 'stop' here, because then we would miss
@@ -617,15 +606,20 @@ sim_resume (SIM_DESC sd, int step, int sig_to_deliver)
          interrupt signal handler.  */
       for (;;)
        {
          interrupt signal handler.  */
       for (;;)
        {
+         int rc;
+
          if (stop)
            {
              stop = 0;
              reason = sim_stopped;
          if (stop)
            {
              stop = 0;
              reason = sim_stopped;
-             siggnal = TARGET_SIGNAL_INT;
+             siggnal = GDB_SIGNAL_INT;
              break;
            }
 
              break;
            }
 
-         int rc = decode_opcode ();
+         rc = decode_opcode ();
+#ifdef TIMER_A
+         update_timer_a ();
+#endif
 
          if (!M32C_STEPPED (rc))
            {
 
          if (!M32C_STEPPED (rc))
            {
@@ -634,6 +628,7 @@ sim_resume (SIM_DESC sd, int step, int sig_to_deliver)
            }
        }
     }
            }
        }
     }
+  m32c_sim_restore_console ();
 }
 
 int
 }
 
 int
@@ -654,39 +649,27 @@ sim_stop_reason (SIM_DESC sd, enum sim_stop *reason_p, int *sigrc_p)
 }
 
 void
 }
 
 void
-sim_do_command (SIM_DESC sd, char *cmd)
+sim_do_command (SIM_DESC sd, const char *cmd)
 {
 {
-  check_desc (sd);
-
-  char *p = cmd;
-
-  /* Skip leading whitespace.  */
-  while (isspace (*p))
-    p++;
+  const char *arg;
+  char **argv = buildargv (cmd);
 
 
-  /* Find the extent of the command word.  */
-  for (p = cmd; *p; p++)
-    if (isspace (*p))
-      break;
+  check_desc (sd);
 
 
-  /* Null-terminate the command word, and record the start of any
-     further arguments.  */
-  char *args;
-  if (*p)
+  cmd = arg = "";
+  if (argv != NULL)
     {
     {
-      *p = '\0';
-      args = p + 1;
-      while (isspace (*args))
-       args++;
+      if (argv[0] != NULL)
+       cmd = argv[0];
+      if (argv[1] != NULL)
+       arg = argv[1];
     }
     }
-  else
-    args = p;
 
   if (strcmp (cmd, "trace") == 0)
     {
 
   if (strcmp (cmd, "trace") == 0)
     {
-      if (strcmp (args, "on") == 0)
+      if (strcmp (arg, "on") == 0)
        trace = 1;
        trace = 1;
-      else if (strcmp (args, "off") == 0)
+      else if (strcmp (arg, "off") == 0)
        trace = 0;
       else
        printf ("The 'sim trace' command expects 'on' or 'off' "
        trace = 0;
       else
        printf ("The 'sim trace' command expects 'on' or 'off' "
@@ -694,9 +677,9 @@ sim_do_command (SIM_DESC sd, char *cmd)
     }
   else if (strcmp (cmd, "verbose") == 0)
     {
     }
   else if (strcmp (cmd, "verbose") == 0)
     {
-      if (strcmp (args, "on") == 0)
+      if (strcmp (arg, "on") == 0)
        verbose = 1;
        verbose = 1;
-      else if (strcmp (args, "off") == 0)
+      else if (strcmp (arg, "off") == 0)
        verbose = 0;
       else
        printf ("The 'sim verbose' command expects 'on' or 'off'"
        verbose = 0;
       else
        printf ("The 'sim verbose' command expects 'on' or 'off'"
@@ -705,4 +688,24 @@ sim_do_command (SIM_DESC sd, char *cmd)
   else
     printf ("The 'sim' command expects either 'trace' or 'verbose'"
            " as a subcommand.\n");
   else
     printf ("The 'sim' command expects either 'trace' or 'verbose'"
            " as a subcommand.\n");
+
+  freeargv (argv);
+}
+
+char **
+sim_complete_command (SIM_DESC sd, const char *text, const char *word)
+{
+  return NULL;
+}
+
+char *
+sim_memory_map (SIM_DESC sd)
+{
+  return NULL;
+}
+
+void
+sim_info (SIM_DESC sd, int verbose)
+{
+  printf ("The m32c minisim doesn't collect any statistics.\n");
 }
 }
This page took 0.035535 seconds and 4 git commands to generate.