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