02d5fd6b949a46b1703bb219c1307af51f80075d
1 /* Remote debugging interface for Hitachi HMS Monitor Version 1.0
2 Copyright 1992 Free Software Foundation, Inc.
3 Contributed by Cygnus Support. Written by Steve Chamberlain
6 This file is part of GDB.
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.
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.
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
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
37 /* External data declarations */
38 extern int stop_soon_quietly
; /* for wait_for_inferior */
40 /* Forward data declarations */
41 extern struct target_ops hms_ops
; /* Forward declaration */
43 /* Forward function declarations */
44 static void hms_fetch_registers ();
45 static int hms_store_registers ();
46 static void hms_close ();
47 static int hms_clear_breakpoints ();
49 extern struct target_ops hms_ops
;
56 /***********************************************************************/
57 /* Caching stuff stolen from remote-nindy.c */
59 /* The data cache records all the data read from the remote machine
60 since the last time it stopped.
62 Each cache block holds LINE_SIZE bytes of data
63 starting at a multiple-of-LINE_SIZE address. */
65 #define LINE_SIZE_POWER 4
66 #define LINE_SIZE (1<<LINE_SIZE_POWER) /* eg 1<<3 == 8 */
67 #define LINE_SIZE_MASK ((LINE_SIZE-1)) /* eg 7*2+1= 111*/
68 #define DCACHE_SIZE 64 /* Number of cache blocks */
69 #define XFORM(x) ((x&LINE_SIZE_MASK)>>2)
72 struct dcache_block
*next
, *last
;
73 unsigned int addr
; /* Address for which data is recorded. */
74 int data
[LINE_SIZE
/ sizeof (int)];
77 struct dcache_block dcache_free
, dcache_valid
;
79 /* Free all the data cache blocks, thus discarding all cached data. */
84 register struct dcache_block
*db
;
86 while ((db
= dcache_valid
.next
) != &dcache_valid
)
89 insque (db
, &dcache_free
);
94 * If addr is present in the dcache, return the address of the block
102 register struct dcache_block
*db
;
107 /* Search all cache blocks for one that is at this address. */
108 db
= dcache_valid
.next
;
109 while (db
!= &dcache_valid
)
111 if ((addr
& ~LINE_SIZE_MASK
) == db
->addr
)
118 /* Return the int data at address ADDR in dcache block DC. */
121 dcache_value (db
, addr
)
122 struct dcache_block
*db
;
127 return (db
->data
[XFORM (addr
)]);
130 /* Get a free cache block, put or keep it on the valid list,
131 and return its address. The caller should store into the block
132 the address and data that it describes, then remque it from the
133 free list and insert it into the valid list. This procedure
134 prevents errors from creeping in if a ninMemGet is interrupted
135 (which used to put garbage blocks in the valid list...). */
137 struct dcache_block
*
140 register struct dcache_block
*db
;
142 if ((db
= dcache_free
.next
) == &dcache_free
)
144 /* If we can't get one from the free list, take last valid and put
145 it on the free list. */
146 db
= dcache_valid
.last
;
148 insque (db
, &dcache_free
);
152 insque (db
, &dcache_valid
);
156 /* Return the contents of the word at address ADDR in the remote machine,
157 using the data cache. */
163 register struct dcache_block
*db
;
165 db
= dcache_hit (addr
);
168 db
= dcache_alloc ();
170 hms_read_inferior_memory (addr
& ~LINE_SIZE_MASK
, (unsigned char *) db
->data
, LINE_SIZE
);
172 db
->addr
= addr
& ~LINE_SIZE_MASK
;
173 remque (db
); /* Off the free list */
174 insque (db
, &dcache_valid
); /* On the valid list */
176 return (dcache_value (db
, addr
));
179 /* Write the word at ADDR both in the data cache and in the remote machine. */
181 dcache_poke (addr
, data
)
185 register struct dcache_block
*db
;
187 /* First make sure the word is IN the cache. DB is its cache block. */
188 db
= dcache_hit (addr
);
191 db
= dcache_alloc ();
193 hms_write_inferior_memory (addr
& ~LINE_SIZE_MASK
, (unsigned char *) db
->data
, LINE_SIZE
);
195 db
->addr
= addr
& ~LINE_SIZE_MASK
;
196 remque (db
); /* Off the free list */
197 insque (db
, &dcache_valid
); /* On the valid list */
200 /* Modify the word in the cache. */
201 db
->data
[XFORM (addr
)] = data
;
203 /* Send the changed word. */
205 hms_write_inferior_memory (addr
, (unsigned char *) &data
, 4);
209 /* The cache itself. */
210 struct dcache_block the_cache
[DCACHE_SIZE
];
212 /* Initialize the data cache. */
217 register struct dcache_block
*db
;
220 dcache_free
.next
= dcache_free
.last
= &dcache_free
;
221 dcache_valid
.next
= dcache_valid
.last
= &dcache_valid
;
222 for (i
= 0; i
< DCACHE_SIZE
; i
++, db
++)
223 insque (db
, &dcache_free
);
226 /***********************************************************************
227 * I/O stuff stolen from remote-eb.c
228 ***********************************************************************/
230 static int timeout
= 2;
232 static const char *dev_name
;
234 /* Descriptor for I/O to remote machine. Initialize it to -1 so that
235 hms_open knows that we don't have a file open when the program
244 error ("remote device not open");
251 /* Read a character from the remote system, doing all the fancy
258 buf
= SERIAL_READCHAR (desc
, timeout
);
260 if (buf
== SERIAL_TIMEOUT
)
261 error ("Timeout reading from remote system.");
264 printf_unfiltered ("%c", buf
);
274 buf
= SERIAL_READCHAR (desc
, timeout
);
275 if (buf
== SERIAL_TIMEOUT
)
278 printf_unfiltered ("%c", buf
);
284 /* Keep discarding input from the remote system, until STRING is found.
285 Let the user break out immediately. */
295 if (readchar () == *p
)
309 /* Keep discarding input until we see the hms prompt.
311 The convention for dealing with the prompt is that you
313 o *then* wait for the prompt.
315 Thus the last thing that a procedure does with the serial line
316 will be an expect_prompt(). Exception: hms_resume does not
317 wait for the prompt, because the terminal is being handed over
318 to the inferior. However, the next thing which happens after that
319 is a hms_wait which does wait for the prompt.
320 Note that this includes abnormal exit, e.g. error(). This is
321 necessary to prevent getting into states from which we can't
329 /* Get a hex digit from the remote system & return its value.
330 If ignore_space is nonzero, ignore spaces (not newline, tab, etc). */
332 get_hex_digit (ignore_space
)
340 if (ch
>= '0' && ch
<= '9')
342 else if (ch
>= 'A' && ch
<= 'F')
343 return ch
- 'A' + 10;
344 else if (ch
>= 'a' && ch
<= 'f')
345 return ch
- 'a' + 10;
346 else if (ch
== ' ' && ignore_space
)
351 error ("Invalid hex digit from remote system.");
356 /* Get a byte from hms_desc and put it in *BYT. Accept any number
364 val
= get_hex_digit (1) << 4;
365 val
|= get_hex_digit (0);
369 /* Read a 32-bit hex word from the hms, preceded by a space */
377 for (j
= 0; j
< 8; j
++)
378 val
= (val
<< 4) + get_hex_digit (j
== 0);
382 /* Called when SIGALRM signal sent due to alarm() timeout. */
384 /* Number of SIGTRAPs we need to simulate. That is, the next
385 NEED_ARTIFICIAL_TRAP calls to hms_wait should just return
386 SIGTRAP without actually waiting for anything. */
388 static int need_artificial_trap
= 0;
391 hms_kill (arg
, from_tty
)
399 * Download a file specified in 'args', to the hms.
402 hms_load (args
, fromtty
)
415 abfd
= bfd_openr (args
, gnutarget
);
418 printf_filtered ("Unable to open file %s\n", args
);
422 if (bfd_check_format (abfd
, bfd_object
) == 0)
424 printf_filtered ("File is not an object file\n");
429 while (s
!= (asection
*) NULL
)
431 if (s
->flags
& SEC_LOAD
)
436 char *buffer
= xmalloc (DELTA
);
438 printf_filtered ("%s\t: 0x%4x .. 0x%4x ", s
->name
, s
->vma
, s
->vma
+ s
->_raw_size
);
439 for (i
= 0; i
< s
->_raw_size
; i
+= DELTA
)
443 if (delta
> s
->_raw_size
- i
)
444 delta
= s
->_raw_size
- i
;
446 bfd_get_section_contents (abfd
, s
, buffer
, i
, delta
);
447 hms_write_inferior_memory (s
->vma
+ i
, buffer
, delta
);
448 printf_filtered ("*");
449 gdb_flush (gdb_stdout
);
451 printf_filtered ("\n");
456 sprintf (buffer
, "r PC=%x", abfd
->start_address
);
457 hms_write_cr (buffer
);
459 /* Turn off all breakpoints */
460 hms_write_cr ("b -");
464 /* This is called not only when we first attach, but also when the
465 user types "run" after having attached. */
467 hms_create_inferior (execfile
, args
, env
)
476 error ("Can't pass arguments to remote hms process.");
478 if (execfile
== 0 || exec_bfd
== 0)
479 error ("No exec file specified");
481 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
484 hms_kill (NULL
, NULL
);
485 hms_clear_breakpoints ();
486 init_wait_for_inferior ();
490 insert_breakpoints (); /* Needed to get correct instruction in cache */
491 proceed (entry_pt
, TARGET_SIGNAL_DEFAULT
, 0);
494 /* Open a connection to a remote debugger.
495 NAME is the filename used for communication, then a space,
503 while (*s
&& !isspace (*s
))
524 while (*s
&& !isspace (*s
))
530 copy
= xmalloc (len
+ 1);
531 memcpy (copy
, word
, len
);
537 static int baudrate
= 9600;
544 /* Put this port into NORMAL mode, send the 'normal' character */
546 hms_write ("\001", 1); /* Control A */
547 hms_write ("\r", 1); /* Cr */
551 ok
= SERIAL_READCHAR (desc
, timeout
);
558 if (readchar_nofail () == 'r')
561 /* Not the right baudrate, or the board's not on */
567 if (!SERIAL_SETBAUDRATE (desc
, baudrate
))
568 error ("Can't set baudrate");
573 hms_open (name
, from_tty
)
586 dev_name
= strdup (name
);
588 if (!(desc
= SERIAL_OPEN (dev_name
)))
589 perror_with_name ((char *) dev_name
);
593 push_target (&hms_ops
);
596 /* Hello? Are you there? */
597 SERIAL_WRITE (desc
, "\r", 1);
600 /* Clear any break points */
601 hms_clear_breakpoints ();
603 printf_filtered ("Connected to remote board running HMS monitor.\n");
606 /* Close out all files and local state before this target loses control. */
612 /* Clear any break points */
613 hms_clear_breakpoints ();
614 sleep (1); /* Let any output make it all the way back */
617 SERIAL_WRITE (desc
, "R\r", 2);
623 /* Terminate the open connection to the remote debugger.
624 Use this when you want to detach and do something else
627 hms_detach (args
, from_tty
)
633 hms_clear_breakpoints ();
636 pop_target (); /* calls hms_close to do the real work */
638 printf_filtered ("Ending remote %s debugging\n", target_shortname
);
641 /* Tell the remote machine to resume. */
644 hms_resume (pid
, step
, sig
)
646 enum target_signal sig
;
655 /* Force the next hms_wait to return a trap. Not doing anything
656 about I/O from the target means that the user has to type
657 "continue" to see any. FIXME, this should be fixed. */
658 need_artificial_trap
= 1;
667 /* Wait until the remote machine stops, then return,
668 storing status in STATUS just as `wait' would. */
671 hms_wait (pid
, status
)
673 struct target_waitstatus
*status
;
675 /* Strings to look for. '?' means match any single character.
676 Note that with the algorithm we use, the initial character
677 of the string cannot recur in the string, or we will not
678 find some cases of the string in the input. */
680 static char bpt
[] = "At breakpoint:";
682 /* It would be tempting to look for "\n[__exit + 0x8]\n"
683 but that requires loading symbols with "yc i" and even if
684 we did do that we don't know that the file has symbols. */
685 static char exitmsg
[] = "HMS>";
689 /* Large enough for either sizeof (bpt) or sizeof (exitmsg) chars. */
692 /* Current position in swallowed. */
693 char *swallowed_p
= swallowed
;
697 int old_timeout
= timeout
;
698 int old_immediate_quit
= immediate_quit
;
699 int swallowed_cr
= 0;
701 status
->kind
= TARGET_WAITKIND_EXITED
;
702 status
->value
.integer
= 0;
704 if (need_artificial_trap
!= 0)
706 status
->kind
= TARGET_WAITKIND_STOPPED
;
707 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
708 need_artificial_trap
--;
712 timeout
= -1; /* Don't time out -- user program is running. */
713 immediate_quit
= 1; /* Helps ability to QUIT */
716 QUIT
; /* Let user quit and leave process running */
732 if (ch
== *ep
|| *ep
== '?')
751 /* Print out any characters which have been swallowed. */
752 for (p
= swallowed
; p
< swallowed_p
; ++p
)
753 putc_unfiltered (*p
);
754 swallowed_p
= swallowed
;
756 if ((ch
!= '\r' && ch
!= '\n') || swallowed_cr
> 10)
758 putc_unfiltered (ch
);
767 status
->kind
= TARGET_WAITKIND_STOPPED
;
768 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
773 status
->kind
= TARGET_WAITKIND_EXITED
;
774 status
->value
.integer
= TARGET_SIGNAL_STOP
;
777 timeout
= old_timeout
;
778 immediate_quit
= old_immediate_quit
;
782 /* Return the name of register number REGNO
783 in the form input and output by hms.
785 Returns a pointer to a static buffer containing the answer. */
790 static char *rn
[] = REGISTER_NAMES
;
795 /* Read the remote registers. */
797 gethex (length
, start
, ok
)
807 if (*start
>= 'a' && *start
<= 'f')
809 result
+= *start
- 'a' + 10;
811 else if (*start
>= 'A' && *start
<= 'F')
813 result
+= *start
- 'A' + 10;
815 else if (*start
>= '0' && *start
<= '9')
817 result
+= *start
- '0';
827 timed_read (buf
, n
, timeout
)
853 SERIAL_WRITE (desc
, a
, l
);
856 for (i
= 0; i
< l
; i
++)
858 printf_unfiltered ("%c", a
[i
]);
865 hms_write (s
, strlen (s
));
869 #ifdef GDB_TARGET_IS_H8500
871 /* H8/500 monitor reg dump looks like:
874 PC:8000 SR:070C .7NZ.. CP:00 DP:00 EP:00 TP:00 BR:00
875 R0-R7: FF5A 0001 F4FE F500 0000 F528 F528 F4EE
881 supply_val(n
, size
, ptr
, segptr
)
892 raw
[0] = gethex(2, ptr
, &ok
);
893 raw
[1] = gethex(2, ptr
+2, &ok
);
894 supply_register (n
, raw
);
897 raw
[0] = gethex(2,ptr
,&ok
);
898 supply_register (n
, raw
);
902 int v
= gethex (4, ptr
, &ok
);
903 v
|= gethex (2, segptr
, &ok
) << 16;
905 raw
[1] = (v
>>16) & 0xff ;
906 raw
[2] = (v
>>8) & 0xff ;
907 raw
[3] = (v
>>0) & 0xff ;
908 supply_register (n
, raw
);
914 hms_fetch_register (dummy
)
917 #define REGREPLY_SIZE 108
918 char linebuf
[REGREPLY_SIZE
+ 1];
923 LONGEST reg
[NUM_REGS
];
931 s
= timed_read (linebuf
+1, REGREPLY_SIZE
, 1);
933 linebuf
[REGREPLY_SIZE
] = 0;
935 if (linebuf
[3] == 'P' &&
938 linebuf
[105] == 'H' &&
939 linebuf
[106] == 'M' &&
946 -------1---------2---------3---------4---------5-----
947 345678901234567890123456789012345678901234567890123456
948 PC:8000 SR:070C .7NZ.. CP:00 DP:00 EP:00 TP:00 BR:00**
949 ---6---------7---------8---------9--------10----
950 789012345678901234567890123456789012345678901234
951 R0-R7: FF5A 0001 F4FE F500 0000 F528 F528 F4EE**
959 supply_val(PC_REGNUM
, 4, linebuf
+6, linebuf
+29);
961 supply_val(CCR_REGNUM
, 2, linebuf
+14);
962 supply_val(SEG_C_REGNUM
, 1, linebuf
+29);
963 supply_val(SEG_D_REGNUM
, 1, linebuf
+35);
964 supply_val(SEG_E_REGNUM
, 1, linebuf
+41);
965 supply_val(SEG_T_REGNUM
, 1, linebuf
+47);
966 for (i
= 0; i
< 8; i
++)
968 static int sr
[8] = { 35,35,35,35,
972 char *src
= linebuf
+ 64 + 5 * i
;
973 char *segsrc
= linebuf
+ sr
[i
];
974 supply_val(R0_REGNUM
+ i
, 2, src
);
975 supply_val(PR0_REGNUM
+ i
, 4, src
, segsrc
);
988 #ifdef GDB_TARGET_IS_H8300
990 hms_fetch_register (dummy
)
993 #define REGREPLY_SIZE 79
994 char linebuf
[REGREPLY_SIZE
+ 1];
999 unsigned LONGEST reg
[NUM_REGS
];
1007 s
= timed_read (linebuf
, REGREPLY_SIZE
, 1);
1009 linebuf
[REGREPLY_SIZE
] = 0;
1011 if (linebuf
[0] == 'r' &&
1012 linebuf
[3] == 'P' &&
1013 linebuf
[4] == 'C' &&
1014 linebuf
[5] == '=' &&
1015 linebuf
[75] == 'H' &&
1016 linebuf
[76] == 'M' &&
1020 PC=XXXX CCR=XX:XXXXXXXX R0-R7= XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
1021 5436789012345678901234567890123456789012345678901234567890123456789012
1026 reg
[PC_REGNUM
] = gethex (4, linebuf
+ 6, &gottok
);
1027 reg
[CCR_REGNUM
] = gethex (2, linebuf
+ 15, &gottok
);
1028 for (i
= 0; i
< 8; i
++)
1030 reg
[i
] = gethex (4, linebuf
+ 34 + 5 * i
, &gottok
);
1035 for (i
= 0; i
< NUM_REGS
; i
++)
1039 swapped
[1] = reg
[i
];
1040 swapped
[0] = (reg
[i
]) >> 8;
1042 supply_register (i
, swapped
);
1046 /* Store register REGNO, or all if REGNO == -1.
1047 Return errno value. */
1049 hms_store_register (regno
)
1054 for (regno
= 0; regno
< NUM_REGS
; regno
++)
1056 hms_store_register (regno
);
1061 char *name
= get_reg_name (regno
);
1063 /* Regs starting pr<foo> don't really exist */
1064 if (!(name
[0] == 'p' && name
[1] == 'r') ) {
1065 sprintf (buffer
, "r %s=%x", name
, read_register (regno
));
1066 hms_write_cr (buffer
);
1073 /* Get ready to modify the registers array. On machines which store
1074 individual registers, this doesn't need to do anything. On machines
1075 which store all the registers in one fell swoop, this makes sure
1076 that registers contains all the registers from the program being
1080 hms_prepare_to_store ()
1082 /* Do nothing, since we can store individual regs */
1086 translate_addr (addr
)
1094 /* Read a word from remote address ADDR and return it.
1095 * This goes through the data cache.
1098 hms_fetch_word (addr
)
1101 return dcache_fetch (addr
);
1104 /* Write a word WORD into remote address ADDR.
1105 This goes through the data cache. */
1108 hms_store_word (addr
, word
)
1112 dcache_poke (addr
, word
);
1116 hms_xfer_inferior_memory (memaddr
, myaddr
, len
, write
, target
)
1121 struct target_ops
*target
; /* ignored */
1125 /* Round starting address down to longword boundary. */
1126 register CORE_ADDR addr
;
1128 /* Round ending address up; get number of longwords that makes. */
1131 /* Allocate buffer of that many longwords. */
1132 register int *buffer
;
1135 addr
= memaddr
& -sizeof (int);
1136 count
= (((memaddr
+ len
) - addr
) + sizeof (int) - 1) / sizeof (int);
1138 buffer
= (int *) alloca (count
* sizeof (int));
1142 /* Fill start and end extra bytes of buffer with existing memory data. */
1144 if (addr
!= memaddr
|| len
< (int) sizeof (int))
1146 /* Need part of initial word -- fetch it. */
1147 buffer
[0] = hms_fetch_word (addr
);
1150 if (count
> 1) /* FIXME, avoid if even boundary */
1153 = hms_fetch_word (addr
+ (count
- 1) * sizeof (int));
1156 /* Copy data to be written over corresponding part of buffer */
1158 memcpy ((char *) buffer
+ (memaddr
& (sizeof (int) - 1)), myaddr
, len
);
1160 /* Write the entire buffer. */
1162 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
1165 hms_store_word (addr
, buffer
[i
]);
1176 /* Read all the longwords */
1177 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
1180 buffer
[i
] = hms_fetch_word (addr
);
1188 /* Copy appropriate bytes out of the buffer. */
1189 memcpy (myaddr
, (char *) buffer
+ (memaddr
& (sizeof (int) - 1)), len
);
1196 hms_write_inferior_memory (memaddr
, myaddr
, len
)
1198 unsigned char *myaddr
;
1212 thisgo
= len
- done
;
1216 sprintf (buffer
, "M.B %4x =", memaddr
+ done
);
1217 hms_write (buffer
, 10);
1218 for (idx
= 0; idx
< thisgo
; idx
++)
1222 sprintf (buf
, "%2x ", myaddr
[idx
+ done
]);
1235 char *file
= "nothing";
1238 file
= bfd_get_filename (exec_bfd
);
1242 printf_filtered ("\tAttached to DOS asynctsr and running program %s\n", file
);
1244 printf_filtered ("\tAttached to %s at %d baud and running program %s\n", dev_name
, baudrate
, file
);
1246 printf_filtered ("\ton an H8/300 processor.\n");
1249 /* Copy LEN bytes of data from debugger memory at MYADDR
1250 to inferior's memory at MEMADDR. Returns errno value.
1251 * sb/sh instructions don't work on unaligned addresses, when TU=1.
1254 /* Read LEN bytes from inferior memory at MEMADDR. Put the result
1255 at debugger address MYADDR. Returns errno value. */
1257 hms_read_inferior_memory (memaddr
, myaddr
, len
)
1262 /* Align to nearest low 16 bits */
1266 CORE_ADDR start
= memaddr
& ~0xf;
1267 CORE_ADDR end
= ((memaddr
+ len
+ 16) & ~0xf) - 1;
1270 CORE_ADDR start
= memaddr
;
1271 CORE_ADDR end
= memaddr
+ len
- 1;
1276 AAAA: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX '................'
1277 012345678901234567890123456789012345678901234567890123456789012345
1287 sprintf (buffer
, "m %4x %4x", start
& 0xffff, end
& 0xffff);
1288 hms_write_cr (buffer
);
1289 /* drop the echo and newline*/
1290 for (i
= 0; i
< 13; i
++)
1293 /* Grab the lines as they come out and fill the area */
1304 buffer
[0] = readchar ();
1305 if (buffer
[0] == 'M')
1307 for (i
= 1; i
< 66; i
++)
1308 buffer
[i
] = readchar ();
1310 /* Now parse the line */
1312 addr
= gethex (4, buffer
, &ok
);
1314 for (p
= 0; p
< 16; p
+= 2)
1316 byte
[p
] = gethex (2, buffer
+ idx
, &ok
);
1317 byte
[p
+ 1] = gethex (2, buffer
+ idx
+ 2, &ok
);
1322 for (p
= 0; p
< 16; p
++)
1324 if (addr
+ p
>= memaddr
&&
1325 addr
+ p
< memaddr
+ len
)
1327 myaddr
[(addr
+ p
) - memaddr
] = byte
[p
];
1333 #ifdef TARGET_IS_H8500
1336 #ifdef TARGET_IS_H8300
1345 /* This routine is run as a hook, just before the main command loop is
1346 entered. If gdb is configured for the H8, but has not had its
1347 target specified yet, this will loop prompting the user to do so.
1350 hms_before_main_loop ()
1354 extern GDB_FILE
*instream
;
1356 push_target (&hms_ops
);
1361 #define MAX_BREAKS 16
1362 static int num_brkpts
= 0;
1364 hms_insert_breakpoint (addr
, save
)
1366 char *save
; /* Throw away, let hms save instructions */
1370 if (num_brkpts
< MAX_BREAKS
)
1375 sprintf (buffer
, "b %x", addr
& 0xffff);
1376 hms_write_cr (buffer
);
1382 fprintf_filtered (gdb_stderr
,
1383 "Too many break points, break point not installed\n");
1389 hms_remove_breakpoint (addr
, save
)
1391 char *save
; /* Throw away, let hms save instructions */
1398 sprintf (buffer
, "b - %x", addr
& 0xffff);
1399 hms_write_cr (buffer
);
1406 /* Clear the hmss notion of what the break points are */
1408 hms_clear_breakpoints ()
1413 hms_write_cr ("b -");
1421 hms_clear_breakpoints ();
1422 unpush_target (&hms_ops
);
1423 generic_mourn_inferior ();
1426 /* Put a command string, in args, out to the hms. The hms is assumed to
1427 be in raw mode, all writing/reading done through desc.
1428 Ouput from the hms is placed on the users terminal until the
1429 prompt from the hms is seen.
1430 FIXME: Can't handle commands that take input. */
1433 hms_com (args
, fromtty
)
1442 /* Clear all input so only command relative output is displayed */
1444 hms_write_cr (args
);
1445 hms_write ("\030", 1);
1449 /* Define the target subroutine names */
1451 struct target_ops hms_ops
=
1453 "hms", "Remote HMS monitor",
1454 "Use the H8 evaluation board running the HMS monitor connected\n\
1457 hms_open
, hms_close
,
1458 0, hms_detach
, hms_resume
, hms_wait
, /* attach */
1459 hms_fetch_register
, hms_store_register
,
1460 hms_prepare_to_store
,
1461 hms_xfer_inferior_memory
,
1463 hms_insert_breakpoint
, hms_remove_breakpoint
, /* Breakpoints */
1464 0, 0, 0, 0, 0, /* Terminal handling */
1465 hms_kill
, /* FIXME, kill */
1467 0, /* lookup_symbol */
1468 hms_create_inferior
, /* create_inferior */
1469 hms_mourn
, /* mourn_inferior FIXME */
1471 0, /* notice_signals */
1472 process_stratum
, 0, /* next */
1473 1, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
1474 0, 0, /* Section pointers */
1475 OPS_MAGIC
, /* Always the last thing */
1482 printf_filtered ("Snoop disabled\n");
1484 printf_filtered ("Snoop enabled\n");
1493 dev_name
= get_word (&s
);
1506 int newrate
= atoi (s
);
1509 if (SERIAL_SETBAUDRATE (desc
, newrate
))
1510 error ("Can't use %d baud\n", newrate
);
1512 printf_filtered ("Checking target is in sync\n");
1514 printf_filtered ("Sending commands to set target to %d\n",
1517 sprintf (buffer
, "tm %d. N 8 1", baudrate
);
1518 hms_write_cr (buffer
);
1522 /***********************************************************************/
1525 _initialize_remote_hms ()
1527 add_target (&hms_ops
);
1529 add_com ("hms <command>", class_obscure
, hms_com
,
1530 "Send a command to the HMS monitor.");
1531 add_com ("snoop", class_obscure
, hms_quiet
,
1532 "Show what commands are going to the monitor");
1534 add_com ("device", class_obscure
, hms_device
,
1535 "Set the terminal line for HMS communications");
1537 add_com ("speed", class_obscure
, hms_speed
,
1538 "Set the terminal line speed for HMS communications");