Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Remote debugging for the ARM RDP interface. |
b6ba6518 KB |
2 | Copyright 1994, 1995, 1998, 1999, 2000, 2001 |
3 | Free Software Foundation, Inc. | |
c906108c SS |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
c5aa993b JM |
19 | Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | |
c906108c SS |
21 | |
22 | ||
23 | */ | |
24 | ||
25 | ||
26 | /* | |
27 | Much of this file (in particular the SWI stuff) is based on code by | |
28 | David Taylor (djt1000@uk.ac.cam.hermes). | |
29 | ||
30 | I hacked on and simplified it by removing a lot of sexy features he | |
31 | had added, and some of the (unix specific) workarounds he'd done | |
32 | for other GDB problems - which if they still exist should be fixed | |
33 | in GDB, not in a remote-foo thing . I also made it conform more to | |
34 | the doc I have; which may be wrong. | |
35 | ||
36 | Steve Chamberlain (sac@cygnus.com). | |
37 | */ | |
38 | ||
39 | ||
40 | #include "defs.h" | |
41 | #include "inferior.h" | |
c906108c SS |
42 | #include "value.h" |
43 | #include "callback.h" | |
44 | #include "command.h" | |
c906108c SS |
45 | #include <ctype.h> |
46 | #include <fcntl.h> | |
47 | #include "symfile.h" | |
48 | #include "remote-utils.h" | |
49 | #include "gdb_string.h" | |
c906108c | 50 | #include "gdbcore.h" |
4e052eda | 51 | #include "regcache.h" |
c906108c | 52 | |
104c1213 JM |
53 | #ifdef HAVE_TIME_H |
54 | #include <time.h> | |
55 | #endif | |
c906108c SS |
56 | |
57 | extern struct target_ops remote_rdp_ops; | |
58 | static serial_t io; | |
59 | static host_callback *callback = &default_callback; | |
60 | ||
61 | struct | |
62 | { | |
63 | int step_info; | |
64 | int break_info; | |
65 | int model_info; | |
66 | int target_info; | |
67 | int can_step; | |
68 | char command_line[10]; | |
69 | int rdi_level; | |
70 | int rdi_stopped_status; | |
71 | } | |
72 | ds; | |
73 | ||
74 | ||
75 | ||
76 | /* Definitions for the RDP protocol. */ | |
77 | ||
78 | #define RDP_MOUTHFULL (1<<6) | |
79 | #define FPU_COPRO_NUMBER 1 | |
80 | ||
81 | #define RDP_OPEN 0 | |
82 | #define RDP_OPEN_TYPE_COLD 0 | |
83 | #define RDP_OPEN_TYPE_WARM 1 | |
84 | #define RDP_OPEN_TYPE_BAUDRATE 2 | |
85 | ||
86 | #define RDP_OPEN_BAUDRATE_9600 1 | |
87 | #define RDP_OPEN_BAUDRATE_19200 2 | |
88 | #define RDP_OPEN_BAUDRATE_38400 3 | |
89 | ||
90 | #define RDP_OPEN_TYPE_RETURN_SEX (1<<3) | |
91 | ||
92 | #define RDP_CLOSE 1 | |
93 | ||
94 | #define RDP_MEM_READ 2 | |
95 | ||
96 | #define RDP_MEM_WRITE 3 | |
97 | ||
98 | #define RDP_CPU_READ 4 | |
99 | #define RDP_CPU_WRITE 5 | |
100 | #define RDP_CPU_READWRITE_MODE_CURRENT 255 | |
101 | #define RDP_CPU_READWRITE_MASK_PC (1<<16) | |
102 | #define RDP_CPU_READWRITE_MASK_CPSR (1<<17) | |
103 | #define RDP_CPU_READWRITE_MASK_SPSR (1<<18) | |
104 | ||
105 | #define RDP_COPRO_READ 6 | |
106 | #define RDP_COPRO_WRITE 7 | |
107 | #define RDP_FPU_READWRITE_MASK_FPS (1<<8) | |
108 | ||
109 | #define RDP_SET_BREAK 0xa | |
110 | #define RDP_SET_BREAK_TYPE_PC_EQUAL 0 | |
111 | #define RDP_SET_BREAK_TYPE_GET_HANDLE (0x10) | |
112 | ||
113 | #define RDP_CLEAR_BREAK 0xb | |
114 | ||
115 | #define RDP_EXEC 0x10 | |
116 | #define RDP_EXEC_TYPE_SYNC 0 | |
117 | ||
118 | #define RDP_STEP 0x11 | |
119 | ||
120 | #define RDP_INFO 0x12 | |
121 | #define RDP_INFO_ABOUT_STEP 2 | |
122 | #define RDP_INFO_ABOUT_STEP_GT_1 1 | |
123 | #define RDP_INFO_ABOUT_STEP_TO_JMP 2 | |
124 | #define RDP_INFO_ABOUT_STEP_1 4 | |
125 | #define RDP_INFO_ABOUT_TARGET 0 | |
126 | #define RDP_INFO_ABOUT_BREAK 1 | |
127 | #define RDP_INFO_ABOUT_BREAK_COMP 1 | |
128 | #define RDP_INFO_ABOUT_BREAK_RANGE 2 | |
129 | #define RDP_INFO_ABOUT_BREAK_BYTE_READ 4 | |
130 | #define RDP_INFO_ABOUT_BREAK_HALFWORD_READ 8 | |
131 | #define RDP_INFO_ABOUT_BREAK_WORD_READ (1<<4) | |
132 | #define RDP_INFO_ABOUT_BREAK_BYTE_WRITE (1<<5) | |
133 | #define RDP_INFO_ABOUT_BREAK_HALFWORD_WRITE (1<<6) | |
134 | #define RDP_INFO_ABOUT_BREAK_WORD_WRITE (1<<7) | |
135 | #define RDP_INFO_ABOUT_BREAK_MASK (1<<8) | |
136 | #define RDP_INFO_ABOUT_BREAK_THREAD_BREAK (1<<9) | |
137 | #define RDP_INFO_ABOUT_BREAK_THREAD_WATCH (1<<10) | |
138 | #define RDP_INFO_ABOUT_BREAK_COND (1<<11) | |
139 | #define RDP_INFO_VECTOR_CATCH (0x180) | |
140 | #define RDP_INFO_ICEBREAKER (7) | |
141 | #define RDP_INFO_SET_CMDLINE (0x300) | |
142 | ||
143 | #define RDP_SELECT_CONFIG (0x16) | |
144 | #define RDI_ConfigCPU 0 | |
145 | #define RDI_ConfigSystem 1 | |
146 | #define RDI_MatchAny 0 | |
147 | #define RDI_MatchExactly 1 | |
148 | #define RDI_MatchNoEarlier 2 | |
149 | ||
150 | #define RDP_RESET 0x7f | |
151 | ||
152 | /* Returns from RDP */ | |
153 | #define RDP_RES_STOPPED 0x20 | |
154 | #define RDP_RES_SWI 0x21 | |
155 | #define RDP_RES_FATAL 0x5e | |
156 | #define RDP_RES_VALUE 0x5f | |
157 | #define RDP_RES_VALUE_LITTLE_ENDIAN 240 | |
158 | #define RDP_RES_VALUE_BIG_ENDIAN 241 | |
159 | #define RDP_RES_RESET 0x7f | |
160 | #define RDP_RES_AT_BREAKPOINT 143 | |
161 | #define RDP_RES_IDUNNO 0xe6 | |
162 | #define RDP_OSOpReply 0x13 | |
163 | #define RDP_OSOpWord 2 | |
164 | #define RDP_OSOpNothing 0 | |
165 | ||
166 | static int timeout = 2; | |
167 | ||
c5aa993b | 168 | static char *commandline = NULL; |
c906108c SS |
169 | |
170 | static int | |
29e57380 C |
171 | remote_rdp_xfer_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len, |
172 | int write, | |
173 | struct mem_attrib *attrib, | |
174 | struct target_ops *target); | |
c906108c SS |
175 | |
176 | ||
177 | /* Stuff for talking to the serial layer. */ | |
178 | ||
179 | static unsigned char | |
fba45db2 | 180 | get_byte (void) |
c906108c SS |
181 | { |
182 | int c = SERIAL_READCHAR (io, timeout); | |
183 | ||
184 | if (remote_debug) | |
9846de1b | 185 | fprintf_unfiltered (gdb_stdlog, "[%02x]\n", c); |
c906108c SS |
186 | |
187 | if (c == SERIAL_TIMEOUT) | |
188 | { | |
189 | if (timeout == 0) | |
190 | return (unsigned char) c; | |
191 | ||
192 | error ("Timeout reading from remote_system"); | |
193 | } | |
194 | ||
195 | return c; | |
196 | } | |
197 | ||
198 | /* Note that the target always speaks little-endian to us, | |
199 | even if it's a big endian machine. */ | |
200 | static unsigned int | |
fba45db2 | 201 | get_word (void) |
c906108c SS |
202 | { |
203 | unsigned int val = 0; | |
204 | unsigned int c; | |
205 | int n; | |
206 | for (n = 0; n < 4; n++) | |
207 | { | |
208 | c = get_byte (); | |
209 | val |= c << (n * 8); | |
210 | } | |
211 | return val; | |
212 | } | |
213 | ||
214 | static void | |
fba45db2 | 215 | put_byte (char val) |
c906108c SS |
216 | { |
217 | if (remote_debug) | |
9846de1b | 218 | fprintf_unfiltered (gdb_stdlog, "(%02x)\n", val); |
c906108c SS |
219 | SERIAL_WRITE (io, &val, 1); |
220 | } | |
221 | ||
222 | static void | |
fba45db2 | 223 | put_word (int val) |
c906108c SS |
224 | { |
225 | /* We always send in little endian */ | |
226 | unsigned char b[4]; | |
227 | b[0] = val; | |
228 | b[1] = val >> 8; | |
229 | b[2] = val >> 16; | |
230 | b[3] = val >> 24; | |
231 | ||
232 | if (remote_debug) | |
9846de1b | 233 | fprintf_unfiltered (gdb_stdlog, "(%04x)", val); |
c906108c SS |
234 | |
235 | SERIAL_WRITE (io, b, 4); | |
236 | } | |
237 | ||
238 | ||
239 | ||
240 | /* Stuff for talking to the RDP layer. */ | |
241 | ||
242 | /* This is a bit more fancy that need be so that it syncs even in nasty cases. | |
243 | ||
244 | I'be been unable to make it reliably sync up with the change | |
245 | baudrate open command. It likes to sit and say it's been reset, | |
246 | with no more action. So I took all that code out. I'd rather sync | |
247 | reliably at 9600 than wait forever for a possible 19200 connection. | |
248 | ||
249 | */ | |
250 | static void | |
fba45db2 | 251 | rdp_init (int cold, int tty) |
c906108c SS |
252 | { |
253 | int sync = 0; | |
254 | int type = cold ? RDP_OPEN_TYPE_COLD : RDP_OPEN_TYPE_WARM; | |
255 | int baudtry = 9600; | |
256 | ||
257 | time_t now = time (0); | |
258 | time_t stop_time = now + 10; /* Try and sync for 10 seconds, then give up */ | |
259 | ||
260 | ||
261 | while (time (0) < stop_time && !sync) | |
262 | { | |
263 | int restype; | |
264 | QUIT; | |
265 | ||
266 | SERIAL_FLUSH_INPUT (io); | |
267 | SERIAL_FLUSH_OUTPUT (io); | |
268 | ||
269 | if (tty) | |
270 | printf_unfiltered ("Trying to connect at %d baud.\n", baudtry); | |
271 | ||
272 | /* | |
c5aa993b JM |
273 | ** It seems necessary to reset an EmbeddedICE to get it going. |
274 | ** This has the side benefit of displaying the startup banner. | |
275 | */ | |
c906108c SS |
276 | if (cold) |
277 | { | |
278 | put_byte (RDP_RESET); | |
279 | while ((restype = SERIAL_READCHAR (io, 1)) > 0) | |
280 | { | |
281 | switch (restype) | |
282 | { | |
283 | case SERIAL_TIMEOUT: | |
284 | break; | |
285 | case RDP_RESET: | |
286 | /* Sent at start of reset process: ignore */ | |
287 | break; | |
288 | default: | |
289 | printf_unfiltered ("%c", isgraph (restype) ? restype : ' '); | |
290 | break; | |
291 | } | |
292 | } | |
293 | ||
294 | if (restype == 0) | |
295 | { | |
296 | /* Got end-of-banner mark */ | |
297 | printf_filtered ("\n"); | |
298 | } | |
299 | } | |
300 | ||
301 | put_byte (RDP_OPEN); | |
302 | ||
c5aa993b | 303 | put_byte (type | RDP_OPEN_TYPE_RETURN_SEX); |
c906108c SS |
304 | put_word (0); |
305 | ||
306 | while (!sync && (restype = SERIAL_READCHAR (io, 1)) > 0) | |
307 | { | |
308 | if (remote_debug) | |
9846de1b | 309 | fprintf_unfiltered (gdb_stdlog, "[%02x]\n", restype); |
c906108c SS |
310 | |
311 | switch (restype) | |
312 | { | |
313 | case SERIAL_TIMEOUT: | |
314 | break; | |
315 | ||
316 | case RDP_RESET: | |
317 | while ((restype = SERIAL_READCHAR (io, 1)) == RDP_RESET) | |
318 | ; | |
319 | do | |
320 | { | |
321 | printf_unfiltered ("%c", isgraph (restype) ? restype : ' '); | |
322 | } | |
323 | while ((restype = SERIAL_READCHAR (io, 1)) > 0); | |
324 | ||
325 | if (tty) | |
326 | { | |
327 | printf_unfiltered ("\nThe board has sent notification that it was reset.\n"); | |
328 | printf_unfiltered ("Waiting for it to settle down...\n"); | |
329 | } | |
330 | sleep (3); | |
331 | if (tty) | |
332 | printf_unfiltered ("\nTrying again.\n"); | |
333 | cold = 0; | |
334 | break; | |
335 | ||
336 | default: | |
337 | break; | |
338 | ||
339 | case RDP_RES_VALUE: | |
340 | { | |
341 | int resval = SERIAL_READCHAR (io, 1); | |
342 | ||
343 | if (remote_debug) | |
9846de1b | 344 | fprintf_unfiltered (gdb_stdlog, "[%02x]\n", resval); |
c906108c SS |
345 | |
346 | switch (resval) | |
347 | { | |
348 | case SERIAL_TIMEOUT: | |
349 | break; | |
350 | case RDP_RES_VALUE_LITTLE_ENDIAN: | |
351 | target_byte_order = LITTLE_ENDIAN; | |
352 | sync = 1; | |
353 | break; | |
354 | case RDP_RES_VALUE_BIG_ENDIAN: | |
355 | target_byte_order = BIG_ENDIAN; | |
356 | sync = 1; | |
357 | break; | |
358 | default: | |
359 | break; | |
360 | } | |
361 | } | |
362 | } | |
363 | } | |
364 | } | |
365 | ||
366 | if (!sync) | |
367 | { | |
368 | error ("Couldn't reset the board, try pressing the reset button"); | |
369 | } | |
370 | } | |
371 | ||
372 | ||
c906108c SS |
373 | void |
374 | send_rdp (char *template,...) | |
c906108c SS |
375 | { |
376 | char buf[200]; | |
377 | char *dst = buf; | |
378 | va_list alist; | |
c906108c | 379 | va_start (alist, template); |
c906108c SS |
380 | |
381 | while (*template) | |
382 | { | |
383 | unsigned int val; | |
384 | int *pi; | |
385 | int *pstat; | |
386 | char *pc; | |
387 | int i; | |
388 | switch (*template++) | |
389 | { | |
390 | case 'b': | |
391 | val = va_arg (alist, int); | |
392 | *dst++ = val; | |
393 | break; | |
394 | case 'w': | |
395 | val = va_arg (alist, int); | |
396 | *dst++ = val; | |
397 | *dst++ = val >> 8; | |
398 | *dst++ = val >> 16; | |
399 | *dst++ = val >> 24; | |
400 | break; | |
401 | case 'S': | |
402 | val = get_byte (); | |
403 | if (val != RDP_RES_VALUE) | |
404 | { | |
405 | printf_unfiltered ("got bad res value of %d, %x\n", val, val); | |
406 | } | |
407 | break; | |
408 | case 'V': | |
409 | pstat = va_arg (alist, int *); | |
410 | pi = va_arg (alist, int *); | |
411 | ||
412 | *pstat = get_byte (); | |
413 | /* Check the result was zero, if not read the syndrome */ | |
414 | if (*pstat) | |
415 | { | |
416 | *pi = get_word (); | |
417 | } | |
418 | break; | |
419 | case 'Z': | |
420 | /* Check the result code */ | |
421 | switch (get_byte ()) | |
422 | { | |
423 | case 0: | |
424 | /* Success */ | |
425 | break; | |
426 | case 253: | |
427 | /* Target can't do it; never mind */ | |
428 | printf_unfiltered ("RDP: Insufficient privilege\n"); | |
429 | return; | |
430 | case 254: | |
431 | /* Target can't do it; never mind */ | |
432 | printf_unfiltered ("RDP: Unimplemented message\n"); | |
433 | return; | |
434 | case 255: | |
435 | error ("Command garbled"); | |
436 | break; | |
437 | default: | |
438 | error ("Corrupt reply from target"); | |
439 | break; | |
440 | } | |
441 | break; | |
442 | case 'W': | |
443 | /* Read a word from the target */ | |
444 | pi = va_arg (alist, int *); | |
445 | *pi = get_word (); | |
446 | break; | |
447 | case 'P': | |
448 | /* Read in some bytes from the target. */ | |
449 | pc = va_arg (alist, char *); | |
450 | val = va_arg (alist, int); | |
451 | for (i = 0; i < val; i++) | |
452 | { | |
453 | pc[i] = get_byte (); | |
454 | } | |
455 | break; | |
456 | case 'p': | |
457 | /* send what's being pointed at */ | |
458 | pc = va_arg (alist, char *); | |
459 | val = va_arg (alist, int); | |
460 | dst = buf; | |
461 | SERIAL_WRITE (io, pc, val); | |
462 | break; | |
463 | case '-': | |
464 | /* Send whats in the queue */ | |
465 | if (dst != buf) | |
466 | { | |
467 | SERIAL_WRITE (io, buf, dst - buf); | |
468 | dst = buf; | |
469 | } | |
470 | break; | |
471 | case 'B': | |
472 | pi = va_arg (alist, int *); | |
473 | *pi = get_byte (); | |
474 | break; | |
475 | default: | |
e1e9e218 | 476 | internal_error (__FILE__, __LINE__, "failed internal consistency check"); |
c906108c SS |
477 | } |
478 | } | |
11cf8741 | 479 | va_end (alist); |
c906108c SS |
480 | |
481 | if (dst != buf) | |
e1e9e218 | 482 | internal_error (__FILE__, __LINE__, "failed internal consistency check"); |
c906108c SS |
483 | } |
484 | ||
485 | ||
486 | static int | |
fba45db2 | 487 | rdp_write (CORE_ADDR memaddr, char *buf, int len) |
c906108c SS |
488 | { |
489 | int res; | |
490 | int val; | |
491 | ||
492 | send_rdp ("bww-p-SV", RDP_MEM_WRITE, memaddr, len, buf, len, &res, &val); | |
493 | ||
494 | if (res) | |
495 | { | |
496 | return val; | |
497 | } | |
498 | return len; | |
499 | } | |
500 | ||
501 | ||
502 | static int | |
fba45db2 | 503 | rdp_read (CORE_ADDR memaddr, char *buf, int len) |
c906108c SS |
504 | { |
505 | int res; | |
506 | int val; | |
507 | send_rdp ("bww-S-P-V", | |
508 | RDP_MEM_READ, memaddr, len, | |
509 | buf, len, | |
510 | &res, &val); | |
511 | if (res) | |
512 | { | |
513 | return val; | |
514 | } | |
515 | return len; | |
516 | } | |
517 | ||
518 | static void | |
fba45db2 | 519 | rdp_fetch_one_register (int mask, char *buf) |
c906108c SS |
520 | { |
521 | int val; | |
522 | send_rdp ("bbw-SWZ", RDP_CPU_READ, RDP_CPU_READWRITE_MODE_CURRENT, mask, &val); | |
523 | store_signed_integer (buf, 4, val); | |
524 | } | |
525 | ||
526 | static void | |
fba45db2 | 527 | rdp_fetch_one_fpu_register (int mask, char *buf) |
c906108c SS |
528 | { |
529 | #if 0 | |
530 | /* !!! Since the PIE board doesn't work as documented, | |
531 | and it doesn't have FPU hardware anyway and since it | |
532 | slows everything down, I've disabled this. */ | |
533 | int val; | |
534 | if (mask == RDP_FPU_READWRITE_MASK_FPS) | |
535 | { | |
536 | /* this guy is only a word */ | |
537 | send_rdp ("bbw-SWZ", RDP_COPRO_READ, FPU_COPRO_NUMBER, mask, &val); | |
538 | store_signed_integer (buf, 4, val); | |
539 | } | |
540 | else | |
541 | { | |
542 | /* There are 12 bytes long | |
543 | !! fixme about endianness | |
544 | */ | |
545 | int dummy; /* I've seen these come back as four words !! */ | |
546 | send_rdp ("bbw-SWWWWZ", RDP_COPRO_READ, FPU_COPRO_NUMBER, mask, buf + 0, buf + 4, buf + 8, &dummy); | |
547 | } | |
548 | #endif | |
549 | memset (buf, 0, MAX_REGISTER_RAW_SIZE); | |
550 | } | |
551 | ||
552 | ||
553 | static void | |
fba45db2 | 554 | rdp_store_one_register (int mask, char *buf) |
c906108c SS |
555 | { |
556 | int val = extract_unsigned_integer (buf, 4); | |
557 | ||
558 | send_rdp ("bbww-SZ", | |
559 | RDP_CPU_WRITE, RDP_CPU_READWRITE_MODE_CURRENT, mask, val); | |
560 | } | |
561 | ||
562 | ||
563 | static void | |
fba45db2 | 564 | rdp_store_one_fpu_register (int mask, char *buf) |
c906108c SS |
565 | { |
566 | #if 0 | |
567 | /* See comment in fetch_one_fpu_register */ | |
568 | if (mask == RDP_FPU_READWRITE_MASK_FPS) | |
569 | { | |
570 | int val = extract_unsigned_integer (buf, 4); | |
571 | /* this guy is only a word */ | |
572 | send_rdp ("bbww-SZ", RDP_COPRO_WRITE, | |
573 | FPU_COPRO_NUMBER, | |
574 | mask, val); | |
575 | } | |
576 | else | |
577 | { | |
578 | /* There are 12 bytes long | |
579 | !! fixme about endianness | |
580 | */ | |
581 | int dummy = 0; | |
582 | /* I've seen these come as four words, not the three advertized !! */ | |
583 | printf ("Sending mask %x\n", mask); | |
584 | send_rdp ("bbwwwww-SZ", | |
585 | RDP_COPRO_WRITE, | |
586 | FPU_COPRO_NUMBER, | |
587 | mask, | |
588 | *(int *) (buf + 0), | |
589 | *(int *) (buf + 4), | |
590 | *(int *) (buf + 8), | |
591 | 0); | |
592 | ||
593 | printf ("done mask %x\n", mask); | |
594 | } | |
595 | #endif | |
596 | } | |
597 | \f | |
598 | ||
599 | /* Convert between GDB requests and the RDP layer. */ | |
600 | ||
601 | static void | |
fba45db2 | 602 | remote_rdp_fetch_register (int regno) |
c906108c SS |
603 | { |
604 | if (regno == -1) | |
605 | { | |
606 | for (regno = 0; regno < NUM_REGS; regno++) | |
607 | remote_rdp_fetch_register (regno); | |
608 | } | |
609 | else | |
610 | { | |
611 | char buf[MAX_REGISTER_RAW_SIZE]; | |
612 | if (regno < 15) | |
613 | rdp_fetch_one_register (1 << regno, buf); | |
614 | else if (regno == PC_REGNUM) | |
615 | rdp_fetch_one_register (RDP_CPU_READWRITE_MASK_PC, buf); | |
616 | else if (regno == PS_REGNUM) | |
617 | rdp_fetch_one_register (RDP_CPU_READWRITE_MASK_CPSR, buf); | |
618 | else if (regno == FPS_REGNUM) | |
619 | rdp_fetch_one_fpu_register (RDP_FPU_READWRITE_MASK_FPS, buf); | |
620 | else if (regno >= F0_REGNUM && regno <= F7_REGNUM) | |
621 | rdp_fetch_one_fpu_register (1 << (regno - F0_REGNUM), buf); | |
622 | else | |
623 | { | |
624 | printf ("Help me with fetch reg %d\n", regno); | |
625 | } | |
626 | supply_register (regno, buf); | |
627 | } | |
628 | } | |
629 | ||
630 | ||
631 | static void | |
fba45db2 | 632 | remote_rdp_store_register (int regno) |
c906108c SS |
633 | { |
634 | if (regno == -1) | |
635 | { | |
636 | for (regno = 0; regno < NUM_REGS; regno++) | |
637 | remote_rdp_store_register (regno); | |
638 | } | |
639 | else | |
640 | { | |
641 | char tmp[MAX_REGISTER_RAW_SIZE]; | |
642 | read_register_gen (regno, tmp); | |
643 | if (regno < 15) | |
644 | rdp_store_one_register (1 << regno, tmp); | |
645 | else if (regno == PC_REGNUM) | |
646 | rdp_store_one_register (RDP_CPU_READWRITE_MASK_PC, tmp); | |
647 | else if (regno == PS_REGNUM) | |
648 | rdp_store_one_register (RDP_CPU_READWRITE_MASK_CPSR, tmp); | |
649 | else if (regno >= F0_REGNUM && regno <= F7_REGNUM) | |
650 | rdp_store_one_fpu_register (1 << (regno - F0_REGNUM), tmp); | |
651 | else | |
652 | { | |
653 | printf ("Help me with reg %d\n", regno); | |
654 | } | |
655 | } | |
656 | } | |
657 | ||
658 | static void | |
fba45db2 | 659 | remote_rdp_kill (void) |
c906108c SS |
660 | { |
661 | callback->shutdown (callback); | |
662 | } | |
663 | ||
664 | ||
665 | static void | |
fba45db2 | 666 | rdp_info (void) |
c906108c SS |
667 | { |
668 | send_rdp ("bw-S-W-Z", RDP_INFO, RDP_INFO_ABOUT_STEP, | |
669 | &ds.step_info); | |
670 | send_rdp ("bw-S-W-Z", RDP_INFO, RDP_INFO_ABOUT_BREAK, | |
671 | &ds.break_info); | |
672 | send_rdp ("bw-S-WW-Z", RDP_INFO, RDP_INFO_ABOUT_TARGET, | |
673 | &ds.target_info, | |
674 | &ds.model_info); | |
675 | ||
676 | ds.can_step = ds.step_info & RDP_INFO_ABOUT_STEP_1; | |
677 | ||
678 | ds.rdi_level = (ds.target_info >> 5) & 3; | |
679 | } | |
680 | ||
681 | ||
682 | static void | |
fba45db2 | 683 | rdp_execute_start (void) |
c906108c SS |
684 | { |
685 | /* Start it off, but don't wait for it */ | |
686 | send_rdp ("bb-", RDP_EXEC, RDP_EXEC_TYPE_SYNC); | |
687 | } | |
688 | ||
689 | ||
690 | static void | |
fba45db2 | 691 | rdp_set_command_line (char *command, char *args) |
c906108c SS |
692 | { |
693 | /* | |
c5aa993b JM |
694 | ** We could use RDP_INFO_SET_CMDLINE to send this, but EmbeddedICE systems |
695 | ** don't implement that, and get all confused at the unexpected text. | |
696 | ** Instead, just keep a copy, and send it when the target does a SWI_GetEnv | |
697 | */ | |
c906108c SS |
698 | |
699 | if (commandline != NULL) | |
b8c9b27d | 700 | xfree (commandline); |
c906108c | 701 | |
397b41ad | 702 | xasprintf (&commandline, "%s %s", command, args); |
c906108c SS |
703 | } |
704 | ||
705 | static void | |
fba45db2 | 706 | rdp_catch_vectors (void) |
c906108c SS |
707 | { |
708 | /* | |
c5aa993b JM |
709 | ** We want the target monitor to intercept the abort vectors |
710 | ** i.e. stop the program if any of these are used. | |
711 | */ | |
c906108c | 712 | send_rdp ("bww-SZ", RDP_INFO, RDP_INFO_VECTOR_CATCH, |
c5aa993b JM |
713 | /* |
714 | ** Specify a bitmask including | |
715 | ** the reset vector | |
716 | ** the undefined instruction vector | |
717 | ** the prefetch abort vector | |
718 | ** the data abort vector | |
719 | ** the address exception vector | |
720 | */ | |
721 | (1 << 0) | (1 << 1) | (1 << 3) | (1 << 4) | (1 << 5) | |
722 | ); | |
c906108c | 723 | } |
c5aa993b | 724 | |
c906108c SS |
725 | |
726 | ||
727 | #define a_byte 1 | |
728 | #define a_word 2 | |
729 | #define a_string 3 | |
730 | ||
731 | ||
732 | typedef struct | |
733 | { | |
734 | CORE_ADDR n; | |
735 | const char *s; | |
736 | } | |
737 | argsin; | |
738 | ||
739 | #define ABYTE 1 | |
740 | #define AWORD 2 | |
741 | #define ASTRING 3 | |
742 | #define ADDRLEN 4 | |
743 | ||
744 | #define SWI_WriteC 0x0 | |
745 | #define SWI_Write0 0x2 | |
746 | #define SWI_ReadC 0x4 | |
747 | #define SWI_CLI 0x5 | |
748 | #define SWI_GetEnv 0x10 | |
749 | #define SWI_Exit 0x11 | |
750 | #define SWI_EnterOS 0x16 | |
751 | ||
752 | #define SWI_GetErrno 0x60 | |
753 | #define SWI_Clock 0x61 | |
754 | ||
755 | #define SWI_Time 0x63 | |
756 | #define SWI_Remove 0x64 | |
757 | #define SWI_Rename 0x65 | |
758 | #define SWI_Open 0x66 | |
759 | ||
760 | #define SWI_Close 0x68 | |
761 | #define SWI_Write 0x69 | |
762 | #define SWI_Read 0x6a | |
763 | #define SWI_Seek 0x6b | |
764 | #define SWI_Flen 0x6c | |
765 | ||
766 | #define SWI_IsTTY 0x6e | |
767 | #define SWI_TmpNam 0x6f | |
768 | #define SWI_InstallHandler 0x70 | |
769 | #define SWI_GenerateError 0x71 | |
770 | ||
771 | ||
772 | #ifndef O_BINARY | |
773 | #define O_BINARY 0 | |
774 | #endif | |
775 | ||
776 | static int translate_open_mode[] = | |
777 | { | |
c5aa993b JM |
778 | O_RDONLY, /* "r" */ |
779 | O_RDONLY + O_BINARY, /* "rb" */ | |
780 | O_RDWR, /* "r+" */ | |
781 | O_RDWR + O_BINARY, /* "r+b" */ | |
782 | O_WRONLY + O_CREAT + O_TRUNC, /* "w" */ | |
783 | O_WRONLY + O_BINARY + O_CREAT + O_TRUNC, /* "wb" */ | |
784 | O_RDWR + O_CREAT + O_TRUNC, /* "w+" */ | |
785 | O_RDWR + O_BINARY + O_CREAT + O_TRUNC, /* "w+b" */ | |
786 | O_WRONLY + O_APPEND + O_CREAT, /* "a" */ | |
787 | O_WRONLY + O_BINARY + O_APPEND + O_CREAT, /* "ab" */ | |
788 | O_RDWR + O_APPEND + O_CREAT, /* "a+" */ | |
789 | O_RDWR + O_BINARY + O_APPEND + O_CREAT /* "a+b" */ | |
c906108c SS |
790 | }; |
791 | ||
792 | static int | |
fba45db2 | 793 | exec_swi (int swi, argsin *args) |
c906108c SS |
794 | { |
795 | int i; | |
796 | char c; | |
797 | switch (swi) | |
798 | { | |
799 | case SWI_WriteC: | |
800 | callback->write_stdout (callback, &c, 1); | |
801 | return 0; | |
802 | case SWI_Write0: | |
803 | for (i = 0; i < args->n; i++) | |
804 | callback->write_stdout (callback, args->s, strlen (args->s)); | |
805 | return 0; | |
806 | case SWI_ReadC: | |
807 | callback->read_stdin (callback, &c, 1); | |
808 | args->n = c; | |
809 | return 1; | |
810 | case SWI_CLI: | |
811 | args->n = callback->system (callback, args->s); | |
812 | return 1; | |
813 | case SWI_GetErrno: | |
814 | args->n = callback->get_errno (callback); | |
815 | return 1; | |
816 | case SWI_Time: | |
817 | args->n = callback->time (callback, NULL); | |
818 | return 1; | |
819 | ||
c5aa993b JM |
820 | case SWI_Clock: |
821 | /* return number of centi-seconds... */ | |
822 | args->n = | |
c906108c | 823 | #ifdef CLOCKS_PER_SEC |
c5aa993b JM |
824 | (CLOCKS_PER_SEC >= 100) |
825 | ? (clock () / (CLOCKS_PER_SEC / 100)) | |
826 | : ((clock () * 100) / CLOCKS_PER_SEC); | |
c906108c | 827 | #else |
c5aa993b JM |
828 | /* presume unix... clock() returns microseconds */ |
829 | clock () / 10000; | |
c906108c | 830 | #endif |
c5aa993b | 831 | return 1; |
c906108c SS |
832 | |
833 | case SWI_Remove: | |
834 | args->n = callback->unlink (callback, args->s); | |
835 | return 1; | |
836 | case SWI_Rename: | |
837 | args->n = callback->rename (callback, args[0].s, args[1].s); | |
838 | return 1; | |
839 | ||
840 | case SWI_Open: | |
c5aa993b JM |
841 | /* Now we need to decode the Demon open mode */ |
842 | i = translate_open_mode[args[1].n]; | |
843 | ||
844 | /* Filename ":tt" is special: it denotes stdin/out */ | |
845 | if (strcmp (args->s, ":tt") == 0) | |
846 | { | |
847 | if (i == O_RDONLY) /* opening tty "r" */ | |
848 | args->n = 0 /* stdin */ ; | |
849 | else | |
850 | args->n = 1 /* stdout */ ; | |
851 | } | |
852 | else | |
853 | args->n = callback->open (callback, args->s, i); | |
c906108c SS |
854 | return 1; |
855 | ||
856 | case SWI_Close: | |
857 | args->n = callback->close (callback, args->n); | |
858 | return 1; | |
859 | ||
860 | case SWI_Write: | |
861 | /* Return the number of bytes *not* written */ | |
862 | args->n = args[1].n - | |
863 | callback->write (callback, args[0].n, args[1].s, args[1].n); | |
864 | return 1; | |
865 | ||
866 | case SWI_Read: | |
867 | { | |
868 | char *copy = alloca (args[2].n); | |
869 | int done = callback->read (callback, args[0].n, copy, args[2].n); | |
870 | if (done > 0) | |
29e57380 | 871 | remote_rdp_xfer_inferior_memory (args[1].n, copy, done, 1, 0, 0); |
c5aa993b | 872 | args->n = args[2].n - done; |
c906108c SS |
873 | return 1; |
874 | } | |
875 | ||
876 | case SWI_Seek: | |
877 | /* Return non-zero on failure */ | |
878 | args->n = callback->lseek (callback, args[0].n, args[1].n, 0) < 0; | |
879 | return 1; | |
880 | ||
881 | case SWI_Flen: | |
882 | { | |
883 | long old = callback->lseek (callback, args->n, 0, SEEK_CUR); | |
884 | args->n = callback->lseek (callback, args->n, 0, SEEK_END); | |
885 | callback->lseek (callback, args->n, old, 0); | |
886 | return 1; | |
887 | } | |
888 | ||
889 | case SWI_IsTTY: | |
890 | args->n = callback->isatty (callback, args->n); | |
891 | return 1; | |
892 | ||
893 | case SWI_GetEnv: | |
894 | if (commandline != NULL) | |
895 | { | |
896 | int len = strlen (commandline); | |
897 | if (len > 255) | |
898 | { | |
899 | len = 255; | |
c5aa993b | 900 | commandline[255] = '\0'; |
c906108c SS |
901 | } |
902 | remote_rdp_xfer_inferior_memory (args[0].n, | |
29e57380 | 903 | commandline, len + 1, 1, 0, 0); |
c906108c SS |
904 | } |
905 | else | |
29e57380 | 906 | remote_rdp_xfer_inferior_memory (args[0].n, "", 1, 1, 0, 0); |
c906108c | 907 | return 1; |
c5aa993b | 908 | |
c906108c SS |
909 | default: |
910 | return 0; | |
911 | } | |
912 | } | |
913 | ||
914 | ||
915 | static void | |
fba45db2 | 916 | handle_swi (void) |
c906108c SS |
917 | { |
918 | argsin args[3]; | |
919 | char *buf; | |
920 | int len; | |
921 | int count = 0; | |
922 | ||
923 | int swino = get_word (); | |
924 | int type = get_byte (); | |
925 | while (type != 0) | |
926 | { | |
927 | switch (type & 0x3) | |
928 | { | |
929 | case ABYTE: | |
930 | args[count].n = get_byte (); | |
931 | break; | |
932 | ||
933 | case AWORD: | |
934 | args[count].n = get_word (); | |
935 | break; | |
936 | ||
937 | case ASTRING: | |
938 | /* If the word is under 32 bytes it will be sent otherwise | |
939 | an address to it is passed. Also: Special case of 255 */ | |
940 | ||
941 | len = get_byte (); | |
942 | if (len > 32) | |
943 | { | |
944 | if (len == 255) | |
945 | { | |
946 | len = get_word (); | |
947 | } | |
948 | buf = alloca (len); | |
949 | remote_rdp_xfer_inferior_memory (get_word (), | |
950 | buf, | |
951 | len, | |
952 | 0, | |
29e57380 | 953 | 0, |
c906108c SS |
954 | 0); |
955 | } | |
956 | else | |
957 | { | |
958 | int i; | |
959 | buf = alloca (len + 1); | |
960 | for (i = 0; i < len; i++) | |
961 | buf[i] = get_byte (); | |
962 | buf[i] = 0; | |
963 | } | |
964 | args[count].n = len; | |
965 | args[count].s = buf; | |
966 | break; | |
967 | ||
968 | default: | |
8e1a459b | 969 | error ("Unimplemented SWI argument"); |
c906108c SS |
970 | } |
971 | ||
972 | type = type >> 2; | |
973 | count++; | |
974 | } | |
975 | ||
976 | if (exec_swi (swino, args)) | |
977 | { | |
978 | /* We have two options here reply with either a byte or a word | |
979 | which is stored in args[0].n. There is no harm in replying with | |
980 | a word all the time, so thats what I do! */ | |
981 | send_rdp ("bbw-", RDP_OSOpReply, RDP_OSOpWord, args[0].n); | |
982 | } | |
983 | else | |
984 | { | |
985 | send_rdp ("bb-", RDP_OSOpReply, RDP_OSOpNothing); | |
986 | } | |
987 | } | |
988 | ||
989 | static void | |
fba45db2 | 990 | rdp_execute_finish (void) |
c906108c SS |
991 | { |
992 | int running = 1; | |
993 | ||
994 | while (running) | |
995 | { | |
996 | int res; | |
997 | res = SERIAL_READCHAR (io, 1); | |
998 | while (res == SERIAL_TIMEOUT) | |
999 | { | |
1000 | QUIT; | |
1001 | printf_filtered ("Waiting for target..\n"); | |
1002 | res = SERIAL_READCHAR (io, 1); | |
1003 | } | |
1004 | ||
1005 | switch (res) | |
1006 | { | |
1007 | case RDP_RES_SWI: | |
1008 | handle_swi (); | |
1009 | break; | |
1010 | case RDP_RES_VALUE: | |
1011 | send_rdp ("B", &ds.rdi_stopped_status); | |
1012 | running = 0; | |
1013 | break; | |
1014 | case RDP_RESET: | |
1015 | printf_filtered ("Target reset\n"); | |
1016 | running = 0; | |
1017 | break; | |
1018 | default: | |
1019 | printf_filtered ("Ignoring %x\n", res); | |
1020 | break; | |
1021 | } | |
1022 | } | |
1023 | } | |
1024 | ||
1025 | ||
1026 | static void | |
fba45db2 | 1027 | rdp_execute (void) |
c906108c SS |
1028 | { |
1029 | rdp_execute_start (); | |
1030 | rdp_execute_finish (); | |
1031 | } | |
1032 | ||
1033 | static int | |
fba45db2 | 1034 | remote_rdp_insert_breakpoint (CORE_ADDR addr, char *save) |
c906108c SS |
1035 | { |
1036 | int res; | |
1037 | if (ds.rdi_level > 0) | |
1038 | { | |
1039 | send_rdp ("bwb-SWB", | |
1040 | RDP_SET_BREAK, | |
1041 | addr, | |
1042 | RDP_SET_BREAK_TYPE_PC_EQUAL | RDP_SET_BREAK_TYPE_GET_HANDLE, | |
1043 | save, | |
1044 | &res); | |
1045 | } | |
1046 | else | |
1047 | { | |
1048 | send_rdp ("bwb-SB", | |
1049 | RDP_SET_BREAK, | |
1050 | addr, | |
1051 | RDP_SET_BREAK_TYPE_PC_EQUAL, | |
1052 | &res); | |
1053 | } | |
1054 | return res; | |
1055 | } | |
1056 | ||
1057 | static int | |
fba45db2 | 1058 | remote_rdp_remove_breakpoint (CORE_ADDR addr, char *save) |
c906108c SS |
1059 | { |
1060 | int res; | |
1061 | if (ds.rdi_level > 0) | |
1062 | { | |
1063 | send_rdp ("b-p-S-B", | |
1064 | RDP_CLEAR_BREAK, | |
1065 | save, 4, | |
1066 | &res); | |
1067 | } | |
1068 | else | |
1069 | { | |
1070 | send_rdp ("bw-S-B", | |
1071 | RDP_CLEAR_BREAK, | |
1072 | addr, | |
1073 | &res); | |
1074 | } | |
1075 | return res; | |
1076 | } | |
1077 | ||
1078 | static void | |
fba45db2 | 1079 | rdp_step (void) |
c906108c SS |
1080 | { |
1081 | if (ds.can_step && 0) | |
1082 | { | |
1083 | /* The pie board can't do steps so I can't test this, and | |
1084 | the other code will always work. */ | |
1085 | int status; | |
1086 | send_rdp ("bbw-S-B", | |
1087 | RDP_STEP, 0, 1, | |
1088 | &status); | |
1089 | } | |
1090 | else | |
1091 | { | |
1092 | char handle[4]; | |
1093 | CORE_ADDR pc = read_register (PC_REGNUM); | |
1094 | pc = arm_get_next_pc (pc); | |
3bb04bdd | 1095 | remote_rdp_insert_breakpoint (pc, handle); |
c906108c | 1096 | rdp_execute (); |
3bb04bdd | 1097 | remote_rdp_remove_breakpoint (pc, handle); |
c906108c SS |
1098 | } |
1099 | } | |
1100 | ||
1101 | static void | |
fba45db2 | 1102 | remote_rdp_open (char *args, int from_tty) |
c906108c SS |
1103 | { |
1104 | int not_icebreaker; | |
1105 | ||
1106 | if (!args) | |
1107 | error_no_arg ("serial port device name"); | |
1108 | ||
1109 | baud_rate = 9600; | |
1110 | ||
1111 | target_preopen (from_tty); | |
1112 | ||
1113 | io = SERIAL_OPEN (args); | |
1114 | ||
1115 | if (!io) | |
1116 | perror_with_name (args); | |
1117 | ||
1118 | SERIAL_RAW (io); | |
1119 | ||
1120 | rdp_init (1, from_tty); | |
1121 | ||
1122 | ||
1123 | if (from_tty) | |
1124 | { | |
1125 | printf_unfiltered ("Remote RDP debugging using %s at %d baud\n", args, baud_rate); | |
1126 | } | |
1127 | ||
1128 | rdp_info (); | |
1129 | ||
1130 | /* Need to set up the vector interception state */ | |
c5aa993b | 1131 | rdp_catch_vectors (); |
c906108c SS |
1132 | |
1133 | /* | |
c5aa993b JM |
1134 | ** If it's an EmbeddedICE, we need to set the processor config. |
1135 | ** Assume we can always have ARM7TDI... | |
1136 | */ | |
1137 | send_rdp ("bw-SB", RDP_INFO, RDP_INFO_ICEBREAKER, ¬_icebreaker); | |
c906108c SS |
1138 | if (!not_icebreaker) |
1139 | { | |
c5aa993b | 1140 | const char *CPU = "ARM7TDI"; |
c906108c SS |
1141 | int ICEversion; |
1142 | int len = strlen (CPU); | |
c5aa993b | 1143 | |
c906108c SS |
1144 | send_rdp ("bbbbw-p-SWZ", |
1145 | RDP_SELECT_CONFIG, | |
1146 | RDI_ConfigCPU, /* Aspect: set the CPU */ | |
1147 | len, /* The number of bytes in the name */ | |
1148 | RDI_MatchAny, /* We'll take whatever we get */ | |
1149 | 0, /* We'll take whatever version's there */ | |
c5aa993b JM |
1150 | CPU, len, |
1151 | &ICEversion); | |
c906108c SS |
1152 | } |
1153 | ||
c5aa993b | 1154 | /* command line initialised on 'run' */ |
c906108c | 1155 | |
c5aa993b | 1156 | push_target (&remote_rdp_ops); |
c906108c SS |
1157 | |
1158 | callback->init (callback); | |
1159 | flush_cached_frames (); | |
1160 | registers_changed (); | |
1161 | stop_pc = read_pc (); | |
1162 | set_current_frame (create_new_frame (read_fp (), stop_pc)); | |
1163 | select_frame (get_current_frame (), 0); | |
1164 | print_stack_frame (selected_frame, -1, 1); | |
1165 | } | |
1166 | ||
1167 | ||
1168 | ||
1169 | /* Close out all files and local state before this target loses control. */ | |
1170 | ||
1171 | static void | |
fba45db2 | 1172 | remote_rdp_close (int quitting) |
c906108c SS |
1173 | { |
1174 | callback->shutdown (callback); | |
1175 | if (io) | |
1176 | SERIAL_CLOSE (io); | |
1177 | io = 0; | |
1178 | } | |
1179 | ||
1180 | ||
1181 | /* Resume execution of the target process. STEP says whether to single-step | |
1182 | or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be given | |
1183 | to the target, or zero for no signal. */ | |
1184 | ||
1185 | static void | |
39f77062 | 1186 | remote_rdp_resume (ptid_t ptid, int step, enum target_signal siggnal) |
c906108c SS |
1187 | { |
1188 | if (step) | |
1189 | rdp_step (); | |
1190 | else | |
1191 | rdp_execute (); | |
1192 | } | |
1193 | ||
1194 | /* Wait for inferior process to do something. Return pid of child, | |
1195 | or -1 in case of error; store status through argument pointer STATUS, | |
1196 | just as `wait' would. */ | |
1197 | ||
39f77062 KB |
1198 | static ptid_t |
1199 | remote_rdp_wait (ptid_t ptid, struct target_waitstatus *status) | |
c906108c SS |
1200 | { |
1201 | switch (ds.rdi_stopped_status) | |
1202 | { | |
1203 | default: | |
1204 | case RDP_RES_RESET: | |
1205 | case RDP_RES_SWI: | |
1206 | status->kind = TARGET_WAITKIND_EXITED; | |
1207 | status->value.integer = read_register (0); | |
1208 | break; | |
1209 | case RDP_RES_AT_BREAKPOINT: | |
1210 | status->kind = TARGET_WAITKIND_STOPPED; | |
1211 | /* The signal in sigrc is a host signal. That probably | |
1212 | should be fixed. */ | |
1213 | status->value.sig = TARGET_SIGNAL_TRAP; | |
1214 | break; | |
1215 | #if 0 | |
1216 | case rdp_signalled: | |
1217 | status->kind = TARGET_WAITKIND_SIGNALLED; | |
1218 | /* The signal in sigrc is a host signal. That probably | |
1219 | should be fixed. */ | |
1220 | status->value.sig = target_signal_from_host (sigrc); | |
1221 | break; | |
1222 | #endif | |
1223 | } | |
1224 | ||
39f77062 | 1225 | return inferior_ptid; |
c906108c SS |
1226 | } |
1227 | ||
1228 | /* Get ready to modify the registers array. On machines which store | |
1229 | individual registers, this doesn't need to do anything. On machines | |
1230 | which store all the registers in one fell swoop, this makes sure | |
1231 | that registers contains all the registers from the program being | |
1232 | debugged. */ | |
1233 | ||
1234 | static void | |
fba45db2 | 1235 | remote_rdp_prepare_to_store (void) |
c906108c SS |
1236 | { |
1237 | /* Do nothing, since we can store individual regs */ | |
1238 | } | |
1239 | ||
d93bce06 KB |
1240 | /* Transfer LEN bytes between GDB address MYADDR and target address |
1241 | MEMADDR. If WRITE is non-zero, transfer them to the target, | |
1242 | otherwise transfer them from the target. TARGET is unused. | |
1243 | ||
1244 | Returns the number of bytes transferred. */ | |
1245 | ||
c906108c | 1246 | static int |
d93bce06 | 1247 | remote_rdp_xfer_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len, |
29e57380 C |
1248 | int write, |
1249 | struct mem_attrib *attrib ATTRIBUTE_UNUSED, | |
1250 | struct target_ops *target ATTRIBUTE_UNUSED) | |
c906108c SS |
1251 | { |
1252 | /* I infer from D Taylor's code that there's a limit on the amount | |
1253 | we can transfer in one chunk.. */ | |
1254 | int done = 0; | |
1255 | while (done < len) | |
1256 | { | |
1257 | int justdone; | |
1258 | int thisbite = len - done; | |
1259 | if (thisbite > RDP_MOUTHFULL) | |
1260 | thisbite = RDP_MOUTHFULL; | |
1261 | ||
1262 | QUIT; | |
1263 | ||
1264 | if (write) | |
1265 | { | |
1266 | justdone = rdp_write (memaddr + done, myaddr + done, thisbite); | |
1267 | } | |
1268 | else | |
1269 | { | |
1270 | justdone = rdp_read (memaddr + done, myaddr + done, thisbite); | |
1271 | } | |
1272 | ||
1273 | done += justdone; | |
1274 | ||
1275 | if (justdone != thisbite) | |
1276 | break; | |
1277 | } | |
1278 | return done; | |
1279 | } | |
1280 | ||
1281 | ||
1282 | ||
1283 | struct yn | |
1284 | { | |
1285 | const char *name; | |
1286 | int bit; | |
1287 | }; | |
1288 | static struct yn stepinfo[] = | |
1289 | { | |
1290 | {"Step more than one instruction", RDP_INFO_ABOUT_STEP_GT_1}, | |
1291 | {"Step to jump", RDP_INFO_ABOUT_STEP_TO_JMP}, | |
1292 | {"Step one instruction", RDP_INFO_ABOUT_STEP_1}, | |
1293 | {0} | |
1294 | }; | |
1295 | ||
1296 | static struct yn breakinfo[] = | |
1297 | { | |
1298 | {"comparison breakpoints supported", RDP_INFO_ABOUT_BREAK_COMP}, | |
1299 | {"range breakpoints supported", RDP_INFO_ABOUT_BREAK_RANGE}, | |
1300 | {"watchpoints for byte reads supported", RDP_INFO_ABOUT_BREAK_BYTE_READ}, | |
1301 | {"watchpoints for half-word reads supported", RDP_INFO_ABOUT_BREAK_HALFWORD_READ}, | |
1302 | {"watchpoints for word reads supported", RDP_INFO_ABOUT_BREAK_WORD_READ}, | |
1303 | {"watchpoints for byte writes supported", RDP_INFO_ABOUT_BREAK_BYTE_WRITE}, | |
1304 | {"watchpoints for half-word writes supported", RDP_INFO_ABOUT_BREAK_HALFWORD_WRITE}, | |
1305 | {"watchpoints for word writes supported", RDP_INFO_ABOUT_BREAK_WORD_WRITE}, | |
1306 | {"mask break/watch-points supported", RDP_INFO_ABOUT_BREAK_MASK}, | |
1307 | {"thread-specific breakpoints supported", RDP_INFO_ABOUT_BREAK_THREAD_BREAK}, | |
1308 | {"thread-specific watchpoints supported", RDP_INFO_ABOUT_BREAK_THREAD_WATCH}, | |
1309 | {"conditional breakpoints supported", RDP_INFO_ABOUT_BREAK_COND}, | |
1310 | {0} | |
1311 | }; | |
1312 | ||
1313 | ||
1314 | static void | |
fba45db2 | 1315 | dump_bits (struct yn *t, int info) |
c906108c SS |
1316 | { |
1317 | while (t->name) | |
1318 | { | |
1319 | printf_unfiltered (" %-45s : %s\n", t->name, (info & t->bit) ? "Yes" : "No"); | |
1320 | t++; | |
1321 | } | |
1322 | } | |
1323 | ||
1324 | static void | |
fba45db2 | 1325 | remote_rdp_files_info (struct target_ops *target) |
c906108c SS |
1326 | { |
1327 | printf_filtered ("Target capabilities:\n"); | |
1328 | dump_bits (stepinfo, ds.step_info); | |
1329 | dump_bits (breakinfo, ds.break_info); | |
1330 | printf_unfiltered ("target level RDI %x\n", (ds.target_info >> 5) & 3); | |
1331 | } | |
1332 | ||
1333 | ||
1334 | static void | |
fba45db2 | 1335 | remote_rdp_create_inferior (char *exec_file, char *allargs, char **env) |
c906108c SS |
1336 | { |
1337 | CORE_ADDR entry_point; | |
1338 | ||
1339 | if (exec_file == 0 || exec_bfd == 0) | |
c5aa993b | 1340 | error ("No executable file specified."); |
c906108c SS |
1341 | |
1342 | entry_point = (CORE_ADDR) bfd_get_start_address (exec_bfd); | |
1343 | ||
c5aa993b | 1344 | remote_rdp_kill (); |
c906108c SS |
1345 | remove_breakpoints (); |
1346 | init_wait_for_inferior (); | |
1347 | ||
1348 | /* This gives us a chance to set up the command line */ | |
1349 | rdp_set_command_line (exec_file, allargs); | |
1350 | ||
39f77062 | 1351 | inferior_ptid = pid_to_ptid (42); |
c5aa993b | 1352 | insert_breakpoints (); /* Needed to get correct instruction in cache */ |
c906108c SS |
1353 | |
1354 | /* | |
c5aa993b JM |
1355 | ** RDP targets don't provide any facility to set the top of memory, |
1356 | ** so we don't bother to look for MEMSIZE in the environment. | |
1357 | */ | |
c906108c SS |
1358 | |
1359 | /* Let's go! */ | |
1360 | proceed (entry_point, TARGET_SIGNAL_DEFAULT, 0); | |
1361 | } | |
1362 | ||
1363 | /* Accept any stray run/attach commands */ | |
1364 | static int | |
fba45db2 | 1365 | remote_rdp_can_run (void) |
c906108c SS |
1366 | { |
1367 | return 1; | |
1368 | } | |
1369 | ||
1370 | /* Attach doesn't need to do anything */ | |
1371 | static void | |
fba45db2 | 1372 | remote_rdp_attach (char *args, int from_tty) |
c906108c SS |
1373 | { |
1374 | return; | |
1375 | } | |
c5aa993b | 1376 | |
c906108c SS |
1377 | /* Define the target subroutine names */ |
1378 | ||
c5aa993b | 1379 | struct target_ops remote_rdp_ops; |
c906108c | 1380 | |
c5aa993b JM |
1381 | static void |
1382 | init_remote_rdp_ops (void) | |
c906108c | 1383 | { |
c5aa993b JM |
1384 | remote_rdp_ops.to_shortname = "rdp"; |
1385 | remote_rdp_ops.to_longname = "Remote Target using the RDProtocol"; | |
1386 | remote_rdp_ops.to_doc = "Use a remote ARM system which uses the ARM Remote Debugging Protocol"; | |
1387 | remote_rdp_ops.to_open = remote_rdp_open; | |
1388 | remote_rdp_ops.to_close = remote_rdp_close; | |
1389 | remote_rdp_ops.to_attach = remote_rdp_attach; | |
c906108c SS |
1390 | remote_rdp_ops.to_post_attach = NULL; |
1391 | remote_rdp_ops.to_require_attach = NULL; | |
c5aa993b JM |
1392 | remote_rdp_ops.to_detach = NULL; |
1393 | remote_rdp_ops.to_require_detach = NULL; | |
1394 | remote_rdp_ops.to_resume = remote_rdp_resume; | |
1395 | remote_rdp_ops.to_wait = remote_rdp_wait; | |
1396 | remote_rdp_ops.to_post_wait = NULL; | |
1397 | remote_rdp_ops.to_fetch_registers = remote_rdp_fetch_register; | |
1398 | remote_rdp_ops.to_store_registers = remote_rdp_store_register; | |
1399 | remote_rdp_ops.to_prepare_to_store = remote_rdp_prepare_to_store; | |
1400 | remote_rdp_ops.to_xfer_memory = remote_rdp_xfer_inferior_memory; | |
1401 | remote_rdp_ops.to_files_info = remote_rdp_files_info; | |
1402 | remote_rdp_ops.to_insert_breakpoint = remote_rdp_insert_breakpoint; | |
1403 | remote_rdp_ops.to_remove_breakpoint = remote_rdp_remove_breakpoint; | |
1404 | remote_rdp_ops.to_terminal_init = NULL; | |
1405 | remote_rdp_ops.to_terminal_inferior = NULL; | |
1406 | remote_rdp_ops.to_terminal_ours_for_output = NULL; | |
1407 | remote_rdp_ops.to_terminal_ours = NULL; | |
1408 | remote_rdp_ops.to_terminal_info = NULL; | |
1409 | remote_rdp_ops.to_kill = remote_rdp_kill; | |
1410 | remote_rdp_ops.to_load = generic_load; | |
1411 | remote_rdp_ops.to_lookup_symbol = NULL; | |
1412 | remote_rdp_ops.to_create_inferior = remote_rdp_create_inferior; | |
c906108c SS |
1413 | remote_rdp_ops.to_post_startup_inferior = NULL; |
1414 | remote_rdp_ops.to_acknowledge_created_inferior = NULL; | |
1415 | remote_rdp_ops.to_clone_and_follow_inferior = NULL; | |
1416 | remote_rdp_ops.to_post_follow_inferior_by_clone = NULL; | |
1417 | remote_rdp_ops.to_insert_fork_catchpoint = NULL; | |
1418 | remote_rdp_ops.to_remove_fork_catchpoint = NULL; | |
1419 | remote_rdp_ops.to_insert_vfork_catchpoint = NULL; | |
1420 | remote_rdp_ops.to_remove_vfork_catchpoint = NULL; | |
1421 | remote_rdp_ops.to_has_forked = NULL; | |
1422 | remote_rdp_ops.to_has_vforked = NULL; | |
1423 | remote_rdp_ops.to_can_follow_vfork_prior_to_exec = NULL; | |
1424 | remote_rdp_ops.to_post_follow_vfork = NULL; | |
1425 | remote_rdp_ops.to_insert_exec_catchpoint = NULL; | |
1426 | remote_rdp_ops.to_remove_exec_catchpoint = NULL; | |
1427 | remote_rdp_ops.to_has_execd = NULL; | |
1428 | remote_rdp_ops.to_reported_exec_events_per_exec_call = NULL; | |
1429 | remote_rdp_ops.to_has_exited = NULL; | |
c5aa993b JM |
1430 | remote_rdp_ops.to_mourn_inferior = generic_mourn_inferior; |
1431 | remote_rdp_ops.to_can_run = remote_rdp_can_run; | |
1432 | remote_rdp_ops.to_notice_signals = 0; | |
1433 | remote_rdp_ops.to_thread_alive = 0; | |
1434 | remote_rdp_ops.to_stop = 0; | |
c906108c | 1435 | remote_rdp_ops.to_pid_to_exec_file = NULL; |
c5aa993b JM |
1436 | remote_rdp_ops.to_stratum = process_stratum; |
1437 | remote_rdp_ops.DONT_USE = NULL; | |
1438 | remote_rdp_ops.to_has_all_memory = 1; | |
1439 | remote_rdp_ops.to_has_memory = 1; | |
1440 | remote_rdp_ops.to_has_stack = 1; | |
1441 | remote_rdp_ops.to_has_registers = 1; | |
1442 | remote_rdp_ops.to_has_execution = 1; | |
1443 | remote_rdp_ops.to_sections = NULL; | |
1444 | remote_rdp_ops.to_sections_end = NULL; | |
1445 | remote_rdp_ops.to_magic = OPS_MAGIC; | |
c906108c SS |
1446 | } |
1447 | ||
1448 | void | |
fba45db2 | 1449 | _initialize_remote_rdp (void) |
c906108c | 1450 | { |
c5aa993b | 1451 | init_remote_rdp_ops (); |
c906108c SS |
1452 | add_target (&remote_rdp_ops); |
1453 | } |