1 /* Remote debugging interface for Array Tech RAID controller..
3 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
6 Contributed by Cygnus Support. Written by Rob Savoye for Cygnus.
8 This module talks to a debug monitor called 'MONITOR', which
9 We communicate with MONITOR via either a direct serial line, or a TCP
10 (or possibly TELNET) stream to a terminal multiplexor,
11 which in turn talks to the target board.
13 This file is part of GDB.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. */
34 #include <sys/types.h>
35 #include "gdb_string.h"
39 #include "remote-utils.h"
46 #define ARRAY_PROMPT ">> "
48 static void debuglogs (int, char *, ...);
49 static void array_open ();
50 static void array_close ();
51 static void array_detach ();
52 static void array_attach ();
53 static void array_resume (ptid_t ptid
, int step
, enum target_signal sig
);
54 static void array_fetch_register ();
55 static void array_store_register ();
56 static void array_fetch_registers ();
57 static void array_store_registers ();
58 static void array_prepare_to_store ();
59 static void array_files_info ();
60 static void array_kill ();
61 static void array_create_inferior ();
62 static void array_mourn_inferior ();
63 static void make_gdb_packet ();
64 static int array_xfer_memory ();
65 static ptid_t
array_wait (ptid_t ptid
,
66 struct target_waitstatus
*status
);
67 static int array_insert_breakpoint ();
68 static int array_remove_breakpoint ();
71 static int from_hex ();
72 static int array_send_packet ();
73 static int array_get_packet ();
74 static unsigned long ascii2hexword ();
75 static void hexword2ascii ();
77 #define LOG_FILE "monitor.log"
78 #if defined (LOG_FILE)
82 static int timeout
= 30;
83 /* Having this larger than 400 causes us to be incompatible with
84 m68k-stub.c and i386-stub.c. Normally, no one would notice because
85 it only matters for writing large chunks of memory (e.g. in
86 downloads). Also, this needs to be more than 400 if required to
87 hold the registers (see below, where we round it up based on
88 DEPRECATED_REGISTER_BYTES). */
92 * Descriptor for I/O to remote machine. Initialize it to NULL so that
93 * array_open knows that we don't have a file open when the program starts.
95 struct serial
*array_desc
= NULL
;
98 * this array of registers need to match the indexes used by GDB. The
99 * whole reason this exists is cause the various ROM monitors use
100 * different strings than GDB does, and doesn't support all the
101 * registers either. So, typing "info reg sp" becomes a "r30".
103 extern char *tmp_mips_processor_type
;
104 extern int mips_set_processor_type ();
106 static struct target_ops array_ops
;
109 init_array_ops (void)
111 array_ops
.to_shortname
= "array";
112 array_ops
.to_longname
=
113 "Debug using the standard GDB remote protocol for the Array Tech target.",
115 "Debug using the standard GDB remote protocol for the Array Tech target.\n\
116 Specify the serial device it is connected to (e.g. /dev/ttya).";
117 array_ops
.to_open
= array_open
;
118 array_ops
.to_close
= array_close
;
119 array_ops
.to_detach
= array_detach
;
120 array_ops
.to_resume
= array_resume
;
121 array_ops
.to_wait
= array_wait
;
122 array_ops
.to_fetch_registers
= array_fetch_registers
;
123 array_ops
.to_store_registers
= array_store_registers
;
124 array_ops
.to_prepare_to_store
= array_prepare_to_store
;
125 array_ops
.to_xfer_memory
= array_xfer_memory
;
126 array_ops
.to_files_info
= array_files_info
;
127 array_ops
.to_insert_breakpoint
= array_insert_breakpoint
;
128 array_ops
.to_remove_breakpoint
= array_remove_breakpoint
;
129 array_ops
.to_kill
= array_kill
;
130 array_ops
.to_create_inferior
= array_create_inferior
;
131 array_ops
.to_mourn_inferior
= array_mourn_inferior
;
132 array_ops
.to_stratum
= process_stratum
;
133 array_ops
.to_has_all_memory
= 1;
134 array_ops
.to_has_memory
= 1;
135 array_ops
.to_has_stack
= 1;
136 array_ops
.to_has_registers
= 1;
137 array_ops
.to_has_execution
= 1;
138 array_ops
.to_magic
= OPS_MAGIC
;
142 * printf_monitor -- send data to monitor. Works just like printf.
145 printf_monitor (char *pattern
,...)
151 va_start (args
, pattern
);
153 vsprintf (buf
, pattern
, args
);
155 debuglogs (1, "printf_monitor(), Sending: \"%s\".", buf
);
157 if (strlen (buf
) > PBUFSIZ
)
158 error ("printf_monitor(): string too long");
159 if (serial_write (array_desc
, buf
, strlen (buf
)))
160 fprintf_unfiltered (gdb_stderr
, "serial_write failed: %s\n",
161 safe_strerror (errno
));
164 * write_monitor -- send raw data to monitor.
167 write_monitor (char data
[], int len
)
169 if (serial_write (array_desc
, data
, len
))
170 fprintf_unfiltered (gdb_stderr
, "serial_write failed: %s\n",
171 safe_strerror (errno
));
173 *(data
+ len
+ 1) = '\0';
174 debuglogs (1, "write_monitor(), Sending: \"%s\".", data
);
179 * debuglogs -- deal with debugging info to multiple sources. This takes
180 * two real args, the first one is the level to be compared against
181 * the sr_get_debug() value, the second arg is a printf buffer and args
182 * to be formatted and printed. A CR is added after each string is printed.
185 debuglogs (int level
, char *pattern
,...)
189 unsigned char buf
[PBUFSIZ
];
190 char newbuf
[PBUFSIZ
];
193 va_start (args
, pattern
);
195 if ((level
< 0) || (level
> 100))
197 error ("Bad argument passed to debuglogs(), needs debug level");
201 vsprintf (buf
, pattern
, args
); /* format the string */
203 /* convert some characters so it'll look right in the log */
205 for (i
= 0; buf
[i
] != '\0'; i
++)
208 error ("Debug message too long");
211 case '\n': /* newlines */
215 case '\r': /* carriage returns */
219 case '\033': /* escape */
227 case '\b': /* backspace */
231 default: /* no change */
236 { /* modify control characters */
242 { /* modify control characters */
248 *p
= '\0'; /* terminate the string */
250 if (sr_get_debug () > level
)
251 printf_unfiltered ("%s\n", newbuf
);
253 #ifdef LOG_FILE /* write to the monitor log */
256 fputs (newbuf
, log_file
);
257 fputc ('\n', log_file
);
263 /* readchar -- read a character from the remote system, doing all the fancy
267 readchar (int timeout
)
271 c
= serial_readchar (array_desc
, abs (timeout
));
273 if (sr_get_debug () > 5)
276 debuglogs (5, "readchar: timeout = %d\n", timeout
);
281 putc (c
& 0x7f, log_file
);
287 if (c
== SERIAL_TIMEOUT
)
290 return c
; /* Polls shouldn't generate timeout errors */
291 error ("Timeout reading from remote system.");
293 fputs ("ERROR: Timeout reading from remote system", log_file
);
296 perror_with_name ("readchar");
300 * expect -- scan input from the remote system, until STRING is found.
301 * If DISCARD is non-zero, then discard non-matching input, else print
302 * it out. Let the user break out immediately.
305 expect (char *string
, int discard
)
311 debuglogs (1, "Expecting \"%s\".", string
);
316 c
= readchar (timeout
);
324 debuglogs (4, "Matched");
332 fputc_unfiltered (c
, gdb_stdout
);
339 /* Keep discarding input until we see the MONITOR array_cmds->prompt.
341 The convention for dealing with the expect_prompt is that you
343 o *then* wait for the expect_prompt.
345 Thus the last thing that a procedure does with the serial line
346 will be an expect_prompt(). Exception: array_resume does not
347 wait for the expect_prompt, because the terminal is being handed over
348 to the inferior. However, the next thing which happens after that
349 is a array_wait which does wait for the expect_prompt.
350 Note that this includes abnormal exit, e.g. error(). This is
351 necessary to prevent getting into states from which we can't
354 expect_prompt (int discard
)
356 expect (ARRAY_PROMPT
, discard
);
360 * junk -- ignore junk characters. Returns a 1 if junk, 0 otherwise
373 if (sr_get_debug () > 5)
374 debuglogs (5, "Ignoring \'%c\'.", ch
);
377 if (sr_get_debug () > 5)
378 debuglogs (5, "Accepting \'%c\'.", ch
);
384 * get_hex_digit -- Get a hex digit from the remote system & return its value.
385 * If ignore is nonzero, ignore spaces, newline & tabs.
388 get_hex_digit (int ignore
)
393 ch
= readchar (timeout
);
396 if (sr_get_debug () > 4)
398 debuglogs (4, "get_hex_digit() got a 0x%x(%c)", ch
, ch
);
402 #ifdef LOG_FILE /* write to the monitor log */
405 fputs ("get_hex_digit() got a 0x", log_file
);
406 fputc (ch
, log_file
);
407 fputc ('\n', log_file
);
413 if (ch
>= '0' && ch
<= '9')
415 else if (ch
>= 'A' && ch
<= 'F')
416 return ch
- 'A' + 10;
417 else if (ch
>= 'a' && ch
<= 'f')
418 return ch
- 'a' + 10;
419 else if (ch
== ' ' && ignore
)
424 debuglogs (4, "Invalid hex digit from remote system. (0x%x)", ch
);
425 error ("Invalid hex digit from remote system. (0x%x)", ch
);
430 /* get_hex_byte -- Get a byte from monitor and put it in *BYT.
431 * Accept any number leading spaces.
434 get_hex_byte (char *byt
)
438 val
= get_hex_digit (1) << 4;
439 debuglogs (4, "get_hex_byte() -- Read first nibble 0x%x", val
);
441 val
|= get_hex_digit (0);
442 debuglogs (4, "get_hex_byte() -- Read second nibble 0x%x", val
);
445 debuglogs (4, "get_hex_byte() -- Read a 0x%x", val
);
449 * get_hex_word -- Get N 32-bit words from remote, each preceded by a space,
450 * and put them in registers starting at REGNO.
460 for (i
= 0; i
< 8; i
++)
461 val
= (val
<< 4) + get_hex_digit (i
== 0);
463 debuglogs (4, "get_hex_word() got a 0x%x.", val
);
468 /* This is called not only when we first attach, but also when the
469 user types "run" after having attached. */
471 array_create_inferior (char *execfile
, char *args
, char **env
)
476 error ("Can't pass arguments to remote MONITOR process");
478 if (execfile
== 0 || exec_bfd
== 0)
479 error ("No executable file specified");
481 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
483 /* The "process" (board) is already stopped awaiting our commands, and
484 the program is already downloaded. We just set its PC and go. */
486 clear_proceed_status ();
488 /* Tell wait_for_inferior that we've started a new process. */
489 init_wait_for_inferior ();
491 /* Set up the "saved terminal modes" of the inferior
492 based on what modes we are starting it with. */
493 target_terminal_init ();
495 /* Install inferior's terminal modes. */
496 target_terminal_inferior ();
498 /* insert_step_breakpoint (); FIXME, do we need this? */
501 proceed ((CORE_ADDR
) entry_pt
, TARGET_SIGNAL_DEFAULT
, 0);
505 * array_open -- open a connection to a remote debugger.
506 * NAME is the filename used for communication.
508 static int baudrate
= 9600;
509 static char dev_name
[100];
512 array_open (char *args
, char *name
, int from_tty
)
514 char packet
[PBUFSIZ
];
517 error ("Use `target %s DEVICE-NAME' to use a serial port, or \n\
518 `target %s HOST-NAME:PORT-NUMBER' to use a network connection.", name
, name
);
523 target_preopen (from_tty
);
524 unpush_target (&array_ops
);
526 tmp_mips_processor_type
= "lsi33k"; /* change the default from r3051 */
527 mips_set_processor_type_command ("lsi33k", 0);
529 strcpy (dev_name
, args
);
530 array_desc
= serial_open (dev_name
);
532 if (array_desc
== NULL
)
533 perror_with_name (dev_name
);
537 if (serial_setbaudrate (array_desc
, baud_rate
))
539 serial_close (array_desc
);
540 perror_with_name (name
);
544 serial_raw (array_desc
);
546 #if defined (LOG_FILE)
547 log_file
= fopen (LOG_FILE
, "w");
548 if (log_file
== NULL
)
549 perror_with_name (LOG_FILE
);
550 fprintf (log_file
, "GDB %s (%s", version
, host_name
);
551 fprintf (log_file
, " --target %s)\n", array_ops
.to_shortname
);
552 fprintf (log_file
, "Remote target %s connected to %s\n\n", array_ops
.to_shortname
, dev_name
);
555 /* see if the target is alive. For a ROM monitor, we can just try to force the
556 expect_prompt to print a few times. For the GDB remote protocol, the application
557 being debugged is sitting at a breakpoint and waiting for GDB to initialize
558 the connection. We force it to give us an empty packet to see if it's alive.
560 debuglogs (3, "Trying to ACK the target's debug stub");
561 /* unless your are on the new hardware, the old board won't initialize
562 because the '@' doesn't flush output like it does on the new ROMS.
564 printf_monitor ("@"); /* ask for the last signal */
565 expect_prompt (1); /* See if we get a expect_prompt */
566 #ifdef TEST_ARRAY /* skip packet for testing */
567 make_gdb_packet (packet
, "?"); /* ask for a bogus packet */
568 if (array_send_packet (packet
) == 0)
569 error ("Couldn't transmit packet\n");
570 printf_monitor ("@\n"); /* force it to flush stdout */
571 expect_prompt (1); /* See if we get a expect_prompt */
573 push_target (&array_ops
);
575 printf ("Remote target %s connected to %s\n", array_ops
.to_shortname
, dev_name
);
579 * array_close -- Close out all files and local state before this
580 * target loses control.
584 array_close (int quitting
)
586 serial_close (array_desc
);
589 debuglogs (1, "array_close (quitting=%d)", quitting
);
591 #if defined (LOG_FILE)
594 if (ferror (log_file
))
595 printf_filtered ("Error writing log file.\n");
596 if (fclose (log_file
) != 0)
597 printf_filtered ("Error closing log file.\n");
603 * array_detach -- terminate the open connection to the remote
604 * debugger. Use this when you want to detach and do something
605 * else with your gdb.
608 array_detach (int from_tty
)
611 debuglogs (1, "array_detach ()");
613 pop_target (); /* calls array_close to do the real work */
615 printf ("Ending remote %s debugging\n", target_shortname
);
619 * array_attach -- attach GDB to the target.
622 array_attach (char *args
, int from_tty
)
625 printf ("Starting remote %s debugging\n", target_shortname
);
627 debuglogs (1, "array_attach (args=%s)", args
);
629 printf_monitor ("go %x\n");
630 /* swallow the echo. */
631 expect ("go %x\n", 1);
635 * array_resume -- Tell the remote machine to resume.
638 array_resume (ptid_t ptid
, int step
, enum target_signal sig
)
640 debuglogs (1, "array_resume (step=%d, sig=%d)", step
, sig
);
644 printf_monitor ("s\n");
648 printf_monitor ("go\n");
655 * array_wait -- Wait until the remote machine stops, then return,
656 * storing status in status just as `wait' would.
659 array_wait (ptid_t ptid
, struct target_waitstatus
*status
)
661 int old_timeout
= timeout
;
664 struct serial
*tty_desc
;
665 serial_ttystate ttystate
;
667 debuglogs (1, "array_wait (), printing extraneous text.");
669 status
->kind
= TARGET_WAITKIND_EXITED
;
670 status
->value
.integer
= 0;
672 timeout
= 0; /* Don't time out -- user program is running. */
674 #if !defined(__GO32__) && !defined(__MSDOS__) && !defined(_WIN32)
675 tty_desc
= serial_fdopen (0);
676 ttystate
= serial_get_tty_state (tty_desc
);
677 serial_raw (tty_desc
);
680 /* poll on the serial port and the keyboard. */
683 c
= readchar (timeout
);
686 if (c
== *(ARRAY_PROMPT
+ i
))
688 if (++i
>= strlen (ARRAY_PROMPT
))
689 { /* matched the prompt */
690 debuglogs (4, "array_wait(), got the expect_prompt.");
695 { /* not the prompt */
698 fputc_unfiltered (c
, gdb_stdout
);
699 gdb_flush (gdb_stdout
);
701 c
= serial_readchar (tty_desc
, timeout
);
704 serial_write (array_desc
, &c
, 1);
705 /* do this so it looks like there's keyboard echo */
706 if (c
== 3) /* exit on Control-C */
709 fputc_unfiltered (c
, gdb_stdout
);
710 gdb_flush (gdb_stdout
);
714 serial_set_tty_state (tty_desc
, ttystate
);
717 debuglogs (4, "array_wait(), got the expect_prompt.");
720 status
->kind
= TARGET_WAITKIND_STOPPED
;
721 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
723 timeout
= old_timeout
;
725 return inferior_ptid
;
729 * array_fetch_registers -- read the remote registers into the
733 array_fetch_registers (int ignored
)
735 char reg
[MAX_REGISTER_SIZE
];
738 char *packet
= alloca (PBUFSIZ
);
740 debuglogs (1, "array_fetch_registers (ignored=%d)\n", ignored
);
742 memset (packet
, 0, PBUFSIZ
);
743 make_gdb_packet (packet
, "g");
744 if (array_send_packet (packet
) == 0)
745 error ("Couldn't transmit packet\n");
746 if (array_get_packet (packet
) == 0)
747 error ("Couldn't receive packet\n");
748 /* FIXME: read bytes from packet */
749 debuglogs (4, "array_fetch_registers: Got a \"%s\" back\n", packet
);
750 for (regno
= 0; regno
<= PC_REGNUM
+ 4; regno
++)
752 /* supply register stores in target byte order, so swap here */
753 /* FIXME: convert from ASCII hex to raw bytes */
754 LONGEST i
= ascii2hexword (packet
+ (regno
* 8));
755 debuglogs (5, "Adding register %d = %x\n", regno
, i
);
756 store_unsigned_integer (®
, REGISTER_RAW_SIZE (regno
), i
);
757 supply_register (regno
, (char *) ®
);
762 * This is unused by targets like this one that use a
763 * protocol based on GDB's remote protocol.
766 array_fetch_register (int ignored
)
768 array_fetch_registers (0 /* ignored */);
772 * Get all the registers from the targets. They come back in a large array.
775 array_store_registers (int ignored
)
779 char packet
[PBUFSIZ
];
783 debuglogs (1, "array_store_registers()");
785 memset (packet
, 0, PBUFSIZ
);
786 memset (buf
, 0, PBUFSIZ
);
789 /* Unimplemented registers read as all bits zero. */
790 /* FIXME: read bytes from packet */
791 for (regno
= 0; regno
< 41; regno
++)
793 /* supply register stores in target byte order, so swap here */
794 /* FIXME: convert from ASCII hex to raw bytes */
795 i
= (unsigned long) read_register (regno
);
796 hexword2ascii (num
, i
);
797 strcpy (buf
+ (regno
* 8) + 1, num
);
799 *(buf
+ (regno
* 8) + 2) = 0;
800 make_gdb_packet (packet
, buf
);
801 if (array_send_packet (packet
) == 0)
802 error ("Couldn't transmit packet\n");
803 if (array_get_packet (packet
) == 0)
804 error ("Couldn't receive packet\n");
806 registers_changed ();
810 * This is unused by targets like this one that use a
811 * protocol based on GDB's remote protocol.
814 array_store_register (int ignored
)
816 array_store_registers (0 /* ignored */);
819 /* Get ready to modify the registers array. On machines which store
820 individual registers, this doesn't need to do anything. On machines
821 which store all the registers in one fell swoop, this makes sure
822 that registers contains all the registers from the program being
826 array_prepare_to_store (void)
828 /* Do nothing, since we can store individual regs */
832 array_files_info (void)
834 printf ("\tAttached to %s at %d baud.\n",
839 * array_write_inferior_memory -- Copy LEN bytes of data from debugger
840 * memory at MYADDR to inferior's memory at MEMADDR. Returns length moved.
843 array_write_inferior_memory (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
)
847 char packet
[PBUFSIZ
];
852 debuglogs (1, "array_write_inferior_memory (memaddr=0x%x, myaddr=0x%x, len=%d)", memaddr
, myaddr
, len
);
853 memset (buf
, '\0', PBUFSIZ
); /* this also sets the string terminator */
856 *p
++ = 'M'; /* The command to write memory */
857 hexword2ascii (num
, memaddr
); /* convert the address */
858 strcpy (p
, num
); /* copy the address */
860 *p
++ = ','; /* add comma delimeter */
861 hexword2ascii (num
, len
); /* Get the length as a 4 digit number */
866 *p
++ = ':'; /* add the colon delimeter */
867 for (j
= 0; j
< len
; j
++)
868 { /* copy the data in after converting it */
869 *p
++ = tohex ((myaddr
[j
] >> 4) & 0xf);
870 *p
++ = tohex (myaddr
[j
] & 0xf);
873 make_gdb_packet (packet
, buf
);
874 if (array_send_packet (packet
) == 0)
875 error ("Couldn't transmit packet\n");
876 if (array_get_packet (packet
) == 0)
877 error ("Couldn't receive packet\n");
883 * array_read_inferior_memory -- read LEN bytes from inferior memory
884 * at MEMADDR. Put the result at debugger address MYADDR. Returns
888 array_read_inferior_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
892 char packet
[PBUFSIZ
];
893 int count
; /* Number of bytes read so far. */
894 unsigned long startaddr
; /* Starting address of this pass. */
895 int len_this_pass
; /* Number of bytes to read in this pass. */
897 debuglogs (1, "array_read_inferior_memory (memaddr=0x%x, myaddr=0x%x, len=%d)", memaddr
, myaddr
, len
);
899 /* Note that this code works correctly if startaddr is just less
900 than UINT_MAX (well, really CORE_ADDR_MAX if there was such a
901 thing). That is, something like
902 array_read_bytes (CORE_ADDR_MAX - 4, foo, 4)
903 works--it never adds len To memaddr and gets 0. */
904 /* However, something like
905 array_read_bytes (CORE_ADDR_MAX - 3, foo, 4)
906 doesn't need to work. Detect it and give up if there's an attempt
908 if (((memaddr
- 1) + len
) < memaddr
)
914 for (count
= 0, startaddr
= memaddr
; count
< len
; startaddr
+= len_this_pass
)
916 /* Try to align to 16 byte boundry (why?) */
918 if ((startaddr
% 16) != 0)
920 len_this_pass
-= startaddr
% 16;
922 /* Only transfer bytes we need */
923 if (len_this_pass
> (len
- count
))
925 len_this_pass
= (len
- count
);
927 /* Fetch the bytes */
928 debuglogs (3, "read %d bytes from inferior address %x", len_this_pass
,
930 sprintf (buf
, "m%08lx,%04x", startaddr
, len_this_pass
);
931 make_gdb_packet (packet
, buf
);
932 if (array_send_packet (packet
) == 0)
934 error ("Couldn't transmit packet\n");
936 if (array_get_packet (packet
) == 0)
938 error ("Couldn't receive packet\n");
942 error ("Got no data in the GDB packet\n");
944 /* Pick packet apart and xfer bytes to myaddr */
945 debuglogs (4, "array_read_inferior_memory: Got a \"%s\" back\n", packet
);
946 for (j
= 0; j
< len_this_pass
; j
++)
948 /* extract the byte values */
949 myaddr
[count
++] = from_hex (*(packet
+ (j
* 2))) * 16 + from_hex (*(packet
+ (j
* 2) + 1));
950 debuglogs (5, "myaddr[%d] set to %x\n", count
- 1, myaddr
[count
- 1]);
956 /* Transfer LEN bytes between GDB address MYADDR and target address
957 MEMADDR. If WRITE is non-zero, transfer them to the target,
958 otherwise transfer them from the target. TARGET is unused.
960 Returns the number of bytes transferred. */
963 array_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
964 struct mem_attrib
*attrib
, struct target_ops
*target
)
967 return array_write_inferior_memory (memaddr
, myaddr
, len
);
969 return array_read_inferior_memory (memaddr
, myaddr
, len
);
973 array_kill (char *args
, int from_tty
)
975 return; /* ignore attempts to kill target system */
978 /* Clean up when a program exits.
979 The program actually lives on in the remote processor's RAM, and may be
980 run again without a download. Don't leave it full of breakpoint
984 array_mourn_inferior (void)
986 remove_breakpoints ();
987 generic_mourn_inferior (); /* Do all the proper things now */
990 #define MAX_ARRAY_BREAKPOINTS 16
992 static CORE_ADDR breakaddr
[MAX_ARRAY_BREAKPOINTS
] =
996 * array_insert_breakpoint -- add a breakpoint
999 array_insert_breakpoint (CORE_ADDR addr
, char *shadow
)
1003 CORE_ADDR bp_addr
= addr
;
1005 debuglogs (1, "array_insert_breakpoint() addr = 0x%x", addr
);
1006 BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
);
1008 for (i
= 0; i
<= MAX_ARRAY_BREAKPOINTS
; i
++)
1010 if (breakaddr
[i
] == 0)
1012 breakaddr
[i
] = addr
;
1013 if (sr_get_debug () > 4)
1014 printf ("Breakpoint at %s\n", paddr_nz (addr
));
1015 array_read_inferior_memory (bp_addr
, shadow
, bp_size
);
1016 printf_monitor ("b 0x%x\n", addr
);
1022 fprintf_unfiltered (gdb_stderr
, "Too many breakpoints (> 16) for monitor\n");
1027 * _remove_breakpoint -- Tell the monitor to remove a breakpoint
1030 array_remove_breakpoint (CORE_ADDR addr
, char *shadow
)
1034 debuglogs (1, "array_remove_breakpoint() addr = 0x%x", addr
);
1036 for (i
= 0; i
< MAX_ARRAY_BREAKPOINTS
; i
++)
1038 if (breakaddr
[i
] == addr
)
1041 /* some monitors remove breakpoints based on the address */
1042 printf_monitor ("bd %x\n", i
);
1047 fprintf_unfiltered (gdb_stderr
,
1048 "Can't find breakpoint associated with 0x%s\n",
1056 debuglogs (1, "array_stop()");
1057 printf_monitor ("\003");
1062 * array_command -- put a command string, in args, out to MONITOR.
1063 * Output from MONITOR is placed on the users terminal until the
1064 * expect_prompt is seen. FIXME
1067 monitor_command (char *args
, int fromtty
)
1069 debuglogs (1, "monitor_command (args=%s)", args
);
1071 if (array_desc
== NULL
)
1072 error ("monitor target not open.");
1075 error ("Missing command.");
1077 printf_monitor ("%s\n", args
);
1082 * make_gdb_packet -- make a GDB packet. The data is always ASCII.
1083 * A debug packet whose contents are <data>
1084 * is encapsulated for transmission in the form:
1086 * $ <data> # CSUM1 CSUM2
1088 * <data> must be ASCII alphanumeric and cannot include characters
1089 * '$' or '#'. If <data> starts with two characters followed by
1090 * ':', then the existing stubs interpret this as a sequence number.
1092 * CSUM1 and CSUM2 are ascii hex representation of an 8-bit
1093 * checksum of <data>, the most significant nibble is sent first.
1094 * the hex digits 0-9,a-f are used.
1098 make_gdb_packet (char *buf
, char *data
)
1101 unsigned char csum
= 0;
1105 debuglogs (3, "make_gdb_packet(%s)\n", data
);
1106 cnt
= strlen (data
);
1108 error ("make_gdb_packet(): to much data\n");
1110 /* start with the packet header */
1114 /* calculate the checksum */
1115 for (i
= 0; i
< cnt
; i
++)
1121 /* terminate the data with a '#' */
1124 /* add the checksum as two ascii digits */
1125 *p
++ = tohex ((csum
>> 4) & 0xf);
1126 *p
++ = tohex (csum
& 0xf);
1127 *p
= 0x0; /* Null terminator on string */
1131 * array_send_packet -- send a GDB packet to the target with error handling. We
1132 * get a '+' (ACK) back if the packet is received and the checksum
1133 * matches. Otherwise a '-' (NAK) is returned. It returns a 1 for a
1134 * successful transmition, or a 0 for a failure.
1137 array_send_packet (char *packet
)
1145 /* scan the packet to make sure it only contains valid characters.
1146 this may sound silly, but sometimes a garbled packet will hang
1147 the target board. We scan the whole thing, then print the error
1150 for (i
= 0; i
< strlen (packet
); i
++)
1152 debuglogs (5, "array_send_packet(): Scanning \'%c\'\n", packet
[i
]);
1153 /* legit hex numbers or command */
1154 if ((isxdigit (packet
[i
])) || (isalpha (packet
[i
])))
1160 case '#': /* end of packet */
1161 case '$': /* start of packet */
1163 default: /* bogus character */
1165 debuglogs (4, "array_send_packet(): Found a non-ascii digit \'%c\' in the packet.\n", packet
[i
]);
1171 error ("Can't send packet, found %d non-ascii characters", retries
);
1173 /* ok, try to send the packet */
1175 while (retries
++ <= 10)
1177 printf_monitor ("%s", packet
);
1179 /* read until either a timeout occurs (-2) or '+' is read */
1180 while (retries
<= 10)
1182 c
= readchar (-timeout
);
1183 debuglogs (3, "Reading a GDB protocol packet... Got a '%c'\n", c
);
1187 debuglogs (3, "Got Ack\n");
1189 case SERIAL_TIMEOUT
:
1190 debuglogs (3, "Timed out reading serial port\n");
1191 printf_monitor ("@"); /* resync with the monitor */
1192 expect_prompt (1); /* See if we get a expect_prompt */
1193 break; /* Retransmit buffer */
1195 debuglogs (3, "Got NAK\n");
1196 printf_monitor ("@"); /* resync with the monitor */
1197 expect_prompt (1); /* See if we get a expect_prompt */
1200 /* it's probably an old response, or the echo of our command.
1201 * just gobble up the packet and ignore it.
1203 debuglogs (3, "Got a junk packet\n");
1207 c
= readchar (timeout
);
1211 c
= readchar (timeout
);
1213 c
= readchar (timeout
);
1216 debuglogs (3, "Reading a junk packet, got a \"%s\"\n", junk
);
1217 continue; /* Now, go look for next packet */
1222 debuglogs (3, "Retransmitting packet \"%s\"\n", packet
);
1223 break; /* Here to retransmit */
1230 * array_get_packet -- get a GDB packet from the target. Basically we read till we
1231 * see a '#', then check the checksum. It returns a 1 if it's gotten a
1232 * packet, or a 0 it the packet wasn't transmitted correctly.
1235 array_get_packet (char *packet
)
1240 unsigned char pktcsum
;
1246 memset (packet
, 1, PBUFSIZ
);
1248 while (retries
<= 10)
1252 c
= readchar (timeout
);
1253 if (c
== SERIAL_TIMEOUT
)
1255 debuglogs (3, "array_get_packet: got time out from serial port.\n");
1257 debuglogs (3, "Waiting for a '$', got a %c\n", c
);
1262 while (retries
<= 10)
1264 c
= readchar (timeout
);
1265 debuglogs (3, "array_get_packet: got a '%c'\n", c
);
1268 case SERIAL_TIMEOUT
:
1269 debuglogs (3, "Timeout in mid-packet, retrying\n");
1272 debuglogs (3, "Saw new packet start in middle of old one\n");
1273 return 0; /* Start a new packet, count retries */
1276 pktcsum
= from_hex (readchar (timeout
)) << 4;
1277 pktcsum
|= from_hex (readchar (timeout
));
1279 debuglogs (3, "\nGDB packet checksum zero, must be a bogus packet\n");
1280 if (csum
== pktcsum
)
1282 debuglogs (3, "\nGDB packet checksum correct, packet data is \"%s\",\n", packet
);
1283 printf_monitor ("@");
1287 debuglogs (3, "Bad checksum, sentsum=0x%x, csum=0x%x\n", pktcsum
, csum
);
1289 case '*': /* Run length encoding */
1290 debuglogs (5, "Run length encoding in packet\n");
1292 c
= readchar (timeout
);
1294 c
= c
- ' ' + 3; /* Compute repeat count */
1296 if (c
> 0 && c
< 255 && bp
+ c
- 1 < packet
+ PBUFSIZ
- 1)
1298 memset (bp
, *(bp
- 1), c
);
1303 printf_filtered ("Repeat count %d too large for buffer.\n", c
);
1307 if ((!isxdigit (c
)) && (!ispunct (c
)))
1308 debuglogs (4, "Got a non-ascii digit \'%c\'.\\n", c
);
1309 if (bp
< packet
+ PBUFSIZ
- 1)
1317 puts_filtered ("Remote packet too long.\n");
1322 return 0; /* exceeded retries */
1326 * ascii2hexword -- convert an ascii number represented by 8 digits to a hex value.
1328 static unsigned long
1329 ascii2hexword (unsigned char *mem
)
1336 for (i
= 0; i
< 8; i
++)
1339 if (mem
[i
] >= 'A' && mem
[i
] <= 'F')
1340 val
= val
+ mem
[i
] - 'A' + 10;
1341 if (mem
[i
] >= 'a' && mem
[i
] <= 'f')
1342 val
= val
+ mem
[i
] - 'a' + 10;
1343 if (mem
[i
] >= '0' && mem
[i
] <= '9')
1344 val
= val
+ mem
[i
] - '0';
1348 debuglogs (4, "ascii2hexword() got a 0x%x from %s(%x).\n", val
, buf
, mem
);
1353 * ascii2hexword -- convert a hex value to an ascii number represented by 8
1357 hexword2ascii (unsigned char *mem
, unsigned long num
)
1362 debuglogs (4, "hexword2ascii() converting %x ", num
);
1363 for (i
= 7; i
>= 0; i
--)
1365 mem
[i
] = tohex ((num
>> 4) & 0xf);
1366 mem
[i
] = tohex (num
& 0xf);
1370 debuglogs (4, "\tto a %s", mem
);
1373 /* Convert hex digit A to a number. */
1380 debuglogs (4, "from_hex got a 0x%x(%c)\n", a
, a
);
1381 if (a
>= '0' && a
<= '9')
1383 if (a
>= 'a' && a
<= 'f')
1384 return a
- 'a' + 10;
1385 if (a
>= 'A' && a
<= 'F')
1386 return a
- 'A' + 10;
1389 error ("Reply contains invalid hex digit 0x%x", a
);
1393 /* Convert number NIB to a hex digit. */
1400 return 'a' + nib
- 10;
1404 * _initialize_remote_monitors -- setup a few addtitional commands that
1405 * are usually only used by monitors.
1408 _initialize_remote_monitors (void)
1410 /* generic monitor command */
1411 add_com ("monitor", class_obscure
, monitor_command
,
1412 "Send a command to the debug monitor.");
1417 * _initialize_array -- do any special init stuff for the target.
1420 _initialize_array (void)
1423 add_target (&array_ops
);
This page took 0.08355 seconds and 4 git commands to generate.