* serial.h (SERIAL_SET_TTY_STATE): Comment return value.
[deliverable/binutils-gdb.git] / gdb / remote-mips.c
index 6e4e62ac86fd5942a4a7afe30f7da088e428b265..0c5ee6e77b6ca98a2275bfffdf38cbb49f80efb9 100644 (file)
@@ -1,5 +1,5 @@
 /* Remote debugging interface for MIPS remote debugging protocol.
-   Copyright 1993 Free Software Foundation, Inc.
+   Copyright 1993, 1994 Free Software Foundation, Inc.
    Contributed by Cygnus Support.  Written by Ian Lance Taylor
    <ian@cygnus.com>.
 
@@ -58,7 +58,7 @@ static int mips_receive_packet PARAMS ((char *buff, int throw_error,
 
 static int
 mips_request PARAMS ((char cmd, unsigned int addr, unsigned int data,
-                     int *perr, timeout));
+                     int *perr, int timeout));
 
 static void
 mips_initialize PARAMS ((void));
@@ -72,11 +72,11 @@ mips_close PARAMS ((int quitting));
 static void
 mips_detach PARAMS ((char *args, int from_tty));
 
-static void
-mips_resume PARAMS ((int pid, int step, int siggnal));
+static void mips_resume PARAMS ((int pid, int step,
+                                enum target_signal siggnal));
 
 static int
-mips_wait PARAMS ((int pid, WAITTYPE *status));
+mips_wait PARAMS ((int pid, struct target_waitstatus *status));
 
 static int
 mips_map_regno PARAMS ((int regno));
@@ -888,6 +888,13 @@ mips_request (cmd, addr, data, perr, timeout)
   return rresponse;
 }
 
+static void
+mips_initialize_cleanups (arg)
+     PTR arg;
+{
+  mips_initializing = 0;
+}
+
 /* Initialize a new connection to the MIPS board, and make sure we are
    really connected.  */
 
@@ -897,9 +904,16 @@ mips_initialize ()
   char cr;
   char buff[DATA_MAXLEN + 1];
   int err;
+  struct cleanup *old_cleanups = make_cleanup (mips_initialize_cleanups, NULL);
 
+  /* What is this code doing here?  I don't see any way it can happen, and
+     it might mean mips_initializing didn't get cleared properly.
+     So I'll make it a warning.  */
   if (mips_initializing)
-    return;
+    {
+      warning ("internal error: mips_initialize called twice");
+      return;
+    }
 
   mips_initializing = 1;
 
@@ -929,7 +943,7 @@ mips_initialize ()
     }
   mips_receive_packet (buff, 1, 3);
 
-  mips_initializing = 0;
+  do_cleanups (old_cleanups);
 
   /* If this doesn't call error, we have connected; we don't care if
      the request itself succeeds or fails.  */
@@ -1011,11 +1025,13 @@ mips_detach (args, from_tty)
 
 static void
 mips_resume (pid, step, siggnal)
-     int pid, step, siggnal;
+     int pid, step;
+     enum target_signal siggnal;
 {
-  if (siggnal)
-    mips_error ("Can't send signals to a remote system.  Try `handle %d ignore'.",
-          siggnal);
+  if (siggnal != TARGET_SIGNAL_0)
+    warning
+      ("Can't send signals to a remote system.  Try `handle %s ignore'.",
+       target_signal_to_name (siggnal));
 
   mips_request (step ? 's' : 'c',
                (unsigned int) 1,
@@ -1024,12 +1040,32 @@ mips_resume (pid, step, siggnal)
                mips_receive_wait);
 }
 
+/* Return the signal corresponding to SIG, where SIG is the number which
+   the MIPS protocol uses for the signal.  */
+enum target_signal
+mips_signal_from_protocol (sig)
+     int sig;
+{
+  /* We allow a few more signals than the IDT board actually returns, on
+     the theory that there is at least *some* hope that perhaps the numbering
+     for these signals is widely agreed upon.  */
+  if (sig <= 0
+      || sig > 31)
+    return TARGET_SIGNAL_UNKNOWN;
+
+  /* Don't want to use target_signal_from_host because we are converting
+     from MIPS signal numbers, not host ones.  Our internal numbers
+     match the MIPS numbers for the signals the board can return, which
+     are: SIGINT, SIGSEGV, SIGBUS, SIGILL, SIGFPE, SIGTRAP.  */
+  return (enum target_signal) sig;
+}
+
 /* Wait until the remote stops, and return a wait status.  */
 
 static int
 mips_wait (pid, status)
      int pid;
-     WAITTYPE *status;
+     struct target_waitstatus *status;
 {
   int rstatus;
   int err;
@@ -1039,7 +1075,8 @@ mips_wait (pid, status)
      indicating that it is stopped.  */
   if (! mips_need_reply)
     {
-      WSETSTOP (*status, SIGTRAP);
+      status->kind = TARGET_WAITKIND_STOPPED;
+      status->value.sig = TARGET_SIGNAL_TRAP;
       return 0;
     }
 
@@ -1048,16 +1085,24 @@ mips_wait (pid, status)
   if (err)
     mips_error ("Remote failure: %s", safe_strerror (errno));
 
-  /* FIXME: The target board uses numeric signal values which are
-     those used on MIPS systems.  If the host uses different signal
-     values, we need to translate here.  I believe all Unix systems
-     use the same values for the signals the board can return, which
-     are: SIGINT, SIGSEGV, SIGBUS, SIGILL, SIGFPE, SIGTRAP.  */
-
-  /* FIXME: The target board uses a standard Unix wait status int.  If
-     the host system does not, we must translate here.  */
-
-  *status = rstatus;
+  /* Translate a MIPS waitstatus.  We use constants here rather than WTERMSIG
+     and so on, because the constants we want here are determined by the
+     MIPS protocol and have nothing to do with what host we are running on.  */
+  if ((rstatus & 0377) == 0)
+    {
+      status->kind = TARGET_WAITKIND_EXITED;
+      status->value.integer = (((rstatus) >> 8) & 0377);
+    }
+  else if ((rstatus & 0377) == 0177)
+    {
+      status->kind = TARGET_WAITKIND_STOPPED;
+      status->value.sig = mips_signal_from_protocol (((rstatus) >> 8) & 0377);
+    }
+  else
+    {
+      status->kind = TARGET_WAITKIND_SIGNALLED;
+      status->value.sig = mips_signal_from_protocol (rstatus & 0177);
+    }
 
   return 0;
 }
@@ -1320,7 +1365,7 @@ mips_create_inferior (execfile, args, env)
 
   /* FIXME: Should we set inferior_pid here?  */
 
-  proceed (entry_pt, -1, 0);
+  proceed (entry_pt, TARGET_SIGNAL_DEFAULT, 0);
 }
 
 /* Clean up after a process.  Actually nothing to do.  */
@@ -1338,8 +1383,10 @@ struct target_ops mips_ops =
 {
   "mips",                      /* to_shortname */
   "Remote MIPS debugging over serial line",    /* to_longname */
-  "Debug a board using the MIPS remote debugging protocol over a serial line.\n\
-Specify the serial device it is connected to (e.g., /dev/ttya).",  /* to_doc */
+  "\
+Debug a board using the MIPS remote debugging protocol over a serial line.\n\
+The argument is the device it is connected to or, if it contains a colon,\n\
+HOST:PORT to access a board over a network",  /* to_doc */
   mips_open,                   /* to_open */
   mips_close,                  /* to_close */
   NULL,                                /* to_attach */
This page took 0.025117 seconds and 4 git commands to generate.