/* Remote debugging interface for MIPS remote debugging protocol.
- Copyright 1993-1995, 2000 Free Software Foundation, Inc.
+ Copyright 1993, 1994, 1995, 2000 Free Software Foundation, Inc.
Contributed by Cygnus Support. Written by Ian Lance Taylor
<ian@cygnus.com>.
#include <sys/types.h>
#include <sys/stat.h>
+#include <ctype.h>
+
/* Microsoft C's stat.h doesn't define all the POSIX file modes. */
#ifndef S_IROTH
#define S_IROTH S_IREAD
/* Prototypes for local functions. */
-static int mips_readchar PARAMS ((int timeout));
+static int mips_readchar (int timeout);
-static int mips_receive_header PARAMS ((unsigned char *hdr, int *pgarbage,
- int ch, int timeout));
+static int mips_receive_header (unsigned char *hdr, int *pgarbage,
+ int ch, int timeout);
-static int mips_receive_trailer PARAMS ((unsigned char *trlr, int *pgarbage,
- int *pch, int timeout));
+static int mips_receive_trailer (unsigned char *trlr, int *pgarbage,
+ int *pch, int timeout);
-static int mips_cksum PARAMS ((const unsigned char *hdr,
- const unsigned char *data,
- int len));
+static int mips_cksum (const unsigned char *hdr,
+ const unsigned char *data, int len);
-static void mips_send_packet PARAMS ((const char *s, int get_ack));
+static void mips_send_packet (const char *s, int get_ack);
-static void mips_send_command PARAMS ((const char *cmd, int prompt));
+static void mips_send_command (const char *cmd, int prompt);
-static int mips_receive_packet PARAMS ((char *buff, int throw_error,
- int timeout));
+static int mips_receive_packet (char *buff, int throw_error, int timeout);
-static CORE_ADDR mips_request PARAMS ((int cmd, CORE_ADDR addr,
- CORE_ADDR data, int *perr, int timeout,
- char *buff));
+static ULONGEST mips_request (int cmd, ULONGEST addr, ULONGEST data,
+ int *perr, int timeout, char *buff);
-static void mips_initialize PARAMS ((void));
+static void mips_initialize (void);
-static void mips_open PARAMS ((char *name, int from_tty));
+static void mips_open (char *name, int from_tty);
-static void pmon_open PARAMS ((char *name, int from_tty));
+static void pmon_open (char *name, int from_tty);
-static void ddb_open PARAMS ((char *name, int from_tty));
+static void ddb_open (char *name, int from_tty);
-static void lsi_open PARAMS ((char *name, int from_tty));
+static void lsi_open (char *name, int from_tty);
-static void mips_close PARAMS ((int quitting));
+static void mips_close (int quitting);
-static void mips_detach PARAMS ((char *args, int from_tty));
+static void mips_detach (char *args, int from_tty);
-static void mips_resume PARAMS ((int pid, int step,
- enum target_signal siggnal));
+static void mips_resume (int pid, int step, enum target_signal siggnal);
-static int mips_wait PARAMS ((int pid, struct target_waitstatus * status));
+static int mips_wait (int pid, struct target_waitstatus *status);
-static int mips_map_regno PARAMS ((int regno));
+static int mips_map_regno (int regno);
-static void mips_fetch_registers PARAMS ((int regno));
+static void mips_fetch_registers (int regno);
-static void mips_prepare_to_store PARAMS ((void));
+static void mips_prepare_to_store (void);
-static void mips_store_registers PARAMS ((int regno));
+static void mips_store_registers (int regno);
-static unsigned int mips_fetch_word PARAMS ((CORE_ADDR addr));
+static unsigned int mips_fetch_word (CORE_ADDR addr);
-static int mips_store_word PARAMS ((CORE_ADDR addr, unsigned int value,
- char *old_contents));
+static int mips_store_word (CORE_ADDR addr, unsigned int value,
+ char *old_contents);
-static int mips_xfer_memory PARAMS ((CORE_ADDR memaddr, char *myaddr, int len,
- int write, struct target_ops * ignore));
+static int mips_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
+ int write, struct target_ops *ignore);
-static void mips_files_info PARAMS ((struct target_ops * ignore));
+static void mips_files_info (struct target_ops *ignore);
-static void mips_create_inferior PARAMS ((char *execfile, char *args,
- char **env));
+static void mips_create_inferior (char *execfile, char *args, char **env);
-static void mips_mourn_inferior PARAMS ((void));
+static void mips_mourn_inferior (void);
-static int pmon_makeb64 PARAMS ((unsigned long v, char *p, int n, int *chksum));
+static int pmon_makeb64 (unsigned long v, char *p, int n, int *chksum);
-static int pmon_zeroset PARAMS ((int recsize, char **buff, int *amount,
- unsigned int *chksum));
+static int pmon_zeroset (int recsize, char **buff, int *amount,
+ unsigned int *chksum);
-static int pmon_checkset PARAMS ((int recsize, char **buff, int *value));
+static int pmon_checkset (int recsize, char **buff, int *value);
-static void pmon_make_fastrec PARAMS ((char **outbuf, unsigned char *inbuf,
- int *inptr, int inamount, int *recsize,
- unsigned int *csum, unsigned int *zerofill));
+static void pmon_make_fastrec (char **outbuf, unsigned char *inbuf,
+ int *inptr, int inamount, int *recsize,
+ unsigned int *csum, unsigned int *zerofill);
-static int pmon_check_ack PARAMS ((char *mesg));
+static int pmon_check_ack (char *mesg);
-static void pmon_start_download PARAMS ((void));
+static void pmon_start_download (void);
-static void pmon_end_download PARAMS ((int final, int bintotal));
+static void pmon_end_download (int final, int bintotal);
-static void pmon_download PARAMS ((char *buffer, int length));
+static void pmon_download (char *buffer, int length);
-static void pmon_load_fast PARAMS ((char *file));
+static void pmon_load_fast (char *file);
-static void mips_load PARAMS ((char *file, int from_tty));
+static void mips_load (char *file, int from_tty);
-static int mips_make_srec PARAMS ((char *buffer, int type, CORE_ADDR memaddr,
- unsigned char *myaddr, int len));
+static int mips_make_srec (char *buffer, int type, CORE_ADDR memaddr,
+ unsigned char *myaddr, int len);
-static int set_breakpoint PARAMS ((CORE_ADDR addr, int len,
- enum break_type type));
+static int set_breakpoint (CORE_ADDR addr, int len, enum break_type type);
-static int clear_breakpoint PARAMS ((CORE_ADDR addr, int len,
- enum break_type type));
+static int clear_breakpoint (CORE_ADDR addr, int len, enum break_type type);
-static int common_breakpoint PARAMS ((int set, CORE_ADDR addr, int len,
- enum break_type type));
+static int common_breakpoint (int set, CORE_ADDR addr, int len,
+ enum break_type type);
/* Forward declarations. */
extern struct target_ops mips_ops;
/* The number of garbage characters to accept when looking for an
SYN for the next packet. */
-static int mips_syn_garbage = 1050;
+static int mips_syn_garbage = 10;
/* The time to wait for a packet, in seconds. */
static int mips_receive_wait = 5;
{
/* Printing the character here lets the user of gdb see
what the program is outputting, if the debugging is
- being done on the console port. Don't use _filtered;
- we can't deal with a QUIT out of target_wait. */
- if (!mips_initializing || remote_debug > 0)
- {
- fputc_readable (ch, gdb_stdlog);
- gdb_flush (gdb_stdlog);
- }
+ being done on the console port. Don't use _filtered:
+ we can't deal with a QUIT out of target_wait and
+ buffered target output confuses the user. */
+ if (!mips_initializing || remote_debug > 0)
+ {
+ if (isprint (ch) || isspace (ch))
+ {
+ fputc_unfiltered (ch, gdb_stdtarg);
+ }
+ else
+ {
+ fputc_readable (ch, gdb_stdtarg);
+ }
+ gdb_flush (gdb_stdtarg);
+ }
+
+ /* Only count unprintable characters. */
+ if (! (isprint (ch) || isspace (ch)))
+ (*pgarbage) += 1;
- ++*pgarbage;
if (mips_syn_garbage > 0
&& *pgarbage > mips_syn_garbage)
mips_error ("Debug protocol failure: more than %d characters before a sync.",
occurs, it sets *PERR to 1 and sets errno according to what the
target board reports. */
-static CORE_ADDR
-mips_request (cmd, addr, data, perr, timeout, buff)
- int cmd;
- CORE_ADDR addr;
- CORE_ADDR data;
- int *perr;
- int timeout;
- char *buff;
+static ULONGEST
+mips_request (int cmd,
+ ULONGEST addr,
+ ULONGEST data,
+ int *perr,
+ int timeout,
+ char *buff)
{
char myBuff[DATA_MAXLEN + 1];
int len;
{
/* The DDB (NEC) and MiniRISC (LSI) versions of PMON exit immediately,
so we do not get a reply to this command: */
- mips_request ('x', (unsigned int) 0, (unsigned int) 0, NULL,
- mips_receive_wait, NULL);
+ mips_request ('x', 0, 0, NULL, mips_receive_wait, NULL);
mips_need_reply = 0;
if (!mips_expect (" break!"))
return -1;
}
else
- mips_request ('x', (unsigned int) 0, (unsigned int) 0, &err,
- mips_receive_wait, NULL);
+ mips_request ('x', 0, 0, &err, mips_receive_wait, NULL);
if (!mips_expect (mips_monitor_prompt))
return -1;
/* If this doesn't call error, we have connected; we don't care if
the request itself succeeds or fails. */
- mips_request ('r', (unsigned int) 0, (unsigned int) 0, &err,
- mips_receive_wait, NULL);
+ mips_request ('r', 0, 0, &err, mips_receive_wait, NULL);
set_current_frame (create_new_frame (read_fp (), read_pc ()));
select_frame (get_current_frame (), 0);
}
char *name;
int from_tty;
{
- common_open (&mips_ops, name, from_tty, MON_IDT, TARGET_MONITOR_PROMPT);
+ const char *monitor_prompt = NULL;
+ if (TARGET_ARCHITECTURE != NULL
+ && TARGET_ARCHITECTURE->arch == bfd_arch_mips)
+ {
+ switch (TARGET_ARCHITECTURE->mach)
+ {
+ case bfd_mach_mips4100:
+ case bfd_mach_mips4300:
+ case bfd_mach_mips4600:
+ case bfd_mach_mips4650:
+ case bfd_mach_mips5000:
+ monitor_prompt = "<RISQ> ";
+ break;
+ }
+ }
+ if (monitor_prompt == NULL)
+ monitor_prompt = "<IDT>";
+ common_open (&mips_ops, name, from_tty, MON_IDT, monitor_prompt);
}
static void
/* LSI PMON requires returns a reply packet "0x1 s 0x0 0x57f" after
a single step, so we wait for that. */
- mips_request (step ? 's' : 'c',
- (unsigned int) 1,
- (unsigned int) siggnal,
+ mips_request (step ? 's' : 'c', 1, siggnal,
mips_monitor == MON_LSI && step ? &err : (int *) NULL,
mips_receive_wait, NULL);
}
/* No timeout; we sit here as long as the program continues to execute. */
mips_wait_flag = 1;
- rstatus = mips_request ('\000', (unsigned int) 0, (unsigned int) 0, &err, -1,
- buff);
+ rstatus = mips_request ('\000', 0, 0, &err, -1, buff);
mips_wait_flag = 0;
if (err)
mips_error ("Remote failure: %s", safe_strerror (errno));
compiled without the 64bit register access commands. This
means we cannot get hold of the full register width. */
if (mips_monitor == MON_DDB)
- val = (unsigned) mips_request ('t', (unsigned int) pmon_reg,
- (unsigned int) 0, &err, mips_receive_wait, NULL);
+ val = (unsigned) mips_request ('t', pmon_reg, 0,
+ &err, mips_receive_wait, NULL);
else
- val = mips_request ('r', (unsigned int) pmon_reg,
- (unsigned int) 0, &err, mips_receive_wait, NULL);
+ val = mips_request ('r', pmon_reg, 0,
+ &err, mips_receive_wait, NULL);
if (err)
mips_error ("Can't read register %d: %s", regno,
safe_strerror (errno));
return;
}
- mips_request ('R', (unsigned int) mips_map_regno (regno),
+ mips_request ('R', mips_map_regno (regno),
read_register (regno),
&err, mips_receive_wait, NULL);
if (err)
unsigned int val;
int err;
- /* FIXME! addr was cast to uint! */
- val = mips_request ('d', addr, (unsigned int) 0, &err,
- mips_receive_wait, NULL);
+ val = mips_request ('d', addr, 0, &err, mips_receive_wait, NULL);
if (err)
{
/* Data space failed; try instruction space. */
- /* FIXME! addr was cast to uint! */
- val = mips_request ('i', addr, (unsigned int) 0, &err,
+ val = mips_request ('i', addr, 0, &err,
mips_receive_wait, NULL);
if (err)
mips_error ("Can't read address 0x%s: %s",
int err;
unsigned int oldcontents;
- oldcontents = mips_request ('D', addr, (unsigned int) val,
- &err,
+ oldcontents = mips_request ('D', addr, val, &err,
mips_receive_wait, NULL);
if (err)
{
/* Data space failed; try instruction space. */
- oldcontents = mips_request ('I', addr,
- (unsigned int) val, &err,
+ oldcontents = mips_request ('I', addr, val, &err,
mips_receive_wait, NULL);
if (err)
return errno;
for a longword, since it transfers values in ASCII. We want the
byte values, so we have to swap the longword values. */
+static int mask_address_p = 1;
+
static int
mips_xfer_memory (memaddr, myaddr, len, write, ignore)
CORE_ADDR memaddr;
int write;
struct target_ops *ignore;
{
- register int i;
+ int i;
+ CORE_ADDR addr;
+ int count;
+ char *buffer;
+ int status;
+
+ /* PMON targets do not cope well with 64 bit addresses. Mask the
+ value down to 32 bits. */
+ if (mask_address_p)
+ memaddr &= (CORE_ADDR) 0xffffffff;
+
/* Round starting address down to longword boundary. */
- register CORE_ADDR addr = memaddr & ~3;
+ addr = memaddr & ~3;
/* Round ending address up; get number of longwords that makes. */
- register int count = (((memaddr + len) - addr) + 3) / 4;
+ count = (((memaddr + len) - addr) + 3) / 4;
/* Allocate buffer of that many longwords. */
- register char *buffer = alloca (count * 4);
-
- int status;
+ buffer = alloca (count * 4);
if (write)
{
add_com ("pmon <command>", class_obscure, pmon_command,
"Send a packet to PMON (must be in debug mode).");
+
+ add_show_from_set (add_set_cmd ("mask-address", no_class,
+ var_boolean, &mask_address_p,
+ "Set zeroing of upper 32 bits of 64-bit addresses when talking to PMON targets.\n\
+Use \"on\" to enable the masking and \"off\" to disable it.\n",
+ &setlist),
+ &showlist);
}