1 /* Remote debugging interface for Renesas E7000 ICE, for GDB
3 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
4 2002, 2003, 2004 Free Software Foundation, Inc.
6 Contributed by Cygnus Support.
8 Written by Steve Chamberlain for Cygnus Support.
10 This file is part of GDB.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. */
27 /* The E7000 is an in-circuit emulator for the Renesas H8/300-H and
28 Renesas-SH processor. It has serial port and a lan port.
30 The monitor command set makes it difficult to load large ammounts of
31 data over the lan without using ftp - so try not to issue load
32 commands when communicating over ethernet; use the ftpload command.
34 The monitor pauses for a second when dumping srecords to the serial
35 line too, so we use a slower per byte mechanism but without the
36 startup overhead. Even so, it's pretty slow... */
45 #include "gdb_string.h"
47 #include <sys/types.h>
49 #include "remote-utils.h"
57 #define HARD_BREAKPOINTS /* Now handled by set option. */
58 #define BC_BREAKPOINTS use_hard_breakpoints
66 /* This file is used by 2 different targets, sh-elf and h8300. The
67 h8300 is not multiarched and doesn't use the registers defined in
68 tm-sh.h. To avoid using a macro GDB_TARGET_IS_SH, we do runtime check
69 of the target, which requires that these namse below are always
70 defined also in the h8300 case. */
72 #if !defined (PR_REGNUM)
75 #if !defined (GBR_REGNUM)
78 #if !defined (VBR_REGNUM)
81 #if !defined (MACH_REGNUM)
82 #define MACH_REGNUM -1
84 #if !defined (MACL_REGNUM)
85 #define MACL_REGNUM -1
87 #if !defined (SR_REGNUM)
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 struct serial
*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 (char *buf
)
154 error ("Use \"target e7000 ...\" first.");
157 printf_unfiltered ("Sending %s\n", buf
);
159 if (serial_write (e7000_desc
, buf
, strlen (buf
)))
160 fprintf_unfiltered (gdb_stderr
, "serial_write failed: %s\n", safe_strerror (errno
));
162 /* And expect to see it echoed, unless using the pc interface */
170 putchar_e7000 (int x
)
175 serial_write (e7000_desc
, b
, 1);
179 write_e7000 (char *s
)
181 serial_write (e7000_desc
, s
, strlen (s
));
192 /* Read a character from the remote system, doing all the fancy timeout
193 stuff. Handles serial errors and EOF. If TIMEOUT == 0, and no chars,
194 returns -1, else returns next char. Discards chars > 127. */
197 readchar (int timeout
)
203 c
= serial_readchar (e7000_desc
, timeout
);
207 if (c
== SERIAL_TIMEOUT
)
212 error ("Timeout reading from remote system.");
215 error ("Serial communication error");
219 putchar_unfiltered (c
);
220 gdb_flush (gdb_stdout
);
230 static char b
[8][10];
242 sprintf (b
[p
], "<%d>", x
);
249 /* Scan input from the remote system, until STRING is found. If
250 DISCARD is non-zero, then discard non-matching input, else print it
251 out. Let the user break out immediately. */
254 expect (char *string
)
262 c
= readchar (timeout
);
266 if (c
== '\r' || c
== '\n')
269 putchar_unfiltered ('\n');
275 putchar_unfiltered (c
);
277 gdb_flush (gdb_stdout
);
279 if (normal (c
) == normal (*p
++))
288 if (normal (c
) == normal (string
[0]))
294 /* Keep discarding input until we see the e7000 prompt.
296 The convention for dealing with the prompt is that you
298 o *then* wait for the prompt.
300 Thus the last thing that a procedure does with the serial line will
301 be an expect_prompt(). Exception: e7000_resume does not wait for
302 the prompt, because the terminal is being handed over to the
303 inferior. However, the next thing which happens after that is a
304 e7000_wait which does wait for the prompt. Note that this includes
305 abnormal exit, e.g. error(). This is necessary to prevent getting
306 into states from which we can't recover. */
315 expect_full_prompt (void)
321 convert_hex_digit (int ch
)
323 if (ch
>= '0' && ch
<= '9')
325 else if (ch
>= 'A' && ch
<= 'F')
326 return ch
- 'A' + 10;
327 else if (ch
>= 'a' && ch
<= 'f')
328 return ch
- 'a' + 10;
335 int value
= convert_hex_digit (*start
);
338 *start
= readchar (timeout
);
339 while ((try = convert_hex_digit (*start
)) >= 0)
343 *start
= readchar (timeout
);
349 /* Get N 32-bit words from remote, each preceded by a space, and put
350 them in registers starting at REGNO. */
353 get_hex_regs (int n
, int regno
)
358 for (i
= 0; i
< n
; i
++)
363 for (j
= 0; j
< 8; j
++)
364 val
= (val
<< 4) + get_hex_digit (j
== 0);
365 regcache_raw_supply (current_regcache
, regno
++, (char *) &val
);
370 /* This is called not only when we first attach, but also when the
371 user types "run" after having attached. */
374 e7000_create_inferior (char *execfile
, char *args
, char **env
,
380 error ("Can't pass arguments to remote E7000DEBUG process");
382 if (execfile
== 0 || exec_bfd
== 0)
383 error ("No executable file specified");
385 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
387 #ifdef CREATE_INFERIOR_HOOK
388 CREATE_INFERIOR_HOOK (0); /* No process-ID */
391 /* The "process" (board) is already stopped awaiting our commands, and
392 the program is already downloaded. We just set its PC and go. */
394 clear_proceed_status ();
396 /* Tell wait_for_inferior that we've started a new process. */
397 init_wait_for_inferior ();
399 /* Set up the "saved terminal modes" of the inferior
400 based on what modes we are starting it with. */
401 target_terminal_init ();
403 /* Install inferior's terminal modes. */
404 target_terminal_inferior ();
406 /* insert_step_breakpoint (); FIXME, do we need this? */
407 proceed ((CORE_ADDR
) entry_pt
, -1, 0); /* Let 'er rip... */
410 /* Open a connection to a remote debugger. NAME is the filename used
411 for communication. */
413 static int baudrate
= 9600;
414 static char dev_name
[100];
416 static char *machine
= "";
417 static char *user
= "";
418 static char *passwd
= "";
419 static char *dir
= "";
421 /* Grab the next token and buy some space for it */
431 while (*p
&& *p
== ' ')
434 while (*p
&& (*p
!= ' ' && *p
!= '\t'))
447 e7000_login_command (char *args
, int from_tty
)
451 machine
= next (&args
);
453 passwd
= next (&args
);
457 printf_unfiltered ("Set info to %s %s %s %s\n", machine
, user
, passwd
, dir
);
462 error ("Syntax is ftplogin <machine> <user> <passwd> <directory>");
466 /* Start an ftp transfer from the E7000 to a host */
469 e7000_ftp_command (char *args
, int from_tty
)
471 /* FIXME: arbitrary limit on machine names and such. */
474 int oldtimeout
= timeout
;
475 timeout
= remote_timeout
;
477 sprintf (buf
, "ftp %s\r", machine
);
478 puts_e7000debug (buf
);
479 expect (" Username : ");
480 sprintf (buf
, "%s\r", user
);
481 puts_e7000debug (buf
);
482 expect (" Password : ");
483 write_e7000 (passwd
);
485 expect ("success\r");
487 sprintf (buf
, "cd %s\r", dir
);
488 puts_e7000debug (buf
);
490 sprintf (buf
, "ll 0;s:%s\r", args
);
491 puts_e7000debug (buf
);
493 puts_e7000debug ("bye\r");
495 timeout
= oldtimeout
;
499 e7000_parse_device (char *args
, char *dev_name
, int baudrate
)
503 if (args
&& strcasecmp (args
, "pc") == 0)
505 strcpy (dev_name
, args
);
510 /* FIXME! temp hack to allow use with port master -
511 target tcp_remote <device> */
512 if (args
&& strncmp (args
, "tcp", 10) == 0)
515 n
= sscanf (args
, " %s %s %d %s", com_type
, dev_name
, &baudrate
, junk
);
516 using_tcp_remote
= 1;
521 n
= sscanf (args
, " %s %d %s", dev_name
, &baudrate
, junk
);
524 if (n
!= 1 && n
!= 2)
526 error ("Bad arguments. Usage:\ttarget e7000 <device> <speed>\n\
527 or \t\ttarget e7000 <host>[:<port>]\n\
528 or \t\ttarget e7000 tcp_remote <host>[:<port>]\n\
529 or \t\ttarget e7000 pc\n");
532 #if !defined(__GO32__) && !defined(_WIN32) && !defined(__CYGWIN__)
533 /* FIXME! test for ':' is ambiguous */
534 if (n
== 1 && strchr (dev_name
, ':') == 0)
536 /* Default to normal telnet port */
537 /* serial_open will use this to determine tcp communication */
538 strcat (dev_name
, ":23");
541 if (!using_tcp_remote
&& strchr (dev_name
, ':'))
548 /* Stub for catch_errors. */
551 e7000_start_remote (void *dummy
)
558 immediate_quit
++; /* Allow user to interrupt it */
560 /* Hello? Are you there? */
565 putchar_e7000 (CTRLC
);
566 while (!sync
&& ++try <= quit_trying
)
570 printf_unfiltered ("[waiting for e7000...]\n");
575 /* FIXME! this didn't seem right-> while (c != SERIAL_TIMEOUT)
576 * we get stuck in this loop ...
577 * We may never timeout, and never sync up :-(
579 while (!sync
&& c
!= -1)
584 putchar_unfiltered (c
);
585 gdb_flush (gdb_stdout
);
587 /* Shouldn't we either break here, or check for sync in inner loop? */
593 putchar_e7000 (CTRLC
);
601 putchar_e7000 (CTRLC
);
602 /* Was-> quit_flag = 0; */
604 quit_trying
= try + 1; /* we don't want to try anymore */
615 fprintf_unfiltered (gdb_stderr
, "Giving up after %d tries...\n", try);
616 error ("Unable to synchronize with target.\n");
619 puts_e7000debug ("\r");
621 puts_e7000debug ("b -\r"); /* Clear breakpoints */
626 /* This is really the job of start_remote however, that makes an assumption
627 that the target is about to print out a status message of some sort. That
628 doesn't happen here. */
630 flush_cached_frames ();
631 registers_changed ();
632 stop_pc
= read_pc ();
633 print_stack_frame (get_selected_frame (), 0, SRC_AND_LOC
);
639 e7000_open (char *args
, int from_tty
)
643 target_preopen (from_tty
);
645 n
= e7000_parse_device (args
, dev_name
, baudrate
);
647 push_target (&e7000_ops
);
649 e7000_desc
= serial_open (dev_name
);
652 perror_with_name (dev_name
);
654 if (serial_setbaudrate (e7000_desc
, baudrate
))
656 serial_close (e7000_desc
);
657 perror_with_name (dev_name
);
659 serial_raw (e7000_desc
);
661 /* Start the remote connection; if error (0), discard this target.
662 In particular, if the user quits, be sure to discard it
663 (we'd be in an inconsistent state otherwise). */
664 if (!catch_errors (e7000_start_remote
, (char *) 0,
665 "Couldn't establish connection to remote target\n", RETURN_MASK_ALL
))
667 printf_filtered ("Remote target %s connected to %s\n", target_shortname
,
671 /* Close out all files and local state before this target loses control. */
674 e7000_close (int quitting
)
678 serial_close (e7000_desc
);
683 /* Terminate the open connection to the remote debugger. Use this
684 when you want to detach and do something else with your gdb. */
687 e7000_detach (char *arg
, int from_tty
)
689 pop_target (); /* calls e7000_close to do the real work */
691 printf_unfiltered ("Ending remote %s debugging\n", target_shortname
);
694 /* Tell the remote machine to resume. */
697 e7000_resume (ptid_t ptid
, int step
, enum target_signal sigal
)
700 puts_e7000debug ("S\r");
702 puts_e7000debug ("G\r");
705 /* Read the remote registers into the block REGS.
707 For the H8/300 a register dump looks like:
709 PC=00021A CCR=80:I*******
710 ER0 - ER3 0000000A 0000002E 0000002E 00000000
711 ER4 - ER7 00000000 00000000 00000000 00FFEFF6
717 char *want_h8300h
= "PC=%p CCR=%c\n\
718 ER0 - ER3 %0 %1 %2 %3\n\
719 ER4 - ER7 %4 %5 %6 %7\n";
721 char *want_nopc_h8300h
= "%p CCR=%c\n\
722 ER0 - ER3 %0 %1 %2 %3\n\
723 ER4 - ER7 %4 %5 %6 %7";
725 char *want_h8300s
= "PC=%p CCR=%c\n\
727 ER0 - ER3 %0 %1 %2 %3\n\
728 ER4 - ER7 %4 %5 %6 %7\n";
730 char *want_nopc_h8300s
= "%p CCR=%c EXR=%9\n\
731 ER0 - ER3 %0 %1 %2 %3\n\
732 ER4 - ER7 %4 %5 %6 %7";
734 char *want_sh
= "PC=%16 SR=%22\n\
735 PR=%17 GBR=%18 VBR=%19\n\
737 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
738 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n";
740 char *want_nopc_sh
= "%16 SR=%22\n\
741 PR=%17 GBR=%18 VBR=%19\n\
743 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
744 R8-15 %8 %9 %10 %11 %12 %13 %14 %15";
746 char *want_sh3
= "PC=%16 SR=%22\n\
747 PR=%17 GBR=%18 VBR=%19\n\
748 MACH=%20 MACL=%21 SSR=%23 SPC=%24\n\
749 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
750 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
751 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
752 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
753 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
754 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
756 char *want_nopc_sh3
= "%16 SR=%22\n\
757 PR=%17 GBR=%18 VBR=%19\n\
758 MACH=%20 MACL=%21 SSR=%22 SPC=%23\n\
759 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
760 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
761 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
762 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
763 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
764 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
769 return readchar (timeout
);
775 int high
= convert_hex_digit (gch ());
776 int low
= convert_hex_digit (gch ());
778 return (high
<< 4) + low
;
782 fetch_regs_from_dump (int (*nextchar
) (), char *want
)
785 char buf
[MAX_REGISTER_SIZE
];
787 int thischar
= nextchar ();
790 internal_error (__FILE__
, __LINE__
, "Register set not selected.");
797 /* Skip to end of line and then eat all new line type stuff */
798 while (thischar
!= '\n' && thischar
!= '\r')
799 thischar
= nextchar ();
800 while (thischar
== '\n' || thischar
== '\r')
801 thischar
= nextchar ();
806 while (thischar
== ' '
810 thischar
= nextchar ();
815 if (*want
== thischar
)
819 thischar
= nextchar ();
822 else if (thischar
== ' ' || thischar
== '\n' || thischar
== '\r')
824 thischar
= nextchar ();
828 error ("out of sync in fetch registers wanted <%s>, got <%c 0x%x>",
829 want
, thischar
, thischar
);
834 /* Got a register command */
856 #ifdef DEPRECATED_FP_REGNUM
858 regno
= DEPRECATED_FP_REGNUM
;
864 if (isdigit (want
[0]))
866 if (isdigit (want
[1]))
868 regno
= (want
[0] - '0') * 10 + want
[1] - '0';
873 regno
= want
[0] - '0';
879 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
881 store_signed_integer (buf
,
882 register_size (current_gdbarch
, regno
),
883 (LONGEST
) get_hex (&thischar
));
884 regcache_raw_supply (current_regcache
, regno
, buf
);
891 e7000_fetch_registers (void)
896 puts_e7000debug ("R\r");
898 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_sh
)
901 switch (TARGET_ARCHITECTURE
->mach
)
909 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_h8300
)
911 wanted
= want_h8300h
;
912 switch (TARGET_ARCHITECTURE
->mach
)
914 case bfd_mach_h8300s
:
915 case bfd_mach_h8300sn
:
916 case bfd_mach_h8300sx
:
917 case bfd_mach_h8300sxn
:
918 wanted
= want_h8300s
;
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 regcache_raw_supply (current_regcache
, 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 %s %x%02x%02x%02x;l\r",
1085 paddr_nz (memaddr
+ i
),
1086 myaddr
[i
], myaddr
[i
+ 1], myaddr
[i
+ 2], myaddr
[i
+ 3]);
1087 puts_e7000debug (buf
);
1092 sprintf (buf
, "m %s %x\r", paddr_nz (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 %s;l\r", paddr_nz (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 %s %s\r", paddr_nz (memaddr
), paddr_nz (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
, int len
,
1467 int write
, struct mem_attrib
*attrib
,
1468 struct target_ops
*target
)
1471 return e7000_write_inferior_memory (memaddr
, myaddr
, len
);
1473 return e7000_read_inferior_memory (memaddr
, myaddr
, len
);
1475 return e7000_read_inferior_memory_large (memaddr
, myaddr
, len
);
1484 e7000_load (char *args
, int from_tty
)
1486 struct cleanup
*old_chain
;
1490 #define WRITESIZE 0x1000
1491 char buf
[2 + 4 + 4 + WRITESIZE
]; /* `DT' + <addr> + <len> + <data> */
1495 time_t start_time
, end_time
; /* Start and end times of download */
1496 unsigned long data_count
; /* Number of bytes transferred to memory */
1497 int oldtimeout
= timeout
;
1499 timeout
= remote_timeout
;
1502 /* FIXME! change test to test for type of download */
1505 generic_load (args
, from_tty
);
1509 /* for direct tcp connections, we can do a fast binary download */
1516 while (*args
!= '\000')
1520 while (isspace (*args
))
1525 while ((*args
!= '\000') && !isspace (*args
))
1528 if (*args
!= '\000')
1533 else if (strncmp (arg
, "-quiet", strlen (arg
)) == 0)
1535 else if (strncmp (arg
, "-nostart", strlen (arg
)) == 0)
1538 error ("unknown option `%s'", arg
);
1542 filename
= get_exec_file (1);
1544 pbfd
= bfd_openr (filename
, gnutarget
);
1547 perror_with_name (filename
);
1550 old_chain
= make_cleanup_bfd_close (pbfd
);
1552 if (!bfd_check_format (pbfd
, bfd_object
))
1553 error ("\"%s\" is not an object file: %s", filename
,
1554 bfd_errmsg (bfd_get_error ()));
1556 start_time
= time (NULL
);
1559 puts_e7000debug ("mw\r");
1563 for (section
= pbfd
->sections
; section
; section
= section
->next
)
1565 if (bfd_get_section_flags (pbfd
, section
) & SEC_LOAD
)
1567 bfd_vma section_address
;
1568 bfd_size_type section_size
;
1571 section_address
= bfd_get_section_vma (pbfd
, section
);
1572 section_size
= bfd_get_section_size (section
);
1575 printf_filtered ("[Loading section %s at 0x%s (%s bytes)]\n",
1576 bfd_get_section_name (pbfd
, section
),
1577 paddr_nz (section_address
),
1578 paddr_u (section_size
));
1582 data_count
+= section_size
;
1584 while (section_size
> 0)
1587 static char inds
[] = "|/-\\";
1592 count
= min (section_size
, WRITESIZE
);
1594 buf
[2] = section_address
>> 24;
1595 buf
[3] = section_address
>> 16;
1596 buf
[4] = section_address
>> 8;
1597 buf
[5] = section_address
;
1599 buf
[6] = count
>> 24;
1600 buf
[7] = count
>> 16;
1601 buf
[8] = count
>> 8;
1604 bfd_get_section_contents (pbfd
, section
, buf
+ 10, fptr
, count
);
1606 if (serial_write (e7000_desc
, buf
, count
+ 10))
1607 fprintf_unfiltered (gdb_stderr
,
1608 "e7000_load: serial_write failed: %s\n",
1609 safe_strerror (errno
));
1615 printf_unfiltered ("\r%c", inds
[k
++ % 4]);
1616 gdb_flush (gdb_stdout
);
1619 section_address
+= count
;
1621 section_size
-= count
;
1630 end_time
= time (NULL
);
1632 /* Finally, make the PC point at the start address */
1635 write_pc (bfd_get_start_address (exec_bfd
));
1637 inferior_ptid
= null_ptid
; /* No process now */
1639 /* This is necessary because many things were based on the PC at the time that
1640 we attached to the monitor, which is no longer valid now that we have loaded
1641 new code (and just changed the PC). Another way to do this might be to call
1642 normal_stop, except that the stack may not be valid, and things would get
1643 horribly confused... */
1645 clear_symtab_users ();
1649 entry
= bfd_get_start_address (pbfd
);
1652 printf_unfiltered ("[Starting %s at 0x%s]\n", filename
, paddr_nz (entry
));
1654 /* start_routine (entry); */
1657 report_transfer_performance (data_count
, start_time
, end_time
);
1659 do_cleanups (old_chain
);
1660 timeout
= oldtimeout
;
1663 /* Clean up when a program exits.
1665 The program actually lives on in the remote processor's RAM, and may be
1666 run again without a download. Don't leave it full of breakpoint
1670 e7000_mourn_inferior (void)
1672 remove_breakpoints ();
1673 unpush_target (&e7000_ops
);
1674 generic_mourn_inferior (); /* Do all the proper things now */
1677 #define MAX_BREAKPOINTS 200
1678 #ifdef HARD_BREAKPOINTS
1679 #define MAX_E7000DEBUG_BREAKPOINTS (BC_BREAKPOINTS ? 5 : MAX_BREAKPOINTS)
1681 #define MAX_E7000DEBUG_BREAKPOINTS MAX_BREAKPOINTS
1684 /* Since we can change to soft breakpoints dynamically, we must define
1685 more than enough. Was breakaddr[MAX_E7000DEBUG_BREAKPOINTS]. */
1686 static CORE_ADDR breakaddr
[MAX_BREAKPOINTS
] =
1690 e7000_insert_breakpoint (CORE_ADDR addr
, char *shadow
)
1695 static char nop
[2] = NOP
;
1698 for (i
= 0; i
<= MAX_E7000DEBUG_BREAKPOINTS
; i
++)
1699 if (breakaddr
[i
] == 0)
1701 breakaddr
[i
] = addr
;
1702 /* Save old contents, and insert a nop in the space */
1703 #ifdef HARD_BREAKPOINTS
1706 sprintf (buf
, "BC%d A=%s\r", i
+ 1, paddr_nz (addr
));
1707 puts_e7000debug (buf
);
1711 sprintf (buf
, "B %s\r", paddr_nz (addr
));
1712 puts_e7000debug (buf
);
1716 e7000_read_inferior_memory (addr
, shadow
, 2);
1717 e7000_write_inferior_memory (addr
, nop
, 2);
1720 sprintf (buf
, "B %x\r", addr
);
1721 puts_e7000debug (buf
);
1727 error ("Too many breakpoints ( > %d) for the E7000\n",
1728 MAX_E7000DEBUG_BREAKPOINTS
);
1733 e7000_remove_breakpoint (CORE_ADDR addr
, char *shadow
)
1738 for (i
= 0; i
< MAX_E7000DEBUG_BREAKPOINTS
; i
++)
1739 if (breakaddr
[i
] == addr
)
1742 #ifdef HARD_BREAKPOINTS
1745 sprintf (buf
, "BC%d - \r", i
+ 1);
1746 puts_e7000debug (buf
);
1750 sprintf (buf
, "B - %s\r", paddr_nz (addr
));
1751 puts_e7000debug (buf
);
1755 sprintf (buf
, "B - %s\r", paddr_nz (addr
));
1756 puts_e7000debug (buf
);
1760 /* Replace the insn under the break */
1761 e7000_write_inferior_memory (addr
, shadow
, 2);
1768 warning ("Can't find breakpoint associated with 0x%s\n", paddr_nz (addr
));
1772 /* Put a command string, in args, out to STDBUG. Output from STDBUG
1773 is placed on the users terminal until the prompt is seen. */
1776 e7000_command (char *args
, int fromtty
)
1778 /* FIXME: arbitrary limit on length of args. */
1784 error ("e7000 target not open.");
1787 puts_e7000debug ("\r");
1791 sprintf (buf
, "%s\r", args
);
1792 puts_e7000debug (buf
);
1797 expect_full_prompt ();
1800 printf_unfiltered ("\n");
1802 /* Who knows what the command did... */
1803 registers_changed ();
1808 e7000_drain_command (char *args
, int fromtty
)
1812 puts_e7000debug ("end\r");
1813 putchar_e7000 (CTRLC
);
1815 while ((c
= readchar (1)) != -1)
1819 putchar_e7000 (CTRLC
);
1822 if (c
> ' ' && c
< 127)
1823 printf_unfiltered ("%c", c
& 0xff);
1825 printf_unfiltered ("<%x>", c
& 0xff);
1834 static char *strings
[NITEMS
] =
1841 "ILLEGAL INSTRUCTION",
1848 for (i
= 0; i
< NITEMS
; ++i
)
1854 for (i
= 0; i
< NITEMS
; i
++)
1861 /* found one of the choices */
1873 /* Suck characters, if a string match, then return the strings index
1874 otherwise echo them. */
1877 expect_n (char **strings
)
1883 char *buffer
= saveaway
;
1884 /* Count number of expect strings */
1886 for (n
= 0; strings
[n
]; n
++)
1888 ptr
[n
] = strings
[n
];
1899 printf_unfiltered ("[waiting for e7000...]\n");
1912 putchar_e7000 (CTRLC
); /* interrupt the running program */
1916 for (i
= 0; i
< n
; i
++)
1923 /* Gone all the way */
1930 ptr
[i
] = strings
[i
];
1936 /* Save it up incase we find that there was no match */
1941 if (buffer
!= saveaway
)
1944 printf_unfiltered ("%s", buffer
);
1949 putchar_unfiltered (c
);
1950 gdb_flush (gdb_stdout
);
1956 /* We subtract two from the pc here rather than use
1957 DECR_PC_AFTER_BREAK since the e7000 doesn't always add two to the
1958 pc, and the simulators never do. */
1966 store_signed_integer (buf
,
1967 register_size (current_gdbarch
, PC_REGNUM
),
1968 read_register (PC_REGNUM
) - 2);
1969 regcache_raw_supply (current_regcache
, PC_REGNUM
, buf
);
1970 sprintf (buf2
, ".PC %s\r", phex_nz (read_register (PC_REGNUM
), 0));
1971 puts_e7000debug (buf2
);
1976 #define WAS_RUNNING 2
1979 static char *estrings
[] =
1988 /* Wait until the remote machine stops, then return, storing status in
1989 STATUS just as `wait' would. */
1992 e7000_wait (ptid_t ptid
, struct target_waitstatus
*status
)
1996 int running_count
= 0;
1999 char *wanted_nopc
= NULL
;
2001 /* Then echo chars until PC= string seen */
2002 gch (); /* Drop cr */
2003 gch (); /* and space */
2007 switch (expect_n (estrings
))
2010 /* how did this happen ? */
2015 putchar_e7000 (CTRLC
);
2023 if (running_count
== 20)
2025 printf_unfiltered ("[running...]\n");
2035 /* Skip till the PC= */
2038 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_sh
)
2040 wanted_nopc
= want_nopc_sh
;
2041 switch (TARGET_ARCHITECTURE
->mach
)
2046 wanted_nopc
= want_nopc_sh3
;
2049 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_h8300
)
2051 wanted_nopc
= want_nopc_h8300h
;
2052 switch (TARGET_ARCHITECTURE
->mach
)
2054 case bfd_mach_h8300s
:
2055 case bfd_mach_h8300sn
:
2056 case bfd_mach_h8300sx
:
2057 case bfd_mach_h8300sxn
:
2058 wanted_nopc
= want_nopc_h8300s
;
2061 fetch_regs_from_dump (gch
, wanted_nopc
);
2063 /* And supply the extra ones the simulator uses */
2064 for (regno
= NUM_REALREGS
; regno
< NUM_REGS
; regno
++)
2067 regcache_raw_supply (current_regcache
, regno
, (char *) &buf
);
2070 stop_reason
= why_stop ();
2071 expect_full_prompt ();
2073 status
->kind
= TARGET_WAITKIND_STOPPED
;
2074 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2076 switch (stop_reason
)
2078 case 1: /* Breakpoint */
2079 write_pc (read_pc ()); /* PC is always off by 2 for breakpoints */
2080 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2082 case 0: /* Single step */
2083 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2085 case 2: /* Interrupt */
2088 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2093 status
->value
.sig
= TARGET_SIGNAL_INT
;
2099 printf_unfiltered ("a cycle address error?\n");
2100 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2103 status
->value
.sig
= TARGET_SIGNAL_ILL
;
2106 status
->value
.sig
= TARGET_SIGNAL_SEGV
;
2108 case 7: /* Anything else (NITEMS + 1) */
2109 printf_unfiltered ("a write protect error?\n");
2110 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2113 /* Get the user's attention - this should never happen. */
2114 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
2117 return inferior_ptid
;
2120 /* Stop the running program. */
2125 /* Sending a ^C is supposed to stop the running program. */
2126 putchar_e7000 (CTRLC
);
2129 /* Define the target subroutine names. */
2131 struct target_ops e7000_ops
;
2134 init_e7000_ops (void)
2136 e7000_ops
.to_shortname
= "e7000";
2137 e7000_ops
.to_longname
= "Remote Renesas e7000 target";
2138 e7000_ops
.to_doc
= "Use a remote Renesas e7000 ICE connected by a serial line;\n\
2139 or a network connection.\n\
2140 Arguments are the name of the device for the serial line,\n\
2141 the speed to connect at in bits per second.\n\
2143 target e7000 /dev/ttya 9600\n\
2144 target e7000 foobar";
2145 e7000_ops
.to_open
= e7000_open
;
2146 e7000_ops
.to_close
= e7000_close
;
2147 e7000_ops
.to_detach
= e7000_detach
;
2148 e7000_ops
.to_resume
= e7000_resume
;
2149 e7000_ops
.to_wait
= e7000_wait
;
2150 e7000_ops
.to_fetch_registers
= e7000_fetch_register
;
2151 e7000_ops
.to_store_registers
= e7000_store_register
;
2152 e7000_ops
.to_prepare_to_store
= e7000_prepare_to_store
;
2153 e7000_ops
.to_xfer_memory
= e7000_xfer_inferior_memory
;
2154 e7000_ops
.to_files_info
= e7000_files_info
;
2155 e7000_ops
.to_insert_breakpoint
= e7000_insert_breakpoint
;
2156 e7000_ops
.to_remove_breakpoint
= e7000_remove_breakpoint
;
2157 e7000_ops
.to_kill
= e7000_kill
;
2158 e7000_ops
.to_load
= e7000_load
;
2159 e7000_ops
.to_create_inferior
= e7000_create_inferior
;
2160 e7000_ops
.to_mourn_inferior
= e7000_mourn_inferior
;
2161 e7000_ops
.to_stop
= e7000_stop
;
2162 e7000_ops
.to_stratum
= process_stratum
;
2163 e7000_ops
.to_has_all_memory
= 1;
2164 e7000_ops
.to_has_memory
= 1;
2165 e7000_ops
.to_has_stack
= 1;
2166 e7000_ops
.to_has_registers
= 1;
2167 e7000_ops
.to_has_execution
= 1;
2168 e7000_ops
.to_magic
= OPS_MAGIC
;
2171 extern initialize_file_ftype _initialize_remote_e7000
; /* -Wmissing-prototypes */
2174 _initialize_remote_e7000 (void)
2177 add_target (&e7000_ops
);
2179 add_com ("e7000", class_obscure
, e7000_command
,
2180 "Send a command to the e7000 monitor.");
2182 add_com ("ftplogin", class_obscure
, e7000_login_command
,
2183 "Login to machine and change to directory.");
2185 add_com ("ftpload", class_obscure
, e7000_ftp_command
,
2186 "Fetch and load a file from previously described place.");
2188 add_com ("drain", class_obscure
, e7000_drain_command
,
2189 "Drain pending e7000 text buffers.");
2191 deprecated_add_show_from_set
2192 (add_set_cmd ("usehardbreakpoints", no_class
,
2193 var_integer
, (char *) &use_hard_breakpoints
, "\
2194 Set use of hardware breakpoints for all breakpoints.\n", &setlist
),