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"
43 #include <sys/types.h>
45 #include "remote-utils.h"
50 #define HARD_BREAKPOINTS
51 #define BC_BREAKPOINTS 0
59 extern void notice_quit
PARAMS ((void));
61 extern void report_transfer_performance
PARAMS ((unsigned long,
64 extern char *sh_processor_type
;
66 /* Local function declarations. */
68 static void e7000_close
PARAMS ((int));
70 static void e7000_fetch_register
PARAMS ((int));
72 static void e7000_store_register
PARAMS ((int));
74 static void e7000_command
PARAMS ((char *, int));
76 static void e7000_login_command
PARAMS ((char *, int));
78 static void e7000_ftp_command
PARAMS ((char *, int));
80 static void e7000_drain_command
PARAMS ((char *, int));
82 static void expect
PARAMS ((char *));
84 static void expect_full_prompt
PARAMS ((void));
86 static void expect_prompt
PARAMS ((void));
90 static serial_t e7000_desc
;
92 /* Nonzero if using the tcp serial driver. */
94 static int using_tcp
; /* direct tcp connection to target */
95 static int using_tcp_remote
; /* indirect connection to target
96 via tcp to controller */
98 /* Nonzero if using the pc isa card. */
102 extern struct target_ops e7000_ops
; /* Forward declaration */
104 char *ENQSTRING
= "\005";
106 /* Nonzero if some routine (as opposed to the user) wants echoing.
107 FIXME: Do this reentrantly with an extra parameter. */
113 static int timeout
= 5;
115 /* Send data to e7000debug. */
118 puts_e7000debug (buf
)
122 error ("Use \"target e7000 ...\" first.");
125 printf("Sending %s\n", buf
);
127 if (SERIAL_WRITE (e7000_desc
, buf
, strlen (buf
)))
128 fprintf (stderr
, "SERIAL_WRITE failed: %s\n", safe_strerror (errno
));
130 /* And expect to see it echoed, unless using the pc interface */
144 SERIAL_WRITE (e7000_desc
, b
, 1);
151 SERIAL_WRITE (e7000_desc
, s
, strlen (s
));
163 /* Read a character from the remote system, doing all the fancy timeout
174 c
= SERIAL_READCHAR (e7000_desc
, timeout
);
178 if (c
== SERIAL_TIMEOUT
)
183 error ("Timeout reading from remote system.");
198 static char b
[8][10];
210 sprintf(b
[p
], "<%d>", x
);
217 /* Scan input from the remote system, until STRING is found. If
218 DISCARD is non-zero, then discard non-matching input, else print it
219 out. Let the user break out immediately. */
231 c
= readchar (timeout
);
237 putchar_e7000(CTRLC
);
246 if (c
== SERIAL_ERROR
)
248 error ("Serial communication error");
250 if (echo
|| remote_debug
)
252 if (c
== '\r' || c
== '\n')
265 if (normal (c
) == normal (*p
++))
274 if (normal (c
) == normal (string
[0]))
280 /* Keep discarding input until we see the e7000 prompt.
282 The convention for dealing with the prompt is that you
284 o *then* wait for the prompt.
286 Thus the last thing that a procedure does with the serial line will
287 be an expect_prompt(). Exception: e7000_resume does not wait for
288 the prompt, because the terminal is being handed over to the
289 inferior. However, the next thing which happens after that is a
290 e7000_wait which does wait for the prompt. Note that this includes
291 abnormal exit, e.g. error(). This is necessary to prevent getting
292 into states from which we can't recover. */
301 expect_full_prompt ()
307 convert_hex_digit (ch
)
310 if (ch
>= '0' && ch
<= '9')
312 else if (ch
>= 'A' && ch
<= 'F')
313 return ch
- 'A' + 10;
314 else if (ch
>= 'a' && ch
<= 'f')
315 return ch
- 'a' + 10;
323 int value
= convert_hex_digit (*start
);
326 *start
= readchar (timeout
);
327 while ((try = convert_hex_digit (*start
)) >= 0)
331 *start
= readchar (timeout
);
337 /* Get N 32-bit words from remote, each preceded by a space, and put
338 them in registers starting at REGNO. */
341 get_hex_regs (n
, regno
)
348 for (i
= 0; i
< n
; i
++)
353 for (j
= 0; j
< 8; j
++)
354 val
= (val
<< 4) + get_hex_digit (j
== 0);
355 supply_register (regno
++, (char *) &val
);
360 /* This is called not only when we first attach, but also when the
361 user types "run" after having attached. */
364 e7000_create_inferior (execfile
, args
, env
)
372 error ("Can't pass arguments to remote E7000DEBUG process");
374 if (execfile
== 0 || exec_bfd
== 0)
375 error ("No exec file specified");
377 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
379 #ifdef CREATE_INFERIOR_HOOK
380 CREATE_INFERIOR_HOOK (0); /* No process-ID */
383 /* The "process" (board) is already stopped awaiting our commands, and
384 the program is already downloaded. We just set its PC and go. */
386 clear_proceed_status ();
388 /* Tell wait_for_inferior that we've started a new process. */
389 init_wait_for_inferior ();
391 /* Set up the "saved terminal modes" of the inferior
392 based on what modes we are starting it with. */
393 target_terminal_init ();
395 /* Install inferior's terminal modes. */
396 target_terminal_inferior ();
398 /* insert_step_breakpoint (); FIXME, do we need this? */
399 proceed ((CORE_ADDR
) entry_pt
, -1, 0); /* Let 'er rip... */
402 /* Open a connection to a remote debugger. NAME is the filename used
403 for communication. */
405 static int baudrate
= 9600;
406 static char dev_name
[100];
408 static char *machine
= "";
409 static char *user
= "";
410 static char *passwd
= "";
411 static char *dir
= "";
413 /* Grab the next token and buy some space for it */
424 while (*p
&& *p
== ' ')
427 while (*p
&& (*p
!= ' ' && *p
!= '\t'))
440 e7000_login_command (args
, from_tty
)
446 machine
= next (&args
);
448 passwd
= next (&args
);
452 printf ("Set info to %s %s %s %s\n", machine
, user
, passwd
, dir
);
457 error ("Syntax is ftplogin <machine> <user> <passwd> <directory>");
461 /* Start an ftp transfer from the E7000 to a host */
464 e7000_ftp_command (args
, from_tty
)
468 /* FIXME: arbitrary limit on machine names and such. */
471 int oldtimeout
= timeout
;
474 sprintf (buf
, "ftp %s\r", machine
);
475 puts_e7000debug (buf
);
476 expect (" Username : ");
477 sprintf (buf
, "%s\r", user
);
478 puts_e7000debug (buf
);
479 expect (" Password : ");
480 write_e7000 (passwd
);
482 expect ("success\r");
484 sprintf (buf
, "cd %s\r", dir
);
485 puts_e7000debug (buf
);
487 sprintf (buf
, "ll 0;s:%s\r", args
);
488 puts_e7000debug (buf
);
490 puts_e7000debug ("bye\r");
492 timeout
= oldtimeout
;
496 e7000_parse_device(args
,dev_name
,serial_flag
,baudrate
)
504 if (args
&& strcasecmp (args
, "pc") == 0)
506 strcpy (dev_name
, args
);
511 /* FIXME! temp hack to allow use with port master -
512 target tcp_remote <device> */
513 if (args
&& strncmp (args
, "tcp_remote", 10) == 0)
516 n
= sscanf (args
, " %s %s %d %s", com_type
, dev_name
, &baudrate
, junk
);
522 n
= sscanf (args
, " %s %d %s", dev_name
, &baudrate
, junk
);
525 if (n
!= 1 && n
!= 2)
527 error ("Bad arguments. Usage:\ttarget e7000 <device> <speed>\n\
528 or \t\ttarget e7000 <host>[:<port>]\n\
529 or \t\ttarget e7000 tcp_remote <host>[:<port>]\n\
530 or \t\ttarget e7000 pc\n");
533 #if !defined(__GO32__) && !defined(__WIN32__)
534 /* FIXME! test for ':' is ambiguous */
535 if (n
== 1 && strchr (dev_name
, ':') == 0)
537 /* Default to normal telnet port */
538 /* serial_open will use this to determine tcp communication */
539 strcat (dev_name
, ":23");
542 if (!using_tcp_remote
&& strchr (dev_name
, ':'))
550 e7000_open (args
, from_tty
)
559 target_preopen (from_tty
);
561 n
= e7000_parse_device(args
,dev_name
,serial_flag
,baudrate
);
563 push_target (&e7000_ops
);
565 e7000_desc
= SERIAL_OPEN (dev_name
);
568 perror_with_name (dev_name
);
570 SERIAL_SETBAUDRATE (e7000_desc
, baudrate
);
571 SERIAL_RAW (e7000_desc
);
573 /* Hello? Are you there? */
576 putchar_e7000 (CTRLC
);
582 printf_unfiltered ("[waiting for e7000...]\n");
585 c
= SERIAL_READCHAR (e7000_desc
, 1);
586 while (c
!= SERIAL_TIMEOUT
)
589 if (from_tty
&& c
!= '\r')
599 putchar_e7000 (CTRLC
);
608 putchar_e7000 (CTRLC
);
611 c
= SERIAL_READCHAR (e7000_desc
, 1);
614 puts_e7000debug ("\r");
618 puts_e7000debug ("b -\r");
623 printf_filtered ("Remote target %s connected to %s\n", target_shortname
,
626 #ifdef GDB_TARGET_IS_H8300
631 /* Close out all files and local state before this target loses control. */
634 e7000_close (quitting
)
639 SERIAL_CLOSE (e7000_desc
);
644 /* Terminate the open connection to the remote debugger. Use this
645 when you want to detach and do something else with your gdb. */
648 e7000_detach (from_tty
)
651 pop_target (); /* calls e7000_close to do the real work */
653 printf ("Ending remote %s debugging\n", target_shortname
);
656 /* Tell the remote machine to resume. */
659 e7000_resume (pid
, step
, sig
)
663 puts_e7000debug ("S\r");
665 puts_e7000debug ("G\r");
668 /* Read the remote registers into the block REGS.
670 For the H8/300 a register dump looks like:
672 PC=00021A CCR=80:I*******
673 ER0 - ER3 0000000A 0000002E 0000002E 00000000
674 ER4 - ER7 00000000 00000000 00000000 00FFEFF6
680 #ifdef GDB_TARGET_IS_H8300
682 char *want
= "PC=%p CCR=%c\n\
683 ER0 - ER3 %0 %1 %2 %3\n\
684 ER4 - ER7 %4 %5 %6 %7\n";
686 char *want_nopc
= "%p CCR=%c\n\
687 ER0 - ER3 %0 %1 %2 %3\n\
688 ER4 - ER7 %4 %5 %6 %7";
692 #ifdef GDB_TARGET_IS_SH
694 char *want
= "PC=%16 SR=%22\n\
695 PR=%17 GBR=%18 VBR=%19\n\
697 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
698 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n";
700 char *want_nopc
= "%16 SR=%22\n\
701 PR=%17 GBR=%18 VBR=%19\n\
703 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
704 R8-15 %8 %9 %10 %11 %12 %13 %14 %15";
706 char *want_sh3
= "PC=%16 SR=%22\n\
707 PR=%17 GBR=%18 VBR=%19\n\
708 MACH=%20 MACL=%21 SSR=%23 SPC=%24\n\
709 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
710 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
711 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
712 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
713 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
714 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
716 char *want_sh3_nopc
= "%16 SR=%22\n\
717 PR=%17 GBR=%18 VBR=%19\n\
718 MACH=%20 MACL=%21 SSR=%22 SPC=%23\n\
719 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
720 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
721 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
722 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
723 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
724 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
731 int c
= readchar (timeout
);
746 int high
= convert_hex_digit (gch ());
747 int low
= convert_hex_digit (gch ());
749 return (high
<< 4) + low
;
753 fetch_regs_from_dump (nextchar
, want
)
758 char buf
[MAX_REGISTER_RAW_SIZE
];
760 int thischar
= nextchar ();
767 /* Skip to end of line and then eat all new line type stuff */
768 while (thischar
!= '\n' && thischar
!= '\r')
769 thischar
= nextchar ();
770 while (thischar
== '\n' || thischar
== '\r')
771 thischar
= nextchar ();
776 while (thischar
== ' '
780 thischar
= nextchar ();
785 if (*want
== thischar
)
789 thischar
= nextchar ();
792 else if (thischar
== ' ' || thischar
== '\n' || thischar
== '\r')
794 thischar
= nextchar ();
797 error ("out of sync in fetch registers wanted <%s>, got <%c 0x%x>",
798 want
, thischar
, thischar
);
803 /* Got a register command */
833 if (isdigit (want
[0]))
835 if (isdigit (want
[1]))
837 regno
= (want
[0] - '0') * 10 + want
[1] - '0';
842 regno
= want
[0] - '0';
850 store_signed_integer (buf
,
851 REGISTER_RAW_SIZE(regno
),
852 (LONGEST
) get_hex (&thischar
, nextchar
));
853 supply_register (regno
, buf
);
860 e7000_fetch_registers ()
864 puts_e7000debug ("R\r");
866 #ifdef GDB_TARGET_IS_SH
867 if ((sh_processor_type
!= NULL
) && (*(sh_processor_type
+2) == '3'))
868 fetch_regs_from_dump (gch
, want_sh3
);
870 fetch_regs_from_dump (gch
, want
);
872 fetch_regs_from_dump (gch
, want
);
876 /* And supply the extra ones the simulator uses */
877 for (regno
= NUM_REALREGS
; regno
< NUM_REGS
; regno
++)
881 supply_register (regno
, (char *) (&buf
));
885 /* Fetch register REGNO, or all registers if REGNO is -1. Returns
889 e7000_fetch_register (regno
)
892 e7000_fetch_registers ();
895 /* Store the remote registers from the contents of the block REGS. */
898 e7000_store_registers ()
902 for (regno
= 0; regno
< NUM_REALREGS
; regno
++)
903 e7000_store_register (regno
);
905 registers_changed ();
908 /* Store register REGNO, or all if REGNO == 0. Return errno value. */
911 e7000_store_register (regno
)
918 e7000_store_registers ();
922 #ifdef GDB_TARGET_IS_H8300
925 sprintf (buf
, ".ER%d %x\r", regno
, read_register (regno
));
926 puts_e7000debug (buf
);
928 else if (regno
== PC_REGNUM
)
930 sprintf (buf
, ".PC %x\r", read_register (regno
));
931 puts_e7000debug (buf
);
933 else if (regno
== CCR_REGNUM
)
935 sprintf (buf
, ".CCR %x\r", read_register (regno
));
936 puts_e7000debug (buf
);
938 #endif /* GDB_TARGET_IS_H8300 */
940 #ifdef GDB_TARGET_IS_SH
944 sprintf (buf
, ".R%d %x\r", regno
, read_register (regno
));
945 puts_e7000debug (buf
);
949 sprintf (buf
, ".PC %x\r", read_register (regno
));
950 puts_e7000debug (buf
);
954 sprintf (buf
, ".SR %x\r", read_register (regno
));
955 puts_e7000debug (buf
);
959 sprintf (buf
, ".PR %x\r", read_register (regno
));
960 puts_e7000debug (buf
);
964 sprintf (buf
, ".GBR %x\r", read_register (regno
));
965 puts_e7000debug (buf
);
969 sprintf (buf
, ".VBR %x\r", read_register (regno
));
970 puts_e7000debug (buf
);
974 sprintf (buf
, ".MACH %x\r", read_register (regno
));
975 puts_e7000debug (buf
);
979 sprintf (buf
, ".MACL %x\r", read_register (regno
));
980 puts_e7000debug (buf
);
984 #endif /* GDB_TARGET_IS_SH */
989 /* Get ready to modify the registers array. On machines which store
990 individual registers, this doesn't need to do anything. On machines
991 which store all the registers in one fell swoop, this makes sure
992 that registers contains all the registers from the program being
996 e7000_prepare_to_store ()
998 /* Do nothing, since we can store individual regs */
1004 printf ("\tAttached to %s at %d baud.\n", dev_name
, baudrate
);
1008 stickbyte (where
, what
)
1012 static CONST
char digs
[] = "0123456789ABCDEF";
1014 where
[0] = digs
[(what
>> 4) & 0xf];
1015 where
[1] = digs
[(what
& 0xf) & 0xf];
1020 /* Write a small ammount of memory. */
1023 write_small (memaddr
, myaddr
, len
)
1025 unsigned char *myaddr
;
1031 for (i
= 0; i
< len
; i
++)
1033 if (((memaddr
+ i
) & 3) == 0 && (i
+ 3 < len
))
1035 /* Can be done with a long word */
1036 sprintf (buf
, "m %x %x%02x%02x%02x;l\r",
1038 myaddr
[i
], myaddr
[i
+ 1], myaddr
[i
+ 2], myaddr
[i
+ 3]);
1039 puts_e7000debug (buf
);
1044 sprintf (buf
, "m %x %x\r", memaddr
+ i
, myaddr
[i
]);
1045 puts_e7000debug (buf
);
1054 /* Write a large ammount of memory, this only works with the serial
1055 mode enabled. Command is sent as
1070 write_large (memaddr
, myaddr
, len
)
1072 unsigned char *myaddr
;
1076 #define maxstride 128
1079 puts_e7000debug ("IL ;S:FK\r");
1081 putchar_e7000 (ACK
);
1084 for (i
= 0; i
< len
; i
+= stride
)
1086 char compose
[maxstride
* 2 + 50];
1087 int address
= i
+ memaddr
;
1094 if (stride
> maxstride
)
1097 compose
[where
++] = 'S';
1099 if (address
>= 0xffffff)
1101 else if (address
>= 0xffff)
1106 compose
[where
++] = alen
- 1 + '0';
1107 /* Insert length. */
1108 check_sum
+= stickbyte (compose
+ where
, alen
+ stride
+ 1);
1113 check_sum
+= stickbyte (compose
+ where
, address
>> (8 * (alen
)));
1117 for (j
= 0; j
< stride
; j
++)
1119 check_sum
+= stickbyte (compose
+ where
, myaddr
[i
+ j
]);
1122 stickbyte (compose
+ where
, ~check_sum
);
1124 compose
[where
++] = '\r';
1125 compose
[where
++] = '\n';
1126 compose
[where
++] = 0;
1128 SERIAL_WRITE (e7000_desc
, compose
, where
);
1129 j
= SERIAL_READCHAR (e7000_desc
, 0);
1130 if (j
== SERIAL_TIMEOUT
)
1132 /* This is ok - nothing there */
1136 /* Hmm, it's trying to tell us something */
1138 error ("Error writing memory");
1142 printf ("@%d}@", j
);
1143 while ((j
= SERIAL_READCHAR(e7000_desc
,0)) > 0)
1145 printf ("@{%d}@",j
);
1150 /* Send the trailer record */
1151 write_e7000 ("S70500000000FA\r");
1152 putchar_e7000 (CTRLZ
);
1154 putchar_e7000 (ACK
);
1160 /* Copy LEN bytes of data from debugger memory at MYADDR to inferior's
1161 memory at MEMADDR. Returns length moved.
1163 Can't use the Srecord load over ethernet, so don't use fast method
1167 e7000_write_inferior_memory (memaddr
, myaddr
, len
)
1169 unsigned char *myaddr
;
1172 if (len
< 16 || using_tcp
|| using_pc
)
1173 return write_small (memaddr
, myaddr
, len
);
1175 return write_large (memaddr
, myaddr
, len
);
1178 /* Read LEN bytes from inferior memory at MEMADDR. Put the result
1179 at debugger address MYADDR. Returns length moved.
1181 Small transactions we send
1188 e7000_read_inferior_memory (memaddr
, myaddr
, len
)
1190 unsigned char *myaddr
;
1197 /* Starting address of this pass. */
1199 /* printf("READ INF %x %x %d\n", memaddr, myaddr, len);*/
1200 if (((memaddr
- 1) + len
) < memaddr
)
1206 sprintf (buf
, "m %x;l\r", memaddr
);
1207 puts_e7000debug (buf
);
1209 for (count
= 0; count
< len
; count
+= 4)
1211 /* Suck away the address */
1217 { /* Some kind of error */
1224 /* Now read in the data */
1225 for (i
= 0; i
< 4; i
++)
1228 if (count
+ i
< len
) {
1229 myaddr
[count
+ i
] = b
;
1233 /* Skip the trailing ? and send a . to end and a cr for more */
1236 if (count
+ 4 >= len
)
1237 puts_e7000debug(".\r");
1239 puts_e7000debug("\r");
1249 For large transfers we used to send
1252 d <addr> <endaddr>\r
1255 <ADDRESS> < D A T A > < ASCII CODE >
1256 00000000 5F FD FD FF DF 7F DF FF 01 00 01 00 02 00 08 04 "_..............."
1257 00000010 FF D7 FF 7F D7 F1 7F FF 00 05 00 00 08 00 40 00 "..............@."
1258 00000020 7F FD FF F7 7F FF FF F7 00 00 00 00 00 00 00 00 "................"
1260 A cost in chars for each transaction of 80 + 5*n-bytes.
1262 Large transactions could be done with the srecord load code, but
1263 there is a pause for a second before dumping starts, which slows the
1268 e7000_read_inferior_memory_large (memaddr
, myaddr
, len
)
1270 unsigned char *myaddr
;
1277 /* Starting address of this pass. */
1279 if (((memaddr
- 1) + len
) < memaddr
)
1285 sprintf (buf
, "d %x %x\r", memaddr
, memaddr
+ len
- 1);
1286 puts_e7000debug (buf
);
1291 /* skip down to the first ">" */
1294 /* now skip to the end of that line */
1301 /* get rid of any white space before the address */
1305 /* Skip the address */
1308 /* read in the bytes on the line */
1309 while (c
!= '"' && count
< len
)
1315 myaddr
[count
++] = get_hex (&c
);
1318 /* throw out the rest of the line */
1323 /* wait for the ":" prompt */
1333 fast_but_for_the_pause_e7000_read_inferior_memory (memaddr
, myaddr
, len
)
1342 if (((memaddr
- 1) + len
) < memaddr
)
1348 sprintf (buf
, "is %x@%x:s\r", memaddr
, len
);
1349 puts_e7000debug (buf
);
1355 error ("Memory read error");
1357 putchar_e7000 (ACK
);
1370 case ENQ
: /* ENQ, at the end */
1374 /* Start of an Srecord */
1379 case '7': /* Termination record, ignore */
1383 /* Header record - ignore it */
1395 alen
= type
- '0' + 1;
1399 addr
= (addr
<< 8) + gbyte ();
1403 for (i
= 0; i
< length
- 1; i
++)
1404 myaddr
[i
+ addr
- memaddr
] = gbyte ();
1406 gbyte (); /* Ignore checksum */
1412 putchar_e7000 (ACK
);
1413 expect ("TOP ADDRESS =");
1414 expect ("END ADDRESS =");
1423 e7000_xfer_inferior_memory (memaddr
, myaddr
, len
, write
, target
)
1425 unsigned char *myaddr
;
1428 struct target_ops
*target
; /* ignored */
1431 return e7000_write_inferior_memory( memaddr
, myaddr
, len
);
1434 return e7000_read_inferior_memory( memaddr
, myaddr
, len
);
1436 return e7000_read_inferior_memory_large( memaddr
, myaddr
, len
);
1440 e7000_kill (args
, from_tty
)
1447 e7000_load (args
, from_tty
)
1451 struct cleanup
*old_chain
;
1456 #define WRITESIZE 0x1000
1457 char buf
[2 + 4 + 4 + WRITESIZE
]; /* `DT' + <addr> + <len> + <data> */
1461 time_t start_time
, end_time
; /* Start and end times of download */
1462 unsigned long data_count
; /* Number of bytes transferred to memory */
1465 /* FIXME! change test to test for type of download */
1468 generic_load (args
, from_tty
);
1472 /* for direct tcp connections, we can do a fast binary download */
1479 while (*args
!= '\000')
1483 while (isspace (*args
)) args
++;
1487 while ((*args
!= '\000') && !isspace (*args
)) args
++;
1489 if (*args
!= '\000')
1494 else if (strncmp (arg
, "-quiet", strlen (arg
)) == 0)
1496 else if (strncmp (arg
, "-nostart", strlen (arg
)) == 0)
1499 error ("unknown option `%s'", arg
);
1503 filename
= get_exec_file (1);
1505 pbfd
= bfd_openr (filename
, gnutarget
);
1508 perror_with_name (filename
);
1511 old_chain
= make_cleanup (bfd_close
, pbfd
);
1513 if (!bfd_check_format (pbfd
, bfd_object
))
1514 error ("\"%s\" is not an object file: %s", filename
,
1515 bfd_errmsg (bfd_get_error ()));
1517 start_time
= time (NULL
);
1520 puts_e7000debug ("mw\r");
1524 for (section
= pbfd
->sections
; section
; section
= section
->next
)
1526 if (bfd_get_section_flags (pbfd
, section
) & SEC_LOAD
)
1528 bfd_vma section_address
;
1529 bfd_size_type section_size
;
1532 section_address
= bfd_get_section_vma (pbfd
, section
);
1533 section_size
= bfd_get_section_size_before_reloc (section
);
1536 printf_filtered ("[Loading section %s at 0x%x (%d bytes)]\n",
1537 bfd_get_section_name (pbfd
, section
),
1543 data_count
+= section_size
;
1545 while (section_size
> 0)
1548 static char inds
[] = "|/-\\";
1553 count
= min (section_size
, WRITESIZE
);
1555 buf
[2] = section_address
>> 24;
1556 buf
[3] = section_address
>> 16;
1557 buf
[4] = section_address
>> 8;
1558 buf
[5] = section_address
;
1560 buf
[6] = count
>> 24;
1561 buf
[7] = count
>> 16;
1562 buf
[8] = count
>> 8;
1565 bfd_get_section_contents (pbfd
, section
, buf
+ 10, fptr
, count
);
1567 if (SERIAL_WRITE (e7000_desc
, buf
, count
+ 10))
1568 fprintf_unfiltered (gdb_stderr
,
1569 "e7000_load: SERIAL_WRITE failed: %s\n",
1570 safe_strerror(errno
));
1576 printf_unfiltered ("\r%c", inds
[k
++ % 4]);
1577 gdb_flush (gdb_stdout
);
1580 section_address
+= count
;
1582 section_size
-= count
;
1591 end_time
= time (NULL
);
1593 /* Finally, make the PC point at the start address */
1596 write_pc (bfd_get_start_address (exec_bfd
));
1598 inferior_pid
= 0; /* No process now */
1600 /* This is necessary because many things were based on the PC at the time that
1601 we attached to the monitor, which is no longer valid now that we have loaded
1602 new code (and just changed the PC). Another way to do this might be to call
1603 normal_stop, except that the stack may not be valid, and things would get
1604 horribly confused... */
1606 clear_symtab_users ();
1610 entry
= bfd_get_start_address (pbfd
);
1613 printf_unfiltered ("[Starting %s at 0x%x]\n", filename
, entry
);
1615 /* start_routine (entry);*/
1618 report_transfer_performance (data_count
, start_time
, end_time
);
1620 do_cleanups (old_chain
);
1623 /* Clean up when a program exits.
1625 The program actually lives on in the remote processor's RAM, and may be
1626 run again without a download. Don't leave it full of breakpoint
1630 e7000_mourn_inferior ()
1632 remove_breakpoints ();
1633 unpush_target (&e7000_ops
);
1634 generic_mourn_inferior (); /* Do all the proper things now */
1637 #ifdef HARD_BREAKPOINTS
1638 #define MAX_E7000DEBUG_BREAKPOINTS (BC_BREAKPOINTS ? 5 : 200)
1640 #define MAX_E7000DEBUG_BREAKPOINTS 200
1643 extern int memory_breakpoint_size
;
1645 static CORE_ADDR breakaddr
[MAX_E7000DEBUG_BREAKPOINTS
] = {0};
1648 e7000_insert_breakpoint (addr
, shadow
)
1650 unsigned char *shadow
;
1654 static char nop
[2] = NOP
;
1656 for (i
= 0; i
<= MAX_E7000DEBUG_BREAKPOINTS
; i
++)
1657 if (breakaddr
[i
] == 0)
1659 breakaddr
[i
] = addr
;
1660 /* Save old contents, and insert a nop in the space */
1661 #ifdef HARD_BREAKPOINTS
1664 sprintf (buf
, "BC%d A=%x\r", i
+1, addr
);
1665 puts_e7000debug (buf
);
1669 sprintf (buf
, "B %x\r", addr
);
1670 puts_e7000debug (buf
);
1674 e7000_read_inferior_memory (addr
, shadow
, 2);
1675 e7000_write_inferior_memory (addr
, nop
, 2);
1678 sprintf (buf
, "B %x\r", addr
);
1679 puts_e7000debug (buf
);
1685 error ("Too many breakpoints ( > %d) for the E7000\n",
1686 MAX_E7000DEBUG_BREAKPOINTS
);
1691 e7000_remove_breakpoint (addr
, shadow
)
1693 unsigned char *shadow
;
1698 for (i
= 0; i
< MAX_E7000DEBUG_BREAKPOINTS
; i
++)
1699 if (breakaddr
[i
] == addr
)
1702 #ifdef HARD_BREAKPOINTS
1705 sprintf (buf
, "BC%d - \r", i
+1);
1706 puts_e7000debug (buf
);
1710 sprintf (buf
, "B - %x\r", addr
);
1711 puts_e7000debug (buf
);
1715 sprintf (buf
, "B - %x\r", addr
);
1716 puts_e7000debug (buf
);
1720 /* Replace the insn under the break */
1721 e7000_write_inferior_memory (addr
, shadow
, 2);
1728 warning ("Can't find breakpoint associated with 0x%x\n", addr
);
1732 /* Put a command string, in args, out to STDBUG. Output from STDBUG
1733 is placed on the users terminal until the prompt is seen. */
1736 e7000_command (args
, fromtty
)
1740 /* FIXME: arbitrary limit on length of args. */
1746 error ("e7000 target not open.");
1749 puts_e7000debug ("\r");
1753 sprintf (buf
, "%s\r", args
);
1754 puts_e7000debug (buf
);
1759 expect_full_prompt ();
1762 printf_unfiltered ("\n");
1764 /* Who knows what the command did... */
1765 registers_changed ();
1770 e7000_drain_command (args
, fromtty
)
1777 puts_e7000debug("end\r");
1778 putchar_e7000 (CTRLC
);
1780 while ((c
= SERIAL_READCHAR (e7000_desc
, 1) != SERIAL_TIMEOUT
))
1784 putchar_e7000(CTRLC
);
1787 if (c
> ' ' && c
< 127)
1788 printf ("%c", c
& 0xff);
1790 printf ("<%x>", c
& 0xff);
1799 static char *strings
[NITEMS
] = {
1805 "ILLEGAL INSTRUCTION",
1812 for (i
= 0; i
< NITEMS
; ++i
)
1818 for (i
= 0; i
< NITEMS
; i
++)
1825 /* found one of the choices */
1837 /* Suck characters, if a string match, then return the strings index
1838 otherwise echo them. */
1848 char *buffer
= saveaway
;
1849 /* Count number of expect strings */
1851 for (n
= 0; strings
[n
]; n
++)
1853 ptr
[n
] = strings
[n
];
1861 c
= SERIAL_READCHAR (e7000_desc
, 1);
1862 if (c
== SERIAL_TIMEOUT
)
1864 printf_unfiltered ("[waiting for e7000...]\n");
1877 putchar_e7000 (CTRLC
); /* interrupt the running program */
1881 for (i
= 0; i
< n
; i
++)
1888 /* Gone all the way */
1895 ptr
[i
] = strings
[i
];
1901 /* Save it up incase we find that there was no match */
1906 if (buffer
!= saveaway
)
1909 printf ("%s", buffer
);
1912 if (c
!= SERIAL_TIMEOUT
)
1921 /* We subtract two from the pc here rather than use
1922 DECR_PC_AFTER_BREAK since the e7000 doesn't always add two to the
1923 pc, and the simulators never do. */
1931 store_signed_integer (buf
,
1932 REGISTER_RAW_SIZE(PC_REGNUM
),
1933 read_register (PC_REGNUM
) -2);
1934 supply_register (PC_REGNUM
, buf
);
1935 sprintf (buf2
, ".PC %x\r", read_register (PC_REGNUM
));
1936 puts_e7000debug (buf2
);
1941 #define WAS_RUNNING 2
1944 static char *estrings
[] = {
1952 /* Wait until the remote machine stops, then return, storing status in
1953 STATUS just as `wait' would. */
1956 e7000_wait (pid
, status
)
1958 struct target_waitstatus
*status
;
1962 int running_count
= 0;
1966 /* Then echo chars until PC= string seen */
1967 gch (); /* Drop cr */
1968 gch (); /* and space */
1972 switch (expect_n (estrings
))
1975 /* how did this happen ? */
1980 putchar_e7000 (CTRLC
);
1988 if (running_count
== 20)
1990 printf_unfiltered ("[running...]\n");
2000 /* Skip till the PC= */
2003 #ifdef GDB_TARGET_IS_SH
2004 if ((sh_processor_type
!= NULL
) && (*(sh_processor_type
+2) == '3'))
2005 fetch_regs_from_dump (gch
, want_sh3_nopc
);
2007 fetch_regs_from_dump (gch
, want_nopc
);
2009 fetch_regs_from_dump (gch
, want_nopc
);
2012 /* And supply the extra ones the simulator uses */
2013 for (regno
= NUM_REALREGS
; regno
< NUM_REGS
; regno
++)
2016 supply_register (regno
, (char *) &buf
);
2019 stop_reason
= why_stop ();
2020 expect_full_prompt ();
2022 status
->kind
= TARGET_WAITKIND_STOPPED
;
2023 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2025 switch (stop_reason
)
2027 case 1: /* Breakpoint */
2028 write_pc (read_pc ()); /* PC is always off by 2 for breakpoints */
2029 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2031 case 0: /* Single step */
2032 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2034 case 2: /* Interrupt */
2037 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2042 status
->value
.sig
= TARGET_SIGNAL_INT
;
2048 printf_unfiltered ("a cycle address error?\n");
2049 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2052 status
->value
.sig
= TARGET_SIGNAL_ILL
;
2055 status
->value
.sig
= TARGET_SIGNAL_SEGV
;
2057 case 7: /* Anything else (NITEMS + 1) */
2058 printf_unfiltered ("a write protect error?\n");
2059 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2062 /* Get the user's attention - this should never happen. */
2069 /* Define the target subroutine names. */
2071 struct target_ops e7000_ops
=
2074 "Remote Hitachi e7000 target",
2075 "Use a remote Hitachi e7000 ICE connected by a serial line,\n\
2076 or a network connection.\n\
2077 Arguments are the name of the device for the serial line,\n\
2078 the speed to connect at in bits per second.\n\
2080 target e7000 /dev/ttya 9600\n\
2081 target e7000 foobar",
2082 e7000_open
, /* to_open */
2083 e7000_close
, /* to_close */
2085 e7000_detach
, /* to_detach */
2086 e7000_resume
, /* to_resume */
2087 e7000_wait
, /* to_wait */
2088 e7000_fetch_register
, /* to_fetch_registers */
2089 e7000_store_register
, /* to_store_registers */
2090 e7000_prepare_to_store
, /* to_prepare_to_store */
2091 e7000_xfer_inferior_memory
, /* to_xfer_memory */
2092 e7000_files_info
, /* to_files_info */
2093 e7000_insert_breakpoint
, /* to_insert_breakpoint */
2094 e7000_remove_breakpoint
, /* to_remove_breakpoint */
2095 0, /* to_terminal_init */
2096 0, /* to_terminal_inferior */
2097 0, /* to_terminal_ours_for_output */
2098 0, /* to_terminal_ours */
2099 0, /* to_terminal_info */
2100 e7000_kill
, /* to_kill */
2101 e7000_load
, /* to_load */
2102 0, /* to_lookup_symbol */
2103 e7000_create_inferior
, /* to_create_inferior */
2104 e7000_mourn_inferior
, /* to_mourn_inferior */
2106 0, /* to_notice_signals */
2107 0, /* to_thread_alive */
2109 process_stratum
, /* to_stratum */
2110 0, /* next (unused) */
2111 1, /* to_has_all_memory */
2112 1, /* to_has_memory */
2113 1, /* to_has_stack */
2114 1, /* to_has_registers */
2115 1, /* to_has_execution */
2116 0, /* to_sections */
2117 0, /* to_sections_end */
2118 OPS_MAGIC
, /* Always the last thing */
2122 _initialize_remote_e7000 ()
2124 add_target (&e7000_ops
);
2126 add_com ("e7000 <command>", class_obscure
, e7000_command
,
2127 "Send a command to the e7000 monitor.");
2129 add_com ("ftplogin <machine> <name> <passwd> <dir>", class_obscure
, e7000_login_command
,
2130 "Login to machine and change to directory.");
2132 add_com ("ftpload <file>", class_obscure
, e7000_ftp_command
,
2133 "Fetch and load a file from previously described place.");
2135 add_com ("drain", class_obscure
, e7000_drain_command
,
2136 "Drain pending e7000 text buffers.");