home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 7
/
FreshFishVol7.bin
/
bbs
/
gnu
/
gdb-4.12-src.lha
/
GNU
/
src
/
amiga
/
gdb-4.12
/
gdb
/
remote-bug.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-03
|
25KB
|
1,054 lines
/* Remote debugging interface for Motorola's MVME187BUG monitor, an embedded
monitor for the m88k.
Copyright 1992, 1993 Free Software Foundation, Inc.
Contributed by Cygnus Support. Written by K. Richard Pixley.
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "defs.h"
#include "inferior.h"
#include "wait.h"
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#include <signal.h>
#include <setjmp.h>
#include <errno.h>
#include "terminal.h"
#include "gdbcore.h"
#include "gdbcmd.h"
#include "remote-utils.h"
extern int sleep();
/* External data declarations */
extern int stop_soon_quietly; /* for wait_for_inferior */
/* Forward data declarations */
extern struct target_ops bug_ops; /* Forward declaration */
/* Forward function declarations */
static int bug_clear_breakpoints PARAMS((void));
static int bug_read_memory PARAMS((CORE_ADDR memaddr,
unsigned char *myaddr,
int len));
static int bug_write_memory PARAMS((CORE_ADDR memaddr,
unsigned char *myaddr,
int len));
/* This variable is somewhat arbitrary. It's here so that it can be
set from within a running gdb. */
static int srec_max_retries = 3;
/* Each S-record download to the target consists of an S0 header
record, some number of S3 data records, and one S7 termination
record. I call this download a "frame". Srec_frame says how many
bytes will be represented in each frame. */
#define SREC_SIZE 160
static int srec_frame = SREC_SIZE;
/* This variable determines how many bytes will be represented in each
S3 s-record. */
static int srec_bytes = 40;
/* At one point it appeared to me as though the bug monitor could not
really be expected to receive two sequential characters at 9600
baud reliably. Echo-pacing is an attempt to force data across the
line even in this condition. Specifically, in echo-pace mode, each
character is sent one at a time and we look for the echo before
sending the next. This is excruciatingly slow. */
static int srec_echo_pace = 0;
/* How long to wait after an srec for a possible error message.
Similar to the above, I tried sleeping after sending each S3 record
in hopes that I might actually see error messages from the bug
monitor. This might actually work if we were to use sleep
intervals smaller than 1 second. */
static int srec_sleep = 0;
/* Every srec_noise records, flub the checksum. This is a debugging
feature. Set the variable to something other than 1 in order to
inject *deliberate* checksum errors. One might do this if one
wanted to test error handling and recovery. */
static int srec_noise = 0;
/* Called when SIGALRM signal sent due to alarm() timeout. */
/* Number of SIGTRAPs we need to simulate. That is, the next
NEED_ARTIFICIAL_TRAP calls to bug_wait should just return
SIGTRAP without actually waiting for anything. */
static int need_artificial_trap = 0;
/*
* Download a file specified in 'args', to the bug.
*/
static void
bug_load (args, fromtty)
char *args;
int fromtty;
{
bfd *abfd;
asection *s;
char buffer[1024];
sr_check_open ();
dcache_flush (gr_get_dcache());
inferior_pid = 0;
abfd = bfd_openr (args, 0);
if (!abfd)
{
printf_filtered ("Unable to open file %s\n", args);
return;
}
if (bfd_check_format (abfd, bfd_object) == 0)
{
printf_filtered ("File is not an object file\n");
return;
}
s = abfd->sections;
while (s != (asection *) NULL)
{
srec_frame = SREC_SIZE;
if (s->flags & SEC_LOAD)
{
int i;
char *buffer = xmalloc (srec_frame);
printf_filtered ("%s\t: 0x%4x .. 0x%4x ", s->name, s->vma, s->vma + s->_raw_size);
fflush (stdout);
for (i = 0; i < s->_raw_size; i += srec_frame)
{
if (srec_frame > s->_raw_size - i)
srec_frame = s->_raw_size - i;
bfd_get_section_contents (abfd, s, buffer, i, srec_frame);
bug_write_memory (s->vma + i, buffer, srec_frame);
printf_filtered ("*");
fflush (stdout);
}
printf_filtered ("\n");
free (buffer);
}
s = s->next;
}
sprintf (buffer, "rs ip %lx", (unsigned long) abfd->start_address);
sr_write_cr (buffer);
gr_expect_prompt ();
}
#if 0
static char *
get_word (p)
char **p;
{
char *s = *p;
char *word;
char *copy;
size_t len;
while (isspace (*s))
s++;
word = s;
len = 0;
while (*s && !isspace (*s))
{
s++;
len++;
}
copy = xmalloc (len + 1);
memcpy (copy, word, len);
copy[len] = 0;
*p = s;
return copy;
}
#endif
static struct gr_settings bug_settings = {
NULL, /* dcache */
"Bug>", /* prompt */
&bug_ops, /* ops */
bug_clear_breakpoints, /* clear_all_breakpoints */
bug_read_memory, /* readfunc */
bug_write_memory, /* writefunc */
gr_generic_checkin, /* checkin */
};
static char *cpu_check_strings[] = {
"=",
"Invalid Register",
};
static void
bug_open (args, from_tty)
char *args;
int from_tty;
{
if (args == NULL)
args = "";
gr_open(args, from_tty, &bug_settings);
/* decide *now* whether we are on an 88100 or an 88110 */
sr_write_cr("rs cr06");
sr_expect("rs cr06");
switch (gr_multi_scan(cpu_check_strings, 0))
{
case 0: /* this is an m88100 */
target_is_m88110 = 0;
break;
case 1: /* this is an m88110 */
target_is_m88110 = 1;
break;
default:
abort();
}
}
/* Tell the remote machine to resume. */
void
bug_resume (pid, step, sig)
int pid, step;
enum target_signal sig;
{
dcache_flush (gr_get_dcache());
if (step)
{
sr_write_cr("t");
/* Force the next bug_wait to return a trap. Not doing anything
about I/O from the target means that the user has to type
"continue" to see any. FIXME, this should be fixed. */
need_artificial_trap = 1;
}
else
sr_write_cr ("g");
return;
}
/* Wait until the remote machine stops, then return,
storing status in STATUS just as `wait' would. */
static char *wait_strings[] = {
"At Breakpoint",
"Exception: Data Access Fault (Local Bus Timeout)",
"\r8???-Bug>",
"\r197-Bug>",
NULL,
};
int
bug_wait (pid, status)
int pid;
struct target_waitstatus *status;
{
int old_timeout = sr_get_timeout();
int old_immediate_quit = immediate_quit;
status->kind = TARGET_WAITKIND_EXITED;
status->value.integer = 0;
/* read off leftovers from resume so that the rest can be passed
back out as stdout. */
if (need_artificial_trap == 0)
{
sr_expect("Effective address: ");
(void) sr_get_hex_word();
sr_expect ("\r\n");
}
sr_set_timeout(-1); /* Don't time out -- user program is running. */
immediate_quit = 1; /* Helps ability to QUIT */
switch (gr_multi_scan(wait_strings, need_artificial_trap == 0))
{
case 0: /* breakpoint case */
status->kind = TARGET_WAITKIND_STOPPED;
status->value.sig = TARGET_SIGNAL_TRAP;
/* user output from the target can be discarded here. (?) */
gr_expect_prompt();
break;
case 1: /* bus error */
status->kind = TARGET_WAITKIND_STOPPED;
status->value.sig = TARGET_SIGNAL_BUS;
/* user output from the target can be discarded here. (?) */
gr_expect_prompt();
break;
case 2: /* normal case */
case 3:
if (need_artificial_trap != 0)
{
/* stepping */
status->kind = TARGET_WAITKIND_STOPPED;
status->value.sig = TARGET_SIGNAL_TRAP;
need_artificial_trap--;
b