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 /* Local function declarations. */
66 static void e7000_close
PARAMS ((int));
68 static void e7000_fetch_register
PARAMS ((int));
70 static void e7000_store_register
PARAMS ((int));
72 static void e7000_command
PARAMS ((char *, int));
74 static void e7000_login_command
PARAMS ((char *, int));
76 static void e7000_ftp_command
PARAMS ((char *, int));
78 static void e7000_drain_command
PARAMS ((char *, int));
80 static void expect
PARAMS ((char *));
82 static void expect_full_prompt
PARAMS ((void));
84 static void expect_prompt
PARAMS ((void));
88 static serial_t e7000_desc
;
90 /* Nonzero if using the tcp serial driver. */
94 /* Nonzero if using the pc isa card. */
98 extern struct target_ops e7000_ops
; /* Forward declaration */
100 char *ENQSTRING
= "\005";
102 /* Nonzero if some routine (as opposed to the user) wants echoing.
103 FIXME: Do this reentrantly with an extra parameter. */
109 static int timeout
= 5;
111 /* Send data to e7000debug. */
114 puts_e7000debug (buf
)
118 error ("Use \"target e7000 ...\" first.");
121 printf("Sending %s\n", buf
);
123 if (SERIAL_WRITE (e7000_desc
, buf
, strlen (buf
)))
124 fprintf (stderr
, "SERIAL_WRITE failed: %s\n", safe_strerror (errno
));
126 /* And expect to see it echoed, unless using the pc interface */
140 SERIAL_WRITE (e7000_desc
, b
, 1);
147 SERIAL_WRITE (e7000_desc
, s
, strlen (s
));
159 /* Read a character from the remote system, doing all the fancy timeout
170 c
= SERIAL_READCHAR (e7000_desc
, timeout
);
174 if (c
== SERIAL_TIMEOUT
)
179 error ("Timeout reading from remote system.");
194 static char b
[8][10];
206 sprintf(b
[p
], "<%d>", x
);
213 /* Scan input from the remote system, until STRING is found. If
214 DISCARD is non-zero, then discard non-matching input, else print it
215 out. Let the user break out immediately. */
227 c
= readchar (timeout
);
233 putchar_e7000(CTRLC
);
242 if (c
== SERIAL_ERROR
)
244 error ("Serial communication error");
246 if (echo
|| remote_debug
)
248 if (c
== '\r' || c
== '\n')
261 if (normal (c
) == normal (*p
++))
270 if (normal (c
) == normal (string
[0]))
276 /* Keep discarding input until we see the e7000 prompt.
278 The convention for dealing with the prompt is that you
280 o *then* wait for the prompt.
282 Thus the last thing that a procedure does with the serial line will
283 be an expect_prompt(). Exception: e7000_resume does not wait for
284 the prompt, because the terminal is being handed over to the
285 inferior. However, the next thing which happens after that is a
286 e7000_wait which does wait for the prompt. Note that this includes
287 abnormal exit, e.g. error(). This is necessary to prevent getting
288 into states from which we can't recover. */
297 expect_full_prompt ()
303 convert_hex_digit (ch
)
306 if (ch
>= '0' && ch
<= '9')
308 else if (ch
>= 'A' && ch
<= 'F')
309 return ch
- 'A' + 10;
310 else if (ch
>= 'a' && ch
<= 'f')
311 return ch
- 'a' + 10;
319 int value
= convert_hex_digit (*start
);
322 *start
= readchar (timeout
);
323 while ((try = convert_hex_digit (*start
)) >= 0)
327 *start
= readchar (timeout
);
333 /* Get N 32-bit words from remote, each preceded by a space, and put
334 them in registers starting at REGNO. */
337 get_hex_regs (n
, regno
)
344 for (i
= 0; i
< n
; i
++)
349 for (j
= 0; j
< 8; j
++)
350 val
= (val
<< 4) + get_hex_digit (j
== 0);
351 supply_register (regno
++, (char *) &val
);
356 /* This is called not only when we first attach, but also when the
357 user types "run" after having attached. */
360 e7000_create_inferior (execfile
, args
, env
)
368 error ("Can't pass arguments to remote E7000DEBUG process");
370 if (execfile
== 0 || exec_bfd
== 0)
371 error ("No exec file specified");
373 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
375 #ifdef CREATE_INFERIOR_HOOK
376 CREATE_INFERIOR_HOOK (0); /* No process-ID */
379 /* The "process" (board) is already stopped awaiting our commands, and
380 the program is already downloaded. We just set its PC and go. */
382 clear_proceed_status ();
384 /* Tell wait_for_inferior that we've started a new process. */
385 init_wait_for_inferior ();
387 /* Set up the "saved terminal modes" of the inferior
388 based on what modes we are starting it with. */
389 target_terminal_init ();
391 /* Install inferior's terminal modes. */
392 target_terminal_inferior ();
394 /* insert_step_breakpoint (); FIXME, do we need this? */
395 proceed ((CORE_ADDR
) entry_pt
, -1, 0); /* Let 'er rip... */
398 /* Open a connection to a remote debugger. NAME is the filename used
399 for communication. */
401 static int baudrate
= 9600;
402 static char dev_name
[100];
404 static char *machine
= "";
405 static char *user
= "";
406 static char *passwd
= "";
407 static char *dir
= "";
409 /* Grab the next token and buy some space for it */
420 while (*p
&& *p
== ' ')
423 while (*p
&& (*p
!= ' ' && *p
!= '\t'))
436 e7000_login_command (args
, from_tty
)
442 machine
= next (&args
);
444 passwd
= next (&args
);
448 printf ("Set info to %s %s %s %s\n", machine
, user
, passwd
, dir
);
453 error ("Syntax is ftplogin <machine> <user> <passwd> <directory>");
457 /* Start an ftp transfer from the E7000 to a host */
460 e7000_ftp_command (args
, from_tty
)
464 /* FIXME: arbitrary limit on machine names and such. */
467 int oldtimeout
= timeout
;
470 sprintf (buf
, "ftp %s\r", machine
);
471 puts_e7000debug (buf
);
472 expect (" Username : ");
473 sprintf (buf
, "%s\r", user
);
474 puts_e7000debug (buf
);
475 expect (" Password : ");
476 write_e7000 (passwd
);
478 expect ("success\r");
480 sprintf (buf
, "cd %s\r", dir
);
481 puts_e7000debug (buf
);
483 sprintf (buf
, "ll 0;s:%s\r", args
);
484 puts_e7000debug (buf
);
486 puts_e7000debug ("bye\r");
488 timeout
= oldtimeout
;
492 e7000_open (args
, from_tty
)
500 target_preopen (from_tty
);
503 if (args
&& strcasecmp (args
, "pc") == 0)
505 strcpy (dev_name
, args
);
511 n
= sscanf (args
, " %s %d %s", dev_name
, &baudrate
, junk
);
514 if (n
!= 1 && n
!= 2)
516 error ("Bad arguments. Usage:\ttarget e7000 <device> <speed>\n\
517 or \t\ttarget e7000 <host>[:<port>]\n\
518 or \t\ttarget e7000 pc\n");
522 if (n
== 1 && strchr (dev_name
, ':') == 0)
524 /* Default to normal telnet port */
525 strcat (dev_name
, ":23");
530 push_target (&e7000_ops
);
532 e7000_desc
= SERIAL_OPEN (dev_name
);
535 perror_with_name (dev_name
);
537 using_tcp
= strcmp (e7000_desc
->ops
->name
, "tcp") == 0;
538 using_pc
= strcmp (e7000_desc
->ops
->name
, "pc") == 0;
540 SERIAL_SETBAUDRATE (e7000_desc
, baudrate
);
541 SERIAL_RAW (e7000_desc
);
543 /* Hello? Are you there? */
546 putchar_e7000 (CTRLC
);
552 printf_unfiltered ("[waiting for e7000...]\n");
555 c
= SERIAL_READCHAR (e7000_desc
, 1);
556 while (c
!= SERIAL_TIMEOUT
)
559 if (from_tty
&& c
!= '\r')
569 putchar_e7000 (CTRLC
);
578 putchar_e7000 (CTRLC
);
581 c
= SERIAL_READCHAR (e7000_desc
, 1);
584 puts_e7000debug ("\r");
588 puts_e7000debug ("b -\r");
593 printf_filtered ("Remote target %s connected to %s\n", target_shortname
,
596 #ifdef GDB_TARGET_IS_H8300
601 /* Close out all files and local state before this target loses control. */
604 e7000_close (quitting
)
609 SERIAL_CLOSE (e7000_desc
);
614 /* Terminate the open connection to the remote debugger. Use this
615 when you want to detach and do something else with your gdb. */
618 e7000_detach (from_tty
)
621 pop_target (); /* calls e7000_close to do the real work */
623 printf ("Ending remote %s debugging\n", target_shortname
);
626 /* Tell the remote machine to resume. */
629 e7000_resume (pid
, step
, sig
)
633 puts_e7000debug ("S\r");
635 puts_e7000debug ("G\r");
638 /* Read the remote registers into the block REGS.
640 For the H8/300 a register dump looks like:
642 PC=00021A CCR=80:I*******
643 ER0 - ER3 0000000A 0000002E 0000002E 00000000
644 ER4 - ER7 00000000 00000000 00000000 00FFEFF6
650 #ifdef GDB_TARGET_IS_H8300
652 char *want
= "PC=%p CCR=%c\n\
653 ER0 - ER3 %0 %1 %2 %3\n\
654 ER4 - ER7 %4 %5 %6 %7\n";
656 char *want_nopc
= "%p CCR=%c\n\
657 ER0 - ER3 %0 %1 %2 %3\n\
658 ER4 - ER7 %4 %5 %6 %7";
662 #ifdef GDB_TARGET_IS_SH
664 char *want
= "PC=%16 SR=%22\n\
665 PR=%17 GBR=%18 VBR=%19\n\
667 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
668 R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n";
670 char *want_nopc
= "%16 SR=%22\n\
671 PR=%17 GBR=%18 VBR=%19\n\
673 R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\
674 R8-15 %8 %9 %10 %11 %12 %13 %14 %15";
681 int c
= readchar (timeout
);
696 int high
= convert_hex_digit (gch ());
697 int low
= convert_hex_digit (gch ());
699 return (high
<< 4) + low
;
703 fetch_regs_from_dump (nextchar
, want
)
708 char buf
[MAX_REGISTER_RAW_SIZE
];
710 int thischar
= nextchar ();
717 /* Skip to end of line and then eat all new line type stuff */
718 while (thischar
!= '\n' && thischar
!= '\r')
719 thischar
= nextchar ();
720 while (thischar
== '\n' || thischar
== '\r')
721 thischar
= nextchar ();
726 while (thischar
== ' '
730 thischar
= nextchar ();
735 if (*want
== thischar
)
739 thischar
= nextchar ();
742 else if (thischar
== ' ' || thischar
== '\n' || thischar
== '\r')
744 thischar
= nextchar ();
747 error ("out of sync in fetch registers wanted <%s>, got <%c 0x%x>",
748 want
, thischar
, thischar
);
753 /* Got a register command */
783 if (isdigit (want
[0]))
785 if (isdigit (want
[1]))
787 regno
= (want
[0] - '0') * 10 + want
[1] - '0';
792 regno
= want
[0] - '0';
800 store_signed_integer (buf
,
801 REGISTER_RAW_SIZE(regno
),
802 (LONGEST
) get_hex (&thischar
, nextchar
));
803 supply_register (regno
, buf
);
810 e7000_fetch_registers ()
814 puts_e7000debug ("R\r");
815 fetch_regs_from_dump (gch
, want
);
817 /* And supply the extra ones the simulator uses */
818 for (regno
= NUM_REALREGS
; regno
< NUM_REGS
; regno
++)
822 supply_register (regno
, (char *) (&buf
));
826 /* Fetch register REGNO, or all registers if REGNO is -1. Returns
830 e7000_fetch_register (regno
)
833 e7000_fetch_registers ();
836 /* Store the remote registers from the contents of the block REGS. */
839 e7000_store_registers ()
843 for (regno
= 0; regno
< NUM_REALREGS
; regno
++)
844 e7000_store_register (regno
);
846 registers_changed ();
849 /* Store register REGNO, or all if REGNO == 0. Return errno value. */
852 e7000_store_register (regno
)
859 e7000_store_registers ();
863 #ifdef GDB_TARGET_IS_H8300
866 sprintf (buf
, ".ER%d %x\r", regno
, read_register (regno
));
867 puts_e7000debug (buf
);
869 else if (regno
== PC_REGNUM
)
871 sprintf (buf
, ".PC %x\r", read_register (regno
));
872 puts_e7000debug (buf
);
874 else if (regno
== CCR_REGNUM
)
876 sprintf (buf
, ".CCR %x\r", read_register (regno
));
877 puts_e7000debug (buf
);
879 #endif /* GDB_TARGET_IS_H8300 */
881 #ifdef GDB_TARGET_IS_SH
885 sprintf (buf
, ".R%d %x\r", regno
, read_register (regno
));
886 puts_e7000debug (buf
);
890 sprintf (buf
, ".PC %x\r", read_register (regno
));
891 puts_e7000debug (buf
);
895 sprintf (buf
, ".SR %x\r", read_register (regno
));
896 puts_e7000debug (buf
);
900 sprintf (buf
, ".PR %x\r", read_register (regno
));
901 puts_e7000debug (buf
);
905 sprintf (buf
, ".GBR %x\r", read_register (regno
));
906 puts_e7000debug (buf
);
910 sprintf (buf
, ".VBR %x\r", read_register (regno
));
911 puts_e7000debug (buf
);
915 sprintf (buf
, ".MACH %x\r", read_register (regno
));
916 puts_e7000debug (buf
);
920 sprintf (buf
, ".MACL %x\r", read_register (regno
));
921 puts_e7000debug (buf
);
925 #endif /* GDB_TARGET_IS_SH */
930 /* Get ready to modify the registers array. On machines which store
931 individual registers, this doesn't need to do anything. On machines
932 which store all the registers in one fell swoop, this makes sure
933 that registers contains all the registers from the program being
937 e7000_prepare_to_store ()
939 /* Do nothing, since we can store individual regs */
945 printf ("\tAttached to %s at %d baud.\n", dev_name
, baudrate
);
949 stickbyte (where
, what
)
953 static CONST
char digs
[] = "0123456789ABCDEF";
955 where
[0] = digs
[(what
>> 4) & 0xf];
956 where
[1] = digs
[(what
& 0xf) & 0xf];
961 /* Write a small ammount of memory. */
964 write_small (memaddr
, myaddr
, len
)
966 unsigned char *myaddr
;
972 for (i
= 0; i
< len
; i
++)
974 if (((memaddr
+ i
) & 3) == 0 && (i
+ 3 < len
))
976 /* Can be done with a long word */
977 sprintf (buf
, "m %x %x%02x%02x%02x;l\r",
979 myaddr
[i
], myaddr
[i
+ 1], myaddr
[i
+ 2], myaddr
[i
+ 3]);
980 puts_e7000debug (buf
);
985 sprintf (buf
, "m %x %x\r", memaddr
+ i
, myaddr
[i
]);
986 puts_e7000debug (buf
);
995 /* Write a large ammount of memory, this only works with the serial
996 mode enabled. Command is sent as
1011 write_large (memaddr
, myaddr
, len
)
1013 unsigned char *myaddr
;
1017 #define maxstride 128
1020 puts_e7000debug ("IL ;S:FK\r");
1022 putchar_e7000 (ACK
);
1025 for (i
= 0; i
< len
; i
+= stride
)
1027 char compose
[maxstride
* 2 + 50];
1028 int address
= i
+ memaddr
;
1035 if (stride
> maxstride
)
1038 compose
[where
++] = 'S';
1040 if (address
>= 0xffffff)
1042 else if (address
>= 0xffff)
1047 compose
[where
++] = alen
- 1 + '0';
1048 /* Insert length. */
1049 check_sum
+= stickbyte (compose
+ where
, alen
+ stride
+ 1);
1054 check_sum
+= stickbyte (compose
+ where
, address
>> (8 * (alen
)));
1058 for (j
= 0; j
< stride
; j
++)
1060 check_sum
+= stickbyte (compose
+ where
, myaddr
[i
+ j
]);
1063 stickbyte (compose
+ where
, ~check_sum
);
1065 compose
[where
++] = '\r';
1066 compose
[where
++] = '\n';
1067 compose
[where
++] = 0;
1069 SERIAL_WRITE (e7000_desc
, compose
, where
);
1070 j
= SERIAL_READCHAR (e7000_desc
, 0);
1071 if (j
== SERIAL_TIMEOUT
)
1073 /* This is ok - nothing there */
1077 /* Hmm, it's trying to tell us something */
1079 error ("Error writing memory");
1083 printf ("@%d}@", j
);
1084 while ((j
= SERIAL_READCHAR(e7000_desc
,0)) > 0)
1086 printf ("@{%d}@",j
);
1091 /* Send the trailer record */
1092 write_e7000 ("S70500000000FA\r");
1093 putchar_e7000 (CTRLZ
);
1095 putchar_e7000 (ACK
);
1101 /* Copy LEN bytes of data from debugger memory at MYADDR to inferior's
1102 memory at MEMADDR. Returns length moved.
1104 Can't use the Srecord load over ethernet, so don't use fast method
1108 e7000_write_inferior_memory (memaddr
, myaddr
, len
)
1110 unsigned char *myaddr
;
1113 if (len
< 16 || using_tcp
|| using_pc
)
1114 return write_small (memaddr
, myaddr
, len
);
1116 return write_large (memaddr
, myaddr
, len
);
1119 /* Read LEN bytes from inferior memory at MEMADDR. Put the result
1120 at debugger address MYADDR. Returns length moved.
1122 Small transactions we send
1129 e7000_read_inferior_memory (memaddr
, myaddr
, len
)
1131 unsigned char *myaddr
;
1138 /* Starting address of this pass. */
1140 /* printf("READ INF %x %x %d\n", memaddr, myaddr, len);*/
1141 if (((memaddr
- 1) + len
) < memaddr
)
1147 sprintf (buf
, "m %x;l\r", memaddr
);
1148 puts_e7000debug (buf
);
1150 for (count
= 0; count
< len
; count
+= 4)
1152 /* Suck away the address */
1158 { /* Some kind of error */
1165 /* Now read in the data */
1166 for (i
= 0; i
< 4; i
++)
1169 if (count
+ i
< len
) {
1170 myaddr
[count
+ i
] = b
;
1174 /* Skip the trailing ? and send a . to end and a cr for more */
1177 if (count
+ 4 >= len
)
1178 puts_e7000debug(".\r");
1180 puts_e7000debug("\r");
1190 For large transfers we used to send
1193 d <addr> <endaddr>\r
1196 <ADDR> < D A T A > < ASCII CODE >
1197 000000 5F FD FD FF DF 7F DF FF 01 00 01 00 02 00 08 04 "_..............."
1198 000010 FF D7 FF 7F D7 F1 7F FF 00 05 00 00 08 00 40 00 "..............@."
1199 000020 7F FD FF F7 7F FF FF F7 00 00 00 00 00 00 00 00 "................"
1201 A cost in chars for each transaction of 80 + 5*n-bytes.
1203 Large transactions could be done with the srecord load code, but
1204 there is a pause for a second before dumping starts, which slows the
1209 e7000_read_inferior_memory (memaddr
, myaddr
, len
)
1211 unsigned char *myaddr
;
1218 /* Starting address of this pass. */
1220 if (((memaddr
- 1) + len
) < memaddr
)
1226 sprintf (buf
, "d %x %x\r", memaddr
, memaddr
+ len
- 1);
1227 puts_e7000debug (buf
);
1232 /* First skip the command */
1244 /* Skip the title line */
1250 /* Skip the address */
1256 /* read in the bytes on the line */
1257 while (c
!= '"' && count
< len
)
1263 myaddr
[count
++] = get_hex (&c
);
1278 fast_but_for_the_pause_e7000_read_inferior_memory (memaddr
, myaddr
, len
)
1287 if (((memaddr
- 1) + len
) < memaddr
)
1293 sprintf (buf
, "is %x@%x:s\r", memaddr
, len
);
1294 puts_e7000debug (buf
);
1300 error ("Memory read error");
1302 putchar_e7000 (ACK
);
1315 case ENQ
: /* ENQ, at the end */
1319 /* Start of an Srecord */
1324 case '7': /* Termination record, ignore */
1328 /* Header record - ignore it */
1340 alen
= type
- '0' + 1;
1344 addr
= (addr
<< 8) + gbyte ();
1348 for (i
= 0; i
< length
- 1; i
++)
1349 myaddr
[i
+ addr
- memaddr
] = gbyte ();
1351 gbyte (); /* Ignore checksum */
1357 putchar_e7000 (ACK
);
1358 expect ("TOP ADDRESS =");
1359 expect ("END ADDRESS =");
1368 e7000_xfer_inferior_memory (memaddr
, myaddr
, len
, write
, target
)
1370 unsigned char *myaddr
;
1373 struct target_ops
*target
; /* ignored */
1376 return e7000_write_inferior_memory( memaddr
, myaddr
, len
);
1378 return e7000_read_inferior_memory( memaddr
, myaddr
, len
);
1382 e7000_kill (args
, from_tty
)
1389 e7000_load (args
, from_tty
)
1393 struct cleanup
*old_chain
;
1398 #define WRITESIZE 0x1000
1399 char buf
[2 + 4 + 4 + WRITESIZE
]; /* `DT' + <addr> + <len> + <data> */
1403 time_t start_time
, end_time
; /* Start and end times of download */
1404 unsigned long data_count
; /* Number of bytes transferred to memory */
1406 if (!strchr (dev_name
, ':'))
1408 generic_load (args
, from_tty
);
1418 while (*args
!= '\000')
1422 while (isspace (*args
)) args
++;
1426 while ((*args
!= '\000') && !isspace (*args
)) args
++;
1428 if (*args
!= '\000')
1433 else if (strncmp (arg
, "-quiet", strlen (arg
)) == 0)
1435 else if (strncmp (arg
, "-nostart", strlen (arg
)) == 0)
1438 error ("unknown option `%s'", arg
);
1442 filename
= get_exec_file (1);
1444 pbfd
= bfd_openr (filename
, gnutarget
);
1447 perror_with_name (filename
);
1450 old_chain
= make_cleanup (bfd_close
, pbfd
);
1452 if (!bfd_check_format (pbfd
, bfd_object
))
1453 error ("\"%s\" is not an object file: %s", filename
,
1454 bfd_errmsg (bfd_get_error ()));
1456 start_time
= time (NULL
);
1459 puts_e7000debug ("mw\r");
1463 for (section
= pbfd
->sections
; section
; section
= section
->next
)
1465 if (bfd_get_section_flags (pbfd
, section
) & SEC_LOAD
)
1467 bfd_vma section_address
;
1468 bfd_size_type section_size
;
1471 section_address
= bfd_get_section_vma (pbfd
, section
);
1472 section_size
= bfd_get_section_size_before_reloc (section
);
1475 printf_filtered ("[Loading section %s at 0x%x (%d bytes)]\n",
1476 bfd_get_section_name (pbfd
, section
),
1482 data_count
+= section_size
;
1484 while (section_size
> 0)
1487 static char inds
[] = "|/-\\";
1492 count
= min (section_size
, WRITESIZE
);
1494 buf
[2] = section_address
>> 24;
1495 buf
[3] = section_address
>> 16;
1496 buf
[4] = section_address
>> 8;
1497 buf
[5] = section_address
;
1499 buf
[6] = count
>> 24;
1500 buf
[7] = count
>> 16;
1501 buf
[8] = count
>> 8;
1504 bfd_get_section_contents (pbfd
, section
, buf
+ 10, fptr
, count
);
1506 if (SERIAL_WRITE (e7000_desc
, buf
, count
+ 10))
1507 fprintf_unfiltered (gdb_stderr
,
1508 "e7000_load: SERIAL_WRITE failed: %s\n",
1509 safe_strerror(errno
));
1515 printf_unfiltered ("\r%c", inds
[k
++ % 4]);
1516 gdb_flush (gdb_stdout
);
1519 section_address
+= count
;
1521 section_size
-= count
;
1530 end_time
= time (NULL
);
1532 /* Finally, make the PC point at the start address */
1535 write_pc (bfd_get_start_address (exec_bfd
));
1537 inferior_pid
= 0; /* No process now */
1539 /* This is necessary because many things were based on the PC at the time that
1540 we attached to the monitor, which is no longer valid now that we have loaded
1541 new code (and just changed the PC). Another way to do this might be to call
1542 normal_stop, except that the stack may not be valid, and things would get
1543 horribly confused... */
1545 clear_symtab_users ();
1549 entry
= bfd_get_start_address (pbfd
);
1552 printf_unfiltered ("[Starting %s at 0x%x]\n", filename
, entry
);
1554 /* start_routine (entry);*/
1557 report_transfer_performance (data_count
, start_time
, end_time
);
1559 do_cleanups (old_chain
);
1562 /* Clean up when a program exits.
1564 The program actually lives on in the remote processor's RAM, and may be
1565 run again without a download. Don't leave it full of breakpoint
1569 e7000_mourn_inferior ()
1571 remove_breakpoints ();
1572 unpush_target (&e7000_ops
);
1573 generic_mourn_inferior (); /* Do all the proper things now */
1576 #ifdef HARD_BREAKPOINTS
1577 #define MAX_E7000DEBUG_BREAKPOINTS (BC_BREAKPOINTS ? 5 : 200)
1579 #define MAX_E7000DEBUG_BREAKPOINTS 200
1582 extern int memory_breakpoint_size
;
1584 static CORE_ADDR breakaddr
[MAX_E7000DEBUG_BREAKPOINTS
] = {0};
1587 e7000_insert_breakpoint (addr
, shadow
)
1589 unsigned char *shadow
;
1593 static char nop
[2] = NOP
;
1595 for (i
= 0; i
<= MAX_E7000DEBUG_BREAKPOINTS
; i
++)
1596 if (breakaddr
[i
] == 0)
1598 breakaddr
[i
] = addr
;
1599 /* Save old contents, and insert a nop in the space */
1600 #ifdef HARD_BREAKPOINTS
1603 sprintf (buf
, "BC%d A=%x\r", i
+1, addr
);
1604 puts_e7000debug (buf
);
1608 sprintf (buf
, "B %x\r", addr
);
1609 puts_e7000debug (buf
);
1613 e7000_read_inferior_memory (addr
, shadow
, 2);
1614 e7000_write_inferior_memory (addr
, nop
, 2);
1617 sprintf (buf
, "B %x\r", addr
);
1618 puts_e7000debug (buf
);
1624 error ("Too many breakpoints ( > %d) for the E7000\n",
1625 MAX_E7000DEBUG_BREAKPOINTS
);
1630 e7000_remove_breakpoint (addr
, shadow
)
1632 unsigned char *shadow
;
1637 for (i
= 0; i
< MAX_E7000DEBUG_BREAKPOINTS
; i
++)
1638 if (breakaddr
[i
] == addr
)
1641 #ifdef HARD_BREAKPOINTS
1644 sprintf (buf
, "BC%d - \r", i
+1);
1645 puts_e7000debug (buf
);
1649 sprintf (buf
, "B - %x\r", addr
);
1650 puts_e7000debug (buf
);
1654 sprintf (buf
, "B - %x\r", addr
);
1655 puts_e7000debug (buf
);
1659 /* Replace the insn under the break */
1660 e7000_write_inferior_memory (addr
, shadow
, 2);
1667 warning ("Can't find breakpoint associated with 0x%x\n", addr
);
1671 /* Put a command string, in args, out to STDBUG. Output from STDBUG
1672 is placed on the users terminal until the prompt is seen. */
1675 e7000_command (args
, fromtty
)
1679 /* FIXME: arbitrary limit on length of args. */
1685 error ("e7000 target not open.");
1688 puts_e7000debug ("\r");
1692 sprintf (buf
, "%s\r", args
);
1693 puts_e7000debug (buf
);
1698 expect_full_prompt ();
1701 printf_unfiltered ("\n");
1703 /* Who knows what the command did... */
1704 registers_changed ();
1709 e7000_drain_command (args
, fromtty
)
1716 puts_e7000debug("end\r");
1717 putchar_e7000 (CTRLC
);
1719 while ((c
= SERIAL_READCHAR (e7000_desc
, 1) != SERIAL_TIMEOUT
))
1723 putchar_e7000(CTRLC
);
1726 if (c
> ' ' && c
< 127)
1727 printf ("%c", c
& 0xff);
1729 printf ("<%x>", c
& 0xff);
1738 static char *strings
[NITEMS
] = {
1744 "ILLEGAL INSTRUCTION",
1751 for (i
= 0; i
< NITEMS
; ++i
)
1757 for (i
= 0; i
< NITEMS
; i
++)
1764 /* found one of the choices */
1776 /* Suck characters, if a string match, then return the strings index
1777 otherwise echo them. */
1787 char *buffer
= saveaway
;
1788 /* Count number of expect strings */
1790 for (n
= 0; strings
[n
]; n
++)
1792 ptr
[n
] = strings
[n
];
1800 c
= SERIAL_READCHAR (e7000_desc
, 1);
1801 if (c
== SERIAL_TIMEOUT
)
1803 printf_unfiltered ("[waiting for e7000...]\n");
1816 putchar_e7000 (CTRLC
); /* interrupt the running program */
1820 for (i
= 0; i
< n
; i
++)
1827 /* Gone all the way */
1834 ptr
[i
] = strings
[i
];
1840 /* Save it up incase we find that there was no match */
1845 if (buffer
!= saveaway
)
1848 printf ("%s", buffer
);
1851 if (c
!= SERIAL_TIMEOUT
)
1860 /* We subtract two from the pc here rather than use
1861 DECR_PC_AFTER_BREAK since the e7000 doesn't always add two to the
1862 pc, and the simulators never do. */
1870 store_signed_integer (buf
,
1871 REGISTER_RAW_SIZE(PC_REGNUM
),
1872 read_register (PC_REGNUM
) -2);
1873 supply_register (PC_REGNUM
, buf
);
1874 sprintf (buf2
, ".PC %x\r", read_register (PC_REGNUM
));
1875 puts_e7000debug (buf2
);
1880 #define WAS_RUNNING 2
1883 static char *estrings
[] = {
1891 /* Wait until the remote machine stops, then return, storing status in
1892 STATUS just as `wait' would. */
1895 e7000_wait (pid
, status
)
1897 struct target_waitstatus
*status
;
1901 int running_count
= 0;
1905 /* Then echo chars until PC= string seen */
1906 gch (); /* Drop cr */
1907 gch (); /* and space */
1911 switch (expect_n (estrings
))
1914 /* how did this happen ? */
1919 putchar_e7000 (CTRLC
);
1927 if (running_count
== 20)
1929 printf_unfiltered ("[running...]\n");
1939 /* Skip till the PC= */
1941 fetch_regs_from_dump (gch
, want_nopc
);
1943 /* And supply the extra ones the simulator uses */
1944 for (regno
= NUM_REALREGS
; regno
< NUM_REGS
; regno
++)
1947 supply_register (regno
, (char *) &buf
);
1950 stop_reason
= why_stop ();
1951 expect_full_prompt ();
1953 status
->kind
= TARGET_WAITKIND_STOPPED
;
1954 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
1956 switch (stop_reason
)
1958 case 1: /* Breakpoint */
1959 write_pc (read_pc ()); /* PC is always off by 2 for breakpoints */
1960 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
1962 case 0: /* Single step */
1963 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
1965 case 2: /* Interrupt */
1968 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
1973 status
->value
.sig
= TARGET_SIGNAL_INT
;
1979 printf_unfiltered ("a cycle address error?\n");
1980 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
1983 status
->value
.sig
= TARGET_SIGNAL_ILL
;
1986 status
->value
.sig
= TARGET_SIGNAL_SEGV
;
1988 case 7: /* Anything else (NITEMS + 1) */
1989 printf_unfiltered ("a write protect error?\n");
1990 status
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
1993 /* Get the user's attention - this should never happen. */
2000 /* Define the target subroutine names. */
2002 struct target_ops e7000_ops
=
2005 "Remote Hitachi e7000 target",
2006 "Use a remote Hitachi e7000 ICE connected by a serial line,\n\
2007 or a network connection.\n\
2008 Arguments are the name of the device for the serial line,\n\
2009 the speed to connect at in bits per second.\n\
2011 target e7000 /dev/ttya 9600\n\
2012 target e7000 foobar",
2013 e7000_open
, /* to_open */
2014 e7000_close
, /* to_close */
2016 e7000_detach
, /* to_detach */
2017 e7000_resume
, /* to_resume */
2018 e7000_wait
, /* to_wait */
2019 e7000_fetch_register
, /* to_fetch_registers */
2020 e7000_store_register
, /* to_store_registers */
2021 e7000_prepare_to_store
, /* to_prepare_to_store */
2022 e7000_xfer_inferior_memory
, /* to_xfer_memory */
2023 e7000_files_info
, /* to_files_info */
2024 e7000_insert_breakpoint
, /* to_insert_breakpoint */
2025 e7000_remove_breakpoint
, /* to_remove_breakpoint */
2026 0, /* to_terminal_init */
2027 0, /* to_terminal_inferior */
2028 0, /* to_terminal_ours_for_output */
2029 0, /* to_terminal_ours */
2030 0, /* to_terminal_info */
2031 e7000_kill
, /* to_kill */
2032 e7000_load
, /* to_load */
2033 0, /* to_lookup_symbol */
2034 e7000_create_inferior
, /* to_create_inferior */
2035 e7000_mourn_inferior
, /* to_mourn_inferior */
2037 0, /* to_notice_signals */
2038 0, /* to_thread_alive */
2040 process_stratum
, /* to_stratum */
2041 0, /* next (unused) */
2042 1, /* to_has_all_memory */
2043 1, /* to_has_memory */
2044 1, /* to_has_stack */
2045 1, /* to_has_registers */
2046 1, /* to_has_execution */
2047 0, /* to_sections */
2048 0, /* to_sections_end */
2049 OPS_MAGIC
, /* Always the last thing */
2053 _initialize_remote_e7000 ()
2055 add_target (&e7000_ops
);
2057 add_com ("e7000 <command>", class_obscure
, e7000_command
,
2058 "Send a command to the e7000 monitor.");
2060 add_com ("ftplogin <machine> <name> <passwd> <dir>", class_obscure
, e7000_login_command
,
2061 "Login to machine and change to directory.");
2063 add_com ("ftpload <file>", class_obscure
, e7000_ftp_command
,
2064 "Fetch and load a file from previously described place.");
2066 add_com ("drain", class_obscure
, e7000_drain_command
,
2067 "Drain pending e7000 text buffers.");