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