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