1999-04-16 03:35:26 +02:00
|
|
|
/* Remote debugging interface for Array Tech RAID controller..
|
2002-01-19 04:32:43 +01:00
|
|
|
|
|
|
|
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
|
|
|
|
1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
Contributed by Cygnus Support. Written by Rob Savoye for Cygnus.
|
|
|
|
|
|
|
|
This module talks to a debug monitor called 'MONITOR', which
|
|
|
|
We communicate with MONITOR via either a direct serial line, or a TCP
|
|
|
|
(or possibly TELNET) stream to a terminal multiplexor,
|
|
|
|
which in turn talks to the target board.
|
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
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 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,
|
2002-01-19 04:32:43 +01:00
|
|
|
Boston, MA 02111-1307, USA. */
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
#include "gdbcore.h"
|
|
|
|
#include "target.h"
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include "gdb_string.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "serial.h"
|
|
|
|
#include "monitor.h"
|
|
|
|
#include "remote-utils.h"
|
1999-09-09 02:02:17 +02:00
|
|
|
#include "inferior.h"
|
|
|
|
#include "version.h"
|
2001-03-01 02:39:22 +01:00
|
|
|
#include "regcache.h"
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
extern int baud_rate;
|
|
|
|
|
|
|
|
#define ARRAY_PROMPT ">> "
|
|
|
|
|
2000-05-28 03:12:42 +02:00
|
|
|
static void debuglogs (int, char *, ...);
|
1999-07-07 22:19:36 +02:00
|
|
|
static void array_open ();
|
|
|
|
static void array_close ();
|
|
|
|
static void array_detach ();
|
|
|
|
static void array_attach ();
|
2001-05-04 06:15:33 +02:00
|
|
|
static void array_resume (ptid_t ptid, int step, enum target_signal sig);
|
1999-07-07 22:19:36 +02:00
|
|
|
static void array_fetch_register ();
|
|
|
|
static void array_store_register ();
|
|
|
|
static void array_fetch_registers ();
|
|
|
|
static void array_store_registers ();
|
|
|
|
static void array_prepare_to_store ();
|
|
|
|
static void array_files_info ();
|
|
|
|
static void array_kill ();
|
|
|
|
static void array_create_inferior ();
|
|
|
|
static void array_mourn_inferior ();
|
|
|
|
static void make_gdb_packet ();
|
|
|
|
static int array_xfer_memory ();
|
2001-05-04 06:15:33 +02:00
|
|
|
static ptid_t array_wait (ptid_t ptid,
|
|
|
|
struct target_waitstatus *status);
|
1999-07-07 22:19:36 +02:00
|
|
|
static int array_insert_breakpoint ();
|
|
|
|
static int array_remove_breakpoint ();
|
|
|
|
static int tohex ();
|
|
|
|
static int to_hex ();
|
|
|
|
static int from_hex ();
|
|
|
|
static int array_send_packet ();
|
|
|
|
static int array_get_packet ();
|
|
|
|
static unsigned long ascii2hexword ();
|
|
|
|
static void hexword2ascii ();
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
#define LOG_FILE "monitor.log"
|
|
|
|
#if defined (LOG_FILE)
|
|
|
|
FILE *log_file;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int timeout = 30;
|
|
|
|
/* Having this larger than 400 causes us to be incompatible with m68k-stub.c
|
|
|
|
and i386-stub.c. Normally, no one would notice because it only matters
|
|
|
|
for writing large chunks of memory (e.g. in downloads). Also, this needs
|
|
|
|
to be more than 400 if required to hold the registers (see below, where
|
|
|
|
we round it up based on REGISTER_BYTES). */
|
|
|
|
#define PBUFSIZ 400
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Descriptor for I/O to remote machine. Initialize it to NULL so that
|
|
|
|
* array_open knows that we don't have a file open when the program starts.
|
|
|
|
*/
|
2001-07-11 19:52:32 +02:00
|
|
|
struct serial *array_desc = NULL;
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* this array of registers need to match the indexes used by GDB. The
|
|
|
|
* whole reason this exists is cause the various ROM monitors use
|
|
|
|
* different strings than GDB does, and doesn't support all the
|
|
|
|
* registers either. So, typing "info reg sp" becomes a "r30".
|
|
|
|
*/
|
|
|
|
extern char *tmp_mips_processor_type;
|
1999-07-07 22:19:36 +02:00
|
|
|
extern int mips_set_processor_type ();
|
1999-04-16 03:35:26 +02:00
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
static struct target_ops array_ops;
|
1999-04-16 03:35:26 +02:00
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
static void
|
|
|
|
init_array_ops (void)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
1999-07-07 22:19:36 +02:00
|
|
|
array_ops.to_shortname = "array";
|
|
|
|
array_ops.to_longname =
|
1999-04-16 03:35:26 +02:00
|
|
|
"Debug using the standard GDB remote protocol for the Array Tech target.",
|
1999-07-07 22:19:36 +02:00
|
|
|
array_ops.to_doc =
|
1999-04-16 03:35:26 +02:00
|
|
|
"Debug using the standard GDB remote protocol for the Array Tech target.\n\
|
1999-07-07 22:19:36 +02:00
|
|
|
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;
|
1999-04-16 03:35:26 +02:00
|
|
|
array_ops.to_require_attach = NULL;
|
1999-07-07 22:19:36 +02:00
|
|
|
array_ops.to_detach = array_detach;
|
1999-04-16 03:35:26 +02:00
|
|
|
array_ops.to_require_detach = NULL;
|
1999-07-07 22:19:36 +02:00
|
|
|
array_ops.to_resume = array_resume;
|
|
|
|
array_ops.to_wait = array_wait;
|
1999-04-16 03:35:26 +02:00
|
|
|
array_ops.to_post_wait = NULL;
|
1999-07-07 22:19:36 +02:00
|
|
|
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;
|
1999-04-16 03:35:26 +02:00
|
|
|
array_ops.to_post_startup_inferior = NULL;
|
|
|
|
array_ops.to_acknowledge_created_inferior = NULL;
|
1999-07-07 22:19:36 +02:00
|
|
|
array_ops.to_clone_and_follow_inferior = NULL;
|
|
|
|
array_ops.to_post_follow_inferior_by_clone = NULL;
|
1999-04-16 03:35:26 +02:00
|
|
|
array_ops.to_insert_fork_catchpoint = NULL;
|
|
|
|
array_ops.to_remove_fork_catchpoint = NULL;
|
|
|
|
array_ops.to_insert_vfork_catchpoint = NULL;
|
1999-07-07 22:19:36 +02:00
|
|
|
array_ops.to_remove_vfork_catchpoint = NULL;
|
1999-04-16 03:35:26 +02:00
|
|
|
array_ops.to_has_forked = NULL;
|
1999-07-07 22:19:36 +02:00
|
|
|
array_ops.to_has_vforked = NULL;
|
|
|
|
array_ops.to_can_follow_vfork_prior_to_exec = NULL;
|
1999-04-16 03:35:26 +02:00
|
|
|
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;
|
1999-07-07 22:19:36 +02:00
|
|
|
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;
|
1999-04-16 03:35:26 +02:00
|
|
|
array_ops.to_pid_to_exec_file = NULL;
|
1999-07-07 22:19:36 +02:00
|
|
|
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;
|
1999-04-16 03:35:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* printf_monitor -- send data to monitor. Works just like printf.
|
|
|
|
*/
|
|
|
|
static void
|
1999-07-07 22:19:36 +02:00
|
|
|
printf_monitor (char *pattern,...)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
char buf[PBUFSIZ];
|
|
|
|
int i;
|
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
va_start (args, pattern);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
vsprintf (buf, pattern, args);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
debuglogs (1, "printf_monitor(), Sending: \"%s\".", buf);
|
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
if (strlen (buf) > PBUFSIZ)
|
1999-04-16 03:35:26 +02:00
|
|
|
error ("printf_monitor(): string too long");
|
2001-07-15 22:34:14 +02:00
|
|
|
if (serial_write (array_desc, buf, strlen (buf)))
|
|
|
|
fprintf (stderr, "serial_write failed: %s\n", safe_strerror (errno));
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* write_monitor -- send raw data to monitor.
|
|
|
|
*/
|
|
|
|
static void
|
2000-10-02 02:49:55 +02:00
|
|
|
write_monitor (char data[], int len)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
2001-07-15 22:34:14 +02:00
|
|
|
if (serial_write (array_desc, data, len))
|
|
|
|
fprintf (stderr, "serial_write failed: %s\n", safe_strerror (errno));
|
1999-07-07 22:19:36 +02:00
|
|
|
|
|
|
|
*(data + len + 1) = '\0';
|
1999-04-16 03:35:26 +02:00
|
|
|
debuglogs (1, "write_monitor(), Sending: \"%s\".", data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* debuglogs -- deal with debugging info to multiple sources. This takes
|
1999-07-07 22:19:36 +02:00
|
|
|
* two real args, the first one is the level to be compared against
|
|
|
|
* the sr_get_debug() value, the second arg is a printf buffer and args
|
|
|
|
* to be formatted and printed. A CR is added after each string is printed.
|
1999-04-16 03:35:26 +02:00
|
|
|
*/
|
|
|
|
static void
|
1999-07-07 22:19:36 +02:00
|
|
|
debuglogs (int level, char *pattern,...)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
char *p;
|
|
|
|
unsigned char buf[PBUFSIZ];
|
|
|
|
char newbuf[PBUFSIZ];
|
|
|
|
int i;
|
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
va_start (args, pattern);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
if ((level < 0) || (level > 100))
|
|
|
|
{
|
|
|
|
error ("Bad argument passed to debuglogs(), needs debug level");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
vsprintf (buf, pattern, args); /* format the string */
|
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
/* convert some characters so it'll look right in the log */
|
|
|
|
p = newbuf;
|
1999-07-07 22:19:36 +02:00
|
|
|
for (i = 0; buf[i] != '\0'; i++)
|
|
|
|
{
|
|
|
|
if (i > PBUFSIZ)
|
|
|
|
error ("Debug message too long");
|
|
|
|
switch (buf[i])
|
|
|
|
{
|
|
|
|
case '\n': /* newlines */
|
|
|
|
*p++ = '\\';
|
|
|
|
*p++ = 'n';
|
|
|
|
continue;
|
|
|
|
case '\r': /* carriage returns */
|
|
|
|
*p++ = '\\';
|
|
|
|
*p++ = 'r';
|
|
|
|
continue;
|
|
|
|
case '\033': /* escape */
|
|
|
|
*p++ = '\\';
|
|
|
|
*p++ = 'e';
|
|
|
|
continue;
|
|
|
|
case '\t': /* tab */
|
|
|
|
*p++ = '\\';
|
|
|
|
*p++ = 't';
|
|
|
|
continue;
|
|
|
|
case '\b': /* backspace */
|
|
|
|
*p++ = '\\';
|
|
|
|
*p++ = 'b';
|
|
|
|
continue;
|
|
|
|
default: /* no change */
|
|
|
|
*p++ = buf[i];
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
if (buf[i] < 26)
|
|
|
|
{ /* modify control characters */
|
|
|
|
*p++ = '^';
|
|
|
|
*p++ = buf[i] + 'A';
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (buf[i] >= 128)
|
|
|
|
{ /* modify control characters */
|
|
|
|
*p++ = '!';
|
|
|
|
*p++ = buf[i] + 'A';
|
|
|
|
continue;
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
1999-07-07 22:19:36 +02:00
|
|
|
*p = '\0'; /* terminate the string */
|
1999-04-16 03:35:26 +02:00
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
if (sr_get_debug () > level)
|
1999-04-16 03:35:26 +02:00
|
|
|
printf_unfiltered ("%s\n", newbuf);
|
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
#ifdef LOG_FILE /* write to the monitor log */
|
|
|
|
if (log_file != 0x0)
|
|
|
|
{
|
|
|
|
fputs (newbuf, log_file);
|
|
|
|
fputc ('\n', log_file);
|
|
|
|
fflush (log_file);
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* readchar -- read a character from the remote system, doing all the fancy
|
1999-07-07 22:19:36 +02:00
|
|
|
* timeout stuff.
|
1999-04-16 03:35:26 +02:00
|
|
|
*/
|
|
|
|
static int
|
2000-07-30 03:48:28 +02:00
|
|
|
readchar (int timeout)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
2001-07-15 22:34:14 +02:00
|
|
|
c = serial_readchar (array_desc, abs (timeout));
|
1999-04-16 03:35:26 +02:00
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
if (sr_get_debug () > 5)
|
|
|
|
{
|
|
|
|
putchar (c & 0x7f);
|
|
|
|
debuglogs (5, "readchar: timeout = %d\n", timeout);
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
#ifdef LOG_FILE
|
|
|
|
if (isascii (c))
|
1999-07-07 22:19:36 +02:00
|
|
|
putc (c & 0x7f, log_file);
|
1999-04-16 03:35:26 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (c >= 0)
|
|
|
|
return c & 0x7f;
|
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
if (c == SERIAL_TIMEOUT)
|
|
|
|
{
|
|
|
|
if (timeout <= 0)
|
|
|
|
return c; /* Polls shouldn't generate timeout errors */
|
|
|
|
error ("Timeout reading from remote system.");
|
1999-04-16 03:35:26 +02:00
|
|
|
#ifdef LOG_FILE
|
|
|
|
fputs ("ERROR: Timeout reading from remote system", log_file);
|
|
|
|
#endif
|
1999-07-07 22:19:36 +02:00
|
|
|
}
|
|
|
|
perror_with_name ("readchar");
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* expect -- scan input from the remote system, until STRING is found.
|
1999-07-07 22:19:36 +02:00
|
|
|
* If DISCARD is non-zero, then discard non-matching input, else print
|
|
|
|
* it out. Let the user break out immediately.
|
1999-04-16 03:35:26 +02:00
|
|
|
*/
|
|
|
|
static void
|
2000-07-30 03:48:28 +02:00
|
|
|
expect (char *string, int discard)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
char *p = string;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
|
|
|
|
debuglogs (1, "Expecting \"%s\".", string);
|
|
|
|
|
2000-09-01 02:12:10 +02:00
|
|
|
immediate_quit++;
|
1999-07-07 22:19:36 +02:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
c = readchar (timeout);
|
|
|
|
if (!isascii (c))
|
|
|
|
continue;
|
|
|
|
if (c == *p++)
|
|
|
|
{
|
|
|
|
if (*p == '\0')
|
|
|
|
{
|
2000-09-01 02:12:10 +02:00
|
|
|
immediate_quit--;
|
1999-07-07 22:19:36 +02:00
|
|
|
debuglogs (4, "Matched");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!discard)
|
|
|
|
{
|
|
|
|
fputc_unfiltered (c, gdb_stdout);
|
|
|
|
}
|
|
|
|
p = string;
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Keep discarding input until we see the MONITOR array_cmds->prompt.
|
|
|
|
|
|
|
|
The convention for dealing with the expect_prompt is that you
|
|
|
|
o give your command
|
|
|
|
o *then* wait for the expect_prompt.
|
|
|
|
|
|
|
|
Thus the last thing that a procedure does with the serial line
|
|
|
|
will be an expect_prompt(). Exception: array_resume does not
|
|
|
|
wait for the expect_prompt, because the terminal is being handed over
|
|
|
|
to the inferior. However, the next thing which happens after that
|
|
|
|
is a array_wait which does wait for the expect_prompt.
|
|
|
|
Note that this includes abnormal exit, e.g. error(). This is
|
|
|
|
necessary to prevent getting into states from which we can't
|
|
|
|
recover. */
|
|
|
|
static void
|
2000-07-30 03:48:28 +02:00
|
|
|
expect_prompt (int discard)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
expect (ARRAY_PROMPT, discard);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* junk -- ignore junk characters. Returns a 1 if junk, 0 otherwise
|
|
|
|
*/
|
|
|
|
static int
|
2000-07-30 03:48:28 +02:00
|
|
|
junk (char ch)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
1999-07-07 22:19:36 +02:00
|
|
|
switch (ch)
|
|
|
|
{
|
|
|
|
case '\0':
|
|
|
|
case ' ':
|
|
|
|
case '-':
|
|
|
|
case '\t':
|
|
|
|
case '\r':
|
|
|
|
case '\n':
|
|
|
|
if (sr_get_debug () > 5)
|
|
|
|
debuglogs (5, "Ignoring \'%c\'.", ch);
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
if (sr_get_debug () > 5)
|
|
|
|
debuglogs (5, "Accepting \'%c\'.", ch);
|
|
|
|
return 0;
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get_hex_digit -- Get a hex digit from the remote system & return its value.
|
1999-07-07 22:19:36 +02:00
|
|
|
* If ignore is nonzero, ignore spaces, newline & tabs.
|
1999-04-16 03:35:26 +02:00
|
|
|
*/
|
|
|
|
static int
|
2000-07-30 03:48:28 +02:00
|
|
|
get_hex_digit (int ignore)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
static int ch;
|
1999-07-07 22:19:36 +02:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
ch = readchar (timeout);
|
|
|
|
if (junk (ch))
|
|
|
|
continue;
|
|
|
|
if (sr_get_debug () > 4)
|
|
|
|
{
|
|
|
|
debuglogs (4, "get_hex_digit() got a 0x%x(%c)", ch, ch);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef LOG_FILE /* write to the monitor log */
|
|
|
|
if (log_file != 0x0)
|
|
|
|
{
|
|
|
|
fputs ("get_hex_digit() got a 0x", log_file);
|
|
|
|
fputc (ch, log_file);
|
|
|
|
fputc ('\n', log_file);
|
|
|
|
fflush (log_file);
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
#endif
|
1999-07-07 22:19:36 +02:00
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
if (ch >= '0' && ch <= '9')
|
|
|
|
return ch - '0';
|
|
|
|
else if (ch >= 'A' && ch <= 'F')
|
|
|
|
return ch - 'A' + 10;
|
|
|
|
else if (ch >= 'a' && ch <= 'f')
|
|
|
|
return ch - 'a' + 10;
|
|
|
|
else if (ch == ' ' && ignore)
|
|
|
|
;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
expect_prompt (1);
|
|
|
|
debuglogs (4, "Invalid hex digit from remote system. (0x%x)", ch);
|
|
|
|
error ("Invalid hex digit from remote system. (0x%x)", ch);
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get_hex_byte -- Get a byte from monitor and put it in *BYT.
|
1999-07-07 22:19:36 +02:00
|
|
|
* Accept any number leading spaces.
|
1999-04-16 03:35:26 +02:00
|
|
|
*/
|
|
|
|
static void
|
2000-07-30 03:48:28 +02:00
|
|
|
get_hex_byte (char *byt)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
int val;
|
|
|
|
|
|
|
|
val = get_hex_digit (1) << 4;
|
|
|
|
debuglogs (4, "get_hex_byte() -- Read first nibble 0x%x", val);
|
1999-07-07 22:19:36 +02:00
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
val |= get_hex_digit (0);
|
|
|
|
debuglogs (4, "get_hex_byte() -- Read second nibble 0x%x", val);
|
|
|
|
*byt = val;
|
1999-07-07 22:19:36 +02:00
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
debuglogs (4, "get_hex_byte() -- Read a 0x%x", val);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get_hex_word -- Get N 32-bit words from remote, each preceded by a space,
|
1999-07-07 22:19:36 +02:00
|
|
|
* and put them in registers starting at REGNO.
|
1999-04-16 03:35:26 +02:00
|
|
|
*/
|
|
|
|
static int
|
2000-07-30 03:48:28 +02:00
|
|
|
get_hex_word (void)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
long val, newval;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
val = 0;
|
|
|
|
|
2001-06-29 06:41:20 +02:00
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
val = (val << 4) + get_hex_digit (i == 0);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
2001-06-29 06:41:20 +02:00
|
|
|
debuglogs (4, "get_hex_word() got a 0x%x.", val);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is called not only when we first attach, but also when the
|
|
|
|
user types "run" after having attached. */
|
|
|
|
static void
|
2000-07-30 03:48:28 +02:00
|
|
|
array_create_inferior (char *execfile, char *args, char **env)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
int entry_pt;
|
|
|
|
|
|
|
|
if (args && *args)
|
1999-07-07 22:19:36 +02:00
|
|
|
error ("Can't pass arguments to remote MONITOR process");
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
if (execfile == 0 || exec_bfd == 0)
|
1999-07-07 22:19:36 +02:00
|
|
|
error ("No executable file specified");
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
entry_pt = (int) bfd_get_start_address (exec_bfd);
|
|
|
|
|
|
|
|
/* The "process" (board) is already stopped awaiting our commands, and
|
|
|
|
the program is already downloaded. We just set its PC and go. */
|
|
|
|
|
|
|
|
clear_proceed_status ();
|
|
|
|
|
|
|
|
/* Tell wait_for_inferior that we've started a new process. */
|
|
|
|
init_wait_for_inferior ();
|
|
|
|
|
|
|
|
/* Set up the "saved terminal modes" of the inferior
|
|
|
|
based on what modes we are starting it with. */
|
|
|
|
target_terminal_init ();
|
|
|
|
|
|
|
|
/* Install inferior's terminal modes. */
|
|
|
|
target_terminal_inferior ();
|
|
|
|
|
|
|
|
/* insert_step_breakpoint (); FIXME, do we need this? */
|
|
|
|
|
|
|
|
/* Let 'er rip... */
|
1999-07-07 22:19:36 +02:00
|
|
|
proceed ((CORE_ADDR) entry_pt, TARGET_SIGNAL_DEFAULT, 0);
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* array_open -- open a connection to a remote debugger.
|
1999-07-07 22:19:36 +02:00
|
|
|
* NAME is the filename used for communication.
|
1999-04-16 03:35:26 +02:00
|
|
|
*/
|
|
|
|
static int baudrate = 9600;
|
|
|
|
static char dev_name[100];
|
|
|
|
|
|
|
|
static void
|
2000-07-30 03:48:28 +02:00
|
|
|
array_open (char *args, char *name, int from_tty)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
char packet[PBUFSIZ];
|
|
|
|
|
|
|
|
if (args == NULL)
|
|
|
|
error ("Use `target %s DEVICE-NAME' to use a serial port, or \n\
|
|
|
|
`target %s HOST-NAME:PORT-NUMBER' to use a network connection.", name, name);
|
|
|
|
|
|
|
|
/* if (is_open) */
|
1999-07-07 22:19:36 +02:00
|
|
|
array_close (0);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
strcpy (dev_name, args);
|
2001-07-15 22:34:14 +02:00
|
|
|
array_desc = serial_open (dev_name);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
if (array_desc == NULL)
|
1999-07-07 22:19:36 +02:00
|
|
|
perror_with_name (dev_name);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
if (baud_rate != -1)
|
|
|
|
{
|
2001-07-15 22:34:14 +02:00
|
|
|
if (serial_setbaudrate (array_desc, baud_rate))
|
1999-07-07 22:19:36 +02:00
|
|
|
{
|
2001-07-15 22:34:14 +02:00
|
|
|
serial_close (array_desc);
|
1999-07-07 22:19:36 +02:00
|
|
|
perror_with_name (name);
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
1999-07-07 22:19:36 +02:00
|
|
|
|
2001-07-15 22:34:14 +02:00
|
|
|
serial_raw (array_desc);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
#if defined (LOG_FILE)
|
|
|
|
log_file = fopen (LOG_FILE, "w");
|
|
|
|
if (log_file == NULL)
|
|
|
|
perror_with_name (LOG_FILE);
|
1999-09-09 02:02:17 +02:00
|
|
|
fprintf (log_file, "GDB %s (%s", version, host_name);
|
1999-04-16 03:35:26 +02:00
|
|
|
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
|
|
|
|
expect_prompt to print a few times. For the GDB remote protocol, the application
|
|
|
|
being debugged is sitting at a breakpoint and waiting for GDB to initialize
|
|
|
|
the connection. We force it to give us an empty packet to see if it's alive.
|
1999-07-07 22:19:36 +02:00
|
|
|
*/
|
|
|
|
debuglogs (3, "Trying to ACK the target's debug stub");
|
|
|
|
/* unless your are on the new hardware, the old board won't initialize
|
|
|
|
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 */
|
1999-04-16 03:35:26 +02:00
|
|
|
#ifdef TEST_ARRAY /* skip packet for testing */
|
1999-07-07 22:19:36 +02:00
|
|
|
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 */
|
1999-04-16 03:35:26 +02:00
|
|
|
#endif
|
|
|
|
push_target (&array_ops);
|
|
|
|
if (from_tty)
|
1999-07-07 22:19:36 +02:00
|
|
|
printf ("Remote target %s connected to %s\n", array_ops.to_shortname, dev_name);
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* array_close -- Close out all files and local state before this
|
1999-07-07 22:19:36 +02:00
|
|
|
* target loses control.
|
1999-04-16 03:35:26 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2000-07-30 03:48:28 +02:00
|
|
|
array_close (int quitting)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
2001-07-15 22:34:14 +02:00
|
|
|
serial_close (array_desc);
|
1999-04-16 03:35:26 +02:00
|
|
|
array_desc = NULL;
|
|
|
|
|
|
|
|
debuglogs (1, "array_close (quitting=%d)", quitting);
|
|
|
|
|
|
|
|
#if defined (LOG_FILE)
|
1999-07-07 22:19:36 +02:00
|
|
|
if (log_file)
|
|
|
|
{
|
|
|
|
if (ferror (log_file))
|
|
|
|
printf_filtered ("Error writing log file.\n");
|
|
|
|
if (fclose (log_file) != 0)
|
|
|
|
printf_filtered ("Error closing log file.\n");
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* array_detach -- terminate the open connection to the remote
|
1999-07-07 22:19:36 +02:00
|
|
|
* debugger. Use this when you want to detach and do something
|
|
|
|
* else with your gdb.
|
1999-04-16 03:35:26 +02:00
|
|
|
*/
|
|
|
|
static void
|
2000-07-30 03:48:28 +02:00
|
|
|
array_detach (int from_tty)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
debuglogs (1, "array_detach ()");
|
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
pop_target (); /* calls array_close to do the real work */
|
1999-04-16 03:35:26 +02:00
|
|
|
if (from_tty)
|
|
|
|
printf ("Ending remote %s debugging\n", target_shortname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* array_attach -- attach GDB to the target.
|
|
|
|
*/
|
|
|
|
static void
|
2000-07-30 03:48:28 +02:00
|
|
|
array_attach (char *args, int from_tty)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
if (from_tty)
|
|
|
|
printf ("Starting remote %s debugging\n", target_shortname);
|
1999-07-07 22:19:36 +02:00
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
debuglogs (1, "array_attach (args=%s)", args);
|
1999-07-07 22:19:36 +02:00
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
printf_monitor ("go %x\n");
|
|
|
|
/* swallow the echo. */
|
|
|
|
expect ("go %x\n", 1);
|
|
|
|
}
|
1999-07-07 22:19:36 +02:00
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
/*
|
|
|
|
* array_resume -- Tell the remote machine to resume.
|
|
|
|
*/
|
|
|
|
static void
|
2001-05-04 06:15:33 +02:00
|
|
|
array_resume (ptid_t ptid, int step, enum target_signal sig)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
debuglogs (1, "array_resume (step=%d, sig=%d)", step, sig);
|
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
if (step)
|
|
|
|
{
|
|
|
|
printf_monitor ("s\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf_monitor ("go\n");
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#define TMPBUFSIZ 5
|
|
|
|
|
|
|
|
/*
|
|
|
|
* array_wait -- Wait until the remote machine stops, then return,
|
|
|
|
* storing status in status just as `wait' would.
|
|
|
|
*/
|
2001-05-04 06:15:33 +02:00
|
|
|
static ptid_t
|
|
|
|
array_wait (ptid_t ptid, struct target_waitstatus *status)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
int old_timeout = timeout;
|
|
|
|
int result, i;
|
|
|
|
char c;
|
2001-07-11 19:52:32 +02:00
|
|
|
struct serial *tty_desc;
|
1999-04-16 03:35:26 +02:00
|
|
|
serial_ttystate ttystate;
|
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
debuglogs (1, "array_wait (), printing extraneous text.");
|
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
status->kind = TARGET_WAITKIND_EXITED;
|
|
|
|
status->value.integer = 0;
|
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
timeout = 0; /* Don't time out -- user program is running. */
|
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
#if !defined(__GO32__) && !defined(__MSDOS__) && !defined(_WIN32)
|
2001-07-15 22:34:14 +02:00
|
|
|
tty_desc = serial_fdopen (0);
|
|
|
|
ttystate = serial_get_tty_state (tty_desc);
|
|
|
|
serial_raw (tty_desc);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
/* poll on the serial port and the keyboard. */
|
1999-07-07 22:19:36 +02:00
|
|
|
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);
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
2001-07-15 22:34:14 +02:00
|
|
|
c = serial_readchar (tty_desc, timeout);
|
1999-07-07 22:19:36 +02:00
|
|
|
if (c > 0)
|
|
|
|
{
|
2001-07-15 22:34:14 +02:00
|
|
|
serial_write (array_desc, &c, 1);
|
1999-07-07 22:19:36 +02:00
|
|
|
/* do this so it looks like there's keyboard echo */
|
|
|
|
if (c == 3) /* exit on Control-C */
|
|
|
|
break;
|
1999-04-16 03:35:26 +02:00
|
|
|
#if 0
|
1999-07-07 22:19:36 +02:00
|
|
|
fputc_unfiltered (c, gdb_stdout);
|
|
|
|
gdb_flush (gdb_stdout);
|
1999-04-16 03:35:26 +02:00
|
|
|
#endif
|
1999-07-07 22:19:36 +02:00
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
2001-07-15 22:34:14 +02:00
|
|
|
serial_set_tty_state (tty_desc, ttystate);
|
1999-04-16 03:35:26 +02:00
|
|
|
#else
|
1999-07-07 22:19:36 +02:00
|
|
|
expect_prompt (1);
|
1999-04-16 03:35:26 +02:00
|
|
|
debuglogs (4, "array_wait(), got the expect_prompt.");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
status->kind = TARGET_WAITKIND_STOPPED;
|
|
|
|
status->value.sig = TARGET_SIGNAL_TRAP;
|
|
|
|
|
|
|
|
timeout = old_timeout;
|
|
|
|
|
2001-05-04 06:15:33 +02:00
|
|
|
return inferior_ptid;
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* array_fetch_registers -- read the remote registers into the
|
1999-07-07 22:19:36 +02:00
|
|
|
* block regs.
|
1999-04-16 03:35:26 +02:00
|
|
|
*/
|
|
|
|
static void
|
2000-07-30 03:48:28 +02:00
|
|
|
array_fetch_registers (int ignored)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
2001-06-29 06:41:20 +02:00
|
|
|
char *reg = alloca (MAX_REGISTER_RAW_SIZE);
|
|
|
|
int regno;
|
1999-04-16 03:35:26 +02:00
|
|
|
char *p;
|
2001-06-29 06:41:20 +02:00
|
|
|
char *packet = alloca (PBUFSIZ);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
debuglogs (1, "array_fetch_registers (ignored=%d)\n", ignored);
|
|
|
|
|
|
|
|
memset (packet, 0, PBUFSIZ);
|
|
|
|
make_gdb_packet (packet, "g");
|
|
|
|
if (array_send_packet (packet) == 0)
|
|
|
|
error ("Couldn't transmit packet\n");
|
|
|
|
if (array_get_packet (packet) == 0)
|
1999-07-07 22:19:36 +02:00
|
|
|
error ("Couldn't receive packet\n");
|
1999-04-16 03:35:26 +02:00
|
|
|
/* FIXME: read bytes from packet */
|
|
|
|
debuglogs (4, "array_fetch_registers: Got a \"%s\" back\n", packet);
|
1999-07-07 22:19:36 +02:00
|
|
|
for (regno = 0; regno <= PC_REGNUM + 4; regno++)
|
|
|
|
{
|
|
|
|
/* supply register stores in target byte order, so swap here */
|
|
|
|
/* FIXME: convert from ASCII hex to raw bytes */
|
2001-06-29 06:41:20 +02:00
|
|
|
LONGEST i = ascii2hexword (packet + (regno * 8));
|
1999-07-07 22:19:36 +02:00
|
|
|
debuglogs (5, "Adding register %d = %x\n", regno, i);
|
2001-06-29 06:41:20 +02:00
|
|
|
store_unsigned_integer (®, REGISTER_RAW_SIZE (regno), i);
|
|
|
|
supply_register (regno, (char *) ®);
|
1999-07-07 22:19:36 +02:00
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is unused by targets like this one that use a
|
|
|
|
* protocol based on GDB's remote protocol.
|
|
|
|
*/
|
|
|
|
static void
|
2000-07-30 03:48:28 +02:00
|
|
|
array_fetch_register (int ignored)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
2000-08-19 00:02:43 +02:00
|
|
|
array_fetch_registers (0 /* ignored */);
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get all the registers from the targets. They come back in a large array.
|
|
|
|
*/
|
|
|
|
static void
|
2000-07-30 03:48:28 +02:00
|
|
|
array_store_registers (int ignored)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
int regno;
|
|
|
|
unsigned long i;
|
|
|
|
char packet[PBUFSIZ];
|
|
|
|
char buf[PBUFSIZ];
|
|
|
|
char num[9];
|
1999-07-07 22:19:36 +02:00
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
debuglogs (1, "array_store_registers()");
|
|
|
|
|
|
|
|
memset (packet, 0, PBUFSIZ);
|
|
|
|
memset (buf, 0, PBUFSIZ);
|
|
|
|
buf[0] = 'G';
|
|
|
|
|
|
|
|
/* Unimplemented registers read as all bits zero. */
|
|
|
|
/* FIXME: read bytes from packet */
|
1999-07-07 22:19:36 +02:00
|
|
|
for (regno = 0; regno < 41; regno++)
|
|
|
|
{ /* FIXME */
|
|
|
|
/* supply register stores in target byte order, so swap here */
|
|
|
|
/* FIXME: convert from ASCII hex to raw bytes */
|
|
|
|
i = (unsigned long) read_register (regno);
|
|
|
|
hexword2ascii (num, i);
|
|
|
|
strcpy (buf + (regno * 8) + 1, num);
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
*(buf + (regno * 8) + 2) = 0;
|
|
|
|
make_gdb_packet (packet, buf);
|
|
|
|
if (array_send_packet (packet) == 0)
|
|
|
|
error ("Couldn't transmit packet\n");
|
|
|
|
if (array_get_packet (packet) == 0)
|
1999-07-07 22:19:36 +02:00
|
|
|
error ("Couldn't receive packet\n");
|
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
registers_changed ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is unused by targets like this one that use a
|
|
|
|
* protocol based on GDB's remote protocol.
|
|
|
|
*/
|
|
|
|
static void
|
2000-07-30 03:48:28 +02:00
|
|
|
array_store_register (int ignored)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
2000-08-19 00:02:43 +02:00
|
|
|
array_store_registers (0 /* ignored */);
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get ready to modify the registers array. On machines which store
|
|
|
|
individual registers, this doesn't need to do anything. On machines
|
|
|
|
which store all the registers in one fell swoop, this makes sure
|
|
|
|
that registers contains all the registers from the program being
|
|
|
|
debugged. */
|
|
|
|
|
|
|
|
static void
|
2000-07-30 03:48:28 +02:00
|
|
|
array_prepare_to_store (void)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
/* Do nothing, since we can store individual regs */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-07-30 03:48:28 +02:00
|
|
|
array_files_info (void)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
printf ("\tAttached to %s at %d baud.\n",
|
|
|
|
dev_name, baudrate);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* array_write_inferior_memory -- Copy LEN bytes of data from debugger
|
1999-07-07 22:19:36 +02:00
|
|
|
* memory at MYADDR to inferior's memory at MEMADDR. Returns length moved.
|
1999-04-16 03:35:26 +02:00
|
|
|
*/
|
|
|
|
static int
|
2000-07-30 03:48:28 +02:00
|
|
|
array_write_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
unsigned long i;
|
|
|
|
int j;
|
|
|
|
char packet[PBUFSIZ];
|
|
|
|
char buf[PBUFSIZ];
|
|
|
|
char num[9];
|
|
|
|
char *p;
|
1999-07-07 22:19:36 +02:00
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
debuglogs (1, "array_write_inferior_memory (memaddr=0x%x, myaddr=0x%x, len=%d)", memaddr, myaddr, len);
|
1999-07-07 22:19:36 +02:00
|
|
|
memset (buf, '\0', PBUFSIZ); /* this also sets the string terminator */
|
1999-04-16 03:35:26 +02:00
|
|
|
p = buf;
|
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
*p++ = 'M'; /* The command to write memory */
|
1999-04-16 03:35:26 +02:00
|
|
|
hexword2ascii (num, memaddr); /* convert the address */
|
1999-07-07 22:19:36 +02:00
|
|
|
strcpy (p, num); /* copy the address */
|
1999-04-16 03:35:26 +02:00
|
|
|
p += 8;
|
1999-07-07 22:19:36 +02:00
|
|
|
*p++ = ','; /* add comma delimeter */
|
|
|
|
hexword2ascii (num, len); /* Get the length as a 4 digit number */
|
1999-04-16 03:35:26 +02:00
|
|
|
*p++ = num[4];
|
|
|
|
*p++ = num[5];
|
|
|
|
*p++ = num[6];
|
|
|
|
*p++ = num[7];
|
1999-07-07 22:19:36 +02:00
|
|
|
*p++ = ':'; /* add the colon delimeter */
|
|
|
|
for (j = 0; j < len; j++)
|
|
|
|
{ /* copy the data in after converting it */
|
|
|
|
*p++ = tohex ((myaddr[j] >> 4) & 0xf);
|
|
|
|
*p++ = tohex (myaddr[j] & 0xf);
|
|
|
|
}
|
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
make_gdb_packet (packet, buf);
|
|
|
|
if (array_send_packet (packet) == 0)
|
|
|
|
error ("Couldn't transmit packet\n");
|
|
|
|
if (array_get_packet (packet) == 0)
|
1999-07-07 22:19:36 +02:00
|
|
|
error ("Couldn't receive packet\n");
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* array_read_inferior_memory -- read LEN bytes from inferior memory
|
1999-07-07 22:19:36 +02:00
|
|
|
* at MEMADDR. Put the result at debugger address MYADDR. Returns
|
|
|
|
* length moved.
|
1999-04-16 03:35:26 +02:00
|
|
|
*/
|
|
|
|
static int
|
2000-07-30 03:48:28 +02:00
|
|
|
array_read_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
int j;
|
|
|
|
char buf[20];
|
|
|
|
char packet[PBUFSIZ];
|
|
|
|
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);
|
|
|
|
|
|
|
|
/* Note that this code works correctly if startaddr is just less
|
|
|
|
than UINT_MAX (well, really CORE_ADDR_MAX if there was such a
|
|
|
|
thing). That is, something like
|
|
|
|
array_read_bytes (CORE_ADDR_MAX - 4, foo, 4)
|
|
|
|
works--it never adds len To memaddr and gets 0. */
|
|
|
|
/* However, something like
|
|
|
|
array_read_bytes (CORE_ADDR_MAX - 3, foo, 4)
|
|
|
|
doesn't need to work. Detect it and give up if there's an attempt
|
|
|
|
to do that. */
|
1999-07-07 22:19:36 +02:00
|
|
|
if (((memaddr - 1) + len) < memaddr)
|
|
|
|
{
|
|
|
|
errno = EIO;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
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);
|
1999-09-09 02:02:17 +02:00
|
|
|
sprintf (buf, "m%08lx,%04x", startaddr, len_this_pass);
|
1999-04-16 03:35:26 +02:00
|
|
|
make_gdb_packet (packet, buf);
|
|
|
|
if (array_send_packet (packet) == 0)
|
|
|
|
{
|
|
|
|
error ("Couldn't transmit packet\n");
|
|
|
|
}
|
|
|
|
if (array_get_packet (packet) == 0)
|
|
|
|
{
|
1999-07-07 22:19:36 +02:00
|
|
|
error ("Couldn't receive packet\n");
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
if (*packet == 0)
|
|
|
|
{
|
|
|
|
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);
|
1999-07-07 22:19:36 +02:00
|
|
|
for (j = 0; j < len_this_pass; j++)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
/* extract the byte values */
|
1999-07-07 22:19:36 +02:00
|
|
|
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]);
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (count);
|
|
|
|
}
|
|
|
|
|
2000-10-02 02:49:55 +02:00
|
|
|
/* Transfer LEN bytes between GDB address MYADDR and target address
|
|
|
|
MEMADDR. If WRITE is non-zero, transfer them to the target,
|
|
|
|
otherwise transfer them from the target. TARGET is unused.
|
|
|
|
|
|
|
|
Returns the number of bytes transferred. */
|
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
static int
|
2000-10-02 02:49:55 +02:00
|
|
|
array_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
|
2002-01-19 04:32:43 +01:00
|
|
|
struct mem_attrib *attrib, struct target_ops *target)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
if (write)
|
|
|
|
return array_write_inferior_memory (memaddr, myaddr, len);
|
|
|
|
else
|
|
|
|
return array_read_inferior_memory (memaddr, myaddr, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-07-30 03:48:28 +02:00
|
|
|
array_kill (char *args, int from_tty)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
1999-07-07 22:19:36 +02:00
|
|
|
return; /* ignore attempts to kill target system */
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Clean up when a program exits.
|
|
|
|
The program actually lives on in the remote processor's RAM, and may be
|
|
|
|
run again without a download. Don't leave it full of breakpoint
|
|
|
|
instructions. */
|
|
|
|
|
|
|
|
static void
|
2000-07-30 03:48:28 +02:00
|
|
|
array_mourn_inferior (void)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
remove_breakpoints ();
|
|
|
|
generic_mourn_inferior (); /* Do all the proper things now */
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_ARRAY_BREAKPOINTS 16
|
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
static CORE_ADDR breakaddr[MAX_ARRAY_BREAKPOINTS] =
|
|
|
|
{0};
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* array_insert_breakpoint -- add a breakpoint
|
|
|
|
*/
|
|
|
|
static int
|
2000-07-30 03:48:28 +02:00
|
|
|
array_insert_breakpoint (CORE_ADDR addr, char *shadow)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
for (i = 0; i <= MAX_ARRAY_BREAKPOINTS; i++)
|
|
|
|
{
|
|
|
|
if (breakaddr[i] == 0)
|
|
|
|
{
|
|
|
|
breakaddr[i] = addr;
|
|
|
|
if (sr_get_debug () > 4)
|
1999-09-09 02:02:17 +02:00
|
|
|
printf ("Breakpoint at %s\n", paddr_nz (addr));
|
1999-07-07 22:19:36 +02:00
|
|
|
array_read_inferior_memory (bp_addr, shadow, bp_size);
|
|
|
|
printf_monitor ("b 0x%x\n", addr);
|
|
|
|
expect_prompt (1);
|
|
|
|
return 0;
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
fprintf (stderr, "Too many breakpoints (> 16) for monitor\n");
|
1999-04-16 03:35:26 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _remove_breakpoint -- Tell the monitor to remove a breakpoint
|
|
|
|
*/
|
|
|
|
static int
|
2000-07-30 03:48:28 +02:00
|
|
|
array_remove_breakpoint (CORE_ADDR addr, char *shadow)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
debuglogs (1, "array_remove_breakpoint() addr = 0x%x", addr);
|
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
for (i = 0; i < MAX_ARRAY_BREAKPOINTS; i++)
|
|
|
|
{
|
|
|
|
if (breakaddr[i] == addr)
|
|
|
|
{
|
|
|
|
breakaddr[i] = 0;
|
|
|
|
/* some monitors remove breakpoints based on the address */
|
|
|
|
printf_monitor ("bd %x\n", i);
|
|
|
|
expect_prompt (1);
|
|
|
|
return 0;
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
1999-09-09 02:02:17 +02:00
|
|
|
fprintf (stderr, "Can't find breakpoint associated with 0x%s\n",
|
|
|
|
paddr_nz (addr));
|
1999-04-16 03:35:26 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-07-30 03:48:28 +02:00
|
|
|
array_stop (void)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
debuglogs (1, "array_stop()");
|
1999-07-07 22:19:36 +02:00
|
|
|
printf_monitor ("\003");
|
|
|
|
expect_prompt (1);
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* array_command -- put a command string, in args, out to MONITOR.
|
1999-07-07 22:19:36 +02:00
|
|
|
* Output from MONITOR is placed on the users terminal until the
|
|
|
|
* expect_prompt is seen. FIXME
|
1999-04-16 03:35:26 +02:00
|
|
|
*/
|
|
|
|
static void
|
2000-07-30 03:48:28 +02:00
|
|
|
monitor_command (char *args, int fromtty)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
debuglogs (1, "monitor_command (args=%s)", args);
|
|
|
|
|
|
|
|
if (array_desc == NULL)
|
1999-07-07 22:19:36 +02:00
|
|
|
error ("monitor target not open.");
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
if (!args)
|
1999-07-07 22:19:36 +02:00
|
|
|
error ("Missing command.");
|
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
printf_monitor ("%s\n", args);
|
1999-07-07 22:19:36 +02:00
|
|
|
expect_prompt (0);
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* make_gdb_packet -- make a GDB packet. The data is always ASCII.
|
1999-07-07 22:19:36 +02:00
|
|
|
* A debug packet whose contents are <data>
|
|
|
|
* is encapsulated for transmission in the form:
|
1999-04-16 03:35:26 +02:00
|
|
|
*
|
1999-07-07 22:19:36 +02:00
|
|
|
* $ <data> # CSUM1 CSUM2
|
1999-04-16 03:35:26 +02:00
|
|
|
*
|
|
|
|
* <data> must be ASCII alphanumeric and cannot include characters
|
|
|
|
* '$' or '#'. If <data> starts with two characters followed by
|
|
|
|
* ':', then the existing stubs interpret this as a sequence number.
|
|
|
|
*
|
|
|
|
* CSUM1 and CSUM2 are ascii hex representation of an 8-bit
|
|
|
|
* checksum of <data>, the most significant nibble is sent first.
|
|
|
|
* the hex digits 0-9,a-f are used.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void
|
2000-07-30 03:48:28 +02:00
|
|
|
make_gdb_packet (char *buf, char *data)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned char csum = 0;
|
|
|
|
int cnt;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
debuglogs (3, "make_gdb_packet(%s)\n", data);
|
1999-07-07 22:19:36 +02:00
|
|
|
cnt = strlen (data);
|
1999-04-16 03:35:26 +02:00
|
|
|
if (cnt > PBUFSIZ)
|
|
|
|
error ("make_gdb_packet(): to much data\n");
|
|
|
|
|
|
|
|
/* start with the packet header */
|
|
|
|
p = buf;
|
|
|
|
*p++ = '$';
|
|
|
|
|
|
|
|
/* calculate the checksum */
|
1999-07-07 22:19:36 +02:00
|
|
|
for (i = 0; i < cnt; i++)
|
|
|
|
{
|
|
|
|
csum += data[i];
|
|
|
|
*p++ = data[i];
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
/* terminate the data with a '#' */
|
|
|
|
*p++ = '#';
|
1999-07-07 22:19:36 +02:00
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
/* add the checksum as two ascii digits */
|
|
|
|
*p++ = tohex ((csum >> 4) & 0xf);
|
|
|
|
*p++ = tohex (csum & 0xf);
|
1999-07-07 22:19:36 +02:00
|
|
|
*p = 0x0; /* Null terminator on string */
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* array_send_packet -- send a GDB packet to the target with error handling. We
|
1999-07-07 22:19:36 +02:00
|
|
|
* get a '+' (ACK) back if the packet is received and the checksum
|
|
|
|
* matches. Otherwise a '-' (NAK) is returned. It returns a 1 for a
|
|
|
|
* successful transmition, or a 0 for a failure.
|
1999-04-16 03:35:26 +02:00
|
|
|
*/
|
|
|
|
static int
|
2000-07-30 03:48:28 +02:00
|
|
|
array_send_packet (char *packet)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
int c, retries, i;
|
|
|
|
char junk[PBUFSIZ];
|
|
|
|
|
|
|
|
retries = 0;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* scan the packet to make sure it only contains valid characters.
|
|
|
|
this may sound silly, but sometimes a garbled packet will hang
|
|
|
|
the target board. We scan the whole thing, then print the error
|
|
|
|
message.
|
1999-07-07 22:19:36 +02:00
|
|
|
*/
|
|
|
|
for (i = 0; i < strlen (packet); i++)
|
|
|
|
{
|
|
|
|
debuglogs (5, "array_send_packet(): Scanning \'%c\'\n", packet[i]);
|
|
|
|
/* legit hex numbers or command */
|
|
|
|
if ((isxdigit (packet[i])) || (isalpha (packet[i])))
|
|
|
|
continue;
|
|
|
|
switch (packet[i])
|
|
|
|
{
|
|
|
|
case '+': /* ACK */
|
|
|
|
case '-': /* NAK */
|
|
|
|
case '#': /* end of packet */
|
|
|
|
case '$': /* start of packet */
|
|
|
|
continue;
|
|
|
|
default: /* bogus character */
|
|
|
|
retries++;
|
|
|
|
debuglogs (4, "array_send_packet(): Found a non-ascii digit \'%c\' in the packet.\n", packet[i]);
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
1999-07-07 22:19:36 +02:00
|
|
|
#endif
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
if (retries > 0)
|
|
|
|
error ("Can't send packet, found %d non-ascii characters", retries);
|
|
|
|
|
|
|
|
/* ok, try to send the packet */
|
|
|
|
retries = 0;
|
1999-07-07 22:19:36 +02:00
|
|
|
while (retries++ <= 10)
|
|
|
|
{
|
|
|
|
printf_monitor ("%s", packet);
|
|
|
|
|
|
|
|
/* read until either a timeout occurs (-2) or '+' is read */
|
|
|
|
while (retries <= 10)
|
|
|
|
{
|
|
|
|
c = readchar (-timeout);
|
|
|
|
debuglogs (3, "Reading a GDB protocol packet... Got a '%c'\n", c);
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case '+':
|
|
|
|
debuglogs (3, "Got Ack\n");
|
|
|
|
return 1;
|
|
|
|
case SERIAL_TIMEOUT:
|
|
|
|
debuglogs (3, "Timed out reading serial port\n");
|
|
|
|
printf_monitor ("@"); /* resync with the monitor */
|
|
|
|
expect_prompt (1); /* See if we get a expect_prompt */
|
|
|
|
break; /* Retransmit buffer */
|
|
|
|
case '-':
|
|
|
|
debuglogs (3, "Got NAK\n");
|
|
|
|
printf_monitor ("@"); /* resync with the monitor */
|
|
|
|
expect_prompt (1); /* See if we get a expect_prompt */
|
|
|
|
break;
|
|
|
|
case '$':
|
|
|
|
/* it's probably an old response, or the echo of our command.
|
|
|
|
* just gobble up the packet and ignore it.
|
|
|
|
*/
|
|
|
|
debuglogs (3, "Got a junk packet\n");
|
|
|
|
i = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
c = readchar (timeout);
|
|
|
|
junk[i++] = c;
|
|
|
|
}
|
|
|
|
while (c != '#');
|
|
|
|
c = readchar (timeout);
|
|
|
|
junk[i++] = c;
|
|
|
|
c = readchar (timeout);
|
|
|
|
junk[i++] = c;
|
|
|
|
junk[i++] = '\0';
|
|
|
|
debuglogs (3, "Reading a junk packet, got a \"%s\"\n", junk);
|
|
|
|
continue; /* Now, go look for next packet */
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
retries++;
|
|
|
|
debuglogs (3, "Retransmitting packet \"%s\"\n", packet);
|
|
|
|
break; /* Here to retransmit */
|
|
|
|
}
|
|
|
|
} /* outer while */
|
1999-04-16 03:35:26 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* array_get_packet -- get a GDB packet from the target. Basically we read till we
|
1999-07-07 22:19:36 +02:00
|
|
|
* see a '#', then check the checksum. It returns a 1 if it's gotten a
|
|
|
|
* packet, or a 0 it the packet wasn't transmitted correctly.
|
1999-04-16 03:35:26 +02:00
|
|
|
*/
|
|
|
|
static int
|
2000-07-30 03:48:28 +02:00
|
|
|
array_get_packet (char *packet)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
int c;
|
|
|
|
int retries;
|
|
|
|
unsigned char csum;
|
|
|
|
unsigned char pktcsum;
|
|
|
|
char *bp;
|
|
|
|
|
|
|
|
csum = 0;
|
|
|
|
bp = packet;
|
|
|
|
|
|
|
|
memset (packet, 1, PBUFSIZ);
|
|
|
|
retries = 0;
|
1999-07-07 22:19:36 +02:00
|
|
|
while (retries <= 10)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
c = readchar (timeout);
|
|
|
|
if (c == SERIAL_TIMEOUT)
|
|
|
|
{
|
|
|
|
debuglogs (3, "array_get_packet: got time out from serial port.\n");
|
|
|
|
}
|
|
|
|
debuglogs (3, "Waiting for a '$', got a %c\n", c);
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
1999-07-07 22:19:36 +02:00
|
|
|
while (c != '$');
|
|
|
|
|
|
|
|
retries = 0;
|
|
|
|
while (retries <= 10)
|
|
|
|
{
|
|
|
|
c = readchar (timeout);
|
|
|
|
debuglogs (3, "array_get_packet: got a '%c'\n", c);
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case SERIAL_TIMEOUT:
|
|
|
|
debuglogs (3, "Timeout in mid-packet, retrying\n");
|
|
|
|
return 0;
|
|
|
|
case '$':
|
|
|
|
debuglogs (3, "Saw new packet start in middle of old one\n");
|
|
|
|
return 0; /* Start a new packet, count retries */
|
|
|
|
case '#':
|
|
|
|
*bp = '\0';
|
|
|
|
pktcsum = from_hex (readchar (timeout)) << 4;
|
|
|
|
pktcsum |= from_hex (readchar (timeout));
|
|
|
|
if (csum == 0)
|
|
|
|
debuglogs (3, "\nGDB packet checksum zero, must be a bogus packet\n");
|
|
|
|
if (csum == pktcsum)
|
|
|
|
{
|
|
|
|
debuglogs (3, "\nGDB packet checksum correct, packet data is \"%s\",\n", packet);
|
|
|
|
printf_monitor ("@");
|
|
|
|
expect_prompt (1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
debuglogs (3, "Bad checksum, sentsum=0x%x, csum=0x%x\n", pktcsum, csum);
|
|
|
|
return 0;
|
|
|
|
case '*': /* Run length encoding */
|
|
|
|
debuglogs (5, "Run length encoding in packet\n");
|
|
|
|
csum += c;
|
|
|
|
c = readchar (timeout);
|
|
|
|
csum += c;
|
|
|
|
c = c - ' ' + 3; /* Compute repeat count */
|
|
|
|
|
|
|
|
if (c > 0 && c < 255 && bp + c - 1 < packet + PBUFSIZ - 1)
|
|
|
|
{
|
|
|
|
memset (bp, *(bp - 1), c);
|
|
|
|
bp += c;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*bp = '\0';
|
|
|
|
printf_filtered ("Repeat count %d too large for buffer.\n", c);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if ((!isxdigit (c)) && (!ispunct (c)))
|
|
|
|
debuglogs (4, "Got a non-ascii digit \'%c\'.\\n", c);
|
|
|
|
if (bp < packet + PBUFSIZ - 1)
|
|
|
|
{
|
|
|
|
*bp++ = c;
|
|
|
|
csum += c;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
*bp = '\0';
|
|
|
|
puts_filtered ("Remote packet too long.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
}
|
1999-07-07 22:19:36 +02:00
|
|
|
return 0; /* exceeded retries */
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ascii2hexword -- convert an ascii number represented by 8 digits to a hex value.
|
|
|
|
*/
|
|
|
|
static unsigned long
|
2000-07-30 03:48:28 +02:00
|
|
|
ascii2hexword (unsigned char *mem)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
unsigned long val;
|
|
|
|
int i;
|
|
|
|
char buf[9];
|
|
|
|
|
|
|
|
val = 0;
|
1999-07-07 22:19:36 +02:00
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
val <<= 4;
|
|
|
|
if (mem[i] >= 'A' && mem[i] <= 'F')
|
|
|
|
val = val + mem[i] - 'A' + 10;
|
|
|
|
if (mem[i] >= 'a' && mem[i] <= 'f')
|
|
|
|
val = val + mem[i] - 'a' + 10;
|
|
|
|
if (mem[i] >= '0' && mem[i] <= '9')
|
|
|
|
val = val + mem[i] - '0';
|
|
|
|
buf[i] = mem[i];
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
buf[8] = '\0';
|
|
|
|
debuglogs (4, "ascii2hexword() got a 0x%x from %s(%x).\n", val, buf, mem);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ascii2hexword -- convert a hex value to an ascii number represented by 8
|
1999-07-07 22:19:36 +02:00
|
|
|
* digits.
|
1999-04-16 03:35:26 +02:00
|
|
|
*/
|
|
|
|
static void
|
2000-07-30 03:48:28 +02:00
|
|
|
hexword2ascii (unsigned char *mem, unsigned long num)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned char ch;
|
1999-07-07 22:19:36 +02:00
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
debuglogs (4, "hexword2ascii() converting %x ", num);
|
1999-07-07 22:19:36 +02:00
|
|
|
for (i = 7; i >= 0; i--)
|
|
|
|
{
|
|
|
|
mem[i] = tohex ((num >> 4) & 0xf);
|
|
|
|
mem[i] = tohex (num & 0xf);
|
|
|
|
num = num >> 4;
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
mem[8] = '\0';
|
|
|
|
debuglogs (4, "\tto a %s", mem);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert hex digit A to a number. */
|
|
|
|
static int
|
2000-07-30 03:48:28 +02:00
|
|
|
from_hex (int a)
|
1999-07-07 22:19:36 +02:00
|
|
|
{
|
1999-04-16 03:35:26 +02:00
|
|
|
if (a == 0)
|
|
|
|
return 0;
|
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
debuglogs (4, "from_hex got a 0x%x(%c)\n", a, a);
|
1999-04-16 03:35:26 +02:00
|
|
|
if (a >= '0' && a <= '9')
|
|
|
|
return a - '0';
|
|
|
|
if (a >= 'a' && a <= 'f')
|
|
|
|
return a - 'a' + 10;
|
|
|
|
if (a >= 'A' && a <= 'F')
|
|
|
|
return a - 'A' + 10;
|
1999-07-07 22:19:36 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
error ("Reply contains invalid hex digit 0x%x", a);
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert number NIB to a hex digit. */
|
|
|
|
static int
|
2000-07-30 03:48:28 +02:00
|
|
|
tohex (int nib)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
if (nib < 10)
|
1999-07-07 22:19:36 +02:00
|
|
|
return '0' + nib;
|
1999-04-16 03:35:26 +02:00
|
|
|
else
|
1999-07-07 22:19:36 +02:00
|
|
|
return 'a' + nib - 10;
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _initialize_remote_monitors -- setup a few addtitional commands that
|
1999-07-07 22:19:36 +02:00
|
|
|
* are usually only used by monitors.
|
1999-04-16 03:35:26 +02:00
|
|
|
*/
|
|
|
|
void
|
2000-07-30 03:48:28 +02:00
|
|
|
_initialize_remote_monitors (void)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
/* generic monitor command */
|
|
|
|
add_com ("monitor", class_obscure, monitor_command,
|
1999-07-07 22:19:36 +02:00
|
|
|
"Send a command to the debug monitor.");
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _initialize_array -- do any special init stuff for the target.
|
|
|
|
*/
|
|
|
|
void
|
2000-07-30 03:48:28 +02:00
|
|
|
_initialize_array (void)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
1999-07-07 22:19:36 +02:00
|
|
|
init_array_ops ();
|
1999-04-16 03:35:26 +02:00
|
|
|
add_target (&array_ops);
|
|
|
|
}
|