* gdbtk.tcl (create_command_window): If command window's buffer
[deliverable/binutils-gdb.git] / gdb / mon960-rom.c
1 /* Remote target glue for the Intel 960 MON960 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 "xmodem.h"
28 #include "symtab.h"
29 #include "symfile.h" /* for generic_load */
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
46 static struct target_ops mon960_ops;
47
48 static void mon960_open PARAMS ((char *args, int from_tty));
49
50 #ifdef USE_GENERIC_LOAD
51
52 static void
53 mon960_load_gen (filename, from_tty)
54 char *filename;
55 int from_tty;
56 {
57 extern int inferior_pid;
58
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
68
69 static void
70 mon960_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);
99 monitor_printf (current_monitor->load, s->vma);
100 if (current_monitor->loadresp)
101 monitor_expect (current_monitor->loadresp, NULL, 0);
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 }
124
125 #endif /* USE_GENERIC_LOAD */
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. */
136 static char *mon960_regnames[NUM_REGS] = {
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",
142 };
143
144 /* Define the monitor command strings. Since these are passed directly
145 through to a printf style function, we may include formatting
146 strings. We also need a CR or LF on the end. */
147
148 /* need to pause the monitor for timing reasons, so slow it down */
149
150 static char *mon960_inits[] = {"\n\r\r\r\r\r\r\r\r\r\r\r\r\r\r\n\r\n\r\n", NULL};
151
152 static struct monitor_ops mon960_cmds =
153 {
154 MO_CLR_BREAK_USES_ADDR
155 | MO_NO_ECHO_ON_OPEN
156 | MO_SEND_BREAK_ON_STOP
157 | MO_GETMEM_READ_SINGLE, /* flags */
158 mon960_inits, /* Init strings */
159 "go\n\r", /* continue command */
160 "st\n\r", /* single step */
161 "\n\r", /* break interrupts the program */
162 NULL, /* set a breakpoint */
163 /* can't use "br" because only 2 hw bps are supported */
164 NULL, /* clear a breakpoint - "de" is for hw bps */
165 NULL, /* clear all breakpoints */
166 NULL, /* fill (start end val) */
167 /* can't use "fi" because it takes words, not bytes */
168 {
169 /* can't use "mb", "md" or "mo" because they require interaction */
170 NULL, /* setmem.cmdb (addr, value) */
171 "md %x %x\n\r", /* setmem.cmdw (addr, value) */
172 NULL, /* setmem.cmdl (addr, value) */
173 NULL, /* setmem.cmdll (addr, value) */
174 NULL, /* setmem.resp_delim */
175 NULL, /* setmem.term */
176 NULL, /* setmem.term_cmd */
177 },
178 {
179 /* since the parsing of multiple bytes is difficult due to
180 interspersed addresses, we'll only read 1 value at a time,
181 even tho these can handle a count */
182 "db %x\n\r", /* getmem.cmdb (addr, #bytes) */
183 "ds %x\n\r", /* getmem.cmdw (addr, #swords) */
184 "di %x\n\r", /* getmem.cmdl (addr, #words) */
185 "dd %x\n\r", /* getmem.cmdll (addr, #dwords) */
186 " : ", /* getmem.resp_delim */
187 NULL, /* getmem.term */
188 NULL, /* getmem.term_cmd */
189 },
190 {
191 "md %s %x\n\r", /* setreg.cmd (name, value) */
192 NULL, /* setreg.resp_delim */
193 NULL, /* setreg.term */
194 NULL /* setreg.term_cmd */
195 },
196 {
197 "di %s\n\r", /* getreg.cmd (name) */
198 " : ", /* getreg.resp_delim */
199 NULL, /* getreg.term */
200 NULL, /* getreg.term_cmd */
201 },
202 "re\n\r", /* dump_registers */
203 "\\(\\w+\\)=\\([0-9a-fA-F]+\\)", /* register_pattern */
204 NULL, /* supply_register */
205 #ifdef USE_GENERIC_LOAD
206 NULL, /* load_routine (defaults to SRECs) */
207 NULL, /* download command */
208 NULL, /* load response */
209 #else
210 mon960_load, /* load_routine (defaults to SRECs) */
211 "do\n\r", /* download command */
212 "Downloading\n\r", /* load response */
213 #endif
214 "=>", /* monitor command prompt */
215 "\n\r", /* end-of-command delimitor */
216 NULL, /* optional command terminator */
217 &mon960_ops, /* target operations */
218 SERIAL_1_STOPBITS, /* number of stop bits */
219 mon960_regnames, /* registers names */
220 MONITOR_OPS_MAGIC /* magic */
221 };
222
223 static void
224 mon960_open (args, from_tty)
225 char *args;
226 int from_tty;
227 {
228 monitor_open (args, &mon960_cmds, from_tty);
229 }
230
231 void
232 _initialize_mon960 ()
233 {
234 init_monitor_ops (&mon960_ops);
235
236 mon960_ops.to_shortname = "mon960"; /* for the target command */
237 mon960_ops.to_longname = "Intel 960 MON960 monitor";
238 #ifdef USE_GENERIC_LOAD
239 mon960_ops.to_load = mon960_load_gen; /* FIXME - should go back and try "do" */
240 #endif
241 /* use SW breaks; target only supports 2 HW breakpoints */
242 mon960_ops.to_insert_breakpoint = memory_insert_breakpoint;
243 mon960_ops.to_remove_breakpoint = memory_remove_breakpoint;
244
245 mon960_ops.to_doc =
246 "Use an Intel 960 board running the MON960 debug monitor.\n\
247 Specify the serial device it is connected to (e.g. /dev/ttya).";
248
249 mon960_ops.to_open = mon960_open;
250 add_target (&mon960_ops);
251 }
252
This page took 0.033824 seconds and 4 git commands to generate.