1 /* Remote debugging interface for Hitachi E7000 ICE, for GDB
2 Copyright 1993, 1994, 1996, 1997, 1998, 2000, 2001 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 Written by Steve Chamberlain for Cygnus Support.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
24 /* The E7000 is an in-circuit emulator for the Hitachi H8/300-H and
25 Hitachi-SH processor. It has serial port and a lan port.
27 The monitor command set makes it difficult to load large ammounts of
28 data over the lan without using ftp - so try not to issue load
29 commands when communicating over ethernet; use the ftpload command.
31 The monitor pauses for a second when dumping srecords to the serial
32 line too, so we use a slower per byte mechanism but without the
33 startup overhead. Even so, it's pretty slow... */
42 #include "gdb_string.h"
44 #include <sys/types.h>
46 #include "remote-utils.h"
53 #define HARD_BREAKPOINTS /* Now handled by set option. */
54 #define BC_BREAKPOINTS use_hard_breakpoints
62 /* This file is used by 2 different targets, sh-elf and h8300. The
63 h8300 is not multiarched and doesn't use the registers defined in
64 tm-sh.h. To avoid using a macro GDB_TARGET_IS_SH, we do runtime check
65 of the target, which requires that these namse below are always
66 defined also in the h8300 case. */
68 #if !defined (PR_REGNUM)
71 #if !defined (GBR_REGNUM)
74 #if !defined (VBR_REGNUM)
77 #if !defined (MACH_REGNUM)
78 #define MACH_REGNUM -1
80 #if !defined (MACL_REGNUM)
81 #define MACL_REGNUM -1
83 #if !defined (SR_REGNUM)
87 extern void notice_quit (void);
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 serial_t 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
);
267 putchar_e7000 (CTRLC
);
279 if (c
== '\r' || c
== '\n')
282 putchar_unfiltered ('\n');
288 putchar_unfiltered (c
);
290 gdb_flush (gdb_stdout
);
292 if (normal (c
) == normal (*p
++))
301 if (normal (c
) == normal (string
[0]))
307 /* Keep discarding input until we see the e7000 prompt.
309 The convention for dealing with the prompt is that you
311 o *then* wait for the prompt.
313 Thus the last thing that a procedure does with the serial line will
314 be an expect_prompt(). Exception: e7000_resume does not wait for
315 the prompt, because the terminal is being handed over to the
316 inferior. However, the next thing which happens after that is a
317 e7000_wait which does wait for the prompt. Note that this includes
318 abnormal exit, e.g. error(). This is necessary to prevent getting
319 into states from which we can't recover. */
328 expect_full_prompt (void)
334 convert_hex_digit (int ch
)
336 if (ch
>= '0' && ch
<= '9')
338 else if (ch
>= 'A' && ch
<= 'F')
339 return ch
- 'A' + 10;
340 else if (ch
>= 'a' && ch
<= 'f')
341 return ch
- 'a' + 10;
348 int value
= convert_hex_digit (*start
);
351 *start
= readchar (timeout
);
352 while ((try = convert_hex_digit (*start
)) >= 0)
356 *start
= readchar (timeout
);
362 /* Get N 32-bit words from remote, each preceded by a space, and put
363 them in registers starting at REGNO. */
366 get_hex_regs (int n
, int regno
)
371 for (i
= 0; i
< n
; i
++)
376 for (j
= 0; j
< 8; j
++)
377 val
= (val
<< 4) + get_hex_digit (j
== 0);
378 supply_register (regno
++, (char *) &val
);
383 /* This is called not only when we first attach, but also when the
384 user types "run" after having attached. */
387 e7000_create_inferior (char *execfile
, char *args
, char **env
)
392 error ("Can't pass arguments to remote E7000DEBUG process");
394 if (execfile
== 0 || exec_bfd
== 0)
395 error ("No executable file specified");
397 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
399 #ifdef CREATE_INFERIOR_HOOK
400 CREATE_INFERIOR_HOOK (0); /* No process-ID */
403 /* The "process" (board) is already stopped awaiting our commands, and
404 the program is already downloaded. We just set its PC and go. */
406 clear_proceed_status ();
408 /* Tell wait_for_inferior that we've started a new process. */
409 init_wait_for_inferior ();
411 /* Set up the "saved terminal modes" of the inferior
412 based on what modes we are starting it with. */
413 target_terminal_init ();
415 /* Install inferior's terminal modes. */
416 target_terminal_inferior ();
418 /* insert_step_breakpoint (); FIXME, do we need this? */
419 proceed ((CORE_ADDR
) entry_pt
, -1, 0); /* Let 'er rip... */
422 /* Open a connection to a remote debugger. NAME is the filename used
423 for communication. */
425 static int baudrate
= 9600;
426 static char dev_name
[100];
428 static char *machine
= "";
429 static char *user
= "";
430 static char *passwd
= "";
431 static char *dir
= "";
433 /* Grab the next token and buy some space for it */
443 while (*p
&& *p
== ' ')
446 while (*p
&& (*p
!= ' ' && *p
!= '\t'))
459 e7000_login_command (char *args
, int from_tty
)
463 machine
= next (&args
);
465 passwd
= next (&args
);
469 printf_unfiltered ("Set info to %s %s %s %s\n", machine
, user
, passwd
, dir
);
474 error ("Syntax is ftplogin <machine> <user> <passwd> <directory>");
478 /* Start an ftp transfer from the E7000 to a host */
481 e7000_ftp_command (char *args
, int from_tty
)
483 /* FIXME: arbitrary limit on machine names and such. */
486 int oldtimeout
= timeout
;
487 timeout
= remote_timeout
;
489 sprintf (buf
, "ftp %s\r", machine
);
490 puts_e7000debug (buf
);
491 expect (" Username : ");
492 sprintf (buf
, "%s\r", user
);
493 puts_e7000debug (buf
);
494 expect (" Password : ");
495 write_e7000 (passwd
);
497 expect ("success\r");
499 sprintf (buf
, "cd %s\r", dir
);
500 puts_e7000debug (buf
);
502 sprintf (buf
, "ll 0;s:%s\r", args
);
503 puts_e7000debug (buf
);
505 puts_e7000debug ("bye\r");
507 timeout
= oldtimeout
;
511 e7000_parse_device (char *args
, char *dev_name
, int baudrate
)
515 if (args
&& strcasecmp (args
, "pc") == 0)
517 strcpy (dev_name
, args
);
522 /* FIXME! temp hack to allow use with port master -
523 target tcp_remote <device> */
524 if (args
&& strncmp (args
, "tcp", 10) == 0)
527 n
= sscanf (args
, " %s %s %d %s", com_type
, dev_name
, &baudrate
, junk
);
528 using_tcp_remote
= 1;
533 n
= sscanf (args
, " %s %d %s", dev_name
, &baudrate
, junk
);
536 if (n
!= 1 && n
!= 2)
538 error ("Bad arguments. Usage:\ttarget e7000 <device> <speed>\n\
539 or \t\ttarget e7000 <host>[:<port>]\n\
540 or \t\ttarget e7000 tcp_remote <host>[:<port>]\n\
541 or \t\ttarget e7000 pc\n");
544 #if !defined(__GO32__) && !defined(_WIN32)
545 /* FIXME! test for ':' is ambiguous */
546 if (n
== 1 && strchr (dev_name
, ':') == 0)
548 /* Default to normal telnet port */
549 /* serial_open will use this to determine tcp communication */
550 strcat (dev_name
, ":23");
553 if (!using_tcp_remote
&& strchr (dev_name
, ':'))
560 /* Stub for catch_errors. */
563 e7000_start_remote (void *dummy
)
570 immediate_quit
++; /* Allow user to interrupt it */
572 /* Hello? Are you there? */
577 putchar_e7000 (CTRLC
);
578 while (!sync
&& ++try <= quit_trying
)
582 printf_unfiltered ("[waiting for e7000...]\n");
587 /* FIXME! this didn't seem right-> while (c != SERIAL_TIMEOUT)
588 * we get stuck in this loop ...
589 * We may never timeout, and never sync up :-(
591 while (!sync
&& c
!= -1)
596 putchar_unfiltered (c
);
597 gdb_flush (gdb_stdout
);
599 /* Shouldn't we either break here, or check for sync in inner loop? */
605 putchar_e7000 (CTRLC
);
613 putchar_e7000 (CTRLC
);
614 /* Was-> quit_flag = 0; */
616 quit_trying
= try + 1; /* we don't want to try anymore */
627 fprintf_unfiltered (gdb_stderr
, "Giving up after %d tries...\n", try);
628 error ("Unable to synchronize with target.\n");
631 puts_e7000debug ("\r");
633 puts_e7000debug ("b -\r"); /* Clear breakpoints */
638 /* This is really the job of start_remote however, that makes an assumption
639 that the target is about to print out a status message of some sort. That
640 doesn't happen here. */
642 flush_cached_frames ();
643 registers_changed ();
644 stop_pc
= read_pc ();
645 set_current_frame (create_new_frame (read_fp (), stop_pc
));
646 select_frame (get_current_frame (), 0);
647 print_stack_frame (selected_frame
, -1, 1);
653 e7000_open (char *args
, int from_tty
)
657 target_preopen (from_tty
);
659 n
= e7000_parse_device (args
, dev_name
, baudrate
);
661 push_target (&e7000_ops
);
663 e7000_desc
= SERIAL_OPEN (dev_name
);
666 perror_with_name (dev_name
);
668 SERIAL_SETBAUDRATE (e7000_desc
, baudrate
);
669 SERIAL_RAW (e7000_desc
);
671 #ifdef GDB_TARGET_IS_H8300
675 /* Start the remote connection; if error (0), discard this target.
676 In particular, if the user quits, be sure to discard it
677 (we'd be in an inconsistent state otherwise). */
678 if (!catch_errors (e7000_start_remote
, (char *) 0,
679 "Couldn't establish connection to remote target\n", RETURN_MASK_ALL
))
681 printf_filtered ("Remote target %s connected to %s\n", target_shortname
,
685 /* Close out all files and local state before this target loses control. */
688 e7000_close (int quitting
)
692 SERIAL_CLOSE (e7000_desc
);
697 /* Terminate the open connection to the remote debugger. Use this
698 when you want to detach and do something else with your gdb. */
701 e7000_detach (char *arg
, int from_tty
)
703 pop_target (); /* calls e7000_close to do the real work */
705 printf_unfiltered ("Ending remote %s debugging\n", target_shortname
);
708 /* Tell the remote machine to resume. */
711 e7000_resume (int pid
, int step
, enum target_signal sigal
)
714 puts_e7000debug ("S\r");
716 puts_e7000debug ("G\r");
719 /* Read the remote registers into the block REGS.
721 For the H8/300 a register dump looks like:
723 PC=00021A CCR=80:I*******
724 ER0 - ER3 0000000A 0000002E 0000002E 00000000
725 ER4 - ER7 00000000 00000000 00000000 00FFEFF6
731 char *want_h8300h
= "PC=%p CCR=%c\n\
732 ER0 - ER3 %0 %1 %2 %3\n\
733 ER4 - ER7 %4 %5 %6 %7\n";
735 char *want_nopc_h8300h
= "%p CCR=%c\n\
736 ER0 - ER3 %0 %1 %2 %3\n\
737 ER4 - ER7 %4 %5 %6 %7";
739 char *want_h8300s
= "PC=%p CCR=%c\n\
741 ER0 - ER3 %0 %1 %2 %3\n\
742 ER4 - ER7 %4 %5 %6 %7\n";
744 char *want_nopc_h8300s
= "%p CCR=%c EXR=%9\n\
745 ER0 - ER3 %0 %1 %2 %3\n\
746 ER4 - ER7 %4 %5 %6 %7";
748 char *want_sh
= "PC=%16 SR=%22\n\
749 PR=%17 GBR=%18 VBR=%19\n\
751 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
752 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n";
754 char *want_nopc_sh
= "%16 SR=%22\n\
755 PR=%17 GBR=%18 VBR=%19\n\
757 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
758 R8-15 %8 %9 %10 %11 %12 %13 %14 %15";
760 char *want_sh3
= "PC=%16 SR=%22\n\
761 PR=%17 GBR=%18 VBR=%19\n\
762 MACH=%20 MACL=%21 SSR=%23 SPC=%24\n\
763 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
764 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
765 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
766 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
767 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
768 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
770 char *want_nopc_sh3
= "%16 SR=%22\n\
771 PR=%17 GBR=%18 VBR=%19\n\
772 MACH=%20 MACL=%21 SSR=%22 SPC=%23\n\
773 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
774 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
775 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
776 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
777 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
778 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
783 return readchar (timeout
);
789 int high
= convert_hex_digit (gch ());
790 int low
= convert_hex_digit (gch ());
792 return (high
<< 4) + low
;
796 fetch_regs_from_dump (int (*nextchar
) (), char *want
)
799 char buf
[MAX_REGISTER_RAW_SIZE
];
801 int thischar
= nextchar ();
808 /* Skip to end of line and then eat all new line type stuff */
809 while (thischar
!= '\n' && thischar
!= '\r')
810 thischar
= nextchar ();
811 while (thischar
== '\n' || thischar
== '\r')
812 thischar
= nextchar ();
817 while (thischar
== ' '
821 thischar
= nextchar ();
826 if (*want
== thischar
)
830 thischar
= nextchar ();
833 else if (thischar
== ' ' || thischar
== '\n' || thischar
== '\r')
835 thischar
= nextchar ();
839 error ("out of sync in fetch registers wanted <%s>, got <%c 0x%x>",
840 want
, thischar
, thischar
);
845 /* Got a register command */
875 if (isdigit (want
[0]))
877 if (isdigit (want
[1]))
879 regno
= (want
[0] - '0') * 10 + want
[1] - '0';
884 regno
= want
[0] - '0';
890 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
892 store_signed_integer (buf
,
893 REGISTER_RAW_SIZE (regno
),
894 (LONGEST
) get_hex (&thischar
));
895 supply_register (regno
, buf
);
902 e7000_fetch_registers (void)
907 puts_e7000debug ("R\r");
909 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_sh
)
912 switch (TARGET_ARCHITECTURE
->mach
)
920 #ifdef GDB_TARGET_IS_H8300
921 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_h8300
)
924 wanted
= want_h8300s
;
926 wanted
= want_h8300h
;
930 fetch_regs_from_dump (gch
, wanted
);
932 /* And supply the extra ones the simulator uses */
933 for (regno
= NUM_REALREGS
; regno
< NUM_REGS
; regno
++)
937 supply_register (regno
, (char *) (&buf
));
941 /* Fetch register REGNO, or all registers if REGNO is -1. Returns
945 e7000_fetch_register (int regno
)
947 e7000_fetch_registers ();
950 /* Store the remote registers from the contents of the block REGS. */
953 e7000_store_registers (void)
957 for (regno
= 0; regno
< NUM_REALREGS
; regno
++)
958 e7000_store_register (regno
);
960 registers_changed ();
963 /* Store register REGNO, or all if REGNO == 0. Return errno value. */
966 e7000_store_register (int regno
)
972 e7000_store_registers ();
976 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_h8300
)
980 sprintf (buf
, ".ER%d %lx\r", regno
, read_register (regno
));
981 puts_e7000debug (buf
);
983 else if (regno
== PC_REGNUM
)
985 sprintf (buf
, ".PC %lx\r", read_register (regno
));
986 puts_e7000debug (buf
);
989 else if (regno
== CCR_REGNUM
)
991 sprintf (buf
, ".CCR %lx\r", read_register (regno
));
992 puts_e7000debug (buf
);
997 else if (TARGET_ARCHITECTURE
->arch
== bfd_arch_sh
)
999 if (regno
== PC_REGNUM
)
1001 sprintf (buf
, ".PC %lx\r", read_register (regno
));
1002 puts_e7000debug (buf
);
1005 else if (regno
== SR_REGNUM
)
1007 sprintf (buf
, ".SR %lx\r", read_register (regno
));
1008 puts_e7000debug (buf
);
1011 else if (regno
== PR_REGNUM
)
1013 sprintf (buf
, ".PR %lx\r", read_register (regno
));
1014 puts_e7000debug (buf
);
1017 else if (regno
== GBR_REGNUM
)
1019 sprintf (buf
, ".GBR %lx\r", read_register (regno
));
1020 puts_e7000debug (buf
);
1023 else if (regno
== VBR_REGNUM
)
1025 sprintf (buf
, ".VBR %lx\r", read_register (regno
));
1026 puts_e7000debug (buf
);
1029 else if (regno
== MACH_REGNUM
)
1031 sprintf (buf
, ".MACH %lx\r", read_register (regno
));
1032 puts_e7000debug (buf
);
1035 else if (regno
== MACL_REGNUM
)
1037 sprintf (buf
, ".MACL %lx\r", read_register (regno
));
1038 puts_e7000debug (buf
);
1042 sprintf (buf
, ".R%d %lx\r", regno
, read_register (regno
));
1043 puts_e7000debug (buf
);
1050 /* Get ready to modify the registers array. On machines which store
1051 individual registers, this doesn't need to do anything. On machines
1052 which store all the registers in one fell swoop, this makes sure
1053 that registers contains all the registers from the program being
1057 e7000_prepare_to_store (void)
1059 /* Do nothing, since we can store individual regs */
1063 e7000_files_info (struct target_ops
*ops
)
1065 printf_unfiltered ("\tAttached to %s at %d baud.\n", dev_name
, baudrate
);
1069 stickbyte (char *where
, unsigned int what
)
1071 static CONST
char digs
[] = "0123456789ABCDEF";
1073 where
[0] = digs
[(what
>> 4) & 0xf];
1074 where
[1] = digs
[(what
& 0xf) & 0xf];
1079 /* Write a small ammount of memory. */
1082 write_small (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
)
1087 for (i
= 0; i
< len
; i
++)
1089 if (((memaddr
+ i
) & 3) == 0 && (i
+ 3 < len
))
1091 /* Can be done with a long word */
1092 sprintf (buf
, "m %lx %x%02x%02x%02x;l\r",
1094 myaddr
[i
], myaddr
[i
+ 1], myaddr
[i
+ 2], myaddr
[i
+ 3]);
1095 puts_e7000debug (buf
);
1100 sprintf (buf
, "m %lx %x\r", memaddr
+ i
, myaddr
[i
]);
1101 puts_e7000debug (buf
);
1110 /* Write a large ammount of memory, this only works with the serial
1111 mode enabled. Command is sent as
1126 write_large (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
)
1129 #define maxstride 128
1132 puts_e7000debug ("IL ;S:FK\r");
1134 putchar_e7000 (ACK
);
1137 for (i
= 0; i
< len
; i
+= stride
)
1139 char compose
[maxstride
* 2 + 50];
1140 int address
= i
+ memaddr
;
1147 if (stride
> maxstride
)
1150 compose
[where
++] = 'S';
1152 if (address
>= 0xffffff)
1154 else if (address
>= 0xffff)
1159 compose
[where
++] = alen
- 1 + '0';
1160 /* Insert length. */
1161 check_sum
+= stickbyte (compose
+ where
, alen
+ stride
+ 1);
1166 check_sum
+= stickbyte (compose
+ where
, address
>> (8 * (alen
)));
1170 for (j
= 0; j
< stride
; j
++)
1172 check_sum
+= stickbyte (compose
+ where
, myaddr
[i
+ j
]);
1175 stickbyte (compose
+ where
, ~check_sum
);
1177 compose
[where
++] = '\r';
1178 compose
[where
++] = '\n';
1179 compose
[where
++] = 0;
1181 SERIAL_WRITE (e7000_desc
, compose
, where
);
1185 /* This is ok - nothing there */
1189 /* Hmm, it's trying to tell us something */
1191 error ("Error writing memory");
1195 printf_unfiltered ("@%d}@", j
);
1196 while ((j
= readchar (0)) > 0)
1198 printf_unfiltered ("@{%d}@", j
);
1203 /* Send the trailer record */
1204 write_e7000 ("S70500000000FA\r");
1205 putchar_e7000 (CTRLZ
);
1207 putchar_e7000 (ACK
);
1213 /* Copy LEN bytes of data from debugger memory at MYADDR to inferior's
1214 memory at MEMADDR. Returns length moved.
1216 Can't use the Srecord load over ethernet, so don't use fast method
1220 e7000_write_inferior_memory (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
)
1222 if (len
< 16 || using_tcp
|| using_pc
)
1223 return write_small (memaddr
, myaddr
, len
);
1225 return write_large (memaddr
, myaddr
, len
);
1228 /* Read LEN bytes from inferior memory at MEMADDR. Put the result
1229 at debugger address MYADDR. Returns length moved.
1231 Small transactions we send
1238 e7000_read_inferior_memory (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
)
1244 /* Starting address of this pass. */
1246 /* printf("READ INF %x %x %d\n", memaddr, myaddr, len); */
1247 if (((memaddr
- 1) + len
) < memaddr
)
1253 sprintf (buf
, "m %lx;l\r", memaddr
);
1254 puts_e7000debug (buf
);
1256 for (count
= 0; count
< len
; count
+= 4)
1258 /* Suck away the address */
1264 { /* Some kind of error */
1265 puts_e7000debug (".\r"); /* Some errors leave us in memory input mode */
1266 expect_full_prompt ();
1272 /* Now read in the data */
1273 for (i
= 0; i
< 4; i
++)
1276 if (count
+ i
< len
)
1278 myaddr
[count
+ i
] = b
;
1282 /* Skip the trailing ? and send a . to end and a cr for more */
1285 if (count
+ 4 >= len
)
1286 puts_e7000debug (".\r");
1288 puts_e7000debug ("\r");
1298 For large transfers we used to send
1301 d <addr> <endaddr>\r
1304 <ADDRESS> < D A T A > < ASCII CODE >
1305 00000000 5F FD FD FF DF 7F DF FF 01 00 01 00 02 00 08 04 "_..............."
1306 00000010 FF D7 FF 7F D7 F1 7F FF 00 05 00 00 08 00 40 00 "..............@."
1307 00000020 7F FD FF F7 7F FF FF F7 00 00 00 00 00 00 00 00 "................"
1309 A cost in chars for each transaction of 80 + 5*n-bytes.
1311 Large transactions could be done with the srecord load code, but
1312 there is a pause for a second before dumping starts, which slows the
1317 e7000_read_inferior_memory_large (CORE_ADDR memaddr
, unsigned char *myaddr
,
1324 /* Starting address of this pass. */
1326 if (((memaddr
- 1) + len
) < memaddr
)
1332 sprintf (buf
, "d %lx %lx\r", memaddr
, memaddr
+ len
- 1);
1333 puts_e7000debug (buf
);
1338 /* skip down to the first ">" */
1341 /* now skip to the end of that line */
1348 /* get rid of any white space before the address */
1352 /* Skip the address */
1355 /* read in the bytes on the line */
1356 while (c
!= '"' && count
< len
)
1362 myaddr
[count
++] = get_hex (&c
);
1365 /* throw out the rest of the line */
1370 /* wait for the ":" prompt */
1380 fast_but_for_the_pause_e7000_read_inferior_memory (CORE_ADDR memaddr
,
1381 char *myaddr
, int len
)
1387 if (((memaddr
- 1) + len
) < memaddr
)
1393 sprintf (buf
, "is %x@%x:s\r", memaddr
, len
);
1394 puts_e7000debug (buf
);
1400 error ("Memory read error");
1402 putchar_e7000 (ACK
);
1415 case ENQ
: /* ENQ, at the end */
1419 /* Start of an Srecord */
1424 case '7': /* Termination record, ignore */
1428 /* Header record - ignore it */
1440 alen
= type
- '0' + 1;
1444 addr
= (addr
<< 8) + gbyte ();
1448 for (i
= 0; i
< length
- 1; i
++)
1449 myaddr
[i
+ addr
- memaddr
] = gbyte ();
1451 gbyte (); /* Ignore checksum */
1457 putchar_e7000 (ACK
);
1458 expect ("TOP ADDRESS =");
1459 expect ("END ADDRESS =");
1467 /* Transfer LEN bytes between GDB address MYADDR and target address
1468 MEMADDR. If WRITE is non-zero, transfer them to the target,
1469 otherwise transfer them from the target. TARGET is unused.
1471 Returns the number of bytes transferred. */
1474 e7000_xfer_inferior_memory (CORE_ADDR memaddr
, char *myaddr
,
1476 struct mem_attrib
*attrib ATTRIBUTE_UNUSED
,
1477 struct target_ops
*target ATTRIBUTE_UNUSED
)
1480 return e7000_write_inferior_memory (memaddr
, myaddr
, len
);
1482 return e7000_read_inferior_memory (memaddr
, myaddr
, len
);
1484 return e7000_read_inferior_memory_large (memaddr
, myaddr
, len
);
1493 e7000_load (char *args
, int from_tty
)
1495 struct cleanup
*old_chain
;
1499 #define WRITESIZE 0x1000
1500 char buf
[2 + 4 + 4 + WRITESIZE
]; /* `DT' + <addr> + <len> + <data> */
1504 time_t start_time
, end_time
; /* Start and end times of download */
1505 unsigned long data_count
; /* Number of bytes transferred to memory */
1506 int oldtimeout
= timeout
;
1508 timeout
= remote_timeout
;
1511 /* FIXME! change test to test for type of download */
1514 generic_load (args
, from_tty
);
1518 /* for direct tcp connections, we can do a fast binary download */
1525 while (*args
!= '\000')
1529 while (isspace (*args
))
1534 while ((*args
!= '\000') && !isspace (*args
))
1537 if (*args
!= '\000')
1542 else if (strncmp (arg
, "-quiet", strlen (arg
)) == 0)
1544 else if (strncmp (arg
, "-nostart", strlen (arg
)) == 0)
1547 error ("unknown option `%s'", arg
);
1551 filename
= get_exec_file (1);
1553 pbfd
= bfd_openr (filename
, gnutarget
);
1556 perror_with_name (filename
);
1559 old_chain
= make_cleanup_bfd_close (pbfd
);
1561 if (!bfd_check_format (pbfd
, bfd_object
))
1562 error ("\"%s\" is not an object file: %s", filename
,
1563 bfd_errmsg (bfd_get_error ()));
1565 start_time
= time (NULL
);
1568 puts_e7000debug ("mw\r");
1572 for (section
= pbfd
->sections
; section
; section
= section
->next
)
1574 if (bfd_get_section_flags (pbfd
, section
) & SEC_LOAD
)
1576 bfd_vma section_address
;
1577 bfd_size_type section_size
;
1580 section_address
= bfd_get_section_vma (pbfd
, section
);
1581 section_size
= bfd_get_section_size_before_reloc (section
);
1584 printf_filtered ("[Loading section %s at 0x%x (%ud bytes)]\n",
1585 bfd_get_section_name (pbfd
, section
),
1591 data_count
+= section_size
;
1593 while (section_size
> 0)
1596 static char inds
[] = "|/-\\";
1601 count
= min (section_size
, WRITESIZE
);
1603 buf
[2] = section_address
>> 24;
1604 buf
[3] = section_address
>> 16;
1605 buf
[4] = section_address
>> 8;
1606 buf
[5] = section_address
;
1608 buf
[6] = count
>> 24;
1609 buf
[7] = count
>> 16;
1610 buf
[8] = count
>> 8;
1613 bfd_get_section_contents (pbfd
, section
, buf
+ 10, fptr
, count
);
1615 if (SERIAL_WRITE (e7000_desc
, buf
, count
+ 10))
1616 fprintf_unfiltered (gdb_stderr
,
1617 "e7000_load: SERIAL_WRITE failed: %s\n",
1618 safe_strerror (errno
));
1624 printf_unfiltered ("\r%c", inds
[k
++ % 4]);
1625 gdb_flush (gdb_stdout
);
1628 section_address
+= count
;
1630 section_size
-= count
;
1639 end_time
= time (NULL
);
1641 /* Finally, make the PC point at the start address */
1644 write_pc (bfd_get_start_address (exec_bfd
));
1646 inferior_pid
= 0; /* No process now */
1648 /* This is necessary because many things were based on the PC at the time that
1649 we attached to the monitor, which is no longer valid now that we have loaded
1650 new code (and just changed the PC). Another way to do this might be to call
1651 normal_stop, except that the stack may not be valid, and things would get
1652 horribly confused... */
1654 clear_symtab_users ();
1658 entry
= bfd_get_start_address (pbfd
);
1661 printf_unfiltered ("[Starting %s at 0x%x]\n", filename
, entry
);
1663 /* start_routine (entry); */
1666 report_transfer_performance (data_count
, start_time
, end_time
);
1668 do_cleanups (old_chain
);
1669 timeout
= oldtimeout
;
1672 /* Clean up when a program exits.
1674 The program actually lives on in the remote processor's RAM, and may be
1675 run again without a download. Don't leave it full of breakpoint
1679 e7000_mourn_inferior (void)
1681 remove_breakpoints ();
1682 unpush_target (&e7000_ops
);
1683 generic_mourn_inferior (); /* Do all the proper things now */
1686 #define MAX_BREAKPOINTS 200
1687 #ifdef HARD_BREAKPOINTS
1688 #define MAX_E7000DEBUG_BREAKPOINTS (BC_BREAKPOINTS ? 5 : MAX_BREAKPOINTS)
1690 #define MAX_E7000DEBUG_BREAKPOINTS MAX_BREAKPOINTS
1693 /* Since we can change to soft breakpoints dynamically, we must define
1694 more than enough. Was breakaddr[MAX_E7000DEBUG_BREAKPOINTS]. */
1695 static CORE_ADDR breakaddr
[MAX_BREAKPOINTS
] =
1699 e7000_insert_breakpoint (CORE_ADDR addr
, char *shadow
)
1704 static char nop
[2] = NOP
;
1707 for (i
= 0; i
<= MAX_E7000DEBUG_BREAKPOINTS
; i
++)
1708 if (breakaddr
[i
] == 0)
1710 breakaddr
[i
] = addr
;
1711 /* Save old contents, and insert a nop in the space */
1712 #ifdef HARD_BREAKPOINTS
1715 sprintf (buf
, "BC%d A=%lx\r", i
+ 1, addr
);
1716 puts_e7000debug (buf
);
1720 sprintf (buf
, "B %lx\r", addr
);
1721 puts_e7000debug (buf
);
1725 e7000_read_inferior_memory (addr
, shadow
, 2);
1726 e7000_write_inferior_memory (addr
, nop
, 2);
1729 sprintf (buf
, "B %x\r", addr
);
1730 puts_e7000debug (buf
);
1736 error ("Too many breakpoints ( > %d) for the E7000\n",
1737 MAX_E7000DEBUG_BREAKPOINTS
);
1742 e7000_remove_breakpoint (CORE_ADDR addr
, char *shadow
)
1747 for (i
= 0; i
< MAX_E7000DEBUG_BREAKPOINTS
; i
++)
1748 if (breakaddr
[i
] == addr
)
1751 #ifdef HARD_BREAKPOINTS
1754 sprintf (buf
, "BC%d - \r", i
+ 1);
1755 puts_e7000debug (buf
);
1759 sprintf (buf
, "B - %lx\r", addr
);
1760 puts_e7000debug (buf
);
1764 sprintf (buf
, "B - %lx\r", addr
);
1765 puts_e7000debug (buf
);
1769 /* Replace the insn under the break */
1770 e7000_write_inferior_memory (addr
, shadow
, 2);
1777 warning ("Can't find breakpoint associated with 0x%lx\n", addr
);
1781 /* Put a command string, in args, out to STDBUG. Output from STDBUG
1782 is placed on the users terminal until the prompt is seen. */
1785 e7000_command (char *args
, int fromtty
)
1787 /* FIXME: arbitrary limit on length of args. */
1793 error ("e7000 target not open.");
1796 puts_e7000debug ("\r");
1800 sprintf (buf
, "%s\r", args
);
1801 puts_e7000debug (buf
);
1806 expect_full_prompt ();
1809 printf_unfiltered ("\n");
1811 /* Who knows what the command did... */
1812 registers_changed ();
1817 e7000_drain_command (char *args
, int fromtty
)
1821 puts_e7000debug ("end\r");
1822 putchar_e7000 (CTRLC
);
1824 while ((c
= readchar (1) != -1))
1828 putchar_e7000 (CTRLC
);
1831 if (c
> ' ' && c
< 127)
1832 printf_unfiltered ("%c", c
& 0xff);
1834 printf_unfiltered ("<%x>", c
& 0xff);
1843 static char *strings
[NITEMS
] =
1850 "ILLEGAL INSTRUCTION",
1857 for (i
= 0; i
< NITEMS
; ++i
)
1863 for (i
= 0; i
< NITEMS
; i
++)
1870 /* found one of the choices */
1882 /* Suck characters, if a string match, then return the strings index
1883 otherwise echo them. */
1886 expect_n (char **strings
)
1892 char *buffer
= saveaway
;
1893 /* Count number of expect strings */
1895 for (n
= 0; strings
[n
]; n
++)
1897 ptr
[n
] = strings
[n
];
1908 printf_unfiltered ("[waiting for e7000...]\n");
1921 putchar_e7000 (CTRLC
); /* interrupt the running program */
1925 for (i
= 0; i
< n
; i
++)
1932 /* Gone all the way */
1939 ptr
[i
] = strings
[i
];
1945 /* Save it up incase we find that there was no match */
1950 if (buffer
!= saveaway
)
1953 printf_unfiltered ("%s", buffer
);
1958 putchar_unfiltered (c
);
1959 gdb_flush (gdb_stdout
);
1965 /* We subtract two from the pc here rather than use
1966 DECR_PC_AFTER_BREAK since the e7000 doesn't always add two to the
1967 pc, and the simulators never do. */
1975 store_signed_integer (buf
,
1976 REGISTER_RAW_SIZE (PC_REGNUM
),
1977 read_register (PC_REGNUM
) - 2);
1978 supply_register (PC_REGNUM
, buf
);
1979 sprintf (buf2
, ".PC %lx\r", read_register (PC_REGNUM
));
1980 puts_e7000debug (buf2
);
1985 #define WAS_RUNNING 2
1988 static char *estrings
[] =
1997 /* Wait until the remote machine stops, then return, storing status in
1998 STATUS just as `wait' would. */
2001 e7000_wait (int pid
, struct target_waitstatus
*status
)
2005 int running_count
= 0;
2010 /* Then echo chars until PC= string seen */
2011 gch (); /* Drop cr */
2012 gch (); /* and space */
2016 switch (expect_n (estrings
))
2019 /* how did this happen ? */
2024 putchar_e7000 (CTRLC
);
2032 if (running_count
== 20)
2034 printf_unfiltered ("[running...]\n");
2044 /* Skip till the PC= */
2047 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_sh
)
2049 wanted_nopc
= want_nopc_sh
;
2050 switch (TARGET_ARCHITECTURE
->mach
)
2055 wanted_nopc
= want_nopc_sh3
;
2058 #ifdef GDB_TARGET_IS_H8300
2059 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_h8300
)
2062 wanted_nopc
= want_nopc_h8300s
;
2064 wanted_nopc
= want_nopc_h8300h
;
2067 fetch_regs_from_dump (gch
, wanted_nopc
);
2069 /* And supply the extra ones the simulator uses */
2070 for (regno
= NUM_REALREGS
; regno
< NUM_REGS
; regno
++)
2073 supply_register (regno
, (char *) &buf
);
2076 stop_reason
= why_stop ();
2077 expect_full_prompt ();
2079 status
->kind
= TARGET_WAITKIND_STOPPED
;
2080 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2082 switch (stop_reason
)
2084 case 1: /* Breakpoint */
2085 write_pc (read_pc ()); /* PC is always off by 2 for breakpoints */
2086 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2088 case 0: /* Single step */
2089 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2091 case 2: /* Interrupt */
2094 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2099 status
->value
.sig
= TARGET_SIGNAL_INT
;
2105 printf_unfiltered ("a cycle address error?\n");
2106 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2109 status
->value
.sig
= TARGET_SIGNAL_ILL
;
2112 status
->value
.sig
= TARGET_SIGNAL_SEGV
;
2114 case 7: /* Anything else (NITEMS + 1) */
2115 printf_unfiltered ("a write protect error?\n");
2116 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2119 /* Get the user's attention - this should never happen. */
2120 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
2126 /* Stop the running program. */
2131 /* Sending a ^C is supposed to stop the running program. */
2132 putchar_e7000 (CTRLC
);
2135 /* Define the target subroutine names. */
2137 struct target_ops e7000_ops
;
2140 init_e7000_ops (void)
2142 e7000_ops
.to_shortname
= "e7000";
2143 e7000_ops
.to_longname
= "Remote Hitachi e7000 target";
2144 e7000_ops
.to_doc
= "Use a remote Hitachi e7000 ICE connected by a serial line;\n\
2145 or a network connection.\n\
2146 Arguments are the name of the device for the serial line,\n\
2147 the speed to connect at in bits per second.\n\
2149 target e7000 /dev/ttya 9600\n\
2150 target e7000 foobar";
2151 e7000_ops
.to_open
= e7000_open
;
2152 e7000_ops
.to_close
= e7000_close
;
2153 e7000_ops
.to_attach
= 0;
2154 e7000_ops
.to_post_attach
= NULL
;
2155 e7000_ops
.to_require_attach
= NULL
;
2156 e7000_ops
.to_detach
= e7000_detach
;
2157 e7000_ops
.to_require_detach
= NULL
;
2158 e7000_ops
.to_resume
= e7000_resume
;
2159 e7000_ops
.to_wait
= e7000_wait
;
2160 e7000_ops
.to_post_wait
= NULL
;
2161 e7000_ops
.to_fetch_registers
= e7000_fetch_register
;
2162 e7000_ops
.to_store_registers
= e7000_store_register
;
2163 e7000_ops
.to_prepare_to_store
= e7000_prepare_to_store
;
2164 e7000_ops
.to_xfer_memory
= e7000_xfer_inferior_memory
;
2165 e7000_ops
.to_files_info
= e7000_files_info
;
2166 e7000_ops
.to_insert_breakpoint
= e7000_insert_breakpoint
;
2167 e7000_ops
.to_remove_breakpoint
= e7000_remove_breakpoint
;
2168 e7000_ops
.to_terminal_init
= 0;
2169 e7000_ops
.to_terminal_inferior
= 0;
2170 e7000_ops
.to_terminal_ours_for_output
= 0;
2171 e7000_ops
.to_terminal_ours
= 0;
2172 e7000_ops
.to_terminal_info
= 0;
2173 e7000_ops
.to_kill
= e7000_kill
;
2174 e7000_ops
.to_load
= e7000_load
;
2175 e7000_ops
.to_lookup_symbol
= 0;
2176 e7000_ops
.to_create_inferior
= e7000_create_inferior
;
2177 e7000_ops
.to_post_startup_inferior
= NULL
;
2178 e7000_ops
.to_acknowledge_created_inferior
= NULL
;
2179 e7000_ops
.to_clone_and_follow_inferior
= NULL
;
2180 e7000_ops
.to_post_follow_inferior_by_clone
= NULL
;
2181 e7000_ops
.to_insert_fork_catchpoint
= NULL
;
2182 e7000_ops
.to_remove_fork_catchpoint
= NULL
;
2183 e7000_ops
.to_insert_vfork_catchpoint
= NULL
;
2184 e7000_ops
.to_remove_vfork_catchpoint
= NULL
;
2185 e7000_ops
.to_has_forked
= NULL
;
2186 e7000_ops
.to_has_vforked
= NULL
;
2187 e7000_ops
.to_can_follow_vfork_prior_to_exec
= NULL
;
2188 e7000_ops
.to_post_follow_vfork
= NULL
;
2189 e7000_ops
.to_insert_exec_catchpoint
= NULL
;
2190 e7000_ops
.to_remove_exec_catchpoint
= NULL
;
2191 e7000_ops
.to_has_execd
= NULL
;
2192 e7000_ops
.to_reported_exec_events_per_exec_call
= NULL
;
2193 e7000_ops
.to_has_exited
= NULL
;
2194 e7000_ops
.to_mourn_inferior
= e7000_mourn_inferior
;
2195 e7000_ops
.to_can_run
= 0;
2196 e7000_ops
.to_notice_signals
= 0;
2197 e7000_ops
.to_thread_alive
= 0;
2198 e7000_ops
.to_stop
= e7000_stop
;
2199 e7000_ops
.to_pid_to_exec_file
= NULL
;
2200 e7000_ops
.to_core_file_to_sym_file
= NULL
;
2201 e7000_ops
.to_stratum
= process_stratum
;
2202 e7000_ops
.DONT_USE
= 0;
2203 e7000_ops
.to_has_all_memory
= 1;
2204 e7000_ops
.to_has_memory
= 1;
2205 e7000_ops
.to_has_stack
= 1;
2206 e7000_ops
.to_has_registers
= 1;
2207 e7000_ops
.to_has_execution
= 1;
2208 e7000_ops
.to_sections
= 0;
2209 e7000_ops
.to_sections_end
= 0;
2210 e7000_ops
.to_magic
= OPS_MAGIC
;
2214 _initialize_remote_e7000 (void)
2217 add_target (&e7000_ops
);
2219 add_com ("e7000", class_obscure
, e7000_command
,
2220 "Send a command to the e7000 monitor.");
2222 add_com ("ftplogin", class_obscure
, e7000_login_command
,
2223 "Login to machine and change to directory.");
2225 add_com ("ftpload", class_obscure
, e7000_ftp_command
,
2226 "Fetch and load a file from previously described place.");
2228 add_com ("drain", class_obscure
, e7000_drain_command
,
2229 "Drain pending e7000 text buffers.");
2231 add_show_from_set (add_set_cmd ("usehardbreakpoints", no_class
,
2232 var_integer
, (char *) &use_hard_breakpoints
,
2233 "Set use of hardware breakpoints for all breakpoints.\n", &setlist
),