This commit was generated by cvs2svn to track changes on a CVS vendor
[external/binutils.git] / gdb / w89k-rom.c
1 /* Remote target glue for the WinBond ROM monitor running on the "Cougar"
2    W89k eval board.
3
4    Copyright 1995 Free Software Foundation, Inc.
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 2 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, write to the Free Software
20    Foundation, Inc., 59 Temple Place - Suite 330,
21    Boston, MA 02111-1307, USA.  */
22
23 #include "defs.h"
24 #include "gdbcore.h"
25 #include "target.h"
26 #include "monitor.h"
27 #include "serial.h"
28 #include "xmodem.h"
29
30
31 static void w89k_open PARAMS ((char *args, int from_tty));
32
33 /*
34  * this array of registers need to match the indexes used by GDB. The
35  * whole reason this exists is cause the various ROM monitors use
36  * different strings than GDB does, and doesn't support all the
37  * registers either. So, typing "info reg sp" becomes a "r30".
38  */
39
40 static char *w89k_regnames[NUM_REGS] =
41 {
42   "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
43   "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
44   "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
45   "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
46   "SAR", "PC", NULL, NULL, NULL, "EIEM", "IIR", "IVA",
47   "IOR", "IPSW", NULL, NULL, NULL, NULL, NULL,
48   NULL, NULL, NULL, NULL, NULL, NULL, NULL,
49   "CCR", NULL, NULL, "TR0", "TR1",
50 };
51
52 static void
53 w89k_supply_register (regname, regnamelen, val, vallen)
54      char *regname;
55      int regnamelen;
56      char *val;
57      int vallen;
58 {
59   int numregs;
60   int regno;
61
62   numregs = 1;
63   regno = -1;
64
65   if (regnamelen == 2)
66     switch (regname[0])
67       {
68       case 'r':
69         numregs = 4;
70         switch (regname[1])
71           {
72           case '0':
73             regno = R0_REGNUM;
74             break;
75           case '4':
76             regno = R0_REGNUM + 4;
77             break;
78           case '8':
79             regno = R0_REGNUM + 8;
80             break;
81           }
82         break;
83       case 'P':
84         if (regname[1] == 'C')
85           regno = PC_REGNUM;
86         break;
87       }
88   else if (regnamelen == 3)
89     switch (regname[0])
90       {
91       case 'r':
92         numregs = 4;
93         if (regname[1] == '1' && regname[2] == '2')
94           regno = R0_REGNUM + 12;
95         else if (regname[1] == '1' && regname[2] == '6')
96           regno = R0_REGNUM + 16;
97         else if (regname[1] == '2' && regname[2] == '0')
98           regno = R0_REGNUM + 20;
99         else if (regname[1] == '2' && regname[2] == '4')
100           regno = R0_REGNUM + 24;
101         else if (regname[1] == '2' && regname[2] == '8')
102           regno = R0_REGNUM + 28;
103         break;
104       case 'R':
105         if (regname[1] == 'C' && regname[2] == 'R')
106           regno = RCR_REGNUM;
107         break;
108       case 'C':
109         if (regname[1] == 'C' && regname[2] == 'R')
110           regno = CCR_REGNUM;
111         break;
112       case 'S':
113         if (regname[1] == 'A' && regname[2] == 'R')
114           regno = SAR_REGNUM;
115         break;
116       case 'I':
117         if (regname[1] == 'I' && regname[2] == 'R')
118           regno = IIR_REGNUM;
119         else if (regname[1] == 'O' && regname[2] == 'R')
120           regno = IOR_REGNUM;
121         break;
122       case 'T':
123         numregs = 4;
124         if (regname[1] == 'R')
125           if (regname[2] == '0')
126             regno = TR0_REGNUM;
127           else if (regname[2] == '4')
128             regno = TR0_REGNUM + 4;
129         break;
130       }
131   else if (regnamelen == 4)
132     switch (regname[0])
133       {
134       case 'E':
135         if (regname[1] == 'I')
136           if (regname[2] == 'E' && regname[3] == 'M')
137             regno = EIEM_REGNUM;
138         break;
139       case 'I':
140         if (regname[1] == 'P' && regname[2] == 'S' && regname[3] == 'W')
141           regno = IPSW_REGNUM;
142         break;
143       }
144   else if (regnamelen == 5)
145     switch (regname[0])
146       {
147       case 'I':
148         if (regname[1] == 'A'
149             && regname[2] == 'O'
150             && regname[3] == 'Q'
151             && regname[4] == 'B')
152           regno = PCOQ_TAIL_REGNUM;
153         break;
154       }
155
156   if (regno >= 0)
157     while (numregs-- > 0)
158       val = monitor_supply_register (regno++, val);
159 }
160
161 static int hashmark = 1;        /* flag set by "set hash" */
162
163 extern struct monitor_ops w89k_cmds;    /* fwd decl */
164
165 static void
166 w89k_load (desc, file, hashmark)
167      serial_t desc;
168      char *file;
169      int hashmark;
170 {
171   bfd *abfd;
172   asection *s;
173   char *buffer;
174   int i;
175
176   buffer = alloca (XMODEM_PACKETSIZE);
177
178   abfd = bfd_openr (file, 0);
179   if (!abfd)
180     {
181       printf_filtered ("Unable to open file %s\n", file);
182       return;
183     }
184
185   if (bfd_check_format (abfd, bfd_object) == 0)
186     {
187       printf_filtered ("File is not an object file\n");
188       return;
189     }
190
191   for (s = abfd->sections; s; s = s->next)
192     if (s->flags & SEC_LOAD)
193       {
194         bfd_size_type section_size;
195
196         printf_filtered ("%s\t: 0x%4x .. 0x%4x  ", s->name, s->vma,
197                          s->vma + s->_raw_size);
198         gdb_flush (gdb_stdout);
199
200         monitor_printf (w89k_cmds.load, s->vma);
201         if (w89k_cmds.loadresp)
202           monitor_expect (w89k_cmds.loadresp, NULL, 0);
203
204         xmodem_init_xfer (desc);
205
206         section_size = bfd_section_size (abfd, s);
207
208         for (i = 0; i < section_size; i += XMODEM_DATASIZE)
209           {
210             int numbytes;
211
212             numbytes = min (XMODEM_DATASIZE, section_size - i);
213
214             bfd_get_section_contents (abfd, s, buffer + XMODEM_DATAOFFSET, i,
215                                       numbytes);
216
217             xmodem_send_packet (desc, buffer, numbytes, hashmark);
218
219             if (hashmark)
220               {
221                 putchar_unfiltered ('#');
222                 gdb_flush (gdb_stdout);
223               }
224           }                     /* Per-packet (or S-record) loop */
225
226         xmodem_finish_xfer (desc);
227
228         monitor_expect_prompt (NULL, 0);
229
230         putchar_unfiltered ('\n');
231       }                         /* Loadable sections */
232
233   if (hashmark)
234     putchar_unfiltered ('\n');
235 }
236
237 /*
238  * Define the monitor command strings. Since these are passed directly
239  * through to a printf style function, we need can include formatting
240  * strings. We also need a CR or LF on the end.
241  */
242
243 static struct target_ops w89k_ops;
244
245 static char *w89k_inits[] =
246 {"\n", NULL};
247
248 static struct monitor_ops w89k_cmds;
249 static void
250 init_w89k_cmds (void)
251 {
252   w89k_cmds.flags = MO_GETMEM_NEEDS_RANGE | MO_FILL_USES_ADDR;  /* flags */
253   w89k_cmds.init = w89k_inits;  /* Init strings */
254   w89k_cmds.cont = "g\n";       /* continue command */
255   w89k_cmds.step = "t\n";       /* single step */
256   w89k_cmds.stop = "\003";      /* Interrupt char (^C) */
257   w89k_cmds.set_break = "bp %x\n";      /* set a breakpoint */
258   w89k_cmds.clr_break = "bc %x\n";      /* clear a breakpoint */
259   w89k_cmds.clr_all_break = "bc *\n";   /* clear all breakpoints */
260   w89k_cmds.fill = "f %x %x %x\n";      /* memory fill cmd */
261   w89k_cmds.setmem.cmdb = "eb %x %x\n";         /* setmem.cmdb (addr, value) */
262   w89k_cmds.setmem.cmdw = "eh %x %x\n";         /* setmem.cmdw (addr, value) */
263   w89k_cmds.setmem.cmdl = "ew %x %x\n";         /* setmem.cmdl (addr, value) */
264   w89k_cmds.setmem.cmdll = NULL;        /* setmem.cmdll (addr, value) */
265   w89k_cmds.setmem.resp_delim = NULL;   /* setreg.resp_delim */
266   w89k_cmds.setmem.term = NULL; /* setreg.term */
267   w89k_cmds.setmem.term_cmd = NULL;     /* setreg.term_cmd */
268   w89k_cmds.getmem.cmdb = "db %x %x\n";         /* getmem.cmdb (startaddr, endaddr) */
269   w89k_cmds.getmem.cmdw = "dh %x %x\n";         /* getmem.cmdw (startaddr, endaddr) */
270   w89k_cmds.getmem.cmdl = "dw %x %x\n";         /* getmem.cmdl (startaddr, endaddr) */
271   w89k_cmds.getmem.cmdll = NULL;        /* getmem.cmdll (startaddr, endaddr) */
272   w89k_cmds.getmem.resp_delim = "  ";   /* getmem.resp_delim */
273   w89k_cmds.getmem.term = NULL; /* getmem.term */
274   w89k_cmds.getmem.term_cmd = NULL;     /* getmem.term_cmd */
275   w89k_cmds.setreg.cmd = "r %s %x\n";   /* setreg.cmd (name, value) */
276   w89k_cmds.setreg.resp_delim = NULL;   /* setreg.resp_delim */
277   w89k_cmds.setreg.term = NULL; /* setreg.term */
278   w89k_cmds.setreg.term_cmd = NULL;     /* setreg.term_cmd */
279   w89k_cmds.getreg.cmd = "r %s\n";      /* getreg.cmd (name) */
280   w89k_cmds.getreg.resp_delim = "\r";   /* getreg.resp_delim */
281   w89k_cmds.getreg.term = NULL; /* getreg.term */
282   w89k_cmds.getreg.term_cmd = NULL;     /* getreg.term_cmd */
283   w89k_cmds.dump_registers = "r\n";     /* dump_registers */
284   w89k_cmds.register_pattern = "\\(\\w+\\)\\( +[0-9a-fA-F]+\\b\\)+";
285   w89k_cmds.supply_register = w89k_supply_register;     /* supply_register */
286   w89k_cmds.load_routine = w89k_load;   /* load routine */
287   w89k_cmds.load = "u %x\n";    /* download command */
288   w89k_cmds.loadresp = "\021";  /* load response (^Q) */
289   w89k_cmds.prompt = "ROM>";    /* monitor command prompt */
290   w89k_cmds.line_term = "\n";   /* end-of-line terminator */
291   w89k_cmds.cmd_end = NULL;     /* optional command terminator */
292   w89k_cmds.target = &w89k_ops; /* target operations */
293   w89k_cmds.stopbits = SERIAL_1_STOPBITS;       /* number of stop bits */
294   w89k_cmds.regnames = w89k_regnames;   /* register names */
295   w89k_cmds.magic = MONITOR_OPS_MAGIC;  /* magic */
296 }                               /* init_w89k_cmds */
297
298 static void
299 w89k_open (args, from_tty)
300      char *args;
301      int from_tty;
302 {
303   monitor_open (args, &w89k_cmds, from_tty);
304 }
305
306 void
307 _initialize_w89k ()
308 {
309   init_w89k_cmds ();
310   init_monitor_ops (&w89k_ops);
311
312   w89k_ops.to_shortname = "w89k";
313   w89k_ops.to_longname = "WinBond's debug monitor for the W89k Eval board";
314   w89k_ops.to_doc = "Debug on a WinBond W89K eval board.\n\
315 Specify the serial device it is connected to (e.g. /dev/ttya).";
316   w89k_ops.to_open = w89k_open;
317
318   add_target (&w89k_ops);
319 }