* dwarf2read.c (read_tag_const_type, read_tag_volatile_type):
[deliverable/binutils-gdb.git] / gdb / remote-rdi.c
1 /* GDB interface to ARM RDI library.
2 Copyright 1997, 1998, 2001 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,
19 Boston, MA 02111-1307, USA. */
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 "gdb_wait.h"
30 #include "gdbcmd.h"
31 #include "objfiles.h"
32 #include "gdb-stabs.h"
33 #include "gdbthread.h"
34 #include "gdbcore.h"
35 #include "breakpoint.h"
36
37 #ifdef USG
38 #include <sys/types.h>
39 #endif
40
41 #include <signal.h>
42
43 #include "rdi-share/ardi.h"
44 #include "rdi-share/adp.h"
45 #include "rdi-share/hsys.h"
46
47 extern int isascii (int);
48
49 /* Prototypes for local functions */
50
51 static void arm_rdi_files_info (struct target_ops *ignore);
52
53 static int arm_rdi_xfer_memory (CORE_ADDR memaddr, char *myaddr,
54 int len, int should_write,
55 struct mem_attrib *attrib,
56 struct target_ops *target);
57
58 static void arm_rdi_prepare_to_store (void);
59
60 static void arm_rdi_fetch_registers (int regno);
61
62 static void arm_rdi_resume (int pid, int step, enum target_signal siggnal);
63
64 static int arm_rdi_start_remote (char *dummy);
65
66 static void arm_rdi_open (char *name, int from_tty);
67
68 static void arm_rdi_create_inferior (char *exec_file, char *args, char **env);
69
70 static void arm_rdi_close (int quitting);
71
72 static void arm_rdi_store_registers (int regno);
73
74 static void arm_rdi_mourn (void);
75
76 static void arm_rdi_send (char *buf);
77
78 static int arm_rdi_wait (int pid, struct target_waitstatus *status);
79
80 static void arm_rdi_kill (void);
81
82 static void arm_rdi_detach (char *args, int from_tty);
83
84 static void arm_rdi_interrupt (int signo);
85
86 static void arm_rdi_interrupt_twice (int signo);
87
88 static void interrupt_query (void);
89
90 static int arm_rdi_insert_breakpoint (CORE_ADDR, char *);
91
92 static int arm_rdi_remove_breakpoint (CORE_ADDR, char *);
93
94 static char *rdi_error_message (int err);
95
96 static enum target_signal rdi_error_signal (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 /* Send heatbeat packets? */
111 static int rdi_heartbeat = 0;
112
113 /* Target has ROM at address 0. */
114 static int rom_at_zero = 0;
115
116 /* Enable logging? */
117 static int log_enable = 0;
118
119 /* Name of the log file. Default is "rdi.log". */
120 static char *log_filename;
121
122 /* A little list of breakpoints that have been set. */
123
124 static struct local_bp_list_entry
125 {
126 CORE_ADDR addr;
127 PointHandle point;
128 struct local_bp_list_entry *next;
129 }
130 *local_bp_list;
131 \f
132
133 /* Stub for catch_errors. */
134
135 static int
136 arm_rdi_start_remote (char *dummy)
137 {
138 return 1;
139 }
140
141 /* Helper callbacks for the "host interface" structure. RDI functions call
142 these to forward output from the target system and so forth. */
143
144 void
145 voiddummy (void *dummy)
146 {
147 fprintf_unfiltered (gdb_stdout, "void dummy\n");
148 }
149
150 static void
151 myprint (PTR arg, const char *format, va_list ap)
152 {
153 vfprintf_unfiltered (gdb_stdout, format, ap);
154 }
155
156 static void
157 mywritec (PTR arg, int c)
158 {
159 if (isascii (c))
160 fputc_unfiltered (c, gdb_stdout);
161 }
162
163 static int
164 mywrite (PTR arg, char const *buffer, int len)
165 {
166 int i;
167 char *e;
168
169 e = (char *) buffer;
170 for (i = 0; i < len; i++)
171 {
172 if (isascii ((int) *e))
173 {
174 fputc_unfiltered ((int) *e, gdb_stdout);
175 e++;
176 }
177 }
178
179 return len;
180 }
181
182 static void
183 mypause (PTR arg)
184 {
185 }
186
187 /* These last two are tricky as we have to handle the special case of
188 being interrupted more carefully */
189
190 static int
191 myreadc (PTR arg)
192 {
193 return fgetc (stdin);
194 }
195
196 static char *
197 mygets (PTR arg, char *buffer, int len)
198 {
199 return fgets (buffer, len, stdin);
200 }
201
202 /* Prevent multiple calls to angel_RDI_close(). */
203 static int closed_already = 1;
204
205 /* Open a connection to a remote debugger. NAME is the filename used
206 for communication. */
207
208 static void
209 arm_rdi_open (char *name, int from_tty)
210 {
211 int rslt, i;
212 unsigned long arg1, arg2;
213 char *openArgs = NULL;
214 char *devName = NULL;
215 char *p;
216
217 if (name == NULL)
218 error ("To open an RDI connection, you need to specify what serial\n\
219 device is attached to the remote system (e.g. /dev/ttya).");
220
221 /* split name after whitespace, pass tail as arg to open command */
222
223 devName = xstrdup (name);
224 p = strchr (devName, ' ');
225 if (p)
226 {
227 *p = '\0';
228 ++p;
229
230 while (*p == ' ')
231 ++p;
232
233 openArgs = p;
234 }
235
236 /* Make the basic low-level connection. */
237
238 arm_rdi_close (0);
239 rslt = Adp_OpenDevice (devName, openArgs, rdi_heartbeat);
240
241 if (rslt != adp_ok)
242 error ("Could not open device \"%s\"", name);
243
244 gdb_config.bytesex = 2 | (TARGET_BYTE_ORDER == BIG_ENDIAN ? 1 : 0);
245 gdb_config.fpe = 1;
246 gdb_config.rditype = 2;
247 gdb_config.heartbeat_on = 1;
248 gdb_config.flags = 2;
249
250 gdb_hostif.dbgprint = myprint;
251 gdb_hostif.dbgpause = mypause;
252 gdb_hostif.dbgarg = NULL;
253 gdb_hostif.writec = mywritec;
254 gdb_hostif.readc = myreadc;
255 gdb_hostif.write = mywrite;
256 gdb_hostif.gets = mygets;
257 gdb_hostif.hostosarg = NULL;
258 gdb_hostif.reset = voiddummy;
259
260 rslt = angel_RDI_open (10, &gdb_config, &gdb_hostif, NULL);
261 if (rslt == RDIError_BigEndian || rslt == RDIError_LittleEndian)
262 ; /* do nothing, this is the expected return */
263 else if (rslt)
264 {
265 printf_filtered ("RDI_open: %s\n", rdi_error_message (rslt));
266 Adp_CloseDevice ();
267 error ("RDI_open failed\n");
268 }
269
270 rslt = angel_RDI_info (RDIInfo_Target, &arg1, &arg2);
271 if (rslt)
272 {
273 printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
274 }
275 rslt = angel_RDI_info (RDIInfo_Points, &arg1, &arg2);
276 if (rslt)
277 {
278 printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
279 }
280 rslt = angel_RDI_info (RDIInfo_Step, &arg1, &arg2);
281 if (rslt)
282 {
283 printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
284 }
285 rslt = angel_RDI_info (RDIInfo_CoPro, &arg1, &arg2);
286 if (rslt)
287 {
288 printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
289 }
290 rslt = angel_RDI_info (RDIInfo_SemiHosting, &arg1, &arg2);
291 if (rslt)
292 {
293 printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
294 }
295
296 rslt = angel_RDI_info (RDIInfo_GetLoadSize, &arg1, &arg2);
297 if (rslt)
298 {
299 printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
300 }
301 max_load_size = arg1;
302
303 push_target (&arm_rdi_ops);
304
305 target_fetch_registers (-1);
306
307 rslt = angel_RDI_open (1, &gdb_config, NULL, NULL);
308 if (rslt)
309 {
310 printf_filtered ("RDI_open: %s\n", rdi_error_message (rslt));
311 }
312
313 arg1 = rom_at_zero ? 0x0 : 0x13b;
314
315 rslt = angel_RDI_info (RDIVector_Catch, &arg1, &arg2);
316 if (rslt)
317 {
318 printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
319 }
320
321 arg1 = (unsigned long) "";
322 rslt = angel_RDI_info (RDISet_Cmdline, &arg1, &arg2);
323 if (rslt)
324 {
325 printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
326 }
327
328 /* Clear out any existing records of breakpoints. */
329 {
330 struct local_bp_list_entry *entry, *preventry = NULL;
331
332 for (entry = local_bp_list; entry != NULL; entry = entry->next)
333 {
334 if (preventry)
335 xfree (preventry);
336 }
337 }
338
339 printf_filtered ("Connected to ARM RDI target.\n");
340 closed_already = 0;
341 inferior_pid = 42;
342 }
343
344 /* Start an inferior process and set inferior_pid to its pid.
345 EXEC_FILE is the file to run.
346 ARGS is a string containing the arguments to the program.
347 ENV is the environment vector to pass. Errors reported with error().
348 On VxWorks and various standalone systems, we ignore exec_file. */
349 /* This is called not only when we first attach, but also when the
350 user types "run" after having attached. */
351
352 static void
353 arm_rdi_create_inferior (char *exec_file, char *args, char **env)
354 {
355 int len, rslt;
356 unsigned long arg1, arg2;
357 char *arg_buf;
358 CORE_ADDR entry_point;
359
360 if (exec_file == 0 || exec_bfd == 0)
361 error ("No executable file specified.");
362
363 entry_point = (CORE_ADDR) bfd_get_start_address (exec_bfd);
364
365 arm_rdi_kill ();
366 remove_breakpoints ();
367 init_wait_for_inferior ();
368
369 len = strlen (exec_file) + 1 + strlen (args) + 1 + /*slop */ 10;
370 arg_buf = (char *) alloca (len);
371 arg_buf[0] = '\0';
372 strcat (arg_buf, exec_file);
373 strcat (arg_buf, " ");
374 strcat (arg_buf, args);
375
376 inferior_pid = 42;
377 insert_breakpoints (); /* Needed to get correct instruction in cache */
378
379 if (env != NULL)
380 {
381 while (*env)
382 {
383 if (strncmp (*env, "MEMSIZE=", sizeof ("MEMSIZE=") - 1) == 0)
384 {
385 unsigned long top_of_memory;
386 char *end_of_num;
387
388 /* Set up memory limit */
389 top_of_memory = strtoul (*env + sizeof ("MEMSIZE=") - 1,
390 &end_of_num, 0);
391 printf_filtered ("Setting top-of-memory to 0x%lx\n",
392 top_of_memory);
393
394 rslt = angel_RDI_info (RDIInfo_SetTopMem, &top_of_memory, &arg2);
395 if (rslt)
396 {
397 printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
398 }
399 }
400 env++;
401 }
402 }
403
404 arg1 = (unsigned long) arg_buf;
405 rslt = angel_RDI_info (RDISet_Cmdline, /* &arg1 */ (unsigned long *) arg_buf, &arg2);
406 if (rslt)
407 {
408 printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
409 }
410
411 proceed (entry_point, TARGET_SIGNAL_DEFAULT, 0);
412 }
413
414 /* This takes a program previously attached to and detaches it. After
415 this is done, GDB can be used to debug some other program. We
416 better not have left any breakpoints in the target program or it'll
417 die when it hits one. */
418
419 static void
420 arm_rdi_detach (char *args, int from_tty)
421 {
422 pop_target ();
423 }
424
425 /* Clean up connection to a remote debugger. */
426
427 static void
428 arm_rdi_close (int quitting)
429 {
430 int rslt;
431
432 if (!closed_already)
433 {
434 rslt = angel_RDI_close ();
435 if (rslt)
436 {
437 printf_filtered ("RDI_close: %s\n", rdi_error_message (rslt));
438 }
439 closed_already = 1;
440 inferior_pid = 0;
441 Adp_CloseDevice ();
442 generic_mourn_inferior ();
443 }
444 }
445 \f
446 /* Tell the remote machine to resume. */
447
448 static void
449 arm_rdi_resume (int pid, int step, enum target_signal siggnal)
450 {
451 int rslt;
452 PointHandle point;
453
454 if (0 /* turn on when hardware supports single-stepping */ )
455 {
456 rslt = angel_RDI_step (1, &point);
457 if (rslt)
458 {
459 printf_filtered ("RDI_step: %s\n", rdi_error_message (rslt));
460 }
461 }
462 else
463 {
464 char handle[4];
465 CORE_ADDR pc;
466
467 if (step)
468 {
469 pc = read_register (PC_REGNUM);
470 pc = arm_get_next_pc (pc);
471 arm_rdi_insert_breakpoint (pc, handle);
472 }
473 execute_status = rslt = angel_RDI_execute (&point);
474 if (rslt == RDIError_BreakpointReached)
475 ;
476 else if (rslt)
477 {
478 printf_filtered ("RDI_execute: %s\n", rdi_error_message (rslt));
479 }
480 if (step)
481 {
482 arm_rdi_remove_breakpoint (pc, handle);
483 }
484 }
485 }
486 \f
487 /* Send ^C to target to halt it. Target will respond, and send us a
488 packet. */
489
490 static void
491 arm_rdi_interrupt (int signo)
492 {
493 }
494
495 static void (*ofunc) ();
496
497 /* The user typed ^C twice. */
498 static void
499 arm_rdi_interrupt_twice (int signo)
500 {
501 }
502
503 /* Ask the user what to do when an interrupt is received. */
504
505 static void
506 interrupt_query (void)
507 {
508 }
509
510 /* Wait until the remote machine stops, then return, storing status in
511 STATUS just as `wait' would. Returns "pid" (though it's not clear
512 what, if anything, that means in the case of this target). */
513
514 static int
515 arm_rdi_wait (int pid, struct target_waitstatus *status)
516 {
517 status->kind = (execute_status == RDIError_NoError ?
518 TARGET_WAITKIND_EXITED : TARGET_WAITKIND_STOPPED);
519
520 /* convert stopped code from target into right signal */
521 status->value.sig = rdi_error_signal (execute_status);
522
523 return inferior_pid;
524 }
525
526 /* Read the remote registers into the block REGS. */
527
528 /* ARGSUSED */
529 static void
530 arm_rdi_fetch_registers (int regno)
531 {
532 int rslt, rdi_regmask;
533 unsigned long rawreg, rawregs[32];
534 char cookedreg[4];
535
536 if (regno == -1)
537 {
538 rslt = angel_RDI_CPUread (255, 0x27fff, rawregs);
539 if (rslt)
540 {
541 printf_filtered ("RDI_CPUread: %s\n", rdi_error_message (rslt));
542 }
543
544 for (regno = 0; regno < 15; regno++)
545 {
546 store_unsigned_integer (cookedreg, 4, rawregs[regno]);
547 supply_register (regno, (char *) cookedreg);
548 }
549 store_unsigned_integer (cookedreg, 4, rawregs[15]);
550 supply_register (PS_REGNUM, (char *) cookedreg);
551 arm_rdi_fetch_registers (PC_REGNUM);
552 }
553 else
554 {
555 if (regno == PC_REGNUM)
556 rdi_regmask = RDIReg_PC;
557 else if (regno == PS_REGNUM)
558 rdi_regmask = RDIReg_CPSR;
559 else if (regno < 0 || regno > 15)
560 {
561 rawreg = 0;
562 supply_register (regno, (char *) &rawreg);
563 return;
564 }
565 else
566 rdi_regmask = 1 << regno;
567
568 rslt = angel_RDI_CPUread (255, rdi_regmask, &rawreg);
569 if (rslt)
570 {
571 printf_filtered ("RDI_CPUread: %s\n", rdi_error_message (rslt));
572 }
573 store_unsigned_integer (cookedreg, 4, rawreg);
574 supply_register (regno, (char *) cookedreg);
575 }
576 }
577
578 static void
579 arm_rdi_prepare_to_store (void)
580 {
581 /* Nothing to do. */
582 }
583
584 /* Store register REGNO, or all registers if REGNO == -1, from the contents
585 of REGISTERS. FIXME: ignores errors. */
586
587 static void
588 arm_rdi_store_registers (int regno)
589 {
590 int rslt, rdi_regmask;
591
592 /* These need to be able to take 'floating point register' contents */
593 unsigned long rawreg[3], rawerreg[3];
594
595 if (regno == -1)
596 {
597 for (regno = 0; regno < NUM_REGS; regno++)
598 arm_rdi_store_registers (regno);
599 }
600 else
601 {
602 read_register_gen (regno, (char *) rawreg);
603 /* RDI manipulates data in host byte order, so convert now. */
604 store_unsigned_integer (rawerreg, 4, rawreg[0]);
605
606 if (regno == PC_REGNUM)
607 rdi_regmask = RDIReg_PC;
608 else if (regno == PS_REGNUM)
609 rdi_regmask = RDIReg_CPSR;
610 else if (regno < 0 || regno > 15)
611 return;
612 else
613 rdi_regmask = 1 << regno;
614
615 rslt = angel_RDI_CPUwrite (255, rdi_regmask, rawerreg);
616 if (rslt)
617 {
618 printf_filtered ("RDI_CPUwrite: %s\n", rdi_error_message (rslt));
619 }
620 }
621 }
622 \f
623 /* Read or write LEN bytes from inferior memory at MEMADDR,
624 transferring to or from debugger address MYADDR. Write to inferior
625 if SHOULD_WRITE is nonzero. Returns length of data written or
626 read; 0 for error. TARGET is unused. */
627
628 /* ARGSUSED */
629 static int
630 arm_rdi_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int should_write,
631 struct mem_attrib *attrib ATTRIBUTE_UNUSED,
632 struct target_ops *target ATTRIBUTE_UNUSED)
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 }
644 else
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 (struct target_ops *ignore)
660 {
661 char *file = "nothing";
662 int rslt;
663 unsigned long arg1, arg2;
664
665 rslt = angel_RDI_info (RDIInfo_Target, &arg1, &arg2);
666 if (rslt)
667 {
668 printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
669 }
670 if (arg1 & (1 << 15))
671 printf_filtered ("Target supports Thumb code.\n");
672 if (arg1 & (1 << 14))
673 printf_filtered ("Target can do profiling.\n");
674 if (arg1 & (1 << 4))
675 printf_filtered ("Target is real hardware.\n");
676
677 rslt = angel_RDI_info (RDIInfo_Step, &arg1, &arg2);
678 if (rslt)
679 {
680 printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
681 }
682 printf_filtered ("Target can%s single-step.\n", (arg1 & 0x4 ? "" : "not"));
683
684 rslt = angel_RDI_info (RDIInfo_Icebreaker, &arg1, &arg2);
685 if (rslt)
686 {
687 printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
688 }
689 else
690 printf_filtered ("Target includes an EmbeddedICE.\n");
691 }
692 \f
693 static void
694 arm_rdi_kill (void)
695 {
696 int rslt;
697
698 rslt = angel_RDI_open (1, &gdb_config, NULL, NULL);
699 if (rslt)
700 {
701 printf_filtered ("RDI_open: %s\n", rdi_error_message (rslt));
702 }
703 }
704
705 static void
706 arm_rdi_mourn_inferior (void)
707 {
708 /* We remove the inserted breakpoints in case the user wants to
709 issue another target and load commands to rerun his application;
710 This is something that wouldn't work on a native target, for instance,
711 as the process goes away when the inferior exits, but it works with
712 some remote targets like this one. That is why this is done here. */
713 remove_breakpoints();
714 unpush_target (&arm_rdi_ops);
715 generic_mourn_inferior ();
716 }
717 \f
718 /* While the RDI library keeps track of its own breakpoints, we need
719 to remember "handles" so that we can delete them later. Since
720 breakpoints get used for stepping, be careful not to leak memory
721 here. */
722
723 static int
724 arm_rdi_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
725 {
726 int rslt;
727 PointHandle point;
728 struct local_bp_list_entry *entry;
729 int type = RDIPoint_EQ;
730
731 if (arm_pc_is_thumb (addr) || arm_pc_is_thumb_dummy (addr))
732 type |= RDIPoint_16Bit;
733 rslt = angel_RDI_setbreak (addr, type, 0, &point);
734 if (rslt)
735 {
736 printf_filtered ("RDI_setbreak: %s\n", rdi_error_message (rslt));
737 }
738 entry =
739 (struct local_bp_list_entry *) xmalloc (sizeof (struct local_bp_list_entry));
740 entry->addr = addr;
741 entry->point = point;
742 entry->next = local_bp_list;
743 local_bp_list = entry;
744 return rslt;
745 }
746
747 static int
748 arm_rdi_remove_breakpoint (CORE_ADDR addr, char *contents_cache)
749 {
750 int rslt;
751 PointHandle point;
752 struct local_bp_list_entry *entry, *preventry;
753
754 for (entry = local_bp_list; entry != NULL; entry = entry->next)
755 {
756 if (entry->addr == addr)
757 {
758 break;
759 }
760 preventry = entry;
761 }
762 if (entry)
763 {
764 rslt = angel_RDI_clearbreak (entry->point);
765 if (rslt)
766 {
767 printf_filtered ("RDI_clearbreak: %s\n", rdi_error_message (rslt));
768 }
769 /* Delete the breakpoint entry locally. */
770 if (entry == local_bp_list)
771 {
772 local_bp_list = entry->next;
773 }
774 else
775 {
776 preventry->next = entry->next;
777 }
778 xfree (entry);
779 }
780 return 0;
781 }
782 \f
783 static char *
784 rdi_error_message (int err)
785 {
786 switch (err)
787 {
788 case RDIError_NoError:
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:
867 return "undefined error message, should reset target";
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 (int err)
875 {
876 switch (err)
877 {
878 case RDIError_NoError:
879 return 0;
880 case RDIError_Reset:
881 return TARGET_SIGNAL_TERM; /* ??? */
882 case RDIError_UndefinedInstruction:
883 return TARGET_SIGNAL_ILL;
884 case RDIError_SoftwareInterrupt:
885 case RDIError_PrefetchAbort:
886 case RDIError_DataAbort:
887 return TARGET_SIGNAL_TRAP;
888 case RDIError_AddressException:
889 return TARGET_SIGNAL_SEGV;
890 case RDIError_IRQ:
891 case RDIError_FIQ:
892 return TARGET_SIGNAL_TRAP;
893 case RDIError_Error:
894 return TARGET_SIGNAL_TERM;
895 case RDIError_BranchThrough0:
896 return TARGET_SIGNAL_TRAP;
897 case RDIError_NotInitialised:
898 case RDIError_UnableToInitialise:
899 case RDIError_WrongByteSex:
900 case RDIError_UnableToTerminate:
901 return TARGET_SIGNAL_UNKNOWN;
902 case RDIError_BadInstruction:
903 case RDIError_IllegalInstruction:
904 return TARGET_SIGNAL_ILL;
905 case RDIError_BadCPUStateSetting:
906 case RDIError_UnknownCoPro:
907 case RDIError_UnknownCoProState:
908 case RDIError_BadCoProState:
909 case RDIError_BadPointType:
910 case RDIError_UnimplementedType:
911 case RDIError_BadPointSize:
912 case RDIError_UnimplementedSize:
913 case RDIError_NoMorePoints:
914 return TARGET_SIGNAL_UNKNOWN;
915 case RDIError_BreakpointReached:
916 case RDIError_WatchpointAccessed:
917 return TARGET_SIGNAL_TRAP;
918 case RDIError_NoSuchPoint:
919 case RDIError_ProgramFinishedInStep:
920 return TARGET_SIGNAL_UNKNOWN;
921 case RDIError_UserInterrupt:
922 return TARGET_SIGNAL_INT;
923 case RDIError_IncompatibleRDILevels:
924 case RDIError_LittleEndian:
925 case RDIError_BigEndian:
926 case RDIError_SoftInitialiseError:
927 case RDIError_InsufficientPrivilege:
928 case RDIError_UnimplementedMessage:
929 case RDIError_UndefinedMessage:
930 default:
931 return TARGET_SIGNAL_UNKNOWN;
932 }
933 }
934
935 static void
936 arm_rdi_stop(void)
937 {
938 angel_RDI_stop_request();
939 }
940
941 \f
942 /* Define the target operations structure. */
943
944 static void
945 init_rdi_ops (void)
946 {
947 arm_rdi_ops.to_shortname = "rdi";
948 arm_rdi_ops.to_longname = "ARM RDI";
949 arm_rdi_ops.to_doc = "Use a remote ARM-based computer; via the RDI library.\n\
950 Specify the serial device it is connected to (e.g. /dev/ttya).";
951 arm_rdi_ops.to_open = arm_rdi_open;
952 arm_rdi_ops.to_close = arm_rdi_close;
953 arm_rdi_ops.to_detach = arm_rdi_detach;
954 arm_rdi_ops.to_resume = arm_rdi_resume;
955 arm_rdi_ops.to_wait = arm_rdi_wait;
956 arm_rdi_ops.to_stop = arm_rdi_stop;
957 arm_rdi_ops.to_fetch_registers = arm_rdi_fetch_registers;
958 arm_rdi_ops.to_store_registers = arm_rdi_store_registers;
959 arm_rdi_ops.to_prepare_to_store = arm_rdi_prepare_to_store;
960 arm_rdi_ops.to_xfer_memory = arm_rdi_xfer_memory;
961 arm_rdi_ops.to_files_info = arm_rdi_files_info;
962 arm_rdi_ops.to_insert_breakpoint = arm_rdi_insert_breakpoint;
963 arm_rdi_ops.to_remove_breakpoint = arm_rdi_remove_breakpoint;
964 arm_rdi_ops.to_kill = arm_rdi_kill;
965 arm_rdi_ops.to_load = generic_load;
966 arm_rdi_ops.to_create_inferior = arm_rdi_create_inferior;
967 arm_rdi_ops.to_mourn_inferior = arm_rdi_mourn_inferior;
968 arm_rdi_ops.to_stratum = process_stratum;
969 arm_rdi_ops.to_has_all_memory = 1;
970 arm_rdi_ops.to_has_memory = 1;
971 arm_rdi_ops.to_has_stack = 1;
972 arm_rdi_ops.to_has_registers = 1;
973 arm_rdi_ops.to_has_execution = 1;
974 arm_rdi_ops.to_magic = OPS_MAGIC;
975 }
976
977 static void
978 rdilogfile_command (char *arg, int from_tty)
979 {
980 if (!arg || strlen (arg) == 0)
981 {
982 printf_filtered ("rdi log file is '%s'\n", log_filename);
983 return;
984 }
985
986 if (log_filename)
987 xfree (log_filename);
988
989 log_filename = xstrdup (arg);
990
991 Adp_SetLogfile (log_filename);
992 }
993
994 static void
995 rdilogenable_command (char *args, int from_tty)
996 {
997 if (!args || strlen (args) == 0)
998 {
999 printf_filtered ("rdi log is %s\n", log_enable ? "enabled" : "disabled");
1000 return;
1001 }
1002
1003 if (!strcasecmp (args, "1") ||
1004 !strcasecmp (args, "y") ||
1005 !strcasecmp (args, "yes") ||
1006 !strcasecmp (args, "on") ||
1007 !strcasecmp (args, "t") ||
1008 !strcasecmp (args, "true"))
1009 Adp_SetLogEnable (log_enable = 1);
1010 else if (!strcasecmp (args, "0") ||
1011 !strcasecmp (args, "n") ||
1012 !strcasecmp (args, "no") ||
1013 !strcasecmp (args, "off") ||
1014 !strcasecmp (args, "f") ||
1015 !strcasecmp (args, "false"))
1016 Adp_SetLogEnable (log_enable = 0);
1017 else
1018 printf_filtered ("rdilogenable: unrecognized argument '%s'\n"
1019 " try y or n\n", args);
1020 }
1021
1022 void
1023 _initialize_remote_rdi (void)
1024 {
1025 init_rdi_ops ();
1026 add_target (&arm_rdi_ops);
1027
1028 log_filename = xstrdup ("rdi.log");
1029 Adp_SetLogfile (log_filename);
1030 Adp_SetLogEnable (log_enable);
1031
1032 add_cmd ("rdilogfile", class_maintenance,
1033 rdilogfile_command,
1034 "Set filename for ADP packet log.\n\
1035 This file is used to log Angel Debugger Protocol packets.\n\
1036 With a single argument, sets the logfile name to that value.\n\
1037 Without an argument, shows the current logfile name.\n\
1038 See also: rdilogenable\n",
1039 &maintenancelist);
1040
1041 add_cmd ("rdilogenable", class_maintenance,
1042 rdilogenable_command,
1043 "Set enable logging of ADP packets.\n\
1044 This will log ADP packets exchanged between gdb and the\n\
1045 rdi target device.\n\
1046 An argument of 1,t,true,y,yes will enable.\n\
1047 An argument of 0,f,false,n,no will disabled.\n\
1048 Withough an argument, it will display current state.\n",
1049 &maintenancelist);
1050
1051 add_show_from_set
1052 (add_set_cmd ("rdiromatzero", no_class,
1053 var_boolean, (char *) &rom_at_zero,
1054 "Set target has ROM at addr 0.\n\
1055 A true value disables vector catching, false enables vector catching.\n\
1056 This is evaluated at the time the 'target rdi' command is executed\n",
1057 &setlist),
1058 &showlist);
1059
1060 add_show_from_set
1061 (add_set_cmd ("rdiheartbeat", no_class,
1062 var_boolean, (char *) &rdi_heartbeat,
1063 "Set enable for ADP heartbeat packets.\n\
1064 I don't know why you would want this. If you enable them,\n\
1065 it will confuse ARM and EPI JTAG interface boxes as well\n\
1066 as the Angel Monitor.\n",
1067 &setlist),
1068 &showlist);
1069 }
1070
1071 /* A little dummy to make linking with the library succeed. */
1072
1073 int
1074 Fail (void)
1075 {
1076 return 0;
1077 }
This page took 0.063484 seconds and 4 git commands to generate.