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