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