1 /* Remote debugging interface for Hitachi HMS Monitor Version 1.0
3 Copyright 1992 Free Software Foundation, Inc.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
41 /* External data declarations */
42 extern int stop_soon_quietly; /* for wait_for_inferior */
44 /* External function declarations */
45 extern struct value *call_function_by_hand();
47 /* Forward data declarations */
48 extern struct target_ops hms_ops; /* Forward declaration */
50 /* Forward function declarations */
51 static void hms_fetch_registers ();
52 static int hms_store_registers ();
53 static void hms_close ();
54 static int hms_clear_breakpoints();
56 extern struct target_ops hms_ops;
61 # define DENTER(NAME) if (!quiet) (printf_filtered("Entering %s\n",NAME), fflush(stdout))
62 # define DEXIT(NAME) if (!quiet) (printf_filtered("Exiting %s\n",NAME), fflush(stdout))
69 /***********************************************************************/
70 /* Caching stuff stolen from remote-nindy.c */
72 /* The data cache records all the data read from the remote machine
73 since the last time it stopped.
75 Each cache block holds LINE_SIZE bytes of data
76 starting at a multiple-of-LINE_SIZE address. */
79 #define LINE_SIZE_POWER 4
80 #define LINE_SIZE (1<<LINE_SIZE_POWER) /* eg 1<<3 == 8 */
81 #define LINE_SIZE_MASK ((LINE_SIZE-1)) /* eg 7*2+1= 111*/
82 #define DCACHE_SIZE 64 /* Number of cache blocks */
83 #define XFORM(x) ((x&LINE_SIZE_MASK)>>2)
85 struct dcache_block *next, *last;
86 unsigned int addr; /* Address for which data is recorded. */
87 int data[LINE_SIZE/sizeof(int)];
90 struct dcache_block dcache_free, dcache_valid;
92 /* Free all the data cache blocks, thus discarding all cached data. */
97 register struct dcache_block *db;
99 while ((db = dcache_valid.next) != &dcache_valid)
102 insque (db, &dcache_free);
107 * If addr is present in the dcache, return the address of the block
111 struct dcache_block *
115 register struct dcache_block *db;
120 /* Search all cache blocks for one that is at this address. */
121 db = dcache_valid.next;
122 while (db != &dcache_valid)
124 if ((addr & ~LINE_SIZE_MASK)== db->addr)
131 /* Return the int data at address ADDR in dcache block DC. */
134 dcache_value (db, addr)
135 struct dcache_block *db;
140 return (db->data[XFORM(addr)]);
143 /* Get a free cache block, put or keep it on the valid list,
144 and return its address. The caller should store into the block
145 the address and data that it describes, then remque it from the
146 free list and insert it into the valid list. This procedure
147 prevents errors from creeping in if a ninMemGet is interrupted
148 (which used to put garbage blocks in the valid list...). */
150 struct dcache_block *
153 register struct dcache_block *db;
155 if ((db = dcache_free.next) == &dcache_free)
157 /* If we can't get one from the free list, take last valid and put
158 it on the free list. */
159 db = dcache_valid.last;
161 insque (db, &dcache_free);
165 insque (db, &dcache_valid);
169 /* Return the contents of the word at address ADDR in the remote machine,
170 using the data cache. */
176 register struct dcache_block *db;
178 db = dcache_hit (addr);
181 db = dcache_alloc ();
183 hms_read_inferior_memory(addr & ~LINE_SIZE_MASK, (unsigned char *)db->data, LINE_SIZE);
185 db->addr = addr & ~LINE_SIZE_MASK;
186 remque (db); /* Off the free list */
187 insque (db, &dcache_valid); /* On the valid list */
189 return (dcache_value (db, addr));
192 /* Write the word at ADDR both in the data cache and in the remote machine. */
194 dcache_poke (addr, data)
198 register struct dcache_block *db;
200 /* First make sure the word is IN the cache. DB is its cache block. */
201 db = dcache_hit (addr);
204 db = dcache_alloc ();
206 hms_write_inferior_memory(addr & ~LINE_SIZE_MASK, (unsigned char *)db->data, LINE_SIZE);
208 db->addr = addr & ~LINE_SIZE_MASK;
209 remque (db); /* Off the free list */
210 insque (db, &dcache_valid); /* On the valid list */
213 /* Modify the word in the cache. */
214 db->data[XFORM(addr)] = data;
216 /* Send the changed word. */
218 hms_write_inferior_memory(addr, (unsigned char *)&data, 4);
222 /* The cache itself. */
223 struct dcache_block the_cache[DCACHE_SIZE];
225 /* Initialize the data cache. */
230 register struct dcache_block *db;
233 dcache_free.next = dcache_free.last = &dcache_free;
234 dcache_valid.next = dcache_valid.last = &dcache_valid;
235 for (i=0;i<DCACHE_SIZE;i++,db++)
236 insque (db, &dcache_free);
240 /***********************************************************************
241 * I/O stuff stolen from remote-eb.c
242 ***********************************************************************/
244 static int timeout = 2;
245 static char *dev_name = "/dev/ttya";
250 /* Descriptor for I/O to remote machine. Initialize it to -1 so that
251 hms_open knows that we don't have a file open when the program
254 #define OPEN(x) ((x) >= 0)
262 rawmode(desc, turnon)
271 ioctl (desc, TIOCGETP, &sg);
275 sg.c_lflag &= ~(ICANON);
281 sg.c_lflag |= ICANON;
283 sg.sg_flags &= ~(RAW);
286 ioctl (desc, TIOCSETP, &sg);
290 /* Read a character from the remote system, doing all the fancy
299 /* termio does the timeout for us. */
300 read (hms_desc, &buf, 1);
303 if (read (hms_desc, &buf, 1) < 0)
306 error ("Timeout reading from remote system.");
308 perror_with_name ("remote");
314 error ("Timeout reading from remote system.");
329 /* termio does the timeout for us. */
330 read (hms_desc, &buf, 1);
333 if (read (hms_desc, &buf, 1) < 0)
347 /* Keep discarding input from the remote system, until STRING is found.
348 Let the user break out immediately. */
359 if (readchar() == *p)
373 /* Keep discarding input until we see the hms prompt.
375 The convention for dealing with the prompt is that you
377 o *then* wait for the prompt.
379 Thus the last thing that a procedure does with the serial line
380 will be an expect_prompt(). Exception: hms_resume does not
381 wait for the prompt, because the terminal is being handed over
382 to the inferior. However, the next thing which happens after that
383 is a hms_wait which does wait for the prompt.
384 Note that this includes abnormal exit, e.g. error(). This is
385 necessary to prevent getting into states from which we can't
394 /* Get a hex digit from the remote system & return its value.
395 If ignore_space is nonzero, ignore spaces (not newline, tab, etc). */
397 get_hex_digit (ignore_space)
404 if (ch >= '0' && ch <= '9')
406 else if (ch >= 'A' && ch <= 'F')
407 return ch - 'A' + 10;
408 else if (ch >= 'a' && ch <= 'f')
409 return ch - 'a' + 10;
410 else if (ch == ' ' && ignore_space)
415 error ("Invalid hex digit from remote system.");
420 /* Get a byte from hms_desc and put it in *BYT. Accept any number
428 val = get_hex_digit (1) << 4;
429 val |= get_hex_digit (0);
433 /* Read a 32-bit hex word from the hms, preceded by a space */
441 for (j = 0; j < 8; j++)
442 val = (val << 4) + get_hex_digit (j == 0);
445 /* Called when SIGALRM signal sent due to alarm() timeout. */
450 # define volatile /**/
453 volatile int n_alarms;
463 /* Number of SIGTRAPs we need to simulate. That is, the next
464 NEED_ARTIFICIAL_TRAP calls to hms_wait should just return
465 SIGTRAP without actually waiting for anything. */
467 static int need_artificial_trap = 0;
470 hms_kill(arg,from_tty)
479 if (!OPEN(hms_desc)) {
485 * Download a file specified in 'args', to the hms.
488 hms_load(args,fromtty)
497 DENTER("hms_load()");
502 abfd = bfd_openr(args,"coff-h8300");
505 printf_filtered("Unable to open file %s\n", args);
509 if (bfd_check_format(abfd, bfd_object) ==0)
511 printf_filtered("File is not an object file\n");
516 while (s != (asection *)NULL)
518 if (s->flags & SEC_LOAD)
520 char *buffer = xmalloc(s->_raw_size);
521 bfd_get_section_contents(abfd, s, buffer, 0, s->_raw_size);
523 hms_write_inferior_memory(s->vma, buffer, s->_raw_size);
532 /* This is called not only when we first attach, but also when the
533 user types "run" after having attached. */
535 hms_create_inferior (execfile, args, env)
542 DENTER("hms_create_inferior()");
545 error ("Can't pass arguments to remote hms process.");
547 if (execfile == 0 || exec_bfd == 0)
548 error ("No exec file specified");
550 entry_pt = (int) bfd_get_start_address (exec_bfd);
557 hms_clear_breakpoints();
558 init_wait_for_inferior ();
559 /* Clear the input because what the hms sends back is different
560 * depending on whether it was running or not.
568 insert_breakpoints (); /* Needed to get correct instruction in cache */
569 proceed(entry_pt, -1, 0);
573 DEXIT("hms_create_inferior()");
576 /* Translate baud rates from integers to damn B_codes. Unix should
577 have outgrown this crap years ago, but even POSIX wouldn't buck it. */
586 static struct {int rate, damn_b;} baudtab[] = {
596 static int damn_b (rate)
601 for (i = 0; baudtab[i].rate != -1; i++)
602 if (rate == baudtab[i].rate) return baudtab[i].damn_b;
607 /* Open a connection to a remote debugger.
608 NAME is the filename used for communication, then a space,
616 while (*s && !isspace(*s))
621 static char *get_word(p)
636 while (*s && !isspace(*s))
642 copy = xmalloc(len+1);
643 memcpy(copy, word, len);
649 static int baudrate = 9600;
656 /* Put this port into NORMAL mode, send the 'normal' character */
657 hms_write("\001", 1); /* Control A */
658 hms_write("\r", 1); /* Cr */
660 while ( readchar_nofail()) /* Skip noise we put there */
664 if (readchar_nofail() == 'r')
667 /* Not the right baudrate, or the board's not on */
676 ioctl (hms_desc, TIOCGETP, &sg);
678 sg.c_cc[VMIN] = 0; /* read with timeout. */
679 sg.c_cc[VTIME] = timeout * 10;
680 sg.c_lflag &= ~(ICANON | ECHO);
681 sg.c_cflag = (sg.c_cflag & ~CBAUD) | damn_b (baudrate);
683 sg.sg_ispeed = damn_b (baudrate);
684 sg.sg_ospeed = damn_b (baudrate);
685 sg.sg_flags |= RAW | ANYP;
686 sg.sg_flags &= ~ECHO;
689 ioctl (hms_desc, TIOCSETP, &sg);
698 while (!is_baudrate_right())
700 if (baudtab[which_rate].rate == -1)
709 baudrate = baudtab[which_rate].rate;
710 printf_filtered("Board not responding, trying %d baud\n",baudrate);
717 hms_open (name, from_tty)
725 DENTER("hms_open()");
734 hms_desc = open (dev_name, O_RDWR);
736 perror_with_name (dev_name);
743 /* start_remote (); /* Initialize gdb process mechanisms */
747 #ifndef NO_SIGINTERRUPT
748 /* Cause SIGALRM's to make reads fail with EINTR instead of resuming
750 if (siginterrupt (SIGALRM, 1) != 0)
751 perror ("hms_open: error in siginterrupt");
754 /* Set up read timeout timer. */
755 if ((void (*)) signal (SIGALRM, hms_timer) == (void (*)) -1)
756 perror ("hms_open: error in signal");
759 get_baudrate_right();
761 /* Hello? Are you there? */
762 write (hms_desc, "\r", 1);
766 /* Clear any break points */
767 hms_clear_breakpoints();
770 printf_filtered("Remote debugging on an H8/300 HMS via %s.\n",dev_name);
775 /* Close out all files and local state before this target loses control. */
782 DENTER("hms_close()");
784 /* Clear any break points */
785 hms_clear_breakpoints();
787 /* Put this port back into REMOTE mode */
788 if (OPEN(hms_desc)) {
790 sleep(1); /* Let any output make it all the way back */
791 write(hms_desc, "R\r", 2);
794 /* Due to a bug in Unix, fclose closes not only the stdio stream,
795 but also the file descriptor. So we don't actually close
800 /* Do not try to close hms_desc again, later in the program. */
804 DEXIT("hms_close()");
807 /* Attach to the target that is already loaded and possibly running */
809 hms_attach (args, from_tty)
814 DENTER("hms_attach()");
816 /* push_target(&hms_ops); /* This done in hms_open() */
818 mark_breakpoints_out ();
820 /* Send the hms a kill. It is ok if it is not already running */
822 fprintf(hms_stream, "K\r");
823 expect_prompt(); /* Slurp the echo */
825 /* We will get a task spawn event immediately. */
826 init_wait_for_inferior ();
827 clear_proceed_status ();
828 stop_soon_quietly = 1;
829 wait_for_inferior ();
830 stop_soon_quietly = 0;
832 DEXIT("hms_attach()");
836 /* Terminate the open connection to the remote debugger.
837 Use this when you want to detach and do something else
840 hms_detach (args,from_tty)
844 DENTER("hms_detach()");
845 if (OPEN(hms_desc)) { /* Send it on its way (tell it to continue) */
846 hms_clear_breakpoints();
848 fprintf(hms_stream,"G\r");
852 pop_target(); /* calls hms_close to do the real work */
854 printf_filtered ("Ending remote %s debugging\n", target_shortname);
855 DEXIT("hms_detach()");
858 /* Tell the remote machine to resume. */
861 hms_resume (step, sig)
864 DENTER("hms_resume()");
873 /* Force the next hms_wait to return a trap. Not doing anything
874 about I/O from the target means that the user has to type
875 "continue" to see any. FIXME, this should be fixed. */
876 need_artificial_trap = 1;
883 DEXIT("hms_resume()");
886 /* Wait until the remote machine stops, then return,
887 storing status in STATUS just as `wait' would. */
893 /* Strings to look for. '?' means match any single character.
894 Note that with the algorithm we use, the initial character
895 of the string cannot recur in the string, or we will not
896 find some cases of the string in the input. */
898 static char bpt[] = "At breakpoint:\r";
899 /* It would be tempting to look for "\n[__exit + 0x8]\n"
900 but that requires loading symbols with "yc i" and even if
901 we did do that we don't know that the file has symbols. */
902 static char exitmsg[] = "HMS>";
906 /* Large enough for either sizeof (bpt) or sizeof (exitmsg) chars. */
908 /* Current position in swallowed. */
909 char *swallowed_p = swallowed;
913 int old_timeout = timeout;
914 int old_immediate_quit = immediate_quit;
915 int swallowed_cr = 0;
917 DENTER("hms_wait()");
919 WSETEXIT ((*status), 0);
921 if (need_artificial_trap != 0)
923 WSETSTOP ((*status), SIGTRAP);
924 need_artificial_trap--;
928 timeout = 0; /* Don't time out -- user program is running. */
929 immediate_quit = 1; /* Helps ability to QUIT */
931 QUIT; /* Let user quit and leave process running */
943 if (ch == *ep || *ep == '?') {
955 /* Print out any characters which have been swallowed. */
956 for (p = swallowed; p < swallowed_p; ++p)
958 swallowed_p = swallowed;
961 if ((ch != '\r' && ch != '\n') || swallowed_cr>10)
972 WSETSTOP ((*status), SIGTRAP);
977 WSETEXIT ((*status), 0);
980 timeout = old_timeout;
981 immediate_quit = old_immediate_quit;
986 /* Return the name of register number REGNO
987 in the form input and output by hms.
989 Returns a pointer to a static buffer containing the answer. */
994 static char *rn[NUM_REGS]= REGISTER_NAMES;
1001 /* Read the remote registers. */
1002 static int gethex(length, start, ok)
1003 unsigned int length;
1011 if (*start >='a' && *start <= 'f')
1013 result += *start - 'a' + 10;
1015 else if (*start >='A' && *start <= 'F')
1017 result += *start - 'A' + 10;
1019 else if (*start >='0' && *start <= '9')
1021 result += *start - '0' ;
1030 timed_read(buf, n, timeout)
1041 if (c == 0) return i;
1053 write(hms_desc,a,l);
1055 for (i = 0; i < l ; i++)
1064 hms_write( s, strlen(s));
1069 hms_fetch_registers ()
1071 #define REGREPLY_SIZE 79
1072 char linebuf[REGREPLY_SIZE+1];
1077 REGISTER_TYPE reg[NUM_REGS];
1085 s = timed_read(linebuf, REGREPLY_SIZE, 1);
1088 linebuf[REGREPLY_SIZE] = 0;
1090 if (linebuf[0] == 'r' &&
1091 linebuf[1] == '\r' &&
1092 linebuf[2] == '\n' &&
1093 linebuf[3] == 'P' &&
1094 linebuf[4] == 'C' &&
1095 linebuf[5] == '=' &&
1096 linebuf[75] == 'H' &&
1097 linebuf[76] == 'M' &&
1101 PC=XXXX CCR=XX:XXXXXXXX R0-R7= XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
1102 5436789012345678901234567890123456789012345678901234567890123456789012
1107 reg[PC_REGNUM] = gethex(4,linebuf+6, &gottok);
1108 reg[CCR_REGNUM] = gethex(2,linebuf+15, &gottok);
1109 for (i = 0; i < 8; i++)
1111 reg[i] = gethex(4, linebuf+34+5*i, &gottok);
1116 for (i = 0; i < NUM_REGS; i++)
1118 supply_register (i, reg+i);
1122 /* Fetch register REGNO, or all registers if REGNO is -1.
1125 hms_fetch_register (regno)
1129 hms_fetch_registers ();
1133 /* Store the remote registers from the contents of the block REGS. */
1136 hms_store_registers ()
1139 for (i = 0; i < NUM_REGS; i++)
1140 hms_store_register(i);
1145 /* Store register REGNO, or all if REGNO == -1.
1146 Return errno value. */
1148 hms_store_register (regno)
1152 /* printf("hms_store_register() called.\n"); fflush(stdout); /* */
1154 hms_store_registers ();
1157 char *name = get_reg_name (regno);
1159 sprintf(buffer,"r %s=%x", name, read_register(regno));
1160 hms_write_cr(buffer);
1164 DEXIT("hms_store_registers()");
1168 /* Get ready to modify the registers array. On machines which store
1169 individual registers, this doesn't need to do anything. On machines
1170 which store all the registers in one fell swoop, this makes sure
1171 that registers contains all the registers from the program being
1175 hms_prepare_to_store ()
1177 /* Do nothing, since we can store individual regs */
1181 translate_addr(addr)
1189 /* Read a word from remote address ADDR and return it.
1190 * This goes through the data cache.
1193 hms_fetch_word (addr)
1196 return dcache_fetch (addr);
1199 /* Write a word WORD into remote address ADDR.
1200 This goes through the data cache. */
1203 hms_store_word (addr, word)
1207 dcache_poke (addr, word);
1211 hms_xfer_inferior_memory(memaddr, myaddr, len, write, target)
1216 struct target_ops *target; /* ignored */
1219 /* Round starting address down to longword boundary. */
1220 register CORE_ADDR addr;
1221 /* Round ending address up; get number of longwords that makes. */
1223 /* Allocate buffer of that many longwords. */
1224 register int *buffer ;
1227 addr = memaddr & - sizeof (int);
1228 count = (((memaddr + len) - addr) + sizeof (int) - 1) / sizeof (int);
1231 buffer = (int *)alloca (count * sizeof (int));
1234 /* Fill start and end extra bytes of buffer with existing memory data. */
1236 if (addr != memaddr || len < (int)sizeof (int)) {
1237 /* Need part of initial word -- fetch it. */
1238 buffer[0] = hms_fetch_word (addr);
1241 if (count > 1) /* FIXME, avoid if even boundary */
1244 = hms_fetch_word (addr + (count - 1) * sizeof (int));
1247 /* Copy data to be written over corresponding part of buffer */
1249 bcopy (myaddr, (char *) buffer + (memaddr & (sizeof (int) - 1)), len);
1251 /* Write the entire buffer. */
1253 for (i = 0; i < count; i++, addr += sizeof (int))
1256 hms_store_word (addr, buffer[i]);
1267 /* Read all the longwords */
1268 for (i = 0; i < count; i++, addr += sizeof (int))
1271 buffer[i] = hms_fetch_word (addr);
1279 /* Copy appropriate bytes out of the buffer. */
1280 bcopy ((char *) buffer + (memaddr & (sizeof (int) - 1)), myaddr, len);
1289 hms_xfer_inferior_memory (memaddr, myaddr, len, write)
1297 return hms_write_inferior_memory (memaddr, myaddr, len);
1299 return hms_read_inferior_memory (memaddr, myaddr, len);
1305 hms_write_inferior_memory (memaddr, myaddr, len)
1311 bfd *abfd = bfd_openw(dev_name, "srec");
1314 bfd_set_format(abfd, bfd_object);
1315 a = bfd_make_section(abfd, ".text");
1318 a->flags = SEC_LOAD | SEC_HAS_CONTENTS;
1319 hms_write_cr("tl"); /* tell hms here comes the recs */
1320 bfd_set_section_contents(abfd, a, myaddr, 0, len);
1329 printf_filtered("\tAttached to %s at %d baud and running program %s\n",
1330 dev_name, baudrate, bfd_get_filename(exec_bfd));
1331 printf_filtered("\ton an H8/300 processor.\n");
1334 /* Copy LEN bytes of data from debugger memory at MYADDR
1335 to inferior's memory at MEMADDR. Returns errno value.
1336 * sb/sh instructions don't work on unaligned addresses, when TU=1.
1340 /* Read LEN bytes from inferior memory at MEMADDR. Put the result
1341 at debugger address MYADDR. Returns errno value. */
1343 hms_read_inferior_memory(memaddr, myaddr, len)
1348 /* Align to nearest low 16 bits */
1352 CORE_ADDR start = memaddr & ~0xf;
1353 CORE_ADDR end = ((memaddr + len +16) & ~0xf) -1;
1355 CORE_ADDR start = memaddr;
1356 CORE_ADDR end = memaddr + len -1;
1361 AAAA: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX '................'
1362 012345678901234567890123456789012345678901234567890123456789012345
1366 if (memaddr & 0xf) abort();
1367 if (len != 16) abort();
1369 sprintf(buffer, "m %4x %4x", start, end);
1370 hms_write_cr(buffer);
1371 /* drop the echo and newline*/
1372 for (i = 0; i < 13; i++)
1377 /* Grab the lines as they come out and fill the area */
1387 buffer[0] = readchar();
1388 if (buffer[0] == 'M')
1390 for (i = 1; i < 66; i++)
1391 buffer[i] = readchar();
1393 /* Now parse the line */
1395 addr = gethex(4, buffer, &ok);
1397 for (p = 0; p < 16; p+=2)
1399 byte[p] = gethex(2, buffer + idx, &ok);
1400 byte[p+1] = gethex(2, buffer+ idx + 2, &ok);
1406 for (p = 0; p<16;p++)
1408 if (addr + p >= memaddr &&
1409 addr + p < memaddr + len)
1411 myaddr[ (addr + p)-memaddr] = byte[p];
1420 hms_write("\003",1);
1430 /* This routine is run as a hook, just before the main command loop is
1431 entered. If gdb is configured for the H8, but has not had its
1432 target specified yet, this will loop prompting the user to do so.
1435 hms_before_main_loop ()
1439 extern FILE *instream;
1440 extern jmp_buf to_top_level;
1442 push_target (&hms_ops);
1445 while (current_target != &hms_ops) {
1446 /* remote tty not specified yet */
1447 if ( instream == stdin ){
1448 printf("\nEnter device and filename, or \"quit\" to quit: ");
1451 fgets( ttyname, sizeof(ttyname)-1, stdin );
1453 if ( !strcmp("quit", ttyname) ){
1457 hms_open( ttyname, 1 );
1459 /* Now that we have a tty open for talking to the remote machine,
1460 download the executable file if one was specified. */
1461 if ( !setjmp(to_top_level) && exec_bfd ) {
1462 target_load (bfd_get_filename (exec_bfd), 1);
1469 #define MAX_BREAKS 16
1470 static int num_brkpts=0;
1472 hms_insert_breakpoint(addr, save)
1474 char *save; /* Throw away, let hms save instructions */
1477 DENTER("hms_insert_breakpoint()");
1480 if (num_brkpts < MAX_BREAKS) {
1483 sprintf(buffer,"b %x", addr & 0xffff);
1484 hms_write_cr(buffer);
1486 DEXIT("hms_insert_breakpoint() success");
1487 return(0); /* Success */
1489 fprintf_filtered(stderr,
1490 "Too many break points, break point not installed\n");
1491 DEXIT("hms_insert_breakpoint() failure");
1492 return(1); /* Failure */
1498 hms_remove_breakpoint(addr, save)
1500 char *save; /* Throw away, let hms save instructions */
1502 DENTER("hms_remove_breakpoint()");
1503 if (num_brkpts > 0) {
1507 sprintf(buffer,"b - %x", addr & 0xffff);
1508 hms_write_cr(buffer);
1512 DEXIT("hms_remove_breakpoint()");
1516 /* Clear the hmss notion of what the break points are */
1518 hms_clear_breakpoints()
1521 DENTER("hms_clear_breakpoint()");
1522 if (OPEN(hms_desc)) {
1523 hms_write_cr("b -");
1528 DEXIT("hms_clear_breakpoint()");
1533 DENTER("hms_mourn()");
1534 hms_clear_breakpoints();
1535 /* pop_target (); /* Pop back to no-child state */
1536 generic_mourn_inferior ();
1537 DEXIT("hms_mourn()");
1540 /* Display everthing we read in from the hms until we match/see the
1549 while (c=readchar()) {
1552 if (i == strlen(str)) return;
1555 for (j=0 ; j<i ; j++) /* Put everthing we matched */
1566 /* Put a command string, in args, out to the hms. The hms is assumed to
1567 be in raw mode, all writing/reading done through hms_desc.
1568 Ouput from the hms is placed on the users terminal until the
1569 prompt from the hms is seen.
1570 FIXME: Can't handle commands that take input. */
1573 hms_com (args, fromtty)
1581 /* Clear all input so only command relative output is displayed */
1585 hms_write("\030",1);
1590 /* Define the target subroutine names */
1592 struct target_ops hms_ops = {
1593 "hms", "Remote HMS monitor",
1594 "Use the H8 evaluation board running the HMS monitor connected\n\
1597 hms_open, hms_close,
1598 hms_attach, hms_detach, hms_resume, hms_wait,
1599 hms_fetch_register, hms_store_register,
1600 hms_prepare_to_store, 0, 0, /* conv_to, conv_from */
1601 hms_xfer_inferior_memory,
1603 hms_insert_breakpoint, hms_remove_breakpoint, /* Breakpoints */
1604 0, 0, 0, 0, 0, /* Terminal handling */
1605 hms_kill, /* FIXME, kill */
1607 call_function_by_hand,
1608 0, /* lookup_symbol */
1609 hms_create_inferior, /* create_inferior */
1610 hms_mourn, /* mourn_inferior FIXME */
1611 process_stratum, 0, /* next */
1612 1, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
1613 0,0, /* Section pointers */
1614 OPS_MAGIC, /* Always the last thing */
1627 dev_name = get_word(&s);
1637 int newrate = atoi(s);
1639 while (baudtab[which].rate != newrate)
1641 if (baudtab[which].rate == -1)
1643 error("Can't use %d baud\n", newrate);
1650 printf_filtered("Checking target is in sync\n");
1653 get_baudrate_right();
1655 printf_filtered("Sending commands to set target to %d\n",
1658 sprintf(buffer, "tm %d. N 8 1", baudrate);
1663 /***********************************************************************/
1666 _initialize_remote_hms ()
1668 add_target (&hms_ops);
1669 add_com ("hms <command>", class_obscure, hms_com,
1670 "Send a command to the HMS monitor.");
1671 add_com ("snoop", class_obscure, hms_quiet,
1672 "Show what commands are going to the monitor");
1673 add_com ("device", class_obscure, hms_device,
1674 "Set the terminal line for HMS communications");
1676 add_com ("speed", class_obscure, hms_speed,
1677 "Set the terminal line speed for HMS communications");