GDB (xrefs)
/tmp/gdb-7.10/gdb/microblaze-rom.c
Go to the documentation of this file.
1 /* Remote debugging interface to Xilinx MicroBlaze.
2 
3  Copyright (C) 2009-2015 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 "serial.h"
25 #include "regcache.h"
26 
27 void _initialize_picobug_rom (void);
28 
29 static char *picobug_inits[] =
30 {"\r", NULL};
31 
32 static struct target_ops picobug_ops;
33 static struct monitor_ops picobug_cmds;
34 
35 /* Picobug only supports a subset of registers from MCore. In reality,
36  it doesn't support ss1, either. */
37 static char *picobug_regnames[] = {
38  "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
39  "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
40  0, 0, 0, 0, 0, 0, 0, 0,
41  0, 0, 0, 0, 0, 0, 0, 0,
42  "psr", "vbr", "epsr", "fpsr", "epc", "fpc", 0, "ss1",
43  "ss2", "ss3", "ss4", 0, 0, 0, 0, 0,
44  0, 0, 0, 0, 0, 0, 0, 0,
45  0, 0, 0, 0, 0, 0, 0, 0,
46  "pc" };
47 
48 
49 
50 static void
51 picobug_open (const char *args, int from_tty)
52 {
53  monitor_open (args, &picobug_cmds, from_tty);
54 }
55 /* We choose to write our own dumpregs routine, since the output of
56  the register dumping is rather difficult to encapsulate in a
57  regexp:
58 
59 picobug> rd
60  pc 2f00031e epc 2f00031e fpc 00000000
61  psr 80000101 epsr 80000101 fpsr 00000000
62 ss0-ss4 bad0beef 00000000 00000000 00000000 00000000 vbr 30005c00
63  r0-r7 2f0fff4c 00000090 00000001 00000002 00000003 00000004 00000005 00000006
64  r8-r15 2f0fff64 00000000 00000000 00000000 00000000 00000000 00000000 2f00031e
65 */
66 
67 static int
69 {
70  struct gdbarch *gdbarch = get_regcache_arch (regcache);
71  char buf[1024];
72  int resp_len;
73  char *p;
74 
75  /* Send the dump register command to the monitor and
76  get the reply. */
78  resp_len = monitor_expect_prompt (buf, sizeof (buf));
79 
80  p = strtok (buf, " \t\r\n");
81  while (p)
82  {
83  if (strchr (p, '-'))
84  {
85  /* Got a range. Either r0-r7, r8-r15 or ss0-ss4. */
86  if (startswith (p, "r0") || startswith (p, "r8"))
87  {
88  int rn = (p[1] == '0' ? 0 : 8);
89  int i = 0;
90 
91  /* Get the next 8 values and record them. */
92  while (i < 8)
93  {
94  p = strtok (NULL, " \t\r\n");
95  if (p)
96  monitor_supply_register (regcache, rn + i, p);
97  i++;
98  }
99  }
100  else if (startswith (p, "ss"))
101  {
102  /* Get the next five values, ignoring the first. */
103  int rn;
104  p = strtok (NULL, " \t\r\n");
105  for (rn = 39; rn < 43; rn++)
106  {
107  p = strtok (NULL, " \t\r\n");
108  if (p)
109  monitor_supply_register (regcache, rn, p);
110  }
111  }
112  else
113  {
114  break;
115  }
116  }
117  else
118  {
119  /* Simple register type, paired. */
120  char *name = p;
121  int i;
122 
123  /* Get and record value. */
124  p = strtok (NULL, " \t\r\n");
125  if (p)
126  {
127  for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
128  {
129  if (picobug_regnames[i]
130  && strcmp (picobug_regnames[i], name) == 0)
131  break;
132  }
133 
134  if (i <= gdbarch_num_regs (gdbarch))
135  monitor_supply_register (regcache, i, p);
136  }
137  }
138  p = strtok (NULL, " \t\r\n");
139  }
140 
141  return 0;
142 }
143 
144 static void
146 {
149 
150  picobug_cmds.init = picobug_inits; /* Init strings */
151  picobug_cmds.cont = "g\n"; /* continue command */
152  picobug_cmds.step = "s\n"; /* single step */
153  picobug_cmds.set_break = "br %x\n"; /* set a breakpoint */
154  picobug_cmds.clr_break = "nobr %x\n"; /* clear a breakpoint */
155  picobug_cmds.clr_all_break = "nobr\n"; /* clear all breakpoints */
156  picobug_cmds.setmem.cmdb = "mm %x %x ;b\n"; /* setmem.cmdb (addr, value) */
157  picobug_cmds.setmem.cmdw = "mm %x %x ;h\n"; /* setmem.cmdw (addr, value) */
158  picobug_cmds.setmem.cmdl = "mm %x %x ;w\n"; /* setmem.cmdl (addr, value) */
159  picobug_cmds.getmem.cmdb = "md %x %x\n"; /* getmem.cmdb (start addr,
160  end addr) */
161  picobug_cmds.getmem.resp_delim = ":"; /* getmem.resp_delim */
162  picobug_cmds.setreg.cmd = "rm %s %x\n"; /* setreg.cmd (name, value) */
163  picobug_cmds.getreg.cmd = "rd %s\n"; /* getreg.cmd (name) */
164  picobug_cmds.getreg.resp_delim = ":"; /* getreg.resp_delim */
165  picobug_cmds.dump_registers = "rd\n"; /* dump_registers */
166  picobug_cmds.dumpregs = picobug_dumpregs; /* dump registers parser */
167  picobug_cmds.load = "lo\n"; /* download command */
168  picobug_cmds.prompt = "picobug> "; /* monitor command prompt */
169  picobug_cmds.line_term = "\n"; /* end-of-line terminator */
170  picobug_cmds.target = &picobug_ops; /* target operations */
171  picobug_cmds.stopbits = SERIAL_1_STOPBITS; /* number of stop bits */
172  picobug_cmds.regnames = picobug_regnames; /* registers names */
173  picobug_cmds.num_breakpoints = 20; /* number of breakpoints */
174  picobug_cmds.magic = MONITOR_OPS_MAGIC; /* magic */
175 }
176 
177 void
179 {
180  int i;
181 
182  /* Initialize m32r RevC monitor target. */
185  picobug_ops.to_shortname = "picobug";
186  picobug_ops.to_longname = "picobug monitor";
187  picobug_ops.to_doc = "Debug via the picobug monitor.\n\
188 Specify the serial device it is connected to (e.g. /dev/ttya).";
190 
192 }
void add_target(struct target_ops *t)
Definition: target.c:395
char * cmdl
Definition: monitor.h:60
char ** regnames
Definition: monitor.h:118
char * cmd
Definition: monitor.h:70
int stopbits
Definition: monitor.h:117
void monitor_printf(char *pattern,...)
Definition: monitor.c:328
const char * to_longname
Definition: target.h:433
void _initialize_picobug_rom(void)
char * clr_break
Definition: monitor.h:88
char * prompt
Definition: monitor.h:113
struct memrw_cmd setmem
Definition: monitor.h:91
struct gdbarch * get_regcache_arch(const struct regcache *regcache)
Definition: regcache.c:297
char * resp_delim
Definition: monitor.h:62
char * cmdw
Definition: monitor.h:59
int gdbarch_num_regs(struct gdbarch *gdbarch)
Definition: gdbarch.c:1898
char * cmdb
Definition: monitor.h:58
static struct monitor_ops picobug_cmds
struct regrw_cmd getreg
Definition: monitor.h:94
char * load
Definition: monitor.h:111
const char *const name
Definition: aarch64-tdep.c:68
char * clr_all_break
Definition: monitor.h:89
int(* dumpregs)(struct regcache *)
Definition: monitor.h:105
struct regrw_cmd setreg
Definition: monitor.h:93
int flags
Definition: monitor.h:80
char ** init
Definition: monitor.h:81
#define MO_CLR_BREAK_USES_ADDR
Definition: monitor.h:137
#define MO_PRINT_PROGRAM_OUTPUT
Definition: monitor.h:224
#define MONITOR_OPS_MAGIC
Definition: monitor.h:130
static void init_picobug_cmds(void)
char * step
Definition: monitor.h:83
const char * to_doc
Definition: target.h:434
static int startswith(const char *string, const char *pattern)
Definition: common-utils.h:75
void monitor_open(const char *args, struct monitor_ops *mon_ops, int from_tty)
Definition: monitor.c:700
static struct target_ops picobug_ops
struct memrw_cmd getmem
Definition: monitor.h:92
#define SERIAL_1_STOPBITS
Definition: serial.h:183
void init_monitor_ops(struct target_ops *ops)
Definition: monitor.c:2381
char * dump_registers
Definition: monitor.h:100
static char * picobug_regnames[]
int magic
Definition: monitor.h:124
void(* to_open)(const char *, int)
Definition: target.h:443
char * monitor_supply_register(struct regcache *regcache, int regno, char *valstr)
Definition: monitor.c:874
struct target_ops * target
Definition: monitor.h:116
const char * to_shortname
Definition: target.h:432
static int picobug_dumpregs(struct regcache *regcache)
int num_breakpoints
Definition: monitor.h:122
char * resp_delim
Definition: monitor.h:71
int monitor_expect_prompt(char *buf, int buflen)
Definition: monitor.c:638
static char * picobug_inits[]
static void picobug_open(const char *args, int from_tty)
char * set_break
Definition: monitor.h:85
#define MO_GETMEM_NEEDS_RANGE
Definition: monitor.h:151
char * line_term
Definition: monitor.h:114
char * cont
Definition: monitor.h:82