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