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