1999-02-02 Martin Hunt <hunt@cygnus.com>
[deliverable/binutils-gdb.git] / gdb / remote-array.c
index 6939a30d5c6266de97a76b132f93c0180280874e..624871cff020d30083889d0150d6eed3e16ec4fc 100644 (file)
@@ -1,5 +1,5 @@
 /* Remote debugging interface for Array Tech RAID controller..
-   Copyright 90, 91, 92, 93, 94, 1995  Free Software Foundation, Inc.
+   Copyright 90, 91, 92, 93, 94, 1995, 1998  Free Software Foundation, Inc.
    Contributed by Cygnus Support. Written by Rob Savoye for Cygnus.
 
    This module talks to a debug monitor called 'MONITOR', which
 #else
 #include <varargs.h>
 #endif
+#include <ctype.h>
 #include <signal.h>
-#include "gdb_string.h"
 #include <sys/types.h>
+#include "gdb_string.h"
 #include "command.h"
 #include "serial.h"
 #include "monitor.h"
 
 extern int baud_rate;
 
-static const char hexchars[]="0123456789abcdef";
-static char *hex2mem();
-
-#define SREC_SIZE 160
+#define ARRAY_PROMPT ">> "
 
 #define SWAP_TARGET_AND_HOST(buffer,len)                               \
   do                                                                   \
@@ -92,7 +90,7 @@ static int from_hex();
 static int array_send_packet();
 static int array_get_packet();
 static unsigned long ascii2hexword();
-static char *hexword2ascii();
+static void hexword2ascii();
 
 extern char *version;
 
@@ -124,50 +122,77 @@ serial_t array_desc = NULL;
 extern char *tmp_mips_processor_type;
 extern int mips_set_processor_type();
 
-static struct target_ops array_ops = {
-  "array",                     /* to_shortname */
-                               /* to_longname */
-  "Debug using the standard GDB remote protocol for the Array Tech target.",
-                               /* to_doc */
-  "Debug using the standard GDB remote protocol for the Array Tech target.\n\
-Specify the serial device it is connected to (e.g. /dev/ttya).",
-  array_open,                  /* to_open */
-  array_close,                 /* to_close */
-  NULL,                                /* to_attach */
-  array_detach,                        /* to_detach */
-  array_resume,                        /* to_resume */
-  array_wait,                  /* to_wait */
-  array_fetch_registers,       /* to_fetch_registers */
-  array_store_registers,       /* to_store_registers */
-  array_prepare_to_store,      /* to_prepare_to_store */
-  array_xfer_memory,           /* to_xfer_memory */
-  array_files_info,            /* to_files_info */
-  array_insert_breakpoint,     /* to_insert_breakpoint */
-  array_remove_breakpoint,     /* to_remove_breakpoint */
-  0,                           /* to_terminal_init */
-  0,                           /* to_terminal_inferior */
-  0,                           /* to_terminal_ours_for_output */
-  0,                           /* to_terminal_ours */
-  0,                           /* to_terminal_info */
-  array_kill,                  /* to_kill */
-  0,                           /* to_load */
-  0,                           /* to_lookup_symbol */
-  array_create_inferior,       /* to_create_inferior */
-  array_mourn_inferior,                /* to_mourn_inferior */
-  0,                           /* to_can_run */
-  0,                           /* to_notice_signals */
-  0,                           /* to_thread_alive */
-  0,                            /* to_stop */
-  process_stratum,             /* to_stratum */
-  0,                           /* to_next */
-  1,                           /* to_has_all_memory */
-  1,                           /* to_has_memory */
-  1,                           /* to_has_stack */
-  1,                           /* to_has_registers */
-  1,                           /* to_has_execution */
-  0,                           /* sections */
-  0,                           /* sections_end */
-  OPS_MAGIC                    /* to_magic */
+static struct target_ops array_ops ;
+
+static void 
+init_array_ops(void)
+{
+  array_ops.to_shortname =   "array";  
+  array_ops.to_longname =              
+    "Debug using the standard GDB remote protocol for the Array Tech target.",
+    array_ops.to_doc =                         
+    "Debug using the standard GDB remote protocol for the Array Tech target.\n\
+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;
+  array_ops.to_xfer_memory  =   array_xfer_memory;             
+  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;            
 };
 
 /*
@@ -399,7 +424,7 @@ static void
 expect_prompt(discard)
      int discard;
 {
-  expect (">> ", discard);
+  expect (ARRAY_PROMPT, discard);
 }
 
 /*
@@ -530,7 +555,7 @@ array_create_inferior (execfile, args, env)
     error("Can't pass arguments to remote MONITOR process");
 
   if (execfile == 0 || exec_bfd == 0)
-    error("No exec file specified");
+    error("No executable file specified");
 
   entry_pt = (int) bfd_get_start_address (exec_bfd);
 
@@ -577,6 +602,9 @@ array_open(args, name, from_tty)
 /*  if (is_open) */
     array_close(0);
 
+  target_preopen (from_tty);
+  unpush_target (&array_ops);
+
   tmp_mips_processor_type = "lsi33k";  /* change the default from r3051 */
   mips_set_processor_type_command ("lsi33k", 0);
 
@@ -599,9 +627,9 @@ array_open(args, name, from_tty)
   log_file = fopen (LOG_FILE, "w");
   if (log_file == NULL)
     perror_with_name (LOG_FILE);
-  fprintf_filtered (log_file, "GDB %s (%s", version);
-  fprintf_filtered (log_file, " --target %s)\n", array_ops.to_shortname);
-  fprintf_filtered (log_file, "Remote target %s connected to %s\n\n", array_ops.to_shortname, dev_name);
+  fprintf (log_file, "GDB %s (%s", version);
+  fprintf (log_file, " --target %s)\n", array_ops.to_shortname);
+  fprintf (log_file, "Remote target %s connected to %s\n\n", array_ops.to_shortname, dev_name);
 #endif
 
   /* see if the target is alive. For a ROM monitor, we can just try to force the
@@ -614,13 +642,15 @@ array_open(args, name, from_tty)
        because the '@' doesn't flush output like it does on the new ROMS.
      */
     printf_monitor ("@");      /* ask for the last signal */
-    expect_prompt(1);          /* See if we get a expect_prompt */   
+    expect_prompt(1);          /* See if we get a expect_prompt */
+#ifdef TEST_ARRAY              /* skip packet for testing */
     make_gdb_packet (packet, "?");     /* ask for a bogus packet */
     if (array_send_packet (packet) == 0)
       error ("Couldn't transmit packet\n");
     printf_monitor ("@\n");    /* force it to flush stdout */
    expect_prompt(1);           /* See if we get a expect_prompt */
-
+#endif
+  push_target (&array_ops);
   if (from_tty)
     printf("Remote target %s connected to %s\n", array_ops.to_shortname, dev_name);
 }
@@ -697,10 +727,12 @@ array_resume (pid, step, sig)
   if (step) {
     printf_monitor ("s\n");
   } else {
-    printf_monitor ("go");
+    printf_monitor ("go\n");
   }
 }
 
+#define TMPBUFSIZ 5
+
 /*
  * array_wait -- Wait until the remote machine stops, then return,
  *          storing status in status just as `wait' would.
@@ -711,6 +743,10 @@ array_wait (pid, status)
      struct target_waitstatus *status;
 {
   int old_timeout = timeout;
+  int result, i;
+  char c;
+  serial_t tty_desc;
+  serial_ttystate ttystate;
 
   debuglogs(1, "array_wait (), printing extraneous text.");
   
@@ -718,15 +754,49 @@ array_wait (pid, status)
   status->value.integer = 0;
 
   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);
 
-  expect_prompt(0);    /* Wait for expect_prompt, outputting extraneous text */
+  i = 0;
+  /* poll on the serial port and the keyboard. */
+  while (1) {
+    c = readchar(timeout);
+    if (c > 0) {
+      if (c == *(ARRAY_PROMPT + i)) {
+       if (++i >= strlen (ARRAY_PROMPT)) { /* matched the prompt */
+         debuglogs (4, "array_wait(), got the expect_prompt.");
+         break;
+       }
+      } else {         /* not the prompt */
+       i = 0;
+      }
+      fputc_unfiltered (c, gdb_stdout);
+      gdb_flush (gdb_stdout);
+    }
+    c = SERIAL_READCHAR(tty_desc, timeout);
+    if (c > 0) {
+      SERIAL_WRITE(array_desc, &c, 1);
+      /* do this so it looks like there's keyboard echo */
+      if (c == 3)              /* exit on Control-C */
+       break;
+#if 0
+      fputc_unfiltered (c, gdb_stdout);
+      gdb_flush (gdb_stdout);
+#endif
+    }
+  }
+  SERIAL_SET_TTY_STATE (tty_desc, ttystate);
+#else
+  expect_prompt(1);
   debuglogs (4, "array_wait(), got the expect_prompt.");
+#endif
 
   status->kind = TARGET_WAITKIND_STOPPED;
   status->value.sig = TARGET_SIGNAL_TRAP;
 
-
-
   timeout = old_timeout;
 
   return 0;
@@ -903,21 +973,12 @@ array_read_inferior_memory(memaddr, myaddr, len)
      char *myaddr;
      int len;
 {
-  int i, j;
+  int j;
   char buf[20];
   char packet[PBUFSIZ];
-
-  /* Number of bytes read so far.  */
-  int count;
-
-  /* Starting address of this pass.  */
-  unsigned long startaddr;
-
-  /* Starting address of this pass.  */
-  unsigned long endaddr;
-
-  /* Number of bytes to read in this pass.  */
-  int len_this_pass;
+  int count;                   /* Number of bytes read so far.  */
+  unsigned long startaddr;     /* Starting address of this pass.  */
+  int len_this_pass;           /* Number of bytes to read in this pass.  */
 
   debuglogs (1, "array_read_inferior_memory (memaddr=0x%x, myaddr=0x%x, len=%d)", memaddr, myaddr, len);
 
@@ -935,36 +996,46 @@ array_read_inferior_memory(memaddr, myaddr, len)
     return 0;
   }
   
-  startaddr = memaddr;
-  count = 0;
-  while (count < len) {
-    len_this_pass = 16;
-    if ((startaddr % 16) != 0)
-      len_this_pass -= startaddr % 16;
-    if (len_this_pass > (len - count))
-      len_this_pass = (len - count);
-    
-    debuglogs (3, "Display %d bytes at %x for Big Endian host", len_this_pass, startaddr);
-    
-    for (i = 0; i < len_this_pass; i++) {
+  for (count = 0, startaddr = memaddr; count < len; startaddr += len_this_pass)
+    {
+      /* Try to align to 16 byte boundry (why?) */
+      len_this_pass = 16;
+      if ((startaddr % 16) != 0)
+       {
+         len_this_pass -= startaddr % 16;
+       }
+      /* Only transfer bytes we need */
+      if (len_this_pass > (len - count))
+       {
+         len_this_pass = (len - count);
+       }
+      /* Fetch the bytes */
+      debuglogs (3, "read %d bytes from inferior address %x", len_this_pass,
+                startaddr);
       sprintf (buf, "m%08x,%04x", startaddr, len_this_pass);
       make_gdb_packet (packet, buf);
       if (array_send_packet (packet) == 0)
-       error ("Couldn't transmit packet\n");
+       {
+         error ("Couldn't transmit packet\n");
+       }
       if (array_get_packet (packet) == 0)
-       error ("Couldn't receive packet\n");  
+       {
+         error ("Couldn't receive packet\n");  
+       }
       if (*packet == 0)
-       error ("Got no data in the GDB packet\n");
-      debuglogs (4, "array_read_inferior: Got a \"%s\" back\n", packet);
-      for (j = 0; j < len_this_pass ; j++) {           /* extract the byte values */
-       myaddr[count++] = from_hex (*(packet+(j*2))) * 16 + from_hex (*(packet+(j*2)+1));
-       debuglogs (5, "myaddr set to %x\n", myaddr[count-1]);
-      }
-      startaddr += 1;
+       {
+         error ("Got no data in the GDB packet\n");
+       }
+      /* Pick packet apart and xfer bytes to myaddr */
+      debuglogs (4, "array_read_inferior_memory: Got a \"%s\" back\n", packet);
+      for (j = 0; j < len_this_pass ; j++)
+       {
+         /* extract the byte values */
+         myaddr[count++] = from_hex (*(packet+(j*2))) * 16 + from_hex (*(packet+(j*2)+1));
+         debuglogs (5, "myaddr[%d] set to %x\n", count-1, myaddr[count-1]);
+       }
     }
-
-  }
-  return len;
+  return (count);
 }
 
 /* FIXME-someday!  merge these two.  */
@@ -1004,7 +1075,6 @@ array_mourn_inferior ()
 
 #define MAX_ARRAY_BREAKPOINTS 16
 
-extern int memory_breakpoint_size;
 static CORE_ADDR breakaddr[MAX_ARRAY_BREAKPOINTS] = {0};
 
 /*
@@ -1016,15 +1086,18 @@ array_insert_breakpoint (addr, shadow)
      char *shadow;
 {
   int i;
+  int bp_size = 0;
+  CORE_ADDR bp_addr = addr;
 
   debuglogs (1, "array_insert_breakpoint() addr = 0x%x", addr);
+  BREAKPOINT_FROM_PC (&bp_addr, &bp_size);
 
   for (i = 0; i <= MAX_ARRAY_BREAKPOINTS; i++) {
     if (breakaddr[i] == 0) {
       breakaddr[i] = addr;
       if (sr_get_debug() > 4)
        printf ("Breakpoint at %x\n", addr);
-      array_read_inferior_memory(addr, shadow, memory_breakpoint_size);
+      array_read_inferior_memory (bp_addr, shadow, bp_size);
       printf_monitor("b 0x%x\n", addr);
       expect_prompt(1);
       return 0;
@@ -1317,6 +1390,7 @@ array_get_packet (packet)
       }
     }
   }
+  return 0; /* exceeded retries */
 }
 
 /*
@@ -1350,7 +1424,7 @@ ascii2hexword (mem)
  * ascii2hexword -- convert a hex value to an ascii number represented by 8
  *     digits.
  */
-static char*
+static void
 hexword2ascii (mem, num)
      unsigned char *mem;
      unsigned long num;
@@ -1418,7 +1492,6 @@ _initialize_remote_monitors ()
 void
 _initialize_array ()
 {
+  init_array_ops() ;
   add_target (&array_ops);
-  baud_rate = 4800;                    /* this is the only supported baud rate */
 }
-
This page took 0.027706 seconds and 4 git commands to generate.