4e4e3498ab3be84ef8e8be497483332131d620ed
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
;
54 # define DENTER(NAME) if (!quiet) (printf_filtered("Entering %s\n",NAME), fflush(stdout))
55 # define DEXIT(NAME) if (!quiet) (printf_filtered("Exiting %s\n",NAME), fflush(stdout))
62 /***********************************************************************/
63 /* Caching stuff stolen from remote-nindy.c */
65 /* The data cache records all the data read from the remote machine
66 since the last time it stopped.
68 Each cache block holds LINE_SIZE bytes of data
69 starting at a multiple-of-LINE_SIZE address. */
72 #define LINE_SIZE_POWER 4
73 #define LINE_SIZE (1<<LINE_SIZE_POWER) /* eg 1<<3 == 8 */
74 #define LINE_SIZE_MASK ((LINE_SIZE-1)) /* eg 7*2+1= 111*/
75 #define DCACHE_SIZE 64 /* Number of cache blocks */
76 #define XFORM(x) ((x&LINE_SIZE_MASK)>>2)
78 struct dcache_block
*next
, *last
;
79 unsigned int addr
; /* Address for which data is recorded. */
80 int data
[LINE_SIZE
/sizeof(int)];
83 struct dcache_block dcache_free
, dcache_valid
;
85 /* Free all the data cache blocks, thus discarding all cached data. */
90 register struct dcache_block
*db
;
92 while ((db
= dcache_valid
.next
) != &dcache_valid
)
95 insque (db
, &dcache_free
);
100 * If addr is present in the dcache, return the address of the block
104 struct dcache_block
*
108 register struct dcache_block
*db
;
113 /* Search all cache blocks for one that is at this address. */
114 db
= dcache_valid
.next
;
115 while (db
!= &dcache_valid
)
117 if ((addr
& ~LINE_SIZE_MASK
)== db
->addr
)
124 /* Return the int data at address ADDR in dcache block DC. */
127 dcache_value (db
, addr
)
128 struct dcache_block
*db
;
133 return (db
->data
[XFORM(addr
)]);
136 /* Get a free cache block, put or keep it on the valid list,
137 and return its address. The caller should store into the block
138 the address and data that it describes, then remque it from the
139 free list and insert it into the valid list. This procedure
140 prevents errors from creeping in if a ninMemGet is interrupted
141 (which used to put garbage blocks in the valid list...). */
143 struct dcache_block
*
146 register struct dcache_block
*db
;
148 if ((db
= dcache_free
.next
) == &dcache_free
)
150 /* If we can't get one from the free list, take last valid and put
151 it on the free list. */
152 db
= dcache_valid
.last
;
154 insque (db
, &dcache_free
);
158 insque (db
, &dcache_valid
);
162 /* Return the contents of the word at address ADDR in the remote machine,
163 using the data cache. */
169 register struct dcache_block
*db
;
171 db
= dcache_hit (addr
);
174 db
= dcache_alloc ();
176 hms_read_inferior_memory(addr
& ~LINE_SIZE_MASK
, (unsigned char *)db
->data
, LINE_SIZE
);
178 db
->addr
= addr
& ~LINE_SIZE_MASK
;
179 remque (db
); /* Off the free list */
180 insque (db
, &dcache_valid
); /* On the valid list */
182 return (dcache_value (db
, addr
));
185 /* Write the word at ADDR both in the data cache and in the remote machine. */
187 dcache_poke (addr
, data
)
191 register struct dcache_block
*db
;
193 /* First make sure the word is IN the cache. DB is its cache block. */
194 db
= dcache_hit (addr
);
197 db
= dcache_alloc ();
199 hms_write_inferior_memory(addr
& ~LINE_SIZE_MASK
, (unsigned char *)db
->data
, LINE_SIZE
);
201 db
->addr
= addr
& ~LINE_SIZE_MASK
;
202 remque (db
); /* Off the free list */
203 insque (db
, &dcache_valid
); /* On the valid list */
206 /* Modify the word in the cache. */
207 db
->data
[XFORM(addr
)] = data
;
209 /* Send the changed word. */
211 hms_write_inferior_memory(addr
, (unsigned char *)&data
, 4);
215 /* The cache itself. */
216 struct dcache_block the_cache
[DCACHE_SIZE
];
218 /* Initialize the data cache. */
223 register struct dcache_block
*db
;
226 dcache_free
.next
= dcache_free
.last
= &dcache_free
;
227 dcache_valid
.next
= dcache_valid
.last
= &dcache_valid
;
228 for (i
=0;i
<DCACHE_SIZE
;i
++,db
++)
229 insque (db
, &dcache_free
);
233 /***********************************************************************
234 * I/O stuff stolen from remote-eb.c
235 ***********************************************************************/
237 static int timeout
= 2;
238 static char *dev_name
= "/dev/ttya";
243 /* Descriptor for I/O to remote machine. Initialize it to -1 so that
244 hms_open knows that we don't have a file open when the program
247 #define OPEN(x) ((x) >= 0)
255 rawmode(desc
, turnon
)
264 ioctl (desc
, TIOCGETP
, &sg
);
268 sg
.c_lflag
&= ~(ICANON
);
274 sg
.c_lflag
|= ICANON
;
276 sg
.sg_flags
&= ~(RAW
);
279 ioctl (desc
, TIOCSETP
, &sg
);
283 /* Read a character from the remote system, doing all the fancy
292 /* termio does the timeout for us. */
293 read (hms_desc
, &buf
, 1);
296 if (read (hms_desc
, &buf
, 1) < 0)
299 error ("Timeout reading from remote system.");
301 perror_with_name ("remote");
307 error ("Timeout reading from remote system.");
322 /* termio does the timeout for us. */
323 read (hms_desc
, &buf
, 1);
326 if (read (hms_desc
, &buf
, 1) < 0)
340 /* Keep discarding input from the remote system, until STRING is found.
341 Let the user break out immediately. */
352 if (readchar() == *p
)
366 /* Keep discarding input until we see the hms prompt.
368 The convention for dealing with the prompt is that you
370 o *then* wait for the prompt.
372 Thus the last thing that a procedure does with the serial line
373 will be an expect_prompt(). Exception: hms_resume does not
374 wait for the prompt, because the terminal is being handed over
375 to the inferior. However, the next thing which happens after that
376 is a hms_wait which does wait for the prompt.
377 Note that this includes abnormal exit, e.g. error(). This is
378 necessary to prevent getting into states from which we can't
387 /* Get a hex digit from the remote system & return its value.
388 If ignore_space is nonzero, ignore spaces (not newline, tab, etc). */
390 get_hex_digit (ignore_space
)
397 if (ch
>= '0' && ch
<= '9')
399 else if (ch
>= 'A' && ch
<= 'F')
400 return ch
- 'A' + 10;
401 else if (ch
>= 'a' && ch
<= 'f')
402 return ch
- 'a' + 10;
403 else if (ch
== ' ' && ignore_space
)
408 error ("Invalid hex digit from remote system.");
413 /* Get a byte from hms_desc and put it in *BYT. Accept any number
421 val
= get_hex_digit (1) << 4;
422 val
|= get_hex_digit (0);
426 /* Read a 32-bit hex word from the hms, preceded by a space */
434 for (j
= 0; j
< 8; j
++)
435 val
= (val
<< 4) + get_hex_digit (j
== 0);
438 /* Called when SIGALRM signal sent due to alarm() timeout. */
443 # define volatile /**/
446 volatile int n_alarms
;
456 /* Number of SIGTRAPs we need to simulate. That is, the next
457 NEED_ARTIFICIAL_TRAP calls to hms_wait should just return
458 SIGTRAP without actually waiting for anything. */
460 static int need_artificial_trap
= 0;
463 hms_kill(arg
,from_tty
)
472 if (!OPEN(hms_desc
)) {
478 * Download a file specified in 'args', to the hms.
481 hms_load(args
,fromtty
)
490 DENTER("hms_load()");
495 abfd
= bfd_openr(args
,"coff-h8300");
498 printf_filtered("Unable to open file %s\n", args
);
502 if (bfd_check_format(abfd
, bfd_object
) ==0)
504 printf_filtered("File is not an object file\n");
509 while (s
!= (asection
*)NULL
)
511 if (s
->flags
& SEC_LOAD
)
513 char *buffer
= xmalloc(s
->_raw_size
);
514 bfd_get_section_contents(abfd
, s
, buffer
, 0, s
->_raw_size
);
516 hms_write_inferior_memory(s
->vma
, buffer
, s
->_raw_size
);
525 /* This is called not only when we first attach, but also when the
526 user types "run" after having attached. */
528 hms_create_inferior (execfile
, args
, env
)
535 DENTER("hms_create_inferior()");
538 error ("Can't pass arguments to remote hms process.");
540 if (execfile
== 0 || exec_bfd
== 0)
541 error ("No exec file specified");
543 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
550 hms_clear_breakpoints();
551 init_wait_for_inferior ();
552 /* Clear the input because what the hms sends back is different
553 * depending on whether it was running or not.
561 insert_breakpoints (); /* Needed to get correct instruction in cache */
562 proceed(entry_pt
, -1, 0);
566 DEXIT("hms_create_inferior()");
569 /* Translate baud rates from integers to damn B_codes. Unix should
570 have outgrown this crap years ago, but even POSIX wouldn't buck it. */
579 static struct {int rate
, damn_b
;} baudtab
[] = {
589 static int damn_b (rate
)
594 for (i
= 0; baudtab
[i
].rate
!= -1; i
++)
595 if (rate
== baudtab
[i
].rate
) return baudtab
[i
].damn_b
;
600 /* Open a connection to a remote debugger.
601 NAME is the filename used for communication, then a space,
609 while (*s
&& !isspace(*s
))
614 static char *get_word(p
)
629 while (*s
&& !isspace(*s
))
635 copy
= xmalloc(len
+1);
636 memcpy(copy
, word
, len
);
642 static int baudrate
= 9600;
649 /* Put this port into NORMAL mode, send the 'normal' character */
650 hms_write("\001", 1); /* Control A */
651 hms_write("\r", 1); /* Cr */
653 while ( readchar_nofail()) /* Skip noise we put there */
657 if (readchar_nofail() == 'r')
660 /* Not the right baudrate, or the board's not on */
669 ioctl (hms_desc
, TIOCGETP
, &sg
);
671 sg
.c_cc
[VMIN
] = 0; /* read with timeout. */
672 sg
.c_cc
[VTIME
] = timeout
* 10;
673 sg
.c_lflag
&= ~(ICANON
| ECHO
);
674 sg
.c_cflag
= (sg
.c_cflag
& ~CBAUD
) | damn_b (baudrate
);
676 sg
.sg_ispeed
= damn_b (baudrate
);
677 sg
.sg_ospeed
= damn_b (baudrate
);
678 sg
.sg_flags
|= RAW
| ANYP
;
679 sg
.sg_flags
&= ~ECHO
;
682 ioctl (hms_desc
, TIOCSETP
, &sg
);
691 while (!is_baudrate_right())
693 if (baudtab
[which_rate
].rate
== -1)
702 baudrate
= baudtab
[which_rate
].rate
;
703 printf_filtered("Board not responding, trying %d baud\n",baudrate
);
710 hms_open (name
, from_tty
)
718 DENTER("hms_open()");
727 hms_desc
= open (dev_name
, O_RDWR
);
729 perror_with_name (dev_name
);
736 /* start_remote (); /* Initialize gdb process mechanisms */
740 #ifndef NO_SIGINTERRUPT
741 /* Cause SIGALRM's to make reads fail with EINTR instead of resuming
743 if (siginterrupt (SIGALRM
, 1) != 0)
744 perror ("hms_open: error in siginterrupt");
747 /* Set up read timeout timer. */
748 if ((void (*)) signal (SIGALRM
, hms_timer
) == (void (*)) -1)
749 perror ("hms_open: error in signal");
752 get_baudrate_right();
754 /* Hello? Are you there? */
755 write (hms_desc
, "\r", 1);
759 /* Clear any break points */
760 hms_clear_breakpoints();
763 printf_filtered("Remote debugging on an H8/300 HMS via %s.\n",dev_name
);
768 /* Close out all files and local state before this target loses control. */
775 DENTER("hms_close()");
777 /* Clear any break points */
778 hms_clear_breakpoints();
780 /* Put this port back into REMOTE mode */
781 if (OPEN(hms_desc
)) {
783 sleep(1); /* Let any output make it all the way back */
784 write(hms_desc
, "R\r", 2);
787 /* Due to a bug in Unix, fclose closes not only the stdio stream,
788 but also the file descriptor. So we don't actually close
793 /* Do not try to close hms_desc again, later in the program. */
797 DEXIT("hms_close()");
800 /* Attach to the target that is already loaded and possibly running */
802 hms_attach (args
, from_tty
)
807 DENTER("hms_attach()");
809 /* push_target(&hms_ops); /* This done in hms_open() */
811 mark_breakpoints_out ();
813 /* Send the hms a kill. It is ok if it is not already running */
815 fprintf(hms_stream
, "K\r");
816 expect_prompt(); /* Slurp the echo */
818 /* We will get a task spawn event immediately. */
819 init_wait_for_inferior ();
820 clear_proceed_status ();
821 stop_soon_quietly
= 1;
822 wait_for_inferior ();
823 stop_soon_quietly
= 0;
825 DEXIT("hms_attach()");
829 /* Terminate the open connection to the remote debugger.
830 Use this when you want to detach and do something else
833 hms_detach (args
,from_tty
)
837 DENTER("hms_detach()");
838 if (OPEN(hms_desc
)) { /* Send it on its way (tell it to continue) */
839 hms_clear_breakpoints();
841 fprintf(hms_stream
,"G\r");
845 pop_target(); /* calls hms_close to do the real work */
847 printf_filtered ("Ending remote %s debugging\n", target_shortname
);
848 DEXIT("hms_detach()");
851 /* Tell the remote machine to resume. */
854 hms_resume (step
, sig
)
857 DENTER("hms_resume()");
866 /* Force the next hms_wait to return a trap. Not doing anything
867 about I/O from the target means that the user has to type
868 "continue" to see any. FIXME, this should be fixed. */
869 need_artificial_trap
= 1;
876 DEXIT("hms_resume()");
879 /* Wait until the remote machine stops, then return,
880 storing status in STATUS just as `wait' would. */
886 /* Strings to look for. '?' means match any single character.
887 Note that with the algorithm we use, the initial character
888 of the string cannot recur in the string, or we will not
889 find some cases of the string in the input. */
891 static char bpt
[] = "At breakpoint:\r";
892 /* It would be tempting to look for "\n[__exit + 0x8]\n"
893 but that requires loading symbols with "yc i" and even if
894 we did do that we don't know that the file has symbols. */
895 static char exitmsg
[] = "HMS>";
899 /* Large enough for either sizeof (bpt) or sizeof (exitmsg) chars. */
901 /* Current position in swallowed. */
902 char *swallowed_p
= swallowed
;
906 int old_timeout
= timeout
;
907 int old_immediate_quit
= immediate_quit
;
908 int swallowed_cr
= 0;
910 DENTER("hms_wait()");
912 WSETEXIT ((*status
), 0);
914 if (need_artificial_trap
!= 0)
916 WSETSTOP ((*status
), SIGTRAP
);
917 need_artificial_trap
--;
921 timeout
= 0; /* Don't time out -- user program is running. */
922 immediate_quit
= 1; /* Helps ability to QUIT */
924 QUIT
; /* Let user quit and leave process running */
936 if (ch
== *ep
|| *ep
== '?') {
948 /* Print out any characters which have been swallowed. */
949 for (p
= swallowed
; p
< swallowed_p
; ++p
)
951 swallowed_p
= swallowed
;
954 if ((ch
!= '\r' && ch
!= '\n') || swallowed_cr
>10)
965 WSETSTOP ((*status
), SIGTRAP
);
970 WSETEXIT ((*status
), 0);
973 timeout
= old_timeout
;
974 immediate_quit
= old_immediate_quit
;
979 /* Return the name of register number REGNO
980 in the form input and output by hms.
982 Returns a pointer to a static buffer containing the answer. */
987 static char *rn
[NUM_REGS
]= REGISTER_NAMES
;
994 /* Read the remote registers. */
995 static int gethex(length
, start
, ok
)
1004 if (*start
>='a' && *start
<= 'f')
1006 result
+= *start
- 'a' + 10;
1008 else if (*start
>='A' && *start
<= 'F')
1010 result
+= *start
- 'A' + 10;
1012 else if (*start
>='0' && *start
<= '9')
1014 result
+= *start
- '0' ;
1023 timed_read(buf
, n
, timeout
)
1034 if (c
== 0) return i
;
1046 write(hms_desc
,a
,l
);
1048 for (i
= 0; i
< l
; i
++)
1057 hms_write( s
, strlen(s
));
1062 hms_fetch_registers ()
1064 #define REGREPLY_SIZE 79
1065 char linebuf
[REGREPLY_SIZE
+1];
1070 REGISTER_TYPE reg
[NUM_REGS
];
1078 s
= timed_read(linebuf
, REGREPLY_SIZE
, 1);
1081 linebuf
[REGREPLY_SIZE
] = 0;
1083 if (linebuf
[0] == 'r' &&
1084 linebuf
[1] == '\r' &&
1085 linebuf
[2] == '\n' &&
1086 linebuf
[3] == 'P' &&
1087 linebuf
[4] == 'C' &&
1088 linebuf
[5] == '=' &&
1089 linebuf
[75] == 'H' &&
1090 linebuf
[76] == 'M' &&
1094 PC=XXXX CCR=XX:XXXXXXXX R0-R7= XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
1095 5436789012345678901234567890123456789012345678901234567890123456789012
1100 reg
[PC_REGNUM
] = gethex(4,linebuf
+6, &gottok
);
1101 reg
[CCR_REGNUM
] = gethex(2,linebuf
+15, &gottok
);
1102 for (i
= 0; i
< 8; i
++)
1104 reg
[i
] = gethex(4, linebuf
+34+5*i
, &gottok
);
1109 for (i
= 0; i
< NUM_REGS
; i
++)
1111 supply_register (i
, reg
+i
);
1115 /* Fetch register REGNO, or all registers if REGNO is -1.
1118 hms_fetch_register (regno
)
1122 hms_fetch_registers ();
1126 /* Store the remote registers from the contents of the block REGS. */
1129 hms_store_registers ()
1132 for (i
= 0; i
< NUM_REGS
; i
++)
1133 hms_store_register(i
);
1138 /* Store register REGNO, or all if REGNO == -1.
1139 Return errno value. */
1141 hms_store_register (regno
)
1145 /* printf("hms_store_register() called.\n"); fflush(stdout); /* */
1147 hms_store_registers ();
1150 char *name
= get_reg_name (regno
);
1152 sprintf(buffer
,"r %s=%x", name
, read_register(regno
));
1153 hms_write_cr(buffer
);
1157 DEXIT("hms_store_registers()");
1161 /* Get ready to modify the registers array. On machines which store
1162 individual registers, this doesn't need to do anything. On machines
1163 which store all the registers in one fell swoop, this makes sure
1164 that registers contains all the registers from the program being
1168 hms_prepare_to_store ()
1170 /* Do nothing, since we can store individual regs */
1174 translate_addr(addr
)
1182 /* Read a word from remote address ADDR and return it.
1183 * This goes through the data cache.
1186 hms_fetch_word (addr
)
1189 return dcache_fetch (addr
);
1192 /* Write a word WORD into remote address ADDR.
1193 This goes through the data cache. */
1196 hms_store_word (addr
, word
)
1200 dcache_poke (addr
, word
);
1204 hms_xfer_inferior_memory(memaddr
, myaddr
, len
, write
, target
)
1209 struct target_ops
*target
; /* ignored */
1212 /* Round starting address down to longword boundary. */
1213 register CORE_ADDR addr
;
1214 /* Round ending address up; get number of longwords that makes. */
1216 /* Allocate buffer of that many longwords. */
1217 register int *buffer
;
1220 addr
= memaddr
& - sizeof (int);
1221 count
= (((memaddr
+ len
) - addr
) + sizeof (int) - 1) / sizeof (int);
1224 buffer
= (int *)alloca (count
* sizeof (int));
1227 /* Fill start and end extra bytes of buffer with existing memory data. */
1229 if (addr
!= memaddr
|| len
< (int)sizeof (int)) {
1230 /* Need part of initial word -- fetch it. */
1231 buffer
[0] = hms_fetch_word (addr
);
1234 if (count
> 1) /* FIXME, avoid if even boundary */
1237 = hms_fetch_word (addr
+ (count
- 1) * sizeof (int));
1240 /* Copy data to be written over corresponding part of buffer */
1242 bcopy (myaddr
, (char *) buffer
+ (memaddr
& (sizeof (int) - 1)), len
);
1244 /* Write the entire buffer. */
1246 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
1249 hms_store_word (addr
, buffer
[i
]);
1260 /* Read all the longwords */
1261 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
1264 buffer
[i
] = hms_fetch_word (addr
);
1272 /* Copy appropriate bytes out of the buffer. */
1273 bcopy ((char *) buffer
+ (memaddr
& (sizeof (int) - 1)), myaddr
, len
);
1282 hms_xfer_inferior_memory (memaddr
, myaddr
, len
, write
)
1290 return hms_write_inferior_memory (memaddr
, myaddr
, len
);
1292 return hms_read_inferior_memory (memaddr
, myaddr
, len
);
1298 hms_write_inferior_memory (memaddr
, myaddr
, len
)
1304 bfd
*abfd
= bfd_openw(dev_name
, "srec");
1307 bfd_set_format(abfd
, bfd_object
);
1308 a
= bfd_make_section(abfd
, ".text");
1311 a
->flags
= SEC_LOAD
| SEC_HAS_CONTENTS
;
1312 hms_write_cr("tl"); /* tell hms here comes the recs */
1313 bfd_set_section_contents(abfd
, a
, myaddr
, 0, len
);
1322 printf_filtered("\tAttached to %s at %d baud and running program %s\n",
1323 dev_name
, baudrate
, bfd_get_filename(exec_bfd
));
1324 printf_filtered("\ton an H8/300 processor.\n");
1327 /* Copy LEN bytes of data from debugger memory at MYADDR
1328 to inferior's memory at MEMADDR. Returns errno value.
1329 * sb/sh instructions don't work on unaligned addresses, when TU=1.
1333 /* Read LEN bytes from inferior memory at MEMADDR. Put the result
1334 at debugger address MYADDR. Returns errno value. */
1336 hms_read_inferior_memory(memaddr
, myaddr
, len
)
1341 /* Align to nearest low 16 bits */
1345 CORE_ADDR start
= memaddr
& ~0xf;
1346 CORE_ADDR end
= ((memaddr
+ len
+16) & ~0xf) -1;
1348 CORE_ADDR start
= memaddr
;
1349 CORE_ADDR end
= memaddr
+ len
-1;
1354 AAAA: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX '................'
1355 012345678901234567890123456789012345678901234567890123456789012345
1359 if (memaddr
& 0xf) abort();
1360 if (len
!= 16) abort();
1362 sprintf(buffer
, "m %4x %4x", start
, end
);
1363 hms_write_cr(buffer
);
1364 /* drop the echo and newline*/
1365 for (i
= 0; i
< 13; i
++)
1370 /* Grab the lines as they come out and fill the area */
1380 buffer
[0] = readchar();
1381 if (buffer
[0] == 'M')
1383 for (i
= 1; i
< 66; i
++)
1384 buffer
[i
] = readchar();
1386 /* Now parse the line */
1388 addr
= gethex(4, buffer
, &ok
);
1390 for (p
= 0; p
< 16; p
+=2)
1392 byte
[p
] = gethex(2, buffer
+ idx
, &ok
);
1393 byte
[p
+1] = gethex(2, buffer
+ idx
+ 2, &ok
);
1399 for (p
= 0; p
<16;p
++)
1401 if (addr
+ p
>= memaddr
&&
1402 addr
+ p
< memaddr
+ len
)
1404 myaddr
[ (addr
+ p
)-memaddr
] = byte
[p
];
1413 hms_write("\003",1);
1423 /* This routine is run as a hook, just before the main command loop is
1424 entered. If gdb is configured for the H8, but has not had its
1425 target specified yet, this will loop prompting the user to do so.
1428 hms_before_main_loop ()
1432 extern FILE *instream
;
1433 extern jmp_buf to_top_level
;
1435 push_target (&hms_ops
);
1438 while (current_target
!= &hms_ops
) {
1439 /* remote tty not specified yet */
1440 if ( instream
== stdin
){
1441 printf("\nEnter device and filename, or \"quit\" to quit: ");
1444 fgets( ttyname
, sizeof(ttyname
)-1, stdin
);
1446 if ( !strcmp("quit", ttyname
) ){
1450 hms_open( ttyname
, 1 );
1452 /* Now that we have a tty open for talking to the remote machine,
1453 download the executable file if one was specified. */
1454 if ( !setjmp(to_top_level
) && exec_bfd
) {
1455 target_load (bfd_get_filename (exec_bfd
), 1);
1462 #define MAX_BREAKS 16
1463 static int num_brkpts
=0;
1465 hms_insert_breakpoint(addr
, save
)
1467 char *save
; /* Throw away, let hms save instructions */
1470 DENTER("hms_insert_breakpoint()");
1473 if (num_brkpts
< MAX_BREAKS
) {
1476 sprintf(buffer
,"b %x", addr
& 0xffff);
1477 hms_write_cr(buffer
);
1479 DEXIT("hms_insert_breakpoint() success");
1480 return(0); /* Success */
1482 fprintf_filtered(stderr
,
1483 "Too many break points, break point not installed\n");
1484 DEXIT("hms_insert_breakpoint() failure");
1485 return(1); /* Failure */
1491 hms_remove_breakpoint(addr
, save
)
1493 char *save
; /* Throw away, let hms save instructions */
1495 DENTER("hms_remove_breakpoint()");
1496 if (num_brkpts
> 0) {
1500 sprintf(buffer
,"b - %x", addr
& 0xffff);
1501 hms_write_cr(buffer
);
1505 DEXIT("hms_remove_breakpoint()");
1509 /* Clear the hmss notion of what the break points are */
1511 hms_clear_breakpoints()
1514 DENTER("hms_clear_breakpoint()");
1515 if (OPEN(hms_desc
)) {
1516 hms_write_cr("b -");
1521 DEXIT("hms_clear_breakpoint()");
1526 DENTER("hms_mourn()");
1527 hms_clear_breakpoints();
1528 /* pop_target (); /* Pop back to no-child state */
1529 generic_mourn_inferior ();
1530 DEXIT("hms_mourn()");
1533 /* Display everthing we read in from the hms until we match/see the
1542 while (c
=readchar()) {
1545 if (i
== strlen(str
)) return;
1548 for (j
=0 ; j
<i
; j
++) /* Put everthing we matched */
1559 /* Put a command string, in args, out to the hms. The hms is assumed to
1560 be in raw mode, all writing/reading done through hms_desc.
1561 Ouput from the hms is placed on the users terminal until the
1562 prompt from the hms is seen.
1563 FIXME: Can't handle commands that take input. */
1566 hms_com (args
, fromtty
)
1574 /* Clear all input so only command relative output is displayed */
1578 hms_write("\030",1);
1583 /* Define the target subroutine names */
1585 struct target_ops hms_ops
= {
1586 "hms", "Remote HMS monitor",
1587 "Use the H8 evaluation board running the HMS monitor connected\n\
1590 hms_open
, hms_close
,
1591 hms_attach
, hms_detach
, hms_resume
, hms_wait
,
1592 hms_fetch_register
, hms_store_register
,
1593 hms_prepare_to_store
, 0, 0, /* conv_to, conv_from */
1594 hms_xfer_inferior_memory
,
1596 hms_insert_breakpoint
, hms_remove_breakpoint
, /* Breakpoints */
1597 0, 0, 0, 0, 0, /* Terminal handling */
1598 hms_kill
, /* FIXME, kill */
1600 0, /* lookup_symbol */
1601 hms_create_inferior
, /* create_inferior */
1602 hms_mourn
, /* mourn_inferior FIXME */
1603 process_stratum
, 0, /* next */
1604 1, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
1605 0,0, /* Section pointers */
1606 OPS_MAGIC
, /* Always the last thing */
1619 dev_name
= get_word(&s
);
1629 int newrate
= atoi(s
);
1631 while (baudtab
[which
].rate
!= newrate
)
1633 if (baudtab
[which
].rate
== -1)
1635 error("Can't use %d baud\n", newrate
);
1642 printf_filtered("Checking target is in sync\n");
1645 get_baudrate_right();
1647 printf_filtered("Sending commands to set target to %d\n",
1650 sprintf(buffer
, "tm %d. N 8 1", baudrate
);
1655 /***********************************************************************/
1658 _initialize_remote_hms ()
1660 add_target (&hms_ops
);
1661 add_com ("hms <command>", class_obscure
, hms_com
,
1662 "Send a command to the HMS monitor.");
1663 add_com ("snoop", class_obscure
, hms_quiet
,
1664 "Show what commands are going to the monitor");
1665 add_com ("device", class_obscure
, hms_device
,
1666 "Set the terminal line for HMS communications");
1668 add_com ("speed", class_obscure
, hms_speed
,
1669 "Set the terminal line speed for HMS communications");
This page took 0.062873 seconds and 4 git commands to generate.