/* Target communications support for Macraigor Systems' On-Chip Debugging
- Copyright 1996, 1997, 1998, 1999, 2000, 2001
+
+ Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2006
Free Software Foundation, Inc.
This file is part of GDB.
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. */
#include "defs.h"
#include "gdbcore.h"
#include "bfd.h"
#include "symfile.h"
#include "target.h"
+#include "exceptions.h"
#include "gdbcmd.h"
#include "objfiles.h"
#include "gdb-stabs.h"
static int ocd_read_bytes (CORE_ADDR memaddr, char *myaddr, int len);
-static int ocd_start_remote (PTR dummy);
+static int ocd_start_remote (void *dummy);
static int readchar (int timeout);
-static void reset_packet (void);
-
-static void output_packet (void);
-
-static int get_quoted_char (int timeout);
-
-static void put_quoted_char (int c);
-
static void ocd_interrupt (int signo);
static void ocd_interrupt_twice (int signo);
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. */
-
-#if 0
-/* FIXME: Change to allow option to set timeout value on a per target
- basis. */
-static int remote_timeout = 2;
-#endif
-
/* Descriptor for I/O to remote machine. Initialize it to NULL so that
ocd_open knows that we don't have a file open when the program
starts. */
s = buf;
}
- error (s);
+ error (("%s"), s);
}
/* Return nonzero if the thread TH is still alive on the remote system. */
\f
/* Clean up connection to a remote debugger. */
-/* ARGSUSED */
void
ocd_close (int quitting)
{
if (ocd_desc)
- SERIAL_CLOSE (ocd_desc);
+ serial_close (ocd_desc);
ocd_desc = NULL;
}
/* Stub for catch_errors. */
static int
-ocd_start_remote (PTR dummy)
+ocd_start_remote (void *dummy)
{
unsigned char buf[10], *p;
int pktlen;
immediate_quit++; /* Allow user to interrupt it */
- SERIAL_SEND_BREAK (ocd_desc); /* Wake up the wiggler */
+ serial_send_break (ocd_desc); /* Wake up the wiggler */
speed = 80; /* Divide clock by 4000 */
p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
if (pktlen < 2)
- error ("Truncated response packet from OCD device");
+ error (_("Truncated response packet from OCD device"));
status = p[1];
error_code = p[2];
if (error_code != 0)
- ocd_error ("OCD_INIT:", error_code);
+ ocd_error (_("OCD_INIT:"), error_code);
ocd_do_command (OCD_AYT, &status, &pktlen);
p = ocd_do_command (OCD_GET_VERSION, &status, &pktlen);
- printf_unfiltered ("[Wiggler version %x.%x, capability 0x%x]\n",
+ printf_unfiltered (_("[Wiggler version %x.%x, capability 0x%x]\n"),
p[0], p[1], (p[2] << 16) | p[3]);
-#if 0
- /* Reset the target */
-
- ocd_do_command (OCD_RESET_RUN, &status, &pktlen);
-/* ocd_do_command (OCD_RESET, &status, &pktlen); */
-#endif
-
/* If processor is still running, stop it. */
if (!(status & OCD_FLAG_BDM))
ocd_stop ();
-#if 1
/* 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 */
p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
if (pktlen < 2)
- error ("Truncated response packet from OCD device");
+ error (_("Truncated response packet from OCD device"));
status = p[1];
error_code = p[2];
if (error_code != 0)
ocd_error ("OCD_SET_CTL_FLAGS:", error_code);
-#endif
immediate_quit--;
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 (NULL), 0, SRC_AND_LOC);
buf[0] = OCD_LOG_FILE;
buf[1] = 3; /* close existing WIGGLERS.LOG */
int pktlen;
if (name == 0)
- error ("To open an OCD connection, you need to specify the\n\
-device the OCD device 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);
unpush_target (current_ops);
- if (strncmp (name, "wiggler", 7) == 0)
- {
- ocd_desc = SERIAL_OPEN ("ocd");
- if (!ocd_desc)
- perror_with_name (name);
-
- buf[0] = OCD_LOG_FILE;
- buf[1] = 1; /* open new or overwrite existing WIGGLERS.LOG */
- ocd_put_packet (buf, 2);
- p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
-
- buf[0] = OCD_SET_CONNECTION;
- buf[1] = 0x01; /* atoi (name[11]); */
- ocd_put_packet (buf, 2);
- p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
- }
- else
- /* not using Wigglers.dll */
- {
- ocd_desc = SERIAL_OPEN (name);
- if (!ocd_desc)
- perror_with_name (name);
- }
+ ocd_desc = serial_open (name);
+ if (!ocd_desc)
+ perror_with_name (name);
if (baud_rate != -1)
{
- if (SERIAL_SETBAUDRATE (ocd_desc, baud_rate))
+ if (serial_setbaudrate (ocd_desc, baud_rate))
{
- SERIAL_CLOSE (ocd_desc);
+ serial_close (ocd_desc);
perror_with_name (name);
}
}
- SERIAL_RAW (ocd_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 (ocd_desc);
+ serial_flush_input (ocd_desc);
if (from_tty)
{
RETURN_MASK_ALL))
{
pop_target ();
- error ("Failed to connect to OCD.");
+ error (_("Failed to connect to OCD."));
}
}
ocd_detach (char *args, int from_tty)
{
if (args)
- error ("Argument given to \"detach\" when remotely debugging.");
+ error (_("Argument given to \"detach\" when remotely debugging."));
pop_target ();
if (from_tty)
ocd_do_command (OCD_STOP, &status, &pktlen);
if (!(status & OCD_FLAG_BDM))
- error ("Can't stop target via BDM");
+ error (_("Can't stop target via BDM"));
}
static volatile int ocd_interrupt_flag;
Give up (and stop debugging it)? "))
{
target_mourn_inferior ();
- return_to_top_level (RETURN_QUIT);
+ deprecated_throw_reason (RETURN_QUIT);
}
target_terminal_inferior ();
signal (SIGINT, ofunc);
if (pktlen < 2)
- error ("Truncated response packet from OCD device");
+ error (_("Truncated response packet from OCD device"));
last_run_status = p[1];
error_code = p[2];
ocd_error ("target_wait:", error_code);
if (last_run_status & OCD_FLAG_PWF)
- error ("OCD device lost VCC at BDM interface.");
+ 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.");
+ error (_("OCD device cable appears to have been disconnected."));
}
if (ocd_interrupt_flag)
if (i > pktlen - 4
|| ((i & 3) != 0))
- error ("Register block size bad: %d", i);
+ error (_("Register block size bad: %d"), i);
*reglen = i;
p = ocd_get_packet (OCD_WRITE_REGS, &pktlen, remote_timeout);
if (pktlen < 3)
- error ("Truncated response packet from OCD device");
+ error (_("Truncated response packet from OCD device"));
status = p[1];
error_code = p[2];
ocd_put_packet (buf, 8 + numbytes);
p = ocd_get_packet (OCD_WRITE_MEM, &pktlen, remote_timeout);
if (pktlen < 3)
- error ("Truncated response packet from OCD device");
+ error (_("Truncated response packet from OCD device"));
status = p[1];
error_code = p[2];
ocd_put_packet (buf, 7);
p = ocd_get_packet (OCD_READ_MEM, &pktlen, remote_timeout);
if (pktlen < 4)
- error ("Truncated response packet from OCD device");
+ error (_("Truncated response packet from OCD device"));
status = p[1];
error_code = p[2];
nonzero. Returns length of data written or read; 0 for error. TARGET
is ignored. */
-/* ARGSUSED */
int
ocd_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int should_write,
struct mem_attrib *attrib, struct target_ops *target)
{
int ch;
- ch = SERIAL_READCHAR (ocd_desc, timeout);
+ ch = serial_readchar (ocd_desc, timeout);
switch (ch)
{
case SERIAL_EOF:
- error ("Remote connection closed");
+ error (_("Remote connection closed"));
case SERIAL_ERROR:
- perror_with_name ("Remote communication error");
+ perror_with_name (_("Remote communication error"));
case SERIAL_TIMEOUT:
default:
return ch;
}
}
-#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 (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 */
-
-static void
-reset_packet (void)
-{
- pktp = pkt;
-}
-
-static void
-output_packet (void)
-{
- if (SERIAL_WRITE (ocd_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 (int c)
-{
- switch (c)
- {
- case SYN:
- case DLE:
- *pktp++ = DLE;
- c |= 0100;
- }
-
- *pktp++ = c;
-}
-
-/* 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
-stu_put_packet (unsigned char *buf, int len)
-{
- unsigned char checksum;
- unsigned char c;
-
- if (len == 0 || len > 256)
- internal_error (__FILE__, __LINE__, "failed internal consistency check"); /* 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 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
}
*packet_ptr++ = -checksum;
- if (SERIAL_WRITE (ocd_desc, packet, packet_ptr - packet))
- perror_with_name ("output_packet: write failed");
-}
-#endif
-
-#if 0
-/* 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 *
-stu_get_packet (unsigned char cmd, int *lenp, int timeout)
-{
- 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;
+ if (serial_write (ocd_desc, packet, packet_ptr - packet))
+ perror_with_name (_("output_packet: write failed"));
}
-#else
-
/* 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
ch = readchar (timeout);
if (ch < 0)
- error ("ocd_get_packet (readchar): %d", ch);
+ error (_("ocd_get_packet (readchar): %d"), ch);
if (ch != 0x55)
- error ("ocd_get_packet (readchar): %d", ch);
+ error (_("ocd_get_packet (readchar): %d"), ch);
/* Found the start of a packet */
ch = readchar (timeout);
if (ch < 0)
- error ("ocd_get_packet (readchar): %d", ch);
+ error (_("ocd_get_packet (readchar): %d"), ch);
*packet_ptr++ = ch;
checksum += ch;
ch = readchar (timeout);
if (ch < 0)
- error ("ocd_get_packet (readchar): %d", ch);
+ error (_("ocd_get_packet (readchar): %d"), ch);
*packet_ptr++ = ch;
checksum += ch;
ch = readchar (timeout);
if (ch < 0)
- error ("ocd_get_packet (readchar): %d", ch);
+ error (_("ocd_get_packet (readchar): %d"), ch);
*packet_ptr++ = ch;
checksum += ch;
len = 257;
break;
default:
- error ("ocd_get_packet: unknown packet type 0x%x\n", ch);
+ error (_("ocd_get_packet: unknown packet type 0x%x."), ch);
}
}
ch = readchar (timeout);
if (ch < 0)
- error ("ocd_get_packet (readchar): %d", ch);
+ error (_("ocd_get_packet (readchar): %d"), ch);
*packet_ptr++ = ch;
checksum += ch;
len = ch;
ch = readchar (timeout);
if (ch < 0)
- error ("ocd_get_packet (readchar): %d", ch);
+ error (_("ocd_get_packet (readchar): %d"), ch);
*packet_ptr++ = ch;
checksum += ch;
}
if (checksum != 0)
- error ("ocd_get_packet: bad packet checksum");
+ 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);
+ error (_("Response phase error. Got 0x%x, expected 0x%x"), packet[0], cmd);
*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. */
p = ocd_get_packet (*buf, lenp, remote_timeout);
if (*lenp < 3)
- error ("Truncated response packet from OCD device");
+ error (_("Truncated response packet from OCD device"));
status = p[1];
error_code = p[2];
}
if (status & OCD_FLAG_PWF)
- error ("OCD device can't detect VCC at BDM interface.");
+ error (_("OCD device can't detect VCC at BDM interface."));
else if (status & OCD_FLAG_CABLE_DISC)
- error ("BDM cable appears to be disconnected.");
+ error (_("BDM cable appears to be disconnected."));
*statusp = status;
generic_mourn_inferior ();
}
-/* All we actually do is set the PC to the start address of exec_bfd, and start
- the program at that point. */
+/* All we actually do is set the PC to the start address of exec_bfd. */
void
-ocd_create_inferior (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.");
+ error (_("Args are not supported by BDM."));
clear_proceed_status ();
- proceed (bfd_get_start_address (exec_bfd), TARGET_SIGNAL_0, 0);
+ write_pc (bfd_get_start_address (exec_bfd));
}
void
not yet supported fully */
#define BDM_BREAKPOINT {0x0,0x0,0x0,0x0} /* For ppc 8xx */
-#if 0
-#define BDM_BREAKPOINT {0x4a,0xfa} /* BGND insn used for CPU32 */
-#endif
/* BDM (at least on CPU32) uses a different breakpoint */
static void
bdm_command (char *args, int from_tty)
{
- error ("bdm command must be followed by `reset'");
+ error (_("bdm command must be followed by `reset'"));
}
static void
int status, pktlen;
if (!ocd_desc)
- error ("Not connected to OCD device.");
+ error (_("Not connected to OCD device."));
ocd_do_command (OCD_RESET, &status, &pktlen);
dcache_invalidate (target_dcache);
int status, pktlen;
if (!ocd_desc)
- error ("Not connected to OCD device.");
+ error (_("Not connected to OCD device."));
ocd_do_command (OCD_RESET_RUN, &status, &pktlen);
last_run_status = status;
void (*store_registers_tmp) (int);
if (!ocd_desc)
- error ("Not connected to OCD device.");
+ error (_("Not connected to OCD device."));
if (!args)
- error ("Must specify file containing new OCD code.");
+ error (_("Must specify file containing new OCD code."));
/* old_chain = make_cleanup (flash_cleanup, 0); */
/* discard_cleanups (old_chain); */
}
-
-static void
-bdm_read_register_command (char *args, int from_tty)
-{
- /* XXX repeat should go on to the next register */
-
- if (!ocd_desc)
- error ("Not connected to OCD device.");
-
- if (!args)
- error ("Must specify BDM register number.");
-
-}
\f
+extern initialize_file_ftype _initialize_remote_ocd; /* -Wmissing-prototypes */
+
void
_initialize_remote_ocd (void)
{
extern struct cmd_list_element *cmdlist;
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);
-
- add_prefix_cmd ("ocd", class_obscure, bdm_command, "", &ocd_cmd_list, "ocd ",
- 0, &cmdlist);
-
- 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);
- /* add_cmd ("read-register", class_obscure, bdm_read_register_command, "", &ocd_cmd_list); */
+ add_setshow_integer_cmd ("remotetimeout", no_class, &remote_timeout, _("\
+Set timeout value for remote read."), _("\
+Show timeout value for remote read."), NULL,
+ NULL,
+ NULL, /* FIXME: i18n: */
+ &setlist, &showlist);
+
+ /* FIXME: i18n: What documentation? */
+ add_prefix_cmd ("ocd", class_obscure, bdm_command, (""), &ocd_cmd_list,
+ "ocd ", 0, &cmdlist);
+
+ /* FIXME: i18n: what documentation? */
+ 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);
}