Commit | Line | Data |
---|---|---|
1f46923f | 1 | /* Remote debugging interface for Hitachi HMS Monitor Version 1.0 |
5d747d61 | 2 | Copyright 1995 Free Software Foundation, Inc. |
e17960fb JG |
3 | Contributed by Cygnus Support. Written by Steve Chamberlain |
4 | (sac@cygnus.com). | |
fa4b55a1 | 5 | |
03fc5a0b | 6 | This file is part of GDB. |
fa4b55a1 | 7 | |
03fc5a0b SC |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
fa4b55a1 | 12 | |
03fc5a0b SC |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
fa4b55a1 | 17 | |
03fc5a0b SC |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software | |
6c9638b4 | 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
fa4b55a1 | 21 | |
fa4b55a1 | 22 | #include "defs.h" |
5d747d61 SC |
23 | #include "gdbcore.h" |
24 | #include "target.h" | |
25 | #include "monitor.h" | |
26 | #include "serial.h" | |
27 | ||
28 | static void hms_open PARAMS ((char *args, int from_tty)); | |
5d747d61 SC |
29 | static void |
30 | hms_supply_register (regname, regnamelen, val, vallen) | |
31 | char *regname; | |
32 | int regnamelen; | |
33 | char *val; | |
34 | int vallen; | |
35 | { | |
36 | int regno; | |
37 | ||
38 | if (regnamelen != 2) | |
39 | return; | |
40 | if (regname[0] != 'P') | |
41 | return; | |
42 | /* We scan off all the registers in one go */ | |
43 | ||
44 | val = monitor_supply_register (PC_REGNUM, val); | |
45 | /* Skip the ccr string */ | |
46 | while (*val != '=' && *val) | |
47 | val++; | |
48 | ||
49 | val = monitor_supply_register (CCR_REGNUM, val + 1); | |
50 | ||
51 | /* Skip up to rest of regs */ | |
52 | while (*val != '=' && *val) | |
53 | val++; | |
54 | ||
55 | for (regno = 0; regno < 7; regno++) | |
56 | { | |
57 | val = monitor_supply_register (regno, val + 1); | |
58 | } | |
59 | } | |
60 | ||
61 | /* | |
62 | * This array of registers needs to match the indexes used by GDB. The | |
63 | * whole reason this exists is because the various ROM monitors use | |
64 | * different names than GDB does, and don't support all the | |
65 | * registers either. So, typing "info reg sp" becomes a "r30". | |
66 | */ | |
67 | ||
68 | static char *hms_regnames[NUM_REGS] = | |
69 | { | |
70 | "R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7", "CCR", "PC" | |
71 | }; | |
72 | ||
73 | /* | |
74 | * Define the monitor command strings. Since these are passed directly | |
75 | * through to a printf style function, we need can include formatting | |
76 | * strings. We also need a CR or LF on the end. | |
77 | */ | |
78 | ||
79 | static struct target_ops hms_ops; | |
80 | ||
81 | static char *hms_inits[] = | |
82 | {"\003", /* Resets the prompt, and clears repeated cmds */ | |
83 | NULL}; | |
84 | ||
adc176bb JM |
85 | static struct monitor_ops hms_cmds ; |
86 | static void init_hms_cmds(void) | |
5d747d61 | 87 | { |
adc176bb JM |
88 | hms_cmds.flags = MO_CLR_BREAK_USES_ADDR | MO_FILL_USES_ADDR | MO_GETMEM_NEEDS_RANGE; |
89 | hms_cmds.init = hms_inits; /* Init strings */ | |
90 | hms_cmds.cont = "g\r"; /* continue command */ | |
91 | hms_cmds.step = "s\r"; /* single step */ | |
92 | hms_cmds.stop = "\003"; /* ^C interrupts the program */ | |
93 | hms_cmds.set_break = "b %x\r"; /* set a breakpoint */ | |
94 | hms_cmds.clr_break = "b - %x\r"; /* clear a breakpoint */ | |
95 | hms_cmds.clr_all_break = "b -\r"; /* clear all breakpoints */ | |
96 | hms_cmds.fill = "f %x %x %x\r"; /* fill (start end val) */ | |
97 | hms_cmds.setmem.cmdb = "m.b %x=%x\r"; /* setmem.cmdb (addr, value) */ | |
98 | hms_cmds.setmem.cmdw = "m.w %x=%x\r"; /* setmem.cmdw (addr, value) */ | |
99 | hms_cmds.setmem.cmdl = NULL; /* setmem.cmdl (addr, value) */ | |
100 | hms_cmds.setmem.cmdll = NULL; /* setmem.cmdll (addr, value) */ | |
101 | hms_cmds.setmem.resp_delim = NULL;/* setreg.resp_delim */ | |
102 | hms_cmds.setmem.term = NULL; /* setreg.term */ | |
103 | hms_cmds.setmem.term_cmd = NULL; /* setreg.term_cmd */ | |
104 | hms_cmds.getmem.cmdb = "m.b %x %x\r"; /* getmem.cmdb (addr, addr) */ | |
105 | hms_cmds.getmem.cmdw = "m.w %x %x\r"; /* getmem.cmdw (addr, addr) */ | |
106 | hms_cmds.getmem.cmdl = NULL; /* getmem.cmdl (addr, addr) */ | |
107 | hms_cmds.getmem.cmdll = NULL; /* getmem.cmdll (addr, addr) */ | |
108 | hms_cmds.getmem.resp_delim = ": ";/* getmem.resp_delim */ | |
109 | hms_cmds.getmem.term = ">"; /* getmem.term */ | |
110 | hms_cmds.getmem.term_cmd = "\003";/* getmem.term_cmd */ | |
111 | hms_cmds.setreg.cmd = "r %s=%x\r";/* setreg.cmd (name, value) */ | |
112 | hms_cmds.setreg.resp_delim = NULL;/* setreg.resp_delim */ | |
113 | hms_cmds.setreg.term = NULL; /* setreg.term */ | |
114 | hms_cmds.setreg.term_cmd = NULL; /* setreg.term_cmd */ | |
115 | hms_cmds.getreg.cmd = "r %s\r"; /* getreg.cmd (name) */ | |
116 | hms_cmds.getreg.resp_delim = " (";/* getreg.resp_delim */ | |
117 | hms_cmds.getreg.term = ":"; /* getreg.term */ | |
118 | hms_cmds.getreg.term_cmd = "\003";/* getreg.term_cmd */ | |
119 | hms_cmds.dump_registers = "r\r"; /* dump_registers */ | |
120 | hms_cmds.register_pattern = "\\(\\w+\\)=\\([0-9a-fA-F]+\\)"; /* register_pattern */ | |
121 | hms_cmds.supply_register = hms_supply_register; /* supply_register */ | |
122 | hms_cmds.load_routine = NULL; /* load_routine (defaults to SRECs) */ | |
123 | hms_cmds.load = "tl\r"; /* download command */ | |
124 | hms_cmds.loadresp = NULL; /* load response */ | |
125 | hms_cmds.prompt = ">"; /* monitor command prompt */ | |
126 | hms_cmds.line_term = "\r"; /* end-of-command delimitor */ | |
127 | hms_cmds.cmd_end = NULL; /* optional command terminator */ | |
128 | hms_cmds.target = &hms_ops; /* target operations */ | |
129 | hms_cmds.stopbits = SERIAL_1_STOPBITS;/* number of stop bits */ | |
130 | hms_cmds.regnames = hms_regnames; /* registers names */ | |
131 | hms_cmds.magic = MONITOR_OPS_MAGIC; /* magic */ | |
132 | } /* init_hms-cmds */ | |
5d747d61 | 133 | |
e33c359d | 134 | static void |
5d747d61 SC |
135 | hms_open (args, from_tty) |
136 | char *args; | |
137 | int from_tty; | |
138 | { | |
139 | monitor_open (args, &hms_cmds, from_tty); | |
140 | } | |
141 | ||
5d747d61 | 142 | int write_dos_tick_delay; |
e33c359d | 143 | |
5d747d61 SC |
144 | void |
145 | _initialize_remote_hms () | |
146 | { | |
adc176bb | 147 | init_hms_cmds() ; |
5d747d61 SC |
148 | init_monitor_ops (&hms_ops); |
149 | ||
150 | hms_ops.to_shortname = "hms"; | |
151 | hms_ops.to_longname = "Hitachi Microsystems H8/300 debug monitor"; | |
152 | hms_ops.to_doc = "Debug via the HMS monitor.\n\ | |
153 | Specify the serial device it is connected to (e.g. /dev/ttya)."; | |
154 | hms_ops.to_open = hms_open; | |
155 | /* By trial and error I've found that this delay doesn't break things */ | |
156 | write_dos_tick_delay = 1; | |
157 | add_target (&hms_ops); | |
158 | } | |
159 | ||
5d747d61 SC |
160 | #if 0 |
161 | /* This is kept here because we used to support the H8/500 in this module, | |
162 | and I haven't done the H8/500 yet */ | |
163 | #include "defs.h" | |
fa4b55a1 SC |
164 | #include "inferior.h" |
165 | #include "wait.h" | |
166 | #include "value.h" | |
2b576293 | 167 | #include "gdb_string.h" |
fa4b55a1 SC |
168 | #include <ctype.h> |
169 | #include <fcntl.h> | |
170 | #include <signal.h> | |
171 | #include <setjmp.h> | |
172 | #include <errno.h> | |
173 | #include "terminal.h" | |
174 | #include "target.h" | |
175 | #include "gdbcore.h" | |
a493d9a6 | 176 | #include "serial.h" |
03fc5a0b | 177 | #include "remote-utils.h" |
fa4b55a1 | 178 | /* External data declarations */ |
ec25d19b | 179 | extern int stop_soon_quietly; /* for wait_for_inferior */ |
fa4b55a1 | 180 | |
fa4b55a1 | 181 | /* Forward data declarations */ |
ec25d19b | 182 | extern struct target_ops hms_ops; /* Forward declaration */ |
fa4b55a1 SC |
183 | |
184 | /* Forward function declarations */ | |
185 | static void hms_fetch_registers (); | |
ec25d19b | 186 | static int hms_store_registers (); |
fa4b55a1 | 187 | static void hms_close (); |
ec25d19b | 188 | static int hms_clear_breakpoints (); |
fa4b55a1 SC |
189 | |
190 | extern struct target_ops hms_ops; | |
3b5442f9 SC |
191 | static void hms_drain (); |
192 | static void add_commands (); | |
193 | static void remove_commands (); | |
fa4b55a1 | 194 | |
03fc5a0b | 195 | static int quiet = 1; /* FIXME - can be removed after Dec '94 */ |
a493d9a6 | 196 | |
a493d9a6 | 197 | |
fa4b55a1 | 198 | |
1f46923f SC |
199 | /*********************************************************************** |
200 | * I/O stuff stolen from remote-eb.c | |
201 | ***********************************************************************/ | |
202 | ||
203 | static int timeout = 2; | |
fa4b55a1 | 204 | |
b52373a2 | 205 | static const char *dev_name; |
1f46923f | 206 | |
fa4b55a1 SC |
207 | /* Descriptor for I/O to remote machine. Initialize it to -1 so that |
208 | hms_open knows that we don't have a file open when the program | |
209 | starts. */ | |
fa4b55a1 | 210 | |
402b0d2e SC |
211 | static int before = 0xdead; |
212 | static int is_open = 0; | |
213 | static int after = 0xdead; | |
a493d9a6 | 214 | int |
ec25d19b | 215 | check_open () |
fa4b55a1 | 216 | { |
03fc5a0b SC |
217 | if (before != 0xdead |
218 | || after != 0xdead) | |
219 | printf ("OUTCH! \n"); | |
ae0ea72e | 220 | if (!is_open) |
ec25d19b SC |
221 | { |
222 | error ("remote device not open"); | |
223 | } | |
fa4b55a1 SC |
224 | } |
225 | ||
ae0ea72e SC |
226 | #define ON 1 |
227 | #define OFF 0 | |
1f46923f SC |
228 | |
229 | /* Read a character from the remote system, doing all the fancy | |
230 | timeout stuff. */ | |
231 | static int | |
232 | readchar () | |
fa4b55a1 | 233 | { |
ae0ea72e | 234 | int buf; |
ec25d19b | 235 | |
a493d9a6 | 236 | buf = SERIAL_READCHAR (desc, timeout); |
1f46923f | 237 | |
a493d9a6 | 238 | if (buf == SERIAL_TIMEOUT) |
3b5442f9 SC |
239 | { |
240 | hms_write (".\r\n", 3); | |
241 | error ("Timeout reading from remote system."); | |
242 | } | |
243 | if (buf == SERIAL_ERROR) | |
244 | { | |
245 | error ("Serial port error!"); | |
246 | } | |
1f46923f | 247 | |
791d4d7d | 248 | if (!quiet || remote_debug) |
199b2450 | 249 | printf_unfiltered ("%c", buf); |
ec25d19b | 250 | |
1f46923f | 251 | return buf & 0x7f; |
fa4b55a1 SC |
252 | } |
253 | ||
5d747d61 | 254 | static void |
03fc5a0b | 255 | flush () |
402b0d2e SC |
256 | { |
257 | while (1) | |
258 | { | |
259 | int b = SERIAL_READCHAR (desc, 0); | |
260 | if (b == SERIAL_TIMEOUT) | |
261 | return; | |
262 | } | |
263 | } | |
264 | ||
fa4b55a1 | 265 | static int |
1f46923f | 266 | readchar_nofail () |
fa4b55a1 | 267 | { |
ae0ea72e | 268 | int buf; |
ec25d19b | 269 | |
a493d9a6 SC |
270 | buf = SERIAL_READCHAR (desc, timeout); |
271 | if (buf == SERIAL_TIMEOUT) | |
ec25d19b | 272 | buf = 0; |
791d4d7d | 273 | if (!quiet || remote_debug) |
199b2450 | 274 | printf_unfiltered ("%c", buf); |
ec25d19b | 275 | |
fa4b55a1 | 276 | return buf & 0x7f; |
ae0ea72e | 277 | |
fa4b55a1 SC |
278 | } |
279 | ||
ec25d19b | 280 | /* Keep discarding input from the remote system, until STRING is found. |
fa4b55a1 SC |
281 | Let the user break out immediately. */ |
282 | static void | |
283 | expect (string) | |
284 | char *string; | |
285 | { | |
286 | char *p = string; | |
402b0d2e | 287 | char c; |
fa4b55a1 SC |
288 | immediate_quit = 1; |
289 | while (1) | |
290 | { | |
03fc5a0b | 291 | c = readchar (); |
402b0d2e | 292 | if (c == *p) |
fa4b55a1 SC |
293 | { |
294 | p++; | |
295 | if (*p == '\0') | |
296 | { | |
297 | immediate_quit = 0; | |
298 | return; | |
299 | } | |
300 | } | |
03fc5a0b | 301 | else |
402b0d2e SC |
302 | { |
303 | p = string; | |
304 | if (c == *p) | |
305 | p++; | |
306 | } | |
fa4b55a1 SC |
307 | } |
308 | } | |
309 | ||
310 | /* Keep discarding input until we see the hms prompt. | |
311 | ||
312 | The convention for dealing with the prompt is that you | |
313 | o give your command | |
314 | o *then* wait for the prompt. | |
315 | ||
316 | Thus the last thing that a procedure does with the serial line | |
317 | will be an expect_prompt(). Exception: hms_resume does not | |
318 | wait for the prompt, because the terminal is being handed over | |
319 | to the inferior. However, the next thing which happens after that | |
320 | is a hms_wait which does wait for the prompt. | |
321 | Note that this includes abnormal exit, e.g. error(). This is | |
322 | necessary to prevent getting into states from which we can't | |
323 | recover. */ | |
324 | static void | |
325 | expect_prompt () | |
326 | { | |
fa4b55a1 SC |
327 | expect ("HMS>"); |
328 | } | |
329 | ||
330 | /* Get a hex digit from the remote system & return its value. | |
331 | If ignore_space is nonzero, ignore spaces (not newline, tab, etc). */ | |
332 | static int | |
333 | get_hex_digit (ignore_space) | |
334 | int ignore_space; | |
335 | { | |
336 | int ch; | |
ec25d19b | 337 | |
fa4b55a1 SC |
338 | while (1) |
339 | { | |
340 | ch = readchar (); | |
341 | if (ch >= '0' && ch <= '9') | |
342 | return ch - '0'; | |
343 | else if (ch >= 'A' && ch <= 'F') | |
344 | return ch - 'A' + 10; | |
345 | else if (ch >= 'a' && ch <= 'f') | |
346 | return ch - 'a' + 10; | |
347 | else if (ch == ' ' && ignore_space) | |
348 | ; | |
349 | else | |
350 | { | |
351 | expect_prompt (); | |
352 | error ("Invalid hex digit from remote system."); | |
353 | } | |
354 | } | |
355 | } | |
356 | ||
357 | /* Get a byte from hms_desc and put it in *BYT. Accept any number | |
358 | leading spaces. */ | |
359 | static void | |
360 | get_hex_byte (byt) | |
361 | char *byt; | |
362 | { | |
363 | int val; | |
364 | ||
365 | val = get_hex_digit (1) << 4; | |
366 | val |= get_hex_digit (0); | |
367 | *byt = val; | |
368 | } | |
369 | ||
370 | /* Read a 32-bit hex word from the hms, preceded by a space */ | |
ec25d19b SC |
371 | static long |
372 | get_hex_word () | |
fa4b55a1 SC |
373 | { |
374 | long val; | |
375 | int j; | |
ec25d19b | 376 | |
fa4b55a1 SC |
377 | val = 0; |
378 | for (j = 0; j < 8; j++) | |
ec25d19b | 379 | val = (val << 4) + get_hex_digit (j == 0); |
fa4b55a1 SC |
380 | return val; |
381 | } | |
fa4b55a1 | 382 | |
ec25d19b | 383 | /* Called when SIGALRM signal sent due to alarm() timeout. */ |
fa4b55a1 SC |
384 | |
385 | /* Number of SIGTRAPs we need to simulate. That is, the next | |
386 | NEED_ARTIFICIAL_TRAP calls to hms_wait should just return | |
387 | SIGTRAP without actually waiting for anything. */ | |
388 | ||
389 | static int need_artificial_trap = 0; | |
390 | ||
391 | void | |
ec25d19b SC |
392 | hms_kill (arg, from_tty) |
393 | char *arg; | |
394 | int from_tty; | |
fa4b55a1 | 395 | { |
fa4b55a1 | 396 | |
fa4b55a1 | 397 | } |
1f46923f | 398 | |
fa4b55a1 SC |
399 | /* This is called not only when we first attach, but also when the |
400 | user types "run" after having attached. */ | |
401 | void | |
402 | hms_create_inferior (execfile, args, env) | |
403 | char *execfile; | |
404 | char *args; | |
405 | char **env; | |
406 | { | |
407 | int entry_pt; | |
ec25d19b | 408 | char buffer[100]; |
fa4b55a1 SC |
409 | |
410 | if (args && *args) | |
ec25d19b | 411 | error ("Can't pass arguments to remote hms process."); |
fa4b55a1 SC |
412 | |
413 | if (execfile == 0 || exec_bfd == 0) | |
b8464c15 | 414 | error ("No executable file specified"); |
fa4b55a1 SC |
415 | |
416 | entry_pt = (int) bfd_get_start_address (exec_bfd); | |
ec25d19b | 417 | check_open (); |
1f46923f | 418 | |
ec25d19b SC |
419 | hms_kill (NULL, NULL); |
420 | hms_clear_breakpoints (); | |
ae0ea72e | 421 | init_wait_for_inferior (); |
ec25d19b SC |
422 | hms_write_cr (""); |
423 | expect_prompt (); | |
fa4b55a1 | 424 | |
ae0ea72e | 425 | insert_breakpoints (); /* Needed to get correct instruction in cache */ |
45dc9be3 | 426 | proceed (entry_pt, TARGET_SIGNAL_DEFAULT, 0); |
fa4b55a1 SC |
427 | } |
428 | ||
fa4b55a1 SC |
429 | /* Open a connection to a remote debugger. |
430 | NAME is the filename used for communication, then a space, | |
431 | then the baud rate. | |
432 | */ | |
433 | ||
434 | static char * | |
ec25d19b SC |
435 | find_end_of_word (s) |
436 | char *s; | |
fa4b55a1 | 437 | { |
ec25d19b SC |
438 | while (*s && !isspace (*s)) |
439 | s++; | |
fa4b55a1 SC |
440 | return s; |
441 | } | |
442 | ||
ec25d19b SC |
443 | static char * |
444 | get_word (p) | |
445 | char **p; | |
fa4b55a1 SC |
446 | { |
447 | char *s = *p; | |
ec25d19b | 448 | char *word; |
fa4b55a1 SC |
449 | char *copy; |
450 | size_t len; | |
451 | ||
ec25d19b SC |
452 | while (isspace (*s)) |
453 | s++; | |
fa4b55a1 SC |
454 | |
455 | word = s; | |
456 | ||
457 | len = 0; | |
458 | ||
ec25d19b SC |
459 | while (*s && !isspace (*s)) |
460 | { | |
461 | s++; | |
462 | len++; | |
463 | ||
464 | } | |
465 | copy = xmalloc (len + 1); | |
466 | memcpy (copy, word, len); | |
fa4b55a1 SC |
467 | copy[len] = 0; |
468 | *p = s; | |
469 | return copy; | |
470 | } | |
471 | ||
472 | static int baudrate = 9600; | |
1f46923f SC |
473 | |
474 | static int | |
ec25d19b | 475 | is_baudrate_right () |
1f46923f | 476 | { |
ae0ea72e | 477 | int ok; |
ec25d19b | 478 | |
1f46923f | 479 | /* Put this port into NORMAL mode, send the 'normal' character */ |
ae0ea72e | 480 | |
ec25d19b | 481 | hms_write ("\001", 1); /* Control A */ |
3b5442f9 | 482 | hms_write ("\r\n", 2); /* Cr */ |
ae0ea72e | 483 | |
ec25d19b SC |
484 | while (1) |
485 | { | |
a493d9a6 | 486 | ok = SERIAL_READCHAR (desc, timeout); |
ec25d19b SC |
487 | if (ok < 0) |
488 | break; | |
489 | } | |
ae0ea72e | 490 | |
ec25d19b SC |
491 | hms_write ("r", 1); |
492 | ||
493 | if (readchar_nofail () == 'r') | |
494 | return 1; | |
1f46923f SC |
495 | |
496 | /* Not the right baudrate, or the board's not on */ | |
497 | return 0; | |
1f46923f SC |
498 | } |
499 | static void | |
ec25d19b | 500 | set_rate () |
1f46923f | 501 | { |
a493d9a6 | 502 | if (!SERIAL_SETBAUDRATE (desc, baudrate)) |
ec25d19b | 503 | error ("Can't set baudrate"); |
1f46923f SC |
504 | } |
505 | ||
1f46923f | 506 | |
fa4b55a1 SC |
507 | |
508 | /* Close out all files and local state before this target loses control. */ | |
509 | ||
510 | static void | |
511 | hms_close (quitting) | |
512 | int quitting; | |
513 | { | |
fa4b55a1 | 514 | /* Clear any break points */ |
3b5442f9 | 515 | remove_commands (); |
ec25d19b | 516 | hms_clear_breakpoints (); |
ec25d19b | 517 | sleep (1); /* Let any output make it all the way back */ |
a493d9a6 SC |
518 | if (is_open) |
519 | { | |
3b5442f9 | 520 | SERIAL_WRITE (desc, "R\r\n", 3); |
a493d9a6 SC |
521 | SERIAL_CLOSE (desc); |
522 | } | |
ae0ea72e | 523 | is_open = 0; |
fa4b55a1 SC |
524 | } |
525 | ||
3b5442f9 | 526 | /* Terminate the open connection to the remote debugger. Use this |
03fc5a0b | 527 | when you want to detach and do something else with your gdb. */ void |
ec25d19b | 528 | hms_detach (args, from_tty) |
fa4b55a1 SC |
529 | char *args; |
530 | int from_tty; | |
531 | { | |
ae0ea72e | 532 | if (is_open) |
ec25d19b SC |
533 | { |
534 | hms_clear_breakpoints (); | |
535 | } | |
536 | ||
3b5442f9 | 537 | pop_target (); /* calls hms_close to do the real work |
03fc5a0b | 538 | */ |
fa4b55a1 | 539 | if (from_tty) |
3b5442f9 SC |
540 | printf_filtered ("Ending remote %s debugging\n", |
541 | target_shortname); | |
fa4b55a1 | 542 | } |
ec25d19b | 543 | |
fa4b55a1 SC |
544 | /* Tell the remote machine to resume. */ |
545 | ||
546 | void | |
25286543 | 547 | hms_resume (pid, step, sig) |
67ac9759 | 548 | int pid, step; |
3b5442f9 SC |
549 | enum target_signal |
550 | sig; | |
fa4b55a1 | 551 | { |
ec25d19b SC |
552 | if (step) |
553 | { | |
554 | hms_write_cr ("s"); | |
555 | expect ("Step>"); | |
556 | ||
557 | /* Force the next hms_wait to return a trap. Not doing anything | |
03fc5a0b SC |
558 | about I/O from the target means that the user has to type "continue" |
559 | to see any. FIXME, this should be fixed. */ | |
ec25d19b SC |
560 | need_artificial_trap = 1; |
561 | } | |
fa4b55a1 | 562 | else |
ec25d19b SC |
563 | { |
564 | hms_write_cr ("g"); | |
565 | expect ("g"); | |
566 | } | |
fa4b55a1 SC |
567 | } |
568 | ||
3b5442f9 | 569 | /* Wait until the remote machine stops, then return, storing status in |
03fc5a0b | 570 | STATUS just as `wait' would. */ |
fa4b55a1 SC |
571 | |
572 | int | |
de43d7d0 SG |
573 | hms_wait (pid, status) |
574 | int pid; | |
67ac9759 | 575 | struct target_waitstatus *status; |
fa4b55a1 | 576 | { |
3b5442f9 SC |
577 | /* Strings to look for. '?' means match any single character. Note |
578 | that with the algorithm we use, the initial character of the string | |
579 | cannot recur in the string, or we will not find some cases of the | |
580 | string in the input. */ | |
ec25d19b | 581 | |
96743d3c | 582 | static char bpt[] = "At breakpoint:"; |
ec25d19b | 583 | |
3b5442f9 SC |
584 | /* It would be tempting to look for "\n[__exit + 0x8]\n" but that |
585 | requires loading symbols with "yc i" and even if we did do that we | |
03fc5a0b SC |
586 | don't know that the file has symbols. */ |
587 | static char exitmsg[] = "HMS>"; | |
fa4b55a1 SC |
588 | char *bp = bpt; |
589 | char *ep = exitmsg; | |
590 | ||
3b5442f9 SC |
591 | /* Large enough for either sizeof (bpt) or sizeof (exitmsg) chars. |
592 | */ | |
fa4b55a1 | 593 | char swallowed[50]; |
ec25d19b | 594 | |
fa4b55a1 SC |
595 | /* Current position in swallowed. */ |
596 | char *swallowed_p = swallowed; | |
597 | ||
598 | int ch; | |
599 | int ch_handled; | |
600 | int old_timeout = timeout; | |
3b5442f9 SC |
601 | int |
602 | old_immediate_quit = immediate_quit; | |
1f46923f | 603 | int swallowed_cr = 0; |
ec25d19b | 604 | |
67ac9759 JK |
605 | status->kind = TARGET_WAITKIND_EXITED; |
606 | status->value.integer = 0; | |
fa4b55a1 SC |
607 | |
608 | if (need_artificial_trap != 0) | |
ec25d19b | 609 | { |
3b5442f9 SC |
610 | status->kind = |
611 | TARGET_WAITKIND_STOPPED; | |
67ac9759 | 612 | status->value.sig = TARGET_SIGNAL_TRAP; |
ec25d19b SC |
613 | need_artificial_trap--; |
614 | return 0; | |
615 | } | |
fa4b55a1 | 616 | |
63eef03a | 617 | timeout = 5; /* Don't time out for a while - user program is running. |
3b5442f9 | 618 | */ |
1f46923f | 619 | immediate_quit = 1; /* Helps ability to QUIT */ |
ec25d19b | 620 | while (1) |
96743d3c | 621 | { |
ec25d19b SC |
622 | QUIT; /* Let user quit and leave process running */ |
623 | ch_handled = 0; | |
624 | ch = readchar (); | |
625 | if (ch == *bp) | |
626 | { | |
627 | bp++; | |
628 | if (*bp == '\0') | |
629 | break; | |
630 | ch_handled = 1; | |
631 | ||
632 | *swallowed_p++ = ch; | |
633 | } | |
634 | else | |
635 | { | |
636 | bp = bpt; | |
637 | } | |
3b5442f9 SC |
638 | if |
639 | (ch == *ep || *ep == '?') | |
03fc5a0b SC |
640 | { |
641 | ep++; | |
642 | if (*ep == '\0') | |
643 | break; | |
644 | ||
645 | if (!ch_handled) | |
646 | *swallowed_p++ = ch; | |
647 | ch_handled = | |
648 | 1; | |
649 | } | |
ec25d19b SC |
650 | else |
651 | { | |
652 | ep = exitmsg; | |
653 | } | |
654 | ||
655 | if (!ch_handled) | |
656 | { | |
657 | char *p; | |
658 | ||
659 | /* Print out any characters which have been swallowed. */ | |
660 | for (p = swallowed; p < swallowed_p; ++p) | |
7baea946 | 661 | putchar_unfiltered (*p); |
ec25d19b SC |
662 | swallowed_p = swallowed; |
663 | ||
664 | if ((ch != '\r' && ch != '\n') || swallowed_cr > 10) | |
665 | { | |
7baea946 | 666 | putchar_unfiltered (ch); |
ec25d19b SC |
667 | swallowed_cr = 10; |
668 | } | |
669 | swallowed_cr++; | |
670 | ||
671 | } | |
96743d3c | 672 | } |
ec25d19b | 673 | if (*bp == '\0') |
96743d3c | 674 | { |
67ac9759 JK |
675 | status->kind = TARGET_WAITKIND_STOPPED; |
676 | status->value.sig = TARGET_SIGNAL_TRAP; | |
ec25d19b SC |
677 | expect_prompt (); |
678 | } | |
679 | else | |
96743d3c | 680 | { |
67ac9759 | 681 | status->kind = TARGET_WAITKIND_EXITED; |
3b5442f9 SC |
682 | status->value.integer = |
683 | TARGET_SIGNAL_STOP; | |
96743d3c | 684 | } |
ec25d19b | 685 | |
fa4b55a1 SC |
686 | timeout = old_timeout; |
687 | immediate_quit = old_immediate_quit; | |
3b5442f9 SC |
688 | return |
689 | 0; | |
fa4b55a1 SC |
690 | } |
691 | ||
3b5442f9 | 692 | /* Return the name of register number REGNO in the form input and |
03fc5a0b | 693 | output by hms. |
fa4b55a1 SC |
694 | |
695 | Returns a pointer to a static buffer containing the answer. */ | |
696 | static char * | |
697 | get_reg_name (regno) | |
698 | int regno; | |
699 | { | |
3b5442f9 SC |
700 | static char *rn[] = |
701 | REGISTER_NAMES; | |
ec25d19b | 702 | |
fa4b55a1 | 703 | return rn[regno]; |
fa4b55a1 SC |
704 | } |
705 | ||
03fc5a0b | 706 | /* Read the remote registers. */ |
3b5442f9 | 707 | |
a493d9a6 | 708 | static int |
ec25d19b SC |
709 | gethex (length, start, ok) |
710 | unsigned int length; | |
711 | char *start; | |
712 | int *ok; | |
fa4b55a1 SC |
713 | { |
714 | int result = 0; | |
ec25d19b SC |
715 | |
716 | while (length--) | |
fa4b55a1 | 717 | { |
ec25d19b SC |
718 | result <<= 4; |
719 | if (*start >= 'a' && *start <= 'f') | |
720 | { | |
721 | result += *start - 'a' + 10; | |
722 | } | |
3b5442f9 SC |
723 | else if (*start >= 'A' && |
724 | *start <= 'F') | |
ec25d19b SC |
725 | { |
726 | result += *start - 'A' + 10; | |
727 | } | |
3b5442f9 SC |
728 | else if |
729 | (*start >= '0' && *start <= '9') | |
03fc5a0b SC |
730 | { |
731 | result += *start - '0'; | |
732 | } | |
ec25d19b SC |
733 | else |
734 | *ok = 0; | |
735 | start++; | |
736 | ||
fa4b55a1 | 737 | } |
fa4b55a1 SC |
738 | return result; |
739 | } | |
ec25d19b SC |
740 | static int |
741 | timed_read (buf, n, timeout) | |
3b5442f9 SC |
742 | char |
743 | *buf; | |
fa4b55a1 SC |
744 | |
745 | { | |
746 | int i; | |
747 | char c; | |
ec25d19b | 748 | |
fa4b55a1 | 749 | i = 0; |
ec25d19b SC |
750 | while (i < n) |
751 | { | |
752 | c = readchar (); | |
753 | ||
754 | if (c == 0) | |
755 | return i; | |
756 | buf[i] = c; | |
757 | i++; | |
758 | ||
759 | } | |
760 | return i; | |
fa4b55a1 | 761 | } |
ec25d19b SC |
762 | |
763 | hms_write (a, l) | |
764 | char *a; | |
fa4b55a1 SC |
765 | { |
766 | int i; | |
ec25d19b | 767 | |
a493d9a6 | 768 | SERIAL_WRITE (desc, a, l); |
ae0ea72e | 769 | |
791d4d7d | 770 | if (!quiet || remote_debug) |
3b5442f9 SC |
771 | { |
772 | printf_unfiltered ("<"); | |
773 | for (i = 0; i < l; i++) | |
774 | { | |
775 | printf_unfiltered ("%c", a[i]); | |
776 | } | |
777 | printf_unfiltered (">"); | |
778 | } | |
fa4b55a1 SC |
779 | } |
780 | ||
ec25d19b SC |
781 | hms_write_cr (s) |
782 | char *s; | |
fa4b55a1 | 783 | { |
ec25d19b | 784 | hms_write (s, strlen (s)); |
3b5442f9 | 785 | hms_write ("\r\n", 2); |
1f46923f SC |
786 | } |
787 | ||
edd01519 SC |
788 | #ifdef GDB_TARGET_IS_H8500 |
789 | ||
790 | /* H8/500 monitor reg dump looks like: | |
791 | ||
03fc5a0b SC |
792 | HMS>r |
793 | PC:8000 SR:070C .7NZ.. CP:00 DP:00 EP:00 TP:00 BR:00 | |
794 | R0-R7: FF5A 0001 F4FE F500 0000 F528 F528 F4EE | |
795 | HMS> | |
edd01519 SC |
796 | |
797 | ||
03fc5a0b | 798 | */ |
edd01519 | 799 | |
3b5442f9 SC |
800 | supply_val (n, size, ptr, segptr) |
801 | int n; | |
802 | int size; | |
803 | char *ptr; | |
804 | char *segptr; | |
edd01519 SC |
805 | { |
806 | int ok; | |
807 | char raw[4]; | |
3b5442f9 | 808 | switch (size) |
edd01519 SC |
809 | { |
810 | case 2: | |
3b5442f9 SC |
811 | raw[0] = gethex (2, ptr, &ok); |
812 | raw[1] = gethex (2, ptr + 2, &ok); | |
edd01519 SC |
813 | supply_register (n, raw); |
814 | break; | |
815 | case 1: | |
3b5442f9 | 816 | raw[0] = gethex (2, ptr, &ok); |
edd01519 SC |
817 | supply_register (n, raw); |
818 | break; | |
819 | case 4: | |
820 | { | |
821 | int v = gethex (4, ptr, &ok); | |
822 | v |= gethex (2, segptr, &ok) << 16; | |
823 | raw[0] = 0; | |
3b5442f9 SC |
824 | raw[1] = (v >> 16) & 0xff; |
825 | raw[2] = (v >> 8) & 0xff; | |
826 | raw[3] = (v >> 0) & 0xff; | |
edd01519 SC |
827 | supply_register (n, raw); |
828 | } | |
829 | } | |
830 | ||
831 | } | |
832 | static void | |
833 | hms_fetch_register (dummy) | |
834 | int dummy; | |
835 | { | |
836 | #define REGREPLY_SIZE 108 | |
837 | char linebuf[REGREPLY_SIZE + 1]; | |
838 | int i; | |
839 | int s; | |
840 | int gottok; | |
841 | ||
678ee700 | 842 | LONGEST reg[NUM_REGS]; |
edd01519 SC |
843 | check_open (); |
844 | ||
845 | do | |
846 | { | |
847 | ||
848 | hms_write_cr ("r"); | |
3b5442f9 SC |
849 | expect ("r"); |
850 | s = timed_read (linebuf + 1, REGREPLY_SIZE, 1); | |
edd01519 SC |
851 | |
852 | linebuf[REGREPLY_SIZE] = 0; | |
853 | gottok = 0; | |
854 | if (linebuf[3] == 'P' && | |
855 | linebuf[4] == 'C' && | |
856 | linebuf[5] == ':' && | |
857 | linebuf[105] == 'H' && | |
858 | linebuf[106] == 'M' && | |
859 | linebuf[107] == 'S') | |
860 | { | |
861 | ||
862 | /* | |
03fc5a0b SC |
863 | 012 |
864 | r** | |
865 | -------1---------2---------3---------4---------5----- | |
866 | 345678901234567890123456789012345678901234567890123456 | |
867 | PC:8000 SR:070C .7NZ.. CP:00 DP:00 EP:00 TP:00 BR:00** | |
868 | ---6---------7---------8---------9--------10---- | |
869 | 789012345678901234567890123456789012345678901234 | |
870 | R0-R7: FF5A 0001 F4FE F500 0000 F528 F528 F4EE** | |
871 | ||
872 | 56789 | |
873 | HMS> | |
874 | */ | |
edd01519 SC |
875 | gottok = 1; |
876 | ||
edd01519 | 877 | |
3b5442f9 SC |
878 | supply_val (PC_REGNUM, 4, linebuf + 6, linebuf + 29); |
879 | ||
880 | supply_val (CCR_REGNUM, 2, linebuf + 14); | |
881 | supply_val (SEG_C_REGNUM, 1, linebuf + 29); | |
882 | supply_val (SEG_D_REGNUM, 1, linebuf + 35); | |
883 | supply_val (SEG_E_REGNUM, 1, linebuf + 41); | |
884 | supply_val (SEG_T_REGNUM, 1, linebuf + 47); | |
edd01519 SC |
885 | for (i = 0; i < 8; i++) |
886 | { | |
3b5442f9 SC |
887 | static int sr[8] = |
888 | {35, 35, 35, 35, | |
889 | 41, 41, 47, 47}; | |
edd01519 SC |
890 | |
891 | char raw[4]; | |
892 | char *src = linebuf + 64 + 5 * i; | |
893 | char *segsrc = linebuf + sr[i]; | |
3b5442f9 SC |
894 | supply_val (R0_REGNUM + i, 2, src); |
895 | supply_val (PR0_REGNUM + i, 4, src, segsrc); | |
edd01519 SC |
896 | } |
897 | } | |
898 | if (!gottok) | |
899 | { | |
3b5442f9 SC |
900 | hms_write_cr (""); |
901 | expect ("HMS>"); | |
edd01519 SC |
902 | } |
903 | } | |
904 | while (!gottok); | |
905 | } | |
906 | #endif | |
907 | ||
908 | #ifdef GDB_TARGET_IS_H8300 | |
1f46923f | 909 | static void |
ae0ea72e | 910 | hms_fetch_register (dummy) |
ec25d19b | 911 | int dummy; |
fa4b55a1 SC |
912 | { |
913 | #define REGREPLY_SIZE 79 | |
ec25d19b | 914 | char linebuf[REGREPLY_SIZE + 1]; |
fa4b55a1 | 915 | int i; |
ec25d19b | 916 | int s; |
fa4b55a1 | 917 | int gottok; |
ec25d19b | 918 | |
119dfbb7 | 919 | ULONGEST reg[NUM_REGS]; |
ec25d19b SC |
920 | |
921 | check_open (); | |
922 | ||
923 | do | |
fa4b55a1 | 924 | { |
ec25d19b | 925 | hms_write_cr ("r"); |
3b5442f9 SC |
926 | |
927 | s = timed_read (linebuf, 1, 1); | |
928 | ||
929 | while (linebuf[0] != 'r') | |
930 | s = timed_read (linebuf, 1, 1); | |
931 | ||
932 | s = timed_read (linebuf + 1, REGREPLY_SIZE - 1, 1); | |
ec25d19b SC |
933 | |
934 | linebuf[REGREPLY_SIZE] = 0; | |
935 | gottok = 0; | |
936 | if (linebuf[0] == 'r' && | |
937 | linebuf[3] == 'P' && | |
938 | linebuf[4] == 'C' && | |
939 | linebuf[5] == '=' && | |
940 | linebuf[75] == 'H' && | |
941 | linebuf[76] == 'M' && | |
942 | linebuf[77] == 'S') | |
943 | { | |
944 | /* | |
03fc5a0b SC |
945 | PC=XXXX CCR=XX:XXXXXXXX R0-R7= XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX |
946 | 5436789012345678901234567890123456789012345678901234567890123456789012 | |
947 | 0 1 2 3 4 5 6 | |
948 | */ | |
ec25d19b SC |
949 | gottok = 1; |
950 | ||
951 | reg[PC_REGNUM] = gethex (4, linebuf + 6, &gottok); | |
952 | reg[CCR_REGNUM] = gethex (2, linebuf + 15, &gottok); | |
953 | for (i = 0; i < 8; i++) | |
954 | { | |
955 | reg[i] = gethex (4, linebuf + 34 + 5 * i, &gottok); | |
956 | } | |
957 | } | |
fa4b55a1 | 958 | } |
fa4b55a1 | 959 | while (!gottok); |
ec25d19b SC |
960 | for (i = 0; i < NUM_REGS; i++) |
961 | { | |
962 | char swapped[2]; | |
fa4b55a1 | 963 | |
ec25d19b SC |
964 | swapped[1] = reg[i]; |
965 | swapped[0] = (reg[i]) >> 8; | |
fa4b55a1 | 966 | |
ec25d19b SC |
967 | supply_register (i, swapped); |
968 | } | |
969 | } | |
edd01519 | 970 | #endif |
fa4b55a1 SC |
971 | /* Store register REGNO, or all if REGNO == -1. |
972 | Return errno value. */ | |
ae0ea72e | 973 | static void |
fa4b55a1 SC |
974 | hms_store_register (regno) |
975 | int regno; | |
976 | { | |
ec25d19b | 977 | if (regno == -1) |
ae0ea72e | 978 | { |
ec25d19b SC |
979 | for (regno = 0; regno < NUM_REGS; regno++) |
980 | { | |
981 | hms_store_register (regno); | |
982 | } | |
ae0ea72e | 983 | } |
fa4b55a1 | 984 | else |
ec25d19b SC |
985 | { |
986 | char *name = get_reg_name (regno); | |
987 | char buffer[100]; | |
3b5442f9 SC |
988 | /* Some regs dont really exist */ |
989 | if (!(name[0] == 'p' && name[1] == 'r') | |
990 | && !(name[0] == 'c' && name[1] == 'y') | |
991 | && !(name[0] == 't' && name[1] == 'i') | |
992 | && !(name[0] == 'i' && name[1] == 'n')) | |
993 | { | |
994 | sprintf (buffer, "r %s=%x", name, read_register (regno)); | |
995 | hms_write_cr (buffer); | |
996 | expect_prompt (); | |
997 | } | |
edd01519 | 998 | } |
ec25d19b | 999 | } |
ae0ea72e | 1000 | |
edd01519 | 1001 | |
fa4b55a1 SC |
1002 | /* Get ready to modify the registers array. On machines which store |
1003 | individual registers, this doesn't need to do anything. On machines | |
1004 | which store all the registers in one fell swoop, this makes sure | |
1005 | that registers contains all the registers from the program being | |
1006 | debugged. */ | |
1007 | ||
1008 | void | |
1009 | hms_prepare_to_store () | |
1010 | { | |
1011 | /* Do nothing, since we can store individual regs */ | |
1012 | } | |
1013 | ||
ec25d19b SC |
1014 | static CORE_ADDR |
1015 | translate_addr (addr) | |
1016 | CORE_ADDR addr; | |
fa4b55a1 SC |
1017 | { |
1018 | ||
ec25d19b | 1019 | return (addr); |
fa4b55a1 SC |
1020 | |
1021 | } | |
1022 | ||
fa4b55a1 SC |
1023 | |
1024 | int | |
ec25d19b | 1025 | hms_xfer_inferior_memory (memaddr, myaddr, len, write, target) |
fa4b55a1 SC |
1026 | CORE_ADDR memaddr; |
1027 | char *myaddr; | |
1028 | int len; | |
1029 | int write; | |
ec25d19b | 1030 | struct target_ops *target; /* ignored */ |
fa4b55a1 | 1031 | { |
fa4b55a1 | 1032 | |
fa4b55a1 SC |
1033 | return len; |
1034 | } | |
1035 | ||
fa4b55a1 SC |
1036 | int |
1037 | hms_write_inferior_memory (memaddr, myaddr, len) | |
1038 | CORE_ADDR memaddr; | |
ae0ea72e | 1039 | unsigned char *myaddr; |
fa4b55a1 SC |
1040 | int len; |
1041 | { | |
ae0ea72e SC |
1042 | bfd_vma addr; |
1043 | int done; | |
ec25d19b | 1044 | int todo; |
3b5442f9 | 1045 | char buffer[100]; |
ae0ea72e | 1046 | done = 0; |
3b5442f9 SC |
1047 | hms_write_cr ("."); |
1048 | expect_prompt (); | |
ec25d19b | 1049 | while (done < len) |
ae0ea72e | 1050 | { |
3b5442f9 | 1051 | char *ptr = buffer; |
ec25d19b SC |
1052 | int thisgo; |
1053 | int idx; | |
1054 | ||
1055 | thisgo = len - done; | |
1056 | if (thisgo > 20) | |
1057 | thisgo = 20; | |
ae0ea72e | 1058 | |
3b5442f9 SC |
1059 | sprintf (ptr, "M.B %4x =", memaddr + done); |
1060 | ptr += 10; | |
ec25d19b SC |
1061 | for (idx = 0; idx < thisgo; idx++) |
1062 | { | |
3b5442f9 SC |
1063 | sprintf (ptr, "%2x ", myaddr[idx + done]); |
1064 | ptr += 3; | |
ec25d19b | 1065 | } |
3b5442f9 | 1066 | hms_write_cr (buffer); |
ec25d19b SC |
1067 | expect_prompt (); |
1068 | done += thisgo; | |
1069 | } | |
fa4b55a1 SC |
1070 | } |
1071 | ||
1072 | void | |
1073 | hms_files_info () | |
1074 | { | |
ec25d19b SC |
1075 | char *file = "nothing"; |
1076 | ||
1077 | if (exec_bfd) | |
1078 | file = bfd_get_filename (exec_bfd); | |
ae0ea72e | 1079 | |
ec25d19b | 1080 | if (exec_bfd) |
ae0ea72e | 1081 | #ifdef __GO32__ |
ec25d19b | 1082 | printf_filtered ("\tAttached to DOS asynctsr and running program %s\n", file); |
ae0ea72e | 1083 | #else |
5905161c | 1084 | printf_filtered ("\tAttached to %s at %d baud and running program %s\n", dev_name, baudrate, file); |
ae0ea72e | 1085 | #endif |
ec25d19b | 1086 | printf_filtered ("\ton an H8/300 processor.\n"); |
fa4b55a1 SC |
1087 | } |
1088 | ||
1089 | /* Copy LEN bytes of data from debugger memory at MYADDR | |
ec25d19b | 1090 | to inferior's memory at MEMADDR. Returns errno value. |
03fc5a0b | 1091 | * sb/sh instructions don't work on unaligned addresses, when TU=1. |
fa4b55a1 SC |
1092 | */ |
1093 | ||
fa4b55a1 SC |
1094 | /* Read LEN bytes from inferior memory at MEMADDR. Put the result |
1095 | at debugger address MYADDR. Returns errno value. */ | |
1096 | int | |
ec25d19b | 1097 | hms_read_inferior_memory (memaddr, myaddr, len) |
fa4b55a1 SC |
1098 | CORE_ADDR memaddr; |
1099 | char *myaddr; | |
1100 | int len; | |
1101 | { | |
1102 | /* Align to nearest low 16 bits */ | |
1103 | int i; | |
ec25d19b | 1104 | |
fa4b55a1 | 1105 | CORE_ADDR start = memaddr; |
ec25d19b SC |
1106 | CORE_ADDR end = memaddr + len - 1; |
1107 | ||
1108 | int ok = 1; | |
1109 | ||
fa4b55a1 | 1110 | /* |
03fc5a0b SC |
1111 | AAAA: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX '................' |
1112 | 012345678901234567890123456789012345678901234567890123456789012345 | |
1113 | 0 1 2 3 4 5 6 | |
1114 | */ | |
fa4b55a1 | 1115 | char buffer[66]; |
ec25d19b SC |
1116 | |
1117 | if (memaddr & 0xf) | |
1118 | abort (); | |
1119 | if (len != 16) | |
1120 | abort (); | |
1121 | ||
1122 | sprintf (buffer, "m %4x %4x", start & 0xffff, end & 0xffff); | |
402b0d2e | 1123 | |
03fc5a0b | 1124 | flush (); |
ec25d19b | 1125 | hms_write_cr (buffer); |
03fc5a0b | 1126 | /* drop the echo and newline */ |
fa4b55a1 | 1127 | for (i = 0; i < 13; i++) |
ec25d19b | 1128 | readchar (); |
fa4b55a1 | 1129 | |
fa4b55a1 SC |
1130 | /* Grab the lines as they come out and fill the area */ |
1131 | /* Skip over cr */ | |
ec25d19b | 1132 | while (1) |
fa4b55a1 | 1133 | { |
ec25d19b SC |
1134 | int p; |
1135 | int i; | |
1136 | int addr; | |
1137 | size_t idx; | |
fa4b55a1 | 1138 | |
ec25d19b SC |
1139 | char byte[16]; |
1140 | ||
1141 | buffer[0] = readchar (); | |
03fc5a0b | 1142 | while (buffer[0] == '\r' |
a87594a5 SC |
1143 | || buffer[0] == '\n') |
1144 | buffer[0] = readchar (); | |
1145 | ||
ec25d19b SC |
1146 | if (buffer[0] == 'M') |
1147 | break; | |
402b0d2e | 1148 | |
03fc5a0b SC |
1149 | for (i = 1; i < 50; i++) |
1150 | { | |
1151 | buffer[i] = readchar (); | |
1152 | } | |
402b0d2e | 1153 | /* sometimes we loose characters in the ascii representation of the |
03fc5a0b SC |
1154 | data. I don't know where. So just scan for the end of line */ |
1155 | i = readchar (); | |
402b0d2e | 1156 | while (i != '\n' && i != '\r') |
03fc5a0b SC |
1157 | i = readchar (); |
1158 | ||
ec25d19b SC |
1159 | /* Now parse the line */ |
1160 | ||
1161 | addr = gethex (4, buffer, &ok); | |
1162 | idx = 6; | |
1163 | for (p = 0; p < 16; p += 2) | |
1164 | { | |
1165 | byte[p] = gethex (2, buffer + idx, &ok); | |
1166 | byte[p + 1] = gethex (2, buffer + idx + 2, &ok); | |
1167 | idx += 5; | |
ec25d19b SC |
1168 | } |
1169 | ||
1170 | for (p = 0; p < 16; p++) | |
1171 | { | |
1172 | if (addr + p >= memaddr && | |
1173 | addr + p < memaddr + len) | |
1174 | { | |
1175 | myaddr[(addr + p) - memaddr] = byte[p]; | |
1176 | ||
1177 | } | |
1178 | ||
1179 | } | |
fa4b55a1 | 1180 | } |
3b5442f9 SC |
1181 | #ifdef GDB_TARGET_IS_H8500 |
1182 | expect ("ore>"); | |
edd01519 | 1183 | #endif |
3b5442f9 | 1184 | #ifdef GDB_TARGET_IS_H8300 |
a493d9a6 | 1185 | expect ("emory>"); |
edd01519 | 1186 | #endif |
3b5442f9 SC |
1187 | hms_write_cr ("."); |
1188 | ||
ec25d19b | 1189 | expect_prompt (); |
fa4b55a1 | 1190 | return len; |
fa4b55a1 SC |
1191 | } |
1192 | ||
edd01519 | 1193 | |
fa4b55a1 | 1194 | |
fa4b55a1 | 1195 | #define MAX_BREAKS 16 |
ec25d19b | 1196 | static int num_brkpts = 0; |
fa4b55a1 | 1197 | static int |
ec25d19b SC |
1198 | hms_insert_breakpoint (addr, save) |
1199 | CORE_ADDR addr; | |
1200 | char *save; /* Throw away, let hms save instructions */ | |
fa4b55a1 | 1201 | { |
ec25d19b SC |
1202 | check_open (); |
1203 | ||
1204 | if (num_brkpts < MAX_BREAKS) | |
1205 | { | |
1206 | char buffer[100]; | |
fa4b55a1 | 1207 | |
ec25d19b SC |
1208 | num_brkpts++; |
1209 | sprintf (buffer, "b %x", addr & 0xffff); | |
1210 | hms_write_cr (buffer); | |
1211 | expect_prompt (); | |
1212 | return (0); | |
1213 | } | |
1214 | else | |
1215 | { | |
199b2450 | 1216 | fprintf_filtered (gdb_stderr, |
ec25d19b SC |
1217 | "Too many break points, break point not installed\n"); |
1218 | return (1); | |
1219 | } | |
fa4b55a1 SC |
1220 | |
1221 | } | |
1222 | static int | |
ec25d19b SC |
1223 | hms_remove_breakpoint (addr, save) |
1224 | CORE_ADDR addr; | |
1225 | char *save; /* Throw away, let hms save instructions */ | |
fa4b55a1 | 1226 | { |
ec25d19b SC |
1227 | if (num_brkpts > 0) |
1228 | { | |
1229 | char buffer[100]; | |
1230 | ||
1231 | num_brkpts--; | |
1232 | sprintf (buffer, "b - %x", addr & 0xffff); | |
1233 | hms_write_cr (buffer); | |
1234 | expect_prompt (); | |
1235 | ||
1236 | } | |
1237 | return (0); | |
fa4b55a1 SC |
1238 | } |
1239 | ||
1240 | /* Clear the hmss notion of what the break points are */ | |
1241 | static int | |
ec25d19b SC |
1242 | hms_clear_breakpoints () |
1243 | { | |
fa4b55a1 | 1244 | |
ec25d19b SC |
1245 | if (is_open) |
1246 | { | |
1247 | hms_write_cr ("b -"); | |
1248 | expect_prompt (); | |
1249 | } | |
fa4b55a1 | 1250 | num_brkpts = 0; |
fa4b55a1 SC |
1251 | } |
1252 | static void | |
ec25d19b SC |
1253 | hms_mourn () |
1254 | { | |
1255 | hms_clear_breakpoints (); | |
71607f9d | 1256 | unpush_target (&hms_ops); |
fa4b55a1 | 1257 | generic_mourn_inferior (); |
fa4b55a1 SC |
1258 | } |
1259 | ||
fa4b55a1 | 1260 | /* Put a command string, in args, out to the hms. The hms is assumed to |
ae0ea72e | 1261 | be in raw mode, all writing/reading done through desc. |
fa4b55a1 SC |
1262 | Ouput from the hms is placed on the users terminal until the |
1263 | prompt from the hms is seen. | |
1264 | FIXME: Can't handle commands that take input. */ | |
1265 | ||
1266 | void | |
1267 | hms_com (args, fromtty) | |
ec25d19b SC |
1268 | char *args; |
1269 | int fromtty; | |
fa4b55a1 | 1270 | { |
ec25d19b SC |
1271 | check_open (); |
1272 | ||
1273 | if (!args) | |
1274 | return; | |
1275 | ||
fa4b55a1 SC |
1276 | /* Clear all input so only command relative output is displayed */ |
1277 | ||
ec25d19b | 1278 | hms_write_cr (args); |
03fc5a0b SC |
1279 | /* hms_write ("\030", 1); */ |
1280 | expect_prompt (); | |
1281 | } | |
1282 | ||
1283 | static void | |
1284 | hms_open (name, from_tty) | |
1285 | char *name; | |
1286 | int from_tty; | |
1287 | { | |
1288 | unsigned int prl; | |
1289 | char *p; | |
1290 | ||
1291 | if (name == 0) | |
1292 | { | |
1293 | name = ""; | |
1294 | } | |
1295 | if (is_open) | |
1296 | hms_close (0); | |
1297 | dev_name = strdup (name); | |
1298 | ||
1299 | if (!(desc = SERIAL_OPEN (dev_name))) | |
1300 | perror_with_name ((char *) dev_name); | |
1301 | ||
1302 | SERIAL_RAW (desc); | |
1303 | is_open = 1; | |
1304 | push_target (&hms_ops); | |
5d747d61 SC |
1305 | dcache_ptr = dcache_init (hms_read_inferior_memory, |
1306 | hms_write_inferior_memory); | |
1307 | remote_dcache = 1; | |
03fc5a0b SC |
1308 | /* Hello? Are you there? */ |
1309 | SERIAL_WRITE (desc, "\r\n", 2); | |
ec25d19b | 1310 | expect_prompt (); |
03fc5a0b SC |
1311 | |
1312 | /* Clear any break points */ | |
1313 | hms_clear_breakpoints (); | |
1314 | ||
1315 | printf_filtered ("Connected to remote board running HMS monitor.\n"); | |
1316 | add_commands (); | |
1317 | /* hms_drain (); */ | |
fa4b55a1 SC |
1318 | } |
1319 | ||
1320 | /* Define the target subroutine names */ | |
1321 | ||
c719b714 JM |
1322 | struct target_ops hms_ops ; |
1323 | static void init_hms_ops(void) | |
ec25d19b | 1324 | { |
c719b714 JM |
1325 | hms_ops.to_shortname = "hms"; |
1326 | hms_ops.to_longname = "Remote HMS monitor"; | |
1327 | hms_ops.to_doc = "Use the H8 evaluation board running the HMS monitor connected\n\ | |
1328 | by a serial line."; | |
1329 | hms_ops.to_open = hms_open; | |
1330 | hms_ops.to_close = hms_close; | |
1331 | hms_ops.to_attach = 0; | |
4ef1f467 DT |
1332 | hms_ops.to_post_attach = NULL; |
1333 | hms_ops.to_require_attach = NULL; | |
c719b714 | 1334 | hms_ops.to_detach = hms_detach; |
4ef1f467 | 1335 | hms_ops.to_require_detach = NULL; |
c719b714 JM |
1336 | hms_ops.to_resume = hms_resume; |
1337 | hms_ops.to_wait = hms_wait; | |
4ef1f467 | 1338 | hms_ops.to_post_wait = NULL; |
c719b714 JM |
1339 | hms_ops.to_fetch_registers = hms_fetch_register; |
1340 | hms_ops.to_store_registers = hms_store_register; | |
1341 | hms_ops.to_prepare_to_store = hms_prepare_to_store; | |
1342 | hms_ops.to_xfer_memory = hms_xfer_inferior_memory; | |
1343 | hms_ops.to_files_info = hms_files_info; | |
1344 | hms_ops.to_insert_breakpoint = hms_insert_breakpoint; | |
1345 | hms_ops.to_remove_breakpoint = hms_remove_breakpoint; | |
1346 | hms_ops.to_terminal_init = 0; | |
1347 | hms_ops.to_terminal_inferior = 0; | |
1348 | hms_ops.to_terminal_ours_for_output = 0; | |
1349 | hms_ops.to_terminal_ours = 0; | |
1350 | hms_ops.to_terminal_info = 0; | |
1351 | hms_ops.to_kill = hms_kill; | |
1352 | hms_ops.to_load = generic_load; | |
1353 | hms_ops.to_lookup_symbol = 0; | |
1354 | hms_ops.to_create_inferior = hms_create_inferior; | |
4ef1f467 DT |
1355 | hms_ops.to_post_startup_inferior = NULL; |
1356 | hms_ops.to_acknowledge_created_inferior = NULL; | |
1357 | hms_ops.to_clone_and_follow_inferior = NULL; | |
1358 | hms_ops.to_post_follow_inferior_by_clone = NULL; | |
1359 | hms_ops.to_insert_fork_catchpoint = NULL; | |
1360 | hms_ops.to_remove_fork_catchpoint = NULL; | |
1361 | hms_ops.to_insert_vfork_catchpoint = NULL; | |
1362 | hms_ops.to_remove_vfork_catchpoint = NULL; | |
1363 | hms_ops.to_has_forked = NULL; | |
1364 | hms_ops.to_has_vforked = NULL; | |
1365 | hms_ops.to_can_follow_vfork_prior_to_exec = NULL; | |
1366 | hms_ops.to_post_follow_vfork = NULL; | |
1367 | hms_ops.to_insert_exec_catchpoint = NULL; | |
1368 | hms_ops.to_remove_exec_catchpoint = NULL; | |
1369 | hms_ops.to_has_execd = NULL; | |
1370 | hms_ops.to_reported_exec_events_per_exec_call = NULL; | |
1371 | hms_ops.to_has_exited = NULL; | |
c719b714 JM |
1372 | hms_ops.to_mourn_inferior = hms_mourn; |
1373 | hms_ops.to_can_run = 0; | |
1374 | hms_ops.to_notice_signals = 0; | |
1375 | hms_ops.to_thread_alive = 0; | |
4ef1f467 DT |
1376 | hms_ops.to_stop = 0; |
1377 | hms_ops.to_pid_to_exec_file = NULL; | |
1378 | hms_ops.to_core_file_to_sym_file = NULL; | |
c719b714 JM |
1379 | hms_ops.to_stratum = process_stratum; |
1380 | hms_ops.DONT_USE = 0; | |
1381 | hms_ops.to_has_all_memory = 1; | |
1382 | hms_ops.to_has_memory = 1; | |
1383 | hms_ops.to_has_stack = 1; | |
1384 | hms_ops.to_has_registers = 1; | |
1385 | hms_ops.to_has_execution = 1; | |
1386 | hms_ops.to_sections = 0; | |
1387 | hms_ops.to_sections_end = 0; | |
1388 | hms_ops.to_magic = OPS_MAGIC; | |
fa4b55a1 SC |
1389 | }; |
1390 | ||
03fc5a0b | 1391 | hms_quiet () /* FIXME - this routine can be removed after Dec '94 */ |
fa4b55a1 | 1392 | { |
ec25d19b SC |
1393 | quiet = !quiet; |
1394 | if (quiet) | |
1395 | printf_filtered ("Snoop disabled\n"); | |
1396 | else | |
1397 | printf_filtered ("Snoop enabled\n"); | |
ae0ea72e | 1398 | |
03fc5a0b | 1399 | printf_filtered ("`snoop' is obsolete, please use `set remotedebug'.\n"); |
fa4b55a1 SC |
1400 | } |
1401 | ||
ec25d19b SC |
1402 | hms_device (s) |
1403 | char *s; | |
fa4b55a1 | 1404 | { |
ec25d19b SC |
1405 | if (s) |
1406 | { | |
1407 | dev_name = get_word (&s); | |
1408 | } | |
fa4b55a1 SC |
1409 | } |
1410 | ||
ec25d19b SC |
1411 | static |
1412 | hms_speed (s) | |
1413 | char *s; | |
fa4b55a1 | 1414 | { |
ec25d19b SC |
1415 | check_open (); |
1416 | ||
1417 | if (s) | |
1418 | { | |
1419 | char buffer[100]; | |
1420 | int newrate = atoi (s); | |
1421 | int which = 0; | |
1422 | ||
a493d9a6 | 1423 | if (SERIAL_SETBAUDRATE (desc, newrate)) |
ec25d19b SC |
1424 | error ("Can't use %d baud\n", newrate); |
1425 | ||
1426 | printf_filtered ("Checking target is in sync\n"); | |
1427 | ||
ec25d19b SC |
1428 | printf_filtered ("Sending commands to set target to %d\n", |
1429 | baudrate); | |
1430 | ||
1431 | sprintf (buffer, "tm %d. N 8 1", baudrate); | |
1432 | hms_write_cr (buffer); | |
1433 | } | |
fa4b55a1 SC |
1434 | } |
1435 | ||
1436 | /***********************************************************************/ | |
1437 | ||
3b5442f9 SC |
1438 | static void |
1439 | hms_drain (args, fromtty) | |
1440 | char *args; | |
1441 | int fromtty; | |
3b5442f9 SC |
1442 | { |
1443 | int c; | |
1444 | while (1) | |
1445 | { | |
1446 | c = SERIAL_READCHAR (desc, 1); | |
1447 | if (c == SERIAL_TIMEOUT) | |
1448 | break; | |
1449 | if (c == SERIAL_ERROR) | |
1450 | break; | |
1451 | if (c > ' ' && c < 127) | |
1452 | printf ("%c", c & 0xff); | |
1453 | else | |
1454 | printf ("<%x>", c & 0xff); | |
1455 | } | |
1456 | } | |
1457 | ||
1458 | static void | |
1459 | add_commands () | |
1460 | { | |
1461 | ||
402b0d2e | 1462 | add_com ("hms_drain", class_obscure, hms_drain, |
3b5442f9 SC |
1463 | "Drain pending hms text buffers."); |
1464 | } | |
1465 | ||
1466 | static void | |
1467 | remove_commands () | |
1468 | { | |
1469 | extern struct cmd_list_element *cmdlist; | |
1470 | delete_cmd ("hms-drain", &cmdlist); | |
1471 | } | |
1472 | ||
03fc5a0b | 1473 | |
fa4b55a1 SC |
1474 | void |
1475 | _initialize_remote_hms () | |
1476 | { | |
c719b714 | 1477 | init_hms_ops() ; |
fa4b55a1 | 1478 | add_target (&hms_ops); |
ec25d19b | 1479 | |
fa4b55a1 | 1480 | add_com ("hms <command>", class_obscure, hms_com, |
ec25d19b | 1481 | "Send a command to the HMS monitor."); |
791d4d7d | 1482 | |
03fc5a0b | 1483 | /* FIXME - hms_quiet and `snoop' can be removed after Dec '94 */ |
fa4b55a1 | 1484 | add_com ("snoop", class_obscure, hms_quiet, |
791d4d7d | 1485 | "Show what commands are going to the monitor (OBSOLETE - see 'set remotedebug')"); |
ae0ea72e | 1486 | |
fa4b55a1 SC |
1487 | add_com ("device", class_obscure, hms_device, |
1488 | "Set the terminal line for HMS communications"); | |
1489 | ||
1490 | add_com ("speed", class_obscure, hms_speed, | |
1491 | "Set the terminal line speed for HMS communications"); | |
ec25d19b | 1492 | |
3ec5a74b | 1493 | dev_name = NULL; |
fa4b55a1 | 1494 | } |
5d747d61 SC |
1495 | #endif |
1496 |