#include "defs.h"
#include "gdbcore.h"
#include "target.h"
#include "monitor.h"
#include "serial.h"
#include "xmodem.h"
#include "regcache.h"
static void w89k_open (char *args, int from_tty);
static char *w89k_regnames[NUM_REGS] =
{
"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
"r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
"r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
"SAR", "PC", NULL, NULL, NULL, "EIEM", "IIR", "IVA",
"IOR", "IPSW", NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL,
"CCR", NULL, NULL, "TR0", "TR1",
};
static void
w89k_supply_register (char *regname, int regnamelen, char *val, int vallen)
{
int numregs;
int regno;
numregs = 1;
regno = -1;
if (regnamelen == 2)
switch (regname[0])
{
case 'r':
numregs = 4;
switch (regname[1])
{
case '0':
regno = R0_REGNUM;
break;
case '4':
regno = R0_REGNUM + 4;
break;
case '8':
regno = R0_REGNUM + 8;
break;
}
break;
case 'P':
if (regname[1] == 'C')
regno = PC_REGNUM;
break;
}
else if (regnamelen == 3)
switch (regname[0])
{
case 'r':
numregs = 4;
if (regname[1] == '1' && regname[2] == '2')
regno = R0_REGNUM + 12;
else if (regname[1] == '1' && regname[2] == '6')
regno = R0_REGNUM + 16;
else if (regname[1] == '2' && regname[2] == '0')
regno = R0_REGNUM + 20;
else if (regname[1] == '2' && regname[2] == '4')
regno = R0_REGNUM + 24;
else if (regname[1] == '2' && regname[2] == '8')
regno = R0_REGNUM + 28;
break;
case 'R':
if (regname[1] == 'C' && regname[2] == 'R')
regno = RCR_REGNUM;
break;
case 'C':
if (regname[1] == 'C' && regname[2] == 'R')
regno = CCR_REGNUM;
break;
case 'S':
if (regname[1] == 'A' && regname[2] == 'R')
regno = SAR_REGNUM;
break;
case 'I':
if (regname[1] == 'I' && regname[2] == 'R')
regno = IIR_REGNUM;
else if (regname[1] == 'O' && regname[2] == 'R')
regno = IOR_REGNUM;
break;
case 'T':
numregs = 4;
if (regname[1] == 'R')
if (regname[2] == '0')
regno = TR0_REGNUM;
else if (regname[2] == '4')
regno = TR0_REGNUM + 4;
break;
}
else if (regnamelen == 4)
switch (regname[0])
{
case 'E':
if (regname[1] == 'I')
if (regname[2] == 'E' && regname[3] == 'M')
regno = EIEM_REGNUM;
break;
case 'I':
if (regname[1] == 'P' && regname[2] == 'S' && regname[3] == 'W')
regno = IPSW_REGNUM;
break;
}
else if (regnamelen == 5)
switch (regname[0])
{
case 'I':
if (regname[1] == 'A'
&& regname[2] == 'O'
&& regname[3] == 'Q'
&& regname[4] == 'B')
regno = PCOQ_TAIL_REGNUM;
break;
}
if (regno >= 0)
while (numregs-- > 0)
val = monitor_supply_register (regno++, val);
}
static int hashmark = 1;
extern struct monitor_ops w89k_cmds;
static void
w89k_load (struct serial *desc, char *file, int hashmark)
{
bfd *abfd;
asection *s;
char *buffer;
int i;
buffer = alloca (XMODEM_PACKETSIZE);
abfd = bfd_openr (file, 0);
if (!abfd)
{
printf_filtered ("Unable to open file %s\n", file);
return;
}
if (bfd_check_format (abfd, bfd_object) == 0)
{
printf_filtered ("File is not an object file\n");
return;
}
for (s = abfd->sections; s; s = s->next)
if (s->flags & SEC_LOAD)
{
bfd_size_type section_size;
printf_filtered ("%s\t: 0x%4x .. 0x%4x ", s->name, s->vma,
s->vma + s->_raw_size);
gdb_flush (gdb_stdout);
monitor_printf (w89k_cmds.load, s->vma);
if (w89k_cmds.loadresp)
monitor_expect (w89k_cmds.loadresp, NULL, 0);
xmodem_init_xfer (desc);
section_size = bfd_section_size (abfd, s);
for (i = 0; i < section_size; i += XMODEM_DATASIZE)
{
int numbytes;
numbytes = min (XMODEM_DATASIZE, section_size - i);
bfd_get_section_contents (abfd, s, buffer + XMODEM_DATAOFFSET, i,
numbytes);
xmodem_send_packet (desc, buffer, numbytes, hashmark);
if (hashmark)
{
putchar_unfiltered ('#');
gdb_flush (gdb_stdout);
}
}
xmodem_finish_xfer (desc);
monitor_expect_prompt (NULL, 0);
putchar_unfiltered ('\n');
}
if (hashmark)
putchar_unfiltered ('\n');
}
static struct target_ops w89k_ops;
static char *w89k_inits[] =
{"\n", NULL};
static struct monitor_ops w89k_cmds;
static void
init_w89k_cmds (void)
{
w89k_cmds.flags = MO_GETMEM_NEEDS_RANGE | MO_FILL_USES_ADDR;
w89k_cmds.init = w89k_inits;
w89k_cmds.cont = "g\n";
w89k_cmds.step = "t\n";
w89k_cmds.stop = "\003";
w89k_cmds.set_break = "bp %x\n";
w89k_cmds.clr_break = "bc %x\n";
w89k_cmds.clr_all_break = "bc *\n";
w89k_cmds.fill = "f %x %x %x\n";
w89k_cmds.setmem.cmdb = "eb %x %x\n";
w89k_cmds.setmem.cmdw = "eh %x %x\n";
w89k_cmds.setmem.cmdl = "ew %x %x\n";
w89k_cmds.setmem.cmdll = NULL;
w89k_cmds.setmem.resp_delim = NULL;
w89k_cmds.setmem.term = NULL;
w89k_cmds.setmem.term_cmd = NULL;
w89k_cmds.getmem.cmdb = "db %x %x\n";
w89k_cmds.getmem.cmdw = "dh %x %x\n";
w89k_cmds.getmem.cmdl = "dw %x %x\n";
w89k_cmds.getmem.cmdll = NULL;
w89k_cmds.getmem.resp_delim = " ";
w89k_cmds.getmem.term = NULL;
w89k_cmds.getmem.term_cmd = NULL;
w89k_cmds.setreg.cmd = "r %s %x\n";
w89k_cmds.setreg.resp_delim = NULL;
w89k_cmds.setreg.term = NULL;
w89k_cmds.setreg.term_cmd = NULL;
w89k_cmds.getreg.cmd = "r %s\n";
w89k_cmds.getreg.resp_delim = "\r";
w89k_cmds.getreg.term = NULL;
w89k_cmds.getreg.term_cmd = NULL;
w89k_cmds.dump_registers = "r\n";
w89k_cmds.register_pattern = "\\(\\w+\\)\\( +[0-9a-fA-F]+\\b\\)+";
w89k_cmds.supply_register = w89k_supply_register;
w89k_cmds.load_routine = w89k_load;
w89k_cmds.load = "u %x\n";
w89k_cmds.loadresp = "\021";
w89k_cmds.prompt = "ROM>";
w89k_cmds.line_term = "\n";
w89k_cmds.cmd_end = NULL;
w89k_cmds.target = &w89k_ops;
w89k_cmds.stopbits = SERIAL_1_STOPBITS;
w89k_cmds.regnames = w89k_regnames;
w89k_cmds.magic = MONITOR_OPS_MAGIC;
}
static void
w89k_open (char *args, int from_tty)
{
monitor_open (args, &w89k_cmds, from_tty);
}
void
_initialize_w89k (void)
{
init_w89k_cmds ();
init_monitor_ops (&w89k_ops);
w89k_ops.to_shortname = "w89k";
w89k_ops.to_longname = "WinBond's debug monitor for the W89k Eval board";
w89k_ops.to_doc = "Debug on a WinBond W89K eval board.\n\
Specify the serial device it is connected to (e.g. /dev/ttya).";
w89k_ops.to_open = w89k_open;
add_target (&w89k_ops);
}