1798Swollman/* Remote debugging interface for EST-300 ICE, for GDB
2798Swollman   Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001
3798Swollman   Free Software Foundation, Inc.
4798Swollman   Contributed by Cygnus Support.
5798Swollman
6798Swollman   Written by Steve Chamberlain for Cygnus Support.
7798Swollman   Re-written by Stu Grossman of Cygnus Support
8798Swollman
9798Swollman   This file is part of GDB.
10798Swollman
11798Swollman   This program is free software; you can redistribute it and/or modify
12798Swollman   it under the terms of the GNU General Public License as published by
13798Swollman   the Free Software Foundation; either version 2 of the License, or
14798Swollman   (at your option) any later version.
15798Swollman
16798Swollman   This program is distributed in the hope that it will be useful,
17798Swollman   but WITHOUT ANY WARRANTY; without even the implied warranty of
18798Swollman   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19798Swollman   GNU General Public License for more details.
20798Swollman
21798Swollman   You should have received a copy of the GNU General Public License
22798Swollman   along with this program; if not, write to the Free Software
23798Swollman   Foundation, Inc., 59 Temple Place - Suite 330,
24798Swollman   Boston, MA 02111-1307, USA.  */
25798Swollman
26798Swollman#include "defs.h"
27798Swollman#include "gdbcore.h"
28798Swollman#include "target.h"
29798Swollman#include "monitor.h"
3050477Speter#include "serial.h"
31798Swollman#include "regcache.h"
32798Swollman
33798Swollman#include "m68k-tdep.h"
34798Swollman
35798Swollmanstatic void est_open (char *args, int from_tty);
36798Swollman
3712472Sbdestatic void
3812472Sbdeest_supply_register (char *regname, int regnamelen, char *val, int vallen)
39798Swollman{
40174910Srwatson  int regno;
41174910Srwatson
42174910Srwatson  if (regnamelen != 2)
43174910Srwatson    return;
441549Srgrimes
45798Swollman  switch (regname[0])
46183054Ssam    {
47183054Ssam    case 'S':
48183054Ssam      if (regname[1] != 'R')
49147745Smarcel	return;
50147745Smarcel      regno = PS_REGNUM;
51147745Smarcel      break;
52147745Smarcel    case 'P':
53174914Srwatson      if (regname[1] != 'C')
54174914Srwatson	return;
55174914Srwatson      regno = PC_REGNUM;
56174914Srwatson      break;
57174914Srwatson    case 'D':
58174914Srwatson      if (regname[1] < '0' || regname[1] > '7')
59174914Srwatson	return;
60174914Srwatson      regno = regname[1] - '0' + M68K_D0_REGNUM;
61174914Srwatson      break;
62174914Srwatson    case 'A':
63174914Srwatson      if (regname[1] < '0' || regname[1] > '7')
64174914Srwatson	return;
65174914Srwatson      regno = regname[1] - '0' + M68K_A0_REGNUM;
66174914Srwatson      break;
67174914Srwatson    default:
68174914Srwatson      return;
69174914Srwatson    }
70174914Srwatson
71174914Srwatson  monitor_supply_register (regno, val);
72174914Srwatson}
73147745Smarcel
74147745Smarcel/*
75147745Smarcel * This array of registers needs to match the indexes used by GDB. The
76147745Smarcel * whole reason this exists is because the various ROM monitors use
77147745Smarcel * different names than GDB does, and don't support all the
78147745Smarcel * registers either. So, typing "info reg sp" becomes a "r30".
79183054Ssam */
80183054Ssam
81183054Ssamstatic const char *
82183054Ssamest_regname (int index)
83183054Ssam{
84183054Ssam
85183054Ssam  static char *regnames[] =
86183054Ssam  {
87183054Ssam    "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
88183054Ssam    "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7",
89183054Ssam    "SR", "PC",
90183054Ssam  };
91183054Ssam
92183054Ssam
93183054Ssam  if ((index >= (sizeof (regnames) /  sizeof (regnames[0])))
94183054Ssam       || (index < 0) || (index >= NUM_REGS))
95183054Ssam    return NULL;
96183054Ssam  else
9793009Sbde    return regnames[index];
9893009Sbde}
9912472Sbde
100183054Ssam/*
101183054Ssam * Define the monitor command strings. Since these are passed directly
102183054Ssam * through to a printf style function, we need can include formatting
103183054Ssam * strings. We also need a CR or LF on the end.
104183054Ssam */
105183054Ssam
106183054Ssamstatic struct target_ops est_ops;
107183054Ssam
108183054Ssamstatic char *est_inits[] =
109183054Ssam{"he\r",			/* Resets the prompt, and clears repeated cmds */
110183054Ssam NULL};
111183054Ssam
112183054Ssamstatic struct monitor_ops est_cmds;
113183054Ssam
11418296Sbdestatic void
115183054Ssaminit_est_cmds (void)
116183054Ssam{
117183054Ssam  est_cmds.flags = MO_CLR_BREAK_USES_ADDR | MO_FILL_USES_ADDR | MO_NEED_REGDUMP_AFTER_CONT |
118183054Ssam    MO_SREC_ACK | MO_SREC_ACK_PLUS;
119183054Ssam  est_cmds.init = est_inits;	/* Init strings */
120183054Ssam  est_cmds.cont = "go\r";	/* continue command */
121264210Spfg  est_cmds.step = "sidr\r";	/* single step */
122183054Ssam  est_cmds.stop = "\003";	/* ^C interrupts the program */
123183054Ssam  est_cmds.set_break = "sb %x\r";	/* set a breakpoint */
124183054Ssam  est_cmds.clr_break = "rb %x\r";	/* clear a breakpoint */
125183054Ssam  est_cmds.clr_all_break = "rb\r";	/* clear all breakpoints */
126183054Ssam  est_cmds.fill = "bfb %x %x %x\r";	/* fill (start end val) */
12718296Sbde  est_cmds.setmem.cmdb = "smb %x %x\r";		/* setmem.cmdb (addr, value) */
128183054Ssam  est_cmds.setmem.cmdw = "smw %x %x\r";		/* setmem.cmdw (addr, value) */
129183054Ssam  est_cmds.setmem.cmdl = "sml %x %x\r";		/* setmem.cmdl (addr, value) */
130183054Ssam  est_cmds.setmem.cmdll = NULL;	/* setmem.cmdll (addr, value) */
131183054Ssam  est_cmds.setmem.resp_delim = NULL;	/* setreg.resp_delim */
132183054Ssam  est_cmds.setmem.term = NULL;	/* setreg.term */
133183054Ssam  est_cmds.setmem.term_cmd = NULL;	/* setreg.term_cmd */
134183054Ssam  est_cmds.getmem.cmdb = "dmb %x %x\r";		/* getmem.cmdb (addr, len) */
135183054Ssam  est_cmds.getmem.cmdw = "dmw %x %x\r";		/* getmem.cmdw (addr, len) */
136156412Sjhb  est_cmds.getmem.cmdl = "dml %x %x\r";		/* getmem.cmdl (addr, len) */
137183054Ssam  est_cmds.getmem.cmdll = NULL;	/* getmem.cmdll (addr, len) */
138183054Ssam  est_cmds.getmem.resp_delim = ": ";	/* getmem.resp_delim */
139183054Ssam  est_cmds.getmem.term = NULL;	/* getmem.term */
140183054Ssam  est_cmds.getmem.term_cmd = NULL;	/* getmem.term_cmd */
141183054Ssam  est_cmds.setreg.cmd = "sr %s %x\r";	/* setreg.cmd (name, value) */
142183054Ssam  est_cmds.setreg.resp_delim = NULL;	/* setreg.resp_delim */
143183054Ssam  est_cmds.setreg.term = NULL;	/* setreg.term */
144183054Ssam  est_cmds.setreg.term_cmd = NULL;	/* setreg.term_cmd */
145183054Ssam  est_cmds.getreg.cmd = "dr %s\r";	/* getreg.cmd (name) */
146183054Ssam  est_cmds.getreg.resp_delim = " = ";	/* getreg.resp_delim */
147183054Ssam  est_cmds.getreg.term = NULL;	/* getreg.term */
148264210Spfg  est_cmds.getreg.term_cmd = NULL;	/* getreg.term_cmd */
149183054Ssam  est_cmds.dump_registers = "dr\r";	/* dump_registers */
150183054Ssam  est_cmds.register_pattern = "\\(\\w+\\) = \\([0-9a-fA-F]+\\)";	/* register_pattern */
15118296Sbde  est_cmds.supply_register = est_supply_register;	/* supply_register */
152183054Ssam  est_cmds.load_routine = NULL;	/* load_routine (defaults to SRECs) */
15318296Sbde  est_cmds.load = "dl\r";	/* download command */
154183054Ssam  est_cmds.loadresp = "+";	/* load response */
155264210Spfg  est_cmds.prompt = ">BKM>";	/* monitor command prompt */
156183054Ssam  est_cmds.line_term = "\r";	/* end-of-line terminator */
157183054Ssam  est_cmds.cmd_end = NULL;	/* optional command terminator */
158264210Spfg  est_cmds.target = &est_ops;	/* target operations */
159183054Ssam  est_cmds.stopbits = SERIAL_1_STOPBITS;	/* number of stop bits */
160264210Spfg  est_cmds.regnames = NULL;
161183054Ssam  est_cmds.regname = est_regname; /*register names*/
162264210Spfg  est_cmds.magic = MONITOR_OPS_MAGIC;	/* magic */
163183054Ssam}				/* init_est_cmds */
164264210Spfg
165183054Ssamstatic void
166264210Spfgest_open (char *args, int from_tty)
167183054Ssam{
168264210Spfg  monitor_open (args, &est_cmds, from_tty);
169183054Ssam}
170183054Ssam
17137504Sbdeextern initialize_file_ftype _initialize_est; /* -Wmissing-prototypes */
17218296Sbde
173798Swollmanvoid
174798Swollman_initialize_est (void)
175798Swollman{
176160312Sjhb  init_est_cmds ();
17737504Sbde  init_monitor_ops (&est_ops);
17837504Sbde
17937504Sbde  est_ops.to_shortname = "est";
180137117Sjhb  est_ops.to_longname = "EST background debug monitor";
181798Swollman  est_ops.to_doc = "Debug via the EST BDM.\n\
182131952SmarcelSpecify the serial device it is connected to (e.g. /dev/ttya).";
18318296Sbde  est_ops.to_open = est_open;
18412472Sbde
18592756Salfred  add_target (&est_ops);
18692756Salfred}
18792756Salfred