1 /* Remote debugging interface to Motorola picobug monitor for gdb,
2 the GNU debugger.
3 Copyright 1999, 2000, 2001 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 2 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, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 #include "defs.h"
23 #include "gdbcore.h"
24 #include "target.h"
25 #include "monitor.h"
26 #include "gdb_string.h"
27 #include "regcache.h"
28 #include "serial.h"
29
30 /* Functions used only in this file. */
31
32 static void init_picobug_cmds (void);
33
34
35 /* Functions exported from this file. */
36
37 void _initialize_picobug_rom (void);
38
39 void picobug_open (char *args, int from_tty);
40
41 int picobug_dumpregs (void);
42
43
44 static char *picobug_inits[] =
45 {"\r", NULL};
46
47 static struct target_ops picobug_ops;
48 static struct monitor_ops picobug_cmds;
49
50 /* Picobug only supports a subset of registers from MCore. In reality,
51 it doesn't support ss1, either. */
52 /* *INDENT-OFF* */
53 static char *picobug_regnames[] = {
54 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
55 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
56 0, 0, 0, 0, 0, 0, 0, 0,
57 0, 0, 0, 0, 0, 0, 0, 0,
58 "psr", "vbr", "epsr", "fpsr", "epc", "fpc", 0, "ss1",
59 "ss2", "ss3", "ss4", 0, 0, 0, 0, 0,
60 0, 0, 0, 0, 0, 0, 0, 0,
61 0, 0, 0, 0, 0, 0, 0, 0,
62 "pc" };
63 /* *INDENT-ON* */
64
65
66
67 void
picobug_open(char * args,int from_tty)68 picobug_open (char *args, int from_tty)
69 {
70 monitor_open (args, &picobug_cmds, from_tty);
71 }
72 /* *INDENT-OFF* */
73 /* We choose to write our own dumpregs routine, since the output of
74 the register dumping is rather difficult to encapsulate in a
75 regexp:
76
77 picobug> rd
78 pc 2f00031e epc 2f00031e fpc 00000000
79 psr 80000101 epsr 80000101 fpsr 00000000
80 ss0-ss4 bad0beef 00000000 00000000 00000000 00000000 vbr 30005c00
81 r0-r7 2f0fff4c 00000090 00000001 00000002 00000003 00000004 00000005 00000006
82 r8-r15 2f0fff64 00000000 00000000 00000000 00000000 00000000 00000000 2f00031e */
83 /* *INDENT-ON* */
84
85
86
87 int
picobug_dumpregs(void)88 picobug_dumpregs (void)
89 {
90 char buf[1024];
91 int resp_len;
92 char *p;
93
94 /* Send the dump register command to the monitor and
95 get the reply. */
96 monitor_printf (picobug_cmds.dump_registers);
97 resp_len = monitor_expect_prompt (buf, sizeof (buf));
98
99 p = strtok (buf, " \t\r\n");
100 while (p)
101 {
102 if (strchr (p, '-'))
103 {
104 /* got a range. either r0-r7, r8-r15 or ss0-ss4 */
105 if (DEPRECATED_STREQN (p, "r0", 2) || DEPRECATED_STREQN (p, "r8", 2))
106 {
107 int rn = (p[1] == '0' ? 0 : 8);
108 int i = 0;
109
110 /* Get the next 8 values and record them. */
111 while (i < 8)
112 {
113 p = strtok (NULL, " \t\r\n");
114 if (p)
115 monitor_supply_register (rn + i, p);
116 i++;
117 }
118 }
119 else if (DEPRECATED_STREQN (p, "ss", 2))
120 {
121 /* get the next five values, ignoring the first */
122 int rn;
123 p = strtok (NULL, " \t\r\n");
124 for (rn = 39; rn < 43; rn++)
125 {
126 p = strtok (NULL, " \t\r\n");
127 if (p)
128 monitor_supply_register (rn, p);
129 }
130 }
131 else
132 {
133 break;
134 }
135 }
136 else
137 {
138 /* Simple register type, paired */
139 char *name = p;
140 int i;
141
142 /* Get and record value */
143 p = strtok (NULL, " \t\r\n");
144 if (p)
145 {
146 for (i = 0; i < NUM_REGS; i++)
147 {
148 if (picobug_regnames[i] && DEPRECATED_STREQ (picobug_regnames[i], name))
149 break;
150 }
151
152 if (i <= NUM_REGS)
153 monitor_supply_register (i, p);
154 }
155 }
156 p = strtok (NULL, " \t\r\n");
157 }
158
159 return 0;
160 }
161
162 static void
init_picobug_cmds(void)163 init_picobug_cmds (void)
164 {
165 picobug_cmds.flags = MO_GETMEM_NEEDS_RANGE | MO_CLR_BREAK_USES_ADDR | MO_PRINT_PROGRAM_OUTPUT;
166
167 picobug_cmds.init = picobug_inits; /* Init strings */
168 picobug_cmds.cont = "g\n"; /* continue command */
169 picobug_cmds.step = "s\n"; /* single step */
170 picobug_cmds.set_break = "br %x\n"; /* set a breakpoint */
171 picobug_cmds.clr_break = "nobr %x\n"; /* clear a breakpoint */
172 picobug_cmds.clr_all_break = "nobr\n"; /* clear all breakpoints */
173 picobug_cmds.setmem.cmdb = "mm %x %x ;b\n"; /* setmem.cmdb (addr, value) */
174 picobug_cmds.setmem.cmdw = "mm %x %x ;h\n"; /* setmem.cmdw (addr, value) */
175 picobug_cmds.setmem.cmdl = "mm %x %x ;w\n"; /* setmem.cmdl (addr, value) */
176 picobug_cmds.getmem.cmdb = "md %x %x\n"; /* getmem.cmdb (start addr, end addr) */
177 picobug_cmds.getmem.resp_delim = ":"; /* getmem.resp_delim */
178 picobug_cmds.setreg.cmd = "rm %s %x\n"; /* setreg.cmd (name, value) */
179 picobug_cmds.getreg.cmd = "rd %s\n"; /* getreg.cmd (name) */
180 picobug_cmds.getreg.resp_delim = ":"; /* getreg.resp_delim */
181 picobug_cmds.dump_registers = "rd\n"; /* dump_registers */
182 picobug_cmds.dumpregs = picobug_dumpregs; /* dump registers parser */
183 picobug_cmds.load = "lo\n"; /* download command */
184 picobug_cmds.prompt = "picobug> "; /* monitor command prompt */
185 picobug_cmds.line_term = "\n"; /* end-of-line terminator */
186 picobug_cmds.target = &picobug_ops; /* target operations */
187 picobug_cmds.stopbits = SERIAL_1_STOPBITS; /* number of stop bits */
188 picobug_cmds.regnames = picobug_regnames; /* registers names */
189 picobug_cmds.num_breakpoints = 20; /* number of breakpoints */
190 picobug_cmds.magic = MONITOR_OPS_MAGIC; /* magic */
191 }
192
193 void
_initialize_picobug_rom(void)194 _initialize_picobug_rom (void)
195 {
196 int i;
197
198 /* Initialize m32r RevC monitor target */
199 init_picobug_cmds ();
200 init_monitor_ops (&picobug_ops);
201 picobug_ops.to_shortname = "picobug";
202 picobug_ops.to_longname = "picobug monitor";
203 picobug_ops.to_doc = "Debug via the picobug monitor.\n\
204 Specify the serial device it is connected to (e.g. /dev/ttya).";
205 picobug_ops.to_open = picobug_open;
206
207 add_target (&picobug_ops);
208 }
209