daily update
[deliverable/binutils-gdb.git] / gdb / remote-array.c
index cd3cff3e11eaa3ccb57e2eb1296e67178fbae68c..da9bfc70e68dea227902074f0a163dfa180c32c3 100644 (file)
@@ -1,5 +1,8 @@
 /* Remote debugging interface for Array Tech RAID controller..
-   Copyright 90, 91, 92, 93, 94, 1995, 1998  Free Software Foundation, Inc.
+
+   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+   1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+
    Contributed by Cygnus Support. Written by Rob Savoye for Cygnus.
 
    This module talks to a debug monitor called 'MONITOR', which
    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.
- */
+   Boston, MA 02111-1307, USA.  */
 
 #include "defs.h"
 #include "gdbcore.h"
 #include "target.h"
-#include "gdb_wait.h"
 #include <ctype.h>
-#include <signal.h>
 #include <sys/types.h>
 #include "gdb_string.h"
 #include "command.h"
 #include "remote-utils.h"
 #include "inferior.h"
 #include "version.h"
+#include "regcache.h"
 
 extern int baud_rate;
 
 #define ARRAY_PROMPT ">> "
 
-#define SWAP_TARGET_AND_HOST(buffer,len)                               \
-  do                                                                   \
-    {                                                                  \
-      if (TARGET_BYTE_ORDER != HOST_BYTE_ORDER)                                \
-       {                                                               \
-         char tmp;                                                     \
-         char *p = (char *)(buffer);                                   \
-         char *q = ((char *)(buffer)) + len - 1;                       \
-         for (; p < q; p++, q--)                                       \
-           {                                                           \
-             tmp = *q;                                                 \
-             *q = *p;                                                  \
-             *p = tmp;                                                 \
-           }                                                           \
-       }                                                               \
-    }                                                                  \
-  while (0)
-
 static void debuglogs (int, char *, ...);
 static void array_open ();
 static void array_close ();
 static void array_detach ();
 static void array_attach ();
-static void array_resume ();
+static void array_resume (ptid_t ptid, int step, enum target_signal sig);
 static void array_fetch_register ();
 static void array_store_register ();
 static void array_fetch_registers ();
@@ -79,7 +62,8 @@ static void array_create_inferior ();
 static void array_mourn_inferior ();
 static void make_gdb_packet ();
 static int array_xfer_memory ();
-static int array_wait ();
+static ptid_t array_wait (ptid_t ptid,
+                                 struct target_waitstatus *status);
 static int array_insert_breakpoint ();
 static int array_remove_breakpoint ();
 static int tohex ();
@@ -107,7 +91,7 @@ static int timeout = 30;
  * Descriptor for I/O to remote machine.  Initialize it to NULL so that
  * array_open knows that we don't have a file open when the program starts.
  */
-serial_t array_desc = NULL;
+struct serial *array_desc = NULL;
 
 /*
  * this array of registers need to match the indexes used by GDB. The
@@ -131,14 +115,9 @@ init_array_ops (void)
 Specify the serial device it is connected to (e.g. /dev/ttya).";
   array_ops.to_open = array_open;
   array_ops.to_close = array_close;
-  array_ops.to_attach = NULL;
-  array_ops.to_post_attach = NULL;
-  array_ops.to_require_attach = NULL;
   array_ops.to_detach = array_detach;
-  array_ops.to_require_detach = NULL;
   array_ops.to_resume = array_resume;
   array_ops.to_wait = array_wait;
-  array_ops.to_post_wait = NULL;
   array_ops.to_fetch_registers = array_fetch_registers;
   array_ops.to_store_registers = array_store_registers;
   array_ops.to_prepare_to_store = array_prepare_to_store;
@@ -146,48 +125,15 @@ Specify the serial device it is connected to (e.g. /dev/ttya).";
   array_ops.to_files_info = array_files_info;
   array_ops.to_insert_breakpoint = array_insert_breakpoint;
   array_ops.to_remove_breakpoint = array_remove_breakpoint;
-  array_ops.to_terminal_init = 0;
-  array_ops.to_terminal_inferior = 0;
-  array_ops.to_terminal_ours_for_output = 0;
-  array_ops.to_terminal_ours = 0;
-  array_ops.to_terminal_info = 0;
   array_ops.to_kill = array_kill;
-  array_ops.to_load = 0;
-  array_ops.to_lookup_symbol = 0;
   array_ops.to_create_inferior = array_create_inferior;
-  array_ops.to_post_startup_inferior = NULL;
-  array_ops.to_acknowledge_created_inferior = NULL;
-  array_ops.to_clone_and_follow_inferior = NULL;
-  array_ops.to_post_follow_inferior_by_clone = NULL;
-  array_ops.to_insert_fork_catchpoint = NULL;
-  array_ops.to_remove_fork_catchpoint = NULL;
-  array_ops.to_insert_vfork_catchpoint = NULL;
-  array_ops.to_remove_vfork_catchpoint = NULL;
-  array_ops.to_has_forked = NULL;
-  array_ops.to_has_vforked = NULL;
-  array_ops.to_can_follow_vfork_prior_to_exec = NULL;
-  array_ops.to_post_follow_vfork = NULL;
-  array_ops.to_insert_exec_catchpoint = NULL;
-  array_ops.to_remove_exec_catchpoint = NULL;
-  array_ops.to_has_execd = NULL;
-  array_ops.to_reported_exec_events_per_exec_call = NULL;
-  array_ops.to_has_exited = NULL;
   array_ops.to_mourn_inferior = array_mourn_inferior;
-  array_ops.to_can_run = 0;
-  array_ops.to_notice_signals = 0;
-  array_ops.to_thread_alive = 0;
-  array_ops.to_stop = 0;
-  array_ops.to_pid_to_exec_file = NULL;
-  array_ops.to_core_file_to_sym_file = NULL;
   array_ops.to_stratum = process_stratum;
-  array_ops.DONT_USE = 0;
   array_ops.to_has_all_memory = 1;
   array_ops.to_has_memory = 1;
   array_ops.to_has_stack = 1;
   array_ops.to_has_registers = 1;
   array_ops.to_has_execution = 1;
-  array_ops.to_sections = 0;
-  array_ops.to_sections_end = 0;
   array_ops.to_magic = OPS_MAGIC;
 };
 
@@ -209,8 +155,9 @@ printf_monitor (char *pattern,...)
 
   if (strlen (buf) > PBUFSIZ)
     error ("printf_monitor(): string too long");
-  if (SERIAL_WRITE (array_desc, buf, strlen (buf)))
-    fprintf (stderr, "SERIAL_WRITE failed: %s\n", safe_strerror (errno));
+  if (serial_write (array_desc, buf, strlen (buf)))
+    fprintf_unfiltered (gdb_stderr, "serial_write failed: %s\n", 
+                       safe_strerror (errno));
 }
 /*
  * write_monitor -- send raw data to monitor.
@@ -218,8 +165,9 @@ printf_monitor (char *pattern,...)
 static void
 write_monitor (char data[], int len)
 {
-  if (SERIAL_WRITE (array_desc, data, len))
-    fprintf (stderr, "SERIAL_WRITE failed: %s\n", safe_strerror (errno));
+  if (serial_write (array_desc, data, len))
+    fprintf_unfiltered (gdb_stderr, "serial_write failed: %s\n",
+                       safe_strerror (errno));
 
   *(data + len + 1) = '\0';
   debuglogs (1, "write_monitor(), Sending: \"%s\".", data);
@@ -319,7 +267,7 @@ readchar (int timeout)
 {
   int c;
 
-  c = SERIAL_READCHAR (array_desc, abs (timeout));
+  c = serial_readchar (array_desc, abs (timeout));
 
   if (sr_get_debug () > 5)
     {
@@ -508,22 +456,10 @@ get_hex_word (void)
 
   val = 0;
 
-#if 0
-  if (HOST_BYTE_ORDER == BIG_ENDIAN)
-    {
-#endif
-      for (i = 0; i < 8; i++)
-       val = (val << 4) + get_hex_digit (i == 0);
-#if 0
-    }
-  else
-    {
-      for (i = 7; i >= 0; i--)
-       val = (val << 4) + get_hex_digit (i == 0);
-    }
-#endif
+  for (i = 0; i < 8; i++)
+    val = (val << 4) + get_hex_digit (i == 0);
 
-  debuglogs (4, "get_hex_word() got a 0x%x for a %s host.", val, (HOST_BYTE_ORDER == BIG_ENDIAN) ? "big endian" : "little endian");
+  debuglogs (4, "get_hex_word() got a 0x%x.", val);
 
   return val;
 }
@@ -590,21 +526,21 @@ array_open (char *args, char *name, int from_tty)
   mips_set_processor_type_command ("lsi33k", 0);
 
   strcpy (dev_name, args);
-  array_desc = SERIAL_OPEN (dev_name);
+  array_desc = serial_open (dev_name);
 
   if (array_desc == NULL)
     perror_with_name (dev_name);
 
   if (baud_rate != -1)
     {
-      if (SERIAL_SETBAUDRATE (array_desc, baud_rate))
+      if (serial_setbaudrate (array_desc, baud_rate))
        {
-         SERIAL_CLOSE (array_desc);
+         serial_close (array_desc);
          perror_with_name (name);
        }
     }
 
-  SERIAL_RAW (array_desc);
+  serial_raw (array_desc);
 
 #if defined (LOG_FILE)
   log_file = fopen (LOG_FILE, "w");
@@ -646,7 +582,7 @@ array_open (char *args, char *name, int from_tty)
 static void
 array_close (int quitting)
 {
-  SERIAL_CLOSE (array_desc);
+  serial_close (array_desc);
   array_desc = NULL;
 
   debuglogs (1, "array_close (quitting=%d)", quitting);
@@ -698,7 +634,7 @@ array_attach (char *args, int from_tty)
  * array_resume -- Tell the remote machine to resume.
  */
 static void
-array_resume (int pid, int step, enum target_signal sig)
+array_resume (ptid_t ptid, int step, enum target_signal sig)
 {
   debuglogs (1, "array_resume (step=%d, sig=%d)", step, sig);
 
@@ -718,13 +654,13 @@ array_resume (int pid, int step, enum target_signal sig)
  * array_wait -- Wait until the remote machine stops, then return,
  *          storing status in status just as `wait' would.
  */
-static int
-array_wait (int pid, struct target_waitstatus *status)
+static ptid_t
+array_wait (ptid_t ptid, struct target_waitstatus *status)
 {
   int old_timeout = timeout;
   int result, i;
   char c;
-  serial_t tty_desc;
+  struct serial *tty_desc;
   serial_ttystate ttystate;
 
   debuglogs (1, "array_wait (), printing extraneous text.");
@@ -735,9 +671,9 @@ array_wait (int pid, struct target_waitstatus *status)
   timeout = 0;                 /* Don't time out -- user program is running. */
 
 #if !defined(__GO32__) && !defined(__MSDOS__) && !defined(_WIN32)
-  tty_desc = SERIAL_FDOPEN (0);
-  ttystate = SERIAL_GET_TTY_STATE (tty_desc);
-  SERIAL_RAW (tty_desc);
+  tty_desc = serial_fdopen (0);
+  ttystate = serial_get_tty_state (tty_desc);
+  serial_raw (tty_desc);
 
   i = 0;
   /* poll on the serial port and the keyboard. */
@@ -761,10 +697,10 @@ array_wait (int pid, struct target_waitstatus *status)
          fputc_unfiltered (c, gdb_stdout);
          gdb_flush (gdb_stdout);
        }
-      c = SERIAL_READCHAR (tty_desc, timeout);
+      c = serial_readchar (tty_desc, timeout);
       if (c > 0)
        {
-         SERIAL_WRITE (array_desc, &c, 1);
+         serial_write (array_desc, &c, 1);
          /* do this so it looks like there's keyboard echo */
          if (c == 3)           /* exit on Control-C */
            break;
@@ -774,7 +710,7 @@ array_wait (int pid, struct target_waitstatus *status)
 #endif
        }
     }
-  SERIAL_SET_TTY_STATE (tty_desc, ttystate);
+  serial_set_tty_state (tty_desc, ttystate);
 #else
   expect_prompt (1);
   debuglogs (4, "array_wait(), got the expect_prompt.");
@@ -785,7 +721,7 @@ array_wait (int pid, struct target_waitstatus *status)
 
   timeout = old_timeout;
 
-  return 0;
+  return inferior_ptid;
 }
 
 /*
@@ -795,16 +731,14 @@ array_wait (int pid, struct target_waitstatus *status)
 static void
 array_fetch_registers (int ignored)
 {
-  int regno, i;
+  char *reg = alloca (MAX_REGISTER_RAW_SIZE);
+  int regno;
   char *p;
-  unsigned char packet[PBUFSIZ];
-  char regs[REGISTER_BYTES];
+  char *packet = alloca (PBUFSIZ);
 
   debuglogs (1, "array_fetch_registers (ignored=%d)\n", ignored);
 
   memset (packet, 0, PBUFSIZ);
-  /* Unimplemented registers read as all bits zero.  */
-  memset (regs, 0, REGISTER_BYTES);
   make_gdb_packet (packet, "g");
   if (array_send_packet (packet) == 0)
     error ("Couldn't transmit packet\n");
@@ -816,10 +750,10 @@ array_fetch_registers (int ignored)
     {
       /* supply register stores in target byte order, so swap here */
       /* FIXME: convert from ASCII hex to raw bytes */
-      i = ascii2hexword (packet + (regno * 8));
+      LONGEST i = ascii2hexword (packet + (regno * 8));
       debuglogs (5, "Adding register %d = %x\n", regno, i);
-      SWAP_TARGET_AND_HOST (&i, 4);
-      supply_register (regno, (char *) &i);
+      store_unsigned_integer (&reg, REGISTER_RAW_SIZE (regno), i);
+      supply_register (regno, (char *) &reg);
     }
 }
 
@@ -1026,7 +960,7 @@ array_read_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len)
 
 static int
 array_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
-                  struct target_ops *target)
+                  struct mem_attrib *attrib, struct target_ops *target)
 {
   if (write)
     return array_write_inferior_memory (memaddr, myaddr, len);
@@ -1084,7 +1018,7 @@ array_insert_breakpoint (CORE_ADDR addr, char *shadow)
        }
     }
 
-  fprintf (stderr, "Too many breakpoints (> 16) for monitor\n");
+  fprintf_unfiltered (gdb_stderr, "Too many breakpoints (> 16) for monitor\n");
   return 1;
 }
 
@@ -1109,8 +1043,9 @@ array_remove_breakpoint (CORE_ADDR addr, char *shadow)
          return 0;
        }
     }
-  fprintf (stderr, "Can't find breakpoint associated with 0x%s\n",
-          paddr_nz (addr));
+  fprintf_unfiltered (gdb_stderr,
+                     "Can't find breakpoint associated with 0x%s\n",
+                     paddr_nz (addr));
   return 1;
 }
 
This page took 0.031543 seconds and 4 git commands to generate.