Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* GDB interface to ARM RDI library. |
2 | Copyright 1997, 1998 Free Software Foundation, Inc. | |
3 | ||
c5aa993b | 4 | This file is part of GDB. |
c906108c | 5 | |
c5aa993b JM |
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. | |
c906108c | 10 | |
c5aa993b JM |
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. | |
c906108c | 15 | |
c5aa993b JM |
16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 59 Temple Place - Suite 330, | |
19 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
20 | |
21 | #include "defs.h" | |
22 | #include "gdb_string.h" | |
23 | #include <fcntl.h> | |
24 | #include "frame.h" | |
25 | #include "inferior.h" | |
26 | #include "bfd.h" | |
27 | #include "symfile.h" | |
28 | #include "target.h" | |
29 | #include "wait.h" | |
30 | #include "gdbcmd.h" | |
31 | #include "objfiles.h" | |
32 | #include "gdb-stabs.h" | |
33 | #include "gdbthread.h" | |
34 | #include "gdbcore.h" | |
35 | ||
36 | #ifdef USG | |
37 | #include <sys/types.h> | |
38 | #endif | |
39 | ||
40 | #include <signal.h> | |
41 | ||
42 | #include "rdi-share/ardi.h" | |
43 | #include "rdi-share/adp.h" | |
44 | #include "rdi-share/hsys.h" | |
45 | ||
46 | extern int isascii PARAMS ((int)); | |
47 | ||
48 | /* Prototypes for local functions */ | |
49 | ||
c5aa993b | 50 | static void arm_rdi_files_info PARAMS ((struct target_ops * ignore)); |
c906108c SS |
51 | |
52 | static int arm_rdi_xfer_memory PARAMS ((CORE_ADDR memaddr, char *myaddr, | |
c5aa993b JM |
53 | int len, int should_write, |
54 | struct target_ops * target)); | |
c906108c SS |
55 | |
56 | static void arm_rdi_prepare_to_store PARAMS ((void)); | |
57 | ||
58 | static void arm_rdi_fetch_registers PARAMS ((int regno)); | |
59 | ||
60 | static void arm_rdi_resume PARAMS ((int pid, int step, | |
c5aa993b | 61 | enum target_signal siggnal)); |
c906108c SS |
62 | |
63 | static int arm_rdi_start_remote PARAMS ((char *dummy)); | |
64 | ||
65 | static void arm_rdi_open PARAMS ((char *name, int from_tty)); | |
66 | ||
67 | static void arm_rdi_create_inferior PARAMS ((char *exec_file, char *args, | |
68 | char **env)); | |
69 | ||
70 | static void arm_rdi_close PARAMS ((int quitting)); | |
71 | ||
72 | static void arm_rdi_store_registers PARAMS ((int regno)); | |
73 | ||
74 | static void arm_rdi_mourn PARAMS ((void)); | |
75 | ||
76 | static void arm_rdi_send PARAMS ((char *buf)); | |
77 | ||
c5aa993b | 78 | static int arm_rdi_wait PARAMS ((int pid, struct target_waitstatus * status)); |
c906108c SS |
79 | |
80 | static void arm_rdi_kill PARAMS ((void)); | |
81 | ||
82 | static void arm_rdi_detach PARAMS ((char *args, int from_tty)); | |
83 | ||
84 | static void arm_rdi_interrupt PARAMS ((int signo)); | |
85 | ||
86 | static void arm_rdi_interrupt_twice PARAMS ((int signo)); | |
87 | ||
88 | static void interrupt_query PARAMS ((void)); | |
89 | ||
90 | static int arm_rdi_insert_breakpoint PARAMS ((CORE_ADDR, char *)); | |
91 | ||
92 | static int arm_rdi_remove_breakpoint PARAMS ((CORE_ADDR, char *)); | |
93 | ||
94 | static char *rdi_error_message PARAMS ((int err)); | |
95 | ||
96 | static enum target_signal rdi_error_signal PARAMS ((int err)); | |
97 | ||
98 | /* Global variables. */ | |
99 | ||
100 | struct target_ops arm_rdi_ops; | |
101 | ||
102 | static struct Dbg_ConfigBlock gdb_config; | |
103 | ||
104 | static struct Dbg_HostosInterface gdb_hostif; | |
105 | ||
106 | static int max_load_size; | |
107 | ||
108 | static int execute_status; | |
109 | ||
110 | /* A little list of breakpoints that have been set. */ | |
111 | ||
c5aa993b JM |
112 | static struct local_bp_list_entry |
113 | { | |
114 | CORE_ADDR addr; | |
115 | PointHandle point; | |
116 | struct local_bp_list_entry *next; | |
117 | } | |
118 | *local_bp_list; | |
c906108c | 119 | \f |
c5aa993b | 120 | |
c906108c SS |
121 | /* Stub for catch_errors. */ |
122 | ||
123 | static int | |
124 | arm_rdi_start_remote (dummy) | |
125 | char *dummy; | |
126 | { | |
127 | return 1; | |
128 | } | |
129 | ||
130 | /* Helper callbacks for the "host interface" structure. RDI functions call | |
131 | these to forward output from the target system and so forth. */ | |
132 | ||
133 | void | |
134 | voiddummy () | |
135 | { | |
136 | fprintf_unfiltered (gdb_stdout, "void dummy\n"); | |
137 | } | |
138 | ||
139 | static void | |
140 | myprint (arg, format, ap) | |
141 | PTR arg; | |
142 | const char *format; | |
143 | va_list ap; | |
144 | { | |
145 | vfprintf_unfiltered (gdb_stdout, format, ap); | |
146 | } | |
147 | ||
148 | static void | |
149 | mywritec (arg, c) | |
150 | PTR arg; | |
151 | int c; | |
152 | { | |
153 | if (isascii (c)) | |
154 | fputc_unfiltered (c, gdb_stdout); | |
155 | } | |
156 | ||
157 | static int | |
158 | mywrite (arg, buffer, len) | |
159 | PTR arg; | |
160 | char const *buffer; | |
161 | int len; | |
162 | { | |
163 | int i; | |
164 | char *e; | |
165 | ||
166 | e = (char *) buffer; | |
167 | for (i = 0; i < len; i++) | |
c5aa993b | 168 | { |
c906108c | 169 | if (isascii ((int) *e)) |
c5aa993b JM |
170 | { |
171 | fputc_unfiltered ((int) *e, gdb_stdout); | |
172 | e++; | |
173 | } | |
174 | } | |
c906108c SS |
175 | |
176 | return len; | |
177 | } | |
178 | ||
179 | static void | |
180 | mypause (arg) | |
181 | PTR arg; | |
182 | { | |
183 | } | |
184 | ||
185 | /* These last two are tricky as we have to handle the special case of | |
186 | being interrupted more carefully */ | |
187 | ||
188 | static int | |
189 | myreadc (arg) | |
190 | PTR arg; | |
c5aa993b | 191 | { |
c906108c SS |
192 | return fgetc (stdin); |
193 | } | |
194 | ||
195 | static char * | |
196 | mygets (arg, buffer, len) | |
197 | PTR arg; | |
198 | char *buffer; | |
199 | int len; | |
200 | { | |
c5aa993b | 201 | return fgets (buffer, len, stdin); |
c906108c SS |
202 | } |
203 | ||
204 | /* Prevent multiple calls to angel_RDI_close(). */ | |
205 | static int closed_already = 1; | |
206 | ||
207 | /* Open a connection to a remote debugger. NAME is the filename used | |
208 | for communication. */ | |
209 | ||
210 | static void | |
211 | arm_rdi_open (name, from_tty) | |
212 | char *name; | |
213 | int from_tty; | |
214 | { | |
215 | int rslt, i; | |
216 | unsigned long arg1, arg2; | |
217 | ||
218 | if (name == NULL) | |
219 | error ("To open an RDI connection, you need to specify what serial\n\ | |
220 | device is attached to the remote system (e.g. /dev/ttya)."); | |
221 | ||
222 | /* Make the basic low-level connection. */ | |
223 | ||
224 | rslt = Adp_OpenDevice (name, NULL, 1); | |
225 | ||
226 | if (rslt != adp_ok) | |
227 | error ("Could not open device \"%s\"", name); | |
228 | ||
229 | gdb_config.bytesex = 2 | (TARGET_BYTE_ORDER == BIG_ENDIAN ? 1 : 0); | |
230 | gdb_config.fpe = 1; | |
231 | gdb_config.rditype = 2; | |
232 | gdb_config.heartbeat_on = 1; | |
233 | gdb_config.flags = 2; | |
234 | ||
235 | gdb_hostif.dbgprint = myprint; | |
236 | gdb_hostif.dbgpause = mypause; | |
237 | gdb_hostif.dbgarg = NULL; | |
238 | gdb_hostif.writec = mywritec; | |
239 | gdb_hostif.readc = myreadc; | |
240 | gdb_hostif.write = mywrite; | |
241 | gdb_hostif.gets = mygets; | |
242 | gdb_hostif.hostosarg = NULL; | |
243 | gdb_hostif.reset = voiddummy; | |
244 | ||
245 | rslt = angel_RDI_open (10, &gdb_config, &gdb_hostif, NULL); | |
246 | if (rslt == RDIError_BigEndian || rslt == RDIError_LittleEndian) | |
c5aa993b | 247 | ; /* do nothing, this is the expected return */ |
c906108c SS |
248 | else if (rslt) |
249 | { | |
250 | printf_filtered ("RDI_open: %s\n", rdi_error_message (rslt)); | |
2acceee2 JM |
251 | Adp_CloseDevice (); |
252 | error("RID_open failed\n"); | |
c906108c SS |
253 | } |
254 | ||
255 | rslt = angel_RDI_info (RDIInfo_Target, &arg1, &arg2); | |
256 | if (rslt) | |
257 | { | |
258 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); | |
259 | } | |
260 | rslt = angel_RDI_info (RDIInfo_Points, &arg1, &arg2); | |
261 | if (rslt) | |
262 | { | |
263 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); | |
264 | } | |
265 | rslt = angel_RDI_info (RDIInfo_Step, &arg1, &arg2); | |
266 | if (rslt) | |
267 | { | |
268 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); | |
269 | } | |
270 | rslt = angel_RDI_info (RDIInfo_CoPro, &arg1, &arg2); | |
271 | if (rslt) | |
272 | { | |
273 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); | |
274 | } | |
275 | rslt = angel_RDI_info (RDIInfo_SemiHosting, &arg1, &arg2); | |
276 | if (rslt) | |
277 | { | |
278 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); | |
279 | } | |
280 | ||
281 | rslt = angel_RDI_info (RDIInfo_GetLoadSize, &arg1, &arg2); | |
282 | if (rslt) | |
283 | { | |
284 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); | |
285 | } | |
286 | max_load_size = arg1; | |
287 | ||
288 | push_target (&arm_rdi_ops); | |
289 | ||
290 | target_fetch_registers (-1); | |
291 | ||
292 | rslt = angel_RDI_open (1, &gdb_config, NULL, NULL); | |
293 | if (rslt) | |
294 | { | |
295 | printf_filtered ("RDI_open: %s\n", rdi_error_message (rslt)); | |
296 | } | |
297 | ||
298 | arg1 = 0x13b; | |
299 | rslt = angel_RDI_info (RDIVector_Catch, &arg1, &arg2); | |
300 | if (rslt) | |
301 | { | |
302 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); | |
303 | } | |
304 | ||
305 | arg1 = (unsigned long) ""; | |
306 | rslt = angel_RDI_info (RDISet_Cmdline, &arg1, &arg2); | |
307 | if (rslt) | |
308 | { | |
309 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); | |
310 | } | |
311 | ||
312 | /* Clear out any existing records of breakpoints. */ | |
313 | { | |
314 | struct local_bp_list_entry *entry, *preventry = NULL; | |
315 | ||
316 | for (entry = local_bp_list; entry != NULL; entry = entry->next) | |
317 | { | |
318 | if (preventry) | |
319 | free (preventry); | |
320 | } | |
321 | } | |
322 | ||
323 | printf_filtered ("Connected to ARM RDI target.\n"); | |
324 | closed_already = 0; | |
325 | inferior_pid = 42; | |
326 | } | |
327 | ||
328 | /* Start an inferior process and set inferior_pid to its pid. | |
329 | EXEC_FILE is the file to run. | |
330 | ARGS is a string containing the arguments to the program. | |
331 | ENV is the environment vector to pass. Errors reported with error(). | |
332 | On VxWorks and various standalone systems, we ignore exec_file. */ | |
333 | /* This is called not only when we first attach, but also when the | |
334 | user types "run" after having attached. */ | |
335 | ||
336 | static void | |
337 | arm_rdi_create_inferior (exec_file, args, env) | |
338 | char *exec_file; | |
339 | char *args; | |
340 | char **env; | |
341 | { | |
342 | int len, rslt; | |
343 | unsigned long arg1, arg2; | |
344 | char *arg_buf; | |
345 | CORE_ADDR entry_point; | |
346 | ||
347 | if (exec_file == 0 || exec_bfd == 0) | |
c5aa993b | 348 | error ("No executable file specified."); |
c906108c SS |
349 | |
350 | entry_point = (CORE_ADDR) bfd_get_start_address (exec_bfd); | |
351 | ||
c5aa993b | 352 | arm_rdi_kill (); |
c906108c SS |
353 | remove_breakpoints (); |
354 | init_wait_for_inferior (); | |
355 | ||
c5aa993b | 356 | len = strlen (exec_file) + 1 + strlen (args) + 1 + /*slop */ 10; |
c906108c SS |
357 | arg_buf = (char *) alloca (len); |
358 | arg_buf[0] = '\0'; | |
359 | strcat (arg_buf, exec_file); | |
360 | strcat (arg_buf, " "); | |
361 | strcat (arg_buf, args); | |
362 | ||
363 | inferior_pid = 42; | |
c5aa993b | 364 | insert_breakpoints (); /* Needed to get correct instruction in cache */ |
c906108c SS |
365 | |
366 | if (env != NULL) | |
367 | { | |
368 | while (*env) | |
369 | { | |
370 | if (strncmp (*env, "MEMSIZE=", sizeof ("MEMSIZE=") - 1) == 0) | |
371 | { | |
372 | unsigned long top_of_memory; | |
373 | char *end_of_num; | |
374 | ||
375 | /* Set up memory limit */ | |
376 | top_of_memory = strtoul (*env + sizeof ("MEMSIZE=") - 1, | |
377 | &end_of_num, 0); | |
d4f3574e | 378 | printf_filtered ("Setting top-of-memory to 0x%lx\n", |
c906108c | 379 | top_of_memory); |
c5aa993b | 380 | |
c906108c SS |
381 | rslt = angel_RDI_info (RDIInfo_SetTopMem, &top_of_memory, &arg2); |
382 | if (rslt) | |
383 | { | |
384 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); | |
385 | } | |
386 | } | |
387 | env++; | |
388 | } | |
389 | } | |
390 | ||
391 | arg1 = (unsigned long) arg_buf; | |
c5aa993b | 392 | rslt = angel_RDI_info (RDISet_Cmdline, /* &arg1 */ (unsigned long *) arg_buf, &arg2); |
c906108c SS |
393 | if (rslt) |
394 | { | |
395 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); | |
396 | } | |
397 | ||
398 | proceed (entry_point, TARGET_SIGNAL_DEFAULT, 0); | |
399 | } | |
400 | ||
401 | /* This takes a program previously attached to and detaches it. After | |
402 | this is done, GDB can be used to debug some other program. We | |
403 | better not have left any breakpoints in the target program or it'll | |
404 | die when it hits one. */ | |
405 | ||
406 | static void | |
407 | arm_rdi_detach (args, from_tty) | |
408 | char *args; | |
409 | int from_tty; | |
410 | { | |
411 | pop_target (); | |
412 | } | |
413 | ||
414 | /* Clean up connection to a remote debugger. */ | |
415 | ||
416 | static void | |
417 | arm_rdi_close (quitting) | |
418 | int quitting; | |
419 | { | |
420 | int rslt; | |
421 | ||
c5aa993b | 422 | if (!closed_already) |
c906108c SS |
423 | { |
424 | rslt = angel_RDI_close (); | |
425 | if (rslt) | |
426 | { | |
427 | printf_filtered ("RDI_close: %s\n", rdi_error_message (rslt)); | |
428 | } | |
429 | closed_already = 1; | |
430 | inferior_pid = 0; | |
96baa820 | 431 | Adp_CloseDevice (); |
c906108c SS |
432 | } |
433 | } | |
434 | \f | |
435 | /* Tell the remote machine to resume. */ | |
436 | ||
437 | static void | |
438 | arm_rdi_resume (pid, step, siggnal) | |
439 | int pid, step; | |
440 | enum target_signal siggnal; | |
441 | { | |
442 | int rslt; | |
443 | PointHandle point; | |
444 | ||
c5aa993b | 445 | if (0 /* turn on when hardware supports single-stepping */ ) |
c906108c SS |
446 | { |
447 | rslt = angel_RDI_step (1, &point); | |
448 | if (rslt) | |
449 | { | |
450 | printf_filtered ("RDI_step: %s\n", rdi_error_message (rslt)); | |
451 | } | |
452 | } | |
453 | else | |
454 | { | |
455 | char handle[4]; | |
456 | CORE_ADDR pc; | |
457 | ||
458 | if (step) | |
459 | { | |
460 | pc = read_register (PC_REGNUM); | |
461 | pc = arm_get_next_pc (pc); | |
462 | arm_rdi_insert_breakpoint (pc, handle); | |
463 | } | |
464 | execute_status = rslt = angel_RDI_execute (&point); | |
465 | if (rslt == RDIError_BreakpointReached) | |
466 | ; | |
467 | else if (rslt) | |
468 | { | |
469 | printf_filtered ("RDI_execute: %s\n", rdi_error_message (rslt)); | |
470 | } | |
471 | if (step) | |
472 | { | |
473 | arm_rdi_remove_breakpoint (pc, handle); | |
474 | } | |
475 | } | |
476 | } | |
477 | \f | |
478 | /* Send ^C to target to halt it. Target will respond, and send us a | |
479 | packet. */ | |
480 | ||
481 | static void | |
482 | arm_rdi_interrupt (signo) | |
483 | int signo; | |
484 | { | |
485 | } | |
486 | ||
c5aa993b | 487 | static void (*ofunc) (); |
c906108c SS |
488 | |
489 | /* The user typed ^C twice. */ | |
490 | static void | |
491 | arm_rdi_interrupt_twice (signo) | |
492 | int signo; | |
493 | { | |
494 | } | |
495 | ||
496 | /* Ask the user what to do when an interrupt is received. */ | |
497 | ||
498 | static void | |
499 | interrupt_query () | |
500 | { | |
501 | } | |
502 | ||
503 | /* Wait until the remote machine stops, then return, storing status in | |
504 | STATUS just as `wait' would. Returns "pid" (though it's not clear | |
505 | what, if anything, that means in the case of this target). */ | |
506 | ||
507 | static int | |
508 | arm_rdi_wait (pid, status) | |
509 | int pid; | |
510 | struct target_waitstatus *status; | |
511 | { | |
512 | status->kind = (execute_status == RDIError_NoError ? | |
c5aa993b | 513 | TARGET_WAITKIND_EXITED : TARGET_WAITKIND_STOPPED); |
c906108c SS |
514 | |
515 | /* convert stopped code from target into right signal */ | |
516 | status->value.sig = rdi_error_signal (execute_status); | |
517 | ||
518 | return inferior_pid; | |
519 | } | |
520 | ||
521 | /* Read the remote registers into the block REGS. */ | |
522 | ||
523 | /* ARGSUSED */ | |
524 | static void | |
525 | arm_rdi_fetch_registers (regno) | |
526 | int regno; | |
527 | { | |
528 | int rslt, rdi_regmask; | |
529 | unsigned long rawreg, rawregs[32]; | |
530 | char cookedreg[4]; | |
531 | ||
c5aa993b | 532 | if (regno == -1) |
c906108c SS |
533 | { |
534 | rslt = angel_RDI_CPUread (255, 0x27fff, rawregs); | |
535 | if (rslt) | |
536 | { | |
537 | printf_filtered ("RDI_CPUread: %s\n", rdi_error_message (rslt)); | |
538 | } | |
539 | ||
540 | for (regno = 0; regno < 15; regno++) | |
541 | { | |
542 | store_unsigned_integer (cookedreg, 4, rawregs[regno]); | |
543 | supply_register (regno, (char *) cookedreg); | |
544 | } | |
545 | store_unsigned_integer (cookedreg, 4, rawregs[15]); | |
546 | supply_register (PS_REGNUM, (char *) cookedreg); | |
547 | arm_rdi_fetch_registers (PC_REGNUM); | |
548 | } | |
549 | else | |
550 | { | |
551 | if (regno == PC_REGNUM) | |
552 | rdi_regmask = RDIReg_PC; | |
553 | else if (regno == PS_REGNUM) | |
554 | rdi_regmask = RDIReg_CPSR; | |
555 | else if (regno < 0 || regno > 15) | |
556 | { | |
557 | rawreg = 0; | |
558 | supply_register (regno, (char *) &rawreg); | |
559 | return; | |
560 | } | |
561 | else | |
562 | rdi_regmask = 1 << regno; | |
563 | ||
564 | rslt = angel_RDI_CPUread (255, rdi_regmask, &rawreg); | |
565 | if (rslt) | |
566 | { | |
567 | printf_filtered ("RDI_CPUread: %s\n", rdi_error_message (rslt)); | |
568 | } | |
569 | store_unsigned_integer (cookedreg, 4, rawreg); | |
570 | supply_register (regno, (char *) cookedreg); | |
571 | } | |
572 | } | |
573 | ||
c5aa993b | 574 | static void |
c906108c SS |
575 | arm_rdi_prepare_to_store () |
576 | { | |
577 | /* Nothing to do. */ | |
578 | } | |
579 | ||
580 | /* Store register REGNO, or all registers if REGNO == -1, from the contents | |
581 | of REGISTERS. FIXME: ignores errors. */ | |
582 | ||
583 | static void | |
584 | arm_rdi_store_registers (regno) | |
585 | int regno; | |
586 | { | |
587 | int rslt, rdi_regmask; | |
588 | ||
589 | /* These need to be able to take 'floating point register' contents */ | |
590 | unsigned long rawreg[3], rawerreg[3]; | |
591 | ||
c5aa993b | 592 | if (regno == -1) |
c906108c SS |
593 | { |
594 | for (regno = 0; regno < NUM_REGS; regno++) | |
595 | arm_rdi_store_registers (regno); | |
596 | } | |
597 | else | |
598 | { | |
599 | read_register_gen (regno, (char *) rawreg); | |
600 | /* RDI manipulates data in host byte order, so convert now. */ | |
601 | store_unsigned_integer (rawerreg, 4, rawreg[0]); | |
602 | ||
603 | if (regno == PC_REGNUM) | |
604 | rdi_regmask = RDIReg_PC; | |
605 | else if (regno == PS_REGNUM) | |
606 | rdi_regmask = RDIReg_CPSR; | |
607 | else if (regno < 0 || regno > 15) | |
608 | return; | |
609 | else | |
610 | rdi_regmask = 1 << regno; | |
611 | ||
612 | rslt = angel_RDI_CPUwrite (255, rdi_regmask, rawerreg); | |
613 | if (rslt) | |
614 | { | |
615 | printf_filtered ("RDI_CPUwrite: %s\n", rdi_error_message (rslt)); | |
616 | } | |
617 | } | |
618 | } | |
619 | \f | |
620 | /* Read or write LEN bytes from inferior memory at MEMADDR, | |
621 | transferring to or from debugger address MYADDR. Write to inferior | |
622 | if SHOULD_WRITE is nonzero. Returns length of data written or | |
623 | read; 0 for error. */ | |
624 | ||
625 | /* ARGSUSED */ | |
626 | static int | |
c5aa993b | 627 | arm_rdi_xfer_memory (memaddr, myaddr, len, should_write, target) |
c906108c SS |
628 | CORE_ADDR memaddr; |
629 | char *myaddr; | |
630 | int len; | |
631 | int should_write; | |
c5aa993b | 632 | struct target_ops *target; /* ignored */ |
c906108c SS |
633 | { |
634 | int rslt, i; | |
635 | ||
636 | if (should_write) | |
637 | { | |
638 | rslt = angel_RDI_write (myaddr, memaddr, &len); | |
639 | if (rslt) | |
640 | { | |
641 | printf_filtered ("RDI_write: %s\n", rdi_error_message (rslt)); | |
642 | } | |
643 | } | |
c5aa993b | 644 | else |
c906108c SS |
645 | { |
646 | rslt = angel_RDI_read (memaddr, myaddr, &len); | |
647 | if (rslt) | |
648 | { | |
649 | printf_filtered ("RDI_read: %s\n", rdi_error_message (rslt)); | |
650 | len = 0; | |
651 | } | |
652 | } | |
653 | return len; | |
654 | } | |
655 | \f | |
656 | /* Display random info collected from the target. */ | |
657 | ||
658 | static void | |
659 | arm_rdi_files_info (ignore) | |
660 | struct target_ops *ignore; | |
661 | { | |
662 | char *file = "nothing"; | |
663 | int rslt; | |
664 | unsigned long arg1, arg2; | |
665 | ||
666 | rslt = angel_RDI_info (RDIInfo_Target, &arg1, &arg2); | |
667 | if (rslt) | |
668 | { | |
669 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); | |
670 | } | |
671 | if (arg1 & (1 << 15)) | |
672 | printf_filtered ("Target supports Thumb code.\n"); | |
673 | if (arg1 & (1 << 14)) | |
674 | printf_filtered ("Target can do profiling.\n"); | |
675 | if (arg1 & (1 << 4)) | |
676 | printf_filtered ("Target is real hardware.\n"); | |
c5aa993b | 677 | |
c906108c SS |
678 | rslt = angel_RDI_info (RDIInfo_Step, &arg1, &arg2); |
679 | if (rslt) | |
680 | { | |
681 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); | |
682 | } | |
683 | printf_filtered ("Target can%s single-step.\n", (arg1 & 0x4 ? "" : "not")); | |
684 | ||
685 | rslt = angel_RDI_info (RDIInfo_Icebreaker, &arg1, &arg2); | |
686 | if (rslt) | |
687 | { | |
688 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); | |
689 | } | |
690 | else | |
691 | printf_filtered ("Target includes an EmbeddedICE.\n"); | |
692 | } | |
693 | \f | |
694 | static void | |
695 | arm_rdi_kill () | |
696 | { | |
697 | int rslt; | |
698 | ||
699 | rslt = angel_RDI_open (1, &gdb_config, NULL, NULL); | |
700 | if (rslt) | |
701 | { | |
702 | printf_filtered ("RDI_open: %s\n", rdi_error_message (rslt)); | |
703 | } | |
704 | } | |
705 | ||
706 | static void | |
707 | arm_rdi_mourn_inferior () | |
708 | { | |
709 | unpush_target (&arm_rdi_ops); | |
710 | generic_mourn_inferior (); | |
711 | } | |
712 | \f | |
713 | /* While the RDI library keeps track of its own breakpoints, we need | |
714 | to remember "handles" so that we can delete them later. Since | |
715 | breakpoints get used for stepping, be careful not to leak memory | |
716 | here. */ | |
717 | ||
718 | static int | |
719 | arm_rdi_insert_breakpoint (addr, contents_cache) | |
720 | CORE_ADDR addr; | |
721 | char *contents_cache; | |
722 | { | |
723 | int rslt; | |
724 | PointHandle point; | |
725 | struct local_bp_list_entry *entry; | |
726 | int type = RDIPoint_EQ; | |
727 | ||
728 | if (arm_pc_is_thumb (addr) || arm_pc_is_thumb_dummy (addr)) | |
729 | type |= RDIPoint_16Bit; | |
730 | rslt = angel_RDI_setbreak (addr, type, 0, &point); | |
731 | if (rslt) | |
732 | { | |
733 | printf_filtered ("RDI_setbreak: %s\n", rdi_error_message (rslt)); | |
734 | } | |
735 | entry = | |
736 | (struct local_bp_list_entry *) xmalloc (sizeof (struct local_bp_list_entry)); | |
737 | entry->addr = addr; | |
738 | entry->point = point; | |
739 | entry->next = local_bp_list; | |
740 | local_bp_list = entry; | |
741 | return rslt; | |
742 | } | |
743 | ||
744 | static int | |
745 | arm_rdi_remove_breakpoint (addr, contents_cache) | |
746 | CORE_ADDR addr; | |
747 | char *contents_cache; | |
748 | { | |
749 | int rslt; | |
750 | PointHandle point; | |
751 | struct local_bp_list_entry *entry, *preventry; | |
752 | ||
753 | for (entry = local_bp_list; entry != NULL; entry = entry->next) | |
754 | { | |
755 | if (entry->addr == addr) | |
756 | { | |
757 | break; | |
758 | } | |
759 | preventry = entry; | |
760 | } | |
761 | if (entry) | |
762 | { | |
763 | rslt = angel_RDI_clearbreak (entry->point); | |
764 | if (rslt) | |
765 | { | |
766 | printf_filtered ("RDI_clearbreak: %s\n", rdi_error_message (rslt)); | |
767 | } | |
768 | /* Delete the breakpoint entry locally. */ | |
769 | if (entry == local_bp_list) | |
770 | { | |
771 | local_bp_list = entry->next; | |
772 | } | |
773 | else | |
774 | { | |
775 | preventry->next = entry->next; | |
776 | } | |
777 | free (entry); | |
778 | } | |
779 | return 0; | |
780 | } | |
781 | \f | |
782 | static char * | |
783 | rdi_error_message (err) | |
784 | int err; | |
785 | { | |
786 | switch (err) | |
787 | { | |
c5aa993b | 788 | case RDIError_NoError: |
c906108c SS |
789 | return "no error"; |
790 | case RDIError_Reset: | |
791 | return "debuggee reset"; | |
792 | case RDIError_UndefinedInstruction: | |
793 | return "undefined instruction"; | |
794 | case RDIError_SoftwareInterrupt: | |
795 | return "SWI trapped"; | |
796 | case RDIError_PrefetchAbort: | |
797 | return "prefetch abort, execution ran into unmapped memory?"; | |
798 | case RDIError_DataAbort: | |
799 | return "data abort, no memory at specified address?"; | |
800 | case RDIError_AddressException: | |
801 | return "address exception, access >26bit in 26bit mode"; | |
802 | case RDIError_IRQ: | |
803 | return "IRQ, interrupt trapped"; | |
804 | case RDIError_FIQ: | |
805 | return "FIQ, fast interrupt trapped"; | |
806 | case RDIError_Error: | |
807 | return "a miscellaneous type of error"; | |
808 | case RDIError_BranchThrough0: | |
809 | return "branch through location 0"; | |
810 | case RDIError_NotInitialised: | |
811 | return "internal error, RDI_open not called first"; | |
812 | case RDIError_UnableToInitialise: | |
813 | return "internal error, target world is broken"; | |
814 | case RDIError_WrongByteSex: | |
815 | return "See Operator: WrongByteSex"; | |
816 | case RDIError_UnableToTerminate: | |
817 | return "See Operator: Unable to Terminate"; | |
818 | case RDIError_BadInstruction: | |
819 | return "bad instruction, illegal to execute this instruction"; | |
820 | case RDIError_IllegalInstruction: | |
821 | return "illegal instruction, the effect of executing it is undefined"; | |
822 | case RDIError_BadCPUStateSetting: | |
823 | return "internal error, tried to set SPSR of user mode"; | |
824 | case RDIError_UnknownCoPro: | |
825 | return "unknown co-processor"; | |
826 | case RDIError_UnknownCoProState: | |
827 | return "cannot execute co-processor request"; | |
828 | case RDIError_BadCoProState: | |
829 | return "recognizably broken co-processor request"; | |
830 | case RDIError_BadPointType: | |
831 | return "internal error, bad point yype"; | |
832 | case RDIError_UnimplementedType: | |
833 | return "internal error, unimplemented type"; | |
834 | case RDIError_BadPointSize: | |
835 | return "internal error, bad point size"; | |
836 | case RDIError_UnimplementedSize: | |
837 | return "internal error, unimplemented size"; | |
838 | case RDIError_NoMorePoints: | |
839 | return "last break/watch point was used"; | |
840 | case RDIError_BreakpointReached: | |
841 | return "breakpoint reached"; | |
842 | case RDIError_WatchpointAccessed: | |
843 | return "watchpoint accessed"; | |
844 | case RDIError_NoSuchPoint: | |
845 | return "attempted to clear non-existent break/watch point"; | |
846 | case RDIError_ProgramFinishedInStep: | |
847 | return "end of the program reached while stepping"; | |
848 | case RDIError_UserInterrupt: | |
849 | return "you pressed Escape"; | |
850 | case RDIError_CantSetPoint: | |
851 | return "no more break/watch points available"; | |
852 | case RDIError_IncompatibleRDILevels: | |
853 | return "incompatible RDI levels"; | |
854 | case RDIError_LittleEndian: | |
855 | return "debuggee is little endian"; | |
856 | case RDIError_BigEndian: | |
857 | return "debuggee is big endian"; | |
858 | case RDIError_SoftInitialiseError: | |
859 | return "recoverable error in RDI initialization"; | |
860 | case RDIError_InsufficientPrivilege: | |
861 | return "internal error, supervisor state not accessible to monitor"; | |
862 | case RDIError_UnimplementedMessage: | |
863 | return "internal error, unimplemented message"; | |
864 | case RDIError_UndefinedMessage: | |
865 | return "internal error, undefined message"; | |
866 | default: | |
c5aa993b | 867 | return "undefined error message, should reset target"; |
c906108c SS |
868 | } |
869 | } | |
870 | ||
871 | /* Convert the ARM error messages to signals that GDB knows about. */ | |
872 | ||
873 | static enum target_signal | |
874 | rdi_error_signal (err) | |
875 | int err; | |
876 | { | |
877 | switch (err) | |
878 | { | |
879 | case RDIError_NoError: | |
880 | return 0; | |
881 | case RDIError_Reset: | |
c5aa993b | 882 | return TARGET_SIGNAL_TERM; /* ??? */ |
c906108c SS |
883 | case RDIError_UndefinedInstruction: |
884 | return TARGET_SIGNAL_ILL; | |
885 | case RDIError_SoftwareInterrupt: | |
886 | case RDIError_PrefetchAbort: | |
887 | case RDIError_DataAbort: | |
888 | return TARGET_SIGNAL_TRAP; | |
889 | case RDIError_AddressException: | |
890 | return TARGET_SIGNAL_SEGV; | |
891 | case RDIError_IRQ: | |
892 | case RDIError_FIQ: | |
893 | return TARGET_SIGNAL_TRAP; | |
894 | case RDIError_Error: | |
895 | return TARGET_SIGNAL_TERM; | |
896 | case RDIError_BranchThrough0: | |
897 | return TARGET_SIGNAL_TRAP; | |
898 | case RDIError_NotInitialised: | |
899 | case RDIError_UnableToInitialise: | |
900 | case RDIError_WrongByteSex: | |
901 | case RDIError_UnableToTerminate: | |
902 | return TARGET_SIGNAL_UNKNOWN; | |
903 | case RDIError_BadInstruction: | |
904 | case RDIError_IllegalInstruction: | |
905 | return TARGET_SIGNAL_ILL; | |
906 | case RDIError_BadCPUStateSetting: | |
907 | case RDIError_UnknownCoPro: | |
908 | case RDIError_UnknownCoProState: | |
909 | case RDIError_BadCoProState: | |
910 | case RDIError_BadPointType: | |
911 | case RDIError_UnimplementedType: | |
912 | case RDIError_BadPointSize: | |
913 | case RDIError_UnimplementedSize: | |
914 | case RDIError_NoMorePoints: | |
915 | return TARGET_SIGNAL_UNKNOWN; | |
916 | case RDIError_BreakpointReached: | |
917 | case RDIError_WatchpointAccessed: | |
918 | return TARGET_SIGNAL_TRAP; | |
919 | case RDIError_NoSuchPoint: | |
920 | case RDIError_ProgramFinishedInStep: | |
921 | return TARGET_SIGNAL_UNKNOWN; | |
922 | case RDIError_UserInterrupt: | |
923 | return TARGET_SIGNAL_INT; | |
924 | case RDIError_IncompatibleRDILevels: | |
925 | case RDIError_LittleEndian: | |
926 | case RDIError_BigEndian: | |
927 | case RDIError_SoftInitialiseError: | |
928 | case RDIError_InsufficientPrivilege: | |
929 | case RDIError_UnimplementedMessage: | |
930 | case RDIError_UndefinedMessage: | |
931 | default: | |
c5aa993b | 932 | return TARGET_SIGNAL_UNKNOWN; |
c906108c SS |
933 | } |
934 | } | |
935 | \f | |
936 | /* Define the target operations structure. */ | |
937 | ||
938 | static void | |
939 | init_rdi_ops () | |
940 | { | |
c5aa993b | 941 | arm_rdi_ops.to_shortname = "rdi"; |
c906108c SS |
942 | arm_rdi_ops.to_longname = "ARM RDI"; |
943 | arm_rdi_ops.to_doc = "Use a remote ARM-based computer; via the RDI library.\n\ | |
c5aa993b JM |
944 | Specify the serial device it is connected to (e.g. /dev/ttya)."; |
945 | arm_rdi_ops.to_open = arm_rdi_open; | |
946 | arm_rdi_ops.to_close = arm_rdi_close; | |
947 | arm_rdi_ops.to_detach = arm_rdi_detach; | |
948 | arm_rdi_ops.to_resume = arm_rdi_resume; | |
949 | arm_rdi_ops.to_wait = arm_rdi_wait; | |
c906108c SS |
950 | arm_rdi_ops.to_fetch_registers = arm_rdi_fetch_registers; |
951 | arm_rdi_ops.to_store_registers = arm_rdi_store_registers; | |
952 | arm_rdi_ops.to_prepare_to_store = arm_rdi_prepare_to_store; | |
953 | arm_rdi_ops.to_xfer_memory = arm_rdi_xfer_memory; | |
954 | arm_rdi_ops.to_files_info = arm_rdi_files_info; | |
955 | arm_rdi_ops.to_insert_breakpoint = arm_rdi_insert_breakpoint; | |
c5aa993b JM |
956 | arm_rdi_ops.to_remove_breakpoint = arm_rdi_remove_breakpoint; |
957 | arm_rdi_ops.to_kill = arm_rdi_kill; | |
958 | arm_rdi_ops.to_load = generic_load; | |
c906108c SS |
959 | arm_rdi_ops.to_create_inferior = arm_rdi_create_inferior; |
960 | arm_rdi_ops.to_mourn_inferior = arm_rdi_mourn_inferior; | |
961 | arm_rdi_ops.to_stratum = process_stratum; | |
c5aa993b JM |
962 | arm_rdi_ops.to_has_all_memory = 1; |
963 | arm_rdi_ops.to_has_memory = 1; | |
964 | arm_rdi_ops.to_has_stack = 1; | |
965 | arm_rdi_ops.to_has_registers = 1; | |
966 | arm_rdi_ops.to_has_execution = 1; | |
967 | arm_rdi_ops.to_magic = OPS_MAGIC; | |
c906108c SS |
968 | } |
969 | ||
970 | void | |
971 | _initialize_remote_rdi () | |
972 | { | |
c5aa993b | 973 | init_rdi_ops (); |
c906108c SS |
974 | add_target (&arm_rdi_ops); |
975 | } | |
976 | ||
977 | /* A little dummy to make linking with the library succeed. */ | |
978 | ||
c5aa993b JM |
979 | int |
980 | Fail () | |
981 | { | |
982 | return 0; | |
983 | } |