Add Rust support to source highlighting
[external/binutils.git] / gdb / cris-tdep.c
1 /* Target dependent code for CRIS, for GDB, the GNU debugger.
2
3    Copyright (C) 2001-2019 Free Software Foundation, Inc.
4
5    Contributed by Axis Communications AB.
6    Written by Hendrik Ruijter, Stefan Andersson, and Orjan Friberg.
7
8    This file is part of GDB.
9
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 3 of the License, or
13    (at your option) any later version.
14
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
22
23 #include "defs.h"
24 #include "frame.h"
25 #include "frame-unwind.h"
26 #include "frame-base.h"
27 #include "trad-frame.h"
28 #include "dwarf2-frame.h"
29 #include "symtab.h"
30 #include "inferior.h"
31 #include "gdbtypes.h"
32 #include "gdbcore.h"
33 #include "gdbcmd.h"
34 #include "target.h"
35 #include "value.h"
36 #include "opcode/cris.h"
37 #include "osabi.h"
38 #include "arch-utils.h"
39 #include "regcache.h"
40
41 #include "objfiles.h"
42
43 #include "solib.h"              /* Support for shared libraries.  */
44 #include "solib-svr4.h"
45 #include "dis-asm.h"
46
47 #include "cris-tdep.h"
48
49 enum cris_num_regs
50 {
51   /* There are no floating point registers.  Used in gdbserver low-linux.c.  */
52   NUM_FREGS = 0,
53   
54   /* There are 16 general registers.  */
55   NUM_GENREGS = 16,
56   
57   /* There are 16 special registers.  */
58   NUM_SPECREGS = 16,
59
60   /* CRISv32 has a pseudo PC register, not noted here.  */
61   
62   /* CRISv32 has 16 support registers.  */
63   NUM_SUPPREGS = 16
64 };
65
66 /* Register numbers of various important registers.
67    CRIS_FP_REGNUM   Contains address of executing stack frame.
68    STR_REGNUM  Contains the address of structure return values.
69    RET_REGNUM  Contains the return value when shorter than or equal to 32 bits
70    ARG1_REGNUM Contains the first parameter to a function.
71    ARG2_REGNUM Contains the second parameter to a function.
72    ARG3_REGNUM Contains the third parameter to a function.
73    ARG4_REGNUM Contains the fourth parameter to a function.  Rest on stack.
74    gdbarch_sp_regnum Contains address of top of stack.
75    gdbarch_pc_regnum Contains address of next instruction.
76    SRP_REGNUM  Subroutine return pointer register.
77    BRP_REGNUM  Breakpoint return pointer register.  */
78
79 enum cris_regnums
80 {
81   /* Enums with respect to the general registers, valid for all 
82      CRIS versions.  The frame pointer is always in R8.  */
83   CRIS_FP_REGNUM = 8,
84   /* ABI related registers.  */
85   STR_REGNUM  = 9,
86   RET_REGNUM  = 10,
87   ARG1_REGNUM = 10,
88   ARG2_REGNUM = 11,
89   ARG3_REGNUM = 12,
90   ARG4_REGNUM = 13,
91   
92   /* Registers which happen to be common.  */
93   VR_REGNUM   = 17,
94   MOF_REGNUM  = 23,
95   SRP_REGNUM  = 27,
96
97   /* CRISv10 et al. specific registers.  */
98   P0_REGNUM   = 16,
99   P4_REGNUM   = 20,
100   CCR_REGNUM  = 21,
101   P8_REGNUM   = 24,
102   IBR_REGNUM  = 25,
103   IRP_REGNUM  = 26,
104   BAR_REGNUM  = 28,
105   DCCR_REGNUM = 29,
106   BRP_REGNUM  = 30,
107   USP_REGNUM  = 31,
108
109   /* CRISv32 specific registers.  */
110   ACR_REGNUM  = 15,
111   BZ_REGNUM   = 16,
112   PID_REGNUM  = 18,
113   SRS_REGNUM  = 19,
114   WZ_REGNUM   = 20,
115   EXS_REGNUM  = 21,
116   EDA_REGNUM  = 22,
117   DZ_REGNUM   = 24,
118   EBP_REGNUM  = 25,
119   ERP_REGNUM  = 26,
120   NRP_REGNUM  = 28,
121   CCS_REGNUM  = 29,
122   CRISV32USP_REGNUM  = 30, /* Shares name but not number with CRISv10.  */
123   SPC_REGNUM  = 31,
124   CRISV32PC_REGNUM   = 32, /* Shares name but not number with CRISv10.  */
125
126   S0_REGNUM = 33,
127   S1_REGNUM = 34,
128   S2_REGNUM = 35,
129   S3_REGNUM = 36,
130   S4_REGNUM = 37,
131   S5_REGNUM = 38,
132   S6_REGNUM = 39,
133   S7_REGNUM = 40,
134   S8_REGNUM = 41,
135   S9_REGNUM = 42,
136   S10_REGNUM = 43,
137   S11_REGNUM = 44,
138   S12_REGNUM = 45,
139   S13_REGNUM = 46,
140   S14_REGNUM = 47,
141   S15_REGNUM = 48,
142 };
143
144 extern const struct cris_spec_reg cris_spec_regs[];
145
146 /* CRIS version, set via the user command 'set cris-version'.  Affects
147    register names and sizes.  */
148 static unsigned int usr_cmd_cris_version;
149
150 /* Indicates whether to trust the above variable.  */
151 static int usr_cmd_cris_version_valid = 0;
152
153 static const char cris_mode_normal[] = "normal";
154 static const char cris_mode_guru[] = "guru";
155 static const char *const cris_modes[] = {
156   cris_mode_normal,
157   cris_mode_guru,
158   0
159 };
160
161 /* CRIS mode, set via the user command 'set cris-mode'.  Affects
162    type of break instruction among other things.  */
163 static const char *usr_cmd_cris_mode = cris_mode_normal;
164
165 /* Whether to make use of Dwarf-2 CFI (default on).  */
166 static int usr_cmd_cris_dwarf2_cfi = 1;
167
168 /* Sigtramp identification code copied from i386-linux-tdep.c.  */
169
170 #define SIGTRAMP_INSN0    0x9c5f  /* movu.w 0xXX, $r9 */
171 #define SIGTRAMP_OFFSET0  0
172 #define SIGTRAMP_INSN1    0xe93d  /* break 13 */
173 #define SIGTRAMP_OFFSET1  4
174
175 static const unsigned short sigtramp_code[] =
176 {
177   SIGTRAMP_INSN0, 0x0077,  /* movu.w $0x77, $r9 */
178   SIGTRAMP_INSN1           /* break 13 */
179 };
180
181 #define SIGTRAMP_LEN (sizeof sigtramp_code)
182
183 /* Note: same length as normal sigtramp code.  */
184
185 static const unsigned short rt_sigtramp_code[] =
186 {
187   SIGTRAMP_INSN0, 0x00ad,  /* movu.w $0xad, $r9 */
188   SIGTRAMP_INSN1           /* break 13 */
189 };
190
191 /* If PC is in a sigtramp routine, return the address of the start of
192    the routine.  Otherwise, return 0.  */
193
194 static CORE_ADDR
195 cris_sigtramp_start (struct frame_info *this_frame)
196 {
197   CORE_ADDR pc = get_frame_pc (this_frame);
198   gdb_byte buf[SIGTRAMP_LEN];
199
200   if (!safe_frame_unwind_memory (this_frame, pc, buf, SIGTRAMP_LEN))
201     return 0;
202
203   if (((buf[1] << 8) + buf[0]) != SIGTRAMP_INSN0)
204     {
205       if (((buf[1] << 8) + buf[0]) != SIGTRAMP_INSN1)
206         return 0;
207
208       pc -= SIGTRAMP_OFFSET1;
209       if (!safe_frame_unwind_memory (this_frame, pc, buf, SIGTRAMP_LEN))
210         return 0;
211     }
212
213   if (memcmp (buf, sigtramp_code, SIGTRAMP_LEN) != 0)
214     return 0;
215
216   return pc;
217 }
218
219 /* If PC is in a RT sigtramp routine, return the address of the start of
220    the routine.  Otherwise, return 0.  */
221
222 static CORE_ADDR
223 cris_rt_sigtramp_start (struct frame_info *this_frame)
224 {
225   CORE_ADDR pc = get_frame_pc (this_frame);
226   gdb_byte buf[SIGTRAMP_LEN];
227
228   if (!safe_frame_unwind_memory (this_frame, pc, buf, SIGTRAMP_LEN))
229     return 0;
230
231   if (((buf[1] << 8) + buf[0]) != SIGTRAMP_INSN0)
232     {
233       if (((buf[1] << 8) + buf[0]) != SIGTRAMP_INSN1)
234         return 0;
235
236       pc -= SIGTRAMP_OFFSET1;
237       if (!safe_frame_unwind_memory (this_frame, pc, buf, SIGTRAMP_LEN))
238         return 0;
239     }
240
241   if (memcmp (buf, rt_sigtramp_code, SIGTRAMP_LEN) != 0)
242     return 0;
243
244   return pc;
245 }
246
247 /* Assuming THIS_FRAME is a frame for a GNU/Linux sigtramp routine,
248    return the address of the associated sigcontext structure.  */
249
250 static CORE_ADDR
251 cris_sigcontext_addr (struct frame_info *this_frame)
252 {
253   struct gdbarch *gdbarch = get_frame_arch (this_frame);
254   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
255   CORE_ADDR pc;
256   CORE_ADDR sp;
257   gdb_byte buf[4];
258
259   get_frame_register (this_frame, gdbarch_sp_regnum (gdbarch), buf);
260   sp = extract_unsigned_integer (buf, 4, byte_order);
261
262   /* Look for normal sigtramp frame first.  */
263   pc = cris_sigtramp_start (this_frame);
264   if (pc)
265     {
266       /* struct signal_frame (arch/cris/kernel/signal.c) contains
267          struct sigcontext as its first member, meaning the SP points to
268          it already.  */
269       return sp;
270     }
271
272   pc = cris_rt_sigtramp_start (this_frame);
273   if (pc)
274     {
275       /* struct rt_signal_frame (arch/cris/kernel/signal.c) contains
276          a struct ucontext, which in turn contains a struct sigcontext.
277          Magic digging:
278          4 + 4 + 128 to struct ucontext, then
279          4 + 4 + 12 to struct sigcontext.  */
280       return (sp + 156);
281     }
282
283   error (_("Couldn't recognize signal trampoline."));
284   return 0;
285 }
286
287 struct cris_unwind_cache
288 {
289   /* The previous frame's inner most stack address.  Used as this
290      frame ID's stack_addr.  */
291   CORE_ADDR prev_sp;
292   /* The frame's base, optionally used by the high-level debug info.  */
293   CORE_ADDR base;
294   int size;
295   /* How far the SP and r8 (FP) have been offset from the start of
296      the stack frame (as defined by the previous frame's stack
297      pointer).  */
298   LONGEST sp_offset;
299   LONGEST r8_offset;
300   int uses_frame;
301
302   /* From old frame_extra_info struct.  */
303   CORE_ADDR return_pc;
304   int leaf_function;
305
306   /* Table indicating the location of each and every register.  */
307   struct trad_frame_saved_reg *saved_regs;
308 };
309
310 static struct cris_unwind_cache *
311 cris_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
312                                   void **this_cache)
313 {
314   struct gdbarch *gdbarch = get_frame_arch (this_frame);
315   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
316   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
317   struct cris_unwind_cache *info;
318   CORE_ADDR addr;
319   gdb_byte buf[4];
320   int i;
321
322   if ((*this_cache))
323     return (struct cris_unwind_cache *) (*this_cache);
324
325   info = FRAME_OBSTACK_ZALLOC (struct cris_unwind_cache);
326   (*this_cache) = info;
327   info->saved_regs = trad_frame_alloc_saved_regs (this_frame);
328
329   /* Zero all fields.  */
330   info->prev_sp = 0;
331   info->base = 0;
332   info->size = 0;
333   info->sp_offset = 0;
334   info->r8_offset = 0;
335   info->uses_frame = 0;
336   info->return_pc = 0;
337   info->leaf_function = 0;
338
339   get_frame_register (this_frame, gdbarch_sp_regnum (gdbarch), buf);
340   info->base = extract_unsigned_integer (buf, 4, byte_order);
341
342   addr = cris_sigcontext_addr (this_frame);
343   
344   /* Layout of the sigcontext struct:
345      struct sigcontext {
346         struct pt_regs regs;
347         unsigned long oldmask;
348         unsigned long usp;
349      }; */
350   
351   if (tdep->cris_version == 10)
352     {
353       /* R0 to R13 are stored in reverse order at offset (2 * 4) in 
354          struct pt_regs.  */
355       for (i = 0; i <= 13; i++)
356         info->saved_regs[i].addr = addr + ((15 - i) * 4);
357
358       info->saved_regs[MOF_REGNUM].addr = addr + (16 * 4);
359       info->saved_regs[DCCR_REGNUM].addr = addr + (17 * 4);
360       info->saved_regs[SRP_REGNUM].addr = addr + (18 * 4);
361       /* Note: IRP is off by 2 at this point.  There's no point in correcting
362          it though since that will mean that the backtrace will show a PC 
363          different from what is shown when stopped.  */
364       info->saved_regs[IRP_REGNUM].addr = addr + (19 * 4);
365       info->saved_regs[gdbarch_pc_regnum (gdbarch)]
366         = info->saved_regs[IRP_REGNUM];
367       info->saved_regs[gdbarch_sp_regnum (gdbarch)].addr = addr + (24 * 4);
368     }
369   else
370     {
371       /* CRISv32.  */
372       /* R0 to R13 are stored in order at offset (1 * 4) in 
373          struct pt_regs.  */
374       for (i = 0; i <= 13; i++)
375         info->saved_regs[i].addr = addr + ((i + 1) * 4);
376
377       info->saved_regs[ACR_REGNUM].addr = addr + (15 * 4);
378       info->saved_regs[SRS_REGNUM].addr = addr + (16 * 4);
379       info->saved_regs[MOF_REGNUM].addr = addr + (17 * 4);
380       info->saved_regs[SPC_REGNUM].addr = addr + (18 * 4);
381       info->saved_regs[CCS_REGNUM].addr = addr + (19 * 4);
382       info->saved_regs[SRP_REGNUM].addr = addr + (20 * 4);
383       info->saved_regs[ERP_REGNUM].addr = addr + (21 * 4);
384       info->saved_regs[EXS_REGNUM].addr = addr + (22 * 4);
385       info->saved_regs[EDA_REGNUM].addr = addr + (23 * 4);
386
387       /* FIXME: If ERP is in a delay slot at this point then the PC will
388          be wrong at this point.  This problem manifests itself in the
389          sigaltstack.exp test case, which occasionally generates FAILs when
390          the signal is received while in a delay slot.
391          
392          This could be solved by a couple of read_memory_unsigned_integer and a
393          trad_frame_set_value.  */
394       info->saved_regs[gdbarch_pc_regnum (gdbarch)]
395         = info->saved_regs[ERP_REGNUM];
396
397       info->saved_regs[gdbarch_sp_regnum (gdbarch)].addr
398         = addr + (25 * 4);
399     }
400   
401   return info;
402 }
403
404 static void
405 cris_sigtramp_frame_this_id (struct frame_info *this_frame, void **this_cache,
406                              struct frame_id *this_id)
407 {
408   struct cris_unwind_cache *cache =
409     cris_sigtramp_frame_unwind_cache (this_frame, this_cache);
410   (*this_id) = frame_id_build (cache->base, get_frame_pc (this_frame));
411 }
412
413 /* Forward declaration.  */
414
415 static struct value *cris_frame_prev_register (struct frame_info *this_frame,
416                                                void **this_cache, int regnum);
417 static struct value *
418 cris_sigtramp_frame_prev_register (struct frame_info *this_frame,
419                                    void **this_cache, int regnum)
420 {
421   /* Make sure we've initialized the cache.  */
422   cris_sigtramp_frame_unwind_cache (this_frame, this_cache);
423   return cris_frame_prev_register (this_frame, this_cache, regnum);
424 }
425
426 static int
427 cris_sigtramp_frame_sniffer (const struct frame_unwind *self,
428                              struct frame_info *this_frame,
429                              void **this_cache)
430 {
431   if (cris_sigtramp_start (this_frame) 
432       || cris_rt_sigtramp_start (this_frame))
433     return 1;
434
435   return 0;
436 }
437
438 static const struct frame_unwind cris_sigtramp_frame_unwind =
439 {
440   SIGTRAMP_FRAME,
441   default_frame_unwind_stop_reason,
442   cris_sigtramp_frame_this_id,
443   cris_sigtramp_frame_prev_register,
444   NULL,
445   cris_sigtramp_frame_sniffer
446 };
447
448 static int
449 crisv32_single_step_through_delay (struct gdbarch *gdbarch,
450                                    struct frame_info *this_frame)
451 {
452   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
453   ULONGEST erp;
454   int ret = 0;
455
456   if (tdep->cris_mode == cris_mode_guru)
457     erp = get_frame_register_unsigned (this_frame, NRP_REGNUM);
458   else
459     erp = get_frame_register_unsigned (this_frame, ERP_REGNUM);
460
461   if (erp & 0x1)
462     {
463       /* In delay slot - check if there's a breakpoint at the preceding
464          instruction.  */
465       if (breakpoint_here_p (get_frame_address_space (this_frame), erp & ~0x1))
466         ret = 1;
467     }
468   return ret;
469 }
470
471 /* The instruction environment needed to find single-step breakpoints.  */
472
473 typedef 
474 struct instruction_environment
475 {
476   unsigned long reg[NUM_GENREGS];
477   unsigned long preg[NUM_SPECREGS];
478   unsigned long branch_break_address;
479   unsigned long delay_slot_pc;
480   unsigned long prefix_value;
481   int   branch_found;
482   int   prefix_found;
483   int   invalid;
484   int   slot_needed;
485   int   delay_slot_pc_active;
486   int   xflag_found;
487   int   disable_interrupt;
488   enum bfd_endian byte_order;
489 } inst_env_type;
490
491 /* Machine-dependencies in CRIS for opcodes.  */
492
493 /* Instruction sizes.  */
494 enum cris_instruction_sizes
495 {
496   INST_BYTE_SIZE  = 0,
497   INST_WORD_SIZE  = 1,
498   INST_DWORD_SIZE = 2
499 };
500
501 /* Addressing modes.  */
502 enum cris_addressing_modes
503 {
504   REGISTER_MODE = 1,
505   INDIRECT_MODE = 2,
506   AUTOINC_MODE  = 3
507 };
508
509 /* Prefix addressing modes.  */
510 enum cris_prefix_addressing_modes
511 {
512   PREFIX_INDEX_MODE  = 2,
513   PREFIX_ASSIGN_MODE = 3,
514
515   /* Handle immediate byte offset addressing mode prefix format.  */
516   PREFIX_OFFSET_MODE = 2
517 };
518
519 /* Masks for opcodes.  */
520 enum cris_opcode_masks
521 {
522   BRANCH_SIGNED_SHORT_OFFSET_MASK = 0x1,
523   SIGNED_EXTEND_BIT_MASK          = 0x2,
524   SIGNED_BYTE_MASK                = 0x80,
525   SIGNED_BYTE_EXTEND_MASK         = 0xFFFFFF00,
526   SIGNED_WORD_MASK                = 0x8000,
527   SIGNED_WORD_EXTEND_MASK         = 0xFFFF0000,
528   SIGNED_DWORD_MASK               = 0x80000000,
529   SIGNED_QUICK_VALUE_MASK         = 0x20,
530   SIGNED_QUICK_VALUE_EXTEND_MASK  = 0xFFFFFFC0
531 };
532
533 /* Functions for opcodes.  The general form of the ETRAX 16-bit instruction:
534    Bit 15 - 12   Operand2
535        11 - 10   Mode
536         9 -  6   Opcode
537         5 -  4   Size
538         3 -  0   Operand1  */
539
540 static int 
541 cris_get_operand2 (unsigned short insn)
542 {
543   return ((insn & 0xF000) >> 12);
544 }
545
546 static int
547 cris_get_mode (unsigned short insn)
548 {
549   return ((insn & 0x0C00) >> 10);
550 }
551
552 static int
553 cris_get_opcode (unsigned short insn)
554 {
555   return ((insn & 0x03C0) >> 6);
556 }
557
558 static int
559 cris_get_size (unsigned short insn)
560 {
561   return ((insn & 0x0030) >> 4);
562 }
563
564 static int
565 cris_get_operand1 (unsigned short insn)
566 {
567   return (insn & 0x000F);
568 }
569
570 /* Additional functions in order to handle opcodes.  */
571
572 static int
573 cris_get_quick_value (unsigned short insn)
574 {
575   return (insn & 0x003F);
576 }
577
578 static int
579 cris_get_bdap_quick_offset (unsigned short insn)
580 {
581   return (insn & 0x00FF);
582 }
583
584 static int
585 cris_get_branch_short_offset (unsigned short insn)
586 {
587   return (insn & 0x00FF);
588 }
589
590 static int
591 cris_get_asr_shift_steps (unsigned long value)
592 {
593   return (value & 0x3F);
594 }
595
596 static int
597 cris_get_clear_size (unsigned short insn)
598 {
599   return ((insn) & 0xC000);
600 }
601
602 static int
603 cris_is_signed_extend_bit_on (unsigned short insn)
604 {
605   return (((insn) & 0x20) == 0x20);
606 }
607
608 static int
609 cris_is_xflag_bit_on (unsigned short insn)
610 {
611   return (((insn) & 0x1000) == 0x1000);
612 }
613
614 static void
615 cris_set_size_to_dword (unsigned short *insn)
616 {
617   *insn &= 0xFFCF; 
618   *insn |= 0x20; 
619 }
620
621 static signed char
622 cris_get_signed_offset (unsigned short insn)
623 {
624   return ((signed char) (insn & 0x00FF));
625 }
626
627 /* Calls an op function given the op-type, working on the insn and the
628    inst_env.  */
629 static void cris_gdb_func (struct gdbarch *, enum cris_op_type, unsigned short,
630                            inst_env_type *);
631
632 static struct gdbarch *cris_gdbarch_init (struct gdbarch_info,
633                                           struct gdbarch_list *);
634
635 static void cris_dump_tdep (struct gdbarch *, struct ui_file *);
636
637 static void set_cris_version (const char *ignore_args, int from_tty, 
638                               struct cmd_list_element *c);
639
640 static void set_cris_mode (const char *ignore_args, int from_tty, 
641                            struct cmd_list_element *c);
642
643 static void set_cris_dwarf2_cfi (const char *ignore_args, int from_tty, 
644                                  struct cmd_list_element *c);
645
646 static CORE_ADDR cris_scan_prologue (CORE_ADDR pc, 
647                                      struct frame_info *this_frame,
648                                      struct cris_unwind_cache *info);
649
650 static CORE_ADDR crisv32_scan_prologue (CORE_ADDR pc, 
651                                         struct frame_info *this_frame,
652                                         struct cris_unwind_cache *info);
653
654 /* When arguments must be pushed onto the stack, they go on in reverse
655    order.  The below implements a FILO (stack) to do this.
656    Copied from d10v-tdep.c.  */
657
658 struct stack_item
659 {
660   int len;
661   struct stack_item *prev;
662   gdb_byte *data;
663 };
664
665 static struct stack_item *
666 push_stack_item (struct stack_item *prev, const gdb_byte *contents, int len)
667 {
668   struct stack_item *si = XNEW (struct stack_item);
669   si->data = (gdb_byte *) xmalloc (len);
670   si->len = len;
671   si->prev = prev;
672   memcpy (si->data, contents, len);
673   return si;
674 }
675
676 static struct stack_item *
677 pop_stack_item (struct stack_item *si)
678 {
679   struct stack_item *dead = si;
680   si = si->prev;
681   xfree (dead->data);
682   xfree (dead);
683   return si;
684 }
685
686 /* Put here the code to store, into fi->saved_regs, the addresses of
687    the saved registers of frame described by FRAME_INFO.  This
688    includes special registers such as pc and fp saved in special ways
689    in the stack frame.  sp is even more special: the address we return
690    for it IS the sp for the next frame.  */
691
692 static struct cris_unwind_cache *
693 cris_frame_unwind_cache (struct frame_info *this_frame,
694                          void **this_prologue_cache)
695 {
696   struct gdbarch *gdbarch = get_frame_arch (this_frame);
697   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
698   struct cris_unwind_cache *info;
699
700   if ((*this_prologue_cache))
701     return (struct cris_unwind_cache *) (*this_prologue_cache);
702
703   info = FRAME_OBSTACK_ZALLOC (struct cris_unwind_cache);
704   (*this_prologue_cache) = info;
705   info->saved_regs = trad_frame_alloc_saved_regs (this_frame);
706
707   /* Zero all fields.  */
708   info->prev_sp = 0;
709   info->base = 0;
710   info->size = 0;
711   info->sp_offset = 0;
712   info->r8_offset = 0;
713   info->uses_frame = 0;
714   info->return_pc = 0;
715   info->leaf_function = 0;
716
717   /* Prologue analysis does the rest...  */
718   if (tdep->cris_version == 32)
719     crisv32_scan_prologue (get_frame_func (this_frame), this_frame, info);
720   else
721     cris_scan_prologue (get_frame_func (this_frame), this_frame, info);
722
723   return info;
724 }
725
726 /* Given a GDB frame, determine the address of the calling function's
727    frame.  This will be used to create a new GDB frame struct.  */
728
729 static void
730 cris_frame_this_id (struct frame_info *this_frame,
731                     void **this_prologue_cache,
732                     struct frame_id *this_id)
733 {
734   struct cris_unwind_cache *info
735     = cris_frame_unwind_cache (this_frame, this_prologue_cache);
736   CORE_ADDR base;
737   CORE_ADDR func;
738   struct frame_id id;
739
740   /* The FUNC is easy.  */
741   func = get_frame_func (this_frame);
742
743   /* Hopefully the prologue analysis either correctly determined the
744      frame's base (which is the SP from the previous frame), or set
745      that base to "NULL".  */
746   base = info->prev_sp;
747   if (base == 0)
748     return;
749
750   id = frame_id_build (base, func);
751
752   (*this_id) = id;
753 }
754
755 static struct value *
756 cris_frame_prev_register (struct frame_info *this_frame,
757                           void **this_prologue_cache, int regnum)
758 {
759   struct cris_unwind_cache *info
760     = cris_frame_unwind_cache (this_frame, this_prologue_cache);
761   return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
762 }
763
764 static CORE_ADDR
765 cris_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
766 {
767   /* Align to the size of an instruction (so that they can safely be
768      pushed onto the stack).  */
769   return sp & ~3;
770 }
771
772 static CORE_ADDR
773 cris_push_dummy_code (struct gdbarch *gdbarch,
774                       CORE_ADDR sp, CORE_ADDR funaddr,
775                       struct value **args, int nargs,
776                       struct type *value_type,
777                       CORE_ADDR *real_pc, CORE_ADDR *bp_addr,
778                       struct regcache *regcache)
779 {
780   /* Allocate space sufficient for a breakpoint.  */
781   sp = (sp - 4) & ~3;
782   /* Store the address of that breakpoint */
783   *bp_addr = sp;
784   /* CRIS always starts the call at the callee's entry point.  */
785   *real_pc = funaddr;
786   return sp;
787 }
788
789 static CORE_ADDR
790 cris_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
791                       struct regcache *regcache, CORE_ADDR bp_addr,
792                       int nargs, struct value **args, CORE_ADDR sp,
793                       function_call_return_method return_method,
794                       CORE_ADDR struct_addr)
795 {
796   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
797   int argreg;
798   int argnum;
799
800   struct stack_item *si = NULL;
801
802   /* Push the return address.  */
803   regcache_cooked_write_unsigned (regcache, SRP_REGNUM, bp_addr);
804
805   /* Are we returning a value using a structure return or a normal value
806      return?  struct_addr is the address of the reserved space for the return
807      structure to be written on the stack.  */
808   if (return_method == return_method_struct)
809     regcache_cooked_write_unsigned (regcache, STR_REGNUM, struct_addr);
810
811   /* Now load as many as possible of the first arguments into registers,
812      and push the rest onto the stack.  */
813   argreg = ARG1_REGNUM;
814
815   for (argnum = 0; argnum < nargs; argnum++)
816     {
817       int len;
818       const gdb_byte *val;
819       int reg_demand;
820       int i;
821       
822       len = TYPE_LENGTH (value_type (args[argnum]));
823       val = value_contents (args[argnum]);
824       
825       /* How may registers worth of storage do we need for this argument?  */
826       reg_demand = (len / 4) + (len % 4 != 0 ? 1 : 0);
827         
828       if (len <= (2 * 4) && (argreg + reg_demand - 1 <= ARG4_REGNUM))
829         {
830           /* Data passed by value.  Fits in available register(s).  */
831           for (i = 0; i < reg_demand; i++)
832             {
833               regcache->cooked_write (argreg, val);
834               argreg++;
835               val += 4;
836             }
837         }
838       else if (len <= (2 * 4) && argreg <= ARG4_REGNUM)
839         {
840           /* Data passed by value. Does not fit in available register(s).
841              Use the register(s) first, then the stack.  */
842           for (i = 0; i < reg_demand; i++)
843             {
844               if (argreg <= ARG4_REGNUM)
845                 {
846                   regcache->cooked_write (argreg, val);
847                   argreg++;
848                   val += 4;
849                 }
850               else
851                 {
852                   /* Push item for later so that pushed arguments
853                      come in the right order.  */
854                   si = push_stack_item (si, val, 4);
855                   val += 4;
856                 }
857             }
858         }
859       else if (len > (2 * 4))
860         {
861           /* Data passed by reference.  Push copy of data onto stack
862              and pass pointer to this copy as argument.  */
863           sp = (sp - len) & ~3;
864           write_memory (sp, val, len);
865
866           if (argreg <= ARG4_REGNUM)
867             {
868               regcache_cooked_write_unsigned (regcache, argreg, sp);
869               argreg++;
870             }
871           else
872             {
873               gdb_byte buf[4];
874               store_unsigned_integer (buf, 4, byte_order, sp);
875               si = push_stack_item (si, buf, 4);
876             }
877         }
878       else
879         {
880           /* Data passed by value.  No available registers.  Put it on
881              the stack.  */
882            si = push_stack_item (si, val, len);
883         }
884     }
885
886   while (si)
887     {
888       /* fp_arg must be word-aligned (i.e., don't += len) to match
889          the function prologue.  */
890       sp = (sp - si->len) & ~3;
891       write_memory (sp, si->data, si->len);
892       si = pop_stack_item (si);
893     }
894
895   /* Finally, update the SP register.  */
896   regcache_cooked_write_unsigned (regcache, gdbarch_sp_regnum (gdbarch), sp);
897
898   return sp;
899 }
900
901 static const struct frame_unwind cris_frame_unwind = 
902 {
903   NORMAL_FRAME,
904   default_frame_unwind_stop_reason,
905   cris_frame_this_id,
906   cris_frame_prev_register,
907   NULL,
908   default_frame_sniffer
909 };
910
911 static CORE_ADDR
912 cris_frame_base_address (struct frame_info *this_frame, void **this_cache)
913 {
914   struct cris_unwind_cache *info
915     = cris_frame_unwind_cache (this_frame, this_cache);
916   return info->base;
917 }
918
919 static const struct frame_base cris_frame_base = 
920 {
921   &cris_frame_unwind,
922   cris_frame_base_address,
923   cris_frame_base_address,
924   cris_frame_base_address
925 };
926
927 /* Frames information. The definition of the struct frame_info is
928
929    CORE_ADDR frame
930    CORE_ADDR pc
931    enum frame_type type;
932    CORE_ADDR return_pc
933    int leaf_function
934
935    If the compilation option -fno-omit-frame-pointer is present the
936    variable frame will be set to the content of R8 which is the frame
937    pointer register.
938
939    The variable pc contains the address where execution is performed
940    in the present frame.  The innermost frame contains the current content
941    of the register PC.  All other frames contain the content of the
942    register PC in the next frame.
943
944    The variable `type' indicates the frame's type: normal, SIGTRAMP
945    (associated with a signal handler), dummy (associated with a dummy
946    frame).
947
948    The variable return_pc contains the address where execution should be
949    resumed when the present frame has finished, the return address.
950
951    The variable leaf_function is 1 if the return address is in the register
952    SRP, and 0 if it is on the stack.
953
954    Prologue instructions C-code.
955    The prologue may consist of (-fno-omit-frame-pointer)
956    1)                2)
957    push   srp
958    push   r8         push   r8
959    move.d sp,r8      move.d sp,r8
960    subq   X,sp       subq   X,sp
961    movem  rY,[sp]    movem  rY,[sp]
962    move.S rZ,[r8-U]  move.S rZ,[r8-U]
963
964    where 1 is a non-terminal function, and 2 is a leaf-function.
965
966    Note that this assumption is extremely brittle, and will break at the
967    slightest change in GCC's prologue.
968
969    If local variables are declared or register contents are saved on stack
970    the subq-instruction will be present with X as the number of bytes
971    needed for storage.  The reshuffle with respect to r8 may be performed
972    with any size S (b, w, d) and any of the general registers Z={0..13}. 
973    The offset U should be representable by a signed 8-bit value in all cases.
974    Thus, the prefix word is assumed to be immediate byte offset mode followed
975    by another word containing the instruction.
976
977    Degenerate cases:
978    3)
979    push   r8
980    move.d sp,r8
981    move.d r8,sp
982    pop    r8   
983
984    Prologue instructions C++-code.
985    Case 1) and 2) in the C-code may be followed by
986
987    move.d r10,rS    ; this
988    move.d r11,rT    ; P1
989    move.d r12,rU    ; P2
990    move.d r13,rV    ; P3
991    move.S [r8+U],rZ ; P4
992
993    if any of the call parameters are stored.  The host expects these 
994    instructions to be executed in order to get the call parameters right.  */
995
996 /* Examine the prologue of a function.  The variable ip is the address of 
997    the first instruction of the prologue.  The variable limit is the address 
998    of the first instruction after the prologue.  The variable fi contains the 
999    information in struct frame_info.  The variable frameless_p controls whether
1000    the entire prologue is examined (0) or just enough instructions to 
1001    determine that it is a prologue (1).  */
1002
1003 static CORE_ADDR 
1004 cris_scan_prologue (CORE_ADDR pc, struct frame_info *this_frame,
1005                     struct cris_unwind_cache *info)
1006 {
1007   struct gdbarch *gdbarch = get_frame_arch (this_frame);
1008   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1009
1010   /* Present instruction.  */
1011   unsigned short insn;
1012
1013   /* Next instruction, lookahead.  */
1014   unsigned short insn_next; 
1015   int regno;
1016
1017   /* Number of byte on stack used for local variables and movem.  */
1018   int val; 
1019
1020   /* Highest register number in a movem.  */
1021   int regsave;
1022
1023   /* move.d r<source_register>,rS */
1024   short source_register; 
1025
1026   /* Scan limit.  */
1027   int limit;
1028
1029   /* This frame is with respect to a leaf until a push srp is found.  */
1030   if (info)
1031     {
1032       info->leaf_function = 1;
1033     }
1034
1035   /* Assume nothing on stack.  */
1036   val = 0;
1037   regsave = -1;
1038
1039   /* If we were called without a this_frame, that means we were called
1040      from cris_skip_prologue which already tried to find the end of the
1041      prologue through the symbol information.  64 instructions past current
1042      pc is arbitrarily chosen, but at least it means we'll stop eventually.  */
1043   limit = this_frame ? get_frame_pc (this_frame) : pc + 64;
1044
1045   /* Find the prologue instructions.  */
1046   while (pc > 0 && pc < limit)
1047     {
1048       insn = read_memory_unsigned_integer (pc, 2, byte_order);
1049       pc += 2;
1050       if (insn == 0xE1FC)
1051         {
1052           /* push <reg> 32 bit instruction.  */
1053           insn_next = read_memory_unsigned_integer (pc, 2, byte_order);
1054           pc += 2;
1055           regno = cris_get_operand2 (insn_next);
1056           if (info)
1057             {
1058               info->sp_offset += 4;
1059             }
1060           /* This check, meant to recognize srp, used to be regno == 
1061              (SRP_REGNUM - NUM_GENREGS), but that covers r11 also.  */
1062           if (insn_next == 0xBE7E)
1063             {
1064               if (info)
1065                 {
1066                   info->leaf_function = 0;
1067                 }
1068             }
1069           else if (insn_next == 0x8FEE)
1070             {
1071               /* push $r8 */
1072               if (info)
1073                 {
1074                   info->r8_offset = info->sp_offset;
1075                 }
1076             }
1077         }
1078       else if (insn == 0x866E)
1079         {
1080           /* move.d sp,r8 */
1081           if (info)
1082             {
1083               info->uses_frame = 1;
1084             }
1085           continue;
1086         }
1087       else if (cris_get_operand2 (insn) == gdbarch_sp_regnum (gdbarch)
1088                && cris_get_mode (insn) == 0x0000
1089                && cris_get_opcode (insn) == 0x000A)
1090         {
1091           /* subq <val>,sp */
1092           if (info)
1093             {
1094               info->sp_offset += cris_get_quick_value (insn);
1095             }
1096         }
1097       else if (cris_get_mode (insn) == 0x0002 
1098                && cris_get_opcode (insn) == 0x000F
1099                && cris_get_size (insn) == 0x0003
1100                && cris_get_operand1 (insn) == gdbarch_sp_regnum (gdbarch))
1101         {
1102           /* movem r<regsave>,[sp] */
1103           regsave = cris_get_operand2 (insn);
1104         }
1105       else if (cris_get_operand2 (insn) == gdbarch_sp_regnum (gdbarch)
1106                && ((insn & 0x0F00) >> 8) == 0x0001
1107                && (cris_get_signed_offset (insn) < 0))
1108         {
1109           /* Immediate byte offset addressing prefix word with sp as base 
1110              register.  Used for CRIS v8 i.e. ETRAX 100 and newer if <val> 
1111              is between 64 and 128. 
1112              movem r<regsave>,[sp=sp-<val>] */
1113           if (info)
1114             {
1115               info->sp_offset += -cris_get_signed_offset (insn);
1116             }
1117           insn_next = read_memory_unsigned_integer (pc, 2, byte_order);
1118           pc += 2;
1119           if (cris_get_mode (insn_next) == PREFIX_ASSIGN_MODE
1120               && cris_get_opcode (insn_next) == 0x000F
1121               && cris_get_size (insn_next) == 0x0003
1122               && cris_get_operand1 (insn_next) == gdbarch_sp_regnum
1123                                                   (gdbarch))
1124             {
1125               regsave = cris_get_operand2 (insn_next);
1126             }
1127           else
1128             {
1129               /* The prologue ended before the limit was reached.  */
1130               pc -= 4;
1131               break;
1132             }
1133         }
1134       else if (cris_get_mode (insn) == 0x0001
1135                && cris_get_opcode (insn) == 0x0009
1136                && cris_get_size (insn) == 0x0002)
1137         {
1138           /* move.d r<10..13>,r<0..15> */
1139           source_register = cris_get_operand1 (insn);
1140
1141           /* FIXME?  In the glibc solibs, the prologue might contain something
1142              like (this example taken from relocate_doit):
1143              move.d $pc,$r0
1144              sub.d 0xfffef426,$r0
1145              which isn't covered by the source_register check below.  Question
1146              is whether to add a check for this combo, or make better use of
1147              the limit variable instead.  */
1148           if (source_register < ARG1_REGNUM || source_register > ARG4_REGNUM)
1149             {
1150               /* The prologue ended before the limit was reached.  */
1151               pc -= 2;
1152               break;
1153             }
1154         }
1155       else if (cris_get_operand2 (insn) == CRIS_FP_REGNUM 
1156                /* The size is a fixed-size.  */
1157                && ((insn & 0x0F00) >> 8) == 0x0001 
1158                /* A negative offset.  */
1159                && (cris_get_signed_offset (insn) < 0))  
1160         {
1161           /* move.S rZ,[r8-U] (?) */
1162           insn_next = read_memory_unsigned_integer (pc, 2, byte_order);
1163           pc += 2;
1164           regno = cris_get_operand2 (insn_next);
1165           if ((regno >= 0 && regno < gdbarch_sp_regnum (gdbarch))
1166               && cris_get_mode (insn_next) == PREFIX_OFFSET_MODE
1167               && cris_get_opcode (insn_next) == 0x000F)
1168             {
1169               /* move.S rZ,[r8-U] */
1170               continue;
1171             }
1172           else
1173             {
1174               /* The prologue ended before the limit was reached.  */
1175               pc -= 4;
1176               break;
1177             }
1178         }
1179       else if (cris_get_operand2 (insn) == CRIS_FP_REGNUM 
1180                /* The size is a fixed-size.  */
1181                && ((insn & 0x0F00) >> 8) == 0x0001 
1182                /* A positive offset.  */
1183                && (cris_get_signed_offset (insn) > 0))  
1184         {
1185           /* move.S [r8+U],rZ (?) */
1186           insn_next = read_memory_unsigned_integer (pc, 2, byte_order);
1187           pc += 2;
1188           regno = cris_get_operand2 (insn_next);
1189           if ((regno >= 0 && regno < gdbarch_sp_regnum (gdbarch))
1190               && cris_get_mode (insn_next) == PREFIX_OFFSET_MODE
1191               && cris_get_opcode (insn_next) == 0x0009
1192               && cris_get_operand1 (insn_next) == regno)
1193             {
1194               /* move.S [r8+U],rZ */
1195               continue;
1196             }
1197           else
1198             {
1199               /* The prologue ended before the limit was reached.  */
1200               pc -= 4;
1201               break;
1202             }
1203         }
1204       else
1205         {
1206           /* The prologue ended before the limit was reached.  */
1207           pc -= 2;
1208           break;
1209         }
1210     }
1211
1212   /* We only want to know the end of the prologue when this_frame and info
1213      are NULL (called from cris_skip_prologue i.e.).  */
1214   if (this_frame == NULL && info == NULL)
1215     {
1216       return pc;
1217     }
1218
1219   info->size = info->sp_offset;
1220
1221   /* Compute the previous frame's stack pointer (which is also the
1222      frame's ID's stack address), and this frame's base pointer.  */
1223   if (info->uses_frame)
1224     {
1225       ULONGEST this_base;
1226       /* The SP was moved to the FP.  This indicates that a new frame
1227          was created.  Get THIS frame's FP value by unwinding it from
1228          the next frame.  */
1229       this_base = get_frame_register_unsigned (this_frame, CRIS_FP_REGNUM);
1230       info->base = this_base;
1231       info->saved_regs[CRIS_FP_REGNUM].addr = info->base;
1232   
1233       /* The FP points at the last saved register.  Adjust the FP back
1234          to before the first saved register giving the SP.  */
1235       info->prev_sp = info->base + info->r8_offset;
1236     }
1237   else
1238     {
1239       ULONGEST this_base;      
1240       /* Assume that the FP is this frame's SP but with that pushed
1241          stack space added back.  */
1242       this_base = get_frame_register_unsigned (this_frame,
1243                                                gdbarch_sp_regnum (gdbarch));
1244       info->base = this_base;
1245       info->prev_sp = info->base + info->size;
1246     }
1247       
1248   /* Calculate the addresses for the saved registers on the stack.  */
1249   /* FIXME: The address calculation should really be done on the fly while
1250      we're analyzing the prologue (we only hold one regsave value as it is 
1251      now).  */
1252   val = info->sp_offset;
1253
1254   for (regno = regsave; regno >= 0; regno--)
1255     {
1256       info->saved_regs[regno].addr = info->base + info->r8_offset - val;
1257       val -= 4;
1258     }
1259
1260   /* The previous frame's SP needed to be computed.  Save the computed
1261      value.  */
1262   trad_frame_set_value (info->saved_regs,
1263                         gdbarch_sp_regnum (gdbarch), info->prev_sp);
1264
1265   if (!info->leaf_function)
1266     {
1267       /* SRP saved on the stack.  But where?  */
1268       if (info->r8_offset == 0)
1269         {
1270           /* R8 not pushed yet.  */
1271           info->saved_regs[SRP_REGNUM].addr = info->base;
1272         }
1273       else
1274         {
1275           /* R8 pushed, but SP may or may not be moved to R8 yet.  */
1276           info->saved_regs[SRP_REGNUM].addr = info->base + 4;
1277         }
1278     }
1279
1280   /* The PC is found in SRP (the actual register or located on the stack).  */
1281   info->saved_regs[gdbarch_pc_regnum (gdbarch)]
1282     = info->saved_regs[SRP_REGNUM];
1283
1284   return pc;
1285 }
1286
1287 static CORE_ADDR 
1288 crisv32_scan_prologue (CORE_ADDR pc, struct frame_info *this_frame,
1289                     struct cris_unwind_cache *info)
1290 {
1291   struct gdbarch *gdbarch = get_frame_arch (this_frame);
1292   ULONGEST this_base;
1293
1294   /* Unlike the CRISv10 prologue scanner (cris_scan_prologue), this is not
1295      meant to be a full-fledged prologue scanner.  It is only needed for 
1296      the cases where we end up in code always lacking DWARF-2 CFI, notably:
1297
1298        * PLT stubs (library calls)
1299        * call dummys
1300        * signal trampolines
1301
1302      For those cases, it is assumed that there is no actual prologue; that 
1303      the stack pointer is not adjusted, and (as a consequence) the return
1304      address is not pushed onto the stack.  */
1305
1306   /* We only want to know the end of the prologue when this_frame and info
1307      are NULL (called from cris_skip_prologue i.e.).  */
1308   if (this_frame == NULL && info == NULL)
1309     {
1310       return pc;
1311     }
1312
1313   /* The SP is assumed to be unaltered.  */
1314   this_base = get_frame_register_unsigned (this_frame,
1315                                            gdbarch_sp_regnum (gdbarch));
1316   info->base = this_base;
1317   info->prev_sp = this_base;
1318       
1319   /* The PC is assumed to be found in SRP.  */
1320   info->saved_regs[gdbarch_pc_regnum (gdbarch)]
1321     = info->saved_regs[SRP_REGNUM];
1322
1323   return pc;
1324 }
1325
1326 /* Advance pc beyond any function entry prologue instructions at pc
1327    to reach some "real" code.  */
1328
1329 /* Given a PC value corresponding to the start of a function, return the PC
1330    of the first instruction after the function prologue.  */
1331
1332 static CORE_ADDR
1333 cris_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
1334 {
1335   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1336   CORE_ADDR func_addr, func_end;
1337   struct symtab_and_line sal;
1338   CORE_ADDR pc_after_prologue;
1339   
1340   /* If we have line debugging information, then the end of the prologue
1341      should the first assembly instruction of the first source line.  */
1342   if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
1343     {
1344       sal = find_pc_line (func_addr, 0);
1345       if (sal.end > 0 && sal.end < func_end)
1346         return sal.end;
1347     }
1348
1349   if (tdep->cris_version == 32)
1350     pc_after_prologue = crisv32_scan_prologue (pc, NULL, NULL);
1351   else
1352     pc_after_prologue = cris_scan_prologue (pc, NULL, NULL);
1353
1354   return pc_after_prologue;
1355 }
1356
1357 /* Implement the breakpoint_kind_from_pc gdbarch method.  */
1358
1359 static int
1360 cris_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
1361 {
1362   return 2;
1363 }
1364
1365 /* Implement the sw_breakpoint_from_kind gdbarch method.  */
1366
1367 static const gdb_byte *
1368 cris_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
1369 {
1370   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1371   static unsigned char break8_insn[] = {0x38, 0xe9};
1372   static unsigned char break15_insn[] = {0x3f, 0xe9};
1373
1374   *size = kind;
1375
1376   if (tdep->cris_mode == cris_mode_guru)
1377     return break15_insn;
1378   else
1379     return break8_insn;
1380 }
1381
1382 /* Returns 1 if spec_reg is applicable to the current gdbarch's CRIS version,
1383    0 otherwise.  */
1384
1385 static int
1386 cris_spec_reg_applicable (struct gdbarch *gdbarch,
1387                           struct cris_spec_reg spec_reg)
1388 {
1389   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1390   unsigned int version = tdep->cris_version;
1391   
1392   switch (spec_reg.applicable_version)
1393     {
1394     case cris_ver_version_all:
1395       return 1;
1396     case cris_ver_warning:
1397       /* Indeterminate/obsolete.  */
1398       return 0;
1399     case cris_ver_v0_3:
1400       return in_inclusive_range (version, 0U, 3U);
1401     case cris_ver_v3p:
1402       return (version >= 3);
1403     case cris_ver_v8:
1404       return in_inclusive_range (version, 8U, 9U);
1405     case cris_ver_v8p:
1406       return (version >= 8);
1407     case cris_ver_v0_10:
1408       return in_inclusive_range (version, 0U, 10U);
1409     case cris_ver_v3_10:
1410       return in_inclusive_range (version, 3U, 10U);
1411     case cris_ver_v8_10:
1412       return in_inclusive_range (version, 8U, 10U);
1413     case cris_ver_v10:
1414       return (version == 10);
1415     case cris_ver_v10p:
1416       return (version >= 10);
1417     case cris_ver_v32p:
1418       return (version >= 32);
1419     default:
1420       /* Invalid cris version.  */
1421       return 0;
1422     }
1423 }
1424
1425 /* Returns the register size in unit byte.  Returns 0 for an unimplemented
1426    register, -1 for an invalid register.  */
1427
1428 static int
1429 cris_register_size (struct gdbarch *gdbarch, int regno)
1430 {
1431   int i;
1432   int spec_regno;
1433   
1434   if (regno >= 0 && regno < NUM_GENREGS)
1435     {
1436       /* General registers (R0 - R15) are 32 bits.  */
1437       return 4;
1438     }
1439   else if (regno >= NUM_GENREGS && regno < (NUM_GENREGS + NUM_SPECREGS))
1440     {
1441       /* Special register (R16 - R31).  cris_spec_regs is zero-based. 
1442          Adjust regno accordingly.  */
1443       spec_regno = regno - NUM_GENREGS;
1444       
1445       for (i = 0; cris_spec_regs[i].name != NULL; i++)
1446         {
1447           if (cris_spec_regs[i].number == spec_regno 
1448               && cris_spec_reg_applicable (gdbarch, cris_spec_regs[i]))
1449             /* Go with the first applicable register.  */
1450             return cris_spec_regs[i].reg_size;
1451         }
1452       /* Special register not applicable to this CRIS version.  */
1453       return 0;
1454     }
1455   else if (regno >= gdbarch_pc_regnum (gdbarch)
1456            && regno < gdbarch_num_regs (gdbarch))
1457     {
1458       /* This will apply to CRISv32 only where there are additional registers
1459          after the special registers (pseudo PC and support registers).  */
1460       return 4;
1461     }
1462
1463   
1464   return -1;
1465 }
1466
1467 /* Nonzero if regno should not be fetched from the target.  This is the case
1468    for unimplemented (size 0) and non-existant registers.  */
1469
1470 static int
1471 cris_cannot_fetch_register (struct gdbarch *gdbarch, int regno)
1472 {
1473   return ((regno < 0 || regno >= gdbarch_num_regs (gdbarch))
1474           || (cris_register_size (gdbarch, regno) == 0));
1475 }
1476
1477 /* Nonzero if regno should not be written to the target, for various 
1478    reasons.  */
1479
1480 static int
1481 cris_cannot_store_register (struct gdbarch *gdbarch, int regno)
1482 {
1483   /* There are three kinds of registers we refuse to write to.
1484      1. Those that not implemented.
1485      2. Those that are read-only (depends on the processor mode).
1486      3. Those registers to which a write has no effect.  */
1487
1488   if (regno < 0
1489       || regno >= gdbarch_num_regs (gdbarch)
1490       || cris_register_size (gdbarch, regno) == 0)
1491     /* Not implemented.  */
1492     return 1;
1493
1494   else if  (regno == VR_REGNUM)
1495     /* Read-only.  */
1496     return 1;
1497
1498   else if  (regno == P0_REGNUM || regno == P4_REGNUM || regno == P8_REGNUM)
1499     /* Writing has no effect.  */
1500     return 1;
1501
1502   /* IBR, BAR, BRP and IRP are read-only in user mode.  Let the debug
1503      agent decide whether they are writable.  */
1504   
1505   return 0;
1506 }
1507
1508 /* Nonzero if regno should not be fetched from the target.  This is the case
1509    for unimplemented (size 0) and non-existant registers.  */
1510
1511 static int
1512 crisv32_cannot_fetch_register (struct gdbarch *gdbarch, int regno)
1513 {
1514   return ((regno < 0 || regno >= gdbarch_num_regs (gdbarch))
1515           || (cris_register_size (gdbarch, regno) == 0));
1516 }
1517
1518 /* Nonzero if regno should not be written to the target, for various 
1519    reasons.  */
1520
1521 static int
1522 crisv32_cannot_store_register (struct gdbarch *gdbarch, int regno)
1523 {
1524   /* There are three kinds of registers we refuse to write to.
1525      1. Those that not implemented.
1526      2. Those that are read-only (depends on the processor mode).
1527      3. Those registers to which a write has no effect.  */
1528
1529   if (regno < 0
1530       || regno >= gdbarch_num_regs (gdbarch)
1531       || cris_register_size (gdbarch, regno) == 0)
1532     /* Not implemented.  */
1533     return 1;
1534
1535   else if  (regno == VR_REGNUM)
1536     /* Read-only.  */
1537     return 1;
1538
1539   else if  (regno == BZ_REGNUM || regno == WZ_REGNUM || regno == DZ_REGNUM)
1540     /* Writing has no effect.  */
1541     return 1;
1542
1543   /* Many special registers are read-only in user mode.  Let the debug
1544      agent decide whether they are writable.  */
1545   
1546   return 0;
1547 }
1548
1549 /* Return the GDB type (defined in gdbtypes.c) for the "standard" data type
1550    of data in register regno.  */
1551
1552 static struct type *
1553 cris_register_type (struct gdbarch *gdbarch, int regno)
1554 {
1555   if (regno == gdbarch_pc_regnum (gdbarch))
1556     return builtin_type (gdbarch)->builtin_func_ptr;
1557   else if (regno == gdbarch_sp_regnum (gdbarch)
1558            || regno == CRIS_FP_REGNUM)
1559     return builtin_type (gdbarch)->builtin_data_ptr;
1560   else if ((regno >= 0 && regno < gdbarch_sp_regnum (gdbarch))
1561            || (regno >= MOF_REGNUM && regno <= USP_REGNUM))
1562     /* Note: R8 taken care of previous clause.  */
1563     return builtin_type (gdbarch)->builtin_uint32;
1564   else if (regno >= P4_REGNUM && regno <= CCR_REGNUM)
1565       return builtin_type (gdbarch)->builtin_uint16;
1566   else if (regno >= P0_REGNUM && regno <= VR_REGNUM)
1567       return builtin_type (gdbarch)->builtin_uint8;
1568   else
1569       /* Invalid (unimplemented) register.  */
1570       return builtin_type (gdbarch)->builtin_int0;
1571 }
1572
1573 static struct type *
1574 crisv32_register_type (struct gdbarch *gdbarch, int regno)
1575 {
1576   if (regno == gdbarch_pc_regnum (gdbarch))
1577     return builtin_type (gdbarch)->builtin_func_ptr;
1578   else if (regno == gdbarch_sp_regnum (gdbarch)
1579            || regno == CRIS_FP_REGNUM)
1580     return builtin_type (gdbarch)->builtin_data_ptr;
1581   else if ((regno >= 0 && regno <= ACR_REGNUM)
1582            || (regno >= EXS_REGNUM && regno <= SPC_REGNUM)
1583            || (regno == PID_REGNUM)
1584            || (regno >= S0_REGNUM && regno <= S15_REGNUM))
1585     /* Note: R8 and SP taken care of by previous clause.  */
1586     return builtin_type (gdbarch)->builtin_uint32;
1587   else if (regno == WZ_REGNUM)
1588       return builtin_type (gdbarch)->builtin_uint16;
1589   else if (regno == BZ_REGNUM || regno == VR_REGNUM || regno == SRS_REGNUM)
1590       return builtin_type (gdbarch)->builtin_uint8;
1591   else
1592     {
1593       /* Invalid (unimplemented) register.  Should not happen as there are
1594          no unimplemented CRISv32 registers.  */
1595       warning (_("crisv32_register_type: unknown regno %d"), regno);
1596       return builtin_type (gdbarch)->builtin_int0;
1597     }
1598 }
1599
1600 /* Stores a function return value of type type, where valbuf is the address 
1601    of the value to be stored.  */
1602
1603 /* In the CRIS ABI, R10 and R11 are used to store return values.  */
1604
1605 static void
1606 cris_store_return_value (struct type *type, struct regcache *regcache,
1607                          const gdb_byte *valbuf)
1608 {
1609   struct gdbarch *gdbarch = regcache->arch ();
1610   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1611   ULONGEST val;
1612   int len = TYPE_LENGTH (type);
1613   
1614   if (len <= 4)
1615     {
1616       /* Put the return value in R10.  */
1617       val = extract_unsigned_integer (valbuf, len, byte_order);
1618       regcache_cooked_write_unsigned (regcache, ARG1_REGNUM, val);
1619     }
1620   else if (len <= 8)
1621     {
1622       /* Put the return value in R10 and R11.  */
1623       val = extract_unsigned_integer (valbuf, 4, byte_order);
1624       regcache_cooked_write_unsigned (regcache, ARG1_REGNUM, val);
1625       val = extract_unsigned_integer (valbuf + 4, len - 4, byte_order);
1626       regcache_cooked_write_unsigned (regcache, ARG2_REGNUM, val);
1627     }
1628   else
1629     error (_("cris_store_return_value: type length too large."));
1630 }
1631
1632 /* Return the name of register regno as a string.  Return NULL for an
1633    invalid or unimplemented register.  */
1634
1635 static const char *
1636 cris_special_register_name (struct gdbarch *gdbarch, int regno)
1637 {
1638   int spec_regno;
1639   int i;
1640
1641   /* Special register (R16 - R31).  cris_spec_regs is zero-based. 
1642      Adjust regno accordingly.  */
1643   spec_regno = regno - NUM_GENREGS;
1644   
1645   /* Assume nothing about the layout of the cris_spec_regs struct
1646      when searching.  */
1647   for (i = 0; cris_spec_regs[i].name != NULL; i++)
1648     {
1649       if (cris_spec_regs[i].number == spec_regno 
1650           && cris_spec_reg_applicable (gdbarch, cris_spec_regs[i]))
1651         /* Go with the first applicable register.  */
1652         return cris_spec_regs[i].name;
1653     }
1654   /* Special register not applicable to this CRIS version.  */
1655   return NULL;
1656 }
1657
1658 static const char *
1659 cris_register_name (struct gdbarch *gdbarch, int regno)
1660 {
1661   static const char *cris_genreg_names[] =
1662   { "r0",  "r1",  "r2",  "r3", \
1663     "r4",  "r5",  "r6",  "r7", \
1664     "r8",  "r9",  "r10", "r11", \
1665     "r12", "r13", "sp",  "pc" };
1666
1667   if (regno >= 0 && regno < NUM_GENREGS)
1668     {
1669       /* General register.  */
1670       return cris_genreg_names[regno];
1671     }
1672   else if (regno >= NUM_GENREGS && regno < gdbarch_num_regs (gdbarch))
1673     {
1674       return cris_special_register_name (gdbarch, regno);
1675     }
1676   else
1677     {
1678       /* Invalid register.  */
1679       return NULL;
1680     }
1681 }
1682
1683 static const char *
1684 crisv32_register_name (struct gdbarch *gdbarch, int regno)
1685 {
1686   static const char *crisv32_genreg_names[] =
1687     { "r0",  "r1",  "r2",  "r3", \
1688       "r4",  "r5",  "r6",  "r7", \
1689       "r8",  "r9",  "r10", "r11", \
1690       "r12", "r13", "sp",  "acr"
1691     };
1692
1693   static const char *crisv32_sreg_names[] =
1694     { "s0",  "s1",  "s2",  "s3", \
1695       "s4",  "s5",  "s6",  "s7", \
1696       "s8",  "s9",  "s10", "s11", \
1697       "s12", "s13", "s14",  "s15"
1698     };
1699
1700   if (regno >= 0 && regno < NUM_GENREGS)
1701     {
1702       /* General register.  */
1703       return crisv32_genreg_names[regno];
1704     }
1705   else if (regno >= NUM_GENREGS && regno < (NUM_GENREGS + NUM_SPECREGS))
1706     {
1707       return cris_special_register_name (gdbarch, regno);
1708     }
1709   else if (regno == gdbarch_pc_regnum (gdbarch))
1710     {
1711       return "pc";
1712     }
1713   else if (regno >= S0_REGNUM && regno <= S15_REGNUM)
1714     {
1715       return crisv32_sreg_names[regno - S0_REGNUM];
1716     }
1717   else
1718     {
1719       /* Invalid register.  */
1720       return NULL;
1721     }
1722 }
1723
1724 /* Convert DWARF register number REG to the appropriate register
1725    number used by GDB.  */
1726
1727 static int
1728 cris_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int reg)
1729 {
1730   /* We need to re-map a couple of registers (SRP is 16 in Dwarf-2 register
1731      numbering, MOF is 18).
1732      Adapted from gcc/config/cris/cris.h.  */
1733   static int cris_dwarf_regmap[] = {
1734     0,  1,  2,  3,
1735     4,  5,  6,  7,
1736     8,  9,  10, 11,
1737     12, 13, 14, 15,
1738     27, -1, -1, -1,
1739     -1, -1, -1, 23,
1740     -1, -1, -1, 27,
1741     -1, -1, -1, -1
1742   };
1743   int regnum = -1;
1744
1745   if (reg >= 0 && reg < ARRAY_SIZE (cris_dwarf_regmap))
1746     regnum = cris_dwarf_regmap[reg];
1747
1748   return regnum;
1749 }
1750
1751 /* DWARF-2 frame support.  */
1752
1753 static void
1754 cris_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
1755                             struct dwarf2_frame_state_reg *reg,
1756                             struct frame_info *this_frame)
1757 {
1758   /* The return address column.  */
1759   if (regnum == gdbarch_pc_regnum (gdbarch))
1760     reg->how = DWARF2_FRAME_REG_RA;
1761
1762   /* The call frame address.  */
1763   else if (regnum == gdbarch_sp_regnum (gdbarch))
1764     reg->how = DWARF2_FRAME_REG_CFA;
1765 }
1766
1767 /* Extract from an array regbuf containing the raw register state a function
1768    return value of type type, and copy that, in virtual format, into 
1769    valbuf.  */
1770
1771 /* In the CRIS ABI, R10 and R11 are used to store return values.  */
1772
1773 static void
1774 cris_extract_return_value (struct type *type, struct regcache *regcache,
1775                            gdb_byte *valbuf)
1776 {
1777   struct gdbarch *gdbarch = regcache->arch ();
1778   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1779   ULONGEST val;
1780   int len = TYPE_LENGTH (type);
1781   
1782   if (len <= 4)
1783     {
1784       /* Get the return value from R10.  */
1785       regcache_cooked_read_unsigned (regcache, ARG1_REGNUM, &val);
1786       store_unsigned_integer (valbuf, len, byte_order, val);
1787     }
1788   else if (len <= 8)
1789     {
1790       /* Get the return value from R10 and R11.  */
1791       regcache_cooked_read_unsigned (regcache, ARG1_REGNUM, &val);
1792       store_unsigned_integer (valbuf, 4, byte_order, val);
1793       regcache_cooked_read_unsigned (regcache, ARG2_REGNUM, &val);
1794       store_unsigned_integer (valbuf + 4, len - 4, byte_order, val);
1795     }
1796   else
1797     error (_("cris_extract_return_value: type length too large"));
1798 }
1799
1800 /* Handle the CRIS return value convention.  */
1801
1802 static enum return_value_convention
1803 cris_return_value (struct gdbarch *gdbarch, struct value *function,
1804                    struct type *type, struct regcache *regcache,
1805                    gdb_byte *readbuf, const gdb_byte *writebuf)
1806 {
1807   if (TYPE_CODE (type) == TYPE_CODE_STRUCT 
1808       || TYPE_CODE (type) == TYPE_CODE_UNION
1809       || TYPE_LENGTH (type) > 8)
1810     /* Structs, unions, and anything larger than 8 bytes (2 registers)
1811        goes on the stack.  */
1812     return RETURN_VALUE_STRUCT_CONVENTION;
1813
1814   if (readbuf)
1815     cris_extract_return_value (type, regcache, readbuf);
1816   if (writebuf)
1817     cris_store_return_value (type, regcache, writebuf);
1818
1819   return RETURN_VALUE_REGISTER_CONVENTION;
1820 }
1821
1822 /* Calculates a value that measures how good inst_args constraints an 
1823    instruction.  It stems from cris_constraint, found in cris-dis.c.  */
1824
1825 static int
1826 constraint (unsigned int insn, const char *inst_args,
1827             inst_env_type *inst_env)
1828 {
1829   int retval = 0;
1830   int tmp, i;
1831
1832   const gdb_byte *s = (const gdb_byte *) inst_args;
1833
1834   for (; *s; s++)
1835     switch (*s) 
1836       {
1837       case 'm':
1838         if ((insn & 0x30) == 0x30)
1839           return -1;
1840         break;
1841         
1842       case 'S':
1843         /* A prefix operand.  */
1844         if (inst_env->prefix_found)
1845           break;
1846         else
1847           return -1;
1848
1849       case 'B':
1850         /* A "push" prefix.  (This check was REMOVED by san 970921.)  Check for
1851            valid "push" size.  In case of special register, it may be != 4.  */
1852         if (inst_env->prefix_found)
1853           break;
1854         else
1855           return -1;
1856
1857       case 'D':
1858         retval = (((insn >> 0xC) & 0xF) == (insn & 0xF));
1859         if (!retval)
1860           return -1;
1861         else 
1862           retval += 4;
1863         break;
1864
1865       case 'P':
1866         tmp = (insn >> 0xC) & 0xF;
1867
1868         for (i = 0; cris_spec_regs[i].name != NULL; i++)
1869           {
1870             /* Since we match four bits, we will give a value of
1871                4 - 1 = 3 in a match.  If there is a corresponding
1872                exact match of a special register in another pattern, it
1873                will get a value of 4, which will be higher.  This should
1874                be correct in that an exact pattern would match better that
1875                a general pattern.
1876                Note that there is a reason for not returning zero; the
1877                pattern for "clear" is partly  matched in the bit-pattern
1878                (the two lower bits must be zero), while the bit-pattern
1879                for a move from a special register is matched in the
1880                register constraint.
1881                This also means we will will have a race condition if
1882                there is a partly match in three bits in the bit pattern.  */
1883             if (tmp == cris_spec_regs[i].number)
1884               {
1885                 retval += 3;
1886                 break;
1887               }
1888           }
1889         
1890         if (cris_spec_regs[i].name == NULL)
1891           return -1;
1892         break;
1893       }
1894   return retval;
1895 }
1896
1897 /* Returns the number of bits set in the variable value.  */
1898
1899 static int
1900 number_of_bits (unsigned int value)
1901 {
1902   int number_of_bits = 0;
1903   
1904   while (value != 0)
1905     {
1906       number_of_bits += 1;
1907       value &= (value - 1);
1908     }
1909   return number_of_bits;
1910 }
1911
1912 /* Finds the address that should contain the single step breakpoint(s). 
1913    It stems from code in cris-dis.c.  */
1914
1915 static int
1916 find_cris_op (unsigned short insn, inst_env_type *inst_env)
1917 {
1918   int i;
1919   int max_level_of_match = -1;
1920   int max_matched = -1;
1921   int level_of_match;
1922
1923   for (i = 0; cris_opcodes[i].name != NULL; i++)
1924     {
1925       if (((cris_opcodes[i].match & insn) == cris_opcodes[i].match) 
1926           && ((cris_opcodes[i].lose & insn) == 0)
1927           /* Only CRISv10 instructions, please.  */
1928           && (cris_opcodes[i].applicable_version != cris_ver_v32p))
1929         {
1930           level_of_match = constraint (insn, cris_opcodes[i].args, inst_env);
1931           if (level_of_match >= 0)
1932             {
1933               level_of_match +=
1934                 number_of_bits (cris_opcodes[i].match | cris_opcodes[i].lose);
1935               if (level_of_match > max_level_of_match)
1936                 {
1937                   max_matched = i;
1938                   max_level_of_match = level_of_match;
1939                   if (level_of_match == 16)
1940                     {
1941                       /* All bits matched, cannot find better.  */
1942                       break;
1943                     }
1944                 }
1945             }
1946         }
1947     }
1948   return max_matched;
1949 }
1950
1951 /* Attempts to find single-step breakpoints.  Returns -1 on failure which is
1952    actually an internal error.  */
1953
1954 static int
1955 find_step_target (struct regcache *regcache, inst_env_type *inst_env)
1956 {
1957   int i;
1958   int offset;
1959   unsigned short insn;
1960   struct gdbarch *gdbarch = regcache->arch ();
1961   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1962
1963   /* Create a local register image and set the initial state.  */
1964   for (i = 0; i < NUM_GENREGS; i++)
1965     {
1966       inst_env->reg[i] = 
1967         (unsigned long) regcache_raw_get_unsigned (regcache, i);
1968     }
1969   offset = NUM_GENREGS;
1970   for (i = 0; i < NUM_SPECREGS; i++)
1971     {
1972       inst_env->preg[i] = 
1973         (unsigned long) regcache_raw_get_unsigned (regcache, offset + i);
1974     }
1975   inst_env->branch_found = 0;
1976   inst_env->slot_needed = 0;
1977   inst_env->delay_slot_pc_active = 0;
1978   inst_env->prefix_found = 0;
1979   inst_env->invalid = 0;
1980   inst_env->xflag_found = 0;
1981   inst_env->disable_interrupt = 0;
1982   inst_env->byte_order = byte_order;
1983
1984   /* Look for a step target.  */
1985   do
1986     {
1987       /* Read an instruction from the client.  */
1988       insn = read_memory_unsigned_integer
1989              (inst_env->reg[gdbarch_pc_regnum (gdbarch)], 2, byte_order);
1990
1991       /* If the instruction is not in a delay slot the new content of the
1992          PC is [PC] + 2.  If the instruction is in a delay slot it is not
1993          that simple.  Since a instruction in a delay slot cannot change 
1994          the content of the PC, it does not matter what value PC will have. 
1995          Just make sure it is a valid instruction.  */
1996       if (!inst_env->delay_slot_pc_active)
1997         {
1998           inst_env->reg[gdbarch_pc_regnum (gdbarch)] += 2;
1999         }
2000       else
2001         {
2002           inst_env->delay_slot_pc_active = 0;
2003           inst_env->reg[gdbarch_pc_regnum (gdbarch)]
2004             = inst_env->delay_slot_pc;
2005         }
2006       /* Analyse the present instruction.  */
2007       i = find_cris_op (insn, inst_env);
2008       if (i == -1)
2009         {
2010           inst_env->invalid = 1;
2011         }
2012       else
2013         {
2014           cris_gdb_func (gdbarch, cris_opcodes[i].op, insn, inst_env);
2015         }
2016     } while (!inst_env->invalid 
2017              && (inst_env->prefix_found || inst_env->xflag_found 
2018                  || inst_env->slot_needed));
2019   return i;
2020 }
2021
2022 /* There is no hardware single-step support.  The function find_step_target
2023    digs through the opcodes in order to find all possible targets.
2024    Either one ordinary target or two targets for branches may be found.  */
2025
2026 static std::vector<CORE_ADDR>
2027 cris_software_single_step (struct regcache *regcache)
2028 {
2029   struct gdbarch *gdbarch = regcache->arch ();
2030   inst_env_type inst_env;
2031   std::vector<CORE_ADDR> next_pcs;
2032
2033   /* Analyse the present instruction environment and insert 
2034      breakpoints.  */
2035   int status = find_step_target (regcache, &inst_env);
2036   if (status == -1)
2037     {
2038       /* Could not find a target.  Things are likely to go downhill 
2039          from here.  */
2040       warning (_("CRIS software single step could not find a step target."));
2041     }
2042   else
2043     {
2044       /* Insert at most two breakpoints.  One for the next PC content
2045          and possibly another one for a branch, jump, etc.  */
2046       CORE_ADDR next_pc
2047         = (CORE_ADDR) inst_env.reg[gdbarch_pc_regnum (gdbarch)];
2048
2049       next_pcs.push_back (next_pc);
2050       if (inst_env.branch_found 
2051           && (CORE_ADDR) inst_env.branch_break_address != next_pc)
2052         {
2053           CORE_ADDR branch_target_address
2054                 = (CORE_ADDR) inst_env.branch_break_address;
2055
2056           next_pcs.push_back (branch_target_address);
2057         }
2058     }
2059
2060   return next_pcs;
2061 }
2062
2063 /* Calculates the prefix value for quick offset addressing mode.  */
2064
2065 static void
2066 quick_mode_bdap_prefix (unsigned short inst, inst_env_type *inst_env)
2067 {
2068   /* It's invalid to be in a delay slot.  You can't have a prefix to this
2069      instruction (not 100% sure).  */
2070   if (inst_env->slot_needed || inst_env->prefix_found)
2071     {
2072       inst_env->invalid = 1;
2073       return; 
2074     }
2075  
2076   inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)];
2077   inst_env->prefix_value += cris_get_bdap_quick_offset (inst);
2078
2079   /* A prefix doesn't change the xflag_found.  But the rest of the flags
2080      need updating.  */
2081   inst_env->slot_needed = 0;
2082   inst_env->prefix_found = 1;
2083 }
2084
2085 /* Updates the autoincrement register.  The size of the increment is derived 
2086    from the size of the operation.  The PC is always kept aligned on even
2087    word addresses.  */
2088
2089 static void 
2090 process_autoincrement (int size, unsigned short inst, inst_env_type *inst_env)
2091 {
2092   if (size == INST_BYTE_SIZE)
2093     {
2094       inst_env->reg[cris_get_operand1 (inst)] += 1;
2095
2096       /* The PC must be word aligned, so increase the PC with one
2097          word even if the size is byte.  */
2098       if (cris_get_operand1 (inst) == REG_PC)
2099         {
2100           inst_env->reg[REG_PC] += 1;
2101         }
2102     }
2103   else if (size == INST_WORD_SIZE)
2104     {
2105       inst_env->reg[cris_get_operand1 (inst)] += 2;
2106     }
2107   else if (size == INST_DWORD_SIZE)
2108     {
2109       inst_env->reg[cris_get_operand1 (inst)] += 4;
2110     }
2111   else
2112     {
2113       /* Invalid size.  */
2114       inst_env->invalid = 1;
2115     }
2116 }
2117
2118 /* Just a forward declaration.  */
2119
2120 static unsigned long get_data_from_address (unsigned short *inst,
2121                                             CORE_ADDR address,
2122                                             enum bfd_endian byte_order);
2123
2124 /* Calculates the prefix value for the general case of offset addressing 
2125    mode.  */
2126
2127 static void
2128 bdap_prefix (unsigned short inst, inst_env_type *inst_env)
2129 {
2130   /* It's invalid to be in a delay slot.  */
2131   if (inst_env->slot_needed || inst_env->prefix_found)
2132     {
2133       inst_env->invalid = 1;
2134       return; 
2135     }
2136
2137   /* The calculation of prefix_value used to be after process_autoincrement,
2138      but that fails for an instruction such as jsr [$r0+12] which is encoded
2139      as 5f0d 0c00 30b9 when compiled with -fpic.  Since PC is operand1 it
2140      mustn't be incremented until we have read it and what it points at.  */
2141   inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)];
2142
2143   /* The offset is an indirection of the contents of the operand1 register.  */
2144   inst_env->prefix_value += 
2145     get_data_from_address (&inst, inst_env->reg[cris_get_operand1 (inst)],
2146                            inst_env->byte_order);
2147   
2148   if (cris_get_mode (inst) == AUTOINC_MODE)
2149     {
2150       process_autoincrement (cris_get_size (inst), inst, inst_env); 
2151     }
2152    
2153   /* A prefix doesn't change the xflag_found.  But the rest of the flags
2154      need updating.  */
2155   inst_env->slot_needed = 0;
2156   inst_env->prefix_found = 1;
2157 }
2158
2159 /* Calculates the prefix value for the index addressing mode.  */
2160
2161 static void
2162 biap_prefix (unsigned short inst, inst_env_type *inst_env)
2163 {
2164   /* It's invalid to be in a delay slot.  I can't see that it's possible to
2165      have a prefix to this instruction.  So I will treat this as invalid.  */
2166   if (inst_env->slot_needed || inst_env->prefix_found)
2167     {
2168       inst_env->invalid = 1;
2169       return;
2170     }
2171   
2172   inst_env->prefix_value = inst_env->reg[cris_get_operand1 (inst)];
2173
2174   /* The offset is the operand2 value shifted the size of the instruction 
2175      to the left.  */
2176   inst_env->prefix_value += 
2177     inst_env->reg[cris_get_operand2 (inst)] << cris_get_size (inst);
2178   
2179   /* If the PC is operand1 (base) the address used is the address after 
2180      the main instruction, i.e. address + 2 (the PC is already compensated
2181      for the prefix operation).  */
2182   if (cris_get_operand1 (inst) == REG_PC)
2183     {
2184       inst_env->prefix_value += 2;
2185     }
2186
2187   /* A prefix doesn't change the xflag_found.  But the rest of the flags
2188      need updating.  */
2189   inst_env->slot_needed = 0;
2190   inst_env->xflag_found = 0;
2191   inst_env->prefix_found = 1;
2192 }
2193
2194 /* Calculates the prefix value for the double indirect addressing mode.  */
2195
2196 static void 
2197 dip_prefix (unsigned short inst, inst_env_type *inst_env)
2198 {
2199
2200   CORE_ADDR address;
2201
2202   /* It's invalid to be in a delay slot.  */
2203   if (inst_env->slot_needed || inst_env->prefix_found)
2204     {
2205       inst_env->invalid = 1;
2206       return;
2207     }
2208   
2209   /* The prefix value is one dereference of the contents of the operand1
2210      register.  */
2211   address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)];
2212   inst_env->prefix_value
2213     = read_memory_unsigned_integer (address, 4, inst_env->byte_order);
2214     
2215   /* Check if the mode is autoincrement.  */
2216   if (cris_get_mode (inst) == AUTOINC_MODE)
2217     {
2218       inst_env->reg[cris_get_operand1 (inst)] += 4;
2219     }
2220
2221   /* A prefix doesn't change the xflag_found.  But the rest of the flags
2222      need updating.  */
2223   inst_env->slot_needed = 0;
2224   inst_env->xflag_found = 0;
2225   inst_env->prefix_found = 1;
2226 }
2227
2228 /* Finds the destination for a branch with 8-bits offset.  */
2229
2230 static void
2231 eight_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env)
2232 {
2233
2234   short offset;
2235
2236   /* If we have a prefix or are in a delay slot it's bad.  */
2237   if (inst_env->slot_needed || inst_env->prefix_found)
2238     {
2239       inst_env->invalid = 1;
2240       return;
2241     }
2242   
2243   /* We have a branch, find out where the branch will land.  */
2244   offset = cris_get_branch_short_offset (inst);
2245
2246   /* Check if the offset is signed.  */
2247   if (offset & BRANCH_SIGNED_SHORT_OFFSET_MASK)
2248     {
2249       offset |= 0xFF00;
2250     }
2251   
2252   /* The offset ends with the sign bit, set it to zero.  The address
2253      should always be word aligned.  */
2254   offset &= ~BRANCH_SIGNED_SHORT_OFFSET_MASK;
2255   
2256   inst_env->branch_found = 1;
2257   inst_env->branch_break_address = inst_env->reg[REG_PC] + offset;
2258
2259   inst_env->slot_needed = 1;
2260   inst_env->prefix_found = 0;
2261   inst_env->xflag_found = 0;
2262   inst_env->disable_interrupt = 1;
2263 }
2264
2265 /* Finds the destination for a branch with 16-bits offset.  */
2266
2267 static void 
2268 sixteen_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env)
2269 {
2270   short offset;
2271
2272   /* If we have a prefix or is in a delay slot it's bad.  */
2273   if (inst_env->slot_needed || inst_env->prefix_found)
2274     {
2275       inst_env->invalid = 1;
2276       return;
2277     }
2278
2279   /* We have a branch, find out the offset for the branch.  */
2280   offset = read_memory_integer (inst_env->reg[REG_PC], 2,
2281                                 inst_env->byte_order);
2282
2283   /* The instruction is one word longer than normal, so add one word
2284      to the PC.  */
2285   inst_env->reg[REG_PC] += 2;
2286
2287   inst_env->branch_found = 1;
2288   inst_env->branch_break_address = inst_env->reg[REG_PC] + offset;
2289
2290
2291   inst_env->slot_needed = 1;
2292   inst_env->prefix_found = 0;
2293   inst_env->xflag_found = 0;
2294   inst_env->disable_interrupt = 1;
2295 }
2296
2297 /* Handles the ABS instruction.  */
2298
2299 static void 
2300 abs_op (unsigned short inst, inst_env_type *inst_env)
2301 {
2302
2303   long value;
2304   
2305   /* ABS can't have a prefix, so it's bad if it does.  */
2306   if (inst_env->prefix_found)
2307     {
2308       inst_env->invalid = 1;
2309       return;
2310     }
2311
2312   /* Check if the operation affects the PC.  */
2313   if (cris_get_operand2 (inst) == REG_PC)
2314     {
2315     
2316       /* It's invalid to change to the PC if we are in a delay slot.  */
2317       if (inst_env->slot_needed)
2318         {
2319           inst_env->invalid = 1;
2320           return;
2321         }
2322
2323       value = (long) inst_env->reg[REG_PC];
2324
2325       /* The value of abs (SIGNED_DWORD_MASK) is SIGNED_DWORD_MASK.  */
2326       if (value != SIGNED_DWORD_MASK)
2327         {
2328           value = -value;
2329           inst_env->reg[REG_PC] = (long) value;
2330         }
2331     }
2332
2333   inst_env->slot_needed = 0;
2334   inst_env->prefix_found = 0;
2335   inst_env->xflag_found = 0;
2336   inst_env->disable_interrupt = 0;
2337 }
2338
2339 /* Handles the ADDI instruction.  */
2340
2341 static void 
2342 addi_op (unsigned short inst, inst_env_type *inst_env)
2343 {
2344   /* It's invalid to have the PC as base register.  And ADDI can't have
2345      a prefix.  */
2346   if (inst_env->prefix_found || (cris_get_operand1 (inst) == REG_PC))
2347     {
2348       inst_env->invalid = 1;
2349       return;
2350     }
2351
2352   inst_env->slot_needed = 0;
2353   inst_env->prefix_found = 0;
2354   inst_env->xflag_found = 0;
2355   inst_env->disable_interrupt = 0;
2356 }
2357
2358 /* Handles the ASR instruction.  */
2359
2360 static void 
2361 asr_op (unsigned short inst, inst_env_type *inst_env)
2362 {
2363   int shift_steps;
2364   unsigned long value;
2365   unsigned long signed_extend_mask = 0;
2366
2367   /* ASR can't have a prefix, so check that it doesn't.  */
2368   if (inst_env->prefix_found)
2369     {
2370       inst_env->invalid = 1;
2371       return;
2372     }
2373
2374   /* Check if the PC is the target register.  */
2375   if (cris_get_operand2 (inst) == REG_PC)
2376     {
2377       /* It's invalid to change the PC in a delay slot.  */
2378       if (inst_env->slot_needed)
2379         {
2380           inst_env->invalid = 1;
2381           return;
2382         }
2383       /* Get the number of bits to shift.  */
2384       shift_steps
2385         = cris_get_asr_shift_steps (inst_env->reg[cris_get_operand1 (inst)]);
2386       value = inst_env->reg[REG_PC];
2387
2388       /* Find out how many bits the operation should apply to.  */
2389       if (cris_get_size (inst) == INST_BYTE_SIZE)
2390         {
2391           if (value & SIGNED_BYTE_MASK)
2392             {
2393               signed_extend_mask = 0xFF;
2394               signed_extend_mask = signed_extend_mask >> shift_steps;
2395               signed_extend_mask = ~signed_extend_mask;
2396             }
2397           value = value >> shift_steps;
2398           value |= signed_extend_mask;
2399           value &= 0xFF;
2400           inst_env->reg[REG_PC] &= 0xFFFFFF00;
2401           inst_env->reg[REG_PC] |= value;
2402         }
2403       else if (cris_get_size (inst) == INST_WORD_SIZE)
2404         {
2405           if (value & SIGNED_WORD_MASK)
2406             {
2407               signed_extend_mask = 0xFFFF;
2408               signed_extend_mask = signed_extend_mask >> shift_steps;
2409               signed_extend_mask = ~signed_extend_mask;
2410             }
2411           value = value >> shift_steps;
2412           value |= signed_extend_mask;
2413           value &= 0xFFFF;
2414           inst_env->reg[REG_PC] &= 0xFFFF0000;
2415           inst_env->reg[REG_PC] |= value;
2416         }
2417       else if (cris_get_size (inst) == INST_DWORD_SIZE)
2418         {
2419           if (value & SIGNED_DWORD_MASK)
2420             {
2421               signed_extend_mask = 0xFFFFFFFF;
2422               signed_extend_mask = signed_extend_mask >> shift_steps;
2423               signed_extend_mask = ~signed_extend_mask;
2424             }
2425           value = value >> shift_steps;
2426           value |= signed_extend_mask;
2427           inst_env->reg[REG_PC]  = value;
2428         }
2429     }
2430   inst_env->slot_needed = 0;
2431   inst_env->prefix_found = 0;
2432   inst_env->xflag_found = 0;
2433   inst_env->disable_interrupt = 0;
2434 }
2435
2436 /* Handles the ASRQ instruction.  */
2437
2438 static void 
2439 asrq_op (unsigned short inst, inst_env_type *inst_env)
2440 {
2441
2442   int shift_steps;
2443   unsigned long value;
2444   unsigned long signed_extend_mask = 0;
2445   
2446   /* ASRQ can't have a prefix, so check that it doesn't.  */
2447   if (inst_env->prefix_found)
2448     {
2449       inst_env->invalid = 1;
2450       return;
2451     }
2452
2453   /* Check if the PC is the target register.  */
2454   if (cris_get_operand2 (inst) == REG_PC)
2455     {
2456
2457       /* It's invalid to change the PC in a delay slot.  */
2458       if (inst_env->slot_needed)
2459         {
2460           inst_env->invalid = 1;
2461           return;
2462         }
2463       /* The shift size is given as a 5 bit quick value, i.e. we don't
2464          want the sign bit of the quick value.  */
2465       shift_steps = cris_get_asr_shift_steps (inst);
2466       value = inst_env->reg[REG_PC];
2467       if (value & SIGNED_DWORD_MASK)
2468         {
2469           signed_extend_mask = 0xFFFFFFFF;
2470           signed_extend_mask = signed_extend_mask >> shift_steps;
2471           signed_extend_mask = ~signed_extend_mask;
2472         }
2473       value = value >> shift_steps;
2474       value |= signed_extend_mask;
2475       inst_env->reg[REG_PC]  = value;
2476     }
2477   inst_env->slot_needed = 0;
2478   inst_env->prefix_found = 0;
2479   inst_env->xflag_found = 0;
2480   inst_env->disable_interrupt = 0;
2481 }
2482
2483 /* Handles the AX, EI and SETF instruction.  */
2484
2485 static void 
2486 ax_ei_setf_op (unsigned short inst, inst_env_type *inst_env)
2487 {
2488   if (inst_env->prefix_found)
2489     {
2490       inst_env->invalid = 1;
2491       return;
2492     }
2493   /* Check if the instruction is setting the X flag.  */
2494   if (cris_is_xflag_bit_on (inst))
2495     {
2496       inst_env->xflag_found = 1;
2497     }
2498   else
2499     {
2500       inst_env->xflag_found = 0;
2501     }
2502   inst_env->slot_needed = 0;
2503   inst_env->prefix_found = 0;
2504   inst_env->disable_interrupt = 1;
2505 }
2506
2507 /* Checks if the instruction is in assign mode.  If so, it updates the assign 
2508    register.  Note that check_assign assumes that the caller has checked that
2509    there is a prefix to this instruction.  The mode check depends on this.  */
2510
2511 static void 
2512 check_assign (unsigned short inst, inst_env_type *inst_env)
2513 {
2514   /* Check if it's an assign addressing mode.  */
2515   if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2516     {
2517       /* Assign the prefix value to operand 1.  */
2518       inst_env->reg[cris_get_operand1 (inst)] = inst_env->prefix_value;
2519     }
2520 }
2521
2522 /* Handles the 2-operand BOUND instruction.  */
2523
2524 static void 
2525 two_operand_bound_op (unsigned short inst, inst_env_type *inst_env)
2526 {
2527   /* It's invalid to have the PC as the index operand.  */
2528   if (cris_get_operand2 (inst) == REG_PC)
2529     {
2530       inst_env->invalid = 1;
2531       return;
2532     }
2533   /* Check if we have a prefix.  */
2534   if (inst_env->prefix_found)
2535     {
2536       check_assign (inst, inst_env);
2537     }
2538   /* Check if this is an autoincrement mode.  */
2539   else if (cris_get_mode (inst) == AUTOINC_MODE)
2540     {
2541       /* It's invalid to change the PC in a delay slot.  */
2542       if (inst_env->slot_needed)
2543         {
2544           inst_env->invalid = 1;
2545           return;
2546         }
2547       process_autoincrement (cris_get_size (inst), inst, inst_env);
2548     }
2549   inst_env->slot_needed = 0;
2550   inst_env->prefix_found = 0;
2551   inst_env->xflag_found = 0;
2552   inst_env->disable_interrupt = 0;
2553 }
2554
2555 /* Handles the 3-operand BOUND instruction.  */
2556
2557 static void 
2558 three_operand_bound_op (unsigned short inst, inst_env_type *inst_env)
2559 {
2560   /* It's an error if we haven't got a prefix.  And it's also an error
2561      if the PC is the destination register.  */
2562   if ((!inst_env->prefix_found) || (cris_get_operand1 (inst) == REG_PC))
2563     {
2564       inst_env->invalid = 1;
2565       return;
2566     }
2567   inst_env->slot_needed = 0;
2568   inst_env->prefix_found = 0;
2569   inst_env->xflag_found = 0;
2570   inst_env->disable_interrupt = 0;
2571 }
2572
2573 /* Clears the status flags in inst_env.  */
2574
2575 static void 
2576 btst_nop_op (unsigned short inst, inst_env_type *inst_env)
2577 {
2578   /* It's an error if we have got a prefix.  */
2579   if (inst_env->prefix_found)
2580     {
2581       inst_env->invalid = 1;
2582       return;
2583     }
2584
2585   inst_env->slot_needed = 0;
2586   inst_env->prefix_found = 0;
2587   inst_env->xflag_found = 0;
2588   inst_env->disable_interrupt = 0;
2589 }
2590
2591 /* Clears the status flags in inst_env.  */
2592
2593 static void 
2594 clearf_di_op (unsigned short inst, inst_env_type *inst_env)
2595 {
2596   /* It's an error if we have got a prefix.  */
2597   if (inst_env->prefix_found)
2598     {
2599       inst_env->invalid = 1;
2600       return;
2601     }
2602
2603   inst_env->slot_needed = 0;
2604   inst_env->prefix_found = 0;
2605   inst_env->xflag_found = 0;
2606   inst_env->disable_interrupt = 1;
2607 }
2608
2609 /* Handles the CLEAR instruction if it's in register mode.  */
2610
2611 static void 
2612 reg_mode_clear_op (unsigned short inst, inst_env_type *inst_env)
2613 {
2614   /* Check if the target is the PC.  */
2615   if (cris_get_operand2 (inst) == REG_PC)
2616     {
2617       /* The instruction will clear the instruction's size bits.  */
2618       int clear_size = cris_get_clear_size (inst);
2619       if (clear_size == INST_BYTE_SIZE)
2620         {
2621           inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFFFF00;
2622         }
2623       if (clear_size == INST_WORD_SIZE)
2624         {
2625           inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFF0000;
2626         }
2627       if (clear_size == INST_DWORD_SIZE)
2628         {
2629           inst_env->delay_slot_pc = 0x0;
2630         }
2631       /* The jump will be delayed with one delay slot.  So we need a delay 
2632          slot.  */
2633       inst_env->slot_needed = 1;
2634       inst_env->delay_slot_pc_active = 1;
2635     }
2636   else
2637     {
2638       /* The PC will not change => no delay slot.  */
2639       inst_env->slot_needed = 0;
2640     }
2641   inst_env->prefix_found = 0;
2642   inst_env->xflag_found = 0;
2643   inst_env->disable_interrupt = 0;
2644 }
2645
2646 /* Handles the TEST instruction if it's in register mode.  */
2647
2648 static void
2649 reg_mode_test_op (unsigned short inst, inst_env_type *inst_env)
2650 {
2651   /* It's an error if we have got a prefix.  */
2652   if (inst_env->prefix_found)
2653     {
2654       inst_env->invalid = 1;
2655       return;
2656     }
2657   inst_env->slot_needed = 0;
2658   inst_env->prefix_found = 0;
2659   inst_env->xflag_found = 0;
2660   inst_env->disable_interrupt = 0;
2661
2662 }
2663
2664 /* Handles the CLEAR and TEST instruction if the instruction isn't 
2665    in register mode.  */
2666
2667 static void 
2668 none_reg_mode_clear_test_op (unsigned short inst, inst_env_type *inst_env)
2669 {
2670   /* Check if we are in a prefix mode.  */
2671   if (inst_env->prefix_found)
2672     {
2673       /* The only way the PC can change is if this instruction is in
2674          assign addressing mode.  */
2675       check_assign (inst, inst_env);
2676     }
2677   /* Indirect mode can't change the PC so just check if the mode is
2678      autoincrement.  */
2679   else if (cris_get_mode (inst) == AUTOINC_MODE)
2680     {
2681       process_autoincrement (cris_get_size (inst), inst, inst_env);
2682     }
2683   inst_env->slot_needed = 0;
2684   inst_env->prefix_found = 0;
2685   inst_env->xflag_found = 0;
2686   inst_env->disable_interrupt = 0;
2687 }
2688
2689 /* Checks that the PC isn't the destination register or the instructions has
2690    a prefix.  */
2691
2692 static void 
2693 dstep_logshift_mstep_neg_not_op (unsigned short inst, inst_env_type *inst_env)
2694 {
2695   /* It's invalid to have the PC as the destination.  The instruction can't
2696      have a prefix.  */
2697   if ((cris_get_operand2 (inst) == REG_PC) || inst_env->prefix_found)
2698     {
2699       inst_env->invalid = 1;
2700       return;
2701     }
2702
2703   inst_env->slot_needed = 0;
2704   inst_env->prefix_found = 0;
2705   inst_env->xflag_found = 0;
2706   inst_env->disable_interrupt = 0;
2707 }
2708
2709 /* Checks that the instruction doesn't have a prefix.  */
2710
2711 static void
2712 break_op (unsigned short inst, inst_env_type *inst_env)
2713 {
2714   /* The instruction can't have a prefix.  */
2715   if (inst_env->prefix_found)
2716     {
2717       inst_env->invalid = 1;
2718       return;
2719     }
2720
2721   inst_env->slot_needed = 0;
2722   inst_env->prefix_found = 0;
2723   inst_env->xflag_found = 0;
2724   inst_env->disable_interrupt = 1;
2725 }
2726
2727 /* Checks that the PC isn't the destination register and that the instruction
2728    doesn't have a prefix.  */
2729
2730 static void
2731 scc_op (unsigned short inst, inst_env_type *inst_env)
2732 {
2733   /* It's invalid to have the PC as the destination.  The instruction can't
2734      have a prefix.  */
2735   if ((cris_get_operand2 (inst) == REG_PC) || inst_env->prefix_found)
2736     {
2737       inst_env->invalid = 1;
2738       return;
2739     }
2740
2741   inst_env->slot_needed = 0;
2742   inst_env->prefix_found = 0;
2743   inst_env->xflag_found = 0;
2744   inst_env->disable_interrupt = 1;
2745 }
2746
2747 /* Handles the register mode JUMP instruction.  */
2748
2749 static void 
2750 reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env)
2751 {
2752   /* It's invalid to do a JUMP in a delay slot.  The mode is register, so 
2753      you can't have a prefix.  */
2754   if ((inst_env->slot_needed) || (inst_env->prefix_found))
2755     {
2756       inst_env->invalid = 1;
2757       return;
2758     }
2759   
2760   /* Just change the PC.  */
2761   inst_env->reg[REG_PC] = inst_env->reg[cris_get_operand1 (inst)];
2762   inst_env->slot_needed = 0;
2763   inst_env->prefix_found = 0;
2764   inst_env->xflag_found = 0;
2765   inst_env->disable_interrupt = 1;
2766 }
2767
2768 /* Handles the JUMP instruction for all modes except register.  */
2769
2770 static void
2771 none_reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env)
2772 {
2773   unsigned long newpc;
2774   CORE_ADDR address;
2775
2776   /* It's invalid to do a JUMP in a delay slot.  */
2777   if (inst_env->slot_needed)
2778     {
2779       inst_env->invalid = 1;
2780     }
2781   else
2782     {
2783       /* Check if we have a prefix.  */
2784       if (inst_env->prefix_found)
2785         {
2786           check_assign (inst, inst_env);
2787
2788           /* Get the new value for the PC.  */
2789           newpc = 
2790             read_memory_unsigned_integer ((CORE_ADDR) inst_env->prefix_value,
2791                                           4, inst_env->byte_order);
2792         }
2793       else
2794         {
2795           /* Get the new value for the PC.  */
2796           address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)];
2797           newpc = read_memory_unsigned_integer (address,
2798                                                 4, inst_env->byte_order);
2799
2800           /* Check if we should increment a register.  */
2801           if (cris_get_mode (inst) == AUTOINC_MODE)
2802             {
2803               inst_env->reg[cris_get_operand1 (inst)] += 4;
2804             }
2805         }
2806       inst_env->reg[REG_PC] = newpc;
2807     }
2808   inst_env->slot_needed = 0;
2809   inst_env->prefix_found = 0;
2810   inst_env->xflag_found = 0;
2811   inst_env->disable_interrupt = 1;
2812 }
2813
2814 /* Handles moves to special registers (aka P-register) for all modes.  */
2815
2816 static void 
2817 move_to_preg_op (struct gdbarch *gdbarch, unsigned short inst,
2818                  inst_env_type *inst_env)
2819 {
2820   if (inst_env->prefix_found)
2821     {
2822       /* The instruction has a prefix that means we are only interested if
2823          the instruction is in assign mode.  */
2824       if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2825         {
2826           /* The prefix handles the problem if we are in a delay slot.  */
2827           if (cris_get_operand1 (inst) == REG_PC)
2828             {
2829               /* Just take care of the assign.  */
2830               check_assign (inst, inst_env);
2831             }
2832         }
2833     }
2834   else if (cris_get_mode (inst) == AUTOINC_MODE)
2835     {
2836       /* The instruction doesn't have a prefix, the only case left that we
2837          are interested in is the autoincrement mode.  */
2838       if (cris_get_operand1 (inst) == REG_PC)
2839         {
2840           /* If the PC is to be incremented it's invalid to be in a 
2841              delay slot.  */
2842           if (inst_env->slot_needed)
2843             {
2844               inst_env->invalid = 1;
2845               return;
2846             }
2847
2848           /* The increment depends on the size of the special register.  */
2849           if (cris_register_size (gdbarch, cris_get_operand2 (inst)) == 1)
2850             {
2851               process_autoincrement (INST_BYTE_SIZE, inst, inst_env);
2852             }
2853           else if (cris_register_size (gdbarch, cris_get_operand2 (inst)) == 2)
2854             {
2855               process_autoincrement (INST_WORD_SIZE, inst, inst_env);
2856             }
2857           else
2858             {
2859               process_autoincrement (INST_DWORD_SIZE, inst, inst_env);
2860             }
2861         }
2862     }
2863   inst_env->slot_needed = 0;
2864   inst_env->prefix_found = 0;
2865   inst_env->xflag_found = 0;
2866   inst_env->disable_interrupt = 1;
2867 }
2868
2869 /* Handles moves from special registers (aka P-register) for all modes
2870    except register.  */
2871
2872 static void 
2873 none_reg_mode_move_from_preg_op (struct gdbarch *gdbarch, unsigned short inst,
2874                                  inst_env_type *inst_env)
2875 {
2876   if (inst_env->prefix_found)
2877     {
2878       /* The instruction has a prefix that means we are only interested if
2879          the instruction is in assign mode.  */
2880       if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2881         {
2882           /* The prefix handles the problem if we are in a delay slot.  */
2883           if (cris_get_operand1 (inst) == REG_PC)
2884             {
2885               /* Just take care of the assign.  */
2886               check_assign (inst, inst_env);
2887             }
2888         }
2889     }    
2890   /* The instruction doesn't have a prefix, the only case left that we
2891      are interested in is the autoincrement mode.  */
2892   else if (cris_get_mode (inst) == AUTOINC_MODE)
2893     {
2894       if (cris_get_operand1 (inst) == REG_PC)
2895         {
2896           /* If the PC is to be incremented it's invalid to be in a 
2897              delay slot.  */
2898           if (inst_env->slot_needed)
2899             {
2900               inst_env->invalid = 1;
2901               return;
2902             }
2903           
2904           /* The increment depends on the size of the special register.  */
2905           if (cris_register_size (gdbarch, cris_get_operand2 (inst)) == 1)
2906             {
2907               process_autoincrement (INST_BYTE_SIZE, inst, inst_env);
2908             }
2909           else if (cris_register_size (gdbarch, cris_get_operand2 (inst)) == 2)
2910             {
2911               process_autoincrement (INST_WORD_SIZE, inst, inst_env);
2912             }
2913           else
2914             {
2915               process_autoincrement (INST_DWORD_SIZE, inst, inst_env);
2916             }
2917         }
2918     }
2919   inst_env->slot_needed = 0;
2920   inst_env->prefix_found = 0;
2921   inst_env->xflag_found = 0;
2922   inst_env->disable_interrupt = 1;
2923 }
2924
2925 /* Handles moves from special registers (aka P-register) when the mode
2926    is register.  */
2927
2928 static void 
2929 reg_mode_move_from_preg_op (unsigned short inst, inst_env_type *inst_env)
2930 {
2931   /* Register mode move from special register can't have a prefix.  */
2932   if (inst_env->prefix_found)
2933     {
2934       inst_env->invalid = 1;
2935       return;
2936     }
2937
2938   if (cris_get_operand1 (inst) == REG_PC)
2939     {
2940       /* It's invalid to change the PC in a delay slot.  */
2941       if (inst_env->slot_needed)
2942         {
2943           inst_env->invalid = 1;
2944           return;
2945         }
2946       /* The destination is the PC, the jump will have a delay slot.  */
2947       inst_env->delay_slot_pc = inst_env->preg[cris_get_operand2 (inst)];
2948       inst_env->slot_needed = 1;
2949       inst_env->delay_slot_pc_active = 1;
2950     }
2951   else
2952     {
2953       /* If the destination isn't PC, there will be no jump.  */
2954       inst_env->slot_needed = 0;
2955     }
2956   inst_env->prefix_found = 0;
2957   inst_env->xflag_found = 0;
2958   inst_env->disable_interrupt = 1;
2959 }
2960
2961 /* Handles the MOVEM from memory to general register instruction.  */
2962
2963 static void 
2964 move_mem_to_reg_movem_op (unsigned short inst, inst_env_type *inst_env)
2965 {
2966   if (inst_env->prefix_found)
2967     {
2968       /* The prefix handles the problem if we are in a delay slot.  Is the
2969          MOVEM instruction going to change the PC?  */
2970       if (cris_get_operand2 (inst) >= REG_PC)
2971         {
2972           inst_env->reg[REG_PC] = 
2973             read_memory_unsigned_integer (inst_env->prefix_value,
2974                                           4, inst_env->byte_order);
2975         }
2976       /* The assign value is the value after the increment.  Normally, the   
2977          assign value is the value before the increment.  */
2978       if ((cris_get_operand1 (inst) == REG_PC) 
2979           && (cris_get_mode (inst) == PREFIX_ASSIGN_MODE))
2980         {
2981           inst_env->reg[REG_PC] = inst_env->prefix_value;
2982           inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
2983         }
2984     }
2985   else
2986     {
2987       /* Is the MOVEM instruction going to change the PC?  */
2988       if (cris_get_operand2 (inst) == REG_PC)
2989         {
2990           /* It's invalid to change the PC in a delay slot.  */
2991           if (inst_env->slot_needed)
2992             {
2993               inst_env->invalid = 1;
2994               return;
2995             }
2996           inst_env->reg[REG_PC] =
2997             read_memory_unsigned_integer (inst_env->reg[cris_get_operand1 (inst)], 
2998                                           4, inst_env->byte_order);
2999         }
3000       /* The increment is not depending on the size, instead it's depending
3001          on the number of registers loaded from memory.  */
3002       if ((cris_get_operand1 (inst) == REG_PC)
3003           && (cris_get_mode (inst) == AUTOINC_MODE))
3004         {
3005           /* It's invalid to change the PC in a delay slot.  */
3006           if (inst_env->slot_needed)
3007             {
3008               inst_env->invalid = 1;
3009               return;
3010             }
3011           inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1); 
3012         }
3013     }
3014   inst_env->slot_needed = 0;
3015   inst_env->prefix_found = 0;
3016   inst_env->xflag_found = 0;
3017   inst_env->disable_interrupt = 0;
3018 }
3019
3020 /* Handles the MOVEM to memory from general register instruction.  */
3021
3022 static void 
3023 move_reg_to_mem_movem_op (unsigned short inst, inst_env_type *inst_env)
3024 {
3025   if (inst_env->prefix_found)
3026     {
3027       /* The assign value is the value after the increment.  Normally, the
3028          assign value is the value before the increment.  */
3029       if ((cris_get_operand1 (inst) == REG_PC)
3030           && (cris_get_mode (inst) == PREFIX_ASSIGN_MODE))
3031         {
3032           /* The prefix handles the problem if we are in a delay slot.  */
3033           inst_env->reg[REG_PC] = inst_env->prefix_value;
3034           inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
3035         }
3036     }
3037   else
3038     {
3039       /* The increment is not depending on the size, instead it's depending
3040          on the number of registers loaded to memory.  */
3041       if ((cris_get_operand1 (inst) == REG_PC)
3042           && (cris_get_mode (inst) == AUTOINC_MODE))
3043         {
3044           /* It's invalid to change the PC in a delay slot.  */
3045           if (inst_env->slot_needed)
3046             {
3047               inst_env->invalid = 1;
3048               return;
3049             }
3050           inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
3051         }
3052     }
3053   inst_env->slot_needed = 0;
3054   inst_env->prefix_found = 0;
3055   inst_env->xflag_found = 0;
3056   inst_env->disable_interrupt = 0;
3057 }
3058
3059 /* Handles the intructions that's not yet implemented, by setting 
3060    inst_env->invalid to true.  */
3061
3062 static void 
3063 not_implemented_op (unsigned short inst, inst_env_type *inst_env)
3064 {
3065   inst_env->invalid = 1;
3066 }
3067
3068 /* Handles the XOR instruction.  */
3069
3070 static void 
3071 xor_op (unsigned short inst, inst_env_type *inst_env)
3072 {
3073   /* XOR can't have a prefix.  */
3074   if (inst_env->prefix_found)
3075     {
3076       inst_env->invalid = 1;
3077       return;
3078     }
3079
3080   /* Check if the PC is the target.  */
3081   if (cris_get_operand2 (inst) == REG_PC)
3082     {
3083       /* It's invalid to change the PC in a delay slot.  */
3084       if (inst_env->slot_needed)
3085         {
3086           inst_env->invalid = 1;
3087           return;
3088         }
3089       inst_env->reg[REG_PC] ^= inst_env->reg[cris_get_operand1 (inst)];
3090     }
3091   inst_env->slot_needed = 0;
3092   inst_env->prefix_found = 0;
3093   inst_env->xflag_found = 0;
3094   inst_env->disable_interrupt = 0;
3095 }
3096
3097 /* Handles the MULS instruction.  */
3098
3099 static void 
3100 muls_op (unsigned short inst, inst_env_type *inst_env)
3101 {
3102   /* MULS/U can't have a prefix.  */
3103   if (inst_env->prefix_found)
3104     {
3105       inst_env->invalid = 1;
3106       return;
3107     }
3108
3109   /* Consider it invalid if the PC is the target.  */
3110   if (cris_get_operand2 (inst) == REG_PC)
3111     {
3112       inst_env->invalid = 1;
3113       return;
3114     }
3115   inst_env->slot_needed = 0;
3116   inst_env->prefix_found = 0;
3117   inst_env->xflag_found = 0;
3118   inst_env->disable_interrupt = 0;
3119 }
3120
3121 /* Handles the MULU instruction.  */
3122
3123 static void 
3124 mulu_op (unsigned short inst, inst_env_type *inst_env)
3125 {
3126   /* MULS/U can't have a prefix.  */
3127   if (inst_env->prefix_found)
3128     {
3129       inst_env->invalid = 1;
3130       return;
3131     }
3132
3133   /* Consider it invalid if the PC is the target.  */
3134   if (cris_get_operand2 (inst) == REG_PC)
3135     {
3136       inst_env->invalid = 1;
3137       return;
3138     }
3139   inst_env->slot_needed = 0;
3140   inst_env->prefix_found = 0;
3141   inst_env->xflag_found = 0;
3142   inst_env->disable_interrupt = 0;
3143 }
3144
3145 /* Calculate the result of the instruction for ADD, SUB, CMP AND, OR and MOVE.
3146    The MOVE instruction is the move from source to register.  */
3147
3148 static void 
3149 add_sub_cmp_and_or_move_action (unsigned short inst, inst_env_type *inst_env, 
3150                                 unsigned long source1, unsigned long source2)
3151 {
3152   unsigned long pc_mask;
3153   unsigned long operation_mask;
3154   
3155   /* Find out how many bits the operation should apply to.  */
3156   if (cris_get_size (inst) == INST_BYTE_SIZE)
3157     {
3158       pc_mask = 0xFFFFFF00; 
3159       operation_mask = 0xFF;
3160     }
3161   else if (cris_get_size (inst) == INST_WORD_SIZE)
3162     {
3163       pc_mask = 0xFFFF0000;
3164       operation_mask = 0xFFFF;
3165     }
3166   else if (cris_get_size (inst) == INST_DWORD_SIZE)
3167     {
3168       pc_mask = 0x0;
3169       operation_mask = 0xFFFFFFFF;
3170     }
3171   else
3172     {
3173       /* The size is out of range.  */
3174       inst_env->invalid = 1;
3175       return;
3176     }
3177
3178   /* The instruction just works on uw_operation_mask bits.  */
3179   source2 &= operation_mask;
3180   source1 &= operation_mask;
3181
3182   /* Now calculate the result.  The opcode's 3 first bits separates
3183      the different actions.  */
3184   switch (cris_get_opcode (inst) & 7)
3185     {
3186     case 0:  /* add */
3187       source1 += source2;
3188       break;
3189
3190     case 1:  /* move */
3191       source1 = source2;
3192       break;
3193
3194     case 2:  /* subtract */
3195       source1 -= source2;
3196       break;
3197
3198     case 3:  /* compare */
3199       break;
3200
3201     case 4:  /* and */
3202       source1 &= source2;
3203       break;
3204
3205     case 5:  /* or */
3206       source1 |= source2;
3207       break;
3208
3209     default:
3210       inst_env->invalid = 1;
3211       return;
3212
3213       break;
3214     }
3215
3216   /* Make sure that the result doesn't contain more than the instruction
3217      size bits.  */
3218   source2 &= operation_mask;
3219
3220   /* Calculate the new breakpoint address.  */
3221   inst_env->reg[REG_PC] &= pc_mask;
3222   inst_env->reg[REG_PC] |= source1;
3223
3224 }
3225
3226 /* Extends the value from either byte or word size to a dword.  If the mode
3227    is zero extend then the value is extended with zero.  If instead the mode
3228    is signed extend the sign bit of the value is taken into consideration.  */
3229
3230 static unsigned long 
3231 do_sign_or_zero_extend (unsigned long value, unsigned short *inst)
3232 {
3233   /* The size can be either byte or word, check which one it is. 
3234      Don't check the highest bit, it's indicating if it's a zero
3235      or sign extend.  */
3236   if (cris_get_size (*inst) & INST_WORD_SIZE)
3237     {
3238       /* Word size.  */
3239       value &= 0xFFFF;
3240
3241       /* Check if the instruction is signed extend.  If so, check if value has
3242          the sign bit on.  */
3243       if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_WORD_MASK))
3244         {
3245           value |= SIGNED_WORD_EXTEND_MASK;
3246         } 
3247     }
3248   else
3249     {
3250       /* Byte size.  */
3251       value &= 0xFF;
3252
3253       /* Check if the instruction is signed extend.  If so, check if value has
3254          the sign bit on.  */
3255       if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_BYTE_MASK))
3256         {
3257           value |= SIGNED_BYTE_EXTEND_MASK;
3258         }
3259     }
3260   /* The size should now be dword.  */
3261   cris_set_size_to_dword (inst);
3262   return value;
3263 }
3264
3265 /* Handles the register mode for the ADD, SUB, CMP, AND, OR and MOVE
3266    instruction.  The MOVE instruction is the move from source to register.  */
3267
3268 static void 
3269 reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst,
3270                                      inst_env_type *inst_env)
3271 {
3272   unsigned long operand1;
3273   unsigned long operand2;
3274
3275   /* It's invalid to have a prefix to the instruction.  This is a register 
3276      mode instruction and can't have a prefix.  */
3277   if (inst_env->prefix_found)
3278     {
3279       inst_env->invalid = 1;
3280       return;
3281     }
3282   /* Check if the instruction has PC as its target.  */
3283   if (cris_get_operand2 (inst) == REG_PC)
3284     {
3285       if (inst_env->slot_needed)
3286         {
3287           inst_env->invalid = 1;
3288           return;
3289         }
3290       /* The instruction has the PC as its target register.  */
3291       operand1 = inst_env->reg[cris_get_operand1 (inst)]; 
3292       operand2 = inst_env->reg[REG_PC];
3293
3294       /* Check if it's a extend, signed or zero instruction.  */
3295       if (cris_get_opcode (inst) < 4)
3296         {
3297           operand1 = do_sign_or_zero_extend (operand1, &inst);
3298         }
3299       /* Calculate the PC value after the instruction, i.e. where the
3300          breakpoint should be.  The order of the udw_operands is vital.  */
3301       add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1); 
3302     }
3303   inst_env->slot_needed = 0;
3304   inst_env->prefix_found = 0;
3305   inst_env->xflag_found = 0;
3306   inst_env->disable_interrupt = 0;
3307 }
3308
3309 /* Returns the data contained at address.  The size of the data is derived from
3310    the size of the operation.  If the instruction is a zero or signed
3311    extend instruction, the size field is changed in instruction.  */
3312
3313 static unsigned long 
3314 get_data_from_address (unsigned short *inst, CORE_ADDR address,
3315                        enum bfd_endian byte_order)
3316 {
3317   int size = cris_get_size (*inst);
3318   unsigned long value;
3319
3320   /* If it's an extend instruction we don't want the signed extend bit,
3321      because it influences the size.  */
3322   if (cris_get_opcode (*inst) < 4)
3323     {
3324       size &= ~SIGNED_EXTEND_BIT_MASK;
3325     }
3326   /* Is there a need for checking the size?  Size should contain the number of
3327      bytes to read.  */
3328   size = 1 << size;
3329   value = read_memory_unsigned_integer (address, size, byte_order);
3330
3331   /* Check if it's an extend, signed or zero instruction.  */
3332   if (cris_get_opcode (*inst) < 4)
3333     {
3334       value = do_sign_or_zero_extend (value, inst);
3335     }
3336   return value;
3337 }
3338
3339 /* Handles the assign addresing mode for the ADD, SUB, CMP, AND, OR and MOVE 
3340    instructions.  The MOVE instruction is the move from source to register.  */
3341
3342 static void 
3343 handle_prefix_assign_mode_for_aritm_op (unsigned short inst, 
3344                                         inst_env_type *inst_env)
3345 {
3346   unsigned long operand2;
3347   unsigned long operand3;
3348
3349   check_assign (inst, inst_env);
3350   if (cris_get_operand2 (inst) == REG_PC)
3351     {
3352       operand2 = inst_env->reg[REG_PC];
3353
3354       /* Get the value of the third operand.  */
3355       operand3 = get_data_from_address (&inst, inst_env->prefix_value,
3356                                         inst_env->byte_order);
3357
3358       /* Calculate the PC value after the instruction, i.e. where the
3359          breakpoint should be.  The order of the udw_operands is vital.  */
3360       add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3361     }
3362   inst_env->slot_needed = 0;
3363   inst_env->prefix_found = 0;
3364   inst_env->xflag_found = 0;
3365   inst_env->disable_interrupt = 0;
3366 }
3367
3368 /* Handles the three-operand addressing mode for the ADD, SUB, CMP, AND and
3369    OR instructions.  Note that for this to work as expected, the calling
3370    function must have made sure that there is a prefix to this instruction.  */
3371
3372 static void 
3373 three_operand_add_sub_cmp_and_or_op (unsigned short inst, 
3374                                      inst_env_type *inst_env)
3375 {
3376   unsigned long operand2;
3377   unsigned long operand3;
3378
3379   if (cris_get_operand1 (inst) == REG_PC)
3380     {
3381       /* The PC will be changed by the instruction.  */
3382       operand2 = inst_env->reg[cris_get_operand2 (inst)];
3383
3384       /* Get the value of the third operand.  */
3385       operand3 = get_data_from_address (&inst, inst_env->prefix_value,
3386                                         inst_env->byte_order);
3387
3388       /* Calculate the PC value after the instruction, i.e. where the
3389          breakpoint should be.  */
3390       add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3391     }
3392   inst_env->slot_needed = 0;
3393   inst_env->prefix_found = 0;
3394   inst_env->xflag_found = 0;
3395   inst_env->disable_interrupt = 0;
3396 }
3397
3398 /* Handles the index addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
3399    instructions.  The MOVE instruction is the move from source to register.  */
3400
3401 static void 
3402 handle_prefix_index_mode_for_aritm_op (unsigned short inst, 
3403                                        inst_env_type *inst_env)
3404 {
3405   if (cris_get_operand1 (inst) != cris_get_operand2 (inst))
3406     {
3407       /* If the instruction is MOVE it's invalid.  If the instruction is ADD,
3408          SUB, AND or OR something weird is going on (if everything works these
3409          instructions should end up in the three operand version).  */
3410       inst_env->invalid = 1;
3411       return;
3412     }
3413   else
3414     {
3415       /* three_operand_add_sub_cmp_and_or does the same as we should do here
3416          so use it.  */
3417       three_operand_add_sub_cmp_and_or_op (inst, inst_env);
3418     }
3419   inst_env->slot_needed = 0;
3420   inst_env->prefix_found = 0;
3421   inst_env->xflag_found = 0;
3422   inst_env->disable_interrupt = 0;
3423 }
3424
3425 /* Handles the autoincrement and indirect addresing mode for the ADD, SUB,
3426    CMP, AND OR and MOVE instruction.  The MOVE instruction is the move from
3427    source to register.  */
3428
3429 static void 
3430 handle_inc_and_index_mode_for_aritm_op (unsigned short inst, 
3431                                         inst_env_type *inst_env)
3432 {
3433   unsigned long operand1;
3434   unsigned long operand2;
3435   unsigned long operand3;
3436   int size;
3437
3438   /* The instruction is either an indirect or autoincrement addressing mode.
3439      Check if the destination register is the PC.  */
3440   if (cris_get_operand2 (inst) == REG_PC)
3441     {
3442       /* Must be done here, get_data_from_address may change the size 
3443          field.  */
3444       size = cris_get_size (inst);
3445       operand2 = inst_env->reg[REG_PC];
3446
3447       /* Get the value of the third operand, i.e. the indirect operand.  */
3448       operand1 = inst_env->reg[cris_get_operand1 (inst)];
3449       operand3 = get_data_from_address (&inst, operand1, inst_env->byte_order);
3450
3451       /* Calculate the PC value after the instruction, i.e. where the
3452          breakpoint should be.  The order of the udw_operands is vital.  */
3453       add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3); 
3454     }
3455   /* If this is an autoincrement addressing mode, check if the increment
3456      changes the PC.  */
3457   if ((cris_get_operand1 (inst) == REG_PC)
3458       && (cris_get_mode (inst) == AUTOINC_MODE))
3459     {
3460       /* Get the size field.  */
3461       size = cris_get_size (inst);
3462
3463       /* If it's an extend instruction we don't want the signed extend bit,
3464          because it influences the size.  */
3465       if (cris_get_opcode (inst) < 4)
3466         {
3467           size &= ~SIGNED_EXTEND_BIT_MASK;
3468         }
3469       process_autoincrement (size, inst, inst_env);
3470     } 
3471   inst_env->slot_needed = 0;
3472   inst_env->prefix_found = 0;
3473   inst_env->xflag_found = 0;
3474   inst_env->disable_interrupt = 0;
3475 }
3476
3477 /* Handles the two-operand addressing mode, all modes except register, for
3478    the ADD, SUB CMP, AND and OR instruction.  */
3479
3480 static void 
3481 none_reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst, 
3482                                           inst_env_type *inst_env)
3483 {
3484   if (inst_env->prefix_found)
3485     {
3486       if (cris_get_mode (inst) == PREFIX_INDEX_MODE)
3487         {
3488           handle_prefix_index_mode_for_aritm_op (inst, inst_env);
3489         }
3490       else if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
3491         {
3492           handle_prefix_assign_mode_for_aritm_op (inst, inst_env);
3493         }
3494       else
3495         {
3496           /* The mode is invalid for a prefixed base instruction.  */
3497           inst_env->invalid = 1;
3498           return;
3499         }
3500     }
3501   else
3502     {
3503       handle_inc_and_index_mode_for_aritm_op (inst, inst_env);
3504     }
3505 }
3506
3507 /* Handles the quick addressing mode for the ADD and SUB instruction.  */
3508
3509 static void 
3510 quick_mode_add_sub_op (unsigned short inst, inst_env_type *inst_env)
3511 {
3512   unsigned long operand1;
3513   unsigned long operand2;
3514
3515   /* It's a bad idea to be in a prefix instruction now.  This is a quick mode
3516      instruction and can't have a prefix.  */
3517   if (inst_env->prefix_found)
3518     {
3519       inst_env->invalid = 1;
3520       return;
3521     }
3522
3523   /* Check if the instruction has PC as its target.  */
3524   if (cris_get_operand2 (inst) == REG_PC)
3525     {
3526       if (inst_env->slot_needed)
3527         {
3528           inst_env->invalid = 1;
3529           return;
3530         }
3531       operand1 = cris_get_quick_value (inst);
3532       operand2 = inst_env->reg[REG_PC];
3533
3534       /* The size should now be dword.  */
3535       cris_set_size_to_dword (&inst);
3536
3537       /* Calculate the PC value after the instruction, i.e. where the
3538          breakpoint should be.  */
3539       add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3540     }
3541   inst_env->slot_needed = 0;
3542   inst_env->prefix_found = 0;
3543   inst_env->xflag_found = 0;
3544   inst_env->disable_interrupt = 0;
3545 }
3546
3547 /* Handles the quick addressing mode for the CMP, AND and OR instruction.  */
3548
3549 static void 
3550 quick_mode_and_cmp_move_or_op (unsigned short inst, inst_env_type *inst_env)
3551 {
3552   unsigned long operand1;
3553   unsigned long operand2;
3554
3555   /* It's a bad idea to be in a prefix instruction now.  This is a quick mode
3556      instruction and can't have a prefix.  */
3557   if (inst_env->prefix_found)
3558     {
3559       inst_env->invalid = 1;
3560       return;
3561     }
3562   /* Check if the instruction has PC as its target.  */
3563   if (cris_get_operand2 (inst) == REG_PC)
3564     {
3565       if (inst_env->slot_needed)
3566         {
3567           inst_env->invalid = 1;
3568           return;
3569         }
3570       /* The instruction has the PC as its target register.  */
3571       operand1 = cris_get_quick_value (inst);
3572       operand2 = inst_env->reg[REG_PC];
3573
3574       /* The quick value is signed, so check if we must do a signed extend.  */
3575       if (operand1 & SIGNED_QUICK_VALUE_MASK)
3576         {
3577           /* sign extend  */
3578           operand1 |= SIGNED_QUICK_VALUE_EXTEND_MASK;
3579         }
3580       /* The size should now be dword.  */
3581       cris_set_size_to_dword (&inst);
3582
3583       /* Calculate the PC value after the instruction, i.e. where the
3584          breakpoint should be.  */
3585       add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3586     }
3587   inst_env->slot_needed = 0;
3588   inst_env->prefix_found = 0;
3589   inst_env->xflag_found = 0;
3590   inst_env->disable_interrupt = 0;
3591 }
3592
3593 /* Translate op_type to a function and call it.  */
3594
3595 static void
3596 cris_gdb_func (struct gdbarch *gdbarch, enum cris_op_type op_type,
3597                unsigned short inst, inst_env_type *inst_env)
3598 {
3599   switch (op_type)
3600     {
3601     case cris_not_implemented_op:
3602       not_implemented_op (inst, inst_env);
3603       break;
3604
3605     case cris_abs_op:
3606       abs_op (inst, inst_env);
3607       break;
3608
3609     case cris_addi_op:
3610       addi_op (inst, inst_env);
3611       break;
3612
3613     case cris_asr_op:
3614       asr_op (inst, inst_env);
3615       break;
3616
3617     case cris_asrq_op:
3618       asrq_op (inst, inst_env);
3619       break;
3620
3621     case cris_ax_ei_setf_op:
3622       ax_ei_setf_op (inst, inst_env);
3623       break;
3624
3625     case cris_bdap_prefix:
3626       bdap_prefix (inst, inst_env);
3627       break;
3628
3629     case cris_biap_prefix:
3630       biap_prefix (inst, inst_env);
3631       break;
3632
3633     case cris_break_op:
3634       break_op (inst, inst_env);
3635       break;
3636
3637     case cris_btst_nop_op:
3638       btst_nop_op (inst, inst_env);
3639       break;
3640
3641     case cris_clearf_di_op:
3642       clearf_di_op (inst, inst_env);
3643       break;
3644
3645     case cris_dip_prefix:
3646       dip_prefix (inst, inst_env);
3647       break;
3648
3649     case cris_dstep_logshift_mstep_neg_not_op:
3650       dstep_logshift_mstep_neg_not_op (inst, inst_env);
3651       break;
3652
3653     case cris_eight_bit_offset_branch_op:
3654       eight_bit_offset_branch_op (inst, inst_env);
3655       break;
3656
3657     case cris_move_mem_to_reg_movem_op:
3658       move_mem_to_reg_movem_op (inst, inst_env);
3659       break;
3660
3661     case cris_move_reg_to_mem_movem_op:
3662       move_reg_to_mem_movem_op (inst, inst_env);
3663       break;
3664
3665     case cris_move_to_preg_op:
3666       move_to_preg_op (gdbarch, inst, inst_env);
3667       break;
3668
3669     case cris_muls_op:
3670       muls_op (inst, inst_env);
3671       break;
3672
3673     case cris_mulu_op:
3674       mulu_op (inst, inst_env);
3675       break;
3676
3677     case cris_none_reg_mode_add_sub_cmp_and_or_move_op:
3678       none_reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env);
3679       break;
3680
3681     case cris_none_reg_mode_clear_test_op:
3682       none_reg_mode_clear_test_op (inst, inst_env);
3683       break;
3684
3685     case cris_none_reg_mode_jump_op:
3686       none_reg_mode_jump_op (inst, inst_env);
3687       break;
3688
3689     case cris_none_reg_mode_move_from_preg_op:
3690       none_reg_mode_move_from_preg_op (gdbarch, inst, inst_env);
3691       break;
3692
3693     case cris_quick_mode_add_sub_op:
3694       quick_mode_add_sub_op (inst, inst_env);
3695       break;
3696
3697     case cris_quick_mode_and_cmp_move_or_op:
3698       quick_mode_and_cmp_move_or_op (inst, inst_env);
3699       break;
3700
3701     case cris_quick_mode_bdap_prefix:
3702       quick_mode_bdap_prefix (inst, inst_env);
3703       break;
3704
3705     case cris_reg_mode_add_sub_cmp_and_or_move_op:
3706       reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env);
3707       break;
3708
3709     case cris_reg_mode_clear_op:
3710       reg_mode_clear_op (inst, inst_env);
3711       break;
3712
3713     case cris_reg_mode_jump_op:
3714       reg_mode_jump_op (inst, inst_env);
3715       break;
3716
3717     case cris_reg_mode_move_from_preg_op:
3718       reg_mode_move_from_preg_op (inst, inst_env);
3719       break;
3720
3721     case cris_reg_mode_test_op:
3722       reg_mode_test_op (inst, inst_env);
3723       break;
3724
3725     case cris_scc_op:
3726       scc_op (inst, inst_env);
3727       break;
3728
3729     case cris_sixteen_bit_offset_branch_op:
3730       sixteen_bit_offset_branch_op (inst, inst_env);
3731       break;
3732
3733     case cris_three_operand_add_sub_cmp_and_or_op:
3734       three_operand_add_sub_cmp_and_or_op (inst, inst_env);
3735       break;
3736
3737     case cris_three_operand_bound_op:
3738       three_operand_bound_op (inst, inst_env);
3739       break;
3740
3741     case cris_two_operand_bound_op:
3742       two_operand_bound_op (inst, inst_env);
3743       break;
3744
3745     case cris_xor_op:
3746       xor_op (inst, inst_env);
3747       break;
3748     }
3749 }
3750
3751 /* Originally from <asm/elf.h>.  */
3752 typedef unsigned char cris_elf_greg_t[4];
3753
3754 /* Same as user_regs_struct struct in <asm/user.h>.  */
3755 #define CRISV10_ELF_NGREG 35
3756 typedef cris_elf_greg_t cris_elf_gregset_t[CRISV10_ELF_NGREG];
3757
3758 #define CRISV32_ELF_NGREG 32
3759 typedef cris_elf_greg_t crisv32_elf_gregset_t[CRISV32_ELF_NGREG];
3760
3761 /* Unpack a cris_elf_gregset_t into GDB's register cache.  */
3762
3763 static void 
3764 cris_supply_gregset (struct regcache *regcache, cris_elf_gregset_t *gregsetp)
3765 {
3766   struct gdbarch *gdbarch = regcache->arch ();
3767   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3768   int i;
3769   cris_elf_greg_t *regp = *gregsetp;
3770
3771   /* The kernel dumps all 32 registers as unsigned longs, but supply_register
3772      knows about the actual size of each register so that's no problem.  */
3773   for (i = 0; i < NUM_GENREGS + NUM_SPECREGS; i++)
3774     {
3775       regcache->raw_supply (i, (char *)&regp[i]);
3776     }
3777
3778   if (tdep->cris_version == 32)
3779     {
3780       /* Needed to set pseudo-register PC for CRISv32.  */
3781       /* FIXME: If ERP is in a delay slot at this point then the PC will
3782          be wrong.  Issue a warning to alert the user.  */
3783       regcache->raw_supply (gdbarch_pc_regnum (gdbarch),
3784                             (char *)&regp[ERP_REGNUM]);
3785
3786       if (*(char *)&regp[ERP_REGNUM] & 0x1)
3787         fprintf_unfiltered (gdb_stderr, "Warning: PC in delay slot\n");
3788     }
3789 }
3790
3791 /*  Use a local version of this function to get the correct types for
3792     regsets, until multi-arch core support is ready.  */
3793
3794 static void
3795 fetch_core_registers (struct regcache *regcache,
3796                       char *core_reg_sect, unsigned core_reg_size,
3797                       int which, CORE_ADDR reg_addr)
3798 {
3799   cris_elf_gregset_t gregset;
3800
3801   switch (which)
3802     {
3803     case 0:
3804       if (core_reg_size != sizeof (cris_elf_gregset_t)
3805           && core_reg_size != sizeof (crisv32_elf_gregset_t))
3806         {
3807           warning (_("wrong size gregset struct in core file"));
3808         }
3809       else
3810         {
3811           memcpy (&gregset, core_reg_sect, sizeof (gregset));
3812           cris_supply_gregset (regcache, &gregset);
3813         }
3814
3815     default:
3816       /* We've covered all the kinds of registers we know about here,
3817          so this must be something we wouldn't know what to do with
3818          anyway.  Just ignore it.  */
3819       break;
3820     }
3821 }
3822
3823 static struct core_fns cris_elf_core_fns =
3824 {
3825   bfd_target_elf_flavour,               /* core_flavour */
3826   default_check_format,                 /* check_format */
3827   default_core_sniffer,                 /* core_sniffer */
3828   fetch_core_registers,                 /* core_read_registers */
3829   NULL                                  /* next */
3830 };
3831
3832 void
3833 _initialize_cris_tdep (void)
3834 {
3835   gdbarch_register (bfd_arch_cris, cris_gdbarch_init, cris_dump_tdep);
3836   
3837   /* CRIS-specific user-commands.  */
3838   add_setshow_zuinteger_cmd ("cris-version", class_support,
3839                              &usr_cmd_cris_version,
3840                              _("Set the current CRIS version."),
3841                              _("Show the current CRIS version."),
3842                              _("\
3843 Set to 10 for CRISv10 or 32 for CRISv32 if autodetection fails.\n\
3844 Defaults to 10. "),
3845                              set_cris_version,
3846                              NULL, /* FIXME: i18n: Current CRIS version
3847                                       is %s.  */
3848                              &setlist, &showlist);
3849
3850   add_setshow_enum_cmd ("cris-mode", class_support, 
3851                         cris_modes, &usr_cmd_cris_mode, 
3852                         _("Set the current CRIS mode."),
3853                         _("Show the current CRIS mode."),
3854                         _("\
3855 Set to CRIS_MODE_GURU when debugging in guru mode.\n\
3856 Makes GDB use the NRP register instead of the ERP register in certain cases."),
3857                         set_cris_mode,
3858                         NULL, /* FIXME: i18n: Current CRIS version is %s.  */
3859                         &setlist, &showlist);
3860   
3861   add_setshow_boolean_cmd ("cris-dwarf2-cfi", class_support,
3862                            &usr_cmd_cris_dwarf2_cfi,
3863                            _("Set the usage of Dwarf-2 CFI for CRIS."),
3864                            _("Show the usage of Dwarf-2 CFI for CRIS."),
3865                            _("Set this to \"off\" if using gcc-cris < R59."),
3866                            set_cris_dwarf2_cfi,
3867                            NULL, /* FIXME: i18n: Usage of Dwarf-2 CFI
3868                                     for CRIS is %d.  */
3869                            &setlist, &showlist);
3870
3871   deprecated_add_core_fns (&cris_elf_core_fns);
3872 }
3873
3874 /* Prints out all target specific values.  */
3875
3876 static void
3877 cris_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
3878 {
3879   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3880   if (tdep != NULL)
3881     {
3882       fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_version = %i\n",
3883                           tdep->cris_version);
3884       fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_mode = %s\n",
3885                           tdep->cris_mode);
3886       fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_dwarf2_cfi = %i\n",
3887                           tdep->cris_dwarf2_cfi);
3888     }
3889 }
3890
3891 static void
3892 set_cris_version (const char *ignore_args, int from_tty, 
3893                   struct cmd_list_element *c)
3894 {
3895   struct gdbarch_info info;
3896
3897   usr_cmd_cris_version_valid = 1;
3898   
3899   /* Update the current architecture, if needed.  */
3900   gdbarch_info_init (&info);
3901   if (!gdbarch_update_p (info))
3902     internal_error (__FILE__, __LINE__, 
3903                     _("cris_gdbarch_update: failed to update architecture."));
3904 }
3905
3906 static void
3907 set_cris_mode (const char *ignore_args, int from_tty, 
3908                struct cmd_list_element *c)
3909 {
3910   struct gdbarch_info info;
3911
3912   /* Update the current architecture, if needed.  */
3913   gdbarch_info_init (&info);
3914   if (!gdbarch_update_p (info))
3915     internal_error (__FILE__, __LINE__, 
3916                     "cris_gdbarch_update: failed to update architecture.");
3917 }
3918
3919 static void
3920 set_cris_dwarf2_cfi (const char *ignore_args, int from_tty, 
3921                      struct cmd_list_element *c)
3922 {
3923   struct gdbarch_info info;
3924
3925   /* Update the current architecture, if needed.  */
3926   gdbarch_info_init (&info);
3927   if (!gdbarch_update_p (info))
3928     internal_error (__FILE__, __LINE__, 
3929                     _("cris_gdbarch_update: failed to update architecture."));
3930 }
3931
3932 static struct gdbarch *
3933 cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
3934 {
3935   struct gdbarch *gdbarch;
3936   struct gdbarch_tdep *tdep;
3937   unsigned int cris_version;
3938
3939   if (usr_cmd_cris_version_valid)
3940     {
3941       /* Trust the user's CRIS version setting.  */ 
3942       cris_version = usr_cmd_cris_version;
3943     }
3944   else if (info.abfd && bfd_get_mach (info.abfd) == bfd_mach_cris_v32)
3945     {
3946       cris_version = 32;
3947     }
3948   else
3949     {
3950       /* Assume it's CRIS version 10.  */
3951       cris_version = 10;
3952     }
3953
3954   /* Make the current settings visible to the user.  */
3955   usr_cmd_cris_version = cris_version;
3956   
3957   /* Find a candidate among the list of pre-declared architectures.  */
3958   for (arches = gdbarch_list_lookup_by_info (arches, &info); 
3959        arches != NULL;
3960        arches = gdbarch_list_lookup_by_info (arches->next, &info))
3961     {
3962       if ((gdbarch_tdep (arches->gdbarch)->cris_version 
3963            == usr_cmd_cris_version)
3964           && (gdbarch_tdep (arches->gdbarch)->cris_mode 
3965            == usr_cmd_cris_mode)
3966           && (gdbarch_tdep (arches->gdbarch)->cris_dwarf2_cfi 
3967               == usr_cmd_cris_dwarf2_cfi))
3968         return arches->gdbarch;
3969     }
3970
3971   /* No matching architecture was found.  Create a new one.  */
3972   tdep = XCNEW (struct gdbarch_tdep);
3973   info.byte_order = BFD_ENDIAN_LITTLE;
3974   gdbarch = gdbarch_alloc (&info, tdep);
3975
3976   tdep->cris_version = usr_cmd_cris_version;
3977   tdep->cris_mode = usr_cmd_cris_mode;
3978   tdep->cris_dwarf2_cfi = usr_cmd_cris_dwarf2_cfi;
3979
3980   set_gdbarch_return_value (gdbarch, cris_return_value);
3981   set_gdbarch_sp_regnum (gdbarch, 14);
3982   
3983   /* Length of ordinary registers used in push_word and a few other
3984      places.  register_size() is the real way to know how big a
3985      register is.  */
3986
3987   set_gdbarch_double_bit (gdbarch, 64);
3988   /* The default definition of a long double is 2 * gdbarch_double_bit,
3989      which means we have to set this explicitly.  */
3990   set_gdbarch_long_double_bit (gdbarch, 64);
3991
3992   /* The total amount of space needed to store (in an array called registers)
3993      GDB's copy of the machine's register state.  Note: We can not use
3994      cris_register_size at this point, since it relies on gdbarch
3995      being set.  */
3996   switch (tdep->cris_version)
3997     {
3998     case 0:
3999     case 1:
4000     case 2:
4001     case 3:
4002     case 8:
4003     case 9:
4004       /* Old versions; not supported.  */
4005       return 0;
4006
4007     case 10:
4008     case 11: 
4009       /* CRIS v10 and v11, a.k.a. ETRAX 100LX.  In addition to ETRAX 100, 
4010          P7 (32 bits), and P15 (32 bits) have been implemented.  */
4011       set_gdbarch_pc_regnum (gdbarch, 15);
4012       set_gdbarch_register_type (gdbarch, cris_register_type);
4013       /* There are 32 registers (some of which may not be implemented).  */
4014       set_gdbarch_num_regs (gdbarch, 32);
4015       set_gdbarch_register_name (gdbarch, cris_register_name);
4016       set_gdbarch_cannot_store_register (gdbarch, cris_cannot_store_register);
4017       set_gdbarch_cannot_fetch_register (gdbarch, cris_cannot_fetch_register);
4018
4019       set_gdbarch_software_single_step (gdbarch, cris_software_single_step);
4020       break;
4021
4022     case 32:
4023       /* CRIS v32.  General registers R0 - R15 (32 bits), special registers 
4024          P0 - P15 (32 bits) except P0, P1, P3 (8 bits) and P4 (16 bits)
4025          and pseudo-register PC (32 bits).  */
4026       set_gdbarch_pc_regnum (gdbarch, 32);
4027       set_gdbarch_register_type (gdbarch, crisv32_register_type);
4028       /* 32 registers + pseudo-register PC + 16 support registers.  */
4029       set_gdbarch_num_regs (gdbarch, 32 + 1 + 16);
4030       set_gdbarch_register_name (gdbarch, crisv32_register_name);
4031
4032       set_gdbarch_cannot_store_register 
4033         (gdbarch, crisv32_cannot_store_register);
4034       set_gdbarch_cannot_fetch_register
4035         (gdbarch, crisv32_cannot_fetch_register);
4036
4037       set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
4038
4039       set_gdbarch_single_step_through_delay 
4040         (gdbarch, crisv32_single_step_through_delay);
4041
4042       break;
4043
4044     default:
4045       /* Unknown version.  */
4046       return 0;
4047     }
4048
4049   /* Dummy frame functions (shared between CRISv10 and CRISv32 since they
4050      have the same ABI).  */
4051   set_gdbarch_push_dummy_code (gdbarch, cris_push_dummy_code);
4052   set_gdbarch_push_dummy_call (gdbarch, cris_push_dummy_call);
4053   set_gdbarch_frame_align (gdbarch, cris_frame_align);
4054   set_gdbarch_skip_prologue (gdbarch, cris_skip_prologue);
4055   
4056   /* The stack grows downward.  */
4057   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
4058
4059   set_gdbarch_breakpoint_kind_from_pc (gdbarch, cris_breakpoint_kind_from_pc);
4060   set_gdbarch_sw_breakpoint_from_kind (gdbarch, cris_sw_breakpoint_from_kind);
4061   
4062   if (tdep->cris_dwarf2_cfi == 1)
4063     {
4064       /* Hook in the Dwarf-2 frame sniffer.  */
4065       set_gdbarch_dwarf2_reg_to_regnum (gdbarch, cris_dwarf2_reg_to_regnum);
4066       dwarf2_frame_set_init_reg (gdbarch, cris_dwarf2_frame_init_reg);
4067       dwarf2_append_unwinders (gdbarch);
4068     }
4069
4070   if (tdep->cris_mode != cris_mode_guru)
4071     {
4072       frame_unwind_append_unwinder (gdbarch, &cris_sigtramp_frame_unwind);
4073     }
4074
4075   frame_unwind_append_unwinder (gdbarch, &cris_frame_unwind);
4076   frame_base_set_default (gdbarch, &cris_frame_base);
4077
4078   /* Hook in ABI-specific overrides, if they have been registered.  */
4079   gdbarch_init_osabi (info, gdbarch);
4080
4081   return gdbarch;
4082 }