1 /* Target dependent code for CRIS, for GDB, the GNU debugger.
3 Copyright (C) 2001-2019 Free Software Foundation, Inc.
5 Contributed by Axis Communications AB.
6 Written by Hendrik Ruijter, Stefan Andersson, and Orjan Friberg.
8 This file is part of GDB.
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.
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.
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/>. */
25 #include "frame-unwind.h"
26 #include "frame-base.h"
27 #include "trad-frame.h"
28 #include "dwarf2-frame.h"
36 #include "opcode/cris.h"
38 #include "arch-utils.h"
43 #include "solib.h" /* Support for shared libraries. */
44 #include "solib-svr4.h"
47 #include "cris-tdep.h"
51 /* There are no floating point registers. Used in gdbserver low-linux.c. */
54 /* There are 16 general registers. */
57 /* There are 16 special registers. */
60 /* CRISv32 has a pseudo PC register, not noted here. */
62 /* CRISv32 has 16 support registers. */
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. */
81 /* Enums with respect to the general registers, valid for all
82 CRIS versions. The frame pointer is always in R8. */
84 /* ABI related registers. */
92 /* Registers which happen to be common. */
97 /* CRISv10 et al. specific registers. */
109 /* CRISv32 specific registers. */
122 CRISV32USP_REGNUM = 30, /* Shares name but not number with CRISv10. */
124 CRISV32PC_REGNUM = 32, /* Shares name but not number with CRISv10. */
144 extern const struct cris_spec_reg cris_spec_regs[];
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;
150 /* Indicates whether to trust the above variable. */
151 static int usr_cmd_cris_version_valid = 0;
153 static const char cris_mode_normal[] = "normal";
154 static const char cris_mode_guru[] = "guru";
155 static const char *const cris_modes[] = {
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;
165 /* Whether to make use of Dwarf-2 CFI (default on). */
166 static int usr_cmd_cris_dwarf2_cfi = 1;
168 /* Sigtramp identification code copied from i386-linux-tdep.c. */
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
175 static const unsigned short sigtramp_code[] =
177 SIGTRAMP_INSN0, 0x0077, /* movu.w $0x77, $r9 */
178 SIGTRAMP_INSN1 /* break 13 */
181 #define SIGTRAMP_LEN (sizeof sigtramp_code)
183 /* Note: same length as normal sigtramp code. */
185 static const unsigned short rt_sigtramp_code[] =
187 SIGTRAMP_INSN0, 0x00ad, /* movu.w $0xad, $r9 */
188 SIGTRAMP_INSN1 /* break 13 */
191 /* If PC is in a sigtramp routine, return the address of the start of
192 the routine. Otherwise, return 0. */
195 cris_sigtramp_start (struct frame_info *this_frame)
197 CORE_ADDR pc = get_frame_pc (this_frame);
198 gdb_byte buf[SIGTRAMP_LEN];
200 if (!safe_frame_unwind_memory (this_frame, pc, buf, SIGTRAMP_LEN))
203 if (((buf[1] << 8) + buf[0]) != SIGTRAMP_INSN0)
205 if (((buf[1] << 8) + buf[0]) != SIGTRAMP_INSN1)
208 pc -= SIGTRAMP_OFFSET1;
209 if (!safe_frame_unwind_memory (this_frame, pc, buf, SIGTRAMP_LEN))
213 if (memcmp (buf, sigtramp_code, SIGTRAMP_LEN) != 0)
219 /* If PC is in a RT sigtramp routine, return the address of the start of
220 the routine. Otherwise, return 0. */
223 cris_rt_sigtramp_start (struct frame_info *this_frame)
225 CORE_ADDR pc = get_frame_pc (this_frame);
226 gdb_byte buf[SIGTRAMP_LEN];
228 if (!safe_frame_unwind_memory (this_frame, pc, buf, SIGTRAMP_LEN))
231 if (((buf[1] << 8) + buf[0]) != SIGTRAMP_INSN0)
233 if (((buf[1] << 8) + buf[0]) != SIGTRAMP_INSN1)
236 pc -= SIGTRAMP_OFFSET1;
237 if (!safe_frame_unwind_memory (this_frame, pc, buf, SIGTRAMP_LEN))
241 if (memcmp (buf, rt_sigtramp_code, SIGTRAMP_LEN) != 0)
247 /* Assuming THIS_FRAME is a frame for a GNU/Linux sigtramp routine,
248 return the address of the associated sigcontext structure. */
251 cris_sigcontext_addr (struct frame_info *this_frame)
253 struct gdbarch *gdbarch = get_frame_arch (this_frame);
254 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
259 get_frame_register (this_frame, gdbarch_sp_regnum (gdbarch), buf);
260 sp = extract_unsigned_integer (buf, 4, byte_order);
262 /* Look for normal sigtramp frame first. */
263 pc = cris_sigtramp_start (this_frame);
266 /* struct signal_frame (arch/cris/kernel/signal.c) contains
267 struct sigcontext as its first member, meaning the SP points to
272 pc = cris_rt_sigtramp_start (this_frame);
275 /* struct rt_signal_frame (arch/cris/kernel/signal.c) contains
276 a struct ucontext, which in turn contains a struct sigcontext.
278 4 + 4 + 128 to struct ucontext, then
279 4 + 4 + 12 to struct sigcontext. */
283 error (_("Couldn't recognize signal trampoline."));
287 struct cris_unwind_cache
289 /* The previous frame's inner most stack address. Used as this
290 frame ID's stack_addr. */
292 /* The frame's base, optionally used by the high-level debug info. */
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
302 /* From old frame_extra_info struct. */
306 /* Table indicating the location of each and every register. */
307 struct trad_frame_saved_reg *saved_regs;
310 static struct cris_unwind_cache *
311 cris_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
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;
323 return (struct cris_unwind_cache *) (*this_cache);
325 info = FRAME_OBSTACK_ZALLOC (struct cris_unwind_cache);
326 (*this_cache) = info;
327 info->saved_regs = trad_frame_alloc_saved_regs (this_frame);
329 /* Zero all fields. */
335 info->uses_frame = 0;
337 info->leaf_function = 0;
339 get_frame_register (this_frame, gdbarch_sp_regnum (gdbarch), buf);
340 info->base = extract_unsigned_integer (buf, 4, byte_order);
342 addr = cris_sigcontext_addr (this_frame);
344 /* Layout of the sigcontext struct:
347 unsigned long oldmask;
351 if (tdep->cris_version == 10)
353 /* R0 to R13 are stored in reverse order at offset (2 * 4) in
355 for (i = 0; i <= 13; i++)
356 info->saved_regs[i].addr = addr + ((15 - i) * 4);
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);
372 /* R0 to R13 are stored in order at offset (1 * 4) in
374 for (i = 0; i <= 13; i++)
375 info->saved_regs[i].addr = addr + ((i + 1) * 4);
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);
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.
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];
397 info->saved_regs[gdbarch_sp_regnum (gdbarch)].addr
405 cris_sigtramp_frame_this_id (struct frame_info *this_frame, void **this_cache,
406 struct frame_id *this_id)
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));
413 /* Forward declaration. */
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)
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);
427 cris_sigtramp_frame_sniffer (const struct frame_unwind *self,
428 struct frame_info *this_frame,
431 if (cris_sigtramp_start (this_frame)
432 || cris_rt_sigtramp_start (this_frame))
438 static const struct frame_unwind cris_sigtramp_frame_unwind =
441 default_frame_unwind_stop_reason,
442 cris_sigtramp_frame_this_id,
443 cris_sigtramp_frame_prev_register,
445 cris_sigtramp_frame_sniffer
449 crisv32_single_step_through_delay (struct gdbarch *gdbarch,
450 struct frame_info *this_frame)
452 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
456 if (tdep->cris_mode == cris_mode_guru)
457 erp = get_frame_register_unsigned (this_frame, NRP_REGNUM);
459 erp = get_frame_register_unsigned (this_frame, ERP_REGNUM);
463 /* In delay slot - check if there's a breakpoint at the preceding
465 if (breakpoint_here_p (get_frame_address_space (this_frame), erp & ~0x1))
471 /* The instruction environment needed to find single-step breakpoints. */
474 struct instruction_environment
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;
485 int delay_slot_pc_active;
487 int disable_interrupt;
488 enum bfd_endian byte_order;
491 /* Machine-dependencies in CRIS for opcodes. */
493 /* Instruction sizes. */
494 enum cris_instruction_sizes
501 /* Addressing modes. */
502 enum cris_addressing_modes
509 /* Prefix addressing modes. */
510 enum cris_prefix_addressing_modes
512 PREFIX_INDEX_MODE = 2,
513 PREFIX_ASSIGN_MODE = 3,
515 /* Handle immediate byte offset addressing mode prefix format. */
516 PREFIX_OFFSET_MODE = 2
519 /* Masks for opcodes. */
520 enum cris_opcode_masks
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
533 /* Functions for opcodes. The general form of the ETRAX 16-bit instruction:
541 cris_get_operand2 (unsigned short insn)
543 return ((insn & 0xF000) >> 12);
547 cris_get_mode (unsigned short insn)
549 return ((insn & 0x0C00) >> 10);
553 cris_get_opcode (unsigned short insn)
555 return ((insn & 0x03C0) >> 6);
559 cris_get_size (unsigned short insn)
561 return ((insn & 0x0030) >> 4);
565 cris_get_operand1 (unsigned short insn)
567 return (insn & 0x000F);
570 /* Additional functions in order to handle opcodes. */
573 cris_get_quick_value (unsigned short insn)
575 return (insn & 0x003F);
579 cris_get_bdap_quick_offset (unsigned short insn)
581 return (insn & 0x00FF);
585 cris_get_branch_short_offset (unsigned short insn)
587 return (insn & 0x00FF);
591 cris_get_asr_shift_steps (unsigned long value)
593 return (value & 0x3F);
597 cris_get_clear_size (unsigned short insn)
599 return ((insn) & 0xC000);
603 cris_is_signed_extend_bit_on (unsigned short insn)
605 return (((insn) & 0x20) == 0x20);
609 cris_is_xflag_bit_on (unsigned short insn)
611 return (((insn) & 0x1000) == 0x1000);
615 cris_set_size_to_dword (unsigned short *insn)
622 cris_get_signed_offset (unsigned short insn)
624 return ((signed char) (insn & 0x00FF));
627 /* Calls an op function given the op-type, working on the insn and the
629 static void cris_gdb_func (struct gdbarch *, enum cris_op_type, unsigned short,
632 static struct gdbarch *cris_gdbarch_init (struct gdbarch_info,
633 struct gdbarch_list *);
635 static void cris_dump_tdep (struct gdbarch *, struct ui_file *);
637 static void set_cris_version (const char *ignore_args, int from_tty,
638 struct cmd_list_element *c);
640 static void set_cris_mode (const char *ignore_args, int from_tty,
641 struct cmd_list_element *c);
643 static void set_cris_dwarf2_cfi (const char *ignore_args, int from_tty,
644 struct cmd_list_element *c);
646 static CORE_ADDR cris_scan_prologue (CORE_ADDR pc,
647 struct frame_info *this_frame,
648 struct cris_unwind_cache *info);
650 static CORE_ADDR crisv32_scan_prologue (CORE_ADDR pc,
651 struct frame_info *this_frame,
652 struct cris_unwind_cache *info);
654 static CORE_ADDR cris_unwind_pc (struct gdbarch *gdbarch,
655 struct frame_info *next_frame);
657 static CORE_ADDR cris_unwind_sp (struct gdbarch *gdbarch,
658 struct frame_info *next_frame);
660 /* When arguments must be pushed onto the stack, they go on in reverse
661 order. The below implements a FILO (stack) to do this.
662 Copied from d10v-tdep.c. */
667 struct stack_item *prev;
671 static struct stack_item *
672 push_stack_item (struct stack_item *prev, const gdb_byte *contents, int len)
674 struct stack_item *si = XNEW (struct stack_item);
675 si->data = (gdb_byte *) xmalloc (len);
678 memcpy (si->data, contents, len);
682 static struct stack_item *
683 pop_stack_item (struct stack_item *si)
685 struct stack_item *dead = si;
692 /* Put here the code to store, into fi->saved_regs, the addresses of
693 the saved registers of frame described by FRAME_INFO. This
694 includes special registers such as pc and fp saved in special ways
695 in the stack frame. sp is even more special: the address we return
696 for it IS the sp for the next frame. */
698 static struct cris_unwind_cache *
699 cris_frame_unwind_cache (struct frame_info *this_frame,
700 void **this_prologue_cache)
702 struct gdbarch *gdbarch = get_frame_arch (this_frame);
703 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
704 struct cris_unwind_cache *info;
706 if ((*this_prologue_cache))
707 return (struct cris_unwind_cache *) (*this_prologue_cache);
709 info = FRAME_OBSTACK_ZALLOC (struct cris_unwind_cache);
710 (*this_prologue_cache) = info;
711 info->saved_regs = trad_frame_alloc_saved_regs (this_frame);
713 /* Zero all fields. */
719 info->uses_frame = 0;
721 info->leaf_function = 0;
723 /* Prologue analysis does the rest... */
724 if (tdep->cris_version == 32)
725 crisv32_scan_prologue (get_frame_func (this_frame), this_frame, info);
727 cris_scan_prologue (get_frame_func (this_frame), this_frame, info);
732 /* Given a GDB frame, determine the address of the calling function's
733 frame. This will be used to create a new GDB frame struct. */
736 cris_frame_this_id (struct frame_info *this_frame,
737 void **this_prologue_cache,
738 struct frame_id *this_id)
740 struct cris_unwind_cache *info
741 = cris_frame_unwind_cache (this_frame, this_prologue_cache);
746 /* The FUNC is easy. */
747 func = get_frame_func (this_frame);
749 /* Hopefully the prologue analysis either correctly determined the
750 frame's base (which is the SP from the previous frame), or set
751 that base to "NULL". */
752 base = info->prev_sp;
756 id = frame_id_build (base, func);
761 static struct value *
762 cris_frame_prev_register (struct frame_info *this_frame,
763 void **this_prologue_cache, int regnum)
765 struct cris_unwind_cache *info
766 = cris_frame_unwind_cache (this_frame, this_prologue_cache);
767 return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
770 /* Assuming THIS_FRAME is a dummy, return the frame ID of that dummy
771 frame. The frame ID's base needs to match the TOS value saved by
772 save_dummy_frame_tos(), and the PC match the dummy frame's breakpoint. */
774 static struct frame_id
775 cris_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
778 sp = get_frame_register_unsigned (this_frame, gdbarch_sp_regnum (gdbarch));
779 return frame_id_build (sp, get_frame_pc (this_frame));
783 cris_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
785 /* Align to the size of an instruction (so that they can safely be
786 pushed onto the stack). */
791 cris_push_dummy_code (struct gdbarch *gdbarch,
792 CORE_ADDR sp, CORE_ADDR funaddr,
793 struct value **args, int nargs,
794 struct type *value_type,
795 CORE_ADDR *real_pc, CORE_ADDR *bp_addr,
796 struct regcache *regcache)
798 /* Allocate space sufficient for a breakpoint. */
800 /* Store the address of that breakpoint */
802 /* CRIS always starts the call at the callee's entry point. */
808 cris_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
809 struct regcache *regcache, CORE_ADDR bp_addr,
810 int nargs, struct value **args, CORE_ADDR sp,
811 function_call_return_method return_method,
812 CORE_ADDR struct_addr)
814 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
818 struct stack_item *si = NULL;
820 /* Push the return address. */
821 regcache_cooked_write_unsigned (regcache, SRP_REGNUM, bp_addr);
823 /* Are we returning a value using a structure return or a normal value
824 return? struct_addr is the address of the reserved space for the return
825 structure to be written on the stack. */
826 if (return_method == return_method_struct)
827 regcache_cooked_write_unsigned (regcache, STR_REGNUM, struct_addr);
829 /* Now load as many as possible of the first arguments into registers,
830 and push the rest onto the stack. */
831 argreg = ARG1_REGNUM;
833 for (argnum = 0; argnum < nargs; argnum++)
840 len = TYPE_LENGTH (value_type (args[argnum]));
841 val = value_contents (args[argnum]);
843 /* How may registers worth of storage do we need for this argument? */
844 reg_demand = (len / 4) + (len % 4 != 0 ? 1 : 0);
846 if (len <= (2 * 4) && (argreg + reg_demand - 1 <= ARG4_REGNUM))
848 /* Data passed by value. Fits in available register(s). */
849 for (i = 0; i < reg_demand; i++)
851 regcache->cooked_write (argreg, val);
856 else if (len <= (2 * 4) && argreg <= ARG4_REGNUM)
858 /* Data passed by value. Does not fit in available register(s).
859 Use the register(s) first, then the stack. */
860 for (i = 0; i < reg_demand; i++)
862 if (argreg <= ARG4_REGNUM)
864 regcache->cooked_write (argreg, val);
870 /* Push item for later so that pushed arguments
871 come in the right order. */
872 si = push_stack_item (si, val, 4);
877 else if (len > (2 * 4))
879 /* Data passed by reference. Push copy of data onto stack
880 and pass pointer to this copy as argument. */
881 sp = (sp - len) & ~3;
882 write_memory (sp, val, len);
884 if (argreg <= ARG4_REGNUM)
886 regcache_cooked_write_unsigned (regcache, argreg, sp);
892 store_unsigned_integer (buf, 4, byte_order, sp);
893 si = push_stack_item (si, buf, 4);
898 /* Data passed by value. No available registers. Put it on
900 si = push_stack_item (si, val, len);
906 /* fp_arg must be word-aligned (i.e., don't += len) to match
907 the function prologue. */
908 sp = (sp - si->len) & ~3;
909 write_memory (sp, si->data, si->len);
910 si = pop_stack_item (si);
913 /* Finally, update the SP register. */
914 regcache_cooked_write_unsigned (regcache, gdbarch_sp_regnum (gdbarch), sp);
919 static const struct frame_unwind cris_frame_unwind =
922 default_frame_unwind_stop_reason,
924 cris_frame_prev_register,
926 default_frame_sniffer
930 cris_frame_base_address (struct frame_info *this_frame, void **this_cache)
932 struct cris_unwind_cache *info
933 = cris_frame_unwind_cache (this_frame, this_cache);
937 static const struct frame_base cris_frame_base =
940 cris_frame_base_address,
941 cris_frame_base_address,
942 cris_frame_base_address
945 /* Frames information. The definition of the struct frame_info is
949 enum frame_type type;
953 If the compilation option -fno-omit-frame-pointer is present the
954 variable frame will be set to the content of R8 which is the frame
957 The variable pc contains the address where execution is performed
958 in the present frame. The innermost frame contains the current content
959 of the register PC. All other frames contain the content of the
960 register PC in the next frame.
962 The variable `type' indicates the frame's type: normal, SIGTRAMP
963 (associated with a signal handler), dummy (associated with a dummy
966 The variable return_pc contains the address where execution should be
967 resumed when the present frame has finished, the return address.
969 The variable leaf_function is 1 if the return address is in the register
970 SRP, and 0 if it is on the stack.
972 Prologue instructions C-code.
973 The prologue may consist of (-fno-omit-frame-pointer)
977 move.d sp,r8 move.d sp,r8
979 movem rY,[sp] movem rY,[sp]
980 move.S rZ,[r8-U] move.S rZ,[r8-U]
982 where 1 is a non-terminal function, and 2 is a leaf-function.
984 Note that this assumption is extremely brittle, and will break at the
985 slightest change in GCC's prologue.
987 If local variables are declared or register contents are saved on stack
988 the subq-instruction will be present with X as the number of bytes
989 needed for storage. The reshuffle with respect to r8 may be performed
990 with any size S (b, w, d) and any of the general registers Z={0..13}.
991 The offset U should be representable by a signed 8-bit value in all cases.
992 Thus, the prefix word is assumed to be immediate byte offset mode followed
993 by another word containing the instruction.
1002 Prologue instructions C++-code.
1003 Case 1) and 2) in the C-code may be followed by
1005 move.d r10,rS ; this
1009 move.S [r8+U],rZ ; P4
1011 if any of the call parameters are stored. The host expects these
1012 instructions to be executed in order to get the call parameters right. */
1014 /* Examine the prologue of a function. The variable ip is the address of
1015 the first instruction of the prologue. The variable limit is the address
1016 of the first instruction after the prologue. The variable fi contains the
1017 information in struct frame_info. The variable frameless_p controls whether
1018 the entire prologue is examined (0) or just enough instructions to
1019 determine that it is a prologue (1). */
1022 cris_scan_prologue (CORE_ADDR pc, struct frame_info *this_frame,
1023 struct cris_unwind_cache *info)
1025 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1026 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1028 /* Present instruction. */
1029 unsigned short insn;
1031 /* Next instruction, lookahead. */
1032 unsigned short insn_next;
1035 /* Number of byte on stack used for local variables and movem. */
1038 /* Highest register number in a movem. */
1041 /* move.d r<source_register>,rS */
1042 short source_register;
1047 /* This frame is with respect to a leaf until a push srp is found. */
1050 info->leaf_function = 1;
1053 /* Assume nothing on stack. */
1057 /* If we were called without a this_frame, that means we were called
1058 from cris_skip_prologue which already tried to find the end of the
1059 prologue through the symbol information. 64 instructions past current
1060 pc is arbitrarily chosen, but at least it means we'll stop eventually. */
1061 limit = this_frame ? get_frame_pc (this_frame) : pc + 64;
1063 /* Find the prologue instructions. */
1064 while (pc > 0 && pc < limit)
1066 insn = read_memory_unsigned_integer (pc, 2, byte_order);
1070 /* push <reg> 32 bit instruction. */
1071 insn_next = read_memory_unsigned_integer (pc, 2, byte_order);
1073 regno = cris_get_operand2 (insn_next);
1076 info->sp_offset += 4;
1078 /* This check, meant to recognize srp, used to be regno ==
1079 (SRP_REGNUM - NUM_GENREGS), but that covers r11 also. */
1080 if (insn_next == 0xBE7E)
1084 info->leaf_function = 0;
1087 else if (insn_next == 0x8FEE)
1092 info->r8_offset = info->sp_offset;
1096 else if (insn == 0x866E)
1101 info->uses_frame = 1;
1105 else if (cris_get_operand2 (insn) == gdbarch_sp_regnum (gdbarch)
1106 && cris_get_mode (insn) == 0x0000
1107 && cris_get_opcode (insn) == 0x000A)
1112 info->sp_offset += cris_get_quick_value (insn);
1115 else if (cris_get_mode (insn) == 0x0002
1116 && cris_get_opcode (insn) == 0x000F
1117 && cris_get_size (insn) == 0x0003
1118 && cris_get_operand1 (insn) == gdbarch_sp_regnum (gdbarch))
1120 /* movem r<regsave>,[sp] */
1121 regsave = cris_get_operand2 (insn);
1123 else if (cris_get_operand2 (insn) == gdbarch_sp_regnum (gdbarch)
1124 && ((insn & 0x0F00) >> 8) == 0x0001
1125 && (cris_get_signed_offset (insn) < 0))
1127 /* Immediate byte offset addressing prefix word with sp as base
1128 register. Used for CRIS v8 i.e. ETRAX 100 and newer if <val>
1129 is between 64 and 128.
1130 movem r<regsave>,[sp=sp-<val>] */
1133 info->sp_offset += -cris_get_signed_offset (insn);
1135 insn_next = read_memory_unsigned_integer (pc, 2, byte_order);
1137 if (cris_get_mode (insn_next) == PREFIX_ASSIGN_MODE
1138 && cris_get_opcode (insn_next) == 0x000F
1139 && cris_get_size (insn_next) == 0x0003
1140 && cris_get_operand1 (insn_next) == gdbarch_sp_regnum
1143 regsave = cris_get_operand2 (insn_next);
1147 /* The prologue ended before the limit was reached. */
1152 else if (cris_get_mode (insn) == 0x0001
1153 && cris_get_opcode (insn) == 0x0009
1154 && cris_get_size (insn) == 0x0002)
1156 /* move.d r<10..13>,r<0..15> */
1157 source_register = cris_get_operand1 (insn);
1159 /* FIXME? In the glibc solibs, the prologue might contain something
1160 like (this example taken from relocate_doit):
1162 sub.d 0xfffef426,$r0
1163 which isn't covered by the source_register check below. Question
1164 is whether to add a check for this combo, or make better use of
1165 the limit variable instead. */
1166 if (source_register < ARG1_REGNUM || source_register > ARG4_REGNUM)
1168 /* The prologue ended before the limit was reached. */
1173 else if (cris_get_operand2 (insn) == CRIS_FP_REGNUM
1174 /* The size is a fixed-size. */
1175 && ((insn & 0x0F00) >> 8) == 0x0001
1176 /* A negative offset. */
1177 && (cris_get_signed_offset (insn) < 0))
1179 /* move.S rZ,[r8-U] (?) */
1180 insn_next = read_memory_unsigned_integer (pc, 2, byte_order);
1182 regno = cris_get_operand2 (insn_next);
1183 if ((regno >= 0 && regno < gdbarch_sp_regnum (gdbarch))
1184 && cris_get_mode (insn_next) == PREFIX_OFFSET_MODE
1185 && cris_get_opcode (insn_next) == 0x000F)
1187 /* move.S rZ,[r8-U] */
1192 /* The prologue ended before the limit was reached. */
1197 else if (cris_get_operand2 (insn) == CRIS_FP_REGNUM
1198 /* The size is a fixed-size. */
1199 && ((insn & 0x0F00) >> 8) == 0x0001
1200 /* A positive offset. */
1201 && (cris_get_signed_offset (insn) > 0))
1203 /* move.S [r8+U],rZ (?) */
1204 insn_next = read_memory_unsigned_integer (pc, 2, byte_order);
1206 regno = cris_get_operand2 (insn_next);
1207 if ((regno >= 0 && regno < gdbarch_sp_regnum (gdbarch))
1208 && cris_get_mode (insn_next) == PREFIX_OFFSET_MODE
1209 && cris_get_opcode (insn_next) == 0x0009
1210 && cris_get_operand1 (insn_next) == regno)
1212 /* move.S [r8+U],rZ */
1217 /* The prologue ended before the limit was reached. */
1224 /* The prologue ended before the limit was reached. */
1230 /* We only want to know the end of the prologue when this_frame and info
1231 are NULL (called from cris_skip_prologue i.e.). */
1232 if (this_frame == NULL && info == NULL)
1237 info->size = info->sp_offset;
1239 /* Compute the previous frame's stack pointer (which is also the
1240 frame's ID's stack address), and this frame's base pointer. */
1241 if (info->uses_frame)
1244 /* The SP was moved to the FP. This indicates that a new frame
1245 was created. Get THIS frame's FP value by unwinding it from
1247 this_base = get_frame_register_unsigned (this_frame, CRIS_FP_REGNUM);
1248 info->base = this_base;
1249 info->saved_regs[CRIS_FP_REGNUM].addr = info->base;
1251 /* The FP points at the last saved register. Adjust the FP back
1252 to before the first saved register giving the SP. */
1253 info->prev_sp = info->base + info->r8_offset;
1258 /* Assume that the FP is this frame's SP but with that pushed
1259 stack space added back. */
1260 this_base = get_frame_register_unsigned (this_frame,
1261 gdbarch_sp_regnum (gdbarch));
1262 info->base = this_base;
1263 info->prev_sp = info->base + info->size;
1266 /* Calculate the addresses for the saved registers on the stack. */
1267 /* FIXME: The address calculation should really be done on the fly while
1268 we're analyzing the prologue (we only hold one regsave value as it is
1270 val = info->sp_offset;
1272 for (regno = regsave; regno >= 0; regno--)
1274 info->saved_regs[regno].addr = info->base + info->r8_offset - val;
1278 /* The previous frame's SP needed to be computed. Save the computed
1280 trad_frame_set_value (info->saved_regs,
1281 gdbarch_sp_regnum (gdbarch), info->prev_sp);
1283 if (!info->leaf_function)
1285 /* SRP saved on the stack. But where? */
1286 if (info->r8_offset == 0)
1288 /* R8 not pushed yet. */
1289 info->saved_regs[SRP_REGNUM].addr = info->base;
1293 /* R8 pushed, but SP may or may not be moved to R8 yet. */
1294 info->saved_regs[SRP_REGNUM].addr = info->base + 4;
1298 /* The PC is found in SRP (the actual register or located on the stack). */
1299 info->saved_regs[gdbarch_pc_regnum (gdbarch)]
1300 = info->saved_regs[SRP_REGNUM];
1306 crisv32_scan_prologue (CORE_ADDR pc, struct frame_info *this_frame,
1307 struct cris_unwind_cache *info)
1309 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1312 /* Unlike the CRISv10 prologue scanner (cris_scan_prologue), this is not
1313 meant to be a full-fledged prologue scanner. It is only needed for
1314 the cases where we end up in code always lacking DWARF-2 CFI, notably:
1316 * PLT stubs (library calls)
1318 * signal trampolines
1320 For those cases, it is assumed that there is no actual prologue; that
1321 the stack pointer is not adjusted, and (as a consequence) the return
1322 address is not pushed onto the stack. */
1324 /* We only want to know the end of the prologue when this_frame and info
1325 are NULL (called from cris_skip_prologue i.e.). */
1326 if (this_frame == NULL && info == NULL)
1331 /* The SP is assumed to be unaltered. */
1332 this_base = get_frame_register_unsigned (this_frame,
1333 gdbarch_sp_regnum (gdbarch));
1334 info->base = this_base;
1335 info->prev_sp = this_base;
1337 /* The PC is assumed to be found in SRP. */
1338 info->saved_regs[gdbarch_pc_regnum (gdbarch)]
1339 = info->saved_regs[SRP_REGNUM];
1344 /* Advance pc beyond any function entry prologue instructions at pc
1345 to reach some "real" code. */
1347 /* Given a PC value corresponding to the start of a function, return the PC
1348 of the first instruction after the function prologue. */
1351 cris_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
1353 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1354 CORE_ADDR func_addr, func_end;
1355 struct symtab_and_line sal;
1356 CORE_ADDR pc_after_prologue;
1358 /* If we have line debugging information, then the end of the prologue
1359 should the first assembly instruction of the first source line. */
1360 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
1362 sal = find_pc_line (func_addr, 0);
1363 if (sal.end > 0 && sal.end < func_end)
1367 if (tdep->cris_version == 32)
1368 pc_after_prologue = crisv32_scan_prologue (pc, NULL, NULL);
1370 pc_after_prologue = cris_scan_prologue (pc, NULL, NULL);
1372 return pc_after_prologue;
1376 cris_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
1379 pc = frame_unwind_register_unsigned (next_frame,
1380 gdbarch_pc_regnum (gdbarch));
1385 cris_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
1388 sp = frame_unwind_register_unsigned (next_frame,
1389 gdbarch_sp_regnum (gdbarch));
1393 /* Implement the breakpoint_kind_from_pc gdbarch method. */
1396 cris_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
1401 /* Implement the sw_breakpoint_from_kind gdbarch method. */
1403 static const gdb_byte *
1404 cris_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
1406 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1407 static unsigned char break8_insn[] = {0x38, 0xe9};
1408 static unsigned char break15_insn[] = {0x3f, 0xe9};
1412 if (tdep->cris_mode == cris_mode_guru)
1413 return break15_insn;
1418 /* Returns 1 if spec_reg is applicable to the current gdbarch's CRIS version,
1422 cris_spec_reg_applicable (struct gdbarch *gdbarch,
1423 struct cris_spec_reg spec_reg)
1425 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1426 unsigned int version = tdep->cris_version;
1428 switch (spec_reg.applicable_version)
1430 case cris_ver_version_all:
1432 case cris_ver_warning:
1433 /* Indeterminate/obsolete. */
1436 return in_inclusive_range (version, 0U, 3U);
1438 return (version >= 3);
1440 return in_inclusive_range (version, 8U, 9U);
1442 return (version >= 8);
1443 case cris_ver_v0_10:
1444 return in_inclusive_range (version, 0U, 10U);
1445 case cris_ver_v3_10:
1446 return in_inclusive_range (version, 3U, 10U);
1447 case cris_ver_v8_10:
1448 return in_inclusive_range (version, 8U, 10U);
1450 return (version == 10);
1452 return (version >= 10);
1454 return (version >= 32);
1456 /* Invalid cris version. */
1461 /* Returns the register size in unit byte. Returns 0 for an unimplemented
1462 register, -1 for an invalid register. */
1465 cris_register_size (struct gdbarch *gdbarch, int regno)
1470 if (regno >= 0 && regno < NUM_GENREGS)
1472 /* General registers (R0 - R15) are 32 bits. */
1475 else if (regno >= NUM_GENREGS && regno < (NUM_GENREGS + NUM_SPECREGS))
1477 /* Special register (R16 - R31). cris_spec_regs is zero-based.
1478 Adjust regno accordingly. */
1479 spec_regno = regno - NUM_GENREGS;
1481 for (i = 0; cris_spec_regs[i].name != NULL; i++)
1483 if (cris_spec_regs[i].number == spec_regno
1484 && cris_spec_reg_applicable (gdbarch, cris_spec_regs[i]))
1485 /* Go with the first applicable register. */
1486 return cris_spec_regs[i].reg_size;
1488 /* Special register not applicable to this CRIS version. */
1491 else if (regno >= gdbarch_pc_regnum (gdbarch)
1492 && regno < gdbarch_num_regs (gdbarch))
1494 /* This will apply to CRISv32 only where there are additional registers
1495 after the special registers (pseudo PC and support registers). */
1503 /* Nonzero if regno should not be fetched from the target. This is the case
1504 for unimplemented (size 0) and non-existant registers. */
1507 cris_cannot_fetch_register (struct gdbarch *gdbarch, int regno)
1509 return ((regno < 0 || regno >= gdbarch_num_regs (gdbarch))
1510 || (cris_register_size (gdbarch, regno) == 0));
1513 /* Nonzero if regno should not be written to the target, for various
1517 cris_cannot_store_register (struct gdbarch *gdbarch, int regno)
1519 /* There are three kinds of registers we refuse to write to.
1520 1. Those that not implemented.
1521 2. Those that are read-only (depends on the processor mode).
1522 3. Those registers to which a write has no effect. */
1525 || regno >= gdbarch_num_regs (gdbarch)
1526 || cris_register_size (gdbarch, regno) == 0)
1527 /* Not implemented. */
1530 else if (regno == VR_REGNUM)
1534 else if (regno == P0_REGNUM || regno == P4_REGNUM || regno == P8_REGNUM)
1535 /* Writing has no effect. */
1538 /* IBR, BAR, BRP and IRP are read-only in user mode. Let the debug
1539 agent decide whether they are writable. */
1544 /* Nonzero if regno should not be fetched from the target. This is the case
1545 for unimplemented (size 0) and non-existant registers. */
1548 crisv32_cannot_fetch_register (struct gdbarch *gdbarch, int regno)
1550 return ((regno < 0 || regno >= gdbarch_num_regs (gdbarch))
1551 || (cris_register_size (gdbarch, regno) == 0));
1554 /* Nonzero if regno should not be written to the target, for various
1558 crisv32_cannot_store_register (struct gdbarch *gdbarch, int regno)
1560 /* There are three kinds of registers we refuse to write to.
1561 1. Those that not implemented.
1562 2. Those that are read-only (depends on the processor mode).
1563 3. Those registers to which a write has no effect. */
1566 || regno >= gdbarch_num_regs (gdbarch)
1567 || cris_register_size (gdbarch, regno) == 0)
1568 /* Not implemented. */
1571 else if (regno == VR_REGNUM)
1575 else if (regno == BZ_REGNUM || regno == WZ_REGNUM || regno == DZ_REGNUM)
1576 /* Writing has no effect. */
1579 /* Many special registers are read-only in user mode. Let the debug
1580 agent decide whether they are writable. */
1585 /* Return the GDB type (defined in gdbtypes.c) for the "standard" data type
1586 of data in register regno. */
1588 static struct type *
1589 cris_register_type (struct gdbarch *gdbarch, int regno)
1591 if (regno == gdbarch_pc_regnum (gdbarch))
1592 return builtin_type (gdbarch)->builtin_func_ptr;
1593 else if (regno == gdbarch_sp_regnum (gdbarch)
1594 || regno == CRIS_FP_REGNUM)
1595 return builtin_type (gdbarch)->builtin_data_ptr;
1596 else if ((regno >= 0 && regno < gdbarch_sp_regnum (gdbarch))
1597 || (regno >= MOF_REGNUM && regno <= USP_REGNUM))
1598 /* Note: R8 taken care of previous clause. */
1599 return builtin_type (gdbarch)->builtin_uint32;
1600 else if (regno >= P4_REGNUM && regno <= CCR_REGNUM)
1601 return builtin_type (gdbarch)->builtin_uint16;
1602 else if (regno >= P0_REGNUM && regno <= VR_REGNUM)
1603 return builtin_type (gdbarch)->builtin_uint8;
1605 /* Invalid (unimplemented) register. */
1606 return builtin_type (gdbarch)->builtin_int0;
1609 static struct type *
1610 crisv32_register_type (struct gdbarch *gdbarch, int regno)
1612 if (regno == gdbarch_pc_regnum (gdbarch))
1613 return builtin_type (gdbarch)->builtin_func_ptr;
1614 else if (regno == gdbarch_sp_regnum (gdbarch)
1615 || regno == CRIS_FP_REGNUM)
1616 return builtin_type (gdbarch)->builtin_data_ptr;
1617 else if ((regno >= 0 && regno <= ACR_REGNUM)
1618 || (regno >= EXS_REGNUM && regno <= SPC_REGNUM)
1619 || (regno == PID_REGNUM)
1620 || (regno >= S0_REGNUM && regno <= S15_REGNUM))
1621 /* Note: R8 and SP taken care of by previous clause. */
1622 return builtin_type (gdbarch)->builtin_uint32;
1623 else if (regno == WZ_REGNUM)
1624 return builtin_type (gdbarch)->builtin_uint16;
1625 else if (regno == BZ_REGNUM || regno == VR_REGNUM || regno == SRS_REGNUM)
1626 return builtin_type (gdbarch)->builtin_uint8;
1629 /* Invalid (unimplemented) register. Should not happen as there are
1630 no unimplemented CRISv32 registers. */
1631 warning (_("crisv32_register_type: unknown regno %d"), regno);
1632 return builtin_type (gdbarch)->builtin_int0;
1636 /* Stores a function return value of type type, where valbuf is the address
1637 of the value to be stored. */
1639 /* In the CRIS ABI, R10 and R11 are used to store return values. */
1642 cris_store_return_value (struct type *type, struct regcache *regcache,
1643 const gdb_byte *valbuf)
1645 struct gdbarch *gdbarch = regcache->arch ();
1646 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1648 int len = TYPE_LENGTH (type);
1652 /* Put the return value in R10. */
1653 val = extract_unsigned_integer (valbuf, len, byte_order);
1654 regcache_cooked_write_unsigned (regcache, ARG1_REGNUM, val);
1658 /* Put the return value in R10 and R11. */
1659 val = extract_unsigned_integer (valbuf, 4, byte_order);
1660 regcache_cooked_write_unsigned (regcache, ARG1_REGNUM, val);
1661 val = extract_unsigned_integer (valbuf + 4, len - 4, byte_order);
1662 regcache_cooked_write_unsigned (regcache, ARG2_REGNUM, val);
1665 error (_("cris_store_return_value: type length too large."));
1668 /* Return the name of register regno as a string. Return NULL for an
1669 invalid or unimplemented register. */
1672 cris_special_register_name (struct gdbarch *gdbarch, int regno)
1677 /* Special register (R16 - R31). cris_spec_regs is zero-based.
1678 Adjust regno accordingly. */
1679 spec_regno = regno - NUM_GENREGS;
1681 /* Assume nothing about the layout of the cris_spec_regs struct
1683 for (i = 0; cris_spec_regs[i].name != NULL; i++)
1685 if (cris_spec_regs[i].number == spec_regno
1686 && cris_spec_reg_applicable (gdbarch, cris_spec_regs[i]))
1687 /* Go with the first applicable register. */
1688 return cris_spec_regs[i].name;
1690 /* Special register not applicable to this CRIS version. */
1695 cris_register_name (struct gdbarch *gdbarch, int regno)
1697 static const char *cris_genreg_names[] =
1698 { "r0", "r1", "r2", "r3", \
1699 "r4", "r5", "r6", "r7", \
1700 "r8", "r9", "r10", "r11", \
1701 "r12", "r13", "sp", "pc" };
1703 if (regno >= 0 && regno < NUM_GENREGS)
1705 /* General register. */
1706 return cris_genreg_names[regno];
1708 else if (regno >= NUM_GENREGS && regno < gdbarch_num_regs (gdbarch))
1710 return cris_special_register_name (gdbarch, regno);
1714 /* Invalid register. */
1720 crisv32_register_name (struct gdbarch *gdbarch, int regno)
1722 static const char *crisv32_genreg_names[] =
1723 { "r0", "r1", "r2", "r3", \
1724 "r4", "r5", "r6", "r7", \
1725 "r8", "r9", "r10", "r11", \
1726 "r12", "r13", "sp", "acr"
1729 static const char *crisv32_sreg_names[] =
1730 { "s0", "s1", "s2", "s3", \
1731 "s4", "s5", "s6", "s7", \
1732 "s8", "s9", "s10", "s11", \
1733 "s12", "s13", "s14", "s15"
1736 if (regno >= 0 && regno < NUM_GENREGS)
1738 /* General register. */
1739 return crisv32_genreg_names[regno];
1741 else if (regno >= NUM_GENREGS && regno < (NUM_GENREGS + NUM_SPECREGS))
1743 return cris_special_register_name (gdbarch, regno);
1745 else if (regno == gdbarch_pc_regnum (gdbarch))
1749 else if (regno >= S0_REGNUM && regno <= S15_REGNUM)
1751 return crisv32_sreg_names[regno - S0_REGNUM];
1755 /* Invalid register. */
1760 /* Convert DWARF register number REG to the appropriate register
1761 number used by GDB. */
1764 cris_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int reg)
1766 /* We need to re-map a couple of registers (SRP is 16 in Dwarf-2 register
1767 numbering, MOF is 18).
1768 Adapted from gcc/config/cris/cris.h. */
1769 static int cris_dwarf_regmap[] = {
1781 if (reg >= 0 && reg < ARRAY_SIZE (cris_dwarf_regmap))
1782 regnum = cris_dwarf_regmap[reg];
1787 /* DWARF-2 frame support. */
1790 cris_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
1791 struct dwarf2_frame_state_reg *reg,
1792 struct frame_info *this_frame)
1794 /* The return address column. */
1795 if (regnum == gdbarch_pc_regnum (gdbarch))
1796 reg->how = DWARF2_FRAME_REG_RA;
1798 /* The call frame address. */
1799 else if (regnum == gdbarch_sp_regnum (gdbarch))
1800 reg->how = DWARF2_FRAME_REG_CFA;
1803 /* Extract from an array regbuf containing the raw register state a function
1804 return value of type type, and copy that, in virtual format, into
1807 /* In the CRIS ABI, R10 and R11 are used to store return values. */
1810 cris_extract_return_value (struct type *type, struct regcache *regcache,
1813 struct gdbarch *gdbarch = regcache->arch ();
1814 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1816 int len = TYPE_LENGTH (type);
1820 /* Get the return value from R10. */
1821 regcache_cooked_read_unsigned (regcache, ARG1_REGNUM, &val);
1822 store_unsigned_integer (valbuf, len, byte_order, val);
1826 /* Get the return value from R10 and R11. */
1827 regcache_cooked_read_unsigned (regcache, ARG1_REGNUM, &val);
1828 store_unsigned_integer (valbuf, 4, byte_order, val);
1829 regcache_cooked_read_unsigned (regcache, ARG2_REGNUM, &val);
1830 store_unsigned_integer (valbuf + 4, len - 4, byte_order, val);
1833 error (_("cris_extract_return_value: type length too large"));
1836 /* Handle the CRIS return value convention. */
1838 static enum return_value_convention
1839 cris_return_value (struct gdbarch *gdbarch, struct value *function,
1840 struct type *type, struct regcache *regcache,
1841 gdb_byte *readbuf, const gdb_byte *writebuf)
1843 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
1844 || TYPE_CODE (type) == TYPE_CODE_UNION
1845 || TYPE_LENGTH (type) > 8)
1846 /* Structs, unions, and anything larger than 8 bytes (2 registers)
1847 goes on the stack. */
1848 return RETURN_VALUE_STRUCT_CONVENTION;
1851 cris_extract_return_value (type, regcache, readbuf);
1853 cris_store_return_value (type, regcache, writebuf);
1855 return RETURN_VALUE_REGISTER_CONVENTION;
1858 /* Calculates a value that measures how good inst_args constraints an
1859 instruction. It stems from cris_constraint, found in cris-dis.c. */
1862 constraint (unsigned int insn, const char *inst_args,
1863 inst_env_type *inst_env)
1868 const gdb_byte *s = (const gdb_byte *) inst_args;
1874 if ((insn & 0x30) == 0x30)
1879 /* A prefix operand. */
1880 if (inst_env->prefix_found)
1886 /* A "push" prefix. (This check was REMOVED by san 970921.) Check for
1887 valid "push" size. In case of special register, it may be != 4. */
1888 if (inst_env->prefix_found)
1894 retval = (((insn >> 0xC) & 0xF) == (insn & 0xF));
1902 tmp = (insn >> 0xC) & 0xF;
1904 for (i = 0; cris_spec_regs[i].name != NULL; i++)
1906 /* Since we match four bits, we will give a value of
1907 4 - 1 = 3 in a match. If there is a corresponding
1908 exact match of a special register in another pattern, it
1909 will get a value of 4, which will be higher. This should
1910 be correct in that an exact pattern would match better that
1912 Note that there is a reason for not returning zero; the
1913 pattern for "clear" is partly matched in the bit-pattern
1914 (the two lower bits must be zero), while the bit-pattern
1915 for a move from a special register is matched in the
1916 register constraint.
1917 This also means we will will have a race condition if
1918 there is a partly match in three bits in the bit pattern. */
1919 if (tmp == cris_spec_regs[i].number)
1926 if (cris_spec_regs[i].name == NULL)
1933 /* Returns the number of bits set in the variable value. */
1936 number_of_bits (unsigned int value)
1938 int number_of_bits = 0;
1942 number_of_bits += 1;
1943 value &= (value - 1);
1945 return number_of_bits;
1948 /* Finds the address that should contain the single step breakpoint(s).
1949 It stems from code in cris-dis.c. */
1952 find_cris_op (unsigned short insn, inst_env_type *inst_env)
1955 int max_level_of_match = -1;
1956 int max_matched = -1;
1959 for (i = 0; cris_opcodes[i].name != NULL; i++)
1961 if (((cris_opcodes[i].match & insn) == cris_opcodes[i].match)
1962 && ((cris_opcodes[i].lose & insn) == 0)
1963 /* Only CRISv10 instructions, please. */
1964 && (cris_opcodes[i].applicable_version != cris_ver_v32p))
1966 level_of_match = constraint (insn, cris_opcodes[i].args, inst_env);
1967 if (level_of_match >= 0)
1970 number_of_bits (cris_opcodes[i].match | cris_opcodes[i].lose);
1971 if (level_of_match > max_level_of_match)
1974 max_level_of_match = level_of_match;
1975 if (level_of_match == 16)
1977 /* All bits matched, cannot find better. */
1987 /* Attempts to find single-step breakpoints. Returns -1 on failure which is
1988 actually an internal error. */
1991 find_step_target (struct regcache *regcache, inst_env_type *inst_env)
1995 unsigned short insn;
1996 struct gdbarch *gdbarch = regcache->arch ();
1997 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1999 /* Create a local register image and set the initial state. */
2000 for (i = 0; i < NUM_GENREGS; i++)
2003 (unsigned long) regcache_raw_get_unsigned (regcache, i);
2005 offset = NUM_GENREGS;
2006 for (i = 0; i < NUM_SPECREGS; i++)
2009 (unsigned long) regcache_raw_get_unsigned (regcache, offset + i);
2011 inst_env->branch_found = 0;
2012 inst_env->slot_needed = 0;
2013 inst_env->delay_slot_pc_active = 0;
2014 inst_env->prefix_found = 0;
2015 inst_env->invalid = 0;
2016 inst_env->xflag_found = 0;
2017 inst_env->disable_interrupt = 0;
2018 inst_env->byte_order = byte_order;
2020 /* Look for a step target. */
2023 /* Read an instruction from the client. */
2024 insn = read_memory_unsigned_integer
2025 (inst_env->reg[gdbarch_pc_regnum (gdbarch)], 2, byte_order);
2027 /* If the instruction is not in a delay slot the new content of the
2028 PC is [PC] + 2. If the instruction is in a delay slot it is not
2029 that simple. Since a instruction in a delay slot cannot change
2030 the content of the PC, it does not matter what value PC will have.
2031 Just make sure it is a valid instruction. */
2032 if (!inst_env->delay_slot_pc_active)
2034 inst_env->reg[gdbarch_pc_regnum (gdbarch)] += 2;
2038 inst_env->delay_slot_pc_active = 0;
2039 inst_env->reg[gdbarch_pc_regnum (gdbarch)]
2040 = inst_env->delay_slot_pc;
2042 /* Analyse the present instruction. */
2043 i = find_cris_op (insn, inst_env);
2046 inst_env->invalid = 1;
2050 cris_gdb_func (gdbarch, cris_opcodes[i].op, insn, inst_env);
2052 } while (!inst_env->invalid
2053 && (inst_env->prefix_found || inst_env->xflag_found
2054 || inst_env->slot_needed));
2058 /* There is no hardware single-step support. The function find_step_target
2059 digs through the opcodes in order to find all possible targets.
2060 Either one ordinary target or two targets for branches may be found. */
2062 static std::vector<CORE_ADDR>
2063 cris_software_single_step (struct regcache *regcache)
2065 struct gdbarch *gdbarch = regcache->arch ();
2066 inst_env_type inst_env;
2067 std::vector<CORE_ADDR> next_pcs;
2069 /* Analyse the present instruction environment and insert
2071 int status = find_step_target (regcache, &inst_env);
2074 /* Could not find a target. Things are likely to go downhill
2076 warning (_("CRIS software single step could not find a step target."));
2080 /* Insert at most two breakpoints. One for the next PC content
2081 and possibly another one for a branch, jump, etc. */
2083 = (CORE_ADDR) inst_env.reg[gdbarch_pc_regnum (gdbarch)];
2085 next_pcs.push_back (next_pc);
2086 if (inst_env.branch_found
2087 && (CORE_ADDR) inst_env.branch_break_address != next_pc)
2089 CORE_ADDR branch_target_address
2090 = (CORE_ADDR) inst_env.branch_break_address;
2092 next_pcs.push_back (branch_target_address);
2099 /* Calculates the prefix value for quick offset addressing mode. */
2102 quick_mode_bdap_prefix (unsigned short inst, inst_env_type *inst_env)
2104 /* It's invalid to be in a delay slot. You can't have a prefix to this
2105 instruction (not 100% sure). */
2106 if (inst_env->slot_needed || inst_env->prefix_found)
2108 inst_env->invalid = 1;
2112 inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)];
2113 inst_env->prefix_value += cris_get_bdap_quick_offset (inst);
2115 /* A prefix doesn't change the xflag_found. But the rest of the flags
2117 inst_env->slot_needed = 0;
2118 inst_env->prefix_found = 1;
2121 /* Updates the autoincrement register. The size of the increment is derived
2122 from the size of the operation. The PC is always kept aligned on even
2126 process_autoincrement (int size, unsigned short inst, inst_env_type *inst_env)
2128 if (size == INST_BYTE_SIZE)
2130 inst_env->reg[cris_get_operand1 (inst)] += 1;
2132 /* The PC must be word aligned, so increase the PC with one
2133 word even if the size is byte. */
2134 if (cris_get_operand1 (inst) == REG_PC)
2136 inst_env->reg[REG_PC] += 1;
2139 else if (size == INST_WORD_SIZE)
2141 inst_env->reg[cris_get_operand1 (inst)] += 2;
2143 else if (size == INST_DWORD_SIZE)
2145 inst_env->reg[cris_get_operand1 (inst)] += 4;
2150 inst_env->invalid = 1;
2154 /* Just a forward declaration. */
2156 static unsigned long get_data_from_address (unsigned short *inst,
2158 enum bfd_endian byte_order);
2160 /* Calculates the prefix value for the general case of offset addressing
2164 bdap_prefix (unsigned short inst, inst_env_type *inst_env)
2166 /* It's invalid to be in a delay slot. */
2167 if (inst_env->slot_needed || inst_env->prefix_found)
2169 inst_env->invalid = 1;
2173 /* The calculation of prefix_value used to be after process_autoincrement,
2174 but that fails for an instruction such as jsr [$r0+12] which is encoded
2175 as 5f0d 0c00 30b9 when compiled with -fpic. Since PC is operand1 it
2176 mustn't be incremented until we have read it and what it points at. */
2177 inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)];
2179 /* The offset is an indirection of the contents of the operand1 register. */
2180 inst_env->prefix_value +=
2181 get_data_from_address (&inst, inst_env->reg[cris_get_operand1 (inst)],
2182 inst_env->byte_order);
2184 if (cris_get_mode (inst) == AUTOINC_MODE)
2186 process_autoincrement (cris_get_size (inst), inst, inst_env);
2189 /* A prefix doesn't change the xflag_found. But the rest of the flags
2191 inst_env->slot_needed = 0;
2192 inst_env->prefix_found = 1;
2195 /* Calculates the prefix value for the index addressing mode. */
2198 biap_prefix (unsigned short inst, inst_env_type *inst_env)
2200 /* It's invalid to be in a delay slot. I can't see that it's possible to
2201 have a prefix to this instruction. So I will treat this as invalid. */
2202 if (inst_env->slot_needed || inst_env->prefix_found)
2204 inst_env->invalid = 1;
2208 inst_env->prefix_value = inst_env->reg[cris_get_operand1 (inst)];
2210 /* The offset is the operand2 value shifted the size of the instruction
2212 inst_env->prefix_value +=
2213 inst_env->reg[cris_get_operand2 (inst)] << cris_get_size (inst);
2215 /* If the PC is operand1 (base) the address used is the address after
2216 the main instruction, i.e. address + 2 (the PC is already compensated
2217 for the prefix operation). */
2218 if (cris_get_operand1 (inst) == REG_PC)
2220 inst_env->prefix_value += 2;
2223 /* A prefix doesn't change the xflag_found. But the rest of the flags
2225 inst_env->slot_needed = 0;
2226 inst_env->xflag_found = 0;
2227 inst_env->prefix_found = 1;
2230 /* Calculates the prefix value for the double indirect addressing mode. */
2233 dip_prefix (unsigned short inst, inst_env_type *inst_env)
2238 /* It's invalid to be in a delay slot. */
2239 if (inst_env->slot_needed || inst_env->prefix_found)
2241 inst_env->invalid = 1;
2245 /* The prefix value is one dereference of the contents of the operand1
2247 address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)];
2248 inst_env->prefix_value
2249 = read_memory_unsigned_integer (address, 4, inst_env->byte_order);
2251 /* Check if the mode is autoincrement. */
2252 if (cris_get_mode (inst) == AUTOINC_MODE)
2254 inst_env->reg[cris_get_operand1 (inst)] += 4;
2257 /* A prefix doesn't change the xflag_found. But the rest of the flags
2259 inst_env->slot_needed = 0;
2260 inst_env->xflag_found = 0;
2261 inst_env->prefix_found = 1;
2264 /* Finds the destination for a branch with 8-bits offset. */
2267 eight_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env)
2272 /* If we have a prefix or are in a delay slot it's bad. */
2273 if (inst_env->slot_needed || inst_env->prefix_found)
2275 inst_env->invalid = 1;
2279 /* We have a branch, find out where the branch will land. */
2280 offset = cris_get_branch_short_offset (inst);
2282 /* Check if the offset is signed. */
2283 if (offset & BRANCH_SIGNED_SHORT_OFFSET_MASK)
2288 /* The offset ends with the sign bit, set it to zero. The address
2289 should always be word aligned. */
2290 offset &= ~BRANCH_SIGNED_SHORT_OFFSET_MASK;
2292 inst_env->branch_found = 1;
2293 inst_env->branch_break_address = inst_env->reg[REG_PC] + offset;
2295 inst_env->slot_needed = 1;
2296 inst_env->prefix_found = 0;
2297 inst_env->xflag_found = 0;
2298 inst_env->disable_interrupt = 1;
2301 /* Finds the destination for a branch with 16-bits offset. */
2304 sixteen_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env)
2308 /* If we have a prefix or is in a delay slot it's bad. */
2309 if (inst_env->slot_needed || inst_env->prefix_found)
2311 inst_env->invalid = 1;
2315 /* We have a branch, find out the offset for the branch. */
2316 offset = read_memory_integer (inst_env->reg[REG_PC], 2,
2317 inst_env->byte_order);
2319 /* The instruction is one word longer than normal, so add one word
2321 inst_env->reg[REG_PC] += 2;
2323 inst_env->branch_found = 1;
2324 inst_env->branch_break_address = inst_env->reg[REG_PC] + offset;
2327 inst_env->slot_needed = 1;
2328 inst_env->prefix_found = 0;
2329 inst_env->xflag_found = 0;
2330 inst_env->disable_interrupt = 1;
2333 /* Handles the ABS instruction. */
2336 abs_op (unsigned short inst, inst_env_type *inst_env)
2341 /* ABS can't have a prefix, so it's bad if it does. */
2342 if (inst_env->prefix_found)
2344 inst_env->invalid = 1;
2348 /* Check if the operation affects the PC. */
2349 if (cris_get_operand2 (inst) == REG_PC)
2352 /* It's invalid to change to the PC if we are in a delay slot. */
2353 if (inst_env->slot_needed)
2355 inst_env->invalid = 1;
2359 value = (long) inst_env->reg[REG_PC];
2361 /* The value of abs (SIGNED_DWORD_MASK) is SIGNED_DWORD_MASK. */
2362 if (value != SIGNED_DWORD_MASK)
2365 inst_env->reg[REG_PC] = (long) value;
2369 inst_env->slot_needed = 0;
2370 inst_env->prefix_found = 0;
2371 inst_env->xflag_found = 0;
2372 inst_env->disable_interrupt = 0;
2375 /* Handles the ADDI instruction. */
2378 addi_op (unsigned short inst, inst_env_type *inst_env)
2380 /* It's invalid to have the PC as base register. And ADDI can't have
2382 if (inst_env->prefix_found || (cris_get_operand1 (inst) == REG_PC))
2384 inst_env->invalid = 1;
2388 inst_env->slot_needed = 0;
2389 inst_env->prefix_found = 0;
2390 inst_env->xflag_found = 0;
2391 inst_env->disable_interrupt = 0;
2394 /* Handles the ASR instruction. */
2397 asr_op (unsigned short inst, inst_env_type *inst_env)
2400 unsigned long value;
2401 unsigned long signed_extend_mask = 0;
2403 /* ASR can't have a prefix, so check that it doesn't. */
2404 if (inst_env->prefix_found)
2406 inst_env->invalid = 1;
2410 /* Check if the PC is the target register. */
2411 if (cris_get_operand2 (inst) == REG_PC)
2413 /* It's invalid to change the PC in a delay slot. */
2414 if (inst_env->slot_needed)
2416 inst_env->invalid = 1;
2419 /* Get the number of bits to shift. */
2421 = cris_get_asr_shift_steps (inst_env->reg[cris_get_operand1 (inst)]);
2422 value = inst_env->reg[REG_PC];
2424 /* Find out how many bits the operation should apply to. */
2425 if (cris_get_size (inst) == INST_BYTE_SIZE)
2427 if (value & SIGNED_BYTE_MASK)
2429 signed_extend_mask = 0xFF;
2430 signed_extend_mask = signed_extend_mask >> shift_steps;
2431 signed_extend_mask = ~signed_extend_mask;
2433 value = value >> shift_steps;
2434 value |= signed_extend_mask;
2436 inst_env->reg[REG_PC] &= 0xFFFFFF00;
2437 inst_env->reg[REG_PC] |= value;
2439 else if (cris_get_size (inst) == INST_WORD_SIZE)
2441 if (value & SIGNED_WORD_MASK)
2443 signed_extend_mask = 0xFFFF;
2444 signed_extend_mask = signed_extend_mask >> shift_steps;
2445 signed_extend_mask = ~signed_extend_mask;
2447 value = value >> shift_steps;
2448 value |= signed_extend_mask;
2450 inst_env->reg[REG_PC] &= 0xFFFF0000;
2451 inst_env->reg[REG_PC] |= value;
2453 else if (cris_get_size (inst) == INST_DWORD_SIZE)
2455 if (value & SIGNED_DWORD_MASK)
2457 signed_extend_mask = 0xFFFFFFFF;
2458 signed_extend_mask = signed_extend_mask >> shift_steps;
2459 signed_extend_mask = ~signed_extend_mask;
2461 value = value >> shift_steps;
2462 value |= signed_extend_mask;
2463 inst_env->reg[REG_PC] = value;
2466 inst_env->slot_needed = 0;
2467 inst_env->prefix_found = 0;
2468 inst_env->xflag_found = 0;
2469 inst_env->disable_interrupt = 0;
2472 /* Handles the ASRQ instruction. */
2475 asrq_op (unsigned short inst, inst_env_type *inst_env)
2479 unsigned long value;
2480 unsigned long signed_extend_mask = 0;
2482 /* ASRQ can't have a prefix, so check that it doesn't. */
2483 if (inst_env->prefix_found)
2485 inst_env->invalid = 1;
2489 /* Check if the PC is the target register. */
2490 if (cris_get_operand2 (inst) == REG_PC)
2493 /* It's invalid to change the PC in a delay slot. */
2494 if (inst_env->slot_needed)
2496 inst_env->invalid = 1;
2499 /* The shift size is given as a 5 bit quick value, i.e. we don't
2500 want the sign bit of the quick value. */
2501 shift_steps = cris_get_asr_shift_steps (inst);
2502 value = inst_env->reg[REG_PC];
2503 if (value & SIGNED_DWORD_MASK)
2505 signed_extend_mask = 0xFFFFFFFF;
2506 signed_extend_mask = signed_extend_mask >> shift_steps;
2507 signed_extend_mask = ~signed_extend_mask;
2509 value = value >> shift_steps;
2510 value |= signed_extend_mask;
2511 inst_env->reg[REG_PC] = value;
2513 inst_env->slot_needed = 0;
2514 inst_env->prefix_found = 0;
2515 inst_env->xflag_found = 0;
2516 inst_env->disable_interrupt = 0;
2519 /* Handles the AX, EI and SETF instruction. */
2522 ax_ei_setf_op (unsigned short inst, inst_env_type *inst_env)
2524 if (inst_env->prefix_found)
2526 inst_env->invalid = 1;
2529 /* Check if the instruction is setting the X flag. */
2530 if (cris_is_xflag_bit_on (inst))
2532 inst_env->xflag_found = 1;
2536 inst_env->xflag_found = 0;
2538 inst_env->slot_needed = 0;
2539 inst_env->prefix_found = 0;
2540 inst_env->disable_interrupt = 1;
2543 /* Checks if the instruction is in assign mode. If so, it updates the assign
2544 register. Note that check_assign assumes that the caller has checked that
2545 there is a prefix to this instruction. The mode check depends on this. */
2548 check_assign (unsigned short inst, inst_env_type *inst_env)
2550 /* Check if it's an assign addressing mode. */
2551 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2553 /* Assign the prefix value to operand 1. */
2554 inst_env->reg[cris_get_operand1 (inst)] = inst_env->prefix_value;
2558 /* Handles the 2-operand BOUND instruction. */
2561 two_operand_bound_op (unsigned short inst, inst_env_type *inst_env)
2563 /* It's invalid to have the PC as the index operand. */
2564 if (cris_get_operand2 (inst) == REG_PC)
2566 inst_env->invalid = 1;
2569 /* Check if we have a prefix. */
2570 if (inst_env->prefix_found)
2572 check_assign (inst, inst_env);
2574 /* Check if this is an autoincrement mode. */
2575 else if (cris_get_mode (inst) == AUTOINC_MODE)
2577 /* It's invalid to change the PC in a delay slot. */
2578 if (inst_env->slot_needed)
2580 inst_env->invalid = 1;
2583 process_autoincrement (cris_get_size (inst), inst, inst_env);
2585 inst_env->slot_needed = 0;
2586 inst_env->prefix_found = 0;
2587 inst_env->xflag_found = 0;
2588 inst_env->disable_interrupt = 0;
2591 /* Handles the 3-operand BOUND instruction. */
2594 three_operand_bound_op (unsigned short inst, inst_env_type *inst_env)
2596 /* It's an error if we haven't got a prefix. And it's also an error
2597 if the PC is the destination register. */
2598 if ((!inst_env->prefix_found) || (cris_get_operand1 (inst) == REG_PC))
2600 inst_env->invalid = 1;
2603 inst_env->slot_needed = 0;
2604 inst_env->prefix_found = 0;
2605 inst_env->xflag_found = 0;
2606 inst_env->disable_interrupt = 0;
2609 /* Clears the status flags in inst_env. */
2612 btst_nop_op (unsigned short inst, inst_env_type *inst_env)
2614 /* It's an error if we have got a prefix. */
2615 if (inst_env->prefix_found)
2617 inst_env->invalid = 1;
2621 inst_env->slot_needed = 0;
2622 inst_env->prefix_found = 0;
2623 inst_env->xflag_found = 0;
2624 inst_env->disable_interrupt = 0;
2627 /* Clears the status flags in inst_env. */
2630 clearf_di_op (unsigned short inst, inst_env_type *inst_env)
2632 /* It's an error if we have got a prefix. */
2633 if (inst_env->prefix_found)
2635 inst_env->invalid = 1;
2639 inst_env->slot_needed = 0;
2640 inst_env->prefix_found = 0;
2641 inst_env->xflag_found = 0;
2642 inst_env->disable_interrupt = 1;
2645 /* Handles the CLEAR instruction if it's in register mode. */
2648 reg_mode_clear_op (unsigned short inst, inst_env_type *inst_env)
2650 /* Check if the target is the PC. */
2651 if (cris_get_operand2 (inst) == REG_PC)
2653 /* The instruction will clear the instruction's size bits. */
2654 int clear_size = cris_get_clear_size (inst);
2655 if (clear_size == INST_BYTE_SIZE)
2657 inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFFFF00;
2659 if (clear_size == INST_WORD_SIZE)
2661 inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFF0000;
2663 if (clear_size == INST_DWORD_SIZE)
2665 inst_env->delay_slot_pc = 0x0;
2667 /* The jump will be delayed with one delay slot. So we need a delay
2669 inst_env->slot_needed = 1;
2670 inst_env->delay_slot_pc_active = 1;
2674 /* The PC will not change => no delay slot. */
2675 inst_env->slot_needed = 0;
2677 inst_env->prefix_found = 0;
2678 inst_env->xflag_found = 0;
2679 inst_env->disable_interrupt = 0;
2682 /* Handles the TEST instruction if it's in register mode. */
2685 reg_mode_test_op (unsigned short inst, inst_env_type *inst_env)
2687 /* It's an error if we have got a prefix. */
2688 if (inst_env->prefix_found)
2690 inst_env->invalid = 1;
2693 inst_env->slot_needed = 0;
2694 inst_env->prefix_found = 0;
2695 inst_env->xflag_found = 0;
2696 inst_env->disable_interrupt = 0;
2700 /* Handles the CLEAR and TEST instruction if the instruction isn't
2701 in register mode. */
2704 none_reg_mode_clear_test_op (unsigned short inst, inst_env_type *inst_env)
2706 /* Check if we are in a prefix mode. */
2707 if (inst_env->prefix_found)
2709 /* The only way the PC can change is if this instruction is in
2710 assign addressing mode. */
2711 check_assign (inst, inst_env);
2713 /* Indirect mode can't change the PC so just check if the mode is
2715 else if (cris_get_mode (inst) == AUTOINC_MODE)
2717 process_autoincrement (cris_get_size (inst), inst, inst_env);
2719 inst_env->slot_needed = 0;
2720 inst_env->prefix_found = 0;
2721 inst_env->xflag_found = 0;
2722 inst_env->disable_interrupt = 0;
2725 /* Checks that the PC isn't the destination register or the instructions has
2729 dstep_logshift_mstep_neg_not_op (unsigned short inst, inst_env_type *inst_env)
2731 /* It's invalid to have the PC as the destination. The instruction can't
2733 if ((cris_get_operand2 (inst) == REG_PC) || inst_env->prefix_found)
2735 inst_env->invalid = 1;
2739 inst_env->slot_needed = 0;
2740 inst_env->prefix_found = 0;
2741 inst_env->xflag_found = 0;
2742 inst_env->disable_interrupt = 0;
2745 /* Checks that the instruction doesn't have a prefix. */
2748 break_op (unsigned short inst, inst_env_type *inst_env)
2750 /* The instruction can't have a prefix. */
2751 if (inst_env->prefix_found)
2753 inst_env->invalid = 1;
2757 inst_env->slot_needed = 0;
2758 inst_env->prefix_found = 0;
2759 inst_env->xflag_found = 0;
2760 inst_env->disable_interrupt = 1;
2763 /* Checks that the PC isn't the destination register and that the instruction
2764 doesn't have a prefix. */
2767 scc_op (unsigned short inst, inst_env_type *inst_env)
2769 /* It's invalid to have the PC as the destination. The instruction can't
2771 if ((cris_get_operand2 (inst) == REG_PC) || inst_env->prefix_found)
2773 inst_env->invalid = 1;
2777 inst_env->slot_needed = 0;
2778 inst_env->prefix_found = 0;
2779 inst_env->xflag_found = 0;
2780 inst_env->disable_interrupt = 1;
2783 /* Handles the register mode JUMP instruction. */
2786 reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env)
2788 /* It's invalid to do a JUMP in a delay slot. The mode is register, so
2789 you can't have a prefix. */
2790 if ((inst_env->slot_needed) || (inst_env->prefix_found))
2792 inst_env->invalid = 1;
2796 /* Just change the PC. */
2797 inst_env->reg[REG_PC] = inst_env->reg[cris_get_operand1 (inst)];
2798 inst_env->slot_needed = 0;
2799 inst_env->prefix_found = 0;
2800 inst_env->xflag_found = 0;
2801 inst_env->disable_interrupt = 1;
2804 /* Handles the JUMP instruction for all modes except register. */
2807 none_reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env)
2809 unsigned long newpc;
2812 /* It's invalid to do a JUMP in a delay slot. */
2813 if (inst_env->slot_needed)
2815 inst_env->invalid = 1;
2819 /* Check if we have a prefix. */
2820 if (inst_env->prefix_found)
2822 check_assign (inst, inst_env);
2824 /* Get the new value for the PC. */
2826 read_memory_unsigned_integer ((CORE_ADDR) inst_env->prefix_value,
2827 4, inst_env->byte_order);
2831 /* Get the new value for the PC. */
2832 address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)];
2833 newpc = read_memory_unsigned_integer (address,
2834 4, inst_env->byte_order);
2836 /* Check if we should increment a register. */
2837 if (cris_get_mode (inst) == AUTOINC_MODE)
2839 inst_env->reg[cris_get_operand1 (inst)] += 4;
2842 inst_env->reg[REG_PC] = newpc;
2844 inst_env->slot_needed = 0;
2845 inst_env->prefix_found = 0;
2846 inst_env->xflag_found = 0;
2847 inst_env->disable_interrupt = 1;
2850 /* Handles moves to special registers (aka P-register) for all modes. */
2853 move_to_preg_op (struct gdbarch *gdbarch, unsigned short inst,
2854 inst_env_type *inst_env)
2856 if (inst_env->prefix_found)
2858 /* The instruction has a prefix that means we are only interested if
2859 the instruction is in assign mode. */
2860 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2862 /* The prefix handles the problem if we are in a delay slot. */
2863 if (cris_get_operand1 (inst) == REG_PC)
2865 /* Just take care of the assign. */
2866 check_assign (inst, inst_env);
2870 else if (cris_get_mode (inst) == AUTOINC_MODE)
2872 /* The instruction doesn't have a prefix, the only case left that we
2873 are interested in is the autoincrement mode. */
2874 if (cris_get_operand1 (inst) == REG_PC)
2876 /* If the PC is to be incremented it's invalid to be in a
2878 if (inst_env->slot_needed)
2880 inst_env->invalid = 1;
2884 /* The increment depends on the size of the special register. */
2885 if (cris_register_size (gdbarch, cris_get_operand2 (inst)) == 1)
2887 process_autoincrement (INST_BYTE_SIZE, inst, inst_env);
2889 else if (cris_register_size (gdbarch, cris_get_operand2 (inst)) == 2)
2891 process_autoincrement (INST_WORD_SIZE, inst, inst_env);
2895 process_autoincrement (INST_DWORD_SIZE, inst, inst_env);
2899 inst_env->slot_needed = 0;
2900 inst_env->prefix_found = 0;
2901 inst_env->xflag_found = 0;
2902 inst_env->disable_interrupt = 1;
2905 /* Handles moves from special registers (aka P-register) for all modes
2909 none_reg_mode_move_from_preg_op (struct gdbarch *gdbarch, unsigned short inst,
2910 inst_env_type *inst_env)
2912 if (inst_env->prefix_found)
2914 /* The instruction has a prefix that means we are only interested if
2915 the instruction is in assign mode. */
2916 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2918 /* The prefix handles the problem if we are in a delay slot. */
2919 if (cris_get_operand1 (inst) == REG_PC)
2921 /* Just take care of the assign. */
2922 check_assign (inst, inst_env);
2926 /* The instruction doesn't have a prefix, the only case left that we
2927 are interested in is the autoincrement mode. */
2928 else if (cris_get_mode (inst) == AUTOINC_MODE)
2930 if (cris_get_operand1 (inst) == REG_PC)
2932 /* If the PC is to be incremented it's invalid to be in a
2934 if (inst_env->slot_needed)
2936 inst_env->invalid = 1;
2940 /* The increment depends on the size of the special register. */
2941 if (cris_register_size (gdbarch, cris_get_operand2 (inst)) == 1)
2943 process_autoincrement (INST_BYTE_SIZE, inst, inst_env);
2945 else if (cris_register_size (gdbarch, cris_get_operand2 (inst)) == 2)
2947 process_autoincrement (INST_WORD_SIZE, inst, inst_env);
2951 process_autoincrement (INST_DWORD_SIZE, inst, inst_env);
2955 inst_env->slot_needed = 0;
2956 inst_env->prefix_found = 0;
2957 inst_env->xflag_found = 0;
2958 inst_env->disable_interrupt = 1;
2961 /* Handles moves from special registers (aka P-register) when the mode
2965 reg_mode_move_from_preg_op (unsigned short inst, inst_env_type *inst_env)
2967 /* Register mode move from special register can't have a prefix. */
2968 if (inst_env->prefix_found)
2970 inst_env->invalid = 1;
2974 if (cris_get_operand1 (inst) == REG_PC)
2976 /* It's invalid to change the PC in a delay slot. */
2977 if (inst_env->slot_needed)
2979 inst_env->invalid = 1;
2982 /* The destination is the PC, the jump will have a delay slot. */
2983 inst_env->delay_slot_pc = inst_env->preg[cris_get_operand2 (inst)];
2984 inst_env->slot_needed = 1;
2985 inst_env->delay_slot_pc_active = 1;
2989 /* If the destination isn't PC, there will be no jump. */
2990 inst_env->slot_needed = 0;
2992 inst_env->prefix_found = 0;
2993 inst_env->xflag_found = 0;
2994 inst_env->disable_interrupt = 1;
2997 /* Handles the MOVEM from memory to general register instruction. */
3000 move_mem_to_reg_movem_op (unsigned short inst, inst_env_type *inst_env)
3002 if (inst_env->prefix_found)
3004 /* The prefix handles the problem if we are in a delay slot. Is the
3005 MOVEM instruction going to change the PC? */
3006 if (cris_get_operand2 (inst) >= REG_PC)
3008 inst_env->reg[REG_PC] =
3009 read_memory_unsigned_integer (inst_env->prefix_value,
3010 4, inst_env->byte_order);
3012 /* The assign value is the value after the increment. Normally, the
3013 assign value is the value before the increment. */
3014 if ((cris_get_operand1 (inst) == REG_PC)
3015 && (cris_get_mode (inst) == PREFIX_ASSIGN_MODE))
3017 inst_env->reg[REG_PC] = inst_env->prefix_value;
3018 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
3023 /* Is the MOVEM instruction going to change the PC? */
3024 if (cris_get_operand2 (inst) == REG_PC)
3026 /* It's invalid to change the PC in a delay slot. */
3027 if (inst_env->slot_needed)
3029 inst_env->invalid = 1;
3032 inst_env->reg[REG_PC] =
3033 read_memory_unsigned_integer (inst_env->reg[cris_get_operand1 (inst)],
3034 4, inst_env->byte_order);
3036 /* The increment is not depending on the size, instead it's depending
3037 on the number of registers loaded from memory. */
3038 if ((cris_get_operand1 (inst) == REG_PC)
3039 && (cris_get_mode (inst) == AUTOINC_MODE))
3041 /* It's invalid to change the PC in a delay slot. */
3042 if (inst_env->slot_needed)
3044 inst_env->invalid = 1;
3047 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
3050 inst_env->slot_needed = 0;
3051 inst_env->prefix_found = 0;
3052 inst_env->xflag_found = 0;
3053 inst_env->disable_interrupt = 0;
3056 /* Handles the MOVEM to memory from general register instruction. */
3059 move_reg_to_mem_movem_op (unsigned short inst, inst_env_type *inst_env)
3061 if (inst_env->prefix_found)
3063 /* The assign value is the value after the increment. Normally, the
3064 assign value is the value before the increment. */
3065 if ((cris_get_operand1 (inst) == REG_PC)
3066 && (cris_get_mode (inst) == PREFIX_ASSIGN_MODE))
3068 /* The prefix handles the problem if we are in a delay slot. */
3069 inst_env->reg[REG_PC] = inst_env->prefix_value;
3070 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
3075 /* The increment is not depending on the size, instead it's depending
3076 on the number of registers loaded to memory. */
3077 if ((cris_get_operand1 (inst) == REG_PC)
3078 && (cris_get_mode (inst) == AUTOINC_MODE))
3080 /* It's invalid to change the PC in a delay slot. */
3081 if (inst_env->slot_needed)
3083 inst_env->invalid = 1;
3086 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
3089 inst_env->slot_needed = 0;
3090 inst_env->prefix_found = 0;
3091 inst_env->xflag_found = 0;
3092 inst_env->disable_interrupt = 0;
3095 /* Handles the intructions that's not yet implemented, by setting
3096 inst_env->invalid to true. */
3099 not_implemented_op (unsigned short inst, inst_env_type *inst_env)
3101 inst_env->invalid = 1;
3104 /* Handles the XOR instruction. */
3107 xor_op (unsigned short inst, inst_env_type *inst_env)
3109 /* XOR can't have a prefix. */
3110 if (inst_env->prefix_found)
3112 inst_env->invalid = 1;
3116 /* Check if the PC is the target. */
3117 if (cris_get_operand2 (inst) == REG_PC)
3119 /* It's invalid to change the PC in a delay slot. */
3120 if (inst_env->slot_needed)
3122 inst_env->invalid = 1;
3125 inst_env->reg[REG_PC] ^= inst_env->reg[cris_get_operand1 (inst)];
3127 inst_env->slot_needed = 0;
3128 inst_env->prefix_found = 0;
3129 inst_env->xflag_found = 0;
3130 inst_env->disable_interrupt = 0;
3133 /* Handles the MULS instruction. */
3136 muls_op (unsigned short inst, inst_env_type *inst_env)
3138 /* MULS/U can't have a prefix. */
3139 if (inst_env->prefix_found)
3141 inst_env->invalid = 1;
3145 /* Consider it invalid if the PC is the target. */
3146 if (cris_get_operand2 (inst) == REG_PC)
3148 inst_env->invalid = 1;
3151 inst_env->slot_needed = 0;
3152 inst_env->prefix_found = 0;
3153 inst_env->xflag_found = 0;
3154 inst_env->disable_interrupt = 0;
3157 /* Handles the MULU instruction. */
3160 mulu_op (unsigned short inst, inst_env_type *inst_env)
3162 /* MULS/U can't have a prefix. */
3163 if (inst_env->prefix_found)
3165 inst_env->invalid = 1;
3169 /* Consider it invalid if the PC is the target. */
3170 if (cris_get_operand2 (inst) == REG_PC)
3172 inst_env->invalid = 1;
3175 inst_env->slot_needed = 0;
3176 inst_env->prefix_found = 0;
3177 inst_env->xflag_found = 0;
3178 inst_env->disable_interrupt = 0;
3181 /* Calculate the result of the instruction for ADD, SUB, CMP AND, OR and MOVE.
3182 The MOVE instruction is the move from source to register. */
3185 add_sub_cmp_and_or_move_action (unsigned short inst, inst_env_type *inst_env,
3186 unsigned long source1, unsigned long source2)
3188 unsigned long pc_mask;
3189 unsigned long operation_mask;
3191 /* Find out how many bits the operation should apply to. */
3192 if (cris_get_size (inst) == INST_BYTE_SIZE)
3194 pc_mask = 0xFFFFFF00;
3195 operation_mask = 0xFF;
3197 else if (cris_get_size (inst) == INST_WORD_SIZE)
3199 pc_mask = 0xFFFF0000;
3200 operation_mask = 0xFFFF;
3202 else if (cris_get_size (inst) == INST_DWORD_SIZE)
3205 operation_mask = 0xFFFFFFFF;
3209 /* The size is out of range. */
3210 inst_env->invalid = 1;
3214 /* The instruction just works on uw_operation_mask bits. */
3215 source2 &= operation_mask;
3216 source1 &= operation_mask;
3218 /* Now calculate the result. The opcode's 3 first bits separates
3219 the different actions. */
3220 switch (cris_get_opcode (inst) & 7)
3230 case 2: /* subtract */
3234 case 3: /* compare */
3246 inst_env->invalid = 1;
3252 /* Make sure that the result doesn't contain more than the instruction
3254 source2 &= operation_mask;
3256 /* Calculate the new breakpoint address. */
3257 inst_env->reg[REG_PC] &= pc_mask;
3258 inst_env->reg[REG_PC] |= source1;
3262 /* Extends the value from either byte or word size to a dword. If the mode
3263 is zero extend then the value is extended with zero. If instead the mode
3264 is signed extend the sign bit of the value is taken into consideration. */
3266 static unsigned long
3267 do_sign_or_zero_extend (unsigned long value, unsigned short *inst)
3269 /* The size can be either byte or word, check which one it is.
3270 Don't check the highest bit, it's indicating if it's a zero
3272 if (cris_get_size (*inst) & INST_WORD_SIZE)
3277 /* Check if the instruction is signed extend. If so, check if value has
3279 if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_WORD_MASK))
3281 value |= SIGNED_WORD_EXTEND_MASK;
3289 /* Check if the instruction is signed extend. If so, check if value has
3291 if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_BYTE_MASK))
3293 value |= SIGNED_BYTE_EXTEND_MASK;
3296 /* The size should now be dword. */
3297 cris_set_size_to_dword (inst);
3301 /* Handles the register mode for the ADD, SUB, CMP, AND, OR and MOVE
3302 instruction. The MOVE instruction is the move from source to register. */
3305 reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst,
3306 inst_env_type *inst_env)
3308 unsigned long operand1;
3309 unsigned long operand2;
3311 /* It's invalid to have a prefix to the instruction. This is a register
3312 mode instruction and can't have a prefix. */
3313 if (inst_env->prefix_found)
3315 inst_env->invalid = 1;
3318 /* Check if the instruction has PC as its target. */
3319 if (cris_get_operand2 (inst) == REG_PC)
3321 if (inst_env->slot_needed)
3323 inst_env->invalid = 1;
3326 /* The instruction has the PC as its target register. */
3327 operand1 = inst_env->reg[cris_get_operand1 (inst)];
3328 operand2 = inst_env->reg[REG_PC];
3330 /* Check if it's a extend, signed or zero instruction. */
3331 if (cris_get_opcode (inst) < 4)
3333 operand1 = do_sign_or_zero_extend (operand1, &inst);
3335 /* Calculate the PC value after the instruction, i.e. where the
3336 breakpoint should be. The order of the udw_operands is vital. */
3337 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3339 inst_env->slot_needed = 0;
3340 inst_env->prefix_found = 0;
3341 inst_env->xflag_found = 0;
3342 inst_env->disable_interrupt = 0;
3345 /* Returns the data contained at address. The size of the data is derived from
3346 the size of the operation. If the instruction is a zero or signed
3347 extend instruction, the size field is changed in instruction. */
3349 static unsigned long
3350 get_data_from_address (unsigned short *inst, CORE_ADDR address,
3351 enum bfd_endian byte_order)
3353 int size = cris_get_size (*inst);
3354 unsigned long value;
3356 /* If it's an extend instruction we don't want the signed extend bit,
3357 because it influences the size. */
3358 if (cris_get_opcode (*inst) < 4)
3360 size &= ~SIGNED_EXTEND_BIT_MASK;
3362 /* Is there a need for checking the size? Size should contain the number of
3365 value = read_memory_unsigned_integer (address, size, byte_order);
3367 /* Check if it's an extend, signed or zero instruction. */
3368 if (cris_get_opcode (*inst) < 4)
3370 value = do_sign_or_zero_extend (value, inst);
3375 /* Handles the assign addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
3376 instructions. The MOVE instruction is the move from source to register. */
3379 handle_prefix_assign_mode_for_aritm_op (unsigned short inst,
3380 inst_env_type *inst_env)
3382 unsigned long operand2;
3383 unsigned long operand3;
3385 check_assign (inst, inst_env);
3386 if (cris_get_operand2 (inst) == REG_PC)
3388 operand2 = inst_env->reg[REG_PC];
3390 /* Get the value of the third operand. */
3391 operand3 = get_data_from_address (&inst, inst_env->prefix_value,
3392 inst_env->byte_order);
3394 /* Calculate the PC value after the instruction, i.e. where the
3395 breakpoint should be. The order of the udw_operands is vital. */
3396 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3398 inst_env->slot_needed = 0;
3399 inst_env->prefix_found = 0;
3400 inst_env->xflag_found = 0;
3401 inst_env->disable_interrupt = 0;
3404 /* Handles the three-operand addressing mode for the ADD, SUB, CMP, AND and
3405 OR instructions. Note that for this to work as expected, the calling
3406 function must have made sure that there is a prefix to this instruction. */
3409 three_operand_add_sub_cmp_and_or_op (unsigned short inst,
3410 inst_env_type *inst_env)
3412 unsigned long operand2;
3413 unsigned long operand3;
3415 if (cris_get_operand1 (inst) == REG_PC)
3417 /* The PC will be changed by the instruction. */
3418 operand2 = inst_env->reg[cris_get_operand2 (inst)];
3420 /* Get the value of the third operand. */
3421 operand3 = get_data_from_address (&inst, inst_env->prefix_value,
3422 inst_env->byte_order);
3424 /* Calculate the PC value after the instruction, i.e. where the
3425 breakpoint should be. */
3426 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3428 inst_env->slot_needed = 0;
3429 inst_env->prefix_found = 0;
3430 inst_env->xflag_found = 0;
3431 inst_env->disable_interrupt = 0;
3434 /* Handles the index addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
3435 instructions. The MOVE instruction is the move from source to register. */
3438 handle_prefix_index_mode_for_aritm_op (unsigned short inst,
3439 inst_env_type *inst_env)
3441 if (cris_get_operand1 (inst) != cris_get_operand2 (inst))
3443 /* If the instruction is MOVE it's invalid. If the instruction is ADD,
3444 SUB, AND or OR something weird is going on (if everything works these
3445 instructions should end up in the three operand version). */
3446 inst_env->invalid = 1;
3451 /* three_operand_add_sub_cmp_and_or does the same as we should do here
3453 three_operand_add_sub_cmp_and_or_op (inst, inst_env);
3455 inst_env->slot_needed = 0;
3456 inst_env->prefix_found = 0;
3457 inst_env->xflag_found = 0;
3458 inst_env->disable_interrupt = 0;
3461 /* Handles the autoincrement and indirect addresing mode for the ADD, SUB,
3462 CMP, AND OR and MOVE instruction. The MOVE instruction is the move from
3463 source to register. */
3466 handle_inc_and_index_mode_for_aritm_op (unsigned short inst,
3467 inst_env_type *inst_env)
3469 unsigned long operand1;
3470 unsigned long operand2;
3471 unsigned long operand3;
3474 /* The instruction is either an indirect or autoincrement addressing mode.
3475 Check if the destination register is the PC. */
3476 if (cris_get_operand2 (inst) == REG_PC)
3478 /* Must be done here, get_data_from_address may change the size
3480 size = cris_get_size (inst);
3481 operand2 = inst_env->reg[REG_PC];
3483 /* Get the value of the third operand, i.e. the indirect operand. */
3484 operand1 = inst_env->reg[cris_get_operand1 (inst)];
3485 operand3 = get_data_from_address (&inst, operand1, inst_env->byte_order);
3487 /* Calculate the PC value after the instruction, i.e. where the
3488 breakpoint should be. The order of the udw_operands is vital. */
3489 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3491 /* If this is an autoincrement addressing mode, check if the increment
3493 if ((cris_get_operand1 (inst) == REG_PC)
3494 && (cris_get_mode (inst) == AUTOINC_MODE))
3496 /* Get the size field. */
3497 size = cris_get_size (inst);
3499 /* If it's an extend instruction we don't want the signed extend bit,
3500 because it influences the size. */
3501 if (cris_get_opcode (inst) < 4)
3503 size &= ~SIGNED_EXTEND_BIT_MASK;
3505 process_autoincrement (size, inst, inst_env);
3507 inst_env->slot_needed = 0;
3508 inst_env->prefix_found = 0;
3509 inst_env->xflag_found = 0;
3510 inst_env->disable_interrupt = 0;
3513 /* Handles the two-operand addressing mode, all modes except register, for
3514 the ADD, SUB CMP, AND and OR instruction. */
3517 none_reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst,
3518 inst_env_type *inst_env)
3520 if (inst_env->prefix_found)
3522 if (cris_get_mode (inst) == PREFIX_INDEX_MODE)
3524 handle_prefix_index_mode_for_aritm_op (inst, inst_env);
3526 else if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
3528 handle_prefix_assign_mode_for_aritm_op (inst, inst_env);
3532 /* The mode is invalid for a prefixed base instruction. */
3533 inst_env->invalid = 1;
3539 handle_inc_and_index_mode_for_aritm_op (inst, inst_env);
3543 /* Handles the quick addressing mode for the ADD and SUB instruction. */
3546 quick_mode_add_sub_op (unsigned short inst, inst_env_type *inst_env)
3548 unsigned long operand1;
3549 unsigned long operand2;
3551 /* It's a bad idea to be in a prefix instruction now. This is a quick mode
3552 instruction and can't have a prefix. */
3553 if (inst_env->prefix_found)
3555 inst_env->invalid = 1;
3559 /* Check if the instruction has PC as its target. */
3560 if (cris_get_operand2 (inst) == REG_PC)
3562 if (inst_env->slot_needed)
3564 inst_env->invalid = 1;
3567 operand1 = cris_get_quick_value (inst);
3568 operand2 = inst_env->reg[REG_PC];
3570 /* The size should now be dword. */
3571 cris_set_size_to_dword (&inst);
3573 /* Calculate the PC value after the instruction, i.e. where the
3574 breakpoint should be. */
3575 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3577 inst_env->slot_needed = 0;
3578 inst_env->prefix_found = 0;
3579 inst_env->xflag_found = 0;
3580 inst_env->disable_interrupt = 0;
3583 /* Handles the quick addressing mode for the CMP, AND and OR instruction. */
3586 quick_mode_and_cmp_move_or_op (unsigned short inst, inst_env_type *inst_env)
3588 unsigned long operand1;
3589 unsigned long operand2;
3591 /* It's a bad idea to be in a prefix instruction now. This is a quick mode
3592 instruction and can't have a prefix. */
3593 if (inst_env->prefix_found)
3595 inst_env->invalid = 1;
3598 /* Check if the instruction has PC as its target. */
3599 if (cris_get_operand2 (inst) == REG_PC)
3601 if (inst_env->slot_needed)
3603 inst_env->invalid = 1;
3606 /* The instruction has the PC as its target register. */
3607 operand1 = cris_get_quick_value (inst);
3608 operand2 = inst_env->reg[REG_PC];
3610 /* The quick value is signed, so check if we must do a signed extend. */
3611 if (operand1 & SIGNED_QUICK_VALUE_MASK)
3614 operand1 |= SIGNED_QUICK_VALUE_EXTEND_MASK;
3616 /* The size should now be dword. */
3617 cris_set_size_to_dword (&inst);
3619 /* Calculate the PC value after the instruction, i.e. where the
3620 breakpoint should be. */
3621 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3623 inst_env->slot_needed = 0;
3624 inst_env->prefix_found = 0;
3625 inst_env->xflag_found = 0;
3626 inst_env->disable_interrupt = 0;
3629 /* Translate op_type to a function and call it. */
3632 cris_gdb_func (struct gdbarch *gdbarch, enum cris_op_type op_type,
3633 unsigned short inst, inst_env_type *inst_env)
3637 case cris_not_implemented_op:
3638 not_implemented_op (inst, inst_env);
3642 abs_op (inst, inst_env);
3646 addi_op (inst, inst_env);
3650 asr_op (inst, inst_env);
3654 asrq_op (inst, inst_env);
3657 case cris_ax_ei_setf_op:
3658 ax_ei_setf_op (inst, inst_env);
3661 case cris_bdap_prefix:
3662 bdap_prefix (inst, inst_env);
3665 case cris_biap_prefix:
3666 biap_prefix (inst, inst_env);
3670 break_op (inst, inst_env);
3673 case cris_btst_nop_op:
3674 btst_nop_op (inst, inst_env);
3677 case cris_clearf_di_op:
3678 clearf_di_op (inst, inst_env);
3681 case cris_dip_prefix:
3682 dip_prefix (inst, inst_env);
3685 case cris_dstep_logshift_mstep_neg_not_op:
3686 dstep_logshift_mstep_neg_not_op (inst, inst_env);
3689 case cris_eight_bit_offset_branch_op:
3690 eight_bit_offset_branch_op (inst, inst_env);
3693 case cris_move_mem_to_reg_movem_op:
3694 move_mem_to_reg_movem_op (inst, inst_env);
3697 case cris_move_reg_to_mem_movem_op:
3698 move_reg_to_mem_movem_op (inst, inst_env);
3701 case cris_move_to_preg_op:
3702 move_to_preg_op (gdbarch, inst, inst_env);
3706 muls_op (inst, inst_env);
3710 mulu_op (inst, inst_env);
3713 case cris_none_reg_mode_add_sub_cmp_and_or_move_op:
3714 none_reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env);
3717 case cris_none_reg_mode_clear_test_op:
3718 none_reg_mode_clear_test_op (inst, inst_env);
3721 case cris_none_reg_mode_jump_op:
3722 none_reg_mode_jump_op (inst, inst_env);
3725 case cris_none_reg_mode_move_from_preg_op:
3726 none_reg_mode_move_from_preg_op (gdbarch, inst, inst_env);
3729 case cris_quick_mode_add_sub_op:
3730 quick_mode_add_sub_op (inst, inst_env);
3733 case cris_quick_mode_and_cmp_move_or_op:
3734 quick_mode_and_cmp_move_or_op (inst, inst_env);
3737 case cris_quick_mode_bdap_prefix:
3738 quick_mode_bdap_prefix (inst, inst_env);
3741 case cris_reg_mode_add_sub_cmp_and_or_move_op:
3742 reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env);
3745 case cris_reg_mode_clear_op:
3746 reg_mode_clear_op (inst, inst_env);
3749 case cris_reg_mode_jump_op:
3750 reg_mode_jump_op (inst, inst_env);
3753 case cris_reg_mode_move_from_preg_op:
3754 reg_mode_move_from_preg_op (inst, inst_env);
3757 case cris_reg_mode_test_op:
3758 reg_mode_test_op (inst, inst_env);
3762 scc_op (inst, inst_env);
3765 case cris_sixteen_bit_offset_branch_op:
3766 sixteen_bit_offset_branch_op (inst, inst_env);
3769 case cris_three_operand_add_sub_cmp_and_or_op:
3770 three_operand_add_sub_cmp_and_or_op (inst, inst_env);
3773 case cris_three_operand_bound_op:
3774 three_operand_bound_op (inst, inst_env);
3777 case cris_two_operand_bound_op:
3778 two_operand_bound_op (inst, inst_env);
3782 xor_op (inst, inst_env);
3787 /* Originally from <asm/elf.h>. */
3788 typedef unsigned char cris_elf_greg_t[4];
3790 /* Same as user_regs_struct struct in <asm/user.h>. */
3791 #define CRISV10_ELF_NGREG 35
3792 typedef cris_elf_greg_t cris_elf_gregset_t[CRISV10_ELF_NGREG];
3794 #define CRISV32_ELF_NGREG 32
3795 typedef cris_elf_greg_t crisv32_elf_gregset_t[CRISV32_ELF_NGREG];
3797 /* Unpack a cris_elf_gregset_t into GDB's register cache. */
3800 cris_supply_gregset (struct regcache *regcache, cris_elf_gregset_t *gregsetp)
3802 struct gdbarch *gdbarch = regcache->arch ();
3803 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3805 cris_elf_greg_t *regp = *gregsetp;
3807 /* The kernel dumps all 32 registers as unsigned longs, but supply_register
3808 knows about the actual size of each register so that's no problem. */
3809 for (i = 0; i < NUM_GENREGS + NUM_SPECREGS; i++)
3811 regcache->raw_supply (i, (char *)®p[i]);
3814 if (tdep->cris_version == 32)
3816 /* Needed to set pseudo-register PC for CRISv32. */
3817 /* FIXME: If ERP is in a delay slot at this point then the PC will
3818 be wrong. Issue a warning to alert the user. */
3819 regcache->raw_supply (gdbarch_pc_regnum (gdbarch),
3820 (char *)®p[ERP_REGNUM]);
3822 if (*(char *)®p[ERP_REGNUM] & 0x1)
3823 fprintf_unfiltered (gdb_stderr, "Warning: PC in delay slot\n");
3827 /* Use a local version of this function to get the correct types for
3828 regsets, until multi-arch core support is ready. */
3831 fetch_core_registers (struct regcache *regcache,
3832 char *core_reg_sect, unsigned core_reg_size,
3833 int which, CORE_ADDR reg_addr)
3835 cris_elf_gregset_t gregset;
3840 if (core_reg_size != sizeof (cris_elf_gregset_t)
3841 && core_reg_size != sizeof (crisv32_elf_gregset_t))
3843 warning (_("wrong size gregset struct in core file"));
3847 memcpy (&gregset, core_reg_sect, sizeof (gregset));
3848 cris_supply_gregset (regcache, &gregset);
3852 /* We've covered all the kinds of registers we know about here,
3853 so this must be something we wouldn't know what to do with
3854 anyway. Just ignore it. */
3859 static struct core_fns cris_elf_core_fns =
3861 bfd_target_elf_flavour, /* core_flavour */
3862 default_check_format, /* check_format */
3863 default_core_sniffer, /* core_sniffer */
3864 fetch_core_registers, /* core_read_registers */
3869 _initialize_cris_tdep (void)
3871 gdbarch_register (bfd_arch_cris, cris_gdbarch_init, cris_dump_tdep);
3873 /* CRIS-specific user-commands. */
3874 add_setshow_zuinteger_cmd ("cris-version", class_support,
3875 &usr_cmd_cris_version,
3876 _("Set the current CRIS version."),
3877 _("Show the current CRIS version."),
3879 Set to 10 for CRISv10 or 32 for CRISv32 if autodetection fails.\n\
3882 NULL, /* FIXME: i18n: Current CRIS version
3884 &setlist, &showlist);
3886 add_setshow_enum_cmd ("cris-mode", class_support,
3887 cris_modes, &usr_cmd_cris_mode,
3888 _("Set the current CRIS mode."),
3889 _("Show the current CRIS mode."),
3891 Set to CRIS_MODE_GURU when debugging in guru mode.\n\
3892 Makes GDB use the NRP register instead of the ERP register in certain cases."),
3894 NULL, /* FIXME: i18n: Current CRIS version is %s. */
3895 &setlist, &showlist);
3897 add_setshow_boolean_cmd ("cris-dwarf2-cfi", class_support,
3898 &usr_cmd_cris_dwarf2_cfi,
3899 _("Set the usage of Dwarf-2 CFI for CRIS."),
3900 _("Show the usage of Dwarf-2 CFI for CRIS."),
3901 _("Set this to \"off\" if using gcc-cris < R59."),
3902 set_cris_dwarf2_cfi,
3903 NULL, /* FIXME: i18n: Usage of Dwarf-2 CFI
3905 &setlist, &showlist);
3907 deprecated_add_core_fns (&cris_elf_core_fns);
3910 /* Prints out all target specific values. */
3913 cris_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
3915 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3918 fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_version = %i\n",
3919 tdep->cris_version);
3920 fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_mode = %s\n",
3922 fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_dwarf2_cfi = %i\n",
3923 tdep->cris_dwarf2_cfi);
3928 set_cris_version (const char *ignore_args, int from_tty,
3929 struct cmd_list_element *c)
3931 struct gdbarch_info info;
3933 usr_cmd_cris_version_valid = 1;
3935 /* Update the current architecture, if needed. */
3936 gdbarch_info_init (&info);
3937 if (!gdbarch_update_p (info))
3938 internal_error (__FILE__, __LINE__,
3939 _("cris_gdbarch_update: failed to update architecture."));
3943 set_cris_mode (const char *ignore_args, int from_tty,
3944 struct cmd_list_element *c)
3946 struct gdbarch_info info;
3948 /* Update the current architecture, if needed. */
3949 gdbarch_info_init (&info);
3950 if (!gdbarch_update_p (info))
3951 internal_error (__FILE__, __LINE__,
3952 "cris_gdbarch_update: failed to update architecture.");
3956 set_cris_dwarf2_cfi (const char *ignore_args, int from_tty,
3957 struct cmd_list_element *c)
3959 struct gdbarch_info info;
3961 /* Update the current architecture, if needed. */
3962 gdbarch_info_init (&info);
3963 if (!gdbarch_update_p (info))
3964 internal_error (__FILE__, __LINE__,
3965 _("cris_gdbarch_update: failed to update architecture."));
3968 static struct gdbarch *
3969 cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
3971 struct gdbarch *gdbarch;
3972 struct gdbarch_tdep *tdep;
3973 unsigned int cris_version;
3975 if (usr_cmd_cris_version_valid)
3977 /* Trust the user's CRIS version setting. */
3978 cris_version = usr_cmd_cris_version;
3980 else if (info.abfd && bfd_get_mach (info.abfd) == bfd_mach_cris_v32)
3986 /* Assume it's CRIS version 10. */
3990 /* Make the current settings visible to the user. */
3991 usr_cmd_cris_version = cris_version;
3993 /* Find a candidate among the list of pre-declared architectures. */
3994 for (arches = gdbarch_list_lookup_by_info (arches, &info);
3996 arches = gdbarch_list_lookup_by_info (arches->next, &info))
3998 if ((gdbarch_tdep (arches->gdbarch)->cris_version
3999 == usr_cmd_cris_version)
4000 && (gdbarch_tdep (arches->gdbarch)->cris_mode
4001 == usr_cmd_cris_mode)
4002 && (gdbarch_tdep (arches->gdbarch)->cris_dwarf2_cfi
4003 == usr_cmd_cris_dwarf2_cfi))
4004 return arches->gdbarch;
4007 /* No matching architecture was found. Create a new one. */
4008 tdep = XCNEW (struct gdbarch_tdep);
4009 info.byte_order = BFD_ENDIAN_LITTLE;
4010 gdbarch = gdbarch_alloc (&info, tdep);
4012 tdep->cris_version = usr_cmd_cris_version;
4013 tdep->cris_mode = usr_cmd_cris_mode;
4014 tdep->cris_dwarf2_cfi = usr_cmd_cris_dwarf2_cfi;
4016 set_gdbarch_return_value (gdbarch, cris_return_value);
4017 set_gdbarch_sp_regnum (gdbarch, 14);
4019 /* Length of ordinary registers used in push_word and a few other
4020 places. register_size() is the real way to know how big a
4023 set_gdbarch_double_bit (gdbarch, 64);
4024 /* The default definition of a long double is 2 * gdbarch_double_bit,
4025 which means we have to set this explicitly. */
4026 set_gdbarch_long_double_bit (gdbarch, 64);
4028 /* The total amount of space needed to store (in an array called registers)
4029 GDB's copy of the machine's register state. Note: We can not use
4030 cris_register_size at this point, since it relies on gdbarch
4032 switch (tdep->cris_version)
4040 /* Old versions; not supported. */
4045 /* CRIS v10 and v11, a.k.a. ETRAX 100LX. In addition to ETRAX 100,
4046 P7 (32 bits), and P15 (32 bits) have been implemented. */
4047 set_gdbarch_pc_regnum (gdbarch, 15);
4048 set_gdbarch_register_type (gdbarch, cris_register_type);
4049 /* There are 32 registers (some of which may not be implemented). */
4050 set_gdbarch_num_regs (gdbarch, 32);
4051 set_gdbarch_register_name (gdbarch, cris_register_name);
4052 set_gdbarch_cannot_store_register (gdbarch, cris_cannot_store_register);
4053 set_gdbarch_cannot_fetch_register (gdbarch, cris_cannot_fetch_register);
4055 set_gdbarch_software_single_step (gdbarch, cris_software_single_step);
4059 /* CRIS v32. General registers R0 - R15 (32 bits), special registers
4060 P0 - P15 (32 bits) except P0, P1, P3 (8 bits) and P4 (16 bits)
4061 and pseudo-register PC (32 bits). */
4062 set_gdbarch_pc_regnum (gdbarch, 32);
4063 set_gdbarch_register_type (gdbarch, crisv32_register_type);
4064 /* 32 registers + pseudo-register PC + 16 support registers. */
4065 set_gdbarch_num_regs (gdbarch, 32 + 1 + 16);
4066 set_gdbarch_register_name (gdbarch, crisv32_register_name);
4068 set_gdbarch_cannot_store_register
4069 (gdbarch, crisv32_cannot_store_register);
4070 set_gdbarch_cannot_fetch_register
4071 (gdbarch, crisv32_cannot_fetch_register);
4073 set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
4075 set_gdbarch_single_step_through_delay
4076 (gdbarch, crisv32_single_step_through_delay);
4081 /* Unknown version. */
4085 /* Dummy frame functions (shared between CRISv10 and CRISv32 since they
4086 have the same ABI). */
4087 set_gdbarch_push_dummy_code (gdbarch, cris_push_dummy_code);
4088 set_gdbarch_push_dummy_call (gdbarch, cris_push_dummy_call);
4089 set_gdbarch_frame_align (gdbarch, cris_frame_align);
4090 set_gdbarch_skip_prologue (gdbarch, cris_skip_prologue);
4092 /* The stack grows downward. */
4093 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
4095 set_gdbarch_breakpoint_kind_from_pc (gdbarch, cris_breakpoint_kind_from_pc);
4096 set_gdbarch_sw_breakpoint_from_kind (gdbarch, cris_sw_breakpoint_from_kind);
4098 set_gdbarch_unwind_pc (gdbarch, cris_unwind_pc);
4099 set_gdbarch_unwind_sp (gdbarch, cris_unwind_sp);
4100 set_gdbarch_dummy_id (gdbarch, cris_dummy_id);
4102 if (tdep->cris_dwarf2_cfi == 1)
4104 /* Hook in the Dwarf-2 frame sniffer. */
4105 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, cris_dwarf2_reg_to_regnum);
4106 dwarf2_frame_set_init_reg (gdbarch, cris_dwarf2_frame_init_reg);
4107 dwarf2_append_unwinders (gdbarch);
4110 if (tdep->cris_mode != cris_mode_guru)
4112 frame_unwind_append_unwinder (gdbarch, &cris_sigtramp_frame_unwind);
4115 frame_unwind_append_unwinder (gdbarch, &cris_frame_unwind);
4116 frame_base_set_default (gdbarch, &cris_frame_base);
4118 /* Hook in ABI-specific overrides, if they have been registered. */
4119 gdbarch_init_osabi (info, gdbarch);