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