1 /* Remote debugging interface for Array Tech RAID controller..
2 Copyright 90, 91, 92, 93, 94, 1995 Free Software Foundation, Inc.
3 Contributed by Cygnus Support. Written by Rob Savoye for Cygnus.
5 This module talks to a debug monitor called 'MONITOR', which
6 We communicate with MONITOR via either a direct serial line, or a TCP
7 (or possibly TELNET) stream to a terminal multiplexor,
8 which in turn talks to the target board.
10 This file is part of GDB.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 #ifdef ANSI_PROTOTYPES
38 #include <sys/types.h>
42 #include "remote-utils.h"
46 static const char hexchars
[]="0123456789abcdef";
47 static char *hex2mem();
51 #define SWAP_TARGET_AND_HOST(buffer,len) \
54 if (TARGET_BYTE_ORDER != HOST_BYTE_ORDER) \
57 char *p = (char *)(buffer); \
58 char *q = ((char *)(buffer)) + len - 1; \
59 for (; p < q; p++, q--) \
69 static void debuglogs
PARAMS((int, char *, ...));
70 static void array_open();
71 static void array_close();
72 static void array_detach();
73 static void array_attach();
74 static void array_resume();
75 static void array_fetch_register();
76 static void array_store_register();
77 static void array_fetch_registers();
78 static void array_store_registers();
79 static void array_prepare_to_store();
80 static void array_files_info();
81 static void array_kill();
82 static void array_create_inferior();
83 static void array_mourn_inferior();
84 static void make_gdb_packet();
85 static int array_xfer_memory();
86 static int array_wait();
87 static int array_insert_breakpoint();
88 static int array_remove_breakpoint();
91 static int from_hex();
92 static int array_send_packet();
93 static int array_get_packet();
94 static unsigned long ascii2hexword();
95 static char *hexword2ascii();
99 #define LOG_FILE "monitor.log"
100 #if defined (LOG_FILE)
104 static int timeout
= 30;
105 /* Having this larger than 400 causes us to be incompatible with m68k-stub.c
106 and i386-stub.c. Normally, no one would notice because it only matters
107 for writing large chunks of memory (e.g. in downloads). Also, this needs
108 to be more than 400 if required to hold the registers (see below, where
109 we round it up based on REGISTER_BYTES). */
113 * Descriptor for I/O to remote machine. Initialize it to NULL so that
114 * array_open knows that we don't have a file open when the program starts.
116 serial_t array_desc
= NULL
;
119 * this array of registers need to match the indexes used by GDB. The
120 * whole reason this exists is cause the various ROM monitors use
121 * different strings than GDB does, and doesn't support all the
122 * registers either. So, typing "info reg sp" becomes a "r30".
124 extern char *tmp_mips_processor_type
;
125 extern int mips_set_processor_type();
127 static struct target_ops array_ops
= {
128 "array", /* to_shortname */
130 "Debug using the standard GDB remote protocol for the Array Tech target.",
132 "Debug using the standard GDB remote protocol for the Array Tech target.\n\
133 Specify the serial device it is connected to (e.g. /dev/ttya).",
134 array_open
, /* to_open */
135 array_close
, /* to_close */
136 NULL
, /* to_attach */
137 array_detach
, /* to_detach */
138 array_resume
, /* to_resume */
139 array_wait
, /* to_wait */
140 array_fetch_registers
, /* to_fetch_registers */
141 array_store_registers
, /* to_store_registers */
142 array_prepare_to_store
, /* to_prepare_to_store */
143 array_xfer_memory
, /* to_xfer_memory */
144 array_files_info
, /* to_files_info */
145 array_insert_breakpoint
, /* to_insert_breakpoint */
146 array_remove_breakpoint
, /* to_remove_breakpoint */
147 0, /* to_terminal_init */
148 0, /* to_terminal_inferior */
149 0, /* to_terminal_ours_for_output */
150 0, /* to_terminal_ours */
151 0, /* to_terminal_info */
152 array_kill
, /* to_kill */
154 0, /* to_lookup_symbol */
155 array_create_inferior
, /* to_create_inferior */
156 array_mourn_inferior
, /* to_mourn_inferior */
158 0, /* to_notice_signals */
160 process_stratum
, /* to_stratum */
162 1, /* to_has_all_memory */
163 1, /* to_has_memory */
164 1, /* to_has_stack */
165 1, /* to_has_registers */
166 1, /* to_has_execution */
168 0, /* sections_end */
169 OPS_MAGIC
/* to_magic */
173 * printf_monitor -- send data to monitor. Works just like printf.
176 #ifdef ANSI_PROTOTYPES
177 printf_monitor(char *pattern
, ...)
179 printf_monitor(va_alist
)
187 #ifdef ANSI_PROTOTYPES
188 va_start(args
, pattern
);
192 pattern
= va_arg(args
, char *);
195 vsprintf(buf
, pattern
, args
);
197 debuglogs (1, "printf_monitor(), Sending: \"%s\".", buf
);
199 if (strlen(buf
) > PBUFSIZ
)
200 error ("printf_monitor(): string too long");
201 if (SERIAL_WRITE(array_desc
, buf
, strlen(buf
)))
202 fprintf(stderr
, "SERIAL_WRITE failed: %s\n", safe_strerror(errno
));
205 * write_monitor -- send raw data to monitor.
208 write_monitor(data
, len
)
212 if (SERIAL_WRITE(array_desc
, data
, len
))
213 fprintf(stderr
, "SERIAL_WRITE failed: %s\n", safe_strerror(errno
));
215 *(data
+ len
+1) = '\0';
216 debuglogs (1, "write_monitor(), Sending: \"%s\".", data
);
221 * debuglogs -- deal with debugging info to multiple sources. This takes
222 * two real args, the first one is the level to be compared against
223 * the sr_get_debug() value, the second arg is a printf buffer and args
224 * to be formatted and printed. A CR is added after each string is printed.
227 #ifdef ANSI_PROTOTYPES
228 debuglogs(int level
, char *pattern
, ...)
236 unsigned char buf
[PBUFSIZ
];
237 char newbuf
[PBUFSIZ
];
240 #ifdef ANSI_PROTOTYPES
241 va_start(args
, pattern
);
246 level
= va_arg(args
, int); /* get the debug level */
247 pattern
= va_arg(args
, char *); /* get the printf style pattern */
250 if ((level
<0) || (level
> 100)) {
251 error ("Bad argument passed to debuglogs(), needs debug level");
255 vsprintf(buf
, pattern
, args
); /* format the string */
257 /* convert some characters so it'll look right in the log */
259 for (i
= 0 ; buf
[i
] != '\0'; i
++) {
261 error ("Debug message too long");
263 case '\n': /* newlines */
267 case '\r': /* carriage returns */
271 case '\033': /* escape */
279 case '\b': /* backspace */
283 default: /* no change */
287 if (buf
[i
] < 26) { /* modify control characters */
292 if (buf
[i
] >= 128) { /* modify control characters */
298 *p
= '\0'; /* terminate the string */
300 if (sr_get_debug() > level
)
301 printf_unfiltered ("%s\n", newbuf
);
303 #ifdef LOG_FILE /* write to the monitor log */
304 if (log_file
!= 0x0) {
305 fputs (newbuf
, log_file
);
306 fputc ('\n', log_file
);
312 /* readchar -- read a character from the remote system, doing all the fancy
321 c
= SERIAL_READCHAR(array_desc
, abs(timeout
));
323 if (sr_get_debug() > 5) {
325 debuglogs (5, "readchar: timeout = %d\n", timeout
);
330 putc(c
& 0x7f, log_file
);
336 if (c
== SERIAL_TIMEOUT
) {
338 return c
; /* Polls shouldn't generate timeout errors */
339 error("Timeout reading from remote system.");
341 fputs ("ERROR: Timeout reading from remote system", log_file
);
344 perror_with_name("readchar");
348 * expect -- scan input from the remote system, until STRING is found.
349 * If DISCARD is non-zero, then discard non-matching input, else print
350 * it out. Let the user break out immediately.
353 expect (string
, discard
)
361 debuglogs (1, "Expecting \"%s\".", string
);
365 c
= readchar(timeout
);
371 debuglogs (4, "Matched");
376 fputc_unfiltered (c
, gdb_stdout
);
383 /* Keep discarding input until we see the MONITOR array_cmds->prompt.
385 The convention for dealing with the expect_prompt is that you
387 o *then* wait for the expect_prompt.
389 Thus the last thing that a procedure does with the serial line
390 will be an expect_prompt(). Exception: array_resume does not
391 wait for the expect_prompt, because the terminal is being handed over
392 to the inferior. However, the next thing which happens after that
393 is a array_wait which does wait for the expect_prompt.
394 Note that this includes abnormal exit, e.g. error(). This is
395 necessary to prevent getting into states from which we can't
398 expect_prompt(discard
)
401 expect (expect_prompt
, discard
);
405 * junk -- ignore junk characters. Returns a 1 if junk, 0 otherwise
418 if (sr_get_debug() > 5)
419 debuglogs (5, "Ignoring \'%c\'.", ch
);
422 if (sr_get_debug() > 5)
423 debuglogs (5, "Accepting \'%c\'.", ch
);
429 * get_hex_digit -- Get a hex digit from the remote system & return its value.
430 * If ignore is nonzero, ignore spaces, newline & tabs.
433 get_hex_digit(ignore
)
438 ch
= readchar(timeout
);
441 if (sr_get_debug() > 4) {
442 debuglogs (4, "get_hex_digit() got a 0x%x(%c)", ch
, ch
);
444 #ifdef LOG_FILE /* write to the monitor log */
445 if (log_file
!= 0x0) {
446 fputs ("get_hex_digit() got a 0x", log_file
);
447 fputc (ch
, log_file
);
448 fputc ('\n', log_file
);
454 if (ch
>= '0' && ch
<= '9')
456 else if (ch
>= 'A' && ch
<= 'F')
457 return ch
- 'A' + 10;
458 else if (ch
>= 'a' && ch
<= 'f')
459 return ch
- 'a' + 10;
460 else if (ch
== ' ' && ignore
)
464 debuglogs (4, "Invalid hex digit from remote system. (0x%x)", ch
);
465 error("Invalid hex digit from remote system. (0x%x)", ch
);
470 /* get_hex_byte -- Get a byte from monitor and put it in *BYT.
471 * Accept any number leading spaces.
479 val
= get_hex_digit (1) << 4;
480 debuglogs (4, "get_hex_byte() -- Read first nibble 0x%x", val
);
482 val
|= get_hex_digit (0);
483 debuglogs (4, "get_hex_byte() -- Read second nibble 0x%x", val
);
486 debuglogs (4, "get_hex_byte() -- Read a 0x%x", val
);
490 * get_hex_word -- Get N 32-bit words from remote, each preceded by a space,
491 * and put them in registers starting at REGNO.
502 if (HOST_BYTE_ORDER
== BIG_ENDIAN
) {
504 for (i
= 0; i
< 8; i
++)
505 val
= (val
<< 4) + get_hex_digit (i
== 0);
508 for (i
= 7; i
>= 0; i
--)
509 val
= (val
<< 4) + get_hex_digit (i
== 0);
513 debuglogs (4, "get_hex_word() got a 0x%x for a %s host.", val
, (HOST_BYTE_ORDER
== BIG_ENDIAN
) ? "big endian" : "little endian");
518 /* This is called not only when we first attach, but also when the
519 user types "run" after having attached. */
521 array_create_inferior (execfile
, args
, env
)
529 error("Can't pass arguments to remote MONITOR process");
531 if (execfile
== 0 || exec_bfd
== 0)
532 error("No exec file specified");
534 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
536 /* The "process" (board) is already stopped awaiting our commands, and
537 the program is already downloaded. We just set its PC and go. */
539 clear_proceed_status ();
541 /* Tell wait_for_inferior that we've started a new process. */
542 init_wait_for_inferior ();
544 /* Set up the "saved terminal modes" of the inferior
545 based on what modes we are starting it with. */
546 target_terminal_init ();
548 /* Install inferior's terminal modes. */
549 target_terminal_inferior ();
551 /* insert_step_breakpoint (); FIXME, do we need this? */
554 proceed ((CORE_ADDR
)entry_pt
, TARGET_SIGNAL_DEFAULT
, 0);
558 * array_open -- open a connection to a remote debugger.
559 * NAME is the filename used for communication.
561 static int baudrate
= 9600;
562 static char dev_name
[100];
565 array_open(args
, name
, from_tty
)
570 char packet
[PBUFSIZ
];
573 error ("Use `target %s DEVICE-NAME' to use a serial port, or \n\
574 `target %s HOST-NAME:PORT-NUMBER' to use a network connection.", name
, name
);
579 tmp_mips_processor_type
= "lsi33k"; /* change the default from r3051 */
580 mips_set_processor_type_command ("lsi33k", 0);
582 strcpy(dev_name
, args
);
583 array_desc
= SERIAL_OPEN(dev_name
);
585 if (array_desc
== NULL
)
586 perror_with_name(dev_name
);
588 if (baud_rate
!= -1) {
589 if (SERIAL_SETBAUDRATE (array_desc
, baud_rate
)) {
590 SERIAL_CLOSE (array_desc
);
591 perror_with_name (name
);
595 SERIAL_RAW(array_desc
);
597 #if defined (LOG_FILE)
598 log_file
= fopen (LOG_FILE
, "w");
599 if (log_file
== NULL
)
600 perror_with_name (LOG_FILE
);
601 fprintf_filtered (log_file
, "GDB %s (%s", version
);
602 fprintf_filtered (log_file
, " --target %s)\n", array_ops
.to_shortname
);
603 fprintf_filtered (log_file
, "Remote target %s connected to %s\n\n", array_ops
.to_shortname
, dev_name
);
606 /* see if the target is alive. For a ROM monitor, we can just try to force the
607 expect_prompt to print a few times. For the GDB remote protocol, the application
608 being debugged is sitting at a breakpoint and waiting for GDB to initialize
609 the connection. We force it to give us an empty packet to see if it's alive.
611 debuglogs (3, "Trying to ACK the target's debug stub");
612 /* unless your are on the new hardware, the old board won't initialize
613 because the '+' doesn't flush output like it does on the new ROMS.
615 printf_monitor ("+"); /* ask for the last signal */
616 expect_prompt(1); /* See if we get a expect_prompt */
617 make_gdb_packet (packet
, "?"); /* ask for a bogus packet */
618 if (array_send_packet (packet
) == 0)
619 error ("Couldn't transmit packet\n");
620 printf_monitor ("+\n"); /* force it to flush stdout */
621 expect_prompt(1); /* See if we get a expect_prompt */
624 printf("Remote target %s connected to %s\n", array_ops
.to_shortname
, dev_name
);
628 * array_close -- Close out all files and local state before this
629 * target loses control.
633 array_close (quitting
)
636 SERIAL_CLOSE(array_desc
);
639 debuglogs (1, "array_close (quitting=%d)", quitting
);
641 #if defined (LOG_FILE)
643 if (ferror(log_file
))
644 printf_filtered ("Error writing log file.\n");
645 if (fclose(log_file
) != 0)
646 printf_filtered ("Error closing log file.\n");
652 * array_detach -- terminate the open connection to the remote
653 * debugger. Use this when you want to detach and do something
654 * else with your gdb.
657 array_detach (from_tty
)
661 debuglogs (1, "array_detach ()");
663 pop_target(); /* calls array_close to do the real work */
665 printf ("Ending remote %s debugging\n", target_shortname
);
669 * array_attach -- attach GDB to the target.
672 array_attach (args
, from_tty
)
677 printf ("Starting remote %s debugging\n", target_shortname
);
679 debuglogs (1, "array_attach (args=%s)", args
);
681 printf_monitor ("go %x\n");
682 /* swallow the echo. */
683 expect ("go %x\n", 1);
687 * array_resume -- Tell the remote machine to resume.
690 array_resume (pid
, step
, sig
)
692 enum target_signal sig
;
694 debuglogs (1, "array_resume (step=%d, sig=%d)", step
, sig
);
697 printf_monitor ("s\n");
699 printf_monitor ("go");
704 * array_wait -- Wait until the remote machine stops, then return,
705 * storing status in status just as `wait' would.
708 array_wait (pid
, status
)
710 struct target_waitstatus
*status
;
712 int old_timeout
= timeout
;
714 debuglogs(1, "array_wait (), printing extraneous text.");
716 status
->kind
= TARGET_WAITKIND_EXITED
;
717 status
->value
.integer
= 0;
719 timeout
= 0; /* Don't time out -- user program is running. */
721 expect_prompt(0); /* Wait for expect_prompt, outputting extraneous text */
722 debuglogs (4, "array_wait(), got the expect_prompt.");
724 status
->kind
= TARGET_WAITKIND_STOPPED
;
725 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
729 timeout
= old_timeout
;
735 * array_fetch_registers -- read the remote registers into the
739 array_fetch_registers (ignored
)
744 unsigned char packet
[PBUFSIZ
];
745 char regs
[REGISTER_BYTES
];
747 debuglogs (1, "array_fetch_registers (ignored=%d)\n", ignored
);
749 memset (packet
, 0, PBUFSIZ
);
750 /* Unimplemented registers read as all bits zero. */
751 memset (regs
, 0, REGISTER_BYTES
);
752 make_gdb_packet (packet
, "g");
753 if (array_send_packet (packet
) == 0)
754 error ("Couldn't transmit packet\n");
755 if (array_get_packet (packet
) == 0)
756 error ("Couldn't receive packet\n");
757 /* FIXME: read bytes from packet */
758 debuglogs (4, "array_fetch_registers: Got a \"%s\" back\n", packet
);
759 for (regno
= 0; regno
<= PC_REGNUM
+4; regno
++) {
760 /* supply register stores in target byte order, so swap here */
761 /* FIXME: convert from ASCII hex to raw bytes */
762 i
= ascii2hexword (packet
+ (regno
* 8));
763 debuglogs (5, "Adding register %d = %x\n", regno
, i
);
764 SWAP_TARGET_AND_HOST (&i
, 4);
765 supply_register (regno
, (char *)&i
);
770 * This is unused by targets like this one that use a
771 * protocol based on GDB's remote protocol.
774 array_fetch_register (ignored
)
777 array_fetch_registers ();
781 * Get all the registers from the targets. They come back in a large array.
784 array_store_registers (ignored
)
789 char packet
[PBUFSIZ
];
793 debuglogs (1, "array_store_registers()");
795 memset (packet
, 0, PBUFSIZ
);
796 memset (buf
, 0, PBUFSIZ
);
799 /* Unimplemented registers read as all bits zero. */
800 /* FIXME: read bytes from packet */
801 for (regno
= 0; regno
< 41; regno
++) { /* FIXME */
802 /* supply register stores in target byte order, so swap here */
803 /* FIXME: convert from ASCII hex to raw bytes */
804 i
= (unsigned long)read_register (regno
);
805 hexword2ascii (num
, i
);
806 strcpy (buf
+(regno
* 8)+1, num
);
808 *(buf
+ (regno
* 8) + 2) = 0;
809 make_gdb_packet (packet
, buf
);
810 if (array_send_packet (packet
) == 0)
811 error ("Couldn't transmit packet\n");
812 if (array_get_packet (packet
) == 0)
813 error ("Couldn't receive packet\n");
815 registers_changed ();
819 * This is unused by targets like this one that use a
820 * protocol based on GDB's remote protocol.
823 array_store_register (ignored
)
826 array_store_registers ();
829 /* Get ready to modify the registers array. On machines which store
830 individual registers, this doesn't need to do anything. On machines
831 which store all the registers in one fell swoop, this makes sure
832 that registers contains all the registers from the program being
836 array_prepare_to_store ()
838 /* Do nothing, since we can store individual regs */
844 printf ("\tAttached to %s at %d baud.\n",
849 * array_write_inferior_memory -- Copy LEN bytes of data from debugger
850 * memory at MYADDR to inferior's memory at MEMADDR. Returns length moved.
853 array_write_inferior_memory (memaddr
, myaddr
, len
)
855 unsigned char *myaddr
;
860 char packet
[PBUFSIZ
];
865 debuglogs (1, "array_write_inferior_memory (memaddr=0x%x, myaddr=0x%x, len=%d)", memaddr
, myaddr
, len
);
866 memset (buf
, '\0', PBUFSIZ
); /* this also sets the string terminator */
869 *p
++ = 'M'; /* The command to write memory */
870 hexword2ascii (num
, memaddr
); /* convert the address */
871 strcpy (p
, num
); /* copy the address */
873 *p
++ = ','; /* add comma delimeter */
874 hexword2ascii (num
, len
); /* Get the length as a 4 digit number */
879 *p
++ = ':'; /* add the colon delimeter */
880 for (j
= 0; j
< len
; j
++) { /* copy the data in after converting it */
881 *p
++ = tohex ((myaddr
[j
] >> 4) & 0xf);
882 *p
++ = tohex (myaddr
[j
] & 0xf);
885 make_gdb_packet (packet
, buf
);
886 if (array_send_packet (packet
) == 0)
887 error ("Couldn't transmit packet\n");
888 if (array_get_packet (packet
) == 0)
889 error ("Couldn't receive packet\n");
895 * array_read_inferior_memory -- read LEN bytes from inferior memory
896 * at MEMADDR. Put the result at debugger address MYADDR. Returns
900 array_read_inferior_memory(memaddr
, myaddr
, len
)
907 char packet
[PBUFSIZ
];
909 /* Number of bytes read so far. */
912 /* Starting address of this pass. */
913 unsigned long startaddr
;
915 /* Starting address of this pass. */
916 unsigned long endaddr
;
918 /* Number of bytes to read in this pass. */
921 debuglogs (1, "array_read_inferior_memory (memaddr=0x%x, myaddr=0x%x, len=%d)", memaddr
, myaddr
, len
);
923 /* Note that this code works correctly if startaddr is just less
924 than UINT_MAX (well, really CORE_ADDR_MAX if there was such a
925 thing). That is, something like
926 array_read_bytes (CORE_ADDR_MAX - 4, foo, 4)
927 works--it never adds len To memaddr and gets 0. */
928 /* However, something like
929 array_read_bytes (CORE_ADDR_MAX - 3, foo, 4)
930 doesn't need to work. Detect it and give up if there's an attempt
932 if (((memaddr
- 1) + len
) < memaddr
) {
939 while (count
< len
) {
941 if ((startaddr
% 16) != 0)
942 len_this_pass
-= startaddr
% 16;
943 if (len_this_pass
> (len
- count
))
944 len_this_pass
= (len
- count
);
946 debuglogs (3, "Display %d bytes at %x for Big Endian host", len_this_pass
, startaddr
);
948 for (i
= 0; i
< len_this_pass
; i
++) {
949 sprintf (buf
, "m%08x,%04x", startaddr
, len_this_pass
);
950 make_gdb_packet (packet
, buf
);
951 if (array_send_packet (packet
) == 0)
952 error ("Couldn't transmit packet\n");
953 if (array_get_packet (packet
) == 0)
954 error ("Couldn't receive packet\n");
956 error ("Got no data in the GDB packet\n");
957 debuglogs (4, "array_read_inferior: Got a \"%s\" back\n", packet
);
958 for (j
= 0; j
< len_this_pass
; j
++) { /* extract the byte values */
959 myaddr
[count
++] = from_hex (*(packet
+(j
*2))) * 16 + from_hex (*(packet
+(j
*2)+1));
960 debuglogs (5, "myaddr set to %x\n", myaddr
[count
-1]);
969 /* FIXME-someday! merge these two. */
971 array_xfer_memory (memaddr
, myaddr
, len
, write
, target
)
976 struct target_ops
*target
; /* ignored */
979 return array_write_inferior_memory (memaddr
, myaddr
, len
);
981 return array_read_inferior_memory (memaddr
, myaddr
, len
);
985 array_kill (args
, from_tty
)
989 return; /* ignore attempts to kill target system */
992 /* Clean up when a program exits.
993 The program actually lives on in the remote processor's RAM, and may be
994 run again without a download. Don't leave it full of breakpoint
998 array_mourn_inferior ()
1000 remove_breakpoints ();
1001 generic_mourn_inferior (); /* Do all the proper things now */
1004 #define MAX_ARRAY_BREAKPOINTS 16
1006 extern int memory_breakpoint_size
;
1007 static CORE_ADDR breakaddr
[MAX_ARRAY_BREAKPOINTS
] = {0};
1010 * array_insert_breakpoint -- add a breakpoint
1013 array_insert_breakpoint (addr
, shadow
)
1019 debuglogs (1, "array_insert_breakpoint() addr = 0x%x", addr
);
1021 for (i
= 0; i
<= MAX_ARRAY_BREAKPOINTS
; i
++) {
1022 if (breakaddr
[i
] == 0) {
1023 breakaddr
[i
] = addr
;
1024 if (sr_get_debug() > 4)
1025 printf ("Breakpoint at %x\n", addr
);
1026 array_read_inferior_memory(addr
, shadow
, memory_breakpoint_size
);
1027 printf_monitor("brk 0x%x\n", addr
);
1033 fprintf(stderr
, "Too many breakpoints (> 16) for monitor\n");
1038 * _remove_breakpoint -- Tell the monitor to remove a breakpoint
1041 array_remove_breakpoint (addr
, shadow
)
1047 debuglogs (1, "array_remove_breakpoint() addr = 0x%x", addr
);
1049 for (i
= 0; i
< MAX_ARRAY_BREAKPOINTS
; i
++) {
1050 if (breakaddr
[i
] == addr
) {
1052 /* some monitors remove breakpoints based on the address */
1053 printf_monitor("unbrk %x\n", i
);
1058 fprintf(stderr
, "Can't find breakpoint associated with 0x%x\n", addr
);
1065 debuglogs (1, "array_stop()");
1066 printf_monitor("\003");
1071 * array_command -- put a command string, in args, out to MONITOR.
1072 * Output from MONITOR is placed on the users terminal until the
1073 * expect_prompt is seen. FIXME
1076 monitor_command (args
, fromtty
)
1080 debuglogs (1, "monitor_command (args=%s)", args
);
1082 if (array_desc
== NULL
)
1083 error("monitor target not open.");
1086 error("Missing command.");
1088 printf_monitor ("%s\n", args
);
1093 * make_gdb_packet -- make a GDB packet. The data is always ASCII.
1094 * A debug packet whose contents are <data>
1095 * is encapsulated for transmission in the form:
1097 * $ <data> # CSUM1 CSUM2
1099 * <data> must be ASCII alphanumeric and cannot include characters
1100 * '$' or '#'. If <data> starts with two characters followed by
1101 * ':', then the existing stubs interpret this as a sequence number.
1103 * CSUM1 and CSUM2 are ascii hex representation of an 8-bit
1104 * checksum of <data>, the most significant nibble is sent first.
1105 * the hex digits 0-9,a-f are used.
1109 make_gdb_packet (buf
, data
)
1113 unsigned char csum
= 0;
1117 debuglogs (3, "make_gdb_packet(%s)\n", data
);
1118 cnt
= strlen (data
);
1120 error ("make_gdb_packet(): to much data\n");
1122 /* start with the packet header */
1126 /* calculate the checksum */
1127 for (i
= 0; i
< cnt
; i
++) {
1132 /* terminate the data with a '#' */
1135 /* add the checksum as two ascii digits */
1136 *p
++ = tohex ((csum
>> 4) & 0xf);
1137 *p
++ = tohex (csum
& 0xf);
1138 *p
= 0x0; /* Null terminator on string */
1142 * array_send_packet -- send a GDB packet to the target with error handling. We
1143 * get a '+' (ACK) back if the packet is received and the checksum
1144 * matches. Otherwise a '-' (NAK) is returned. It returns a 1 for a
1145 * successful transmition, or a 0 for a failure.
1148 array_send_packet (packet
)
1157 /* scan the packet to make sure it only contains valid characters.
1158 this may sound silly, but sometimes a garbled packet will hang
1159 the target board. We scan the whole thing, then print the error
1162 for (i
= 0; i
< strlen(packet
); i
++) {
1163 debuglogs (5, "array_send_packet(): Scanning \'%c\'\n", packet
[i
]);
1164 /* legit hex numbers or command */
1165 if ((isxdigit(packet
[i
])) || (isalpha(packet
[i
])))
1167 switch (packet
[i
]) {
1170 case '#': /* end of packet */
1171 case '$': /* start of packet */
1173 default: /* bogus character */
1175 debuglogs (4, "array_send_packet(): Found a non-ascii digit \'%c\' in the packet.\n", packet
[i
]);
1181 error ("Can't send packet, found %d non-ascii characters", retries
);
1183 /* ok, try to send the packet */
1185 while (retries
++ <= 10) {
1186 printf_monitor ("%s", packet
);
1188 /* read until either a timeout occurs (-2) or '+' is read */
1189 while (retries
<= 10) {
1190 c
= readchar (-timeout
);
1191 debuglogs (3, "Reading a GDB protocol packet... Got a '%c'\n", c
);
1194 debuglogs (3, "Got Ack\n");
1196 case SERIAL_TIMEOUT
:
1197 debuglogs (3, "Timed out reading serial port\n");
1198 printf_monitor("+"); /* resync with the monitor */
1199 expect_prompt(1); /* See if we get a expect_prompt */
1200 break; /* Retransmit buffer */
1202 debuglogs (3, "Got NAK\n");
1203 printf_monitor("+"); /* resync with the monitor */
1204 expect_prompt(1); /* See if we get a expect_prompt */
1207 /* it's probably an old response, or the echo of our command.
1208 * just gobble up the packet and ignore it.
1210 debuglogs (3, "Got a junk packet\n");
1213 c
= readchar (timeout
);
1216 c
= readchar (timeout
);
1218 c
= readchar (timeout
);
1221 debuglogs (3, "Reading a junk packet, got a \"%s\"\n", junk
);
1222 continue; /* Now, go look for next packet */
1227 debuglogs (3, "Retransmitting packet \"%s\"\n", packet
);
1228 break; /* Here to retransmit */
1235 * array_get_packet -- get a GDB packet from the target. Basically we read till we
1236 * see a '#', then check the checksum. It returns a 1 if it's gotten a
1237 * packet, or a 0 it the packet wasn't transmitted correctly.
1240 array_get_packet (packet
)
1246 unsigned char pktcsum
;
1252 memset (packet
, 1, PBUFSIZ
);
1254 while (retries
<= 10) {
1256 c
= readchar (timeout
);
1257 if (c
== SERIAL_TIMEOUT
) {
1258 debuglogs (3, "array_get_packet: got time out from serial port.\n");
1260 debuglogs (3, "Waiting for a '$', got a %c\n", c
);
1264 while (retries
<= 10) {
1265 c
= readchar (timeout
);
1266 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
) {
1281 debuglogs (3, "\nGDB packet checksum correct, packet data is \"%s\",\n", packet
);
1282 printf_monitor ("+");
1286 debuglogs (3, "Bad checksum, sentsum=0x%x, csum=0x%x\n", pktcsum
, csum
);
1288 case '*': /* Run length encoding */
1289 debuglogs (5, "Run length encoding in packet\n");
1291 c
= readchar (timeout
);
1293 c
= c
- ' ' + 3; /* Compute repeat count */
1295 if (c
> 0 && c
< 255 && bp
+ c
- 1 < packet
+ PBUFSIZ
- 1) {
1296 memset (bp
, *(bp
- 1), c
);
1301 printf_filtered ("Repeat count %d too large for buffer.\n", c
);
1305 if ((!isxdigit(c
)) && (!ispunct(c
)))
1306 debuglogs (4, "Got a non-ascii digit \'%c\'.\\n", c
);
1307 if (bp
< packet
+ PBUFSIZ
- 1) {
1314 puts_filtered ("Remote packet too long.\n");
1322 * ascii2hexword -- convert an ascii number represented by 8 digits to a hex value.
1324 static unsigned long
1333 for (i
= 0; i
< 8; i
++) {
1335 if (mem
[i
] >= 'A' && mem
[i
] <= 'F')
1336 val
= val
+ mem
[i
] - 'A' + 10;
1337 if (mem
[i
] >= 'a' && mem
[i
] <= 'f')
1338 val
= val
+ mem
[i
] - 'a' + 10;
1339 if (mem
[i
] >= '0' && mem
[i
] <= '9')
1340 val
= val
+ mem
[i
] - '0';
1344 debuglogs (4, "ascii2hexword() got a 0x%x from %s(%x).\n", val
, buf
, mem
);
1349 * ascii2hexword -- convert a hex value to an ascii number represented by 8
1353 hexword2ascii (mem
, num
)
1360 debuglogs (4, "hexword2ascii() converting %x ", num
);
1361 for (i
= 7; i
>= 0; i
--) {
1362 mem
[i
] = tohex ((num
>> 4) & 0xf);
1363 mem
[i
] = tohex (num
& 0xf);
1367 debuglogs (4, "\tto a %s", mem
);
1370 /* Convert hex digit A to a number. */
1378 debuglogs (4, "from_hex got a 0x%x(%c)\n",a
,a
);
1379 if (a
>= '0' && a
<= '9')
1381 if (a
>= 'a' && a
<= 'f')
1382 return a
- 'a' + 10;
1383 if (a
>= 'A' && a
<= 'F')
1384 return a
- 'A' + 10;
1386 error ("Reply contains invalid hex digit 0x%x", a
);
1390 /* Convert number NIB to a hex digit. */
1402 * _initialize_remote_monitors -- setup a few addtitional commands that
1403 * are usually only used by monitors.
1406 _initialize_remote_monitors ()
1408 /* generic monitor command */
1409 add_com ("monitor", class_obscure
, monitor_command
,
1410 "Send a command to the debug monitor.");
1415 * _initialize_array -- do any special init stuff for the target.
1418 _initialize_array ()
1420 add_target (&array_ops
);
1421 baud_rate
= 4800; /* this is the only supported baud rate */
This page took 0.060361 seconds and 4 git commands to generate.