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