1 /* Remote debugging interface for Hitachi E7000 ICE, for GDB
2 Copyright 1993, 1994 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 Written by Steve Chamberlain for Cygnus Support.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 /* The E7000 is an in-circuit emulator for the Hitachi H8/300-H and
24 Hitachi-SH processor. It has serial port and a lan port.
26 The monitor command set makes it difficult to load large ammounts of
27 data over the lan without using ftp - so try not to issue load
28 commands when communicating over ethernet; use the ftpload command.
30 The monitor pauses for a second when dumping srecords to the serial
31 line too, so we use a slower per byte mechanism but without the
32 startup overhead. Even so, it's pretty slow... */
42 #include "gdb_string.h"
43 #include <sys/types.h>
45 #include "remote-utils.h"
48 #define HARD_BREAKPOINTS
49 #define BC_BREAKPOINTS 0
57 extern void notice_quit PARAMS ((void));
59 /* Local function declarations. */
61 static void e7000_close PARAMS ((int));
63 static void e7000_fetch_register PARAMS ((int));
65 static void e7000_store_register PARAMS ((int));
67 static void e7000_command PARAMS ((char *, int));
69 static void e7000_login_command PARAMS ((char *, int));
71 static void e7000_ftp_command PARAMS ((char *, int));
73 static void e7000_drain_command PARAMS ((char *, int));
75 static void expect PARAMS ((char *));
77 static void expect_full_prompt PARAMS ((void));
79 static void expect_prompt PARAMS ((void));
83 static serial_t e7000_desc;
85 /* Nonzero if using the tcp serial driver. */
89 /* Nonzero if using the pc isa card. */
93 extern struct target_ops e7000_ops; /* Forward declaration */
95 char *ENQSTRING = "\005";
97 /* Nonzero if some routine (as opposed to the user) wants echoing.
98 FIXME: Do this reentrantly with an extra parameter. */
104 static int timeout = 5;
106 /* Send data to e7000debug. */
109 puts_e7000debug (buf)
113 error ("Use \"target e7000 ...\" first.");
116 printf("Sending %s\n", buf);
118 if (SERIAL_WRITE (e7000_desc, buf, strlen (buf)))
119 fprintf (stderr, "SERIAL_WRITE failed: %s\n", safe_strerror (errno));
121 /* And expect to see it echoed, unless using the pc interface */
135 SERIAL_WRITE (e7000_desc, b, 1);
142 SERIAL_WRITE (e7000_desc, s, strlen (s));
154 /* Read a character from the remote system, doing all the fancy timeout
165 c = SERIAL_READCHAR (e7000_desc, timeout);
169 if (c == SERIAL_TIMEOUT)
174 error ("Timeout reading from remote system.");
189 static char b[8][10];
201 sprintf(b[p], "<%d>", x);
208 /* Scan input from the remote system, until STRING is found. If
209 DISCARD is non-zero, then discard non-matching input, else print it
210 out. Let the user break out immediately. */
222 c = readchar (timeout);
228 putchar_e7000(CTRLC);
237 if (c == SERIAL_ERROR)
239 error ("Serial communication error");
241 if (echo || remote_debug)
243 if (c == '\r' || c == '\n')
256 if (normal (c) == normal (*p++))
265 if (normal (c) == normal (string[0]))
271 /* Keep discarding input until we see the e7000 prompt.
273 The convention for dealing with the prompt is that you
275 o *then* wait for the prompt.
277 Thus the last thing that a procedure does with the serial line will
278 be an expect_prompt(). Exception: e7000_resume does not wait for
279 the prompt, because the terminal is being handed over to the
280 inferior. However, the next thing which happens after that is a
281 e7000_wait which does wait for the prompt. Note that this includes
282 abnormal exit, e.g. error(). This is necessary to prevent getting
283 into states from which we can't recover. */
292 expect_full_prompt ()
298 convert_hex_digit (ch)
301 if (ch >= '0' && ch <= '9')
303 else if (ch >= 'A' && ch <= 'F')
304 return ch - 'A' + 10;
305 else if (ch >= 'a' && ch <= 'f')
306 return ch - 'a' + 10;
314 int value = convert_hex_digit (*start);
317 *start = readchar (timeout);
318 while ((try = convert_hex_digit (*start)) >= 0)
322 *start = readchar (timeout);
328 /* Get N 32-bit words from remote, each preceded by a space, and put
329 them in registers starting at REGNO. */
332 get_hex_regs (n, regno)
339 for (i = 0; i < n; i++)
344 for (j = 0; j < 8; j++)
345 val = (val << 4) + get_hex_digit (j == 0);
346 supply_register (regno++, (char *) &val);
351 /* This is called not only when we first attach, but also when the
352 user types "run" after having attached. */
355 e7000_create_inferior (execfile, args, env)
363 error ("Can't pass arguments to remote E7000DEBUG process");
365 if (execfile == 0 || exec_bfd == 0)
366 error ("No exec file specified");
368 entry_pt = (int) bfd_get_start_address (exec_bfd);
370 #ifdef CREATE_INFERIOR_HOOK
371 CREATE_INFERIOR_HOOK (0); /* No process-ID */
374 /* The "process" (board) is already stopped awaiting our commands, and
375 the program is already downloaded. We just set its PC and go. */
377 clear_proceed_status ();
379 /* Tell wait_for_inferior that we've started a new process. */
380 init_wait_for_inferior ();
382 /* Set up the "saved terminal modes" of the inferior
383 based on what modes we are starting it with. */
384 target_terminal_init ();
386 /* Install inferior's terminal modes. */
387 target_terminal_inferior ();
389 /* insert_step_breakpoint (); FIXME, do we need this? */
390 proceed ((CORE_ADDR) entry_pt, -1, 0); /* Let 'er rip... */
393 /* Open a connection to a remote debugger. NAME is the filename used
394 for communication. */
396 static int baudrate = 9600;
397 static char dev_name[100];
399 static char *machine = "";
400 static char *user = "";
401 static char *passwd = "";
402 static char *dir = "";
404 /* Grab the next token and buy some space for it */
415 while (*p && *p == ' ')
418 while (*p && (*p != ' ' && *p != '\t'))
431 e7000_login_command (args, from_tty)
437 machine = next (&args);
439 passwd = next (&args);
443 printf ("Set info to %s %s %s %s\n", machine, user, passwd, dir);
448 error ("Syntax is ftplogin <machine> <user> <passwd> <directory>");
452 /* Start an ftp transfer from the E7000 to a host */
455 e7000_ftp_command (args, from_tty)
459 /* FIXME: arbitrary limit on machine names and such. */
462 int oldtimeout = timeout;
465 sprintf (buf, "ftp %s\r", machine);
466 puts_e7000debug (buf);
467 expect (" Username : ");
468 sprintf (buf, "%s\r", user);
469 puts_e7000debug (buf);
470 expect (" Password : ");
471 write_e7000 (passwd);
473 expect ("success\r");
475 sprintf (buf, "cd %s\r", dir);
476 puts_e7000debug (buf);
478 sprintf (buf, "ll 0;s:%s\r", args);
479 puts_e7000debug (buf);
481 puts_e7000debug ("bye\r");
483 timeout = oldtimeout;
487 e7000_open (args, from_tty)
495 target_preopen (from_tty);
498 if (args && strcasecmp (args, "pc") == 0)
500 strcpy (dev_name, args);
506 n = sscanf (args, " %s %d %s", dev_name, &baudrate, junk);
509 if (n != 1 && n != 2)
511 error ("Bad arguments. Usage:\ttarget e7000 <device> <speed>\n\
512 or \t\ttarget e7000 <host>[:<port>]\n\
513 or \t\ttarget e7000 pc\n");
517 if (n == 1 && strchr (dev_name, ':') == 0)
519 /* Default to normal telnet port */
520 strcat (dev_name, ":23");
525 push_target (&e7000_ops);
527 e7000_desc = SERIAL_OPEN (dev_name);
530 perror_with_name (dev_name);
532 using_tcp = strcmp (e7000_desc->ops->name, "tcp") == 0;
533 using_pc = strcmp (e7000_desc->ops->name, "pc") == 0;
535 SERIAL_SETBAUDRATE (e7000_desc, baudrate);
536 SERIAL_RAW (e7000_desc);
538 /* Hello? Are you there? */
541 putchar_e7000 (CTRLC);
547 printf_unfiltered ("[waiting for e7000...]\n");
550 c = SERIAL_READCHAR (e7000_desc, 1);
551 while (c != SERIAL_TIMEOUT)
554 if (from_tty && c != '\r')
564 putchar_e7000 (CTRLC);
573 putchar_e7000 (CTRLC);
576 c = SERIAL_READCHAR (e7000_desc, 1);
579 puts_e7000debug ("\r");
584 printf_filtered ("Remote %s connected to %s\n", target_shortname,
587 #ifdef GDB_TARGET_IS_H8300
592 /* Close out all files and local state before this target loses control. */
595 e7000_close (quitting)
600 SERIAL_CLOSE (e7000_desc);
605 /* Terminate the open connection to the remote debugger. Use this
606 when you want to detach and do something else with your gdb. */
609 e7000_detach (from_tty)
612 pop_target (); /* calls e7000_close to do the real work */
614 printf ("Ending remote %s debugging\n", target_shortname);
617 /* Tell the remote machine to resume. */
620 e7000_resume (pid, step, sig)
624 puts_e7000debug ("S\r");
626 puts_e7000debug ("G\r");
629 /* Read the remote registers into the block REGS.
631 For the H8/300 a register dump looks like:
633 PC=00021A CCR=80:I*******
634 ER0 - ER3 0000000A 0000002E 0000002E 00000000
635 ER4 - ER7 00000000 00000000 00000000 00FFEFF6
641 #ifdef GDB_TARGET_IS_H8300
643 char *want = "PC=%p CCR=%c\n\
644 ER0 - ER3 %0 %1 %2 %3\n\
645 ER4 - ER7 %4 %5 %6 %7\n";
647 char *want_nopc = "%p CCR=%c\n\
648 ER0 - ER3 %0 %1 %2 %3\n\
649 ER4 - ER7 %4 %5 %6 %7";
653 #ifdef GDB_TARGET_IS_SH
655 char *want = "PC=%16 SR=%22\n\
656 PR=%17 GBR=%18 VBR=%19\n\
658 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
659 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n";
661 char *want_nopc = "%16 SR=%22\n\
662 PR=%17 GBR=%18 VBR=%19\n\
664 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
665 R8-15 %8 %9 %10 %11 %12 %13 %14 %15";
672 int c = readchar (timeout);
687 int high = convert_hex_digit (gch ());
688 int low = convert_hex_digit (gch ());
690 return (high << 4) + low;
694 fetch_regs_from_dump (nextchar, want)
699 char buf[MAX_REGISTER_RAW_SIZE];
701 int thischar = nextchar ();
708 /* Skip to end of line and then eat all new line type stuff */
709 while (thischar != '\n' && thischar != '\r')
710 thischar = nextchar ();
711 while (thischar == '\n' || thischar == '\r')
712 thischar = nextchar ();
717 while (thischar == ' '
721 thischar = nextchar ();
726 if (*want == thischar)
730 thischar = nextchar ();
733 else if (thischar == ' ' || thischar == '\n' || thischar == '\r')
735 thischar = nextchar ();
738 error ("out of sync in fetch registers wanted <%s>, got <%c 0x%x>",
739 want, thischar, thischar);
744 /* Got a register command */
774 if (isdigit (want[0]))
776 if (isdigit (want[1]))
778 regno = (want[0] - '0') * 10 + want[1] - '0';
783 regno = want[0] - '0';
791 store_signed_integer (buf,
792 REGISTER_RAW_SIZE(regno),
793 (LONGEST) get_hex (&thischar, nextchar));
794 supply_register (regno, buf);
801 e7000_fetch_registers ()
805 puts_e7000debug ("R\r");
806 fetch_regs_from_dump (gch, want);
808 /* And supply the extra ones the simulator uses */
809 for (regno = NUM_REALREGS; regno < NUM_REGS; regno++)
813 supply_register (regno, (char *) (&buf));
817 /* Fetch register REGNO, or all registers if REGNO is -1. Returns
821 e7000_fetch_register (regno)
824 e7000_fetch_registers ();
827 /* Store the remote registers from the contents of the block REGS. */
830 e7000_store_registers ()
834 for (regno = 0; regno < NUM_REALREGS; regno++)
835 e7000_store_register (regno);
837 registers_changed ();
840 /* Store register REGNO, or all if REGNO == 0. Return errno value. */
843 e7000_store_register (regno)
850 e7000_store_registers ();
854 #ifdef GDB_TARGET_IS_H8300
857 sprintf (buf, ".ER%d %x\r", regno, read_register (regno));
858 puts_e7000debug (buf);
860 else if (regno == PC_REGNUM)
862 sprintf (buf, ".PC %x\r", read_register (regno));
863 puts_e7000debug (buf);
865 else if (regno == CCR_REGNUM)
867 sprintf (buf, ".CCR %x\r", read_register (regno));
868 puts_e7000debug (buf);
870 #endif /* GDB_TARGET_IS_H8300 */
872 #ifdef GDB_TARGET_IS_SH
876 sprintf (buf, ".R%d %x\r", regno, read_register (regno));
877 puts_e7000debug (buf);
881 sprintf (buf, ".PC %x\r", read_register (regno));
882 puts_e7000debug (buf);
886 sprintf (buf, ".SR %x\r", read_register (regno));
887 puts_e7000debug (buf);
891 sprintf (buf, ".PR %x\r", read_register (regno));
892 puts_e7000debug (buf);
896 sprintf (buf, ".GBR %x\r", read_register (regno));
897 puts_e7000debug (buf);
901 sprintf (buf, ".VBR %x\r", read_register (regno));
902 puts_e7000debug (buf);
906 sprintf (buf, ".MACH %x\r", read_register (regno));
907 puts_e7000debug (buf);
911 sprintf (buf, ".MACL %x\r", read_register (regno));
912 puts_e7000debug (buf);
916 #endif /* GDB_TARGET_IS_SH */
921 /* Get ready to modify the registers array. On machines which store
922 individual registers, this doesn't need to do anything. On machines
923 which store all the registers in one fell swoop, this makes sure
924 that registers contains all the registers from the program being
928 e7000_prepare_to_store ()
930 /* Do nothing, since we can store individual regs */
936 printf ("\tAttached to %s at %d baud.\n", dev_name, baudrate);
940 stickbyte (where, what)
944 static CONST char digs[] = "0123456789ABCDEF";
946 where[0] = digs[(what >> 4) & 0xf];
947 where[1] = digs[(what & 0xf) & 0xf];
952 /* Write a small ammount of memory. */
955 write_small (memaddr, myaddr, len)
957 unsigned char *myaddr;
963 for (i = 0; i < len; i++)
965 if (((memaddr + i) & 3) == 0 && (i + 3 < len))
967 /* Can be done with a long word */
968 sprintf (buf, "m %x %x%02x%02x%02x;l\r",
970 myaddr[i], myaddr[i + 1], myaddr[i + 2], myaddr[i + 3]);
971 puts_e7000debug (buf);
976 sprintf (buf, "m %x %x\r", memaddr + i, myaddr[i]);
977 puts_e7000debug (buf);
986 /* Write a large ammount of memory, this only works with the serial
987 mode enabled. Command is sent as
1002 write_large (memaddr, myaddr, len)
1004 unsigned char *myaddr;
1008 #define maxstride 128
1011 puts_e7000debug ("IL ;S:FK\r");
1013 putchar_e7000 (ACK);
1016 for (i = 0; i < len; i += stride)
1018 char compose[maxstride * 2 + 50];
1019 int address = i + memaddr;
1026 if (stride > maxstride)
1029 compose[where++] = 'S';
1031 if (address >= 0xffffff)
1033 else if (address >= 0xffff)
1038 compose[where++] = alen - 1 + '0';
1039 /* Insert length. */
1040 check_sum += stickbyte (compose + where, alen + stride + 1);
1045 check_sum += stickbyte (compose + where, address >> (8 * (alen)));
1049 for (j = 0; j < stride; j++)
1051 check_sum += stickbyte (compose + where, myaddr[i + j]);
1054 stickbyte (compose + where, ~check_sum);
1056 compose[where++] = '\r';
1057 compose[where++] = '\n';
1058 compose[where++] = 0;
1060 SERIAL_WRITE (e7000_desc, compose, where);
1061 j = SERIAL_READCHAR (e7000_desc, 0);
1062 if (j == SERIAL_TIMEOUT)
1064 /* This is ok - nothing there */
1068 /* Hmm, it's trying to tell us something */
1070 error ("Error writing memory");
1074 printf ("@%d}@", j);
1075 while ((j = SERIAL_READCHAR(e7000_desc,0)) > 0)
1077 printf ("@{%d}@",j);
1082 /* Send the trailer record */
1083 write_e7000 ("S70500000000FA\r");
1084 putchar_e7000 (CTRLZ);
1086 putchar_e7000 (ACK);
1092 /* Copy LEN bytes of data from debugger memory at MYADDR to inferior's
1093 memory at MEMADDR. Returns length moved.
1095 Can't use the Srecord load over ethernet, so don't use fast method
1099 e7000_write_inferior_memory (memaddr, myaddr, len)
1101 unsigned char *myaddr;
1104 if (len < 16 || using_tcp || using_pc)
1105 return write_small (memaddr, myaddr, len);
1107 return write_large (memaddr, myaddr, len);
1110 /* Read LEN bytes from inferior memory at MEMADDR. Put the result
1111 at debugger address MYADDR. Returns length moved.
1113 Small transactions we send
1120 e7000_read_inferior_memory (memaddr, myaddr, len)
1122 unsigned char *myaddr;
1129 /* Starting address of this pass. */
1131 /* printf("READ INF %x %x %d\n", memaddr, myaddr, len);*/
1132 if (((memaddr - 1) + len) < memaddr)
1138 sprintf (buf, "m %x;l\r", memaddr);
1139 puts_e7000debug (buf);
1141 for (count = 0; count < len; count += 4)
1143 /* Suck away the address */
1149 { /* Some kind of error */
1156 /* Now read in the data */
1157 for (i = 0; i < 4; i++)
1160 if (count + i < len) {
1161 myaddr[count + i] = b;
1165 /* Skip the trailing ? and send a . to end and a cr for more */
1168 if (count + 4 >= len)
1169 puts_e7000debug(".\r");
1171 puts_e7000debug("\r");
1181 For large transfers we used to send
1184 d <addr> <endaddr>\r
1187 <ADDR> < D A T A > < ASCII CODE >
1188 000000 5F FD FD FF DF 7F DF FF 01 00 01 00 02 00 08 04 "_..............."
1189 000010 FF D7 FF 7F D7 F1 7F FF 00 05 00 00 08 00 40 00 "..............@."
1190 000020 7F FD FF F7 7F FF FF F7 00 00 00 00 00 00 00 00 "................"
1192 A cost in chars for each transaction of 80 + 5*n-bytes.
1194 Large transactions could be done with the srecord load code, but
1195 there is a pause for a second before dumping starts, which slows the
1200 e7000_read_inferior_memory (memaddr, myaddr, len)
1202 unsigned char *myaddr;
1209 /* Starting address of this pass. */
1211 if (((memaddr - 1) + len) < memaddr)
1217 sprintf (buf, "d %x %x\r", memaddr, memaddr + len - 1);
1218 puts_e7000debug (buf);
1223 /* First skip the command */
1235 /* Skip the title line */
1241 /* Skip the address */
1247 /* read in the bytes on the line */
1248 while (c != '"' && count < len)
1254 myaddr[count++] = get_hex (&c);
1269 fast_but_for_the_pause_e7000_read_inferior_memory (memaddr, myaddr, len)
1278 if (((memaddr - 1) + len) < memaddr)
1284 sprintf (buf, "is %x@%x:s\r", memaddr, len);
1285 puts_e7000debug (buf);
1291 error ("Memory read error");
1293 putchar_e7000 (ACK);
1306 case ENQ: /* ENQ, at the end */
1310 /* Start of an Srecord */
1315 case '7': /* Termination record, ignore */
1319 /* Header record - ignore it */
1331 alen = type - '0' + 1;
1335 addr = (addr << 8) + gbyte ();
1339 for (i = 0; i < length - 1; i++)
1340 myaddr[i + addr - memaddr] = gbyte ();
1342 gbyte (); /* Ignore checksum */
1348 putchar_e7000 (ACK);
1349 expect ("TOP ADDRESS =");
1350 expect ("END ADDRESS =");
1359 e7000_xfer_inferior_memory (memaddr, myaddr, len, write, target)
1361 unsigned char *myaddr;
1364 struct target_ops *target; /* ignored */
1367 return e7000_write_inferior_memory( memaddr, myaddr, len);
1369 return e7000_read_inferior_memory( memaddr, myaddr, len);
1373 e7000_kill (args, from_tty)
1379 /* Clean up when a program exits.
1381 The program actually lives on in the remote processor's RAM, and may be
1382 run again without a download. Don't leave it full of breakpoint
1386 e7000_mourn_inferior ()
1388 remove_breakpoints ();
1389 unpush_target (&e7000_ops);
1390 generic_mourn_inferior (); /* Do all the proper things now */
1393 #ifdef HARD_BREAKPOINTS
1394 #define MAX_E7000DEBUG_BREAKPOINTS (BC_BREAKPOINTS ? 5 : 200)
1396 #define MAX_E7000DEBUG_BREAKPOINTS 200
1399 extern int memory_breakpoint_size;
1401 static CORE_ADDR breakaddr[MAX_E7000DEBUG_BREAKPOINTS] = {0};
1404 e7000_insert_breakpoint (addr, shadow)
1406 unsigned char *shadow;
1410 static char nop[2] = NOP;
1412 for (i = 0; i <= MAX_E7000DEBUG_BREAKPOINTS; i++)
1413 if (breakaddr[i] == 0)
1415 breakaddr[i] = addr;
1416 /* Save old contents, and insert a nop in the space */
1417 #ifdef HARD_BREAKPOINTS
1420 sprintf (buf, "BC%d A=%x\r", i+1, addr);
1421 puts_e7000debug (buf);
1425 sprintf (buf, "B %x\r", addr);
1426 puts_e7000debug (buf);
1429 e7000_read_inferior_memory (addr, shadow, 2);
1430 e7000_write_inferior_memory (addr, nop, 2);
1432 sprintf (buf, "B %x\r", addr);
1433 puts_e7000debug (buf);
1439 error ("Too many breakpoints ( > %d) for the E7000\n",
1440 MAX_E7000DEBUG_BREAKPOINTS);
1445 e7000_remove_breakpoint (addr, shadow)
1447 unsigned char *shadow;
1452 for (i = 0; i < MAX_E7000DEBUG_BREAKPOINTS; i++)
1453 if (breakaddr[i] == addr)
1456 #ifdef HARD_BREAKPOINTS
1459 sprintf (buf, "BC%d - \r", i+1);
1460 puts_e7000debug (buf);
1464 sprintf (buf, "B - %x\r", addr);
1465 puts_e7000debug (buf);
1469 sprintf (buf, "B - %x\r", addr);
1470 puts_e7000debug (buf);
1473 /* Replace the insn under the break */
1474 e7000_write_inferior_memory (addr, shadow, 2);
1480 warning ("Can't find breakpoint associated with 0x%x\n", addr);
1484 /* Put a command string, in args, out to STDBUG. Output from STDBUG
1485 is placed on the users terminal until the prompt is seen. */
1488 e7000_command (args, fromtty)
1492 /* FIXME: arbitrary limit on length of args. */
1498 error ("e7000 target not open.");
1501 puts_e7000debug ("\r");
1505 sprintf (buf, "%s\r", args);
1506 puts_e7000debug (buf);
1511 expect_full_prompt ();
1514 printf_unfiltered ("\n");
1516 /* Who knows what the command did... */
1517 registers_changed ();
1521 e7000_load (args, fromtty)
1525 gr_load_image (args, fromtty);
1529 e7000_drain_command (args, fromtty)
1536 puts_e7000debug("end\r");
1537 putchar_e7000 (CTRLC);
1539 while ((c = SERIAL_READCHAR (e7000_desc, 1) != SERIAL_TIMEOUT))
1543 putchar_e7000(CTRLC);
1546 if (c > ' ' && c < 127)
1547 printf ("%c", c & 0xff);
1549 printf ("<%x>", c & 0xff);
1558 static char *strings[NITEMS] = {
1564 "ILLEGAL INSTRUCTION",
1571 for (i = 0; i < NITEMS; ++i)
1577 for (i = 0; i < NITEMS; i++)
1584 /* found one of the choices */
1596 /* Suck characters, if a string match, then return the strings index
1597 otherwise echo them. */
1607 char *buffer = saveaway;
1608 /* Count number of expect strings */
1610 for (n = 0; strings[n]; n++)
1612 ptr[n] = strings[n];
1620 c = SERIAL_READCHAR (e7000_desc, 1);
1621 if (c == SERIAL_TIMEOUT)
1623 printf_unfiltered ("[waiting for e7000...]\n");
1636 putchar_e7000 (CTRLC); /* interrupt the running program */
1640 for (i = 0; i < n; i++)
1647 /* Gone all the way */
1654 ptr[i] = strings[i];
1660 /* Save it up incase we find that there was no match */
1665 if (buffer != saveaway)
1668 printf ("%s", buffer);
1671 if (c != SERIAL_TIMEOUT)
1680 /* We subtract two from the pc here rather than use
1681 DECR_PC_AFTER_BREAK since the e7000 doesn't always add two to the
1682 pc, and the simulators never do. */
1690 store_signed_integer (buf,
1691 REGISTER_RAW_SIZE(PC_REGNUM),
1692 read_register (PC_REGNUM) -2);
1693 supply_register (PC_REGNUM, buf);
1694 sprintf (buf2, ".PC %x\r", read_register (PC_REGNUM));
1695 puts_e7000debug (buf2);
1700 #define WAS_RUNNING 2
1703 static char *estrings[] = {
1711 /* Wait until the remote machine stops, then return, storing status in
1712 STATUS just as `wait' would. */
1715 e7000_wait (pid, status)
1717 struct target_waitstatus *status;
1721 int running_count = 0;
1725 /* Then echo chars until PC= string seen */
1726 gch (); /* Drop cr */
1727 gch (); /* and space */
1731 switch (expect_n (estrings))
1734 /* how did this happen ? */
1739 putchar_e7000 (CTRLC);
1747 if (running_count == 20)
1749 printf_unfiltered ("[running...]\n");
1759 /* Skip till the PC= */
1761 fetch_regs_from_dump (gch, want_nopc);
1763 /* And supply the extra ones the simulator uses */
1764 for (regno = NUM_REALREGS; regno < NUM_REGS; regno++)
1767 supply_register (regno, (char *) &buf);
1770 stop_reason = why_stop ();
1771 expect_full_prompt ();
1773 status->kind = TARGET_WAITKIND_STOPPED;
1774 status->value.sig = TARGET_SIGNAL_TRAP;
1776 switch (stop_reason)
1778 case 1: /* Breakpoint */
1779 status->value.sig = TARGET_SIGNAL_TRAP;
1781 case 0: /* Single step */
1782 status->value.sig = TARGET_SIGNAL_TRAP;
1784 case 2: /* Interrupt */
1787 status->value.sig = TARGET_SIGNAL_TRAP;
1792 status->value.sig = TARGET_SIGNAL_INT;
1798 printf_unfiltered ("a cycle address error?\n");
1799 status->value.sig = TARGET_SIGNAL_UNKNOWN;
1802 status->value.sig = TARGET_SIGNAL_ILL;
1805 status->value.sig = TARGET_SIGNAL_SEGV;
1807 case 7: /* Anything else (NITEMS + 1) */
1808 printf_unfiltered ("a write protect error?\n");
1809 status->value.sig = TARGET_SIGNAL_UNKNOWN;
1812 /* Get the user's attention - this should never happen. */
1819 /* Define the target subroutine names. */
1821 struct target_ops e7000_ops =
1824 "Remote Hitachi e7000 target",
1825 "Use a remote Hitachi e7000 ICE connected by a serial line,\n\
1826 or a network connection.\n\
1827 Arguments are the name of the device for the serial line,\n\
1828 the speed to connect at in bits per second.\n\
1830 target e7000 /dev/ttya 9600\n\
1831 target e7000 foobar",
1832 e7000_open, /* to_open */
1833 e7000_close, /* to_close */
1835 e7000_detach, /* to_detach */
1836 e7000_resume, /* to_resume */
1837 e7000_wait, /* to_wait */
1838 e7000_fetch_register, /* to_fetch_registers */
1839 e7000_store_register, /* to_store_registers */
1840 e7000_prepare_to_store, /* to_prepare_to_store */
1841 e7000_xfer_inferior_memory, /* to_xfer_memory */
1842 e7000_files_info, /* to_files_info */
1843 #ifdef HARD_BREAKPOINTS
1844 e7000_insert_breakpoint, /* to_insert_breakpoint */
1845 e7000_remove_breakpoint, /* to_remove_breakpoint */
1847 memory_insert_breakpoint, /* to_insert_breakpoint */
1848 memory_remove_breakpoint, /* to_remove_breakpoint */
1850 0, /* to_terminal_init */
1851 0, /* to_terminal_inferior */
1852 0, /* to_terminal_ours_for_output */
1853 0, /* to_terminal_ours */
1854 0, /* to_terminal_info */
1855 e7000_kill, /* to_kill */
1856 e7000_load, /* to_load */
1857 0, /* to_lookup_symbol */
1858 e7000_create_inferior, /* to_create_inferior */
1859 e7000_mourn_inferior, /* to_mourn_inferior */
1861 0, /* to_notice_signals */
1862 0, /* to_thread_alive */
1864 process_stratum, /* to_stratum */
1865 0, /* next (unused) */
1866 1, /* to_has_all_memory */
1867 1, /* to_has_memory */
1868 1, /* to_has_stack */
1869 1, /* to_has_registers */
1870 1, /* to_has_execution */
1871 0, /* to_sections */
1872 0, /* to_sections_end */
1873 OPS_MAGIC, /* Always the last thing */
1877 _initialize_remote_e7000 ()
1879 add_target (&e7000_ops);
1881 add_com ("e7000 <command>", class_obscure, e7000_command,
1882 "Send a command to the e7000 monitor.");
1884 add_com ("ftplogin <machine> <name> <passwd> <dir>", class_obscure, e7000_login_command,
1885 "Login to machine and change to directory.");
1887 add_com ("ftpload <file>", class_obscure, e7000_ftp_command,
1888 "Fetch and load a file from previously described place.");
1890 add_com ("drain", class_obscure, e7000_drain_command,
1891 "Drain pending e7000 text buffers.");