gdb/
[deliverable/binutils-gdb.git] / gdb / remote-sds.c
index f7fbf00fae1bd52214a5016830258b6bf95675ce..8394ae5870871cad24dad7a303f20dee01286c0f 100644 (file)
@@ -1,5 +1,7 @@
 /* Remote target communications for serial-line targets using SDS' protocol.
-   Copyright 1997 Free Software Foundation, Inc.
+
+   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2006 Free Software
+   Foundation, Inc.
 
    This file is part of GDB.
 
@@ -15,8 +17,8 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301, USA.  */
 
 /* This interface was written by studying the behavior of the SDS
    monitor on an ADS 821/860 board, and by consulting the
 #include <fcntl.h>
 #include "frame.h"
 #include "inferior.h"
+#include "exceptions.h"
 #include "bfd.h"
 #include "symfile.h"
 #include "target.h"
-#include "gdb_wait.h"
 #include "gdbcmd.h"
 #include "objfiles.h"
 #include "gdb-stabs.h"
 #include "gdbthread.h"
 #include "gdbcore.h"
-#include "dcache.h"
-
-#ifdef USG
-#include <sys/types.h>
-#endif
+#include "regcache.h"
 
 #include <signal.h>
 #include "serial.h"
@@ -56,15 +54,16 @@ static int sds_read_bytes (CORE_ADDR, char *, int);
 
 static void sds_files_info (struct target_ops *ignore);
 
-static int sds_xfer_memory (CORE_ADDR, char *, int, int, struct target_ops *);
+static int sds_xfer_memory (CORE_ADDR, char *, int, int, 
+                           struct mem_attrib *, struct target_ops *);
 
 static void sds_prepare_to_store (void);
 
 static void sds_fetch_registers (int);
 
-static void sds_resume (int, int, enum target_signal);
+static void sds_resume (ptid_t, int, enum target_signal);
 
-static int sds_start_remote (PTR);
+static int sds_start_remote (void *);
 
 static void sds_open (char *, int);
 
@@ -74,8 +73,6 @@ static void sds_store_registers (int);
 
 static void sds_mourn (void);
 
-static void sds_create_inferior (char *, char *, char **);
-
 static void sds_load (char *, int);
 
 static int getmessage (unsigned char *, int);
@@ -86,12 +83,10 @@ static int sds_send (unsigned char *, int);
 
 static int readchar (int);
 
-static int sds_wait (int, struct target_waitstatus *);
+static ptid_t sds_wait (ptid_t, struct target_waitstatus *);
 
 static void sds_kill (void);
 
-static int tohex (int);
-
 static int fromhex (int);
 
 static void sds_detach (char *, int);
@@ -104,10 +99,6 @@ static void interrupt_query (void);
 
 static int read_frame (char *);
 
-static int sds_insert_breakpoint (CORE_ADDR, char *);
-
-static int sds_remove_breakpoint (CORE_ADDR, char *);
-
 static void init_sds_ops (void);
 
 static void sds_command (char *args, int from_tty);
@@ -127,7 +118,7 @@ static int sds_timeout = 2;
    that sds_open knows that we don't have a file open when the program
    starts.  */
 
-static serial_t sds_desc = NULL;
+static struct serial *sds_desc = NULL;
 
 /* This limit comes from the monitor.  */
 
@@ -146,28 +137,27 @@ static int message_pending;
 
 /* Clean up connection to a remote debugger.  */
 
-/* ARGSUSED */
 static void
 sds_close (int quitting)
 {
   if (sds_desc)
-    SERIAL_CLOSE (sds_desc);
+    serial_close (sds_desc);
   sds_desc = NULL;
 }
 
 /* Stub for catch_errors.  */
 
 static int
-sds_start_remote (PTR dummy)
+sds_start_remote (void *dummy)
 {
-  char c;
+  int c;
   unsigned char buf[200];
 
   immediate_quit++;            /* Allow user to interrupt it */
 
   /* Ack any packet which the remote side has already sent.  */
-  SERIAL_WRITE (sds_desc, "{#*\r\n", 5);
-  SERIAL_WRITE (sds_desc, "{#}\r\n", 5);
+  serial_write (sds_desc, "{#*\r\n", 5);
+  serial_write (sds_desc, "{#}\r\n", 5);
 
   while ((c = readchar (1)) >= 0)
     printf_unfiltered ("%c", c);
@@ -190,8 +180,6 @@ sds_start_remote (PTR dummy)
 /* Open a connection to a remote debugger.
    NAME is the filename used for communication.  */
 
-static DCACHE *sds_dcache;
-
 static void
 sds_open (char *name, int from_tty)
 {
@@ -203,30 +191,25 @@ device is attached to the remote system (e.g. /dev/ttya).");
 
   unpush_target (&sds_ops);
 
-  if (!sds_dcache)
-    sds_dcache = dcache_init (sds_read_bytes, sds_write_bytes);
-  else
-    dcache_invd (sds_dcache);
-
-  sds_desc = SERIAL_OPEN (name);
+  sds_desc = serial_open (name);
   if (!sds_desc)
     perror_with_name (name);
 
   if (baud_rate != -1)
     {
-      if (SERIAL_SETBAUDRATE (sds_desc, baud_rate))
+      if (serial_setbaudrate (sds_desc, baud_rate))
        {
-         SERIAL_CLOSE (sds_desc);
+         serial_close (sds_desc);
          perror_with_name (name);
        }
     }
 
 
-  SERIAL_RAW (sds_desc);
+  serial_raw (sds_desc);
 
   /* If there is something sitting in the buffer we might take it as a
      response to a command, which would be bad.  */
-  SERIAL_FLUSH_INPUT (sds_desc);
+  serial_flush_input (sds_desc);
 
   if (from_tty)
     {
@@ -284,17 +267,6 @@ fromhex (int a)
     error ("Reply contains invalid hex digit %d", a);
 }
 
-/* Convert number NIB to a hex digit.  */
-
-static int
-tohex (int nib)
-{
-  if (nib < 10)
-    return '0' + nib;
-  else
-    return 'a' + nib - 10;
-}
-
 static int
 tob64 (unsigned char *inbuf, char *outbuf, int len)
 {
@@ -354,12 +326,10 @@ static enum target_signal last_sent_signal = TARGET_SIGNAL_0;
 int last_sent_step;
 
 static void
-sds_resume (int pid, int step, enum target_signal siggnal)
+sds_resume (ptid_t ptid, int step, enum target_signal siggnal)
 {
   unsigned char buf[PBUFSIZ];
 
-  dcache_invd (sds_dcache);
-
   last_sent_signal = siggnal;
   last_sent_step = step;
 
@@ -412,7 +382,7 @@ interrupt_query (void)
 Give up (and stop debugging it)? "))
     {
       target_mourn_inferior ();
-      return_to_top_level (RETURN_QUIT);
+      deprecated_throw_reason (RETURN_QUIT);
     }
 
   target_terminal_inferior ();
@@ -425,8 +395,8 @@ int kill_kludge;
    STATUS just as `wait' would.  Returns "pid" (though it's not clear
    what, if anything, that means in the case of this target).  */
 
-static int
-sds_wait (int pid, struct target_waitstatus *status)
+static ptid_t
+sds_wait (ptid_t ptid, struct target_waitstatus *status)
 {
   unsigned char buf[PBUFSIZ];
   int retlen;
@@ -442,7 +412,7 @@ sds_wait (int pid, struct target_waitstatus *status)
     {
       just_started = 0;
       status->kind = TARGET_WAITKIND_STOPPED;
-      return inferior_pid;
+      return inferior_ptid;
     }
 
   while (1)
@@ -466,7 +436,7 @@ sds_wait (int pid, struct target_waitstatus *status)
        }
     }
 got_status:
-  return inferior_pid;
+  return inferior_ptid;
 }
 
 static unsigned char sprs[16];
@@ -474,16 +444,15 @@ static unsigned char sprs[16];
 /* Read the remote registers into the block REGS.  */
 /* Currently we just read all the registers, so we don't use regno.  */
 
-/* ARGSUSED */
 static void
 sds_fetch_registers (int regno)
 {
   unsigned char buf[PBUFSIZ];
   int i, retlen;
-  char regs[REGISTER_BYTES];
+  char *regs = alloca (deprecated_register_bytes ());
 
   /* Unimplemented registers read as all bits zero.  */
-  memset (regs, 0, REGISTER_BYTES);
+  memset (regs, 0, deprecated_register_bytes ());
 
   buf[0] = 18;
   buf[1] = 1;
@@ -506,7 +475,8 @@ sds_fetch_registers (int regno)
   /* (should warn about reply too short) */
 
   for (i = 0; i < NUM_REGS; i++)
-    supply_register (i, &regs[REGISTER_BYTE (i)]);
+    regcache_raw_supply (current_regcache, i,
+                        &regs[DEPRECATED_REGISTER_BYTE (i)]);
 }
 
 /* Prepare to store registers.  Since we may send them all, we have to
@@ -516,7 +486,7 @@ static void
 sds_prepare_to_store (void)
 {
   /* Make sure the entire registers array is valid.  */
-  read_register_bytes (0, (char *) NULL, REGISTER_BYTES);
+  deprecated_read_register_bytes (0, (char *) NULL, deprecated_register_bytes ());
 }
 
 /* Store register REGNO, or all registers if REGNO == -1, from the contents
@@ -535,7 +505,7 @@ sds_store_registers (int regno)
   *p++ = 0;
   *p++ = 0;
   for (i = 0; i < 4 * 6; i++)
-    *p++ = registers[i + 4 * 32 + 8 * 32];
+    *p++ = deprecated_registers[i + 4 * 32 + 8 * 32];
   for (i = 0; i < 4 * 1; i++)
     *p++ = 0;
   for (i = 0; i < 4 * 4; i++)
@@ -550,7 +520,7 @@ sds_store_registers (int regno)
   *p++ = 0;
   *p++ = 0;
   for (i = 0; i < 4 * 32; i++)
-    *p++ = registers[i];
+    *p++ = deprecated_registers[i];
 
   sds_send (buf, p - buf);
 
@@ -662,18 +632,20 @@ sds_read_bytes (CORE_ADDR memaddr, char *myaddr, int len)
 /* Read or write LEN bytes from inferior memory at MEMADDR,
    transferring to or from debugger address MYADDR.  Write to inferior
    if SHOULD_WRITE is nonzero.  Returns length of data written or
-   read; 0 for error.  */
+   read; 0 for error.  TARGET is unused.  */
 
-/* ARGSUSED */
 static int
-sds_xfer_memory (memaddr, myaddr, len, should_write, target)
-     CORE_ADDR memaddr;
-     char *myaddr;
-     int len;
-     int should_write;
-     struct target_ops *target;        /* ignored */
+sds_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int should_write,
+                struct mem_attrib *attrib, struct target_ops *target)
 {
-  return dcache_xfer_memory (sds_dcache, memaddr, myaddr, len, should_write);
+  int res;
+
+  if (should_write)
+    res = sds_write_bytes (memaddr, myaddr, len);
+  else
+    res = sds_read_bytes (memaddr, myaddr, len);
+  
+  return res;
 }
 \f
 
@@ -693,7 +665,7 @@ readchar (int timeout)
 {
   int ch;
 
-  ch = SERIAL_READCHAR (sds_desc, timeout);
+  ch = serial_readchar (sds_desc, timeout);
 
   if (remote_debug > 1 && ch >= 0)
     fprintf_unfiltered (gdb_stdlog, "%c(%x)", ch, ch);
@@ -752,7 +724,7 @@ putmessage (unsigned char *buf, int len)
      and giving it a checksum.  */
 
   if (len > 170)               /* Prosanity check */
-    abort ();
+    internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
 
   if (remote_debug)
     {
@@ -804,7 +776,7 @@ putmessage (unsigned char *buf, int len)
                              header[0], header[1], header[2]);
          gdb_flush (gdb_stdlog);
        }
-      if (SERIAL_WRITE (sds_desc, buf2, p - buf2))
+      if (serial_write (sds_desc, buf2, p - buf2))
        perror_with_name ("putmessage: write failed");
 
       return 1;
@@ -982,6 +954,7 @@ getmessage (unsigned char *buf, int forever)
       /* Try the whole thing again.  */
     retry:
       /* need to do something here */
+      ;
     }
 
   /* We have tried hard enough, and just can't receive the packet.  Give up. */
@@ -1004,15 +977,14 @@ sds_mourn (void)
 }
 
 static void
-sds_create_inferior (char *exec_file, char *args, char **env)
+sds_create_inferior (char *exec_file, char *args, char **env, int from_tty)
 {
-  inferior_pid = 42000;
+  inferior_ptid = pid_to_ptid (42000);
 
   /* Clean up from the last time we were running.  */
   clear_proceed_status ();
 
-  /* Let the remote process run.  */
-  proceed (bfd_get_start_address (exec_bfd), TARGET_SIGNAL_0, 0);
+  write_pc (bfd_get_start_address (exec_bfd));
 }
 
 static void
@@ -1020,7 +992,7 @@ sds_load (char *filename, int from_tty)
 {
   generic_load (filename, from_tty);
 
-  inferior_pid = 0;
+  inferior_ptid = null_ptid;
 }
 \f
 /* The SDS monitor has commands for breakpoint insertion, although it
@@ -1028,8 +1000,9 @@ sds_load (char *filename, int from_tty)
    replaced instruction back to the debugger.  */
 
 static int
-sds_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
+sds_insert_breakpoint (struct bp_target_info *bp_tgt)
 {
+  CORE_ADDR addr = bp_tgt->placed_address;
   int i, retlen;
   unsigned char *p, buf[PBUFSIZ];
 
@@ -1044,14 +1017,15 @@ sds_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
   retlen = sds_send (buf, p - buf);
 
   for (i = 0; i < 4; ++i)
-    contents_cache[i] = buf[i + 2];
+    bp_tgt->shadow_contents[i] = buf[i + 2];
 
   return 0;
 }
 
 static int
-sds_remove_breakpoint (CORE_ADDR addr, char *contents_cache)
+sds_remove_breakpoint (struct bp_target_info *bp_tgt)
 {
+  CORE_ADDR addr = bp_tgt->placed_address;
   int i, retlen;
   unsigned char *p, buf[PBUFSIZ];
 
@@ -1063,7 +1037,7 @@ sds_remove_breakpoint (CORE_ADDR addr, char *contents_cache)
   *p++ = (int) (addr >> 8) & 0xff;
   *p++ = (int) (addr) & 0xff;
   for (i = 0; i < 4; ++i)
-    *p++ = contents_cache[i];
+    *p++ = bp_tgt->shadow_contents[i];
 
   retlen = sds_send (buf, p - buf);
 
@@ -1085,7 +1059,7 @@ Specify the serial device it is connected to (e.g. /dev/ttya).";
   sds_ops.to_fetch_registers = sds_fetch_registers;
   sds_ops.to_store_registers = sds_store_registers;
   sds_ops.to_prepare_to_store = sds_prepare_to_store;
-  sds_ops.to_xfer_memory = sds_xfer_memory;
+  sds_ops.deprecated_xfer_memory = sds_xfer_memory;
   sds_ops.to_files_info = sds_files_info;
   sds_ops.to_insert_breakpoint = sds_insert_breakpoint;
   sds_ops.to_remove_breakpoint = sds_remove_breakpoint;
@@ -1139,11 +1113,13 @@ _initialize_remote_sds (void)
   init_sds_ops ();
   add_target (&sds_ops);
 
-  add_show_from_set (add_set_cmd ("sdstimeout", no_class,
-                                 var_integer, (char *) &sds_timeout,
-                            "Set timeout value for sds read.\n", &setlist),
-                    &showlist);
+  add_setshow_integer_cmd ("sdstimeout", no_class, &sds_timeout, _("\
+Set timeout value for sds read."), _("\
+Show timeout value for sds read."), NULL,
+                          NULL,
+                          NULL, /* FIXME: i18n: */
+                          &setlist, &showlist);
 
   add_com ("sds", class_obscure, sds_command,
-          "Send a command to the SDS monitor.");
+          _("Send a command to the SDS monitor."));
 }
This page took 0.053284 seconds and 4 git commands to generate.