1 /* Target dependent code for CRIS, for GDB, the GNU debugger.
3 Copyright (C) 2001-2013 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"
40 #include "gdb_assert.h"
44 #include "solib.h" /* Support for shared libraries. */
45 #include "solib-svr4.h"
49 #include "cris-tdep.h"
53 /* There are no floating point registers. Used in gdbserver low-linux.c. */
56 /* There are 16 general registers. */
59 /* There are 16 special registers. */
62 /* CRISv32 has a pseudo PC register, not noted here. */
64 /* CRISv32 has 16 support registers. */
68 /* Register numbers of various important registers.
69 CRIS_FP_REGNUM Contains address of executing stack frame.
70 STR_REGNUM Contains the address of structure return values.
71 RET_REGNUM Contains the return value when shorter than or equal to 32 bits
72 ARG1_REGNUM Contains the first parameter to a function.
73 ARG2_REGNUM Contains the second parameter to a function.
74 ARG3_REGNUM Contains the third parameter to a function.
75 ARG4_REGNUM Contains the fourth parameter to a function. Rest on stack.
76 gdbarch_sp_regnum Contains address of top of stack.
77 gdbarch_pc_regnum Contains address of next instruction.
78 SRP_REGNUM Subroutine return pointer register.
79 BRP_REGNUM Breakpoint return pointer register. */
83 /* Enums with respect to the general registers, valid for all
84 CRIS versions. The frame pointer is always in R8. */
86 /* ABI related registers. */
94 /* Registers which happen to be common. */
99 /* CRISv10 et al. specific registers. */
111 /* CRISv32 specific registers. */
124 CRISV32USP_REGNUM = 30, /* Shares name but not number with CRISv10. */
126 CRISV32PC_REGNUM = 32, /* Shares name but not number with CRISv10. */
146 extern const struct cris_spec_reg cris_spec_regs[];
148 /* CRIS version, set via the user command 'set cris-version'. Affects
149 register names and sizes. */
150 static unsigned int usr_cmd_cris_version;
152 /* Indicates whether to trust the above variable. */
153 static int usr_cmd_cris_version_valid = 0;
155 static const char cris_mode_normal[] = "normal";
156 static const char cris_mode_guru[] = "guru";
157 static const char *const cris_modes[] = {
163 /* CRIS mode, set via the user command 'set cris-mode'. Affects
164 type of break instruction among other things. */
165 static const char *usr_cmd_cris_mode = cris_mode_normal;
167 /* Whether to make use of Dwarf-2 CFI (default on). */
168 static int usr_cmd_cris_dwarf2_cfi = 1;
170 /* Sigtramp identification code copied from i386-linux-tdep.c. */
172 #define SIGTRAMP_INSN0 0x9c5f /* movu.w 0xXX, $r9 */
173 #define SIGTRAMP_OFFSET0 0
174 #define SIGTRAMP_INSN1 0xe93d /* break 13 */
175 #define SIGTRAMP_OFFSET1 4
177 static const unsigned short sigtramp_code[] =
179 SIGTRAMP_INSN0, 0x0077, /* movu.w $0x77, $r9 */
180 SIGTRAMP_INSN1 /* break 13 */
183 #define SIGTRAMP_LEN (sizeof sigtramp_code)
185 /* Note: same length as normal sigtramp code. */
187 static const unsigned short rt_sigtramp_code[] =
189 SIGTRAMP_INSN0, 0x00ad, /* movu.w $0xad, $r9 */
190 SIGTRAMP_INSN1 /* break 13 */
193 /* If PC is in a sigtramp routine, return the address of the start of
194 the routine. Otherwise, return 0. */
197 cris_sigtramp_start (struct frame_info *this_frame)
199 CORE_ADDR pc = get_frame_pc (this_frame);
200 gdb_byte buf[SIGTRAMP_LEN];
202 if (!safe_frame_unwind_memory (this_frame, pc, buf, SIGTRAMP_LEN))
205 if (((buf[1] << 8) + buf[0]) != SIGTRAMP_INSN0)
207 if (((buf[1] << 8) + buf[0]) != SIGTRAMP_INSN1)
210 pc -= SIGTRAMP_OFFSET1;
211 if (!safe_frame_unwind_memory (this_frame, pc, buf, SIGTRAMP_LEN))
215 if (memcmp (buf, sigtramp_code, SIGTRAMP_LEN) != 0)
221 /* If PC is in a RT sigtramp routine, return the address of the start of
222 the routine. Otherwise, return 0. */
225 cris_rt_sigtramp_start (struct frame_info *this_frame)
227 CORE_ADDR pc = get_frame_pc (this_frame);
228 gdb_byte buf[SIGTRAMP_LEN];
230 if (!safe_frame_unwind_memory (this_frame, pc, buf, SIGTRAMP_LEN))
233 if (((buf[1] << 8) + buf[0]) != SIGTRAMP_INSN0)
235 if (((buf[1] << 8) + buf[0]) != SIGTRAMP_INSN1)
238 pc -= SIGTRAMP_OFFSET1;
239 if (!safe_frame_unwind_memory (this_frame, pc, buf, SIGTRAMP_LEN))
243 if (memcmp (buf, rt_sigtramp_code, SIGTRAMP_LEN) != 0)
249 /* Assuming THIS_FRAME is a frame for a GNU/Linux sigtramp routine,
250 return the address of the associated sigcontext structure. */
253 cris_sigcontext_addr (struct frame_info *this_frame)
255 struct gdbarch *gdbarch = get_frame_arch (this_frame);
256 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
261 get_frame_register (this_frame, gdbarch_sp_regnum (gdbarch), buf);
262 sp = extract_unsigned_integer (buf, 4, byte_order);
264 /* Look for normal sigtramp frame first. */
265 pc = cris_sigtramp_start (this_frame);
268 /* struct signal_frame (arch/cris/kernel/signal.c) contains
269 struct sigcontext as its first member, meaning the SP points to
274 pc = cris_rt_sigtramp_start (this_frame);
277 /* struct rt_signal_frame (arch/cris/kernel/signal.c) contains
278 a struct ucontext, which in turn contains a struct sigcontext.
280 4 + 4 + 128 to struct ucontext, then
281 4 + 4 + 12 to struct sigcontext. */
285 error (_("Couldn't recognize signal trampoline."));
289 struct cris_unwind_cache
291 /* The previous frame's inner most stack address. Used as this
292 frame ID's stack_addr. */
294 /* The frame's base, optionally used by the high-level debug info. */
297 /* How far the SP and r8 (FP) have been offset from the start of
298 the stack frame (as defined by the previous frame's stack
304 /* From old frame_extra_info struct. */
308 /* Table indicating the location of each and every register. */
309 struct trad_frame_saved_reg *saved_regs;
312 static struct cris_unwind_cache *
313 cris_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
316 struct gdbarch *gdbarch = get_frame_arch (this_frame);
317 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
318 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
319 struct cris_unwind_cache *info;
325 return (*this_cache);
327 info = FRAME_OBSTACK_ZALLOC (struct cris_unwind_cache);
328 (*this_cache) = info;
329 info->saved_regs = trad_frame_alloc_saved_regs (this_frame);
331 /* Zero all fields. */
337 info->uses_frame = 0;
339 info->leaf_function = 0;
341 get_frame_register (this_frame, gdbarch_sp_regnum (gdbarch), buf);
342 info->base = extract_unsigned_integer (buf, 4, byte_order);
344 addr = cris_sigcontext_addr (this_frame);
346 /* Layout of the sigcontext struct:
349 unsigned long oldmask;
353 if (tdep->cris_version == 10)
355 /* R0 to R13 are stored in reverse order at offset (2 * 4) in
357 for (i = 0; i <= 13; i++)
358 info->saved_regs[i].addr = addr + ((15 - i) * 4);
360 info->saved_regs[MOF_REGNUM].addr = addr + (16 * 4);
361 info->saved_regs[DCCR_REGNUM].addr = addr + (17 * 4);
362 info->saved_regs[SRP_REGNUM].addr = addr + (18 * 4);
363 /* Note: IRP is off by 2 at this point. There's no point in correcting
364 it though since that will mean that the backtrace will show a PC
365 different from what is shown when stopped. */
366 info->saved_regs[IRP_REGNUM].addr = addr + (19 * 4);
367 info->saved_regs[gdbarch_pc_regnum (gdbarch)]
368 = info->saved_regs[IRP_REGNUM];
369 info->saved_regs[gdbarch_sp_regnum (gdbarch)].addr = addr + (24 * 4);
374 /* R0 to R13 are stored in order at offset (1 * 4) in
376 for (i = 0; i <= 13; i++)
377 info->saved_regs[i].addr = addr + ((i + 1) * 4);
379 info->saved_regs[ACR_REGNUM].addr = addr + (15 * 4);
380 info->saved_regs[SRS_REGNUM].addr = addr + (16 * 4);
381 info->saved_regs[MOF_REGNUM].addr = addr + (17 * 4);
382 info->saved_regs[SPC_REGNUM].addr = addr + (18 * 4);
383 info->saved_regs[CCS_REGNUM].addr = addr + (19 * 4);
384 info->saved_regs[SRP_REGNUM].addr = addr + (20 * 4);
385 info->saved_regs[ERP_REGNUM].addr = addr + (21 * 4);
386 info->saved_regs[EXS_REGNUM].addr = addr + (22 * 4);
387 info->saved_regs[EDA_REGNUM].addr = addr + (23 * 4);
389 /* FIXME: If ERP is in a delay slot at this point then the PC will
390 be wrong at this point. This problem manifests itself in the
391 sigaltstack.exp test case, which occasionally generates FAILs when
392 the signal is received while in a delay slot.
394 This could be solved by a couple of read_memory_unsigned_integer and a
395 trad_frame_set_value. */
396 info->saved_regs[gdbarch_pc_regnum (gdbarch)]
397 = info->saved_regs[ERP_REGNUM];
399 info->saved_regs[gdbarch_sp_regnum (gdbarch)].addr
407 cris_sigtramp_frame_this_id (struct frame_info *this_frame, void **this_cache,
408 struct frame_id *this_id)
410 struct cris_unwind_cache *cache =
411 cris_sigtramp_frame_unwind_cache (this_frame, this_cache);
412 (*this_id) = frame_id_build (cache->base, get_frame_pc (this_frame));
415 /* Forward declaration. */
417 static struct value *cris_frame_prev_register (struct frame_info *this_frame,
418 void **this_cache, int regnum);
419 static struct value *
420 cris_sigtramp_frame_prev_register (struct frame_info *this_frame,
421 void **this_cache, int regnum)
423 /* Make sure we've initialized the cache. */
424 cris_sigtramp_frame_unwind_cache (this_frame, this_cache);
425 return cris_frame_prev_register (this_frame, this_cache, regnum);
429 cris_sigtramp_frame_sniffer (const struct frame_unwind *self,
430 struct frame_info *this_frame,
433 if (cris_sigtramp_start (this_frame)
434 || cris_rt_sigtramp_start (this_frame))
440 static const struct frame_unwind cris_sigtramp_frame_unwind =
443 default_frame_unwind_stop_reason,
444 cris_sigtramp_frame_this_id,
445 cris_sigtramp_frame_prev_register,
447 cris_sigtramp_frame_sniffer
451 crisv32_single_step_through_delay (struct gdbarch *gdbarch,
452 struct frame_info *this_frame)
454 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
458 if (tdep->cris_mode == cris_mode_guru)
459 erp = get_frame_register_unsigned (this_frame, NRP_REGNUM);
461 erp = get_frame_register_unsigned (this_frame, ERP_REGNUM);
465 /* In delay slot - check if there's a breakpoint at the preceding
467 if (breakpoint_here_p (get_frame_address_space (this_frame), erp & ~0x1))
473 /* The instruction environment needed to find single-step breakpoints. */
476 struct instruction_environment
478 unsigned long reg[NUM_GENREGS];
479 unsigned long preg[NUM_SPECREGS];
480 unsigned long branch_break_address;
481 unsigned long delay_slot_pc;
482 unsigned long prefix_value;
487 int delay_slot_pc_active;
489 int disable_interrupt;
493 /* Machine-dependencies in CRIS for opcodes. */
495 /* Instruction sizes. */
496 enum cris_instruction_sizes
503 /* Addressing modes. */
504 enum cris_addressing_modes
511 /* Prefix addressing modes. */
512 enum cris_prefix_addressing_modes
514 PREFIX_INDEX_MODE = 2,
515 PREFIX_ASSIGN_MODE = 3,
517 /* Handle immediate byte offset addressing mode prefix format. */
518 PREFIX_OFFSET_MODE = 2
521 /* Masks for opcodes. */
522 enum cris_opcode_masks
524 BRANCH_SIGNED_SHORT_OFFSET_MASK = 0x1,
525 SIGNED_EXTEND_BIT_MASK = 0x2,
526 SIGNED_BYTE_MASK = 0x80,
527 SIGNED_BYTE_EXTEND_MASK = 0xFFFFFF00,
528 SIGNED_WORD_MASK = 0x8000,
529 SIGNED_WORD_EXTEND_MASK = 0xFFFF0000,
530 SIGNED_DWORD_MASK = 0x80000000,
531 SIGNED_QUICK_VALUE_MASK = 0x20,
532 SIGNED_QUICK_VALUE_EXTEND_MASK = 0xFFFFFFC0
535 /* Functions for opcodes. The general form of the ETRAX 16-bit instruction:
543 cris_get_operand2 (unsigned short insn)
545 return ((insn & 0xF000) >> 12);
549 cris_get_mode (unsigned short insn)
551 return ((insn & 0x0C00) >> 10);
555 cris_get_opcode (unsigned short insn)
557 return ((insn & 0x03C0) >> 6);
561 cris_get_size (unsigned short insn)
563 return ((insn & 0x0030) >> 4);
567 cris_get_operand1 (unsigned short insn)
569 return (insn & 0x000F);
572 /* Additional functions in order to handle opcodes. */
575 cris_get_quick_value (unsigned short insn)
577 return (insn & 0x003F);
581 cris_get_bdap_quick_offset (unsigned short insn)
583 return (insn & 0x00FF);
587 cris_get_branch_short_offset (unsigned short insn)
589 return (insn & 0x00FF);
593 cris_get_asr_shift_steps (unsigned long value)
595 return (value & 0x3F);
599 cris_get_clear_size (unsigned short insn)
601 return ((insn) & 0xC000);
605 cris_is_signed_extend_bit_on (unsigned short insn)
607 return (((insn) & 0x20) == 0x20);
611 cris_is_xflag_bit_on (unsigned short insn)
613 return (((insn) & 0x1000) == 0x1000);
617 cris_set_size_to_dword (unsigned short *insn)
624 cris_get_signed_offset (unsigned short insn)
626 return ((signed char) (insn & 0x00FF));
629 /* Calls an op function given the op-type, working on the insn and the
631 static void cris_gdb_func (struct gdbarch *, enum cris_op_type, unsigned short,
634 static struct gdbarch *cris_gdbarch_init (struct gdbarch_info,
635 struct gdbarch_list *);
637 static void cris_dump_tdep (struct gdbarch *, struct ui_file *);
639 static void set_cris_version (char *ignore_args, int from_tty,
640 struct cmd_list_element *c);
642 static void set_cris_mode (char *ignore_args, int from_tty,
643 struct cmd_list_element *c);
645 static void set_cris_dwarf2_cfi (char *ignore_args, int from_tty,
646 struct cmd_list_element *c);
648 static CORE_ADDR cris_scan_prologue (CORE_ADDR pc,
649 struct frame_info *this_frame,
650 struct cris_unwind_cache *info);
652 static CORE_ADDR crisv32_scan_prologue (CORE_ADDR pc,
653 struct frame_info *this_frame,
654 struct cris_unwind_cache *info);
656 static CORE_ADDR cris_unwind_pc (struct gdbarch *gdbarch,
657 struct frame_info *next_frame);
659 static CORE_ADDR cris_unwind_sp (struct gdbarch *gdbarch,
660 struct frame_info *next_frame);
662 /* When arguments must be pushed onto the stack, they go on in reverse
663 order. The below implements a FILO (stack) to do this.
664 Copied from d10v-tdep.c. */
669 struct stack_item *prev;
673 static struct stack_item *
674 push_stack_item (struct stack_item *prev, const gdb_byte *contents, int len)
676 struct stack_item *si;
677 si = xmalloc (sizeof (struct stack_item));
678 si->data = xmalloc (len);
681 memcpy (si->data, contents, len);
685 static struct stack_item *
686 pop_stack_item (struct stack_item *si)
688 struct stack_item *dead = si;
695 /* Put here the code to store, into fi->saved_regs, the addresses of
696 the saved registers of frame described by FRAME_INFO. This
697 includes special registers such as pc and fp saved in special ways
698 in the stack frame. sp is even more special: the address we return
699 for it IS the sp for the next frame. */
701 static struct cris_unwind_cache *
702 cris_frame_unwind_cache (struct frame_info *this_frame,
703 void **this_prologue_cache)
705 struct gdbarch *gdbarch = get_frame_arch (this_frame);
706 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
707 struct cris_unwind_cache *info;
709 if ((*this_prologue_cache))
710 return (*this_prologue_cache);
712 info = FRAME_OBSTACK_ZALLOC (struct cris_unwind_cache);
713 (*this_prologue_cache) = info;
714 info->saved_regs = trad_frame_alloc_saved_regs (this_frame);
716 /* Zero all fields. */
722 info->uses_frame = 0;
724 info->leaf_function = 0;
726 /* Prologue analysis does the rest... */
727 if (tdep->cris_version == 32)
728 crisv32_scan_prologue (get_frame_func (this_frame), this_frame, info);
730 cris_scan_prologue (get_frame_func (this_frame), this_frame, info);
735 /* Given a GDB frame, determine the address of the calling function's
736 frame. This will be used to create a new GDB frame struct. */
739 cris_frame_this_id (struct frame_info *this_frame,
740 void **this_prologue_cache,
741 struct frame_id *this_id)
743 struct cris_unwind_cache *info
744 = cris_frame_unwind_cache (this_frame, this_prologue_cache);
749 /* The FUNC is easy. */
750 func = get_frame_func (this_frame);
752 /* Hopefully the prologue analysis either correctly determined the
753 frame's base (which is the SP from the previous frame), or set
754 that base to "NULL". */
755 base = info->prev_sp;
759 id = frame_id_build (base, func);
764 static struct value *
765 cris_frame_prev_register (struct frame_info *this_frame,
766 void **this_prologue_cache, int regnum)
768 struct cris_unwind_cache *info
769 = cris_frame_unwind_cache (this_frame, this_prologue_cache);
770 return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
773 /* Assuming THIS_FRAME is a dummy, return the frame ID of that dummy
774 frame. The frame ID's base needs to match the TOS value saved by
775 save_dummy_frame_tos(), and the PC match the dummy frame's breakpoint. */
777 static struct frame_id
778 cris_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
781 sp = get_frame_register_unsigned (this_frame, gdbarch_sp_regnum (gdbarch));
782 return frame_id_build (sp, get_frame_pc (this_frame));
786 cris_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
788 /* Align to the size of an instruction (so that they can safely be
789 pushed onto the stack). */
794 cris_push_dummy_code (struct gdbarch *gdbarch,
795 CORE_ADDR sp, CORE_ADDR funaddr,
796 struct value **args, int nargs,
797 struct type *value_type,
798 CORE_ADDR *real_pc, CORE_ADDR *bp_addr,
799 struct regcache *regcache)
801 /* Allocate space sufficient for a breakpoint. */
803 /* Store the address of that breakpoint */
805 /* CRIS always starts the call at the callee's entry point. */
811 cris_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
812 struct regcache *regcache, CORE_ADDR bp_addr,
813 int nargs, struct value **args, CORE_ADDR sp,
814 int struct_return, CORE_ADDR struct_addr)
816 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
821 /* The function's arguments and memory allocated by gdb for the arguments to
822 point at reside in separate areas on the stack.
823 Both frame pointers grow toward higher addresses. */
827 struct stack_item *si = NULL;
829 /* Push the return address. */
830 regcache_cooked_write_unsigned (regcache, SRP_REGNUM, bp_addr);
832 /* Are we returning a value using a structure return or a normal value
833 return? struct_addr is the address of the reserved space for the return
834 structure to be written on the stack. */
837 regcache_cooked_write_unsigned (regcache, STR_REGNUM, struct_addr);
840 /* Now load as many as possible of the first arguments into registers,
841 and push the rest onto the stack. */
842 argreg = ARG1_REGNUM;
845 for (argnum = 0; argnum < nargs; argnum++)
852 len = TYPE_LENGTH (value_type (args[argnum]));
853 val = value_contents (args[argnum]);
855 /* How may registers worth of storage do we need for this argument? */
856 reg_demand = (len / 4) + (len % 4 != 0 ? 1 : 0);
858 if (len <= (2 * 4) && (argreg + reg_demand - 1 <= ARG4_REGNUM))
860 /* Data passed by value. Fits in available register(s). */
861 for (i = 0; i < reg_demand; i++)
863 regcache_cooked_write (regcache, argreg, val);
868 else if (len <= (2 * 4) && argreg <= ARG4_REGNUM)
870 /* Data passed by value. Does not fit in available register(s).
871 Use the register(s) first, then the stack. */
872 for (i = 0; i < reg_demand; i++)
874 if (argreg <= ARG4_REGNUM)
876 regcache_cooked_write (regcache, argreg, val);
882 /* Push item for later so that pushed arguments
883 come in the right order. */
884 si = push_stack_item (si, val, 4);
889 else if (len > (2 * 4))
891 /* Data passed by reference. Push copy of data onto stack
892 and pass pointer to this copy as argument. */
893 sp = (sp - len) & ~3;
894 write_memory (sp, val, len);
896 if (argreg <= ARG4_REGNUM)
898 regcache_cooked_write_unsigned (regcache, argreg, sp);
904 store_unsigned_integer (buf, 4, byte_order, sp);
905 si = push_stack_item (si, buf, 4);
910 /* Data passed by value. No available registers. Put it on
912 si = push_stack_item (si, val, len);
918 /* fp_arg must be word-aligned (i.e., don't += len) to match
919 the function prologue. */
920 sp = (sp - si->len) & ~3;
921 write_memory (sp, si->data, si->len);
922 si = pop_stack_item (si);
925 /* Finally, update the SP register. */
926 regcache_cooked_write_unsigned (regcache, gdbarch_sp_regnum (gdbarch), sp);
931 static const struct frame_unwind cris_frame_unwind =
934 default_frame_unwind_stop_reason,
936 cris_frame_prev_register,
938 default_frame_sniffer
942 cris_frame_base_address (struct frame_info *this_frame, void **this_cache)
944 struct cris_unwind_cache *info
945 = cris_frame_unwind_cache (this_frame, this_cache);
949 static const struct frame_base cris_frame_base =
952 cris_frame_base_address,
953 cris_frame_base_address,
954 cris_frame_base_address
957 /* Frames information. The definition of the struct frame_info is
961 enum frame_type type;
965 If the compilation option -fno-omit-frame-pointer is present the
966 variable frame will be set to the content of R8 which is the frame
969 The variable pc contains the address where execution is performed
970 in the present frame. The innermost frame contains the current content
971 of the register PC. All other frames contain the content of the
972 register PC in the next frame.
974 The variable `type' indicates the frame's type: normal, SIGTRAMP
975 (associated with a signal handler), dummy (associated with a dummy
978 The variable return_pc contains the address where execution should be
979 resumed when the present frame has finished, the return address.
981 The variable leaf_function is 1 if the return address is in the register
982 SRP, and 0 if it is on the stack.
984 Prologue instructions C-code.
985 The prologue may consist of (-fno-omit-frame-pointer)
989 move.d sp,r8 move.d sp,r8
991 movem rY,[sp] movem rY,[sp]
992 move.S rZ,[r8-U] move.S rZ,[r8-U]
994 where 1 is a non-terminal function, and 2 is a leaf-function.
996 Note that this assumption is extremely brittle, and will break at the
997 slightest change in GCC's prologue.
999 If local variables are declared or register contents are saved on stack
1000 the subq-instruction will be present with X as the number of bytes
1001 needed for storage. The reshuffle with respect to r8 may be performed
1002 with any size S (b, w, d) and any of the general registers Z={0..13}.
1003 The offset U should be representable by a signed 8-bit value in all cases.
1004 Thus, the prefix word is assumed to be immediate byte offset mode followed
1005 by another word containing the instruction.
1014 Prologue instructions C++-code.
1015 Case 1) and 2) in the C-code may be followed by
1017 move.d r10,rS ; this
1021 move.S [r8+U],rZ ; P4
1023 if any of the call parameters are stored. The host expects these
1024 instructions to be executed in order to get the call parameters right. */
1026 /* Examine the prologue of a function. The variable ip is the address of
1027 the first instruction of the prologue. The variable limit is the address
1028 of the first instruction after the prologue. The variable fi contains the
1029 information in struct frame_info. The variable frameless_p controls whether
1030 the entire prologue is examined (0) or just enough instructions to
1031 determine that it is a prologue (1). */
1034 cris_scan_prologue (CORE_ADDR pc, struct frame_info *this_frame,
1035 struct cris_unwind_cache *info)
1037 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1038 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1040 /* Present instruction. */
1041 unsigned short insn;
1043 /* Next instruction, lookahead. */
1044 unsigned short insn_next;
1047 /* Is there a push fp? */
1050 /* Number of byte on stack used for local variables and movem. */
1053 /* Highest register number in a movem. */
1056 /* move.d r<source_register>,rS */
1057 short source_register;
1062 /* This frame is with respect to a leaf until a push srp is found. */
1065 info->leaf_function = 1;
1068 /* Assume nothing on stack. */
1072 /* If we were called without a this_frame, that means we were called
1073 from cris_skip_prologue which already tried to find the end of the
1074 prologue through the symbol information. 64 instructions past current
1075 pc is arbitrarily chosen, but at least it means we'll stop eventually. */
1076 limit = this_frame ? get_frame_pc (this_frame) : pc + 64;
1078 /* Find the prologue instructions. */
1079 while (pc > 0 && pc < limit)
1081 insn = read_memory_unsigned_integer (pc, 2, byte_order);
1085 /* push <reg> 32 bit instruction. */
1086 insn_next = read_memory_unsigned_integer (pc, 2, byte_order);
1088 regno = cris_get_operand2 (insn_next);
1091 info->sp_offset += 4;
1093 /* This check, meant to recognize srp, used to be regno ==
1094 (SRP_REGNUM - NUM_GENREGS), but that covers r11 also. */
1095 if (insn_next == 0xBE7E)
1099 info->leaf_function = 0;
1102 else if (insn_next == 0x8FEE)
1107 info->r8_offset = info->sp_offset;
1111 else if (insn == 0x866E)
1116 info->uses_frame = 1;
1120 else if (cris_get_operand2 (insn) == gdbarch_sp_regnum (gdbarch)
1121 && cris_get_mode (insn) == 0x0000
1122 && cris_get_opcode (insn) == 0x000A)
1127 info->sp_offset += cris_get_quick_value (insn);
1130 else if (cris_get_mode (insn) == 0x0002
1131 && cris_get_opcode (insn) == 0x000F
1132 && cris_get_size (insn) == 0x0003
1133 && cris_get_operand1 (insn) == gdbarch_sp_regnum (gdbarch))
1135 /* movem r<regsave>,[sp] */
1136 regsave = cris_get_operand2 (insn);
1138 else if (cris_get_operand2 (insn) == gdbarch_sp_regnum (gdbarch)
1139 && ((insn & 0x0F00) >> 8) == 0x0001
1140 && (cris_get_signed_offset (insn) < 0))
1142 /* Immediate byte offset addressing prefix word with sp as base
1143 register. Used for CRIS v8 i.e. ETRAX 100 and newer if <val>
1144 is between 64 and 128.
1145 movem r<regsave>,[sp=sp-<val>] */
1148 info->sp_offset += -cris_get_signed_offset (insn);
1150 insn_next = read_memory_unsigned_integer (pc, 2, byte_order);
1152 if (cris_get_mode (insn_next) == PREFIX_ASSIGN_MODE
1153 && cris_get_opcode (insn_next) == 0x000F
1154 && cris_get_size (insn_next) == 0x0003
1155 && cris_get_operand1 (insn_next) == gdbarch_sp_regnum
1158 regsave = cris_get_operand2 (insn_next);
1162 /* The prologue ended before the limit was reached. */
1167 else if (cris_get_mode (insn) == 0x0001
1168 && cris_get_opcode (insn) == 0x0009
1169 && cris_get_size (insn) == 0x0002)
1171 /* move.d r<10..13>,r<0..15> */
1172 source_register = cris_get_operand1 (insn);
1174 /* FIXME? In the glibc solibs, the prologue might contain something
1175 like (this example taken from relocate_doit):
1177 sub.d 0xfffef426,$r0
1178 which isn't covered by the source_register check below. Question
1179 is whether to add a check for this combo, or make better use of
1180 the limit variable instead. */
1181 if (source_register < ARG1_REGNUM || source_register > ARG4_REGNUM)
1183 /* The prologue ended before the limit was reached. */
1188 else if (cris_get_operand2 (insn) == CRIS_FP_REGNUM
1189 /* The size is a fixed-size. */
1190 && ((insn & 0x0F00) >> 8) == 0x0001
1191 /* A negative offset. */
1192 && (cris_get_signed_offset (insn) < 0))
1194 /* move.S rZ,[r8-U] (?) */
1195 insn_next = read_memory_unsigned_integer (pc, 2, byte_order);
1197 regno = cris_get_operand2 (insn_next);
1198 if ((regno >= 0 && regno < gdbarch_sp_regnum (gdbarch))
1199 && cris_get_mode (insn_next) == PREFIX_OFFSET_MODE
1200 && cris_get_opcode (insn_next) == 0x000F)
1202 /* move.S rZ,[r8-U] */
1207 /* The prologue ended before the limit was reached. */
1212 else if (cris_get_operand2 (insn) == CRIS_FP_REGNUM
1213 /* The size is a fixed-size. */
1214 && ((insn & 0x0F00) >> 8) == 0x0001
1215 /* A positive offset. */
1216 && (cris_get_signed_offset (insn) > 0))
1218 /* move.S [r8+U],rZ (?) */
1219 insn_next = read_memory_unsigned_integer (pc, 2, byte_order);
1221 regno = cris_get_operand2 (insn_next);
1222 if ((regno >= 0 && regno < gdbarch_sp_regnum (gdbarch))
1223 && cris_get_mode (insn_next) == PREFIX_OFFSET_MODE
1224 && cris_get_opcode (insn_next) == 0x0009
1225 && cris_get_operand1 (insn_next) == regno)
1227 /* move.S [r8+U],rZ */
1232 /* The prologue ended before the limit was reached. */
1239 /* The prologue ended before the limit was reached. */
1245 /* We only want to know the end of the prologue when this_frame and info
1246 are NULL (called from cris_skip_prologue i.e.). */
1247 if (this_frame == NULL && info == NULL)
1252 info->size = info->sp_offset;
1254 /* Compute the previous frame's stack pointer (which is also the
1255 frame's ID's stack address), and this frame's base pointer. */
1256 if (info->uses_frame)
1259 /* The SP was moved to the FP. This indicates that a new frame
1260 was created. Get THIS frame's FP value by unwinding it from
1262 this_base = get_frame_register_unsigned (this_frame, CRIS_FP_REGNUM);
1263 info->base = this_base;
1264 info->saved_regs[CRIS_FP_REGNUM].addr = info->base;
1266 /* The FP points at the last saved register. Adjust the FP back
1267 to before the first saved register giving the SP. */
1268 info->prev_sp = info->base + info->r8_offset;
1273 /* Assume that the FP is this frame's SP but with that pushed
1274 stack space added back. */
1275 this_base = get_frame_register_unsigned (this_frame,
1276 gdbarch_sp_regnum (gdbarch));
1277 info->base = this_base;
1278 info->prev_sp = info->base + info->size;
1281 /* Calculate the addresses for the saved registers on the stack. */
1282 /* FIXME: The address calculation should really be done on the fly while
1283 we're analyzing the prologue (we only hold one regsave value as it is
1285 val = info->sp_offset;
1287 for (regno = regsave; regno >= 0; regno--)
1289 info->saved_regs[regno].addr = info->base + info->r8_offset - val;
1293 /* The previous frame's SP needed to be computed. Save the computed
1295 trad_frame_set_value (info->saved_regs,
1296 gdbarch_sp_regnum (gdbarch), info->prev_sp);
1298 if (!info->leaf_function)
1300 /* SRP saved on the stack. But where? */
1301 if (info->r8_offset == 0)
1303 /* R8 not pushed yet. */
1304 info->saved_regs[SRP_REGNUM].addr = info->base;
1308 /* R8 pushed, but SP may or may not be moved to R8 yet. */
1309 info->saved_regs[SRP_REGNUM].addr = info->base + 4;
1313 /* The PC is found in SRP (the actual register or located on the stack). */
1314 info->saved_regs[gdbarch_pc_regnum (gdbarch)]
1315 = info->saved_regs[SRP_REGNUM];
1321 crisv32_scan_prologue (CORE_ADDR pc, struct frame_info *this_frame,
1322 struct cris_unwind_cache *info)
1324 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1327 /* Unlike the CRISv10 prologue scanner (cris_scan_prologue), this is not
1328 meant to be a full-fledged prologue scanner. It is only needed for
1329 the cases where we end up in code always lacking DWARF-2 CFI, notably:
1331 * PLT stubs (library calls)
1333 * signal trampolines
1335 For those cases, it is assumed that there is no actual prologue; that
1336 the stack pointer is not adjusted, and (as a consequence) the return
1337 address is not pushed onto the stack. */
1339 /* We only want to know the end of the prologue when this_frame and info
1340 are NULL (called from cris_skip_prologue i.e.). */
1341 if (this_frame == NULL && info == NULL)
1346 /* The SP is assumed to be unaltered. */
1347 this_base = get_frame_register_unsigned (this_frame,
1348 gdbarch_sp_regnum (gdbarch));
1349 info->base = this_base;
1350 info->prev_sp = this_base;
1352 /* The PC is assumed to be found in SRP. */
1353 info->saved_regs[gdbarch_pc_regnum (gdbarch)]
1354 = info->saved_regs[SRP_REGNUM];
1359 /* Advance pc beyond any function entry prologue instructions at pc
1360 to reach some "real" code. */
1362 /* Given a PC value corresponding to the start of a function, return the PC
1363 of the first instruction after the function prologue. */
1366 cris_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
1368 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1369 CORE_ADDR func_addr, func_end;
1370 struct symtab_and_line sal;
1371 CORE_ADDR pc_after_prologue;
1373 /* If we have line debugging information, then the end of the prologue
1374 should the first assembly instruction of the first source line. */
1375 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
1377 sal = find_pc_line (func_addr, 0);
1378 if (sal.end > 0 && sal.end < func_end)
1382 if (tdep->cris_version == 32)
1383 pc_after_prologue = crisv32_scan_prologue (pc, NULL, NULL);
1385 pc_after_prologue = cris_scan_prologue (pc, NULL, NULL);
1387 return pc_after_prologue;
1391 cris_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
1394 pc = frame_unwind_register_unsigned (next_frame,
1395 gdbarch_pc_regnum (gdbarch));
1400 cris_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
1403 sp = frame_unwind_register_unsigned (next_frame,
1404 gdbarch_sp_regnum (gdbarch));
1408 /* Use the program counter to determine the contents and size of a breakpoint
1409 instruction. It returns a pointer to a string of bytes that encode a
1410 breakpoint instruction, stores the length of the string to *lenptr, and
1411 adjusts pcptr (if necessary) to point to the actual memory location where
1412 the breakpoint should be inserted. */
1414 static const unsigned char *
1415 cris_breakpoint_from_pc (struct gdbarch *gdbarch,
1416 CORE_ADDR *pcptr, int *lenptr)
1418 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1419 static unsigned char break8_insn[] = {0x38, 0xe9};
1420 static unsigned char break15_insn[] = {0x3f, 0xe9};
1423 if (tdep->cris_mode == cris_mode_guru)
1424 return break15_insn;
1429 /* Returns 1 if spec_reg is applicable to the current gdbarch's CRIS version,
1433 cris_spec_reg_applicable (struct gdbarch *gdbarch,
1434 struct cris_spec_reg spec_reg)
1436 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1437 unsigned int version = tdep->cris_version;
1439 switch (spec_reg.applicable_version)
1441 case cris_ver_version_all:
1443 case cris_ver_warning:
1444 /* Indeterminate/obsolete. */
1447 return (version >= 0 && version <= 3);
1449 return (version >= 3);
1451 return (version == 8 || version == 9);
1453 return (version >= 8);
1454 case cris_ver_v0_10:
1455 return (version >= 0 && version <= 10);
1456 case cris_ver_v3_10:
1457 return (version >= 3 && version <= 10);
1458 case cris_ver_v8_10:
1459 return (version >= 8 && version <= 10);
1461 return (version == 10);
1463 return (version >= 10);
1465 return (version >= 32);
1467 /* Invalid cris version. */
1472 /* Returns the register size in unit byte. Returns 0 for an unimplemented
1473 register, -1 for an invalid register. */
1476 cris_register_size (struct gdbarch *gdbarch, int regno)
1478 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1482 if (regno >= 0 && regno < NUM_GENREGS)
1484 /* General registers (R0 - R15) are 32 bits. */
1487 else if (regno >= NUM_GENREGS && regno < (NUM_GENREGS + NUM_SPECREGS))
1489 /* Special register (R16 - R31). cris_spec_regs is zero-based.
1490 Adjust regno accordingly. */
1491 spec_regno = regno - NUM_GENREGS;
1493 for (i = 0; cris_spec_regs[i].name != NULL; i++)
1495 if (cris_spec_regs[i].number == spec_regno
1496 && cris_spec_reg_applicable (gdbarch, cris_spec_regs[i]))
1497 /* Go with the first applicable register. */
1498 return cris_spec_regs[i].reg_size;
1500 /* Special register not applicable to this CRIS version. */
1503 else if (regno >= gdbarch_pc_regnum (gdbarch)
1504 && regno < gdbarch_num_regs (gdbarch))
1506 /* This will apply to CRISv32 only where there are additional registers
1507 after the special registers (pseudo PC and support registers). */
1515 /* Nonzero if regno should not be fetched from the target. This is the case
1516 for unimplemented (size 0) and non-existant registers. */
1519 cris_cannot_fetch_register (struct gdbarch *gdbarch, int regno)
1521 return ((regno < 0 || regno >= gdbarch_num_regs (gdbarch))
1522 || (cris_register_size (gdbarch, regno) == 0));
1525 /* Nonzero if regno should not be written to the target, for various
1529 cris_cannot_store_register (struct gdbarch *gdbarch, int regno)
1531 /* There are three kinds of registers we refuse to write to.
1532 1. Those that not implemented.
1533 2. Those that are read-only (depends on the processor mode).
1534 3. Those registers to which a write has no effect. */
1537 || regno >= gdbarch_num_regs (gdbarch)
1538 || cris_register_size (gdbarch, regno) == 0)
1539 /* Not implemented. */
1542 else if (regno == VR_REGNUM)
1546 else if (regno == P0_REGNUM || regno == P4_REGNUM || regno == P8_REGNUM)
1547 /* Writing has no effect. */
1550 /* IBR, BAR, BRP and IRP are read-only in user mode. Let the debug
1551 agent decide whether they are writable. */
1556 /* Nonzero if regno should not be fetched from the target. This is the case
1557 for unimplemented (size 0) and non-existant registers. */
1560 crisv32_cannot_fetch_register (struct gdbarch *gdbarch, int regno)
1562 return ((regno < 0 || regno >= gdbarch_num_regs (gdbarch))
1563 || (cris_register_size (gdbarch, regno) == 0));
1566 /* Nonzero if regno should not be written to the target, for various
1570 crisv32_cannot_store_register (struct gdbarch *gdbarch, int regno)
1572 /* There are three kinds of registers we refuse to write to.
1573 1. Those that not implemented.
1574 2. Those that are read-only (depends on the processor mode).
1575 3. Those registers to which a write has no effect. */
1578 || regno >= gdbarch_num_regs (gdbarch)
1579 || cris_register_size (gdbarch, regno) == 0)
1580 /* Not implemented. */
1583 else if (regno == VR_REGNUM)
1587 else if (regno == BZ_REGNUM || regno == WZ_REGNUM || regno == DZ_REGNUM)
1588 /* Writing has no effect. */
1591 /* Many special registers are read-only in user mode. Let the debug
1592 agent decide whether they are writable. */
1597 /* Return the GDB type (defined in gdbtypes.c) for the "standard" data type
1598 of data in register regno. */
1600 static struct type *
1601 cris_register_type (struct gdbarch *gdbarch, int regno)
1603 if (regno == gdbarch_pc_regnum (gdbarch))
1604 return builtin_type (gdbarch)->builtin_func_ptr;
1605 else if (regno == gdbarch_sp_regnum (gdbarch)
1606 || regno == CRIS_FP_REGNUM)
1607 return builtin_type (gdbarch)->builtin_data_ptr;
1608 else if ((regno >= 0 && regno < gdbarch_sp_regnum (gdbarch))
1609 || (regno >= MOF_REGNUM && regno <= USP_REGNUM))
1610 /* Note: R8 taken care of previous clause. */
1611 return builtin_type (gdbarch)->builtin_uint32;
1612 else if (regno >= P4_REGNUM && regno <= CCR_REGNUM)
1613 return builtin_type (gdbarch)->builtin_uint16;
1614 else if (regno >= P0_REGNUM && regno <= VR_REGNUM)
1615 return builtin_type (gdbarch)->builtin_uint8;
1617 /* Invalid (unimplemented) register. */
1618 return builtin_type (gdbarch)->builtin_int0;
1621 static struct type *
1622 crisv32_register_type (struct gdbarch *gdbarch, int regno)
1624 if (regno == gdbarch_pc_regnum (gdbarch))
1625 return builtin_type (gdbarch)->builtin_func_ptr;
1626 else if (regno == gdbarch_sp_regnum (gdbarch)
1627 || regno == CRIS_FP_REGNUM)
1628 return builtin_type (gdbarch)->builtin_data_ptr;
1629 else if ((regno >= 0 && regno <= ACR_REGNUM)
1630 || (regno >= EXS_REGNUM && regno <= SPC_REGNUM)
1631 || (regno == PID_REGNUM)
1632 || (regno >= S0_REGNUM && regno <= S15_REGNUM))
1633 /* Note: R8 and SP taken care of by previous clause. */
1634 return builtin_type (gdbarch)->builtin_uint32;
1635 else if (regno == WZ_REGNUM)
1636 return builtin_type (gdbarch)->builtin_uint16;
1637 else if (regno == BZ_REGNUM || regno == VR_REGNUM || regno == SRS_REGNUM)
1638 return builtin_type (gdbarch)->builtin_uint8;
1641 /* Invalid (unimplemented) register. Should not happen as there are
1642 no unimplemented CRISv32 registers. */
1643 warning (_("crisv32_register_type: unknown regno %d"), regno);
1644 return builtin_type (gdbarch)->builtin_int0;
1648 /* Stores a function return value of type type, where valbuf is the address
1649 of the value to be stored. */
1651 /* In the CRIS ABI, R10 and R11 are used to store return values. */
1654 cris_store_return_value (struct type *type, struct regcache *regcache,
1655 const gdb_byte *valbuf)
1657 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1658 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1660 int len = TYPE_LENGTH (type);
1664 /* Put the return value in R10. */
1665 val = extract_unsigned_integer (valbuf, len, byte_order);
1666 regcache_cooked_write_unsigned (regcache, ARG1_REGNUM, val);
1670 /* Put the return value in R10 and R11. */
1671 val = extract_unsigned_integer (valbuf, 4, byte_order);
1672 regcache_cooked_write_unsigned (regcache, ARG1_REGNUM, val);
1673 val = extract_unsigned_integer (valbuf + 4, len - 4, byte_order);
1674 regcache_cooked_write_unsigned (regcache, ARG2_REGNUM, val);
1677 error (_("cris_store_return_value: type length too large."));
1680 /* Return the name of register regno as a string. Return NULL for an
1681 invalid or unimplemented register. */
1684 cris_special_register_name (struct gdbarch *gdbarch, int regno)
1689 /* Special register (R16 - R31). cris_spec_regs is zero-based.
1690 Adjust regno accordingly. */
1691 spec_regno = regno - NUM_GENREGS;
1693 /* Assume nothing about the layout of the cris_spec_regs struct
1695 for (i = 0; cris_spec_regs[i].name != NULL; i++)
1697 if (cris_spec_regs[i].number == spec_regno
1698 && cris_spec_reg_applicable (gdbarch, cris_spec_regs[i]))
1699 /* Go with the first applicable register. */
1700 return cris_spec_regs[i].name;
1702 /* Special register not applicable to this CRIS version. */
1707 cris_register_name (struct gdbarch *gdbarch, int regno)
1709 static char *cris_genreg_names[] =
1710 { "r0", "r1", "r2", "r3", \
1711 "r4", "r5", "r6", "r7", \
1712 "r8", "r9", "r10", "r11", \
1713 "r12", "r13", "sp", "pc" };
1715 if (regno >= 0 && regno < NUM_GENREGS)
1717 /* General register. */
1718 return cris_genreg_names[regno];
1720 else if (regno >= NUM_GENREGS && regno < gdbarch_num_regs (gdbarch))
1722 return cris_special_register_name (gdbarch, regno);
1726 /* Invalid register. */
1732 crisv32_register_name (struct gdbarch *gdbarch, int regno)
1734 static char *crisv32_genreg_names[] =
1735 { "r0", "r1", "r2", "r3", \
1736 "r4", "r5", "r6", "r7", \
1737 "r8", "r9", "r10", "r11", \
1738 "r12", "r13", "sp", "acr"
1741 static char *crisv32_sreg_names[] =
1742 { "s0", "s1", "s2", "s3", \
1743 "s4", "s5", "s6", "s7", \
1744 "s8", "s9", "s10", "s11", \
1745 "s12", "s13", "s14", "s15"
1748 if (regno >= 0 && regno < NUM_GENREGS)
1750 /* General register. */
1751 return crisv32_genreg_names[regno];
1753 else if (regno >= NUM_GENREGS && regno < (NUM_GENREGS + NUM_SPECREGS))
1755 return cris_special_register_name (gdbarch, regno);
1757 else if (regno == gdbarch_pc_regnum (gdbarch))
1761 else if (regno >= S0_REGNUM && regno <= S15_REGNUM)
1763 return crisv32_sreg_names[regno - S0_REGNUM];
1767 /* Invalid register. */
1772 /* Convert DWARF register number REG to the appropriate register
1773 number used by GDB. */
1776 cris_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int reg)
1778 /* We need to re-map a couple of registers (SRP is 16 in Dwarf-2 register
1779 numbering, MOF is 18).
1780 Adapted from gcc/config/cris/cris.h. */
1781 static int cris_dwarf_regmap[] = {
1793 if (reg >= 0 && reg < ARRAY_SIZE (cris_dwarf_regmap))
1794 regnum = cris_dwarf_regmap[reg];
1797 warning (_("Unmapped DWARF Register #%d encountered."), reg);
1802 /* DWARF-2 frame support. */
1805 cris_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
1806 struct dwarf2_frame_state_reg *reg,
1807 struct frame_info *this_frame)
1809 /* The return address column. */
1810 if (regnum == gdbarch_pc_regnum (gdbarch))
1811 reg->how = DWARF2_FRAME_REG_RA;
1813 /* The call frame address. */
1814 else if (regnum == gdbarch_sp_regnum (gdbarch))
1815 reg->how = DWARF2_FRAME_REG_CFA;
1818 /* Extract from an array regbuf containing the raw register state a function
1819 return value of type type, and copy that, in virtual format, into
1822 /* In the CRIS ABI, R10 and R11 are used to store return values. */
1825 cris_extract_return_value (struct type *type, struct regcache *regcache,
1828 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1829 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1831 int len = TYPE_LENGTH (type);
1835 /* Get the return value from R10. */
1836 regcache_cooked_read_unsigned (regcache, ARG1_REGNUM, &val);
1837 store_unsigned_integer (valbuf, len, byte_order, val);
1841 /* Get the return value from R10 and R11. */
1842 regcache_cooked_read_unsigned (regcache, ARG1_REGNUM, &val);
1843 store_unsigned_integer (valbuf, 4, byte_order, val);
1844 regcache_cooked_read_unsigned (regcache, ARG2_REGNUM, &val);
1845 store_unsigned_integer (valbuf + 4, len - 4, byte_order, val);
1848 error (_("cris_extract_return_value: type length too large"));
1851 /* Handle the CRIS return value convention. */
1853 static enum return_value_convention
1854 cris_return_value (struct gdbarch *gdbarch, struct value *function,
1855 struct type *type, struct regcache *regcache,
1856 gdb_byte *readbuf, const gdb_byte *writebuf)
1858 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
1859 || TYPE_CODE (type) == TYPE_CODE_UNION
1860 || TYPE_LENGTH (type) > 8)
1861 /* Structs, unions, and anything larger than 8 bytes (2 registers)
1862 goes on the stack. */
1863 return RETURN_VALUE_STRUCT_CONVENTION;
1866 cris_extract_return_value (type, regcache, readbuf);
1868 cris_store_return_value (type, regcache, writebuf);
1870 return RETURN_VALUE_REGISTER_CONVENTION;
1873 /* Calculates a value that measures how good inst_args constraints an
1874 instruction. It stems from cris_constraint, found in cris-dis.c. */
1877 constraint (unsigned int insn, const char *inst_args,
1878 inst_env_type *inst_env)
1883 const gdb_byte *s = (const gdb_byte *) inst_args;
1889 if ((insn & 0x30) == 0x30)
1894 /* A prefix operand. */
1895 if (inst_env->prefix_found)
1901 /* A "push" prefix. (This check was REMOVED by san 970921.) Check for
1902 valid "push" size. In case of special register, it may be != 4. */
1903 if (inst_env->prefix_found)
1909 retval = (((insn >> 0xC) & 0xF) == (insn & 0xF));
1917 tmp = (insn >> 0xC) & 0xF;
1919 for (i = 0; cris_spec_regs[i].name != NULL; i++)
1921 /* Since we match four bits, we will give a value of
1922 4 - 1 = 3 in a match. If there is a corresponding
1923 exact match of a special register in another pattern, it
1924 will get a value of 4, which will be higher. This should
1925 be correct in that an exact pattern would match better that
1927 Note that there is a reason for not returning zero; the
1928 pattern for "clear" is partly matched in the bit-pattern
1929 (the two lower bits must be zero), while the bit-pattern
1930 for a move from a special register is matched in the
1931 register constraint.
1932 This also means we will will have a race condition if
1933 there is a partly match in three bits in the bit pattern. */
1934 if (tmp == cris_spec_regs[i].number)
1941 if (cris_spec_regs[i].name == NULL)
1948 /* Returns the number of bits set in the variable value. */
1951 number_of_bits (unsigned int value)
1953 int number_of_bits = 0;
1957 number_of_bits += 1;
1958 value &= (value - 1);
1960 return number_of_bits;
1963 /* Finds the address that should contain the single step breakpoint(s).
1964 It stems from code in cris-dis.c. */
1967 find_cris_op (unsigned short insn, inst_env_type *inst_env)
1970 int max_level_of_match = -1;
1971 int max_matched = -1;
1974 for (i = 0; cris_opcodes[i].name != NULL; i++)
1976 if (((cris_opcodes[i].match & insn) == cris_opcodes[i].match)
1977 && ((cris_opcodes[i].lose & insn) == 0)
1978 /* Only CRISv10 instructions, please. */
1979 && (cris_opcodes[i].applicable_version != cris_ver_v32p))
1981 level_of_match = constraint (insn, cris_opcodes[i].args, inst_env);
1982 if (level_of_match >= 0)
1985 number_of_bits (cris_opcodes[i].match | cris_opcodes[i].lose);
1986 if (level_of_match > max_level_of_match)
1989 max_level_of_match = level_of_match;
1990 if (level_of_match == 16)
1992 /* All bits matched, cannot find better. */
2002 /* Attempts to find single-step breakpoints. Returns -1 on failure which is
2003 actually an internal error. */
2006 find_step_target (struct frame_info *frame, inst_env_type *inst_env)
2010 unsigned short insn;
2011 struct gdbarch *gdbarch = get_frame_arch (frame);
2012 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2014 /* Create a local register image and set the initial state. */
2015 for (i = 0; i < NUM_GENREGS; i++)
2018 (unsigned long) get_frame_register_unsigned (frame, i);
2020 offset = NUM_GENREGS;
2021 for (i = 0; i < NUM_SPECREGS; i++)
2024 (unsigned long) get_frame_register_unsigned (frame, offset + i);
2026 inst_env->branch_found = 0;
2027 inst_env->slot_needed = 0;
2028 inst_env->delay_slot_pc_active = 0;
2029 inst_env->prefix_found = 0;
2030 inst_env->invalid = 0;
2031 inst_env->xflag_found = 0;
2032 inst_env->disable_interrupt = 0;
2033 inst_env->byte_order = byte_order;
2035 /* Look for a step target. */
2038 /* Read an instruction from the client. */
2039 insn = read_memory_unsigned_integer
2040 (inst_env->reg[gdbarch_pc_regnum (gdbarch)], 2, byte_order);
2042 /* If the instruction is not in a delay slot the new content of the
2043 PC is [PC] + 2. If the instruction is in a delay slot it is not
2044 that simple. Since a instruction in a delay slot cannot change
2045 the content of the PC, it does not matter what value PC will have.
2046 Just make sure it is a valid instruction. */
2047 if (!inst_env->delay_slot_pc_active)
2049 inst_env->reg[gdbarch_pc_regnum (gdbarch)] += 2;
2053 inst_env->delay_slot_pc_active = 0;
2054 inst_env->reg[gdbarch_pc_regnum (gdbarch)]
2055 = inst_env->delay_slot_pc;
2057 /* Analyse the present instruction. */
2058 i = find_cris_op (insn, inst_env);
2061 inst_env->invalid = 1;
2065 cris_gdb_func (gdbarch, cris_opcodes[i].op, insn, inst_env);
2067 } while (!inst_env->invalid
2068 && (inst_env->prefix_found || inst_env->xflag_found
2069 || inst_env->slot_needed));
2073 /* There is no hardware single-step support. The function find_step_target
2074 digs through the opcodes in order to find all possible targets.
2075 Either one ordinary target or two targets for branches may be found. */
2078 cris_software_single_step (struct frame_info *frame)
2080 struct gdbarch *gdbarch = get_frame_arch (frame);
2081 struct address_space *aspace = get_frame_address_space (frame);
2082 inst_env_type inst_env;
2084 /* Analyse the present instruction environment and insert
2086 int status = find_step_target (frame, &inst_env);
2089 /* Could not find a target. Things are likely to go downhill
2091 warning (_("CRIS software single step could not find a step target."));
2095 /* Insert at most two breakpoints. One for the next PC content
2096 and possibly another one for a branch, jump, etc. */
2098 = (CORE_ADDR) inst_env.reg[gdbarch_pc_regnum (gdbarch)];
2099 insert_single_step_breakpoint (gdbarch, aspace, next_pc);
2100 if (inst_env.branch_found
2101 && (CORE_ADDR) inst_env.branch_break_address != next_pc)
2103 CORE_ADDR branch_target_address
2104 = (CORE_ADDR) inst_env.branch_break_address;
2105 insert_single_step_breakpoint (gdbarch,
2106 aspace, branch_target_address);
2113 /* Calculates the prefix value for quick offset addressing mode. */
2116 quick_mode_bdap_prefix (unsigned short inst, inst_env_type *inst_env)
2118 /* It's invalid to be in a delay slot. You can't have a prefix to this
2119 instruction (not 100% sure). */
2120 if (inst_env->slot_needed || inst_env->prefix_found)
2122 inst_env->invalid = 1;
2126 inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)];
2127 inst_env->prefix_value += cris_get_bdap_quick_offset (inst);
2129 /* A prefix doesn't change the xflag_found. But the rest of the flags
2131 inst_env->slot_needed = 0;
2132 inst_env->prefix_found = 1;
2135 /* Updates the autoincrement register. The size of the increment is derived
2136 from the size of the operation. The PC is always kept aligned on even
2140 process_autoincrement (int size, unsigned short inst, inst_env_type *inst_env)
2142 if (size == INST_BYTE_SIZE)
2144 inst_env->reg[cris_get_operand1 (inst)] += 1;
2146 /* The PC must be word aligned, so increase the PC with one
2147 word even if the size is byte. */
2148 if (cris_get_operand1 (inst) == REG_PC)
2150 inst_env->reg[REG_PC] += 1;
2153 else if (size == INST_WORD_SIZE)
2155 inst_env->reg[cris_get_operand1 (inst)] += 2;
2157 else if (size == INST_DWORD_SIZE)
2159 inst_env->reg[cris_get_operand1 (inst)] += 4;
2164 inst_env->invalid = 1;
2168 /* Just a forward declaration. */
2170 static unsigned long get_data_from_address (unsigned short *inst,
2172 enum bfd_endian byte_order);
2174 /* Calculates the prefix value for the general case of offset addressing
2178 bdap_prefix (unsigned short inst, inst_env_type *inst_env)
2180 /* It's invalid to be in a delay slot. */
2181 if (inst_env->slot_needed || inst_env->prefix_found)
2183 inst_env->invalid = 1;
2187 /* The calculation of prefix_value used to be after process_autoincrement,
2188 but that fails for an instruction such as jsr [$r0+12] which is encoded
2189 as 5f0d 0c00 30b9 when compiled with -fpic. Since PC is operand1 it
2190 mustn't be incremented until we have read it and what it points at. */
2191 inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)];
2193 /* The offset is an indirection of the contents of the operand1 register. */
2194 inst_env->prefix_value +=
2195 get_data_from_address (&inst, inst_env->reg[cris_get_operand1 (inst)],
2196 inst_env->byte_order);
2198 if (cris_get_mode (inst) == AUTOINC_MODE)
2200 process_autoincrement (cris_get_size (inst), inst, inst_env);
2203 /* A prefix doesn't change the xflag_found. But the rest of the flags
2205 inst_env->slot_needed = 0;
2206 inst_env->prefix_found = 1;
2209 /* Calculates the prefix value for the index addressing mode. */
2212 biap_prefix (unsigned short inst, inst_env_type *inst_env)
2214 /* It's invalid to be in a delay slot. I can't see that it's possible to
2215 have a prefix to this instruction. So I will treat this as invalid. */
2216 if (inst_env->slot_needed || inst_env->prefix_found)
2218 inst_env->invalid = 1;
2222 inst_env->prefix_value = inst_env->reg[cris_get_operand1 (inst)];
2224 /* The offset is the operand2 value shifted the size of the instruction
2226 inst_env->prefix_value +=
2227 inst_env->reg[cris_get_operand2 (inst)] << cris_get_size (inst);
2229 /* If the PC is operand1 (base) the address used is the address after
2230 the main instruction, i.e. address + 2 (the PC is already compensated
2231 for the prefix operation). */
2232 if (cris_get_operand1 (inst) == REG_PC)
2234 inst_env->prefix_value += 2;
2237 /* A prefix doesn't change the xflag_found. But the rest of the flags
2239 inst_env->slot_needed = 0;
2240 inst_env->xflag_found = 0;
2241 inst_env->prefix_found = 1;
2244 /* Calculates the prefix value for the double indirect addressing mode. */
2247 dip_prefix (unsigned short inst, inst_env_type *inst_env)
2252 /* It's invalid to be in a delay slot. */
2253 if (inst_env->slot_needed || inst_env->prefix_found)
2255 inst_env->invalid = 1;
2259 /* The prefix value is one dereference of the contents of the operand1
2261 address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)];
2262 inst_env->prefix_value
2263 = read_memory_unsigned_integer (address, 4, inst_env->byte_order);
2265 /* Check if the mode is autoincrement. */
2266 if (cris_get_mode (inst) == AUTOINC_MODE)
2268 inst_env->reg[cris_get_operand1 (inst)] += 4;
2271 /* A prefix doesn't change the xflag_found. But the rest of the flags
2273 inst_env->slot_needed = 0;
2274 inst_env->xflag_found = 0;
2275 inst_env->prefix_found = 1;
2278 /* Finds the destination for a branch with 8-bits offset. */
2281 eight_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env)
2286 /* If we have a prefix or are in a delay slot it's bad. */
2287 if (inst_env->slot_needed || inst_env->prefix_found)
2289 inst_env->invalid = 1;
2293 /* We have a branch, find out where the branch will land. */
2294 offset = cris_get_branch_short_offset (inst);
2296 /* Check if the offset is signed. */
2297 if (offset & BRANCH_SIGNED_SHORT_OFFSET_MASK)
2302 /* The offset ends with the sign bit, set it to zero. The address
2303 should always be word aligned. */
2304 offset &= ~BRANCH_SIGNED_SHORT_OFFSET_MASK;
2306 inst_env->branch_found = 1;
2307 inst_env->branch_break_address = inst_env->reg[REG_PC] + offset;
2309 inst_env->slot_needed = 1;
2310 inst_env->prefix_found = 0;
2311 inst_env->xflag_found = 0;
2312 inst_env->disable_interrupt = 1;
2315 /* Finds the destination for a branch with 16-bits offset. */
2318 sixteen_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env)
2322 /* If we have a prefix or is in a delay slot it's bad. */
2323 if (inst_env->slot_needed || inst_env->prefix_found)
2325 inst_env->invalid = 1;
2329 /* We have a branch, find out the offset for the branch. */
2330 offset = read_memory_integer (inst_env->reg[REG_PC], 2,
2331 inst_env->byte_order);
2333 /* The instruction is one word longer than normal, so add one word
2335 inst_env->reg[REG_PC] += 2;
2337 inst_env->branch_found = 1;
2338 inst_env->branch_break_address = inst_env->reg[REG_PC] + offset;
2341 inst_env->slot_needed = 1;
2342 inst_env->prefix_found = 0;
2343 inst_env->xflag_found = 0;
2344 inst_env->disable_interrupt = 1;
2347 /* Handles the ABS instruction. */
2350 abs_op (unsigned short inst, inst_env_type *inst_env)
2355 /* ABS can't have a prefix, so it's bad if it does. */
2356 if (inst_env->prefix_found)
2358 inst_env->invalid = 1;
2362 /* Check if the operation affects the PC. */
2363 if (cris_get_operand2 (inst) == REG_PC)
2366 /* It's invalid to change to the PC if we are in a delay slot. */
2367 if (inst_env->slot_needed)
2369 inst_env->invalid = 1;
2373 value = (long) inst_env->reg[REG_PC];
2375 /* The value of abs (SIGNED_DWORD_MASK) is SIGNED_DWORD_MASK. */
2376 if (value != SIGNED_DWORD_MASK)
2379 inst_env->reg[REG_PC] = (long) value;
2383 inst_env->slot_needed = 0;
2384 inst_env->prefix_found = 0;
2385 inst_env->xflag_found = 0;
2386 inst_env->disable_interrupt = 0;
2389 /* Handles the ADDI instruction. */
2392 addi_op (unsigned short inst, inst_env_type *inst_env)
2394 /* It's invalid to have the PC as base register. And ADDI can't have
2396 if (inst_env->prefix_found || (cris_get_operand1 (inst) == REG_PC))
2398 inst_env->invalid = 1;
2402 inst_env->slot_needed = 0;
2403 inst_env->prefix_found = 0;
2404 inst_env->xflag_found = 0;
2405 inst_env->disable_interrupt = 0;
2408 /* Handles the ASR instruction. */
2411 asr_op (unsigned short inst, inst_env_type *inst_env)
2414 unsigned long value;
2415 unsigned long signed_extend_mask = 0;
2417 /* ASR can't have a prefix, so check that it doesn't. */
2418 if (inst_env->prefix_found)
2420 inst_env->invalid = 1;
2424 /* Check if the PC is the target register. */
2425 if (cris_get_operand2 (inst) == REG_PC)
2427 /* It's invalid to change the PC in a delay slot. */
2428 if (inst_env->slot_needed)
2430 inst_env->invalid = 1;
2433 /* Get the number of bits to shift. */
2435 = cris_get_asr_shift_steps (inst_env->reg[cris_get_operand1 (inst)]);
2436 value = inst_env->reg[REG_PC];
2438 /* Find out how many bits the operation should apply to. */
2439 if (cris_get_size (inst) == INST_BYTE_SIZE)
2441 if (value & SIGNED_BYTE_MASK)
2443 signed_extend_mask = 0xFF;
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] &= 0xFFFFFF00;
2451 inst_env->reg[REG_PC] |= value;
2453 else if (cris_get_size (inst) == INST_WORD_SIZE)
2455 if (value & SIGNED_WORD_MASK)
2457 signed_extend_mask = 0xFFFF;
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;
2464 inst_env->reg[REG_PC] &= 0xFFFF0000;
2465 inst_env->reg[REG_PC] |= value;
2467 else if (cris_get_size (inst) == INST_DWORD_SIZE)
2469 if (value & SIGNED_DWORD_MASK)
2471 signed_extend_mask = 0xFFFFFFFF;
2472 signed_extend_mask = signed_extend_mask >> shift_steps;
2473 signed_extend_mask = ~signed_extend_mask;
2475 value = value >> shift_steps;
2476 value |= signed_extend_mask;
2477 inst_env->reg[REG_PC] = value;
2480 inst_env->slot_needed = 0;
2481 inst_env->prefix_found = 0;
2482 inst_env->xflag_found = 0;
2483 inst_env->disable_interrupt = 0;
2486 /* Handles the ASRQ instruction. */
2489 asrq_op (unsigned short inst, inst_env_type *inst_env)
2493 unsigned long value;
2494 unsigned long signed_extend_mask = 0;
2496 /* ASRQ can't have a prefix, so check that it doesn't. */
2497 if (inst_env->prefix_found)
2499 inst_env->invalid = 1;
2503 /* Check if the PC is the target register. */
2504 if (cris_get_operand2 (inst) == REG_PC)
2507 /* It's invalid to change the PC in a delay slot. */
2508 if (inst_env->slot_needed)
2510 inst_env->invalid = 1;
2513 /* The shift size is given as a 5 bit quick value, i.e. we don't
2514 want the sign bit of the quick value. */
2515 shift_steps = cris_get_asr_shift_steps (inst);
2516 value = inst_env->reg[REG_PC];
2517 if (value & SIGNED_DWORD_MASK)
2519 signed_extend_mask = 0xFFFFFFFF;
2520 signed_extend_mask = signed_extend_mask >> shift_steps;
2521 signed_extend_mask = ~signed_extend_mask;
2523 value = value >> shift_steps;
2524 value |= signed_extend_mask;
2525 inst_env->reg[REG_PC] = value;
2527 inst_env->slot_needed = 0;
2528 inst_env->prefix_found = 0;
2529 inst_env->xflag_found = 0;
2530 inst_env->disable_interrupt = 0;
2533 /* Handles the AX, EI and SETF instruction. */
2536 ax_ei_setf_op (unsigned short inst, inst_env_type *inst_env)
2538 if (inst_env->prefix_found)
2540 inst_env->invalid = 1;
2543 /* Check if the instruction is setting the X flag. */
2544 if (cris_is_xflag_bit_on (inst))
2546 inst_env->xflag_found = 1;
2550 inst_env->xflag_found = 0;
2552 inst_env->slot_needed = 0;
2553 inst_env->prefix_found = 0;
2554 inst_env->disable_interrupt = 1;
2557 /* Checks if the instruction is in assign mode. If so, it updates the assign
2558 register. Note that check_assign assumes that the caller has checked that
2559 there is a prefix to this instruction. The mode check depends on this. */
2562 check_assign (unsigned short inst, inst_env_type *inst_env)
2564 /* Check if it's an assign addressing mode. */
2565 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2567 /* Assign the prefix value to operand 1. */
2568 inst_env->reg[cris_get_operand1 (inst)] = inst_env->prefix_value;
2572 /* Handles the 2-operand BOUND instruction. */
2575 two_operand_bound_op (unsigned short inst, inst_env_type *inst_env)
2577 /* It's invalid to have the PC as the index operand. */
2578 if (cris_get_operand2 (inst) == REG_PC)
2580 inst_env->invalid = 1;
2583 /* Check if we have a prefix. */
2584 if (inst_env->prefix_found)
2586 check_assign (inst, inst_env);
2588 /* Check if this is an autoincrement mode. */
2589 else if (cris_get_mode (inst) == AUTOINC_MODE)
2591 /* It's invalid to change the PC in a delay slot. */
2592 if (inst_env->slot_needed)
2594 inst_env->invalid = 1;
2597 process_autoincrement (cris_get_size (inst), inst, inst_env);
2599 inst_env->slot_needed = 0;
2600 inst_env->prefix_found = 0;
2601 inst_env->xflag_found = 0;
2602 inst_env->disable_interrupt = 0;
2605 /* Handles the 3-operand BOUND instruction. */
2608 three_operand_bound_op (unsigned short inst, inst_env_type *inst_env)
2610 /* It's an error if we haven't got a prefix. And it's also an error
2611 if the PC is the destination register. */
2612 if ((!inst_env->prefix_found) || (cris_get_operand1 (inst) == REG_PC))
2614 inst_env->invalid = 1;
2617 inst_env->slot_needed = 0;
2618 inst_env->prefix_found = 0;
2619 inst_env->xflag_found = 0;
2620 inst_env->disable_interrupt = 0;
2623 /* Clears the status flags in inst_env. */
2626 btst_nop_op (unsigned short inst, inst_env_type *inst_env)
2628 /* It's an error if we have got a prefix. */
2629 if (inst_env->prefix_found)
2631 inst_env->invalid = 1;
2635 inst_env->slot_needed = 0;
2636 inst_env->prefix_found = 0;
2637 inst_env->xflag_found = 0;
2638 inst_env->disable_interrupt = 0;
2641 /* Clears the status flags in inst_env. */
2644 clearf_di_op (unsigned short inst, inst_env_type *inst_env)
2646 /* It's an error if we have got a prefix. */
2647 if (inst_env->prefix_found)
2649 inst_env->invalid = 1;
2653 inst_env->slot_needed = 0;
2654 inst_env->prefix_found = 0;
2655 inst_env->xflag_found = 0;
2656 inst_env->disable_interrupt = 1;
2659 /* Handles the CLEAR instruction if it's in register mode. */
2662 reg_mode_clear_op (unsigned short inst, inst_env_type *inst_env)
2664 /* Check if the target is the PC. */
2665 if (cris_get_operand2 (inst) == REG_PC)
2667 /* The instruction will clear the instruction's size bits. */
2668 int clear_size = cris_get_clear_size (inst);
2669 if (clear_size == INST_BYTE_SIZE)
2671 inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFFFF00;
2673 if (clear_size == INST_WORD_SIZE)
2675 inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFF0000;
2677 if (clear_size == INST_DWORD_SIZE)
2679 inst_env->delay_slot_pc = 0x0;
2681 /* The jump will be delayed with one delay slot. So we need a delay
2683 inst_env->slot_needed = 1;
2684 inst_env->delay_slot_pc_active = 1;
2688 /* The PC will not change => no delay slot. */
2689 inst_env->slot_needed = 0;
2691 inst_env->prefix_found = 0;
2692 inst_env->xflag_found = 0;
2693 inst_env->disable_interrupt = 0;
2696 /* Handles the TEST instruction if it's in register mode. */
2699 reg_mode_test_op (unsigned short inst, inst_env_type *inst_env)
2701 /* It's an error if we have got a prefix. */
2702 if (inst_env->prefix_found)
2704 inst_env->invalid = 1;
2707 inst_env->slot_needed = 0;
2708 inst_env->prefix_found = 0;
2709 inst_env->xflag_found = 0;
2710 inst_env->disable_interrupt = 0;
2714 /* Handles the CLEAR and TEST instruction if the instruction isn't
2715 in register mode. */
2718 none_reg_mode_clear_test_op (unsigned short inst, inst_env_type *inst_env)
2720 /* Check if we are in a prefix mode. */
2721 if (inst_env->prefix_found)
2723 /* The only way the PC can change is if this instruction is in
2724 assign addressing mode. */
2725 check_assign (inst, inst_env);
2727 /* Indirect mode can't change the PC so just check if the mode is
2729 else if (cris_get_mode (inst) == AUTOINC_MODE)
2731 process_autoincrement (cris_get_size (inst), inst, inst_env);
2733 inst_env->slot_needed = 0;
2734 inst_env->prefix_found = 0;
2735 inst_env->xflag_found = 0;
2736 inst_env->disable_interrupt = 0;
2739 /* Checks that the PC isn't the destination register or the instructions has
2743 dstep_logshift_mstep_neg_not_op (unsigned short inst, inst_env_type *inst_env)
2745 /* It's invalid to have the PC as the destination. The instruction can't
2747 if ((cris_get_operand2 (inst) == REG_PC) || inst_env->prefix_found)
2749 inst_env->invalid = 1;
2753 inst_env->slot_needed = 0;
2754 inst_env->prefix_found = 0;
2755 inst_env->xflag_found = 0;
2756 inst_env->disable_interrupt = 0;
2759 /* Checks that the instruction doesn't have a prefix. */
2762 break_op (unsigned short inst, inst_env_type *inst_env)
2764 /* The instruction can't have a prefix. */
2765 if (inst_env->prefix_found)
2767 inst_env->invalid = 1;
2771 inst_env->slot_needed = 0;
2772 inst_env->prefix_found = 0;
2773 inst_env->xflag_found = 0;
2774 inst_env->disable_interrupt = 1;
2777 /* Checks that the PC isn't the destination register and that the instruction
2778 doesn't have a prefix. */
2781 scc_op (unsigned short inst, inst_env_type *inst_env)
2783 /* It's invalid to have the PC as the destination. The instruction can't
2785 if ((cris_get_operand2 (inst) == REG_PC) || inst_env->prefix_found)
2787 inst_env->invalid = 1;
2791 inst_env->slot_needed = 0;
2792 inst_env->prefix_found = 0;
2793 inst_env->xflag_found = 0;
2794 inst_env->disable_interrupt = 1;
2797 /* Handles the register mode JUMP instruction. */
2800 reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env)
2802 /* It's invalid to do a JUMP in a delay slot. The mode is register, so
2803 you can't have a prefix. */
2804 if ((inst_env->slot_needed) || (inst_env->prefix_found))
2806 inst_env->invalid = 1;
2810 /* Just change the PC. */
2811 inst_env->reg[REG_PC] = inst_env->reg[cris_get_operand1 (inst)];
2812 inst_env->slot_needed = 0;
2813 inst_env->prefix_found = 0;
2814 inst_env->xflag_found = 0;
2815 inst_env->disable_interrupt = 1;
2818 /* Handles the JUMP instruction for all modes except register. */
2821 none_reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env)
2823 unsigned long newpc;
2826 /* It's invalid to do a JUMP in a delay slot. */
2827 if (inst_env->slot_needed)
2829 inst_env->invalid = 1;
2833 /* Check if we have a prefix. */
2834 if (inst_env->prefix_found)
2836 check_assign (inst, inst_env);
2838 /* Get the new value for the PC. */
2840 read_memory_unsigned_integer ((CORE_ADDR) inst_env->prefix_value,
2841 4, inst_env->byte_order);
2845 /* Get the new value for the PC. */
2846 address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)];
2847 newpc = read_memory_unsigned_integer (address,
2848 4, inst_env->byte_order);
2850 /* Check if we should increment a register. */
2851 if (cris_get_mode (inst) == AUTOINC_MODE)
2853 inst_env->reg[cris_get_operand1 (inst)] += 4;
2856 inst_env->reg[REG_PC] = newpc;
2858 inst_env->slot_needed = 0;
2859 inst_env->prefix_found = 0;
2860 inst_env->xflag_found = 0;
2861 inst_env->disable_interrupt = 1;
2864 /* Handles moves to special registers (aka P-register) for all modes. */
2867 move_to_preg_op (struct gdbarch *gdbarch, unsigned short inst,
2868 inst_env_type *inst_env)
2870 if (inst_env->prefix_found)
2872 /* The instruction has a prefix that means we are only interested if
2873 the instruction is in assign mode. */
2874 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2876 /* The prefix handles the problem if we are in a delay slot. */
2877 if (cris_get_operand1 (inst) == REG_PC)
2879 /* Just take care of the assign. */
2880 check_assign (inst, inst_env);
2884 else if (cris_get_mode (inst) == AUTOINC_MODE)
2886 /* The instruction doesn't have a prefix, the only case left that we
2887 are interested in is the autoincrement mode. */
2888 if (cris_get_operand1 (inst) == REG_PC)
2890 /* If the PC is to be incremented it's invalid to be in a
2892 if (inst_env->slot_needed)
2894 inst_env->invalid = 1;
2898 /* The increment depends on the size of the special register. */
2899 if (cris_register_size (gdbarch, cris_get_operand2 (inst)) == 1)
2901 process_autoincrement (INST_BYTE_SIZE, inst, inst_env);
2903 else if (cris_register_size (gdbarch, cris_get_operand2 (inst)) == 2)
2905 process_autoincrement (INST_WORD_SIZE, inst, inst_env);
2909 process_autoincrement (INST_DWORD_SIZE, inst, inst_env);
2913 inst_env->slot_needed = 0;
2914 inst_env->prefix_found = 0;
2915 inst_env->xflag_found = 0;
2916 inst_env->disable_interrupt = 1;
2919 /* Handles moves from special registers (aka P-register) for all modes
2923 none_reg_mode_move_from_preg_op (struct gdbarch *gdbarch, unsigned short inst,
2924 inst_env_type *inst_env)
2926 if (inst_env->prefix_found)
2928 /* The instruction has a prefix that means we are only interested if
2929 the instruction is in assign mode. */
2930 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2932 /* The prefix handles the problem if we are in a delay slot. */
2933 if (cris_get_operand1 (inst) == REG_PC)
2935 /* Just take care of the assign. */
2936 check_assign (inst, inst_env);
2940 /* The instruction doesn't have a prefix, the only case left that we
2941 are interested in is the autoincrement mode. */
2942 else if (cris_get_mode (inst) == AUTOINC_MODE)
2944 if (cris_get_operand1 (inst) == REG_PC)
2946 /* If the PC is to be incremented it's invalid to be in a
2948 if (inst_env->slot_needed)
2950 inst_env->invalid = 1;
2954 /* The increment depends on the size of the special register. */
2955 if (cris_register_size (gdbarch, cris_get_operand2 (inst)) == 1)
2957 process_autoincrement (INST_BYTE_SIZE, inst, inst_env);
2959 else if (cris_register_size (gdbarch, cris_get_operand2 (inst)) == 2)
2961 process_autoincrement (INST_WORD_SIZE, inst, inst_env);
2965 process_autoincrement (INST_DWORD_SIZE, inst, inst_env);
2969 inst_env->slot_needed = 0;
2970 inst_env->prefix_found = 0;
2971 inst_env->xflag_found = 0;
2972 inst_env->disable_interrupt = 1;
2975 /* Handles moves from special registers (aka P-register) when the mode
2979 reg_mode_move_from_preg_op (unsigned short inst, inst_env_type *inst_env)
2981 /* Register mode move from special register can't have a prefix. */
2982 if (inst_env->prefix_found)
2984 inst_env->invalid = 1;
2988 if (cris_get_operand1 (inst) == REG_PC)
2990 /* It's invalid to change the PC in a delay slot. */
2991 if (inst_env->slot_needed)
2993 inst_env->invalid = 1;
2996 /* The destination is the PC, the jump will have a delay slot. */
2997 inst_env->delay_slot_pc = inst_env->preg[cris_get_operand2 (inst)];
2998 inst_env->slot_needed = 1;
2999 inst_env->delay_slot_pc_active = 1;
3003 /* If the destination isn't PC, there will be no jump. */
3004 inst_env->slot_needed = 0;
3006 inst_env->prefix_found = 0;
3007 inst_env->xflag_found = 0;
3008 inst_env->disable_interrupt = 1;
3011 /* Handles the MOVEM from memory to general register instruction. */
3014 move_mem_to_reg_movem_op (unsigned short inst, inst_env_type *inst_env)
3016 if (inst_env->prefix_found)
3018 /* The prefix handles the problem if we are in a delay slot. Is the
3019 MOVEM instruction going to change the PC? */
3020 if (cris_get_operand2 (inst) >= REG_PC)
3022 inst_env->reg[REG_PC] =
3023 read_memory_unsigned_integer (inst_env->prefix_value,
3024 4, inst_env->byte_order);
3026 /* The assign value is the value after the increment. Normally, the
3027 assign value is the value before the increment. */
3028 if ((cris_get_operand1 (inst) == REG_PC)
3029 && (cris_get_mode (inst) == PREFIX_ASSIGN_MODE))
3031 inst_env->reg[REG_PC] = inst_env->prefix_value;
3032 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
3037 /* Is the MOVEM instruction going to change the PC? */
3038 if (cris_get_operand2 (inst) == REG_PC)
3040 /* It's invalid to change the PC in a delay slot. */
3041 if (inst_env->slot_needed)
3043 inst_env->invalid = 1;
3046 inst_env->reg[REG_PC] =
3047 read_memory_unsigned_integer (inst_env->reg[cris_get_operand1 (inst)],
3048 4, inst_env->byte_order);
3050 /* The increment is not depending on the size, instead it's depending
3051 on the number of registers loaded from memory. */
3052 if ((cris_get_operand1 (inst) == REG_PC)
3053 && (cris_get_mode (inst) == AUTOINC_MODE))
3055 /* It's invalid to change the PC in a delay slot. */
3056 if (inst_env->slot_needed)
3058 inst_env->invalid = 1;
3061 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
3064 inst_env->slot_needed = 0;
3065 inst_env->prefix_found = 0;
3066 inst_env->xflag_found = 0;
3067 inst_env->disable_interrupt = 0;
3070 /* Handles the MOVEM to memory from general register instruction. */
3073 move_reg_to_mem_movem_op (unsigned short inst, inst_env_type *inst_env)
3075 if (inst_env->prefix_found)
3077 /* The assign value is the value after the increment. Normally, the
3078 assign value is the value before the increment. */
3079 if ((cris_get_operand1 (inst) == REG_PC)
3080 && (cris_get_mode (inst) == PREFIX_ASSIGN_MODE))
3082 /* The prefix handles the problem if we are in a delay slot. */
3083 inst_env->reg[REG_PC] = inst_env->prefix_value;
3084 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
3089 /* The increment is not depending on the size, instead it's depending
3090 on the number of registers loaded to memory. */
3091 if ((cris_get_operand1 (inst) == REG_PC)
3092 && (cris_get_mode (inst) == AUTOINC_MODE))
3094 /* It's invalid to change the PC in a delay slot. */
3095 if (inst_env->slot_needed)
3097 inst_env->invalid = 1;
3100 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
3103 inst_env->slot_needed = 0;
3104 inst_env->prefix_found = 0;
3105 inst_env->xflag_found = 0;
3106 inst_env->disable_interrupt = 0;
3109 /* Handles the intructions that's not yet implemented, by setting
3110 inst_env->invalid to true. */
3113 not_implemented_op (unsigned short inst, inst_env_type *inst_env)
3115 inst_env->invalid = 1;
3118 /* Handles the XOR instruction. */
3121 xor_op (unsigned short inst, inst_env_type *inst_env)
3123 /* XOR can't have a prefix. */
3124 if (inst_env->prefix_found)
3126 inst_env->invalid = 1;
3130 /* Check if the PC is the target. */
3131 if (cris_get_operand2 (inst) == REG_PC)
3133 /* It's invalid to change the PC in a delay slot. */
3134 if (inst_env->slot_needed)
3136 inst_env->invalid = 1;
3139 inst_env->reg[REG_PC] ^= inst_env->reg[cris_get_operand1 (inst)];
3141 inst_env->slot_needed = 0;
3142 inst_env->prefix_found = 0;
3143 inst_env->xflag_found = 0;
3144 inst_env->disable_interrupt = 0;
3147 /* Handles the MULS instruction. */
3150 muls_op (unsigned short inst, inst_env_type *inst_env)
3152 /* MULS/U can't have a prefix. */
3153 if (inst_env->prefix_found)
3155 inst_env->invalid = 1;
3159 /* Consider it invalid if the PC is the target. */
3160 if (cris_get_operand2 (inst) == REG_PC)
3162 inst_env->invalid = 1;
3165 inst_env->slot_needed = 0;
3166 inst_env->prefix_found = 0;
3167 inst_env->xflag_found = 0;
3168 inst_env->disable_interrupt = 0;
3171 /* Handles the MULU instruction. */
3174 mulu_op (unsigned short inst, inst_env_type *inst_env)
3176 /* MULS/U can't have a prefix. */
3177 if (inst_env->prefix_found)
3179 inst_env->invalid = 1;
3183 /* Consider it invalid if the PC is the target. */
3184 if (cris_get_operand2 (inst) == REG_PC)
3186 inst_env->invalid = 1;
3189 inst_env->slot_needed = 0;
3190 inst_env->prefix_found = 0;
3191 inst_env->xflag_found = 0;
3192 inst_env->disable_interrupt = 0;
3195 /* Calculate the result of the instruction for ADD, SUB, CMP AND, OR and MOVE.
3196 The MOVE instruction is the move from source to register. */
3199 add_sub_cmp_and_or_move_action (unsigned short inst, inst_env_type *inst_env,
3200 unsigned long source1, unsigned long source2)
3202 unsigned long pc_mask;
3203 unsigned long operation_mask;
3205 /* Find out how many bits the operation should apply to. */
3206 if (cris_get_size (inst) == INST_BYTE_SIZE)
3208 pc_mask = 0xFFFFFF00;
3209 operation_mask = 0xFF;
3211 else if (cris_get_size (inst) == INST_WORD_SIZE)
3213 pc_mask = 0xFFFF0000;
3214 operation_mask = 0xFFFF;
3216 else if (cris_get_size (inst) == INST_DWORD_SIZE)
3219 operation_mask = 0xFFFFFFFF;
3223 /* The size is out of range. */
3224 inst_env->invalid = 1;
3228 /* The instruction just works on uw_operation_mask bits. */
3229 source2 &= operation_mask;
3230 source1 &= operation_mask;
3232 /* Now calculate the result. The opcode's 3 first bits separates
3233 the different actions. */
3234 switch (cris_get_opcode (inst) & 7)
3244 case 2: /* subtract */
3248 case 3: /* compare */
3260 inst_env->invalid = 1;
3266 /* Make sure that the result doesn't contain more than the instruction
3268 source2 &= operation_mask;
3270 /* Calculate the new breakpoint address. */
3271 inst_env->reg[REG_PC] &= pc_mask;
3272 inst_env->reg[REG_PC] |= source1;
3276 /* Extends the value from either byte or word size to a dword. If the mode
3277 is zero extend then the value is extended with zero. If instead the mode
3278 is signed extend the sign bit of the value is taken into consideration. */
3280 static unsigned long
3281 do_sign_or_zero_extend (unsigned long value, unsigned short *inst)
3283 /* The size can be either byte or word, check which one it is.
3284 Don't check the highest bit, it's indicating if it's a zero
3286 if (cris_get_size (*inst) & INST_WORD_SIZE)
3291 /* Check if the instruction is signed extend. If so, check if value has
3293 if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_WORD_MASK))
3295 value |= SIGNED_WORD_EXTEND_MASK;
3303 /* Check if the instruction is signed extend. If so, check if value has
3305 if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_BYTE_MASK))
3307 value |= SIGNED_BYTE_EXTEND_MASK;
3310 /* The size should now be dword. */
3311 cris_set_size_to_dword (inst);
3315 /* Handles the register mode for the ADD, SUB, CMP, AND, OR and MOVE
3316 instruction. The MOVE instruction is the move from source to register. */
3319 reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst,
3320 inst_env_type *inst_env)
3322 unsigned long operand1;
3323 unsigned long operand2;
3325 /* It's invalid to have a prefix to the instruction. This is a register
3326 mode instruction and can't have a prefix. */
3327 if (inst_env->prefix_found)
3329 inst_env->invalid = 1;
3332 /* Check if the instruction has PC as its target. */
3333 if (cris_get_operand2 (inst) == REG_PC)
3335 if (inst_env->slot_needed)
3337 inst_env->invalid = 1;
3340 /* The instruction has the PC as its target register. */
3341 operand1 = inst_env->reg[cris_get_operand1 (inst)];
3342 operand2 = inst_env->reg[REG_PC];
3344 /* Check if it's a extend, signed or zero instruction. */
3345 if (cris_get_opcode (inst) < 4)
3347 operand1 = do_sign_or_zero_extend (operand1, &inst);
3349 /* Calculate the PC value after the instruction, i.e. where the
3350 breakpoint should be. The order of the udw_operands is vital. */
3351 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3353 inst_env->slot_needed = 0;
3354 inst_env->prefix_found = 0;
3355 inst_env->xflag_found = 0;
3356 inst_env->disable_interrupt = 0;
3359 /* Returns the data contained at address. The size of the data is derived from
3360 the size of the operation. If the instruction is a zero or signed
3361 extend instruction, the size field is changed in instruction. */
3363 static unsigned long
3364 get_data_from_address (unsigned short *inst, CORE_ADDR address,
3365 enum bfd_endian byte_order)
3367 int size = cris_get_size (*inst);
3368 unsigned long value;
3370 /* If it's an extend instruction we don't want the signed extend bit,
3371 because it influences the size. */
3372 if (cris_get_opcode (*inst) < 4)
3374 size &= ~SIGNED_EXTEND_BIT_MASK;
3376 /* Is there a need for checking the size? Size should contain the number of
3379 value = read_memory_unsigned_integer (address, size, byte_order);
3381 /* Check if it's an extend, signed or zero instruction. */
3382 if (cris_get_opcode (*inst) < 4)
3384 value = do_sign_or_zero_extend (value, inst);
3389 /* Handles the assign addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
3390 instructions. The MOVE instruction is the move from source to register. */
3393 handle_prefix_assign_mode_for_aritm_op (unsigned short inst,
3394 inst_env_type *inst_env)
3396 unsigned long operand2;
3397 unsigned long operand3;
3399 check_assign (inst, inst_env);
3400 if (cris_get_operand2 (inst) == REG_PC)
3402 operand2 = inst_env->reg[REG_PC];
3404 /* Get the value of the third operand. */
3405 operand3 = get_data_from_address (&inst, inst_env->prefix_value,
3406 inst_env->byte_order);
3408 /* Calculate the PC value after the instruction, i.e. where the
3409 breakpoint should be. The order of the udw_operands is vital. */
3410 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3412 inst_env->slot_needed = 0;
3413 inst_env->prefix_found = 0;
3414 inst_env->xflag_found = 0;
3415 inst_env->disable_interrupt = 0;
3418 /* Handles the three-operand addressing mode for the ADD, SUB, CMP, AND and
3419 OR instructions. Note that for this to work as expected, the calling
3420 function must have made sure that there is a prefix to this instruction. */
3423 three_operand_add_sub_cmp_and_or_op (unsigned short inst,
3424 inst_env_type *inst_env)
3426 unsigned long operand2;
3427 unsigned long operand3;
3429 if (cris_get_operand1 (inst) == REG_PC)
3431 /* The PC will be changed by the instruction. */
3432 operand2 = inst_env->reg[cris_get_operand2 (inst)];
3434 /* Get the value of the third operand. */
3435 operand3 = get_data_from_address (&inst, inst_env->prefix_value,
3436 inst_env->byte_order);
3438 /* Calculate the PC value after the instruction, i.e. where the
3439 breakpoint should be. */
3440 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3442 inst_env->slot_needed = 0;
3443 inst_env->prefix_found = 0;
3444 inst_env->xflag_found = 0;
3445 inst_env->disable_interrupt = 0;
3448 /* Handles the index addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
3449 instructions. The MOVE instruction is the move from source to register. */
3452 handle_prefix_index_mode_for_aritm_op (unsigned short inst,
3453 inst_env_type *inst_env)
3455 if (cris_get_operand1 (inst) != cris_get_operand2 (inst))
3457 /* If the instruction is MOVE it's invalid. If the instruction is ADD,
3458 SUB, AND or OR something weird is going on (if everything works these
3459 instructions should end up in the three operand version). */
3460 inst_env->invalid = 1;
3465 /* three_operand_add_sub_cmp_and_or does the same as we should do here
3467 three_operand_add_sub_cmp_and_or_op (inst, inst_env);
3469 inst_env->slot_needed = 0;
3470 inst_env->prefix_found = 0;
3471 inst_env->xflag_found = 0;
3472 inst_env->disable_interrupt = 0;
3475 /* Handles the autoincrement and indirect addresing mode for the ADD, SUB,
3476 CMP, AND OR and MOVE instruction. The MOVE instruction is the move from
3477 source to register. */
3480 handle_inc_and_index_mode_for_aritm_op (unsigned short inst,
3481 inst_env_type *inst_env)
3483 unsigned long operand1;
3484 unsigned long operand2;
3485 unsigned long operand3;
3488 /* The instruction is either an indirect or autoincrement addressing mode.
3489 Check if the destination register is the PC. */
3490 if (cris_get_operand2 (inst) == REG_PC)
3492 /* Must be done here, get_data_from_address may change the size
3494 size = cris_get_size (inst);
3495 operand2 = inst_env->reg[REG_PC];
3497 /* Get the value of the third operand, i.e. the indirect operand. */
3498 operand1 = inst_env->reg[cris_get_operand1 (inst)];
3499 operand3 = get_data_from_address (&inst, operand1, inst_env->byte_order);
3501 /* Calculate the PC value after the instruction, i.e. where the
3502 breakpoint should be. The order of the udw_operands is vital. */
3503 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3505 /* If this is an autoincrement addressing mode, check if the increment
3507 if ((cris_get_operand1 (inst) == REG_PC)
3508 && (cris_get_mode (inst) == AUTOINC_MODE))
3510 /* Get the size field. */
3511 size = cris_get_size (inst);
3513 /* If it's an extend instruction we don't want the signed extend bit,
3514 because it influences the size. */
3515 if (cris_get_opcode (inst) < 4)
3517 size &= ~SIGNED_EXTEND_BIT_MASK;
3519 process_autoincrement (size, inst, inst_env);
3521 inst_env->slot_needed = 0;
3522 inst_env->prefix_found = 0;
3523 inst_env->xflag_found = 0;
3524 inst_env->disable_interrupt = 0;
3527 /* Handles the two-operand addressing mode, all modes except register, for
3528 the ADD, SUB CMP, AND and OR instruction. */
3531 none_reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst,
3532 inst_env_type *inst_env)
3534 if (inst_env->prefix_found)
3536 if (cris_get_mode (inst) == PREFIX_INDEX_MODE)
3538 handle_prefix_index_mode_for_aritm_op (inst, inst_env);
3540 else if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
3542 handle_prefix_assign_mode_for_aritm_op (inst, inst_env);
3546 /* The mode is invalid for a prefixed base instruction. */
3547 inst_env->invalid = 1;
3553 handle_inc_and_index_mode_for_aritm_op (inst, inst_env);
3557 /* Handles the quick addressing mode for the ADD and SUB instruction. */
3560 quick_mode_add_sub_op (unsigned short inst, inst_env_type *inst_env)
3562 unsigned long operand1;
3563 unsigned long operand2;
3565 /* It's a bad idea to be in a prefix instruction now. This is a quick mode
3566 instruction and can't have a prefix. */
3567 if (inst_env->prefix_found)
3569 inst_env->invalid = 1;
3573 /* Check if the instruction has PC as its target. */
3574 if (cris_get_operand2 (inst) == REG_PC)
3576 if (inst_env->slot_needed)
3578 inst_env->invalid = 1;
3581 operand1 = cris_get_quick_value (inst);
3582 operand2 = inst_env->reg[REG_PC];
3584 /* The size should now be dword. */
3585 cris_set_size_to_dword (&inst);
3587 /* Calculate the PC value after the instruction, i.e. where the
3588 breakpoint should be. */
3589 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3591 inst_env->slot_needed = 0;
3592 inst_env->prefix_found = 0;
3593 inst_env->xflag_found = 0;
3594 inst_env->disable_interrupt = 0;
3597 /* Handles the quick addressing mode for the CMP, AND and OR instruction. */
3600 quick_mode_and_cmp_move_or_op (unsigned short inst, inst_env_type *inst_env)
3602 unsigned long operand1;
3603 unsigned long operand2;
3605 /* It's a bad idea to be in a prefix instruction now. This is a quick mode
3606 instruction and can't have a prefix. */
3607 if (inst_env->prefix_found)
3609 inst_env->invalid = 1;
3612 /* Check if the instruction has PC as its target. */
3613 if (cris_get_operand2 (inst) == REG_PC)
3615 if (inst_env->slot_needed)
3617 inst_env->invalid = 1;
3620 /* The instruction has the PC as its target register. */
3621 operand1 = cris_get_quick_value (inst);
3622 operand2 = inst_env->reg[REG_PC];
3624 /* The quick value is signed, so check if we must do a signed extend. */
3625 if (operand1 & SIGNED_QUICK_VALUE_MASK)
3628 operand1 |= SIGNED_QUICK_VALUE_EXTEND_MASK;
3630 /* The size should now be dword. */
3631 cris_set_size_to_dword (&inst);
3633 /* Calculate the PC value after the instruction, i.e. where the
3634 breakpoint should be. */
3635 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3637 inst_env->slot_needed = 0;
3638 inst_env->prefix_found = 0;
3639 inst_env->xflag_found = 0;
3640 inst_env->disable_interrupt = 0;
3643 /* Translate op_type to a function and call it. */
3646 cris_gdb_func (struct gdbarch *gdbarch, enum cris_op_type op_type,
3647 unsigned short inst, inst_env_type *inst_env)
3651 case cris_not_implemented_op:
3652 not_implemented_op (inst, inst_env);
3656 abs_op (inst, inst_env);
3660 addi_op (inst, inst_env);
3664 asr_op (inst, inst_env);
3668 asrq_op (inst, inst_env);
3671 case cris_ax_ei_setf_op:
3672 ax_ei_setf_op (inst, inst_env);
3675 case cris_bdap_prefix:
3676 bdap_prefix (inst, inst_env);
3679 case cris_biap_prefix:
3680 biap_prefix (inst, inst_env);
3684 break_op (inst, inst_env);
3687 case cris_btst_nop_op:
3688 btst_nop_op (inst, inst_env);
3691 case cris_clearf_di_op:
3692 clearf_di_op (inst, inst_env);
3695 case cris_dip_prefix:
3696 dip_prefix (inst, inst_env);
3699 case cris_dstep_logshift_mstep_neg_not_op:
3700 dstep_logshift_mstep_neg_not_op (inst, inst_env);
3703 case cris_eight_bit_offset_branch_op:
3704 eight_bit_offset_branch_op (inst, inst_env);
3707 case cris_move_mem_to_reg_movem_op:
3708 move_mem_to_reg_movem_op (inst, inst_env);
3711 case cris_move_reg_to_mem_movem_op:
3712 move_reg_to_mem_movem_op (inst, inst_env);
3715 case cris_move_to_preg_op:
3716 move_to_preg_op (gdbarch, inst, inst_env);
3720 muls_op (inst, inst_env);
3724 mulu_op (inst, inst_env);
3727 case cris_none_reg_mode_add_sub_cmp_and_or_move_op:
3728 none_reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env);
3731 case cris_none_reg_mode_clear_test_op:
3732 none_reg_mode_clear_test_op (inst, inst_env);
3735 case cris_none_reg_mode_jump_op:
3736 none_reg_mode_jump_op (inst, inst_env);
3739 case cris_none_reg_mode_move_from_preg_op:
3740 none_reg_mode_move_from_preg_op (gdbarch, inst, inst_env);
3743 case cris_quick_mode_add_sub_op:
3744 quick_mode_add_sub_op (inst, inst_env);
3747 case cris_quick_mode_and_cmp_move_or_op:
3748 quick_mode_and_cmp_move_or_op (inst, inst_env);
3751 case cris_quick_mode_bdap_prefix:
3752 quick_mode_bdap_prefix (inst, inst_env);
3755 case cris_reg_mode_add_sub_cmp_and_or_move_op:
3756 reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env);
3759 case cris_reg_mode_clear_op:
3760 reg_mode_clear_op (inst, inst_env);
3763 case cris_reg_mode_jump_op:
3764 reg_mode_jump_op (inst, inst_env);
3767 case cris_reg_mode_move_from_preg_op:
3768 reg_mode_move_from_preg_op (inst, inst_env);
3771 case cris_reg_mode_test_op:
3772 reg_mode_test_op (inst, inst_env);
3776 scc_op (inst, inst_env);
3779 case cris_sixteen_bit_offset_branch_op:
3780 sixteen_bit_offset_branch_op (inst, inst_env);
3783 case cris_three_operand_add_sub_cmp_and_or_op:
3784 three_operand_add_sub_cmp_and_or_op (inst, inst_env);
3787 case cris_three_operand_bound_op:
3788 three_operand_bound_op (inst, inst_env);
3791 case cris_two_operand_bound_op:
3792 two_operand_bound_op (inst, inst_env);
3796 xor_op (inst, inst_env);
3801 /* This wrapper is to avoid cris_get_assembler being called before
3802 exec_bfd has been set. */
3805 cris_delayed_get_disassembler (bfd_vma addr, struct disassemble_info *info)
3807 int (*print_insn) (bfd_vma addr, struct disassemble_info *info);
3808 /* FIXME: cagney/2003-08-27: It should be possible to select a CRIS
3809 disassembler, even when there is no BFD. Does something like
3810 "gdb; target remote; disassmeble *0x123" work? */
3811 gdb_assert (exec_bfd != NULL);
3812 print_insn = cris_get_disassembler (exec_bfd);
3813 gdb_assert (print_insn != NULL);
3814 return print_insn (addr, info);
3817 /* Originally from <asm/elf.h>. */
3818 typedef unsigned char cris_elf_greg_t[4];
3820 /* Same as user_regs_struct struct in <asm/user.h>. */
3821 #define CRISV10_ELF_NGREG 35
3822 typedef cris_elf_greg_t cris_elf_gregset_t[CRISV10_ELF_NGREG];
3824 #define CRISV32_ELF_NGREG 32
3825 typedef cris_elf_greg_t crisv32_elf_gregset_t[CRISV32_ELF_NGREG];
3827 /* Unpack a cris_elf_gregset_t into GDB's register cache. */
3830 cris_supply_gregset (struct regcache *regcache, cris_elf_gregset_t *gregsetp)
3832 struct gdbarch *gdbarch = get_regcache_arch (regcache);
3833 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3835 cris_elf_greg_t *regp = *gregsetp;
3836 static char zerobuf[4] = {0};
3838 /* The kernel dumps all 32 registers as unsigned longs, but supply_register
3839 knows about the actual size of each register so that's no problem. */
3840 for (i = 0; i < NUM_GENREGS + NUM_SPECREGS; i++)
3842 regcache_raw_supply (regcache, i, (char *)®p[i]);
3845 if (tdep->cris_version == 32)
3847 /* Needed to set pseudo-register PC for CRISv32. */
3848 /* FIXME: If ERP is in a delay slot at this point then the PC will
3849 be wrong. Issue a warning to alert the user. */
3850 regcache_raw_supply (regcache, gdbarch_pc_regnum (gdbarch),
3851 (char *)®p[ERP_REGNUM]);
3853 if (*(char *)®p[ERP_REGNUM] & 0x1)
3854 fprintf_unfiltered (gdb_stderr, "Warning: PC in delay slot\n");
3858 /* Use a local version of this function to get the correct types for
3859 regsets, until multi-arch core support is ready. */
3862 fetch_core_registers (struct regcache *regcache,
3863 char *core_reg_sect, unsigned core_reg_size,
3864 int which, CORE_ADDR reg_addr)
3866 cris_elf_gregset_t gregset;
3871 if (core_reg_size != sizeof (cris_elf_gregset_t)
3872 && core_reg_size != sizeof (crisv32_elf_gregset_t))
3874 warning (_("wrong size gregset struct in core file"));
3878 memcpy (&gregset, core_reg_sect, sizeof (gregset));
3879 cris_supply_gregset (regcache, &gregset);
3883 /* We've covered all the kinds of registers we know about here,
3884 so this must be something we wouldn't know what to do with
3885 anyway. Just ignore it. */
3890 static struct core_fns cris_elf_core_fns =
3892 bfd_target_elf_flavour, /* core_flavour */
3893 default_check_format, /* check_format */
3894 default_core_sniffer, /* core_sniffer */
3895 fetch_core_registers, /* core_read_registers */
3899 extern initialize_file_ftype _initialize_cris_tdep; /* -Wmissing-prototypes */
3902 _initialize_cris_tdep (void)
3904 static struct cmd_list_element *cris_set_cmdlist;
3905 static struct cmd_list_element *cris_show_cmdlist;
3907 struct cmd_list_element *c;
3909 gdbarch_register (bfd_arch_cris, cris_gdbarch_init, cris_dump_tdep);
3911 /* CRIS-specific user-commands. */
3912 add_setshow_zuinteger_cmd ("cris-version", class_support,
3913 &usr_cmd_cris_version,
3914 _("Set the current CRIS version."),
3915 _("Show the current CRIS version."),
3917 Set to 10 for CRISv10 or 32 for CRISv32 if autodetection fails.\n\
3920 NULL, /* FIXME: i18n: Current CRIS version
3922 &setlist, &showlist);
3924 add_setshow_enum_cmd ("cris-mode", class_support,
3925 cris_modes, &usr_cmd_cris_mode,
3926 _("Set the current CRIS mode."),
3927 _("Show the current CRIS mode."),
3929 Set to CRIS_MODE_GURU when debugging in guru mode.\n\
3930 Makes GDB use the NRP register instead of the ERP register in certain cases."),
3932 NULL, /* FIXME: i18n: Current CRIS version is %s. */
3933 &setlist, &showlist);
3935 add_setshow_boolean_cmd ("cris-dwarf2-cfi", class_support,
3936 &usr_cmd_cris_dwarf2_cfi,
3937 _("Set the usage of Dwarf-2 CFI for CRIS."),
3938 _("Show the usage of Dwarf-2 CFI for CRIS."),
3939 _("Set this to \"off\" if using gcc-cris < R59."),
3940 set_cris_dwarf2_cfi,
3941 NULL, /* FIXME: i18n: Usage of Dwarf-2 CFI
3943 &setlist, &showlist);
3945 deprecated_add_core_fns (&cris_elf_core_fns);
3948 /* Prints out all target specific values. */
3951 cris_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
3953 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3956 fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_version = %i\n",
3957 tdep->cris_version);
3958 fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_mode = %s\n",
3960 fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_dwarf2_cfi = %i\n",
3961 tdep->cris_dwarf2_cfi);
3966 set_cris_version (char *ignore_args, int from_tty,
3967 struct cmd_list_element *c)
3969 struct gdbarch_info info;
3971 usr_cmd_cris_version_valid = 1;
3973 /* Update the current architecture, if needed. */
3974 gdbarch_info_init (&info);
3975 if (!gdbarch_update_p (info))
3976 internal_error (__FILE__, __LINE__,
3977 _("cris_gdbarch_update: failed to update architecture."));
3981 set_cris_mode (char *ignore_args, int from_tty,
3982 struct cmd_list_element *c)
3984 struct gdbarch_info info;
3986 /* Update the current architecture, if needed. */
3987 gdbarch_info_init (&info);
3988 if (!gdbarch_update_p (info))
3989 internal_error (__FILE__, __LINE__,
3990 "cris_gdbarch_update: failed to update architecture.");
3994 set_cris_dwarf2_cfi (char *ignore_args, int from_tty,
3995 struct cmd_list_element *c)
3997 struct gdbarch_info info;
3999 /* Update the current architecture, if needed. */
4000 gdbarch_info_init (&info);
4001 if (!gdbarch_update_p (info))
4002 internal_error (__FILE__, __LINE__,
4003 _("cris_gdbarch_update: failed to update architecture."));
4006 static struct gdbarch *
4007 cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
4009 struct gdbarch *gdbarch;
4010 struct gdbarch_tdep *tdep;
4011 unsigned int cris_version;
4013 if (usr_cmd_cris_version_valid)
4015 /* Trust the user's CRIS version setting. */
4016 cris_version = usr_cmd_cris_version;
4018 else if (info.abfd && bfd_get_mach (info.abfd) == bfd_mach_cris_v32)
4024 /* Assume it's CRIS version 10. */
4028 /* Make the current settings visible to the user. */
4029 usr_cmd_cris_version = cris_version;
4031 /* Find a candidate among the list of pre-declared architectures. */
4032 for (arches = gdbarch_list_lookup_by_info (arches, &info);
4034 arches = gdbarch_list_lookup_by_info (arches->next, &info))
4036 if ((gdbarch_tdep (arches->gdbarch)->cris_version
4037 == usr_cmd_cris_version)
4038 && (gdbarch_tdep (arches->gdbarch)->cris_mode
4039 == usr_cmd_cris_mode)
4040 && (gdbarch_tdep (arches->gdbarch)->cris_dwarf2_cfi
4041 == usr_cmd_cris_dwarf2_cfi))
4042 return arches->gdbarch;
4045 /* No matching architecture was found. Create a new one. */
4046 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
4047 gdbarch = gdbarch_alloc (&info, tdep);
4049 tdep->cris_version = usr_cmd_cris_version;
4050 tdep->cris_mode = usr_cmd_cris_mode;
4051 tdep->cris_dwarf2_cfi = usr_cmd_cris_dwarf2_cfi;
4053 /* INIT shall ensure that the INFO.BYTE_ORDER is non-zero. */
4054 switch (info.byte_order)
4056 case BFD_ENDIAN_LITTLE:
4060 case BFD_ENDIAN_BIG:
4061 internal_error (__FILE__, __LINE__,
4062 _("cris_gdbarch_init: big endian byte order in info"));
4066 internal_error (__FILE__, __LINE__,
4067 _("cris_gdbarch_init: unknown byte order in info"));
4070 set_gdbarch_return_value (gdbarch, cris_return_value);
4072 set_gdbarch_sp_regnum (gdbarch, 14);
4074 /* Length of ordinary registers used in push_word and a few other
4075 places. register_size() is the real way to know how big a
4078 set_gdbarch_double_bit (gdbarch, 64);
4079 /* The default definition of a long double is 2 * gdbarch_double_bit,
4080 which means we have to set this explicitly. */
4081 set_gdbarch_long_double_bit (gdbarch, 64);
4083 /* The total amount of space needed to store (in an array called registers)
4084 GDB's copy of the machine's register state. Note: We can not use
4085 cris_register_size at this point, since it relies on gdbarch
4087 switch (tdep->cris_version)
4095 /* Old versions; not supported. */
4096 internal_error (__FILE__, __LINE__,
4097 _("cris_gdbarch_init: unsupported CRIS version"));
4102 /* CRIS v10 and v11, a.k.a. ETRAX 100LX. In addition to ETRAX 100,
4103 P7 (32 bits), and P15 (32 bits) have been implemented. */
4104 set_gdbarch_pc_regnum (gdbarch, 15);
4105 set_gdbarch_register_type (gdbarch, cris_register_type);
4106 /* There are 32 registers (some of which may not be implemented). */
4107 set_gdbarch_num_regs (gdbarch, 32);
4108 set_gdbarch_register_name (gdbarch, cris_register_name);
4109 set_gdbarch_cannot_store_register (gdbarch, cris_cannot_store_register);
4110 set_gdbarch_cannot_fetch_register (gdbarch, cris_cannot_fetch_register);
4112 set_gdbarch_software_single_step (gdbarch, cris_software_single_step);
4116 /* CRIS v32. General registers R0 - R15 (32 bits), special registers
4117 P0 - P15 (32 bits) except P0, P1, P3 (8 bits) and P4 (16 bits)
4118 and pseudo-register PC (32 bits). */
4119 set_gdbarch_pc_regnum (gdbarch, 32);
4120 set_gdbarch_register_type (gdbarch, crisv32_register_type);
4121 /* 32 registers + pseudo-register PC + 16 support registers. */
4122 set_gdbarch_num_regs (gdbarch, 32 + 1 + 16);
4123 set_gdbarch_register_name (gdbarch, crisv32_register_name);
4125 set_gdbarch_cannot_store_register
4126 (gdbarch, crisv32_cannot_store_register);
4127 set_gdbarch_cannot_fetch_register
4128 (gdbarch, crisv32_cannot_fetch_register);
4130 set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
4132 set_gdbarch_single_step_through_delay
4133 (gdbarch, crisv32_single_step_through_delay);
4138 internal_error (__FILE__, __LINE__,
4139 _("cris_gdbarch_init: unknown CRIS version"));
4142 /* Dummy frame functions (shared between CRISv10 and CRISv32 since they
4143 have the same ABI). */
4144 set_gdbarch_push_dummy_code (gdbarch, cris_push_dummy_code);
4145 set_gdbarch_push_dummy_call (gdbarch, cris_push_dummy_call);
4146 set_gdbarch_frame_align (gdbarch, cris_frame_align);
4147 set_gdbarch_skip_prologue (gdbarch, cris_skip_prologue);
4149 /* The stack grows downward. */
4150 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
4152 set_gdbarch_breakpoint_from_pc (gdbarch, cris_breakpoint_from_pc);
4154 set_gdbarch_unwind_pc (gdbarch, cris_unwind_pc);
4155 set_gdbarch_unwind_sp (gdbarch, cris_unwind_sp);
4156 set_gdbarch_dummy_id (gdbarch, cris_dummy_id);
4158 if (tdep->cris_dwarf2_cfi == 1)
4160 /* Hook in the Dwarf-2 frame sniffer. */
4161 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, cris_dwarf2_reg_to_regnum);
4162 dwarf2_frame_set_init_reg (gdbarch, cris_dwarf2_frame_init_reg);
4163 dwarf2_append_unwinders (gdbarch);
4166 if (tdep->cris_mode != cris_mode_guru)
4168 frame_unwind_append_unwinder (gdbarch, &cris_sigtramp_frame_unwind);
4171 frame_unwind_append_unwinder (gdbarch, &cris_frame_unwind);
4172 frame_base_set_default (gdbarch, &cris_frame_base);
4174 /* Hook in ABI-specific overrides, if they have been registered. */
4175 gdbarch_init_osabi (info, gdbarch);
4177 /* FIXME: cagney/2003-08-27: It should be possible to select a CRIS
4178 disassembler, even when there is no BFD. Does something like
4179 "gdb; target remote; disassmeble *0x123" work? */
4180 set_gdbarch_print_insn (gdbarch, cris_delayed_get_disassembler);