1 /* Remote debugging interface for Hitachi E7000 ICE, for GDB
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Contributed by Cygnus Support.
6 Written by Steve Chamberlain for Cygnus Support.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* The E7000 is an in-circuit emulator for the Hitachi H8/300-H and
26 Hitachi-SH processor. It has serial port and a lan port.
28 The monitor command set makes it difficult to load large ammounts of
29 data over the lan without using ftp - so try not to issue load
30 commands when communicating over ethernet; use the ftpload command.
32 The monitor pauses for a second when dumping srecords to the serial
33 line too, so we use a slower per byte mechanism but without the
34 startup overhead. Even so, it's pretty slow... */
43 #include "gdb_string.h"
45 #include <sys/types.h>
47 #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 report_transfer_performance (unsigned long, time_t, time_t);
91 extern char *sh_processor_type
;
93 /* Local function declarations. */
95 static void e7000_close (int);
97 static void e7000_fetch_register (int);
99 static void e7000_store_register (int);
101 static void e7000_command (char *, int);
103 static void e7000_login_command (char *, int);
105 static void e7000_ftp_command (char *, int);
107 static void e7000_drain_command (char *, int);
109 static void expect (char *);
111 static void expect_full_prompt (void);
113 static void expect_prompt (void);
115 static int e7000_parse_device (char *args
, char *dev_name
, int baudrate
);
118 static struct serial
*e7000_desc
;
120 /* Allow user to chose between using hardware breakpoints or memory. */
121 static int use_hard_breakpoints
= 0; /* use sw breakpoints by default */
123 /* Nonzero if using the tcp serial driver. */
125 static int using_tcp
; /* direct tcp connection to target */
126 static int using_tcp_remote
; /* indirect connection to target
127 via tcp to controller */
129 /* Nonzero if using the pc isa card. */
133 extern struct target_ops e7000_ops
; /* Forward declaration */
135 char *ENQSTRING
= "\005";
137 /* Nonzero if some routine (as opposed to the user) wants echoing.
138 FIXME: Do this reentrantly with an extra parameter. */
144 static int timeout
= 20;
146 /* Send data to e7000debug. */
149 puts_e7000debug (char *buf
)
152 error ("Use \"target e7000 ...\" first.");
155 printf_unfiltered ("Sending %s\n", buf
);
157 if (SERIAL_WRITE (e7000_desc
, buf
, strlen (buf
)))
158 fprintf_unfiltered (gdb_stderr
, "SERIAL_WRITE failed: %s\n", safe_strerror (errno
));
160 /* And expect to see it echoed, unless using the pc interface */
168 putchar_e7000 (int x
)
173 SERIAL_WRITE (e7000_desc
, b
, 1);
177 write_e7000 (char *s
)
179 SERIAL_WRITE (e7000_desc
, s
, strlen (s
));
190 /* Read a character from the remote system, doing all the fancy timeout
191 stuff. Handles serial errors and EOF. If TIMEOUT == 0, and no chars,
192 returns -1, else returns next char. Discards chars > 127. */
195 readchar (int timeout
)
201 c
= SERIAL_READCHAR (e7000_desc
, timeout
);
205 if (c
== SERIAL_TIMEOUT
)
210 error ("Timeout reading from remote system.");
213 error ("Serial communication error");
217 putchar_unfiltered (c
);
218 gdb_flush (gdb_stdout
);
228 static char b
[8][10];
240 sprintf (b
[p
], "<%d>", x
);
247 /* Scan input from the remote system, until STRING is found. If
248 DISCARD is non-zero, then discard non-matching input, else print it
249 out. Let the user break out immediately. */
252 expect (char *string
)
260 c
= readchar (timeout
);
264 if (c
== '\r' || c
== '\n')
267 putchar_unfiltered ('\n');
273 putchar_unfiltered (c
);
275 gdb_flush (gdb_stdout
);
277 if (normal (c
) == normal (*p
++))
286 if (normal (c
) == normal (string
[0]))
292 /* Keep discarding input until we see the e7000 prompt.
294 The convention for dealing with the prompt is that you
296 o *then* wait for the prompt.
298 Thus the last thing that a procedure does with the serial line will
299 be an expect_prompt(). Exception: e7000_resume does not wait for
300 the prompt, because the terminal is being handed over to the
301 inferior. However, the next thing which happens after that is a
302 e7000_wait which does wait for the prompt. Note that this includes
303 abnormal exit, e.g. error(). This is necessary to prevent getting
304 into states from which we can't recover. */
313 expect_full_prompt (void)
319 convert_hex_digit (int ch
)
321 if (ch
>= '0' && ch
<= '9')
323 else if (ch
>= 'A' && ch
<= 'F')
324 return ch
- 'A' + 10;
325 else if (ch
>= 'a' && ch
<= 'f')
326 return ch
- 'a' + 10;
333 int value
= convert_hex_digit (*start
);
336 *start
= readchar (timeout
);
337 while ((try = convert_hex_digit (*start
)) >= 0)
341 *start
= readchar (timeout
);
347 /* Get N 32-bit words from remote, each preceded by a space, and put
348 them in registers starting at REGNO. */
351 get_hex_regs (int n
, int regno
)
356 for (i
= 0; i
< n
; i
++)
361 for (j
= 0; j
< 8; j
++)
362 val
= (val
<< 4) + get_hex_digit (j
== 0);
363 supply_register (regno
++, (char *) &val
);
368 /* This is called not only when we first attach, but also when the
369 user types "run" after having attached. */
372 e7000_create_inferior (char *execfile
, char *args
, char **env
)
377 error ("Can't pass arguments to remote E7000DEBUG process");
379 if (execfile
== 0 || exec_bfd
== 0)
380 error ("No executable file specified");
382 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
384 #ifdef CREATE_INFERIOR_HOOK
385 CREATE_INFERIOR_HOOK (0); /* No process-ID */
388 /* The "process" (board) is already stopped awaiting our commands, and
389 the program is already downloaded. We just set its PC and go. */
391 clear_proceed_status ();
393 /* Tell wait_for_inferior that we've started a new process. */
394 init_wait_for_inferior ();
396 /* Set up the "saved terminal modes" of the inferior
397 based on what modes we are starting it with. */
398 target_terminal_init ();
400 /* Install inferior's terminal modes. */
401 target_terminal_inferior ();
403 /* insert_step_breakpoint (); FIXME, do we need this? */
404 proceed ((CORE_ADDR
) entry_pt
, -1, 0); /* Let 'er rip... */
407 /* Open a connection to a remote debugger. NAME is the filename used
408 for communication. */
410 static int baudrate
= 9600;
411 static char dev_name
[100];
413 static char *machine
= "";
414 static char *user
= "";
415 static char *passwd
= "";
416 static char *dir
= "";
418 /* Grab the next token and buy some space for it */
428 while (*p
&& *p
== ' ')
431 while (*p
&& (*p
!= ' ' && *p
!= '\t'))
444 e7000_login_command (char *args
, int from_tty
)
448 machine
= next (&args
);
450 passwd
= next (&args
);
454 printf_unfiltered ("Set info to %s %s %s %s\n", machine
, user
, passwd
, dir
);
459 error ("Syntax is ftplogin <machine> <user> <passwd> <directory>");
463 /* Start an ftp transfer from the E7000 to a host */
466 e7000_ftp_command (char *args
, int from_tty
)
468 /* FIXME: arbitrary limit on machine names and such. */
471 int oldtimeout
= timeout
;
472 timeout
= remote_timeout
;
474 sprintf (buf
, "ftp %s\r", machine
);
475 puts_e7000debug (buf
);
476 expect (" Username : ");
477 sprintf (buf
, "%s\r", user
);
478 puts_e7000debug (buf
);
479 expect (" Password : ");
480 write_e7000 (passwd
);
482 expect ("success\r");
484 sprintf (buf
, "cd %s\r", dir
);
485 puts_e7000debug (buf
);
487 sprintf (buf
, "ll 0;s:%s\r", args
);
488 puts_e7000debug (buf
);
490 puts_e7000debug ("bye\r");
492 timeout
= oldtimeout
;
496 e7000_parse_device (char *args
, char *dev_name
, int baudrate
)
500 if (args
&& strcasecmp (args
, "pc") == 0)
502 strcpy (dev_name
, args
);
507 /* FIXME! temp hack to allow use with port master -
508 target tcp_remote <device> */
509 if (args
&& strncmp (args
, "tcp", 10) == 0)
512 n
= sscanf (args
, " %s %s %d %s", com_type
, dev_name
, &baudrate
, junk
);
513 using_tcp_remote
= 1;
518 n
= sscanf (args
, " %s %d %s", dev_name
, &baudrate
, junk
);
521 if (n
!= 1 && n
!= 2)
523 error ("Bad arguments. Usage:\ttarget e7000 <device> <speed>\n\
524 or \t\ttarget e7000 <host>[:<port>]\n\
525 or \t\ttarget e7000 tcp_remote <host>[:<port>]\n\
526 or \t\ttarget e7000 pc\n");
529 #if !defined(__GO32__) && !defined(_WIN32) && !defined(__CYGWIN__)
530 /* FIXME! test for ':' is ambiguous */
531 if (n
== 1 && strchr (dev_name
, ':') == 0)
533 /* Default to normal telnet port */
534 /* serial_open will use this to determine tcp communication */
535 strcat (dev_name
, ":23");
538 if (!using_tcp_remote
&& strchr (dev_name
, ':'))
545 /* Stub for catch_errors. */
548 e7000_start_remote (void *dummy
)
555 immediate_quit
++; /* Allow user to interrupt it */
557 /* Hello? Are you there? */
562 putchar_e7000 (CTRLC
);
563 while (!sync
&& ++try <= quit_trying
)
567 printf_unfiltered ("[waiting for e7000...]\n");
572 /* FIXME! this didn't seem right-> while (c != SERIAL_TIMEOUT)
573 * we get stuck in this loop ...
574 * We may never timeout, and never sync up :-(
576 while (!sync
&& c
!= -1)
581 putchar_unfiltered (c
);
582 gdb_flush (gdb_stdout
);
584 /* Shouldn't we either break here, or check for sync in inner loop? */
590 putchar_e7000 (CTRLC
);
598 putchar_e7000 (CTRLC
);
599 /* Was-> quit_flag = 0; */
601 quit_trying
= try + 1; /* we don't want to try anymore */
612 fprintf_unfiltered (gdb_stderr
, "Giving up after %d tries...\n", try);
613 error ("Unable to synchronize with target.\n");
616 puts_e7000debug ("\r");
618 puts_e7000debug ("b -\r"); /* Clear breakpoints */
623 /* This is really the job of start_remote however, that makes an assumption
624 that the target is about to print out a status message of some sort. That
625 doesn't happen here. */
627 flush_cached_frames ();
628 registers_changed ();
629 stop_pc
= read_pc ();
630 set_current_frame (create_new_frame (read_fp (), stop_pc
));
631 select_frame (get_current_frame (), 0);
632 print_stack_frame (selected_frame
, -1, 1);
638 e7000_open (char *args
, int from_tty
)
642 target_preopen (from_tty
);
644 n
= e7000_parse_device (args
, dev_name
, baudrate
);
646 push_target (&e7000_ops
);
648 e7000_desc
= SERIAL_OPEN (dev_name
);
651 perror_with_name (dev_name
);
653 if (SERIAL_SETBAUDRATE (e7000_desc
, baudrate
))
655 SERIAL_CLOSE (e7000_desc
);
656 perror_with_name (dev_name
);
658 SERIAL_RAW (e7000_desc
);
660 #ifdef GDB_TARGET_IS_H8300
664 /* Start the remote connection; if error (0), discard this target.
665 In particular, if the user quits, be sure to discard it
666 (we'd be in an inconsistent state otherwise). */
667 if (!catch_errors (e7000_start_remote
, (char *) 0,
668 "Couldn't establish connection to remote target\n", RETURN_MASK_ALL
))
670 printf_filtered ("Remote target %s connected to %s\n", target_shortname
,
674 /* Close out all files and local state before this target loses control. */
677 e7000_close (int quitting
)
681 SERIAL_CLOSE (e7000_desc
);
686 /* Terminate the open connection to the remote debugger. Use this
687 when you want to detach and do something else with your gdb. */
690 e7000_detach (char *arg
, int from_tty
)
692 pop_target (); /* calls e7000_close to do the real work */
694 printf_unfiltered ("Ending remote %s debugging\n", target_shortname
);
697 /* Tell the remote machine to resume. */
700 e7000_resume (ptid_t ptid
, int step
, enum target_signal sigal
)
703 puts_e7000debug ("S\r");
705 puts_e7000debug ("G\r");
708 /* Read the remote registers into the block REGS.
710 For the H8/300 a register dump looks like:
712 PC=00021A CCR=80:I*******
713 ER0 - ER3 0000000A 0000002E 0000002E 00000000
714 ER4 - ER7 00000000 00000000 00000000 00FFEFF6
720 char *want_h8300h
= "PC=%p CCR=%c\n\
721 ER0 - ER3 %0 %1 %2 %3\n\
722 ER4 - ER7 %4 %5 %6 %7\n";
724 char *want_nopc_h8300h
= "%p CCR=%c\n\
725 ER0 - ER3 %0 %1 %2 %3\n\
726 ER4 - ER7 %4 %5 %6 %7";
728 char *want_h8300s
= "PC=%p CCR=%c\n\
730 ER0 - ER3 %0 %1 %2 %3\n\
731 ER4 - ER7 %4 %5 %6 %7\n";
733 char *want_nopc_h8300s
= "%p CCR=%c EXR=%9\n\
734 ER0 - ER3 %0 %1 %2 %3\n\
735 ER4 - ER7 %4 %5 %6 %7";
737 char *want_sh
= "PC=%16 SR=%22\n\
738 PR=%17 GBR=%18 VBR=%19\n\
740 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
741 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n";
743 char *want_nopc_sh
= "%16 SR=%22\n\
744 PR=%17 GBR=%18 VBR=%19\n\
746 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
747 R8-15 %8 %9 %10 %11 %12 %13 %14 %15";
749 char *want_sh3
= "PC=%16 SR=%22\n\
750 PR=%17 GBR=%18 VBR=%19\n\
751 MACH=%20 MACL=%21 SSR=%23 SPC=%24\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\
754 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
755 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
756 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
757 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
759 char *want_nopc_sh3
= "%16 SR=%22\n\
760 PR=%17 GBR=%18 VBR=%19\n\
761 MACH=%20 MACL=%21 SSR=%22 SPC=%23\n\
762 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
763 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
764 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
765 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
766 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
767 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
772 return readchar (timeout
);
778 int high
= convert_hex_digit (gch ());
779 int low
= convert_hex_digit (gch ());
781 return (high
<< 4) + low
;
785 fetch_regs_from_dump (int (*nextchar
) (), char *want
)
788 char buf
[MAX_REGISTER_RAW_SIZE
];
790 int thischar
= nextchar ();
793 internal_error (__FILE__
, __LINE__
, "Register set not selected.");
800 /* Skip to end of line and then eat all new line type stuff */
801 while (thischar
!= '\n' && thischar
!= '\r')
802 thischar
= nextchar ();
803 while (thischar
== '\n' || thischar
== '\r')
804 thischar
= nextchar ();
809 while (thischar
== ' '
813 thischar
= nextchar ();
818 if (*want
== thischar
)
822 thischar
= nextchar ();
825 else if (thischar
== ' ' || thischar
== '\n' || thischar
== '\r')
827 thischar
= nextchar ();
831 error ("out of sync in fetch registers wanted <%s>, got <%c 0x%x>",
832 want
, thischar
, thischar
);
837 /* Got a register command */
867 if (isdigit (want
[0]))
869 if (isdigit (want
[1]))
871 regno
= (want
[0] - '0') * 10 + want
[1] - '0';
876 regno
= want
[0] - '0';
882 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
884 store_signed_integer (buf
,
885 REGISTER_RAW_SIZE (regno
),
886 (LONGEST
) get_hex (&thischar
));
887 supply_register (regno
, buf
);
894 e7000_fetch_registers (void)
899 puts_e7000debug ("R\r");
901 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_sh
)
904 switch (TARGET_ARCHITECTURE
->mach
)
912 #ifdef GDB_TARGET_IS_H8300
913 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_h8300
)
916 wanted
= want_h8300s
;
918 wanted
= want_h8300h
;
922 fetch_regs_from_dump (gch
, wanted
);
924 /* And supply the extra ones the simulator uses */
925 for (regno
= NUM_REALREGS
; regno
< NUM_REGS
; regno
++)
929 supply_register (regno
, (char *) (&buf
));
933 /* Fetch register REGNO, or all registers if REGNO is -1. Returns
937 e7000_fetch_register (int regno
)
939 e7000_fetch_registers ();
942 /* Store the remote registers from the contents of the block REGS. */
945 e7000_store_registers (void)
949 for (regno
= 0; regno
< NUM_REALREGS
; regno
++)
950 e7000_store_register (regno
);
952 registers_changed ();
955 /* Store register REGNO, or all if REGNO == 0. Return errno value. */
958 e7000_store_register (int regno
)
964 e7000_store_registers ();
968 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_h8300
)
972 sprintf (buf
, ".ER%d %s\r", regno
, phex_nz (read_register (regno
), 0));
973 puts_e7000debug (buf
);
975 else if (regno
== PC_REGNUM
)
977 sprintf (buf
, ".PC %s\r", phex_nz (read_register (regno
), 0));
978 puts_e7000debug (buf
);
981 else if (regno
== CCR_REGNUM
)
983 sprintf (buf
, ".CCR %s\r", phex_nz (read_register (regno
), 0));
984 puts_e7000debug (buf
);
989 else if (TARGET_ARCHITECTURE
->arch
== bfd_arch_sh
)
991 if (regno
== PC_REGNUM
)
993 sprintf (buf
, ".PC %s\r", phex_nz (read_register (regno
), 0));
994 puts_e7000debug (buf
);
997 else if (regno
== SR_REGNUM
)
999 sprintf (buf
, ".SR %s\r", phex_nz (read_register (regno
), 0));
1000 puts_e7000debug (buf
);
1003 else if (regno
== PR_REGNUM
)
1005 sprintf (buf
, ".PR %s\r", phex_nz (read_register (regno
), 0));
1006 puts_e7000debug (buf
);
1009 else if (regno
== GBR_REGNUM
)
1011 sprintf (buf
, ".GBR %s\r", phex_nz (read_register (regno
), 0));
1012 puts_e7000debug (buf
);
1015 else if (regno
== VBR_REGNUM
)
1017 sprintf (buf
, ".VBR %s\r", phex_nz (read_register (regno
), 0));
1018 puts_e7000debug (buf
);
1021 else if (regno
== MACH_REGNUM
)
1023 sprintf (buf
, ".MACH %s\r", phex_nz (read_register (regno
), 0));
1024 puts_e7000debug (buf
);
1027 else if (regno
== MACL_REGNUM
)
1029 sprintf (buf
, ".MACL %s\r", phex_nz (read_register (regno
), 0));
1030 puts_e7000debug (buf
);
1034 sprintf (buf
, ".R%d %s\r", regno
, phex_nz (read_register (regno
), 0));
1035 puts_e7000debug (buf
);
1042 /* Get ready to modify the registers array. On machines which store
1043 individual registers, this doesn't need to do anything. On machines
1044 which store all the registers in one fell swoop, this makes sure
1045 that registers contains all the registers from the program being
1049 e7000_prepare_to_store (void)
1051 /* Do nothing, since we can store individual regs */
1055 e7000_files_info (struct target_ops
*ops
)
1057 printf_unfiltered ("\tAttached to %s at %d baud.\n", dev_name
, baudrate
);
1061 stickbyte (char *where
, unsigned int what
)
1063 static CONST
char digs
[] = "0123456789ABCDEF";
1065 where
[0] = digs
[(what
>> 4) & 0xf];
1066 where
[1] = digs
[(what
& 0xf) & 0xf];
1071 /* Write a small ammount of memory. */
1074 write_small (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
)
1079 for (i
= 0; i
< len
; i
++)
1081 if (((memaddr
+ i
) & 3) == 0 && (i
+ 3 < len
))
1083 /* Can be done with a long word */
1084 sprintf (buf
, "m %lx %x%02x%02x%02x;l\r",
1086 myaddr
[i
], myaddr
[i
+ 1], myaddr
[i
+ 2], myaddr
[i
+ 3]);
1087 puts_e7000debug (buf
);
1092 sprintf (buf
, "m %lx %x\r", memaddr
+ i
, myaddr
[i
]);
1093 puts_e7000debug (buf
);
1102 /* Write a large ammount of memory, this only works with the serial
1103 mode enabled. Command is sent as
1118 write_large (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
)
1121 #define maxstride 128
1124 puts_e7000debug ("IL ;S:FK\r");
1126 putchar_e7000 (ACK
);
1129 for (i
= 0; i
< len
; i
+= stride
)
1131 char compose
[maxstride
* 2 + 50];
1132 int address
= i
+ memaddr
;
1139 if (stride
> maxstride
)
1142 compose
[where
++] = 'S';
1144 if (address
>= 0xffffff)
1146 else if (address
>= 0xffff)
1151 compose
[where
++] = alen
- 1 + '0';
1152 /* Insert length. */
1153 check_sum
+= stickbyte (compose
+ where
, alen
+ stride
+ 1);
1158 check_sum
+= stickbyte (compose
+ where
, address
>> (8 * (alen
)));
1162 for (j
= 0; j
< stride
; j
++)
1164 check_sum
+= stickbyte (compose
+ where
, myaddr
[i
+ j
]);
1167 stickbyte (compose
+ where
, ~check_sum
);
1169 compose
[where
++] = '\r';
1170 compose
[where
++] = '\n';
1171 compose
[where
++] = 0;
1173 SERIAL_WRITE (e7000_desc
, compose
, where
);
1177 /* This is ok - nothing there */
1181 /* Hmm, it's trying to tell us something */
1183 error ("Error writing memory");
1187 printf_unfiltered ("@%d}@", j
);
1188 while ((j
= readchar (0)) > 0)
1190 printf_unfiltered ("@{%d}@", j
);
1195 /* Send the trailer record */
1196 write_e7000 ("S70500000000FA\r");
1197 putchar_e7000 (CTRLZ
);
1199 putchar_e7000 (ACK
);
1205 /* Copy LEN bytes of data from debugger memory at MYADDR to inferior's
1206 memory at MEMADDR. Returns length moved.
1208 Can't use the Srecord load over ethernet, so don't use fast method
1212 e7000_write_inferior_memory (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
)
1214 if (len
< 16 || using_tcp
|| using_pc
)
1215 return write_small (memaddr
, myaddr
, len
);
1217 return write_large (memaddr
, myaddr
, len
);
1220 /* Read LEN bytes from inferior memory at MEMADDR. Put the result
1221 at debugger address MYADDR. Returns length moved.
1223 Small transactions we send
1230 e7000_read_inferior_memory (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
)
1236 /* Starting address of this pass. */
1238 /* printf("READ INF %x %x %d\n", memaddr, myaddr, len); */
1239 if (((memaddr
- 1) + len
) < memaddr
)
1245 sprintf (buf
, "m %lx;l\r", memaddr
);
1246 puts_e7000debug (buf
);
1248 for (count
= 0; count
< len
; count
+= 4)
1250 /* Suck away the address */
1256 { /* Some kind of error */
1257 puts_e7000debug (".\r"); /* Some errors leave us in memory input mode */
1258 expect_full_prompt ();
1264 /* Now read in the data */
1265 for (i
= 0; i
< 4; i
++)
1268 if (count
+ i
< len
)
1270 myaddr
[count
+ i
] = b
;
1274 /* Skip the trailing ? and send a . to end and a cr for more */
1277 if (count
+ 4 >= len
)
1278 puts_e7000debug (".\r");
1280 puts_e7000debug ("\r");
1290 For large transfers we used to send
1293 d <addr> <endaddr>\r
1296 <ADDRESS> < D A T A > < ASCII CODE >
1297 00000000 5F FD FD FF DF 7F DF FF 01 00 01 00 02 00 08 04 "_..............."
1298 00000010 FF D7 FF 7F D7 F1 7F FF 00 05 00 00 08 00 40 00 "..............@."
1299 00000020 7F FD FF F7 7F FF FF F7 00 00 00 00 00 00 00 00 "................"
1301 A cost in chars for each transaction of 80 + 5*n-bytes.
1303 Large transactions could be done with the srecord load code, but
1304 there is a pause for a second before dumping starts, which slows the
1309 e7000_read_inferior_memory_large (CORE_ADDR memaddr
, unsigned char *myaddr
,
1316 /* Starting address of this pass. */
1318 if (((memaddr
- 1) + len
) < memaddr
)
1324 sprintf (buf
, "d %lx %lx\r", memaddr
, memaddr
+ len
- 1);
1325 puts_e7000debug (buf
);
1330 /* skip down to the first ">" */
1333 /* now skip to the end of that line */
1340 /* get rid of any white space before the address */
1344 /* Skip the address */
1347 /* read in the bytes on the line */
1348 while (c
!= '"' && count
< len
)
1354 myaddr
[count
++] = get_hex (&c
);
1357 /* throw out the rest of the line */
1362 /* wait for the ":" prompt */
1372 fast_but_for_the_pause_e7000_read_inferior_memory (CORE_ADDR memaddr
,
1373 char *myaddr
, int len
)
1379 if (((memaddr
- 1) + len
) < memaddr
)
1385 sprintf (buf
, "is %x@%x:s\r", memaddr
, len
);
1386 puts_e7000debug (buf
);
1392 error ("Memory read error");
1394 putchar_e7000 (ACK
);
1407 case ENQ
: /* ENQ, at the end */
1411 /* Start of an Srecord */
1416 case '7': /* Termination record, ignore */
1420 /* Header record - ignore it */
1432 alen
= type
- '0' + 1;
1436 addr
= (addr
<< 8) + gbyte ();
1440 for (i
= 0; i
< length
- 1; i
++)
1441 myaddr
[i
+ addr
- memaddr
] = gbyte ();
1443 gbyte (); /* Ignore checksum */
1449 putchar_e7000 (ACK
);
1450 expect ("TOP ADDRESS =");
1451 expect ("END ADDRESS =");
1459 /* Transfer LEN bytes between GDB address MYADDR and target address
1460 MEMADDR. If WRITE is non-zero, transfer them to the target,
1461 otherwise transfer them from the target. TARGET is unused.
1463 Returns the number of bytes transferred. */
1466 e7000_xfer_inferior_memory (CORE_ADDR memaddr
, char *myaddr
,
1468 struct mem_attrib
*attrib ATTRIBUTE_UNUSED
,
1469 struct target_ops
*target ATTRIBUTE_UNUSED
)
1472 return e7000_write_inferior_memory (memaddr
, myaddr
, len
);
1474 return e7000_read_inferior_memory (memaddr
, myaddr
, len
);
1476 return e7000_read_inferior_memory_large (memaddr
, myaddr
, len
);
1485 e7000_load (char *args
, int from_tty
)
1487 struct cleanup
*old_chain
;
1491 #define WRITESIZE 0x1000
1492 char buf
[2 + 4 + 4 + WRITESIZE
]; /* `DT' + <addr> + <len> + <data> */
1496 time_t start_time
, end_time
; /* Start and end times of download */
1497 unsigned long data_count
; /* Number of bytes transferred to memory */
1498 int oldtimeout
= timeout
;
1500 timeout
= remote_timeout
;
1503 /* FIXME! change test to test for type of download */
1506 generic_load (args
, from_tty
);
1510 /* for direct tcp connections, we can do a fast binary download */
1517 while (*args
!= '\000')
1521 while (isspace (*args
))
1526 while ((*args
!= '\000') && !isspace (*args
))
1529 if (*args
!= '\000')
1534 else if (strncmp (arg
, "-quiet", strlen (arg
)) == 0)
1536 else if (strncmp (arg
, "-nostart", strlen (arg
)) == 0)
1539 error ("unknown option `%s'", arg
);
1543 filename
= get_exec_file (1);
1545 pbfd
= bfd_openr (filename
, gnutarget
);
1548 perror_with_name (filename
);
1551 old_chain
= make_cleanup_bfd_close (pbfd
);
1553 if (!bfd_check_format (pbfd
, bfd_object
))
1554 error ("\"%s\" is not an object file: %s", filename
,
1555 bfd_errmsg (bfd_get_error ()));
1557 start_time
= time (NULL
);
1560 puts_e7000debug ("mw\r");
1564 for (section
= pbfd
->sections
; section
; section
= section
->next
)
1566 if (bfd_get_section_flags (pbfd
, section
) & SEC_LOAD
)
1568 bfd_vma section_address
;
1569 bfd_size_type section_size
;
1572 section_address
= bfd_get_section_vma (pbfd
, section
);
1573 section_size
= bfd_get_section_size_before_reloc (section
);
1576 printf_filtered ("[Loading section %s at 0x%s (%s bytes)]\n",
1577 bfd_get_section_name (pbfd
, section
),
1578 paddr_nz (section_address
),
1579 paddr_u (section_size
));
1583 data_count
+= section_size
;
1585 while (section_size
> 0)
1588 static char inds
[] = "|/-\\";
1593 count
= min (section_size
, WRITESIZE
);
1595 buf
[2] = section_address
>> 24;
1596 buf
[3] = section_address
>> 16;
1597 buf
[4] = section_address
>> 8;
1598 buf
[5] = section_address
;
1600 buf
[6] = count
>> 24;
1601 buf
[7] = count
>> 16;
1602 buf
[8] = count
>> 8;
1605 bfd_get_section_contents (pbfd
, section
, buf
+ 10, fptr
, count
);
1607 if (SERIAL_WRITE (e7000_desc
, buf
, count
+ 10))
1608 fprintf_unfiltered (gdb_stderr
,
1609 "e7000_load: SERIAL_WRITE failed: %s\n",
1610 safe_strerror (errno
));
1616 printf_unfiltered ("\r%c", inds
[k
++ % 4]);
1617 gdb_flush (gdb_stdout
);
1620 section_address
+= count
;
1622 section_size
-= count
;
1631 end_time
= time (NULL
);
1633 /* Finally, make the PC point at the start address */
1636 write_pc (bfd_get_start_address (exec_bfd
));
1638 inferior_ptid
= null_ptid
; /* No process now */
1640 /* This is necessary because many things were based on the PC at the time that
1641 we attached to the monitor, which is no longer valid now that we have loaded
1642 new code (and just changed the PC). Another way to do this might be to call
1643 normal_stop, except that the stack may not be valid, and things would get
1644 horribly confused... */
1646 clear_symtab_users ();
1650 entry
= bfd_get_start_address (pbfd
);
1653 printf_unfiltered ("[Starting %s at 0x%s]\n", filename
, paddr_nz (entry
));
1655 /* start_routine (entry); */
1658 report_transfer_performance (data_count
, start_time
, end_time
);
1660 do_cleanups (old_chain
);
1661 timeout
= oldtimeout
;
1664 /* Clean up when a program exits.
1666 The program actually lives on in the remote processor's RAM, and may be
1667 run again without a download. Don't leave it full of breakpoint
1671 e7000_mourn_inferior (void)
1673 remove_breakpoints ();
1674 unpush_target (&e7000_ops
);
1675 generic_mourn_inferior (); /* Do all the proper things now */
1678 #define MAX_BREAKPOINTS 200
1679 #ifdef HARD_BREAKPOINTS
1680 #define MAX_E7000DEBUG_BREAKPOINTS (BC_BREAKPOINTS ? 5 : MAX_BREAKPOINTS)
1682 #define MAX_E7000DEBUG_BREAKPOINTS MAX_BREAKPOINTS
1685 /* Since we can change to soft breakpoints dynamically, we must define
1686 more than enough. Was breakaddr[MAX_E7000DEBUG_BREAKPOINTS]. */
1687 static CORE_ADDR breakaddr
[MAX_BREAKPOINTS
] =
1691 e7000_insert_breakpoint (CORE_ADDR addr
, char *shadow
)
1696 static char nop
[2] = NOP
;
1699 for (i
= 0; i
<= MAX_E7000DEBUG_BREAKPOINTS
; i
++)
1700 if (breakaddr
[i
] == 0)
1702 breakaddr
[i
] = addr
;
1703 /* Save old contents, and insert a nop in the space */
1704 #ifdef HARD_BREAKPOINTS
1707 sprintf (buf
, "BC%d A=%lx\r", i
+ 1, addr
);
1708 puts_e7000debug (buf
);
1712 sprintf (buf
, "B %lx\r", addr
);
1713 puts_e7000debug (buf
);
1717 e7000_read_inferior_memory (addr
, shadow
, 2);
1718 e7000_write_inferior_memory (addr
, nop
, 2);
1721 sprintf (buf
, "B %x\r", addr
);
1722 puts_e7000debug (buf
);
1728 error ("Too many breakpoints ( > %d) for the E7000\n",
1729 MAX_E7000DEBUG_BREAKPOINTS
);
1734 e7000_remove_breakpoint (CORE_ADDR addr
, char *shadow
)
1739 for (i
= 0; i
< MAX_E7000DEBUG_BREAKPOINTS
; i
++)
1740 if (breakaddr
[i
] == addr
)
1743 #ifdef HARD_BREAKPOINTS
1746 sprintf (buf
, "BC%d - \r", i
+ 1);
1747 puts_e7000debug (buf
);
1751 sprintf (buf
, "B - %lx\r", addr
);
1752 puts_e7000debug (buf
);
1756 sprintf (buf
, "B - %lx\r", addr
);
1757 puts_e7000debug (buf
);
1761 /* Replace the insn under the break */
1762 e7000_write_inferior_memory (addr
, shadow
, 2);
1769 warning ("Can't find breakpoint associated with 0x%lx\n", addr
);
1773 /* Put a command string, in args, out to STDBUG. Output from STDBUG
1774 is placed on the users terminal until the prompt is seen. */
1777 e7000_command (char *args
, int fromtty
)
1779 /* FIXME: arbitrary limit on length of args. */
1785 error ("e7000 target not open.");
1788 puts_e7000debug ("\r");
1792 sprintf (buf
, "%s\r", args
);
1793 puts_e7000debug (buf
);
1798 expect_full_prompt ();
1801 printf_unfiltered ("\n");
1803 /* Who knows what the command did... */
1804 registers_changed ();
1809 e7000_drain_command (char *args
, int fromtty
)
1813 puts_e7000debug ("end\r");
1814 putchar_e7000 (CTRLC
);
1816 while ((c
= readchar (1) != -1))
1820 putchar_e7000 (CTRLC
);
1823 if (c
> ' ' && c
< 127)
1824 printf_unfiltered ("%c", c
& 0xff);
1826 printf_unfiltered ("<%x>", c
& 0xff);
1835 static char *strings
[NITEMS
] =
1842 "ILLEGAL INSTRUCTION",
1849 for (i
= 0; i
< NITEMS
; ++i
)
1855 for (i
= 0; i
< NITEMS
; i
++)
1862 /* found one of the choices */
1874 /* Suck characters, if a string match, then return the strings index
1875 otherwise echo them. */
1878 expect_n (char **strings
)
1884 char *buffer
= saveaway
;
1885 /* Count number of expect strings */
1887 for (n
= 0; strings
[n
]; n
++)
1889 ptr
[n
] = strings
[n
];
1900 printf_unfiltered ("[waiting for e7000...]\n");
1913 putchar_e7000 (CTRLC
); /* interrupt the running program */
1917 for (i
= 0; i
< n
; i
++)
1924 /* Gone all the way */
1931 ptr
[i
] = strings
[i
];
1937 /* Save it up incase we find that there was no match */
1942 if (buffer
!= saveaway
)
1945 printf_unfiltered ("%s", buffer
);
1950 putchar_unfiltered (c
);
1951 gdb_flush (gdb_stdout
);
1957 /* We subtract two from the pc here rather than use
1958 DECR_PC_AFTER_BREAK since the e7000 doesn't always add two to the
1959 pc, and the simulators never do. */
1967 store_signed_integer (buf
,
1968 REGISTER_RAW_SIZE (PC_REGNUM
),
1969 read_register (PC_REGNUM
) - 2);
1970 supply_register (PC_REGNUM
, buf
);
1971 sprintf (buf2
, ".PC %s\r", phex_nz (read_register (PC_REGNUM
), 0));
1972 puts_e7000debug (buf2
);
1977 #define WAS_RUNNING 2
1980 static char *estrings
[] =
1989 /* Wait until the remote machine stops, then return, storing status in
1990 STATUS just as `wait' would. */
1993 e7000_wait (ptid_t ptid
, struct target_waitstatus
*status
)
1997 int running_count
= 0;
2000 char *wanted_nopc
= NULL
;
2002 /* Then echo chars until PC= string seen */
2003 gch (); /* Drop cr */
2004 gch (); /* and space */
2008 switch (expect_n (estrings
))
2011 /* how did this happen ? */
2016 putchar_e7000 (CTRLC
);
2024 if (running_count
== 20)
2026 printf_unfiltered ("[running...]\n");
2036 /* Skip till the PC= */
2039 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_sh
)
2041 wanted_nopc
= want_nopc_sh
;
2042 switch (TARGET_ARCHITECTURE
->mach
)
2047 wanted_nopc
= want_nopc_sh3
;
2050 #ifdef GDB_TARGET_IS_H8300
2051 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_h8300
)
2054 wanted_nopc
= want_nopc_h8300s
;
2056 wanted_nopc
= want_nopc_h8300h
;
2059 fetch_regs_from_dump (gch
, wanted_nopc
);
2061 /* And supply the extra ones the simulator uses */
2062 for (regno
= NUM_REALREGS
; regno
< NUM_REGS
; regno
++)
2065 supply_register (regno
, (char *) &buf
);
2068 stop_reason
= why_stop ();
2069 expect_full_prompt ();
2071 status
->kind
= TARGET_WAITKIND_STOPPED
;
2072 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2074 switch (stop_reason
)
2076 case 1: /* Breakpoint */
2077 write_pc (read_pc ()); /* PC is always off by 2 for breakpoints */
2078 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2080 case 0: /* Single step */
2081 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2083 case 2: /* Interrupt */
2086 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2091 status
->value
.sig
= TARGET_SIGNAL_INT
;
2097 printf_unfiltered ("a cycle address error?\n");
2098 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2101 status
->value
.sig
= TARGET_SIGNAL_ILL
;
2104 status
->value
.sig
= TARGET_SIGNAL_SEGV
;
2106 case 7: /* Anything else (NITEMS + 1) */
2107 printf_unfiltered ("a write protect error?\n");
2108 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2111 /* Get the user's attention - this should never happen. */
2112 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
2115 return inferior_ptid
;
2118 /* Stop the running program. */
2123 /* Sending a ^C is supposed to stop the running program. */
2124 putchar_e7000 (CTRLC
);
2127 /* Define the target subroutine names. */
2129 struct target_ops e7000_ops
;
2132 init_e7000_ops (void)
2134 e7000_ops
.to_shortname
= "e7000";
2135 e7000_ops
.to_longname
= "Remote Hitachi e7000 target";
2136 e7000_ops
.to_doc
= "Use a remote Hitachi e7000 ICE connected by a serial line;\n\
2137 or a network connection.\n\
2138 Arguments are the name of the device for the serial line,\n\
2139 the speed to connect at in bits per second.\n\
2141 target e7000 /dev/ttya 9600\n\
2142 target e7000 foobar";
2143 e7000_ops
.to_open
= e7000_open
;
2144 e7000_ops
.to_close
= e7000_close
;
2145 e7000_ops
.to_attach
= 0;
2146 e7000_ops
.to_post_attach
= NULL
;
2147 e7000_ops
.to_require_attach
= NULL
;
2148 e7000_ops
.to_detach
= e7000_detach
;
2149 e7000_ops
.to_require_detach
= NULL
;
2150 e7000_ops
.to_resume
= e7000_resume
;
2151 e7000_ops
.to_wait
= e7000_wait
;
2152 e7000_ops
.to_post_wait
= NULL
;
2153 e7000_ops
.to_fetch_registers
= e7000_fetch_register
;
2154 e7000_ops
.to_store_registers
= e7000_store_register
;
2155 e7000_ops
.to_prepare_to_store
= e7000_prepare_to_store
;
2156 e7000_ops
.to_xfer_memory
= e7000_xfer_inferior_memory
;
2157 e7000_ops
.to_files_info
= e7000_files_info
;
2158 e7000_ops
.to_insert_breakpoint
= e7000_insert_breakpoint
;
2159 e7000_ops
.to_remove_breakpoint
= e7000_remove_breakpoint
;
2160 e7000_ops
.to_terminal_init
= 0;
2161 e7000_ops
.to_terminal_inferior
= 0;
2162 e7000_ops
.to_terminal_ours_for_output
= 0;
2163 e7000_ops
.to_terminal_ours
= 0;
2164 e7000_ops
.to_terminal_info
= 0;
2165 e7000_ops
.to_kill
= e7000_kill
;
2166 e7000_ops
.to_load
= e7000_load
;
2167 e7000_ops
.to_lookup_symbol
= 0;
2168 e7000_ops
.to_create_inferior
= e7000_create_inferior
;
2169 e7000_ops
.to_post_startup_inferior
= NULL
;
2170 e7000_ops
.to_acknowledge_created_inferior
= NULL
;
2171 e7000_ops
.to_clone_and_follow_inferior
= NULL
;
2172 e7000_ops
.to_post_follow_inferior_by_clone
= NULL
;
2173 e7000_ops
.to_insert_fork_catchpoint
= NULL
;
2174 e7000_ops
.to_remove_fork_catchpoint
= NULL
;
2175 e7000_ops
.to_insert_vfork_catchpoint
= NULL
;
2176 e7000_ops
.to_remove_vfork_catchpoint
= NULL
;
2177 e7000_ops
.to_has_forked
= NULL
;
2178 e7000_ops
.to_has_vforked
= NULL
;
2179 e7000_ops
.to_can_follow_vfork_prior_to_exec
= NULL
;
2180 e7000_ops
.to_post_follow_vfork
= NULL
;
2181 e7000_ops
.to_insert_exec_catchpoint
= NULL
;
2182 e7000_ops
.to_remove_exec_catchpoint
= NULL
;
2183 e7000_ops
.to_has_execd
= NULL
;
2184 e7000_ops
.to_reported_exec_events_per_exec_call
= NULL
;
2185 e7000_ops
.to_has_exited
= NULL
;
2186 e7000_ops
.to_mourn_inferior
= e7000_mourn_inferior
;
2187 e7000_ops
.to_can_run
= 0;
2188 e7000_ops
.to_notice_signals
= 0;
2189 e7000_ops
.to_thread_alive
= 0;
2190 e7000_ops
.to_stop
= e7000_stop
;
2191 e7000_ops
.to_pid_to_exec_file
= NULL
;
2192 e7000_ops
.to_stratum
= process_stratum
;
2193 e7000_ops
.DONT_USE
= 0;
2194 e7000_ops
.to_has_all_memory
= 1;
2195 e7000_ops
.to_has_memory
= 1;
2196 e7000_ops
.to_has_stack
= 1;
2197 e7000_ops
.to_has_registers
= 1;
2198 e7000_ops
.to_has_execution
= 1;
2199 e7000_ops
.to_sections
= 0;
2200 e7000_ops
.to_sections_end
= 0;
2201 e7000_ops
.to_magic
= OPS_MAGIC
;
2205 _initialize_remote_e7000 (void)
2208 add_target (&e7000_ops
);
2210 add_com ("e7000", class_obscure
, e7000_command
,
2211 "Send a command to the e7000 monitor.");
2213 add_com ("ftplogin", class_obscure
, e7000_login_command
,
2214 "Login to machine and change to directory.");
2216 add_com ("ftpload", class_obscure
, e7000_ftp_command
,
2217 "Fetch and load a file from previously described place.");
2219 add_com ("drain", class_obscure
, e7000_drain_command
,
2220 "Drain pending e7000 text buffers.");
2222 add_show_from_set (add_set_cmd ("usehardbreakpoints", no_class
,
2223 var_integer
, (char *) &use_hard_breakpoints
,
2224 "Set use of hardware breakpoints for all breakpoints.\n", &setlist
),