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