1 /* Remote debugging interface for Hitachi E7000 ICE, for GDB
2 Copyright 1993, 1994, 1996, 1997, 1998 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 Written by Steve Chamberlain for Cygnus Support.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
24 /* The E7000 is an in-circuit emulator for the Hitachi H8/300-H and
25 Hitachi-SH processor. It has serial port and a lan port.
27 The monitor command set makes it difficult to load large ammounts of
28 data over the lan without using ftp - so try not to issue load
29 commands when communicating over ethernet; use the ftpload command.
31 The monitor pauses for a second when dumping srecords to the serial
32 line too, so we use a slower per byte mechanism but without the
33 startup overhead. Even so, it's pretty slow... */
44 #include "gdb_string.h"
46 #include <sys/types.h>
48 #include "remote-utils.h"
55 #define HARD_BREAKPOINTS /* Now handled by set option. */
56 #define BC_BREAKPOINTS use_hard_breakpoints
64 extern void notice_quit (void);
66 extern void report_transfer_performance (unsigned long, time_t, time_t);
68 extern char *sh_processor_type
;
70 /* Local function declarations. */
72 static void e7000_close (int);
74 static void e7000_fetch_register (int);
76 static void e7000_store_register (int);
78 static void e7000_command (char *, int);
80 static void e7000_login_command (char *, int);
82 static void e7000_ftp_command (char *, int);
84 static void e7000_drain_command (char *, int);
86 static void expect (char *);
88 static void expect_full_prompt (void);
90 static void expect_prompt (void);
92 static int e7000_parse_device (char *args
, char *dev_name
, int baudrate
);
95 static serial_t e7000_desc
;
97 /* Allow user to chose between using hardware breakpoints or memory. */
98 static int use_hard_breakpoints
= 0; /* use sw breakpoints by default */
100 /* Nonzero if using the tcp serial driver. */
102 static int using_tcp
; /* direct tcp connection to target */
103 static int using_tcp_remote
; /* indirect connection to target
104 via tcp to controller */
106 /* Nonzero if using the pc isa card. */
110 extern struct target_ops e7000_ops
; /* Forward declaration */
112 char *ENQSTRING
= "\005";
114 /* Nonzero if some routine (as opposed to the user) wants echoing.
115 FIXME: Do this reentrantly with an extra parameter. */
121 static int timeout
= 20;
123 /* Send data to e7000debug. */
126 puts_e7000debug (buf
)
130 error ("Use \"target e7000 ...\" first.");
133 printf_unfiltered ("Sending %s\n", buf
);
135 if (SERIAL_WRITE (e7000_desc
, buf
, strlen (buf
)))
136 fprintf_unfiltered (gdb_stderr
, "SERIAL_WRITE failed: %s\n", safe_strerror (errno
));
138 /* And expect to see it echoed, unless using the pc interface */
152 SERIAL_WRITE (e7000_desc
, b
, 1);
159 SERIAL_WRITE (e7000_desc
, s
, strlen (s
));
171 /* Read a character from the remote system, doing all the fancy timeout
172 stuff. Handles serial errors and EOF. If TIMEOUT == 0, and no chars,
173 returns -1, else returns next char. Discards chars > 127. */
183 c
= SERIAL_READCHAR (e7000_desc
, timeout
);
187 if (c
== SERIAL_TIMEOUT
)
192 error ("Timeout reading from remote system.");
195 error ("Serial communication error");
199 putchar_unfiltered (c
);
200 gdb_flush (gdb_stdout
);
210 static char b
[8][10];
222 sprintf (b
[p
], "<%d>", x
);
229 /* Scan input from the remote system, until STRING is found. If
230 DISCARD is non-zero, then discard non-matching input, else print it
231 out. Let the user break out immediately. */
243 c
= readchar (timeout
);
250 putchar_e7000 (CTRLC
);
262 if (c
== '\r' || c
== '\n')
265 putchar_unfiltered ('\n');
271 putchar_unfiltered (c
);
273 gdb_flush (gdb_stdout
);
275 if (normal (c
) == normal (*p
++))
284 if (normal (c
) == normal (string
[0]))
290 /* Keep discarding input until we see the e7000 prompt.
292 The convention for dealing with the prompt is that you
294 o *then* wait for the prompt.
296 Thus the last thing that a procedure does with the serial line will
297 be an expect_prompt(). Exception: e7000_resume does not wait for
298 the prompt, because the terminal is being handed over to the
299 inferior. However, the next thing which happens after that is a
300 e7000_wait which does wait for the prompt. Note that this includes
301 abnormal exit, e.g. error(). This is necessary to prevent getting
302 into states from which we can't recover. */
311 expect_full_prompt ()
317 convert_hex_digit (ch
)
320 if (ch
>= '0' && ch
<= '9')
322 else if (ch
>= 'A' && ch
<= 'F')
323 return ch
- 'A' + 10;
324 else if (ch
>= 'a' && ch
<= 'f')
325 return ch
- 'a' + 10;
333 int value
= convert_hex_digit (*start
);
336 *start
= readchar (timeout
);
337 while ((try = convert_hex_digit (*start
)) >= 0)
341 *start
= readchar (timeout
);
347 /* Get N 32-bit words from remote, each preceded by a space, and put
348 them in registers starting at REGNO. */
351 get_hex_regs (n
, regno
)
358 for (i
= 0; i
< n
; i
++)
363 for (j
= 0; j
< 8; j
++)
364 val
= (val
<< 4) + get_hex_digit (j
== 0);
365 supply_register (regno
++, (char *) &val
);
370 /* This is called not only when we first attach, but also when the
371 user types "run" after having attached. */
374 e7000_create_inferior (execfile
, args
, env
)
382 error ("Can't pass arguments to remote E7000DEBUG process");
384 if (execfile
== 0 || exec_bfd
== 0)
385 error ("No executable file specified");
387 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
389 #ifdef CREATE_INFERIOR_HOOK
390 CREATE_INFERIOR_HOOK (0); /* No process-ID */
393 /* The "process" (board) is already stopped awaiting our commands, and
394 the program is already downloaded. We just set its PC and go. */
396 clear_proceed_status ();
398 /* Tell wait_for_inferior that we've started a new process. */
399 init_wait_for_inferior ();
401 /* Set up the "saved terminal modes" of the inferior
402 based on what modes we are starting it with. */
403 target_terminal_init ();
405 /* Install inferior's terminal modes. */
406 target_terminal_inferior ();
408 /* insert_step_breakpoint (); FIXME, do we need this? */
409 proceed ((CORE_ADDR
) entry_pt
, -1, 0); /* Let 'er rip... */
412 /* Open a connection to a remote debugger. NAME is the filename used
413 for communication. */
415 static int baudrate
= 9600;
416 static char dev_name
[100];
418 static char *machine
= "";
419 static char *user
= "";
420 static char *passwd
= "";
421 static char *dir
= "";
423 /* Grab the next token and buy some space for it */
434 while (*p
&& *p
== ' ')
437 while (*p
&& (*p
!= ' ' && *p
!= '\t'))
450 e7000_login_command (args
, from_tty
)
456 machine
= next (&args
);
458 passwd
= next (&args
);
462 printf_unfiltered ("Set info to %s %s %s %s\n", machine
, user
, passwd
, dir
);
467 error ("Syntax is ftplogin <machine> <user> <passwd> <directory>");
471 /* Start an ftp transfer from the E7000 to a host */
474 e7000_ftp_command (args
, from_tty
)
478 /* FIXME: arbitrary limit on machine names and such. */
481 int oldtimeout
= timeout
;
482 timeout
= remote_timeout
;
484 sprintf (buf
, "ftp %s\r", machine
);
485 puts_e7000debug (buf
);
486 expect (" Username : ");
487 sprintf (buf
, "%s\r", user
);
488 puts_e7000debug (buf
);
489 expect (" Password : ");
490 write_e7000 (passwd
);
492 expect ("success\r");
494 sprintf (buf
, "cd %s\r", dir
);
495 puts_e7000debug (buf
);
497 sprintf (buf
, "ll 0;s:%s\r", args
);
498 puts_e7000debug (buf
);
500 puts_e7000debug ("bye\r");
502 timeout
= oldtimeout
;
506 e7000_parse_device (args
, dev_name
, 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", 10) == 0)
525 n
= sscanf (args
, " %s %s %d %s", com_type
, dev_name
, &baudrate
, junk
);
526 using_tcp_remote
= 1;
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
, ':'))
558 /* Stub for catch_errors. */
561 e7000_start_remote (dummy
)
569 immediate_quit
= 1; /* Allow user to interrupt it */
571 /* Hello? Are you there? */
576 putchar_e7000 (CTRLC
);
577 while (!sync
&& ++try <= quit_trying
)
581 printf_unfiltered ("[waiting for e7000...]\n");
586 /* FIXME! this didn't seem right-> while (c != SERIAL_TIMEOUT)
587 * we get stuck in this loop ...
588 * We may never timeout, and never sync up :-(
590 while (!sync
&& c
!= -1)
595 putchar_unfiltered (c
);
596 gdb_flush (gdb_stdout
);
598 /* Shouldn't we either break here, or check for sync in inner loop? */
604 putchar_e7000 (CTRLC
);
612 putchar_e7000 (CTRLC
);
613 /* Was-> quit_flag = 0; */
615 quit_trying
= try + 1; /* we don't want to try anymore */
626 fprintf_unfiltered (gdb_stderr
, "Giving up after %d tries...\n", try);
627 error ("Unable to syncronize with target.\n");
630 puts_e7000debug ("\r");
632 puts_e7000debug ("b -\r"); /* Clear breakpoints */
637 /* This is really the job of start_remote however, that makes an assumption
638 that the target is about to print out a status message of some sort. That
639 doesn't happen here. */
641 flush_cached_frames ();
642 registers_changed ();
643 stop_pc
= read_pc ();
644 set_current_frame (create_new_frame (read_fp (), stop_pc
));
645 select_frame (get_current_frame (), 0);
646 print_stack_frame (selected_frame
, -1, 1);
652 e7000_open (args
, from_tty
)
658 target_preopen (from_tty
);
660 n
= e7000_parse_device (args
, dev_name
, baudrate
);
662 push_target (&e7000_ops
);
664 e7000_desc
= SERIAL_OPEN (dev_name
);
667 perror_with_name (dev_name
);
669 SERIAL_SETBAUDRATE (e7000_desc
, baudrate
);
670 SERIAL_RAW (e7000_desc
);
672 #ifdef GDB_TARGET_IS_H8300
676 /* Start the remote connection; if error (0), discard this target.
677 In particular, if the user quits, be sure to discard it
678 (we'd be in an inconsistent state otherwise). */
679 if (!catch_errors (e7000_start_remote
, (char *) 0,
680 "Couldn't establish connection to remote target\n", RETURN_MASK_ALL
))
682 printf_filtered ("Remote target %s connected to %s\n", target_shortname
,
686 /* Close out all files and local state before this target loses control. */
689 e7000_close (quitting
)
694 SERIAL_CLOSE (e7000_desc
);
699 /* Terminate the open connection to the remote debugger. Use this
700 when you want to detach and do something else with your gdb. */
703 e7000_detach (from_tty
)
706 pop_target (); /* calls e7000_close to do the real work */
708 printf_unfiltered ("Ending remote %s debugging\n", target_shortname
);
711 /* Tell the remote machine to resume. */
714 e7000_resume (pid
, step
, sig
)
718 puts_e7000debug ("S\r");
720 puts_e7000debug ("G\r");
723 /* Read the remote registers into the block REGS.
725 For the H8/300 a register dump looks like:
727 PC=00021A CCR=80:I*******
728 ER0 - ER3 0000000A 0000002E 0000002E 00000000
729 ER4 - ER7 00000000 00000000 00000000 00FFEFF6
735 #ifdef GDB_TARGET_IS_H8300
737 char *want_h8300h
= "PC=%p CCR=%c\n\
738 ER0 - ER3 %0 %1 %2 %3\n\
739 ER4 - ER7 %4 %5 %6 %7\n";
741 char *want_nopc_h8300h
= "%p CCR=%c\n\
742 ER0 - ER3 %0 %1 %2 %3\n\
743 ER4 - ER7 %4 %5 %6 %7";
745 char *want_h8300s
= "PC=%p CCR=%c\n\
747 ER0 - ER3 %0 %1 %2 %3\n\
748 ER4 - ER7 %4 %5 %6 %7\n";
750 char *want_nopc_h8300s
= "%p CCR=%c EXR=%9\n\
751 ER0 - ER3 %0 %1 %2 %3\n\
752 ER4 - ER7 %4 %5 %6 %7";
756 #ifdef GDB_TARGET_IS_SH
758 char *want
= "PC=%16 SR=%22\n\
759 PR=%17 GBR=%18 VBR=%19\n\
761 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
762 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n";
764 char *want_nopc
= "%16 SR=%22\n\
765 PR=%17 GBR=%18 VBR=%19\n\
767 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
768 R8-15 %8 %9 %10 %11 %12 %13 %14 %15";
770 char *want_sh3
= "PC=%16 SR=%22\n\
771 PR=%17 GBR=%18 VBR=%19\n\
772 MACH=%20 MACL=%21 SSR=%23 SPC=%24\n\
773 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
774 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
775 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
776 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
777 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
778 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
780 char *want_sh3_nopc
= "%16 SR=%22\n\
781 PR=%17 GBR=%18 VBR=%19\n\
782 MACH=%20 MACL=%21 SSR=%22 SPC=%23\n\
783 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
784 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
785 R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
786 R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
787 R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
788 R4_BANK1-R7_BANK1 %37 %38 %39 %40";
795 return readchar (timeout
);
801 int high
= convert_hex_digit (gch ());
802 int low
= convert_hex_digit (gch ());
804 return (high
<< 4) + low
;
808 fetch_regs_from_dump (nextchar
, want
)
813 char buf
[MAX_REGISTER_RAW_SIZE
];
815 int thischar
= nextchar ();
822 /* Skip to end of line and then eat all new line type stuff */
823 while (thischar
!= '\n' && thischar
!= '\r')
824 thischar
= nextchar ();
825 while (thischar
== '\n' || thischar
== '\r')
826 thischar
= nextchar ();
831 while (thischar
== ' '
835 thischar
= nextchar ();
840 if (*want
== thischar
)
844 thischar
= nextchar ();
847 else if (thischar
== ' ' || thischar
== '\n' || thischar
== '\r')
849 thischar
= nextchar ();
853 error ("out of sync in fetch registers wanted <%s>, got <%c 0x%x>",
854 want
, thischar
, thischar
);
859 /* Got a register command */
889 if (isdigit (want
[0]))
891 if (isdigit (want
[1]))
893 regno
= (want
[0] - '0') * 10 + want
[1] - '0';
898 regno
= want
[0] - '0';
906 store_signed_integer (buf
,
907 REGISTER_RAW_SIZE (regno
),
908 (LONGEST
) get_hex (&thischar
, nextchar
));
909 supply_register (regno
, buf
);
916 e7000_fetch_registers ()
921 puts_e7000debug ("R\r");
923 #ifdef GDB_TARGET_IS_SH
925 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_sh
)
926 switch (TARGET_ARCHITECTURE
->mach
)
935 wanted
= want_h8300s
;
937 wanted
= want_h8300h
;
939 fetch_regs_from_dump (gch
, wanted
);
941 /* And supply the extra ones the simulator uses */
942 for (regno
= NUM_REALREGS
; regno
< NUM_REGS
; regno
++)
946 supply_register (regno
, (char *) (&buf
));
950 /* Fetch register REGNO, or all registers if REGNO is -1. Returns
954 e7000_fetch_register (regno
)
957 e7000_fetch_registers ();
960 /* Store the remote registers from the contents of the block REGS. */
963 e7000_store_registers ()
967 for (regno
= 0; regno
< NUM_REALREGS
; regno
++)
968 e7000_store_register (regno
);
970 registers_changed ();
973 /* Store register REGNO, or all if REGNO == 0. Return errno value. */
976 e7000_store_register (regno
)
983 e7000_store_registers ();
987 #ifdef GDB_TARGET_IS_H8300
990 sprintf (buf
, ".ER%d %x\r", regno
, read_register (regno
));
991 puts_e7000debug (buf
);
993 else if (regno
== PC_REGNUM
)
995 sprintf (buf
, ".PC %x\r", read_register (regno
));
996 puts_e7000debug (buf
);
998 else if (regno
== CCR_REGNUM
)
1000 sprintf (buf
, ".CCR %x\r", read_register (regno
));
1001 puts_e7000debug (buf
);
1003 #endif /* GDB_TARGET_IS_H8300 */
1005 #ifdef GDB_TARGET_IS_SH
1009 sprintf (buf
, ".R%d %x\r", regno
, read_register (regno
));
1010 puts_e7000debug (buf
);
1014 sprintf (buf
, ".PC %x\r", read_register (regno
));
1015 puts_e7000debug (buf
);
1019 sprintf (buf
, ".SR %x\r", read_register (regno
));
1020 puts_e7000debug (buf
);
1024 sprintf (buf
, ".PR %x\r", read_register (regno
));
1025 puts_e7000debug (buf
);
1029 sprintf (buf
, ".GBR %x\r", read_register (regno
));
1030 puts_e7000debug (buf
);
1034 sprintf (buf
, ".VBR %x\r", read_register (regno
));
1035 puts_e7000debug (buf
);
1039 sprintf (buf
, ".MACH %x\r", read_register (regno
));
1040 puts_e7000debug (buf
);
1044 sprintf (buf
, ".MACL %x\r", read_register (regno
));
1045 puts_e7000debug (buf
);
1049 #endif /* GDB_TARGET_IS_SH */
1054 /* Get ready to modify the registers array. On machines which store
1055 individual registers, this doesn't need to do anything. On machines
1056 which store all the registers in one fell swoop, this makes sure
1057 that registers contains all the registers from the program being
1061 e7000_prepare_to_store ()
1063 /* Do nothing, since we can store individual regs */
1069 printf_unfiltered ("\tAttached to %s at %d baud.\n", dev_name
, baudrate
);
1073 stickbyte (where
, what
)
1077 static CONST
char digs
[] = "0123456789ABCDEF";
1079 where
[0] = digs
[(what
>> 4) & 0xf];
1080 where
[1] = digs
[(what
& 0xf) & 0xf];
1085 /* Write a small ammount of memory. */
1088 write_small (memaddr
, myaddr
, len
)
1090 unsigned char *myaddr
;
1096 for (i
= 0; i
< len
; i
++)
1098 if (((memaddr
+ i
) & 3) == 0 && (i
+ 3 < len
))
1100 /* Can be done with a long word */
1101 sprintf (buf
, "m %x %x%02x%02x%02x;l\r",
1103 myaddr
[i
], myaddr
[i
+ 1], myaddr
[i
+ 2], myaddr
[i
+ 3]);
1104 puts_e7000debug (buf
);
1109 sprintf (buf
, "m %x %x\r", memaddr
+ i
, myaddr
[i
]);
1110 puts_e7000debug (buf
);
1119 /* Write a large ammount of memory, this only works with the serial
1120 mode enabled. Command is sent as
1135 write_large (memaddr
, myaddr
, len
)
1137 unsigned char *myaddr
;
1141 #define maxstride 128
1144 puts_e7000debug ("IL ;S:FK\r");
1146 putchar_e7000 (ACK
);
1149 for (i
= 0; i
< len
; i
+= stride
)
1151 char compose
[maxstride
* 2 + 50];
1152 int address
= i
+ memaddr
;
1159 if (stride
> maxstride
)
1162 compose
[where
++] = 'S';
1164 if (address
>= 0xffffff)
1166 else if (address
>= 0xffff)
1171 compose
[where
++] = alen
- 1 + '0';
1172 /* Insert length. */
1173 check_sum
+= stickbyte (compose
+ where
, alen
+ stride
+ 1);
1178 check_sum
+= stickbyte (compose
+ where
, address
>> (8 * (alen
)));
1182 for (j
= 0; j
< stride
; j
++)
1184 check_sum
+= stickbyte (compose
+ where
, myaddr
[i
+ j
]);
1187 stickbyte (compose
+ where
, ~check_sum
);
1189 compose
[where
++] = '\r';
1190 compose
[where
++] = '\n';
1191 compose
[where
++] = 0;
1193 SERIAL_WRITE (e7000_desc
, compose
, where
);
1197 /* This is ok - nothing there */
1201 /* Hmm, it's trying to tell us something */
1203 error ("Error writing memory");
1207 printf_unfiltered ("@%d}@", j
);
1208 while ((j
= readchar (0)) > 0)
1210 printf_unfiltered ("@{%d}@", j
);
1215 /* Send the trailer record */
1216 write_e7000 ("S70500000000FA\r");
1217 putchar_e7000 (CTRLZ
);
1219 putchar_e7000 (ACK
);
1225 /* Copy LEN bytes of data from debugger memory at MYADDR to inferior's
1226 memory at MEMADDR. Returns length moved.
1228 Can't use the Srecord load over ethernet, so don't use fast method
1232 e7000_write_inferior_memory (memaddr
, myaddr
, len
)
1234 unsigned char *myaddr
;
1237 if (len
< 16 || using_tcp
|| using_pc
)
1238 return write_small (memaddr
, myaddr
, len
);
1240 return write_large (memaddr
, myaddr
, len
);
1243 /* Read LEN bytes from inferior memory at MEMADDR. Put the result
1244 at debugger address MYADDR. Returns length moved.
1246 Small transactions we send
1253 e7000_read_inferior_memory (memaddr
, myaddr
, len
)
1255 unsigned char *myaddr
;
1262 /* Starting address of this pass. */
1264 /* printf("READ INF %x %x %d\n", memaddr, myaddr, len); */
1265 if (((memaddr
- 1) + len
) < memaddr
)
1271 sprintf (buf
, "m %x;l\r", memaddr
);
1272 puts_e7000debug (buf
);
1274 for (count
= 0; count
< len
; count
+= 4)
1276 /* Suck away the address */
1282 { /* Some kind of error */
1283 puts_e7000debug (".\r"); /* Some errors leave us in memory input mode */
1284 expect_full_prompt ();
1290 /* Now read in the data */
1291 for (i
= 0; i
< 4; i
++)
1294 if (count
+ i
< len
)
1296 myaddr
[count
+ i
] = b
;
1300 /* Skip the trailing ? and send a . to end and a cr for more */
1303 if (count
+ 4 >= len
)
1304 puts_e7000debug (".\r");
1306 puts_e7000debug ("\r");
1316 For large transfers we used to send
1319 d <addr> <endaddr>\r
1322 <ADDRESS> < D A T A > < ASCII CODE >
1323 00000000 5F FD FD FF DF 7F DF FF 01 00 01 00 02 00 08 04 "_..............."
1324 00000010 FF D7 FF 7F D7 F1 7F FF 00 05 00 00 08 00 40 00 "..............@."
1325 00000020 7F FD FF F7 7F FF FF F7 00 00 00 00 00 00 00 00 "................"
1327 A cost in chars for each transaction of 80 + 5*n-bytes.
1329 Large transactions could be done with the srecord load code, but
1330 there is a pause for a second before dumping starts, which slows the
1335 e7000_read_inferior_memory_large (memaddr
, myaddr
, len
)
1337 unsigned char *myaddr
;
1344 /* Starting address of this pass. */
1346 if (((memaddr
- 1) + len
) < memaddr
)
1352 sprintf (buf
, "d %x %x\r", memaddr
, memaddr
+ len
- 1);
1353 puts_e7000debug (buf
);
1358 /* skip down to the first ">" */
1361 /* now skip to the end of that line */
1368 /* get rid of any white space before the address */
1372 /* Skip the address */
1375 /* read in the bytes on the line */
1376 while (c
!= '"' && count
< len
)
1382 myaddr
[count
++] = get_hex (&c
);
1385 /* throw out the rest of the line */
1390 /* wait for the ":" prompt */
1400 fast_but_for_the_pause_e7000_read_inferior_memory (memaddr
, myaddr
, len
)
1409 if (((memaddr
- 1) + len
) < memaddr
)
1415 sprintf (buf
, "is %x@%x:s\r", memaddr
, len
);
1416 puts_e7000debug (buf
);
1422 error ("Memory read error");
1424 putchar_e7000 (ACK
);
1437 case ENQ
: /* ENQ, at the end */
1441 /* Start of an Srecord */
1446 case '7': /* Termination record, ignore */
1450 /* Header record - ignore it */
1462 alen
= type
- '0' + 1;
1466 addr
= (addr
<< 8) + gbyte ();
1470 for (i
= 0; i
< length
- 1; i
++)
1471 myaddr
[i
+ addr
- memaddr
] = gbyte ();
1473 gbyte (); /* Ignore checksum */
1479 putchar_e7000 (ACK
);
1480 expect ("TOP ADDRESS =");
1481 expect ("END ADDRESS =");
1490 e7000_xfer_inferior_memory (memaddr
, myaddr
, len
, write
, target
)
1492 unsigned char *myaddr
;
1495 struct target_ops
*target
; /* ignored */
1498 return e7000_write_inferior_memory (memaddr
, myaddr
, len
);
1500 return e7000_read_inferior_memory (memaddr
, myaddr
, len
);
1502 return e7000_read_inferior_memory_large (memaddr
, myaddr
, len
);
1506 e7000_kill (args
, from_tty
)
1513 e7000_load (args
, from_tty
)
1517 struct cleanup
*old_chain
;
1521 #define WRITESIZE 0x1000
1522 char buf
[2 + 4 + 4 + WRITESIZE
]; /* `DT' + <addr> + <len> + <data> */
1526 time_t start_time
, end_time
; /* Start and end times of download */
1527 unsigned long data_count
; /* Number of bytes transferred to memory */
1528 int oldtimeout
= timeout
;
1530 timeout
= remote_timeout
;
1533 /* FIXME! change test to test for type of download */
1536 generic_load (args
, from_tty
);
1540 /* for direct tcp connections, we can do a fast binary download */
1547 while (*args
!= '\000')
1551 while (isspace (*args
))
1556 while ((*args
!= '\000') && !isspace (*args
))
1559 if (*args
!= '\000')
1564 else if (strncmp (arg
, "-quiet", strlen (arg
)) == 0)
1566 else if (strncmp (arg
, "-nostart", strlen (arg
)) == 0)
1569 error ("unknown option `%s'", arg
);
1573 filename
= get_exec_file (1);
1575 pbfd
= bfd_openr (filename
, gnutarget
);
1578 perror_with_name (filename
);
1581 old_chain
= make_cleanup_bfd_close (pbfd
);
1583 if (!bfd_check_format (pbfd
, bfd_object
))
1584 error ("\"%s\" is not an object file: %s", filename
,
1585 bfd_errmsg (bfd_get_error ()));
1587 start_time
= time (NULL
);
1590 puts_e7000debug ("mw\r");
1594 for (section
= pbfd
->sections
; section
; section
= section
->next
)
1596 if (bfd_get_section_flags (pbfd
, section
) & SEC_LOAD
)
1598 bfd_vma section_address
;
1599 bfd_size_type section_size
;
1602 section_address
= bfd_get_section_vma (pbfd
, section
);
1603 section_size
= bfd_get_section_size_before_reloc (section
);
1606 printf_filtered ("[Loading section %s at 0x%x (%d bytes)]\n",
1607 bfd_get_section_name (pbfd
, section
),
1613 data_count
+= section_size
;
1615 while (section_size
> 0)
1618 static char inds
[] = "|/-\\";
1623 count
= min (section_size
, WRITESIZE
);
1625 buf
[2] = section_address
>> 24;
1626 buf
[3] = section_address
>> 16;
1627 buf
[4] = section_address
>> 8;
1628 buf
[5] = section_address
;
1630 buf
[6] = count
>> 24;
1631 buf
[7] = count
>> 16;
1632 buf
[8] = count
>> 8;
1635 bfd_get_section_contents (pbfd
, section
, buf
+ 10, fptr
, count
);
1637 if (SERIAL_WRITE (e7000_desc
, buf
, count
+ 10))
1638 fprintf_unfiltered (gdb_stderr
,
1639 "e7000_load: SERIAL_WRITE failed: %s\n",
1640 safe_strerror (errno
));
1646 printf_unfiltered ("\r%c", inds
[k
++ % 4]);
1647 gdb_flush (gdb_stdout
);
1650 section_address
+= count
;
1652 section_size
-= count
;
1661 end_time
= time (NULL
);
1663 /* Finally, make the PC point at the start address */
1666 write_pc (bfd_get_start_address (exec_bfd
));
1668 inferior_pid
= 0; /* No process now */
1670 /* This is necessary because many things were based on the PC at the time that
1671 we attached to the monitor, which is no longer valid now that we have loaded
1672 new code (and just changed the PC). Another way to do this might be to call
1673 normal_stop, except that the stack may not be valid, and things would get
1674 horribly confused... */
1676 clear_symtab_users ();
1680 entry
= bfd_get_start_address (pbfd
);
1683 printf_unfiltered ("[Starting %s at 0x%x]\n", filename
, entry
);
1685 /* start_routine (entry); */
1688 report_transfer_performance (data_count
, start_time
, end_time
);
1690 do_cleanups (old_chain
);
1691 timeout
= oldtimeout
;
1694 /* Clean up when a program exits.
1696 The program actually lives on in the remote processor's RAM, and may be
1697 run again without a download. Don't leave it full of breakpoint
1701 e7000_mourn_inferior ()
1703 remove_breakpoints ();
1704 unpush_target (&e7000_ops
);
1705 generic_mourn_inferior (); /* Do all the proper things now */
1708 #define MAX_BREAKPOINTS 200
1709 #ifdef HARD_BREAKPOINTS
1710 #define MAX_E7000DEBUG_BREAKPOINTS (BC_BREAKPOINTS ? 5 : MAX_BREAKPOINTS)
1712 #define MAX_E7000DEBUG_BREAKPOINTS MAX_BREAKPOINTS
1715 /* Since we can change to soft breakpoints dynamically, we must define
1716 more than enough. Was breakaddr[MAX_E7000DEBUG_BREAKPOINTS]. */
1717 static CORE_ADDR breakaddr
[MAX_BREAKPOINTS
] =
1721 e7000_insert_breakpoint (addr
, shadow
)
1723 unsigned char *shadow
;
1728 static char nop
[2] = NOP
;
1731 for (i
= 0; i
<= MAX_E7000DEBUG_BREAKPOINTS
; i
++)
1732 if (breakaddr
[i
] == 0)
1734 breakaddr
[i
] = addr
;
1735 /* Save old contents, and insert a nop in the space */
1736 #ifdef HARD_BREAKPOINTS
1739 sprintf (buf
, "BC%d A=%x\r", i
+ 1, addr
);
1740 puts_e7000debug (buf
);
1744 sprintf (buf
, "B %x\r", addr
);
1745 puts_e7000debug (buf
);
1749 e7000_read_inferior_memory (addr
, shadow
, 2);
1750 e7000_write_inferior_memory (addr
, nop
, 2);
1753 sprintf (buf
, "B %x\r", addr
);
1754 puts_e7000debug (buf
);
1760 error ("Too many breakpoints ( > %d) for the E7000\n",
1761 MAX_E7000DEBUG_BREAKPOINTS
);
1766 e7000_remove_breakpoint (addr
, shadow
)
1768 unsigned char *shadow
;
1773 for (i
= 0; i
< MAX_E7000DEBUG_BREAKPOINTS
; i
++)
1774 if (breakaddr
[i
] == addr
)
1777 #ifdef HARD_BREAKPOINTS
1780 sprintf (buf
, "BC%d - \r", i
+ 1);
1781 puts_e7000debug (buf
);
1785 sprintf (buf
, "B - %x\r", addr
);
1786 puts_e7000debug (buf
);
1790 sprintf (buf
, "B - %x\r", addr
);
1791 puts_e7000debug (buf
);
1795 /* Replace the insn under the break */
1796 e7000_write_inferior_memory (addr
, shadow
, 2);
1803 warning ("Can't find breakpoint associated with 0x%x\n", addr
);
1807 /* Put a command string, in args, out to STDBUG. Output from STDBUG
1808 is placed on the users terminal until the prompt is seen. */
1811 e7000_command (args
, fromtty
)
1815 /* FIXME: arbitrary limit on length of args. */
1821 error ("e7000 target not open.");
1824 puts_e7000debug ("\r");
1828 sprintf (buf
, "%s\r", args
);
1829 puts_e7000debug (buf
);
1834 expect_full_prompt ();
1837 printf_unfiltered ("\n");
1839 /* Who knows what the command did... */
1840 registers_changed ();
1845 e7000_drain_command (args
, fromtty
)
1852 puts_e7000debug ("end\r");
1853 putchar_e7000 (CTRLC
);
1855 while ((c
= readchar (1) != -1))
1859 putchar_e7000 (CTRLC
);
1862 if (c
> ' ' && c
< 127)
1863 printf_unfiltered ("%c", c
& 0xff);
1865 printf_unfiltered ("<%x>", c
& 0xff);
1874 static char *strings
[NITEMS
] =
1881 "ILLEGAL INSTRUCTION",
1888 for (i
= 0; i
< NITEMS
; ++i
)
1894 for (i
= 0; i
< NITEMS
; i
++)
1901 /* found one of the choices */
1913 /* Suck characters, if a string match, then return the strings index
1914 otherwise echo them. */
1924 char *buffer
= saveaway
;
1925 /* Count number of expect strings */
1927 for (n
= 0; strings
[n
]; n
++)
1929 ptr
[n
] = strings
[n
];
1940 printf_unfiltered ("[waiting for e7000...]\n");
1953 putchar_e7000 (CTRLC
); /* interrupt the running program */
1957 for (i
= 0; i
< n
; i
++)
1964 /* Gone all the way */
1971 ptr
[i
] = strings
[i
];
1977 /* Save it up incase we find that there was no match */
1982 if (buffer
!= saveaway
)
1985 printf_unfiltered ("%s", buffer
);
1990 putchar_unfiltered (c
);
1991 gdb_flush (gdb_stdout
);
1997 /* We subtract two from the pc here rather than use
1998 DECR_PC_AFTER_BREAK since the e7000 doesn't always add two to the
1999 pc, and the simulators never do. */
2007 store_signed_integer (buf
,
2008 REGISTER_RAW_SIZE (PC_REGNUM
),
2009 read_register (PC_REGNUM
) - 2);
2010 supply_register (PC_REGNUM
, buf
);
2011 sprintf (buf2
, ".PC %x\r", read_register (PC_REGNUM
));
2012 puts_e7000debug (buf2
);
2017 #define WAS_RUNNING 2
2020 static char *estrings
[] =
2029 /* Wait until the remote machine stops, then return, storing status in
2030 STATUS just as `wait' would. */
2033 e7000_wait (pid
, status
)
2035 struct target_waitstatus
*status
;
2039 int running_count
= 0;
2044 /* Then echo chars until PC= string seen */
2045 gch (); /* Drop cr */
2046 gch (); /* and space */
2050 switch (expect_n (estrings
))
2053 /* how did this happen ? */
2058 putchar_e7000 (CTRLC
);
2066 if (running_count
== 20)
2068 printf_unfiltered ("[running...]\n");
2078 /* Skip till the PC= */
2081 #ifdef GDB_TARGET_IS_SH
2082 wanted_nopc
= want_nopc
;
2083 if (TARGET_ARCHITECTURE
->arch
== bfd_arch_sh
)
2084 switch (TARGET_ARCHITECTURE
->mach
)
2089 wanted_nopc
= want_sh3_nopc
;
2093 wanted_nopc
= want_nopc_h8300s
;
2095 wanted_nopc
= want_nopc_h8300h
;
2097 fetch_regs_from_dump (gch
, wanted_nopc
);
2099 /* And supply the extra ones the simulator uses */
2100 for (regno
= NUM_REALREGS
; regno
< NUM_REGS
; regno
++)
2103 supply_register (regno
, (char *) &buf
);
2106 stop_reason
= why_stop ();
2107 expect_full_prompt ();
2109 status
->kind
= TARGET_WAITKIND_STOPPED
;
2110 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2112 switch (stop_reason
)
2114 case 1: /* Breakpoint */
2115 write_pc (read_pc ()); /* PC is always off by 2 for breakpoints */
2116 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2118 case 0: /* Single step */
2119 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2121 case 2: /* Interrupt */
2124 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
2129 status
->value
.sig
= TARGET_SIGNAL_INT
;
2135 printf_unfiltered ("a cycle address error?\n");
2136 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2139 status
->value
.sig
= TARGET_SIGNAL_ILL
;
2142 status
->value
.sig
= TARGET_SIGNAL_SEGV
;
2144 case 7: /* Anything else (NITEMS + 1) */
2145 printf_unfiltered ("a write protect error?\n");
2146 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
2149 /* Get the user's attention - this should never happen. */
2156 /* Stop the running program. */
2161 /* Sending a ^C is supposed to stop the running program. */
2162 putchar_e7000 (CTRLC
);
2165 /* Define the target subroutine names. */
2167 struct target_ops e7000_ops
;
2170 init_e7000_ops (void)
2172 e7000_ops
.to_shortname
= "e7000";
2173 e7000_ops
.to_longname
= "Remote Hitachi e7000 target";
2174 e7000_ops
.to_doc
= "Use a remote Hitachi e7000 ICE connected by a serial line;\n\
2175 or a network connection.\n\
2176 Arguments are the name of the device for the serial line,\n\
2177 the speed to connect at in bits per second.\n\
2179 target e7000 /dev/ttya 9600\n\
2180 target e7000 foobar";
2181 e7000_ops
.to_open
= e7000_open
;
2182 e7000_ops
.to_close
= e7000_close
;
2183 e7000_ops
.to_attach
= 0;
2184 e7000_ops
.to_post_attach
= NULL
;
2185 e7000_ops
.to_require_attach
= NULL
;
2186 e7000_ops
.to_detach
= e7000_detach
;
2187 e7000_ops
.to_require_detach
= NULL
;
2188 e7000_ops
.to_resume
= e7000_resume
;
2189 e7000_ops
.to_wait
= e7000_wait
;
2190 e7000_ops
.to_post_wait
= NULL
;
2191 e7000_ops
.to_fetch_registers
= e7000_fetch_register
;
2192 e7000_ops
.to_store_registers
= e7000_store_register
;
2193 e7000_ops
.to_prepare_to_store
= e7000_prepare_to_store
;
2194 e7000_ops
.to_xfer_memory
= e7000_xfer_inferior_memory
;
2195 e7000_ops
.to_files_info
= e7000_files_info
;
2196 e7000_ops
.to_insert_breakpoint
= e7000_insert_breakpoint
;
2197 e7000_ops
.to_remove_breakpoint
= e7000_remove_breakpoint
;
2198 e7000_ops
.to_terminal_init
= 0;
2199 e7000_ops
.to_terminal_inferior
= 0;
2200 e7000_ops
.to_terminal_ours_for_output
= 0;
2201 e7000_ops
.to_terminal_ours
= 0;
2202 e7000_ops
.to_terminal_info
= 0;
2203 e7000_ops
.to_kill
= e7000_kill
;
2204 e7000_ops
.to_load
= e7000_load
;
2205 e7000_ops
.to_lookup_symbol
= 0;
2206 e7000_ops
.to_create_inferior
= e7000_create_inferior
;
2207 e7000_ops
.to_post_startup_inferior
= NULL
;
2208 e7000_ops
.to_acknowledge_created_inferior
= NULL
;
2209 e7000_ops
.to_clone_and_follow_inferior
= NULL
;
2210 e7000_ops
.to_post_follow_inferior_by_clone
= NULL
;
2211 e7000_ops
.to_insert_fork_catchpoint
= NULL
;
2212 e7000_ops
.to_remove_fork_catchpoint
= NULL
;
2213 e7000_ops
.to_insert_vfork_catchpoint
= NULL
;
2214 e7000_ops
.to_remove_vfork_catchpoint
= NULL
;
2215 e7000_ops
.to_has_forked
= NULL
;
2216 e7000_ops
.to_has_vforked
= NULL
;
2217 e7000_ops
.to_can_follow_vfork_prior_to_exec
= NULL
;
2218 e7000_ops
.to_post_follow_vfork
= NULL
;
2219 e7000_ops
.to_insert_exec_catchpoint
= NULL
;
2220 e7000_ops
.to_remove_exec_catchpoint
= NULL
;
2221 e7000_ops
.to_has_execd
= NULL
;
2222 e7000_ops
.to_reported_exec_events_per_exec_call
= NULL
;
2223 e7000_ops
.to_has_exited
= NULL
;
2224 e7000_ops
.to_mourn_inferior
= e7000_mourn_inferior
;
2225 e7000_ops
.to_can_run
= 0;
2226 e7000_ops
.to_notice_signals
= 0;
2227 e7000_ops
.to_thread_alive
= 0;
2228 e7000_ops
.to_stop
= e7000_stop
;
2229 e7000_ops
.to_pid_to_exec_file
= NULL
;
2230 e7000_ops
.to_core_file_to_sym_file
= NULL
;
2231 e7000_ops
.to_stratum
= process_stratum
;
2232 e7000_ops
.DONT_USE
= 0;
2233 e7000_ops
.to_has_all_memory
= 1;
2234 e7000_ops
.to_has_memory
= 1;
2235 e7000_ops
.to_has_stack
= 1;
2236 e7000_ops
.to_has_registers
= 1;
2237 e7000_ops
.to_has_execution
= 1;
2238 e7000_ops
.to_sections
= 0;
2239 e7000_ops
.to_sections_end
= 0;
2240 e7000_ops
.to_magic
= OPS_MAGIC
;
2244 _initialize_remote_e7000 ()
2247 add_target (&e7000_ops
);
2249 add_com ("e7000", class_obscure
, e7000_command
,
2250 "Send a command to the e7000 monitor.");
2252 add_com ("ftplogin", class_obscure
, e7000_login_command
,
2253 "Login to machine and change to directory.");
2255 add_com ("ftpload", class_obscure
, e7000_ftp_command
,
2256 "Fetch and load a file from previously described place.");
2258 add_com ("drain", class_obscure
, e7000_drain_command
,
2259 "Drain pending e7000 text buffers.");
2261 add_show_from_set (add_set_cmd ("usehardbreakpoints", no_class
,
2262 var_integer
, (char *) &use_hard_breakpoints
,
2263 "Set use of hardware breakpoints for all breakpoints.\n", &setlist
),