]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/sparclet-rom.c
* Makefile.in (SUBDIRS): Add mswin so that make cleanup cleans up
[thirdparty/binutils-gdb.git] / gdb / sparclet-rom.c
1 /* Remote target glue for the SPARC Sparclet ROM monitor.
2 Copyright 1995, 1996 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
21 #include "defs.h"
22 #include "gdbcore.h"
23 #include "target.h"
24 #include "monitor.h"
25 #include "serial.h"
26 #include "srec.h"
27 #include "symtab.h"
28 #include "symfile.h" /* for generic_load */
29 #include <time.h>
30
31 static struct target_ops sparclet_ops;
32
33 static void sparclet_open PARAMS ((char *args, int from_tty));
34
35 /* This array of registers need to match the indexes used by GDB.
36 This exists because the various ROM monitors use different strings
37 than does GDB, and don't necessarily support all the registers
38 either. So, typing "info reg sp" becomes a "r30". */
39
40 /*PSR 0x00000080 impl ver icc AW LE EE EC EF PIL S PS ET CWP WIM
41 0x0 0x0 0x0 0 0 0 0 0 0x0 1 0 0 0x00 0x2
42 0000010
43 INS LOCALS OUTS GLOBALS
44 0 0x00000000 0x00000000 0x00000000 0x00000000
45 1 0x00000000 0x00000000 0x00000000 0x00000000
46 2 0x00000000 0x00000000 0x00000000 0x00000000
47 3 0x00000000 0x00000000 0x00000000 0x00000000
48 4 0x00000000 0x00000000 0x00000000 0x00000000
49 5 0x00000000 0x00001000 0x00000000 0x00000000
50 6 0x00000000 0x00000000 0x123f0000 0x00000000
51 7 0x00000000 0x00000000 0x00000000 0x00000000
52 pc: 0x12010000 0x00000000 unimp
53 npc: 0x12010004 0x00001000 unimp 0x1000
54 tbr: 0x00000000
55 y: 0x00000000
56 */
57 /* these correspond to the offsets from tm-* files from config directories */
58
59 /* is wim part of psr?? */
60 /* monitor wants lower case */
61 static char *sparclet_regnames[NUM_REGS] = REGISTER_NAMES;
62
63
64 /* Function: sparclet_supply_register
65 Just returns with no action.
66 This function is required, because parse_register_dump (monitor.c)
67 expects to be able to call it. If we don't supply something, it will
68 call a null pointer and core-dump. Since this function does not
69 actually do anything, GDB will request the registers individually. */
70
71 static void
72 sparclet_supply_register (regname, regnamelen, val, vallen)
73 char *regname;
74 int regnamelen;
75 char *val;
76 int vallen;
77 {
78 return;
79 }
80
81 static void
82 sparclet_load (desc, file, hashmark)
83 serial_t desc;
84 char *file;
85 int hashmark;
86 {
87 bfd *abfd;
88 asection *s;
89 int i;
90 CORE_ADDR load_offset;
91 time_t start_time, end_time;
92 unsigned long data_count = 0;
93
94 /* enable user to specify address for downloading as 2nd arg to load */
95
96 i = sscanf(file, "%*s 0x%lx", &load_offset);
97 if (i >= 1 )
98 {
99 char *p;
100
101 for (p = file; *p != '\000' && !isspace (*p); p++);
102
103 *p = '\000';
104 }
105 else
106 load_offset = 0;
107
108 abfd = bfd_openr (file, 0);
109 if (!abfd)
110 {
111 printf_filtered ("Unable to open file %s\n", file);
112 return;
113 }
114
115 if (bfd_check_format (abfd, bfd_object) == 0)
116 {
117 printf_filtered ("File is not an object file\n");
118 return;
119 }
120
121 start_time = time (NULL);
122
123 for (s = abfd->sections; s; s = s->next)
124 if (s->flags & SEC_LOAD)
125 {
126 bfd_size_type section_size;
127 bfd_vma vma;
128
129 vma = bfd_get_section_vma (abfd, s) + load_offset;
130 section_size = bfd_section_size (abfd, s);
131
132 data_count += section_size;
133
134 printf_filtered ("%s\t: 0x%4x .. 0x%4x ",
135 bfd_get_section_name (abfd, s), vma,
136 vma + section_size);
137 gdb_flush (gdb_stdout);
138
139 monitor_printf ("load c r %x %x\r", vma, section_size);
140
141 monitor_expect ("load: loading ", NULL, 0);
142 monitor_expect ("\r", NULL, 0);
143
144 for (i = 0; i < section_size; i += 2048)
145 {
146 int numbytes;
147 char buf[2048];
148
149 numbytes = min (sizeof buf, section_size - i);
150
151 bfd_get_section_contents (abfd, s, buf, i, numbytes);
152
153 SERIAL_WRITE (desc, buf, numbytes);
154
155 if (hashmark)
156 {
157 putchar_unfiltered ('#');
158 gdb_flush (gdb_stdout);
159 }
160 } /* Per-packet (or S-record) loop */
161
162 monitor_expect_prompt (NULL, 0);
163
164 putchar_unfiltered ('\n');
165 } /* Loadable sections */
166
167 monitor_printf ("reg pc %x\r", bfd_get_start_address (abfd));
168 monitor_expect_prompt (NULL, 0);
169 monitor_printf ("reg npc %x\r", bfd_get_start_address (abfd) + 4);
170 monitor_expect_prompt (NULL, 0);
171
172 monitor_printf ("run\r");
173
174 end_time = time (NULL);
175
176 if (hashmark)
177 putchar_unfiltered ('\n');
178
179 report_transfer_performance (data_count, start_time, end_time);
180
181 pop_target ();
182 push_remote_target (monitor_get_dev_name (), 1);
183
184 return_to_top_level (RETURN_QUIT);
185 }
186
187 /* Define the monitor command strings. Since these are passed directly
188 through to a printf style function, we may include formatting
189 strings. We also need a CR or LF on the end. */
190
191 /* need to pause the monitor for timing reasons, so slow it down */
192
193 static char *sparclet_inits[] = {"\n\r\r\n", NULL};
194
195 static struct monitor_ops sparclet_cmds =
196 {
197 MO_CLR_BREAK_USES_ADDR |
198 MO_HEX_PREFIX |
199 MO_NO_ECHO_ON_OPEN |
200 MO_NO_ECHO_ON_SETMEM |
201 MO_RUN_FIRST_TIME |
202 MO_GETMEM_READ_SINGLE, /* flags */
203 sparclet_inits, /* Init strings */
204 "cont\r", /* continue command */
205 "step\r", /* single step */
206 "\r", /* break interrupts the program */
207 "+bp %x\r", /* set a breakpoint */
208 /* can't use "br" because only 2 hw bps are supported */
209 "-bp %x\r", /* clear a breakpoint */
210 "-bp\r", /* clear all breakpoints */
211 "fill %x -n %x -v %x -b\r", /* fill (start length val) */
212 /* can't use "fi" because it takes words, not bytes */
213 {
214 /* ex [addr] [-n count] [-b|-s|-l] default: ex cur -n 1 -b */
215 "ex %x -b\r%x\rq\r", /* setmem.cmdb (addr, value) */
216 "ex %x -s\r%x\rq\r", /* setmem.cmdw (addr, value) */
217 "ex %x -l\r%x\rq\r", /* setmem.cmdl (addr, value) */
218 NULL, /* setmem.cmdll (addr, value) */
219 NULL, /*": " */ /* setmem.resp_delim */
220 NULL, /*"? " */ /* setmem.term */
221 NULL, /*"q\r" */ /* setmem.term_cmd */
222 },
223 {
224 /* since the parsing of multiple bytes is difficult due to
225 interspersed addresses, we'll only read 1 value at a time,
226 even tho these can handle a count */
227 /* we can use -n to set count to read, but may have to parse? */
228 "ex %x -n 1 -b\r", /* getmem.cmdb (addr, #bytes) */
229 "ex %x -n 1 -s\r", /* getmem.cmdw (addr, #swords) */
230 "ex %x -n 1 -l\r", /* getmem.cmdl (addr, #words) */
231 NULL, /* getmem.cmdll (addr, #dwords) */
232 ": ", /* getmem.resp_delim */
233 NULL, /* getmem.term */
234 NULL, /* getmem.term_cmd */
235 },
236 {
237 "reg %s 0x%x\r", /* setreg.cmd (name, value) */
238 NULL, /* setreg.resp_delim */
239 NULL, /* setreg.term */
240 NULL /* setreg.term_cmd */
241 },
242 {
243 "reg %s\r", /* getreg.cmd (name) */
244 " ", /* getreg.resp_delim */
245 NULL, /* getreg.term */
246 NULL, /* getreg.term_cmd */
247 },
248 "reg\r", /* dump_registers */
249 "\\(\\w+\\)=\\([0-9a-fA-F]+\\)", /* register_pattern */
250 sparclet_supply_register, /* supply_register */
251 sparclet_load, /* load_routine */
252 NULL, /* download command (srecs on console) */
253 NULL, /* load response */
254 "monitor>", /* monitor command prompt */
255 /* yikes! gdb core dumps without this delimitor!! */
256 "\r", /* end-of-command delimitor */
257 NULL, /* optional command terminator */
258 &sparclet_ops, /* target operations */
259 SERIAL_1_STOPBITS, /* number of stop bits */
260 sparclet_regnames, /* registers names */
261 MONITOR_OPS_MAGIC /* magic */
262 };
263
264 static void
265 sparclet_open (args, from_tty)
266 char *args;
267 int from_tty;
268 {
269 monitor_open (args, &sparclet_cmds, from_tty);
270 }
271
272 void
273 _initialize_sparclet ()
274 {
275 int i;
276
277 for (i = 0; i < NUM_REGS; i++)
278 if (sparclet_regnames[i][0] == 'c' ||
279 sparclet_regnames[i][0] == 'a')
280 sparclet_regnames[i] = 0; /* mon can't report c* or a* regs */
281
282 sparclet_regnames[0] = 0; /* mon won't report %G0 */
283
284 init_monitor_ops (&sparclet_ops);
285 sparclet_ops.to_shortname = "sparclet"; /* for the target command */
286 sparclet_ops.to_longname = "SPARC Sparclet monitor";
287 /* use SW breaks; target only supports 2 HW breakpoints */
288 sparclet_ops.to_insert_breakpoint = memory_insert_breakpoint;
289 sparclet_ops.to_remove_breakpoint = memory_remove_breakpoint;
290
291 sparclet_ops.to_doc =
292 "Use a board running the Sparclet debug monitor.\n\
293 Specify the serial device it is connected to (e.g. /dev/ttya).";
294
295 sparclet_ops.to_open = sparclet_open;
296 add_target (&sparclet_ops);
297 }
298