1 /* Remote debugging for the ARM RDP interface.
3 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2006
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
28 Much of this file (in particular the SWI stuff) is based on code by
29 David Taylor (djt1000@uk.ac.cam.hermes).
31 I hacked on and simplified it by removing a lot of sexy features he
32 had added, and some of the (unix specific) workarounds he'd done
33 for other GDB problems - which if they still exist should be fixed
34 in GDB, not in a remote-foo thing . I also made it conform more to
35 the doc I have; which may be wrong.
37 Steve Chamberlain (sac@cygnus.com).
44 #include "gdb/callback.h"
49 #include "remote-utils.h"
50 #include "gdb_string.h"
61 extern struct target_ops remote_rdp_ops
;
62 static struct serial
*io
;
63 static host_callback
*callback
= &default_callback
;
72 char command_line
[10];
74 int rdi_stopped_status
;
80 /* Definitions for the RDP protocol. */
82 #define RDP_MOUTHFULL (1<<6)
83 #define FPU_COPRO_NUMBER 1
86 #define RDP_OPEN_TYPE_COLD 0
87 #define RDP_OPEN_TYPE_WARM 1
88 #define RDP_OPEN_TYPE_BAUDRATE 2
90 #define RDP_OPEN_BAUDRATE_9600 1
91 #define RDP_OPEN_BAUDRATE_19200 2
92 #define RDP_OPEN_BAUDRATE_38400 3
94 #define RDP_OPEN_TYPE_RETURN_SEX (1<<3)
98 #define RDP_MEM_READ 2
100 #define RDP_MEM_WRITE 3
102 #define RDP_CPU_READ 4
103 #define RDP_CPU_WRITE 5
104 #define RDP_CPU_READWRITE_MODE_CURRENT 255
105 #define RDP_CPU_READWRITE_MASK_PC (1<<16)
106 #define RDP_CPU_READWRITE_MASK_CPSR (1<<17)
107 #define RDP_CPU_READWRITE_MASK_SPSR (1<<18)
109 #define RDP_COPRO_READ 6
110 #define RDP_COPRO_WRITE 7
111 #define RDP_FPU_READWRITE_MASK_FPS (1<<8)
113 #define RDP_SET_BREAK 0xa
114 #define RDP_SET_BREAK_TYPE_PC_EQUAL 0
115 #define RDP_SET_BREAK_TYPE_GET_HANDLE (0x10)
117 #define RDP_CLEAR_BREAK 0xb
119 #define RDP_EXEC 0x10
120 #define RDP_EXEC_TYPE_SYNC 0
122 #define RDP_STEP 0x11
124 #define RDP_INFO 0x12
125 #define RDP_INFO_ABOUT_STEP 2
126 #define RDP_INFO_ABOUT_STEP_GT_1 1
127 #define RDP_INFO_ABOUT_STEP_TO_JMP 2
128 #define RDP_INFO_ABOUT_STEP_1 4
129 #define RDP_INFO_ABOUT_TARGET 0
130 #define RDP_INFO_ABOUT_BREAK 1
131 #define RDP_INFO_ABOUT_BREAK_COMP 1
132 #define RDP_INFO_ABOUT_BREAK_RANGE 2
133 #define RDP_INFO_ABOUT_BREAK_BYTE_READ 4
134 #define RDP_INFO_ABOUT_BREAK_HALFWORD_READ 8
135 #define RDP_INFO_ABOUT_BREAK_WORD_READ (1<<4)
136 #define RDP_INFO_ABOUT_BREAK_BYTE_WRITE (1<<5)
137 #define RDP_INFO_ABOUT_BREAK_HALFWORD_WRITE (1<<6)
138 #define RDP_INFO_ABOUT_BREAK_WORD_WRITE (1<<7)
139 #define RDP_INFO_ABOUT_BREAK_MASK (1<<8)
140 #define RDP_INFO_ABOUT_BREAK_THREAD_BREAK (1<<9)
141 #define RDP_INFO_ABOUT_BREAK_THREAD_WATCH (1<<10)
142 #define RDP_INFO_ABOUT_BREAK_COND (1<<11)
143 #define RDP_INFO_VECTOR_CATCH (0x180)
144 #define RDP_INFO_ICEBREAKER (7)
145 #define RDP_INFO_SET_CMDLINE (0x300)
147 #define RDP_SELECT_CONFIG (0x16)
148 #define RDI_ConfigCPU 0
149 #define RDI_ConfigSystem 1
150 #define RDI_MatchAny 0
151 #define RDI_MatchExactly 1
152 #define RDI_MatchNoEarlier 2
154 #define RDP_RESET 0x7f
156 /* Returns from RDP */
157 #define RDP_RES_STOPPED 0x20
158 #define RDP_RES_SWI 0x21
159 #define RDP_RES_FATAL 0x5e
160 #define RDP_RES_VALUE 0x5f
161 #define RDP_RES_VALUE_LITTLE_ENDIAN 240
162 #define RDP_RES_VALUE_BIG_ENDIAN 241
163 #define RDP_RES_RESET 0x7f
164 #define RDP_RES_AT_BREAKPOINT 143
165 #define RDP_RES_IDUNNO 0xe6
166 #define RDP_OSOpReply 0x13
167 #define RDP_OSOpWord 2
168 #define RDP_OSOpNothing 0
170 static int timeout
= 2;
172 static char *commandline
= NULL
;
175 remote_rdp_xfer_inferior_memory (CORE_ADDR memaddr
, char *myaddr
, int len
,
177 struct mem_attrib
*attrib
,
178 struct target_ops
*target
);
181 /* Stuff for talking to the serial layer. */
186 int c
= serial_readchar (io
, timeout
);
189 fprintf_unfiltered (gdb_stdlog
, "[%02x]\n", c
);
191 if (c
== SERIAL_TIMEOUT
)
194 return (unsigned char) c
;
196 error (_("Timeout reading from remote_system"));
202 /* Note that the target always speaks little-endian to us,
203 even if it's a big endian machine. */
207 unsigned int val
= 0;
210 for (n
= 0; n
< 4; n
++)
222 fprintf_unfiltered (gdb_stdlog
, "(%02x)\n", val
);
223 serial_write (io
, &val
, 1);
229 /* We always send in little endian */
237 fprintf_unfiltered (gdb_stdlog
, "(%04x)", val
);
239 serial_write (io
, b
, 4);
244 /* Stuff for talking to the RDP layer. */
246 /* This is a bit more fancy that need be so that it syncs even in nasty cases.
248 I'be been unable to make it reliably sync up with the change
249 baudrate open command. It likes to sit and say it's been reset,
250 with no more action. So I took all that code out. I'd rather sync
251 reliably at 9600 than wait forever for a possible 19200 connection.
255 rdp_init (int cold
, int tty
)
258 int type
= cold
? RDP_OPEN_TYPE_COLD
: RDP_OPEN_TYPE_WARM
;
261 time_t now
= time (0);
262 time_t stop_time
= now
+ 10; /* Try and sync for 10 seconds, then give up */
265 while (time (0) < stop_time
&& !sync
)
270 serial_flush_input (io
);
271 serial_flush_output (io
);
274 printf_unfiltered ("Trying to connect at %d baud.\n", baudtry
);
277 ** It seems necessary to reset an EmbeddedICE to get it going.
278 ** This has the side benefit of displaying the startup banner.
282 put_byte (RDP_RESET
);
283 while ((restype
= serial_readchar (io
, 1)) > 0)
290 /* Sent at start of reset process: ignore */
293 printf_unfiltered ("%c", isgraph (restype
) ? restype
: ' ');
300 /* Got end-of-banner mark */
301 printf_filtered ("\n");
307 put_byte (type
| RDP_OPEN_TYPE_RETURN_SEX
);
310 while (!sync
&& (restype
= serial_readchar (io
, 1)) > 0)
313 fprintf_unfiltered (gdb_stdlog
, "[%02x]\n", restype
);
321 while ((restype
= serial_readchar (io
, 1)) == RDP_RESET
)
325 printf_unfiltered ("%c", isgraph (restype
) ? restype
: ' ');
327 while ((restype
= serial_readchar (io
, 1)) > 0);
331 printf_unfiltered ("\nThe board has sent notification that it was reset.\n");
332 printf_unfiltered ("Waiting for it to settle down...\n");
336 printf_unfiltered ("\nTrying again.\n");
345 int resval
= serial_readchar (io
, 1);
348 fprintf_unfiltered (gdb_stdlog
, "[%02x]\n", resval
);
354 case RDP_RES_VALUE_LITTLE_ENDIAN
:
356 /* FIXME: cagney/2003-11-22: Ever since the ARM
357 was multi-arched (in 2002-02-08), this
358 assignment has had no effect. There needs to
359 be some sort of check/decision based on the
360 current architecture's byte-order vs the remote
361 target's byte order. For the moment disable
362 the assignment to keep things building. */
363 target_byte_order
= BFD_ENDIAN_LITTLE
;
367 case RDP_RES_VALUE_BIG_ENDIAN
:
369 /* FIXME: cagney/2003-11-22: Ever since the ARM
370 was multi-arched (in 2002-02-08), this
371 assignment has had no effect. There needs to
372 be some sort of check/decision based on the
373 current architecture's byte-order vs the remote
374 target's byte order. For the moment disable
375 the assignment to keep things building. */
376 target_byte_order
= BFD_ENDIAN_BIG
;
390 error (_("Couldn't reset the board, try pressing the reset button"));
396 send_rdp (char *template,...)
401 va_start (alist
, template);
413 val
= va_arg (alist
, int);
417 val
= va_arg (alist
, int);
425 if (val
!= RDP_RES_VALUE
)
427 printf_unfiltered ("got bad res value of %d, %x\n", val
, val
);
431 pstat
= va_arg (alist
, int *);
432 pi
= va_arg (alist
, int *);
434 *pstat
= get_byte ();
435 /* Check the result was zero, if not read the syndrome */
442 /* Check the result code */
449 /* Target can't do it; never mind */
450 printf_unfiltered ("RDP: Insufficient privilege\n");
453 /* Target can't do it; never mind */
454 printf_unfiltered ("RDP: Unimplemented message\n");
457 error (_("Command garbled"));
460 error (_("Corrupt reply from target"));
465 /* Read a word from the target */
466 pi
= va_arg (alist
, int *);
470 /* Read in some bytes from the target. */
471 pc
= va_arg (alist
, char *);
472 val
= va_arg (alist
, int);
473 for (i
= 0; i
< val
; i
++)
479 /* send what's being pointed at */
480 pc
= va_arg (alist
, char *);
481 val
= va_arg (alist
, int);
483 serial_write (io
, pc
, val
);
486 /* Send whats in the queue */
489 serial_write (io
, buf
, dst
- buf
);
494 pi
= va_arg (alist
, int *);
498 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
504 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
509 rdp_write (CORE_ADDR memaddr
, char *buf
, int len
)
514 send_rdp ("bww-p-SV", RDP_MEM_WRITE
, memaddr
, len
, buf
, len
, &res
, &val
);
525 rdp_read (CORE_ADDR memaddr
, char *buf
, int len
)
529 send_rdp ("bww-S-P-V",
530 RDP_MEM_READ
, memaddr
, len
,
541 rdp_fetch_one_register (int mask
, char *buf
)
544 send_rdp ("bbw-SWZ", RDP_CPU_READ
, RDP_CPU_READWRITE_MODE_CURRENT
, mask
, &val
);
545 store_signed_integer (buf
, 4, val
);
549 rdp_fetch_one_fpu_register (int mask
, char *buf
)
552 /* !!! Since the PIE board doesn't work as documented,
553 and it doesn't have FPU hardware anyway and since it
554 slows everything down, I've disabled this. */
556 if (mask
== RDP_FPU_READWRITE_MASK_FPS
)
558 /* this guy is only a word */
559 send_rdp ("bbw-SWZ", RDP_COPRO_READ
, FPU_COPRO_NUMBER
, mask
, &val
);
560 store_signed_integer (buf
, 4, val
);
564 /* There are 12 bytes long
565 !! fixme about endianness
567 int dummy
; /* I've seen these come back as four words !! */
568 send_rdp ("bbw-SWWWWZ", RDP_COPRO_READ
, FPU_COPRO_NUMBER
, mask
, buf
+ 0, buf
+ 4, buf
+ 8, &dummy
);
571 memset (buf
, 0, MAX_REGISTER_SIZE
);
576 rdp_store_one_register (int mask
, char *buf
)
578 int val
= extract_unsigned_integer (buf
, 4);
581 RDP_CPU_WRITE
, RDP_CPU_READWRITE_MODE_CURRENT
, mask
, val
);
586 rdp_store_one_fpu_register (int mask
, char *buf
)
589 /* See comment in fetch_one_fpu_register */
590 if (mask
== RDP_FPU_READWRITE_MASK_FPS
)
592 int val
= extract_unsigned_integer (buf
, 4);
593 /* this guy is only a word */
594 send_rdp ("bbww-SZ", RDP_COPRO_WRITE
,
600 /* There are 12 bytes long
601 !! fixme about endianness
604 /* I've seen these come as four words, not the three advertized !! */
605 printf ("Sending mask %x\n", mask
);
606 send_rdp ("bbwwwww-SZ",
615 printf ("done mask %x\n", mask
);
621 /* Convert between GDB requests and the RDP layer. */
624 remote_rdp_fetch_register (int regno
)
628 for (regno
= 0; regno
< NUM_REGS
; regno
++)
629 remote_rdp_fetch_register (regno
);
633 char buf
[MAX_REGISTER_SIZE
];
635 rdp_fetch_one_register (1 << regno
, buf
);
636 else if (regno
== ARM_PC_REGNUM
)
637 rdp_fetch_one_register (RDP_CPU_READWRITE_MASK_PC
, buf
);
638 else if (regno
== ARM_PS_REGNUM
)
639 rdp_fetch_one_register (RDP_CPU_READWRITE_MASK_CPSR
, buf
);
640 else if (regno
== ARM_FPS_REGNUM
)
641 rdp_fetch_one_fpu_register (RDP_FPU_READWRITE_MASK_FPS
, buf
);
642 else if (regno
>= ARM_F0_REGNUM
&& regno
<= ARM_F7_REGNUM
)
643 rdp_fetch_one_fpu_register (1 << (regno
- ARM_F0_REGNUM
), buf
);
646 printf ("Help me with fetch reg %d\n", regno
);
648 regcache_raw_supply (current_regcache
, regno
, buf
);
654 remote_rdp_store_register (int regno
)
658 for (regno
= 0; regno
< NUM_REGS
; regno
++)
659 remote_rdp_store_register (regno
);
663 char tmp
[MAX_REGISTER_SIZE
];
664 deprecated_read_register_gen (regno
, tmp
);
666 rdp_store_one_register (1 << regno
, tmp
);
667 else if (regno
== ARM_PC_REGNUM
)
668 rdp_store_one_register (RDP_CPU_READWRITE_MASK_PC
, tmp
);
669 else if (regno
== ARM_PS_REGNUM
)
670 rdp_store_one_register (RDP_CPU_READWRITE_MASK_CPSR
, tmp
);
671 else if (regno
>= ARM_F0_REGNUM
&& regno
<= ARM_F7_REGNUM
)
672 rdp_store_one_fpu_register (1 << (regno
- ARM_F0_REGNUM
), tmp
);
675 printf ("Help me with reg %d\n", regno
);
681 remote_rdp_kill (void)
683 callback
->shutdown (callback
);
690 send_rdp ("bw-S-W-Z", RDP_INFO
, RDP_INFO_ABOUT_STEP
,
692 send_rdp ("bw-S-W-Z", RDP_INFO
, RDP_INFO_ABOUT_BREAK
,
694 send_rdp ("bw-S-WW-Z", RDP_INFO
, RDP_INFO_ABOUT_TARGET
,
698 ds
.can_step
= ds
.step_info
& RDP_INFO_ABOUT_STEP_1
;
700 ds
.rdi_level
= (ds
.target_info
>> 5) & 3;
705 rdp_execute_start (void)
707 /* Start it off, but don't wait for it */
708 send_rdp ("bb-", RDP_EXEC
, RDP_EXEC_TYPE_SYNC
);
713 rdp_set_command_line (char *command
, char *args
)
716 ** We could use RDP_INFO_SET_CMDLINE to send this, but EmbeddedICE systems
717 ** don't implement that, and get all confused at the unexpected text.
718 ** Instead, just keep a copy, and send it when the target does a SWI_GetEnv
721 if (commandline
!= NULL
)
724 commandline
= xstrprintf ("%s %s", command
, args
);
728 rdp_catch_vectors (void)
731 ** We want the target monitor to intercept the abort vectors
732 ** i.e. stop the program if any of these are used.
734 send_rdp ("bww-SZ", RDP_INFO
, RDP_INFO_VECTOR_CATCH
,
736 ** Specify a bitmask including
738 ** the undefined instruction vector
739 ** the prefetch abort vector
740 ** the data abort vector
741 ** the address exception vector
743 (1 << 0) | (1 << 1) | (1 << 3) | (1 << 4) | (1 << 5)
766 #define SWI_WriteC 0x0
767 #define SWI_Write0 0x2
768 #define SWI_ReadC 0x4
770 #define SWI_GetEnv 0x10
771 #define SWI_Exit 0x11
772 #define SWI_EnterOS 0x16
774 #define SWI_GetErrno 0x60
775 #define SWI_Clock 0x61
777 #define SWI_Time 0x63
778 #define SWI_Remove 0x64
779 #define SWI_Rename 0x65
780 #define SWI_Open 0x66
782 #define SWI_Close 0x68
783 #define SWI_Write 0x69
784 #define SWI_Read 0x6a
785 #define SWI_Seek 0x6b
786 #define SWI_Flen 0x6c
788 #define SWI_IsTTY 0x6e
789 #define SWI_TmpNam 0x6f
790 #define SWI_InstallHandler 0x70
791 #define SWI_GenerateError 0x71
795 static int translate_open_mode
[] =
798 O_RDONLY
+ O_BINARY
, /* "rb" */
800 O_RDWR
+ O_BINARY
, /* "r+b" */
801 O_WRONLY
+ O_CREAT
+ O_TRUNC
, /* "w" */
802 O_WRONLY
+ O_BINARY
+ O_CREAT
+ O_TRUNC
, /* "wb" */
803 O_RDWR
+ O_CREAT
+ O_TRUNC
, /* "w+" */
804 O_RDWR
+ O_BINARY
+ O_CREAT
+ O_TRUNC
, /* "w+b" */
805 O_WRONLY
+ O_APPEND
+ O_CREAT
, /* "a" */
806 O_WRONLY
+ O_BINARY
+ O_APPEND
+ O_CREAT
, /* "ab" */
807 O_RDWR
+ O_APPEND
+ O_CREAT
, /* "a+" */
808 O_RDWR
+ O_BINARY
+ O_APPEND
+ O_CREAT
/* "a+b" */
812 exec_swi (int swi
, argsin
*args
)
819 callback
->write_stdout (callback
, &c
, 1);
822 for (i
= 0; i
< args
->n
; i
++)
823 callback
->write_stdout (callback
, args
->s
, strlen (args
->s
));
826 callback
->read_stdin (callback
, &c
, 1);
830 args
->n
= callback
->system (callback
, args
->s
);
833 args
->n
= callback
->get_errno (callback
);
836 args
->n
= callback
->time (callback
, NULL
);
840 /* return number of centi-seconds... */
842 #ifdef CLOCKS_PER_SEC
843 (CLOCKS_PER_SEC
>= 100)
844 ? (clock () / (CLOCKS_PER_SEC
/ 100))
845 : ((clock () * 100) / CLOCKS_PER_SEC
);
847 /* presume unix... clock() returns microseconds */
853 args
->n
= callback
->unlink (callback
, args
->s
);
856 args
->n
= callback
->rename (callback
, args
[0].s
, args
[1].s
);
860 /* Now we need to decode the Demon open mode */
861 i
= translate_open_mode
[args
[1].n
];
863 /* Filename ":tt" is special: it denotes stdin/out */
864 if (strcmp (args
->s
, ":tt") == 0)
866 if (i
== O_RDONLY
) /* opening tty "r" */
867 args
->n
= 0 /* stdin */ ;
869 args
->n
= 1 /* stdout */ ;
872 args
->n
= callback
->open (callback
, args
->s
, i
);
876 args
->n
= callback
->close (callback
, args
->n
);
880 /* Return the number of bytes *not* written */
881 args
->n
= args
[1].n
-
882 callback
->write (callback
, args
[0].n
, args
[1].s
, args
[1].n
);
887 char *copy
= alloca (args
[2].n
);
888 int done
= callback
->read (callback
, args
[0].n
, copy
, args
[2].n
);
890 remote_rdp_xfer_inferior_memory (args
[1].n
, copy
, done
, 1, 0, 0);
891 args
->n
= args
[2].n
- done
;
896 /* Return non-zero on failure */
897 args
->n
= callback
->lseek (callback
, args
[0].n
, args
[1].n
, 0) < 0;
902 long old
= callback
->lseek (callback
, args
->n
, 0, SEEK_CUR
);
903 args
->n
= callback
->lseek (callback
, args
->n
, 0, SEEK_END
);
904 callback
->lseek (callback
, args
->n
, old
, 0);
909 args
->n
= callback
->isatty (callback
, args
->n
);
913 if (commandline
!= NULL
)
915 int len
= strlen (commandline
);
919 commandline
[255] = '\0';
921 remote_rdp_xfer_inferior_memory (args
[0].n
,
922 commandline
, len
+ 1, 1, 0, 0);
925 remote_rdp_xfer_inferior_memory (args
[0].n
, "", 1, 1, 0, 0);
942 int swino
= get_word ();
943 int type
= get_byte ();
949 args
[count
].n
= get_byte ();
953 args
[count
].n
= get_word ();
957 /* If the word is under 32 bytes it will be sent otherwise
958 an address to it is passed. Also: Special case of 255 */
968 remote_rdp_xfer_inferior_memory (get_word (),
978 buf
= alloca (len
+ 1);
979 for (i
= 0; i
< len
; i
++)
980 buf
[i
] = get_byte ();
988 error (_("Unimplemented SWI argument"));
995 if (exec_swi (swino
, args
))
997 /* We have two options here reply with either a byte or a word
998 which is stored in args[0].n. There is no harm in replying with
999 a word all the time, so thats what I do! */
1000 send_rdp ("bbw-", RDP_OSOpReply
, RDP_OSOpWord
, args
[0].n
);
1004 send_rdp ("bb-", RDP_OSOpReply
, RDP_OSOpNothing
);
1009 rdp_execute_finish (void)
1016 res
= serial_readchar (io
, 1);
1017 while (res
== SERIAL_TIMEOUT
)
1020 printf_filtered ("Waiting for target..\n");
1021 res
= serial_readchar (io
, 1);
1030 send_rdp ("B", &ds
.rdi_stopped_status
);
1034 printf_filtered ("Target reset\n");
1038 printf_filtered ("Ignoring %x\n", res
);
1048 rdp_execute_start ();
1049 rdp_execute_finish ();
1053 remote_rdp_insert_breakpoint (CORE_ADDR addr
, bfd_byte
*save
)
1056 if (ds
.rdi_level
> 0)
1058 send_rdp ("bwb-SWB",
1061 RDP_SET_BREAK_TYPE_PC_EQUAL
| RDP_SET_BREAK_TYPE_GET_HANDLE
,
1070 RDP_SET_BREAK_TYPE_PC_EQUAL
,
1077 remote_rdp_remove_breakpoint (CORE_ADDR addr
, bfd_byte
*save
)
1080 if (ds
.rdi_level
> 0)
1082 send_rdp ("b-p-S-B",
1100 if (ds
.can_step
&& 0)
1102 /* The pie board can't do steps so I can't test this, and
1103 the other code will always work. */
1105 send_rdp ("bbw-S-B",
1112 CORE_ADDR pc
= read_register (ARM_PC_REGNUM
);
1113 pc
= arm_get_next_pc (pc
);
1114 remote_rdp_insert_breakpoint (pc
, handle
);
1116 remote_rdp_remove_breakpoint (pc
, handle
);
1121 remote_rdp_open (char *args
, int from_tty
)
1126 error_no_arg (_("serial port device name"));
1130 target_preopen (from_tty
);
1132 io
= serial_open (args
);
1135 perror_with_name (args
);
1139 rdp_init (1, from_tty
);
1144 printf_unfiltered ("Remote RDP debugging using %s at %d baud\n", args
, baud_rate
);
1149 /* Need to set up the vector interception state */
1150 rdp_catch_vectors ();
1153 ** If it's an EmbeddedICE, we need to set the processor config.
1154 ** Assume we can always have ARM7TDI...
1156 send_rdp ("bw-SB", RDP_INFO
, RDP_INFO_ICEBREAKER
, ¬_icebreaker
);
1157 if (!not_icebreaker
)
1159 const char *CPU
= "ARM7TDI";
1161 int len
= strlen (CPU
);
1163 send_rdp ("bbbbw-p-SWZ",
1165 RDI_ConfigCPU
, /* Aspect: set the CPU */
1166 len
, /* The number of bytes in the name */
1167 RDI_MatchAny
, /* We'll take whatever we get */
1168 0, /* We'll take whatever version's there */
1173 /* command line initialised on 'run' */
1175 push_target (&remote_rdp_ops
);
1177 callback
->init (callback
);
1178 flush_cached_frames ();
1179 registers_changed ();
1180 stop_pc
= read_pc ();
1181 print_stack_frame (get_selected_frame (NULL
), 0, SRC_AND_LOC
);
1186 /* Close out all files and local state before this target loses control. */
1189 remote_rdp_close (int quitting
)
1191 callback
->shutdown (callback
);
1198 /* Resume execution of the target process. STEP says whether to single-step
1199 or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be given
1200 to the target, or zero for no signal. */
1203 remote_rdp_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
1211 /* Wait for inferior process to do something. Return pid of child,
1212 or -1 in case of error; store status through argument pointer STATUS,
1213 just as `wait' would. */
1216 remote_rdp_wait (ptid_t ptid
, struct target_waitstatus
*status
)
1218 switch (ds
.rdi_stopped_status
)
1223 status
->kind
= TARGET_WAITKIND_EXITED
;
1224 status
->value
.integer
= read_register (0);
1226 case RDP_RES_AT_BREAKPOINT
:
1227 status
->kind
= TARGET_WAITKIND_STOPPED
;
1228 /* The signal in sigrc is a host signal. That probably
1230 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
1234 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
1235 /* The signal in sigrc is a host signal. That probably
1237 status
->value
.sig
= target_signal_from_host (sigrc
);
1242 return inferior_ptid
;
1245 /* Get ready to modify the registers array. On machines which store
1246 individual registers, this doesn't need to do anything. On machines
1247 which store all the registers in one fell swoop, this makes sure
1248 that registers contains all the registers from the program being
1252 remote_rdp_prepare_to_store (void)
1254 /* Do nothing, since we can store individual regs */
1257 /* Transfer LEN bytes between GDB address MYADDR and target address
1258 MEMADDR. If WRITE is non-zero, transfer them to the target,
1259 otherwise transfer them from the target. TARGET is unused.
1261 Returns the number of bytes transferred. */
1264 remote_rdp_xfer_inferior_memory (CORE_ADDR memaddr
, char *myaddr
, int len
,
1265 int write
, struct mem_attrib
*attrib
,
1266 struct target_ops
*target
)
1268 /* I infer from D Taylor's code that there's a limit on the amount
1269 we can transfer in one chunk.. */
1274 int thisbite
= len
- done
;
1275 if (thisbite
> RDP_MOUTHFULL
)
1276 thisbite
= RDP_MOUTHFULL
;
1282 justdone
= rdp_write (memaddr
+ done
, myaddr
+ done
, thisbite
);
1286 justdone
= rdp_read (memaddr
+ done
, myaddr
+ done
, thisbite
);
1291 if (justdone
!= thisbite
)
1304 static struct yn stepinfo
[] =
1306 {"Step more than one instruction", RDP_INFO_ABOUT_STEP_GT_1
},
1307 {"Step to jump", RDP_INFO_ABOUT_STEP_TO_JMP
},
1308 {"Step one instruction", RDP_INFO_ABOUT_STEP_1
},
1312 static struct yn breakinfo
[] =
1314 {"comparison breakpoints supported", RDP_INFO_ABOUT_BREAK_COMP
},
1315 {"range breakpoints supported", RDP_INFO_ABOUT_BREAK_RANGE
},
1316 {"watchpoints for byte reads supported", RDP_INFO_ABOUT_BREAK_BYTE_READ
},
1317 {"watchpoints for half-word reads supported", RDP_INFO_ABOUT_BREAK_HALFWORD_READ
},
1318 {"watchpoints for word reads supported", RDP_INFO_ABOUT_BREAK_WORD_READ
},
1319 {"watchpoints for byte writes supported", RDP_INFO_ABOUT_BREAK_BYTE_WRITE
},
1320 {"watchpoints for half-word writes supported", RDP_INFO_ABOUT_BREAK_HALFWORD_WRITE
},
1321 {"watchpoints for word writes supported", RDP_INFO_ABOUT_BREAK_WORD_WRITE
},
1322 {"mask break/watch-points supported", RDP_INFO_ABOUT_BREAK_MASK
},
1323 {"thread-specific breakpoints supported", RDP_INFO_ABOUT_BREAK_THREAD_BREAK
},
1324 {"thread-specific watchpoints supported", RDP_INFO_ABOUT_BREAK_THREAD_WATCH
},
1325 {"conditional breakpoints supported", RDP_INFO_ABOUT_BREAK_COND
},
1331 dump_bits (struct yn
*t
, int info
)
1335 printf_unfiltered (" %-45s : %s\n", t
->name
, (info
& t
->bit
) ? "Yes" : "No");
1341 remote_rdp_files_info (struct target_ops
*target
)
1343 printf_filtered ("Target capabilities:\n");
1344 dump_bits (stepinfo
, ds
.step_info
);
1345 dump_bits (breakinfo
, ds
.break_info
);
1346 printf_unfiltered ("target level RDI %x\n", (ds
.target_info
>> 5) & 3);
1351 remote_rdp_create_inferior (char *exec_file
, char *allargs
, char **env
,
1354 CORE_ADDR entry_point
;
1356 if (exec_file
== 0 || exec_bfd
== 0)
1357 error (_("No executable file specified."));
1359 entry_point
= (CORE_ADDR
) bfd_get_start_address (exec_bfd
);
1362 remove_breakpoints ();
1363 init_wait_for_inferior ();
1365 /* This gives us a chance to set up the command line */
1366 rdp_set_command_line (exec_file
, allargs
);
1368 inferior_ptid
= pid_to_ptid (42);
1369 insert_breakpoints (); /* Needed to get correct instruction in cache */
1372 ** RDP targets don't provide any facility to set the top of memory,
1373 ** so we don't bother to look for MEMSIZE in the environment.
1376 write_pc (entry_point
);
1379 /* Attach doesn't need to do anything */
1381 remote_rdp_attach (char *args
, int from_tty
)
1386 /* Define the target subroutine names */
1388 struct target_ops remote_rdp_ops
;
1391 init_remote_rdp_ops (void)
1393 remote_rdp_ops
.to_shortname
= "rdp";
1394 remote_rdp_ops
.to_longname
= "Remote Target using the RDProtocol";
1395 remote_rdp_ops
.to_doc
= "Use a remote ARM system which uses the ARM Remote Debugging Protocol";
1396 remote_rdp_ops
.to_open
= remote_rdp_open
;
1397 remote_rdp_ops
.to_close
= remote_rdp_close
;
1398 remote_rdp_ops
.to_attach
= remote_rdp_attach
;
1399 remote_rdp_ops
.to_resume
= remote_rdp_resume
;
1400 remote_rdp_ops
.to_wait
= remote_rdp_wait
;
1401 remote_rdp_ops
.to_fetch_registers
= remote_rdp_fetch_register
;
1402 remote_rdp_ops
.to_store_registers
= remote_rdp_store_register
;
1403 remote_rdp_ops
.to_prepare_to_store
= remote_rdp_prepare_to_store
;
1404 remote_rdp_ops
.deprecated_xfer_memory
= remote_rdp_xfer_inferior_memory
;
1405 remote_rdp_ops
.to_files_info
= remote_rdp_files_info
;
1406 remote_rdp_ops
.to_insert_breakpoint
= remote_rdp_insert_breakpoint
;
1407 remote_rdp_ops
.to_remove_breakpoint
= remote_rdp_remove_breakpoint
;
1408 remote_rdp_ops
.to_kill
= remote_rdp_kill
;
1409 remote_rdp_ops
.to_load
= generic_load
;
1410 remote_rdp_ops
.to_create_inferior
= remote_rdp_create_inferior
;
1411 remote_rdp_ops
.to_mourn_inferior
= generic_mourn_inferior
;
1412 remote_rdp_ops
.to_stratum
= process_stratum
;
1413 remote_rdp_ops
.to_has_all_memory
= 1;
1414 remote_rdp_ops
.to_has_memory
= 1;
1415 remote_rdp_ops
.to_has_stack
= 1;
1416 remote_rdp_ops
.to_has_registers
= 1;
1417 remote_rdp_ops
.to_has_execution
= 1;
1418 remote_rdp_ops
.to_magic
= OPS_MAGIC
;
1421 extern initialize_file_ftype _initialize_remote_rdp
; /* -Wmissing-prototypes */
1424 _initialize_remote_rdp (void)
1426 init_remote_rdp_ops ();
1427 add_target (&remote_rdp_ops
);