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"
44 #include <sys/types.h>
46 #include "remote-utils.h"
51 #define HARD_BREAKPOINTS /* Now handled by set option. */
52 #define BC_BREAKPOINTS use_hard_breakpoints
60 extern void notice_quit PARAMS ((void));
62 extern void report_transfer_performance PARAMS ((unsigned long,
65 extern char *sh_processor_type;
67 /* Local function declarations. */
69 static void e7000_close PARAMS ((int));
71 static void e7000_fetch_register PARAMS ((int));
73 static void e7000_store_register PARAMS ((int));
75 static void e7000_command PARAMS ((char *, int));
77 static void e7000_login_command PARAMS ((char *, int));
79 static void e7000_ftp_command PARAMS ((char *, int));
81 static void e7000_drain_command PARAMS ((char *, int));
83 static void expect PARAMS ((char *));
85 static void expect_full_prompt PARAMS ((void));
87 static void expect_prompt PARAMS ((void));
91 static serial_t e7000_desc;
93 /* Allow user to chose between using hardware breakpoints or memory. */
94 static int use_hard_breakpoints = 0; /* use sw breakpoints by default */
96 /* Nonzero if using the tcp serial driver. */
98 static int using_tcp; /* direct tcp connection to target */
99 static int using_tcp_remote; /* indirect connection to target
100 via tcp to controller */
102 /* Nonzero if using the pc isa card. */
106 extern struct target_ops e7000_ops; /* Forward declaration */
108 char *ENQSTRING = "\005";
110 /* Nonzero if some routine (as opposed to the user) wants echoing.
111 FIXME: Do this reentrantly with an extra parameter. */
117 static int timeout = 20;
119 /* Send data to e7000debug. */
122 puts_e7000debug (buf)
126 error ("Use \"target e7000 ...\" first.");
129 printf("Sending %s\n", buf);
131 if (SERIAL_WRITE (e7000_desc, buf, strlen (buf)))
132 fprintf (stderr, "SERIAL_WRITE failed: %s\n", safe_strerror (errno));
134 /* And expect to see it echoed, unless using the pc interface */
148 SERIAL_WRITE (e7000_desc, b, 1);
155 SERIAL_WRITE (e7000_desc, s, strlen (s));
167 /* Read a character from the remote system, doing all the fancy timeout
178 c = SERIAL_READCHAR (e7000_desc, timeout);
182 if (c == SERIAL_TIMEOUT)
187 error ("Timeout reading from remote system.");
202 static char b[8][10];
214 sprintf(b[p], "<%d>", x);
221 /* Scan input from the remote system, until STRING is found. If
222 DISCARD is non-zero, then discard non-matching input, else print it
223 out. Let the user break out immediately. */
235 c = readchar (timeout);
241 putchar_e7000(CTRLC);
250 if (c == SERIAL_ERROR)
252 error ("Serial communication error");
254 if (echo || remote_debug)
256 if (c == '\r' || c == '\n')
269 if (normal (c) == normal (*p++))
278 if (normal (c) == normal (string[0]))
284 /* Keep discarding input until we see the e7000 prompt.
286 The convention for dealing with the prompt is that you
288 o *then* wait for the prompt.
290 Thus the last thing that a procedure does with the serial line will
291 be an expect_prompt(). Exception: e7000_resume does not wait for
292 the prompt, because the terminal is being handed over to the
293 inferior. However, the next thing which happens after that is a
294 e7000_wait which does wait for the prompt. Note that this includes
295 abnormal exit, e.g. error(). This is necessary to prevent getting
296 into states from which we can't recover. */
305 expect_full_prompt ()
311 convert_hex_digit (ch)
314 if (ch >= '0' && ch <= '9')
316 else if (ch >= 'A' && ch <= 'F')
317 return ch - 'A' + 10;
318 else if (ch >= 'a' && ch <= 'f')
319 return ch - 'a' + 10;
327 int value = convert_hex_digit (*start);
330 *start = readchar (timeout);
331 while ((try = convert_hex_digit (*start)) >= 0)
335 *start = readchar (timeout);
341 /* Get N 32-bit words from remote, each preceded by a space, and put
342 them in registers starting at REGNO. */
345 get_hex_regs (n, regno)
352 for (i = 0; i < n; i++)
357 for (j = 0; j < 8; j++)
358 val = (val << 4) + get_hex_digit (j == 0);
359 supply_register (regno++, (char *) &val);
364 /* This is called not only when we first attach, but also when the
365 user types "run" after having attached. */
368 e7000_create_inferior (execfile, args, env)
376 error ("Can't pass arguments to remote E7000DEBUG process");
378 if (execfile == 0 || exec_bfd == 0)
379 error ("No exec file specified");
381 entry_pt = (int) bfd_get_start_address (exec_bfd);
383 #ifdef CREATE_INFERIOR_HOOK
384 CREATE_INFERIOR_HOOK (0); /* No process-ID */
387 /* The "process" (board) is already stopped awaiting our commands, and
388 the program is already downloaded. We just set its PC and go. */
390 clear_proceed_status ();
392 /* Tell wait_for_inferior that we've started a new process. */
393 init_wait_for_inferior ();
395 /* Set up the "saved terminal modes" of the inferior
396 based on what modes we are starting it with. */
397 target_terminal_init ();
399 /* Install inferior's terminal modes. */
400 target_terminal_inferior ();
402 /* insert_step_breakpoint (); FIXME, do we need this? */
403 proceed ((CORE_ADDR) entry_pt, -1, 0); /* Let 'er rip... */
406 /* Open a connection to a remote debugger. NAME is the filename used
407 for communication. */
409 static int baudrate = 9600;
410 static char dev_name[100];
412 static char *machine = "";
413 static char *user = "";
414 static char *passwd = "";
415 static char *dir = "";
417 /* Grab the next token and buy some space for it */
428 while (*p && *p == ' ')
431 while (*p && (*p != ' ' && *p != '\t'))
444 e7000_login_command (args, from_tty)
450 machine = next (&args);
452 passwd = next (&args);
456 printf ("Set info to %s %s %s %s\n", machine, user, passwd, dir);
461 error ("Syntax is ftplogin <machine> <user> <passwd> <directory>");
465 /* Start an ftp transfer from the E7000 to a host */
468 e7000_ftp_command (args, from_tty)
472 /* FIXME: arbitrary limit on machine names and such. */
475 int oldtimeout = timeout;
476 timeout = remote_timeout;
478 sprintf (buf, "ftp %s\r", machine);
479 puts_e7000debug (buf);
480 expect (" Username : ");
481 sprintf (buf, "%s\r", user);
482 puts_e7000debug (buf);
483 expect (" Password : ");
484 write_e7000 (passwd);
486 expect ("success\r");
488 sprintf (buf, "cd %s\r", dir);
489 puts_e7000debug (buf);
491 sprintf (buf, "ll 0;s:%s\r", args);
492 puts_e7000debug (buf);
494 puts_e7000debug ("bye\r");
496 timeout = oldtimeout;
500 e7000_parse_device(args,dev_name,serial_flag,baudrate)
508 if (args && strcasecmp (args, "pc") == 0)
510 strcpy (dev_name, args);
515 /* FIXME! temp hack to allow use with port master -
516 target tcp_remote <device> */
517 if (args && strncmp (args, "tcp_remote", 10) == 0)
520 n = sscanf (args, " %s %s %d %s", com_type, dev_name, &baudrate, junk);
526 n = sscanf (args, " %s %d %s", dev_name, &baudrate, junk);
529 if (n != 1 && n != 2)
531 error ("Bad arguments. Usage:\ttarget e7000 <device> <speed>\n\
532 or \t\ttarget e7000 <host>[:<port>]\n\
533 or \t\ttarget e7000 tcp_remote <host>[:<port>]\n\
534 or \t\ttarget e7000 pc\n");
537 #if !defined(__GO32__) && !defined(__WIN32__)
538 /* FIXME! test for ':' is ambiguous */
539 if (n == 1 && strchr (dev_name, ':') == 0)
541 /* Default to normal telnet port */
542 /* serial_open will use this to determine tcp communication */
543 strcat (dev_name, ":23");
546 if (!using_tcp_remote && strchr (dev_name, ':'))
554 e7000_open (args, from_tty)
563 target_preopen (from_tty);
565 n = e7000_parse_device(args,dev_name,serial_flag,baudrate);
567 push_target (&e7000_ops);
569 e7000_desc = SERIAL_OPEN (dev_name);
572 perror_with_name (dev_name);
574 SERIAL_SETBAUDRATE (e7000_desc, baudrate);
575 SERIAL_RAW (e7000_desc);
577 /* Hello? Are you there? */
580 putchar_e7000 (CTRLC);
586 printf_unfiltered ("[waiting for e7000...]\n");
589 c = SERIAL_READCHAR (e7000_desc, 1);
590 while (c != SERIAL_TIMEOUT)
593 if (from_tty && c != '\r')
603 putchar_e7000 (CTRLC);
612 putchar_e7000 (CTRLC);
615 c = SERIAL_READCHAR (e7000_desc, 1);
618 puts_e7000debug ("\r");
622 puts_e7000debug ("b -\r");
627 printf_filtered ("Remote target %s connected to %s\n", target_shortname,
630 #ifdef GDB_TARGET_IS_H8300
635 /* Close out all files and local state before this target loses control. */
638 e7000_close (quitting)
643 SERIAL_CLOSE (e7000_desc);
648 /* Terminate the open connection to the remote debugger. Use this
649 when you want to detach and do something else with your gdb. */
652 e7000_detach (from_tty)
655 pop_target (); /* calls e7000_close to do the real work */
657 printf ("Ending remote %s debugging\n", target_shortname);
660 /* Tell the remote machine to resume. */
663 e7000_resume (pid, step, sig)
667 puts_e7000debug ("S\r");
669 puts_e7000debug ("G\r");
672 /* Read the remote registers into the block REGS.
674 For the H8/300 a register dump looks like:
676 PC=00021A CCR=80:I*******
677 ER0 - ER3 0000000A 0000002E 0000002E 00000000
678 ER4 - ER7 00000000 00000000 00000000 00FFEFF6
684 #ifdef GDB_TARGET_IS_H8300
686 char *want = "PC=%p CCR=%c\n\
687 ER0 - ER3 %0 %1 %2 %3\n\
688 ER4 - ER7 %4 %5 %6 %7\n";
690 char *want_nopc = "%p CCR=%c\n\
691 ER0 - ER3 %0 %1 %2 %3\n\
692 ER4 - ER7 %4 %5 %6 %7";
696 #ifdef GDB_TARGET_IS_SH
698 char *want = "PC=%16 SR=%22\n\
699 PR=%17 GBR=%18 VBR=%19\n\
701 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
702 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n";
704 char *want_nopc = "%16 SR=%22\n\
705 PR=%17 GBR=%18 VBR=%19\n\
707 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
708 R8-15 %8 %9 %10 %11 %12 %13 %14 %15";
710 char *want_sh3 = "PC=%16 SR=%22\n\
711 PR=%17 GBR=%18 VBR=%19\n\
712 MACH=%20 MACL=%21 SSR=%23 SPC=%24\n\
713 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
714 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
715 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
716 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
717 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
718 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
720 char *want_sh3_nopc = "%16 SR=%22\n\
721 PR=%17 GBR=%18 VBR=%19\n\
722 MACH=%20 MACL=%21 SSR=%22 SPC=%23\n\
723 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
724 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
725 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
726 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
727 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
728 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
735 int c = readchar (timeout);
750 int high = convert_hex_digit (gch ());
751 int low = convert_hex_digit (gch ());
753 return (high << 4) + low;
757 fetch_regs_from_dump (nextchar, want)
762 char buf[MAX_REGISTER_RAW_SIZE];
764 int thischar = nextchar ();
771 /* Skip to end of line and then eat all new line type stuff */
772 while (thischar != '\n' && thischar != '\r')
773 thischar = nextchar ();
774 while (thischar == '\n' || thischar == '\r')
775 thischar = nextchar ();
780 while (thischar == ' '
784 thischar = nextchar ();
789 if (*want == thischar)
793 thischar = nextchar ();
796 else if (thischar == ' ' || thischar == '\n' || thischar == '\r')
798 thischar = nextchar ();
801 error ("out of sync in fetch registers wanted <%s>, got <%c 0x%x>",
802 want, thischar, thischar);
807 /* Got a register command */
837 if (isdigit (want[0]))
839 if (isdigit (want[1]))
841 regno = (want[0] - '0') * 10 + want[1] - '0';
846 regno = want[0] - '0';
854 store_signed_integer (buf,
855 REGISTER_RAW_SIZE(regno),
856 (LONGEST) get_hex (&thischar, nextchar));
857 supply_register (regno, buf);
864 e7000_fetch_registers ()
868 puts_e7000debug ("R\r");
870 #ifdef GDB_TARGET_IS_SH
871 if ((sh_processor_type != NULL) && (*(sh_processor_type+2) == '3'))
872 fetch_regs_from_dump (gch, want_sh3);
874 fetch_regs_from_dump (gch, want);
876 fetch_regs_from_dump (gch, want);
880 /* And supply the extra ones the simulator uses */
881 for (regno = NUM_REALREGS; regno < NUM_REGS; regno++)
885 supply_register (regno, (char *) (&buf));
889 /* Fetch register REGNO, or all registers if REGNO is -1. Returns
893 e7000_fetch_register (regno)
896 e7000_fetch_registers ();
899 /* Store the remote registers from the contents of the block REGS. */
902 e7000_store_registers ()
906 for (regno = 0; regno < NUM_REALREGS; regno++)
907 e7000_store_register (regno);
909 registers_changed ();
912 /* Store register REGNO, or all if REGNO == 0. Return errno value. */
915 e7000_store_register (regno)
922 e7000_store_registers ();
926 #ifdef GDB_TARGET_IS_H8300
929 sprintf (buf, ".ER%d %x\r", regno, read_register (regno));
930 puts_e7000debug (buf);
932 else if (regno == PC_REGNUM)
934 sprintf (buf, ".PC %x\r", read_register (regno));
935 puts_e7000debug (buf);
937 else if (regno == CCR_REGNUM)
939 sprintf (buf, ".CCR %x\r", read_register (regno));
940 puts_e7000debug (buf);
942 #endif /* GDB_TARGET_IS_H8300 */
944 #ifdef GDB_TARGET_IS_SH
948 sprintf (buf, ".R%d %x\r", regno, read_register (regno));
949 puts_e7000debug (buf);
953 sprintf (buf, ".PC %x\r", read_register (regno));
954 puts_e7000debug (buf);
958 sprintf (buf, ".SR %x\r", read_register (regno));
959 puts_e7000debug (buf);
963 sprintf (buf, ".PR %x\r", read_register (regno));
964 puts_e7000debug (buf);
968 sprintf (buf, ".GBR %x\r", read_register (regno));
969 puts_e7000debug (buf);
973 sprintf (buf, ".VBR %x\r", read_register (regno));
974 puts_e7000debug (buf);
978 sprintf (buf, ".MACH %x\r", read_register (regno));
979 puts_e7000debug (buf);
983 sprintf (buf, ".MACL %x\r", read_register (regno));
984 puts_e7000debug (buf);
988 #endif /* GDB_TARGET_IS_SH */
993 /* Get ready to modify the registers array. On machines which store
994 individual registers, this doesn't need to do anything. On machines
995 which store all the registers in one fell swoop, this makes sure
996 that registers contains all the registers from the program being
1000 e7000_prepare_to_store ()
1002 /* Do nothing, since we can store individual regs */
1008 printf ("\tAttached to %s at %d baud.\n", dev_name, baudrate);
1012 stickbyte (where, what)
1016 static CONST char digs[] = "0123456789ABCDEF";
1018 where[0] = digs[(what >> 4) & 0xf];
1019 where[1] = digs[(what & 0xf) & 0xf];
1024 /* Write a small ammount of memory. */
1027 write_small (memaddr, myaddr, len)
1029 unsigned char *myaddr;
1035 for (i = 0; i < len; i++)
1037 if (((memaddr + i) & 3) == 0 && (i + 3 < len))
1039 /* Can be done with a long word */
1040 sprintf (buf, "m %x %x%02x%02x%02x;l\r",
1042 myaddr[i], myaddr[i + 1], myaddr[i + 2], myaddr[i + 3]);
1043 puts_e7000debug (buf);
1048 sprintf (buf, "m %x %x\r", memaddr + i, myaddr[i]);
1049 puts_e7000debug (buf);
1058 /* Write a large ammount of memory, this only works with the serial
1059 mode enabled. Command is sent as
1074 write_large (memaddr, myaddr, len)
1076 unsigned char *myaddr;
1080 #define maxstride 128
1083 puts_e7000debug ("IL ;S:FK\r");
1085 putchar_e7000 (ACK);
1088 for (i = 0; i < len; i += stride)
1090 char compose[maxstride * 2 + 50];
1091 int address = i + memaddr;
1098 if (stride > maxstride)
1101 compose[where++] = 'S';
1103 if (address >= 0xffffff)
1105 else if (address >= 0xffff)
1110 compose[where++] = alen - 1 + '0';
1111 /* Insert length. */
1112 check_sum += stickbyte (compose + where, alen + stride + 1);
1117 check_sum += stickbyte (compose + where, address >> (8 * (alen)));
1121 for (j = 0; j < stride; j++)
1123 check_sum += stickbyte (compose + where, myaddr[i + j]);
1126 stickbyte (compose + where, ~check_sum);
1128 compose[where++] = '\r';
1129 compose[where++] = '\n';
1130 compose[where++] = 0;
1132 SERIAL_WRITE (e7000_desc, compose, where);
1133 j = SERIAL_READCHAR (e7000_desc, 0);
1134 if (j == SERIAL_TIMEOUT)
1136 /* This is ok - nothing there */
1140 /* Hmm, it's trying to tell us something */
1142 error ("Error writing memory");
1146 printf ("@%d}@", j);
1147 while ((j = SERIAL_READCHAR(e7000_desc,0)) > 0)
1149 printf ("@{%d}@",j);
1154 /* Send the trailer record */
1155 write_e7000 ("S70500000000FA\r");
1156 putchar_e7000 (CTRLZ);
1158 putchar_e7000 (ACK);
1164 /* Copy LEN bytes of data from debugger memory at MYADDR to inferior's
1165 memory at MEMADDR. Returns length moved.
1167 Can't use the Srecord load over ethernet, so don't use fast method
1171 e7000_write_inferior_memory (memaddr, myaddr, len)
1173 unsigned char *myaddr;
1176 if (len < 16 || using_tcp || using_pc)
1177 return write_small (memaddr, myaddr, len);
1179 return write_large (memaddr, myaddr, len);
1182 /* Read LEN bytes from inferior memory at MEMADDR. Put the result
1183 at debugger address MYADDR. Returns length moved.
1185 Small transactions we send
1192 e7000_read_inferior_memory (memaddr, myaddr, len)
1194 unsigned char *myaddr;
1201 /* Starting address of this pass. */
1203 /* printf("READ INF %x %x %d\n", memaddr, myaddr, len);*/
1204 if (((memaddr - 1) + len) < memaddr)
1210 sprintf (buf, "m %x;l\r", memaddr);
1211 puts_e7000debug (buf);
1213 for (count = 0; count < len; count += 4)
1215 /* Suck away the address */
1221 { /* Some kind of error */
1228 /* Now read in the data */
1229 for (i = 0; i < 4; i++)
1232 if (count + i < len) {
1233 myaddr[count + i] = b;
1237 /* Skip the trailing ? and send a . to end and a cr for more */
1240 if (count + 4 >= len)
1241 puts_e7000debug(".\r");
1243 puts_e7000debug("\r");
1253 For large transfers we used to send
1256 d <addr> <endaddr>\r
1259 <ADDRESS> < D A T A > < ASCII CODE >
1260 00000000 5F FD FD FF DF 7F DF FF 01 00 01 00 02 00 08 04 "_..............."
1261 00000010 FF D7 FF 7F D7 F1 7F FF 00 05 00 00 08 00 40 00 "..............@."
1262 00000020 7F FD FF F7 7F FF FF F7 00 00 00 00 00 00 00 00 "................"
1264 A cost in chars for each transaction of 80 + 5*n-bytes.
1266 Large transactions could be done with the srecord load code, but
1267 there is a pause for a second before dumping starts, which slows the
1272 e7000_read_inferior_memory_large (memaddr, myaddr, len)
1274 unsigned char *myaddr;
1281 /* Starting address of this pass. */
1283 if (((memaddr - 1) + len) < memaddr)
1289 sprintf (buf, "d %x %x\r", memaddr, memaddr + len - 1);
1290 puts_e7000debug (buf);
1295 /* skip down to the first ">" */
1298 /* now skip to the end of that line */
1305 /* get rid of any white space before the address */
1309 /* Skip the address */
1312 /* read in the bytes on the line */
1313 while (c != '"' && count < len)
1319 myaddr[count++] = get_hex (&c);
1322 /* throw out the rest of the line */
1327 /* wait for the ":" prompt */
1337 fast_but_for_the_pause_e7000_read_inferior_memory (memaddr, myaddr, len)
1346 if (((memaddr - 1) + len) < memaddr)
1352 sprintf (buf, "is %x@%x:s\r", memaddr, len);
1353 puts_e7000debug (buf);
1359 error ("Memory read error");
1361 putchar_e7000 (ACK);
1374 case ENQ: /* ENQ, at the end */
1378 /* Start of an Srecord */
1383 case '7': /* Termination record, ignore */
1387 /* Header record - ignore it */
1399 alen = type - '0' + 1;
1403 addr = (addr << 8) + gbyte ();
1407 for (i = 0; i < length - 1; i++)
1408 myaddr[i + addr - memaddr] = gbyte ();
1410 gbyte (); /* Ignore checksum */
1416 putchar_e7000 (ACK);
1417 expect ("TOP ADDRESS =");
1418 expect ("END ADDRESS =");
1427 e7000_xfer_inferior_memory (memaddr, myaddr, len, write, target)
1429 unsigned char *myaddr;
1432 struct target_ops *target; /* ignored */
1435 return e7000_write_inferior_memory( memaddr, myaddr, len);
1438 return e7000_read_inferior_memory( memaddr, myaddr, len);
1440 return e7000_read_inferior_memory_large( memaddr, myaddr, len);
1444 e7000_kill (args, from_tty)
1451 e7000_load (args, from_tty)
1455 struct cleanup *old_chain;
1460 #define WRITESIZE 0x1000
1461 char buf[2 + 4 + 4 + WRITESIZE]; /* `DT' + <addr> + <len> + <data> */
1465 time_t start_time, end_time; /* Start and end times of download */
1466 unsigned long data_count; /* Number of bytes transferred to memory */
1467 int oldtimeout = timeout;
1469 timeout = remote_timeout;
1472 /* FIXME! change test to test for type of download */
1475 generic_load (args, from_tty);
1479 /* for direct tcp connections, we can do a fast binary download */
1486 while (*args != '\000')
1490 while (isspace (*args)) args++;
1494 while ((*args != '\000') && !isspace (*args)) args++;
1496 if (*args != '\000')
1501 else if (strncmp (arg, "-quiet", strlen (arg)) == 0)
1503 else if (strncmp (arg, "-nostart", strlen (arg)) == 0)
1506 error ("unknown option `%s'", arg);
1510 filename = get_exec_file (1);
1512 pbfd = bfd_openr (filename, gnutarget);
1515 perror_with_name (filename);
1518 old_chain = make_cleanup (bfd_close, pbfd);
1520 if (!bfd_check_format (pbfd, bfd_object))
1521 error ("\"%s\" is not an object file: %s", filename,
1522 bfd_errmsg (bfd_get_error ()));
1524 start_time = time (NULL);
1527 puts_e7000debug ("mw\r");
1531 for (section = pbfd->sections; section; section = section->next)
1533 if (bfd_get_section_flags (pbfd, section) & SEC_LOAD)
1535 bfd_vma section_address;
1536 bfd_size_type section_size;
1539 section_address = bfd_get_section_vma (pbfd, section);
1540 section_size = bfd_get_section_size_before_reloc (section);
1543 printf_filtered ("[Loading section %s at 0x%x (%d bytes)]\n",
1544 bfd_get_section_name (pbfd, section),
1550 data_count += section_size;
1552 while (section_size > 0)
1555 static char inds[] = "|/-\\";
1560 count = min (section_size, WRITESIZE);
1562 buf[2] = section_address >> 24;
1563 buf[3] = section_address >> 16;
1564 buf[4] = section_address >> 8;
1565 buf[5] = section_address;
1567 buf[6] = count >> 24;
1568 buf[7] = count >> 16;
1569 buf[8] = count >> 8;
1572 bfd_get_section_contents (pbfd, section, buf + 10, fptr, count);
1574 if (SERIAL_WRITE (e7000_desc, buf, count + 10))
1575 fprintf_unfiltered (gdb_stderr,
1576 "e7000_load: SERIAL_WRITE failed: %s\n",
1577 safe_strerror(errno));
1583 printf_unfiltered ("\r%c", inds[k++ % 4]);
1584 gdb_flush (gdb_stdout);
1587 section_address += count;
1589 section_size -= count;
1598 end_time = time (NULL);
1600 /* Finally, make the PC point at the start address */
1603 write_pc (bfd_get_start_address (exec_bfd));
1605 inferior_pid = 0; /* No process now */
1607 /* This is necessary because many things were based on the PC at the time that
1608 we attached to the monitor, which is no longer valid now that we have loaded
1609 new code (and just changed the PC). Another way to do this might be to call
1610 normal_stop, except that the stack may not be valid, and things would get
1611 horribly confused... */
1613 clear_symtab_users ();
1617 entry = bfd_get_start_address (pbfd);
1620 printf_unfiltered ("[Starting %s at 0x%x]\n", filename, entry);
1622 /* start_routine (entry);*/
1625 report_transfer_performance (data_count, start_time, end_time);
1627 do_cleanups (old_chain);
1628 timeout = oldtimeout;
1631 /* Clean up when a program exits.
1633 The program actually lives on in the remote processor's RAM, and may be
1634 run again without a download. Don't leave it full of breakpoint
1638 e7000_mourn_inferior ()
1640 remove_breakpoints ();
1641 unpush_target (&e7000_ops);
1642 generic_mourn_inferior (); /* Do all the proper things now */
1645 #define MAX_BREAKPOINTS 200
1646 #ifdef HARD_BREAKPOINTS
1647 #define MAX_E7000DEBUG_BREAKPOINTS (BC_BREAKPOINTS ? 5 : MAX_BREAKPOINTS)
1649 #define MAX_E7000DEBUG_BREAKPOINTS MAX_BREAKPOINTS
1652 extern int memory_breakpoint_size;
1654 /* Since we can change to soft breakpoints dynamically, we must define
1655 more than enough. Was breakaddr[MAX_E7000DEBUG_BREAKPOINTS]. */
1656 static CORE_ADDR breakaddr[MAX_BREAKPOINTS] = {0};
1659 e7000_insert_breakpoint (addr, shadow)
1661 unsigned char *shadow;
1665 static char nop[2] = NOP;
1667 for (i = 0; i <= MAX_E7000DEBUG_BREAKPOINTS; i++)
1668 if (breakaddr[i] == 0)
1670 breakaddr[i] = addr;
1671 /* Save old contents, and insert a nop in the space */
1672 #ifdef HARD_BREAKPOINTS
1675 sprintf (buf, "BC%d A=%x\r", i+1, addr);
1676 puts_e7000debug (buf);
1680 sprintf (buf, "B %x\r", addr);
1681 puts_e7000debug (buf);
1685 e7000_read_inferior_memory (addr, shadow, 2);
1686 e7000_write_inferior_memory (addr, nop, 2);
1689 sprintf (buf, "B %x\r", addr);
1690 puts_e7000debug (buf);
1696 error ("Too many breakpoints ( > %d) for the E7000\n",
1697 MAX_E7000DEBUG_BREAKPOINTS);
1702 e7000_remove_breakpoint (addr, shadow)
1704 unsigned char *shadow;
1709 for (i = 0; i < MAX_E7000DEBUG_BREAKPOINTS; i++)
1710 if (breakaddr[i] == addr)
1713 #ifdef HARD_BREAKPOINTS
1716 sprintf (buf, "BC%d - \r", i+1);
1717 puts_e7000debug (buf);
1721 sprintf (buf, "B - %x\r", addr);
1722 puts_e7000debug (buf);
1726 sprintf (buf, "B - %x\r", addr);
1727 puts_e7000debug (buf);
1731 /* Replace the insn under the break */
1732 e7000_write_inferior_memory (addr, shadow, 2);
1739 warning ("Can't find breakpoint associated with 0x%x\n", addr);
1743 /* Put a command string, in args, out to STDBUG. Output from STDBUG
1744 is placed on the users terminal until the prompt is seen. */
1747 e7000_command (args, fromtty)
1751 /* FIXME: arbitrary limit on length of args. */
1757 error ("e7000 target not open.");
1760 puts_e7000debug ("\r");
1764 sprintf (buf, "%s\r", args);
1765 puts_e7000debug (buf);
1770 expect_full_prompt ();
1773 printf_unfiltered ("\n");
1775 /* Who knows what the command did... */
1776 registers_changed ();
1781 e7000_drain_command (args, fromtty)
1788 puts_e7000debug("end\r");
1789 putchar_e7000 (CTRLC);
1791 while ((c = SERIAL_READCHAR (e7000_desc, 1) != SERIAL_TIMEOUT))
1795 putchar_e7000(CTRLC);
1798 if (c > ' ' && c < 127)
1799 printf ("%c", c & 0xff);
1801 printf ("<%x>", c & 0xff);
1810 static char *strings[NITEMS] = {
1816 "ILLEGAL INSTRUCTION",
1823 for (i = 0; i < NITEMS; ++i)
1829 for (i = 0; i < NITEMS; i++)
1836 /* found one of the choices */
1848 /* Suck characters, if a string match, then return the strings index
1849 otherwise echo them. */
1859 char *buffer = saveaway;
1860 /* Count number of expect strings */
1862 for (n = 0; strings[n]; n++)
1864 ptr[n] = strings[n];
1872 c = SERIAL_READCHAR (e7000_desc, 1);
1873 if (c == SERIAL_TIMEOUT)
1875 printf_unfiltered ("[waiting for e7000...]\n");
1888 putchar_e7000 (CTRLC); /* interrupt the running program */
1892 for (i = 0; i < n; i++)
1899 /* Gone all the way */
1906 ptr[i] = strings[i];
1912 /* Save it up incase we find that there was no match */
1917 if (buffer != saveaway)
1920 printf ("%s", buffer);
1923 if (c != SERIAL_TIMEOUT)
1932 /* We subtract two from the pc here rather than use
1933 DECR_PC_AFTER_BREAK since the e7000 doesn't always add two to the
1934 pc, and the simulators never do. */
1942 store_signed_integer (buf,
1943 REGISTER_RAW_SIZE(PC_REGNUM),
1944 read_register (PC_REGNUM) -2);
1945 supply_register (PC_REGNUM, buf);
1946 sprintf (buf2, ".PC %x\r", read_register (PC_REGNUM));
1947 puts_e7000debug (buf2);
1952 #define WAS_RUNNING 2
1955 static char *estrings[] = {
1963 /* Wait until the remote machine stops, then return, storing status in
1964 STATUS just as `wait' would. */
1967 e7000_wait (pid, status)
1969 struct target_waitstatus *status;
1973 int running_count = 0;
1977 /* Then echo chars until PC= string seen */
1978 gch (); /* Drop cr */
1979 gch (); /* and space */
1983 switch (expect_n (estrings))
1986 /* how did this happen ? */
1991 putchar_e7000 (CTRLC);
1999 if (running_count == 20)
2001 printf_unfiltered ("[running...]\n");
2011 /* Skip till the PC= */
2014 #ifdef GDB_TARGET_IS_SH
2015 if ((sh_processor_type != NULL) && (*(sh_processor_type+2) == '3'))
2016 fetch_regs_from_dump (gch, want_sh3_nopc);
2018 fetch_regs_from_dump (gch, want_nopc);
2020 fetch_regs_from_dump (gch, want_nopc);
2023 /* And supply the extra ones the simulator uses */
2024 for (regno = NUM_REALREGS; regno < NUM_REGS; regno++)
2027 supply_register (regno, (char *) &buf);
2030 stop_reason = why_stop ();
2031 expect_full_prompt ();
2033 status->kind = TARGET_WAITKIND_STOPPED;
2034 status->value.sig = TARGET_SIGNAL_TRAP;
2036 switch (stop_reason)
2038 case 1: /* Breakpoint */
2039 write_pc (read_pc ()); /* PC is always off by 2 for breakpoints */
2040 status->value.sig = TARGET_SIGNAL_TRAP;
2042 case 0: /* Single step */
2043 status->value.sig = TARGET_SIGNAL_TRAP;
2045 case 2: /* Interrupt */
2048 status->value.sig = TARGET_SIGNAL_TRAP;
2053 status->value.sig = TARGET_SIGNAL_INT;
2059 printf_unfiltered ("a cycle address error?\n");
2060 status->value.sig = TARGET_SIGNAL_UNKNOWN;
2063 status->value.sig = TARGET_SIGNAL_ILL;
2066 status->value.sig = TARGET_SIGNAL_SEGV;
2068 case 7: /* Anything else (NITEMS + 1) */
2069 printf_unfiltered ("a write protect error?\n");
2070 status->value.sig = TARGET_SIGNAL_UNKNOWN;
2073 /* Get the user's attention - this should never happen. */
2080 /* Define the target subroutine names. */
2082 struct target_ops e7000_ops =
2085 "Remote Hitachi e7000 target",
2086 "Use a remote Hitachi e7000 ICE connected by a serial line,\n\
2087 or a network connection.\n\
2088 Arguments are the name of the device for the serial line,\n\
2089 the speed to connect at in bits per second.\n\
2091 target e7000 /dev/ttya 9600\n\
2092 target e7000 foobar",
2093 e7000_open, /* to_open */
2094 e7000_close, /* to_close */
2096 e7000_detach, /* to_detach */
2097 e7000_resume, /* to_resume */
2098 e7000_wait, /* to_wait */
2099 e7000_fetch_register, /* to_fetch_registers */
2100 e7000_store_register, /* to_store_registers */
2101 e7000_prepare_to_store, /* to_prepare_to_store */
2102 e7000_xfer_inferior_memory, /* to_xfer_memory */
2103 e7000_files_info, /* to_files_info */
2104 e7000_insert_breakpoint, /* to_insert_breakpoint */
2105 e7000_remove_breakpoint, /* to_remove_breakpoint */
2106 0, /* to_terminal_init */
2107 0, /* to_terminal_inferior */
2108 0, /* to_terminal_ours_for_output */
2109 0, /* to_terminal_ours */
2110 0, /* to_terminal_info */
2111 e7000_kill, /* to_kill */
2112 e7000_load, /* to_load */
2113 0, /* to_lookup_symbol */
2114 e7000_create_inferior, /* to_create_inferior */
2115 e7000_mourn_inferior, /* to_mourn_inferior */
2117 0, /* to_notice_signals */
2118 0, /* to_thread_alive */
2120 process_stratum, /* to_stratum */
2121 0, /* next (unused) */
2122 1, /* to_has_all_memory */
2123 1, /* to_has_memory */
2124 1, /* to_has_stack */
2125 1, /* to_has_registers */
2126 1, /* to_has_execution */
2127 0, /* to_sections */
2128 0, /* to_sections_end */
2129 OPS_MAGIC, /* Always the last thing */
2133 _initialize_remote_e7000 ()
2135 add_target (&e7000_ops);
2137 add_com ("e7000 <command>", class_obscure, e7000_command,
2138 "Send a command to the e7000 monitor.");
2140 add_com ("ftplogin <machine> <name> <passwd> <dir>", class_obscure, e7000_login_command,
2141 "Login to machine and change to directory.");
2143 add_com ("ftpload <file>", class_obscure, e7000_ftp_command,
2144 "Fetch and load a file from previously described place.");
2146 add_com ("drain", class_obscure, e7000_drain_command,
2147 "Drain pending e7000 text buffers.");
2149 add_show_from_set (add_set_cmd ("usehardbreakpoints", no_class,
2150 var_integer, (char *)&use_hard_breakpoints,
2151 "Set use of hardware breakpoints for all breakpoints.\n", &setlist),