| 1 | /* Remote target glue for the WinBond ROM monitor running on the "Cougar" |
| 2 | W89k eval board. |
| 3 | |
| 4 | Copyright 1995 Free Software Foundation, Inc. |
| 5 | |
| 6 | This file is part of GDB. |
| 7 | |
| 8 | This program is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation; either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program; if not, write to the Free Software |
| 20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 21 | |
| 22 | #include "defs.h" |
| 23 | #include "gdbcore.h" |
| 24 | #include "target.h" |
| 25 | #include "monitor.h" |
| 26 | #include "serial.h" |
| 27 | #include "xmodem.h" |
| 28 | |
| 29 | static void w89k_open PARAMS ((char *args, int from_tty)); |
| 30 | |
| 31 | /* |
| 32 | * this array of registers need to match the indexes used by GDB. The |
| 33 | * whole reason this exists is cause the various ROM monitors use |
| 34 | * different strings than GDB does, and doesn't support all the |
| 35 | * registers either. So, typing "info reg sp" becomes a "r30". |
| 36 | */ |
| 37 | |
| 38 | static char *w89k_regnames[NUM_REGS] = |
| 39 | { |
| 40 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 41 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
| 42 | "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", |
| 43 | "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", |
| 44 | "SAR", "PC", NULL, NULL, NULL, "EIEM", "IIR", "IVA", |
| 45 | "IOR", "IPSW", NULL, NULL, NULL, NULL, NULL, |
| 46 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 47 | "CCR", NULL, NULL, "TR0", "TR1", |
| 48 | }; |
| 49 | |
| 50 | static void |
| 51 | w89k_supply_register (regname, regnamelen, val, vallen) |
| 52 | char *regname; |
| 53 | int regnamelen; |
| 54 | char *val; |
| 55 | int vallen; |
| 56 | { |
| 57 | int numregs; |
| 58 | int regno; |
| 59 | |
| 60 | numregs = 1; |
| 61 | regno = -1; |
| 62 | |
| 63 | if (regnamelen == 2) |
| 64 | switch (regname[0]) |
| 65 | { |
| 66 | case 'r': |
| 67 | numregs = 4; |
| 68 | switch (regname[1]) |
| 69 | { |
| 70 | case '0': |
| 71 | regno = R0_REGNUM; |
| 72 | break; |
| 73 | case '4': |
| 74 | regno = R0_REGNUM + 4; |
| 75 | break; |
| 76 | case '8': |
| 77 | regno = R0_REGNUM + 8; |
| 78 | break; |
| 79 | } |
| 80 | break; |
| 81 | case 'P': |
| 82 | if (regname[1] == 'C') |
| 83 | regno = PC_REGNUM; |
| 84 | break; |
| 85 | } |
| 86 | else if (regnamelen == 3) |
| 87 | switch (regname[0]) |
| 88 | { |
| 89 | case 'r': |
| 90 | numregs = 4; |
| 91 | if (regname[1] == '1' && regname[2] == '2') |
| 92 | regno = R0_REGNUM + 12; |
| 93 | else if (regname[1] == '1' && regname[2] == '6') |
| 94 | regno = R0_REGNUM + 16; |
| 95 | else if (regname[1] == '2' && regname[2] == '0') |
| 96 | regno = R0_REGNUM + 20; |
| 97 | else if (regname[1] == '2' && regname[2] == '4') |
| 98 | regno = R0_REGNUM + 24; |
| 99 | else if (regname[1] == '2' && regname[2] == '8') |
| 100 | regno = R0_REGNUM + 28; |
| 101 | break; |
| 102 | case 'R': |
| 103 | if (regname[1] == 'C' && regname[2] == 'R') |
| 104 | regno = RCR_REGNUM; |
| 105 | break; |
| 106 | case 'C': |
| 107 | if (regname[1] == 'C' && regname[2] == 'R') |
| 108 | regno = CCR_REGNUM; |
| 109 | break; |
| 110 | case 'S': |
| 111 | if (regname[1] == 'A' && regname[2] == 'R') |
| 112 | regno = SAR_REGNUM; |
| 113 | break; |
| 114 | case 'I': |
| 115 | if (regname[1] == 'I' && regname[2] == 'R') |
| 116 | regno = IIR_REGNUM; |
| 117 | else if (regname[1] == 'O' && regname[2] == 'R') |
| 118 | regno = IOR_REGNUM; |
| 119 | break; |
| 120 | case 'T': |
| 121 | numregs = 4; |
| 122 | if (regname[1] == 'R') |
| 123 | if (regname[2] == '0') |
| 124 | regno = TR0_REGNUM; |
| 125 | else if (regname[2] == '4') |
| 126 | regno = TR0_REGNUM + 4; |
| 127 | break; |
| 128 | } |
| 129 | else if (regnamelen == 4) |
| 130 | switch (regname[0]) |
| 131 | { |
| 132 | case 'E': |
| 133 | if (regname[1] == 'I') |
| 134 | if (regname[2] == 'E' && regname[3] == 'M') |
| 135 | regno = EIEM_REGNUM; |
| 136 | break; |
| 137 | case 'I': |
| 138 | if (regname[1] == 'P' && regname[2] == 'S' && regname[3] == 'W') |
| 139 | regno = IPSW_REGNUM; |
| 140 | break; |
| 141 | } |
| 142 | else if (regnamelen == 5) |
| 143 | switch (regname[0]) |
| 144 | { |
| 145 | case 'I': |
| 146 | if (regname[1] == 'A' |
| 147 | && regname[2] == 'O' |
| 148 | && regname[3] == 'Q' |
| 149 | && regname[4] == 'B') |
| 150 | regno = PCOQ_TAIL_REGNUM; |
| 151 | break; |
| 152 | } |
| 153 | |
| 154 | if (regno >= 0) |
| 155 | while (numregs-- > 0) |
| 156 | val = monitor_supply_register (regno++, val); |
| 157 | } |
| 158 | |
| 159 | static int hashmark = 1; /* flag set by "set hash" */ |
| 160 | |
| 161 | extern struct monitor_ops w89k_cmds; /* fwd decl */ |
| 162 | |
| 163 | static void |
| 164 | w89k_load (desc, file, hashmark) |
| 165 | serial_t desc; |
| 166 | char *file; |
| 167 | int hashmark; |
| 168 | { |
| 169 | bfd *abfd; |
| 170 | asection *s; |
| 171 | char *buffer; |
| 172 | int i; |
| 173 | |
| 174 | buffer = alloca (XMODEM_PACKETSIZE); |
| 175 | |
| 176 | abfd = bfd_openr (file, 0); |
| 177 | if (!abfd) |
| 178 | { |
| 179 | printf_filtered ("Unable to open file %s\n", file); |
| 180 | return; |
| 181 | } |
| 182 | |
| 183 | if (bfd_check_format (abfd, bfd_object) == 0) |
| 184 | { |
| 185 | printf_filtered ("File is not an object file\n"); |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | for (s = abfd->sections; s; s = s->next) |
| 190 | if (s->flags & SEC_LOAD) |
| 191 | { |
| 192 | bfd_size_type section_size; |
| 193 | |
| 194 | printf_filtered ("%s\t: 0x%4x .. 0x%4x ", s->name, s->vma, |
| 195 | s->vma + s->_raw_size); |
| 196 | gdb_flush (gdb_stdout); |
| 197 | |
| 198 | monitor_printf (w89k_cmds.load, s->vma); |
| 199 | if (w89k_cmds.loadresp) |
| 200 | monitor_expect (w89k_cmds.loadresp, NULL, 0); |
| 201 | |
| 202 | xmodem_init_xfer (desc); |
| 203 | |
| 204 | section_size = bfd_section_size (abfd, s); |
| 205 | |
| 206 | for (i = 0; i < section_size; i += XMODEM_DATASIZE) |
| 207 | { |
| 208 | int numbytes; |
| 209 | |
| 210 | numbytes = min (XMODEM_DATASIZE, section_size - i); |
| 211 | |
| 212 | bfd_get_section_contents (abfd, s, buffer + XMODEM_DATAOFFSET, i, |
| 213 | numbytes); |
| 214 | |
| 215 | xmodem_send_packet (desc, buffer, numbytes, hashmark); |
| 216 | |
| 217 | if (hashmark) |
| 218 | { |
| 219 | putchar_unfiltered ('#'); |
| 220 | gdb_flush (gdb_stdout); |
| 221 | } |
| 222 | } /* Per-packet (or S-record) loop */ |
| 223 | |
| 224 | xmodem_finish_xfer (desc); |
| 225 | |
| 226 | monitor_expect_prompt (NULL, 0); |
| 227 | |
| 228 | putchar_unfiltered ('\n'); |
| 229 | } /* Loadable sections */ |
| 230 | |
| 231 | if (hashmark) |
| 232 | putchar_unfiltered ('\n'); |
| 233 | } |
| 234 | |
| 235 | /* |
| 236 | * Define the monitor command strings. Since these are passed directly |
| 237 | * through to a printf style function, we need can include formatting |
| 238 | * strings. We also need a CR or LF on the end. |
| 239 | */ |
| 240 | |
| 241 | static struct target_ops w89k_ops; |
| 242 | |
| 243 | static char *w89k_inits[] = {"\n", NULL}; |
| 244 | |
| 245 | static struct monitor_ops w89k_cmds = |
| 246 | { |
| 247 | MO_GETMEM_NEEDS_RANGE|MO_FILL_USES_ADDR, /* flags */ |
| 248 | w89k_inits, /* Init strings */ |
| 249 | "g\n", /* continue command */ |
| 250 | "t\n", /* single step */ |
| 251 | "\003", /* Interrupt char (^C) */ |
| 252 | "bp %x\n", /* set a breakpoint */ |
| 253 | "bc %x\n", /* clear a breakpoint */ |
| 254 | "bc *\n", /* clear all breakpoints */ |
| 255 | "f %x %x %x\n", /* memory fill cmd */ |
| 256 | { |
| 257 | "eb %x %x\n", /* setmem.cmdb (addr, value) */ |
| 258 | "eh %x %x\n", /* setmem.cmdw (addr, value) */ |
| 259 | "ew %x %x\n", /* setmem.cmdl (addr, value) */ |
| 260 | NULL, /* setmem.cmdll (addr, value) */ |
| 261 | NULL, /* setreg.resp_delim */ |
| 262 | NULL, /* setreg.term */ |
| 263 | NULL, /* setreg.term_cmd */ |
| 264 | }, |
| 265 | { |
| 266 | "db %x %x\n", /* getmem.cmdb (startaddr, endaddr) */ |
| 267 | "dh %x %x\n", /* getmem.cmdw (startaddr, endaddr) */ |
| 268 | "dw %x %x\n", /* getmem.cmdl (startaddr, endaddr) */ |
| 269 | NULL, /* getmem.cmdll (startaddr, endaddr) */ |
| 270 | " ", /* getmem.resp_delim */ |
| 271 | NULL, /* getmem.term */ |
| 272 | NULL, /* getmem.term_cmd */ |
| 273 | }, |
| 274 | { |
| 275 | "r %s %x\n", /* setreg.cmd (name, value) */ |
| 276 | NULL, /* setreg.resp_delim */ |
| 277 | NULL, /* setreg.term */ |
| 278 | NULL, /* setreg.term_cmd */ |
| 279 | }, |
| 280 | { |
| 281 | "r %s\n", /* getreg.cmd (name) */ |
| 282 | "\r", /* getreg.resp_delim */ |
| 283 | NULL, /* getreg.term */ |
| 284 | NULL, /* getreg.term_cmd */ |
| 285 | }, |
| 286 | "r\n", /* dump_registers */ |
| 287 | "\\(\\w+\\)\\( +[0-9a-fA-F]+\\b\\)+", |
| 288 | w89k_supply_register, /* supply_register */ |
| 289 | w89k_load, /* load routine */ |
| 290 | "u %x\n", /* download command */ |
| 291 | "\021", /* load response (^Q) */ |
| 292 | "ROM>", /* monitor command prompt */ |
| 293 | "\n", /* end-of-line terminator */ |
| 294 | NULL, /* optional command terminator */ |
| 295 | &w89k_ops, /* target operations */ |
| 296 | SERIAL_1_STOPBITS, /* number of stop bits */ |
| 297 | w89k_regnames, /* register names */ |
| 298 | MONITOR_OPS_MAGIC /* magic */ |
| 299 | }; |
| 300 | |
| 301 | static void |
| 302 | w89k_open(args, from_tty) |
| 303 | char *args; |
| 304 | int from_tty; |
| 305 | { |
| 306 | monitor_open (args, &w89k_cmds, from_tty); |
| 307 | } |
| 308 | |
| 309 | void |
| 310 | _initialize_w89k () |
| 311 | { |
| 312 | init_monitor_ops (&w89k_ops); |
| 313 | |
| 314 | w89k_ops.to_shortname = "w89k"; |
| 315 | w89k_ops.to_longname = "WinBond's debug monitor for the W89k Eval board"; |
| 316 | w89k_ops.to_doc = "Debug on a WinBond W89K eval board.\n\ |
| 317 | Specify the serial device it is connected to (e.g. /dev/ttya)."; |
| 318 | w89k_ops.to_open = w89k_open; |
| 319 | |
| 320 | add_target (&w89k_ops); |
| 321 | } |