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"
52 #define HARD_BREAKPOINTS /* Now handled by set option. */
53 #define BC_BREAKPOINTS use_hard_breakpoints
61 extern void notice_quit PARAMS ((void));
63 extern void report_transfer_performance PARAMS ((unsigned long,
66 extern char *sh_processor_type;
68 /* Local function declarations. */
70 static void e7000_close PARAMS ((int));
72 static void e7000_fetch_register PARAMS ((int));
74 static void e7000_store_register PARAMS ((int));
76 static void e7000_command PARAMS ((char *, int));
78 static void e7000_login_command PARAMS ((char *, int));
80 static void e7000_ftp_command PARAMS ((char *, int));
82 static void e7000_drain_command PARAMS ((char *, int));
84 static void expect PARAMS ((char *));
86 static void expect_full_prompt PARAMS ((void));
88 static void expect_prompt PARAMS ((void));
90 static int e7000_parse_device PARAMS ((char *args, char *dev_name,
94 static serial_t e7000_desc;
96 /* Allow user to chose between using hardware breakpoints or memory. */
97 static int use_hard_breakpoints = 0; /* use sw breakpoints by default */
99 /* Nonzero if using the tcp serial driver. */
101 static int using_tcp; /* direct tcp connection to target */
102 static int using_tcp_remote; /* indirect connection to target
103 via tcp to controller */
105 /* Nonzero if using the pc isa card. */
109 extern struct target_ops e7000_ops; /* Forward declaration */
111 char *ENQSTRING = "\005";
113 /* Nonzero if some routine (as opposed to the user) wants echoing.
114 FIXME: Do this reentrantly with an extra parameter. */
120 static int timeout = 20;
122 /* Send data to e7000debug. */
125 puts_e7000debug (buf)
129 error ("Use \"target e7000 ...\" first.");
132 printf_unfiltered ("Sending %s\n", buf);
134 if (SERIAL_WRITE (e7000_desc, buf, strlen (buf)))
135 fprintf_unfiltered (gdb_stderr, "SERIAL_WRITE failed: %s\n", safe_strerror (errno));
137 /* And expect to see it echoed, unless using the pc interface */
151 SERIAL_WRITE (e7000_desc, b, 1);
158 SERIAL_WRITE (e7000_desc, s, strlen (s));
170 /* Read a character from the remote system, doing all the fancy timeout
171 stuff. Handles serial errors and EOF. If TIMEOUT == 0, and no chars,
172 returns -1, else returns next char. Discards chars > 127. */
182 c = SERIAL_READCHAR (e7000_desc, timeout);
186 if (c == SERIAL_TIMEOUT)
191 error ("Timeout reading from remote system.");
194 error ("Serial communication error");
198 putchar_unfiltered (c);
199 gdb_flush (gdb_stdout);
209 static char b[8][10];
221 sprintf(b[p], "<%d>", x);
228 /* Scan input from the remote system, until STRING is found. If
229 DISCARD is non-zero, then discard non-matching input, else print it
230 out. Let the user break out immediately. */
242 c = readchar (timeout);
249 putchar_e7000(CTRLC);
261 if (c == '\r' || c == '\n')
264 putchar_unfiltered ('\n');
270 putchar_unfiltered (c);
272 gdb_flush (gdb_stdout);
274 if (normal (c) == normal (*p++))
283 if (normal (c) == normal (string[0]))
289 /* Keep discarding input until we see the e7000 prompt.
291 The convention for dealing with the prompt is that you
293 o *then* wait for the prompt.
295 Thus the last thing that a procedure does with the serial line will
296 be an expect_prompt(). Exception: e7000_resume does not wait for
297 the prompt, because the terminal is being handed over to the
298 inferior. However, the next thing which happens after that is a
299 e7000_wait which does wait for the prompt. Note that this includes
300 abnormal exit, e.g. error(). This is necessary to prevent getting
301 into states from which we can't recover. */
310 expect_full_prompt ()
316 convert_hex_digit (ch)
319 if (ch >= '0' && ch <= '9')
321 else if (ch >= 'A' && ch <= 'F')
322 return ch - 'A' + 10;
323 else if (ch >= 'a' && ch <= 'f')
324 return ch - 'a' + 10;
332 int value = convert_hex_digit (*start);
335 *start = readchar (timeout);
336 while ((try = convert_hex_digit (*start)) >= 0)
340 *start = readchar (timeout);
346 /* Get N 32-bit words from remote, each preceded by a space, and put
347 them in registers starting at REGNO. */
350 get_hex_regs (n, regno)
357 for (i = 0; i < n; i++)
362 for (j = 0; j < 8; j++)
363 val = (val << 4) + get_hex_digit (j == 0);
364 supply_register (regno++, (char *) &val);
369 /* This is called not only when we first attach, but also when the
370 user types "run" after having attached. */
373 e7000_create_inferior (execfile, args, env)
381 error ("Can't pass arguments to remote E7000DEBUG process");
383 if (execfile == 0 || exec_bfd == 0)
384 error ("No exec file specified");
386 entry_pt = (int) bfd_get_start_address (exec_bfd);
388 #ifdef CREATE_INFERIOR_HOOK
389 CREATE_INFERIOR_HOOK (0); /* No process-ID */
392 /* The "process" (board) is already stopped awaiting our commands, and
393 the program is already downloaded. We just set its PC and go. */
395 clear_proceed_status ();
397 /* Tell wait_for_inferior that we've started a new process. */
398 init_wait_for_inferior ();
400 /* Set up the "saved terminal modes" of the inferior
401 based on what modes we are starting it with. */
402 target_terminal_init ();
404 /* Install inferior's terminal modes. */
405 target_terminal_inferior ();
407 /* insert_step_breakpoint (); FIXME, do we need this? */
408 proceed ((CORE_ADDR) entry_pt, -1, 0); /* Let 'er rip... */
411 /* Open a connection to a remote debugger. NAME is the filename used
412 for communication. */
414 static int baudrate = 9600;
415 static char dev_name[100];
417 static char *machine = "";
418 static char *user = "";
419 static char *passwd = "";
420 static char *dir = "";
422 /* Grab the next token and buy some space for it */
433 while (*p && *p == ' ')
436 while (*p && (*p != ' ' && *p != '\t'))
449 e7000_login_command (args, from_tty)
455 machine = next (&args);
457 passwd = next (&args);
461 printf_unfiltered ("Set info to %s %s %s %s\n", machine, user, passwd, dir);
466 error ("Syntax is ftplogin <machine> <user> <passwd> <directory>");
470 /* Start an ftp transfer from the E7000 to a host */
473 e7000_ftp_command (args, from_tty)
477 /* FIXME: arbitrary limit on machine names and such. */
480 int oldtimeout = timeout;
481 timeout = remote_timeout;
483 sprintf (buf, "ftp %s\r", machine);
484 puts_e7000debug (buf);
485 expect (" Username : ");
486 sprintf (buf, "%s\r", user);
487 puts_e7000debug (buf);
488 expect (" Password : ");
489 write_e7000 (passwd);
491 expect ("success\r");
493 sprintf (buf, "cd %s\r", dir);
494 puts_e7000debug (buf);
496 sprintf (buf, "ll 0;s:%s\r", args);
497 puts_e7000debug (buf);
499 puts_e7000debug ("bye\r");
501 timeout = oldtimeout;
505 e7000_parse_device (args, dev_name, baudrate)
512 if (args && strcasecmp (args, "pc") == 0)
514 strcpy (dev_name, args);
519 /* FIXME! temp hack to allow use with port master -
520 target tcp_remote <device> */
521 if (args && strncmp (args, "tcp", 10) == 0)
524 n = sscanf (args, " %s %s %d %s", com_type, dev_name, &baudrate, junk);
530 n = sscanf (args, " %s %d %s", dev_name, &baudrate, junk);
533 if (n != 1 && n != 2)
535 error ("Bad arguments. Usage:\ttarget e7000 <device> <speed>\n\
536 or \t\ttarget e7000 <host>[:<port>]\n\
537 or \t\ttarget e7000 tcp_remote <host>[:<port>]\n\
538 or \t\ttarget e7000 pc\n");
541 #if !defined(__GO32__) && !defined(_WIN32)
542 /* FIXME! test for ':' is ambiguous */
543 if (n == 1 && strchr (dev_name, ':') == 0)
545 /* Default to normal telnet port */
546 /* serial_open will use this to determine tcp communication */
547 strcat (dev_name, ":23");
550 if (!using_tcp_remote && strchr (dev_name, ':'))
557 /* Stub for catch_errors. */
560 e7000_start_remote (dummy)
568 immediate_quit = 1; /* Allow user to interrupt it */
570 /* Hello? Are you there? */
575 putchar_e7000 (CTRLC);
576 while (!sync && ++try <= quit_trying)
580 printf_unfiltered ("[waiting for e7000...]\n");
585 /* FIXME! this didn't seem right-> while (c != SERIAL_TIMEOUT)
586 * we get stuck in this loop ...
587 * We may never timeout, and never sync up :-(
589 while (!sync && c != -1)
594 putchar_unfiltered (c);
595 gdb_flush (gdb_stdout);
597 /* Shouldn't we either break here, or check for sync in inner loop? */
603 putchar_e7000 (CTRLC);
611 putchar_e7000 (CTRLC);
612 /* Was-> quit_flag = 0; */
614 quit_trying = try+1; /* we don't want to try anymore */
625 fprintf_unfiltered (gdb_stderr, "Giving up after %d tries...\n",try);
626 error ("Unable to syncronize with target.\n");
629 puts_e7000debug ("\r");
631 puts_e7000debug ("b -\r"); /* Clear breakpoints */
636 /* This is really the job of start_remote however, that makes an assumption
637 that the target is about to print out a status message of some sort. That
638 doesn't happen here. */
640 flush_cached_frames ();
641 registers_changed ();
642 stop_pc = read_pc ();
643 set_current_frame (create_new_frame (read_fp (), stop_pc));
644 select_frame (get_current_frame (), 0);
645 print_stack_frame (selected_frame, -1, 1);
651 e7000_open (args, from_tty)
657 target_preopen (from_tty);
659 n = e7000_parse_device (args, dev_name, baudrate);
661 push_target (&e7000_ops);
663 e7000_desc = SERIAL_OPEN (dev_name);
666 perror_with_name (dev_name);
668 SERIAL_SETBAUDRATE (e7000_desc, baudrate);
669 SERIAL_RAW (e7000_desc);
671 #ifdef GDB_TARGET_IS_H8300
675 /* Start the remote connection; if error (0), discard this target.
676 In particular, if the user quits, be sure to discard it
677 (we'd be in an inconsistent state otherwise). */
678 if (!catch_errors (e7000_start_remote, (char *)0,
679 "Couldn't establish connection to remote target\n", RETURN_MASK_ALL))
681 printf_filtered ("Remote target %s connected to %s\n", target_shortname,
685 /* Close out all files and local state before this target loses control. */
688 e7000_close (quitting)
693 SERIAL_CLOSE (e7000_desc);
698 /* Terminate the open connection to the remote debugger. Use this
699 when you want to detach and do something else with your gdb. */
702 e7000_detach (from_tty)
705 pop_target (); /* calls e7000_close to do the real work */
707 printf_unfiltered ("Ending remote %s debugging\n", target_shortname);
710 /* Tell the remote machine to resume. */
713 e7000_resume (pid, step, sig)
717 puts_e7000debug ("S\r");
719 puts_e7000debug ("G\r");
722 /* Read the remote registers into the block REGS.
724 For the H8/300 a register dump looks like:
726 PC=00021A CCR=80:I*******
727 ER0 - ER3 0000000A 0000002E 0000002E 00000000
728 ER4 - ER7 00000000 00000000 00000000 00FFEFF6
734 #ifdef GDB_TARGET_IS_H8300
736 char *want_h8300h = "PC=%p CCR=%c\n\
737 ER0 - ER3 %0 %1 %2 %3\n\
738 ER4 - ER7 %4 %5 %6 %7\n";
740 char *want_nopc_h8300h = "%p CCR=%c\n\
741 ER0 - ER3 %0 %1 %2 %3\n\
742 ER4 - ER7 %4 %5 %6 %7";
744 char *want_h8300s = "PC=%p CCR=%c\n\
746 ER0 - ER3 %0 %1 %2 %3\n\
747 ER4 - ER7 %4 %5 %6 %7\n";
749 char *want_nopc_h8300s = "%p CCR=%c EXR=%9\n\
750 ER0 - ER3 %0 %1 %2 %3\n\
751 ER4 - ER7 %4 %5 %6 %7";
755 #ifdef GDB_TARGET_IS_SH
757 char *want = "PC=%16 SR=%22\n\
758 PR=%17 GBR=%18 VBR=%19\n\
760 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
761 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n";
763 char *want_nopc = "%16 SR=%22\n\
764 PR=%17 GBR=%18 VBR=%19\n\
766 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
767 R8-15 %8 %9 %10 %11 %12 %13 %14 %15";
769 char *want_sh3 = "PC=%16 SR=%22\n\
770 PR=%17 GBR=%18 VBR=%19\n\
771 MACH=%20 MACL=%21 SSR=%23 SPC=%24\n\
772 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
773 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
774 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
775 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
776 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
777 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
779 char *want_sh3_nopc = "%16 SR=%22\n\
780 PR=%17 GBR=%18 VBR=%19\n\
781 MACH=%20 MACL=%21 SSR=%22 SPC=%23\n\
782 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
783 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
784 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
785 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
786 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
787 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
794 return readchar (timeout);
800 int high = convert_hex_digit (gch ());
801 int low = convert_hex_digit (gch ());
803 return (high << 4) + low;
807 fetch_regs_from_dump (nextchar, want)
812 char buf[MAX_REGISTER_RAW_SIZE];
814 int thischar = nextchar ();
821 /* Skip to end of line and then eat all new line type stuff */
822 while (thischar != '\n' && thischar != '\r')
823 thischar = nextchar ();
824 while (thischar == '\n' || thischar == '\r')
825 thischar = nextchar ();
830 while (thischar == ' '
834 thischar = nextchar ();
839 if (*want == thischar)
843 thischar = nextchar ();
846 else if (thischar == ' ' || thischar == '\n' || thischar == '\r')
848 thischar = nextchar ();
851 error ("out of sync in fetch registers wanted <%s>, got <%c 0x%x>",
852 want, thischar, thischar);
857 /* Got a register command */
887 if (isdigit (want[0]))
889 if (isdigit (want[1]))
891 regno = (want[0] - '0') * 10 + want[1] - '0';
896 regno = want[0] - '0';
904 store_signed_integer (buf,
905 REGISTER_RAW_SIZE(regno),
906 (LONGEST) get_hex (&thischar, nextchar));
907 supply_register (regno, buf);
914 e7000_fetch_registers ()
919 puts_e7000debug ("R\r");
921 #ifdef GDB_TARGET_IS_SH
923 if (target_architecture->arch == bfd_arch_sh)
924 switch (target_architecture->mach)
928 /* start-sanitize-sh4 */
930 /* end-sanitize-sh4 */
935 wanted = want_h8300s;
937 wanted = want_h8300h);
939 fetch_regs_from_dump (gch, wanted);
941 /* And supply the extra ones the simulator uses */
942 for (regno = NUM_REALREGS; regno < NUM_REGS; regno++)
946 supply_register (regno, (char *) (&buf));
950 /* Fetch register REGNO, or all registers if REGNO is -1. Returns
954 e7000_fetch_register (regno)
957 e7000_fetch_registers ();
960 /* Store the remote registers from the contents of the block REGS. */
963 e7000_store_registers ()
967 for (regno = 0; regno < NUM_REALREGS; regno++)
968 e7000_store_register (regno);
970 registers_changed ();
973 /* Store register REGNO, or all if REGNO == 0. Return errno value. */
976 e7000_store_register (regno)
983 e7000_store_registers ();
987 #ifdef GDB_TARGET_IS_H8300
990 sprintf (buf, ".ER%d %x\r", regno, read_register (regno));
991 puts_e7000debug (buf);
993 else if (regno == PC_REGNUM)
995 sprintf (buf, ".PC %x\r", read_register (regno));
996 puts_e7000debug (buf);
998 else if (regno == CCR_REGNUM)
1000 sprintf (buf, ".CCR %x\r", read_register (regno));
1001 puts_e7000debug (buf);
1003 #endif /* GDB_TARGET_IS_H8300 */
1005 #ifdef GDB_TARGET_IS_SH
1009 sprintf (buf, ".R%d %x\r", regno, read_register (regno));
1010 puts_e7000debug (buf);
1014 sprintf (buf, ".PC %x\r", read_register (regno));
1015 puts_e7000debug (buf);
1019 sprintf (buf, ".SR %x\r", read_register (regno));
1020 puts_e7000debug (buf);
1024 sprintf (buf, ".PR %x\r", read_register (regno));
1025 puts_e7000debug (buf);
1029 sprintf (buf, ".GBR %x\r", read_register (regno));
1030 puts_e7000debug (buf);
1034 sprintf (buf, ".VBR %x\r", read_register (regno));
1035 puts_e7000debug (buf);
1039 sprintf (buf, ".MACH %x\r", read_register (regno));
1040 puts_e7000debug (buf);
1044 sprintf (buf, ".MACL %x\r", read_register (regno));
1045 puts_e7000debug (buf);
1049 #endif /* GDB_TARGET_IS_SH */
1054 /* Get ready to modify the registers array. On machines which store
1055 individual registers, this doesn't need to do anything. On machines
1056 which store all the registers in one fell swoop, this makes sure
1057 that registers contains all the registers from the program being
1061 e7000_prepare_to_store ()
1063 /* Do nothing, since we can store individual regs */
1069 printf_unfiltered ("\tAttached to %s at %d baud.\n", dev_name, baudrate);
1073 stickbyte (where, what)
1077 static CONST char digs[] = "0123456789ABCDEF";
1079 where[0] = digs[(what >> 4) & 0xf];
1080 where[1] = digs[(what & 0xf) & 0xf];
1085 /* Write a small ammount of memory. */
1088 write_small (memaddr, myaddr, len)
1090 unsigned char *myaddr;
1096 for (i = 0; i < len; i++)
1098 if (((memaddr + i) & 3) == 0 && (i + 3 < len))
1100 /* Can be done with a long word */
1101 sprintf (buf, "m %x %x%02x%02x%02x;l\r",
1103 myaddr[i], myaddr[i + 1], myaddr[i + 2], myaddr[i + 3]);
1104 puts_e7000debug (buf);
1109 sprintf (buf, "m %x %x\r", memaddr + i, myaddr[i]);
1110 puts_e7000debug (buf);
1119 /* Write a large ammount of memory, this only works with the serial
1120 mode enabled. Command is sent as
1135 write_large (memaddr, myaddr, len)
1137 unsigned char *myaddr;
1141 #define maxstride 128
1144 puts_e7000debug ("IL ;S:FK\r");
1146 putchar_e7000 (ACK);
1149 for (i = 0; i < len; i += stride)
1151 char compose[maxstride * 2 + 50];
1152 int address = i + memaddr;
1159 if (stride > maxstride)
1162 compose[where++] = 'S';
1164 if (address >= 0xffffff)
1166 else if (address >= 0xffff)
1171 compose[where++] = alen - 1 + '0';
1172 /* Insert length. */
1173 check_sum += stickbyte (compose + where, alen + stride + 1);
1178 check_sum += stickbyte (compose + where, address >> (8 * (alen)));
1182 for (j = 0; j < stride; j++)
1184 check_sum += stickbyte (compose + where, myaddr[i + j]);
1187 stickbyte (compose + where, ~check_sum);
1189 compose[where++] = '\r';
1190 compose[where++] = '\n';
1191 compose[where++] = 0;
1193 SERIAL_WRITE (e7000_desc, compose, where);
1197 /* This is ok - nothing there */
1201 /* Hmm, it's trying to tell us something */
1203 error ("Error writing memory");
1207 printf_unfiltered ("@%d}@", j);
1208 while ((j = readchar (0)) > 0)
1210 printf_unfiltered ("@{%d}@",j);
1215 /* Send the trailer record */
1216 write_e7000 ("S70500000000FA\r");
1217 putchar_e7000 (CTRLZ);
1219 putchar_e7000 (ACK);
1225 /* Copy LEN bytes of data from debugger memory at MYADDR to inferior's
1226 memory at MEMADDR. Returns length moved.
1228 Can't use the Srecord load over ethernet, so don't use fast method
1232 e7000_write_inferior_memory (memaddr, myaddr, len)
1234 unsigned char *myaddr;
1237 if (len < 16 || using_tcp || using_pc)
1238 return write_small (memaddr, myaddr, len);
1240 return write_large (memaddr, myaddr, len);
1243 /* Read LEN bytes from inferior memory at MEMADDR. Put the result
1244 at debugger address MYADDR. Returns length moved.
1246 Small transactions we send
1253 e7000_read_inferior_memory (memaddr, myaddr, len)
1255 unsigned char *myaddr;
1262 /* Starting address of this pass. */
1264 /* printf("READ INF %x %x %d\n", memaddr, myaddr, len);*/
1265 if (((memaddr - 1) + len) < memaddr)
1271 sprintf (buf, "m %x;l\r", memaddr);
1272 puts_e7000debug (buf);
1274 for (count = 0; count < len; count += 4)
1276 /* Suck away the address */
1282 { /* Some kind of error */
1283 puts_e7000debug (".\r"); /* Some errors leave us in memory input mode */
1284 expect_full_prompt();
1290 /* Now read in the data */
1291 for (i = 0; i < 4; i++)
1294 if (count + i < len) {
1295 myaddr[count + i] = b;
1299 /* Skip the trailing ? and send a . to end and a cr for more */
1302 if (count + 4 >= len)
1303 puts_e7000debug(".\r");
1305 puts_e7000debug("\r");
1315 For large transfers we used to send
1318 d <addr> <endaddr>\r
1321 <ADDRESS> < D A T A > < ASCII CODE >
1322 00000000 5F FD FD FF DF 7F DF FF 01 00 01 00 02 00 08 04 "_..............."
1323 00000010 FF D7 FF 7F D7 F1 7F FF 00 05 00 00 08 00 40 00 "..............@."
1324 00000020 7F FD FF F7 7F FF FF F7 00 00 00 00 00 00 00 00 "................"
1326 A cost in chars for each transaction of 80 + 5*n-bytes.
1328 Large transactions could be done with the srecord load code, but
1329 there is a pause for a second before dumping starts, which slows the
1334 e7000_read_inferior_memory_large (memaddr, myaddr, len)
1336 unsigned char *myaddr;
1343 /* Starting address of this pass. */
1345 if (((memaddr - 1) + len) < memaddr)
1351 sprintf (buf, "d %x %x\r", memaddr, memaddr + len - 1);
1352 puts_e7000debug (buf);
1357 /* skip down to the first ">" */
1360 /* now skip to the end of that line */
1367 /* get rid of any white space before the address */
1371 /* Skip the address */
1374 /* read in the bytes on the line */
1375 while (c != '"' && count < len)
1381 myaddr[count++] = get_hex (&c);
1384 /* throw out the rest of the line */
1389 /* wait for the ":" prompt */
1399 fast_but_for_the_pause_e7000_read_inferior_memory (memaddr, myaddr, len)
1408 if (((memaddr - 1) + len) < memaddr)
1414 sprintf (buf, "is %x@%x:s\r", memaddr, len);
1415 puts_e7000debug (buf);
1421 error ("Memory read error");
1423 putchar_e7000 (ACK);
1436 case ENQ: /* ENQ, at the end */
1440 /* Start of an Srecord */
1445 case '7': /* Termination record, ignore */
1449 /* Header record - ignore it */
1461 alen = type - '0' + 1;
1465 addr = (addr << 8) + gbyte ();
1469 for (i = 0; i < length - 1; i++)
1470 myaddr[i + addr - memaddr] = gbyte ();
1472 gbyte (); /* Ignore checksum */
1478 putchar_e7000 (ACK);
1479 expect ("TOP ADDRESS =");
1480 expect ("END ADDRESS =");
1489 e7000_xfer_inferior_memory (memaddr, myaddr, len, write, target)
1491 unsigned char *myaddr;
1494 struct target_ops *target; /* ignored */
1497 return e7000_write_inferior_memory( memaddr, myaddr, len);
1500 return e7000_read_inferior_memory( memaddr, myaddr, len);
1502 return e7000_read_inferior_memory_large( memaddr, myaddr, len);
1506 e7000_kill (args, from_tty)
1513 e7000_load (args, from_tty)
1517 struct cleanup *old_chain;
1521 #define WRITESIZE 0x1000
1522 char buf[2 + 4 + 4 + WRITESIZE]; /* `DT' + <addr> + <len> + <data> */
1526 time_t start_time, end_time; /* Start and end times of download */
1527 unsigned long data_count; /* Number of bytes transferred to memory */
1528 int oldtimeout = timeout;
1530 timeout = remote_timeout;
1533 /* FIXME! change test to test for type of download */
1536 generic_load (args, from_tty);
1540 /* for direct tcp connections, we can do a fast binary download */
1547 while (*args != '\000')
1551 while (isspace (*args)) args++;
1555 while ((*args != '\000') && !isspace (*args)) args++;
1557 if (*args != '\000')
1562 else if (strncmp (arg, "-quiet", strlen (arg)) == 0)
1564 else if (strncmp (arg, "-nostart", strlen (arg)) == 0)
1567 error ("unknown option `%s'", arg);
1571 filename = get_exec_file (1);
1573 pbfd = bfd_openr (filename, gnutarget);
1576 perror_with_name (filename);
1579 old_chain = make_cleanup (bfd_close, pbfd);
1581 if (!bfd_check_format (pbfd, bfd_object))
1582 error ("\"%s\" is not an object file: %s", filename,
1583 bfd_errmsg (bfd_get_error ()));
1585 start_time = time (NULL);
1588 puts_e7000debug ("mw\r");
1592 for (section = pbfd->sections; section; section = section->next)
1594 if (bfd_get_section_flags (pbfd, section) & SEC_LOAD)
1596 bfd_vma section_address;
1597 bfd_size_type section_size;
1600 section_address = bfd_get_section_vma (pbfd, section);
1601 section_size = bfd_get_section_size_before_reloc (section);
1604 printf_filtered ("[Loading section %s at 0x%x (%d bytes)]\n",
1605 bfd_get_section_name (pbfd, section),
1611 data_count += section_size;
1613 while (section_size > 0)
1616 static char inds[] = "|/-\\";
1621 count = min (section_size, WRITESIZE);
1623 buf[2] = section_address >> 24;
1624 buf[3] = section_address >> 16;
1625 buf[4] = section_address >> 8;
1626 buf[5] = section_address;
1628 buf[6] = count >> 24;
1629 buf[7] = count >> 16;
1630 buf[8] = count >> 8;
1633 bfd_get_section_contents (pbfd, section, buf + 10, fptr, count);
1635 if (SERIAL_WRITE (e7000_desc, buf, count + 10))
1636 fprintf_unfiltered (gdb_stderr,
1637 "e7000_load: SERIAL_WRITE failed: %s\n",
1638 safe_strerror(errno));
1644 printf_unfiltered ("\r%c", inds[k++ % 4]);
1645 gdb_flush (gdb_stdout);
1648 section_address += count;
1650 section_size -= count;
1659 end_time = time (NULL);
1661 /* Finally, make the PC point at the start address */
1664 write_pc (bfd_get_start_address (exec_bfd));
1666 inferior_pid = 0; /* No process now */
1668 /* This is necessary because many things were based on the PC at the time that
1669 we attached to the monitor, which is no longer valid now that we have loaded
1670 new code (and just changed the PC). Another way to do this might be to call
1671 normal_stop, except that the stack may not be valid, and things would get
1672 horribly confused... */
1674 clear_symtab_users ();
1678 entry = bfd_get_start_address (pbfd);
1681 printf_unfiltered ("[Starting %s at 0x%x]\n", filename, entry);
1683 /* start_routine (entry);*/
1686 report_transfer_performance (data_count, start_time, end_time);
1688 do_cleanups (old_chain);
1689 timeout = oldtimeout;
1692 /* Clean up when a program exits.
1694 The program actually lives on in the remote processor's RAM, and may be
1695 run again without a download. Don't leave it full of breakpoint
1699 e7000_mourn_inferior ()
1701 remove_breakpoints ();
1702 unpush_target (&e7000_ops);
1703 generic_mourn_inferior (); /* Do all the proper things now */
1706 #define MAX_BREAKPOINTS 200
1707 #ifdef HARD_BREAKPOINTS
1708 #define MAX_E7000DEBUG_BREAKPOINTS (BC_BREAKPOINTS ? 5 : MAX_BREAKPOINTS)
1710 #define MAX_E7000DEBUG_BREAKPOINTS MAX_BREAKPOINTS
1713 extern int memory_breakpoint_size;
1715 /* Since we can change to soft breakpoints dynamically, we must define
1716 more than enough. Was breakaddr[MAX_E7000DEBUG_BREAKPOINTS]. */
1717 static CORE_ADDR breakaddr[MAX_BREAKPOINTS] = {0};
1720 e7000_insert_breakpoint (addr, shadow)
1722 unsigned char *shadow;
1727 static char nop[2] = NOP;
1730 for (i = 0; i <= MAX_E7000DEBUG_BREAKPOINTS; i++)
1731 if (breakaddr[i] == 0)
1733 breakaddr[i] = addr;
1734 /* Save old contents, and insert a nop in the space */
1735 #ifdef HARD_BREAKPOINTS
1738 sprintf (buf, "BC%d A=%x\r", i+1, addr);
1739 puts_e7000debug (buf);
1743 sprintf (buf, "B %x\r", addr);
1744 puts_e7000debug (buf);
1748 e7000_read_inferior_memory (addr, shadow, 2);
1749 e7000_write_inferior_memory (addr, nop, 2);
1752 sprintf (buf, "B %x\r", addr);
1753 puts_e7000debug (buf);
1759 error ("Too many breakpoints ( > %d) for the E7000\n",
1760 MAX_E7000DEBUG_BREAKPOINTS);
1765 e7000_remove_breakpoint (addr, shadow)
1767 unsigned char *shadow;
1772 for (i = 0; i < MAX_E7000DEBUG_BREAKPOINTS; i++)
1773 if (breakaddr[i] == addr)
1776 #ifdef HARD_BREAKPOINTS
1779 sprintf (buf, "BC%d - \r", i+1);
1780 puts_e7000debug (buf);
1784 sprintf (buf, "B - %x\r", addr);
1785 puts_e7000debug (buf);
1789 sprintf (buf, "B - %x\r", addr);
1790 puts_e7000debug (buf);
1794 /* Replace the insn under the break */
1795 e7000_write_inferior_memory (addr, shadow, 2);
1802 warning ("Can't find breakpoint associated with 0x%x\n", addr);
1806 /* Put a command string, in args, out to STDBUG. Output from STDBUG
1807 is placed on the users terminal until the prompt is seen. */
1810 e7000_command (args, fromtty)
1814 /* FIXME: arbitrary limit on length of args. */
1820 error ("e7000 target not open.");
1823 puts_e7000debug ("\r");
1827 sprintf (buf, "%s\r", args);
1828 puts_e7000debug (buf);
1833 expect_full_prompt ();
1836 printf_unfiltered ("\n");
1838 /* Who knows what the command did... */
1839 registers_changed ();
1844 e7000_drain_command (args, fromtty)
1851 puts_e7000debug("end\r");
1852 putchar_e7000 (CTRLC);
1854 while ((c = readchar (1) != -1))
1858 putchar_e7000(CTRLC);
1861 if (c > ' ' && c < 127)
1862 printf_unfiltered ("%c", c & 0xff);
1864 printf_unfiltered ("<%x>", c & 0xff);
1873 static char *strings[NITEMS] = {
1879 "ILLEGAL INSTRUCTION",
1886 for (i = 0; i < NITEMS; ++i)
1892 for (i = 0; i < NITEMS; i++)
1899 /* found one of the choices */
1911 /* Suck characters, if a string match, then return the strings index
1912 otherwise echo them. */
1922 char *buffer = saveaway;
1923 /* Count number of expect strings */
1925 for (n = 0; strings[n]; n++)
1927 ptr[n] = strings[n];
1938 printf_unfiltered ("[waiting for e7000...]\n");
1951 putchar_e7000 (CTRLC); /* interrupt the running program */
1955 for (i = 0; i < n; i++)
1962 /* Gone all the way */
1969 ptr[i] = strings[i];
1975 /* Save it up incase we find that there was no match */
1980 if (buffer != saveaway)
1983 printf_unfiltered ("%s", buffer);
1988 putchar_unfiltered (c);
1989 gdb_flush (gdb_stdout);
1995 /* We subtract two from the pc here rather than use
1996 DECR_PC_AFTER_BREAK since the e7000 doesn't always add two to the
1997 pc, and the simulators never do. */
2005 store_signed_integer (buf,
2006 REGISTER_RAW_SIZE(PC_REGNUM),
2007 read_register (PC_REGNUM) -2);
2008 supply_register (PC_REGNUM, buf);
2009 sprintf (buf2, ".PC %x\r", read_register (PC_REGNUM));
2010 puts_e7000debug (buf2);
2015 #define WAS_RUNNING 2
2018 static char *estrings[] = {
2026 /* Wait until the remote machine stops, then return, storing status in
2027 STATUS just as `wait' would. */
2030 e7000_wait (pid, status)
2032 struct target_waitstatus *status;
2036 int running_count = 0;
2041 /* Then echo chars until PC= string seen */
2042 gch (); /* Drop cr */
2043 gch (); /* and space */
2047 switch (expect_n (estrings))
2050 /* how did this happen ? */
2055 putchar_e7000 (CTRLC);
2063 if (running_count == 20)
2065 printf_unfiltered ("[running...]\n");
2075 /* Skip till the PC= */
2078 #ifdef GDB_TARGET_IS_SH
2079 wanted_nopc = want_nopc;
2080 if (target_architecture->arch == bfd_arch_sh)
2081 switch (target_architecture->mach)
2085 /* start-sanitize-sh4 */
2087 /* end-sanitize-sh4 */
2088 wanted_nopc = want_sh3_nopc;
2092 wanted_nopc = want_nopc_h8300s;
2094 wanted_nopc = want_nopc_h8300h);
2096 fetch_regs_from_dump (gch, wanted_nopc);
2098 /* And supply the extra ones the simulator uses */
2099 for (regno = NUM_REALREGS; regno < NUM_REGS; regno++)
2102 supply_register (regno, (char *) &buf);
2105 stop_reason = why_stop ();
2106 expect_full_prompt ();
2108 status->kind = TARGET_WAITKIND_STOPPED;
2109 status->value.sig = TARGET_SIGNAL_TRAP;
2111 switch (stop_reason)
2113 case 1: /* Breakpoint */
2114 write_pc (read_pc ()); /* PC is always off by 2 for breakpoints */
2115 status->value.sig = TARGET_SIGNAL_TRAP;
2117 case 0: /* Single step */
2118 status->value.sig = TARGET_SIGNAL_TRAP;
2120 case 2: /* Interrupt */
2123 status->value.sig = TARGET_SIGNAL_TRAP;
2128 status->value.sig = TARGET_SIGNAL_INT;
2134 printf_unfiltered ("a cycle address error?\n");
2135 status->value.sig = TARGET_SIGNAL_UNKNOWN;
2138 status->value.sig = TARGET_SIGNAL_ILL;
2141 status->value.sig = TARGET_SIGNAL_SEGV;
2143 case 7: /* Anything else (NITEMS + 1) */
2144 printf_unfiltered ("a write protect error?\n");
2145 status->value.sig = TARGET_SIGNAL_UNKNOWN;
2148 /* Get the user's attention - this should never happen. */
2155 /* Stop the running program. */
2160 /* Sending a ^C is supposed to stop the running program. */
2161 putchar_e7000 (CTRLC);
2164 /* Define the target subroutine names. */
2166 struct target_ops e7000_ops =
2169 "Remote Hitachi e7000 target",
2170 "Use a remote Hitachi e7000 ICE connected by a serial line,\n\
2171 or a network connection.\n\
2172 Arguments are the name of the device for the serial line,\n\
2173 the speed to connect at in bits per second.\n\
2175 target e7000 /dev/ttya 9600\n\
2176 target e7000 foobar",
2177 e7000_open, /* to_open */
2178 e7000_close, /* to_close */
2180 e7000_detach, /* to_detach */
2181 e7000_resume, /* to_resume */
2182 e7000_wait, /* to_wait */
2183 e7000_fetch_register, /* to_fetch_registers */
2184 e7000_store_register, /* to_store_registers */
2185 e7000_prepare_to_store, /* to_prepare_to_store */
2186 e7000_xfer_inferior_memory, /* to_xfer_memory */
2187 e7000_files_info, /* to_files_info */
2188 e7000_insert_breakpoint, /* to_insert_breakpoint */
2189 e7000_remove_breakpoint, /* to_remove_breakpoint */
2190 0, /* to_terminal_init */
2191 0, /* to_terminal_inferior */
2192 0, /* to_terminal_ours_for_output */
2193 0, /* to_terminal_ours */
2194 0, /* to_terminal_info */
2195 e7000_kill, /* to_kill */
2196 e7000_load, /* to_load */
2197 0, /* to_lookup_symbol */
2198 e7000_create_inferior, /* to_create_inferior */
2199 e7000_mourn_inferior, /* to_mourn_inferior */
2201 0, /* to_notice_signals */
2202 0, /* to_thread_alive */
2203 e7000_stop, /* to_stop */
2204 process_stratum, /* to_stratum */
2205 0, /* next (unused) */
2206 1, /* to_has_all_memory */
2207 1, /* to_has_memory */
2208 1, /* to_has_stack */
2209 1, /* to_has_registers */
2210 1, /* to_has_execution */
2211 0, /* to_sections */
2212 0, /* to_sections_end */
2213 OPS_MAGIC, /* Always the last thing */
2217 _initialize_remote_e7000 ()
2219 add_target (&e7000_ops);
2221 add_com ("e7000", class_obscure, e7000_command,
2222 "Send a command to the e7000 monitor.");
2224 add_com ("ftplogin", class_obscure, e7000_login_command,
2225 "Login to machine and change to directory.");
2227 add_com ("ftpload", class_obscure, e7000_ftp_command,
2228 "Fetch and load a file from previously described place.");
2230 add_com ("drain", class_obscure, e7000_drain_command,
2231 "Drain pending e7000 text buffers.");
2233 add_show_from_set (add_set_cmd ("usehardbreakpoints", no_class,
2234 var_integer, (char *)&use_hard_breakpoints,
2235 "Set use of hardware breakpoints for all breakpoints.\n", &setlist),