GDB (xrefs)
/tmp/gdb-7.10/gdb/dbug-rom.c
Go to the documentation of this file.
1 /* Remote debugging interface to dBUG ROM monitor for GDB, the GNU debugger.
2  Copyright (C) 1996-2015 Free Software Foundation, Inc.
3 
4  Written by Stan Shebs of Cygnus Support.
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 3 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, see <http://www.gnu.org/licenses/>. */
20 
21 /* dBUG is a monitor supplied on various Motorola boards, including
22  m68k, ColdFire, and PowerPC-based designs. The code here assumes
23  the ColdFire, and (as of 9/25/96) has only been tested with a
24  ColdFire IDP board. */
25 
26 #include "defs.h"
27 #include "gdbcore.h"
28 #include "target.h"
29 #include "monitor.h"
30 #include "serial.h"
31 #include "regcache.h"
32 
33 #include "m68k-tdep.h"
34 
35 static void
37  int regnamelen, char *val, int vallen)
38 {
39  int regno;
40  struct gdbarch *gdbarch = get_regcache_arch (regcache);
41 
42  if (regnamelen != 2)
43  return;
44 
45  switch (regname[0])
46  {
47  case 'S':
48  if (regname[1] != 'R')
49  return;
50  regno = gdbarch_ps_regnum (gdbarch);
51  break;
52  case 'P':
53  if (regname[1] != 'C')
54  return;
55  regno = gdbarch_pc_regnum (gdbarch);
56  break;
57  case 'D':
58  if (regname[1] < '0' || regname[1] > '7')
59  return;
60  regno = regname[1] - '0' + M68K_D0_REGNUM;
61  break;
62  case 'A':
63  if (regname[1] < '0' || regname[1] > '7')
64  return;
65  regno = regname[1] - '0' + M68K_A0_REGNUM;
66  break;
67  default:
68  return;
69  }
70 
71  monitor_supply_register (regcache, regno, val);
72 }
73 
74 /* This array of registers needs to match the indexes used by GDB.
75  The whole reason this exists is because the various ROM monitors
76  use different names than GDB does, and don't support all the
77  registers either. So, typing "info reg sp" becomes an "A7". */
78 
79 static const char *
80 dbug_regname (int index)
81 {
82  static char *regnames[] =
83  {
84  "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
85  "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7",
86  "SR", "PC"
87  /* no float registers */
88  };
89 
90  if (index >= ARRAY_SIZE (regnames) || index < 0)
91  return NULL;
92  else
93  return regnames[index];
94 
95 }
96 
97 static struct target_ops dbug_ops;
98 static struct monitor_ops dbug_cmds;
99 
100 static char *dbug_inits[] =
101 {"\r", NULL};
102 
103 
104 static void
106 {
109  dbug_cmds.init = dbug_inits; /* Init strings */
110  dbug_cmds.cont = "go\r"; /* continue command */
111  dbug_cmds.step = "trace\r"; /* single step */
112  dbug_cmds.stop = NULL; /* interrupt command */
113  dbug_cmds.set_break = "br %x\r"; /* set a breakpoint */
114  dbug_cmds.clr_break = "br -r %x\r"; /* clear a breakpoint */
115  dbug_cmds.clr_all_break = "br -r\r"; /* clear all breakpoints */
116  dbug_cmds.fill = "bf.b %x %x %x\r"; /* fill (start end val) */
117  dbug_cmds.setmem.cmdb = "mm.b %x %x\r"; /* setmem.cmdb (addr, value) */
118  dbug_cmds.setmem.cmdw = "mm.w %x %x\r"; /* setmem.cmdw (addr, value) */
119  dbug_cmds.setmem.cmdl = "mm.l %x %x\r"; /* setmem.cmdl (addr, value) */
120  dbug_cmds.setmem.cmdll = NULL; /* setmem.cmdll (addr, value) */
121  dbug_cmds.setmem.resp_delim = NULL; /* setmem.resp_delim */
122  dbug_cmds.setmem.term = NULL; /* setmem.term */
123  dbug_cmds.setmem.term_cmd = NULL; /* setmem.term_cmd */
124  dbug_cmds.getmem.cmdb = "md.b %x %x\r"; /* getmem.cmdb (addr, addr2) */
125  dbug_cmds.getmem.cmdw = "md.w %x %x\r"; /* getmem.cmdw (addr, addr2) */
126  dbug_cmds.getmem.cmdl = "md.l %x %x\r"; /* getmem.cmdl (addr, addr2) */
127  dbug_cmds.getmem.cmdll = NULL; /* getmem.cmdll (addr, addr2) */
128  dbug_cmds.getmem.resp_delim = ":"; /* getmem.resp_delim */
129  dbug_cmds.getmem.term = NULL; /* getmem.term */
130  dbug_cmds.getmem.term_cmd = NULL; /* getmem.term_cmd */
131  dbug_cmds.setreg.cmd = "rm %s %x\r"; /* setreg.cmd (name, value) */
132  dbug_cmds.setreg.resp_delim = NULL; /* setreg.resp_delim */
133  dbug_cmds.setreg.term = NULL; /* setreg.term */
134  dbug_cmds.setreg.term_cmd = NULL; /* setreg.term_cmd */
135  dbug_cmds.getreg.cmd = "rd %s\r"; /* getreg.cmd (name) */
136  dbug_cmds.getreg.resp_delim = ":"; /* getreg.resp_delim */
137  dbug_cmds.getreg.term = NULL; /* getreg.term */
138  dbug_cmds.getreg.term_cmd = NULL; /* getreg.term_cmd */
139  dbug_cmds.dump_registers = "rd\r"; /* dump_registers */
140  /* register_pattern */
141  dbug_cmds.register_pattern = "\\(\\w+\\) +:\\([0-9a-fA-F]+\\b\\)";
143  dbug_cmds.load = "dl\r"; /* download command */
144  dbug_cmds.loadresp = "\n"; /* load response */
145  dbug_cmds.prompt = "dBUG>"; /* monitor command prompt */
146  dbug_cmds.line_term = "\r"; /* end-of-line terminator */
147  dbug_cmds.cmd_end = NULL; /* optional command terminator */
148  dbug_cmds.target = &dbug_ops; /* target operations */
149  dbug_cmds.stopbits = SERIAL_1_STOPBITS; /* number of stop bits */
150  dbug_cmds.regnames = NULL; /* registers names */
152  dbug_cmds.magic = MONITOR_OPS_MAGIC; /* magic */
153 } /* init_debug_ops */
154 
155 static void
156 dbug_open (const char *args, int from_tty)
157 {
158  monitor_open (args, &dbug_cmds, from_tty);
159 }
160 
161 extern initialize_file_ftype _initialize_dbug_rom; /* -Wmissing-prototypes */
162 
163 void
165 {
166  init_dbug_cmds ();
168 
169  dbug_ops.to_shortname = "dbug";
170  dbug_ops.to_longname = "dBUG monitor";
171  dbug_ops.to_doc = "Debug via the dBUG monitor.\n\
172 Specify the serial device it is connected to (e.g. /dev/ttya).";
174 
175  add_target (&dbug_ops);
176 }
void add_target(struct target_ops *t)
Definition: target.c:395
char * cmdl
Definition: monitor.h:60
char ** regnames
Definition: monitor.h:118
static char * dbug_inits[]
Definition: dbug-rom.c:100
char * cmd
Definition: monitor.h:70
int stopbits
Definition: monitor.h:117
const char * to_longname
Definition: target.h:433
char * clr_break
Definition: monitor.h:88
char * prompt
Definition: monitor.h:113
char * stop
Definition: monitor.h:84
struct memrw_cmd setmem
Definition: monitor.h:91
struct gdbarch * get_regcache_arch(const struct regcache *regcache)
Definition: regcache.c:297
char * loadresp
Definition: monitor.h:112
char * resp_delim
Definition: monitor.h:62
#define MO_FILL_USES_ADDR
Definition: monitor.h:142
char * cmdw
Definition: monitor.h:59
char * cmdb
Definition: monitor.h:58
int gdbarch_ps_regnum(struct gdbarch *gdbarch)
Definition: gdbarch.c:2015
static struct target_ops dbug_ops
Definition: dbug-rom.c:97
void(* supply_register)(struct regcache *regcache, char *name, int namelen, char *val, int vallen)
Definition: monitor.h:103
struct regrw_cmd getreg
Definition: monitor.h:94
char * load
Definition: monitor.h:111
static void dbug_open(const char *args, int from_tty)
Definition: dbug-rom.c:156
void initialize_file_ftype(void)
Definition: defs.h:281
char * clr_all_break
Definition: monitor.h:89
char * cmdll
Definition: monitor.h:61
char * term
Definition: monitor.h:63
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 MONITOR_OPS_MAGIC
Definition: monitor.h:130
char * step
Definition: monitor.h:83
const char * to_doc
Definition: target.h:434
static void dbug_supply_register(struct regcache *regcache, char *regname, int regnamelen, char *val, int vallen)
Definition: dbug-rom.c:36
static void init_dbug_cmds(void)
Definition: dbug-rom.c:105
void monitor_open(const char *args, struct monitor_ops *mon_ops, int from_tty)
Definition: monitor.c:700
char * term
Definition: monitor.h:73
struct memrw_cmd getmem
Definition: monitor.h:92
char * register_pattern
Definition: monitor.h:101
#define SERIAL_1_STOPBITS
Definition: serial.h:183
initialize_file_ftype _initialize_dbug_rom
void init_monitor_ops(struct target_ops *ops)
Definition: monitor.c:2381
static struct monitor_ops dbug_cmds
Definition: dbug-rom.c:98
char * dump_registers
Definition: monitor.h:100
char * term_cmd
Definition: monitor.h:74
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
char * fill
Definition: monitor.h:90
int gdbarch_pc_regnum(struct gdbarch *gdbarch)
Definition: gdbarch.c:1998
static const char * dbug_regname(int index)
Definition: dbug-rom.c:80
char * resp_delim
Definition: monitor.h:71
char * set_break
Definition: monitor.h:85
#define MO_GETMEM_NEEDS_RANGE
Definition: monitor.h:151
const char *(* regname)(int index)
Definition: monitor.h:120
char * line_term
Definition: monitor.h:114
char * cont
Definition: monitor.h:82
char * cmd_end
Definition: monitor.h:115
char * term_cmd
Definition: monitor.h:64