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