1 /* Remote debugging interface for Hitachi E7000 ICE, for GDB
2 Copyright 1993, 1994, 1996, 1997, 1998 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 Written by Steve Chamberlain for Cygnus Support.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
24 /* The E7000 is an in-circuit emulator for the Hitachi H8/300-H and
25 Hitachi-SH processor. It has serial port and a lan port.
27 The monitor command set makes it difficult to load large ammounts of
28 data over the lan without using ftp - so try not to issue load
29 commands when communicating over ethernet; use the ftpload command.
31 The monitor pauses for a second when dumping srecords to the serial
32 line too, so we use a slower per byte mechanism but without the
33 startup overhead. Even so, it's pretty slow... */
44 #include "gdb_string.h"
46 #include <sys/types.h>
48 #include "remote-utils.h"
55 #define HARD_BREAKPOINTS /* Now handled by set option. */
56 #define BC_BREAKPOINTS use_hard_breakpoints
64 extern void notice_quit
PARAMS ((void));
66 extern void report_transfer_performance
PARAMS ((unsigned long,
69 extern char *sh_processor_type
;
71 /* Local function declarations. */
73 static void e7000_close
PARAMS ((int));
75 static void e7000_fetch_register
PARAMS ((int));
77 static void e7000_store_register
PARAMS ((int));
79 static void e7000_command
PARAMS ((char *, int));
81 static void e7000_login_command
PARAMS ((char *, int));
83 static void e7000_ftp_command
PARAMS ((char *, int));
85 static void e7000_drain_command
PARAMS ((char *, int));
87 static void expect
PARAMS ((char *));
89 static void expect_full_prompt
PARAMS ((void));
91 static void expect_prompt
PARAMS ((void));
93 static int e7000_parse_device
PARAMS ((char *args
, char *dev_name
,
97 static serial_t e7000_desc
;
99 /* Allow user to chose between using hardware breakpoints or memory. */
100 static int use_hard_breakpoints
= 0; /* use sw breakpoints by default */
102 /* Nonzero if using the tcp serial driver. */
104 static int using_tcp
; /* direct tcp connection to target */
105 static int using_tcp_remote
; /* indirect connection to target
106 via tcp to controller */
108 /* Nonzero if using the pc isa card. */
112 extern struct target_ops e7000_ops
; /* Forward declaration */
114 char *ENQSTRING
= "\005";
116 /* Nonzero if some routine (as opposed to the user) wants echoing.
117 FIXME: Do this reentrantly with an extra parameter. */
123 static int timeout
= 20;
125 /* Send data to e7000debug. */
128 puts_e7000debug (buf
)
132 error ("Use \"target e7000 ...\" first.");
135 printf_unfiltered ("Sending %s\n", buf
);
137 if (SERIAL_WRITE (e7000_desc
, buf
, strlen (buf
)))
138 fprintf_unfiltered (gdb_stderr
, "SERIAL_WRITE failed: %s\n", safe_strerror (errno
));
140 /* And expect to see it echoed, unless using the pc interface */
154 SERIAL_WRITE (e7000_desc
, b
, 1);
161 SERIAL_WRITE (e7000_desc
, s
, strlen (s
));
173 /* Read a character from the remote system, doing all the fancy timeout
174 stuff. Handles serial errors and EOF. If TIMEOUT == 0, and no chars,
175 returns -1, else returns next char. Discards chars > 127. */
185 c
= SERIAL_READCHAR (e7000_desc
, timeout
);
189 if (c
== SERIAL_TIMEOUT
)
194 error ("Timeout reading from remote system.");
197 error ("Serial communication error");
201 putchar_unfiltered (c
);
202 gdb_flush (gdb_stdout
);
212 static char b
[8][10];
224 sprintf (b
[p
], "<%d>", x
);
231 /* Scan input from the remote system, until STRING is found. If
232 DISCARD is non-zero, then discard non-matching input, else print it
233 out. Let the user break out immediately. */
245 c
= readchar (timeout
);
252 putchar_e7000 (CTRLC
);
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 ()
319 convert_hex_digit (ch
)
322 if (ch
>= '0' && ch
<= '9')
324 else if (ch
>= 'A' && ch
<= 'F')
325 return ch
- 'A' + 10;
326 else if (ch
>= 'a' && ch
<= 'f')
327 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 (n
, regno
)
360 for (i
= 0; i
< n
; i
++)
365 for (j
= 0; j
< 8; j
++)
366 val
= (val
<< 4) + get_hex_digit (j
== 0);
367 supply_register (regno
++, (char *) &val
);
372 /* This is called not only when we first attach, but also when the
373 user types "run" after having attached. */
376 e7000_create_inferior (execfile
, args
, env
)
384 error ("Can't pass arguments to remote E7000DEBUG process");
386 if (execfile
== 0 || exec_bfd
== 0)
387 error ("No executable file specified");
389 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
391 #ifdef CREATE_INFERIOR_HOOK
392 CREATE_INFERIOR_HOOK (0); /* No process-ID */
395 /* The "process" (board) is already stopped awaiting our commands, and
396 the program is already downloaded. We just set its PC and go. */
398 clear_proceed_status ();
400 /* Tell wait_for_inferior that we've started a new process. */
401 init_wait_for_inferior ();
403 /* Set up the "saved terminal modes" of the inferior
404 based on what modes we are starting it with. */
405 target_terminal_init ();
407 /* Install inferior's terminal modes. */
408 target_terminal_inferior ();
410 /* insert_step_breakpoint (); FIXME, do we need this? */
411 proceed ((CORE_ADDR
) entry_pt
, -1, 0); /* Let 'er rip... */
414 /* Open a connection to a remote debugger. NAME is the filename used
415 for communication. */
417 static int baudrate
= 9600;
418 static char dev_name
[100];
420 static char *machine
= "";
421 static char *user
= "";
422 static char *passwd
= "";
423 static char *dir
= "";
425 /* Grab the next token and buy some space for it */
436 while (*p
&& *p
== ' ')
439 while (*p
&& (*p
!= ' ' && *p
!= '\t'))
452 e7000_login_command (args
, from_tty
)
458 machine
= next (&args
);
460 passwd
= next (&args
);
464 printf_unfiltered ("Set info to %s %s %s %s\n", machine
, user
, passwd
, dir
);
469 error ("Syntax is ftplogin <machine> <user> <passwd> <directory>");
473 /* Start an ftp transfer from the E7000 to a host */
476 e7000_ftp_command (args
, from_tty
)
480 /* FIXME: arbitrary limit on machine names and such. */
483 int oldtimeout
= timeout
;
484 timeout
= remote_timeout
;
486 sprintf (buf
, "ftp %s\r", machine
);
487 puts_e7000debug (buf
);
488 expect (" Username : ");
489 sprintf (buf
, "%s\r", user
);
490 puts_e7000debug (buf
);
491 expect (" Password : ");
492 write_e7000 (passwd
);
494 expect ("success\r");
496 sprintf (buf
, "cd %s\r", dir
);
497 puts_e7000debug (buf
);
499 sprintf (buf
, "ll 0;s:%s\r", args
);
500 puts_e7000debug (buf
);
502 puts_e7000debug ("bye\r");
504 timeout
= oldtimeout
;
508 e7000_parse_device (args
, dev_name
, 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 (dummy
)
571 immediate_quit
= 1; /* Allow user to interrupt it */
573 /* Hello? Are you there? */
578 putchar_e7000 (CTRLC
);
579 while (!sync
&& ++try <= quit_trying
)
583 printf_unfiltered ("[waiting for e7000...]\n");
588 /* FIXME! this didn't seem right-> while (c != SERIAL_TIMEOUT)
589 * we get stuck in this loop ...
590 * We may never timeout, and never sync up :-(
592 while (!sync
&& c
!= -1)
597 putchar_unfiltered (c
);
598 gdb_flush (gdb_stdout
);
600 /* Shouldn't we either break here, or check for sync in inner loop? */
606 putchar_e7000 (CTRLC
);
614 putchar_e7000 (CTRLC
);
615 /* Was-> quit_flag = 0; */
617 quit_trying
= try + 1; /* we don't want to try anymore */
628 fprintf_unfiltered (gdb_stderr
, "Giving up after %d tries...\n", try);
629 error ("Unable to syncronize with target.\n");
632 puts_e7000debug ("\r");
634 puts_e7000debug ("b -\r"); /* Clear breakpoints */
639 /* This is really the job of start_remote however, that makes an assumption
640 that the target is about to print out a status message of some sort. That
641 doesn't happen here. */
643 flush_cached_frames ();
644 registers_changed ();
645 stop_pc
= read_pc ();
646 set_current_frame (create_new_frame (read_fp (), stop_pc
));
647 select_frame (get_current_frame (), 0);
648 print_stack_frame (selected_frame
, -1, 1);
654 e7000_open (args
, from_tty
)
660 target_preopen (from_tty
);
662 n
= e7000_parse_device (args
, dev_name
, baudrate
);
664 push_target (&e7000_ops
);
666 e7000_desc
= SERIAL_OPEN (dev_name
);
669 perror_with_name (dev_name
);
671 SERIAL_SETBAUDRATE (e7000_desc
, baudrate
);
672 SERIAL_RAW (e7000_desc
);
674 #ifdef GDB_TARGET_IS_H8300
678 /* Start the remote connection; if error (0), discard this target.
679 In particular, if the user quits, be sure to discard it
680 (we'd be in an inconsistent state otherwise). */
681 if (!catch_errors (e7000_start_remote
, (char *) 0,
682 "Couldn't establish connection to remote target\n", RETURN_MASK_ALL
))
684 printf_filtered ("Remote target %s connected to %s\n", target_shortname
,
688 /* Close out all files and local state before this target loses control. */
691 e7000_close (quitting
)
696 SERIAL_CLOSE (e7000_desc
);
701 /* Terminate the open connection to the remote debugger. Use this
702 when you want to detach and do something else with your gdb. */
705 e7000_detach (from_tty
)
708 pop_target (); /* calls e7000_close to do the real work */
710 printf_unfiltered ("Ending remote %s debugging\n", target_shortname
);
713 /* Tell the remote machine to resume. */
716 e7000_resume (pid
, step
, sig
)
720 puts_e7000debug ("S\r");
722 puts_e7000debug ("G\r");
725 /* Read the remote registers into the block REGS.
727 For the H8/300 a register dump looks like:
729 PC=00021A CCR=80:I*******
730 ER0 - ER3 0000000A 0000002E 0000002E 00000000
731 ER4 - ER7 00000000 00000000 00000000 00FFEFF6
737 #ifdef GDB_TARGET_IS_H8300
739 char *want_h8300h
= "PC=%p CCR=%c\n\
740 ER0 - ER3 %0 %1 %2 %3\n\
741 ER4 - ER7 %4 %5 %6 %7\n";
743 char *want_nopc_h8300h
= "%p CCR=%c\n\
744 ER0 - ER3 %0 %1 %2 %3\n\
745 ER4 - ER7 %4 %5 %6 %7";
747 char *want_h8300s
= "PC=%p CCR=%c\n\
749 ER0 - ER3 %0 %1 %2 %3\n\
750 ER4 - ER7 %4 %5 %6 %7\n";
752 char *want_nopc_h8300s
= "%p CCR=%c EXR=%9\n\
753 ER0 - ER3 %0 %1 %2 %3\n\
754 ER4 - ER7 %4 %5 %6 %7";
758 #ifdef GDB_TARGET_IS_SH
760 char *want
= "PC=%16 SR=%22\n\
761 PR=%17 GBR=%18 VBR=%19\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";
766 char *want_nopc
= "%16 SR=%22\n\
767 PR=%17 GBR=%18 VBR=%19\n\
769 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
770 R8-15 %8 %9 %10 %11 %12 %13 %14 %15";
772 char *want_sh3
= "PC=%16 SR=%22\n\
773 PR=%17 GBR=%18 VBR=%19\n\
774 MACH=%20 MACL=%21 SSR=%23 SPC=%24\n\
775 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
776 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
777 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
778 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
779 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
780 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
782 char *want_sh3_nopc
= "%16 SR=%22\n\
783 PR=%17 GBR=%18 VBR=%19\n\
784 MACH=%20 MACL=%21 SSR=%22 SPC=%23\n\
785 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
786 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
787 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
788 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
789 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
790 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
797 return readchar (timeout
);
803 int high
= convert_hex_digit (gch ());
804 int low
= convert_hex_digit (gch ());
806 return (high
<< 4) + low
;
810 fetch_regs_from_dump (nextchar
, want
)
815 char buf
[MAX_REGISTER_RAW_SIZE
];
817 int thischar
= nextchar ();
824 /* Skip to end of line and then eat all new line type stuff */
825 while (thischar
!= '\n' && thischar
!= '\r')
826 thischar
= nextchar ();
827 while (thischar
== '\n' || thischar
== '\r')
828 thischar
= nextchar ();
833 while (thischar
== ' '
837 thischar
= nextchar ();
842 if (*want
== thischar
)
846 thischar
= nextchar ();
849 else if (thischar
== ' ' || thischar
== '\n' || thischar
== '\r')
851 thischar
= nextchar ();
855 error ("out of sync in fetch registers wanted <%s>, got <%c 0x%x>",
856 want
, thischar
, thischar
);
861 /* Got a register command */
891 if (isdigit (want
[0]))
893 if (isdigit (want
[1]))
895 regno
= (want
[0] - '0') * 10 + want
[1] - '0';
900 regno
= want
[0] - '0';
908 store_signed_integer (buf
,
909 REGISTER_RAW_SIZE (regno
),
910 (LONGEST
) get_hex (&thischar
, nextchar
));
911 supply_register (regno
, buf
);
918 e7000_fetch_registers ()
923 puts_e7000debug ("R\r");
925 #ifdef GDB_TARGET_IS_SH
927 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_sh
)
928 switch (TARGET_ARCHITECTURE
->mach
)
937 wanted
= want_h8300s
;
939 wanted
= want_h8300h
;
941 fetch_regs_from_dump (gch
, wanted
);
943 /* And supply the extra ones the simulator uses */
944 for (regno
= NUM_REALREGS
; regno
< NUM_REGS
; regno
++)
948 supply_register (regno
, (char *) (&buf
));
952 /* Fetch register REGNO, or all registers if REGNO is -1. Returns
956 e7000_fetch_register (regno
)
959 e7000_fetch_registers ();
962 /* Store the remote registers from the contents of the block REGS. */
965 e7000_store_registers ()
969 for (regno
= 0; regno
< NUM_REALREGS
; regno
++)
970 e7000_store_register (regno
);
972 registers_changed ();
975 /* Store register REGNO, or all if REGNO == 0. Return errno value. */
978 e7000_store_register (regno
)
985 e7000_store_registers ();
989 #ifdef GDB_TARGET_IS_H8300
992 sprintf (buf
, ".ER%d %x\r", regno
, read_register (regno
));
993 puts_e7000debug (buf
);
995 else if (regno
== PC_REGNUM
)
997 sprintf (buf
, ".PC %x\r", read_register (regno
));
998 puts_e7000debug (buf
);
1000 else if (regno
== CCR_REGNUM
)
1002 sprintf (buf
, ".CCR %x\r", read_register (regno
));
1003 puts_e7000debug (buf
);
1005 #endif /* GDB_TARGET_IS_H8300 */
1007 #ifdef GDB_TARGET_IS_SH
1011 sprintf (buf
, ".R%d %x\r", regno
, read_register (regno
));
1012 puts_e7000debug (buf
);
1016 sprintf (buf
, ".PC %x\r", read_register (regno
));
1017 puts_e7000debug (buf
);
1021 sprintf (buf
, ".SR %x\r", read_register (regno
));
1022 puts_e7000debug (buf
);
1026 sprintf (buf
, ".PR %x\r", read_register (regno
));
1027 puts_e7000debug (buf
);
1031 sprintf (buf
, ".GBR %x\r", read_register (regno
));
1032 puts_e7000debug (buf
);
1036 sprintf (buf
, ".VBR %x\r", read_register (regno
));
1037 puts_e7000debug (buf
);
1041 sprintf (buf
, ".MACH %x\r", read_register (regno
));
1042 puts_e7000debug (buf
);
1046 sprintf (buf
, ".MACL %x\r", read_register (regno
));
1047 puts_e7000debug (buf
);
1051 #endif /* GDB_TARGET_IS_SH */
1056 /* Get ready to modify the registers array. On machines which store
1057 individual registers, this doesn't need to do anything. On machines
1058 which store all the registers in one fell swoop, this makes sure
1059 that registers contains all the registers from the program being
1063 e7000_prepare_to_store ()
1065 /* Do nothing, since we can store individual regs */
1071 printf_unfiltered ("\tAttached to %s at %d baud.\n", dev_name
, baudrate
);
1075 stickbyte (where
, what
)
1079 static CONST
char digs
[] = "0123456789ABCDEF";
1081 where
[0] = digs
[(what
>> 4) & 0xf];
1082 where
[1] = digs
[(what
& 0xf) & 0xf];
1087 /* Write a small ammount of memory. */
1090 write_small (memaddr
, myaddr
, len
)
1092 unsigned char *myaddr
;
1098 for (i
= 0; i
< len
; i
++)
1100 if (((memaddr
+ i
) & 3) == 0 && (i
+ 3 < len
))
1102 /* Can be done with a long word */
1103 sprintf (buf
, "m %x %x%02x%02x%02x;l\r",
1105 myaddr
[i
], myaddr
[i
+ 1], myaddr
[i
+ 2], myaddr
[i
+ 3]);
1106 puts_e7000debug (buf
);
1111 sprintf (buf
, "m %x %x\r", memaddr
+ i
, myaddr
[i
]);
1112 puts_e7000debug (buf
);
1121 /* Write a large ammount of memory, this only works with the serial
1122 mode enabled. Command is sent as
1137 write_large (memaddr
, myaddr
, len
)
1139 unsigned char *myaddr
;
1143 #define maxstride 128
1146 puts_e7000debug ("IL ;S:FK\r");
1148 putchar_e7000 (ACK
);
1151 for (i
= 0; i
< len
; i
+= stride
)
1153 char compose
[maxstride
* 2 + 50];
1154 int address
= i
+ memaddr
;
1161 if (stride
> maxstride
)
1164 compose
[where
++] = 'S';
1166 if (address
>= 0xffffff)
1168 else if (address
>= 0xffff)
1173 compose
[where
++] = alen
- 1 + '0';
1174 /* Insert length. */
1175 check_sum
+= stickbyte (compose
+ where
, alen
+ stride
+ 1);
1180 check_sum
+= stickbyte (compose
+ where
, address
>> (8 * (alen
)));
1184 for (j
= 0; j
< stride
; j
++)
1186 check_sum
+= stickbyte (compose
+ where
, myaddr
[i
+ j
]);
1189 stickbyte (compose
+ where
, ~check_sum
);
1191 compose
[where
++] = '\r';
1192 compose
[where
++] = '\n';
1193 compose
[where
++] = 0;
1195 SERIAL_WRITE (e7000_desc
, compose
, where
);
1199 /* This is ok - nothing there */
1203 /* Hmm, it's trying to tell us something */
1205 error ("Error writing memory");
1209 printf_unfiltered ("@%d}@", j
);
1210 while ((j
= readchar (0)) > 0)
1212 printf_unfiltered ("@{%d}@", j
);
1217 /* Send the trailer record */
1218 write_e7000 ("S70500000000FA\r");
1219 putchar_e7000 (CTRLZ
);
1221 putchar_e7000 (ACK
);
1227 /* Copy LEN bytes of data from debugger memory at MYADDR to inferior's
1228 memory at MEMADDR. Returns length moved.
1230 Can't use the Srecord load over ethernet, so don't use fast method
1234 e7000_write_inferior_memory (memaddr
, myaddr
, len
)
1236 unsigned char *myaddr
;
1239 if (len
< 16 || using_tcp
|| using_pc
)
1240 return write_small (memaddr
, myaddr
, len
);
1242 return write_large (memaddr
, myaddr
, len
);
1245 /* Read LEN bytes from inferior memory at MEMADDR. Put the result
1246 at debugger address MYADDR. Returns length moved.
1248 Small transactions we send
1255 e7000_read_inferior_memory (memaddr
, myaddr
, len
)
1257 unsigned char *myaddr
;
1264 /* Starting address of this pass. */
1266 /* printf("READ INF %x %x %d\n", memaddr, myaddr, len); */
1267 if (((memaddr
- 1) + len
) < memaddr
)
1273 sprintf (buf
, "m %x;l\r", memaddr
);
1274 puts_e7000debug (buf
);
1276 for (count
= 0; count
< len
; count
+= 4)
1278 /* Suck away the address */
1284 { /* Some kind of error */
1285 puts_e7000debug (".\r"); /* Some errors leave us in memory input mode */
1286 expect_full_prompt ();
1292 /* Now read in the data */
1293 for (i
= 0; i
< 4; i
++)
1296 if (count
+ i
< len
)
1298 myaddr
[count
+ i
] = b
;
1302 /* Skip the trailing ? and send a . to end and a cr for more */
1305 if (count
+ 4 >= len
)
1306 puts_e7000debug (".\r");
1308 puts_e7000debug ("\r");
1318 For large transfers we used to send
1321 d <addr> <endaddr>\r
1324 <ADDRESS> < D A T A > < ASCII CODE >
1325 00000000 5F FD FD FF DF 7F DF FF 01 00 01 00 02 00 08 04 "_..............."
1326 00000010 FF D7 FF 7F D7 F1 7F FF 00 05 00 00 08 00 40 00 "..............@."
1327 00000020 7F FD FF F7 7F FF FF F7 00 00 00 00 00 00 00 00 "................"
1329 A cost in chars for each transaction of 80 + 5*n-bytes.
1331 Large transactions could be done with the srecord load code, but
1332 there is a pause for a second before dumping starts, which slows the
1337 e7000_read_inferior_memory_large (memaddr
, myaddr
, len
)
1339 unsigned char *myaddr
;
1346 /* Starting address of this pass. */
1348 if (((memaddr
- 1) + len
) < memaddr
)
1354 sprintf (buf
, "d %x %x\r", memaddr
, memaddr
+ len
- 1);
1355 puts_e7000debug (buf
);
1360 /* skip down to the first ">" */
1363 /* now skip to the end of that line */
1370 /* get rid of any white space before the address */
1374 /* Skip the address */
1377 /* read in the bytes on the line */
1378 while (c
!= '"' && count
< len
)
1384 myaddr
[count
++] = get_hex (&c
);
1387 /* throw out the rest of the line */
1392 /* wait for the ":" prompt */
1402 fast_but_for_the_pause_e7000_read_inferior_memory (memaddr
, myaddr
, len
)
1411 if (((memaddr
- 1) + len
) < memaddr
)
1417 sprintf (buf
, "is %x@%x:s\r", memaddr
, len
);
1418 puts_e7000debug (buf
);
1424 error ("Memory read error");
1426 putchar_e7000 (ACK
);
1439 case ENQ
: /* ENQ, at the end */
1443 /* Start of an Srecord */
1448 case '7': /* Termination record, ignore */
1452 /* Header record - ignore it */
1464 alen
= type
- '0' + 1;
1468 addr
= (addr
<< 8) + gbyte ();
1472 for (i
= 0; i
< length
- 1; i
++)
1473 myaddr
[i
+ addr
- memaddr
] = gbyte ();
1475 gbyte (); /* Ignore checksum */
1481 putchar_e7000 (ACK
);
1482 expect ("TOP ADDRESS =");
1483 expect ("END ADDRESS =");
1492 e7000_xfer_inferior_memory (memaddr
, myaddr
, len
, write
, target
)
1494 unsigned char *myaddr
;
1497 struct target_ops
*target
; /* ignored */
1500 return e7000_write_inferior_memory (memaddr
, myaddr
, len
);
1502 return e7000_read_inferior_memory (memaddr
, myaddr
, len
);
1504 return e7000_read_inferior_memory_large (memaddr
, myaddr
, len
);
1508 e7000_kill (args
, from_tty
)
1515 e7000_load (args
, from_tty
)
1519 struct cleanup
*old_chain
;
1523 #define WRITESIZE 0x1000
1524 char buf
[2 + 4 + 4 + WRITESIZE
]; /* `DT' + <addr> + <len> + <data> */
1528 time_t start_time
, end_time
; /* Start and end times of download */
1529 unsigned long data_count
; /* Number of bytes transferred to memory */
1530 int oldtimeout
= timeout
;
1532 timeout
= remote_timeout
;
1535 /* FIXME! change test to test for type of download */
1538 generic_load (args
, from_tty
);
1542 /* for direct tcp connections, we can do a fast binary download */
1549 while (*args
!= '\000')
1553 while (isspace (*args
))
1558 while ((*args
!= '\000') && !isspace (*args
))
1561 if (*args
!= '\000')
1566 else if (strncmp (arg
, "-quiet", strlen (arg
)) == 0)
1568 else if (strncmp (arg
, "-nostart", strlen (arg
)) == 0)
1571 error ("unknown option `%s'", arg
);
1575 filename
= get_exec_file (1);
1577 pbfd
= bfd_openr (filename
, gnutarget
);
1580 perror_with_name (filename
);
1583 old_chain
= make_cleanup ((make_cleanup_func
) bfd_close
, pbfd
);
1585 if (!bfd_check_format (pbfd
, bfd_object
))
1586 error ("\"%s\" is not an object file: %s", filename
,
1587 bfd_errmsg (bfd_get_error ()));
1589 start_time
= time (NULL
);
1592 puts_e7000debug ("mw\r");
1596 for (section
= pbfd
->sections
; section
; section
= section
->next
)
1598 if (bfd_get_section_flags (pbfd
, section
) & SEC_LOAD
)
1600 bfd_vma section_address
;
1601 bfd_size_type section_size
;
1604 section_address
= bfd_get_section_vma (pbfd
, section
);
1605 section_size
= bfd_get_section_size_before_reloc (section
);
1608 printf_filtered ("[Loading section %s at 0x%x (%d bytes)]\n",
1609 bfd_get_section_name (pbfd
, section
),
1615 data_count
+= section_size
;
1617 while (section_size
> 0)
1620 static char inds
[] = "|/-\\";
1625 count
= min (section_size
, WRITESIZE
);
1627 buf
[2] = section_address
>> 24;
1628 buf
[3] = section_address
>> 16;
1629 buf
[4] = section_address
>> 8;
1630 buf
[5] = section_address
;
1632 buf
[6] = count
>> 24;
1633 buf
[7] = count
>> 16;
1634 buf
[8] = count
>> 8;
1637 bfd_get_section_contents (pbfd
, section
, buf
+ 10, fptr
, count
);
1639 if (SERIAL_WRITE (e7000_desc
, buf
, count
+ 10))
1640 fprintf_unfiltered (gdb_stderr
,
1641 "e7000_load: SERIAL_WRITE failed: %s\n",
1642 safe_strerror (errno
));
1648 printf_unfiltered ("\r%c", inds
[k
++ % 4]);
1649 gdb_flush (gdb_stdout
);
1652 section_address
+= count
;
1654 section_size
-= count
;
1663 end_time
= time (NULL
);
1665 /* Finally, make the PC point at the start address */
1668 write_pc (bfd_get_start_address (exec_bfd
));
1670 inferior_pid
= 0; /* No process now */
1672 /* This is necessary because many things were based on the PC at the time that
1673 we attached to the monitor, which is no longer valid now that we have loaded
1674 new code (and just changed the PC). Another way to do this might be to call
1675 normal_stop, except that the stack may not be valid, and things would get
1676 horribly confused... */
1678 clear_symtab_users ();
1682 entry
= bfd_get_start_address (pbfd
);
1685 printf_unfiltered ("[Starting %s at 0x%x]\n", filename
, entry
);
1687 /* start_routine (entry); */
1690 report_transfer_performance (data_count
, start_time
, end_time
);
1692 do_cleanups (old_chain
);
1693 timeout
= oldtimeout
;
1696 /* Clean up when a program exits.
1698 The program actually lives on in the remote processor's RAM, and may be
1699 run again without a download. Don't leave it full of breakpoint
1703 e7000_mourn_inferior ()
1705 remove_breakpoints ();
1706 unpush_target (&e7000_ops
);
1707 generic_mourn_inferior (); /* Do all the proper things now */
1710 #define MAX_BREAKPOINTS 200
1711 #ifdef HARD_BREAKPOINTS
1712 #define MAX_E7000DEBUG_BREAKPOINTS (BC_BREAKPOINTS ? 5 : MAX_BREAKPOINTS)
1714 #define MAX_E7000DEBUG_BREAKPOINTS MAX_BREAKPOINTS
1717 /* Since we can change to soft breakpoints dynamically, we must define
1718 more than enough. Was breakaddr[MAX_E7000DEBUG_BREAKPOINTS]. */
1719 static CORE_ADDR breakaddr
[MAX_BREAKPOINTS
] =
1723 e7000_insert_breakpoint (addr
, shadow
)
1725 unsigned char *shadow
;
1730 static char nop
[2] = NOP
;
1733 for (i
= 0; i
<= MAX_E7000DEBUG_BREAKPOINTS
; i
++)
1734 if (breakaddr
[i
] == 0)
1736 breakaddr
[i
] = addr
;
1737 /* Save old contents, and insert a nop in the space */
1738 #ifdef HARD_BREAKPOINTS
1741 sprintf (buf
, "BC%d A=%x\r", i
+ 1, addr
);
1742 puts_e7000debug (buf
);
1746 sprintf (buf
, "B %x\r", addr
);
1747 puts_e7000debug (buf
);
1751 e7000_read_inferior_memory (addr
, shadow
, 2);
1752 e7000_write_inferior_memory (addr
, nop
, 2);
1755 sprintf (buf
, "B %x\r", addr
);
1756 puts_e7000debug (buf
);
1762 error ("Too many breakpoints ( > %d) for the E7000\n",
1763 MAX_E7000DEBUG_BREAKPOINTS
);
1768 e7000_remove_breakpoint (addr
, shadow
)
1770 unsigned char *shadow
;
1775 for (i
= 0; i
< MAX_E7000DEBUG_BREAKPOINTS
; i
++)
1776 if (breakaddr
[i
] == addr
)
1779 #ifdef HARD_BREAKPOINTS
1782 sprintf (buf
, "BC%d - \r", i
+ 1);
1783 puts_e7000debug (buf
);
1787 sprintf (buf
, "B - %x\r", addr
);
1788 puts_e7000debug (buf
);
1792 sprintf (buf
, "B - %x\r", addr
);
1793 puts_e7000debug (buf
);
1797 /* Replace the insn under the break */
1798 e7000_write_inferior_memory (addr
, shadow
, 2);
1805 warning ("Can't find breakpoint associated with 0x%x\n", addr
);
1809 /* Put a command string, in args, out to STDBUG. Output from STDBUG
1810 is placed on the users terminal until the prompt is seen. */
1813 e7000_command (args
, fromtty
)
1817 /* FIXME: arbitrary limit on length of args. */
1823 error ("e7000 target not open.");
1826 puts_e7000debug ("\r");
1830 sprintf (buf
, "%s\r", args
);
1831 puts_e7000debug (buf
);
1836 expect_full_prompt ();
1839 printf_unfiltered ("\n");
1841 /* Who knows what the command did... */
1842 registers_changed ();
1847 e7000_drain_command (args
, fromtty
)
1854 puts_e7000debug ("end\r");
1855 putchar_e7000 (CTRLC
);
1857 while ((c
= readchar (1) != -1))
1861 putchar_e7000 (CTRLC
);
1864 if (c
> ' ' && c
< 127)
1865 printf_unfiltered ("%c", c
& 0xff);
1867 printf_unfiltered ("<%x>", c
& 0xff);
1876 static char *strings
[NITEMS
] =
1883 "ILLEGAL INSTRUCTION",
1890 for (i
= 0; i
< NITEMS
; ++i
)
1896 for (i
= 0; i
< NITEMS
; i
++)
1903 /* found one of the choices */
1915 /* Suck characters, if a string match, then return the strings index
1916 otherwise echo them. */
1926 char *buffer
= saveaway
;
1927 /* Count number of expect strings */
1929 for (n
= 0; strings
[n
]; n
++)
1931 ptr
[n
] = strings
[n
];
1942 printf_unfiltered ("[waiting for e7000...]\n");
1955 putchar_e7000 (CTRLC
); /* interrupt the running program */
1959 for (i
= 0; i
< n
; i
++)
1966 /* Gone all the way */
1973 ptr
[i
] = strings
[i
];
1979 /* Save it up incase we find that there was no match */
1984 if (buffer
!= saveaway
)
1987 printf_unfiltered ("%s", buffer
);
1992 putchar_unfiltered (c
);
1993 gdb_flush (gdb_stdout
);
1999 /* We subtract two from the pc here rather than use
2000 DECR_PC_AFTER_BREAK since the e7000 doesn't always add two to the
2001 pc, and the simulators never do. */
2009 store_signed_integer (buf
,
2010 REGISTER_RAW_SIZE (PC_REGNUM
),
2011 read_register (PC_REGNUM
) - 2);
2012 supply_register (PC_REGNUM
, buf
);
2013 sprintf (buf2
, ".PC %x\r", read_register (PC_REGNUM
));
2014 puts_e7000debug (buf2
);
2019 #define WAS_RUNNING 2
2022 static char *estrings
[] =
2031 /* Wait until the remote machine stops, then return, storing status in
2032 STATUS just as `wait' would. */
2035 e7000_wait (pid
, status
)
2037 struct target_waitstatus
*status
;
2041 int running_count
= 0;
2046 /* Then echo chars until PC= string seen */
2047 gch (); /* Drop cr */
2048 gch (); /* and space */
2052 switch (expect_n (estrings
))
2055 /* how did this happen ? */
2060 putchar_e7000 (CTRLC
);
2068 if (running_count
== 20)
2070 printf_unfiltered ("[running...]\n");
2080 /* Skip till the PC= */
2083 #ifdef GDB_TARGET_IS_SH
2084 wanted_nopc
= want_nopc
;
2085 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_sh
)
2086 switch (TARGET_ARCHITECTURE
->mach
)
2091 wanted_nopc
= want_sh3_nopc
;
2095 wanted_nopc
= want_nopc_h8300s
;
2097 wanted_nopc
= want_nopc_h8300h
;
2099 fetch_regs_from_dump (gch
, wanted_nopc
);
2101 /* And supply the extra ones the simulator uses */
2102 for (regno
= NUM_REALREGS
; regno
< NUM_REGS
; regno
++)
2105 supply_register (regno
, (char *) &buf
);
2108 stop_reason
= why_stop ();
2109 expect_full_prompt ();
2111 status
->kind
= TARGET_WAITKIND_STOPPED
;
2112 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2114 switch (stop_reason
)
2116 case 1: /* Breakpoint */
2117 write_pc (read_pc ()); /* PC is always off by 2 for breakpoints */
2118 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2120 case 0: /* Single step */
2121 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2123 case 2: /* Interrupt */
2126 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2131 status
->value
.sig
= TARGET_SIGNAL_INT
;
2137 printf_unfiltered ("a cycle address error?\n");
2138 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2141 status
->value
.sig
= TARGET_SIGNAL_ILL
;
2144 status
->value
.sig
= TARGET_SIGNAL_SEGV
;
2146 case 7: /* Anything else (NITEMS + 1) */
2147 printf_unfiltered ("a write protect error?\n");
2148 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2151 /* Get the user's attention - this should never happen. */
2158 /* Stop the running program. */
2163 /* Sending a ^C is supposed to stop the running program. */
2164 putchar_e7000 (CTRLC
);
2167 /* Define the target subroutine names. */
2169 struct target_ops e7000_ops
;
2172 init_e7000_ops (void)
2174 e7000_ops
.to_shortname
= "e7000";
2175 e7000_ops
.to_longname
= "Remote Hitachi e7000 target";
2176 e7000_ops
.to_doc
= "Use a remote Hitachi e7000 ICE connected by a serial line;\n\
2177 or a network connection.\n\
2178 Arguments are the name of the device for the serial line,\n\
2179 the speed to connect at in bits per second.\n\
2181 target e7000 /dev/ttya 9600\n\
2182 target e7000 foobar";
2183 e7000_ops
.to_open
= e7000_open
;
2184 e7000_ops
.to_close
= e7000_close
;
2185 e7000_ops
.to_attach
= 0;
2186 e7000_ops
.to_post_attach
= NULL
;
2187 e7000_ops
.to_require_attach
= NULL
;
2188 e7000_ops
.to_detach
= e7000_detach
;
2189 e7000_ops
.to_require_detach
= NULL
;
2190 e7000_ops
.to_resume
= e7000_resume
;
2191 e7000_ops
.to_wait
= e7000_wait
;
2192 e7000_ops
.to_post_wait
= NULL
;
2193 e7000_ops
.to_fetch_registers
= e7000_fetch_register
;
2194 e7000_ops
.to_store_registers
= e7000_store_register
;
2195 e7000_ops
.to_prepare_to_store
= e7000_prepare_to_store
;
2196 e7000_ops
.to_xfer_memory
= e7000_xfer_inferior_memory
;
2197 e7000_ops
.to_files_info
= e7000_files_info
;
2198 e7000_ops
.to_insert_breakpoint
= e7000_insert_breakpoint
;
2199 e7000_ops
.to_remove_breakpoint
= e7000_remove_breakpoint
;
2200 e7000_ops
.to_terminal_init
= 0;
2201 e7000_ops
.to_terminal_inferior
= 0;
2202 e7000_ops
.to_terminal_ours_for_output
= 0;
2203 e7000_ops
.to_terminal_ours
= 0;
2204 e7000_ops
.to_terminal_info
= 0;
2205 e7000_ops
.to_kill
= e7000_kill
;
2206 e7000_ops
.to_load
= e7000_load
;
2207 e7000_ops
.to_lookup_symbol
= 0;
2208 e7000_ops
.to_create_inferior
= e7000_create_inferior
;
2209 e7000_ops
.to_post_startup_inferior
= NULL
;
2210 e7000_ops
.to_acknowledge_created_inferior
= NULL
;
2211 e7000_ops
.to_clone_and_follow_inferior
= NULL
;
2212 e7000_ops
.to_post_follow_inferior_by_clone
= NULL
;
2213 e7000_ops
.to_insert_fork_catchpoint
= NULL
;
2214 e7000_ops
.to_remove_fork_catchpoint
= NULL
;
2215 e7000_ops
.to_insert_vfork_catchpoint
= NULL
;
2216 e7000_ops
.to_remove_vfork_catchpoint
= NULL
;
2217 e7000_ops
.to_has_forked
= NULL
;
2218 e7000_ops
.to_has_vforked
= NULL
;
2219 e7000_ops
.to_can_follow_vfork_prior_to_exec
= NULL
;
2220 e7000_ops
.to_post_follow_vfork
= NULL
;
2221 e7000_ops
.to_insert_exec_catchpoint
= NULL
;
2222 e7000_ops
.to_remove_exec_catchpoint
= NULL
;
2223 e7000_ops
.to_has_execd
= NULL
;
2224 e7000_ops
.to_reported_exec_events_per_exec_call
= NULL
;
2225 e7000_ops
.to_has_exited
= NULL
;
2226 e7000_ops
.to_mourn_inferior
= e7000_mourn_inferior
;
2227 e7000_ops
.to_can_run
= 0;
2228 e7000_ops
.to_notice_signals
= 0;
2229 e7000_ops
.to_thread_alive
= 0;
2230 e7000_ops
.to_stop
= e7000_stop
;
2231 e7000_ops
.to_pid_to_exec_file
= NULL
;
2232 e7000_ops
.to_core_file_to_sym_file
= NULL
;
2233 e7000_ops
.to_stratum
= process_stratum
;
2234 e7000_ops
.DONT_USE
= 0;
2235 e7000_ops
.to_has_all_memory
= 1;
2236 e7000_ops
.to_has_memory
= 1;
2237 e7000_ops
.to_has_stack
= 1;
2238 e7000_ops
.to_has_registers
= 1;
2239 e7000_ops
.to_has_execution
= 1;
2240 e7000_ops
.to_sections
= 0;
2241 e7000_ops
.to_sections_end
= 0;
2242 e7000_ops
.to_magic
= OPS_MAGIC
;
2246 _initialize_remote_e7000 ()
2249 add_target (&e7000_ops
);
2251 add_com ("e7000", class_obscure
, e7000_command
,
2252 "Send a command to the e7000 monitor.");
2254 add_com ("ftplogin", class_obscure
, e7000_login_command
,
2255 "Login to machine and change to directory.");
2257 add_com ("ftpload", class_obscure
, e7000_ftp_command
,
2258 "Fetch and load a file from previously described place.");
2260 add_com ("drain", class_obscure
, e7000_drain_command
,
2261 "Drain pending e7000 text buffers.");
2263 add_show_from_set (add_set_cmd ("usehardbreakpoints", no_class
,
2264 var_integer
, (char *) &use_hard_breakpoints
,
2265 "Set use of hardware breakpoints for all breakpoints.\n", &setlist
),