fcf4d9ff646836efee8e63873ee69d2949da8764
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. */
36 /* External data declarations */
37 extern int stop_soon_quietly
; /* for wait_for_inferior */
39 /* Forward data declarations */
40 extern struct target_ops hms_ops
; /* Forward declaration */
42 /* Forward function declarations */
43 static void hms_fetch_registers ();
44 static int hms_store_registers ();
45 static void hms_close ();
46 static int hms_clear_breakpoints();
48 extern struct target_ops hms_ops
;
53 # define DENTER(NAME) if (!quiet) (printf_filtered("Entering %s\n",NAME), fflush(stdout))
54 # define DEXIT(NAME) if (!quiet) (printf_filtered("Exiting %s\n",NAME), fflush(stdout))
61 /***********************************************************************/
62 /* Caching stuff stolen from remote-nindy.c */
64 /* The data cache records all the data read from the remote machine
65 since the last time it stopped.
67 Each cache block holds LINE_SIZE bytes of data
68 starting at a multiple-of-LINE_SIZE address. */
71 #define LINE_SIZE_POWER 4
72 #define LINE_SIZE (1<<LINE_SIZE_POWER) /* eg 1<<3 == 8 */
73 #define LINE_SIZE_MASK ((LINE_SIZE-1)) /* eg 7*2+1= 111*/
74 #define DCACHE_SIZE 64 /* Number of cache blocks */
75 #define XFORM(x) ((x&LINE_SIZE_MASK)>>2)
77 struct dcache_block
*next
, *last
;
78 unsigned int addr
; /* Address for which data is recorded. */
79 int data
[LINE_SIZE
/sizeof(int)];
82 struct dcache_block dcache_free
, dcache_valid
;
84 /* Free all the data cache blocks, thus discarding all cached data. */
89 register struct dcache_block
*db
;
91 while ((db
= dcache_valid
.next
) != &dcache_valid
)
94 insque (db
, &dcache_free
);
99 * If addr is present in the dcache, return the address of the block
103 struct dcache_block
*
107 register struct dcache_block
*db
;
112 /* Search all cache blocks for one that is at this address. */
113 db
= dcache_valid
.next
;
114 while (db
!= &dcache_valid
)
116 if ((addr
& ~LINE_SIZE_MASK
)== db
->addr
)
123 /* Return the int data at address ADDR in dcache block DC. */
126 dcache_value (db
, addr
)
127 struct dcache_block
*db
;
132 return (db
->data
[XFORM(addr
)]);
135 /* Get a free cache block, put or keep it on the valid list,
136 and return its address. The caller should store into the block
137 the address and data that it describes, then remque it from the
138 free list and insert it into the valid list. This procedure
139 prevents errors from creeping in if a ninMemGet is interrupted
140 (which used to put garbage blocks in the valid list...). */
142 struct dcache_block
*
145 register struct dcache_block
*db
;
147 if ((db
= dcache_free
.next
) == &dcache_free
)
149 /* If we can't get one from the free list, take last valid and put
150 it on the free list. */
151 db
= dcache_valid
.last
;
153 insque (db
, &dcache_free
);
157 insque (db
, &dcache_valid
);
161 /* Return the contents of the word at address ADDR in the remote machine,
162 using the data cache. */
168 register struct dcache_block
*db
;
170 db
= dcache_hit (addr
);
173 db
= dcache_alloc ();
175 hms_read_inferior_memory(addr
& ~LINE_SIZE_MASK
, (unsigned char *)db
->data
, LINE_SIZE
);
177 db
->addr
= addr
& ~LINE_SIZE_MASK
;
178 remque (db
); /* Off the free list */
179 insque (db
, &dcache_valid
); /* On the valid list */
181 return (dcache_value (db
, addr
));
184 /* Write the word at ADDR both in the data cache and in the remote machine. */
186 dcache_poke (addr
, data
)
190 register struct dcache_block
*db
;
192 /* First make sure the word is IN the cache. DB is its cache block. */
193 db
= dcache_hit (addr
);
196 db
= dcache_alloc ();
198 hms_write_inferior_memory(addr
& ~LINE_SIZE_MASK
, (unsigned char *)db
->data
, LINE_SIZE
);
200 db
->addr
= addr
& ~LINE_SIZE_MASK
;
201 remque (db
); /* Off the free list */
202 insque (db
, &dcache_valid
); /* On the valid list */
205 /* Modify the word in the cache. */
206 db
->data
[XFORM(addr
)] = data
;
208 /* Send the changed word. */
210 hms_write_inferior_memory(addr
, (unsigned char *)&data
, 4);
214 /* The cache itself. */
215 struct dcache_block the_cache
[DCACHE_SIZE
];
217 /* Initialize the data cache. */
222 register struct dcache_block
*db
;
225 dcache_free
.next
= dcache_free
.last
= &dcache_free
;
226 dcache_valid
.next
= dcache_valid
.last
= &dcache_valid
;
227 for (i
=0;i
<DCACHE_SIZE
;i
++,db
++)
228 insque (db
, &dcache_free
);
232 /***********************************************************************
233 * I/O stuff stolen from remote-eb.c
234 ***********************************************************************/
236 static int timeout
= 2;
237 static char *dev_name
= "/dev/ttya";
242 /* Descriptor for I/O to remote machine. Initialize it to -1 so that
243 hms_open knows that we don't have a file open when the program
246 #define OPEN(x) ((x) >= 0)
254 rawmode(desc
, turnon
)
263 ioctl (desc
, TIOCGETP
, &sg
);
267 sg
.c_lflag
&= ~(ICANON
);
273 sg
.c_lflag
|= ICANON
;
275 sg
.sg_flags
&= ~(RAW
);
278 ioctl (desc
, TIOCSETP
, &sg
);
282 /* Read a character from the remote system, doing all the fancy
291 /* termio does the timeout for us. */
292 read (hms_desc
, &buf
, 1);
295 if (read (hms_desc
, &buf
, 1) < 0)
298 error ("Timeout reading from remote system.");
300 perror_with_name ("remote");
306 error ("Timeout reading from remote system.");
321 /* termio does the timeout for us. */
322 read (hms_desc
, &buf
, 1);
325 if (read (hms_desc
, &buf
, 1) < 0)
339 /* Keep discarding input from the remote system, until STRING is found.
340 Let the user break out immediately. */
351 if (readchar() == *p
)
365 /* Keep discarding input until we see the hms prompt.
367 The convention for dealing with the prompt is that you
369 o *then* wait for the prompt.
371 Thus the last thing that a procedure does with the serial line
372 will be an expect_prompt(). Exception: hms_resume does not
373 wait for the prompt, because the terminal is being handed over
374 to the inferior. However, the next thing which happens after that
375 is a hms_wait which does wait for the prompt.
376 Note that this includes abnormal exit, e.g. error(). This is
377 necessary to prevent getting into states from which we can't
386 /* Get a hex digit from the remote system & return its value.
387 If ignore_space is nonzero, ignore spaces (not newline, tab, etc). */
389 get_hex_digit (ignore_space
)
396 if (ch
>= '0' && ch
<= '9')
398 else if (ch
>= 'A' && ch
<= 'F')
399 return ch
- 'A' + 10;
400 else if (ch
>= 'a' && ch
<= 'f')
401 return ch
- 'a' + 10;
402 else if (ch
== ' ' && ignore_space
)
407 error ("Invalid hex digit from remote system.");
412 /* Get a byte from hms_desc and put it in *BYT. Accept any number
420 val
= get_hex_digit (1) << 4;
421 val
|= get_hex_digit (0);
425 /* Read a 32-bit hex word from the hms, preceded by a space */
433 for (j
= 0; j
< 8; j
++)
434 val
= (val
<< 4) + get_hex_digit (j
== 0);
437 /* Called when SIGALRM signal sent due to alarm() timeout. */
442 # define volatile /**/
445 volatile int n_alarms
;
455 /* Number of SIGTRAPs we need to simulate. That is, the next
456 NEED_ARTIFICIAL_TRAP calls to hms_wait should just return
457 SIGTRAP without actually waiting for anything. */
459 static int need_artificial_trap
= 0;
462 hms_kill(arg
,from_tty
)
471 if (!OPEN(hms_desc
)) {
477 * Download a file specified in 'args', to the hms.
480 hms_load(args
,fromtty
)
489 DENTER("hms_load()");
494 abfd
= bfd_openr(args
,"coff-h8300");
497 printf_filtered("Unable to open file %s\n", args
);
501 if (bfd_check_format(abfd
, bfd_object
) ==0)
503 printf_filtered("File is not an object file\n");
508 while (s
!= (asection
*)NULL
)
510 if (s
->flags
& SEC_LOAD
)
516 char *buffer
= xmalloc(DELTA
);
517 printf_filtered("%s: %4x .. %4x ",s
->name
, s
->vma
, s
->vma
+ s
->_raw_size
);
518 for (i
= 0; i
< s
->_raw_size
; i
+= DELTA
)
521 if (delta
> s
->_raw_size
- i
)
522 delta
= s
->_raw_size
- i
;
524 bfd_get_section_contents(abfd
, s
, buffer
, i
, delta
);
525 hms_write_inferior_memory(s
->vma
+ i
, buffer
, delta
);
526 printf_filtered("*");
529 printf_filtered( "\n");
539 /* This is called not only when we first attach, but also when the
540 user types "run" after having attached. */
542 hms_create_inferior (execfile
, args
, env
)
549 DENTER("hms_create_inferior()");
552 error ("Can't pass arguments to remote hms process.");
554 if (execfile
== 0 || exec_bfd
== 0)
555 error ("No exec file specified");
557 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
564 hms_clear_breakpoints();
565 init_wait_for_inferior ();
566 /* Clear the input because what the hms sends back is different
567 * depending on whether it was running or not.
569 /*sprintf(buffer,"g %x", entry_pt);
571 hms_write_cr(buffer);
578 insert_breakpoints (); /* Needed to get correct instruction in cache */
579 proceed(entry_pt
, -1, 0);
583 DEXIT("hms_create_inferior()");
586 /* Translate baud rates from integers to damn B_codes. Unix should
587 have outgrown this crap years ago, but even POSIX wouldn't buck it. */
596 static struct {int rate
, damn_b
;} baudtab
[] = {
606 static int damn_b (rate
)
611 for (i
= 0; baudtab
[i
].rate
!= -1; i
++)
612 if (rate
== baudtab
[i
].rate
) return baudtab
[i
].damn_b
;
617 /* Open a connection to a remote debugger.
618 NAME is the filename used for communication, then a space,
626 while (*s
&& !isspace(*s
))
631 static char *get_word(p
)
646 while (*s
&& !isspace(*s
))
652 copy
= xmalloc(len
+1);
653 memcpy(copy
, word
, len
);
659 static int baudrate
= 9600;
666 /* Put this port into NORMAL mode, send the 'normal' character */
667 hms_write("\001", 1); /* Control A */
668 hms_write("\r", 1); /* Cr */
670 while ( readchar_nofail()) /* Skip noise we put there */
674 if (readchar_nofail() == 'r')
677 /* Not the right baudrate, or the board's not on */
686 ioctl (hms_desc
, TIOCGETP
, &sg
);
688 sg
.c_cc
[VMIN
] = 0; /* read with timeout. */
689 sg
.c_cc
[VTIME
] = timeout
* 10;
690 sg
.c_lflag
&= ~(ICANON
| ECHO
);
691 sg
.c_cflag
= (sg
.c_cflag
& ~CBAUD
) | damn_b (baudrate
);
693 sg
.sg_ispeed
= damn_b (baudrate
);
694 sg
.sg_ospeed
= damn_b (baudrate
);
695 sg
.sg_flags
|= RAW
| ANYP
;
696 sg
.sg_flags
&= ~ECHO
;
699 ioctl (hms_desc
, TIOCSETP
, &sg
);
709 while (!is_baudrate_right())
713 if (baudtab
[which_rate
].rate
== -1)
719 baudrate
= baudtab
[which_rate
].rate
;
720 printf_filtered("Board not responding, trying %d baud\n",baudrate
);
727 hms_open (name
, from_tty
)
735 DENTER("hms_open()");
744 hms_desc
= open (dev_name
, O_RDWR
);
746 perror_with_name (dev_name
);
753 /* start_remote (); /* Initialize gdb process mechanisms */
757 #ifndef NO_SIGINTERRUPT
758 /* Cause SIGALRM's to make reads fail with EINTR instead of resuming
760 if (siginterrupt (SIGALRM
, 1) != 0)
761 perror ("hms_open: error in siginterrupt");
764 /* Set up read timeout timer. */
765 if ((void (*)) signal (SIGALRM
, hms_timer
) == (void (*)) -1)
766 perror ("hms_open: error in signal");
769 get_baudrate_right();
771 /* Hello? Are you there? */
772 write (hms_desc
, "\r", 1);
776 /* Clear any break points */
777 hms_clear_breakpoints();
780 printf_filtered("Remote debugging on an H8/300 HMS via %s.\n",dev_name
);
785 /* Close out all files and local state before this target loses control. */
792 DENTER("hms_close()");
794 /* Clear any break points */
795 hms_clear_breakpoints();
797 /* Put this port back into REMOTE mode */
798 if (OPEN(hms_desc
)) {
800 sleep(1); /* Let any output make it all the way back */
801 write(hms_desc
, "R\r", 2);
804 /* Due to a bug in Unix, fclose closes not only the stdio stream,
805 but also the file descriptor. So we don't actually close
810 /* Do not try to close hms_desc again, later in the program. */
814 DEXIT("hms_close()");
817 /* Attach to the target that is already loaded and possibly running */
819 hms_attach (args
, from_tty
)
824 DENTER("hms_attach()");
826 /* push_target(&hms_ops); /* This done in hms_open() */
828 mark_breakpoints_out ();
830 /* Send the hms a kill. It is ok if it is not already running */
832 fprintf(hms_stream
, "K\r");
833 expect_prompt(); /* Slurp the echo */
835 /* We will get a task spawn event immediately. */
836 init_wait_for_inferior ();
837 clear_proceed_status ();
838 stop_soon_quietly
= 1;
839 wait_for_inferior ();
840 stop_soon_quietly
= 0;
842 DEXIT("hms_attach()");
846 /* Terminate the open connection to the remote debugger.
847 Use this when you want to detach and do something else
850 hms_detach (args
,from_tty
)
854 DENTER("hms_detach()");
855 if (OPEN(hms_desc
)) { /* Send it on its way (tell it to continue) */
856 hms_clear_breakpoints();
858 fprintf(hms_stream
,"G\r");
862 pop_target(); /* calls hms_close to do the real work */
864 printf_filtered ("Ending remote %s debugging\n", target_shortname
);
865 DEXIT("hms_detach()");
868 /* Tell the remote machine to resume. */
871 hms_resume (step
, sig
)
874 DENTER("hms_resume()");
882 /* Force the next hms_wait to return a trap. Not doing anything
883 about I/O from the target means that the user has to type
884 "continue" to see any. FIXME, this should be fixed. */
885 need_artificial_trap
= 1;
892 DEXIT("hms_resume()");
895 /* Wait until the remote machine stops, then return,
896 storing status in STATUS just as `wait' would. */
902 /* Strings to look for. '?' means match any single character.
903 Note that with the algorithm we use, the initial character
904 of the string cannot recur in the string, or we will not
905 find some cases of the string in the input. */
907 static char bpt
[] = "At breakpoint:";
908 /* It would be tempting to look for "\n[__exit + 0x8]\n"
909 but that requires loading symbols with "yc i" and even if
910 we did do that we don't know that the file has symbols. */
911 static char exitmsg
[] = "HMS>";
915 /* Large enough for either sizeof (bpt) or sizeof (exitmsg) chars. */
917 /* Current position in swallowed. */
918 char *swallowed_p
= swallowed
;
922 int old_timeout
= timeout
;
923 int old_immediate_quit
= immediate_quit
;
924 int swallowed_cr
= 0;
926 DENTER("hms_wait()");
928 WSETEXIT ((*status
), 0);
930 if (need_artificial_trap
!= 0)
932 WSETSTOP ((*status
), SIGTRAP
);
933 need_artificial_trap
--;
937 timeout
= 0; /* Don't time out -- user program is running. */
938 immediate_quit
= 1; /* Helps ability to QUIT */
941 QUIT
; /* Let user quit and leave process running */
957 if (ch
== *ep
|| *ep
== '?')
974 /* Print out any characters which have been swallowed. */
975 for (p
= swallowed
; p
< swallowed_p
; ++p
)
977 swallowed_p
= swallowed
;
980 if ((ch
!= '\r' && ch
!= '\n') || swallowed_cr
>10)
991 WSETSTOP ((*status
), SIGTRAP
);
996 WSETEXIT ((*status
), 0);
999 timeout
= old_timeout
;
1000 immediate_quit
= old_immediate_quit
;
1001 DEXIT("hms_wait()");
1005 /* Return the name of register number REGNO
1006 in the form input and output by hms.
1008 Returns a pointer to a static buffer containing the answer. */
1010 get_reg_name (regno
)
1013 static char *rn
[NUM_REGS
]= REGISTER_NAMES
;
1020 /* Read the remote registers. */
1021 static int gethex(length
, start
, ok
)
1022 unsigned int length
;
1030 if (*start
>='a' && *start
<= 'f')
1032 result
+= *start
- 'a' + 10;
1034 else if (*start
>='A' && *start
<= 'F')
1036 result
+= *start
- 'A' + 10;
1038 else if (*start
>='0' && *start
<= '9')
1040 result
+= *start
- '0' ;
1049 timed_read(buf
, n
, timeout
)
1060 if (c
== 0) return i
;
1072 write(hms_desc
,a
,l
);
1074 for (i
= 0; i
< l
; i
++)
1083 hms_write( s
, strlen(s
));
1088 hms_fetch_registers ()
1090 #define REGREPLY_SIZE 79
1091 char linebuf
[REGREPLY_SIZE
+1];
1096 REGISTER_TYPE reg
[NUM_REGS
];
1104 s
= timed_read(linebuf
, REGREPLY_SIZE
, 1);
1107 linebuf
[REGREPLY_SIZE
] = 0;
1109 if (linebuf
[0] == 'r' &&
1110 linebuf
[3] == 'P' &&
1111 linebuf
[4] == 'C' &&
1112 linebuf
[5] == '=' &&
1113 linebuf
[75] == 'H' &&
1114 linebuf
[76] == 'M' &&
1118 PC=XXXX CCR=XX:XXXXXXXX R0-R7= XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
1119 5436789012345678901234567890123456789012345678901234567890123456789012
1124 reg
[PC_REGNUM
] = gethex(4,linebuf
+6, &gottok
);
1125 reg
[CCR_REGNUM
] = gethex(2,linebuf
+15, &gottok
);
1126 for (i
= 0; i
< 8; i
++)
1128 reg
[i
] = gethex(4, linebuf
+34+5*i
, &gottok
);
1133 for (i
= 0; i
< NUM_REGS
; i
++)
1135 supply_register (i
, reg
+i
);
1139 /* Fetch register REGNO, or all registers if REGNO is -1.
1142 hms_fetch_register (regno
)
1146 hms_fetch_registers ();
1150 /* Store the remote registers from the contents of the block REGS. */
1153 hms_store_registers ()
1156 for (i
= 0; i
< NUM_REGS
; i
++)
1157 hms_store_register(i
);
1162 /* Store register REGNO, or all if REGNO == -1.
1163 Return errno value. */
1165 hms_store_register (regno
)
1169 /* printf("hms_store_register() called.\n"); fflush(stdout); /* */
1171 hms_store_registers ();
1174 char *name
= get_reg_name (regno
);
1176 sprintf(buffer
,"r %s=%x", name
, read_register(regno
));
1177 hms_write_cr(buffer
);
1181 DEXIT("hms_store_registers()");
1185 /* Get ready to modify the registers array. On machines which store
1186 individual registers, this doesn't need to do anything. On machines
1187 which store all the registers in one fell swoop, this makes sure
1188 that registers contains all the registers from the program being
1192 hms_prepare_to_store ()
1194 /* Do nothing, since we can store individual regs */
1198 translate_addr(addr
)
1206 /* Read a word from remote address ADDR and return it.
1207 * This goes through the data cache.
1210 hms_fetch_word (addr
)
1213 return dcache_fetch (addr
);
1216 /* Write a word WORD into remote address ADDR.
1217 This goes through the data cache. */
1220 hms_store_word (addr
, word
)
1224 dcache_poke (addr
, word
);
1228 hms_xfer_inferior_memory(memaddr
, myaddr
, len
, write
, target
)
1233 struct target_ops
*target
; /* ignored */
1236 /* Round starting address down to longword boundary. */
1237 register CORE_ADDR addr
;
1238 /* Round ending address up; get number of longwords that makes. */
1240 /* Allocate buffer of that many longwords. */
1241 register int *buffer
;
1244 addr
= memaddr
& - sizeof (int);
1245 count
= (((memaddr
+ len
) - addr
) + sizeof (int) - 1) / sizeof (int);
1248 buffer
= (int *)alloca (count
* sizeof (int));
1251 /* Fill start and end extra bytes of buffer with existing memory data. */
1253 if (addr
!= memaddr
|| len
< (int)sizeof (int)) {
1254 /* Need part of initial word -- fetch it. */
1255 buffer
[0] = hms_fetch_word (addr
);
1258 if (count
> 1) /* FIXME, avoid if even boundary */
1261 = hms_fetch_word (addr
+ (count
- 1) * sizeof (int));
1264 /* Copy data to be written over corresponding part of buffer */
1266 bcopy (myaddr
, (char *) buffer
+ (memaddr
& (sizeof (int) - 1)), len
);
1268 /* Write the entire buffer. */
1270 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
1273 hms_store_word (addr
, buffer
[i
]);
1284 /* Read all the longwords */
1285 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
1288 buffer
[i
] = hms_fetch_word (addr
);
1296 /* Copy appropriate bytes out of the buffer. */
1297 bcopy ((char *) buffer
+ (memaddr
& (sizeof (int) - 1)), myaddr
, len
);
1306 hms_xfer_inferior_memory (memaddr
, myaddr
, len
, write
)
1314 return hms_write_inferior_memory (memaddr
, myaddr
, len
);
1316 return hms_read_inferior_memory (memaddr
, myaddr
, len
);
1322 hms_write_inferior_memory (memaddr
, myaddr
, len
)
1328 bfd
*abfd
= bfd_openw(dev_name
, "srec");
1331 bfd_set_format(abfd
, bfd_object
);
1332 a
= bfd_make_section(abfd
, ".text");
1335 a
->flags
= SEC_LOAD
| SEC_HAS_CONTENTS
;
1336 hms_write_cr("tl"); /* tell hms here comes the recs */
1337 bfd_set_section_contents(abfd
, a
, myaddr
, 0, len
);
1346 printf_filtered("\tAttached to %s at %d baud and running program %s\n",
1347 dev_name
, baudrate
, bfd_get_filename(exec_bfd
));
1348 printf_filtered("\ton an H8/300 processor.\n");
1351 /* Copy LEN bytes of data from debugger memory at MYADDR
1352 to inferior's memory at MEMADDR. Returns errno value.
1353 * sb/sh instructions don't work on unaligned addresses, when TU=1.
1357 /* Read LEN bytes from inferior memory at MEMADDR. Put the result
1358 at debugger address MYADDR. Returns errno value. */
1360 hms_read_inferior_memory(memaddr
, myaddr
, len
)
1365 /* Align to nearest low 16 bits */
1369 CORE_ADDR start
= memaddr
& ~0xf;
1370 CORE_ADDR end
= ((memaddr
+ len
+16) & ~0xf) -1;
1372 CORE_ADDR start
= memaddr
;
1373 CORE_ADDR end
= memaddr
+ len
-1;
1378 AAAA: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX '................'
1379 012345678901234567890123456789012345678901234567890123456789012345
1383 if (memaddr
& 0xf) abort();
1384 if (len
!= 16) abort();
1386 sprintf(buffer
, "m %4x %4x", start
& 0xffff, end
& 0xffff);
1387 hms_write_cr(buffer
);
1388 /* drop the echo and newline*/
1389 for (i
= 0; i
< 13; i
++)
1394 /* Grab the lines as they come out and fill the area */
1404 buffer
[0] = readchar();
1405 if (buffer
[0] == 'M')
1407 for (i
= 1; i
< 66; i
++)
1408 buffer
[i
] = readchar();
1410 /* Now parse the line */
1412 addr
= gethex(4, buffer
, &ok
);
1414 for (p
= 0; p
< 16; p
+=2)
1416 byte
[p
] = gethex(2, buffer
+ idx
, &ok
);
1417 byte
[p
+1] = gethex(2, buffer
+ idx
+ 2, &ok
);
1423 for (p
= 0; p
<16;p
++)
1425 if (addr
+ p
>= memaddr
&&
1426 addr
+ p
< memaddr
+ len
)
1428 myaddr
[ (addr
+ p
)-memaddr
] = byte
[p
];
1447 /* This routine is run as a hook, just before the main command loop is
1448 entered. If gdb is configured for the H8, but has not had its
1449 target specified yet, this will loop prompting the user to do so.
1452 hms_before_main_loop ()
1456 extern FILE *instream
;
1457 extern jmp_buf to_top_level
;
1459 push_target (&hms_ops
);
1462 while (current_target
!= &hms_ops
) {
1463 /* remote tty not specified yet */
1464 if ( instream
== stdin
){
1465 printf("\nEnter device and filename, or \"quit\" to quit: ");
1468 fgets( ttyname
, sizeof(ttyname
)-1, stdin
);
1470 if ( !strcmp("quit", ttyname
) ){
1474 hms_open( ttyname
, 1 );
1476 /* Now that we have a tty open for talking to the remote machine,
1477 download the executable file if one was specified. */
1478 if ( !setjmp(to_top_level
) && exec_bfd
) {
1479 target_load (bfd_get_filename (exec_bfd
), 1);
1486 #define MAX_BREAKS 16
1487 static int num_brkpts
=0;
1489 hms_insert_breakpoint(addr
, save
)
1491 char *save
; /* Throw away, let hms save instructions */
1494 DENTER("hms_insert_breakpoint()");
1497 if (num_brkpts
< MAX_BREAKS
) {
1500 sprintf(buffer
,"b %x", addr
& 0xffff);
1501 hms_write_cr(buffer
);
1503 DEXIT("hms_insert_breakpoint() success");
1504 return(0); /* Success */
1506 fprintf_filtered(stderr
,
1507 "Too many break points, break point not installed\n");
1508 DEXIT("hms_insert_breakpoint() failure");
1509 return(1); /* Failure */
1515 hms_remove_breakpoint(addr
, save
)
1517 char *save
; /* Throw away, let hms save instructions */
1519 DENTER("hms_remove_breakpoint()");
1520 if (num_brkpts
> 0) {
1524 sprintf(buffer
,"b - %x", addr
& 0xffff);
1525 hms_write_cr(buffer
);
1529 DEXIT("hms_remove_breakpoint()");
1533 /* Clear the hmss notion of what the break points are */
1535 hms_clear_breakpoints()
1538 DENTER("hms_clear_breakpoint()");
1539 if (OPEN(hms_desc
)) {
1540 hms_write_cr("b -");
1545 DEXIT("hms_clear_breakpoint()");
1550 DENTER("hms_mourn()");
1551 hms_clear_breakpoints();
1552 /* pop_target (); /* Pop back to no-child state */
1553 generic_mourn_inferior ();
1554 DEXIT("hms_mourn()");
1557 /* Display everthing we read in from the hms until we match/see the
1566 while (c
=readchar()) {
1569 if (i
== strlen(str
)) return;
1572 for (j
=0 ; j
<i
; j
++) /* Put everthing we matched */
1583 /* Put a command string, in args, out to the hms. The hms is assumed to
1584 be in raw mode, all writing/reading done through hms_desc.
1585 Ouput from the hms is placed on the users terminal until the
1586 prompt from the hms is seen.
1587 FIXME: Can't handle commands that take input. */
1590 hms_com (args
, fromtty
)
1598 /* Clear all input so only command relative output is displayed */
1602 hms_write("\030",1);
1607 /* Define the target subroutine names */
1609 struct target_ops hms_ops
= {
1610 "hms", "Remote HMS monitor",
1611 "Use the H8 evaluation board running the HMS monitor connected\n\
1614 hms_open
, hms_close
,
1615 hms_attach
, hms_detach
, hms_resume
, hms_wait
,
1616 hms_fetch_register
, hms_store_register
,
1617 hms_prepare_to_store
, 0, 0, /* conv_to, conv_from */
1618 hms_xfer_inferior_memory
,
1620 hms_insert_breakpoint
, hms_remove_breakpoint
, /* Breakpoints */
1621 0, 0, 0, 0, 0, /* Terminal handling */
1622 hms_kill
, /* FIXME, kill */
1624 0, /* lookup_symbol */
1625 hms_create_inferior
, /* create_inferior */
1626 hms_mourn
, /* mourn_inferior FIXME */
1627 process_stratum
, 0, /* next */
1628 1, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
1629 0,0, /* Section pointers */
1630 OPS_MAGIC
, /* Always the last thing */
1643 dev_name
= get_word(&s
);
1657 int newrate
= atoi(s
);
1659 while (baudtab
[which
].rate
!= newrate
)
1661 if (baudtab
[which
].rate
== -1)
1663 error("Can't use %d baud\n", newrate
);
1668 printf_filtered("Checking target is in sync\n");
1670 get_baudrate_right();
1672 printf_filtered("Sending commands to set target to %d\n",
1675 sprintf(buffer
, "tm %d. N 8 1", baudrate
);
1676 hms_write_cr(buffer
);
1680 /***********************************************************************/
1683 _initialize_remote_hms ()
1685 add_target (&hms_ops
);
1686 add_com ("hms <command>", class_obscure
, hms_com
,
1687 "Send a command to the HMS monitor.");
1688 add_com ("snoop", class_obscure
, hms_quiet
,
1689 "Show what commands are going to the monitor");
1690 add_com ("device", class_obscure
, hms_device
,
1691 "Set the terminal line for HMS communications");
1693 add_com ("speed", class_obscure
, hms_speed
,
1694 "Set the terminal line speed for HMS communications");
This page took 0.062684 seconds and 4 git commands to generate.