1 /* Remote debugging interface for Hitachi E7000 ICE, for GDB
2 Copyright 1993, 1994, 1996 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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"
50 #define HARD_BREAKPOINTS
51 #define BC_BREAKPOINTS 0
59 extern void notice_quit PARAMS ((void));
61 extern void report_transfer_performance PARAMS ((unsigned long,
64 extern char *sh_processor_type;
66 /* Local function declarations. */
68 static void e7000_close PARAMS ((int));
70 static void e7000_fetch_register PARAMS ((int));
72 static void e7000_store_register PARAMS ((int));
74 static void e7000_command PARAMS ((char *, int));
76 static void e7000_login_command PARAMS ((char *, int));
78 static void e7000_ftp_command PARAMS ((char *, int));
80 static void e7000_drain_command PARAMS ((char *, int));
82 static void expect PARAMS ((char *));
84 static void expect_full_prompt PARAMS ((void));
86 static void expect_prompt PARAMS ((void));
90 static serial_t e7000_desc;
92 /* Nonzero if using the tcp serial driver. */
96 /* Nonzero if using the pc isa card. */
100 extern struct target_ops e7000_ops; /* Forward declaration */
102 char *ENQSTRING = "\005";
104 /* Nonzero if some routine (as opposed to the user) wants echoing.
105 FIXME: Do this reentrantly with an extra parameter. */
111 static int timeout = 5;
113 /* Send data to e7000debug. */
116 puts_e7000debug (buf)
120 error ("Use \"target e7000 ...\" first.");
123 printf("Sending %s\n", buf);
125 if (SERIAL_WRITE (e7000_desc, buf, strlen (buf)))
126 fprintf (stderr, "SERIAL_WRITE failed: %s\n", safe_strerror (errno));
128 /* And expect to see it echoed, unless using the pc interface */
142 SERIAL_WRITE (e7000_desc, b, 1);
149 SERIAL_WRITE (e7000_desc, s, strlen (s));
161 /* Read a character from the remote system, doing all the fancy timeout
172 c = SERIAL_READCHAR (e7000_desc, timeout);
176 if (c == SERIAL_TIMEOUT)
181 error ("Timeout reading from remote system.");
196 static char b[8][10];
208 sprintf(b[p], "<%d>", x);
215 /* Scan input from the remote system, until STRING is found. If
216 DISCARD is non-zero, then discard non-matching input, else print it
217 out. Let the user break out immediately. */
229 c = readchar (timeout);
235 putchar_e7000(CTRLC);
244 if (c == SERIAL_ERROR)
246 error ("Serial communication error");
248 if (echo || remote_debug)
250 if (c == '\r' || c == '\n')
263 if (normal (c) == normal (*p++))
272 if (normal (c) == normal (string[0]))
278 /* Keep discarding input until we see the e7000 prompt.
280 The convention for dealing with the prompt is that you
282 o *then* wait for the prompt.
284 Thus the last thing that a procedure does with the serial line will
285 be an expect_prompt(). Exception: e7000_resume does not wait for
286 the prompt, because the terminal is being handed over to the
287 inferior. However, the next thing which happens after that is a
288 e7000_wait which does wait for the prompt. Note that this includes
289 abnormal exit, e.g. error(). This is necessary to prevent getting
290 into states from which we can't recover. */
299 expect_full_prompt ()
305 convert_hex_digit (ch)
308 if (ch >= '0' && ch <= '9')
310 else if (ch >= 'A' && ch <= 'F')
311 return ch - 'A' + 10;
312 else if (ch >= 'a' && ch <= 'f')
313 return ch - 'a' + 10;
321 int value = convert_hex_digit (*start);
324 *start = readchar (timeout);
325 while ((try = convert_hex_digit (*start)) >= 0)
329 *start = readchar (timeout);
335 /* Get N 32-bit words from remote, each preceded by a space, and put
336 them in registers starting at REGNO. */
339 get_hex_regs (n, regno)
346 for (i = 0; i < n; i++)
351 for (j = 0; j < 8; j++)
352 val = (val << 4) + get_hex_digit (j == 0);
353 supply_register (regno++, (char *) &val);
358 /* This is called not only when we first attach, but also when the
359 user types "run" after having attached. */
362 e7000_create_inferior (execfile, args, env)
370 error ("Can't pass arguments to remote E7000DEBUG process");
372 if (execfile == 0 || exec_bfd == 0)
373 error ("No exec file specified");
375 entry_pt = (int) bfd_get_start_address (exec_bfd);
377 #ifdef CREATE_INFERIOR_HOOK
378 CREATE_INFERIOR_HOOK (0); /* No process-ID */
381 /* The "process" (board) is already stopped awaiting our commands, and
382 the program is already downloaded. We just set its PC and go. */
384 clear_proceed_status ();
386 /* Tell wait_for_inferior that we've started a new process. */
387 init_wait_for_inferior ();
389 /* Set up the "saved terminal modes" of the inferior
390 based on what modes we are starting it with. */
391 target_terminal_init ();
393 /* Install inferior's terminal modes. */
394 target_terminal_inferior ();
396 /* insert_step_breakpoint (); FIXME, do we need this? */
397 proceed ((CORE_ADDR) entry_pt, -1, 0); /* Let 'er rip... */
400 /* Open a connection to a remote debugger. NAME is the filename used
401 for communication. */
403 static int baudrate = 9600;
404 static char dev_name[100];
406 static char *machine = "";
407 static char *user = "";
408 static char *passwd = "";
409 static char *dir = "";
411 /* Grab the next token and buy some space for it */
422 while (*p && *p == ' ')
425 while (*p && (*p != ' ' && *p != '\t'))
438 e7000_login_command (args, from_tty)
444 machine = next (&args);
446 passwd = next (&args);
450 printf ("Set info to %s %s %s %s\n", machine, user, passwd, dir);
455 error ("Syntax is ftplogin <machine> <user> <passwd> <directory>");
459 /* Start an ftp transfer from the E7000 to a host */
462 e7000_ftp_command (args, from_tty)
466 /* FIXME: arbitrary limit on machine names and such. */
469 int oldtimeout = timeout;
472 sprintf (buf, "ftp %s\r", machine);
473 puts_e7000debug (buf);
474 expect (" Username : ");
475 sprintf (buf, "%s\r", user);
476 puts_e7000debug (buf);
477 expect (" Password : ");
478 write_e7000 (passwd);
480 expect ("success\r");
482 sprintf (buf, "cd %s\r", dir);
483 puts_e7000debug (buf);
485 sprintf (buf, "ll 0;s:%s\r", args);
486 puts_e7000debug (buf);
488 puts_e7000debug ("bye\r");
490 timeout = oldtimeout;
494 e7000_open (args, from_tty)
502 target_preopen (from_tty);
505 if (args && strcasecmp (args, "pc") == 0)
507 strcpy (dev_name, args);
513 n = sscanf (args, " %s %d %s", dev_name, &baudrate, junk);
516 if (n != 1 && n != 2)
518 error ("Bad arguments. Usage:\ttarget e7000 <device> <speed>\n\
519 or \t\ttarget e7000 <host>[:<port>]\n\
520 or \t\ttarget e7000 pc\n");
523 #if !defined(__GO32__) && !defined(__WIN32__)
524 if (n == 1 && strchr (dev_name, ':') == 0)
526 /* Default to normal telnet port */
527 strcat (dev_name, ":23");
532 push_target (&e7000_ops);
534 e7000_desc = SERIAL_OPEN (dev_name);
537 perror_with_name (dev_name);
539 using_tcp = strcmp (e7000_desc->ops->name, "tcp") == 0;
540 using_pc = strcmp (e7000_desc->ops->name, "pc") == 0;
542 SERIAL_SETBAUDRATE (e7000_desc, baudrate);
543 SERIAL_RAW (e7000_desc);
545 /* Hello? Are you there? */
548 putchar_e7000 (CTRLC);
554 printf_unfiltered ("[waiting for e7000...]\n");
557 c = SERIAL_READCHAR (e7000_desc, 1);
558 while (c != SERIAL_TIMEOUT)
561 if (from_tty && c != '\r')
571 putchar_e7000 (CTRLC);
580 putchar_e7000 (CTRLC);
583 c = SERIAL_READCHAR (e7000_desc, 1);
586 puts_e7000debug ("\r");
590 puts_e7000debug ("b -\r");
595 printf_filtered ("Remote target %s connected to %s\n", target_shortname,
598 #ifdef GDB_TARGET_IS_H8300
603 /* Close out all files and local state before this target loses control. */
606 e7000_close (quitting)
611 SERIAL_CLOSE (e7000_desc);
616 /* Terminate the open connection to the remote debugger. Use this
617 when you want to detach and do something else with your gdb. */
620 e7000_detach (from_tty)
623 pop_target (); /* calls e7000_close to do the real work */
625 printf ("Ending remote %s debugging\n", target_shortname);
628 /* Tell the remote machine to resume. */
631 e7000_resume (pid, step, sig)
635 puts_e7000debug ("S\r");
637 puts_e7000debug ("G\r");
640 /* Read the remote registers into the block REGS.
642 For the H8/300 a register dump looks like:
644 PC=00021A CCR=80:I*******
645 ER0 - ER3 0000000A 0000002E 0000002E 00000000
646 ER4 - ER7 00000000 00000000 00000000 00FFEFF6
652 #ifdef GDB_TARGET_IS_H8300
654 char *want = "PC=%p CCR=%c\n\
655 ER0 - ER3 %0 %1 %2 %3\n\
656 ER4 - ER7 %4 %5 %6 %7\n";
658 char *want_nopc = "%p CCR=%c\n\
659 ER0 - ER3 %0 %1 %2 %3\n\
660 ER4 - ER7 %4 %5 %6 %7";
664 #ifdef GDB_TARGET_IS_SH
666 char *want = "PC=%16 SR=%22\n\
667 PR=%17 GBR=%18 VBR=%19\n\
669 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
670 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n";
672 char *want_nopc = "%16 SR=%22\n\
673 PR=%17 GBR=%18 VBR=%19\n\
675 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
676 R8-15 %8 %9 %10 %11 %12 %13 %14 %15";
678 char *want_sh3 = "PC=%16 SR=%22\n\
679 PR=%17 GBR=%18 VBR=%19\n\
680 MACH=%20 MACL=%21 SSR=%23 SPC=%24\n\
681 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
682 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
683 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
684 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
685 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
686 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
688 char *want_sh3_nopc = "%16 SR=%22\n\
689 PR=%17 GBR=%18 VBR=%19\n\
690 MACH=%20 MACL=%21 SSR=%22 SPC=%23\n\
691 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
692 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
693 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
694 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
695 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
696 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
703 int c = readchar (timeout);
718 int high = convert_hex_digit (gch ());
719 int low = convert_hex_digit (gch ());
721 return (high << 4) + low;
725 fetch_regs_from_dump (nextchar, want)
730 char buf[MAX_REGISTER_RAW_SIZE];
732 int thischar = nextchar ();
739 /* Skip to end of line and then eat all new line type stuff */
740 while (thischar != '\n' && thischar != '\r')
741 thischar = nextchar ();
742 while (thischar == '\n' || thischar == '\r')
743 thischar = nextchar ();
748 while (thischar == ' '
752 thischar = nextchar ();
757 if (*want == thischar)
761 thischar = nextchar ();
764 else if (thischar == ' ' || thischar == '\n' || thischar == '\r')
766 thischar = nextchar ();
769 error ("out of sync in fetch registers wanted <%s>, got <%c 0x%x>",
770 want, thischar, thischar);
775 /* Got a register command */
805 if (isdigit (want[0]))
807 if (isdigit (want[1]))
809 regno = (want[0] - '0') * 10 + want[1] - '0';
814 regno = want[0] - '0';
822 store_signed_integer (buf,
823 REGISTER_RAW_SIZE(regno),
824 (LONGEST) get_hex (&thischar, nextchar));
825 supply_register (regno, buf);
832 e7000_fetch_registers ()
836 puts_e7000debug ("R\r");
838 #ifdef GDB_TARGET_IS_SH
839 if ((sh_processor_type != NULL) && (*(sh_processor_type+2) == '3'))
840 fetch_regs_from_dump (gch, want_sh3);
842 fetch_regs_from_dump (gch, want);
844 fetch_regs_from_dump (gch, want);
848 /* And supply the extra ones the simulator uses */
849 for (regno = NUM_REALREGS; regno < NUM_REGS; regno++)
853 supply_register (regno, (char *) (&buf));
857 /* Fetch register REGNO, or all registers if REGNO is -1. Returns
861 e7000_fetch_register (regno)
864 e7000_fetch_registers ();
867 /* Store the remote registers from the contents of the block REGS. */
870 e7000_store_registers ()
874 for (regno = 0; regno < NUM_REALREGS; regno++)
875 e7000_store_register (regno);
877 registers_changed ();
880 /* Store register REGNO, or all if REGNO == 0. Return errno value. */
883 e7000_store_register (regno)
890 e7000_store_registers ();
894 #ifdef GDB_TARGET_IS_H8300
897 sprintf (buf, ".ER%d %x\r", regno, read_register (regno));
898 puts_e7000debug (buf);
900 else if (regno == PC_REGNUM)
902 sprintf (buf, ".PC %x\r", read_register (regno));
903 puts_e7000debug (buf);
905 else if (regno == CCR_REGNUM)
907 sprintf (buf, ".CCR %x\r", read_register (regno));
908 puts_e7000debug (buf);
910 #endif /* GDB_TARGET_IS_H8300 */
912 #ifdef GDB_TARGET_IS_SH
916 sprintf (buf, ".R%d %x\r", regno, read_register (regno));
917 puts_e7000debug (buf);
921 sprintf (buf, ".PC %x\r", read_register (regno));
922 puts_e7000debug (buf);
926 sprintf (buf, ".SR %x\r", read_register (regno));
927 puts_e7000debug (buf);
931 sprintf (buf, ".PR %x\r", read_register (regno));
932 puts_e7000debug (buf);
936 sprintf (buf, ".GBR %x\r", read_register (regno));
937 puts_e7000debug (buf);
941 sprintf (buf, ".VBR %x\r", read_register (regno));
942 puts_e7000debug (buf);
946 sprintf (buf, ".MACH %x\r", read_register (regno));
947 puts_e7000debug (buf);
951 sprintf (buf, ".MACL %x\r", read_register (regno));
952 puts_e7000debug (buf);
956 #endif /* GDB_TARGET_IS_SH */
961 /* Get ready to modify the registers array. On machines which store
962 individual registers, this doesn't need to do anything. On machines
963 which store all the registers in one fell swoop, this makes sure
964 that registers contains all the registers from the program being
968 e7000_prepare_to_store ()
970 /* Do nothing, since we can store individual regs */
976 printf ("\tAttached to %s at %d baud.\n", dev_name, baudrate);
980 stickbyte (where, what)
984 static CONST char digs[] = "0123456789ABCDEF";
986 where[0] = digs[(what >> 4) & 0xf];
987 where[1] = digs[(what & 0xf) & 0xf];
992 /* Write a small ammount of memory. */
995 write_small (memaddr, myaddr, len)
997 unsigned char *myaddr;
1003 for (i = 0; i < len; i++)
1005 if (((memaddr + i) & 3) == 0 && (i + 3 < len))
1007 /* Can be done with a long word */
1008 sprintf (buf, "m %x %x%02x%02x%02x;l\r",
1010 myaddr[i], myaddr[i + 1], myaddr[i + 2], myaddr[i + 3]);
1011 puts_e7000debug (buf);
1016 sprintf (buf, "m %x %x\r", memaddr + i, myaddr[i]);
1017 puts_e7000debug (buf);
1026 /* Write a large ammount of memory, this only works with the serial
1027 mode enabled. Command is sent as
1042 write_large (memaddr, myaddr, len)
1044 unsigned char *myaddr;
1048 #define maxstride 128
1051 puts_e7000debug ("IL ;S:FK\r");
1053 putchar_e7000 (ACK);
1056 for (i = 0; i < len; i += stride)
1058 char compose[maxstride * 2 + 50];
1059 int address = i + memaddr;
1066 if (stride > maxstride)
1069 compose[where++] = 'S';
1071 if (address >= 0xffffff)
1073 else if (address >= 0xffff)
1078 compose[where++] = alen - 1 + '0';
1079 /* Insert length. */
1080 check_sum += stickbyte (compose + where, alen + stride + 1);
1085 check_sum += stickbyte (compose + where, address >> (8 * (alen)));
1089 for (j = 0; j < stride; j++)
1091 check_sum += stickbyte (compose + where, myaddr[i + j]);
1094 stickbyte (compose + where, ~check_sum);
1096 compose[where++] = '\r';
1097 compose[where++] = '\n';
1098 compose[where++] = 0;
1100 SERIAL_WRITE (e7000_desc, compose, where);
1101 j = SERIAL_READCHAR (e7000_desc, 0);
1102 if (j == SERIAL_TIMEOUT)
1104 /* This is ok - nothing there */
1108 /* Hmm, it's trying to tell us something */
1110 error ("Error writing memory");
1114 printf ("@%d}@", j);
1115 while ((j = SERIAL_READCHAR(e7000_desc,0)) > 0)
1117 printf ("@{%d}@",j);
1122 /* Send the trailer record */
1123 write_e7000 ("S70500000000FA\r");
1124 putchar_e7000 (CTRLZ);
1126 putchar_e7000 (ACK);
1132 /* Copy LEN bytes of data from debugger memory at MYADDR to inferior's
1133 memory at MEMADDR. Returns length moved.
1135 Can't use the Srecord load over ethernet, so don't use fast method
1139 e7000_write_inferior_memory (memaddr, myaddr, len)
1141 unsigned char *myaddr;
1144 if (len < 16 || using_tcp || using_pc)
1145 return write_small (memaddr, myaddr, len);
1147 return write_large (memaddr, myaddr, len);
1150 /* Read LEN bytes from inferior memory at MEMADDR. Put the result
1151 at debugger address MYADDR. Returns length moved.
1153 Small transactions we send
1160 e7000_read_inferior_memory (memaddr, myaddr, len)
1162 unsigned char *myaddr;
1169 /* Starting address of this pass. */
1171 /* printf("READ INF %x %x %d\n", memaddr, myaddr, len);*/
1172 if (((memaddr - 1) + len) < memaddr)
1178 sprintf (buf, "m %x;l\r", memaddr);
1179 puts_e7000debug (buf);
1181 for (count = 0; count < len; count += 4)
1183 /* Suck away the address */
1189 { /* Some kind of error */
1196 /* Now read in the data */
1197 for (i = 0; i < 4; i++)
1200 if (count + i < len) {
1201 myaddr[count + i] = b;
1205 /* Skip the trailing ? and send a . to end and a cr for more */
1208 if (count + 4 >= len)
1209 puts_e7000debug(".\r");
1211 puts_e7000debug("\r");
1221 For large transfers we used to send
1224 d <addr> <endaddr>\r
1227 <ADDRESS> < D A T A > < ASCII CODE >
1228 00000000 5F FD FD FF DF 7F DF FF 01 00 01 00 02 00 08 04 "_..............."
1229 00000010 FF D7 FF 7F D7 F1 7F FF 00 05 00 00 08 00 40 00 "..............@."
1230 00000020 7F FD FF F7 7F FF FF F7 00 00 00 00 00 00 00 00 "................"
1232 A cost in chars for each transaction of 80 + 5*n-bytes.
1234 Large transactions could be done with the srecord load code, but
1235 there is a pause for a second before dumping starts, which slows the
1240 e7000_read_inferior_memory_large (memaddr, myaddr, len)
1242 unsigned char *myaddr;
1249 /* Starting address of this pass. */
1251 if (((memaddr - 1) + len) < memaddr)
1257 sprintf (buf, "d %x %x\r", memaddr, memaddr + len - 1);
1258 puts_e7000debug (buf);
1263 /* skip down to the first ">" */
1266 /* now skip to the end of that line */
1273 /* get rid of any white space before the address */
1277 /* Skip the address */
1280 /* read in the bytes on the line */
1281 while (c != '"' && count < len)
1287 myaddr[count++] = get_hex (&c);
1290 /* throw out the rest of the line */
1295 /* wait for the ":" prompt */
1305 fast_but_for_the_pause_e7000_read_inferior_memory (memaddr, myaddr, len)
1314 if (((memaddr - 1) + len) < memaddr)
1320 sprintf (buf, "is %x@%x:s\r", memaddr, len);
1321 puts_e7000debug (buf);
1327 error ("Memory read error");
1329 putchar_e7000 (ACK);
1342 case ENQ: /* ENQ, at the end */
1346 /* Start of an Srecord */
1351 case '7': /* Termination record, ignore */
1355 /* Header record - ignore it */
1367 alen = type - '0' + 1;
1371 addr = (addr << 8) + gbyte ();
1375 for (i = 0; i < length - 1; i++)
1376 myaddr[i + addr - memaddr] = gbyte ();
1378 gbyte (); /* Ignore checksum */
1384 putchar_e7000 (ACK);
1385 expect ("TOP ADDRESS =");
1386 expect ("END ADDRESS =");
1395 e7000_xfer_inferior_memory (memaddr, myaddr, len, write, target)
1397 unsigned char *myaddr;
1400 struct target_ops *target; /* ignored */
1403 return e7000_write_inferior_memory( memaddr, myaddr, len);
1406 return e7000_read_inferior_memory( memaddr, myaddr, len);
1408 return e7000_read_inferior_memory_large( memaddr, myaddr, len);
1412 e7000_kill (args, from_tty)
1419 e7000_load (args, from_tty)
1423 struct cleanup *old_chain;
1428 #define WRITESIZE 0x1000
1429 char buf[2 + 4 + 4 + WRITESIZE]; /* `DT' + <addr> + <len> + <data> */
1433 time_t start_time, end_time; /* Start and end times of download */
1434 unsigned long data_count; /* Number of bytes transferred to memory */
1436 if (!strchr (dev_name, ':'))
1438 generic_load (args, from_tty);
1448 while (*args != '\000')
1452 while (isspace (*args)) args++;
1456 while ((*args != '\000') && !isspace (*args)) args++;
1458 if (*args != '\000')
1463 else if (strncmp (arg, "-quiet", strlen (arg)) == 0)
1465 else if (strncmp (arg, "-nostart", strlen (arg)) == 0)
1468 error ("unknown option `%s'", arg);
1472 filename = get_exec_file (1);
1474 pbfd = bfd_openr (filename, gnutarget);
1477 perror_with_name (filename);
1480 old_chain = make_cleanup (bfd_close, pbfd);
1482 if (!bfd_check_format (pbfd, bfd_object))
1483 error ("\"%s\" is not an object file: %s", filename,
1484 bfd_errmsg (bfd_get_error ()));
1486 start_time = time (NULL);
1489 puts_e7000debug ("mw\r");
1493 for (section = pbfd->sections; section; section = section->next)
1495 if (bfd_get_section_flags (pbfd, section) & SEC_LOAD)
1497 bfd_vma section_address;
1498 bfd_size_type section_size;
1501 section_address = bfd_get_section_vma (pbfd, section);
1502 section_size = bfd_get_section_size_before_reloc (section);
1505 printf_filtered ("[Loading section %s at 0x%x (%d bytes)]\n",
1506 bfd_get_section_name (pbfd, section),
1512 data_count += section_size;
1514 while (section_size > 0)
1517 static char inds[] = "|/-\\";
1522 count = min (section_size, WRITESIZE);
1524 buf[2] = section_address >> 24;
1525 buf[3] = section_address >> 16;
1526 buf[4] = section_address >> 8;
1527 buf[5] = section_address;
1529 buf[6] = count >> 24;
1530 buf[7] = count >> 16;
1531 buf[8] = count >> 8;
1534 bfd_get_section_contents (pbfd, section, buf + 10, fptr, count);
1536 if (SERIAL_WRITE (e7000_desc, buf, count + 10))
1537 fprintf_unfiltered (gdb_stderr,
1538 "e7000_load: SERIAL_WRITE failed: %s\n",
1539 safe_strerror(errno));
1545 printf_unfiltered ("\r%c", inds[k++ % 4]);
1546 gdb_flush (gdb_stdout);
1549 section_address += count;
1551 section_size -= count;
1560 end_time = time (NULL);
1562 /* Finally, make the PC point at the start address */
1565 write_pc (bfd_get_start_address (exec_bfd));
1567 inferior_pid = 0; /* No process now */
1569 /* This is necessary because many things were based on the PC at the time that
1570 we attached to the monitor, which is no longer valid now that we have loaded
1571 new code (and just changed the PC). Another way to do this might be to call
1572 normal_stop, except that the stack may not be valid, and things would get
1573 horribly confused... */
1575 clear_symtab_users ();
1579 entry = bfd_get_start_address (pbfd);
1582 printf_unfiltered ("[Starting %s at 0x%x]\n", filename, entry);
1584 /* start_routine (entry);*/
1587 report_transfer_performance (data_count, start_time, end_time);
1589 do_cleanups (old_chain);
1592 /* Clean up when a program exits.
1594 The program actually lives on in the remote processor's RAM, and may be
1595 run again without a download. Don't leave it full of breakpoint
1599 e7000_mourn_inferior ()
1601 remove_breakpoints ();
1602 unpush_target (&e7000_ops);
1603 generic_mourn_inferior (); /* Do all the proper things now */
1606 #ifdef HARD_BREAKPOINTS
1607 #define MAX_E7000DEBUG_BREAKPOINTS (BC_BREAKPOINTS ? 5 : 200)
1609 #define MAX_E7000DEBUG_BREAKPOINTS 200
1612 extern int memory_breakpoint_size;
1614 static CORE_ADDR breakaddr[MAX_E7000DEBUG_BREAKPOINTS] = {0};
1617 e7000_insert_breakpoint (addr, shadow)
1619 unsigned char *shadow;
1623 static char nop[2] = NOP;
1625 for (i = 0; i <= MAX_E7000DEBUG_BREAKPOINTS; i++)
1626 if (breakaddr[i] == 0)
1628 breakaddr[i] = addr;
1629 /* Save old contents, and insert a nop in the space */
1630 #ifdef HARD_BREAKPOINTS
1633 sprintf (buf, "BC%d A=%x\r", i+1, addr);
1634 puts_e7000debug (buf);
1638 sprintf (buf, "B %x\r", addr);
1639 puts_e7000debug (buf);
1643 e7000_read_inferior_memory (addr, shadow, 2);
1644 e7000_write_inferior_memory (addr, nop, 2);
1647 sprintf (buf, "B %x\r", addr);
1648 puts_e7000debug (buf);
1654 error ("Too many breakpoints ( > %d) for the E7000\n",
1655 MAX_E7000DEBUG_BREAKPOINTS);
1660 e7000_remove_breakpoint (addr, shadow)
1662 unsigned char *shadow;
1667 for (i = 0; i < MAX_E7000DEBUG_BREAKPOINTS; i++)
1668 if (breakaddr[i] == addr)
1671 #ifdef HARD_BREAKPOINTS
1674 sprintf (buf, "BC%d - \r", i+1);
1675 puts_e7000debug (buf);
1679 sprintf (buf, "B - %x\r", addr);
1680 puts_e7000debug (buf);
1684 sprintf (buf, "B - %x\r", addr);
1685 puts_e7000debug (buf);
1689 /* Replace the insn under the break */
1690 e7000_write_inferior_memory (addr, shadow, 2);
1697 warning ("Can't find breakpoint associated with 0x%x\n", addr);
1701 /* Put a command string, in args, out to STDBUG. Output from STDBUG
1702 is placed on the users terminal until the prompt is seen. */
1705 e7000_command (args, fromtty)
1709 /* FIXME: arbitrary limit on length of args. */
1715 error ("e7000 target not open.");
1718 puts_e7000debug ("\r");
1722 sprintf (buf, "%s\r", args);
1723 puts_e7000debug (buf);
1728 expect_full_prompt ();
1731 printf_unfiltered ("\n");
1733 /* Who knows what the command did... */
1734 registers_changed ();
1739 e7000_drain_command (args, fromtty)
1746 puts_e7000debug("end\r");
1747 putchar_e7000 (CTRLC);
1749 while ((c = SERIAL_READCHAR (e7000_desc, 1) != SERIAL_TIMEOUT))
1753 putchar_e7000(CTRLC);
1756 if (c > ' ' && c < 127)
1757 printf ("%c", c & 0xff);
1759 printf ("<%x>", c & 0xff);
1768 static char *strings[NITEMS] = {
1774 "ILLEGAL INSTRUCTION",
1781 for (i = 0; i < NITEMS; ++i)
1787 for (i = 0; i < NITEMS; i++)
1794 /* found one of the choices */
1806 /* Suck characters, if a string match, then return the strings index
1807 otherwise echo them. */
1817 char *buffer = saveaway;
1818 /* Count number of expect strings */
1820 for (n = 0; strings[n]; n++)
1822 ptr[n] = strings[n];
1830 c = SERIAL_READCHAR (e7000_desc, 1);
1831 if (c == SERIAL_TIMEOUT)
1833 printf_unfiltered ("[waiting for e7000...]\n");
1846 putchar_e7000 (CTRLC); /* interrupt the running program */
1850 for (i = 0; i < n; i++)
1857 /* Gone all the way */
1864 ptr[i] = strings[i];
1870 /* Save it up incase we find that there was no match */
1875 if (buffer != saveaway)
1878 printf ("%s", buffer);
1881 if (c != SERIAL_TIMEOUT)
1890 /* We subtract two from the pc here rather than use
1891 DECR_PC_AFTER_BREAK since the e7000 doesn't always add two to the
1892 pc, and the simulators never do. */
1900 store_signed_integer (buf,
1901 REGISTER_RAW_SIZE(PC_REGNUM),
1902 read_register (PC_REGNUM) -2);
1903 supply_register (PC_REGNUM, buf);
1904 sprintf (buf2, ".PC %x\r", read_register (PC_REGNUM));
1905 puts_e7000debug (buf2);
1910 #define WAS_RUNNING 2
1913 static char *estrings[] = {
1921 /* Wait until the remote machine stops, then return, storing status in
1922 STATUS just as `wait' would. */
1925 e7000_wait (pid, status)
1927 struct target_waitstatus *status;
1931 int running_count = 0;
1935 /* Then echo chars until PC= string seen */
1936 gch (); /* Drop cr */
1937 gch (); /* and space */
1941 switch (expect_n (estrings))
1944 /* how did this happen ? */
1949 putchar_e7000 (CTRLC);
1957 if (running_count == 20)
1959 printf_unfiltered ("[running...]\n");
1969 /* Skip till the PC= */
1972 #ifdef GDB_TARGET_IS_SH
1973 if ((sh_processor_type != NULL) && (*(sh_processor_type+2) == '3'))
1974 fetch_regs_from_dump (gch, want_sh3_nopc);
1976 fetch_regs_from_dump (gch, want_nopc);
1978 fetch_regs_from_dump (gch, want_nopc);
1981 /* And supply the extra ones the simulator uses */
1982 for (regno = NUM_REALREGS; regno < NUM_REGS; regno++)
1985 supply_register (regno, (char *) &buf);
1988 stop_reason = why_stop ();
1989 expect_full_prompt ();
1991 status->kind = TARGET_WAITKIND_STOPPED;
1992 status->value.sig = TARGET_SIGNAL_TRAP;
1994 switch (stop_reason)
1996 case 1: /* Breakpoint */
1997 write_pc (read_pc ()); /* PC is always off by 2 for breakpoints */
1998 status->value.sig = TARGET_SIGNAL_TRAP;
2000 case 0: /* Single step */
2001 status->value.sig = TARGET_SIGNAL_TRAP;
2003 case 2: /* Interrupt */
2006 status->value.sig = TARGET_SIGNAL_TRAP;
2011 status->value.sig = TARGET_SIGNAL_INT;
2017 printf_unfiltered ("a cycle address error?\n");
2018 status->value.sig = TARGET_SIGNAL_UNKNOWN;
2021 status->value.sig = TARGET_SIGNAL_ILL;
2024 status->value.sig = TARGET_SIGNAL_SEGV;
2026 case 7: /* Anything else (NITEMS + 1) */
2027 printf_unfiltered ("a write protect error?\n");
2028 status->value.sig = TARGET_SIGNAL_UNKNOWN;
2031 /* Get the user's attention - this should never happen. */
2038 /* Define the target subroutine names. */
2040 struct target_ops e7000_ops =
2043 "Remote Hitachi e7000 target",
2044 "Use a remote Hitachi e7000 ICE connected by a serial line,\n\
2045 or a network connection.\n\
2046 Arguments are the name of the device for the serial line,\n\
2047 the speed to connect at in bits per second.\n\
2049 target e7000 /dev/ttya 9600\n\
2050 target e7000 foobar",
2051 e7000_open, /* to_open */
2052 e7000_close, /* to_close */
2054 e7000_detach, /* to_detach */
2055 e7000_resume, /* to_resume */
2056 e7000_wait, /* to_wait */
2057 e7000_fetch_register, /* to_fetch_registers */
2058 e7000_store_register, /* to_store_registers */
2059 e7000_prepare_to_store, /* to_prepare_to_store */
2060 e7000_xfer_inferior_memory, /* to_xfer_memory */
2061 e7000_files_info, /* to_files_info */
2062 e7000_insert_breakpoint, /* to_insert_breakpoint */
2063 e7000_remove_breakpoint, /* to_remove_breakpoint */
2064 0, /* to_terminal_init */
2065 0, /* to_terminal_inferior */
2066 0, /* to_terminal_ours_for_output */
2067 0, /* to_terminal_ours */
2068 0, /* to_terminal_info */
2069 e7000_kill, /* to_kill */
2070 e7000_load, /* to_load */
2071 0, /* to_lookup_symbol */
2072 e7000_create_inferior, /* to_create_inferior */
2073 e7000_mourn_inferior, /* to_mourn_inferior */
2075 0, /* to_notice_signals */
2076 0, /* to_thread_alive */
2078 process_stratum, /* to_stratum */
2079 0, /* next (unused) */
2080 1, /* to_has_all_memory */
2081 1, /* to_has_memory */
2082 1, /* to_has_stack */
2083 1, /* to_has_registers */
2084 1, /* to_has_execution */
2085 0, /* to_sections */
2086 0, /* to_sections_end */
2087 OPS_MAGIC, /* Always the last thing */
2091 _initialize_remote_e7000 ()
2093 add_target (&e7000_ops);
2095 add_com ("e7000 <command>", class_obscure, e7000_command,
2096 "Send a command to the e7000 monitor.");
2098 add_com ("ftplogin <machine> <name> <passwd> <dir>", class_obscure, e7000_login_command,
2099 "Login to machine and change to directory.");
2101 add_com ("ftpload <file>", class_obscure, e7000_ftp_command,
2102 "Fetch and load a file from previously described place.");
2104 add_com ("drain", class_obscure, e7000_drain_command,
2105 "Drain pending e7000 text buffers.");