* gas/config/tc-avr.c: Change ISA for devices with USB support to
[external/binutils.git] / sim / m32c / gdb-if.c
index 5ef1487..83e9f1e 100644 (file)
@@ -1,6 +1,6 @@
 /* gdb.c --- sim interface to GDB.
 
-Copyright (C) 2005, 2007 Free Software Foundation, Inc.
+Copyright (C) 2005-2013 Free Software Foundation, Inc.
 Contributed by Red Hat, Inc.
 
 This file is part of the GNU simulators.
@@ -18,7 +18,7 @@ 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/>.  */
 
-
+#include "config.h"
 #include <stdio.h>
 #include <assert.h>
 #include <signal.h>
@@ -35,6 +35,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #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
@@ -58,6 +61,7 @@ sim_open (SIM_OPEN_KIND kind,
          struct host_callback_struct *callback,
          struct bfd *abfd, char **argv)
 {
+  setbuf (stdout, 0);
   if (open)
     fprintf (stderr, "m32c minisim: re-opened sim\n");
 
@@ -124,7 +128,7 @@ open_objfile (const char *filename)
 
 
 SIM_RC
-sim_load (SIM_DESC sd, char *prog, struct bfd *abfd, int from_tty)
+sim_load (SIM_DESC sd, char *prog, struct bfd * abfd, int from_tty)
 {
   check_desc (sd);
 
@@ -139,7 +143,7 @@ sim_load (SIM_DESC sd, char *prog, struct bfd *abfd, int from_tty)
 }
 
 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 **argv, char **env)
 {
   check_desc (sd);
 
@@ -163,7 +167,7 @@ sim_read (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
 }
 
 int
-sim_write (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
+sim_write (SIM_DESC sd, SIM_ADDR mem, const unsigned char *buf, int length)
 {
   check_desc (sd);
 
@@ -401,7 +405,7 @@ sim_store_register (SIM_DESC sd, int regno, unsigned char *buf, int length)
   check_desc (sd);
 
   if (!check_regno (regno))
-    return 0;
+    return -1;
 
   size = reg_size (regno);
 
@@ -498,7 +502,7 @@ sim_store_register (SIM_DESC sd, int regno, unsigned char *buf, int length)
        default:
          fprintf (stderr, "m32c minisim: unrecognized register number: %d\n",
                   regno);
-         return -1;
+         return 0;
        }
     }
 
@@ -519,52 +523,35 @@ int siggnal;
 
 
 /* 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...)  */
+   return a target signal number used by GDB.  */
 int
-m32c_signal_to_host (int m32c)
+m32c_signal_to_target (int m32c)
 {
   switch (m32c)
     {
     case 4:
-#ifdef SIGILL
-      return SIGILL;
-#else
-      return SIGSEGV;
-#endif
+      return GDB_SIGNAL_ILL;
 
     case 5:
-      return SIGTRAP;
+      return GDB_SIGNAL_TRAP;
 
     case 10:
-#ifdef SIGBUS
-      return SIGBUS;
-#else
-      return SIGSEGV;
-#endif
+      return GDB_SIGNAL_BUS;
 
     case 11:
-      return SIGSEGV;
+      return GDB_SIGNAL_SEGV;
 
     case 24:
-#ifdef SIGXCPU
-      return SIGXCPU;
-#else
-      break;
-#endif
+      return GDB_SIGNAL_XCPU;
 
     case 2:
-      return SIGINT;
+      return GDB_SIGNAL_INT;
 
     case 8:
-#ifdef SIGFPE
-      return SIGFPE;
-#else
-      break;
-#endif
+      return GDB_SIGNAL_FPE;
 
     case 6:
-      return SIGABRT;
+      return GDB_SIGNAL_ABRT;
     }
 
   return 0;
@@ -579,12 +566,12 @@ 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;
-      siggnal = m32c_signal_to_host (M32C_STOP_SIG (rc));
+      siggnal = m32c_signal_to_target (M32C_STOP_SIG (rc));
     }
   else
     {
@@ -608,7 +595,12 @@ sim_resume (SIM_DESC sd, int step, int sig_to_deliver)
     }
 
   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
@@ -621,11 +613,14 @@ sim_resume (SIM_DESC sd, int step, int sig_to_deliver)
            {
              stop = 0;
              reason = sim_stopped;
-             siggnal = TARGET_SIGNAL_INT;
+             siggnal = GDB_SIGNAL_INT;
              break;
            }
 
          int rc = decode_opcode ();
+#ifdef TIMER_A
+         update_timer_a ();
+#endif
 
          if (!M32C_STEPPED (rc))
            {
@@ -634,6 +629,7 @@ sim_resume (SIM_DESC sd, int step, int sig_to_deliver)
            }
        }
     }
+  m32c_sim_restore_console ();
 }
 
 int
@@ -706,3 +702,9 @@ sim_do_command (SIM_DESC sd, char *cmd)
     printf ("The 'sim' command expects either 'trace' or 'verbose'"
            " as a subcommand.\n");
 }
+
+char **
+sim_complete_command (SIM_DESC sd, const char *text, const char *word)
+{
+  return NULL;
+}