1130812Smarcel/* Remote debugging interface for ABug Rom monitor for GDB, the GNU debugger.
2130812Smarcel   Copyright 1995, 1996, 1998, 1999, 2000, 2001
3130812Smarcel   Free Software Foundation, Inc.
4130812Smarcel
5130812Smarcel   Written by Rob Savoye of Cygnus Support
6130812Smarcel
7130812Smarcel   This file is part of GDB.
8130812Smarcel
9130812Smarcel   This program is free software; you can redistribute it and/or modify
10130812Smarcel   it under the terms of the GNU General Public License as published by
11130812Smarcel   the Free Software Foundation; either version 2 of the License, or
12130812Smarcel   (at your option) any later version.
13130812Smarcel
14130812Smarcel   This program is distributed in the hope that it will be useful,
15130812Smarcel   but WITHOUT ANY WARRANTY; without even the implied warranty of
16130812Smarcel   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17130812Smarcel   GNU General Public License for more details.
18130812Smarcel
19130812Smarcel   You should have received a copy of the GNU General Public License
20130812Smarcel   along with this program; if not, write to the Free Software
21130812Smarcel   Foundation, Inc., 59 Temple Place - Suite 330,
22130812Smarcel   Boston, MA 02111-1307, USA.  */
23130812Smarcel
24130812Smarcel#include "defs.h"
25130812Smarcel#include "gdbcore.h"
26130812Smarcel#include "target.h"
27130812Smarcel#include "monitor.h"
28130812Smarcel#include "serial.h"
29130812Smarcel#include "regcache.h"
30130812Smarcel
31130812Smarcel#include "m68k-tdep.h"
32130812Smarcel
33130812Smarcel/* Prototypes for local functions. */
34130812Smarcel
35130812Smarcelstatic void abug_open (char *args, int from_tty);
36130812Smarcel
37130812Smarcelstatic void
38130812Smarcelabug_supply_register (char *regname, int regnamelen, char *val, int vallen)
39130812Smarcel{
40130812Smarcel  int regno;
41130812Smarcel
42130812Smarcel  if (regnamelen != 2)
43130812Smarcel    return;
44130812Smarcel
45130812Smarcel  switch (regname[0])
46130812Smarcel    {
47130812Smarcel    case 'S':
48130812Smarcel      if (regname[1] != 'R')
49130812Smarcel	return;
50130812Smarcel      regno = PS_REGNUM;
51130812Smarcel      break;
52130812Smarcel    case 'P':
53130812Smarcel      if (regname[1] != 'C')
54130812Smarcel	return;
55130812Smarcel      regno = PC_REGNUM;
56130812Smarcel      break;
57130812Smarcel    case 'D':
58130812Smarcel      if (regname[1] < '0' || regname[1] > '7')
59130812Smarcel	return;
60130812Smarcel      regno = regname[1] - '0' + M68K_D0_REGNUM;
61130812Smarcel      break;
62130812Smarcel    case 'A':
63130812Smarcel      if (regname[1] < '0' || regname[1] > '7')
64130812Smarcel	return;
65130812Smarcel      regno = regname[1] - '0' + M68K_A0_REGNUM;
66130812Smarcel      break;
67130812Smarcel    default:
68130812Smarcel      return;
69130812Smarcel    }
70130812Smarcel
71130812Smarcel  monitor_supply_register (regno, val);
72130812Smarcel}
73130812Smarcel
74130812Smarcel/*
75130812Smarcel * This array of registers needs to match the indexes used by GDB. The
76130812Smarcel * whole reason this exists is because the various ROM monitors use
77130812Smarcel * different names than GDB does, and don't support all the
78130812Smarcel * registers either. So, typing "info reg sp" becomes an "A7".
79130812Smarcel */
80130812Smarcel
81130812Smarcelstatic const char *
82130812Smarcelabug_regname (int index)
83130812Smarcel{
84130812Smarcel  static char *regnames[] =
85130812Smarcel  {
86130812Smarcel    "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
87130812Smarcel    "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7",
88130812Smarcel    "PC",
89130812Smarcel  };
90130812Smarcel
91130812Smarcel  if ((index >= (sizeof (regnames) / sizeof (regnames[0])))
92130812Smarcel       || (index < 0) || (index >= NUM_REGS))
93130812Smarcel    return NULL;
94130812Smarcel  else
95130812Smarcel    return regnames[index];
96130812Smarcel}
97130812Smarcel
98130812Smarcel/*
99130812Smarcel * Define the monitor command strings. Since these are passed directly
100130812Smarcel * through to a printf style function, we need can include formatting
101130812Smarcel * strings. We also need a CR or LF on the end.
102130812Smarcel */
103130812Smarcel
104130812Smarcelstatic struct target_ops abug_ops;
105130812Smarcel
106130812Smarcelstatic char *abug_inits[] =
107130812Smarcel{"\r", NULL};
108130812Smarcel
109130812Smarcelstatic struct monitor_ops abug_cmds;
110130812Smarcel
111130812Smarcelstatic void
112130812Smarcelinit_abug_cmds (void)
113130812Smarcel{
114130812Smarcel  abug_cmds.flags = MO_CLR_BREAK_USES_ADDR;
115130812Smarcel  abug_cmds.init = abug_inits;	/* Init strings */
116130812Smarcel  abug_cmds.cont = "g\r";	/* continue command */
117130812Smarcel  abug_cmds.step = "t\r";	/* single step */
118130812Smarcel  abug_cmds.stop = NULL;	/* interrupt command */
119130812Smarcel  abug_cmds.set_break = "br %x\r";	/* set a breakpoint */
120130812Smarcel  abug_cmds.clr_break = "nobr %x\r";	/* clear a breakpoint */
121130812Smarcel  abug_cmds.clr_all_break = "nobr\r";	/* clear all breakpoints */
122130812Smarcel  abug_cmds.fill = "bf %x:%x %x;b\r";	/* fill (start count val) */
123130812Smarcel  abug_cmds.setmem.cmdb = "ms %x %02x\r";	/* setmem.cmdb (addr, value) */
124130812Smarcel  abug_cmds.setmem.cmdw = "ms %x %04x\r";	/* setmem.cmdw (addr, value) */
125130812Smarcel  abug_cmds.setmem.cmdl = "ms %x %08x\r";	/* setmem.cmdl (addr, value) */
126130812Smarcel  abug_cmds.setmem.cmdll = NULL;	/* setmem.cmdll (addr, value) */
127130812Smarcel  abug_cmds.setmem.resp_delim = NULL;	/* setreg.resp_delim */
128130812Smarcel  abug_cmds.setmem.term = NULL;	/* setreg.term */
129130812Smarcel  abug_cmds.setmem.term_cmd = NULL;	/* setreg.term_cmd */
130130812Smarcel  abug_cmds.getmem.cmdb = "md %x:%x;b\r";	/* getmem.cmdb (addr, len) */
131130812Smarcel  abug_cmds.getmem.cmdw = "md %x:%x;b\r";	/* getmem.cmdw (addr, len) */
132130812Smarcel  abug_cmds.getmem.cmdl = "md %x:%x;b\r";	/* getmem.cmdl (addr, len) */
133130812Smarcel  abug_cmds.getmem.cmdll = NULL;	/* getmem.cmdll (addr, len) */
134130812Smarcel  abug_cmds.getmem.resp_delim = " ";	/* getmem.resp_delim */
135130812Smarcel  abug_cmds.getmem.term = NULL;	/* getmem.term */
136130812Smarcel  abug_cmds.getmem.term_cmd = NULL;	/* getmem.term_cmd */
137130812Smarcel  abug_cmds.setreg.cmd = "rm %s %x\r";	/* setreg.cmd (name, value) */
138130812Smarcel  abug_cmds.setreg.resp_delim = "=";	/* setreg.resp_delim */
139130812Smarcel  abug_cmds.setreg.term = "? ";	/* setreg.term */
140130812Smarcel  abug_cmds.setreg.term_cmd = ".\r";	/* setreg.term_cmd */
141130812Smarcel  abug_cmds.getreg.cmd = "rm %s\r";	/* getreg.cmd (name) */
142130812Smarcel  abug_cmds.getreg.resp_delim = "=";	/* getreg.resp_delim */
143130812Smarcel  abug_cmds.getreg.term = "? ";	/* getreg.term */
144130812Smarcel  abug_cmds.getreg.term_cmd = ".\r";	/* getreg.term_cmd */
145130812Smarcel  abug_cmds.dump_registers = "rd\r";	/* dump_registers */
146130812Smarcel  abug_cmds.register_pattern = "\\(\\w+\\) +=\\([0-9a-fA-F]+\\b\\)";	/* register_pattern */
147130812Smarcel  abug_cmds.supply_register = abug_supply_register;	/* supply_register */
148130812Smarcel  abug_cmds.load_routine = NULL;	/* load_routine (defaults to SRECs) */
149130812Smarcel  abug_cmds.load = "lo 0\r";	/* download command */
150130812Smarcel  abug_cmds.loadresp = "\n";	/* load response */
151130812Smarcel  abug_cmds.prompt = "135Bug>";	/* monitor command prompt */
152130812Smarcel  abug_cmds.line_term = "\r";	/* end-of-line terminator */
153130812Smarcel  abug_cmds.cmd_end = NULL;	/* optional command terminator */
154130812Smarcel  abug_cmds.target = &abug_ops;	/* target operations */
155130812Smarcel  abug_cmds.stopbits = SERIAL_1_STOPBITS;	/* number of stop bits */
156130812Smarcel  abug_cmds.regnames = NULL;	/* registers names */
157130812Smarcel  abug_cmds.regname = abug_regname;
158130812Smarcel  abug_cmds.magic = MONITOR_OPS_MAGIC;	/* magic */
159130812Smarcel};
160130812Smarcel
161130812Smarcelstatic void
162130812Smarcelabug_open (char *args, int from_tty)
163130812Smarcel{
164130812Smarcel  monitor_open (args, &abug_cmds, from_tty);
165130812Smarcel}
166130812Smarcel
167130812Smarcelextern initialize_file_ftype _initialize_abug_rom; /* -Wmissing-prototypes */
168130812Smarcel
169130812Smarcelvoid
170130812Smarcel_initialize_abug_rom (void)
171130812Smarcel{
172130812Smarcel  init_abug_cmds ();
173130812Smarcel  init_monitor_ops (&abug_ops);
174130812Smarcel
175130812Smarcel  abug_ops.to_shortname = "abug";
176130812Smarcel  abug_ops.to_longname = "ABug monitor";
177130812Smarcel  abug_ops.to_doc = "Debug via the ABug monitor.\n\
178130812SmarcelSpecify the serial device it is connected to (e.g. /dev/ttya).";
179130812Smarcel  abug_ops.to_open = abug_open;
180130812Smarcel
181130812Smarcel  add_target (&abug_ops);
182130812Smarcel}
183