Commit | Line | Data |
---|---|---|
dedcc91d SC |
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 | |
18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
19 | ||
20 | ||
21 | */ | |
22 | ||
23 | ||
24 | /* | |
25 | Much of this file (in particular the SWI stuff) is based on code by | |
26 | David Taylor (djt1000@uk.ac.cam.hermes). | |
27 | ||
28 | I hacked on and simplified it by removing a lot of sexy features he | |
29 | had added, and some of the (unix specific) workarounds he'd done | |
30 | for other GDB problems - which if they still exist should be fixed | |
31 | in GDB, not in a remote-foo thing . I also made it conform more to | |
32 | the doc I have; which may be wrong. | |
33 | ||
34 | Steve Chamberlain (sac@cygnus.com). | |
35 | */ | |
36 | ||
37 | ||
38 | #include "defs.h" | |
39 | #include "inferior.h" | |
40 | #include "wait.h" | |
41 | #include "value.h" | |
42 | #include "callback.h" | |
43 | #include "command.h" | |
44 | #ifdef ANSI_PROTOTYPES | |
45 | #include <stdarg.h> | |
46 | #else | |
47 | #include <varargs.h> | |
48 | #endif | |
49 | ||
50 | #include <fcntl.h> | |
51 | #include "symfile.h" | |
52 | #include "remote-utils.h" | |
53 | ||
54 | extern struct target_ops remote_rdp_ops; | |
55 | static serial_t io; | |
56 | static host_callback *callback = &default_callback; | |
57 | ||
58 | struct | |
59 | { | |
60 | int step_info; | |
61 | int break_info; | |
62 | int model_info; | |
63 | int target_info; | |
64 | int can_step; | |
65 | char command_line[10]; | |
66 | int rdi_level; | |
67 | int rdi_stopped_status; | |
68 | } ds; | |
69 | ||
70 | ||
71 | ||
72 | /* Definitions for the RDP protocol. */ | |
73 | ||
74 | #define RDP_MOUTHFULL (1<<6) | |
75 | #define FPU_COPRO_NUMBER 1 | |
76 | ||
77 | #define RDP_OPEN 0 | |
78 | #define RDP_OPEN_TYPE_COLD 0 | |
79 | #define RDP_OPEN_TYPE_WARM 1 | |
80 | #define RDP_OPEN_TYPE_RETURN_SEX (1<<3) | |
81 | ||
82 | #define RDP_CLOSE 1 | |
83 | ||
84 | #define RDP_MEM_READ 2 | |
85 | ||
86 | #define RDP_MEM_WRITE 3 | |
87 | ||
88 | #define RDP_CPU_READ 4 | |
89 | #define RDP_CPU_WRITE 5 | |
90 | #define RDP_CPU_READWRITE_MODE_CURRENT 255 | |
91 | #define RDP_CPU_READWRITE_MASK_PC (1<<16) | |
92 | #define RDP_CPU_READWRITE_MASK_CPSR (1<<17) | |
93 | #define RDP_CPU_READWRITE_MASK_SPSR (1<<18) | |
94 | ||
95 | #define RDP_COPRO_READ 6 | |
96 | #define RDP_COPRO_WRITE 7 | |
97 | #define RDP_FPU_READWRITE_MASK_FPS (1<<8) | |
98 | ||
99 | #define RDP_SET_BREAK 0xa | |
100 | #define RDP_SET_BREAK_TYPE_PC_EQUAL 0 | |
101 | #define RDP_SET_BREAK_TYPE_GET_HANDLE (0x10) | |
102 | ||
103 | #define RDP_CLEAR_BREAK 0xb | |
104 | ||
105 | #define RDP_EXEC 0x10 | |
106 | #define RDP_EXEC_TYPE_SYNC 0 | |
107 | ||
108 | #define RDP_STEP 0x11 | |
109 | ||
110 | #define RDP_INFO 0x12 | |
111 | #define RDP_INFO_ABOUT_STEP 2 | |
112 | #define RDP_INFO_ABOUT_STEP_GT_1 1 | |
113 | #define RDP_INFO_ABOUT_STEP_TO_JMP 2 | |
114 | #define RDP_INFO_ABOUT_STEP_1 4 | |
115 | #define RDP_INFO_ABOUT_TARGET 0 | |
116 | #define RDP_INFO_ABOUT_BREAK 1 | |
117 | #define RDP_INFO_ABOUT_BREAK_COMP 1 | |
118 | #define RDP_INFO_ABOUT_BREAK_RANGE 2 | |
119 | #define RDP_INFO_ABOUT_BREAK_BYTE_READ 4 | |
120 | #define RDP_INFO_ABOUT_BREAK_HALFWORD_READ 8 | |
121 | #define RDP_INFO_ABOUT_BREAK_WORD_READ (1<<4) | |
122 | #define RDP_INFO_ABOUT_BREAK_BYTE_WRITE (1<<5) | |
123 | #define RDP_INFO_ABOUT_BREAK_HALFWORD_WRITE (1<<6) | |
124 | #define RDP_INFO_ABOUT_BREAK_WORD_WRITE (1<<7) | |
125 | #define RDP_INFO_ABOUT_BREAK_MASK (1<<8) | |
126 | #define RDP_INFO_ABOUT_BREAK_THREAD_BREAK (1<<9) | |
127 | #define RDP_INFO_ABOUT_BREAK_THREAD_WATCH (1<<10) | |
128 | #define RDP_INFO_ABOUT_BREAK_COND (1<<11) | |
129 | ||
130 | #define RDP_RESET 0x7f | |
131 | ||
132 | /* Returns from RDP */ | |
133 | #define RDP_RES_STOPPED 0x20 | |
134 | #define RDP_RES_SWI 0x21 | |
135 | #define RDP_RES_FATAL 0x5e | |
136 | #define RDP_RES_VALUE 0x5f | |
137 | #define RDP_RES_VALUE_LITTLE_ENDIAN 240 | |
138 | #define RDP_RES_VALUE_BIG_ENDIAN 241 | |
139 | #define RDP_RES_RESET 0x7f | |
140 | #define RDP_RES_AT_BREAKPOINT 143 | |
141 | ||
142 | #define RDP_OSOpReply 0x13 | |
143 | #define RDP_OSOpWord 2 | |
144 | #define RDP_OSOpNothing 0 | |
145 | ||
146 | static int timeout = 2; | |
147 | ||
148 | static int | |
149 | remote_rdp_xfer_inferior_memory PARAMS ((CORE_ADDR memaddr, | |
150 | char *myaddr, | |
151 | int len, | |
152 | int write, | |
153 | struct target_ops * target)); | |
154 | ||
155 | ||
156 | /* Stuff for talking to the serial layer. */ | |
157 | ||
158 | static unsigned char | |
159 | get_byte () | |
160 | { | |
161 | int c = SERIAL_READCHAR (io, timeout); | |
162 | ||
163 | if (c == SERIAL_TIMEOUT) | |
164 | { | |
165 | if (timeout == 0) | |
166 | return (unsigned char) c; | |
167 | ||
168 | error ("Timeout reading from remote_system"); | |
169 | } | |
170 | ||
171 | if (remote_debug) | |
172 | printf ("[%02x]", c); | |
173 | return c; | |
174 | } | |
175 | ||
176 | /* Note that the target always speaks little-endian to us, | |
177 | even if it's a big endian machine. */ | |
178 | static unsigned int | |
179 | get_word () | |
180 | { | |
181 | unsigned int val = 0; | |
182 | unsigned int c; | |
183 | int n; | |
184 | for (n = 0; n < 4; n++) | |
185 | { | |
186 | c = get_byte (); | |
187 | val |= c << (n * 8); | |
188 | } | |
189 | return val; | |
190 | } | |
191 | ||
192 | static void | |
193 | put_byte (val) | |
194 | char val; | |
195 | { | |
196 | SERIAL_WRITE (io, &val, 1); | |
197 | } | |
198 | ||
199 | static void | |
200 | put_word (val) | |
201 | long val; | |
202 | { | |
203 | /* We always send in little endian */ | |
204 | unsigned char b[4]; | |
205 | b[0] = val; | |
206 | b[1] = val >> 8; | |
207 | b[2] = val >> 16; | |
208 | b[3] = val >> 24; | |
209 | ||
210 | SERIAL_WRITE (io, b, 4); | |
211 | } | |
212 | ||
213 | ||
214 | ||
215 | /* Stuff for talking to the RDP layer. */ | |
216 | ||
217 | ||
218 | /* This is a bit more fancy that need be so that it syncs even in nasty cases. */ | |
219 | ||
220 | static void | |
221 | rdp_init () | |
222 | { | |
223 | int oloop; | |
224 | ||
225 | for (oloop = 0; oloop < 2; oloop++) | |
226 | { | |
227 | int longtry; | |
228 | SERIAL_FLUSH_INPUT (io); | |
229 | for (longtry = 0; longtry < 2; longtry++) | |
230 | { | |
231 | int try; | |
232 | int flush_and_retry = 0; | |
233 | ||
234 | for (try = 0; try < 10 && !flush_and_retry; try++) | |
235 | { | |
236 | int restype; | |
237 | ||
238 | put_byte (RDP_OPEN); | |
239 | put_byte (RDP_OPEN_TYPE_COLD | RDP_OPEN_TYPE_RETURN_SEX); | |
240 | put_word (0); | |
241 | ||
242 | restype = SERIAL_READCHAR (io, 1); | |
243 | ||
244 | switch (restype) | |
245 | { | |
246 | case SERIAL_TIMEOUT: | |
247 | flush_and_retry = 1; | |
248 | break; | |
249 | case RDP_RESET: | |
250 | return; | |
251 | default: | |
252 | printf_unfiltered ("Got res return %d\n", restype); | |
253 | break; | |
254 | case RDP_RES_VALUE: | |
255 | { | |
256 | int resval = SERIAL_READCHAR (io, 1); | |
257 | ||
258 | switch (resval) | |
259 | { | |
260 | case SERIAL_TIMEOUT: | |
261 | break; | |
262 | case RDP_RES_VALUE_LITTLE_ENDIAN: | |
263 | target_byte_order = LITTLE_ENDIAN; | |
264 | return; | |
265 | case RDP_RES_VALUE_BIG_ENDIAN: | |
266 | target_byte_order = BIG_ENDIAN; | |
267 | return; | |
268 | default: | |
269 | printf_unfiltered ("Trying to sync, got resval %d\n", resval); | |
270 | } | |
271 | } | |
272 | } | |
273 | } | |
274 | } | |
275 | } | |
276 | error ("Couldn't reset the board, try pressing the reset button"); | |
277 | } | |
278 | ||
279 | ||
280 | #ifdef ANSI_PROTOTYPES | |
281 | void | |
282 | send_rdp (char *template,...) | |
283 | #else | |
284 | void | |
285 | send_rdp (char *template, va_alist) | |
286 | va_dcl | |
287 | #endif | |
288 | { | |
289 | char buf[200]; | |
290 | char *dst = buf; | |
291 | va_list alist; | |
292 | #ifdef ANSI_PROTOTYPES | |
293 | va_start (alist, template); | |
294 | #else | |
295 | va_start (alist); | |
296 | #endif | |
297 | ||
298 | while (*template) | |
299 | { | |
300 | unsigned int val; | |
301 | int *pi; | |
302 | int *pstat; | |
303 | char *pc; | |
304 | int i; | |
305 | switch (*template++) | |
306 | { | |
307 | case 'b': | |
308 | val = va_arg (alist, int); | |
309 | *dst++ = val; | |
310 | break; | |
311 | case 'w': | |
312 | val = va_arg (alist, int); | |
313 | *dst++ = val; | |
314 | *dst++ = val >> 8; | |
315 | *dst++ = val >> 16; | |
316 | *dst++ = val >> 24; | |
317 | break; | |
318 | case 'S': | |
319 | val = get_byte (); | |
320 | if (val != RDP_RES_VALUE) | |
321 | { | |
322 | printf_unfiltered ("got bad res value of %d, %x\n", val, val); | |
323 | } | |
324 | break; | |
325 | case 'V': | |
326 | pstat = va_arg (alist, int *); | |
327 | pi = va_arg (alist, int *); | |
328 | ||
329 | *pstat = get_byte (); | |
330 | /* Check the result was zero, if not read the syndrome */ | |
331 | if (*pstat) | |
332 | { | |
333 | *pi = get_word (); | |
334 | } | |
335 | break; | |
336 | case 'Z': | |
337 | /* Check the result code, error if not zero */ | |
338 | if (get_byte ()) | |
339 | error ("Command garbled"); | |
340 | break; | |
341 | case 'W': | |
342 | /* Read a word from the target */ | |
343 | pi = va_arg (alist, int *); | |
344 | *pi = get_word (); | |
345 | break; | |
346 | case 'P': | |
347 | /* Read in some bytes from the target. */ | |
348 | pc = va_arg (alist, char *); | |
349 | val = va_arg (alist, int); | |
350 | for (i = 0; i < val; i++) | |
351 | { | |
352 | pc[i] = get_byte (); | |
353 | } | |
354 | break; | |
355 | case 'p': | |
356 | /* send what's being pointed at */ | |
357 | pc = va_arg (alist, char *); | |
358 | val = va_arg (alist, int); | |
359 | dst = buf; | |
360 | SERIAL_WRITE (io, pc, val); | |
361 | break; | |
362 | case '-': | |
363 | /* Send whats in the queue */ | |
364 | if (dst != buf) | |
365 | { | |
366 | SERIAL_WRITE (io, buf, dst - buf); | |
367 | dst = buf; | |
368 | } | |
369 | break; | |
370 | case 'B': | |
371 | pi = va_arg (alist, int *); | |
372 | *pi = get_byte (); | |
373 | break; | |
374 | default: | |
375 | abort (); | |
376 | } | |
377 | } | |
378 | va_end (args); | |
379 | ||
380 | if (dst != buf) | |
381 | abort (); | |
382 | } | |
383 | ||
384 | ||
385 | static int | |
386 | rdp_write (memaddr, buf, len) | |
387 | CORE_ADDR memaddr; | |
388 | char *buf; | |
389 | int len; | |
390 | { | |
391 | int res; | |
392 | int val; | |
393 | ||
394 | send_rdp ("bww-p-SV", RDP_MEM_WRITE, memaddr, len, buf, len, &res, &val); | |
395 | ||
396 | if (res) | |
397 | { | |
398 | return val; | |
399 | } | |
400 | return len; | |
401 | } | |
402 | ||
403 | ||
404 | static int | |
405 | rdp_read (memaddr, buf, len) | |
406 | CORE_ADDR memaddr; | |
407 | char *buf; | |
408 | int len; | |
409 | { | |
410 | int res; | |
411 | int val; | |
412 | send_rdp ("bww-S-P-V", | |
413 | RDP_MEM_READ, memaddr, len, | |
414 | buf, len, | |
415 | &res, &val); | |
416 | if (res) | |
417 | { | |
418 | return val; | |
419 | } | |
420 | return len; | |
421 | } | |
422 | ||
423 | static void | |
424 | rdp_fetch_one_register (mask, buf) | |
425 | int mask; | |
426 | char *buf; | |
427 | { | |
428 | int val; | |
429 | send_rdp ("bbw-SWZ", RDP_CPU_READ, RDP_CPU_READWRITE_MODE_CURRENT, mask, &val); | |
430 | store_signed_integer (buf, 4, val); | |
431 | } | |
432 | ||
433 | static void | |
434 | rdp_fetch_one_fpu_register (mask, buf) | |
435 | int mask; | |
436 | char *buf; | |
437 | { | |
438 | #if 0 | |
439 | /* !!! Since the PIE board doesn't work as documented, | |
440 | and it doesn't have FPU hardware anyway and since it | |
441 | slows everything down, I've disabled this. */ | |
442 | int val; | |
443 | if (mask == RDP_FPU_READWRITE_MASK_FPS) | |
444 | { | |
445 | /* this guy is only a word */ | |
446 | send_rdp ("bbw-SWZ", RDP_COPRO_READ, FPU_COPRO_NUMBER, mask, &val); | |
447 | store_signed_integer (buf, 4, val); | |
448 | } | |
449 | else | |
450 | { | |
451 | /* There are 12 bytes long | |
452 | !! fixme about endianness | |
453 | */ | |
454 | int dummy; /* I've seen these come back as four words !! */ | |
455 | send_rdp ("bbw-SWWWWZ", RDP_COPRO_READ, FPU_COPRO_NUMBER, mask, buf + 0, buf + 4, buf + 8, &dummy); | |
456 | } | |
457 | #endif | |
458 | memset (buf, 0, MAX_REGISTER_RAW_SIZE); | |
459 | } | |
460 | ||
461 | ||
462 | static void | |
463 | rdp_store_one_register (mask, buf) | |
464 | int mask; | |
465 | char *buf; | |
466 | { | |
467 | int val = extract_unsigned_integer (buf, 4); | |
468 | ||
469 | send_rdp ("bbww-SZ", | |
470 | RDP_CPU_WRITE, RDP_CPU_READWRITE_MODE_CURRENT, mask, val); | |
471 | } | |
472 | ||
473 | ||
474 | static void | |
475 | rdp_store_one_fpu_register (mask, buf) | |
476 | int mask; | |
477 | char *buf; | |
478 | { | |
479 | #if 0 | |
480 | /* See comment in fetch_one_fpu_register */ | |
481 | if (mask == RDP_FPU_READWRITE_MASK_FPS) | |
482 | { | |
483 | int val = extract_unsigned_integer (buf, 4); | |
484 | /* this guy is only a word */ | |
485 | send_rdp ("bbww-SZ", RDP_COPRO_WRITE, | |
486 | FPU_COPRO_NUMBER, | |
487 | mask, val); | |
488 | } | |
489 | else | |
490 | { | |
491 | /* There are 12 bytes long | |
492 | !! fixme about endianness | |
493 | */ | |
494 | int dummy = 0; | |
495 | /* I've seen these come as four words, not the three advertized !! */ | |
496 | printf ("Sending mask %x\n", mask); | |
497 | send_rdp ("bbwwwww-SZ", | |
498 | RDP_COPRO_WRITE, | |
499 | FPU_COPRO_NUMBER, | |
500 | mask, | |
501 | *(int *) (buf + 0), | |
502 | *(int *) (buf + 4), | |
503 | *(int *) (buf + 8), | |
504 | 0); | |
505 | ||
506 | printf ("done mask %x\n", mask); | |
507 | } | |
508 | #endif | |
509 | } | |
510 | ||
511 | \f | |
512 | /* Convert between GDB requests and the RDP layer. */ | |
513 | ||
514 | static void | |
515 | remote_rdp_fetch_register (regno) | |
516 | int regno; | |
517 | { | |
518 | if (regno == -1) | |
519 | { | |
520 | for (regno = 0; regno < NUM_REGS; regno++) | |
521 | remote_rdp_fetch_register (regno); | |
522 | } | |
523 | else | |
524 | { | |
525 | char buf[MAX_REGISTER_RAW_SIZE]; | |
526 | if (regno < 15) | |
527 | rdp_fetch_one_register (1 << regno, buf); | |
528 | else if (regno == PC_REGNUM) | |
529 | rdp_fetch_one_register (RDP_CPU_READWRITE_MASK_PC, buf); | |
530 | else if (regno == PS_REGNUM) | |
531 | rdp_fetch_one_register (RDP_CPU_READWRITE_MASK_CPSR, buf); | |
532 | else if (regno == FPS_REGNUM) | |
533 | rdp_fetch_one_fpu_register (RDP_FPU_READWRITE_MASK_FPS, buf); | |
534 | else if (regno >= F0_REGNUM && regno <= F7_REGNUM) | |
535 | rdp_fetch_one_fpu_register (1 << (regno - F0_REGNUM), buf); | |
536 | else | |
537 | { | |
538 | printf ("Help me with fetch reg %d\n", regno); | |
539 | } | |
540 | supply_register (regno, buf); | |
541 | } | |
542 | } | |
543 | ||
544 | ||
545 | static void | |
546 | remote_rdp_store_register (regno) | |
547 | int regno; | |
548 | { | |
549 | if (regno == -1) | |
550 | { | |
551 | for (regno = 0; regno < NUM_REGS; regno++) | |
552 | remote_rdp_store_register (regno); | |
553 | } | |
554 | else | |
555 | { | |
556 | char tmp[MAX_REGISTER_RAW_SIZE]; | |
557 | read_register_gen (regno, tmp); | |
558 | if (regno < 15) | |
559 | rdp_store_one_register (1 << regno, tmp); | |
560 | else if (regno == PC_REGNUM) | |
561 | rdp_store_one_register (RDP_CPU_READWRITE_MASK_PC, tmp); | |
562 | else if (regno == PS_REGNUM) | |
563 | rdp_store_one_register (RDP_CPU_READWRITE_MASK_CPSR, tmp); | |
564 | else if (regno >= F0_REGNUM && regno <= F7_REGNUM) | |
565 | rdp_store_one_fpu_register (1 << (regno - F0_REGNUM), tmp); | |
566 | else | |
567 | { | |
568 | printf ("Help me with reg %d\n", regno); | |
569 | } | |
570 | } | |
571 | } | |
572 | ||
573 | static void | |
574 | remote_rdp_kill () | |
575 | { | |
576 | callback->shutdown (callback); | |
577 | } | |
578 | ||
579 | ||
580 | static void | |
581 | rdp_info () | |
582 | { | |
583 | send_rdp ("bw-S-W-Z", RDP_INFO, RDP_INFO_ABOUT_STEP, | |
584 | &ds.step_info); | |
585 | send_rdp ("bw-S-W-Z", RDP_INFO, RDP_INFO_ABOUT_BREAK, | |
586 | &ds.break_info); | |
587 | send_rdp ("bw-S-WW-Z", RDP_INFO, RDP_INFO_ABOUT_TARGET, | |
588 | &ds.target_info, | |
589 | &ds.model_info); | |
590 | ||
591 | ds.can_step = ds.step_info & RDP_INFO_ABOUT_STEP_1; | |
592 | ||
593 | ds.rdi_level = (ds.target_info >> 5) & 3; | |
594 | } | |
595 | ||
596 | ||
597 | static void | |
598 | rdp_execute_start () | |
599 | { | |
600 | /* Start it off, but don't wait for it */ | |
601 | send_rdp ("bb-", RDP_EXEC, RDP_EXEC_TYPE_SYNC); | |
602 | } | |
603 | ||
604 | ||
605 | ||
606 | #define a_byte 1 | |
607 | #define a_word 2 | |
608 | #define a_string 3 | |
609 | ||
610 | ||
611 | typedef struct | |
612 | { | |
613 | CORE_ADDR n; | |
614 | const char *s; | |
615 | } | |
616 | argsin; | |
617 | ||
618 | #define ABYTE 1 | |
619 | #define AWORD 2 | |
620 | #define ASTRING 3 | |
621 | #define ADDRLEN 4 | |
622 | ||
623 | #define SWI_WriteC 0x0 | |
624 | #define SWI_Write0 0x2 | |
625 | #define SWI_ReadC 0x4 | |
626 | #define SWI_CLI 0x5 | |
627 | #define SWI_GetEnv 0x10 | |
628 | #define SWI_Exit 0x11 | |
629 | #define SWI_EnterOS 0x16 | |
630 | ||
631 | #define SWI_GetErrno 0x60 | |
632 | #define SWI_Clock 0x61 | |
633 | ||
634 | #define SWI_Time 0x63 | |
635 | #define SWI_Remove 0x64 | |
636 | #define SWI_Rename 0x65 | |
637 | #define SWI_Open 0x66 | |
638 | ||
639 | #define SWI_Close 0x68 | |
640 | #define SWI_Write 0x69 | |
641 | #define SWI_Read 0x6a | |
642 | #define SWI_Seek 0x6b | |
643 | #define SWI_Flen 0x6c | |
644 | ||
645 | #define SWI_IsTTY 0x6e | |
646 | #define SWI_TmpNam 0x6f | |
647 | #define SWI_InstallHandler 0x70 | |
648 | #define SWI_GenerateError 0x71 | |
649 | ||
650 | ||
651 | static int | |
652 | exec_swi (swi, args) | |
653 | int swi; | |
654 | argsin *args; | |
655 | { | |
656 | int i; | |
657 | char c; | |
658 | switch (swi) | |
659 | { | |
660 | case SWI_WriteC: | |
661 | callback->write_stdout (callback, &c, 1); | |
662 | return 0; | |
663 | case SWI_Write0: | |
664 | for (i = 0; i < args->n; i++) | |
665 | callback->write_stdout (callback, args->s, strlen (args->s)); | |
666 | return 0; | |
667 | case SWI_ReadC: | |
668 | callback->read_stdin (callback, &c, 1); | |
669 | args->n = c; | |
670 | return 1; | |
671 | case SWI_CLI: | |
672 | args->n = callback->system (callback, args->s); | |
673 | return 1; | |
674 | case SWI_GetErrno: | |
675 | args->n = callback->get_errno (callback); | |
676 | return 1; | |
677 | case SWI_Time: | |
678 | args->n = callback->time (callback, NULL); | |
679 | return 1; | |
680 | case SWI_Remove: | |
681 | args->n = callback->unlink (callback, args->s); | |
682 | return 1; | |
683 | case SWI_Rename: | |
684 | args->n = callback->rename (callback, args[0].s, args[1].s); | |
685 | return 1; | |
686 | case SWI_Open: | |
687 | i = 0; | |
688 | ||
689 | #ifdef O_BINARY | |
690 | if (args[1].n & 1) | |
691 | i |= O_BINARY; | |
692 | #endif | |
693 | if (args[1].n & 2) | |
694 | i |= O_RDWR; | |
695 | ||
696 | if (args[1].n & 4) | |
697 | { | |
698 | i |= O_CREAT; | |
699 | } | |
700 | ||
701 | if (args[1].n & 8) | |
702 | i |= O_APPEND; | |
703 | ||
704 | args->n = callback->open (callback, args->s, i); | |
705 | return 1; | |
706 | ||
707 | case SWI_Close: | |
708 | args->n = callback->close (callback, args->n); | |
709 | return 1; | |
710 | ||
711 | case SWI_Write: | |
712 | args->n = callback->write (callback, args[0].n, args[1].s, args[1].n); | |
713 | return 1; | |
714 | case SWI_Read: | |
715 | { | |
716 | char *copy = alloca (args[2].n); | |
717 | int done = callback->read (callback, args[0].n, copy, args[2].n); | |
718 | if (done > 0) | |
719 | remote_rdp_xfer_inferior_memory (args[0].n, copy, done, 1, 0); | |
720 | args->n -= done; | |
721 | return 1; | |
722 | } | |
723 | ||
724 | case SWI_Seek: | |
725 | args->n = callback->lseek (callback, args[0].n, args[1].n, 0) >= 0; | |
726 | return 1; | |
727 | case SWI_Flen: | |
728 | { | |
729 | long old = callback->lseek (callback, args->n, 1, 1); | |
730 | args->n = callback->lseek (callback, args->n, 2, 0); | |
731 | callback->lseek (callback, args->n, old, 0); | |
732 | return 1; | |
733 | } | |
734 | ||
735 | case SWI_IsTTY: | |
736 | args->n = callback->isatty (callback, args->n); | |
737 | return 1; | |
738 | ||
739 | default: | |
740 | return 0; | |
741 | } | |
742 | } | |
743 | ||
744 | ||
745 | static void | |
746 | handle_swi () | |
747 | { | |
748 | argsin args[3]; | |
749 | char *buf; | |
750 | int len; | |
751 | int count = 0; | |
752 | ||
753 | int swino = get_word (); | |
754 | int type = get_byte (); | |
755 | while (type != 0) | |
756 | { | |
757 | switch (type & 0x3) | |
758 | { | |
759 | case ABYTE: | |
760 | args[count].n = get_byte (); | |
761 | break; | |
762 | ||
763 | case AWORD: | |
764 | args[count].n = get_word (); | |
765 | break; | |
766 | ||
767 | case ASTRING: | |
768 | /* If the word is under 32 bytes it will be sent otherwise | |
769 | an address to it is passed. Also: Special case of 255 */ | |
770 | ||
771 | len = get_byte (); | |
772 | if (len > 32) | |
773 | { | |
774 | if (len == 255) | |
775 | { | |
776 | len = get_word (); | |
777 | } | |
778 | buf = alloca (len); | |
779 | remote_rdp_xfer_inferior_memory (get_word (), | |
780 | buf, | |
781 | len, | |
782 | 0, | |
783 | 0); | |
784 | } | |
785 | else | |
786 | { | |
787 | int i; | |
788 | buf = alloca (len + 1); | |
789 | for (i = 0; i < len; i++) | |
790 | buf[i] = get_byte (); | |
791 | buf[i] = 0; | |
792 | } | |
793 | args[count].n = len; | |
794 | args[count].s = buf; | |
795 | break; | |
796 | ||
797 | default: | |
798 | error ("Unimplented SWI argument"); | |
799 | } | |
800 | ||
801 | type = type >> 2; | |
802 | count++; | |
803 | } | |
804 | ||
805 | if (exec_swi (swino, args)) | |
806 | { | |
807 | /* We have two options here reply with either a byte or a word | |
808 | which is stored in args[0].n. There is no harm in replying with | |
809 | a word all the time, so thats what I do! */ | |
810 | send_rdp ("bbw-", RDP_OSOpReply, RDP_OSOpWord, args[0].n); | |
811 | } | |
812 | else | |
813 | { | |
814 | send_rdp ("bb-", RDP_OSOpReply, RDP_OSOpNothing); | |
815 | } | |
816 | } | |
817 | ||
818 | static void | |
819 | rdp_execute_finish () | |
820 | { | |
821 | int running = 1; | |
822 | ||
823 | while (running) | |
824 | { | |
825 | int res; | |
826 | res = SERIAL_READCHAR (io, 1); | |
827 | while (res == SERIAL_TIMEOUT) | |
828 | { | |
829 | QUIT ; | |
830 | printf_filtered ("Waiting for target..\n"); | |
831 | res = SERIAL_READCHAR (io, 1); | |
832 | } | |
833 | ||
834 | switch (res) | |
835 | { | |
836 | case RDP_RES_SWI: | |
837 | handle_swi (); | |
838 | break; | |
839 | case RDP_RES_VALUE: | |
840 | send_rdp ("B", &ds.rdi_stopped_status); | |
841 | running = 0; | |
842 | break; | |
843 | case RDP_RESET: | |
844 | printf_filtered ("Target reset\n"); | |
845 | running = 0; | |
846 | break; | |
847 | default: | |
848 | printf_filtered ("Ignoring %x\n", res); | |
849 | break; | |
850 | } | |
851 | } | |
852 | } | |
853 | ||
854 | ||
855 | static void | |
856 | rdp_execute () | |
857 | { | |
858 | rdp_execute_start (); | |
859 | rdp_execute_finish (); | |
860 | } | |
861 | ||
862 | static int | |
863 | remote_rdp_insert_breakpoint (addr, save) | |
864 | CORE_ADDR addr; | |
865 | char *save; | |
866 | { | |
867 | int res; | |
868 | if (ds.rdi_level > 0) | |
869 | { | |
870 | send_rdp ("bwb-SWB", | |
871 | RDP_SET_BREAK, | |
872 | addr, | |
873 | RDP_SET_BREAK_TYPE_PC_EQUAL | RDP_SET_BREAK_TYPE_GET_HANDLE, | |
874 | save, | |
875 | &res); | |
876 | } | |
877 | else | |
878 | { | |
879 | send_rdp ("bwb-SB", | |
880 | RDP_SET_BREAK, | |
881 | addr, | |
882 | RDP_SET_BREAK_TYPE_PC_EQUAL, | |
883 | &res); | |
884 | } | |
885 | return res; | |
886 | } | |
887 | ||
888 | static int | |
889 | remote_rdp_remove_breakpoint (addr, save) | |
890 | CORE_ADDR addr; | |
891 | char *save; | |
892 | { | |
893 | int res; | |
894 | if (ds.rdi_level > 0) | |
895 | { | |
896 | send_rdp ("b-p-S-B", | |
897 | RDP_CLEAR_BREAK, | |
898 | save, 4, | |
899 | &res); | |
900 | } | |
901 | else | |
902 | { | |
903 | send_rdp ("bw-S-B", | |
904 | RDP_CLEAR_BREAK, | |
905 | addr, | |
906 | &res); | |
907 | } | |
908 | return res; | |
909 | } | |
910 | ||
911 | static void | |
912 | rdp_step () | |
913 | { | |
914 | if (ds.can_step && 0) | |
915 | { | |
916 | /* The pie board can't do steps so I can't test this, and | |
917 | the other code will always work. */ | |
918 | int status; | |
919 | send_rdp ("bbw-S-B", | |
920 | RDP_STEP, 0, 1, | |
921 | &status); | |
922 | } | |
923 | else | |
924 | { | |
925 | char handle[4]; | |
926 | CORE_ADDR pc = read_register (PC_REGNUM); | |
927 | pc = arm_get_next_pc (pc); | |
928 | remote_rdp_insert_breakpoint (pc, &handle); | |
929 | rdp_execute (); | |
930 | remote_rdp_remove_breakpoint (pc, &handle); | |
931 | } | |
932 | } | |
933 | ||
934 | static void | |
935 | remote_rdp_open (args, from_tty) | |
936 | char *args; | |
937 | int from_tty; | |
938 | { | |
939 | if (!args) | |
940 | error_no_arg ("serial port device name"); | |
941 | ||
942 | target_preopen (from_tty); | |
943 | ||
944 | io = SERIAL_OPEN (args); | |
945 | ||
946 | if (!io) | |
947 | perror_with_name (args); | |
948 | ||
949 | SERIAL_RAW (io); | |
950 | ||
951 | rdp_init (); | |
952 | ||
953 | rdp_info (); | |
954 | if (from_tty) | |
955 | { | |
956 | printf_unfiltered ("Remote RDP debugging using %s\n", args); | |
957 | } | |
958 | ||
959 | push_target (&remote_rdp_ops); | |
960 | ||
961 | callback->init (callback); | |
962 | flush_cached_frames (); | |
963 | registers_changed (); | |
964 | stop_pc = read_pc (); | |
965 | set_current_frame (create_new_frame (read_fp (), stop_pc)); | |
966 | select_frame (get_current_frame (), 0); | |
967 | print_stack_frame (selected_frame, -1, 1); | |
968 | } | |
969 | ||
970 | ||
971 | ||
972 | /* Close out all files and local state before this target loses control. */ | |
973 | ||
974 | static void | |
975 | remote_rdp_close (quitting) | |
976 | int quitting; | |
977 | { | |
978 | callback->shutdown (callback); | |
979 | SERIAL_CLOSE (io); | |
980 | } | |
981 | ||
982 | /* Terminate the open connection to the remote debugger. */ | |
983 | ||
984 | static void | |
985 | remote_rdp_detach (args, from_tty) | |
986 | char *args; | |
987 | int from_tty; | |
988 | { | |
989 | pop_target (); | |
990 | } | |
991 | ||
992 | /* Resume execution of the target process. STEP says whether to single-step | |
993 | or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be given | |
994 | to the target, or zero for no signal. */ | |
995 | ||
996 | static void | |
997 | remote_rdp_resume (pid, step, siggnal) | |
998 | int pid, step; | |
999 | enum target_signal siggnal; | |
1000 | { | |
1001 | if (step) | |
1002 | rdp_step (); | |
1003 | else | |
1004 | rdp_execute (); | |
1005 | } | |
1006 | ||
1007 | /* Wait for inferior process to do something. Return pid of child, | |
1008 | or -1 in case of error; store status through argument pointer STATUS, | |
1009 | just as `wait' would. */ | |
1010 | ||
1011 | static int | |
1012 | remote_rdp_wait (pid, status) | |
1013 | int pid; | |
1014 | struct target_waitstatus *status; | |
1015 | { | |
1016 | switch (ds.rdi_stopped_status) | |
1017 | { | |
1018 | default: | |
1019 | case RDP_RES_RESET: | |
1020 | case RDP_RES_SWI: | |
1021 | status->kind = TARGET_WAITKIND_EXITED; | |
1022 | status->value.integer = read_register (0); | |
1023 | break; | |
1024 | case RDP_RES_AT_BREAKPOINT: | |
1025 | status->kind = TARGET_WAITKIND_STOPPED; | |
1026 | /* The signal in sigrc is a host signal. That probably | |
1027 | should be fixed. */ | |
1028 | status->value.sig = TARGET_SIGNAL_TRAP; | |
1029 | break; | |
1030 | #if 0 | |
1031 | case rdp_signalled: | |
1032 | status->kind = TARGET_WAITKIND_SIGNALLED; | |
1033 | /* The signal in sigrc is a host signal. That probably | |
1034 | should be fixed. */ | |
1035 | status->value.sig = target_signal_from_host (sigrc); | |
1036 | break; | |
1037 | #endif | |
1038 | } | |
1039 | ||
1040 | return inferior_pid; | |
1041 | } | |
1042 | ||
1043 | /* Get ready to modify the registers array. On machines which store | |
1044 | individual registers, this doesn't need to do anything. On machines | |
1045 | which store all the registers in one fell swoop, this makes sure | |
1046 | that registers contains all the registers from the program being | |
1047 | debugged. */ | |
1048 | ||
1049 | static void | |
1050 | remote_rdp_prepare_to_store () | |
1051 | { | |
1052 | /* Do nothing, since we can store individual regs */ | |
1053 | } | |
1054 | ||
1055 | static int | |
1056 | remote_rdp_xfer_inferior_memory (memaddr, myaddr, len, write, target) | |
1057 | CORE_ADDR memaddr; | |
1058 | char *myaddr; | |
1059 | int len; | |
1060 | int write; | |
1061 | struct target_ops *target; /* ignored */ | |
1062 | { | |
1063 | /* I infer from D Taylor's code that there's a limit on the amount | |
1064 | we can transfer in one chunk.. */ | |
1065 | int done = 0; | |
1066 | while (done < len) | |
1067 | { | |
1068 | int justdone; | |
1069 | int thisbite = len - done; | |
1070 | if (thisbite > RDP_MOUTHFULL) | |
1071 | thisbite = RDP_MOUTHFULL; | |
1072 | ||
1073 | QUIT; | |
1074 | ||
1075 | if (write) | |
1076 | { | |
1077 | justdone = rdp_write (memaddr + done, myaddr + done, thisbite); | |
1078 | } | |
1079 | else | |
1080 | { | |
1081 | justdone = rdp_read (memaddr + done, myaddr + done, thisbite); | |
1082 | } | |
1083 | ||
1084 | done += justdone; | |
1085 | ||
1086 | if (justdone != thisbite) | |
1087 | break; | |
1088 | } | |
1089 | return done; | |
1090 | } | |
1091 | ||
1092 | ||
1093 | ||
1094 | struct yn | |
1095 | { | |
1096 | const char *name; | |
1097 | int bit; | |
1098 | }; | |
1099 | static struct yn stepinfo[] = | |
1100 | { | |
1101 | {"Step more than one instruction", RDP_INFO_ABOUT_STEP_GT_1}, | |
1102 | {"Step to jump", RDP_INFO_ABOUT_STEP_TO_JMP}, | |
1103 | {"Step one instruction", RDP_INFO_ABOUT_STEP_1}, | |
1104 | {0} | |
1105 | }; | |
1106 | ||
1107 | static struct yn breakinfo[] = | |
1108 | { | |
1109 | {"comparison breakpoints supported", RDP_INFO_ABOUT_BREAK_COMP}, | |
1110 | {"range breakpoints supported", RDP_INFO_ABOUT_BREAK_RANGE}, | |
1111 | {"watchpoints for byte reads supported", RDP_INFO_ABOUT_BREAK_BYTE_READ}, | |
1112 | {"watchpoints for half-word reads supported", RDP_INFO_ABOUT_BREAK_HALFWORD_READ}, | |
1113 | {"watchpoints for word reads supported", RDP_INFO_ABOUT_BREAK_WORD_READ}, | |
1114 | {"watchpoints for byte writes supported", RDP_INFO_ABOUT_BREAK_BYTE_WRITE}, | |
1115 | {"watchpoints for half-word writes supported", RDP_INFO_ABOUT_BREAK_HALFWORD_WRITE}, | |
1116 | {"watchpoints for word writes supported", RDP_INFO_ABOUT_BREAK_WORD_WRITE}, | |
1117 | {"mask break/watch-points supported", RDP_INFO_ABOUT_BREAK_MASK}, | |
1118 | {"thread-specific breakpoints supported", RDP_INFO_ABOUT_BREAK_THREAD_BREAK}, | |
1119 | {"thread-specific watchpoints supported", RDP_INFO_ABOUT_BREAK_THREAD_WATCH}, | |
1120 | {"conditional breakpoints supported", RDP_INFO_ABOUT_BREAK_COND}, | |
1121 | {0} | |
1122 | }; | |
1123 | ||
1124 | ||
1125 | static void | |
1126 | dump_bits (t, info) | |
1127 | struct yn *t; | |
1128 | int info; | |
1129 | { | |
1130 | while (t->name) | |
1131 | { | |
1132 | printf_unfiltered (" %-45s : %s\n", t->name, (info & t->bit) ? "Yes" : "No"); | |
1133 | t++; | |
1134 | } | |
1135 | } | |
1136 | ||
1137 | static void | |
1138 | remote_rdp_files_info (target) | |
1139 | struct target_ops *target; | |
1140 | { | |
1141 | printf_filtered ("Target capabilities:\n"); | |
1142 | dump_bits (stepinfo, ds.step_info); | |
1143 | dump_bits (breakinfo, ds.break_info); | |
1144 | printf_unfiltered ("target level RDI %x\n", (ds.target_info >> 5) & 3); | |
1145 | } | |
1146 | ||
1147 | ||
1148 | /* Define the target subroutine names */ | |
1149 | ||
1150 | struct target_ops remote_rdp_ops = | |
1151 | { | |
1152 | "rdp", /* to_shortname */ | |
1153 | /* to_longname */ | |
1154 | "Remote Target using the RDProtocol", | |
1155 | /* to_doc */ | |
1156 | "Use a remote ARM system which uses the ARM Remote Debugging Protocol", | |
1157 | remote_rdp_open, /* to_open */ | |
1158 | remote_rdp_close, /* to_close */ | |
1159 | NULL, /* to_attach */ | |
1160 | NULL, /* to_detach */ | |
1161 | remote_rdp_resume, /* to_resume */ | |
1162 | remote_rdp_wait, /* to_wait */ | |
1163 | remote_rdp_fetch_register, /* to_fetch_registers */ | |
1164 | remote_rdp_store_register, /* to_store_registers */ | |
1165 | remote_rdp_prepare_to_store, /* to_prepare_to_store */ | |
1166 | remote_rdp_xfer_inferior_memory, /* to_xfer_memory */ | |
1167 | remote_rdp_files_info, /* to_files_info */ | |
1168 | remote_rdp_insert_breakpoint, /* to_insert_breakpoint */ | |
1169 | remote_rdp_remove_breakpoint, /* to_remove_breakpoint */ | |
1170 | NULL, /* to_terminal_init */ | |
1171 | NULL, /* to_terminal_inferior */ | |
1172 | NULL, /* to_terminal_ours_for_output */ | |
1173 | NULL, /* to_terminal_ours */ | |
1174 | NULL, /* to_terminal_info */ | |
1175 | remote_rdp_kill, /* to_kill */ | |
1176 | generic_load, /* to_load */ | |
1177 | NULL, /* to_lookup_symbol */ | |
1178 | NULL, /* to_create_inferior */ | |
1179 | generic_mourn_inferior, /* to_mourn_inferior */ | |
1180 | 0, /* to_can_run */ | |
1181 | 0, /* to_notice_signals */ | |
1182 | 0, /* to_thread_alive */ | |
1183 | 0, /* to_stop */ | |
1184 | process_stratum, /* to_stratum */ | |
1185 | NULL, /* to_next */ | |
1186 | 1, /* to_has_all_memory */ | |
1187 | 1, /* to_has_memory */ | |
1188 | 1, /* to_has_stack */ | |
1189 | 1, /* to_has_registers */ | |
1190 | 1, /* to_has_execution */ | |
1191 | NULL, /* sections */ | |
1192 | NULL, /* sections_end */ | |
1193 | OPS_MAGIC, /* to_magic */ | |
1194 | }; | |
1195 | ||
1196 | void | |
1197 | _initialize_remote_rdp () | |
1198 | { | |
1199 | add_target (&remote_rdp_ops); | |
1200 | } |