* doc/gdbint.texinfo (Host Definition): Remove documentation
[deliverable/binutils-gdb.git] / gdb / ocd.c
index b20bd9c8e4e1124e1e79d74485b1c85935ab4b57..dffc176688ad0a0a605f8d29d3fa84c77ab7213c 100644 (file)
--- a/gdb/ocd.c
+++ b/gdb/ocd.c
@@ -1,21 +1,24 @@
-/* Remote target communications for the Macraigor Systems BDM Wiggler
-   Copyright 1996, 1997 Free Software Foundation, Inc.
+/* Target communications support for Macraigor Systems' On-Chip Debugging
 
-This file is part of GDB.
+   Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2004 Free
+   Software Foundation, Inc.
 
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+   This file is part of GDB.
 
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
 
-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.  */
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   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., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
 
 #include "defs.h"
 #include "gdbcore.h"
@@ -26,70 +29,46 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "bfd.h"
 #include "symfile.h"
 #include "target.h"
-#include "wait.h"
 #include "gdbcmd.h"
 #include "objfiles.h"
 #include "gdb-stabs.h"
-#include "dcache.h"
 #include <sys/types.h>
 #include <signal.h>
 #include "serial.h"
 #include "ocd.h"
+#include "regcache.h"
 
 /* Prototypes for local functions */
 
-static int wiggler_write_bytes PARAMS ((CORE_ADDR memaddr,
-                                      char *myaddr, int len));
-
-static int wiggler_read_bytes PARAMS ((CORE_ADDR memaddr,
-                                     char *myaddr, int len));
-
-static int wiggler_start_remote PARAMS ((char *dummy));
-
-static int readchar PARAMS ((int timeout));
-
-static void reset_packet PARAMS ((void));
-
-static void output_packet PARAMS ((void));
+static int ocd_read_bytes (CORE_ADDR memaddr, char *myaddr, int len);
 
-static int get_quoted_char PARAMS ((int timeout));
+static int ocd_start_remote (void *dummy);
 
-static void put_quoted_char PARAMS ((int c));
+static int readchar (int timeout);
 
-static void wiggler_interrupt PARAMS ((int signo));
+static void ocd_interrupt (int signo);
 
-static void wiggler_interrupt_twice PARAMS ((int signo));
+static void ocd_interrupt_twice (int signo);
 
-static void interrupt_query PARAMS ((void));
+static void interrupt_query (void);
 
-static unsigned char * do_command PARAMS ((int cmd, int *statusp, int *lenp));
+static unsigned char *ocd_do_command (int cmd, int *statusp, int *lenp);
 
-static void wiggler_put_packet PARAMS ((unsigned char *packet, int pktlen));
+static void ocd_put_packet (unsigned char *packet, int pktlen);
 
-static unsigned char * wiggler_get_packet PARAMS ((int cmd, int *pktlen, int timeout));
+static unsigned char *ocd_get_packet (int cmd, int *pktlen, int timeout);
 
 static struct target_ops *current_ops = NULL;
 
 static int last_run_status;
 
-/* This was 5 seconds, which is a long time to sit and wait.
-   Unless this is going though some terminal server or multiplexer or
-   other form of hairy serial connection, I would think 2 seconds would
-   be plenty.  */
-
-/* Changed to allow option to set timeout value.
-   was static int remote_timeout = 2; */
-extern int remote_timeout;
-
 /* Descriptor for I/O to remote machine.  Initialize it to NULL so that
-   wiggler_open knows that we don't have a file open when the program
+   ocd_open knows that we don't have a file open when the program
    starts.  */
-static serial_t wiggler_desc = NULL;
+static struct serial *ocd_desc = NULL;
 \f
 void
-wiggler_error (s, error_code)
-     char *s;
-     int error_code;
+ocd_error (char *s, int error_code)
 {
   char buf[100];
 
@@ -98,126 +77,145 @@ wiggler_error (s, error_code)
 
   switch (error_code)
     {
-    case 0x1: s = "Unknown fault"; break;
-    case 0x2: s = "Power failed"; break;
-    case 0x3: s = "Cable disconnected"; break;
-    case 0x4: s = "Couldn't enter BDM"; break;
-    case 0x5: s = "Target stuck in reset"; break;
-    case 0x6: s = "Port not configured"; break;
-    case 0x7: s = "Write verify failed"; break;
-    case 0x11: s = "Bus error"; break;
-    case 0x12: s = "Checksum error"; break;
-    case 0x13: s = "Illegal command"; break;
-    case 0x14: s = "Parameter error"; break;
-    case 0x15: s = "Internal error"; break;
-    case 0x16: s = "Register buffer error"; break;
-    case 0x80: s = "Flash erase error"; break;
+    case 0x1:
+      s = "Unknown fault";
+      break;
+    case 0x2:
+      s = "Power failed";
+      break;
+    case 0x3:
+      s = "Cable disconnected";
+      break;
+    case 0x4:
+      s = "Couldn't enter OCD mode";
+      break;
+    case 0x5:
+      s = "Target stuck in reset";
+      break;
+    case 0x6:
+      s = "OCD hasn't been initialized";
+      break;
+    case 0x7:
+      s = "Write verify failed";
+      break;
+    case 0x8:
+      s = "Reg buff error (during MPC5xx fp reg read/write)";
+      break;
+    case 0x9:
+      s = "Invalid CPU register access attempt failed";
+      break;
+    case 0x11:
+      s = "Bus error";
+      break;
+    case 0x12:
+      s = "Checksum error";
+      break;
+    case 0x13:
+      s = "Illegal command";
+      break;
+    case 0x14:
+      s = "Parameter error";
+      break;
+    case 0x15:
+      s = "Internal error";
+      break;
+    case 0x80:
+      s = "Flash erase error";
+      break;
     default:
       sprintf (buf, "Unknown error code %d", error_code);
       s = buf;
     }
 
-  error (s);
+  error ("%s", s);
 }
 
 /*  Return nonzero if the thread TH is still alive on the remote system.  */
 
 int
-wiggler_thread_alive (th)
-     int th;
+ocd_thread_alive (ptid_t th)
 {
   return 1;
 }
 \f
 /* Clean up connection to a remote debugger.  */
 
-/* ARGSUSED */
 void
-wiggler_close (quitting)
-     int quitting;
+ocd_close (int quitting)
 {
-  if (wiggler_desc)
-    SERIAL_CLOSE (wiggler_desc);
-  wiggler_desc = NULL;
+  if (ocd_desc)
+    serial_close (ocd_desc);
+  ocd_desc = NULL;
 }
 
 /* Stub for catch_errors.  */
 
 static int
-wiggler_start_remote (dummy)
-     char *dummy;
+ocd_start_remote (void *dummy)
 {
   unsigned char buf[10], *p;
   int pktlen;
   int status;
   int error_code;
   int speed;
-  enum wiggler_target_type target_type;
-
-  target_type = (enum wiggler_target_type)dummy;
-
-  immediate_quit = 1;          /* Allow user to interrupt it */
+  enum ocd_target_type target_type;
 
-  SERIAL_SEND_BREAK (wiggler_desc); /* Wake up the wiggler */
+  target_type = *(enum ocd_target_type *) dummy;
 
-  do_command (WIGGLER_AYT, &status, &pktlen);
+  immediate_quit++;            /* Allow user to interrupt it */
 
-  p = do_command (WIGGLER_GET_VERSION, &status, &pktlen);
-
-  printf_unfiltered ("[Wiggler version %x.%x, capability 0x%x]\n",
-                    p[0], p[1], (p[2] << 16) | p[3]);
+  serial_send_break (ocd_desc);        /* Wake up the wiggler */
 
-#if 1
   speed = 80;                  /* Divide clock by 4000 */
 
-  buf[0] = WIGGLER_INIT;
+  buf[0] = OCD_INIT;
   buf[1] = speed >> 8;
   buf[2] = speed & 0xff;
   buf[3] = target_type;
-  wiggler_put_packet (buf, 4); /* Init Wiggler params */
-  p = wiggler_get_packet (buf[0], &pktlen, remote_timeout);
+  ocd_put_packet (buf, 4);     /* Init OCD params */
+  p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
 
   if (pktlen < 2)
-    error ("Truncated response packet from Wiggler");
+    error ("Truncated response packet from OCD device");
 
   status = p[1];
   error_code = p[2];
 
   if (error_code != 0)
-    wiggler_error ("WIGGLER_INIT:", error_code);
-#endif
+    ocd_error ("OCD_INIT:", error_code);
 
-#if 0
-  /* Reset the target */
+  ocd_do_command (OCD_AYT, &status, &pktlen);
 
-  do_command (WIGGLER_RESET_RUN, &status, &pktlen);
-/*  do_command (WIGGLER_RESET, &status, &pktlen);*/
-#endif
+  p = ocd_do_command (OCD_GET_VERSION, &status, &pktlen);
+
+  printf_unfiltered ("[Wiggler version %x.%x, capability 0x%x]\n",
+                    p[0], p[1], (p[2] << 16) | p[3]);
 
   /* If processor is still running, stop it.  */
 
-  if (!(status & WIGGLER_FLAG_BDM))
-    wiggler_stop ();
+  if (!(status & OCD_FLAG_BDM))
+    ocd_stop ();
 
-#if 1
-  buf[0] = WIGGLER_SET_CTL_FLAGS;
+  /* When using a target box, we want to asynchronously return status when
+     target stops.  The OCD_SET_CTL_FLAGS command is ignored by Wigglers.dll
+     when using a parallel Wiggler */
+  buf[0] = OCD_SET_CTL_FLAGS;
   buf[1] = 0;
-  buf[2] = 1;          /* Asynchronously return status when target stops */
-  wiggler_put_packet (buf, 3);
+  buf[2] = 1;
+  ocd_put_packet (buf, 3);
 
-  p = wiggler_get_packet (buf[0], &pktlen, remote_timeout);
+  p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
 
   if (pktlen < 2)
-    error ("Truncated response packet from Wiggler");
+    error ("Truncated response packet from OCD device");
 
   status = p[1];
   error_code = p[2];
 
   if (error_code != 0)
-    wiggler_error ("WIGGLER_SET_CTL_FLAGS:", error_code);
-#endif
+    ocd_error ("OCD_SET_CTL_FLAGS:", error_code);
 
-  immediate_quit = 0;
+  immediate_quit--;
 
 /* This is really the job of start_remote however, that makes an assumption
    that the target is about to print out a status message of some sort.  That
@@ -227,9 +225,17 @@ wiggler_start_remote (dummy)
   flush_cached_frames ();
   registers_changed ();
   stop_pc = read_pc ();
-  set_current_frame (create_new_frame (read_fp (), stop_pc));
-  select_frame (get_current_frame (), 0);
-  print_stack_frame (selected_frame, -1, 1);
+  print_stack_frame (get_selected_frame (), 0, SRC_AND_LOC);
+
+  buf[0] = OCD_LOG_FILE;
+  buf[1] = 3;                  /* close existing WIGGLERS.LOG */
+  ocd_put_packet (buf, 2);
+  p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
+
+  buf[0] = OCD_LOG_FILE;
+  buf[1] = 2;                  /* append to existing WIGGLERS.LOG */
+  ocd_put_packet (buf, 2);
+  p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
 
   return 1;
 }
@@ -237,18 +243,16 @@ wiggler_start_remote (dummy)
 /* Open a connection to a remote debugger.
    NAME is the filename used for communication.  */
 
-static DCACHE *wiggler_dcache;
-
 void
-wiggler_open (name, from_tty, target_type, ops)
-     char *name;
-     int from_tty;
-     enum wiggler_target_type target_type;
-     struct target_ops *ops;
+ocd_open (char *name, int from_tty, enum ocd_target_type target_type,
+         struct target_ops *ops)
 {
+  unsigned char buf[10], *p;
+  int pktlen;
+
   if (name == 0)
-    error ("To open a Wiggler connection, you need to specify what serial\n\
-device the Wiggler is attached to (e.g. /dev/ttya).");
+    error ("To open an OCD connection, you need to specify the\n\
+device the OCD device is attached to (e.g. /dev/ttya).");
 
   target_preopen (from_tty);
 
@@ -256,26 +260,24 @@ device the Wiggler is attached to (e.g. /dev/ttya).");
 
   unpush_target (current_ops);
 
-  wiggler_dcache = dcache_init (wiggler_read_bytes, wiggler_write_bytes);
-
-  wiggler_desc = SERIAL_OPEN (name);
-  if (!wiggler_desc)
+  ocd_desc = serial_open (name);
+  if (!ocd_desc)
     perror_with_name (name);
 
   if (baud_rate != -1)
     {
-      if (SERIAL_SETBAUDRATE (wiggler_desc, baud_rate))
+      if (serial_setbaudrate (ocd_desc, baud_rate))
        {
-         SERIAL_CLOSE (wiggler_desc);
+         serial_close (ocd_desc);
          perror_with_name (name);
        }
     }
 
-  SERIAL_RAW (wiggler_desc);
+  serial_raw (ocd_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 (wiggler_desc);
+  serial_flush_input (ocd_desc);
 
   if (from_tty)
     {
@@ -292,13 +294,17 @@ device the Wiggler is attached to (e.g. /dev/ttya).");
      variables, especially since GDB will someday have a notion of debugging
      several processes.  */
 
-  inferior_pid = 42000;
+  inferior_ptid = pid_to_ptid (42000);
   /* Start the remote connection; if error (0), discard this target.
      In particular, if the user quits, be sure to discard it
      (we'd be in an inconsistent state otherwise).  */
-  if (!catch_errors (wiggler_start_remote, (char *)target_type,
-                    "Couldn't establish connection to remote target\n", RETURN_MASK_ALL))
-    pop_target();
+  if (!catch_errors (ocd_start_remote, &target_type,
+                    "Couldn't establish connection to remote target\n",
+                    RETURN_MASK_ALL))
+    {
+      pop_target ();
+      error ("Failed to connect to OCD.");
+    }
 }
 
 /* This takes a program previously attached to and detaches it.  After
@@ -307,9 +313,7 @@ device the Wiggler is attached to (e.g. /dev/ttya).");
    die when it hits one.  */
 
 void
-wiggler_detach (args, from_tty)
-     char *args;
-     int from_tty;
+ocd_detach (char *args, int from_tty)
 {
   if (args)
     error ("Argument given to \"detach\" when remotely debugging.");
@@ -322,75 +326,69 @@ wiggler_detach (args, from_tty)
 /* Tell the remote machine to resume.  */
 
 void
-wiggler_resume (pid, step, siggnal)
-     int pid, step;
-     enum target_signal siggnal;
+ocd_resume (ptid_t ptid, int step, enum target_signal siggnal)
 {
   int pktlen;
 
-  dcache_flush (wiggler_dcache);
-
   if (step)
-    do_command (WIGGLER_STEP, &last_run_status, &pktlen);
+    ocd_do_command (OCD_STEP, &last_run_status, &pktlen);
   else
-    do_command (WIGGLER_RUN, &last_run_status, &pktlen);
+    ocd_do_command (OCD_RUN, &last_run_status, &pktlen);
 }
 \f
 void
-wiggler_stop ()
+ocd_stop (void)
 {
   int status;
   int pktlen;
 
-  do_command (WIGGLER_STOP, &status, &pktlen);
+  ocd_do_command (OCD_STOP, &status, &pktlen);
 
-  if (!(status & WIGGLER_FLAG_BDM))
+  if (!(status & OCD_FLAG_BDM))
     error ("Can't stop target via BDM");
 }
 
-static volatile int wiggler_interrupt_flag;
+static volatile int ocd_interrupt_flag;
 
 /* Send ^C to target to halt it.  Target will respond, and send us a
    packet.  */
 
 static void
-wiggler_interrupt (signo)
-     int signo;
+ocd_interrupt (int signo)
 {
   /* If this doesn't work, try more severe steps.  */
-  signal (signo, wiggler_interrupt_twice);
-  
+  signal (signo, ocd_interrupt_twice);
+
   if (remote_debug)
-    printf_unfiltered ("wiggler_interrupt called\n");
+    printf_unfiltered ("ocd_interrupt called\n");
 
   {
     char buf[1];
 
-    wiggler_stop ();
-    buf[0] = WIGGLER_AYT;
-    wiggler_put_packet (buf, 1);
-    wiggler_interrupt_flag = 1;
+    ocd_stop ();
+    buf[0] = OCD_AYT;
+    ocd_put_packet (buf, 1);
+    ocd_interrupt_flag = 1;
   }
 }
 
-static void (*ofunc)();
+static void (*ofunc) ();
 
 /* The user typed ^C twice.  */
 static void
-wiggler_interrupt_twice (signo)
-     int signo;
+ocd_interrupt_twice (int signo)
 {
   signal (signo, ofunc);
-  
+
   interrupt_query ();
 
-  signal (signo, wiggler_interrupt);
+  signal (signo, ocd_interrupt);
 }
 
 /* Ask the user what to do when an interrupt is received.  */
 
 static void
-interrupt_query ()
+interrupt_query (void)
 {
   target_terminal_ours ();
 
@@ -398,7 +396,7 @@ interrupt_query ()
 Give up (and stop debugging it)? "))
     {
       target_mourn_inferior ();
-      return_to_top_level (RETURN_QUIT);
+      throw_exception (RETURN_QUIT);
     }
 
   target_terminal_inferior ();
@@ -413,57 +411,55 @@ static int kill_kludge;
    means in the case of this target).  */
 
 int
-wiggler_wait ()
+ocd_wait (void)
 {
   unsigned char *p;
-  int error_code, status;
+  int error_code;
   int pktlen;
+  char buf[1];
 
-  wiggler_interrupt_flag = 0;
+  ocd_interrupt_flag = 0;
 
-  /* Target may already be stopped by the time we get here. */
+  /* Target might already be stopped by the time we get here. */
+  /* If we aren't already stopped, we need to loop until we've dropped
+     back into BDM mode */
 
-  if (!(last_run_status & WIGGLER_FLAG_BDM))
+  while (!(last_run_status & OCD_FLAG_BDM))
     {
-      ofunc = (void (*)()) signal (SIGINT, wiggler_interrupt);
-
-      p = wiggler_get_packet (WIGGLER_AYT, &pktlen, -1);
+      buf[0] = OCD_AYT;
+      ocd_put_packet (buf, 1);
+      p = ocd_get_packet (OCD_AYT, &pktlen, -1);
 
+      ofunc = (void (*)()) signal (SIGINT, ocd_interrupt);
       signal (SIGINT, ofunc);
 
       if (pktlen < 2)
-       error ("Truncated response packet from Wiggler");
+       error ("Truncated response packet from OCD device");
 
-      status = p[1];
+      last_run_status = p[1];
       error_code = p[2];
 
       if (error_code != 0)
-       wiggler_error ("target_wait:", error_code);
+       ocd_error ("target_wait:", error_code);
 
-      if (status & WIGGLER_FLAG_PWF)
-       error ("Wiggler lost VCC at BDM interface.");
-      else if (status & WIGGLER_FLAG_CABLE_DISC)
-       error ("BDM cable appears to have been disconnected.");
-
-      if (!(status & WIGGLER_FLAG_BDM))
-       error ("Wiggler woke up, but wasn't stopped: 0x%x", status);
+      if (last_run_status & OCD_FLAG_PWF)
+       error ("OCD device lost VCC at BDM interface.");
+      else if (last_run_status & OCD_FLAG_CABLE_DISC)
+       error ("OCD device cable appears to have been disconnected.");
     }
 
-  if (wiggler_interrupt_flag)
+  if (ocd_interrupt_flag)
     return 1;
   else
     return 0;
 }
 
-/* Read registers from the Wiggler.  Specify the starting and ending register
-   number.  Return the number of regs actually read in *NUMREGS.  Returns a
-   pointer to a static array containing the register contents.  */
+/* Read registers from the OCD device.  Specify the starting and ending
+   register number.  Return the number of regs actually read in *NUMREGS.
+   Returns a pointer to a static array containing the register contents.  */
 
 unsigned char *
-wiggler_read_bdm_registers (first_bdm_regno, last_bdm_regno, reglen)
-     int first_bdm_regno;
-     int last_bdm_regno;
-     int *reglen;
+ocd_read_bdm_registers (int first_bdm_regno, int last_bdm_regno, int *reglen)
 {
   unsigned char buf[10];
   int i;
@@ -472,20 +468,20 @@ wiggler_read_bdm_registers (first_bdm_regno, last_bdm_regno, reglen)
   int error_code, status;
   int pktlen;
 
-  buf[0] = WIGGLER_READ_REGS;
+  buf[0] = OCD_READ_REGS;
   buf[1] = first_bdm_regno >> 8;
   buf[2] = first_bdm_regno & 0xff;
   buf[3] = last_bdm_regno >> 8;
   buf[4] = last_bdm_regno & 0xff;
 
-  wiggler_put_packet (buf, 5);
-  p = wiggler_get_packet (WIGGLER_READ_REGS, &pktlen, remote_timeout);
+  ocd_put_packet (buf, 5);
+  p = ocd_get_packet (OCD_READ_REGS, &pktlen, remote_timeout);
 
   status = p[1];
   error_code = p[2];
 
   if (error_code != 0)
-    wiggler_error ("read_bdm_registers:", error_code);
+    ocd_error ("read_bdm_registers:", error_code);
 
   i = p[3];
   if (i == 0)
@@ -505,24 +501,20 @@ wiggler_read_bdm_registers (first_bdm_regno, last_bdm_regno, reglen)
 /* Read register BDM_REGNO and returns its value ala read_register() */
 
 CORE_ADDR
-wiggler_read_bdm_register (bdm_regno)
-     int bdm_regno;
+ocd_read_bdm_register (int bdm_regno)
 {
   int reglen;
   unsigned char *p;
   CORE_ADDR regval;
 
-  p = wiggler_read_bdm_registers (bdm_regno, bdm_regno, &reglen);
+  p = ocd_read_bdm_registers (bdm_regno, bdm_regno, &reglen);
   regval = extract_unsigned_integer (p, reglen);
 
   return regval;
 }
 
 void
-wiggler_write_bdm_registers (first_bdm_regno, regptr, reglen)
-     int first_bdm_regno;
-     unsigned char *regptr;
-     int reglen;
+ocd_write_bdm_registers (int first_bdm_regno, unsigned char *regptr, int reglen)
 {
   unsigned char *buf;
   unsigned char *p;
@@ -531,39 +523,37 @@ wiggler_write_bdm_registers (first_bdm_regno, regptr, reglen)
 
   buf = alloca (4 + reglen);
 
-  buf[0] = WIGGLER_WRITE_REGS;
+  buf[0] = OCD_WRITE_REGS;
   buf[1] = first_bdm_regno >> 8;
   buf[2] = first_bdm_regno & 0xff;
   buf[3] = reglen;
   memcpy (buf + 4, regptr, reglen);
 
-  wiggler_put_packet (buf, 4 + reglen);
-  p = wiggler_get_packet (WIGGLER_WRITE_REGS, &pktlen, remote_timeout);
+  ocd_put_packet (buf, 4 + reglen);
+  p = ocd_get_packet (OCD_WRITE_REGS, &pktlen, remote_timeout);
 
   if (pktlen < 3)
-    error ("Truncated response packet from Wiggler");
+    error ("Truncated response packet from OCD device");
 
   status = p[1];
   error_code = p[2];
 
   if (error_code != 0)
-    wiggler_error ("wiggler_write_bdm_registers:", error_code);
+    ocd_error ("ocd_write_bdm_registers:", error_code);
 }
 
 void
-wiggler_write_bdm_register (bdm_regno, reg)
-     int bdm_regno;
-     CORE_ADDR reg;
+ocd_write_bdm_register (int bdm_regno, CORE_ADDR reg)
 {
   unsigned char buf[4];
 
   store_unsigned_integer (buf, 4, reg);
 
-  wiggler_write_bdm_registers (bdm_regno, buf, 4);
+  ocd_write_bdm_registers (bdm_regno, buf, 4);
 }
 \f
-void 
-wiggler_prepare_to_store ()
+void
+ocd_prepare_to_store (void)
 {
 }
 \f
@@ -575,13 +565,10 @@ wiggler_prepare_to_store ()
 
    Returns number of bytes transferred, or 0 for error.  */
 
-static int write_mem_command = WIGGLER_WRITE_MEM;
+static int write_mem_command = OCD_WRITE_MEM;
 
-static int
-wiggler_write_bytes (memaddr, myaddr, len)
-     CORE_ADDR memaddr;
-     char *myaddr;
-     int len;
+int
+ocd_write_bytes (CORE_ADDR memaddr, char *myaddr, int len)
 {
   char buf[256 + 10];
   unsigned char *p;
@@ -609,10 +596,10 @@ wiggler_write_bytes (memaddr, myaddr, len)
       buf[7] = numbytes;
 
       memcpy (&buf[8], myaddr, numbytes);
-      wiggler_put_packet (buf, 8 + numbytes);
-      p = wiggler_get_packet (WIGGLER_WRITE_MEM, &pktlen, remote_timeout);
+      ocd_put_packet (buf, 8 + numbytes);
+      p = ocd_get_packet (OCD_WRITE_MEM, &pktlen, remote_timeout);
       if (pktlen < 3)
-       error ("Truncated response packet from Wiggler");
+       error ("Truncated response packet from OCD device");
 
       status = p[1];
       error_code = p[2];
@@ -634,7 +621,7 @@ wiggler_write_bytes (memaddr, myaddr, len)
          break;
        }
       else if (error_code != 0)
-       wiggler_error ("wiggler_write_bytes:", error_code);
+       ocd_error ("ocd_write_bytes:", error_code);
 
       len -= numbytes;
       memaddr += numbytes;
@@ -653,10 +640,7 @@ wiggler_write_bytes (memaddr, myaddr, len)
    Returns number of bytes transferred, or 0 for error.  */
 
 static int
-wiggler_read_bytes (memaddr, myaddr, len)
-     CORE_ADDR memaddr;
-     char *myaddr;
-     int len;
+ocd_read_bytes (CORE_ADDR memaddr, char *myaddr, int len)
 {
   char buf[256 + 10];
   unsigned char *p;
@@ -664,7 +648,7 @@ wiggler_read_bytes (memaddr, myaddr, len)
 
   origlen = len;
 
-  buf[0] = WIGGLER_READ_MEM;
+  buf[0] = OCD_READ_MEM;
   buf[5] = 1;                  /* Read as bytes */
 
   while (len > 0)
@@ -682,10 +666,10 @@ wiggler_read_bytes (memaddr, myaddr, len)
 
       buf[6] = numbytes;
 
-      wiggler_put_packet (buf, 7);
-      p = wiggler_get_packet (WIGGLER_READ_MEM, &pktlen, remote_timeout);
+      ocd_put_packet (buf, 7);
+      p = ocd_get_packet (OCD_READ_MEM, &pktlen, remote_timeout);
       if (pktlen < 4)
-       error ("Truncated response packet from Wiggler");
+       error ("Truncated response packet from OCD device");
 
       status = p[1];
       error_code = p[2];
@@ -707,7 +691,7 @@ wiggler_read_bytes (memaddr, myaddr, len)
          break;
        }
       else if (error_code != 0)
-       wiggler_error ("wiggler_read_bytes:", error_code);
+       ocd_error ("ocd_read_bytes:", error_code);
 
       memcpy (myaddr, &p[4], numbytes);
 
@@ -721,23 +705,25 @@ wiggler_read_bytes (memaddr, myaddr, len)
 \f
 /* 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.  */
+   nonzero.  Returns length of data written or read; 0 for error.  TARGET
+   is ignored.  */
 
-/* ARGSUSED */
 int
-wiggler_xfer_memory (memaddr, myaddr, len, should_write, target)
-     CORE_ADDR memaddr;
-     char *myaddr;
-     int len;
-     int should_write;
-     struct target_ops *target;                        /* ignored */
+ocd_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int should_write,
+                struct mem_attrib *attrib, struct target_ops *target)
 {
-  return dcache_xfer_memory (wiggler_dcache, memaddr, myaddr, len, should_write);
+  int res;
+
+  if (should_write)
+    res = ocd_write_bytes (memaddr, myaddr, len);
+  else
+    res = ocd_read_bytes (memaddr, myaddr, len);
+
+  return res;
 }
 \f
 void
-wiggler_files_info (ignore)
-     struct target_ops *ignore;
+ocd_files_info (struct target_ops *ignore)
 {
   puts_filtered ("Debugging a target over a serial line.\n");
 }
@@ -748,12 +734,11 @@ wiggler_files_info (ignore)
 /* Read a single character from the remote side, handling wierd errors. */
 
 static int
-readchar (timeout)
-     int timeout;
+readchar (int timeout)
 {
   int ch;
 
-  ch = SERIAL_READCHAR (wiggler_desc, timeout);
+  ch = serial_readchar (ocd_desc, timeout);
 
   switch (ch)
     {
@@ -767,135 +752,23 @@ readchar (timeout)
     }
 }
 
-#if 0
-/* Read a character from the data stream, dequoting as necessary.  SYN is
-   treated special.  Any SYNs appearing in the data stream are returned as the
-   distinct value RAW_SYN (which has a value > 8 bits and therefore cannot be
-   mistaken for real data).  */
-
-static int
-get_quoted_char (timeout)
-     int timeout;
-{
-  int ch;
-
-  ch = readchar (timeout);
-
-  switch (ch)
-    {
-    case SERIAL_TIMEOUT:
-      error ("Timeout in mid-packet, aborting");
-    case SYN:
-      return RAW_SYN;
-    case DLE:
-      ch = readchar (timeout);
-      if (ch == SYN)
-       return RAW_SYN;
-      return ch & ~0100;
-    default:
-      return ch;
-    }
-}
-
-static unsigned char pkt[256 * 2 + 10], *pktp; /* Worst case */
+/* Send a packet to the OCD device.  The packet framed by a SYN character,
+   a byte count and a checksum.  The byte count only counts the number of
+   bytes between the count and the checksum.  A count of zero actually
+   means 256.  Any SYNs within the packet (including the checksum and
+   count) must be quoted.  The quote character must be quoted as well.
+   Quoting is done by replacing the character with the two-character sequence
+   DLE, {char} | 0100.  Note that the quoting mechanism has no effect on the
+   byte count.  */
 
 static void
-reset_packet ()
-{
-  pktp = pkt;
-}
-
-static void
-output_packet ()
-{
-  if (SERIAL_WRITE (wiggler_desc, pkt, pktp - pkt))
-    perror_with_name ("output_packet: write failed");
-
-  reset_packet ();
-}
-
-/* Output a quoted character.  SYNs and DLEs are quoted.  Everything else goes
-   through untouched.  */
-
-static void
-put_quoted_char (c)
-     int c;
-{
-  switch (c)
-    {
-    case SYN:
-    case DLE:
-      *pktp++ = DLE;
-      c |= 0100;
-    }
-
-  *pktp++ = c;
-}
-
-/* Send a packet to the Wiggler.  The packet framed by a SYN character, a byte
-   count and a checksum.  The byte count only counts the number of bytes
-   between the count and the checksum.  A count of zero actually means 256.
-   Any SYNs within the packet (including the checksum and count) must be
-   quoted.  The quote character must be quoted as well.  Quoting is done by
-   replacing the character with the two-character sequence DLE, {char} | 0100.
-   Note that the quoting mechanism has no effect on the byte count.
- */
-
-static void
-stu_put_packet (buf, len)
-     unsigned char *buf;
-     int len;
-{
-  unsigned char checksum;
-  unsigned char c;
-
-  if (len == 0 || len > 256)
-    abort ();                  /* Can't represent 0 length packet */
-
-  reset_packet ();
-
-  checksum = 0;
-
-  put_quoted_char (RAW_SYN);
-
-  c = len;
-
-  do
-    {
-      checksum += c;
-
-      put_quoted_char (c);
-
-      c = *buf++;
-    }
-  while (len-- > 0);
-
-  put_quoted_char (-checksum & 0xff);
-
-  output_packet ();
-}
-
-#else
-
-/* Send a packet to the Wiggler.  The packet framed by a SYN character, a byte
-   count and a checksum.  The byte count only counts the number of bytes
-   between the count and the checksum.  A count of zero actually means 256.
-   Any SYNs within the packet (including the checksum and count) must be
-   quoted.  The quote character must be quoted as well.  Quoting is done by
-   replacing the character with the two-character sequence DLE, {char} | 0100.
-   Note that the quoting mechanism has no effect on the byte count.
- */
-
-static void
-wiggler_put_packet (buf, len)
-     unsigned char *buf;
-     int len;
+ocd_put_packet (unsigned char *buf, int len)
 {
   unsigned char checksum;
   unsigned char c;
   unsigned char *packet, *packet_ptr;
 
-  packet = alloca (len + 1 + 1); /* packet + SYN + checksum */
+  packet = alloca (len + 1 + 1);       /* packet + SYN + checksum */
   packet_ptr = packet;
 
   checksum = 0;
@@ -911,104 +784,32 @@ wiggler_put_packet (buf, len)
     }
 
   *packet_ptr++ = -checksum;
-  if (SERIAL_WRITE (wiggler_desc, packet, packet_ptr - packet))
+  if (serial_write (ocd_desc, packet, packet_ptr - packet))
     perror_with_name ("output_packet: write failed");
 }
-#endif
-
-#if 0
-/* Get a packet from the Wiggler.  Timeout is only enforced for the first byte
-   of the packet.  Subsequent bytes are expected to arrive in time <= 
-   remote_timeout.  Returns a pointer to a static buffer containing the payload
-   of the packet.  *LENP contains the length of the packet.
-*/
-
-static unsigned char *
-stu_get_packet (cmd, lenp, timeout)
-     unsigned char cmd;
-     int *lenp;
-{
-  int ch;
-  int len;
-  static unsigned char buf[256 + 10], *p;
-  unsigned char checksum;
-
- find_packet:
-
-  ch = get_quoted_char (timeout);
-
-  if (ch < 0)
-    error ("get_packet (readchar): %d", ch);
-
-  if (ch != RAW_SYN)
-    goto find_packet;
-
- found_syn:                    /* Found the start of a packet */
-
-  p = buf;
-  checksum = 0;
-
-  len = get_quoted_char (remote_timeout);
-
-  if (len == RAW_SYN)
-    goto found_syn;
-
-  checksum += len;
-
-  if (len == 0)
-    len = 256;
-
-  len++;                       /* Include checksum */
-
-  while (len-- > 0)
-    {
-      ch = get_quoted_char (remote_timeout);
-      if (ch == RAW_SYN)
-       goto found_syn;
-
-      *p++ = ch;
-      checksum += ch;
-    }
-
-  if (checksum != 0)
-    goto find_packet;
-
-  if (cmd != buf[0])
-    error ("Response phase error.  Got 0x%x, expected 0x%x", buf[0], cmd);
-
-  *lenp = p - buf - 1;
-  return buf;
-}
-
-#else
 
-/* Get a packet from the Wiggler.  Timeout is only enforced for the first byte
-   of the packet.  Subsequent bytes are expected to arrive in time <= 
-   remote_timeout.  Returns a pointer to a static buffer containing the payload
-   of the packet.  *LENP contains the length of the packet.
-*/
+/* Get a packet from the OCD device.  Timeout is only enforced for the
+   first byte of the packet.  Subsequent bytes are expected to arrive in
+   time <= remote_timeout.  Returns a pointer to a static buffer containing
+   the payload of the packet.  *LENP contains the length of the packet.
+ */
 
 static unsigned char *
-wiggler_get_packet (cmd, lenp, timeout)
-     int cmd;
-     int *lenp;
+ocd_get_packet (int cmd, int *lenp, int timeout)
 {
   int ch;
   int len;
-  int i;
   static unsigned char packet[512];
   unsigned char *packet_ptr;
   unsigned char checksum;
 
- find_packet:
-
   ch = readchar (timeout);
 
   if (ch < 0)
-    error ("wiggler_get_packet (readchar): %d", ch);
+    error ("ocd_get_packet (readchar): %d", ch);
 
   if (ch != 0x55)
-    goto find_packet;
+    error ("ocd_get_packet (readchar): %d", ch);
 
 /* Found the start of a packet */
 
@@ -1020,7 +821,7 @@ wiggler_get_packet (cmd, lenp, timeout)
   ch = readchar (timeout);
 
   if (ch < 0)
-    error ("wiggler_get_packet (readchar): %d", ch);
+    error ("ocd_get_packet (readchar): %d", ch);
 
   *packet_ptr++ = ch;
   checksum += ch;
@@ -1030,7 +831,7 @@ wiggler_get_packet (cmd, lenp, timeout)
   ch = readchar (timeout);
 
   if (ch < 0)
-    error ("wiggler_get_packet (readchar): %d", ch);
+    error ("ocd_get_packet (readchar): %d", ch);
   *packet_ptr++ = ch;
   checksum += ch;
 
@@ -1039,7 +840,7 @@ wiggler_get_packet (cmd, lenp, timeout)
   ch = readchar (timeout);
 
   if (ch < 0)
-    error ("wiggler_get_packet (readchar): %d", ch);
+    error ("ocd_get_packet (readchar): %d", ch);
   *packet_ptr++ = ch;
   checksum += ch;
 
@@ -1049,7 +850,7 @@ wiggler_get_packet (cmd, lenp, timeout)
       len = 8;                 /* write address, value read back */
       break;
     case 0x11:                 /* Bus error? */
-                               /* write address, read flag */
+      /* write address, read flag */
     case 0x15:                 /* Internal error */
       len = 5;                 /* error code, vector */
       break;
@@ -1059,46 +860,47 @@ wiggler_get_packet (cmd, lenp, timeout)
     case 0x0:                  /* Normal result */
       switch (packet[0])
        {
-       case WIGGLER_AYT:       /* Are You There? */
-       case WIGGLER_SET_BAUD_RATE: /* Set Baud Rate */
-       case WIGGLER_INIT:      /* Initialize wiggler */
-       case WIGGLER_SET_SPEED: /* Set Speed */
-       case WIGGLER_SET_FUNC_CODE: /* Set Function Code */
-       case WIGGLER_SET_CTL_FLAGS: /* Set Control Flags */
-       case WIGGLER_SET_BUF_ADDR: /* Set Register Buffer Address */
-       case WIGGLER_RUN:       /* Run Target from PC  */
-       case WIGGLER_RUN_ADDR:  /* Run Target from Specified Address  */
-       case WIGGLER_STOP:      /* Stop Target */
-       case WIGGLER_RESET_RUN: /* Reset Target and Run */
-       case WIGGLER_RESET:     /* Reset Target and Halt */
-       case WIGGLER_STEP:      /* Single Step */
-       case WIGGLER_WRITE_REGS: /* Write Register */
-       case WIGGLER_WRITE_MEM: /* Write Memory */
-       case WIGGLER_FILL_MEM:  /* Fill Memory */
-       case WIGGLER_MOVE_MEM:  /* Move Memory */
-       case WIGGLER_WRITE_INT_MEM: /* Write Internal Memory */
-       case WIGGLER_JUMP:      /* Jump to Subroutine */
-       case WIGGLER_ERASE_FLASH: /* Erase flash memory */
-       case WIGGLER_PROGRAM_FLASH: /* Write flash memory */
-       case WIGGLER_EXIT_MON:  /* Exit the flash programming monitor  */
-       case WIGGLER_ENTER_MON: /* Enter the flash programming monitor  */
+       case OCD_AYT:           /* Are You There? */
+       case OCD_SET_BAUD_RATE: /* Set Baud Rate */
+       case OCD_INIT:          /* Initialize OCD device */
+       case OCD_SET_SPEED:     /* Set Speed */
+       case OCD_SET_FUNC_CODE: /* Set Function Code */
+       case OCD_SET_CTL_FLAGS: /* Set Control Flags */
+       case OCD_SET_BUF_ADDR:  /* Set Register Buffer Address */
+       case OCD_RUN:           /* Run Target from PC  */
+       case OCD_RUN_ADDR:      /* Run Target from Specified Address  */
+       case OCD_STOP:          /* Stop Target */
+       case OCD_RESET_RUN:     /* Reset Target and Run */
+       case OCD_RESET: /* Reset Target and Halt */
+       case OCD_STEP:          /* Single Step */
+       case OCD_WRITE_REGS:    /* Write Register */
+       case OCD_WRITE_MEM:     /* Write Memory */
+       case OCD_FILL_MEM:      /* Fill Memory */
+       case OCD_MOVE_MEM:      /* Move Memory */
+       case OCD_WRITE_INT_MEM: /* Write Internal Memory */
+       case OCD_JUMP:          /* Jump to Subroutine */
+       case OCD_ERASE_FLASH:   /* Erase flash memory */
+       case OCD_PROGRAM_FLASH: /* Write flash memory */
+       case OCD_EXIT_MON:      /* Exit the flash programming monitor  */
+       case OCD_ENTER_MON:     /* Enter the flash programming monitor  */
+       case OCD_LOG_FILE:      /* Make Wigglers.dll save Wigglers.log */
+       case OCD_SET_CONNECTION:        /* Set type of connection in Wigglers.dll */
          len = 0;
          break;
-       case WIGGLER_GET_VERSION: /* Get Version */
+       case OCD_GET_VERSION:   /* Get Version */
          len = 10;
          break;
-       case WIGGLER_GET_STATUS_MASK: /* Get Status Mask */
+       case OCD_GET_STATUS_MASK:       /* Get Status Mask */
          len = 1;
          break;
-       case WIGGLER_GET_CTRS:  /* Get Error Counters */
-       case WIGGLER_READ_REGS: /* Read Register */
-       case WIGGLER_READ_MEM:  /* Read Memory */
-       case WIGGLER_READ_INT_MEM: /* Read Internal Memory */
+       case OCD_GET_CTRS:      /* Get Error Counters */
+       case OCD_READ_REGS:     /* Read Register */
+       case OCD_READ_MEM:      /* Read Memory */
+       case OCD_READ_INT_MEM:  /* Read Internal Memory */
          len = 257;
          break;
        default:
-         fprintf_filtered (gdb_stderr, "Unknown packet type 0x%x\n", ch);
-         goto find_packet;
+         error ("ocd_get_packet: unknown packet type 0x%x\n", ch);
        }
     }
 
@@ -1107,7 +909,7 @@ wiggler_get_packet (cmd, lenp, timeout)
       ch = readchar (timeout);
 
       if (ch < 0)
-       error ("wiggler_get_packet (readchar): %d", ch);
+       error ("ocd_get_packet (readchar): %d", ch);
       *packet_ptr++ = ch;
       checksum += ch;
       len = ch;
@@ -1120,63 +922,72 @@ wiggler_get_packet (cmd, lenp, timeout)
       ch = readchar (timeout);
 
       if (ch < 0)
-       error ("wiggler_get_packet (readchar): %d", ch);
+       error ("ocd_get_packet (readchar): %d", ch);
       *packet_ptr++ = ch;
       checksum += ch;
     }
 
   if (checksum != 0)
-    goto find_packet;
+    error ("ocd_get_packet: bad packet checksum");
 
   if (cmd != -1 && cmd != packet[0])
     error ("Response phase error.  Got 0x%x, expected 0x%x", packet[0], cmd);
 
-  *lenp = packet_ptr - packet - 1; /* Subtract checksum byte */
+  *lenp = packet_ptr - packet - 1;     /* Subtract checksum byte */
   return packet;
 }
-#endif
 
 /* Execute a simple (one-byte) command.  Returns a pointer to the data
    following the error code.  */
 
 static unsigned char *
-do_command (cmd, statusp, lenp)
-     int cmd;
-     int *statusp;
-     int *lenp;
+ocd_do_command (int cmd, int *statusp, int *lenp)
 {
   unsigned char buf[100], *p;
   int status, error_code;
   char errbuf[100];
 
+  unsigned char logbuf[100];
+  int logpktlen;
+
   buf[0] = cmd;
-  wiggler_put_packet (buf, 1);         /* Send command */
-  p = wiggler_get_packet (*buf, lenp, remote_timeout);
+  ocd_put_packet (buf, 1);     /* Send command */
+  p = ocd_get_packet (*buf, lenp, remote_timeout);
 
   if (*lenp < 3)
-    error ("Truncated response packet from Wiggler");
+    error ("Truncated response packet from OCD device");
 
   status = p[1];
   error_code = p[2];
 
   if (error_code != 0)
     {
-      sprintf (errbuf, "do_command (0x%x):", cmd);
-      wiggler_error (errbuf, error_code);
+      sprintf (errbuf, "ocd_do_command (0x%x):", cmd);
+      ocd_error (errbuf, error_code);
     }
 
-  if (status & WIGGLER_FLAG_PWF)
-    error ("Wiggler can't detect VCC at BDM interface.");
-  else if (status & WIGGLER_FLAG_CABLE_DISC)
+  if (status & OCD_FLAG_PWF)
+    error ("OCD device can't detect VCC at BDM interface.");
+  else if (status & OCD_FLAG_CABLE_DISC)
     error ("BDM cable appears to be disconnected.");
 
   *statusp = status;
 
+  logbuf[0] = OCD_LOG_FILE;
+  logbuf[1] = 3;               /* close existing WIGGLERS.LOG */
+  ocd_put_packet (logbuf, 2);
+  ocd_get_packet (logbuf[0], &logpktlen, remote_timeout);
+
+  logbuf[0] = OCD_LOG_FILE;
+  logbuf[1] = 2;               /* append to existing WIGGLERS.LOG */
+  ocd_put_packet (logbuf, 2);
+  ocd_get_packet (logbuf[0], &logpktlen, remote_timeout);
+
   return p + 3;
 }
 \f
 void
-wiggler_kill ()
+ocd_kill (void)
 {
   /* For some mysterious reason, wait_for_inferior calls kill instead of
      mourn after it gets TARGET_WAITKIND_SIGNALLED.  Work around it.  */
@@ -1193,7 +1004,7 @@ wiggler_kill ()
 }
 
 void
-wiggler_mourn ()
+ocd_mourn (void)
 {
   unpush_target (current_ops);
   generic_mourn_inferior ();
@@ -1203,10 +1014,7 @@ wiggler_mourn ()
    the program at that point.  */
 
 void
-wiggler_create_inferior (exec_file, args, env)
-     char *exec_file;
-     char *args;
-     char **env;
+ocd_create_inferior (char *exec_file, char *args, char **env, int from_tty)
 {
   if (args && (*args != '\000'))
     error ("Args are not supported by BDM.");
@@ -1216,13 +1024,11 @@ wiggler_create_inferior (exec_file, args, env)
 }
 
 void
-wiggler_load (args, from_tty)
-     char *args;
-     int from_tty;
+ocd_load (char *args, int from_tty)
 {
   generic_load (args, from_tty);
 
-  inferior_pid = 0;
+  inferior_ptid = null_ptid;
 
 /* This is necessary because many things were based on the PC at the time that
    we attached to the monitor, which is no longer valid now that we have loaded
@@ -1233,58 +1039,67 @@ wiggler_load (args, from_tty)
   clear_symtab_users ();
 }
 
+/* This should be defined for each target */
+/* But we want to be able to compile this file for some configurations
+   not yet supported fully */
+
+#define BDM_BREAKPOINT {0x0,0x0,0x0,0x0}       /* For ppc 8xx */
+
 /* BDM (at least on CPU32) uses a different breakpoint */
 
-static int
-wiggler_insert_breakpoint (addr, contents_cache)
-     CORE_ADDR addr;
-     char *contents_cache;
+int
+ocd_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
 {
-  static char break_insn[] = {BDM_BREAKPOINT};
+  static char break_insn[] = BDM_BREAKPOINT;
   int val;
 
-  val = target_read_memory (addr, contents_cache, sizeof break_insn);
+  val = target_read_memory (addr, contents_cache, sizeof (break_insn));
 
   if (val == 0)
-    val = target_write_memory (addr, break_insn, sizeof break_insn);
+    val = target_write_memory (addr, break_insn, sizeof (break_insn));
+
+  return val;
+}
+
+int
+ocd_remove_breakpoint (CORE_ADDR addr, char *contents_cache)
+{
+  static char break_insn[] = BDM_BREAKPOINT;
+  int val;
+
+  val = target_write_memory (addr, contents_cache, sizeof (break_insn));
 
   return val;
 }
 
 static void
-bdm_command (args, from_tty)
-     char *args;
-     int from_tty;
+bdm_command (char *args, int from_tty)
 {
   error ("bdm command must be followed by `reset'");
 }
 
 static void
-bdm_reset_command (args, from_tty)
-     char *args;
-     int from_tty;
+bdm_reset_command (char *args, int from_tty)
 {
   int status, pktlen;
 
-  if (!wiggler_desc)
-    error ("Not connected to wiggler.");
+  if (!ocd_desc)
+    error ("Not connected to OCD device.");
 
-  do_command (WIGGLER_RESET, &status, &pktlen);
-  dcache_flush (wiggler_dcache);
+  ocd_do_command (OCD_RESET, &status, &pktlen);
+  dcache_invalidate (target_dcache);
   registers_changed ();
 }
 
 static void
-bdm_restart_command (args, from_tty)
-     char *args;
-     int from_tty;
+bdm_restart_command (char *args, int from_tty)
 {
   int status, pktlen;
 
-  if (!wiggler_desc)
-    error ("Not connected to wiggler.");
+  if (!ocd_desc)
+    error ("Not connected to OCD device.");
 
-  do_command (WIGGLER_RESET_RUN, &status, &pktlen);
+  ocd_do_command (OCD_RESET_RUN, &status, &pktlen);
   last_run_status = status;
   clear_proceed_status ();
   wait_for_inferior ();
@@ -1295,77 +1110,61 @@ bdm_restart_command (args, from_tty)
    generic_load from trying to set the PC.  */
 
 static void
-noop_store_registers (regno)
-     int regno;
+noop_store_registers (int regno)
 {
 }
 
 static void
-bdm_update_flash_command (args, from_tty)
-     char *args;
-     int from_tty;
+bdm_update_flash_command (char *args, int from_tty)
 {
   int status, pktlen;
-  struct cleanup *old_chain;
-  void (*store_registers_tmp) PARAMS ((int));
+  struct cleanup *old_chain; 
+  void (*store_registers_tmp) (int);
 
-  if (!wiggler_desc)
-    error ("Not connected to wiggler.");
+  if (!ocd_desc)
+    error ("Not connected to OCD device.");
 
   if (!args)
-    error ("Must specify file containing new Wiggler code.");
+    error ("Must specify file containing new OCD code.");
 
-/*  old_chain = make_cleanup (flash_cleanup, 0);*/
+/*  old_chain = make_cleanup (flash_cleanup, 0); */
 
-  do_command (WIGGLER_ENTER_MON, &status, &pktlen);
+  ocd_do_command (OCD_ENTER_MON, &status, &pktlen);
 
-  do_command (WIGGLER_ERASE_FLASH, &status, &pktlen);
+  ocd_do_command (OCD_ERASE_FLASH, &status, &pktlen);
 
-  write_mem_command = WIGGLER_PROGRAM_FLASH;
+  write_mem_command = OCD_PROGRAM_FLASH;
   store_registers_tmp = current_target.to_store_registers;
   current_target.to_store_registers = noop_store_registers;
 
   generic_load (args, from_tty);
 
   current_target.to_store_registers = store_registers_tmp;
-  write_mem_command = WIGGLER_WRITE_MEM;
-
-  do_command (WIGGLER_EXIT_MON, &status, &pktlen);
-
-/*  discard_cleanups (old_chain);*/
-}
-
-static void
-bdm_read_register_command (args, from_tty)
-     char *args;
-     int from_tty;
-{
-  /* XXX repeat should go on to the next register */
+  write_mem_command = OCD_WRITE_MEM;
 
-  if (!wiggler_desc)
-    error ("Not connected to wiggler.");
-
-  if (!args)
-    error ("Must specify BDM register number.");
+  ocd_do_command (OCD_EXIT_MON, &status, &pktlen);
 
+/*  discard_cleanups (old_chain); */
 }
 \f
+extern initialize_file_ftype _initialize_remote_ocd; /* -Wmissing-prototypes */
+
 void
-_initialize_remote_wiggler ()
+_initialize_remote_ocd (void)
 {
   extern struct cmd_list_element *cmdlist;
-  static struct cmd_list_element *bdm_cmd_list = NULL;
+  static struct cmd_list_element *ocd_cmd_list = NULL;
 
-  add_show_from_set (add_set_cmd ("remotetimeout", no_class,
-                                 var_integer, (char *)&remote_timeout,
-                                 "Set timeout value for remote read.\n", &setlist),
-                    &showlist);
+  deprecated_add_show_from_set
+    (add_set_cmd ("remotetimeout", no_class,
+                 var_integer, (char *) &remote_timeout,
+                 "Set timeout value for remote read.\n", &setlist),
+     &showlist);
 
-  add_prefix_cmd ("bdm", class_obscure, bdm_command, "", &bdm_cmd_list, "bdm ",
+  add_prefix_cmd ("ocd", class_obscure, bdm_command, "", &ocd_cmd_list, "ocd ",
                  0, &cmdlist);
 
-  add_cmd ("reset", class_obscure, bdm_reset_command, "", &bdm_cmd_list);
-  add_cmd ("restart", class_obscure, bdm_restart_command, "", &bdm_cmd_list);
-  add_cmd ("update-flash", class_obscure, bdm_update_flash_command, "", &bdm_cmd_list);
-  /*  add_cmd ("read-register", class_obscure, bdm_read_register_command, "", &bdm_cmd_list);*/
+  add_cmd ("reset", class_obscure, bdm_reset_command, "", &ocd_cmd_list);
+  add_cmd ("restart", class_obscure, bdm_restart_command, "", &ocd_cmd_list);
+  add_cmd ("update-flash", class_obscure, bdm_update_flash_command, "", &ocd_cmd_list);
 }
This page took 0.043847 seconds and 4 git commands to generate.