Replace "exec" with "executable" in messages.
[deliverable/binutils-gdb.git] / gdb / sparcl-tdep.c
index bf3d87b61b6a3bc727c0ec8009c8f48bcca55155..e50fdce46e6790be64dc22df99be44e4503e86e9 100644 (file)
@@ -1,5 +1,5 @@
 /* Target dependent code for the Fujitsu SPARClite for GDB, the GNU debugger.
-   Copyright 1994, 1995  Free Software Foundation, Inc.
+   Copyright 1994, 1995, 1996  Free Software Foundation, Inc.
 
 This file is part of GDB.
 
@@ -15,7 +15,7 @@ GNU General Public License for more details.
 
 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., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include "defs.h"
 #include "gdbcore.h"
@@ -23,9 +23,11 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "target.h"
 #include "serial.h"
 #include <sys/types.h>
+
+#if !defined(__GO32__) && !defined(_WIN32)
+#define HAVE_SOCKETS
 #include <sys/time.h>
 #include <unistd.h>
-#ifndef __GO32__
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netdb.h>
@@ -37,14 +39,14 @@ extern struct target_ops remote_ops;
 static char *remote_target_name = NULL;
 static serial_t remote_desc = NULL;
 static int serial_flag;
-#ifndef __GO32__
+#ifdef HAVE_SOCKETS
 static int udp_fd = -1;
 #endif
 
 static serial_t open_tty PARAMS ((char *name));
 static int send_resp PARAMS ((serial_t desc, char c));
 static void close_tty PARAMS ((int ignore));
-#ifndef __GO32__
+#ifdef HAVE_SOCKETS
 static int recv_udp_buf PARAMS ((int fd, unsigned char *buf, int len, int timeout));
 static int send_udp_buf PARAMS ((int fd, unsigned char *buf, int len));
 #endif
@@ -60,7 +62,7 @@ static void sparclite_serial_start PARAMS ((bfd_vma entry));
 static void sparclite_serial_write PARAMS ((bfd *from_bfd, asection *from_sec,
                                            file_ptr from_addr,
                                            bfd_vma to_addr, int len));
-#ifndef __GO32__
+#ifdef HAVE_SOCKETS
 static unsigned short calc_checksum PARAMS ((unsigned char *buffer,
                                             int count));
 static void sparclite_udp_start PARAMS ((bfd_vma entry));
@@ -81,7 +83,7 @@ static void sparclite_download PARAMS ((char *filename, int from_tty));
 #define DDA1_ENABLE            0x80
 #define DIA2_ENABLE            0x40
 #define DIA1_ENABLE            0x20
-#define DSINGLE_STEP           0x10
+#define DSINGLE_STEP           0x10            /* not used */
 #define DDV_TYPE_MASK          0xc
 #define DDV_TYPE_LOAD          0x0
 #define DDV_TYPE_STORE                 0x4
@@ -230,18 +232,26 @@ sparclite_check_watch_resources (type, cnt, ot)
      int cnt;
      int ot;
 {
+  /* Watchpoints not supported on simulator.  */
+  if (strcmp (target_shortname, "sim") == 0)
+    return 0;
+
   if (type == bp_hardware_breakpoint)
-    if (TARGET_HW_BREAK_LIMIT == 0)
-      return 0;
-    else if (cnt <= TARGET_HW_BREAK_LIMIT)
-      return 1;
+    {
+      if (TARGET_HW_BREAK_LIMIT == 0)
+       return 0;
+      else if (cnt <= TARGET_HW_BREAK_LIMIT)
+       return 1;
+    }
   else
-    if (TARGET_HW_WATCH_LIMIT == 0)
-      return 0;
-    else if (ot)
-      return -1;
-    else if (cnt <= TARGET_HW_WATCH_LIMIT)
-      return 1;
+    {
+      if (TARGET_HW_WATCH_LIMIT == 0)
+       return 0;
+      else if (ot)
+       return -1;
+      else if (cnt <= TARGET_HW_WATCH_LIMIT)
+       return 1;
+    }
   return -1;
 }
 
@@ -288,30 +298,66 @@ open_tty (name)
   return desc;
 }
 
+/* Read a single character from the remote end, masking it down to 7 bits. */
+
 static int
-send_resp (desc, c)
+readchar (desc, timeout)
      serial_t desc;
-     char c;
+     int timeout;
 {
-  int i;
-
-  SERIAL_WRITE (desc, &c, 1);
-  i = SERIAL_READCHAR (desc, 2);
+  int ch;
+  char s[10];
 
-  if (i >= 0)
-    return i;
+  ch = SERIAL_READCHAR (desc, timeout);
 
-  switch (i)
+  switch (ch)
     {
+    case SERIAL_EOF:
+      error ("SPARClite remote connection closed");
     case SERIAL_ERROR:
-      perror_with_name ("Remote communication error");
+      perror_with_name ("SPARClite communication error");
     case SERIAL_TIMEOUT:
-      error ("Remote timeout");
-    case SERIAL_EOF:
-      error ("Remote connection closed");
+      error ("SPARClite remote timeout");
+    default:
+      if (remote_debug > 0)
+       {
+         sprintf (s, "[%02x]", ch & 0xff);
+         puts_debug ("read -->", s, "<--");
+       }
+      return ch;
     }
 }
 
+static void
+debug_serial_write (desc, buf, len)
+     serial_t desc;
+     char *buf;
+     int len;
+{
+  char s[10];
+
+  SERIAL_WRITE (desc, buf, len);
+  if (remote_debug > 0)
+    {
+      while (len-- > 0)
+       {
+         sprintf (s, "[%02x]", *buf & 0xff);
+         puts_debug ("Sent -->", s, "<--");
+         buf++;
+       }
+    }
+}
+
+
+static int
+send_resp (desc, c)
+     serial_t desc;
+     char c;
+{
+  debug_serial_write (desc, &c, 1);
+  return readchar (desc, 2);
+}
+
 static void
 close_tty (ignore)
      int ignore;
@@ -324,7 +370,7 @@ close_tty (ignore)
   remote_desc = NULL;
 }
 
-#ifndef __GO32__
+#ifdef HAVE_SOCKETS
 static int
 recv_udp_buf (fd, buf, len, timeout)
      int fd, len;
@@ -377,7 +423,7 @@ send_udp_buf (fd, buf, len)
 
   error ("Short count in send: tried %d, sent %d\n", len, cc);
 }
-#endif /* __GO32__ */
+#endif /* HAVE_SOCKETS */
 
 static void
 sparclite_open (name, from_tty)
@@ -449,7 +495,7 @@ or: target sparclite udp host");
     }
   else
     {
-#ifndef __GO32__
+#ifdef HAVE_SOCKETS
       struct hostent *he;
       struct sockaddr_in sockaddr;
       unsigned char buffer[100];
@@ -485,7 +531,7 @@ or: target sparclite udp host");
        error ("SPARClite appears to be ill.");
 #else
       error ("UDP downloading is not supported for DOS hosts.");
-#endif /* __GO32__ */
+#endif /* HAVE_SOCKETS */
     }
 
   printf_unfiltered ("[SPARClite appears to be alive]\n");
@@ -503,7 +549,7 @@ sparclite_close (quitting)
 {
   if (serial_flag)
     close_tty (0);
-#ifndef __GO32__
+#ifdef HAVE_SOCKETS
   else
     if (udp_fd != -1)
       close (udp_fd);
@@ -517,8 +563,9 @@ download (target_name, args, from_tty, write_routine, start_routine)
      char *target_name;
      char *args;
      int from_tty;
-     void (*write_routine)();
-     void (*start_routine)();
+     void (*write_routine) PARAMS ((bfd *from_bfd, asection *from_sec,
+                                   file_ptr from_addr, bfd_vma to_addr, int len));
+     void (*start_routine) PARAMS ((bfd_vma entry));
 {
   struct cleanup *old_chain;
   asection *section;
@@ -643,8 +690,8 @@ sparclite_serial_start (entry)
   buffer[0] = 0x03;
   store_unsigned_integer (buffer + 1, 4, entry);
 
-  SERIAL_WRITE (remote_desc, buffer, 1 + 4);
-  i = SERIAL_READCHAR (remote_desc, 2);
+  debug_serial_write (remote_desc, buffer, 1 + 4);
+  i = readchar (remote_desc, 2);
   if (i != 0x55)
     error ("Can't start SparcLite.  Error code %d\n", i);
 }
@@ -675,16 +722,14 @@ sparclite_serial_write (from_bfd, from_sec, from_addr, to_addr, len)
   if (i != 0x5a)
     error ("Bad response from load command (0x%x)", i);
 
-  SERIAL_WRITE (remote_desc, buffer, 4 + 4 + len);
-  i = SERIAL_READCHAR (remote_desc, 2);
-  if (i < 0)
-    error ("I/O error in serial code.  Return code %d\n", i);
+  debug_serial_write (remote_desc, buffer, 4 + 4 + len);
+  i = readchar (remote_desc, 2);
 
   if (i != checksum)
     error ("Bad checksum from load command (0x%x)", i);
 }
 
-#ifndef __GO32__
+#ifdef HAVE_SOCKETS
 
 static unsigned short
 calc_checksum (buffer, count)
@@ -798,7 +843,7 @@ sparclite_udp_write (from_bfd, from_sec, from_addr, to_addr, len)
     }
 }
 
-#endif /* __GO32__ */
+#endif /* HAVE_SOCKETS */
 
 static void
 sparclite_download (filename, from_tty)
@@ -806,7 +851,7 @@ sparclite_download (filename, from_tty)
      int from_tty;
 {
   if (!serial_flag)
-#ifndef __GO32__
+#ifdef HAVE_SOCKETS
     download (remote_target_name, filename, from_tty, sparclite_udp_write,
              sparclite_udp_start);
 #else
@@ -819,52 +864,56 @@ sparclite_download (filename, from_tty)
 \f
 /* Define the target subroutine names */
 
-static struct target_ops sparclite_ops =
+static struct target_ops sparclite_ops ;
+
+static void init_sparclite_ops(void)
 {
-  "sparclite",                 /* to_shortname */
-  "SPARClite remote target",   /* to_longname */
-  "Use a remote SPARClite target board via a serial line, using a gdb-specific protocol.\n\
-Specify the serial device it is connected to (e.g. /dev/ttya).",  /* to_doc */
-  sparclite_open,              /* to_open */
-  sparclite_close,             /* to_close */
-  0,                           /* to_attach */
-  0,                           /* to_detach */
-  0,                           /* to_resume */
-  0,                           /* to_wait */
-  0,                           /* to_fetch_registers */
-  0,                           /* to_store_registers */
-  0,                           /* to_prepare_to_store */
-  0,                           /* to_xfer_memory */
-  0,                           /* to_files_info */
-  0,                           /* to_insert_breakpoint */
-  0,                           /* 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 */
-  0,                           /* to_kill */
-  sparclite_download,          /* to_load */
-  0,                           /* to_lookup_symbol */
-  0,                           /* to_create_inferior */
-  0,                           /* to_mourn_inferior */
-  0,                           /* to_can_run */
-  0,                           /* to_notice_signals */
-  0,                           /* to_stop */
-  download_stratum,            /* to_stratum */
-  0,                           /* to_next */
-  0,                           /* to_has_all_memory */
-  0,                           /* to_has_memory */
-  0,                           /* to_has_stack */
-  0,                           /* to_has_registers */
-  0,                           /* to_has_execution */
-  0,                           /* sections */
-  0,                           /* sections_end */
-  OPS_MAGIC                    /* to_magic */
-  };
+  sparclite_ops.to_shortname =   "sparclite";          
+  sparclite_ops.to_longname =   "SPARClite remote target";
+  sparclite_ops.to_doc =   "Use a remote SPARClite target board via a serial line; using a gdb-specific protocol.\n\
+Specify the serial device it is connected to (e.g. /dev/ttya).";  
+  sparclite_ops.to_open =   sparclite_open;    
+  sparclite_ops.to_close =   sparclite_close;  
+  sparclite_ops.to_attach =   0;       
+  sparclite_ops.to_detach =   0;       
+  sparclite_ops.to_resume =   0;       
+  sparclite_ops.to_wait  =   0;                
+  sparclite_ops.to_fetch_registers  =   0;
+  sparclite_ops.to_store_registers  =   0;
+  sparclite_ops.to_prepare_to_store =   0;
+  sparclite_ops.to_xfer_memory  =   0;         
+  sparclite_ops.to_files_info  =   0;          
+  sparclite_ops.to_insert_breakpoint =   0;    
+  sparclite_ops.to_remove_breakpoint =   0;    
+  sparclite_ops.to_terminal_init  =   0;       
+  sparclite_ops.to_terminal_inferior =   0;    
+  sparclite_ops.to_terminal_ours_for_output =   0;
+  sparclite_ops.to_terminal_ours  =   0;               
+  sparclite_ops.to_terminal_info  =   0;               
+  sparclite_ops.to_kill  =   0;                        
+  sparclite_ops.to_load  =   sparclite_download;
+  sparclite_ops.to_lookup_symbol =   0;                
+  sparclite_ops.to_create_inferior =   0;      
+  sparclite_ops.to_mourn_inferior =   0;       
+  sparclite_ops.to_can_run  =   0;             
+  sparclite_ops.to_notice_signals =   0;       
+  sparclite_ops.to_thread_alive  =   0;                
+  sparclite_ops.to_stop  =   0;                        
+  sparclite_ops.to_stratum =   download_stratum;
+  sparclite_ops.DONT_USE =   0;                        
+  sparclite_ops.to_has_all_memory =   0;       
+  sparclite_ops.to_has_memory =   0;           
+  sparclite_ops.to_has_stack =   0;            
+  sparclite_ops.to_has_registers =   0;                
+  sparclite_ops.to_has_execution =   0;                
+  sparclite_ops.to_sections =   0;             
+  sparclite_ops.to_sections_end =   0;         
+  sparclite_ops.to_magic =   OPS_MAGIC ;       
+} /* init_sparclite_ops */
 
 void
 _initialize_sparcl_tdep ()
 {
+  init_sparclite_ops() ;
   add_target (&sparclite_ops);
 }
This page took 0.028129 seconds and 4 git commands to generate.