1 /* Remote debugging interface for Hitachi E7000 ICE, for GDB
2 Copyright 1993, 1994, 1996, 1997, 1998, 2000 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... */
44 #include "gdb_string.h"
46 #include <sys/types.h>
48 #include "remote-utils.h"
55 #define HARD_BREAKPOINTS /* Now handled by set option. */
56 #define BC_BREAKPOINTS use_hard_breakpoints
64 /* This file is used by 2 different targets, sh-elf and h8300. The
65 h8300 is not multiarched and doesn't use the registers defined in
66 tm-sh.h. To avoid using a macro GDB_TARGET_IS_SH, we do runtime check
67 of the target, which requires that these namse below are always
68 defined also in the h8300 case. */
70 #if !defined (PR_REGNUM)
73 #if !defined (GBR_REGNUM)
76 #if !defined (VBR_REGNUM)
79 #if !defined (MACH_REGNUM)
80 #define MACH_REGNUM -1
82 #if !defined (MACL_REGNUM)
83 #define MACL_REGNUM -1
85 #if !defined (SR_REGNUM)
89 extern void notice_quit (void);
91 extern void report_transfer_performance (unsigned long, time_t, time_t);
93 extern char *sh_processor_type
;
95 /* Local function declarations. */
97 static void e7000_close (int);
99 static void e7000_fetch_register (int);
101 static void e7000_store_register (int);
103 static void e7000_command (char *, int);
105 static void e7000_login_command (char *, int);
107 static void e7000_ftp_command (char *, int);
109 static void e7000_drain_command (char *, int);
111 static void expect (char *);
113 static void expect_full_prompt (void);
115 static void expect_prompt (void);
117 static int e7000_parse_device (char *args
, char *dev_name
, int baudrate
);
120 static serial_t e7000_desc
;
122 /* Allow user to chose between using hardware breakpoints or memory. */
123 static int use_hard_breakpoints
= 0; /* use sw breakpoints by default */
125 /* Nonzero if using the tcp serial driver. */
127 static int using_tcp
; /* direct tcp connection to target */
128 static int using_tcp_remote
; /* indirect connection to target
129 via tcp to controller */
131 /* Nonzero if using the pc isa card. */
135 extern struct target_ops e7000_ops
; /* Forward declaration */
137 char *ENQSTRING
= "\005";
139 /* Nonzero if some routine (as opposed to the user) wants echoing.
140 FIXME: Do this reentrantly with an extra parameter. */
146 static int timeout
= 20;
148 /* Send data to e7000debug. */
151 puts_e7000debug (buf
)
155 error ("Use \"target e7000 ...\" first.");
158 printf_unfiltered ("Sending %s\n", buf
);
160 if (SERIAL_WRITE (e7000_desc
, buf
, strlen (buf
)))
161 fprintf_unfiltered (gdb_stderr
, "SERIAL_WRITE failed: %s\n", safe_strerror (errno
));
163 /* And expect to see it echoed, unless using the pc interface */
177 SERIAL_WRITE (e7000_desc
, b
, 1);
184 SERIAL_WRITE (e7000_desc
, s
, strlen (s
));
196 /* Read a character from the remote system, doing all the fancy timeout
197 stuff. Handles serial errors and EOF. If TIMEOUT == 0, and no chars,
198 returns -1, else returns next char. Discards chars > 127. */
208 c
= SERIAL_READCHAR (e7000_desc
, timeout
);
212 if (c
== SERIAL_TIMEOUT
)
217 error ("Timeout reading from remote system.");
220 error ("Serial communication error");
224 putchar_unfiltered (c
);
225 gdb_flush (gdb_stdout
);
235 static char b
[8][10];
247 sprintf (b
[p
], "<%d>", x
);
254 /* Scan input from the remote system, until STRING is found. If
255 DISCARD is non-zero, then discard non-matching input, else print it
256 out. Let the user break out immediately. */
268 c
= readchar (timeout
);
275 putchar_e7000 (CTRLC
);
287 if (c
== '\r' || c
== '\n')
290 putchar_unfiltered ('\n');
296 putchar_unfiltered (c
);
298 gdb_flush (gdb_stdout
);
300 if (normal (c
) == normal (*p
++))
309 if (normal (c
) == normal (string
[0]))
315 /* Keep discarding input until we see the e7000 prompt.
317 The convention for dealing with the prompt is that you
319 o *then* wait for the prompt.
321 Thus the last thing that a procedure does with the serial line will
322 be an expect_prompt(). Exception: e7000_resume does not wait for
323 the prompt, because the terminal is being handed over to the
324 inferior. However, the next thing which happens after that is a
325 e7000_wait which does wait for the prompt. Note that this includes
326 abnormal exit, e.g. error(). This is necessary to prevent getting
327 into states from which we can't recover. */
336 expect_full_prompt ()
342 convert_hex_digit (ch
)
345 if (ch
>= '0' && ch
<= '9')
347 else if (ch
>= 'A' && ch
<= 'F')
348 return ch
- 'A' + 10;
349 else if (ch
>= 'a' && ch
<= 'f')
350 return ch
- 'a' + 10;
358 int value
= convert_hex_digit (*start
);
361 *start
= readchar (timeout
);
362 while ((try = convert_hex_digit (*start
)) >= 0)
366 *start
= readchar (timeout
);
372 /* Get N 32-bit words from remote, each preceded by a space, and put
373 them in registers starting at REGNO. */
376 get_hex_regs (n
, regno
)
383 for (i
= 0; i
< n
; i
++)
388 for (j
= 0; j
< 8; j
++)
389 val
= (val
<< 4) + get_hex_digit (j
== 0);
390 supply_register (regno
++, (char *) &val
);
395 /* This is called not only when we first attach, but also when the
396 user types "run" after having attached. */
399 e7000_create_inferior (execfile
, args
, env
)
407 error ("Can't pass arguments to remote E7000DEBUG process");
409 if (execfile
== 0 || exec_bfd
== 0)
410 error ("No executable file specified");
412 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
414 #ifdef CREATE_INFERIOR_HOOK
415 CREATE_INFERIOR_HOOK (0); /* No process-ID */
418 /* The "process" (board) is already stopped awaiting our commands, and
419 the program is already downloaded. We just set its PC and go. */
421 clear_proceed_status ();
423 /* Tell wait_for_inferior that we've started a new process. */
424 init_wait_for_inferior ();
426 /* Set up the "saved terminal modes" of the inferior
427 based on what modes we are starting it with. */
428 target_terminal_init ();
430 /* Install inferior's terminal modes. */
431 target_terminal_inferior ();
433 /* insert_step_breakpoint (); FIXME, do we need this? */
434 proceed ((CORE_ADDR
) entry_pt
, -1, 0); /* Let 'er rip... */
437 /* Open a connection to a remote debugger. NAME is the filename used
438 for communication. */
440 static int baudrate
= 9600;
441 static char dev_name
[100];
443 static char *machine
= "";
444 static char *user
= "";
445 static char *passwd
= "";
446 static char *dir
= "";
448 /* Grab the next token and buy some space for it */
459 while (*p
&& *p
== ' ')
462 while (*p
&& (*p
!= ' ' && *p
!= '\t'))
475 e7000_login_command (args
, from_tty
)
481 machine
= next (&args
);
483 passwd
= next (&args
);
487 printf_unfiltered ("Set info to %s %s %s %s\n", machine
, user
, passwd
, dir
);
492 error ("Syntax is ftplogin <machine> <user> <passwd> <directory>");
496 /* Start an ftp transfer from the E7000 to a host */
499 e7000_ftp_command (args
, from_tty
)
503 /* FIXME: arbitrary limit on machine names and such. */
506 int oldtimeout
= timeout
;
507 timeout
= remote_timeout
;
509 sprintf (buf
, "ftp %s\r", machine
);
510 puts_e7000debug (buf
);
511 expect (" Username : ");
512 sprintf (buf
, "%s\r", user
);
513 puts_e7000debug (buf
);
514 expect (" Password : ");
515 write_e7000 (passwd
);
517 expect ("success\r");
519 sprintf (buf
, "cd %s\r", dir
);
520 puts_e7000debug (buf
);
522 sprintf (buf
, "ll 0;s:%s\r", args
);
523 puts_e7000debug (buf
);
525 puts_e7000debug ("bye\r");
527 timeout
= oldtimeout
;
531 e7000_parse_device (args
, dev_name
, baudrate
)
538 if (args
&& strcasecmp (args
, "pc") == 0)
540 strcpy (dev_name
, args
);
545 /* FIXME! temp hack to allow use with port master -
546 target tcp_remote <device> */
547 if (args
&& strncmp (args
, "tcp", 10) == 0)
550 n
= sscanf (args
, " %s %s %d %s", com_type
, dev_name
, &baudrate
, junk
);
551 using_tcp_remote
= 1;
556 n
= sscanf (args
, " %s %d %s", dev_name
, &baudrate
, junk
);
559 if (n
!= 1 && n
!= 2)
561 error ("Bad arguments. Usage:\ttarget e7000 <device> <speed>\n\
562 or \t\ttarget e7000 <host>[:<port>]\n\
563 or \t\ttarget e7000 tcp_remote <host>[:<port>]\n\
564 or \t\ttarget e7000 pc\n");
567 #if !defined(__GO32__) && !defined(_WIN32)
568 /* FIXME! test for ':' is ambiguous */
569 if (n
== 1 && strchr (dev_name
, ':') == 0)
571 /* Default to normal telnet port */
572 /* serial_open will use this to determine tcp communication */
573 strcat (dev_name
, ":23");
576 if (!using_tcp_remote
&& strchr (dev_name
, ':'))
583 /* Stub for catch_errors. */
586 e7000_start_remote (dummy
)
594 immediate_quit
= 1; /* Allow user to interrupt it */
596 /* Hello? Are you there? */
601 putchar_e7000 (CTRLC
);
602 while (!sync
&& ++try <= quit_trying
)
606 printf_unfiltered ("[waiting for e7000...]\n");
611 /* FIXME! this didn't seem right-> while (c != SERIAL_TIMEOUT)
612 * we get stuck in this loop ...
613 * We may never timeout, and never sync up :-(
615 while (!sync
&& c
!= -1)
620 putchar_unfiltered (c
);
621 gdb_flush (gdb_stdout
);
623 /* Shouldn't we either break here, or check for sync in inner loop? */
629 putchar_e7000 (CTRLC
);
637 putchar_e7000 (CTRLC
);
638 /* Was-> quit_flag = 0; */
640 quit_trying
= try + 1; /* we don't want to try anymore */
651 fprintf_unfiltered (gdb_stderr
, "Giving up after %d tries...\n", try);
652 error ("Unable to syncronize with target.\n");
655 puts_e7000debug ("\r");
657 puts_e7000debug ("b -\r"); /* Clear breakpoints */
662 /* This is really the job of start_remote however, that makes an assumption
663 that the target is about to print out a status message of some sort. That
664 doesn't happen here. */
666 flush_cached_frames ();
667 registers_changed ();
668 stop_pc
= read_pc ();
669 set_current_frame (create_new_frame (read_fp (), stop_pc
));
670 select_frame (get_current_frame (), 0);
671 print_stack_frame (selected_frame
, -1, 1);
677 e7000_open (args
, from_tty
)
683 target_preopen (from_tty
);
685 n
= e7000_parse_device (args
, dev_name
, baudrate
);
687 push_target (&e7000_ops
);
689 e7000_desc
= SERIAL_OPEN (dev_name
);
692 perror_with_name (dev_name
);
694 SERIAL_SETBAUDRATE (e7000_desc
, baudrate
);
695 SERIAL_RAW (e7000_desc
);
697 #ifdef GDB_TARGET_IS_H8300
701 /* Start the remote connection; if error (0), discard this target.
702 In particular, if the user quits, be sure to discard it
703 (we'd be in an inconsistent state otherwise). */
704 if (!catch_errors (e7000_start_remote
, (char *) 0,
705 "Couldn't establish connection to remote target\n", RETURN_MASK_ALL
))
707 printf_filtered ("Remote target %s connected to %s\n", target_shortname
,
711 /* Close out all files and local state before this target loses control. */
714 e7000_close (quitting
)
719 SERIAL_CLOSE (e7000_desc
);
724 /* Terminate the open connection to the remote debugger. Use this
725 when you want to detach and do something else with your gdb. */
728 e7000_detach (from_tty
)
731 pop_target (); /* calls e7000_close to do the real work */
733 printf_unfiltered ("Ending remote %s debugging\n", target_shortname
);
736 /* Tell the remote machine to resume. */
739 e7000_resume (pid
, step
, sig
)
743 puts_e7000debug ("S\r");
745 puts_e7000debug ("G\r");
748 /* Read the remote registers into the block REGS.
750 For the H8/300 a register dump looks like:
752 PC=00021A CCR=80:I*******
753 ER0 - ER3 0000000A 0000002E 0000002E 00000000
754 ER4 - ER7 00000000 00000000 00000000 00FFEFF6
760 char *want_h8300h
= "PC=%p CCR=%c\n\
761 ER0 - ER3 %0 %1 %2 %3\n\
762 ER4 - ER7 %4 %5 %6 %7\n";
764 char *want_nopc_h8300h
= "%p CCR=%c\n\
765 ER0 - ER3 %0 %1 %2 %3\n\
766 ER4 - ER7 %4 %5 %6 %7";
768 char *want_h8300s
= "PC=%p CCR=%c\n\
770 ER0 - ER3 %0 %1 %2 %3\n\
771 ER4 - ER7 %4 %5 %6 %7\n";
773 char *want_nopc_h8300s
= "%p CCR=%c EXR=%9\n\
774 ER0 - ER3 %0 %1 %2 %3\n\
775 ER4 - ER7 %4 %5 %6 %7";
777 char *want_sh
= "PC=%16 SR=%22\n\
778 PR=%17 GBR=%18 VBR=%19\n\
780 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
781 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n";
783 char *want_nopc_sh
= "%16 SR=%22\n\
784 PR=%17 GBR=%18 VBR=%19\n\
786 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
787 R8-15 %8 %9 %10 %11 %12 %13 %14 %15";
789 char *want_sh3
= "PC=%16 SR=%22\n\
790 PR=%17 GBR=%18 VBR=%19\n\
791 MACH=%20 MACL=%21 SSR=%23 SPC=%24\n\
792 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
793 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
794 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
795 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
796 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
797 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
799 char *want_nopc_sh3
= "%16 SR=%22\n\
800 PR=%17 GBR=%18 VBR=%19\n\
801 MACH=%20 MACL=%21 SSR=%22 SPC=%23\n\
802 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
803 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
804 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
805 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
806 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
807 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
812 return readchar (timeout
);
818 int high
= convert_hex_digit (gch ());
819 int low
= convert_hex_digit (gch ());
821 return (high
<< 4) + low
;
825 fetch_regs_from_dump (nextchar
, want
)
830 char buf
[MAX_REGISTER_RAW_SIZE
];
832 int thischar
= nextchar ();
839 /* Skip to end of line and then eat all new line type stuff */
840 while (thischar
!= '\n' && thischar
!= '\r')
841 thischar
= nextchar ();
842 while (thischar
== '\n' || thischar
== '\r')
843 thischar
= nextchar ();
848 while (thischar
== ' '
852 thischar
= nextchar ();
857 if (*want
== thischar
)
861 thischar
= nextchar ();
864 else if (thischar
== ' ' || thischar
== '\n' || thischar
== '\r')
866 thischar
= nextchar ();
870 error ("out of sync in fetch registers wanted <%s>, got <%c 0x%x>",
871 want
, thischar
, thischar
);
876 /* Got a register command */
906 if (isdigit (want
[0]))
908 if (isdigit (want
[1]))
910 regno
= (want
[0] - '0') * 10 + want
[1] - '0';
915 regno
= want
[0] - '0';
923 store_signed_integer (buf
,
924 REGISTER_RAW_SIZE (regno
),
925 (LONGEST
) get_hex (&thischar
, nextchar
));
926 supply_register (regno
, buf
);
933 e7000_fetch_registers ()
938 puts_e7000debug ("R\r");
940 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_sh
)
943 switch (TARGET_ARCHITECTURE
->mach
)
951 #ifdef GDB_TARGET_IS_H8300
952 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_h8300
)
955 wanted
= want_h8300s
;
957 wanted
= want_h8300h
;
961 fetch_regs_from_dump (gch
, wanted
);
963 /* And supply the extra ones the simulator uses */
964 for (regno
= NUM_REALREGS
; regno
< NUM_REGS
; regno
++)
968 supply_register (regno
, (char *) (&buf
));
972 /* Fetch register REGNO, or all registers if REGNO is -1. Returns
976 e7000_fetch_register (regno
)
979 e7000_fetch_registers ();
982 /* Store the remote registers from the contents of the block REGS. */
985 e7000_store_registers ()
989 for (regno
= 0; regno
< NUM_REALREGS
; regno
++)
990 e7000_store_register (regno
);
992 registers_changed ();
995 /* Store register REGNO, or all if REGNO == 0. Return errno value. */
998 e7000_store_register (regno
)
1005 e7000_store_registers ();
1009 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_h8300
)
1013 sprintf (buf
, ".ER%d %lx\r", regno
, read_register (regno
));
1014 puts_e7000debug (buf
);
1016 else if (regno
== PC_REGNUM
)
1018 sprintf (buf
, ".PC %lx\r", read_register (regno
));
1019 puts_e7000debug (buf
);
1022 else if (regno
== CCR_REGNUM
)
1024 sprintf (buf
, ".CCR %lx\r", read_register (regno
));
1025 puts_e7000debug (buf
);
1030 else if (TARGET_ARCHITECTURE
->arch
== bfd_arch_sh
)
1032 if (regno
== PC_REGNUM
)
1034 sprintf (buf
, ".PC %lx\r", read_register (regno
));
1035 puts_e7000debug (buf
);
1038 else if (regno
== SR_REGNUM
)
1040 sprintf (buf
, ".SR %lx\r", read_register (regno
));
1041 puts_e7000debug (buf
);
1044 else if (regno
== PR_REGNUM
)
1046 sprintf (buf
, ".PR %lx\r", read_register (regno
));
1047 puts_e7000debug (buf
);
1050 else if (regno
== GBR_REGNUM
)
1052 sprintf (buf
, ".GBR %lx\r", read_register (regno
));
1053 puts_e7000debug (buf
);
1056 else if (regno
== VBR_REGNUM
)
1058 sprintf (buf
, ".VBR %lx\r", read_register (regno
));
1059 puts_e7000debug (buf
);
1062 else if (regno
== MACH_REGNUM
)
1064 sprintf (buf
, ".MACH %lx\r", read_register (regno
));
1065 puts_e7000debug (buf
);
1068 else if (regno
== MACL_REGNUM
)
1070 sprintf (buf
, ".MACL %lx\r", read_register (regno
));
1071 puts_e7000debug (buf
);
1075 sprintf (buf
, ".R%d %lx\r", regno
, read_register (regno
));
1076 puts_e7000debug (buf
);
1083 /* Get ready to modify the registers array. On machines which store
1084 individual registers, this doesn't need to do anything. On machines
1085 which store all the registers in one fell swoop, this makes sure
1086 that registers contains all the registers from the program being
1090 e7000_prepare_to_store ()
1092 /* Do nothing, since we can store individual regs */
1098 printf_unfiltered ("\tAttached to %s at %d baud.\n", dev_name
, baudrate
);
1102 stickbyte (where
, what
)
1106 static CONST
char digs
[] = "0123456789ABCDEF";
1108 where
[0] = digs
[(what
>> 4) & 0xf];
1109 where
[1] = digs
[(what
& 0xf) & 0xf];
1114 /* Write a small ammount of memory. */
1117 write_small (memaddr
, myaddr
, len
)
1119 unsigned char *myaddr
;
1125 for (i
= 0; i
< len
; i
++)
1127 if (((memaddr
+ i
) & 3) == 0 && (i
+ 3 < len
))
1129 /* Can be done with a long word */
1130 sprintf (buf
, "m %lx %x%02x%02x%02x;l\r",
1132 myaddr
[i
], myaddr
[i
+ 1], myaddr
[i
+ 2], myaddr
[i
+ 3]);
1133 puts_e7000debug (buf
);
1138 sprintf (buf
, "m %lx %x\r", memaddr
+ i
, myaddr
[i
]);
1139 puts_e7000debug (buf
);
1148 /* Write a large ammount of memory, this only works with the serial
1149 mode enabled. Command is sent as
1164 write_large (memaddr
, myaddr
, len
)
1166 unsigned char *myaddr
;
1170 #define maxstride 128
1173 puts_e7000debug ("IL ;S:FK\r");
1175 putchar_e7000 (ACK
);
1178 for (i
= 0; i
< len
; i
+= stride
)
1180 char compose
[maxstride
* 2 + 50];
1181 int address
= i
+ memaddr
;
1188 if (stride
> maxstride
)
1191 compose
[where
++] = 'S';
1193 if (address
>= 0xffffff)
1195 else if (address
>= 0xffff)
1200 compose
[where
++] = alen
- 1 + '0';
1201 /* Insert length. */
1202 check_sum
+= stickbyte (compose
+ where
, alen
+ stride
+ 1);
1207 check_sum
+= stickbyte (compose
+ where
, address
>> (8 * (alen
)));
1211 for (j
= 0; j
< stride
; j
++)
1213 check_sum
+= stickbyte (compose
+ where
, myaddr
[i
+ j
]);
1216 stickbyte (compose
+ where
, ~check_sum
);
1218 compose
[where
++] = '\r';
1219 compose
[where
++] = '\n';
1220 compose
[where
++] = 0;
1222 SERIAL_WRITE (e7000_desc
, compose
, where
);
1226 /* This is ok - nothing there */
1230 /* Hmm, it's trying to tell us something */
1232 error ("Error writing memory");
1236 printf_unfiltered ("@%d}@", j
);
1237 while ((j
= readchar (0)) > 0)
1239 printf_unfiltered ("@{%d}@", j
);
1244 /* Send the trailer record */
1245 write_e7000 ("S70500000000FA\r");
1246 putchar_e7000 (CTRLZ
);
1248 putchar_e7000 (ACK
);
1254 /* Copy LEN bytes of data from debugger memory at MYADDR to inferior's
1255 memory at MEMADDR. Returns length moved.
1257 Can't use the Srecord load over ethernet, so don't use fast method
1261 e7000_write_inferior_memory (memaddr
, myaddr
, len
)
1263 unsigned char *myaddr
;
1266 if (len
< 16 || using_tcp
|| using_pc
)
1267 return write_small (memaddr
, myaddr
, len
);
1269 return write_large (memaddr
, myaddr
, len
);
1272 /* Read LEN bytes from inferior memory at MEMADDR. Put the result
1273 at debugger address MYADDR. Returns length moved.
1275 Small transactions we send
1282 e7000_read_inferior_memory (memaddr
, myaddr
, len
)
1284 unsigned char *myaddr
;
1291 /* Starting address of this pass. */
1293 /* printf("READ INF %x %x %d\n", memaddr, myaddr, len); */
1294 if (((memaddr
- 1) + len
) < memaddr
)
1300 sprintf (buf
, "m %lx;l\r", memaddr
);
1301 puts_e7000debug (buf
);
1303 for (count
= 0; count
< len
; count
+= 4)
1305 /* Suck away the address */
1311 { /* Some kind of error */
1312 puts_e7000debug (".\r"); /* Some errors leave us in memory input mode */
1313 expect_full_prompt ();
1319 /* Now read in the data */
1320 for (i
= 0; i
< 4; i
++)
1323 if (count
+ i
< len
)
1325 myaddr
[count
+ i
] = b
;
1329 /* Skip the trailing ? and send a . to end and a cr for more */
1332 if (count
+ 4 >= len
)
1333 puts_e7000debug (".\r");
1335 puts_e7000debug ("\r");
1345 For large transfers we used to send
1348 d <addr> <endaddr>\r
1351 <ADDRESS> < D A T A > < ASCII CODE >
1352 00000000 5F FD FD FF DF 7F DF FF 01 00 01 00 02 00 08 04 "_..............."
1353 00000010 FF D7 FF 7F D7 F1 7F FF 00 05 00 00 08 00 40 00 "..............@."
1354 00000020 7F FD FF F7 7F FF FF F7 00 00 00 00 00 00 00 00 "................"
1356 A cost in chars for each transaction of 80 + 5*n-bytes.
1358 Large transactions could be done with the srecord load code, but
1359 there is a pause for a second before dumping starts, which slows the
1364 e7000_read_inferior_memory_large (memaddr
, myaddr
, len
)
1366 unsigned char *myaddr
;
1373 /* Starting address of this pass. */
1375 if (((memaddr
- 1) + len
) < memaddr
)
1381 sprintf (buf
, "d %lx %lx\r", memaddr
, memaddr
+ len
- 1);
1382 puts_e7000debug (buf
);
1387 /* skip down to the first ">" */
1390 /* now skip to the end of that line */
1397 /* get rid of any white space before the address */
1401 /* Skip the address */
1404 /* read in the bytes on the line */
1405 while (c
!= '"' && count
< len
)
1411 myaddr
[count
++] = get_hex (&c
);
1414 /* throw out the rest of the line */
1419 /* wait for the ":" prompt */
1429 fast_but_for_the_pause_e7000_read_inferior_memory (memaddr
, myaddr
, len
)
1438 if (((memaddr
- 1) + len
) < memaddr
)
1444 sprintf (buf
, "is %x@%x:s\r", memaddr
, len
);
1445 puts_e7000debug (buf
);
1451 error ("Memory read error");
1453 putchar_e7000 (ACK
);
1466 case ENQ
: /* ENQ, at the end */
1470 /* Start of an Srecord */
1475 case '7': /* Termination record, ignore */
1479 /* Header record - ignore it */
1491 alen
= type
- '0' + 1;
1495 addr
= (addr
<< 8) + gbyte ();
1499 for (i
= 0; i
< length
- 1; i
++)
1500 myaddr
[i
+ addr
- memaddr
] = gbyte ();
1502 gbyte (); /* Ignore checksum */
1508 putchar_e7000 (ACK
);
1509 expect ("TOP ADDRESS =");
1510 expect ("END ADDRESS =");
1519 e7000_xfer_inferior_memory (memaddr
, myaddr
, len
, write
, target
)
1521 unsigned char *myaddr
;
1524 struct target_ops
*target
; /* ignored */
1527 return e7000_write_inferior_memory (memaddr
, myaddr
, len
);
1529 return e7000_read_inferior_memory (memaddr
, myaddr
, len
);
1531 return e7000_read_inferior_memory_large (memaddr
, myaddr
, len
);
1535 e7000_kill (args
, from_tty
)
1542 e7000_load (args
, from_tty
)
1546 struct cleanup
*old_chain
;
1550 #define WRITESIZE 0x1000
1551 char buf
[2 + 4 + 4 + WRITESIZE
]; /* `DT' + <addr> + <len> + <data> */
1555 time_t start_time
, end_time
; /* Start and end times of download */
1556 unsigned long data_count
; /* Number of bytes transferred to memory */
1557 int oldtimeout
= timeout
;
1559 timeout
= remote_timeout
;
1562 /* FIXME! change test to test for type of download */
1565 generic_load (args
, from_tty
);
1569 /* for direct tcp connections, we can do a fast binary download */
1576 while (*args
!= '\000')
1580 while (isspace (*args
))
1585 while ((*args
!= '\000') && !isspace (*args
))
1588 if (*args
!= '\000')
1593 else if (strncmp (arg
, "-quiet", strlen (arg
)) == 0)
1595 else if (strncmp (arg
, "-nostart", strlen (arg
)) == 0)
1598 error ("unknown option `%s'", arg
);
1602 filename
= get_exec_file (1);
1604 pbfd
= bfd_openr (filename
, gnutarget
);
1607 perror_with_name (filename
);
1610 old_chain
= make_cleanup_bfd_close (pbfd
);
1612 if (!bfd_check_format (pbfd
, bfd_object
))
1613 error ("\"%s\" is not an object file: %s", filename
,
1614 bfd_errmsg (bfd_get_error ()));
1616 start_time
= time (NULL
);
1619 puts_e7000debug ("mw\r");
1623 for (section
= pbfd
->sections
; section
; section
= section
->next
)
1625 if (bfd_get_section_flags (pbfd
, section
) & SEC_LOAD
)
1627 bfd_vma section_address
;
1628 bfd_size_type section_size
;
1631 section_address
= bfd_get_section_vma (pbfd
, section
);
1632 section_size
= bfd_get_section_size_before_reloc (section
);
1635 printf_filtered ("[Loading section %s at 0x%x (%ud bytes)]\n",
1636 bfd_get_section_name (pbfd
, section
),
1642 data_count
+= section_size
;
1644 while (section_size
> 0)
1647 static char inds
[] = "|/-\\";
1652 count
= min (section_size
, WRITESIZE
);
1654 buf
[2] = section_address
>> 24;
1655 buf
[3] = section_address
>> 16;
1656 buf
[4] = section_address
>> 8;
1657 buf
[5] = section_address
;
1659 buf
[6] = count
>> 24;
1660 buf
[7] = count
>> 16;
1661 buf
[8] = count
>> 8;
1664 bfd_get_section_contents (pbfd
, section
, buf
+ 10, fptr
, count
);
1666 if (SERIAL_WRITE (e7000_desc
, buf
, count
+ 10))
1667 fprintf_unfiltered (gdb_stderr
,
1668 "e7000_load: SERIAL_WRITE failed: %s\n",
1669 safe_strerror (errno
));
1675 printf_unfiltered ("\r%c", inds
[k
++ % 4]);
1676 gdb_flush (gdb_stdout
);
1679 section_address
+= count
;
1681 section_size
-= count
;
1690 end_time
= time (NULL
);
1692 /* Finally, make the PC point at the start address */
1695 write_pc (bfd_get_start_address (exec_bfd
));
1697 inferior_pid
= 0; /* No process now */
1699 /* This is necessary because many things were based on the PC at the time that
1700 we attached to the monitor, which is no longer valid now that we have loaded
1701 new code (and just changed the PC). Another way to do this might be to call
1702 normal_stop, except that the stack may not be valid, and things would get
1703 horribly confused... */
1705 clear_symtab_users ();
1709 entry
= bfd_get_start_address (pbfd
);
1712 printf_unfiltered ("[Starting %s at 0x%x]\n", filename
, entry
);
1714 /* start_routine (entry); */
1717 report_transfer_performance (data_count
, start_time
, end_time
);
1719 do_cleanups (old_chain
);
1720 timeout
= oldtimeout
;
1723 /* Clean up when a program exits.
1725 The program actually lives on in the remote processor's RAM, and may be
1726 run again without a download. Don't leave it full of breakpoint
1730 e7000_mourn_inferior ()
1732 remove_breakpoints ();
1733 unpush_target (&e7000_ops
);
1734 generic_mourn_inferior (); /* Do all the proper things now */
1737 #define MAX_BREAKPOINTS 200
1738 #ifdef HARD_BREAKPOINTS
1739 #define MAX_E7000DEBUG_BREAKPOINTS (BC_BREAKPOINTS ? 5 : MAX_BREAKPOINTS)
1741 #define MAX_E7000DEBUG_BREAKPOINTS MAX_BREAKPOINTS
1744 /* Since we can change to soft breakpoints dynamically, we must define
1745 more than enough. Was breakaddr[MAX_E7000DEBUG_BREAKPOINTS]. */
1746 static CORE_ADDR breakaddr
[MAX_BREAKPOINTS
] =
1750 e7000_insert_breakpoint (addr
, shadow
)
1752 unsigned char *shadow
;
1757 static char nop
[2] = NOP
;
1760 for (i
= 0; i
<= MAX_E7000DEBUG_BREAKPOINTS
; i
++)
1761 if (breakaddr
[i
] == 0)
1763 breakaddr
[i
] = addr
;
1764 /* Save old contents, and insert a nop in the space */
1765 #ifdef HARD_BREAKPOINTS
1768 sprintf (buf
, "BC%d A=%lx\r", i
+ 1, addr
);
1769 puts_e7000debug (buf
);
1773 sprintf (buf
, "B %lx\r", addr
);
1774 puts_e7000debug (buf
);
1778 e7000_read_inferior_memory (addr
, shadow
, 2);
1779 e7000_write_inferior_memory (addr
, nop
, 2);
1782 sprintf (buf
, "B %x\r", addr
);
1783 puts_e7000debug (buf
);
1789 error ("Too many breakpoints ( > %d) for the E7000\n",
1790 MAX_E7000DEBUG_BREAKPOINTS
);
1795 e7000_remove_breakpoint (addr
, shadow
)
1797 unsigned char *shadow
;
1802 for (i
= 0; i
< MAX_E7000DEBUG_BREAKPOINTS
; i
++)
1803 if (breakaddr
[i
] == addr
)
1806 #ifdef HARD_BREAKPOINTS
1809 sprintf (buf
, "BC%d - \r", i
+ 1);
1810 puts_e7000debug (buf
);
1814 sprintf (buf
, "B - %lx\r", addr
);
1815 puts_e7000debug (buf
);
1819 sprintf (buf
, "B - %lx\r", addr
);
1820 puts_e7000debug (buf
);
1824 /* Replace the insn under the break */
1825 e7000_write_inferior_memory (addr
, shadow
, 2);
1832 warning ("Can't find breakpoint associated with 0x%lx\n", addr
);
1836 /* Put a command string, in args, out to STDBUG. Output from STDBUG
1837 is placed on the users terminal until the prompt is seen. */
1840 e7000_command (args
, fromtty
)
1844 /* FIXME: arbitrary limit on length of args. */
1850 error ("e7000 target not open.");
1853 puts_e7000debug ("\r");
1857 sprintf (buf
, "%s\r", args
);
1858 puts_e7000debug (buf
);
1863 expect_full_prompt ();
1866 printf_unfiltered ("\n");
1868 /* Who knows what the command did... */
1869 registers_changed ();
1874 e7000_drain_command (args
, fromtty
)
1881 puts_e7000debug ("end\r");
1882 putchar_e7000 (CTRLC
);
1884 while ((c
= readchar (1) != -1))
1888 putchar_e7000 (CTRLC
);
1891 if (c
> ' ' && c
< 127)
1892 printf_unfiltered ("%c", c
& 0xff);
1894 printf_unfiltered ("<%x>", c
& 0xff);
1903 static char *strings
[NITEMS
] =
1910 "ILLEGAL INSTRUCTION",
1917 for (i
= 0; i
< NITEMS
; ++i
)
1923 for (i
= 0; i
< NITEMS
; i
++)
1930 /* found one of the choices */
1942 /* Suck characters, if a string match, then return the strings index
1943 otherwise echo them. */
1953 char *buffer
= saveaway
;
1954 /* Count number of expect strings */
1956 for (n
= 0; strings
[n
]; n
++)
1958 ptr
[n
] = strings
[n
];
1969 printf_unfiltered ("[waiting for e7000...]\n");
1982 putchar_e7000 (CTRLC
); /* interrupt the running program */
1986 for (i
= 0; i
< n
; i
++)
1993 /* Gone all the way */
2000 ptr
[i
] = strings
[i
];
2006 /* Save it up incase we find that there was no match */
2011 if (buffer
!= saveaway
)
2014 printf_unfiltered ("%s", buffer
);
2019 putchar_unfiltered (c
);
2020 gdb_flush (gdb_stdout
);
2026 /* We subtract two from the pc here rather than use
2027 DECR_PC_AFTER_BREAK since the e7000 doesn't always add two to the
2028 pc, and the simulators never do. */
2036 store_signed_integer (buf
,
2037 REGISTER_RAW_SIZE (PC_REGNUM
),
2038 read_register (PC_REGNUM
) - 2);
2039 supply_register (PC_REGNUM
, buf
);
2040 sprintf (buf2
, ".PC %lx\r", read_register (PC_REGNUM
));
2041 puts_e7000debug (buf2
);
2046 #define WAS_RUNNING 2
2049 static char *estrings
[] =
2058 /* Wait until the remote machine stops, then return, storing status in
2059 STATUS just as `wait' would. */
2062 e7000_wait (pid
, status
)
2064 struct target_waitstatus
*status
;
2068 int running_count
= 0;
2073 /* Then echo chars until PC= string seen */
2074 gch (); /* Drop cr */
2075 gch (); /* and space */
2079 switch (expect_n (estrings
))
2082 /* how did this happen ? */
2087 putchar_e7000 (CTRLC
);
2095 if (running_count
== 20)
2097 printf_unfiltered ("[running...]\n");
2107 /* Skip till the PC= */
2110 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_sh
)
2112 wanted_nopc
= want_nopc_sh
;
2113 switch (TARGET_ARCHITECTURE
->mach
)
2118 wanted_nopc
= want_nopc_sh3
;
2121 #ifdef GDB_TARGET_IS_H8300
2122 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_h8300
)
2125 wanted_nopc
= want_nopc_h8300s
;
2127 wanted_nopc
= want_nopc_h8300h
;
2130 fetch_regs_from_dump (gch
, wanted_nopc
);
2132 /* And supply the extra ones the simulator uses */
2133 for (regno
= NUM_REALREGS
; regno
< NUM_REGS
; regno
++)
2136 supply_register (regno
, (char *) &buf
);
2139 stop_reason
= why_stop ();
2140 expect_full_prompt ();
2142 status
->kind
= TARGET_WAITKIND_STOPPED
;
2143 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2145 switch (stop_reason
)
2147 case 1: /* Breakpoint */
2148 write_pc (read_pc ()); /* PC is always off by 2 for breakpoints */
2149 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2151 case 0: /* Single step */
2152 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2154 case 2: /* Interrupt */
2157 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2162 status
->value
.sig
= TARGET_SIGNAL_INT
;
2168 printf_unfiltered ("a cycle address error?\n");
2169 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2172 status
->value
.sig
= TARGET_SIGNAL_ILL
;
2175 status
->value
.sig
= TARGET_SIGNAL_SEGV
;
2177 case 7: /* Anything else (NITEMS + 1) */
2178 printf_unfiltered ("a write protect error?\n");
2179 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2182 /* Get the user's attention - this should never happen. */
2189 /* Stop the running program. */
2194 /* Sending a ^C is supposed to stop the running program. */
2195 putchar_e7000 (CTRLC
);
2198 /* Define the target subroutine names. */
2200 struct target_ops e7000_ops
;
2203 init_e7000_ops (void)
2205 e7000_ops
.to_shortname
= "e7000";
2206 e7000_ops
.to_longname
= "Remote Hitachi e7000 target";
2207 e7000_ops
.to_doc
= "Use a remote Hitachi e7000 ICE connected by a serial line;\n\
2208 or a network connection.\n\
2209 Arguments are the name of the device for the serial line,\n\
2210 the speed to connect at in bits per second.\n\
2212 target e7000 /dev/ttya 9600\n\
2213 target e7000 foobar";
2214 e7000_ops
.to_open
= e7000_open
;
2215 e7000_ops
.to_close
= e7000_close
;
2216 e7000_ops
.to_attach
= 0;
2217 e7000_ops
.to_post_attach
= NULL
;
2218 e7000_ops
.to_require_attach
= NULL
;
2219 e7000_ops
.to_detach
= e7000_detach
;
2220 e7000_ops
.to_require_detach
= NULL
;
2221 e7000_ops
.to_resume
= e7000_resume
;
2222 e7000_ops
.to_wait
= e7000_wait
;
2223 e7000_ops
.to_post_wait
= NULL
;
2224 e7000_ops
.to_fetch_registers
= e7000_fetch_register
;
2225 e7000_ops
.to_store_registers
= e7000_store_register
;
2226 e7000_ops
.to_prepare_to_store
= e7000_prepare_to_store
;
2227 e7000_ops
.to_xfer_memory
= e7000_xfer_inferior_memory
;
2228 e7000_ops
.to_files_info
= e7000_files_info
;
2229 e7000_ops
.to_insert_breakpoint
= e7000_insert_breakpoint
;
2230 e7000_ops
.to_remove_breakpoint
= e7000_remove_breakpoint
;
2231 e7000_ops
.to_terminal_init
= 0;
2232 e7000_ops
.to_terminal_inferior
= 0;
2233 e7000_ops
.to_terminal_ours_for_output
= 0;
2234 e7000_ops
.to_terminal_ours
= 0;
2235 e7000_ops
.to_terminal_info
= 0;
2236 e7000_ops
.to_kill
= e7000_kill
;
2237 e7000_ops
.to_load
= e7000_load
;
2238 e7000_ops
.to_lookup_symbol
= 0;
2239 e7000_ops
.to_create_inferior
= e7000_create_inferior
;
2240 e7000_ops
.to_post_startup_inferior
= NULL
;
2241 e7000_ops
.to_acknowledge_created_inferior
= NULL
;
2242 e7000_ops
.to_clone_and_follow_inferior
= NULL
;
2243 e7000_ops
.to_post_follow_inferior_by_clone
= NULL
;
2244 e7000_ops
.to_insert_fork_catchpoint
= NULL
;
2245 e7000_ops
.to_remove_fork_catchpoint
= NULL
;
2246 e7000_ops
.to_insert_vfork_catchpoint
= NULL
;
2247 e7000_ops
.to_remove_vfork_catchpoint
= NULL
;
2248 e7000_ops
.to_has_forked
= NULL
;
2249 e7000_ops
.to_has_vforked
= NULL
;
2250 e7000_ops
.to_can_follow_vfork_prior_to_exec
= NULL
;
2251 e7000_ops
.to_post_follow_vfork
= NULL
;
2252 e7000_ops
.to_insert_exec_catchpoint
= NULL
;
2253 e7000_ops
.to_remove_exec_catchpoint
= NULL
;
2254 e7000_ops
.to_has_execd
= NULL
;
2255 e7000_ops
.to_reported_exec_events_per_exec_call
= NULL
;
2256 e7000_ops
.to_has_exited
= NULL
;
2257 e7000_ops
.to_mourn_inferior
= e7000_mourn_inferior
;
2258 e7000_ops
.to_can_run
= 0;
2259 e7000_ops
.to_notice_signals
= 0;
2260 e7000_ops
.to_thread_alive
= 0;
2261 e7000_ops
.to_stop
= e7000_stop
;
2262 e7000_ops
.to_pid_to_exec_file
= NULL
;
2263 e7000_ops
.to_core_file_to_sym_file
= NULL
;
2264 e7000_ops
.to_stratum
= process_stratum
;
2265 e7000_ops
.DONT_USE
= 0;
2266 e7000_ops
.to_has_all_memory
= 1;
2267 e7000_ops
.to_has_memory
= 1;
2268 e7000_ops
.to_has_stack
= 1;
2269 e7000_ops
.to_has_registers
= 1;
2270 e7000_ops
.to_has_execution
= 1;
2271 e7000_ops
.to_sections
= 0;
2272 e7000_ops
.to_sections_end
= 0;
2273 e7000_ops
.to_magic
= OPS_MAGIC
;
2277 _initialize_remote_e7000 ()
2280 add_target (&e7000_ops
);
2282 add_com ("e7000", class_obscure
, e7000_command
,
2283 "Send a command to the e7000 monitor.");
2285 add_com ("ftplogin", class_obscure
, e7000_login_command
,
2286 "Login to machine and change to directory.");
2288 add_com ("ftpload", class_obscure
, e7000_ftp_command
,
2289 "Fetch and load a file from previously described place.");
2291 add_com ("drain", class_obscure
, e7000_drain_command
,
2292 "Drain pending e7000 text buffers.");
2294 add_show_from_set (add_set_cmd ("usehardbreakpoints", no_class
,
2295 var_integer
, (char *) &use_hard_breakpoints
,
2296 "Set use of hardware breakpoints for all breakpoints.\n", &setlist
),