* serial.h (SERIAL_SET_TTY_STATE): Comment return value.
[deliverable/binutils-gdb.git] / gdb / remote-mips.c
index a46b450b7460432d78d1572fe8717705b80ba2dd..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>.
 
@@ -53,11 +53,12 @@ static int mips_cksum PARAMS ((const unsigned char *hdr,
 static void
 mips_send_packet PARAMS ((const char *s, int get_ack));
 
-static int mips_receive_packet PARAMS ((char *buff, int));
+static int mips_receive_packet PARAMS ((char *buff, int throw_error,
+                                       int timeout));
 
 static int
 mips_request PARAMS ((char cmd, unsigned int addr, unsigned int data,
-                     int *perr));
+                     int *perr, int timeout));
 
 static void
 mips_initialize PARAMS ((void));
@@ -71,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));
@@ -638,9 +639,10 @@ mips_send_packet (s, get_ack)
    don't print an error message and return -1.  */
 
 static int
-mips_receive_packet (buff, throw_error)
+mips_receive_packet (buff, throw_error, timeout)
      char *buff;
      int throw_error;
+     int timeout;
 {
   int ch;
   int garbage;
@@ -657,7 +659,7 @@ mips_receive_packet (buff, throw_error)
       int i;
       int err;
 
-      if (mips_receive_header (hdr, &garbage, ch, mips_receive_wait) != 0)
+      if (mips_receive_header (hdr, &garbage, ch, timeout) != 0)
        {
          if (throw_error)
            mips_error ("Timed out waiting for remote packet");
@@ -690,7 +692,7 @@ mips_receive_packet (buff, throw_error)
        {
          int rch;
 
-         rch = mips_readchar (mips_receive_wait);
+         rch = mips_readchar (timeout);
          if (rch == SYN)
            {
              ch = SYN;
@@ -714,7 +716,7 @@ mips_receive_packet (buff, throw_error)
          continue;
        }
 
-      err = mips_receive_trailer (trlr, &garbage, &ch, mips_receive_wait);
+      err = mips_receive_trailer (trlr, &garbage, &ch, timeout);
       if (err == -1)
        {
          if (throw_error)
@@ -830,11 +832,12 @@ mips_receive_packet (buff, throw_error)
    target board reports.  */
 
 static int
-mips_request (cmd, addr, data, perr)
+mips_request (cmd, addr, data, perr, timeout)
      char cmd;
      unsigned int addr;
      unsigned int data;
      int *perr;
+     int timeout;
 {
   char buff[DATA_MAXLEN + 1];
   int len;
@@ -860,7 +863,7 @@ mips_request (cmd, addr, data, perr)
 
   mips_need_reply = 0;
 
-  len = mips_receive_packet (buff, 1);
+  len = mips_receive_packet (buff, 1, timeout);
   buff[len] = '\0';
 
   if (sscanf (buff, "0x%x %c 0x%x 0x%x",
@@ -885,6 +888,13 @@ mips_request (cmd, addr, data, perr)
   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.  */
 
@@ -892,12 +902,18 @@ static void
 mips_initialize ()
 {
   char cr;
-  int hold_wait;
   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;
 
@@ -910,10 +926,7 @@ mips_initialize ()
   cr = '\r';
   SERIAL_WRITE (mips_desc, &cr, 1);
 
-  hold_wait = mips_receive_wait;
-  mips_receive_wait = 3;
-
-  if (mips_receive_packet (buff, 0) < 0)
+  if (mips_receive_packet (buff, 0, 3) < 0)
     {
       char cc;
 
@@ -928,14 +941,14 @@ mips_initialize ()
       cr = '\r';
       SERIAL_WRITE (mips_desc, &cr, 1);
     }
-  mips_receive_packet (buff, 1);
+  mips_receive_packet (buff, 1, 3);
 
-  mips_receive_wait = hold_wait;
-  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.  */
-  mips_request ('r', (unsigned int) 0, (unsigned int) 0, &err);
+  mips_request ('r', (unsigned int) 0, (unsigned int) 0, &err,
+               mips_receive_wait);
 }
 
 /* Open a connection to the remote board.  */
@@ -985,7 +998,8 @@ mips_close (quitting)
       mips_is_open = 0;
 
       /* Get the board out of remote debugging mode.  */
-      mips_request ('x', (unsigned int) 0, (unsigned int) 0, &err);
+      mips_request ('x', (unsigned int) 0, (unsigned int) 0, &err,
+                   mips_receive_wait);
 
       SERIAL_CLOSE (mips_desc);
     }
@@ -1011,16 +1025,39 @@ 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,
                (unsigned int) 0,
-               (int *) NULL);
+               (int *) NULL,
+               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.  */
@@ -1028,7 +1065,7 @@ mips_resume (pid, step, siggnal)
 static int
 mips_wait (pid, status)
      int pid;
-     WAITTYPE *status;
+     struct target_waitstatus *status;
 {
   int rstatus;
   int err;
@@ -1038,24 +1075,34 @@ 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;
     }
 
-  rstatus = mips_request ('\0', (unsigned int) 0, (unsigned int) 0, &err);
+  /* No timeout; we sit here as long as the program continues to execute.  */
+  rstatus = mips_request ('\0', (unsigned int) 0, (unsigned int) 0, &err, -1);
   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;
 }
@@ -1111,7 +1158,7 @@ mips_fetch_registers (regno)
     }
 
   val = mips_request ('r', (unsigned int) mips_map_regno (regno),
-                     (unsigned int) 0, &err);
+                     (unsigned int) 0, &err, mips_receive_wait);
   if (err)
     mips_error ("Can't read register %d: %s", regno, safe_strerror (errno));
 
@@ -1150,7 +1197,7 @@ mips_store_registers (regno)
 
   mips_request ('R', (unsigned int) mips_map_regno (regno),
                (unsigned int) read_register (regno),
-               &err);
+               &err, mips_receive_wait);
   if (err)
     mips_error ("Can't write register %d: %s", regno, safe_strerror (errno));
 }
@@ -1164,11 +1211,13 @@ mips_fetch_word (addr)
   int val;
   int err;
 
-  val = mips_request ('d', (unsigned int) addr, (unsigned int) 0, &err);
+  val = mips_request ('d', (unsigned int) addr, (unsigned int) 0, &err,
+                     mips_receive_wait);
   if (err)
     {
       /* Data space failed; try instruction space.  */
-      val = mips_request ('i', (unsigned int) addr, (unsigned int) 0, &err);
+      val = mips_request ('i', (unsigned int) addr, (unsigned int) 0, &err,
+                         mips_receive_wait);
       if (err)
        mips_error ("Can't read address 0x%x: %s", addr, safe_strerror (errno));
     }
@@ -1184,11 +1233,13 @@ mips_store_word (addr, val)
 {
   int err;
 
-  mips_request ('D', (unsigned int) addr, (unsigned int) val, &err);
+  mips_request ('D', (unsigned int) addr, (unsigned int) val, &err,
+               mips_receive_wait);
   if (err)
     {
       /* Data space failed; try instruction space.  */
-      mips_request ('I', (unsigned int) addr, (unsigned int) val, &err);
+      mips_request ('I', (unsigned int) addr, (unsigned int) val, &err,
+                   mips_receive_wait);
       if (err)
        mips_error ("Can't write address 0x%x: %s", addr, safe_strerror (errno));
     }
@@ -1314,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.  */
@@ -1332,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.027728 seconds and 4 git commands to generate.