* remote-sim.c: first attempt at general simulator interface

* remote-hms.c: whitespace
	* h8300-tdep.c: (h8300_skip_prologue, examine_prologue):
	understand new stack layout. (print_register_hook): print ccr
	register in a fancy way.
This commit is contained in:
Steve Chamberlain
1993-01-03 22:36:04 +00:00
parent fb6e675f95
commit ec25d19bd6
6 changed files with 1167 additions and 811 deletions

View File

@ -210,6 +210,7 @@ remote-es1800.c
remote-hms.c remote-hms.c
remote-mm.c remote-mm.c
remote-nindy.c remote-nindy.c
remote-sim.c
remote-st2000.c remote-st2000.c
remote-vx.c remote-vx.c
remote.c remote.c

View File

@ -1,3 +1,11 @@
Sun Jan 3 14:24:56 1993 Steve Chamberlain (sac@thepub.cygnus.com)
* remote-sim.c: first attempt at general simulator interface
* remote-hms.c: whitespace
* h8300-tdep.c: (h8300_skip_prologue, examine_prologue):
understand new stack layout. (print_register_hook): print ccr
register in a fancy way.
Sun Jan 3 14:16:10 1993 Fred Fish (fnf@cygnus.com) Sun Jan 3 14:16:10 1993 Fred Fish (fnf@cygnus.com)
* eval.c (language.h): Include. * eval.c (language.h): Include.

View File

@ -29,40 +29,60 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#define UNSIGNED_SHORT(X) ((X) & 0xffff) #define UNSIGNED_SHORT(X) ((X) & 0xffff)
/* an easy to debug H8 stack frame looks like: /* an easy to debug H8 stack frame looks like:
0x6df2 push r2
0x6df3 push r3
0x6df6 push r6 0x6df6 push r6
0x mov.w r7,r6 0x0d76 mov.w r7,r6
subs stuff,sp mov.w #x,r5 0x6dfn push reg
subs r5,sp 0x7905 nnnn mov.w #n,r5 or 0x1b87 subs #2,sp
0x1957 sub.w r5,sp
*/ */
#define IS_PUSH(x) ((x & 0xff00)==0x6d00) #define IS_PUSH(x) ((x & 0xff00)==0x6d00)
#define IS_PUSH_FP(x) (x == 0x6df6)
#define IS_MOVE_FP(x) (x == 0x0d76) #define IS_MOVE_FP(x) (x == 0x0d76)
#define IS_MOV_SP_FP(x) (x == 0x0d76) #define IS_MOV_SP_FP(x) (x == 0x0d76)
#define IS_SUB2_SP(x) (x==0x1b87) #define IS_SUB2_SP(x) (x==0x1b87)
#define IS_MOVK_R5(x) (x==0x7905) #define IS_MOVK_R5(x) (x==0x7905)
#define IS_SUB_R5SP(x) (x==0x1957)
CORE_ADDR examine_prologue (); CORE_ADDR examine_prologue ();
void frame_find_saved_regs (); void frame_find_saved_regs ();
CORE_ADDR h8300_skip_prologue(start_pc) CORE_ADDR
h8300_skip_prologue (start_pc)
CORE_ADDR start_pc; CORE_ADDR start_pc;
{ {
/* Skip past all push insns */
short int w; short int w;
w = read_memory_short (start_pc); w = read_memory_short (start_pc);
while (IS_PUSH(w)) /* Skip past all push insns */
while (IS_PUSH_FP (w))
{ {
start_pc += 2; start_pc += 2;
w = read_memory_short (start_pc); w = read_memory_short (start_pc);
} }
/* Skip past a move to FP */ /* Skip past a move to FP */
if (IS_MOVE_FP(w)) { if (IS_MOVE_FP (w))
{
start_pc += 2;
w = read_memory_short (start_pc);
}
/* Skip the stack adjust */
if (IS_MOVK_R5 (w))
{
start_pc += 2;
w = read_memory_short (start_pc);
}
if (IS_SUB_R5SP (w))
{
start_pc += 2;
w = read_memory_short (start_pc);
}
while (IS_SUB2_SP (w))
{
start_pc += 2; start_pc += 2;
w = read_memory_short (start_pc); w = read_memory_short (start_pc);
} }
@ -71,7 +91,6 @@ CORE_ADDR start_pc;
} }
int int
print_insn (memaddr, stream) print_insn (memaddr, stream)
CORE_ADDR memaddr; CORE_ADDR memaddr;
@ -79,11 +98,11 @@ FILE *stream;
{ {
/* Nothing is bigger than 8 bytes */ /* Nothing is bigger than 8 bytes */
char data[8]; char data[8];
read_memory (memaddr, data, sizeof (data)); read_memory (memaddr, data, sizeof (data));
return print_insn_h8300 (memaddr, data, stream); return print_insn_h8300 (memaddr, data, stream);
} }
/* Given a GDB frame, determine the address of the calling function's frame. /* Given a GDB frame, determine the address of the calling function's frame.
This will be used to create a new GDB frame struct, and then This will be used to create a new GDB frame struct, and then
INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame. INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame.
@ -100,8 +119,6 @@ FRAME_CHAIN (thisframe)
return thisframe->fsr->regs[SP_REGNUM]; return thisframe->fsr->regs[SP_REGNUM];
} }
/* Put here the code to store, into a struct frame_saved_regs, /* Put here the code to store, into a struct frame_saved_regs,
the addresses of the saved registers of frame described by FRAME_INFO. the addresses of the saved registers of frame described by FRAME_INFO.
This includes special registers such as pc and fp saved in special This includes special registers such as pc and fp saved in special
@ -131,6 +148,7 @@ frame_find_saved_regs (fi, fsr)
obstack_alloc (&frame_cache_obstack, obstack_alloc (&frame_cache_obstack,
sizeof (struct frame_saved_regs)); sizeof (struct frame_saved_regs));
bzero (cache_fsr, sizeof (struct frame_saved_regs)); bzero (cache_fsr, sizeof (struct frame_saved_regs));
fi->fsr = cache_fsr; fi->fsr = cache_fsr;
/* Find the start and end of the function prologue. If the PC /* Find the start and end of the function prologue. If the PC
@ -149,13 +167,11 @@ frame_find_saved_regs (fi, fsr)
*fsr = *fi->fsr; *fsr = *fi->fsr;
} }
/* Fetch the instruction at ADDR, returning 0 if ADDR is beyond LIM or /* Fetch the instruction at ADDR, returning 0 if ADDR is beyond LIM or
is not the address of a valid instruction, the address of the next is not the address of a valid instruction, the address of the next
instruction beyond ADDR otherwise. *PWORD1 receives the first word instruction beyond ADDR otherwise. *PWORD1 receives the first word
of the instruction.*/ of the instruction.*/
CORE_ADDR CORE_ADDR
NEXT_PROLOGUE_INSN (addr, lim, pword1) NEXT_PROLOGUE_INSN (addr, lim, pword1)
CORE_ADDR addr; CORE_ADDR addr;
@ -166,11 +182,10 @@ short *pword1;
{ {
read_memory (addr, pword1, sizeof (*pword1)); read_memory (addr, pword1, sizeof (*pword1));
SWAP_TARGET_AND_HOST (pword1, sizeof (short)); SWAP_TARGET_AND_HOST (pword1, sizeof (short));
return addr + 2; return addr + 2;
} }
return 0; return 0;
} }
/* Examine the prologue of a function. `ip' points to the first instruction. /* Examine the prologue of a function. `ip' points to the first instruction.
@ -182,21 +197,6 @@ short *pword1;
`fi' is a struct frame_info pointer; we fill in various fields in it `fi' is a struct frame_info pointer; we fill in various fields in it
to reflect the offsets of the arg pointer and the locals pointer. */ to reflect the offsets of the arg pointer and the locals pointer. */
/* We will find two sorts of prologue, framefull and non framefull:
push r2
push r3
push fp
mov sp,fp
stack_ad
and
push x
push y
stack_ad
*/
static CORE_ADDR static CORE_ADDR
examine_prologue (ip, limit, after_prolog_fp, fsr, fi) examine_prologue (ip, limit, after_prolog_fp, fsr, fi)
register CORE_ADDR ip; register CORE_ADDR ip;
@ -223,41 +223,41 @@ examine_prologue (ip, limit, after_prolog_fp, fsr, fi)
char in_frame[NUM_REGS]; /* One for each reg */ char in_frame[NUM_REGS]; /* One for each reg */
memset (in_frame, 1, NUM_REGS); memset (in_frame, 1, NUM_REGS);
for (r = 0; r < NUM_REGS; r++)
if (after_prolog_fp == 0) { {
fsr->regs[r] = 0;
}
if (after_prolog_fp == 0)
{
after_prolog_fp = read_register (SP_REGNUM); after_prolog_fp = read_register (SP_REGNUM);
} }
if (ip == 0 || ip & ~0xffff) return 0; if (ip == 0 || ip & ~0xffff)
return 0;
next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn_word); next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn_word);
/* Skip over any push instructions, and remember where they were saved */ /* Skip over any fp push instructions */
fsr->regs[6] = after_prolog_fp;
while (next_ip && IS_PUSH_FP (insn_word))
while (next_ip && IS_PUSH(insn_word))
{ {
ip = next_ip; ip = next_ip;
in_frame[insn_word & 0x7] = reg_save_depth; in_frame[insn_word & 0x7] = reg_save_depth;
next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn_word); next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn_word);
reg_save_depth += 2; reg_save_depth += 2;
} }
/* Is this a move into the fp */ /* Is this a move into the fp */
if (next_ip && IS_MOV_SP_FP (insn_word)) if (next_ip && IS_MOV_SP_FP (insn_word))
{ {
ip = next_ip; ip = next_ip;
next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn_word); next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn_word);
have_fp = 1; have_fp = 1;
} }
/* Skip over any stack adjustment, happens either with a number of /* Skip over any stack adjustment, happens either with a number of
sub#2,sp or a mov #x,r5 sub r5,sp */ sub#2,sp or a mov #x,r5 sub r5,sp */
if (next_ip && IS_SUB2_SP (insn_word)) if (next_ip && IS_SUB2_SP (insn_word))
{ {
while (next_ip && IS_SUB2_SP (insn_word)) while (next_ip && IS_SUB2_SP (insn_word))
@ -274,41 +274,36 @@ examine_prologue (ip, limit, after_prolog_fp, fsr, fi)
ip = next_ip; ip = next_ip;
next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn_word); next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn_word);
auto_depth += insn_word; auto_depth += insn_word;
ip +=4;
next_ip = NEXT_PROLOGUE_INSN (next_ip, limit, &insn_word);
auto_depth += insn_word;
} }
} }
/* Work out which regs are stored where */
while (next_ip && IS_PUSH (insn_word))
{
ip = next_ip;
next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn_word);
fsr->regs[r] = after_prolog_fp + auto_depth;
auto_depth += 2;
}
/* The args are always reffed based from the stack pointer */ /* The args are always reffed based from the stack pointer */
fi->args_pointer = after_prolog_fp - auto_depth; fi->args_pointer = after_prolog_fp;
/* Locals are always reffed based from the fp */ /* Locals are always reffed based from the fp */
fi->locals_pointer = after_prolog_fp; fi->locals_pointer = after_prolog_fp;
/* The PC is at a known place */ /* The PC is at a known place */
fi->from_pc = read_memory_short(after_prolog_fp + reg_save_depth-2 ); fi->from_pc = read_memory_short (after_prolog_fp + 2);
/* Rememeber any others too */ /* Rememeber any others too */
in_frame[PC_REGNUM] = 0; in_frame[PC_REGNUM] = 0;
for (r = 0; r < NUM_REGS; r++)
{
if (in_frame[r] != 1)
{
fsr->regs[r] = after_prolog_fp + reg_save_depth - in_frame[r] -2;
}
else
{
fsr->regs[r] = 0;
}
}
if (have_fp) if (have_fp)
/* We keep the old FP in the SP spot */ /* We keep the old FP in the SP spot */
fsr->regs[SP_REGNUM] = (read_memory_short (fsr->regs[6])); fsr->regs[SP_REGNUM] = (read_memory_short (fsr->regs[6]));
else else
fsr->regs[SP_REGNUM] = after_prolog_fp + reg_save_depth; fsr->regs[SP_REGNUM] = after_prolog_fp + auto_depth;
return (ip); return (ip);
} }
@ -324,6 +319,7 @@ init_extra_frame_info (fromleaf, fi)
fi->from_pc = 0; fi->from_pc = 0;
} }
/* Return the saved PC from this frame. /* Return the saved PC from this frame.
If the frame has a memory copy of SRP_REGNUM, use that. If not, If the frame has a memory copy of SRP_REGNUM, use that. If not,
@ -337,7 +333,6 @@ FRAME frame;
return frame->from_pc; return frame->from_pc;
} }
CORE_ADDR CORE_ADDR
frame_locals_address (fi) frame_locals_address (fi)
struct frame_info *fi; struct frame_info *fi;
@ -345,6 +340,7 @@ frame_locals_address (fi)
if (!fi->locals_pointer) if (!fi->locals_pointer)
{ {
struct frame_saved_regs ignore; struct frame_saved_regs ignore;
get_frame_saved_regs (fi, &ignore); get_frame_saved_regs (fi, &ignore);
} }
@ -361,6 +357,7 @@ frame_args_address (fi)
if (!fi->args_pointer) if (!fi->args_pointer)
{ {
struct frame_saved_regs ignore; struct frame_saved_regs ignore;
get_frame_saved_regs (fi, &ignore); get_frame_saved_regs (fi, &ignore);
} }
@ -368,14 +365,15 @@ frame_args_address (fi)
return fi->args_pointer; return fi->args_pointer;
} }
void
void h8300_pop_frame() h8300_pop_frame ()
{ {
unsigned regnum; unsigned regnum;
struct frame_saved_regs fsr; struct frame_saved_regs fsr;
struct frame_info *fi; struct frame_info *fi;
FRAME frame = get_current_frame (); FRAME frame = get_current_frame ();
fi = get_frame_info (frame); fi = get_frame_info (frame);
get_frame_saved_regs (fi, &fsr); get_frame_saved_regs (fi, &fsr);
@ -393,3 +391,50 @@ void h8300_pop_frame()
} }
} }
void
print_register_hook (regno)
{
if (regno == 8)
{
/* CCR register */
int C, Z, N, V;
unsigned char b[2];
unsigned char l;
read_relative_register_raw_bytes (regno, b);
l = b[1];
printf ("\t");
printf ("I-%d - ", (l & 0x80) != 0);
printf ("H-%d - ", (l & 0x20) != 0);
N = (l & 0x8) != 0;
Z = (l & 0x4) != 0;
V = (l & 0x2) != 0;
C = (l & 0x1) != 0;
printf ("N-%d ", N);
printf ("Z-%d ", Z);
printf ("V-%d ", V);
printf ("C-%d ", C);
if ((C | Z) == 0)
printf ("u> ");
if ((C | Z) == 1)
printf ("u<= ");
if ((C == 0))
printf ("u>= ");
if (C == 1)
printf ("u< ");
if (Z == 0)
printf ("!= ");
if (Z == 1)
printf ("== ");
if ((N ^ V) == 0)
printf (">= ");
if ((N ^ V) == 1)
printf ("< ");
if ((Z | (N ^ V)) == 0)
printf ("> ");
if ((Z | (N ^ V)) == 1)
printf ("<= ");
}
}

View File

@ -58,13 +58,13 @@ static int quiet = 1;
Each cache block holds LINE_SIZE bytes of data Each cache block holds LINE_SIZE bytes of data
starting at a multiple-of-LINE_SIZE address. */ starting at a multiple-of-LINE_SIZE address. */
#define LINE_SIZE_POWER 4 #define LINE_SIZE_POWER 4
#define LINE_SIZE (1<<LINE_SIZE_POWER) /* eg 1<<3 == 8 */ #define LINE_SIZE (1<<LINE_SIZE_POWER) /* eg 1<<3 == 8 */
#define LINE_SIZE_MASK ((LINE_SIZE-1)) /* eg 7*2+1= 111*/ #define LINE_SIZE_MASK ((LINE_SIZE-1)) /* eg 7*2+1= 111*/
#define DCACHE_SIZE 64 /* Number of cache blocks */ #define DCACHE_SIZE 64 /* Number of cache blocks */
#define XFORM(x) ((x&LINE_SIZE_MASK)>>2) #define XFORM(x) ((x&LINE_SIZE_MASK)>>2)
struct dcache_block { struct dcache_block
{
struct dcache_block *next, *last; struct dcache_block *next, *last;
unsigned int addr; /* Address for which data is recorded. */ unsigned int addr; /* Address for which data is recorded. */
int data[LINE_SIZE / sizeof (int)]; int data[LINE_SIZE / sizeof (int)];
@ -219,7 +219,6 @@ dcache_init ()
insque (db, &dcache_free); insque (db, &dcache_free);
} }
/*********************************************************************** /***********************************************************************
* I/O stuff stolen from remote-eb.c * I/O stuff stolen from remote-eb.c
***********************************************************************/ ***********************************************************************/
@ -228,14 +227,13 @@ static int timeout = 2;
static const char *dev_name; static const char *dev_name;
/* Descriptor for I/O to remote machine. Initialize it to -1 so that /* Descriptor for I/O to remote machine. Initialize it to -1 so that
hms_open knows that we don't have a file open when the program hms_open knows that we don't have a file open when the program
starts. */ starts. */
int is_open = 0; int is_open = 0;
int check_open() int
check_open ()
{ {
if (!is_open) if (!is_open)
{ {
@ -252,6 +250,7 @@ static int
readchar () readchar ()
{ {
int buf; int buf;
buf = serial_readchar (timeout); buf = serial_readchar (timeout);
if (buf < 0) if (buf < 0)
@ -267,8 +266,10 @@ static int
readchar_nofail () readchar_nofail ()
{ {
int buf; int buf;
buf = serial_readchar (timeout); buf = serial_readchar (timeout);
if (buf < 0) buf = 0; if (buf < 0)
buf = 0;
if (!quiet) if (!quiet)
printf ("%c", buf); printf ("%c", buf);
@ -284,7 +285,6 @@ expect (string)
{ {
char *p = string; char *p = string;
immediate_quit = 1; immediate_quit = 1;
while (1) while (1)
{ {
@ -329,6 +329,7 @@ get_hex_digit (ignore_space)
int ignore_space; int ignore_space;
{ {
int ch; int ch;
while (1) while (1)
{ {
ch = readchar (); ch = readchar ();
@ -373,10 +374,9 @@ get_hex_word()
val = (val << 4) + get_hex_digit (j == 0); val = (val << 4) + get_hex_digit (j == 0);
return val; return val;
} }
/* Called when SIGALRM signal sent due to alarm() timeout. */ /* Called when SIGALRM signal sent due to alarm() timeout. */
/* Number of SIGTRAPs we need to simulate. That is, the next /* Number of SIGTRAPs we need to simulate. That is, the next
NEED_ARTIFICIAL_TRAP calls to hms_wait should just return NEED_ARTIFICIAL_TRAP calls to hms_wait should just return
SIGTRAP without actually waiting for anything. */ SIGTRAP without actually waiting for anything. */
@ -391,8 +391,6 @@ int from_tty;
} }
/* /*
* Download a file specified in 'args', to the hms. * Download a file specified in 'args', to the hms.
*/ */
@ -410,7 +408,7 @@ int fromtty;
dcache_flush (); dcache_flush ();
inferior_pid = 0; inferior_pid = 0;
abfd = bfd_openr(args,"coff-h8300"); abfd = bfd_openr (args, 0);
if (!abfd) if (!abfd)
{ {
printf_filtered ("Unable to open file %s\n", args); printf_filtered ("Unable to open file %s\n", args);
@ -430,13 +428,14 @@ int fromtty;
{ {
int i; int i;
#define DELTA 1024 #define DELTA 1024
char *buffer = xmalloc (DELTA); char *buffer = xmalloc (DELTA);
printf_filtered ("%s\t: 0x%4x .. 0x%4x ", s->name, s->vma, s->vma + s->_raw_size); printf_filtered ("%s\t: 0x%4x .. 0x%4x ", s->name, s->vma, s->vma + s->_raw_size);
for (i = 0; i < s->_raw_size; i += DELTA) for (i = 0; i < s->_raw_size; i += DELTA)
{ {
int delta = DELTA; int delta = DELTA;
if (delta > s->_raw_size - i) if (delta > s->_raw_size - i)
delta = s->_raw_size - i; delta = s->_raw_size - i;
@ -475,7 +474,6 @@ hms_create_inferior (execfile, args, env)
entry_pt = (int) bfd_get_start_address (exec_bfd); entry_pt = (int) bfd_get_start_address (exec_bfd);
check_open (); check_open ();
hms_kill (NULL, NULL); hms_kill (NULL, NULL);
hms_clear_breakpoints (); hms_clear_breakpoints ();
init_wait_for_inferior (); init_wait_for_inferior ();
@ -486,7 +484,6 @@ hms_create_inferior (execfile, args, env)
proceed (entry_pt, -1, 0); proceed (entry_pt, -1, 0);
} }
/* Open a connection to a remote debugger. /* Open a connection to a remote debugger.
NAME is the filename used for communication, then a space, NAME is the filename used for communication, then a space,
then the baud rate. then the baud rate.
@ -501,7 +498,8 @@ char *s;
return s; return s;
} }
static char *get_word(p) static char *
get_word (p)
char **p; char **p;
{ {
char *s = *p; char *s = *p;
@ -535,6 +533,7 @@ static int
is_baudrate_right () is_baudrate_right ()
{ {
int ok; int ok;
/* Put this port into NORMAL mode, send the 'normal' character */ /* Put this port into NORMAL mode, send the 'normal' character */
hms_write ("\001", 1); /* Control A */ hms_write ("\001", 1); /* Control A */
@ -543,7 +542,8 @@ is_baudrate_right()
while (1) while (1)
{ {
ok = serial_readchar (timeout); ok = serial_readchar (timeout);
if (ok < 0) break; if (ok < 0)
break;
} }
hms_write ("r", 1); hms_write ("r", 1);
@ -568,7 +568,8 @@ get_baudrate_right()
while (!is_baudrate_right ()) while (!is_baudrate_right ())
{ {
baudrate = serial_nextbaudrate (baudrate); baudrate = serial_nextbaudrate (baudrate);
if (baudrate == 0) { if (baudrate == 0)
{
printf_filtered ("Board not yet in sync\n"); printf_filtered ("Board not yet in sync\n");
break; break;
} }
@ -622,7 +623,6 @@ hms_close (quitting)
int quitting; int quitting;
{ {
/* Clear any break points */ /* Clear any break points */
hms_clear_breakpoints (); hms_clear_breakpoints ();
@ -689,6 +689,7 @@ hms_wait (status)
find some cases of the string in the input. */ find some cases of the string in the input. */
static char bpt[] = "At breakpoint:"; static char bpt[] = "At breakpoint:";
/* It would be tempting to look for "\n[__exit + 0x8]\n" /* It would be tempting to look for "\n[__exit + 0x8]\n"
but that requires loading symbols with "yc i" and even if but that requires loading symbols with "yc i" and even if
we did do that we don't know that the file has symbols. */ we did do that we don't know that the file has symbols. */
@ -698,6 +699,7 @@ hms_wait (status)
/* Large enough for either sizeof (bpt) or sizeof (exitmsg) chars. */ /* Large enough for either sizeof (bpt) or sizeof (exitmsg) chars. */
char swallowed[50]; char swallowed[50];
/* Current position in swallowed. */ /* Current position in swallowed. */
char *swallowed_p = swallowed; char *swallowed_p = swallowed;
@ -751,14 +753,15 @@ hms_wait (status)
ep = exitmsg; ep = exitmsg;
} }
if (!ch_handled) { if (!ch_handled)
{
char *p; char *p;
/* Print out any characters which have been swallowed. */ /* Print out any characters which have been swallowed. */
for (p = swallowed; p < swallowed_p; ++p) for (p = swallowed; p < swallowed_p; ++p)
putc (*p, stdout); putc (*p, stdout);
swallowed_p = swallowed; swallowed_p = swallowed;
if ((ch != '\r' && ch != '\n') || swallowed_cr > 10) if ((ch != '\r' && ch != '\n') || swallowed_cr > 10)
{ {
putc (ch, stdout); putc (ch, stdout);
@ -792,16 +795,19 @@ get_reg_name (regno)
int regno; int regno;
{ {
static char *rn[NUM_REGS] = REGISTER_NAMES; static char *rn[NUM_REGS] = REGISTER_NAMES;
return rn[regno]; return rn[regno];
} }
/* Read the remote registers. */ /* Read the remote registers. */
static int gethex(length, start, ok) static int
gethex (length, start, ok)
unsigned int length; unsigned int length;
char *start; char *start;
int *ok; int *ok;
{ {
int result = 0; int result = 0;
while (length--) while (length--)
{ {
result <<= 4; result <<= 4;
@ -817,7 +823,8 @@ int *ok;
{ {
result += *start - '0'; result += *start - '0';
} }
else *ok = 0; else
*ok = 0;
start++; start++;
} }
@ -830,12 +837,14 @@ char *buf;
{ {
int i; int i;
char c; char c;
i = 0; i = 0;
while (i < n) while (i < n)
{ {
c = readchar (); c = readchar ();
if (c == 0) return i; if (c == 0)
return i;
buf[i] = c; buf[i] = c;
i++; i++;
@ -843,10 +852,12 @@ char *buf;
return i; return i;
} }
hms_write (a, l) hms_write (a, l)
char *a; char *a;
{ {
int i; int i;
serial_write (a, l); serial_write (a, l);
if (!quiet) if (!quiet)
@ -875,6 +886,7 @@ int dummy;
REGISTER_TYPE reg[NUM_REGS]; REGISTER_TYPE reg[NUM_REGS];
int foo[8]; int foo[8];
check_open (); check_open ();
do do
@ -883,7 +895,6 @@ int dummy;
hms_write_cr ("r"); hms_write_cr ("r");
s = timed_read (linebuf, REGREPLY_SIZE, 1); s = timed_read (linebuf, REGREPLY_SIZE, 1);
linebuf[REGREPLY_SIZE] = 0; linebuf[REGREPLY_SIZE] = 0;
gottok = 0; gottok = 0;
if (linebuf[0] == 'r' && if (linebuf[0] == 'r' &&
@ -913,6 +924,7 @@ int dummy;
for (i = 0; i < NUM_REGS; i++) for (i = 0; i < NUM_REGS; i++)
{ {
char swapped[2]; char swapped[2];
swapped[1] = reg[i]; swapped[1] = reg[i];
swapped[0] = (reg[i]) >> 8; swapped[0] = (reg[i]) >> 8;
@ -920,7 +932,6 @@ int dummy;
} }
} }
/* Store register REGNO, or all if REGNO == -1. /* Store register REGNO, or all if REGNO == -1.
Return errno value. */ Return errno value. */
static void static void
@ -940,14 +951,13 @@ hms_store_register (regno)
{ {
char *name = get_reg_name (regno); char *name = get_reg_name (regno);
char buffer[100]; char buffer[100];
sprintf (buffer, "r %s=%x", name, read_register (regno)); sprintf (buffer, "r %s=%x", name, read_register (regno));
hms_write_cr (buffer); hms_write_cr (buffer);
expect_prompt (); expect_prompt ();
} }
} }
/* Get ready to modify the registers array. On machines which store /* Get ready to modify the registers array. On machines which store
individual registers, this doesn't need to do anything. On machines individual registers, this doesn't need to do anything. On machines
which store all the registers in one fell swoop, this makes sure which store all the registers in one fell swoop, this makes sure
@ -999,10 +1009,13 @@ hms_xfer_inferior_memory(memaddr, myaddr, len, write, target)
struct target_ops *target; /* ignored */ struct target_ops *target; /* ignored */
{ {
register int i; register int i;
/* Round starting address down to longword boundary. */ /* Round starting address down to longword boundary. */
register CORE_ADDR addr; register CORE_ADDR addr;
/* Round ending address up; get number of longwords that makes. */ /* Round ending address up; get number of longwords that makes. */
register int count; register int count;
/* Allocate buffer of that many longwords. */ /* Allocate buffer of that many longwords. */
register int *buffer; register int *buffer;
@ -1010,13 +1023,14 @@ hms_xfer_inferior_memory(memaddr, myaddr, len, write, target)
addr = memaddr & -sizeof (int); addr = memaddr & -sizeof (int);
count = (((memaddr + len) - addr) + sizeof (int) - 1) / sizeof (int); count = (((memaddr + len) - addr) + sizeof (int) - 1) / sizeof (int);
buffer = (int *) alloca (count * sizeof (int)); buffer = (int *) alloca (count * sizeof (int));
if (write) if (write)
{ {
/* Fill start and end extra bytes of buffer with existing memory data. */ /* Fill start and end extra bytes of buffer with existing memory data. */
if (addr != memaddr || len < (int)sizeof (int)) { if (addr != memaddr || len < (int) sizeof (int))
{
/* Need part of initial word -- fetch it. */ /* Need part of initial word -- fetch it. */
buffer[0] = hms_fetch_word (addr); buffer[0] = hms_fetch_word (addr);
} }
@ -1063,7 +1077,6 @@ hms_xfer_inferior_memory(memaddr, myaddr, len, write, target)
bcopy ((char *) buffer + (memaddr & (sizeof (int) - 1)), myaddr, len); bcopy ((char *) buffer + (memaddr & (sizeof (int) - 1)), myaddr, len);
} }
return len; return len;
} }
@ -1076,20 +1089,24 @@ hms_write_inferior_memory (memaddr, myaddr, len)
bfd_vma addr; bfd_vma addr;
int done; int done;
int todo; int todo;
done = 0; done = 0;
while (done < len) while (done < len)
{ {
char buffer[20]; char buffer[20];
int thisgo; int thisgo;
int idx; int idx;
thisgo = len - done; thisgo = len - done;
if (thisgo > 20) thisgo = 20; if (thisgo > 20)
thisgo = 20;
sprintf (buffer, "M.B %4x =", memaddr + done); sprintf (buffer, "M.B %4x =", memaddr + done);
hms_write (buffer, 10); hms_write (buffer, 10);
for (idx = 0; idx < thisgo; idx++) for (idx = 0; idx < thisgo; idx++)
{ {
char buf[20]; char buf[20];
sprintf (buf, "%2x ", myaddr[idx + done]); sprintf (buf, "%2x ", myaddr[idx + done]);
hms_write (buf, 3); hms_write (buf, 3);
} }
@ -1098,13 +1115,13 @@ hms_write_inferior_memory (memaddr, myaddr, len)
done += thisgo; done += thisgo;
} }
} }
void void
hms_files_info () hms_files_info ()
{ {
char *file = "nothing"; char *file = "nothing";
if (exec_bfd) if (exec_bfd)
file = bfd_get_filename (exec_bfd); file = bfd_get_filename (exec_bfd);
@ -1122,7 +1139,6 @@ if (exec_bfd)
* sb/sh instructions don't work on unaligned addresses, when TU=1. * sb/sh instructions don't work on unaligned addresses, when TU=1.
*/ */
/* Read LEN bytes from inferior memory at MEMADDR. Put the result /* Read LEN bytes from inferior memory at MEMADDR. Put the result
at debugger address MYADDR. Returns errno value. */ at debugger address MYADDR. Returns errno value. */
int int
@ -1137,6 +1153,7 @@ hms_read_inferior_memory(memaddr, myaddr, len)
#if 0 #if 0
CORE_ADDR start = memaddr & ~0xf; CORE_ADDR start = memaddr & ~0xf;
CORE_ADDR end = ((memaddr + len + 16) & ~0xf) - 1; CORE_ADDR end = ((memaddr + len + 16) & ~0xf) - 1;
#endif #endif
CORE_ADDR start = memaddr; CORE_ADDR start = memaddr;
CORE_ADDR end = memaddr + len - 1; CORE_ADDR end = memaddr + len - 1;
@ -1149,8 +1166,11 @@ hms_read_inferior_memory(memaddr, myaddr, len)
0 1 2 3 4 5 6 0 1 2 3 4 5 6
*/ */
char buffer[66]; char buffer[66];
if (memaddr & 0xf) abort();
if (len != 16) abort(); if (memaddr & 0xf)
abort ();
if (len != 16)
abort ();
sprintf (buffer, "m %4x %4x", start & 0xffff, end & 0xffff); sprintf (buffer, "m %4x %4x", start & 0xffff, end & 0xffff);
hms_write_cr (buffer); hms_write_cr (buffer);
@ -1158,8 +1178,6 @@ hms_read_inferior_memory(memaddr, myaddr, len)
for (i = 0; i < 13; i++) for (i = 0; i < 13; i++)
readchar (); readchar ();
/* Grab the lines as they come out and fill the area */ /* Grab the lines as they come out and fill the area */
/* Skip over cr */ /* Skip over cr */
while (1) while (1)
@ -1170,6 +1188,7 @@ hms_read_inferior_memory(memaddr, myaddr, len)
size_t idx; size_t idx;
char byte[16]; char byte[16];
buffer[0] = readchar (); buffer[0] = readchar ();
if (buffer[0] == 'M') if (buffer[0] == 'M')
break; break;
@ -1188,7 +1207,6 @@ hms_read_inferior_memory(memaddr, myaddr, len)
} }
for (p = 0; p < 16; p++) for (p = 0; p < 16; p++)
{ {
if (addr + p >= memaddr && if (addr + p >= memaddr &&
@ -1220,7 +1238,6 @@ hms_before_main_loop ()
push_target (&hms_ops); push_target (&hms_ops);
} }
#define MAX_BREAKS 16 #define MAX_BREAKS 16
static int num_brkpts = 0; static int num_brkpts = 0;
static int static int
@ -1233,6 +1250,7 @@ char *save; /* Throw away, let hms save instructions */
if (num_brkpts < MAX_BREAKS) if (num_brkpts < MAX_BREAKS)
{ {
char buffer[100]; char buffer[100];
num_brkpts++; num_brkpts++;
sprintf (buffer, "b %x", addr & 0xffff); sprintf (buffer, "b %x", addr & 0xffff);
hms_write_cr (buffer); hms_write_cr (buffer);
@ -1246,7 +1264,6 @@ char *save; /* Throw away, let hms save instructions */
return (1); return (1);
} }
} }
static int static int
hms_remove_breakpoint (addr, save) hms_remove_breakpoint (addr, save)
@ -1271,7 +1288,8 @@ static int
hms_clear_breakpoints () hms_clear_breakpoints ()
{ {
if (is_open) { if (is_open)
{
hms_write_cr ("b -"); hms_write_cr ("b -");
expect_prompt (); expect_prompt ();
} }
@ -1284,8 +1302,6 @@ hms_mourn()
generic_mourn_inferior (); generic_mourn_inferior ();
} }
/* Put a command string, in args, out to the hms. The hms is assumed to /* Put a command string, in args, out to the hms. The hms is assumed to
be in raw mode, all writing/reading done through desc. be in raw mode, all writing/reading done through desc.
Ouput from the hms is placed on the users terminal until the Ouput from the hms is placed on the users terminal until the
@ -1299,7 +1315,8 @@ hms_com (args, fromtty)
{ {
check_open (); check_open ();
if (!args) return; if (!args)
return;
/* Clear all input so only command relative output is displayed */ /* Clear all input so only command relative output is displayed */
@ -1310,7 +1327,8 @@ hms_com (args, fromtty)
/* Define the target subroutine names */ /* Define the target subroutine names */
struct target_ops hms_ops = { struct target_ops hms_ops =
{
"hms", "Remote HMS monitor", "hms", "Remote HMS monitor",
"Use the H8 evaluation board running the HMS monitor connected\n\ "Use the H8 evaluation board running the HMS monitor connected\n\
by a serial line.", by a serial line.",
@ -1336,7 +1354,6 @@ by a serial line.",
OPS_MAGIC, /* Always the last thing */ OPS_MAGIC, /* Always the last thing */
}; };
hms_quiet () hms_quiet ()
{ {
quiet = !quiet; quiet = !quiet;
@ -1356,7 +1373,6 @@ char *s;
} }
} }
static static
hms_speed (s) hms_speed (s)
char *s; char *s;
@ -1368,6 +1384,7 @@ char *s;
char buffer[100]; char buffer[100];
int newrate = atoi (s); int newrate = atoi (s);
int which = 0; int which = 0;
if (!serial_setbaudrate (newrate)) if (!serial_setbaudrate (newrate))
error ("Can't use %d baud\n", newrate); error ("Can't use %d baud\n", newrate);
@ -1389,6 +1406,7 @@ void
_initialize_remote_hms () _initialize_remote_hms ()
{ {
add_target (&hms_ops); add_target (&hms_ops);
add_com ("hms <command>", class_obscure, hms_com, add_com ("hms <command>", class_obscure, hms_com,
"Send a command to the HMS monitor."); "Send a command to the HMS monitor.");
add_com ("snoop", class_obscure, hms_quiet, add_com ("snoop", class_obscure, hms_quiet,
@ -1400,8 +1418,5 @@ _initialize_remote_hms ()
add_com ("speed", class_obscure, hms_speed, add_com ("speed", class_obscure, hms_speed,
"Set the terminal line speed for HMS communications"); "Set the terminal line speed for HMS communications");
#if 0
dev_name = serial_default_name();
#endif
dev_name = NULL; dev_name = NULL;
} }

293
gdb/remote-sim.c Normal file
View File

@ -0,0 +1,293 @@
/* Remote debugging interface for generalized simulator
Copyright 1992 Free Software Foundation, Inc.
Contributed by Cygnus Support. Written by Steve Chamberlain
(sac@cygnus.com).
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 "value.h"
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#include <signal.h>
#include <setjmp.h>
#include <errno.h>
#include "terminal.h"
#include "target.h"
#include "gdbcore.h"
/* Forward data declarations */
extern struct target_ops sim_ops; /* Forward declaration */
int
sim_write_inferior_memory (memaddr, myaddr, len)
CORE_ADDR memaddr;
unsigned char *myaddr;
int len;
{
return sim_write(memaddr, myaddr, len);
}
static int
store_register(regno)
int regno;
{
if (regno == -1)
{
for (regno = 0; regno < NUM_REGS; regno++)
store_register(regno);
}
else
{
sim_store_register(regno, read_register(regno));
}
return 0;
}
/*
* Download a file specified in 'args', to the sim.
*/
static void
sim_load(args,fromtty)
char *args;
int fromtty;
{
bfd *abfd;
asection *s;
inferior_pid = 0;
abfd = bfd_openr(args, (char*)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)
{
if (s->flags & SEC_LOAD)
{
int i;
int delta = 4096;
char *buffer = xmalloc(delta);
printf_filtered("%s\t: 0x%4x .. 0x%4x ",
s->name, s->vma, s->vma + s->_raw_size);
for (i = 0; i < s->_raw_size; i+= delta)
{
int sub_delta = delta;
if (sub_delta > s->_raw_size - i)
sub_delta = s->_raw_size - i ;
bfd_get_section_contents(abfd, s, buffer, i, sub_delta);
sim_write_inferior_memory(s->vma + i, buffer, sub_delta);
printf_filtered("*");
fflush(stdout);
}
printf_filtered( "\n");
free(buffer);
}
s = s->next;
}
sim_store_register(PC_REGNUM, abfd->start_address);
}
/* This is called not only when we first attach, but also when the
user types "run" after having attached. */
void
sim_create_inferior (execfile, args, env)
char *execfile;
char *args;
char **env;
{
int entry_pt;
if (args && *args)
error ("Can't pass arguments to remote sim process.");
if (execfile == 0 || exec_bfd == 0)
error ("No exec file specified");
entry_pt = (int) bfd_get_start_address (exec_bfd);
init_wait_for_inferior ();
insert_breakpoints ();
proceed(entry_pt, -1, 0);
}
static int
sim_open (name, from_tty)
char *name;
int from_tty;
{
if(name == 0)
{
name = "";
}
push_target (&sim_ops);
target_fetch_registers(-1);
printf_filtered("Connected to the simulator.\n");
}
/* Close out all files and local state before this target loses control. */
static int
sim_close (quitting)
int quitting;
{
}
/* Terminate the open connection to the remote debugger.
Use this when you want to detach and do something else
with your gdb. */
int
sim_detach (args,from_tty)
char *args;
int from_tty;
{
pop_target(); /* calls sim_close to do the real work */
if (from_tty)
printf_filtered ("Ending remote %s debugging\n", target_shortname);
return 0;
}
/* Tell the remote machine to resume. */
/* Wait until the remote machine stops, then return,
storing status in STATUS just as `wait' would. */
int
sim_wait (status)
WAITTYPE *status;
{
WSETSTOP(*status, sim_stop_signal());
return 0;
}
static void
fetch_register(regno)
int regno;
{
if (regno == -1)
{
for (regno = 0; regno < NUM_REGS; regno++)
fetch_register(regno);
}
else
{
char buf[MAX_REGISTER_RAW_SIZE];
sim_fetch_register(regno, buf);
supply_register(regno, buf);
}
}
int
sim_xfer_inferior_memory(memaddr, myaddr, len, write, target)
CORE_ADDR memaddr;
char *myaddr;
int len;
int write;
struct target_ops *target; /* ignored */
{
if (write)
{
sim_write(memaddr, myaddr, len);
}
else
{
sim_read(memaddr, myaddr, len);
}
return len;
}
/* This routine is run as a hook, just before the main command loop is
entered. If gdb is configured for the H8, but has not had its
target specified yet, this will loop prompting the user to do so.
*/
void
sim_before_main_loop ()
{
push_target (&sim_ops);
}
static int rem_resume(a,b)
{
sim_resume(a,b);
return 0;
}
pstore()
{
return 1;
}
/* Define the target subroutine names */
struct target_ops sim_ops =
{
"sim", "simulator",
"Use the simulator",
sim_open, sim_close,
0, sim_detach, rem_resume, sim_wait, /* attach */
fetch_register, store_register,
pstore,
sim_xfer_inferior_memory,
0,
0, 0, /* Breakpoints */
0, 0, 0, 0, 0, /* Terminal handling */
pstore,
sim_load,
0, /* lookup_symbol */
sim_create_inferior, /* create_inferior */
pstore, /* mourn_inferior FIXME */
0, /* can_run */
0, /* notice_signals */
process_stratum, 0, /* next */
1, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
0,0, /* Section pointers */
OPS_MAGIC, /* Always the last thing */
};
/***********************************************************************/
void
_initialize_remote_sim ()
{
add_target (&sim_ops);
}

View File

@ -77,17 +77,8 @@ UNSIGNED_SHORT(read_memory_integer (read_register (SP_REGNUM), 2))
#define INNER_THAN < #define INNER_THAN <
/* Sequence of bytes for breakpoint instruction.
This is a TRAP instruction. The last 4 bits (0xf below) is the
vector. Systems which don't use 0xf should define BPT_VECTOR
themselves before including this file. */
#define BREAKPOINT {0x53, 0x00}
#define BPT_VECTOR 0xf
#define BREAKPOINT {0x4e, (0x40 | BPT_VECTOR)}
/* If your kernel resets the pc after the trap happens you may need to /* If your kernel resets the pc after the trap happens you may need to
@ -305,3 +296,6 @@ typedef unsigned short INSN_WORD;
#define read_memory_short(x) (read_memory_integer(x,2) & 0xffff) #define read_memory_short(x) (read_memory_integer(x,2) & 0xffff)
#define DONT_USE_REMOTE #define DONT_USE_REMOTE
#define PRINT_REGISTER_HOOK(regno) print_register_hook(regno)