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