* monitor.c (monitor_expect_regexp): Same as monitor_expect, but
[external/binutils.git] / gdb / sh3-rom.c
1 /* Remote target glue for the Hitachi SH-3 ROM monitor.
2    Copyright 1995 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
19
20 #include "defs.h"
21 #include "gdbcore.h"
22 #include "target.h"
23 #include "monitor.h"
24 #include "serial.h"
25
26 static void sh3_open PARAMS ((char *args, int from_tty));
27
28 static void
29 sh3_supply_register (regname, regnamelen, val, vallen)
30      char *regname;
31      int regnamelen;
32      char *val;
33      int vallen;
34 {
35   int numregs;
36   int regno;
37
38   numregs = 1;
39   regno = -1;
40
41   if (regnamelen == 2)
42     switch (regname[0])
43       {
44       case 'S':
45         if (regname[1] == 'R')
46           regno = SR_REGNUM;
47         break;
48       case 'P':
49         if (regname[1] == 'C')
50           regno = PC_REGNUM;
51         else if (regname[1] == 'R')
52           regno = PR_REGNUM;
53         break;
54       }
55   else if (regnamelen == 3)
56     switch (regname[0])
57       {
58       case 'G':
59       case 'V':
60         if (regname[1] == 'B' && regname[2] == 'R')
61           if (regname[0] == 'G')
62             regno = VBR_REGNUM;
63           else
64             regno = GBR_REGNUM;
65         break;
66 #if 0
67       case 'S':
68         if (regname[1] == 'S' && regname[2] == 'R')
69           regno = SSR_REGNUM;
70         else if (regname[1] == 'P' && regname[2] == 'C')
71           regno = SPC_REGNUM;
72         break;
73 #endif
74       }
75   else if (regnamelen == 4)
76     switch (regname[0])
77       {
78       case 'M':
79         if (regname[1] == 'A' && regname[2] == 'C')
80           if (regname[3] == 'H')
81             regno = MACH_REGNUM;
82           else if (regname[3] == 'L')
83             regno = MACL_REGNUM;
84         break;
85       case 'R':
86         if (regname[1] == '0' && regname[2] == '-' && regname[3] == '7')
87           {
88             regno = R0_REGNUM;
89             numregs = 8;
90           }
91       }
92   else if (regnamelen == 5)
93     if (regname[1] == '8' && regname[2] == '-' && regname[3] == '1'
94         && regname[4] =='5')
95       {
96         regno = R0_REGNUM + 8;
97         numregs = 8;
98       }
99
100   if (regno >= 0)
101     while (numregs-- > 0)
102       val = monitor_supply_register (regno++, val);
103 }
104
105 /* This array of registers need to match the indexes used by GDB.
106    This exists because the various ROM monitors use different strings
107    than does GDB, and don't necessarily support all the registers
108    either. So, typing "info reg sp" becomes a "r30".  */
109
110 static char *sh3_regnames[NUM_REGS] = {
111   "R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7",
112   "R8", "R9", "R10","R11","R12","R13","R14","R15",
113   "PC", "PR", "GBR","VBR","MACH","MACL","SR",NULL,
114   NULL,  NULL, NULL, NULL};
115
116 /* Define the monitor command strings. Since these are passed directly
117    through to a printf style function, we may include formatting
118    strings. We also need a CR or LF on the end.  */
119
120 static struct target_ops sh3_ops;
121
122 static char *sh3_inits[] = {"\003", NULL}; /* Exits sub-command mode & download cmds */
123
124 static struct monitor_ops sh3_cmds =
125 {
126   MO_CLR_BREAK_USES_ADDR
127     | MO_GETMEM_READ_SINGLE,    /* flags */
128   sh3_inits,                    /* monitor init string */
129   "g\r",                        /* continue command */
130   "s\r",                        /* single step */
131   "\003",                       /* Interrupt program */
132   "b %x\r",                     /* set a breakpoint */
133   "b -%x\r",                    /* clear a breakpoint */
134   "b -\r",                      /* clear all breakpoints */
135   "f %x @%x %x\r",              /* fill (start len val) */
136   {
137     "m %x %x\r",                /* setmem.cmdb (addr, value) */
138     "m %x %x;w\r",              /* setmem.cmdw (addr, value) */
139     "m %x %x;l\r",              /* setmem.cmdl (addr, value) */
140     NULL,                       /* setmem.cmdll (addr, value) */
141     NULL,                       /* setreg.resp_delim */
142     NULL,                       /* setreg.term */
143     NULL,                       /* setreg.term_cmd */
144   },
145   {
146     "m %x\r",                   /* getmem.cmdb (addr, len) */
147     "m %x;w\r",                 /* getmem.cmdw (addr, len) */
148     "m %x;l\r",                 /* getmem.cmdl (addr, len) */
149     NULL,                       /* getmem.cmdll (addr, len) */
150     "^ [0-9A-F]+ ",             /* getmem.resp_delim */
151     "? ",                       /* getmem.term */
152     ".\r",                      /* getmem.term_cmd */
153   },
154   {
155     ".%s %x\r",                 /* setreg.cmd (name, value) */
156     NULL,                       /* setreg.resp_delim */
157     NULL,                       /* setreg.term */
158     NULL                        /* setreg.term_cmd */
159   },
160   {
161     ".%s\r",                    /* getreg.cmd (name) */
162     "=",                        /* getreg.resp_delim */
163     "? ",                       /* getreg.term */
164     ".\r"                       /* getreg.term_cmd */
165   },
166   "r\r",                        /* dump_registers */
167                                 /* register_pattern */
168   "\\(\\w+\\)=\\([0-9a-fA-F]+\\( +[0-9a-fA-F]+\\b\\)*\\)",
169   sh3_supply_register,          /* supply_register */
170   NULL,                         /* load_routine (defaults to SRECs) */
171   "il;s:x\r\006",               /* download command */
172   NULL,                         /* Load response */
173   "\n:",                        /* monitor command prompt */
174   "\r",                         /* end-of-line terminator */
175   ".\r",                        /* optional command terminator */
176   &sh3_ops,                     /* target operations */
177   SERIAL_1_STOPBITS,            /* number of stop bits */
178   sh3_regnames,                 /* registers names */
179   MONITOR_OPS_MAGIC             /* magic */
180 };
181
182 static void
183 sh3_open (args, from_tty)
184      char *args;
185      int from_tty;
186 {
187   monitor_open (args, &sh3_cmds, from_tty);
188 }
189
190 void
191 _initialize_sh3 ()
192 {
193   init_monitor_ops (&sh3_ops);
194
195   sh3_ops.to_shortname = "sh3";
196   sh3_ops.to_longname = "Hitachi SH-3 rom monitor";
197   sh3_ops.to_doc = "Debug on a Hitachi eval board running the SH-3 rom monitor.\n\
198 Specify the serial device it is connected to (e.g. /dev/ttya).";
199   sh3_ops.to_open = sh3_open;
200
201   add_target (&sh3_ops);
202 }