1 /* Remote debugging for the ARM RDP interface.
2 Copyright 1994, 1995, 2001 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
26 Much of this file (in particular the SWI stuff) is based on code by
29 I hacked on and simplified it by removing a lot of sexy features he
30 had added, and some of the (unix specific) workarounds he'd done
31 for other GDB problems - which if they still exist should be fixed
32 in GDB, not in a remote-foo thing . I also made it conform more to
33 the doc I have; which may be wrong.
47 #include "remote-utils.h"
48 #include "gdb_string.h"
56 extern struct target_ops remote_rdp_ops;
58 static host_callback *callback = &default_callback;
67 char command_line[10];
69 int rdi_stopped_status;
75 /* Definitions for the RDP protocol. */
77 #define RDP_MOUTHFULL (1<<6)
78 #define FPU_COPRO_NUMBER 1
81 #define RDP_OPEN_TYPE_COLD 0
82 #define RDP_OPEN_TYPE_WARM 1
83 #define RDP_OPEN_TYPE_BAUDRATE 2
85 #define RDP_OPEN_BAUDRATE_9600 1
86 #define RDP_OPEN_BAUDRATE_19200 2
87 #define RDP_OPEN_BAUDRATE_38400 3
89 #define RDP_OPEN_TYPE_RETURN_SEX (1<<3)
93 #define RDP_MEM_READ 2
95 #define RDP_MEM_WRITE 3
97 #define RDP_CPU_READ 4
98 #define RDP_CPU_WRITE 5
99 #define RDP_CPU_READWRITE_MODE_CURRENT 255
100 #define RDP_CPU_READWRITE_MASK_PC (1<<16)
101 #define RDP_CPU_READWRITE_MASK_CPSR (1<<17)
102 #define RDP_CPU_READWRITE_MASK_SPSR (1<<18)
104 #define RDP_COPRO_READ 6
105 #define RDP_COPRO_WRITE 7
106 #define RDP_FPU_READWRITE_MASK_FPS (1<<8)
108 #define RDP_SET_BREAK 0xa
109 #define RDP_SET_BREAK_TYPE_PC_EQUAL 0
110 #define RDP_SET_BREAK_TYPE_GET_HANDLE (0x10)
112 #define RDP_CLEAR_BREAK 0xb
114 #define RDP_EXEC 0x10
115 #define RDP_EXEC_TYPE_SYNC 0
117 #define RDP_STEP 0x11
119 #define RDP_INFO 0x12
120 #define RDP_INFO_ABOUT_STEP 2
121 #define RDP_INFO_ABOUT_STEP_GT_1 1
122 #define RDP_INFO_ABOUT_STEP_TO_JMP 2
123 #define RDP_INFO_ABOUT_STEP_1 4
124 #define RDP_INFO_ABOUT_TARGET 0
125 #define RDP_INFO_ABOUT_BREAK 1
126 #define RDP_INFO_ABOUT_BREAK_COMP 1
127 #define RDP_INFO_ABOUT_BREAK_RANGE 2
128 #define RDP_INFO_ABOUT_BREAK_BYTE_READ 4
129 #define RDP_INFO_ABOUT_BREAK_HALFWORD_READ 8
130 #define RDP_INFO_ABOUT_BREAK_WORD_READ (1<<4)
131 #define RDP_INFO_ABOUT_BREAK_BYTE_WRITE (1<<5)
132 #define RDP_INFO_ABOUT_BREAK_HALFWORD_WRITE (1<<6)
133 #define RDP_INFO_ABOUT_BREAK_WORD_WRITE (1<<7)
134 #define RDP_INFO_ABOUT_BREAK_MASK (1<<8)
135 #define RDP_INFO_ABOUT_BREAK_THREAD_BREAK (1<<9)
136 #define RDP_INFO_ABOUT_BREAK_THREAD_WATCH (1<<10)
137 #define RDP_INFO_ABOUT_BREAK_COND (1<<11)
138 #define RDP_INFO_VECTOR_CATCH (0x180)
139 #define RDP_INFO_ICEBREAKER (7)
140 #define RDP_INFO_SET_CMDLINE (0x300)
142 #define RDP_SELECT_CONFIG (0x16)
143 #define RDI_ConfigCPU 0
144 #define RDI_ConfigSystem 1
145 #define RDI_MatchAny 0
146 #define RDI_MatchExactly 1
147 #define RDI_MatchNoEarlier 2
149 #define RDP_RESET 0x7f
151 /* Returns from RDP */
152 #define RDP_RES_STOPPED 0x20
153 #define RDP_RES_SWI 0x21
154 #define RDP_RES_FATAL 0x5e
155 #define RDP_RES_VALUE 0x5f
156 #define RDP_RES_VALUE_LITTLE_ENDIAN 240
157 #define RDP_RES_VALUE_BIG_ENDIAN 241
158 #define RDP_RES_RESET 0x7f
159 #define RDP_RES_AT_BREAKPOINT 143
160 #define RDP_RES_IDUNNO 0xe6
161 #define RDP_OSOpReply 0x13
162 #define RDP_OSOpWord 2
163 #define RDP_OSOpNothing 0
165 static int timeout = 2;
167 static char *commandline = NULL;
170 remote_rdp_xfer_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len,
172 struct mem_attrib *attrib,
173 struct target_ops *target);
176 /* Stuff for talking to the serial layer. */
181 int c = SERIAL_READCHAR (io, timeout);
184 fprintf_unfiltered (gdb_stdlog, "[%02x]\n", c);
186 if (c == SERIAL_TIMEOUT)
189 return (unsigned char) c;
191 error ("Timeout reading from remote_system");
197 /* Note that the target always speaks little-endian to us,
198 even if it's a big endian machine. */
202 unsigned int val = 0;
205 for (n = 0; n < 4; n++)
217 fprintf_unfiltered (gdb_stdlog, "(%02x)\n", val);
218 SERIAL_WRITE (io, &val, 1);
224 /* We always send in little endian */
232 fprintf_unfiltered (gdb_stdlog, "(%04x)", val);
234 SERIAL_WRITE (io, b, 4);
239 /* Stuff for talking to the RDP layer. */
241 /* This is a bit more fancy that need be so that it syncs even in nasty cases.
243 I'be been unable to make it reliably sync up with the change
244 baudrate open command. It likes to sit and say it's been reset,
245 with no more action. So I took all that code out. I'd rather sync
246 reliably at 9600 than wait forever for a possible 19200 connection.
250 rdp_init (int cold, int tty)
253 int type = cold ? RDP_OPEN_TYPE_COLD : RDP_OPEN_TYPE_WARM;
256 time_t now = time (0);
257 time_t stop_time = now + 10; /* Try and sync for 10 seconds, then give up */
260 while (time (0) < stop_time && !sync)
265 SERIAL_FLUSH_INPUT (io);
266 SERIAL_FLUSH_OUTPUT (io);
269 printf_unfiltered ("Trying to connect at %d baud.\n", baudtry);
272 ** It seems necessary to reset an EmbeddedICE to get it going.
273 ** This has the side benefit of displaying the startup banner.
277 put_byte (RDP_RESET);
278 while ((restype = SERIAL_READCHAR (io, 1)) > 0)
285 /* Sent at start of reset process: ignore */
288 printf_unfiltered ("%c", isgraph (restype) ? restype : ' ');
295 /* Got end-of-banner mark */
296 printf_filtered ("\n");
302 put_byte (type | RDP_OPEN_TYPE_RETURN_SEX);
305 while (!sync && (restype = SERIAL_READCHAR (io, 1)) > 0)
308 fprintf_unfiltered (gdb_stdlog, "[%02x]\n", restype);
316 while ((restype = SERIAL_READCHAR (io, 1)) == RDP_RESET)
320 printf_unfiltered ("%c", isgraph (restype) ? restype : ' ');
322 while ((restype = SERIAL_READCHAR (io, 1)) > 0);
326 printf_unfiltered ("\nThe board has sent notification that it was reset.\n");
327 printf_unfiltered ("Waiting for it to settle down...\n");
331 printf_unfiltered ("\nTrying again.\n");
340 int resval = SERIAL_READCHAR (io, 1);
343 fprintf_unfiltered (gdb_stdlog, "[%02x]\n", resval);
349 case RDP_RES_VALUE_LITTLE_ENDIAN:
350 target_byte_order = LITTLE_ENDIAN;
353 case RDP_RES_VALUE_BIG_ENDIAN:
354 target_byte_order = BIG_ENDIAN;
367 error ("Couldn't reset the board, try pressing the reset button");
373 send_rdp (char *template,...)
378 va_start (alist, template);
390 val = va_arg (alist, int);
394 val = va_arg (alist, int);
402 if (val != RDP_RES_VALUE)
404 printf_unfiltered ("got bad res value of %d, %x\n", val, val);
408 pstat = va_arg (alist, int *);
409 pi = va_arg (alist, int *);
411 *pstat = get_byte ();
412 /* Check the result was zero, if not read the syndrome */
419 /* Check the result code */
426 /* Target can't do it; never mind */
427 printf_unfiltered ("RDP: Insufficient privilege\n");
430 /* Target can't do it; never mind */
431 printf_unfiltered ("RDP: Unimplemented message\n");
434 error ("Command garbled");
437 error ("Corrupt reply from target");
442 /* Read a word from the target */
443 pi = va_arg (alist, int *);
447 /* Read in some bytes from the target. */
448 pc = va_arg (alist, char *);
449 val = va_arg (alist, int);
450 for (i = 0; i < val; i++)
456 /* send what's being pointed at */
457 pc = va_arg (alist, char *);
458 val = va_arg (alist, int);
460 SERIAL_WRITE (io, pc, val);
463 /* Send whats in the queue */
466 SERIAL_WRITE (io, buf, dst - buf);
471 pi = va_arg (alist, int *);
475 internal_error (__FILE__, __LINE__, "failed internal consistency check");
481 internal_error (__FILE__, __LINE__, "failed internal consistency check");
486 rdp_write (CORE_ADDR memaddr, char *buf, int len)
491 send_rdp ("bww-p-SV", RDP_MEM_WRITE, memaddr, len, buf, len, &res, &val);
502 rdp_read (CORE_ADDR memaddr, char *buf, int len)
506 send_rdp ("bww-S-P-V",
507 RDP_MEM_READ, memaddr, len,
518 rdp_fetch_one_register (int mask, char *buf)
521 send_rdp ("bbw-SWZ", RDP_CPU_READ, RDP_CPU_READWRITE_MODE_CURRENT, mask, &val);
522 store_signed_integer (buf, 4, val);
526 rdp_fetch_one_fpu_register (int mask, char *buf)
529 /* !!! Since the PIE board doesn't work as documented,
530 and it doesn't have FPU hardware anyway and since it
531 slows everything down, I've disabled this. */
533 if (mask == RDP_FPU_READWRITE_MASK_FPS)
535 /* this guy is only a word */
536 send_rdp ("bbw-SWZ", RDP_COPRO_READ, FPU_COPRO_NUMBER, mask, &val);
537 store_signed_integer (buf, 4, val);
541 /* There are 12 bytes long
542 !! fixme about endianness
544 int dummy; /* I've seen these come back as four words !! */
545 send_rdp ("bbw-SWWWWZ", RDP_COPRO_READ, FPU_COPRO_NUMBER, mask, buf + 0, buf + 4, buf + 8, &dummy);
548 memset (buf, 0, MAX_REGISTER_RAW_SIZE);
553 rdp_store_one_register (int mask, char *buf)
555 int val = extract_unsigned_integer (buf, 4);
558 RDP_CPU_WRITE, RDP_CPU_READWRITE_MODE_CURRENT, mask, val);
563 rdp_store_one_fpu_register (int mask, char *buf)
566 /* See comment in fetch_one_fpu_register */
567 if (mask == RDP_FPU_READWRITE_MASK_FPS)
569 int val = extract_unsigned_integer (buf, 4);
570 /* this guy is only a word */
571 send_rdp ("bbww-SZ", RDP_COPRO_WRITE,
577 /* There are 12 bytes long
578 !! fixme about endianness
581 /* I've seen these come as four words, not the three advertized !! */
582 printf ("Sending mask %x\n", mask);
583 send_rdp ("bbwwwww-SZ",
592 printf ("done mask %x\n", mask);
598 /* Convert between GDB requests and the RDP layer. */
601 remote_rdp_fetch_register (int regno)
605 for (regno = 0; regno < NUM_REGS; regno++)
606 remote_rdp_fetch_register (regno);
610 char buf[MAX_REGISTER_RAW_SIZE];
612 rdp_fetch_one_register (1 << regno, buf);
613 else if (regno == PC_REGNUM)
614 rdp_fetch_one_register (RDP_CPU_READWRITE_MASK_PC, buf);
615 else if (regno == PS_REGNUM)
616 rdp_fetch_one_register (RDP_CPU_READWRITE_MASK_CPSR, buf);
617 else if (regno == FPS_REGNUM)
618 rdp_fetch_one_fpu_register (RDP_FPU_READWRITE_MASK_FPS, buf);
619 else if (regno >= F0_REGNUM && regno <= F7_REGNUM)
620 rdp_fetch_one_fpu_register (1 << (regno - F0_REGNUM), buf);
623 printf ("Help me with fetch reg %d\n", regno);
625 supply_register (regno, buf);
631 remote_rdp_store_register (int regno)
635 for (regno = 0; regno < NUM_REGS; regno++)
636 remote_rdp_store_register (regno);
640 char tmp[MAX_REGISTER_RAW_SIZE];
641 read_register_gen (regno, tmp);
643 rdp_store_one_register (1 << regno, tmp);
644 else if (regno == PC_REGNUM)
645 rdp_store_one_register (RDP_CPU_READWRITE_MASK_PC, tmp);
646 else if (regno == PS_REGNUM)
647 rdp_store_one_register (RDP_CPU_READWRITE_MASK_CPSR, tmp);
648 else if (regno >= F0_REGNUM && regno <= F7_REGNUM)
649 rdp_store_one_fpu_register (1 << (regno - F0_REGNUM), tmp);
652 printf ("Help me with reg %d\n", regno);
658 remote_rdp_kill (void)
660 callback->shutdown (callback);
667 send_rdp ("bw-S-W-Z", RDP_INFO, RDP_INFO_ABOUT_STEP,
669 send_rdp ("bw-S-W-Z", RDP_INFO, RDP_INFO_ABOUT_BREAK,
671 send_rdp ("bw-S-WW-Z", RDP_INFO, RDP_INFO_ABOUT_TARGET,
675 ds.can_step = ds.step_info & RDP_INFO_ABOUT_STEP_1;
677 ds.rdi_level = (ds.target_info >> 5) & 3;
682 rdp_execute_start (void)
684 /* Start it off, but don't wait for it */
685 send_rdp ("bb-", RDP_EXEC, RDP_EXEC_TYPE_SYNC);
690 rdp_set_command_line (char *command, char *args)
693 ** We could use RDP_INFO_SET_CMDLINE to send this, but EmbeddedICE systems
694 ** don't implement that, and get all confused at the unexpected text.
695 ** Instead, just keep a copy, and send it when the target does a SWI_GetEnv
698 if (commandline != NULL)
701 commandline = malloc (strlen (command) + strlen (args) + 2);
702 if (commandline != NULL)
704 strcpy (commandline, command);
705 strcat (commandline, " ");
706 strcat (commandline, args);
711 rdp_catch_vectors (void)
714 ** We want the target monitor to intercept the abort vectors
715 ** i.e. stop the program if any of these are used.
717 send_rdp ("bww-SZ", RDP_INFO, RDP_INFO_VECTOR_CATCH,
719 ** Specify a bitmask including
721 ** the undefined instruction vector
722 ** the prefetch abort vector
723 ** the data abort vector
724 ** the address exception vector
726 (1 << 0) | (1 << 1) | (1 << 3) | (1 << 4) | (1 << 5)
749 #define SWI_WriteC 0x0
750 #define SWI_Write0 0x2
751 #define SWI_ReadC 0x4
753 #define SWI_GetEnv 0x10
754 #define SWI_Exit 0x11
755 #define SWI_EnterOS 0x16
757 #define SWI_GetErrno 0x60
758 #define SWI_Clock 0x61
760 #define SWI_Time 0x63
761 #define SWI_Remove 0x64
762 #define SWI_Rename 0x65
763 #define SWI_Open 0x66
765 #define SWI_Close 0x68
766 #define SWI_Write 0x69
767 #define SWI_Read 0x6a
768 #define SWI_Seek 0x6b
769 #define SWI_Flen 0x6c
771 #define SWI_IsTTY 0x6e
772 #define SWI_TmpNam 0x6f
773 #define SWI_InstallHandler 0x70
774 #define SWI_GenerateError 0x71
781 static int translate_open_mode[] =
784 O_RDONLY + O_BINARY, /* "rb" */
786 O_RDWR + O_BINARY, /* "r+b" */
787 O_WRONLY + O_CREAT + O_TRUNC, /* "w" */
788 O_WRONLY + O_BINARY + O_CREAT + O_TRUNC, /* "wb" */
789 O_RDWR + O_CREAT + O_TRUNC, /* "w+" */
790 O_RDWR + O_BINARY + O_CREAT + O_TRUNC, /* "w+b" */
791 O_WRONLY + O_APPEND + O_CREAT, /* "a" */
792 O_WRONLY + O_BINARY + O_APPEND + O_CREAT, /* "ab" */
793 O_RDWR + O_APPEND + O_CREAT, /* "a+" */
794 O_RDWR + O_BINARY + O_APPEND + O_CREAT /* "a+b" */
798 exec_swi (int swi, argsin *args)
805 callback->write_stdout (callback, &c, 1);
808 for (i = 0; i < args->n; i++)
809 callback->write_stdout (callback, args->s, strlen (args->s));
812 callback->read_stdin (callback, &c, 1);
816 args->n = callback->system (callback, args->s);
819 args->n = callback->get_errno (callback);
822 args->n = callback->time (callback, NULL);
826 /* return number of centi-seconds... */
828 #ifdef CLOCKS_PER_SEC
829 (CLOCKS_PER_SEC >= 100)
830 ? (clock () / (CLOCKS_PER_SEC / 100))
831 : ((clock () * 100) / CLOCKS_PER_SEC);
833 /* presume unix... clock() returns microseconds */
839 args->n = callback->unlink (callback, args->s);
842 args->n = callback->rename (callback, args[0].s, args[1].s);
846 /* Now we need to decode the Demon open mode */
847 i = translate_open_mode[args[1].n];
849 /* Filename ":tt" is special: it denotes stdin/out */
850 if (strcmp (args->s, ":tt") == 0)
852 if (i == O_RDONLY) /* opening tty "r" */
853 args->n = 0 /* stdin */ ;
855 args->n = 1 /* stdout */ ;
858 args->n = callback->open (callback, args->s, i);
862 args->n = callback->close (callback, args->n);
866 /* Return the number of bytes *not* written */
867 args->n = args[1].n -
868 callback->write (callback, args[0].n, args[1].s, args[1].n);
873 char *copy = alloca (args[2].n);
874 int done = callback->read (callback, args[0].n, copy, args[2].n);
876 remote_rdp_xfer_inferior_memory (args[1].n, copy, done, 1, 0, 0);
877 args->n = args[2].n - done;
882 /* Return non-zero on failure */
883 args->n = callback->lseek (callback, args[0].n, args[1].n, 0) < 0;
888 long old = callback->lseek (callback, args->n, 0, SEEK_CUR);
889 args->n = callback->lseek (callback, args->n, 0, SEEK_END);
890 callback->lseek (callback, args->n, old, 0);
895 args->n = callback->isatty (callback, args->n);
899 if (commandline != NULL)
901 int len = strlen (commandline);
905 commandline[255] = '\0';
907 remote_rdp_xfer_inferior_memory (args[0].n,
908 commandline, len + 1, 1, 0, 0);
911 remote_rdp_xfer_inferior_memory (args[0].n, "", 1, 1, 0, 0);
928 int swino = get_word ();
929 int type = get_byte ();
935 args[count].n = get_byte ();
939 args[count].n = get_word ();
943 /* If the word is under 32 bytes it will be sent otherwise
944 an address to it is passed. Also: Special case of 255 */
954 remote_rdp_xfer_inferior_memory (get_word (),
964 buf = alloca (len + 1);
965 for (i = 0; i < len; i++)
966 buf[i] = get_byte ();
974 error ("Unimplemented SWI argument");
981 if (exec_swi (swino, args))
983 /* We have two options here reply with either a byte or a word
984 which is stored in args[0].n. There is no harm in replying with
985 a word all the time, so thats what I do! */
986 send_rdp ("bbw-", RDP_OSOpReply, RDP_OSOpWord, args[0].n);
990 send_rdp ("bb-", RDP_OSOpReply, RDP_OSOpNothing);
995 rdp_execute_finish (void)
1002 res = SERIAL_READCHAR (io, 1);
1003 while (res == SERIAL_TIMEOUT)
1006 printf_filtered ("Waiting for target..\n");
1007 res = SERIAL_READCHAR (io, 1);
1016 send_rdp ("B", &ds.rdi_stopped_status);
1020 printf_filtered ("Target reset\n");
1024 printf_filtered ("Ignoring %x\n", res);
1034 rdp_execute_start ();
1035 rdp_execute_finish ();
1039 remote_rdp_insert_breakpoint (CORE_ADDR addr, char *save)
1042 if (ds.rdi_level > 0)
1044 send_rdp ("bwb-SWB",
1047 RDP_SET_BREAK_TYPE_PC_EQUAL | RDP_SET_BREAK_TYPE_GET_HANDLE,
1056 RDP_SET_BREAK_TYPE_PC_EQUAL,
1063 remote_rdp_remove_breakpoint (CORE_ADDR addr, char *save)
1066 if (ds.rdi_level > 0)
1068 send_rdp ("b-p-S-B",
1086 if (ds.can_step && 0)
1088 /* The pie board can't do steps so I can't test this, and
1089 the other code will always work. */
1091 send_rdp ("bbw-S-B",
1098 CORE_ADDR pc = read_register (PC_REGNUM);
1099 pc = arm_get_next_pc (pc);
1100 remote_rdp_insert_breakpoint (pc, handle);
1102 remote_rdp_remove_breakpoint (pc, handle);
1107 remote_rdp_open (char *args, int from_tty)
1112 error_no_arg ("serial port device name");
1116 target_preopen (from_tty);
1118 io = SERIAL_OPEN (args);
1121 perror_with_name (args);
1125 rdp_init (1, from_tty);
1130 printf_unfiltered ("Remote RDP debugging using %s at %d baud\n", args, baud_rate);
1135 /* Need to set up the vector interception state */
1136 rdp_catch_vectors ();
1139 ** If it's an EmbeddedICE, we need to set the processor config.
1140 ** Assume we can always have ARM7TDI...
1142 send_rdp ("bw-SB", RDP_INFO, RDP_INFO_ICEBREAKER, ¬_icebreaker);
1143 if (!not_icebreaker)
1145 const char *CPU = "ARM7TDI";
1147 int len = strlen (CPU);
1149 send_rdp ("bbbbw-p-SWZ",
1151 RDI_ConfigCPU, /* Aspect: set the CPU */
1152 len, /* The number of bytes in the name */
1153 RDI_MatchAny, /* We'll take whatever we get */
1154 0, /* We'll take whatever version's there */
1159 /* command line initialised on 'run' */
1161 push_target (&remote_rdp_ops);
1163 callback->init (callback);
1164 flush_cached_frames ();
1165 registers_changed ();
1166 stop_pc = read_pc ();
1167 set_current_frame (create_new_frame (read_fp (), stop_pc));
1168 select_frame (get_current_frame (), 0);
1169 print_stack_frame (selected_frame, -1, 1);
1174 /* Close out all files and local state before this target loses control. */
1177 remote_rdp_close (int quitting)
1179 callback->shutdown (callback);
1186 /* Resume execution of the target process. STEP says whether to single-step
1187 or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be given
1188 to the target, or zero for no signal. */
1191 remote_rdp_resume (int pid, int step, enum target_signal siggnal)
1199 /* Wait for inferior process to do something. Return pid of child,
1200 or -1 in case of error; store status through argument pointer STATUS,
1201 just as `wait' would. */
1204 remote_rdp_wait (int pid, struct target_waitstatus *status)
1206 switch (ds.rdi_stopped_status)
1211 status->kind = TARGET_WAITKIND_EXITED;
1212 status->value.integer = read_register (0);
1214 case RDP_RES_AT_BREAKPOINT:
1215 status->kind = TARGET_WAITKIND_STOPPED;
1216 /* The signal in sigrc is a host signal. That probably
1218 status->value.sig = TARGET_SIGNAL_TRAP;
1222 status->kind = TARGET_WAITKIND_SIGNALLED;
1223 /* The signal in sigrc is a host signal. That probably
1225 status->value.sig = target_signal_from_host (sigrc);
1230 return inferior_pid;
1233 /* Get ready to modify the registers array. On machines which store
1234 individual registers, this doesn't need to do anything. On machines
1235 which store all the registers in one fell swoop, this makes sure
1236 that registers contains all the registers from the program being
1240 remote_rdp_prepare_to_store (void)
1242 /* Do nothing, since we can store individual regs */
1245 /* Transfer LEN bytes between GDB address MYADDR and target address
1246 MEMADDR. If WRITE is non-zero, transfer them to the target,
1247 otherwise transfer them from the target. TARGET is unused.
1249 Returns the number of bytes transferred. */
1252 remote_rdp_xfer_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len,
1254 struct mem_attrib *attrib ATTRIBUTE_UNUSED,
1255 struct target_ops *target ATTRIBUTE_UNUSED)
1257 /* I infer from D Taylor's code that there's a limit on the amount
1258 we can transfer in one chunk.. */
1263 int thisbite = len - done;
1264 if (thisbite > RDP_MOUTHFULL)
1265 thisbite = RDP_MOUTHFULL;
1271 justdone = rdp_write (memaddr + done, myaddr + done, thisbite);
1275 justdone = rdp_read (memaddr + done, myaddr + done, thisbite);
1280 if (justdone != thisbite)
1293 static struct yn stepinfo[] =
1295 {"Step more than one instruction", RDP_INFO_ABOUT_STEP_GT_1},
1296 {"Step to jump", RDP_INFO_ABOUT_STEP_TO_JMP},
1297 {"Step one instruction", RDP_INFO_ABOUT_STEP_1},
1301 static struct yn breakinfo[] =
1303 {"comparison breakpoints supported", RDP_INFO_ABOUT_BREAK_COMP},
1304 {"range breakpoints supported", RDP_INFO_ABOUT_BREAK_RANGE},
1305 {"watchpoints for byte reads supported", RDP_INFO_ABOUT_BREAK_BYTE_READ},
1306 {"watchpoints for half-word reads supported", RDP_INFO_ABOUT_BREAK_HALFWORD_READ},
1307 {"watchpoints for word reads supported", RDP_INFO_ABOUT_BREAK_WORD_READ},
1308 {"watchpoints for byte writes supported", RDP_INFO_ABOUT_BREAK_BYTE_WRITE},
1309 {"watchpoints for half-word writes supported", RDP_INFO_ABOUT_BREAK_HALFWORD_WRITE},
1310 {"watchpoints for word writes supported", RDP_INFO_ABOUT_BREAK_WORD_WRITE},
1311 {"mask break/watch-points supported", RDP_INFO_ABOUT_BREAK_MASK},
1312 {"thread-specific breakpoints supported", RDP_INFO_ABOUT_BREAK_THREAD_BREAK},
1313 {"thread-specific watchpoints supported", RDP_INFO_ABOUT_BREAK_THREAD_WATCH},
1314 {"conditional breakpoints supported", RDP_INFO_ABOUT_BREAK_COND},
1320 dump_bits (struct yn *t, int info)
1324 printf_unfiltered (" %-45s : %s\n", t->name, (info & t->bit) ? "Yes" : "No");
1330 remote_rdp_files_info (struct target_ops *target)
1332 printf_filtered ("Target capabilities:\n");
1333 dump_bits (stepinfo, ds.step_info);
1334 dump_bits (breakinfo, ds.break_info);
1335 printf_unfiltered ("target level RDI %x\n", (ds.target_info >> 5) & 3);
1340 remote_rdp_create_inferior (char *exec_file, char *allargs, char **env)
1342 CORE_ADDR entry_point;
1344 if (exec_file == 0 || exec_bfd == 0)
1345 error ("No executable file specified.");
1347 entry_point = (CORE_ADDR) bfd_get_start_address (exec_bfd);
1350 remove_breakpoints ();
1351 init_wait_for_inferior ();
1353 /* This gives us a chance to set up the command line */
1354 rdp_set_command_line (exec_file, allargs);
1357 insert_breakpoints (); /* Needed to get correct instruction in cache */
1360 ** RDP targets don't provide any facility to set the top of memory,
1361 ** so we don't bother to look for MEMSIZE in the environment.
1365 proceed (entry_point, TARGET_SIGNAL_DEFAULT, 0);
1368 /* Accept any stray run/attach commands */
1370 remote_rdp_can_run (void)
1375 /* Attach doesn't need to do anything */
1377 remote_rdp_attach (char *args, int from_tty)
1382 /* Define the target subroutine names */
1384 struct target_ops remote_rdp_ops;
1387 init_remote_rdp_ops (void)
1389 remote_rdp_ops.to_shortname = "rdp";
1390 remote_rdp_ops.to_longname = "Remote Target using the RDProtocol";
1391 remote_rdp_ops.to_doc = "Use a remote ARM system which uses the ARM Remote Debugging Protocol";
1392 remote_rdp_ops.to_open = remote_rdp_open;
1393 remote_rdp_ops.to_close = remote_rdp_close;
1394 remote_rdp_ops.to_attach = remote_rdp_attach;
1395 remote_rdp_ops.to_post_attach = NULL;
1396 remote_rdp_ops.to_require_attach = NULL;
1397 remote_rdp_ops.to_detach = NULL;
1398 remote_rdp_ops.to_require_detach = NULL;
1399 remote_rdp_ops.to_resume = remote_rdp_resume;
1400 remote_rdp_ops.to_wait = remote_rdp_wait;
1401 remote_rdp_ops.to_post_wait = NULL;
1402 remote_rdp_ops.to_fetch_registers = remote_rdp_fetch_register;
1403 remote_rdp_ops.to_store_registers = remote_rdp_store_register;
1404 remote_rdp_ops.to_prepare_to_store = remote_rdp_prepare_to_store;
1405 remote_rdp_ops.to_xfer_memory = remote_rdp_xfer_inferior_memory;
1406 remote_rdp_ops.to_files_info = remote_rdp_files_info;
1407 remote_rdp_ops.to_insert_breakpoint = remote_rdp_insert_breakpoint;
1408 remote_rdp_ops.to_remove_breakpoint = remote_rdp_remove_breakpoint;
1409 remote_rdp_ops.to_terminal_init = NULL;
1410 remote_rdp_ops.to_terminal_inferior = NULL;
1411 remote_rdp_ops.to_terminal_ours_for_output = NULL;
1412 remote_rdp_ops.to_terminal_ours = NULL;
1413 remote_rdp_ops.to_terminal_info = NULL;
1414 remote_rdp_ops.to_kill = remote_rdp_kill;
1415 remote_rdp_ops.to_load = generic_load;
1416 remote_rdp_ops.to_lookup_symbol = NULL;
1417 remote_rdp_ops.to_create_inferior = remote_rdp_create_inferior;
1418 remote_rdp_ops.to_post_startup_inferior = NULL;
1419 remote_rdp_ops.to_acknowledge_created_inferior = NULL;
1420 remote_rdp_ops.to_clone_and_follow_inferior = NULL;
1421 remote_rdp_ops.to_post_follow_inferior_by_clone = NULL;
1422 remote_rdp_ops.to_insert_fork_catchpoint = NULL;
1423 remote_rdp_ops.to_remove_fork_catchpoint = NULL;
1424 remote_rdp_ops.to_insert_vfork_catchpoint = NULL;
1425 remote_rdp_ops.to_remove_vfork_catchpoint = NULL;
1426 remote_rdp_ops.to_has_forked = NULL;
1427 remote_rdp_ops.to_has_vforked = NULL;
1428 remote_rdp_ops.to_can_follow_vfork_prior_to_exec = NULL;
1429 remote_rdp_ops.to_post_follow_vfork = NULL;
1430 remote_rdp_ops.to_insert_exec_catchpoint = NULL;
1431 remote_rdp_ops.to_remove_exec_catchpoint = NULL;
1432 remote_rdp_ops.to_has_execd = NULL;
1433 remote_rdp_ops.to_reported_exec_events_per_exec_call = NULL;
1434 remote_rdp_ops.to_has_exited = NULL;
1435 remote_rdp_ops.to_mourn_inferior = generic_mourn_inferior;
1436 remote_rdp_ops.to_can_run = remote_rdp_can_run;
1437 remote_rdp_ops.to_notice_signals = 0;
1438 remote_rdp_ops.to_thread_alive = 0;
1439 remote_rdp_ops.to_stop = 0;
1440 remote_rdp_ops.to_pid_to_exec_file = NULL;
1441 remote_rdp_ops.to_core_file_to_sym_file = NULL;
1442 remote_rdp_ops.to_stratum = process_stratum;
1443 remote_rdp_ops.DONT_USE = NULL;
1444 remote_rdp_ops.to_has_all_memory = 1;
1445 remote_rdp_ops.to_has_memory = 1;
1446 remote_rdp_ops.to_has_stack = 1;
1447 remote_rdp_ops.to_has_registers = 1;
1448 remote_rdp_ops.to_has_execution = 1;
1449 remote_rdp_ops.to_sections = NULL;
1450 remote_rdp_ops.to_sections_end = NULL;
1451 remote_rdp_ops.to_magic = OPS_MAGIC;
1455 _initialize_remote_rdp (void)
1457 init_remote_rdp_ops ();
1458 add_target (&remote_rdp_ops);