* test-build.mk (HOLES): Add "xargs" for gdb.
[deliverable/binutils-gdb.git] / gdb / mon960-rom.c
CommitLineData
32b18604 1/* Remote target glue for the Intel 960 MON960 ROM monitor.
2e665cd3
DP
2 Copyright 1995, 1996 Free Software Foundation, Inc.
3
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, 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 "xmodem.h"
32b18604
SS
28#include "symtab.h"
29#include "symfile.h" /* for generic_load */
2e665cd3
DP
30
31#if !defined (HAVE_TERMIOS) && !defined (HAVE_TERMIO) && !defined (HAVE_SGTTY)
32#define HAVE_SGTTY
33#endif
34
35#ifdef HAVE_SGTTY
36#include <sys/ioctl.h>
37#endif
38
39#include <sys/types.h> /* Needed by file.h on Sys V */
40#include <sys/file.h>
41#include <signal.h>
42#include <sys/stat.h>
43
44#define USE_GENERIC_LOAD
45
32b18604
SS
46static struct target_ops mon960_ops;
47
2e665cd3
DP
48static void mon960_open PARAMS ((char *args, int from_tty));
49
50#ifdef USE_GENERIC_LOAD
32b18604 51
2e665cd3
DP
52static void
53mon960_load_gen (filename, from_tty)
54 char *filename;
55 int from_tty;
56{
57 extern int inferior_pid;
32b18604 58
2e665cd3
DP
59 generic_load (filename, from_tty);
60 /* Finally, make the PC point at the start address */
61 if (exec_bfd)
62 write_pc (bfd_get_start_address (exec_bfd));
63
64 inferior_pid = 0; /* No process now */
65}
66
67#else
32b18604 68
2e665cd3
DP
69static void
70mon960_load (desc, file, hashmark)
71 serial_t desc;
72 char *file;
73 int hashmark;
74{
75 bfd *abfd;
76 asection *s;
77 char *buffer;
78 int i;
79
80 buffer = alloca (XMODEM_PACKETSIZE);
81 abfd = bfd_openr (file, 0);
82 if (!abfd)
83 {
84 printf_filtered ("Unable to open file %s\n", file);
85 return;
86 }
87 if (bfd_check_format (abfd, bfd_object) == 0)
88 {
89 printf_filtered ("File is not an object file\n");
90 return;
91 }
92 for (s = abfd->sections; s; s = s->next)
93 if (s->flags & SEC_LOAD)
94 {
95 bfd_size_type section_size;
96 printf_filtered ("%s\t: 0x%4x .. 0x%4x ", s->name, s->vma,
97 s->vma + s->_raw_size);
98 gdb_flush (gdb_stdout);
5a2934b4
SS
99 monitor_printf (current_monitor->load, s->vma);
100 if (current_monitor->loadresp)
101 monitor_expect (current_monitor->loadresp, NULL, 0);
2e665cd3
DP
102 xmodem_init_xfer (desc);
103 section_size = bfd_section_size (abfd, s);
104 for (i = 0; i < section_size; i += XMODEM_DATASIZE)
105 {
106 int numbytes;
107 numbytes = min (XMODEM_DATASIZE, section_size - i);
108 bfd_get_section_contents (abfd, s, buffer + XMODEM_DATAOFFSET, i,
109 numbytes);
110 xmodem_send_packet (desc, buffer, numbytes, hashmark);
111 if (hashmark)
112 {
113 putchar_unfiltered ('#');
114 gdb_flush (gdb_stdout);
115 }
116 } /* Per-packet (or S-record) loop */
117 xmodem_finish_xfer (desc);
118 monitor_expect_prompt (NULL, 0);
119 putchar_unfiltered ('\n');
120 } /* Loadable sections */
121 if (hashmark)
122 putchar_unfiltered ('\n');
123}
32b18604
SS
124
125#endif /* USE_GENERIC_LOAD */
2e665cd3
DP
126
127/* This array of registers need to match the indexes used by GDB.
128 This exists because the various ROM monitors use different strings
129 than does GDB, and don't necessarily support all the registers
130 either. So, typing "info reg sp" becomes a "r30". */
131
132/* these correspond to the offsets from tm-* files from config directories */
133/* g0-g14, fp, pfp, sp, rip,r3-15, pc, ac, tc, fp0-3 */
134/* NOTE: "ip" is documented as "ir" in the Mon960 UG. */
135/* NOTE: "ir" can't be accessed... but there's an ip and rip. */
ee7b308f 136static char *full_regnames[NUM_REGS] = {
5a2934b4
SS
137 /* 0 */ "pfp", "sp", "rip", "r3", "r4", "r5", "r6", "r7",
138 /* 8 */ "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
139 /* 16 */ "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
140 /* 24 */ "g8", "g9", "g10", "g11", "g12", "g13", "g14", "fp",
141 /* 32 */ "pc", "ac", "tc", "ip", "fp0", "fp1", "fp2", "fp3",
2e665cd3
DP
142 };
143
ee7b308f
MA
144static char *mon960_regnames[NUM_REGS];
145
2e665cd3
DP
146/* Define the monitor command strings. Since these are passed directly
147 through to a printf style function, we may include formatting
148 strings. We also need a CR or LF on the end. */
149
2e665cd3 150/* need to pause the monitor for timing reasons, so slow it down */
32b18604 151
2531b169 152#if 0
ee7b308f
MA
153/* FIXME: this extremely long init string causes MON960 to return two NAKS
154 instead of performing the autobaud recognition, at least when gdb
155 is running on Linux. The short string below works on Linux, and on
156 SunOS using a tcp serial connection. Must retest on SunOS using a
157 direct serial connection; if that works, get rid of the long string. */
32b18604 158static char *mon960_inits[] = {"\n\r\r\r\r\r\r\r\r\r\r\r\r\r\r\n\r\n\r\n", NULL};
ee7b308f
MA
159#else
160static char *mon960_inits[] = { "\r", NULL};
161#endif
2e665cd3
DP
162
163static struct monitor_ops mon960_cmds =
164{
165 MO_CLR_BREAK_USES_ADDR
166 | MO_NO_ECHO_ON_OPEN
167 | MO_SEND_BREAK_ON_STOP
168 | MO_GETMEM_READ_SINGLE, /* flags */
169 mon960_inits, /* Init strings */
170 "go\n\r", /* continue command */
171 "st\n\r", /* single step */
ee7b308f 172 NULL, /* break interrupts the program */
2e665cd3
DP
173 NULL, /* set a breakpoint */
174 /* can't use "br" because only 2 hw bps are supported */
175 NULL, /* clear a breakpoint - "de" is for hw bps */
176 NULL, /* clear all breakpoints */
177 NULL, /* fill (start end val) */
178 /* can't use "fi" because it takes words, not bytes */
179 {
180 /* can't use "mb", "md" or "mo" because they require interaction */
181 NULL, /* setmem.cmdb (addr, value) */
ee7b308f
MA
182 NULL, /* setmem.cmdw (addr, value) */
183 "md %x %x\n\r", /* setmem.cmdl (addr, value) */
2e665cd3
DP
184 NULL, /* setmem.cmdll (addr, value) */
185 NULL, /* setmem.resp_delim */
186 NULL, /* setmem.term */
187 NULL, /* setmem.term_cmd */
188 },
189 {
190 /* since the parsing of multiple bytes is difficult due to
191 interspersed addresses, we'll only read 1 value at a time,
192 even tho these can handle a count */
193 "db %x\n\r", /* getmem.cmdb (addr, #bytes) */
194 "ds %x\n\r", /* getmem.cmdw (addr, #swords) */
195 "di %x\n\r", /* getmem.cmdl (addr, #words) */
196 "dd %x\n\r", /* getmem.cmdll (addr, #dwords) */
197 " : ", /* getmem.resp_delim */
198 NULL, /* getmem.term */
199 NULL, /* getmem.term_cmd */
200 },
201 {
202 "md %s %x\n\r", /* setreg.cmd (name, value) */
203 NULL, /* setreg.resp_delim */
204 NULL, /* setreg.term */
205 NULL /* setreg.term_cmd */
206 },
207 {
208 "di %s\n\r", /* getreg.cmd (name) */
209 " : ", /* getreg.resp_delim */
210 NULL, /* getreg.term */
211 NULL, /* getreg.term_cmd */
212 },
213 "re\n\r", /* dump_registers */
214 "\\(\\w+\\)=\\([0-9a-fA-F]+\\)", /* register_pattern */
215 NULL, /* supply_register */
216#ifdef USE_GENERIC_LOAD
217 NULL, /* load_routine (defaults to SRECs) */
218 NULL, /* download command */
219 NULL, /* load response */
220#else
221 mon960_load, /* load_routine (defaults to SRECs) */
222 "do\n\r", /* download command */
223 "Downloading\n\r", /* load response */
224#endif
225 "=>", /* monitor command prompt */
226 "\n\r", /* end-of-command delimitor */
227 NULL, /* optional command terminator */
228 &mon960_ops, /* target operations */
229 SERIAL_1_STOPBITS, /* number of stop bits */
230 mon960_regnames, /* registers names */
231 MONITOR_OPS_MAGIC /* magic */
232};
233
2e665cd3
DP
234static void
235mon960_open (args, from_tty)
236 char *args;
237 int from_tty;
238{
ee7b308f
MA
239 char buf[64];
240
32b18604 241 monitor_open (args, &mon960_cmds, from_tty);
ee7b308f
MA
242
243 /* Attempt to fetch the value of the first floating point register (fp0).
244 If the monitor returns a string containing the word "Bad" we'll assume
245 this processor has no floating point registers, and nullify the
246 regnames entries that refer to FP registers. */
247
248 monitor_printf (mon960_cmds.getreg.cmd, full_regnames[FP0_REGNUM]); /* di fp0 */
249 if (monitor_expect_prompt (buf, sizeof(buf)) != -1)
250 if (strstr(buf, "Bad") != NULL)
251 {
252 int i;
253
254 for (i = FP0_REGNUM; i < FP0_REGNUM + 4; i++)
255 mon960_regnames[i] = NULL;
256 }
2e665cd3
DP
257}
258
2e665cd3
DP
259void
260_initialize_mon960 ()
261{
ee7b308f
MA
262 memcpy(mon960_regnames, full_regnames, sizeof(full_regnames));
263
2e665cd3
DP
264 init_monitor_ops (&mon960_ops);
265
266 mon960_ops.to_shortname = "mon960"; /* for the target command */
32b18604 267 mon960_ops.to_longname = "Intel 960 MON960 monitor";
2e665cd3
DP
268#ifdef USE_GENERIC_LOAD
269 mon960_ops.to_load = mon960_load_gen; /* FIXME - should go back and try "do" */
270#endif
271 /* use SW breaks; target only supports 2 HW breakpoints */
272 mon960_ops.to_insert_breakpoint = memory_insert_breakpoint;
273 mon960_ops.to_remove_breakpoint = memory_remove_breakpoint;
274
275 mon960_ops.to_doc =
5a2934b4
SS
276 "Use an Intel 960 board running the MON960 debug monitor.\n\
277Specify the serial device it is connected to (e.g. /dev/ttya).";
2e665cd3
DP
278
279 mon960_ops.to_open = mon960_open;
280 add_target (&mon960_ops);
281}
This page took 0.053466 seconds and 4 git commands to generate.