1 /* Remote debugging interface for Hitachi E7000 ICE, for GDB
2 Copyright 1993, 1994, 1996 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... */
42 #include "gdb_string.h"
44 #include <sys/types.h>
46 #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));
94 static serial_t e7000_desc
;
96 /* Allow user to chose between using hardware breakpoints or memory. */
97 static int use_hard_breakpoints
= 0; /* use sw breakpoints by default */
99 /* Nonzero if using the tcp serial driver. */
101 static int using_tcp
; /* direct tcp connection to target */
102 static int using_tcp_remote
; /* indirect connection to target
103 via tcp to controller */
105 /* Nonzero if using the pc isa card. */
109 extern struct target_ops e7000_ops
; /* Forward declaration */
111 char *ENQSTRING
= "\005";
113 /* Nonzero if some routine (as opposed to the user) wants echoing.
114 FIXME: Do this reentrantly with an extra parameter. */
120 static int timeout
= 20;
122 /* Send data to e7000debug. */
125 puts_e7000debug (buf
)
129 error ("Use \"target e7000 ...\" first.");
132 printf("Sending %s\n", buf
);
133 DBG(("Sending %s; waiting for echo...\n", buf
));
135 if (SERIAL_WRITE (e7000_desc
, buf
, strlen (buf
)))
136 fprintf (stderr
, "SERIAL_WRITE failed: %s\n", safe_strerror (errno
));
138 /* 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
183 c
= SERIAL_READCHAR (e7000_desc
, timeout
);
187 if (c
== SERIAL_TIMEOUT
)
192 error ("Timeout reading from remote system.");
207 static char b
[8][10];
219 sprintf(b
[p
], "<%d>", x
);
226 /* Scan input from the remote system, until STRING is found. If
227 DISCARD is non-zero, then discard non-matching input, else print it
228 out. Let the user break out immediately. */
240 c
= readchar (timeout
);
246 putchar_e7000(CTRLC
);
255 if (c
== SERIAL_ERROR
)
257 error ("Serial communication error");
259 if (echo
|| remote_debug
)
261 if (c
== '\r' || c
== '\n')
274 if (normal (c
) == normal (*p
++))
283 if (normal (c
) == normal (string
[0]))
289 /* Keep discarding input until we see the e7000 prompt.
291 The convention for dealing with the prompt is that you
293 o *then* wait for the prompt.
295 Thus the last thing that a procedure does with the serial line will
296 be an expect_prompt(). Exception: e7000_resume does not wait for
297 the prompt, because the terminal is being handed over to the
298 inferior. However, the next thing which happens after that is a
299 e7000_wait which does wait for the prompt. Note that this includes
300 abnormal exit, e.g. error(). This is necessary to prevent getting
301 into states from which we can't recover. */
310 expect_full_prompt ()
316 convert_hex_digit (ch
)
319 if (ch
>= '0' && ch
<= '9')
321 else if (ch
>= 'A' && ch
<= 'F')
322 return ch
- 'A' + 10;
323 else if (ch
>= 'a' && ch
<= 'f')
324 return ch
- 'a' + 10;
332 int value
= convert_hex_digit (*start
);
335 *start
= readchar (timeout
);
336 while ((try = convert_hex_digit (*start
)) >= 0)
340 *start
= readchar (timeout
);
346 /* Get N 32-bit words from remote, each preceded by a space, and put
347 them in registers starting at REGNO. */
350 get_hex_regs (n
, regno
)
357 for (i
= 0; i
< n
; i
++)
362 for (j
= 0; j
< 8; j
++)
363 val
= (val
<< 4) + get_hex_digit (j
== 0);
364 supply_register (regno
++, (char *) &val
);
369 /* This is called not only when we first attach, but also when the
370 user types "run" after having attached. */
373 e7000_create_inferior (execfile
, args
, env
)
381 error ("Can't pass arguments to remote E7000DEBUG process");
383 if (execfile
== 0 || exec_bfd
== 0)
384 error ("No exec file specified");
386 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
388 #ifdef CREATE_INFERIOR_HOOK
389 CREATE_INFERIOR_HOOK (0); /* No process-ID */
392 /* The "process" (board) is already stopped awaiting our commands, and
393 the program is already downloaded. We just set its PC and go. */
395 clear_proceed_status ();
397 /* Tell wait_for_inferior that we've started a new process. */
398 init_wait_for_inferior ();
400 /* Set up the "saved terminal modes" of the inferior
401 based on what modes we are starting it with. */
402 target_terminal_init ();
404 /* Install inferior's terminal modes. */
405 target_terminal_inferior ();
407 /* insert_step_breakpoint (); FIXME, do we need this? */
408 proceed ((CORE_ADDR
) entry_pt
, -1, 0); /* Let 'er rip... */
411 /* Open a connection to a remote debugger. NAME is the filename used
412 for communication. */
414 static int baudrate
= 9600;
415 static char dev_name
[100];
417 static char *machine
= "";
418 static char *user
= "";
419 static char *passwd
= "";
420 static char *dir
= "";
422 /* Grab the next token and buy some space for it */
433 while (*p
&& *p
== ' ')
436 while (*p
&& (*p
!= ' ' && *p
!= '\t'))
449 e7000_login_command (args
, from_tty
)
455 machine
= next (&args
);
457 passwd
= next (&args
);
461 printf ("Set info to %s %s %s %s\n", machine
, user
, passwd
, dir
);
466 error ("Syntax is ftplogin <machine> <user> <passwd> <directory>");
470 /* Start an ftp transfer from the E7000 to a host */
473 e7000_ftp_command (args
, from_tty
)
477 /* FIXME: arbitrary limit on machine names and such. */
480 int oldtimeout
= timeout
;
481 timeout
= remote_timeout
;
483 sprintf (buf
, "ftp %s\r", machine
);
484 puts_e7000debug (buf
);
485 expect (" Username : ");
486 sprintf (buf
, "%s\r", user
);
487 puts_e7000debug (buf
);
488 expect (" Password : ");
489 write_e7000 (passwd
);
491 expect ("success\r");
493 sprintf (buf
, "cd %s\r", dir
);
494 puts_e7000debug (buf
);
496 sprintf (buf
, "ll 0;s:%s\r", args
);
497 puts_e7000debug (buf
);
499 puts_e7000debug ("bye\r");
501 timeout
= oldtimeout
;
505 e7000_parse_device(args
,dev_name
,serial_flag
,baudrate
)
513 if (args
&& strcasecmp (args
, "pc") == 0)
515 strcpy (dev_name
, args
);
520 /* FIXME! temp hack to allow use with port master -
521 target tcp_remote <device> */
522 if (args
&& strncmp (args
, "tcp_remote", 10) == 0)
525 n
= sscanf (args
, " %s %s %d %s", com_type
, dev_name
, &baudrate
, junk
);
531 n
= sscanf (args
, " %s %d %s", dev_name
, &baudrate
, junk
);
534 if (n
!= 1 && n
!= 2)
536 error ("Bad arguments. Usage:\ttarget e7000 <device> <speed>\n\
537 or \t\ttarget e7000 <host>[:<port>]\n\
538 or \t\ttarget e7000 tcp_remote <host>[:<port>]\n\
539 or \t\ttarget e7000 pc\n");
542 #if !defined(__GO32__) && !defined(_WIN32)
543 /* FIXME! test for ':' is ambiguous */
544 if (n
== 1 && strchr (dev_name
, ':') == 0)
546 /* Default to normal telnet port */
547 /* serial_open will use this to determine tcp communication */
548 strcat (dev_name
, ":23");
551 if (!using_tcp_remote
&& strchr (dev_name
, ':'))
559 e7000_open (args
, from_tty
)
570 target_preopen (from_tty
);
572 n
= e7000_parse_device(args
,dev_name
,serial_flag
,baudrate
);
574 push_target (&e7000_ops
);
576 e7000_desc
= SERIAL_OPEN (dev_name
);
580 error ("Unable to open target or file not found: %s\n", dev_name
);
583 SERIAL_SETBAUDRATE (e7000_desc
, baudrate
);
584 SERIAL_RAW (e7000_desc
);
586 /* Hello? Are you there? */
589 putchar_e7000 (CTRLC
);
590 while (!sync
&& ++try <= quit_trying
)
595 printf_unfiltered ("[waiting for e7000...]\n");
598 c
= SERIAL_READCHAR (e7000_desc
, 1);
600 /* FIXME! this didn't seem right-> while (c != SERIAL_TIMEOUT)
601 * we get stuck in this loop ...
602 * We may never timeout, and never sync up :-(
604 while (!sync
&& c
!= SERIAL_TIMEOUT
)
607 if (from_tty
&& c
!= '\r')
612 /* Shouldn't we either break here, or check for sync in inner loop? */
618 putchar_e7000 (CTRLC
);
625 /* FIXME! with this logic, you might never break out of this loop!
626 * Changed to count tries and treat reads as TIMEOUTS
627 * In windows version, you never timeout cuz always read 1 char!
631 putchar_e7000 (CTRLC
);
632 /* Was-> quit_flag = 0; */
634 quit_trying
= try+1; /* we don't want to try anymore */
637 c
= SERIAL_READCHAR (e7000_desc
, 1);
644 printf_unfiltered ("Giving up after %d tries...\n",try);
645 error ("Unable to syncronize with target.\n");
649 puts_e7000debug ("\r");
653 puts_e7000debug ("b -\r");
658 printf_filtered ("Remote target %s connected to %s\n", target_shortname
,
661 #ifdef GDB_TARGET_IS_H8300
666 /* Close out all files and local state before this target loses control. */
669 e7000_close (quitting
)
674 SERIAL_CLOSE (e7000_desc
);
679 /* Terminate the open connection to the remote debugger. Use this
680 when you want to detach and do something else with your gdb. */
683 e7000_detach (from_tty
)
686 pop_target (); /* calls e7000_close to do the real work */
688 printf ("Ending remote %s debugging\n", target_shortname
);
691 /* Tell the remote machine to resume. */
694 e7000_resume (pid
, step
, sig
)
698 puts_e7000debug ("S\r");
700 puts_e7000debug ("G\r");
703 /* Read the remote registers into the block REGS.
705 For the H8/300 a register dump looks like:
707 PC=00021A CCR=80:I*******
708 ER0 - ER3 0000000A 0000002E 0000002E 00000000
709 ER4 - ER7 00000000 00000000 00000000 00FFEFF6
715 #ifdef GDB_TARGET_IS_H8300
717 char *want_h8300h
= "PC=%p CCR=%c\n\
718 ER0 - ER3 %0 %1 %2 %3\n\
719 ER4 - ER7 %4 %5 %6 %7\n";
721 char *want_nopc_h8300h
= "%p CCR=%c\n\
722 ER0 - ER3 %0 %1 %2 %3\n\
723 ER4 - ER7 %4 %5 %6 %7";
725 char *want_h8300s
= "PC=%p CCR=%c\n\
727 ER0 - ER3 %0 %1 %2 %3\n\
728 ER4 - ER7 %4 %5 %6 %7\n";
730 char *want_nopc_h8300s
= "%p CCR=%c EXR=%9\n\
731 ER0 - ER3 %0 %1 %2 %3\n\
732 ER4 - ER7 %4 %5 %6 %7";
736 #ifdef GDB_TARGET_IS_SH
738 char *want
= "PC=%16 SR=%22\n\
739 PR=%17 GBR=%18 VBR=%19\n\
741 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
742 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n";
744 char *want_nopc
= "%16 SR=%22\n\
745 PR=%17 GBR=%18 VBR=%19\n\
747 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
748 R8-15 %8 %9 %10 %11 %12 %13 %14 %15";
750 char *want_sh3
= "PC=%16 SR=%22\n\
751 PR=%17 GBR=%18 VBR=%19\n\
752 MACH=%20 MACL=%21 SSR=%23 SPC=%24\n\
753 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
754 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
755 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
756 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
757 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
758 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
760 char *want_sh3_nopc
= "%16 SR=%22\n\
761 PR=%17 GBR=%18 VBR=%19\n\
762 MACH=%20 MACL=%21 SSR=%22 SPC=%23\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";
775 int c
= readchar (timeout
);
790 int high
= convert_hex_digit (gch ());
791 int low
= convert_hex_digit (gch ());
793 return (high
<< 4) + low
;
797 fetch_regs_from_dump (nextchar
, want
)
802 char buf
[MAX_REGISTER_RAW_SIZE
];
804 int thischar
= nextchar ();
811 /* Skip to end of line and then eat all new line type stuff */
812 while (thischar
!= '\n' && thischar
!= '\r')
813 thischar
= nextchar ();
814 while (thischar
== '\n' || thischar
== '\r')
815 thischar
= nextchar ();
820 while (thischar
== ' '
824 thischar
= nextchar ();
829 if (*want
== thischar
)
833 thischar
= nextchar ();
836 else if (thischar
== ' ' || thischar
== '\n' || thischar
== '\r')
838 thischar
= nextchar ();
841 error ("out of sync in fetch registers wanted <%s>, got <%c 0x%x>",
842 want
, thischar
, thischar
);
847 /* Got a register command */
877 if (isdigit (want
[0]))
879 if (isdigit (want
[1]))
881 regno
= (want
[0] - '0') * 10 + want
[1] - '0';
886 regno
= want
[0] - '0';
894 store_signed_integer (buf
,
895 REGISTER_RAW_SIZE(regno
),
896 (LONGEST
) get_hex (&thischar
, nextchar
));
897 supply_register (regno
, buf
);
904 e7000_fetch_registers ()
908 puts_e7000debug ("R\r");
910 #ifdef GDB_TARGET_IS_SH
911 if ((sh_processor_type
!= NULL
) && (*(sh_processor_type
+2) == '3'))
912 fetch_regs_from_dump (gch
, want_sh3
);
914 fetch_regs_from_dump (gch
, want
);
916 fetch_regs_from_dump (gch
, h8300smode
? want_h8300s
: want_h8300h
);
920 /* And supply the extra ones the simulator uses */
921 for (regno
= NUM_REALREGS
; regno
< NUM_REGS
; regno
++)
925 supply_register (regno
, (char *) (&buf
));
929 /* Fetch register REGNO, or all registers if REGNO is -1. Returns
933 e7000_fetch_register (regno
)
936 e7000_fetch_registers ();
939 /* Store the remote registers from the contents of the block REGS. */
942 e7000_store_registers ()
946 for (regno
= 0; regno
< NUM_REALREGS
; regno
++)
947 e7000_store_register (regno
);
949 registers_changed ();
952 /* Store register REGNO, or all if REGNO == 0. Return errno value. */
955 e7000_store_register (regno
)
962 e7000_store_registers ();
966 #ifdef GDB_TARGET_IS_H8300
969 sprintf (buf
, ".ER%d %x\r", regno
, read_register (regno
));
970 puts_e7000debug (buf
);
972 else if (regno
== PC_REGNUM
)
974 sprintf (buf
, ".PC %x\r", read_register (regno
));
975 puts_e7000debug (buf
);
977 else if (regno
== CCR_REGNUM
)
979 sprintf (buf
, ".CCR %x\r", read_register (regno
));
980 puts_e7000debug (buf
);
982 #endif /* GDB_TARGET_IS_H8300 */
984 #ifdef GDB_TARGET_IS_SH
988 sprintf (buf
, ".R%d %x\r", regno
, read_register (regno
));
989 puts_e7000debug (buf
);
993 sprintf (buf
, ".PC %x\r", read_register (regno
));
994 puts_e7000debug (buf
);
998 sprintf (buf
, ".SR %x\r", read_register (regno
));
999 puts_e7000debug (buf
);
1003 sprintf (buf
, ".PR %x\r", read_register (regno
));
1004 puts_e7000debug (buf
);
1008 sprintf (buf
, ".GBR %x\r", read_register (regno
));
1009 puts_e7000debug (buf
);
1013 sprintf (buf
, ".VBR %x\r", read_register (regno
));
1014 puts_e7000debug (buf
);
1018 sprintf (buf
, ".MACH %x\r", read_register (regno
));
1019 puts_e7000debug (buf
);
1023 sprintf (buf
, ".MACL %x\r", read_register (regno
));
1024 puts_e7000debug (buf
);
1028 #endif /* GDB_TARGET_IS_SH */
1033 /* Get ready to modify the registers array. On machines which store
1034 individual registers, this doesn't need to do anything. On machines
1035 which store all the registers in one fell swoop, this makes sure
1036 that registers contains all the registers from the program being
1040 e7000_prepare_to_store ()
1042 /* Do nothing, since we can store individual regs */
1048 printf ("\tAttached to %s at %d baud.\n", dev_name
, baudrate
);
1052 stickbyte (where
, what
)
1056 static CONST
char digs
[] = "0123456789ABCDEF";
1058 where
[0] = digs
[(what
>> 4) & 0xf];
1059 where
[1] = digs
[(what
& 0xf) & 0xf];
1064 /* Write a small ammount of memory. */
1067 write_small (memaddr
, myaddr
, len
)
1069 unsigned char *myaddr
;
1075 for (i
= 0; i
< len
; i
++)
1077 if (((memaddr
+ i
) & 3) == 0 && (i
+ 3 < len
))
1079 /* Can be done with a long word */
1080 sprintf (buf
, "m %x %x%02x%02x%02x;l\r",
1082 myaddr
[i
], myaddr
[i
+ 1], myaddr
[i
+ 2], myaddr
[i
+ 3]);
1083 puts_e7000debug (buf
);
1088 sprintf (buf
, "m %x %x\r", memaddr
+ i
, myaddr
[i
]);
1089 puts_e7000debug (buf
);
1098 /* Write a large ammount of memory, this only works with the serial
1099 mode enabled. Command is sent as
1114 write_large (memaddr
, myaddr
, len
)
1116 unsigned char *myaddr
;
1120 #define maxstride 128
1123 puts_e7000debug ("IL ;S:FK\r");
1125 putchar_e7000 (ACK
);
1128 for (i
= 0; i
< len
; i
+= stride
)
1130 char compose
[maxstride
* 2 + 50];
1131 int address
= i
+ memaddr
;
1138 if (stride
> maxstride
)
1141 compose
[where
++] = 'S';
1143 if (address
>= 0xffffff)
1145 else if (address
>= 0xffff)
1150 compose
[where
++] = alen
- 1 + '0';
1151 /* Insert length. */
1152 check_sum
+= stickbyte (compose
+ where
, alen
+ stride
+ 1);
1157 check_sum
+= stickbyte (compose
+ where
, address
>> (8 * (alen
)));
1161 for (j
= 0; j
< stride
; j
++)
1163 check_sum
+= stickbyte (compose
+ where
, myaddr
[i
+ j
]);
1166 stickbyte (compose
+ where
, ~check_sum
);
1168 compose
[where
++] = '\r';
1169 compose
[where
++] = '\n';
1170 compose
[where
++] = 0;
1172 SERIAL_WRITE (e7000_desc
, compose
, where
);
1173 j
= SERIAL_READCHAR (e7000_desc
, 0);
1174 if (j
== SERIAL_TIMEOUT
)
1176 /* This is ok - nothing there */
1180 /* Hmm, it's trying to tell us something */
1182 error ("Error writing memory");
1186 printf ("@%d}@", j
);
1187 while ((j
= SERIAL_READCHAR(e7000_desc
,0)) > 0)
1189 printf ("@{%d}@",j
);
1194 /* Send the trailer record */
1195 write_e7000 ("S70500000000FA\r");
1196 putchar_e7000 (CTRLZ
);
1198 putchar_e7000 (ACK
);
1204 /* Copy LEN bytes of data from debugger memory at MYADDR to inferior's
1205 memory at MEMADDR. Returns length moved.
1207 Can't use the Srecord load over ethernet, so don't use fast method
1211 e7000_write_inferior_memory (memaddr
, myaddr
, len
)
1213 unsigned char *myaddr
;
1216 if (len
< 16 || using_tcp
|| using_pc
)
1217 return write_small (memaddr
, myaddr
, len
);
1219 return write_large (memaddr
, myaddr
, len
);
1222 /* Read LEN bytes from inferior memory at MEMADDR. Put the result
1223 at debugger address MYADDR. Returns length moved.
1225 Small transactions we send
1232 e7000_read_inferior_memory (memaddr
, myaddr
, len
)
1234 unsigned char *myaddr
;
1241 /* Starting address of this pass. */
1243 /* printf("READ INF %x %x %d\n", memaddr, myaddr, len);*/
1244 if (((memaddr
- 1) + len
) < memaddr
)
1250 sprintf (buf
, "m %x;l\r", memaddr
);
1251 puts_e7000debug (buf
);
1253 for (count
= 0; count
< len
; count
+= 4)
1255 /* Suck away the address */
1261 { /* Some kind of error */
1268 /* Now read in the data */
1269 for (i
= 0; i
< 4; i
++)
1272 if (count
+ i
< len
) {
1273 myaddr
[count
+ i
] = b
;
1277 /* Skip the trailing ? and send a . to end and a cr for more */
1280 if (count
+ 4 >= len
)
1281 puts_e7000debug(".\r");
1283 puts_e7000debug("\r");
1293 For large transfers we used to send
1296 d <addr> <endaddr>\r
1299 <ADDRESS> < D A T A > < ASCII CODE >
1300 00000000 5F FD FD FF DF 7F DF FF 01 00 01 00 02 00 08 04 "_..............."
1301 00000010 FF D7 FF 7F D7 F1 7F FF 00 05 00 00 08 00 40 00 "..............@."
1302 00000020 7F FD FF F7 7F FF FF F7 00 00 00 00 00 00 00 00 "................"
1304 A cost in chars for each transaction of 80 + 5*n-bytes.
1306 Large transactions could be done with the srecord load code, but
1307 there is a pause for a second before dumping starts, which slows the
1312 e7000_read_inferior_memory_large (memaddr
, myaddr
, len
)
1314 unsigned char *myaddr
;
1321 /* Starting address of this pass. */
1323 if (((memaddr
- 1) + len
) < memaddr
)
1329 sprintf (buf
, "d %x %x\r", memaddr
, memaddr
+ len
- 1);
1330 puts_e7000debug (buf
);
1335 /* skip down to the first ">" */
1338 /* now skip to the end of that line */
1345 /* get rid of any white space before the address */
1349 /* Skip the address */
1352 /* read in the bytes on the line */
1353 while (c
!= '"' && count
< len
)
1359 myaddr
[count
++] = get_hex (&c
);
1362 /* throw out the rest of the line */
1367 /* wait for the ":" prompt */
1377 fast_but_for_the_pause_e7000_read_inferior_memory (memaddr
, myaddr
, len
)
1386 if (((memaddr
- 1) + len
) < memaddr
)
1392 sprintf (buf
, "is %x@%x:s\r", memaddr
, len
);
1393 puts_e7000debug (buf
);
1399 error ("Memory read error");
1401 putchar_e7000 (ACK
);
1414 case ENQ
: /* ENQ, at the end */
1418 /* Start of an Srecord */
1423 case '7': /* Termination record, ignore */
1427 /* Header record - ignore it */
1439 alen
= type
- '0' + 1;
1443 addr
= (addr
<< 8) + gbyte ();
1447 for (i
= 0; i
< length
- 1; i
++)
1448 myaddr
[i
+ addr
- memaddr
] = gbyte ();
1450 gbyte (); /* Ignore checksum */
1456 putchar_e7000 (ACK
);
1457 expect ("TOP ADDRESS =");
1458 expect ("END ADDRESS =");
1467 e7000_xfer_inferior_memory (memaddr
, myaddr
, len
, write
, target
)
1469 unsigned char *myaddr
;
1472 struct target_ops
*target
; /* ignored */
1475 return e7000_write_inferior_memory( memaddr
, myaddr
, len
);
1478 return e7000_read_inferior_memory( memaddr
, myaddr
, len
);
1480 return e7000_read_inferior_memory_large( memaddr
, myaddr
, len
);
1484 e7000_kill (args
, from_tty
)
1491 e7000_load (args
, from_tty
)
1495 struct cleanup
*old_chain
;
1500 #define WRITESIZE 0x1000
1501 char buf
[2 + 4 + 4 + WRITESIZE
]; /* `DT' + <addr> + <len> + <data> */
1505 time_t start_time
, end_time
; /* Start and end times of download */
1506 unsigned long data_count
; /* Number of bytes transferred to memory */
1507 int oldtimeout
= timeout
;
1509 timeout
= remote_timeout
;
1512 /* FIXME! change test to test for type of download */
1515 generic_load (args
, from_tty
);
1519 /* for direct tcp connections, we can do a fast binary download */
1526 while (*args
!= '\000')
1530 while (isspace (*args
)) args
++;
1534 while ((*args
!= '\000') && !isspace (*args
)) args
++;
1536 if (*args
!= '\000')
1541 else if (strncmp (arg
, "-quiet", strlen (arg
)) == 0)
1543 else if (strncmp (arg
, "-nostart", strlen (arg
)) == 0)
1546 error ("unknown option `%s'", arg
);
1550 filename
= get_exec_file (1);
1552 pbfd
= bfd_openr (filename
, gnutarget
);
1555 perror_with_name (filename
);
1558 old_chain
= make_cleanup (bfd_close
, pbfd
);
1560 if (!bfd_check_format (pbfd
, bfd_object
))
1561 error ("\"%s\" is not an object file: %s", filename
,
1562 bfd_errmsg (bfd_get_error ()));
1564 start_time
= time (NULL
);
1567 puts_e7000debug ("mw\r");
1571 for (section
= pbfd
->sections
; section
; section
= section
->next
)
1573 if (bfd_get_section_flags (pbfd
, section
) & SEC_LOAD
)
1575 bfd_vma section_address
;
1576 bfd_size_type section_size
;
1579 section_address
= bfd_get_section_vma (pbfd
, section
);
1580 section_size
= bfd_get_section_size_before_reloc (section
);
1583 printf_filtered ("[Loading section %s at 0x%x (%d bytes)]\n",
1584 bfd_get_section_name (pbfd
, section
),
1590 data_count
+= section_size
;
1592 while (section_size
> 0)
1595 static char inds
[] = "|/-\\";
1600 count
= min (section_size
, WRITESIZE
);
1602 buf
[2] = section_address
>> 24;
1603 buf
[3] = section_address
>> 16;
1604 buf
[4] = section_address
>> 8;
1605 buf
[5] = section_address
;
1607 buf
[6] = count
>> 24;
1608 buf
[7] = count
>> 16;
1609 buf
[8] = count
>> 8;
1612 bfd_get_section_contents (pbfd
, section
, buf
+ 10, fptr
, count
);
1614 if (SERIAL_WRITE (e7000_desc
, buf
, count
+ 10))
1615 fprintf_unfiltered (gdb_stderr
,
1616 "e7000_load: SERIAL_WRITE failed: %s\n",
1617 safe_strerror(errno
));
1623 printf_unfiltered ("\r%c", inds
[k
++ % 4]);
1624 gdb_flush (gdb_stdout
);
1627 section_address
+= count
;
1629 section_size
-= count
;
1638 end_time
= time (NULL
);
1640 /* Finally, make the PC point at the start address */
1643 write_pc (bfd_get_start_address (exec_bfd
));
1645 inferior_pid
= 0; /* No process now */
1647 /* This is necessary because many things were based on the PC at the time that
1648 we attached to the monitor, which is no longer valid now that we have loaded
1649 new code (and just changed the PC). Another way to do this might be to call
1650 normal_stop, except that the stack may not be valid, and things would get
1651 horribly confused... */
1653 clear_symtab_users ();
1657 entry
= bfd_get_start_address (pbfd
);
1660 printf_unfiltered ("[Starting %s at 0x%x]\n", filename
, entry
);
1662 /* start_routine (entry);*/
1665 report_transfer_performance (data_count
, start_time
, end_time
);
1667 do_cleanups (old_chain
);
1668 timeout
= oldtimeout
;
1671 /* Clean up when a program exits.
1673 The program actually lives on in the remote processor's RAM, and may be
1674 run again without a download. Don't leave it full of breakpoint
1678 e7000_mourn_inferior ()
1680 remove_breakpoints ();
1681 unpush_target (&e7000_ops
);
1682 generic_mourn_inferior (); /* Do all the proper things now */
1685 #define MAX_BREAKPOINTS 200
1686 #ifdef HARD_BREAKPOINTS
1687 #define MAX_E7000DEBUG_BREAKPOINTS (BC_BREAKPOINTS ? 5 : MAX_BREAKPOINTS)
1689 #define MAX_E7000DEBUG_BREAKPOINTS MAX_BREAKPOINTS
1692 extern int memory_breakpoint_size
;
1694 /* Since we can change to soft breakpoints dynamically, we must define
1695 more than enough. Was breakaddr[MAX_E7000DEBUG_BREAKPOINTS]. */
1696 static CORE_ADDR breakaddr
[MAX_BREAKPOINTS
] = {0};
1699 e7000_insert_breakpoint (addr
, shadow
)
1701 unsigned char *shadow
;
1705 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=%x\r", i
+1, addr
);
1716 puts_e7000debug (buf
);
1720 sprintf (buf
, "B %x\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 (addr
, shadow
)
1744 unsigned char *shadow
;
1749 for (i
= 0; i
< MAX_E7000DEBUG_BREAKPOINTS
; i
++)
1750 if (breakaddr
[i
] == addr
)
1753 #ifdef HARD_BREAKPOINTS
1756 sprintf (buf
, "BC%d - \r", i
+1);
1757 puts_e7000debug (buf
);
1761 sprintf (buf
, "B - %x\r", addr
);
1762 puts_e7000debug (buf
);
1766 sprintf (buf
, "B - %x\r", addr
);
1767 puts_e7000debug (buf
);
1771 /* Replace the insn under the break */
1772 e7000_write_inferior_memory (addr
, shadow
, 2);
1779 warning ("Can't find breakpoint associated with 0x%x\n", addr
);
1783 /* Put a command string, in args, out to STDBUG. Output from STDBUG
1784 is placed on the users terminal until the prompt is seen. */
1787 e7000_command (args
, fromtty
)
1791 /* FIXME: arbitrary limit on length of args. */
1797 error ("e7000 target not open.");
1800 puts_e7000debug ("\r");
1804 sprintf (buf
, "%s\r", args
);
1805 puts_e7000debug (buf
);
1810 expect_full_prompt ();
1813 printf_unfiltered ("\n");
1815 /* Who knows what the command did... */
1816 registers_changed ();
1821 e7000_drain_command (args
, fromtty
)
1828 puts_e7000debug("end\r");
1829 putchar_e7000 (CTRLC
);
1831 while ((c
= SERIAL_READCHAR (e7000_desc
, 1) != SERIAL_TIMEOUT
))
1835 putchar_e7000(CTRLC
);
1838 if (c
> ' ' && c
< 127)
1839 printf ("%c", c
& 0xff);
1841 printf ("<%x>", c
& 0xff);
1850 static char *strings
[NITEMS
] = {
1856 "ILLEGAL INSTRUCTION",
1863 for (i
= 0; i
< NITEMS
; ++i
)
1869 for (i
= 0; i
< NITEMS
; i
++)
1876 /* found one of the choices */
1888 /* Suck characters, if a string match, then return the strings index
1889 otherwise echo them. */
1899 char *buffer
= saveaway
;
1900 /* Count number of expect strings */
1902 for (n
= 0; strings
[n
]; n
++)
1904 ptr
[n
] = strings
[n
];
1912 c
= SERIAL_READCHAR (e7000_desc
, 1);
1913 if (c
== SERIAL_TIMEOUT
)
1915 printf_unfiltered ("[waiting for e7000...]\n");
1928 putchar_e7000 (CTRLC
); /* interrupt the running program */
1932 for (i
= 0; i
< n
; i
++)
1939 /* Gone all the way */
1946 ptr
[i
] = strings
[i
];
1952 /* Save it up incase we find that there was no match */
1957 if (buffer
!= saveaway
)
1960 printf ("%s", buffer
);
1963 if (c
!= SERIAL_TIMEOUT
)
1972 /* We subtract two from the pc here rather than use
1973 DECR_PC_AFTER_BREAK since the e7000 doesn't always add two to the
1974 pc, and the simulators never do. */
1982 store_signed_integer (buf
,
1983 REGISTER_RAW_SIZE(PC_REGNUM
),
1984 read_register (PC_REGNUM
) -2);
1985 supply_register (PC_REGNUM
, buf
);
1986 sprintf (buf2
, ".PC %x\r", read_register (PC_REGNUM
));
1987 puts_e7000debug (buf2
);
1992 #define WAS_RUNNING 2
1995 static char *estrings
[] = {
2003 /* Wait until the remote machine stops, then return, storing status in
2004 STATUS just as `wait' would. */
2007 e7000_wait (pid
, status
)
2009 struct target_waitstatus
*status
;
2013 int running_count
= 0;
2017 /* Then echo chars until PC= string seen */
2018 gch (); /* Drop cr */
2019 gch (); /* and space */
2023 switch (expect_n (estrings
))
2026 /* how did this happen ? */
2031 putchar_e7000 (CTRLC
);
2039 if (running_count
== 20)
2041 printf_unfiltered ("[running...]\n");
2051 /* Skip till the PC= */
2054 #ifdef GDB_TARGET_IS_SH
2055 if ((sh_processor_type
!= NULL
) && (*(sh_processor_type
+2) == '3'))
2056 fetch_regs_from_dump (gch
, want_sh3_nopc
);
2058 fetch_regs_from_dump (gch
, want_nopc
);
2060 fetch_regs_from_dump (gch
, h8300smode
? want_nopc_h8300s
: want_nopc_h8300h
);
2063 /* And supply the extra ones the simulator uses */
2064 for (regno
= NUM_REALREGS
; regno
< NUM_REGS
; regno
++)
2067 supply_register (regno
, (char *) &buf
);
2070 stop_reason
= why_stop ();
2071 expect_full_prompt ();
2073 status
->kind
= TARGET_WAITKIND_STOPPED
;
2074 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2076 switch (stop_reason
)
2078 case 1: /* Breakpoint */
2079 write_pc (read_pc ()); /* PC is always off by 2 for breakpoints */
2080 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2082 case 0: /* Single step */
2083 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2085 case 2: /* Interrupt */
2088 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2093 status
->value
.sig
= TARGET_SIGNAL_INT
;
2099 printf_unfiltered ("a cycle address error?\n");
2100 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2103 status
->value
.sig
= TARGET_SIGNAL_ILL
;
2106 status
->value
.sig
= TARGET_SIGNAL_SEGV
;
2108 case 7: /* Anything else (NITEMS + 1) */
2109 printf_unfiltered ("a write protect error?\n");
2110 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2113 /* Get the user's attention - this should never happen. */
2120 /* Stop the running program. */
2125 /* Sending a ^C is supposed to stop the running program. */
2126 putchar_e7000 (CTRLC
);
2129 /* Define the target subroutine names. */
2131 struct target_ops e7000_ops
=
2134 "Remote Hitachi e7000 target",
2135 "Use a remote Hitachi e7000 ICE connected by a serial line,\n\
2136 or a network connection.\n\
2137 Arguments are the name of the device for the serial line,\n\
2138 the speed to connect at in bits per second.\n\
2140 target e7000 /dev/ttya 9600\n\
2141 target e7000 foobar",
2142 e7000_open
, /* to_open */
2143 e7000_close
, /* to_close */
2145 e7000_detach
, /* to_detach */
2146 e7000_resume
, /* to_resume */
2147 e7000_wait
, /* to_wait */
2148 e7000_fetch_register
, /* to_fetch_registers */
2149 e7000_store_register
, /* to_store_registers */
2150 e7000_prepare_to_store
, /* to_prepare_to_store */
2151 e7000_xfer_inferior_memory
, /* to_xfer_memory */
2152 e7000_files_info
, /* to_files_info */
2153 e7000_insert_breakpoint
, /* to_insert_breakpoint */
2154 e7000_remove_breakpoint
, /* to_remove_breakpoint */
2155 0, /* to_terminal_init */
2156 0, /* to_terminal_inferior */
2157 0, /* to_terminal_ours_for_output */
2158 0, /* to_terminal_ours */
2159 0, /* to_terminal_info */
2160 e7000_kill
, /* to_kill */
2161 e7000_load
, /* to_load */
2162 0, /* to_lookup_symbol */
2163 e7000_create_inferior
, /* to_create_inferior */
2164 e7000_mourn_inferior
, /* to_mourn_inferior */
2166 0, /* to_notice_signals */
2167 0, /* to_thread_alive */
2168 e7000_stop
, /* to_stop */
2169 process_stratum
, /* to_stratum */
2170 0, /* next (unused) */
2171 1, /* to_has_all_memory */
2172 1, /* to_has_memory */
2173 1, /* to_has_stack */
2174 1, /* to_has_registers */
2175 1, /* to_has_execution */
2176 0, /* to_sections */
2177 0, /* to_sections_end */
2178 OPS_MAGIC
, /* Always the last thing */
2182 _initialize_remote_e7000 ()
2184 add_target (&e7000_ops
);
2186 add_com ("e7000 <command>", class_obscure
, e7000_command
,
2187 "Send a command to the e7000 monitor.");
2189 add_com ("ftplogin <machine> <name> <passwd> <dir>", class_obscure
, e7000_login_command
,
2190 "Login to machine and change to directory.");
2192 add_com ("ftpload <file>", class_obscure
, e7000_ftp_command
,
2193 "Fetch and load a file from previously described place.");
2195 add_com ("drain", class_obscure
, e7000_drain_command
,
2196 "Drain pending e7000 text buffers.");
2198 add_show_from_set (add_set_cmd ("usehardbreakpoints", no_class
,
2199 var_integer
, (char *)&use_hard_breakpoints
,
2200 "Set use of hardware breakpoints for all breakpoints.\n", &setlist
),