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, Boston, MA 02111-1307, USA. */
23 /* The E7000 is an in-circuit emulator for the Hitachi H8/300-H and
24 Hitachi-SH processor. It has serial port and a lan port.
26 The monitor command set makes it difficult to load large ammounts of
27 data over the lan without using ftp - so try not to issue load
28 commands when communicating over ethernet; use the ftpload command.
30 The monitor pauses for a second when dumping srecords to the serial
31 line too, so we use a slower per byte mechanism but without the
32 startup overhead. Even so, it's pretty slow... */
43 #include "gdb_string.h"
45 #include <sys/types.h>
47 #include "remote-utils.h"
54 #define HARD_BREAKPOINTS /* Now handled by set option. */
55 #define BC_BREAKPOINTS use_hard_breakpoints
63 extern void notice_quit
PARAMS ((void));
65 extern void report_transfer_performance
PARAMS ((unsigned long,
68 extern char *sh_processor_type
;
70 /* Local function declarations. */
72 static void e7000_close
PARAMS ((int));
74 static void e7000_fetch_register
PARAMS ((int));
76 static void e7000_store_register
PARAMS ((int));
78 static void e7000_command
PARAMS ((char *, int));
80 static void e7000_login_command
PARAMS ((char *, int));
82 static void e7000_ftp_command
PARAMS ((char *, int));
84 static void e7000_drain_command
PARAMS ((char *, int));
86 static void expect
PARAMS ((char *));
88 static void expect_full_prompt
PARAMS ((void));
90 static void expect_prompt
PARAMS ((void));
92 static int e7000_parse_device
PARAMS ((char *args
, char *dev_name
,
96 static serial_t e7000_desc
;
98 /* Allow user to chose between using hardware breakpoints or memory. */
99 static int use_hard_breakpoints
= 0; /* use sw breakpoints by default */
101 /* Nonzero if using the tcp serial driver. */
103 static int using_tcp
; /* direct tcp connection to target */
104 static int using_tcp_remote
; /* indirect connection to target
105 via tcp to controller */
107 /* Nonzero if using the pc isa card. */
111 extern struct target_ops e7000_ops
; /* Forward declaration */
113 char *ENQSTRING
= "\005";
115 /* Nonzero if some routine (as opposed to the user) wants echoing.
116 FIXME: Do this reentrantly with an extra parameter. */
122 static int timeout
= 20;
124 /* Send data to e7000debug. */
127 puts_e7000debug (buf
)
131 error ("Use \"target e7000 ...\" first.");
134 printf_unfiltered ("Sending %s\n", buf
);
136 if (SERIAL_WRITE (e7000_desc
, buf
, strlen (buf
)))
137 fprintf_unfiltered (gdb_stderr
, "SERIAL_WRITE failed: %s\n", safe_strerror (errno
));
139 /* And expect to see it echoed, unless using the pc interface */
153 SERIAL_WRITE (e7000_desc
, b
, 1);
160 SERIAL_WRITE (e7000_desc
, s
, strlen (s
));
172 /* Read a character from the remote system, doing all the fancy timeout
173 stuff. Handles serial errors and EOF. If TIMEOUT == 0, and no chars,
174 returns -1, else returns next char. Discards chars > 127. */
184 c
= SERIAL_READCHAR (e7000_desc
, timeout
);
188 if (c
== SERIAL_TIMEOUT
)
193 error ("Timeout reading from remote system.");
196 error ("Serial communication error");
200 putchar_unfiltered (c
);
201 gdb_flush (gdb_stdout
);
211 static char b
[8][10];
223 sprintf(b
[p
], "<%d>", x
);
230 /* Scan input from the remote system, until STRING is found. If
231 DISCARD is non-zero, then discard non-matching input, else print it
232 out. Let the user break out immediately. */
244 c
= readchar (timeout
);
251 putchar_e7000(CTRLC
);
263 if (c
== '\r' || c
== '\n')
266 putchar_unfiltered ('\n');
272 putchar_unfiltered (c
);
274 gdb_flush (gdb_stdout
);
276 if (normal (c
) == normal (*p
++))
285 if (normal (c
) == normal (string
[0]))
291 /* Keep discarding input until we see the e7000 prompt.
293 The convention for dealing with the prompt is that you
295 o *then* wait for the prompt.
297 Thus the last thing that a procedure does with the serial line will
298 be an expect_prompt(). Exception: e7000_resume does not wait for
299 the prompt, because the terminal is being handed over to the
300 inferior. However, the next thing which happens after that is a
301 e7000_wait which does wait for the prompt. Note that this includes
302 abnormal exit, e.g. error(). This is necessary to prevent getting
303 into states from which we can't recover. */
312 expect_full_prompt ()
318 convert_hex_digit (ch
)
321 if (ch
>= '0' && ch
<= '9')
323 else if (ch
>= 'A' && ch
<= 'F')
324 return ch
- 'A' + 10;
325 else if (ch
>= 'a' && ch
<= 'f')
326 return ch
- 'a' + 10;
334 int value
= convert_hex_digit (*start
);
337 *start
= readchar (timeout
);
338 while ((try = convert_hex_digit (*start
)) >= 0)
342 *start
= readchar (timeout
);
348 /* Get N 32-bit words from remote, each preceded by a space, and put
349 them in registers starting at REGNO. */
352 get_hex_regs (n
, regno
)
359 for (i
= 0; i
< n
; i
++)
364 for (j
= 0; j
< 8; j
++)
365 val
= (val
<< 4) + get_hex_digit (j
== 0);
366 supply_register (regno
++, (char *) &val
);
371 /* This is called not only when we first attach, but also when the
372 user types "run" after having attached. */
375 e7000_create_inferior (execfile
, args
, env
)
383 error ("Can't pass arguments to remote E7000DEBUG process");
385 if (execfile
== 0 || exec_bfd
== 0)
386 error ("No executable file specified");
388 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
390 #ifdef CREATE_INFERIOR_HOOK
391 CREATE_INFERIOR_HOOK (0); /* No process-ID */
394 /* The "process" (board) is already stopped awaiting our commands, and
395 the program is already downloaded. We just set its PC and go. */
397 clear_proceed_status ();
399 /* Tell wait_for_inferior that we've started a new process. */
400 init_wait_for_inferior ();
402 /* Set up the "saved terminal modes" of the inferior
403 based on what modes we are starting it with. */
404 target_terminal_init ();
406 /* Install inferior's terminal modes. */
407 target_terminal_inferior ();
409 /* insert_step_breakpoint (); FIXME, do we need this? */
410 proceed ((CORE_ADDR
) entry_pt
, -1, 0); /* Let 'er rip... */
413 /* Open a connection to a remote debugger. NAME is the filename used
414 for communication. */
416 static int baudrate
= 9600;
417 static char dev_name
[100];
419 static char *machine
= "";
420 static char *user
= "";
421 static char *passwd
= "";
422 static char *dir
= "";
424 /* Grab the next token and buy some space for it */
435 while (*p
&& *p
== ' ')
438 while (*p
&& (*p
!= ' ' && *p
!= '\t'))
451 e7000_login_command (args
, from_tty
)
457 machine
= next (&args
);
459 passwd
= next (&args
);
463 printf_unfiltered ("Set info to %s %s %s %s\n", machine
, user
, passwd
, dir
);
468 error ("Syntax is ftplogin <machine> <user> <passwd> <directory>");
472 /* Start an ftp transfer from the E7000 to a host */
475 e7000_ftp_command (args
, from_tty
)
479 /* FIXME: arbitrary limit on machine names and such. */
482 int oldtimeout
= timeout
;
483 timeout
= remote_timeout
;
485 sprintf (buf
, "ftp %s\r", machine
);
486 puts_e7000debug (buf
);
487 expect (" Username : ");
488 sprintf (buf
, "%s\r", user
);
489 puts_e7000debug (buf
);
490 expect (" Password : ");
491 write_e7000 (passwd
);
493 expect ("success\r");
495 sprintf (buf
, "cd %s\r", dir
);
496 puts_e7000debug (buf
);
498 sprintf (buf
, "ll 0;s:%s\r", args
);
499 puts_e7000debug (buf
);
501 puts_e7000debug ("bye\r");
503 timeout
= oldtimeout
;
507 e7000_parse_device (args
, dev_name
, baudrate
)
514 if (args
&& strcasecmp (args
, "pc") == 0)
516 strcpy (dev_name
, args
);
521 /* FIXME! temp hack to allow use with port master -
522 target tcp_remote <device> */
523 if (args
&& strncmp (args
, "tcp", 10) == 0)
526 n
= sscanf (args
, " %s %s %d %s", com_type
, dev_name
, &baudrate
, junk
);
532 n
= sscanf (args
, " %s %d %s", dev_name
, &baudrate
, junk
);
535 if (n
!= 1 && n
!= 2)
537 error ("Bad arguments. Usage:\ttarget e7000 <device> <speed>\n\
538 or \t\ttarget e7000 <host>[:<port>]\n\
539 or \t\ttarget e7000 tcp_remote <host>[:<port>]\n\
540 or \t\ttarget e7000 pc\n");
543 #if !defined(__GO32__) && !defined(_WIN32)
544 /* FIXME! test for ':' is ambiguous */
545 if (n
== 1 && strchr (dev_name
, ':') == 0)
547 /* Default to normal telnet port */
548 /* serial_open will use this to determine tcp communication */
549 strcat (dev_name
, ":23");
552 if (!using_tcp_remote
&& strchr (dev_name
, ':'))
559 /* Stub for catch_errors. */
562 e7000_start_remote (dummy
)
570 immediate_quit
= 1; /* 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 syncronize 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 (args
, from_tty
)
659 target_preopen (from_tty
);
661 n
= e7000_parse_device (args
, dev_name
, baudrate
);
663 push_target (&e7000_ops
);
665 e7000_desc
= SERIAL_OPEN (dev_name
);
668 perror_with_name (dev_name
);
670 SERIAL_SETBAUDRATE (e7000_desc
, baudrate
);
671 SERIAL_RAW (e7000_desc
);
673 #ifdef GDB_TARGET_IS_H8300
677 /* Start the remote connection; if error (0), discard this target.
678 In particular, if the user quits, be sure to discard it
679 (we'd be in an inconsistent state otherwise). */
680 if (!catch_errors (e7000_start_remote
, (char *)0,
681 "Couldn't establish connection to remote target\n", RETURN_MASK_ALL
))
683 printf_filtered ("Remote target %s connected to %s\n", target_shortname
,
687 /* Close out all files and local state before this target loses control. */
690 e7000_close (quitting
)
695 SERIAL_CLOSE (e7000_desc
);
700 /* Terminate the open connection to the remote debugger. Use this
701 when you want to detach and do something else with your gdb. */
704 e7000_detach (from_tty
)
707 pop_target (); /* calls e7000_close to do the real work */
709 printf_unfiltered ("Ending remote %s debugging\n", target_shortname
);
712 /* Tell the remote machine to resume. */
715 e7000_resume (pid
, step
, sig
)
719 puts_e7000debug ("S\r");
721 puts_e7000debug ("G\r");
724 /* Read the remote registers into the block REGS.
726 For the H8/300 a register dump looks like:
728 PC=00021A CCR=80:I*******
729 ER0 - ER3 0000000A 0000002E 0000002E 00000000
730 ER4 - ER7 00000000 00000000 00000000 00FFEFF6
736 #ifdef GDB_TARGET_IS_H8300
738 char *want_h8300h
= "PC=%p CCR=%c\n\
739 ER0 - ER3 %0 %1 %2 %3\n\
740 ER4 - ER7 %4 %5 %6 %7\n";
742 char *want_nopc_h8300h
= "%p CCR=%c\n\
743 ER0 - ER3 %0 %1 %2 %3\n\
744 ER4 - ER7 %4 %5 %6 %7";
746 char *want_h8300s
= "PC=%p CCR=%c\n\
748 ER0 - ER3 %0 %1 %2 %3\n\
749 ER4 - ER7 %4 %5 %6 %7\n";
751 char *want_nopc_h8300s
= "%p CCR=%c EXR=%9\n\
752 ER0 - ER3 %0 %1 %2 %3\n\
753 ER4 - ER7 %4 %5 %6 %7";
757 #ifdef GDB_TARGET_IS_SH
759 char *want
= "PC=%16 SR=%22\n\
760 PR=%17 GBR=%18 VBR=%19\n\
762 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
763 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n";
765 char *want_nopc
= "%16 SR=%22\n\
766 PR=%17 GBR=%18 VBR=%19\n\
768 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
769 R8-15 %8 %9 %10 %11 %12 %13 %14 %15";
771 char *want_sh3
= "PC=%16 SR=%22\n\
772 PR=%17 GBR=%18 VBR=%19\n\
773 MACH=%20 MACL=%21 SSR=%23 SPC=%24\n\
774 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
775 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
776 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
777 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
778 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
779 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
781 char *want_sh3_nopc
= "%16 SR=%22\n\
782 PR=%17 GBR=%18 VBR=%19\n\
783 MACH=%20 MACL=%21 SSR=%22 SPC=%23\n\
784 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
785 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
786 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
787 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
788 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
789 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
796 return readchar (timeout
);
802 int high
= convert_hex_digit (gch ());
803 int low
= convert_hex_digit (gch ());
805 return (high
<< 4) + low
;
809 fetch_regs_from_dump (nextchar
, want
)
814 char buf
[MAX_REGISTER_RAW_SIZE
];
816 int thischar
= nextchar ();
823 /* Skip to end of line and then eat all new line type stuff */
824 while (thischar
!= '\n' && thischar
!= '\r')
825 thischar
= nextchar ();
826 while (thischar
== '\n' || thischar
== '\r')
827 thischar
= nextchar ();
832 while (thischar
== ' '
836 thischar
= nextchar ();
841 if (*want
== thischar
)
845 thischar
= nextchar ();
848 else if (thischar
== ' ' || thischar
== '\n' || thischar
== '\r')
850 thischar
= nextchar ();
853 error ("out of sync in fetch registers wanted <%s>, got <%c 0x%x>",
854 want
, thischar
, thischar
);
859 /* Got a register command */
889 if (isdigit (want
[0]))
891 if (isdigit (want
[1]))
893 regno
= (want
[0] - '0') * 10 + want
[1] - '0';
898 regno
= want
[0] - '0';
906 store_signed_integer (buf
,
907 REGISTER_RAW_SIZE(regno
),
908 (LONGEST
) get_hex (&thischar
, nextchar
));
909 supply_register (regno
, buf
);
916 e7000_fetch_registers ()
921 puts_e7000debug ("R\r");
923 #ifdef GDB_TARGET_IS_SH
925 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_sh
)
926 switch (TARGET_ARCHITECTURE
->mach
)
934 wanted
= want_h8300s
;
936 wanted
= want_h8300h
;
938 fetch_regs_from_dump (gch
, wanted
);
940 /* And supply the extra ones the simulator uses */
941 for (regno
= NUM_REALREGS
; regno
< NUM_REGS
; regno
++)
945 supply_register (regno
, (char *) (&buf
));
949 /* Fetch register REGNO, or all registers if REGNO is -1. Returns
953 e7000_fetch_register (regno
)
956 e7000_fetch_registers ();
959 /* Store the remote registers from the contents of the block REGS. */
962 e7000_store_registers ()
966 for (regno
= 0; regno
< NUM_REALREGS
; regno
++)
967 e7000_store_register (regno
);
969 registers_changed ();
972 /* Store register REGNO, or all if REGNO == 0. Return errno value. */
975 e7000_store_register (regno
)
982 e7000_store_registers ();
986 #ifdef GDB_TARGET_IS_H8300
989 sprintf (buf
, ".ER%d %x\r", regno
, read_register (regno
));
990 puts_e7000debug (buf
);
992 else if (regno
== PC_REGNUM
)
994 sprintf (buf
, ".PC %x\r", read_register (regno
));
995 puts_e7000debug (buf
);
997 else if (regno
== CCR_REGNUM
)
999 sprintf (buf
, ".CCR %x\r", read_register (regno
));
1000 puts_e7000debug (buf
);
1002 #endif /* GDB_TARGET_IS_H8300 */
1004 #ifdef GDB_TARGET_IS_SH
1008 sprintf (buf
, ".R%d %x\r", regno
, read_register (regno
));
1009 puts_e7000debug (buf
);
1013 sprintf (buf
, ".PC %x\r", read_register (regno
));
1014 puts_e7000debug (buf
);
1018 sprintf (buf
, ".SR %x\r", read_register (regno
));
1019 puts_e7000debug (buf
);
1023 sprintf (buf
, ".PR %x\r", read_register (regno
));
1024 puts_e7000debug (buf
);
1028 sprintf (buf
, ".GBR %x\r", read_register (regno
));
1029 puts_e7000debug (buf
);
1033 sprintf (buf
, ".VBR %x\r", read_register (regno
));
1034 puts_e7000debug (buf
);
1038 sprintf (buf
, ".MACH %x\r", read_register (regno
));
1039 puts_e7000debug (buf
);
1043 sprintf (buf
, ".MACL %x\r", read_register (regno
));
1044 puts_e7000debug (buf
);
1048 #endif /* GDB_TARGET_IS_SH */
1053 /* Get ready to modify the registers array. On machines which store
1054 individual registers, this doesn't need to do anything. On machines
1055 which store all the registers in one fell swoop, this makes sure
1056 that registers contains all the registers from the program being
1060 e7000_prepare_to_store ()
1062 /* Do nothing, since we can store individual regs */
1068 printf_unfiltered ("\tAttached to %s at %d baud.\n", dev_name
, baudrate
);
1072 stickbyte (where
, what
)
1076 static CONST
char digs
[] = "0123456789ABCDEF";
1078 where
[0] = digs
[(what
>> 4) & 0xf];
1079 where
[1] = digs
[(what
& 0xf) & 0xf];
1084 /* Write a small ammount of memory. */
1087 write_small (memaddr
, myaddr
, len
)
1089 unsigned char *myaddr
;
1095 for (i
= 0; i
< len
; i
++)
1097 if (((memaddr
+ i
) & 3) == 0 && (i
+ 3 < len
))
1099 /* Can be done with a long word */
1100 sprintf (buf
, "m %x %x%02x%02x%02x;l\r",
1102 myaddr
[i
], myaddr
[i
+ 1], myaddr
[i
+ 2], myaddr
[i
+ 3]);
1103 puts_e7000debug (buf
);
1108 sprintf (buf
, "m %x %x\r", memaddr
+ i
, myaddr
[i
]);
1109 puts_e7000debug (buf
);
1118 /* Write a large ammount of memory, this only works with the serial
1119 mode enabled. Command is sent as
1134 write_large (memaddr
, myaddr
, len
)
1136 unsigned char *myaddr
;
1140 #define maxstride 128
1143 puts_e7000debug ("IL ;S:FK\r");
1145 putchar_e7000 (ACK
);
1148 for (i
= 0; i
< len
; i
+= stride
)
1150 char compose
[maxstride
* 2 + 50];
1151 int address
= i
+ memaddr
;
1158 if (stride
> maxstride
)
1161 compose
[where
++] = 'S';
1163 if (address
>= 0xffffff)
1165 else if (address
>= 0xffff)
1170 compose
[where
++] = alen
- 1 + '0';
1171 /* Insert length. */
1172 check_sum
+= stickbyte (compose
+ where
, alen
+ stride
+ 1);
1177 check_sum
+= stickbyte (compose
+ where
, address
>> (8 * (alen
)));
1181 for (j
= 0; j
< stride
; j
++)
1183 check_sum
+= stickbyte (compose
+ where
, myaddr
[i
+ j
]);
1186 stickbyte (compose
+ where
, ~check_sum
);
1188 compose
[where
++] = '\r';
1189 compose
[where
++] = '\n';
1190 compose
[where
++] = 0;
1192 SERIAL_WRITE (e7000_desc
, compose
, where
);
1196 /* This is ok - nothing there */
1200 /* Hmm, it's trying to tell us something */
1202 error ("Error writing memory");
1206 printf_unfiltered ("@%d}@", j
);
1207 while ((j
= readchar (0)) > 0)
1209 printf_unfiltered ("@{%d}@",j
);
1214 /* Send the trailer record */
1215 write_e7000 ("S70500000000FA\r");
1216 putchar_e7000 (CTRLZ
);
1218 putchar_e7000 (ACK
);
1224 /* Copy LEN bytes of data from debugger memory at MYADDR to inferior's
1225 memory at MEMADDR. Returns length moved.
1227 Can't use the Srecord load over ethernet, so don't use fast method
1231 e7000_write_inferior_memory (memaddr
, myaddr
, len
)
1233 unsigned char *myaddr
;
1236 if (len
< 16 || using_tcp
|| using_pc
)
1237 return write_small (memaddr
, myaddr
, len
);
1239 return write_large (memaddr
, myaddr
, len
);
1242 /* Read LEN bytes from inferior memory at MEMADDR. Put the result
1243 at debugger address MYADDR. Returns length moved.
1245 Small transactions we send
1252 e7000_read_inferior_memory (memaddr
, myaddr
, len
)
1254 unsigned char *myaddr
;
1261 /* Starting address of this pass. */
1263 /* printf("READ INF %x %x %d\n", memaddr, myaddr, len);*/
1264 if (((memaddr
- 1) + len
) < memaddr
)
1270 sprintf (buf
, "m %x;l\r", memaddr
);
1271 puts_e7000debug (buf
);
1273 for (count
= 0; count
< len
; count
+= 4)
1275 /* Suck away the address */
1281 { /* Some kind of error */
1282 puts_e7000debug (".\r"); /* Some errors leave us in memory input mode */
1283 expect_full_prompt();
1289 /* Now read in the data */
1290 for (i
= 0; i
< 4; i
++)
1293 if (count
+ i
< len
) {
1294 myaddr
[count
+ i
] = b
;
1298 /* Skip the trailing ? and send a . to end and a cr for more */
1301 if (count
+ 4 >= len
)
1302 puts_e7000debug(".\r");
1304 puts_e7000debug("\r");
1314 For large transfers we used to send
1317 d <addr> <endaddr>\r
1320 <ADDRESS> < D A T A > < ASCII CODE >
1321 00000000 5F FD FD FF DF 7F DF FF 01 00 01 00 02 00 08 04 "_..............."
1322 00000010 FF D7 FF 7F D7 F1 7F FF 00 05 00 00 08 00 40 00 "..............@."
1323 00000020 7F FD FF F7 7F FF FF F7 00 00 00 00 00 00 00 00 "................"
1325 A cost in chars for each transaction of 80 + 5*n-bytes.
1327 Large transactions could be done with the srecord load code, but
1328 there is a pause for a second before dumping starts, which slows the
1333 e7000_read_inferior_memory_large (memaddr
, myaddr
, len
)
1335 unsigned char *myaddr
;
1342 /* Starting address of this pass. */
1344 if (((memaddr
- 1) + len
) < memaddr
)
1350 sprintf (buf
, "d %x %x\r", memaddr
, memaddr
+ len
- 1);
1351 puts_e7000debug (buf
);
1356 /* skip down to the first ">" */
1359 /* now skip to the end of that line */
1366 /* get rid of any white space before the address */
1370 /* Skip the address */
1373 /* read in the bytes on the line */
1374 while (c
!= '"' && count
< len
)
1380 myaddr
[count
++] = get_hex (&c
);
1383 /* throw out the rest of the line */
1388 /* wait for the ":" prompt */
1398 fast_but_for_the_pause_e7000_read_inferior_memory (memaddr
, myaddr
, len
)
1407 if (((memaddr
- 1) + len
) < memaddr
)
1413 sprintf (buf
, "is %x@%x:s\r", memaddr
, len
);
1414 puts_e7000debug (buf
);
1420 error ("Memory read error");
1422 putchar_e7000 (ACK
);
1435 case ENQ
: /* ENQ, at the end */
1439 /* Start of an Srecord */
1444 case '7': /* Termination record, ignore */
1448 /* Header record - ignore it */
1460 alen
= type
- '0' + 1;
1464 addr
= (addr
<< 8) + gbyte ();
1468 for (i
= 0; i
< length
- 1; i
++)
1469 myaddr
[i
+ addr
- memaddr
] = gbyte ();
1471 gbyte (); /* Ignore checksum */
1477 putchar_e7000 (ACK
);
1478 expect ("TOP ADDRESS =");
1479 expect ("END ADDRESS =");
1488 e7000_xfer_inferior_memory (memaddr
, myaddr
, len
, write
, target
)
1490 unsigned char *myaddr
;
1493 struct target_ops
*target
; /* ignored */
1496 return e7000_write_inferior_memory( memaddr
, myaddr
, len
);
1499 return e7000_read_inferior_memory( memaddr
, myaddr
, len
);
1501 return e7000_read_inferior_memory_large( memaddr
, myaddr
, len
);
1505 e7000_kill (args
, from_tty
)
1512 e7000_load (args
, from_tty
)
1516 struct cleanup
*old_chain
;
1520 #define WRITESIZE 0x1000
1521 char buf
[2 + 4 + 4 + WRITESIZE
]; /* `DT' + <addr> + <len> + <data> */
1525 time_t start_time
, end_time
; /* Start and end times of download */
1526 unsigned long data_count
; /* Number of bytes transferred to memory */
1527 int oldtimeout
= timeout
;
1529 timeout
= remote_timeout
;
1532 /* FIXME! change test to test for type of download */
1535 generic_load (args
, from_tty
);
1539 /* for direct tcp connections, we can do a fast binary download */
1546 while (*args
!= '\000')
1550 while (isspace (*args
)) args
++;
1554 while ((*args
!= '\000') && !isspace (*args
)) args
++;
1556 if (*args
!= '\000')
1561 else if (strncmp (arg
, "-quiet", strlen (arg
)) == 0)
1563 else if (strncmp (arg
, "-nostart", strlen (arg
)) == 0)
1566 error ("unknown option `%s'", arg
);
1570 filename
= get_exec_file (1);
1572 pbfd
= bfd_openr (filename
, gnutarget
);
1575 perror_with_name (filename
);
1578 old_chain
= make_cleanup ((make_cleanup_func
) bfd_close
, pbfd
);
1580 if (!bfd_check_format (pbfd
, bfd_object
))
1581 error ("\"%s\" is not an object file: %s", filename
,
1582 bfd_errmsg (bfd_get_error ()));
1584 start_time
= time (NULL
);
1587 puts_e7000debug ("mw\r");
1591 for (section
= pbfd
->sections
; section
; section
= section
->next
)
1593 if (bfd_get_section_flags (pbfd
, section
) & SEC_LOAD
)
1595 bfd_vma section_address
;
1596 bfd_size_type section_size
;
1599 section_address
= bfd_get_section_vma (pbfd
, section
);
1600 section_size
= bfd_get_section_size_before_reloc (section
);
1603 printf_filtered ("[Loading section %s at 0x%x (%d bytes)]\n",
1604 bfd_get_section_name (pbfd
, section
),
1610 data_count
+= section_size
;
1612 while (section_size
> 0)
1615 static char inds
[] = "|/-\\";
1620 count
= min (section_size
, WRITESIZE
);
1622 buf
[2] = section_address
>> 24;
1623 buf
[3] = section_address
>> 16;
1624 buf
[4] = section_address
>> 8;
1625 buf
[5] = section_address
;
1627 buf
[6] = count
>> 24;
1628 buf
[7] = count
>> 16;
1629 buf
[8] = count
>> 8;
1632 bfd_get_section_contents (pbfd
, section
, buf
+ 10, fptr
, count
);
1634 if (SERIAL_WRITE (e7000_desc
, buf
, count
+ 10))
1635 fprintf_unfiltered (gdb_stderr
,
1636 "e7000_load: SERIAL_WRITE failed: %s\n",
1637 safe_strerror(errno
));
1643 printf_unfiltered ("\r%c", inds
[k
++ % 4]);
1644 gdb_flush (gdb_stdout
);
1647 section_address
+= count
;
1649 section_size
-= count
;
1658 end_time
= time (NULL
);
1660 /* Finally, make the PC point at the start address */
1663 write_pc (bfd_get_start_address (exec_bfd
));
1665 inferior_pid
= 0; /* No process now */
1667 /* This is necessary because many things were based on the PC at the time that
1668 we attached to the monitor, which is no longer valid now that we have loaded
1669 new code (and just changed the PC). Another way to do this might be to call
1670 normal_stop, except that the stack may not be valid, and things would get
1671 horribly confused... */
1673 clear_symtab_users ();
1677 entry
= bfd_get_start_address (pbfd
);
1680 printf_unfiltered ("[Starting %s at 0x%x]\n", filename
, entry
);
1682 /* start_routine (entry);*/
1685 report_transfer_performance (data_count
, start_time
, end_time
);
1687 do_cleanups (old_chain
);
1688 timeout
= oldtimeout
;
1691 /* Clean up when a program exits.
1693 The program actually lives on in the remote processor's RAM, and may be
1694 run again without a download. Don't leave it full of breakpoint
1698 e7000_mourn_inferior ()
1700 remove_breakpoints ();
1701 unpush_target (&e7000_ops
);
1702 generic_mourn_inferior (); /* Do all the proper things now */
1705 #define MAX_BREAKPOINTS 200
1706 #ifdef HARD_BREAKPOINTS
1707 #define MAX_E7000DEBUG_BREAKPOINTS (BC_BREAKPOINTS ? 5 : MAX_BREAKPOINTS)
1709 #define MAX_E7000DEBUG_BREAKPOINTS MAX_BREAKPOINTS
1712 /* Since we can change to soft breakpoints dynamically, we must define
1713 more than enough. Was breakaddr[MAX_E7000DEBUG_BREAKPOINTS]. */
1714 static CORE_ADDR breakaddr
[MAX_BREAKPOINTS
] = {0};
1717 e7000_insert_breakpoint (addr
, shadow
)
1719 unsigned char *shadow
;
1724 static char nop
[2] = NOP
;
1727 for (i
= 0; i
<= MAX_E7000DEBUG_BREAKPOINTS
; i
++)
1728 if (breakaddr
[i
] == 0)
1730 breakaddr
[i
] = addr
;
1731 /* Save old contents, and insert a nop in the space */
1732 #ifdef HARD_BREAKPOINTS
1735 sprintf (buf
, "BC%d A=%x\r", i
+1, addr
);
1736 puts_e7000debug (buf
);
1740 sprintf (buf
, "B %x\r", addr
);
1741 puts_e7000debug (buf
);
1745 e7000_read_inferior_memory (addr
, shadow
, 2);
1746 e7000_write_inferior_memory (addr
, nop
, 2);
1749 sprintf (buf
, "B %x\r", addr
);
1750 puts_e7000debug (buf
);
1756 error ("Too many breakpoints ( > %d) for the E7000\n",
1757 MAX_E7000DEBUG_BREAKPOINTS
);
1762 e7000_remove_breakpoint (addr
, shadow
)
1764 unsigned char *shadow
;
1769 for (i
= 0; i
< MAX_E7000DEBUG_BREAKPOINTS
; i
++)
1770 if (breakaddr
[i
] == addr
)
1773 #ifdef HARD_BREAKPOINTS
1776 sprintf (buf
, "BC%d - \r", i
+1);
1777 puts_e7000debug (buf
);
1781 sprintf (buf
, "B - %x\r", addr
);
1782 puts_e7000debug (buf
);
1786 sprintf (buf
, "B - %x\r", addr
);
1787 puts_e7000debug (buf
);
1791 /* Replace the insn under the break */
1792 e7000_write_inferior_memory (addr
, shadow
, 2);
1799 warning ("Can't find breakpoint associated with 0x%x\n", addr
);
1803 /* Put a command string, in args, out to STDBUG. Output from STDBUG
1804 is placed on the users terminal until the prompt is seen. */
1807 e7000_command (args
, fromtty
)
1811 /* FIXME: arbitrary limit on length of args. */
1817 error ("e7000 target not open.");
1820 puts_e7000debug ("\r");
1824 sprintf (buf
, "%s\r", args
);
1825 puts_e7000debug (buf
);
1830 expect_full_prompt ();
1833 printf_unfiltered ("\n");
1835 /* Who knows what the command did... */
1836 registers_changed ();
1841 e7000_drain_command (args
, fromtty
)
1848 puts_e7000debug("end\r");
1849 putchar_e7000 (CTRLC
);
1851 while ((c
= readchar (1) != -1))
1855 putchar_e7000(CTRLC
);
1858 if (c
> ' ' && c
< 127)
1859 printf_unfiltered ("%c", c
& 0xff);
1861 printf_unfiltered ("<%x>", c
& 0xff);
1870 static char *strings
[NITEMS
] = {
1876 "ILLEGAL INSTRUCTION",
1883 for (i
= 0; i
< NITEMS
; ++i
)
1889 for (i
= 0; i
< NITEMS
; i
++)
1896 /* found one of the choices */
1908 /* Suck characters, if a string match, then return the strings index
1909 otherwise echo them. */
1919 char *buffer
= saveaway
;
1920 /* Count number of expect strings */
1922 for (n
= 0; strings
[n
]; n
++)
1924 ptr
[n
] = strings
[n
];
1935 printf_unfiltered ("[waiting for e7000...]\n");
1948 putchar_e7000 (CTRLC
); /* interrupt the running program */
1952 for (i
= 0; i
< n
; i
++)
1959 /* Gone all the way */
1966 ptr
[i
] = strings
[i
];
1972 /* Save it up incase we find that there was no match */
1977 if (buffer
!= saveaway
)
1980 printf_unfiltered ("%s", buffer
);
1985 putchar_unfiltered (c
);
1986 gdb_flush (gdb_stdout
);
1992 /* We subtract two from the pc here rather than use
1993 DECR_PC_AFTER_BREAK since the e7000 doesn't always add two to the
1994 pc, and the simulators never do. */
2002 store_signed_integer (buf
,
2003 REGISTER_RAW_SIZE(PC_REGNUM
),
2004 read_register (PC_REGNUM
) -2);
2005 supply_register (PC_REGNUM
, buf
);
2006 sprintf (buf2
, ".PC %x\r", read_register (PC_REGNUM
));
2007 puts_e7000debug (buf2
);
2012 #define WAS_RUNNING 2
2015 static char *estrings
[] = {
2023 /* Wait until the remote machine stops, then return, storing status in
2024 STATUS just as `wait' would. */
2027 e7000_wait (pid
, status
)
2029 struct target_waitstatus
*status
;
2033 int running_count
= 0;
2038 /* Then echo chars until PC= string seen */
2039 gch (); /* Drop cr */
2040 gch (); /* and space */
2044 switch (expect_n (estrings
))
2047 /* how did this happen ? */
2052 putchar_e7000 (CTRLC
);
2060 if (running_count
== 20)
2062 printf_unfiltered ("[running...]\n");
2072 /* Skip till the PC= */
2075 #ifdef GDB_TARGET_IS_SH
2076 wanted_nopc
= want_nopc
;
2077 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_sh
)
2078 switch (TARGET_ARCHITECTURE
->mach
)
2082 wanted_nopc
= want_sh3_nopc
;
2086 wanted_nopc
= want_nopc_h8300s
;
2088 wanted_nopc
= want_nopc_h8300h
;
2090 fetch_regs_from_dump (gch
, wanted_nopc
);
2092 /* And supply the extra ones the simulator uses */
2093 for (regno
= NUM_REALREGS
; regno
< NUM_REGS
; regno
++)
2096 supply_register (regno
, (char *) &buf
);
2099 stop_reason
= why_stop ();
2100 expect_full_prompt ();
2102 status
->kind
= TARGET_WAITKIND_STOPPED
;
2103 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2105 switch (stop_reason
)
2107 case 1: /* Breakpoint */
2108 write_pc (read_pc ()); /* PC is always off by 2 for breakpoints */
2109 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2111 case 0: /* Single step */
2112 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2114 case 2: /* Interrupt */
2117 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2122 status
->value
.sig
= TARGET_SIGNAL_INT
;
2128 printf_unfiltered ("a cycle address error?\n");
2129 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2132 status
->value
.sig
= TARGET_SIGNAL_ILL
;
2135 status
->value
.sig
= TARGET_SIGNAL_SEGV
;
2137 case 7: /* Anything else (NITEMS + 1) */
2138 printf_unfiltered ("a write protect error?\n");
2139 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2142 /* Get the user's attention - this should never happen. */
2149 /* Stop the running program. */
2154 /* Sending a ^C is supposed to stop the running program. */
2155 putchar_e7000 (CTRLC
);
2158 /* Define the target subroutine names. */
2160 struct target_ops e7000_ops
;
2163 init_e7000_ops(void)
2165 e7000_ops
.to_shortname
= "e7000";
2166 e7000_ops
.to_longname
= "Remote Hitachi e7000 target";
2167 e7000_ops
.to_doc
= "Use a remote Hitachi e7000 ICE connected by a serial line;\n\
2168 or a network connection.\n\
2169 Arguments are the name of the device for the serial line,\n\
2170 the speed to connect at in bits per second.\n\
2172 target e7000 /dev/ttya 9600\n\
2173 target e7000 foobar" ;
2174 e7000_ops
.to_open
= e7000_open
;
2175 e7000_ops
.to_close
= e7000_close
;
2176 e7000_ops
.to_attach
= 0;
2177 e7000_ops
.to_post_attach
= NULL
;
2178 e7000_ops
.to_require_attach
= NULL
;
2179 e7000_ops
.to_detach
= e7000_detach
;
2180 e7000_ops
.to_require_detach
= NULL
;
2181 e7000_ops
.to_resume
= e7000_resume
;
2182 e7000_ops
.to_wait
= e7000_wait
;
2183 e7000_ops
.to_post_wait
= NULL
;
2184 e7000_ops
.to_fetch_registers
= e7000_fetch_register
;
2185 e7000_ops
.to_store_registers
= e7000_store_register
;
2186 e7000_ops
.to_prepare_to_store
= e7000_prepare_to_store
;
2187 e7000_ops
.to_xfer_memory
= e7000_xfer_inferior_memory
;
2188 e7000_ops
.to_files_info
= e7000_files_info
;
2189 e7000_ops
.to_insert_breakpoint
= e7000_insert_breakpoint
;
2190 e7000_ops
.to_remove_breakpoint
= e7000_remove_breakpoint
;
2191 e7000_ops
.to_terminal_init
= 0;
2192 e7000_ops
.to_terminal_inferior
= 0;
2193 e7000_ops
.to_terminal_ours_for_output
= 0;
2194 e7000_ops
.to_terminal_ours
= 0;
2195 e7000_ops
.to_terminal_info
= 0;
2196 e7000_ops
.to_kill
= e7000_kill
;
2197 e7000_ops
.to_load
= e7000_load
;
2198 e7000_ops
.to_lookup_symbol
= 0;
2199 e7000_ops
.to_create_inferior
= e7000_create_inferior
;
2200 e7000_ops
.to_post_startup_inferior
= NULL
;
2201 e7000_ops
.to_acknowledge_created_inferior
= NULL
;
2202 e7000_ops
.to_clone_and_follow_inferior
= NULL
;
2203 e7000_ops
.to_post_follow_inferior_by_clone
= NULL
;
2204 e7000_ops
.to_insert_fork_catchpoint
= NULL
;
2205 e7000_ops
.to_remove_fork_catchpoint
= NULL
;
2206 e7000_ops
.to_insert_vfork_catchpoint
= NULL
;
2207 e7000_ops
.to_remove_vfork_catchpoint
= NULL
;
2208 e7000_ops
.to_has_forked
= NULL
;
2209 e7000_ops
.to_has_vforked
= NULL
;
2210 e7000_ops
.to_can_follow_vfork_prior_to_exec
= NULL
;
2211 e7000_ops
.to_post_follow_vfork
= NULL
;
2212 e7000_ops
.to_insert_exec_catchpoint
= NULL
;
2213 e7000_ops
.to_remove_exec_catchpoint
= NULL
;
2214 e7000_ops
.to_has_execd
= NULL
;
2215 e7000_ops
.to_reported_exec_events_per_exec_call
= NULL
;
2216 e7000_ops
.to_has_exited
= NULL
;
2217 e7000_ops
.to_mourn_inferior
= e7000_mourn_inferior
;
2218 e7000_ops
.to_can_run
= 0;
2219 e7000_ops
.to_notice_signals
= 0;
2220 e7000_ops
.to_thread_alive
= 0;
2221 e7000_ops
.to_stop
= e7000_stop
;
2222 e7000_ops
.to_pid_to_exec_file
= NULL
;
2223 e7000_ops
.to_core_file_to_sym_file
= NULL
;
2224 e7000_ops
.to_stratum
= process_stratum
;
2225 e7000_ops
.DONT_USE
= 0;
2226 e7000_ops
.to_has_all_memory
= 1;
2227 e7000_ops
.to_has_memory
= 1;
2228 e7000_ops
.to_has_stack
= 1;
2229 e7000_ops
.to_has_registers
= 1;
2230 e7000_ops
.to_has_execution
= 1;
2231 e7000_ops
.to_sections
= 0;
2232 e7000_ops
.to_sections_end
= 0;
2233 e7000_ops
.to_magic
= OPS_MAGIC
;
2237 _initialize_remote_e7000 ()
2240 add_target (&e7000_ops
);
2242 add_com ("e7000", class_obscure
, e7000_command
,
2243 "Send a command to the e7000 monitor.");
2245 add_com ("ftplogin", class_obscure
, e7000_login_command
,
2246 "Login to machine and change to directory.");
2248 add_com ("ftpload", class_obscure
, e7000_ftp_command
,
2249 "Fetch and load a file from previously described place.");
2251 add_com ("drain", class_obscure
, e7000_drain_command
,
2252 "Drain pending e7000 text buffers.");
2254 add_show_from_set (add_set_cmd ("usehardbreakpoints", no_class
,
2255 var_integer
, (char *)&use_hard_breakpoints
,
2256 "Set use of hardware breakpoints for all breakpoints.\n", &setlist
),