| 1 | /* Remote debugging interface to Xilinx MicroBlaze. |
| 2 | |
| 3 | Copyright 2009-2012 Free Software Foundation, Inc. |
| 4 | |
| 5 | This file is part of GDB. |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 3 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 19 | |
| 20 | #include "defs.h" |
| 21 | #include "gdbcore.h" |
| 22 | #include "target.h" |
| 23 | #include "monitor.h" |
| 24 | #include "gdb_string.h" |
| 25 | #include "serial.h" |
| 26 | #include "regcache.h" |
| 27 | |
| 28 | void _initialize_picobug_rom (void); |
| 29 | |
| 30 | static char *picobug_inits[] = |
| 31 | {"\r", NULL}; |
| 32 | |
| 33 | static struct target_ops picobug_ops; |
| 34 | static struct monitor_ops picobug_cmds; |
| 35 | |
| 36 | /* Picobug only supports a subset of registers from MCore. In reality, |
| 37 | it doesn't support ss1, either. */ |
| 38 | static char *picobug_regnames[] = { |
| 39 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 40 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
| 41 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 42 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 43 | "psr", "vbr", "epsr", "fpsr", "epc", "fpc", 0, "ss1", |
| 44 | "ss2", "ss3", "ss4", 0, 0, 0, 0, 0, |
| 45 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 46 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 47 | "pc" }; |
| 48 | |
| 49 | |
| 50 | |
| 51 | static void |
| 52 | picobug_open (char *args, int from_tty) |
| 53 | { |
| 54 | monitor_open (args, &picobug_cmds, from_tty); |
| 55 | } |
| 56 | /* We choose to write our own dumpregs routine, since the output of |
| 57 | the register dumping is rather difficult to encapsulate in a |
| 58 | regexp: |
| 59 | |
| 60 | picobug> rd |
| 61 | pc 2f00031e epc 2f00031e fpc 00000000 |
| 62 | psr 80000101 epsr 80000101 fpsr 00000000 |
| 63 | ss0-ss4 bad0beef 00000000 00000000 00000000 00000000 vbr 30005c00 |
| 64 | r0-r7 2f0fff4c 00000090 00000001 00000002 00000003 00000004 00000005 00000006 |
| 65 | r8-r15 2f0fff64 00000000 00000000 00000000 00000000 00000000 00000000 2f00031e |
| 66 | */ |
| 67 | |
| 68 | static int |
| 69 | picobug_dumpregs (struct regcache *regcache) |
| 70 | { |
| 71 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
| 72 | char buf[1024]; |
| 73 | int resp_len; |
| 74 | char *p; |
| 75 | |
| 76 | /* Send the dump register command to the monitor and |
| 77 | get the reply. */ |
| 78 | monitor_printf (picobug_cmds.dump_registers); |
| 79 | resp_len = monitor_expect_prompt (buf, sizeof (buf)); |
| 80 | |
| 81 | p = strtok (buf, " \t\r\n"); |
| 82 | while (p) |
| 83 | { |
| 84 | if (strchr (p, '-')) |
| 85 | { |
| 86 | /* Got a range. Either r0-r7, r8-r15 or ss0-ss4. */ |
| 87 | if (strncmp (p, "r0", 2) == 0 || strncmp (p, "r8", 2) == 0) |
| 88 | { |
| 89 | int rn = (p[1] == '0' ? 0 : 8); |
| 90 | int i = 0; |
| 91 | |
| 92 | /* Get the next 8 values and record them. */ |
| 93 | while (i < 8) |
| 94 | { |
| 95 | p = strtok (NULL, " \t\r\n"); |
| 96 | if (p) |
| 97 | monitor_supply_register (regcache, rn + i, p); |
| 98 | i++; |
| 99 | } |
| 100 | } |
| 101 | else if (strncmp (p, "ss", 2) == 0) |
| 102 | { |
| 103 | /* Get the next five values, ignoring the first. */ |
| 104 | int rn; |
| 105 | p = strtok (NULL, " \t\r\n"); |
| 106 | for (rn = 39; rn < 43; rn++) |
| 107 | { |
| 108 | p = strtok (NULL, " \t\r\n"); |
| 109 | if (p) |
| 110 | monitor_supply_register (regcache, rn, p); |
| 111 | } |
| 112 | } |
| 113 | else |
| 114 | { |
| 115 | break; |
| 116 | } |
| 117 | } |
| 118 | else |
| 119 | { |
| 120 | /* Simple register type, paired. */ |
| 121 | char *name = p; |
| 122 | int i; |
| 123 | |
| 124 | /* Get and record value. */ |
| 125 | p = strtok (NULL, " \t\r\n"); |
| 126 | if (p) |
| 127 | { |
| 128 | for (i = 0; i < gdbarch_num_regs (gdbarch); i++) |
| 129 | { |
| 130 | if (picobug_regnames[i] |
| 131 | && strcmp (picobug_regnames[i], name) == 0) |
| 132 | break; |
| 133 | } |
| 134 | |
| 135 | if (i <= gdbarch_num_regs (gdbarch)) |
| 136 | monitor_supply_register (regcache, i, p); |
| 137 | } |
| 138 | } |
| 139 | p = strtok (NULL, " \t\r\n"); |
| 140 | } |
| 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | static void |
| 146 | init_picobug_cmds (void) |
| 147 | { |
| 148 | picobug_cmds.flags = MO_GETMEM_NEEDS_RANGE | MO_CLR_BREAK_USES_ADDR |
| 149 | | MO_PRINT_PROGRAM_OUTPUT; |
| 150 | |
| 151 | picobug_cmds.init = picobug_inits; /* Init strings */ |
| 152 | picobug_cmds.cont = "g\n"; /* continue command */ |
| 153 | picobug_cmds.step = "s\n"; /* single step */ |
| 154 | picobug_cmds.set_break = "br %x\n"; /* set a breakpoint */ |
| 155 | picobug_cmds.clr_break = "nobr %x\n"; /* clear a breakpoint */ |
| 156 | picobug_cmds.clr_all_break = "nobr\n"; /* clear all breakpoints */ |
| 157 | picobug_cmds.setmem.cmdb = "mm %x %x ;b\n"; /* setmem.cmdb (addr, value) */ |
| 158 | picobug_cmds.setmem.cmdw = "mm %x %x ;h\n"; /* setmem.cmdw (addr, value) */ |
| 159 | picobug_cmds.setmem.cmdl = "mm %x %x ;w\n"; /* setmem.cmdl (addr, value) */ |
| 160 | picobug_cmds.getmem.cmdb = "md %x %x\n"; /* getmem.cmdb (start addr, |
| 161 | end addr) */ |
| 162 | picobug_cmds.getmem.resp_delim = ":"; /* getmem.resp_delim */ |
| 163 | picobug_cmds.setreg.cmd = "rm %s %x\n"; /* setreg.cmd (name, value) */ |
| 164 | picobug_cmds.getreg.cmd = "rd %s\n"; /* getreg.cmd (name) */ |
| 165 | picobug_cmds.getreg.resp_delim = ":"; /* getreg.resp_delim */ |
| 166 | picobug_cmds.dump_registers = "rd\n"; /* dump_registers */ |
| 167 | picobug_cmds.dumpregs = picobug_dumpregs; /* dump registers parser */ |
| 168 | picobug_cmds.load = "lo\n"; /* download command */ |
| 169 | picobug_cmds.prompt = "picobug> "; /* monitor command prompt */ |
| 170 | picobug_cmds.line_term = "\n"; /* end-of-line terminator */ |
| 171 | picobug_cmds.target = &picobug_ops; /* target operations */ |
| 172 | picobug_cmds.stopbits = SERIAL_1_STOPBITS; /* number of stop bits */ |
| 173 | picobug_cmds.regnames = picobug_regnames; /* registers names */ |
| 174 | picobug_cmds.num_breakpoints = 20; /* number of breakpoints */ |
| 175 | picobug_cmds.magic = MONITOR_OPS_MAGIC; /* magic */ |
| 176 | } |
| 177 | |
| 178 | void |
| 179 | _initialize_picobug_rom (void) |
| 180 | { |
| 181 | int i; |
| 182 | |
| 183 | /* Initialize m32r RevC monitor target. */ |
| 184 | init_picobug_cmds (); |
| 185 | init_monitor_ops (&picobug_ops); |
| 186 | picobug_ops.to_shortname = "picobug"; |
| 187 | picobug_ops.to_longname = "picobug monitor"; |
| 188 | picobug_ops.to_doc = "Debug via the picobug monitor.\n\ |
| 189 | Specify the serial device it is connected to (e.g. /dev/ttya)."; |
| 190 | picobug_ops.to_open = picobug_open; |
| 191 | |
| 192 | add_target (&picobug_ops); |
| 193 | } |