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"
51 #define HARD_BREAKPOINTS /* Now handled by set option. */
52 #define BC_BREAKPOINTS use_hard_breakpoints
60 extern void report_transfer_performance
PARAMS ((unsigned long,
63 extern char *sh_processor_type
;
65 /* Local function declarations. */
67 static void e7000_close
PARAMS ((int));
69 static void e7000_fetch_register
PARAMS ((int));
71 static void e7000_store_register
PARAMS ((int));
73 static void e7000_command
PARAMS ((char *, int));
75 static void e7000_login_command
PARAMS ((char *, int));
77 static void e7000_ftp_command
PARAMS ((char *, int));
79 static void e7000_drain_command
PARAMS ((char *, int));
81 static void expect
PARAMS ((char *));
83 static void expect_full_prompt
PARAMS ((void));
85 static void expect_prompt
PARAMS ((void));
89 static serial_t e7000_desc
;
91 /* Allow user to chose between using hardware breakpoints or memory. */
92 static int use_hard_breakpoints
= 0; /* use sw breakpoints by default */
94 /* Nonzero if using the tcp serial driver. */
96 static int using_tcp
; /* direct tcp connection to target */
97 static int using_tcp_remote
; /* indirect connection to target
98 via tcp to controller */
100 /* Nonzero if using the pc isa card. */
104 extern struct target_ops e7000_ops
; /* Forward declaration */
106 char *ENQSTRING
= "\005";
108 /* Nonzero if some routine (as opposed to the user) wants echoing.
109 FIXME: Do this reentrantly with an extra parameter. */
115 static int timeout
= 20;
117 /* Send data to e7000debug. */
120 puts_e7000debug (buf
)
124 error ("Use \"target e7000 ...\" first.");
127 printf("Sending %s\n", buf
);
129 if (SERIAL_WRITE (e7000_desc
, buf
, strlen (buf
)))
130 fprintf (stderr
, "SERIAL_WRITE failed: %s\n", safe_strerror (errno
));
132 /* And expect to see it echoed, unless using the pc interface */
146 SERIAL_WRITE (e7000_desc
, b
, 1);
153 SERIAL_WRITE (e7000_desc
, s
, strlen (s
));
165 /* Read a character from the remote system, doing all the fancy timeout
176 c
= SERIAL_READCHAR (e7000_desc
, timeout
);
180 if (c
== SERIAL_TIMEOUT
)
185 error ("Timeout reading from remote system.");
200 static char b
[8][10];
212 sprintf(b
[p
], "<%d>", x
);
219 /* Scan input from the remote system, until STRING is found. If
220 DISCARD is non-zero, then discard non-matching input, else print it
221 out. Let the user break out immediately. */
233 c
= readchar (timeout
);
239 putchar_e7000(CTRLC
);
248 if (c
== SERIAL_ERROR
)
250 error ("Serial communication error");
252 if (echo
|| remote_debug
)
254 if (c
== '\r' || c
== '\n')
267 if (normal (c
) == normal (*p
++))
276 if (normal (c
) == normal (string
[0]))
282 /* Keep discarding input until we see the e7000 prompt.
284 The convention for dealing with the prompt is that you
286 o *then* wait for the prompt.
288 Thus the last thing that a procedure does with the serial line will
289 be an expect_prompt(). Exception: e7000_resume does not wait for
290 the prompt, because the terminal is being handed over to the
291 inferior. However, the next thing which happens after that is a
292 e7000_wait which does wait for the prompt. Note that this includes
293 abnormal exit, e.g. error(). This is necessary to prevent getting
294 into states from which we can't recover. */
303 expect_full_prompt ()
309 convert_hex_digit (ch
)
312 if (ch
>= '0' && ch
<= '9')
314 else if (ch
>= 'A' && ch
<= 'F')
315 return ch
- 'A' + 10;
316 else if (ch
>= 'a' && ch
<= 'f')
317 return ch
- 'a' + 10;
325 int value
= convert_hex_digit (*start
);
328 *start
= readchar (timeout
);
329 while ((try = convert_hex_digit (*start
)) >= 0)
333 *start
= readchar (timeout
);
339 /* Get N 32-bit words from remote, each preceded by a space, and put
340 them in registers starting at REGNO. */
343 get_hex_regs (n
, regno
)
350 for (i
= 0; i
< n
; i
++)
355 for (j
= 0; j
< 8; j
++)
356 val
= (val
<< 4) + get_hex_digit (j
== 0);
357 supply_register (regno
++, (char *) &val
);
362 /* This is called not only when we first attach, but also when the
363 user types "run" after having attached. */
366 e7000_create_inferior (execfile
, args
, env
)
374 error ("Can't pass arguments to remote E7000DEBUG process");
376 if (execfile
== 0 || exec_bfd
== 0)
377 error ("No exec file specified");
379 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
381 #ifdef CREATE_INFERIOR_HOOK
382 CREATE_INFERIOR_HOOK (0); /* No process-ID */
385 /* The "process" (board) is already stopped awaiting our commands, and
386 the program is already downloaded. We just set its PC and go. */
388 clear_proceed_status ();
390 /* Tell wait_for_inferior that we've started a new process. */
391 init_wait_for_inferior ();
393 /* Set up the "saved terminal modes" of the inferior
394 based on what modes we are starting it with. */
395 target_terminal_init ();
397 /* Install inferior's terminal modes. */
398 target_terminal_inferior ();
400 /* insert_step_breakpoint (); FIXME, do we need this? */
401 proceed ((CORE_ADDR
) entry_pt
, -1, 0); /* Let 'er rip... */
404 /* Open a connection to a remote debugger. NAME is the filename used
405 for communication. */
407 static int baudrate
= 9600;
408 static char dev_name
[100];
410 static char *machine
= "";
411 static char *user
= "";
412 static char *passwd
= "";
413 static char *dir
= "";
415 /* Grab the next token and buy some space for it */
426 while (*p
&& *p
== ' ')
429 while (*p
&& (*p
!= ' ' && *p
!= '\t'))
442 e7000_login_command (args
, from_tty
)
448 machine
= next (&args
);
450 passwd
= next (&args
);
454 printf ("Set info to %s %s %s %s\n", machine
, user
, passwd
, dir
);
459 error ("Syntax is ftplogin <machine> <user> <passwd> <directory>");
463 /* Start an ftp transfer from the E7000 to a host */
466 e7000_ftp_command (args
, from_tty
)
470 /* FIXME: arbitrary limit on machine names and such. */
473 int oldtimeout
= timeout
;
474 timeout
= remote_timeout
;
476 sprintf (buf
, "ftp %s\r", machine
);
477 puts_e7000debug (buf
);
478 expect (" Username : ");
479 sprintf (buf
, "%s\r", user
);
480 puts_e7000debug (buf
);
481 expect (" Password : ");
482 write_e7000 (passwd
);
484 expect ("success\r");
486 sprintf (buf
, "cd %s\r", dir
);
487 puts_e7000debug (buf
);
489 sprintf (buf
, "ll 0;s:%s\r", args
);
490 puts_e7000debug (buf
);
492 puts_e7000debug ("bye\r");
494 timeout
= oldtimeout
;
498 e7000_parse_device(args
,dev_name
,serial_flag
,baudrate
)
506 if (args
&& strcasecmp (args
, "pc") == 0)
508 strcpy (dev_name
, args
);
513 /* FIXME! temp hack to allow use with port master -
514 target tcp_remote <device> */
515 if (args
&& strncmp (args
, "tcp_remote", 10) == 0)
518 n
= sscanf (args
, " %s %s %d %s", com_type
, dev_name
, &baudrate
, junk
);
524 n
= sscanf (args
, " %s %d %s", dev_name
, &baudrate
, junk
);
527 if (n
!= 1 && n
!= 2)
529 error ("Bad arguments. Usage:\ttarget e7000 <device> <speed>\n\
530 or \t\ttarget e7000 <host>[:<port>]\n\
531 or \t\ttarget e7000 tcp_remote <host>[:<port>]\n\
532 or \t\ttarget e7000 pc\n");
535 #if !defined(__GO32__) && !defined(__WIN32__)
536 /* FIXME! test for ':' is ambiguous */
537 if (n
== 1 && strchr (dev_name
, ':') == 0)
539 /* Default to normal telnet port */
540 /* serial_open will use this to determine tcp communication */
541 strcat (dev_name
, ":23");
544 if (!using_tcp_remote
&& strchr (dev_name
, ':'))
552 e7000_open (args
, from_tty
)
561 target_preopen (from_tty
);
563 n
= e7000_parse_device(args
,dev_name
,serial_flag
,baudrate
);
565 push_target (&e7000_ops
);
567 e7000_desc
= SERIAL_OPEN (dev_name
);
570 perror_with_name (dev_name
);
572 SERIAL_SETBAUDRATE (e7000_desc
, baudrate
);
573 SERIAL_RAW (e7000_desc
);
575 /* Hello? Are you there? */
578 putchar_e7000 (CTRLC
);
584 printf_unfiltered ("[waiting for e7000...]\n");
587 c
= SERIAL_READCHAR (e7000_desc
, 1);
588 while (c
!= SERIAL_TIMEOUT
)
591 if (from_tty
&& c
!= '\r')
601 putchar_e7000 (CTRLC
);
610 putchar_e7000 (CTRLC
);
613 c
= SERIAL_READCHAR (e7000_desc
, 1);
616 puts_e7000debug ("\r");
620 puts_e7000debug ("b -\r");
625 printf_filtered ("Remote target %s connected to %s\n", target_shortname
,
628 #ifdef GDB_TARGET_IS_H8300
633 /* Close out all files and local state before this target loses control. */
636 e7000_close (quitting
)
641 SERIAL_CLOSE (e7000_desc
);
646 /* Terminate the open connection to the remote debugger. Use this
647 when you want to detach and do something else with your gdb. */
650 e7000_detach (from_tty
)
653 pop_target (); /* calls e7000_close to do the real work */
655 printf ("Ending remote %s debugging\n", target_shortname
);
658 /* Tell the remote machine to resume. */
661 e7000_resume (pid
, step
, sig
)
665 puts_e7000debug ("S\r");
667 puts_e7000debug ("G\r");
670 /* Read the remote registers into the block REGS.
672 For the H8/300 a register dump looks like:
674 PC=00021A CCR=80:I*******
675 ER0 - ER3 0000000A 0000002E 0000002E 00000000
676 ER4 - ER7 00000000 00000000 00000000 00FFEFF6
682 #ifdef GDB_TARGET_IS_H8300
684 char *want
= "PC=%p CCR=%c\n\
685 ER0 - ER3 %0 %1 %2 %3\n\
686 ER4 - ER7 %4 %5 %6 %7\n";
688 char *want_nopc
= "%p CCR=%c\n\
689 ER0 - ER3 %0 %1 %2 %3\n\
690 ER4 - ER7 %4 %5 %6 %7";
694 #ifdef GDB_TARGET_IS_SH
696 char *want
= "PC=%16 SR=%22\n\
697 PR=%17 GBR=%18 VBR=%19\n\
699 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
700 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n";
702 char *want_nopc
= "%16 SR=%22\n\
703 PR=%17 GBR=%18 VBR=%19\n\
705 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
706 R8-15 %8 %9 %10 %11 %12 %13 %14 %15";
708 char *want_sh3
= "PC=%16 SR=%22\n\
709 PR=%17 GBR=%18 VBR=%19\n\
710 MACH=%20 MACL=%21 SSR=%23 SPC=%24\n\
711 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
712 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
713 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
714 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
715 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
716 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
718 char *want_sh3_nopc
= "%16 SR=%22\n\
719 PR=%17 GBR=%18 VBR=%19\n\
720 MACH=%20 MACL=%21 SSR=%22 SPC=%23\n\
721 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
722 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
723 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
724 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
725 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
726 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
733 int c
= readchar (timeout
);
748 int high
= convert_hex_digit (gch ());
749 int low
= convert_hex_digit (gch ());
751 return (high
<< 4) + low
;
755 fetch_regs_from_dump (nextchar
, want
)
760 char buf
[MAX_REGISTER_RAW_SIZE
];
762 int thischar
= nextchar ();
769 /* Skip to end of line and then eat all new line type stuff */
770 while (thischar
!= '\n' && thischar
!= '\r')
771 thischar
= nextchar ();
772 while (thischar
== '\n' || thischar
== '\r')
773 thischar
= nextchar ();
778 while (thischar
== ' '
782 thischar
= nextchar ();
787 if (*want
== thischar
)
791 thischar
= nextchar ();
794 else if (thischar
== ' ' || thischar
== '\n' || thischar
== '\r')
796 thischar
= nextchar ();
799 error ("out of sync in fetch registers wanted <%s>, got <%c 0x%x>",
800 want
, thischar
, thischar
);
805 /* Got a register command */
835 if (isdigit (want
[0]))
837 if (isdigit (want
[1]))
839 regno
= (want
[0] - '0') * 10 + want
[1] - '0';
844 regno
= want
[0] - '0';
852 store_signed_integer (buf
,
853 REGISTER_RAW_SIZE(regno
),
854 (LONGEST
) get_hex (&thischar
, nextchar
));
855 supply_register (regno
, buf
);
862 e7000_fetch_registers ()
866 puts_e7000debug ("R\r");
868 #ifdef GDB_TARGET_IS_SH
869 if ((sh_processor_type
!= NULL
) && (*(sh_processor_type
+2) == '3'))
870 fetch_regs_from_dump (gch
, want_sh3
);
872 fetch_regs_from_dump (gch
, want
);
874 fetch_regs_from_dump (gch
, want
);
878 /* And supply the extra ones the simulator uses */
879 for (regno
= NUM_REALREGS
; regno
< NUM_REGS
; regno
++)
883 supply_register (regno
, (char *) (&buf
));
887 /* Fetch register REGNO, or all registers if REGNO is -1. Returns
891 e7000_fetch_register (regno
)
894 e7000_fetch_registers ();
897 /* Store the remote registers from the contents of the block REGS. */
900 e7000_store_registers ()
904 for (regno
= 0; regno
< NUM_REALREGS
; regno
++)
905 e7000_store_register (regno
);
907 registers_changed ();
910 /* Store register REGNO, or all if REGNO == 0. Return errno value. */
913 e7000_store_register (regno
)
920 e7000_store_registers ();
924 #ifdef GDB_TARGET_IS_H8300
927 sprintf (buf
, ".ER%d %x\r", regno
, read_register (regno
));
928 puts_e7000debug (buf
);
930 else if (regno
== PC_REGNUM
)
932 sprintf (buf
, ".PC %x\r", read_register (regno
));
933 puts_e7000debug (buf
);
935 else if (regno
== CCR_REGNUM
)
937 sprintf (buf
, ".CCR %x\r", read_register (regno
));
938 puts_e7000debug (buf
);
940 #endif /* GDB_TARGET_IS_H8300 */
942 #ifdef GDB_TARGET_IS_SH
946 sprintf (buf
, ".R%d %x\r", regno
, read_register (regno
));
947 puts_e7000debug (buf
);
951 sprintf (buf
, ".PC %x\r", read_register (regno
));
952 puts_e7000debug (buf
);
956 sprintf (buf
, ".SR %x\r", read_register (regno
));
957 puts_e7000debug (buf
);
961 sprintf (buf
, ".PR %x\r", read_register (regno
));
962 puts_e7000debug (buf
);
966 sprintf (buf
, ".GBR %x\r", read_register (regno
));
967 puts_e7000debug (buf
);
971 sprintf (buf
, ".VBR %x\r", read_register (regno
));
972 puts_e7000debug (buf
);
976 sprintf (buf
, ".MACH %x\r", read_register (regno
));
977 puts_e7000debug (buf
);
981 sprintf (buf
, ".MACL %x\r", read_register (regno
));
982 puts_e7000debug (buf
);
986 #endif /* GDB_TARGET_IS_SH */
991 /* Get ready to modify the registers array. On machines which store
992 individual registers, this doesn't need to do anything. On machines
993 which store all the registers in one fell swoop, this makes sure
994 that registers contains all the registers from the program being
998 e7000_prepare_to_store ()
1000 /* Do nothing, since we can store individual regs */
1006 printf ("\tAttached to %s at %d baud.\n", dev_name
, baudrate
);
1010 stickbyte (where
, what
)
1014 static CONST
char digs
[] = "0123456789ABCDEF";
1016 where
[0] = digs
[(what
>> 4) & 0xf];
1017 where
[1] = digs
[(what
& 0xf) & 0xf];
1022 /* Write a small ammount of memory. */
1025 write_small (memaddr
, myaddr
, len
)
1027 unsigned char *myaddr
;
1033 for (i
= 0; i
< len
; i
++)
1035 if (((memaddr
+ i
) & 3) == 0 && (i
+ 3 < len
))
1037 /* Can be done with a long word */
1038 sprintf (buf
, "m %x %x%02x%02x%02x;l\r",
1040 myaddr
[i
], myaddr
[i
+ 1], myaddr
[i
+ 2], myaddr
[i
+ 3]);
1041 puts_e7000debug (buf
);
1046 sprintf (buf
, "m %x %x\r", memaddr
+ i
, myaddr
[i
]);
1047 puts_e7000debug (buf
);
1056 /* Write a large ammount of memory, this only works with the serial
1057 mode enabled. Command is sent as
1072 write_large (memaddr
, myaddr
, len
)
1074 unsigned char *myaddr
;
1078 #define maxstride 128
1081 puts_e7000debug ("IL ;S:FK\r");
1083 putchar_e7000 (ACK
);
1086 for (i
= 0; i
< len
; i
+= stride
)
1088 char compose
[maxstride
* 2 + 50];
1089 int address
= i
+ memaddr
;
1096 if (stride
> maxstride
)
1099 compose
[where
++] = 'S';
1101 if (address
>= 0xffffff)
1103 else if (address
>= 0xffff)
1108 compose
[where
++] = alen
- 1 + '0';
1109 /* Insert length. */
1110 check_sum
+= stickbyte (compose
+ where
, alen
+ stride
+ 1);
1115 check_sum
+= stickbyte (compose
+ where
, address
>> (8 * (alen
)));
1119 for (j
= 0; j
< stride
; j
++)
1121 check_sum
+= stickbyte (compose
+ where
, myaddr
[i
+ j
]);
1124 stickbyte (compose
+ where
, ~check_sum
);
1126 compose
[where
++] = '\r';
1127 compose
[where
++] = '\n';
1128 compose
[where
++] = 0;
1130 SERIAL_WRITE (e7000_desc
, compose
, where
);
1131 j
= SERIAL_READCHAR (e7000_desc
, 0);
1132 if (j
== SERIAL_TIMEOUT
)
1134 /* This is ok - nothing there */
1138 /* Hmm, it's trying to tell us something */
1140 error ("Error writing memory");
1144 printf ("@%d}@", j
);
1145 while ((j
= SERIAL_READCHAR(e7000_desc
,0)) > 0)
1147 printf ("@{%d}@",j
);
1152 /* Send the trailer record */
1153 write_e7000 ("S70500000000FA\r");
1154 putchar_e7000 (CTRLZ
);
1156 putchar_e7000 (ACK
);
1162 /* Copy LEN bytes of data from debugger memory at MYADDR to inferior's
1163 memory at MEMADDR. Returns length moved.
1165 Can't use the Srecord load over ethernet, so don't use fast method
1169 e7000_write_inferior_memory (memaddr
, myaddr
, len
)
1171 unsigned char *myaddr
;
1174 if (len
< 16 || using_tcp
|| using_pc
)
1175 return write_small (memaddr
, myaddr
, len
);
1177 return write_large (memaddr
, myaddr
, len
);
1180 /* Read LEN bytes from inferior memory at MEMADDR. Put the result
1181 at debugger address MYADDR. Returns length moved.
1183 Small transactions we send
1190 e7000_read_inferior_memory (memaddr
, myaddr
, len
)
1192 unsigned char *myaddr
;
1199 /* Starting address of this pass. */
1201 /* printf("READ INF %x %x %d\n", memaddr, myaddr, len);*/
1202 if (((memaddr
- 1) + len
) < memaddr
)
1208 sprintf (buf
, "m %x;l\r", memaddr
);
1209 puts_e7000debug (buf
);
1211 for (count
= 0; count
< len
; count
+= 4)
1213 /* Suck away the address */
1219 { /* Some kind of error */
1226 /* Now read in the data */
1227 for (i
= 0; i
< 4; i
++)
1230 if (count
+ i
< len
) {
1231 myaddr
[count
+ i
] = b
;
1235 /* Skip the trailing ? and send a . to end and a cr for more */
1238 if (count
+ 4 >= len
)
1239 puts_e7000debug(".\r");
1241 puts_e7000debug("\r");
1251 For large transfers we used to send
1254 d <addr> <endaddr>\r
1257 <ADDRESS> < D A T A > < ASCII CODE >
1258 00000000 5F FD FD FF DF 7F DF FF 01 00 01 00 02 00 08 04 "_..............."
1259 00000010 FF D7 FF 7F D7 F1 7F FF 00 05 00 00 08 00 40 00 "..............@."
1260 00000020 7F FD FF F7 7F FF FF F7 00 00 00 00 00 00 00 00 "................"
1262 A cost in chars for each transaction of 80 + 5*n-bytes.
1264 Large transactions could be done with the srecord load code, but
1265 there is a pause for a second before dumping starts, which slows the
1270 e7000_read_inferior_memory_large (memaddr
, myaddr
, len
)
1272 unsigned char *myaddr
;
1279 /* Starting address of this pass. */
1281 if (((memaddr
- 1) + len
) < memaddr
)
1287 sprintf (buf
, "d %x %x\r", memaddr
, memaddr
+ len
- 1);
1288 puts_e7000debug (buf
);
1293 /* skip down to the first ">" */
1296 /* now skip to the end of that line */
1303 /* get rid of any white space before the address */
1307 /* Skip the address */
1310 /* read in the bytes on the line */
1311 while (c
!= '"' && count
< len
)
1317 myaddr
[count
++] = get_hex (&c
);
1320 /* throw out the rest of the line */
1325 /* wait for the ":" prompt */
1335 fast_but_for_the_pause_e7000_read_inferior_memory (memaddr
, myaddr
, len
)
1344 if (((memaddr
- 1) + len
) < memaddr
)
1350 sprintf (buf
, "is %x@%x:s\r", memaddr
, len
);
1351 puts_e7000debug (buf
);
1357 error ("Memory read error");
1359 putchar_e7000 (ACK
);
1372 case ENQ
: /* ENQ, at the end */
1376 /* Start of an Srecord */
1381 case '7': /* Termination record, ignore */
1385 /* Header record - ignore it */
1397 alen
= type
- '0' + 1;
1401 addr
= (addr
<< 8) + gbyte ();
1405 for (i
= 0; i
< length
- 1; i
++)
1406 myaddr
[i
+ addr
- memaddr
] = gbyte ();
1408 gbyte (); /* Ignore checksum */
1414 putchar_e7000 (ACK
);
1415 expect ("TOP ADDRESS =");
1416 expect ("END ADDRESS =");
1425 e7000_xfer_inferior_memory (memaddr
, myaddr
, len
, write
, target
)
1427 unsigned char *myaddr
;
1430 struct target_ops
*target
; /* ignored */
1433 return e7000_write_inferior_memory( memaddr
, myaddr
, len
);
1436 return e7000_read_inferior_memory( memaddr
, myaddr
, len
);
1438 return e7000_read_inferior_memory_large( memaddr
, myaddr
, len
);
1442 e7000_kill (args
, from_tty
)
1449 e7000_load (args
, from_tty
)
1453 struct cleanup
*old_chain
;
1458 #define WRITESIZE 0x1000
1459 char buf
[2 + 4 + 4 + WRITESIZE
]; /* `DT' + <addr> + <len> + <data> */
1463 time_t start_time
, end_time
; /* Start and end times of download */
1464 unsigned long data_count
; /* Number of bytes transferred to memory */
1465 int oldtimeout
= timeout
;
1467 timeout
= remote_timeout
;
1470 /* FIXME! change test to test for type of download */
1473 generic_load (args
, from_tty
);
1477 /* for direct tcp connections, we can do a fast binary download */
1484 while (*args
!= '\000')
1488 while (isspace (*args
)) args
++;
1492 while ((*args
!= '\000') && !isspace (*args
)) args
++;
1494 if (*args
!= '\000')
1499 else if (strncmp (arg
, "-quiet", strlen (arg
)) == 0)
1501 else if (strncmp (arg
, "-nostart", strlen (arg
)) == 0)
1504 error ("unknown option `%s'", arg
);
1508 filename
= get_exec_file (1);
1510 pbfd
= bfd_openr (filename
, gnutarget
);
1513 perror_with_name (filename
);
1516 old_chain
= make_cleanup (bfd_close
, pbfd
);
1518 if (!bfd_check_format (pbfd
, bfd_object
))
1519 error ("\"%s\" is not an object file: %s", filename
,
1520 bfd_errmsg (bfd_get_error ()));
1522 start_time
= time (NULL
);
1525 puts_e7000debug ("mw\r");
1529 for (section
= pbfd
->sections
; section
; section
= section
->next
)
1531 if (bfd_get_section_flags (pbfd
, section
) & SEC_LOAD
)
1533 bfd_vma section_address
;
1534 bfd_size_type section_size
;
1537 section_address
= bfd_get_section_vma (pbfd
, section
);
1538 section_size
= bfd_get_section_size_before_reloc (section
);
1541 printf_filtered ("[Loading section %s at 0x%x (%d bytes)]\n",
1542 bfd_get_section_name (pbfd
, section
),
1548 data_count
+= section_size
;
1550 while (section_size
> 0)
1553 static char inds
[] = "|/-\\";
1558 count
= min (section_size
, WRITESIZE
);
1560 buf
[2] = section_address
>> 24;
1561 buf
[3] = section_address
>> 16;
1562 buf
[4] = section_address
>> 8;
1563 buf
[5] = section_address
;
1565 buf
[6] = count
>> 24;
1566 buf
[7] = count
>> 16;
1567 buf
[8] = count
>> 8;
1570 bfd_get_section_contents (pbfd
, section
, buf
+ 10, fptr
, count
);
1572 if (SERIAL_WRITE (e7000_desc
, buf
, count
+ 10))
1573 fprintf_unfiltered (gdb_stderr
,
1574 "e7000_load: SERIAL_WRITE failed: %s\n",
1575 safe_strerror(errno
));
1581 printf_unfiltered ("\r%c", inds
[k
++ % 4]);
1582 gdb_flush (gdb_stdout
);
1585 section_address
+= count
;
1587 section_size
-= count
;
1596 end_time
= time (NULL
);
1598 /* Finally, make the PC point at the start address */
1601 write_pc (bfd_get_start_address (exec_bfd
));
1603 inferior_pid
= 0; /* No process now */
1605 /* This is necessary because many things were based on the PC at the time that
1606 we attached to the monitor, which is no longer valid now that we have loaded
1607 new code (and just changed the PC). Another way to do this might be to call
1608 normal_stop, except that the stack may not be valid, and things would get
1609 horribly confused... */
1611 clear_symtab_users ();
1615 entry
= bfd_get_start_address (pbfd
);
1618 printf_unfiltered ("[Starting %s at 0x%x]\n", filename
, entry
);
1620 /* start_routine (entry);*/
1623 report_transfer_performance (data_count
, start_time
, end_time
);
1625 do_cleanups (old_chain
);
1626 timeout
= oldtimeout
;
1629 /* Clean up when a program exits.
1631 The program actually lives on in the remote processor's RAM, and may be
1632 run again without a download. Don't leave it full of breakpoint
1636 e7000_mourn_inferior ()
1638 remove_breakpoints ();
1639 unpush_target (&e7000_ops
);
1640 generic_mourn_inferior (); /* Do all the proper things now */
1643 #define MAX_BREAKPOINTS 200
1644 #ifdef HARD_BREAKPOINTS
1645 #define MAX_E7000DEBUG_BREAKPOINTS (BC_BREAKPOINTS ? 5 : MAX_BREAKPOINTS)
1647 #define MAX_E7000DEBUG_BREAKPOINTS MAX_BREAKPOINTS
1650 extern int memory_breakpoint_size
;
1652 /* Since we can change to soft breakpoints dynamically, we must define
1653 more than enough. Was breakaddr[MAX_E7000DEBUG_BREAKPOINTS]. */
1654 static CORE_ADDR breakaddr
[MAX_BREAKPOINTS
] = {0};
1657 e7000_insert_breakpoint (addr
, shadow
)
1659 unsigned char *shadow
;
1663 static char nop
[2] = NOP
;
1665 for (i
= 0; i
<= MAX_E7000DEBUG_BREAKPOINTS
; i
++)
1666 if (breakaddr
[i
] == 0)
1668 breakaddr
[i
] = addr
;
1669 /* Save old contents, and insert a nop in the space */
1670 #ifdef HARD_BREAKPOINTS
1673 sprintf (buf
, "BC%d A=%x\r", i
+1, addr
);
1674 puts_e7000debug (buf
);
1678 sprintf (buf
, "B %x\r", addr
);
1679 puts_e7000debug (buf
);
1683 e7000_read_inferior_memory (addr
, shadow
, 2);
1684 e7000_write_inferior_memory (addr
, nop
, 2);
1687 sprintf (buf
, "B %x\r", addr
);
1688 puts_e7000debug (buf
);
1694 error ("Too many breakpoints ( > %d) for the E7000\n",
1695 MAX_E7000DEBUG_BREAKPOINTS
);
1700 e7000_remove_breakpoint (addr
, shadow
)
1702 unsigned char *shadow
;
1707 for (i
= 0; i
< MAX_E7000DEBUG_BREAKPOINTS
; i
++)
1708 if (breakaddr
[i
] == addr
)
1711 #ifdef HARD_BREAKPOINTS
1714 sprintf (buf
, "BC%d - \r", i
+1);
1715 puts_e7000debug (buf
);
1719 sprintf (buf
, "B - %x\r", addr
);
1720 puts_e7000debug (buf
);
1724 sprintf (buf
, "B - %x\r", addr
);
1725 puts_e7000debug (buf
);
1729 /* Replace the insn under the break */
1730 e7000_write_inferior_memory (addr
, shadow
, 2);
1737 warning ("Can't find breakpoint associated with 0x%x\n", addr
);
1741 /* Put a command string, in args, out to STDBUG. Output from STDBUG
1742 is placed on the users terminal until the prompt is seen. */
1745 e7000_command (args
, fromtty
)
1749 /* FIXME: arbitrary limit on length of args. */
1755 error ("e7000 target not open.");
1758 puts_e7000debug ("\r");
1762 sprintf (buf
, "%s\r", args
);
1763 puts_e7000debug (buf
);
1768 expect_full_prompt ();
1771 printf_unfiltered ("\n");
1773 /* Who knows what the command did... */
1774 registers_changed ();
1779 e7000_drain_command (args
, fromtty
)
1786 puts_e7000debug("end\r");
1787 putchar_e7000 (CTRLC
);
1789 while ((c
= SERIAL_READCHAR (e7000_desc
, 1) != SERIAL_TIMEOUT
))
1793 putchar_e7000(CTRLC
);
1796 if (c
> ' ' && c
< 127)
1797 printf ("%c", c
& 0xff);
1799 printf ("<%x>", c
& 0xff);
1808 static char *strings
[NITEMS
] = {
1814 "ILLEGAL INSTRUCTION",
1821 for (i
= 0; i
< NITEMS
; ++i
)
1827 for (i
= 0; i
< NITEMS
; i
++)
1834 /* found one of the choices */
1846 /* Suck characters, if a string match, then return the strings index
1847 otherwise echo them. */
1857 char *buffer
= saveaway
;
1858 /* Count number of expect strings */
1860 for (n
= 0; strings
[n
]; n
++)
1862 ptr
[n
] = strings
[n
];
1870 c
= SERIAL_READCHAR (e7000_desc
, 1);
1871 if (c
== SERIAL_TIMEOUT
)
1873 printf_unfiltered ("[waiting for e7000...]\n");
1886 putchar_e7000 (CTRLC
); /* interrupt the running program */
1890 for (i
= 0; i
< n
; i
++)
1897 /* Gone all the way */
1904 ptr
[i
] = strings
[i
];
1910 /* Save it up incase we find that there was no match */
1915 if (buffer
!= saveaway
)
1918 printf ("%s", buffer
);
1921 if (c
!= SERIAL_TIMEOUT
)
1930 /* We subtract two from the pc here rather than use
1931 DECR_PC_AFTER_BREAK since the e7000 doesn't always add two to the
1932 pc, and the simulators never do. */
1940 store_signed_integer (buf
,
1941 REGISTER_RAW_SIZE(PC_REGNUM
),
1942 read_register (PC_REGNUM
) -2);
1943 supply_register (PC_REGNUM
, buf
);
1944 sprintf (buf2
, ".PC %x\r", read_register (PC_REGNUM
));
1945 puts_e7000debug (buf2
);
1950 #define WAS_RUNNING 2
1953 static char *estrings
[] = {
1961 /* Wait until the remote machine stops, then return, storing status in
1962 STATUS just as `wait' would. */
1965 e7000_wait (pid
, status
)
1967 struct target_waitstatus
*status
;
1971 int running_count
= 0;
1975 /* Then echo chars until PC= string seen */
1976 gch (); /* Drop cr */
1977 gch (); /* and space */
1981 switch (expect_n (estrings
))
1984 /* how did this happen ? */
1989 putchar_e7000 (CTRLC
);
1997 if (running_count
== 20)
1999 printf_unfiltered ("[running...]\n");
2009 /* Skip till the PC= */
2012 #ifdef GDB_TARGET_IS_SH
2013 if ((sh_processor_type
!= NULL
) && (*(sh_processor_type
+2) == '3'))
2014 fetch_regs_from_dump (gch
, want_sh3_nopc
);
2016 fetch_regs_from_dump (gch
, want_nopc
);
2018 fetch_regs_from_dump (gch
, want_nopc
);
2021 /* And supply the extra ones the simulator uses */
2022 for (regno
= NUM_REALREGS
; regno
< NUM_REGS
; regno
++)
2025 supply_register (regno
, (char *) &buf
);
2028 stop_reason
= why_stop ();
2029 expect_full_prompt ();
2031 status
->kind
= TARGET_WAITKIND_STOPPED
;
2032 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2034 switch (stop_reason
)
2036 case 1: /* Breakpoint */
2037 write_pc (read_pc ()); /* PC is always off by 2 for breakpoints */
2038 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2040 case 0: /* Single step */
2041 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2043 case 2: /* Interrupt */
2046 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2051 status
->value
.sig
= TARGET_SIGNAL_INT
;
2057 printf_unfiltered ("a cycle address error?\n");
2058 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2061 status
->value
.sig
= TARGET_SIGNAL_ILL
;
2064 status
->value
.sig
= TARGET_SIGNAL_SEGV
;
2066 case 7: /* Anything else (NITEMS + 1) */
2067 printf_unfiltered ("a write protect error?\n");
2068 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2071 /* Get the user's attention - this should never happen. */
2078 /* Stop the running program. */
2083 /* Sending a ^C is supposed to stop the running program. */
2084 putchar_e7000 (CTRLC
);
2087 /* Define the target subroutine names. */
2089 struct target_ops e7000_ops
=
2092 "Remote Hitachi e7000 target",
2093 "Use a remote Hitachi e7000 ICE connected by a serial line,\n\
2094 or a network connection.\n\
2095 Arguments are the name of the device for the serial line,\n\
2096 the speed to connect at in bits per second.\n\
2098 target e7000 /dev/ttya 9600\n\
2099 target e7000 foobar",
2100 e7000_open
, /* to_open */
2101 e7000_close
, /* to_close */
2103 e7000_detach
, /* to_detach */
2104 e7000_resume
, /* to_resume */
2105 e7000_wait
, /* to_wait */
2106 e7000_fetch_register
, /* to_fetch_registers */
2107 e7000_store_register
, /* to_store_registers */
2108 e7000_prepare_to_store
, /* to_prepare_to_store */
2109 e7000_xfer_inferior_memory
, /* to_xfer_memory */
2110 e7000_files_info
, /* to_files_info */
2111 e7000_insert_breakpoint
, /* to_insert_breakpoint */
2112 e7000_remove_breakpoint
, /* to_remove_breakpoint */
2113 0, /* to_terminal_init */
2114 0, /* to_terminal_inferior */
2115 0, /* to_terminal_ours_for_output */
2116 0, /* to_terminal_ours */
2117 0, /* to_terminal_info */
2118 e7000_kill
, /* to_kill */
2119 e7000_load
, /* to_load */
2120 0, /* to_lookup_symbol */
2121 e7000_create_inferior
, /* to_create_inferior */
2122 e7000_mourn_inferior
, /* to_mourn_inferior */
2124 0, /* to_notice_signals */
2125 0, /* to_thread_alive */
2126 e7000_stop
, /* to_stop */
2127 process_stratum
, /* to_stratum */
2128 0, /* next (unused) */
2129 1, /* to_has_all_memory */
2130 1, /* to_has_memory */
2131 1, /* to_has_stack */
2132 1, /* to_has_registers */
2133 1, /* to_has_execution */
2134 0, /* to_sections */
2135 0, /* to_sections_end */
2136 OPS_MAGIC
, /* Always the last thing */
2140 _initialize_remote_e7000 ()
2142 add_target (&e7000_ops
);
2144 add_com ("e7000 <command>", class_obscure
, e7000_command
,
2145 "Send a command to the e7000 monitor.");
2147 add_com ("ftplogin <machine> <name> <passwd> <dir>", class_obscure
, e7000_login_command
,
2148 "Login to machine and change to directory.");
2150 add_com ("ftpload <file>", class_obscure
, e7000_ftp_command
,
2151 "Fetch and load a file from previously described place.");
2153 add_com ("drain", class_obscure
, e7000_drain_command
,
2154 "Drain pending e7000 text buffers.");
2156 add_show_from_set (add_set_cmd ("usehardbreakpoints", no_class
,
2157 var_integer
, (char *)&use_hard_breakpoints
,
2158 "Set use of hardware breakpoints for all breakpoints.\n", &setlist
),