1 /* Remote debugging interface for Hitachi E7000 ICE, for GDB
2 Copyright 1993, 1994, 1996, 1997, 1998, 2000, 2001 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,
22 Boston, MA 02111-1307, USA. */
24 /* The E7000 is an in-circuit emulator for the Hitachi H8/300-H and
25 Hitachi-SH processor. It has serial port and a lan port.
27 The monitor command set makes it difficult to load large ammounts of
28 data over the lan without using ftp - so try not to issue load
29 commands when communicating over ethernet; use the ftpload command.
31 The monitor pauses for a second when dumping srecords to the serial
32 line too, so we use a slower per byte mechanism but without the
33 startup overhead. Even so, it's pretty slow... */
42 #include "gdb_string.h"
44 #include <sys/types.h>
46 #include "remote-utils.h"
54 #define HARD_BREAKPOINTS /* Now handled by set option. */
55 #define BC_BREAKPOINTS use_hard_breakpoints
63 /* This file is used by 2 different targets, sh-elf and h8300. The
64 h8300 is not multiarched and doesn't use the registers defined in
65 tm-sh.h. To avoid using a macro GDB_TARGET_IS_SH, we do runtime check
66 of the target, which requires that these namse below are always
67 defined also in the h8300 case. */
69 #if !defined (PR_REGNUM)
72 #if !defined (GBR_REGNUM)
75 #if !defined (VBR_REGNUM)
78 #if !defined (MACH_REGNUM)
79 #define MACH_REGNUM -1
81 #if !defined (MACL_REGNUM)
82 #define MACL_REGNUM -1
84 #if !defined (SR_REGNUM)
88 extern void notice_quit (void);
90 extern void report_transfer_performance (unsigned long, time_t, time_t);
92 extern char *sh_processor_type
;
94 /* Local function declarations. */
96 static void e7000_close (int);
98 static void e7000_fetch_register (int);
100 static void e7000_store_register (int);
102 static void e7000_command (char *, int);
104 static void e7000_login_command (char *, int);
106 static void e7000_ftp_command (char *, int);
108 static void e7000_drain_command (char *, int);
110 static void expect (char *);
112 static void expect_full_prompt (void);
114 static void expect_prompt (void);
116 static int e7000_parse_device (char *args
, char *dev_name
, int baudrate
);
119 static serial_t e7000_desc
;
121 /* Allow user to chose between using hardware breakpoints or memory. */
122 static int use_hard_breakpoints
= 0; /* use sw breakpoints by default */
124 /* Nonzero if using the tcp serial driver. */
126 static int using_tcp
; /* direct tcp connection to target */
127 static int using_tcp_remote
; /* indirect connection to target
128 via tcp to controller */
130 /* Nonzero if using the pc isa card. */
134 extern struct target_ops e7000_ops
; /* Forward declaration */
136 char *ENQSTRING
= "\005";
138 /* Nonzero if some routine (as opposed to the user) wants echoing.
139 FIXME: Do this reentrantly with an extra parameter. */
145 static int timeout
= 20;
147 /* Send data to e7000debug. */
150 puts_e7000debug (char *buf
)
153 error ("Use \"target e7000 ...\" first.");
156 printf_unfiltered ("Sending %s\n", buf
);
158 if (SERIAL_WRITE (e7000_desc
, buf
, strlen (buf
)))
159 fprintf_unfiltered (gdb_stderr
, "SERIAL_WRITE failed: %s\n", safe_strerror (errno
));
161 /* And expect to see it echoed, unless using the pc interface */
169 putchar_e7000 (int x
)
174 SERIAL_WRITE (e7000_desc
, b
, 1);
178 write_e7000 (char *s
)
180 SERIAL_WRITE (e7000_desc
, s
, strlen (s
));
191 /* Read a character from the remote system, doing all the fancy timeout
192 stuff. Handles serial errors and EOF. If TIMEOUT == 0, and no chars,
193 returns -1, else returns next char. Discards chars > 127. */
196 readchar (int timeout
)
202 c
= SERIAL_READCHAR (e7000_desc
, timeout
);
206 if (c
== SERIAL_TIMEOUT
)
211 error ("Timeout reading from remote system.");
214 error ("Serial communication error");
218 putchar_unfiltered (c
);
219 gdb_flush (gdb_stdout
);
229 static char b
[8][10];
241 sprintf (b
[p
], "<%d>", x
);
248 /* Scan input from the remote system, until STRING is found. If
249 DISCARD is non-zero, then discard non-matching input, else print it
250 out. Let the user break out immediately. */
253 expect (char *string
)
261 c
= readchar (timeout
);
268 putchar_e7000 (CTRLC
);
280 if (c
== '\r' || c
== '\n')
283 putchar_unfiltered ('\n');
289 putchar_unfiltered (c
);
291 gdb_flush (gdb_stdout
);
293 if (normal (c
) == normal (*p
++))
302 if (normal (c
) == normal (string
[0]))
308 /* Keep discarding input until we see the e7000 prompt.
310 The convention for dealing with the prompt is that you
312 o *then* wait for the prompt.
314 Thus the last thing that a procedure does with the serial line will
315 be an expect_prompt(). Exception: e7000_resume does not wait for
316 the prompt, because the terminal is being handed over to the
317 inferior. However, the next thing which happens after that is a
318 e7000_wait which does wait for the prompt. Note that this includes
319 abnormal exit, e.g. error(). This is necessary to prevent getting
320 into states from which we can't recover. */
329 expect_full_prompt (void)
335 convert_hex_digit (int ch
)
337 if (ch
>= '0' && ch
<= '9')
339 else if (ch
>= 'A' && ch
<= 'F')
340 return ch
- 'A' + 10;
341 else if (ch
>= 'a' && ch
<= 'f')
342 return ch
- 'a' + 10;
349 int value
= convert_hex_digit (*start
);
352 *start
= readchar (timeout
);
353 while ((try = convert_hex_digit (*start
)) >= 0)
357 *start
= readchar (timeout
);
363 /* Get N 32-bit words from remote, each preceded by a space, and put
364 them in registers starting at REGNO. */
367 get_hex_regs (int n
, int regno
)
372 for (i
= 0; i
< n
; i
++)
377 for (j
= 0; j
< 8; j
++)
378 val
= (val
<< 4) + get_hex_digit (j
== 0);
379 supply_register (regno
++, (char *) &val
);
384 /* This is called not only when we first attach, but also when the
385 user types "run" after having attached. */
388 e7000_create_inferior (char *execfile
, char *args
, char **env
)
393 error ("Can't pass arguments to remote E7000DEBUG process");
395 if (execfile
== 0 || exec_bfd
== 0)
396 error ("No executable file specified");
398 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
400 #ifdef CREATE_INFERIOR_HOOK
401 CREATE_INFERIOR_HOOK (0); /* No process-ID */
404 /* The "process" (board) is already stopped awaiting our commands, and
405 the program is already downloaded. We just set its PC and go. */
407 clear_proceed_status ();
409 /* Tell wait_for_inferior that we've started a new process. */
410 init_wait_for_inferior ();
412 /* Set up the "saved terminal modes" of the inferior
413 based on what modes we are starting it with. */
414 target_terminal_init ();
416 /* Install inferior's terminal modes. */
417 target_terminal_inferior ();
419 /* insert_step_breakpoint (); FIXME, do we need this? */
420 proceed ((CORE_ADDR
) entry_pt
, -1, 0); /* Let 'er rip... */
423 /* Open a connection to a remote debugger. NAME is the filename used
424 for communication. */
426 static int baudrate
= 9600;
427 static char dev_name
[100];
429 static char *machine
= "";
430 static char *user
= "";
431 static char *passwd
= "";
432 static char *dir
= "";
434 /* Grab the next token and buy some space for it */
444 while (*p
&& *p
== ' ')
447 while (*p
&& (*p
!= ' ' && *p
!= '\t'))
460 e7000_login_command (char *args
, int from_tty
)
464 machine
= next (&args
);
466 passwd
= next (&args
);
470 printf_unfiltered ("Set info to %s %s %s %s\n", machine
, user
, passwd
, dir
);
475 error ("Syntax is ftplogin <machine> <user> <passwd> <directory>");
479 /* Start an ftp transfer from the E7000 to a host */
482 e7000_ftp_command (char *args
, int from_tty
)
484 /* FIXME: arbitrary limit on machine names and such. */
487 int oldtimeout
= timeout
;
488 timeout
= remote_timeout
;
490 sprintf (buf
, "ftp %s\r", machine
);
491 puts_e7000debug (buf
);
492 expect (" Username : ");
493 sprintf (buf
, "%s\r", user
);
494 puts_e7000debug (buf
);
495 expect (" Password : ");
496 write_e7000 (passwd
);
498 expect ("success\r");
500 sprintf (buf
, "cd %s\r", dir
);
501 puts_e7000debug (buf
);
503 sprintf (buf
, "ll 0;s:%s\r", args
);
504 puts_e7000debug (buf
);
506 puts_e7000debug ("bye\r");
508 timeout
= oldtimeout
;
512 e7000_parse_device (char *args
, char *dev_name
, int baudrate
)
516 if (args
&& strcasecmp (args
, "pc") == 0)
518 strcpy (dev_name
, args
);
523 /* FIXME! temp hack to allow use with port master -
524 target tcp_remote <device> */
525 if (args
&& strncmp (args
, "tcp", 10) == 0)
528 n
= sscanf (args
, " %s %s %d %s", com_type
, dev_name
, &baudrate
, junk
);
529 using_tcp_remote
= 1;
534 n
= sscanf (args
, " %s %d %s", dev_name
, &baudrate
, junk
);
537 if (n
!= 1 && n
!= 2)
539 error ("Bad arguments. Usage:\ttarget e7000 <device> <speed>\n\
540 or \t\ttarget e7000 <host>[:<port>]\n\
541 or \t\ttarget e7000 tcp_remote <host>[:<port>]\n\
542 or \t\ttarget e7000 pc\n");
545 #if !defined(__GO32__) && !defined(_WIN32)
546 /* FIXME! test for ':' is ambiguous */
547 if (n
== 1 && strchr (dev_name
, ':') == 0)
549 /* Default to normal telnet port */
550 /* serial_open will use this to determine tcp communication */
551 strcat (dev_name
, ":23");
554 if (!using_tcp_remote
&& strchr (dev_name
, ':'))
561 /* Stub for catch_errors. */
564 e7000_start_remote (void *dummy
)
571 immediate_quit
++; /* Allow user to interrupt it */
573 /* Hello? Are you there? */
578 putchar_e7000 (CTRLC
);
579 while (!sync
&& ++try <= quit_trying
)
583 printf_unfiltered ("[waiting for e7000...]\n");
588 /* FIXME! this didn't seem right-> while (c != SERIAL_TIMEOUT)
589 * we get stuck in this loop ...
590 * We may never timeout, and never sync up :-(
592 while (!sync
&& c
!= -1)
597 putchar_unfiltered (c
);
598 gdb_flush (gdb_stdout
);
600 /* Shouldn't we either break here, or check for sync in inner loop? */
606 putchar_e7000 (CTRLC
);
614 putchar_e7000 (CTRLC
);
615 /* Was-> quit_flag = 0; */
617 quit_trying
= try + 1; /* we don't want to try anymore */
628 fprintf_unfiltered (gdb_stderr
, "Giving up after %d tries...\n", try);
629 error ("Unable to synchronize with target.\n");
632 puts_e7000debug ("\r");
634 puts_e7000debug ("b -\r"); /* Clear breakpoints */
639 /* This is really the job of start_remote however, that makes an assumption
640 that the target is about to print out a status message of some sort. That
641 doesn't happen here. */
643 flush_cached_frames ();
644 registers_changed ();
645 stop_pc
= read_pc ();
646 set_current_frame (create_new_frame (read_fp (), stop_pc
));
647 select_frame (get_current_frame (), 0);
648 print_stack_frame (selected_frame
, -1, 1);
654 e7000_open (char *args
, int from_tty
)
658 target_preopen (from_tty
);
660 n
= e7000_parse_device (args
, dev_name
, baudrate
);
662 push_target (&e7000_ops
);
664 e7000_desc
= SERIAL_OPEN (dev_name
);
667 perror_with_name (dev_name
);
669 SERIAL_SETBAUDRATE (e7000_desc
, baudrate
);
670 SERIAL_RAW (e7000_desc
);
672 #ifdef GDB_TARGET_IS_H8300
676 /* Start the remote connection; if error (0), discard this target.
677 In particular, if the user quits, be sure to discard it
678 (we'd be in an inconsistent state otherwise). */
679 if (!catch_errors (e7000_start_remote
, (char *) 0,
680 "Couldn't establish connection to remote target\n", RETURN_MASK_ALL
))
682 printf_filtered ("Remote target %s connected to %s\n", target_shortname
,
686 /* Close out all files and local state before this target loses control. */
689 e7000_close (int 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 (char *arg
, int from_tty
)
704 pop_target (); /* calls e7000_close to do the real work */
706 printf_unfiltered ("Ending remote %s debugging\n", target_shortname
);
709 /* Tell the remote machine to resume. */
712 e7000_resume (int pid
, int step
, enum target_signal sigal
)
715 puts_e7000debug ("S\r");
717 puts_e7000debug ("G\r");
720 /* Read the remote registers into the block REGS.
722 For the H8/300 a register dump looks like:
724 PC=00021A CCR=80:I*******
725 ER0 - ER3 0000000A 0000002E 0000002E 00000000
726 ER4 - ER7 00000000 00000000 00000000 00FFEFF6
732 char *want_h8300h
= "PC=%p CCR=%c\n\
733 ER0 - ER3 %0 %1 %2 %3\n\
734 ER4 - ER7 %4 %5 %6 %7\n";
736 char *want_nopc_h8300h
= "%p CCR=%c\n\
737 ER0 - ER3 %0 %1 %2 %3\n\
738 ER4 - ER7 %4 %5 %6 %7";
740 char *want_h8300s
= "PC=%p CCR=%c\n\
742 ER0 - ER3 %0 %1 %2 %3\n\
743 ER4 - ER7 %4 %5 %6 %7\n";
745 char *want_nopc_h8300s
= "%p CCR=%c EXR=%9\n\
746 ER0 - ER3 %0 %1 %2 %3\n\
747 ER4 - ER7 %4 %5 %6 %7";
749 char *want_sh
= "PC=%16 SR=%22\n\
750 PR=%17 GBR=%18 VBR=%19\n\
752 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
753 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n";
755 char *want_nopc_sh
= "%16 SR=%22\n\
756 PR=%17 GBR=%18 VBR=%19\n\
758 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
759 R8-15 %8 %9 %10 %11 %12 %13 %14 %15";
761 char *want_sh3
= "PC=%16 SR=%22\n\
762 PR=%17 GBR=%18 VBR=%19\n\
763 MACH=%20 MACL=%21 SSR=%23 SPC=%24\n\
764 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
765 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
766 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
767 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
768 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
769 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
771 char *want_nopc_sh3
= "%16 SR=%22\n\
772 PR=%17 GBR=%18 VBR=%19\n\
773 MACH=%20 MACL=%21 SSR=%22 SPC=%23\n\
774 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
775 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
776 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
777 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
778 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
779 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
784 return readchar (timeout
);
790 int high
= convert_hex_digit (gch ());
791 int low
= convert_hex_digit (gch ());
793 return (high
<< 4) + low
;
797 fetch_regs_from_dump (int (*nextchar
) (), char *want
)
800 char buf
[MAX_REGISTER_RAW_SIZE
];
802 int thischar
= nextchar ();
809 /* Skip to end of line and then eat all new line type stuff */
810 while (thischar
!= '\n' && thischar
!= '\r')
811 thischar
= nextchar ();
812 while (thischar
== '\n' || thischar
== '\r')
813 thischar
= nextchar ();
818 while (thischar
== ' '
822 thischar
= nextchar ();
827 if (*want
== thischar
)
831 thischar
= nextchar ();
834 else if (thischar
== ' ' || thischar
== '\n' || thischar
== '\r')
836 thischar
= nextchar ();
840 error ("out of sync in fetch registers wanted <%s>, got <%c 0x%x>",
841 want
, thischar
, thischar
);
846 /* Got a register command */
876 if (isdigit (want
[0]))
878 if (isdigit (want
[1]))
880 regno
= (want
[0] - '0') * 10 + want
[1] - '0';
885 regno
= want
[0] - '0';
891 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
893 store_signed_integer (buf
,
894 REGISTER_RAW_SIZE (regno
),
895 (LONGEST
) get_hex (&thischar
));
896 supply_register (regno
, buf
);
903 e7000_fetch_registers (void)
908 puts_e7000debug ("R\r");
910 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_sh
)
913 switch (TARGET_ARCHITECTURE
->mach
)
921 #ifdef GDB_TARGET_IS_H8300
922 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_h8300
)
925 wanted
= want_h8300s
;
927 wanted
= want_h8300h
;
931 fetch_regs_from_dump (gch
, wanted
);
933 /* And supply the extra ones the simulator uses */
934 for (regno
= NUM_REALREGS
; regno
< NUM_REGS
; regno
++)
938 supply_register (regno
, (char *) (&buf
));
942 /* Fetch register REGNO, or all registers if REGNO is -1. Returns
946 e7000_fetch_register (int regno
)
948 e7000_fetch_registers ();
951 /* Store the remote registers from the contents of the block REGS. */
954 e7000_store_registers (void)
958 for (regno
= 0; regno
< NUM_REALREGS
; regno
++)
959 e7000_store_register (regno
);
961 registers_changed ();
964 /* Store register REGNO, or all if REGNO == 0. Return errno value. */
967 e7000_store_register (int regno
)
973 e7000_store_registers ();
977 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_h8300
)
981 sprintf (buf
, ".ER%d %lx\r", regno
, read_register (regno
));
982 puts_e7000debug (buf
);
984 else if (regno
== PC_REGNUM
)
986 sprintf (buf
, ".PC %lx\r", read_register (regno
));
987 puts_e7000debug (buf
);
990 else if (regno
== CCR_REGNUM
)
992 sprintf (buf
, ".CCR %lx\r", read_register (regno
));
993 puts_e7000debug (buf
);
998 else if (TARGET_ARCHITECTURE
->arch
== bfd_arch_sh
)
1000 if (regno
== PC_REGNUM
)
1002 sprintf (buf
, ".PC %lx\r", read_register (regno
));
1003 puts_e7000debug (buf
);
1006 else if (regno
== SR_REGNUM
)
1008 sprintf (buf
, ".SR %lx\r", read_register (regno
));
1009 puts_e7000debug (buf
);
1012 else if (regno
== PR_REGNUM
)
1014 sprintf (buf
, ".PR %lx\r", read_register (regno
));
1015 puts_e7000debug (buf
);
1018 else if (regno
== GBR_REGNUM
)
1020 sprintf (buf
, ".GBR %lx\r", read_register (regno
));
1021 puts_e7000debug (buf
);
1024 else if (regno
== VBR_REGNUM
)
1026 sprintf (buf
, ".VBR %lx\r", read_register (regno
));
1027 puts_e7000debug (buf
);
1030 else if (regno
== MACH_REGNUM
)
1032 sprintf (buf
, ".MACH %lx\r", read_register (regno
));
1033 puts_e7000debug (buf
);
1036 else if (regno
== MACL_REGNUM
)
1038 sprintf (buf
, ".MACL %lx\r", read_register (regno
));
1039 puts_e7000debug (buf
);
1043 sprintf (buf
, ".R%d %lx\r", regno
, read_register (regno
));
1044 puts_e7000debug (buf
);
1051 /* Get ready to modify the registers array. On machines which store
1052 individual registers, this doesn't need to do anything. On machines
1053 which store all the registers in one fell swoop, this makes sure
1054 that registers contains all the registers from the program being
1058 e7000_prepare_to_store (void)
1060 /* Do nothing, since we can store individual regs */
1064 e7000_files_info (struct target_ops
*ops
)
1066 printf_unfiltered ("\tAttached to %s at %d baud.\n", dev_name
, baudrate
);
1070 stickbyte (char *where
, unsigned int what
)
1072 static CONST
char digs
[] = "0123456789ABCDEF";
1074 where
[0] = digs
[(what
>> 4) & 0xf];
1075 where
[1] = digs
[(what
& 0xf) & 0xf];
1080 /* Write a small ammount of memory. */
1083 write_small (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
)
1088 for (i
= 0; i
< len
; i
++)
1090 if (((memaddr
+ i
) & 3) == 0 && (i
+ 3 < len
))
1092 /* Can be done with a long word */
1093 sprintf (buf
, "m %lx %x%02x%02x%02x;l\r",
1095 myaddr
[i
], myaddr
[i
+ 1], myaddr
[i
+ 2], myaddr
[i
+ 3]);
1096 puts_e7000debug (buf
);
1101 sprintf (buf
, "m %lx %x\r", memaddr
+ i
, myaddr
[i
]);
1102 puts_e7000debug (buf
);
1111 /* Write a large ammount of memory, this only works with the serial
1112 mode enabled. Command is sent as
1127 write_large (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
)
1130 #define maxstride 128
1133 puts_e7000debug ("IL ;S:FK\r");
1135 putchar_e7000 (ACK
);
1138 for (i
= 0; i
< len
; i
+= stride
)
1140 char compose
[maxstride
* 2 + 50];
1141 int address
= i
+ memaddr
;
1148 if (stride
> maxstride
)
1151 compose
[where
++] = 'S';
1153 if (address
>= 0xffffff)
1155 else if (address
>= 0xffff)
1160 compose
[where
++] = alen
- 1 + '0';
1161 /* Insert length. */
1162 check_sum
+= stickbyte (compose
+ where
, alen
+ stride
+ 1);
1167 check_sum
+= stickbyte (compose
+ where
, address
>> (8 * (alen
)));
1171 for (j
= 0; j
< stride
; j
++)
1173 check_sum
+= stickbyte (compose
+ where
, myaddr
[i
+ j
]);
1176 stickbyte (compose
+ where
, ~check_sum
);
1178 compose
[where
++] = '\r';
1179 compose
[where
++] = '\n';
1180 compose
[where
++] = 0;
1182 SERIAL_WRITE (e7000_desc
, compose
, where
);
1186 /* This is ok - nothing there */
1190 /* Hmm, it's trying to tell us something */
1192 error ("Error writing memory");
1196 printf_unfiltered ("@%d}@", j
);
1197 while ((j
= readchar (0)) > 0)
1199 printf_unfiltered ("@{%d}@", j
);
1204 /* Send the trailer record */
1205 write_e7000 ("S70500000000FA\r");
1206 putchar_e7000 (CTRLZ
);
1208 putchar_e7000 (ACK
);
1214 /* Copy LEN bytes of data from debugger memory at MYADDR to inferior's
1215 memory at MEMADDR. Returns length moved.
1217 Can't use the Srecord load over ethernet, so don't use fast method
1221 e7000_write_inferior_memory (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
)
1223 if (len
< 16 || using_tcp
|| using_pc
)
1224 return write_small (memaddr
, myaddr
, len
);
1226 return write_large (memaddr
, myaddr
, len
);
1229 /* Read LEN bytes from inferior memory at MEMADDR. Put the result
1230 at debugger address MYADDR. Returns length moved.
1232 Small transactions we send
1239 e7000_read_inferior_memory (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
)
1245 /* Starting address of this pass. */
1247 /* printf("READ INF %x %x %d\n", memaddr, myaddr, len); */
1248 if (((memaddr
- 1) + len
) < memaddr
)
1254 sprintf (buf
, "m %lx;l\r", memaddr
);
1255 puts_e7000debug (buf
);
1257 for (count
= 0; count
< len
; count
+= 4)
1259 /* Suck away the address */
1265 { /* Some kind of error */
1266 puts_e7000debug (".\r"); /* Some errors leave us in memory input mode */
1267 expect_full_prompt ();
1273 /* Now read in the data */
1274 for (i
= 0; i
< 4; i
++)
1277 if (count
+ i
< len
)
1279 myaddr
[count
+ i
] = b
;
1283 /* Skip the trailing ? and send a . to end and a cr for more */
1286 if (count
+ 4 >= len
)
1287 puts_e7000debug (".\r");
1289 puts_e7000debug ("\r");
1299 For large transfers we used to send
1302 d <addr> <endaddr>\r
1305 <ADDRESS> < D A T A > < ASCII CODE >
1306 00000000 5F FD FD FF DF 7F DF FF 01 00 01 00 02 00 08 04 "_..............."
1307 00000010 FF D7 FF 7F D7 F1 7F FF 00 05 00 00 08 00 40 00 "..............@."
1308 00000020 7F FD FF F7 7F FF FF F7 00 00 00 00 00 00 00 00 "................"
1310 A cost in chars for each transaction of 80 + 5*n-bytes.
1312 Large transactions could be done with the srecord load code, but
1313 there is a pause for a second before dumping starts, which slows the
1318 e7000_read_inferior_memory_large (CORE_ADDR memaddr
, unsigned char *myaddr
,
1325 /* Starting address of this pass. */
1327 if (((memaddr
- 1) + len
) < memaddr
)
1333 sprintf (buf
, "d %lx %lx\r", memaddr
, memaddr
+ len
- 1);
1334 puts_e7000debug (buf
);
1339 /* skip down to the first ">" */
1342 /* now skip to the end of that line */
1349 /* get rid of any white space before the address */
1353 /* Skip the address */
1356 /* read in the bytes on the line */
1357 while (c
!= '"' && count
< len
)
1363 myaddr
[count
++] = get_hex (&c
);
1366 /* throw out the rest of the line */
1371 /* wait for the ":" prompt */
1381 fast_but_for_the_pause_e7000_read_inferior_memory (CORE_ADDR memaddr
,
1382 char *myaddr
, int len
)
1388 if (((memaddr
- 1) + len
) < memaddr
)
1394 sprintf (buf
, "is %x@%x:s\r", memaddr
, len
);
1395 puts_e7000debug (buf
);
1401 error ("Memory read error");
1403 putchar_e7000 (ACK
);
1416 case ENQ
: /* ENQ, at the end */
1420 /* Start of an Srecord */
1425 case '7': /* Termination record, ignore */
1429 /* Header record - ignore it */
1441 alen
= type
- '0' + 1;
1445 addr
= (addr
<< 8) + gbyte ();
1449 for (i
= 0; i
< length
- 1; i
++)
1450 myaddr
[i
+ addr
- memaddr
] = gbyte ();
1452 gbyte (); /* Ignore checksum */
1458 putchar_e7000 (ACK
);
1459 expect ("TOP ADDRESS =");
1460 expect ("END ADDRESS =");
1468 /* Transfer LEN bytes between GDB address MYADDR and target address
1469 MEMADDR. If WRITE is non-zero, transfer them to the target,
1470 otherwise transfer them from the target. TARGET is unused.
1472 Returns the number of bytes transferred. */
1475 e7000_xfer_inferior_memory (CORE_ADDR memaddr
, char *myaddr
,
1477 struct mem_attrib
*attrib ATTRIBUTE_UNUSED
,
1478 struct target_ops
*target ATTRIBUTE_UNUSED
)
1481 return e7000_write_inferior_memory (memaddr
, myaddr
, len
);
1483 return e7000_read_inferior_memory (memaddr
, myaddr
, len
);
1485 return e7000_read_inferior_memory_large (memaddr
, myaddr
, len
);
1494 e7000_load (char *args
, int from_tty
)
1496 struct cleanup
*old_chain
;
1500 #define WRITESIZE 0x1000
1501 char buf
[2 + 4 + 4 + WRITESIZE
]; /* `DT' + <addr> + <len> + <data> */
1505 time_t start_time
, end_time
; /* Start and end times of download */
1506 unsigned long data_count
; /* Number of bytes transferred to memory */
1507 int oldtimeout
= timeout
;
1509 timeout
= remote_timeout
;
1512 /* FIXME! change test to test for type of download */
1515 generic_load (args
, from_tty
);
1519 /* for direct tcp connections, we can do a fast binary download */
1526 while (*args
!= '\000')
1530 while (isspace (*args
))
1535 while ((*args
!= '\000') && !isspace (*args
))
1538 if (*args
!= '\000')
1543 else if (strncmp (arg
, "-quiet", strlen (arg
)) == 0)
1545 else if (strncmp (arg
, "-nostart", strlen (arg
)) == 0)
1548 error ("unknown option `%s'", arg
);
1552 filename
= get_exec_file (1);
1554 pbfd
= bfd_openr (filename
, gnutarget
);
1557 perror_with_name (filename
);
1560 old_chain
= make_cleanup_bfd_close (pbfd
);
1562 if (!bfd_check_format (pbfd
, bfd_object
))
1563 error ("\"%s\" is not an object file: %s", filename
,
1564 bfd_errmsg (bfd_get_error ()));
1566 start_time
= time (NULL
);
1569 puts_e7000debug ("mw\r");
1573 for (section
= pbfd
->sections
; section
; section
= section
->next
)
1575 if (bfd_get_section_flags (pbfd
, section
) & SEC_LOAD
)
1577 bfd_vma section_address
;
1578 bfd_size_type section_size
;
1581 section_address
= bfd_get_section_vma (pbfd
, section
);
1582 section_size
= bfd_get_section_size_before_reloc (section
);
1585 printf_filtered ("[Loading section %s at 0x%x (%ud bytes)]\n",
1586 bfd_get_section_name (pbfd
, section
),
1592 data_count
+= section_size
;
1594 while (section_size
> 0)
1597 static char inds
[] = "|/-\\";
1602 count
= min (section_size
, WRITESIZE
);
1604 buf
[2] = section_address
>> 24;
1605 buf
[3] = section_address
>> 16;
1606 buf
[4] = section_address
>> 8;
1607 buf
[5] = section_address
;
1609 buf
[6] = count
>> 24;
1610 buf
[7] = count
>> 16;
1611 buf
[8] = count
>> 8;
1614 bfd_get_section_contents (pbfd
, section
, buf
+ 10, fptr
, count
);
1616 if (SERIAL_WRITE (e7000_desc
, buf
, count
+ 10))
1617 fprintf_unfiltered (gdb_stderr
,
1618 "e7000_load: SERIAL_WRITE failed: %s\n",
1619 safe_strerror (errno
));
1625 printf_unfiltered ("\r%c", inds
[k
++ % 4]);
1626 gdb_flush (gdb_stdout
);
1629 section_address
+= count
;
1631 section_size
-= count
;
1640 end_time
= time (NULL
);
1642 /* Finally, make the PC point at the start address */
1645 write_pc (bfd_get_start_address (exec_bfd
));
1647 inferior_pid
= 0; /* No process now */
1649 /* This is necessary because many things were based on the PC at the time that
1650 we attached to the monitor, which is no longer valid now that we have loaded
1651 new code (and just changed the PC). Another way to do this might be to call
1652 normal_stop, except that the stack may not be valid, and things would get
1653 horribly confused... */
1655 clear_symtab_users ();
1659 entry
= bfd_get_start_address (pbfd
);
1662 printf_unfiltered ("[Starting %s at 0x%x]\n", filename
, entry
);
1664 /* start_routine (entry); */
1667 report_transfer_performance (data_count
, start_time
, end_time
);
1669 do_cleanups (old_chain
);
1670 timeout
= oldtimeout
;
1673 /* Clean up when a program exits.
1675 The program actually lives on in the remote processor's RAM, and may be
1676 run again without a download. Don't leave it full of breakpoint
1680 e7000_mourn_inferior (void)
1682 remove_breakpoints ();
1683 unpush_target (&e7000_ops
);
1684 generic_mourn_inferior (); /* Do all the proper things now */
1687 #define MAX_BREAKPOINTS 200
1688 #ifdef HARD_BREAKPOINTS
1689 #define MAX_E7000DEBUG_BREAKPOINTS (BC_BREAKPOINTS ? 5 : MAX_BREAKPOINTS)
1691 #define MAX_E7000DEBUG_BREAKPOINTS MAX_BREAKPOINTS
1694 /* Since we can change to soft breakpoints dynamically, we must define
1695 more than enough. Was breakaddr[MAX_E7000DEBUG_BREAKPOINTS]. */
1696 static CORE_ADDR breakaddr
[MAX_BREAKPOINTS
] =
1700 e7000_insert_breakpoint (CORE_ADDR addr
, char *shadow
)
1705 static char nop
[2] = NOP
;
1708 for (i
= 0; i
<= MAX_E7000DEBUG_BREAKPOINTS
; i
++)
1709 if (breakaddr
[i
] == 0)
1711 breakaddr
[i
] = addr
;
1712 /* Save old contents, and insert a nop in the space */
1713 #ifdef HARD_BREAKPOINTS
1716 sprintf (buf
, "BC%d A=%lx\r", i
+ 1, addr
);
1717 puts_e7000debug (buf
);
1721 sprintf (buf
, "B %lx\r", addr
);
1722 puts_e7000debug (buf
);
1726 e7000_read_inferior_memory (addr
, shadow
, 2);
1727 e7000_write_inferior_memory (addr
, nop
, 2);
1730 sprintf (buf
, "B %x\r", addr
);
1731 puts_e7000debug (buf
);
1737 error ("Too many breakpoints ( > %d) for the E7000\n",
1738 MAX_E7000DEBUG_BREAKPOINTS
);
1743 e7000_remove_breakpoint (CORE_ADDR addr
, char *shadow
)
1748 for (i
= 0; i
< MAX_E7000DEBUG_BREAKPOINTS
; i
++)
1749 if (breakaddr
[i
] == addr
)
1752 #ifdef HARD_BREAKPOINTS
1755 sprintf (buf
, "BC%d - \r", i
+ 1);
1756 puts_e7000debug (buf
);
1760 sprintf (buf
, "B - %lx\r", addr
);
1761 puts_e7000debug (buf
);
1765 sprintf (buf
, "B - %lx\r", addr
);
1766 puts_e7000debug (buf
);
1770 /* Replace the insn under the break */
1771 e7000_write_inferior_memory (addr
, shadow
, 2);
1778 warning ("Can't find breakpoint associated with 0x%lx\n", addr
);
1782 /* Put a command string, in args, out to STDBUG. Output from STDBUG
1783 is placed on the users terminal until the prompt is seen. */
1786 e7000_command (char *args
, int fromtty
)
1788 /* FIXME: arbitrary limit on length of args. */
1794 error ("e7000 target not open.");
1797 puts_e7000debug ("\r");
1801 sprintf (buf
, "%s\r", args
);
1802 puts_e7000debug (buf
);
1807 expect_full_prompt ();
1810 printf_unfiltered ("\n");
1812 /* Who knows what the command did... */
1813 registers_changed ();
1818 e7000_drain_command (char *args
, int fromtty
)
1822 puts_e7000debug ("end\r");
1823 putchar_e7000 (CTRLC
);
1825 while ((c
= readchar (1) != -1))
1829 putchar_e7000 (CTRLC
);
1832 if (c
> ' ' && c
< 127)
1833 printf_unfiltered ("%c", c
& 0xff);
1835 printf_unfiltered ("<%x>", c
& 0xff);
1844 static char *strings
[NITEMS
] =
1851 "ILLEGAL INSTRUCTION",
1858 for (i
= 0; i
< NITEMS
; ++i
)
1864 for (i
= 0; i
< NITEMS
; i
++)
1871 /* found one of the choices */
1883 /* Suck characters, if a string match, then return the strings index
1884 otherwise echo them. */
1887 expect_n (char **strings
)
1893 char *buffer
= saveaway
;
1894 /* Count number of expect strings */
1896 for (n
= 0; strings
[n
]; n
++)
1898 ptr
[n
] = strings
[n
];
1909 printf_unfiltered ("[waiting for e7000...]\n");
1922 putchar_e7000 (CTRLC
); /* interrupt the running program */
1926 for (i
= 0; i
< n
; i
++)
1933 /* Gone all the way */
1940 ptr
[i
] = strings
[i
];
1946 /* Save it up incase we find that there was no match */
1951 if (buffer
!= saveaway
)
1954 printf_unfiltered ("%s", buffer
);
1959 putchar_unfiltered (c
);
1960 gdb_flush (gdb_stdout
);
1966 /* We subtract two from the pc here rather than use
1967 DECR_PC_AFTER_BREAK since the e7000 doesn't always add two to the
1968 pc, and the simulators never do. */
1976 store_signed_integer (buf
,
1977 REGISTER_RAW_SIZE (PC_REGNUM
),
1978 read_register (PC_REGNUM
) - 2);
1979 supply_register (PC_REGNUM
, buf
);
1980 sprintf (buf2
, ".PC %lx\r", read_register (PC_REGNUM
));
1981 puts_e7000debug (buf2
);
1986 #define WAS_RUNNING 2
1989 static char *estrings
[] =
1998 /* Wait until the remote machine stops, then return, storing status in
1999 STATUS just as `wait' would. */
2002 e7000_wait (int pid
, struct target_waitstatus
*status
)
2006 int running_count
= 0;
2011 /* Then echo chars until PC= string seen */
2012 gch (); /* Drop cr */
2013 gch (); /* and space */
2017 switch (expect_n (estrings
))
2020 /* how did this happen ? */
2025 putchar_e7000 (CTRLC
);
2033 if (running_count
== 20)
2035 printf_unfiltered ("[running...]\n");
2045 /* Skip till the PC= */
2048 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_sh
)
2050 wanted_nopc
= want_nopc_sh
;
2051 switch (TARGET_ARCHITECTURE
->mach
)
2056 wanted_nopc
= want_nopc_sh3
;
2059 #ifdef GDB_TARGET_IS_H8300
2060 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_h8300
)
2063 wanted_nopc
= want_nopc_h8300s
;
2065 wanted_nopc
= want_nopc_h8300h
;
2068 fetch_regs_from_dump (gch
, wanted_nopc
);
2070 /* And supply the extra ones the simulator uses */
2071 for (regno
= NUM_REALREGS
; regno
< NUM_REGS
; regno
++)
2074 supply_register (regno
, (char *) &buf
);
2077 stop_reason
= why_stop ();
2078 expect_full_prompt ();
2080 status
->kind
= TARGET_WAITKIND_STOPPED
;
2081 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2083 switch (stop_reason
)
2085 case 1: /* Breakpoint */
2086 write_pc (read_pc ()); /* PC is always off by 2 for breakpoints */
2087 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2089 case 0: /* Single step */
2090 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2092 case 2: /* Interrupt */
2095 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2100 status
->value
.sig
= TARGET_SIGNAL_INT
;
2106 printf_unfiltered ("a cycle address error?\n");
2107 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2110 status
->value
.sig
= TARGET_SIGNAL_ILL
;
2113 status
->value
.sig
= TARGET_SIGNAL_SEGV
;
2115 case 7: /* Anything else (NITEMS + 1) */
2116 printf_unfiltered ("a write protect error?\n");
2117 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2120 /* Get the user's attention - this should never happen. */
2121 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
2127 /* Stop the running program. */
2132 /* Sending a ^C is supposed to stop the running program. */
2133 putchar_e7000 (CTRLC
);
2136 /* Define the target subroutine names. */
2138 struct target_ops e7000_ops
;
2141 init_e7000_ops (void)
2143 e7000_ops
.to_shortname
= "e7000";
2144 e7000_ops
.to_longname
= "Remote Hitachi e7000 target";
2145 e7000_ops
.to_doc
= "Use a remote Hitachi e7000 ICE connected by a serial line;\n\
2146 or a network connection.\n\
2147 Arguments are the name of the device for the serial line,\n\
2148 the speed to connect at in bits per second.\n\
2150 target e7000 /dev/ttya 9600\n\
2151 target e7000 foobar";
2152 e7000_ops
.to_open
= e7000_open
;
2153 e7000_ops
.to_close
= e7000_close
;
2154 e7000_ops
.to_attach
= 0;
2155 e7000_ops
.to_post_attach
= NULL
;
2156 e7000_ops
.to_require_attach
= NULL
;
2157 e7000_ops
.to_detach
= e7000_detach
;
2158 e7000_ops
.to_require_detach
= NULL
;
2159 e7000_ops
.to_resume
= e7000_resume
;
2160 e7000_ops
.to_wait
= e7000_wait
;
2161 e7000_ops
.to_post_wait
= NULL
;
2162 e7000_ops
.to_fetch_registers
= e7000_fetch_register
;
2163 e7000_ops
.to_store_registers
= e7000_store_register
;
2164 e7000_ops
.to_prepare_to_store
= e7000_prepare_to_store
;
2165 e7000_ops
.to_xfer_memory
= e7000_xfer_inferior_memory
;
2166 e7000_ops
.to_files_info
= e7000_files_info
;
2167 e7000_ops
.to_insert_breakpoint
= e7000_insert_breakpoint
;
2168 e7000_ops
.to_remove_breakpoint
= e7000_remove_breakpoint
;
2169 e7000_ops
.to_terminal_init
= 0;
2170 e7000_ops
.to_terminal_inferior
= 0;
2171 e7000_ops
.to_terminal_ours_for_output
= 0;
2172 e7000_ops
.to_terminal_ours
= 0;
2173 e7000_ops
.to_terminal_info
= 0;
2174 e7000_ops
.to_kill
= e7000_kill
;
2175 e7000_ops
.to_load
= e7000_load
;
2176 e7000_ops
.to_lookup_symbol
= 0;
2177 e7000_ops
.to_create_inferior
= e7000_create_inferior
;
2178 e7000_ops
.to_post_startup_inferior
= NULL
;
2179 e7000_ops
.to_acknowledge_created_inferior
= NULL
;
2180 e7000_ops
.to_clone_and_follow_inferior
= NULL
;
2181 e7000_ops
.to_post_follow_inferior_by_clone
= NULL
;
2182 e7000_ops
.to_insert_fork_catchpoint
= NULL
;
2183 e7000_ops
.to_remove_fork_catchpoint
= NULL
;
2184 e7000_ops
.to_insert_vfork_catchpoint
= NULL
;
2185 e7000_ops
.to_remove_vfork_catchpoint
= NULL
;
2186 e7000_ops
.to_has_forked
= NULL
;
2187 e7000_ops
.to_has_vforked
= NULL
;
2188 e7000_ops
.to_can_follow_vfork_prior_to_exec
= NULL
;
2189 e7000_ops
.to_post_follow_vfork
= NULL
;
2190 e7000_ops
.to_insert_exec_catchpoint
= NULL
;
2191 e7000_ops
.to_remove_exec_catchpoint
= NULL
;
2192 e7000_ops
.to_has_execd
= NULL
;
2193 e7000_ops
.to_reported_exec_events_per_exec_call
= NULL
;
2194 e7000_ops
.to_has_exited
= NULL
;
2195 e7000_ops
.to_mourn_inferior
= e7000_mourn_inferior
;
2196 e7000_ops
.to_can_run
= 0;
2197 e7000_ops
.to_notice_signals
= 0;
2198 e7000_ops
.to_thread_alive
= 0;
2199 e7000_ops
.to_stop
= e7000_stop
;
2200 e7000_ops
.to_pid_to_exec_file
= NULL
;
2201 e7000_ops
.to_core_file_to_sym_file
= NULL
;
2202 e7000_ops
.to_stratum
= process_stratum
;
2203 e7000_ops
.DONT_USE
= 0;
2204 e7000_ops
.to_has_all_memory
= 1;
2205 e7000_ops
.to_has_memory
= 1;
2206 e7000_ops
.to_has_stack
= 1;
2207 e7000_ops
.to_has_registers
= 1;
2208 e7000_ops
.to_has_execution
= 1;
2209 e7000_ops
.to_sections
= 0;
2210 e7000_ops
.to_sections_end
= 0;
2211 e7000_ops
.to_magic
= OPS_MAGIC
;
2215 _initialize_remote_e7000 (void)
2218 add_target (&e7000_ops
);
2220 add_com ("e7000", class_obscure
, e7000_command
,
2221 "Send a command to the e7000 monitor.");
2223 add_com ("ftplogin", class_obscure
, e7000_login_command
,
2224 "Login to machine and change to directory.");
2226 add_com ("ftpload", class_obscure
, e7000_ftp_command
,
2227 "Fetch and load a file from previously described place.");
2229 add_com ("drain", class_obscure
, e7000_drain_command
,
2230 "Drain pending e7000 text buffers.");
2232 add_show_from_set (add_set_cmd ("usehardbreakpoints", no_class
,
2233 var_integer
, (char *) &use_hard_breakpoints
,
2234 "Set use of hardware breakpoints for all breakpoints.\n", &setlist
),