1 /* Target dependent code for CRIS, for GDB, the GNU debugger.
3 Copyright 2001, 2002, 2003, 2004, 2005 Free Software Foundation,
6 Contributed by Axis Communications AB.
7 Written by Hendrik Ruijter, Stefan Andersson, and Orjan Friberg.
9 This file is part of GDB.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #include "frame-unwind.h"
28 #include "frame-base.h"
29 #include "trad-frame.h"
30 #include "dwarf2-frame.h"
38 #include "opcode/cris.h"
39 #include "arch-utils.h"
41 #include "gdb_assert.h"
43 /* To get entry_point_address. */
46 #include "solib.h" /* Support for shared libraries. */
47 #include "solib-svr4.h" /* For struct link_map_offsets. */
48 #include "gdb_string.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 SP_REGNUM Contains address of top of stack.
77 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 /* Whether to make use of Dwarf-2 CFI (default on). */
156 static int usr_cmd_cris_dwarf2_cfi = 1;
158 /* CRIS architecture specific information. */
161 unsigned int cris_version;
165 /* Functions for accessing target dependent data. */
170 return (gdbarch_tdep (current_gdbarch)->cris_version);
173 /* Sigtramp identification code copied from i386-linux-tdep.c. */
175 #define SIGTRAMP_INSN0 0x9c5f /* movu.w 0xXX, $r9 */
176 #define SIGTRAMP_OFFSET0 0
177 #define SIGTRAMP_INSN1 0xe93d /* break 13 */
178 #define SIGTRAMP_OFFSET1 4
180 static const unsigned short sigtramp_code[] =
182 SIGTRAMP_INSN0, 0x0077, /* movu.w $0x77, $r9 */
183 SIGTRAMP_INSN1 /* break 13 */
186 #define SIGTRAMP_LEN (sizeof sigtramp_code)
188 /* Note: same length as normal sigtramp code. */
190 static const unsigned short rt_sigtramp_code[] =
192 SIGTRAMP_INSN0, 0x00ad, /* movu.w $0xad, $r9 */
193 SIGTRAMP_INSN1 /* break 13 */
196 /* If PC is in a sigtramp routine, return the address of the start of
197 the routine. Otherwise, return 0. */
200 cris_sigtramp_start (struct frame_info *next_frame)
202 CORE_ADDR pc = frame_pc_unwind (next_frame);
203 unsigned short buf[SIGTRAMP_LEN];
205 if (!safe_frame_unwind_memory (next_frame, pc, buf, SIGTRAMP_LEN))
208 if (buf[0] != SIGTRAMP_INSN0)
210 if (buf[0] != SIGTRAMP_INSN1)
213 pc -= SIGTRAMP_OFFSET1;
214 if (!safe_frame_unwind_memory (next_frame, pc, buf, SIGTRAMP_LEN))
218 if (memcmp (buf, sigtramp_code, SIGTRAMP_LEN) != 0)
224 /* If PC is in a RT sigtramp routine, return the address of the start of
225 the routine. Otherwise, return 0. */
228 cris_rt_sigtramp_start (struct frame_info *next_frame)
230 CORE_ADDR pc = frame_pc_unwind (next_frame);
231 unsigned short buf[SIGTRAMP_LEN];
233 if (!safe_frame_unwind_memory (next_frame, pc, buf, SIGTRAMP_LEN))
236 if (buf[0] != SIGTRAMP_INSN0)
238 if (buf[0] != SIGTRAMP_INSN1)
241 pc -= SIGTRAMP_OFFSET1;
242 if (!safe_frame_unwind_memory (next_frame, pc, buf, SIGTRAMP_LEN))
246 if (memcmp (buf, rt_sigtramp_code, SIGTRAMP_LEN) != 0)
252 /* Assuming NEXT_FRAME is a frame following a GNU/Linux sigtramp
253 routine, return the address of the associated sigcontext structure. */
256 cris_sigcontext_addr (struct frame_info *next_frame)
262 frame_unwind_register (next_frame, SP_REGNUM, buf);
263 sp = extract_unsigned_integer (buf, 4);
265 /* Look for normal sigtramp frame first. */
266 pc = cris_sigtramp_start (next_frame);
269 /* struct signal_frame (arch/cris/kernel/signal.c) contains
270 struct sigcontext as its first member, meaning the SP points to
275 pc = cris_rt_sigtramp_start (next_frame);
278 /* struct rt_signal_frame (arch/cris/kernel/signal.c) contains
279 a struct ucontext, which in turn contains a struct sigcontext.
281 4 + 4 + 128 to struct ucontext, then
282 4 + 4 + 12 to struct sigcontext. */
286 error (_("Couldn't recognize signal trampoline."));
290 struct cris_unwind_cache
292 /* The previous frame's inner most stack address. Used as this
293 frame ID's stack_addr. */
295 /* The frame's base, optionally used by the high-level debug info. */
298 /* How far the SP and r8 (FP) have been offset from the start of
299 the stack frame (as defined by the previous frame's stack
305 /* From old frame_extra_info struct. */
309 /* Table indicating the location of each and every register. */
310 struct trad_frame_saved_reg *saved_regs;
313 static struct cris_unwind_cache *
314 cris_sigtramp_frame_unwind_cache (struct frame_info *next_frame,
317 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
318 struct cris_unwind_cache *info;
326 return (*this_cache);
328 info = FRAME_OBSTACK_ZALLOC (struct cris_unwind_cache);
329 (*this_cache) = info;
330 info->saved_regs = trad_frame_alloc_saved_regs (next_frame);
332 /* Zero all fields. */
338 info->uses_frame = 0;
340 info->leaf_function = 0;
342 frame_unwind_register (next_frame, SP_REGNUM, buf);
343 info->base = extract_unsigned_integer (buf, 4);
345 addr = cris_sigcontext_addr (next_frame);
347 /* Layout of the sigcontext struct:
350 unsigned long oldmask;
354 if (tdep->cris_version == 10)
356 /* R0 to R13 are stored in reverse order at offset (2 * 4) in
358 for (i = 0; i <= 13; i++)
359 info->saved_regs[i].addr = addr + ((15 - i) * 4);
361 info->saved_regs[MOF_REGNUM].addr = addr + (16 * 4);
362 info->saved_regs[DCCR_REGNUM].addr = addr + (17 * 4);
363 info->saved_regs[SRP_REGNUM].addr = addr + (18 * 4);
364 /* Note: IRP is off by 2 at this point. There's no point in correcting
365 it though since that will mean that the backtrace will show a PC
366 different from what is shown when stopped. */
367 info->saved_regs[IRP_REGNUM].addr = addr + (19 * 4);
368 info->saved_regs[PC_REGNUM] = info->saved_regs[IRP_REGNUM];
369 info->saved_regs[SP_REGNUM].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[PC_REGNUM] = info->saved_regs[ERP_REGNUM];
398 info->saved_regs[SP_REGNUM].addr = addr + (25 * 4);
405 cris_sigtramp_frame_this_id (struct frame_info *next_frame, void **this_cache,
406 struct frame_id *this_id)
408 struct cris_unwind_cache *cache =
409 cris_sigtramp_frame_unwind_cache (next_frame, this_cache);
410 (*this_id) = frame_id_build (cache->base, frame_pc_unwind (next_frame));
413 /* Forward declaration. */
415 static void cris_frame_prev_register (struct frame_info *next_frame,
416 void **this_prologue_cache,
417 int regnum, int *optimizedp,
418 enum lval_type *lvalp, CORE_ADDR *addrp,
419 int *realnump, void *bufferp);
421 cris_sigtramp_frame_prev_register (struct frame_info *next_frame,
423 int regnum, int *optimizedp,
424 enum lval_type *lvalp, CORE_ADDR *addrp,
425 int *realnump, void *valuep)
427 /* Make sure we've initialized the cache. */
428 cris_sigtramp_frame_unwind_cache (next_frame, this_cache);
429 cris_frame_prev_register (next_frame, this_cache, regnum,
430 optimizedp, lvalp, addrp, realnump, valuep);
433 static const struct frame_unwind cris_sigtramp_frame_unwind =
436 cris_sigtramp_frame_this_id,
437 cris_sigtramp_frame_prev_register
440 static const struct frame_unwind *
441 cris_sigtramp_frame_sniffer (struct frame_info *next_frame)
443 if (cris_sigtramp_start (next_frame)
444 || cris_rt_sigtramp_start (next_frame))
445 return &cris_sigtramp_frame_unwind;
451 crisv32_single_step_through_delay (struct gdbarch *gdbarch,
452 struct frame_info *this_frame)
454 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
459 frame_unwind_register (this_frame, ERP_REGNUM, buf);
460 erp = extract_unsigned_integer (buf, 4);
464 /* In delay slot - check if there's a breakpoint at the preceding
466 if (breakpoint_here_p (erp & ~0x1))
472 /* Hardware watchpoint support. */
474 /* We support 6 hardware data watchpoints, but cannot trigger on execute
475 (any combination of read/write is fine). */
478 cris_can_use_hardware_watchpoint (int type, int count, int other)
480 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
482 /* No bookkeeping is done here; it is handled by the remote debug agent. */
484 if (tdep->cris_version != 32)
487 /* CRISv32: Six data watchpoints, one for instructions. */
488 return (((type == bp_read_watchpoint || type == bp_access_watchpoint
489 || type == bp_hardware_watchpoint) && count <= 6)
490 || (type == bp_hardware_breakpoint && count <= 1));
493 /* The CRISv32 hardware data watchpoints work by specifying ranges,
494 which have no alignment or length restrictions. */
497 cris_region_ok_for_watchpoint (CORE_ADDR addr, int len)
502 /* If the inferior has some watchpoint that triggered, return the
503 address associated with that watchpoint. Otherwise, return
507 cris_stopped_data_address (void)
510 eda = read_register (EDA_REGNUM);
514 /* The instruction environment needed to find single-step breakpoints. */
517 struct instruction_environment
519 unsigned long reg[NUM_GENREGS];
520 unsigned long preg[NUM_SPECREGS];
521 unsigned long branch_break_address;
522 unsigned long delay_slot_pc;
523 unsigned long prefix_value;
528 int delay_slot_pc_active;
530 int disable_interrupt;
533 /* Save old breakpoints in order to restore the state before a single_step.
534 At most, two breakpoints will have to be remembered. */
536 char binsn_quantum[BREAKPOINT_MAX];
537 static binsn_quantum break_mem[2];
538 static CORE_ADDR next_pc = 0;
539 static CORE_ADDR branch_target_address = 0;
540 static unsigned char branch_break_inserted = 0;
542 /* Machine-dependencies in CRIS for opcodes. */
544 /* Instruction sizes. */
545 enum cris_instruction_sizes
552 /* Addressing modes. */
553 enum cris_addressing_modes
560 /* Prefix addressing modes. */
561 enum cris_prefix_addressing_modes
563 PREFIX_INDEX_MODE = 2,
564 PREFIX_ASSIGN_MODE = 3,
566 /* Handle immediate byte offset addressing mode prefix format. */
567 PREFIX_OFFSET_MODE = 2
570 /* Masks for opcodes. */
571 enum cris_opcode_masks
573 BRANCH_SIGNED_SHORT_OFFSET_MASK = 0x1,
574 SIGNED_EXTEND_BIT_MASK = 0x2,
575 SIGNED_BYTE_MASK = 0x80,
576 SIGNED_BYTE_EXTEND_MASK = 0xFFFFFF00,
577 SIGNED_WORD_MASK = 0x8000,
578 SIGNED_WORD_EXTEND_MASK = 0xFFFF0000,
579 SIGNED_DWORD_MASK = 0x80000000,
580 SIGNED_QUICK_VALUE_MASK = 0x20,
581 SIGNED_QUICK_VALUE_EXTEND_MASK = 0xFFFFFFC0
584 /* Functions for opcodes. The general form of the ETRAX 16-bit instruction:
592 cris_get_operand2 (unsigned short insn)
594 return ((insn & 0xF000) >> 12);
598 cris_get_mode (unsigned short insn)
600 return ((insn & 0x0C00) >> 10);
604 cris_get_opcode (unsigned short insn)
606 return ((insn & 0x03C0) >> 6);
610 cris_get_size (unsigned short insn)
612 return ((insn & 0x0030) >> 4);
616 cris_get_operand1 (unsigned short insn)
618 return (insn & 0x000F);
621 /* Additional functions in order to handle opcodes. */
624 cris_get_quick_value (unsigned short insn)
626 return (insn & 0x003F);
630 cris_get_bdap_quick_offset (unsigned short insn)
632 return (insn & 0x00FF);
636 cris_get_branch_short_offset (unsigned short insn)
638 return (insn & 0x00FF);
642 cris_get_asr_shift_steps (unsigned long value)
644 return (value & 0x3F);
648 cris_get_clear_size (unsigned short insn)
650 return ((insn) & 0xC000);
654 cris_is_signed_extend_bit_on (unsigned short insn)
656 return (((insn) & 0x20) == 0x20);
660 cris_is_xflag_bit_on (unsigned short insn)
662 return (((insn) & 0x1000) == 0x1000);
666 cris_set_size_to_dword (unsigned short *insn)
673 cris_get_signed_offset (unsigned short insn)
675 return ((signed char) (insn & 0x00FF));
678 /* Calls an op function given the op-type, working on the insn and the
680 static void cris_gdb_func (enum cris_op_type, unsigned short, inst_env_type *);
682 static struct gdbarch *cris_gdbarch_init (struct gdbarch_info,
683 struct gdbarch_list *);
685 static void cris_dump_tdep (struct gdbarch *, struct ui_file *);
687 static void set_cris_version (char *ignore_args, int from_tty,
688 struct cmd_list_element *c);
690 static void set_cris_dwarf2_cfi (char *ignore_args, int from_tty,
691 struct cmd_list_element *c);
693 static CORE_ADDR cris_scan_prologue (CORE_ADDR pc,
694 struct frame_info *next_frame,
695 struct cris_unwind_cache *info);
697 static CORE_ADDR cris_unwind_pc (struct gdbarch *gdbarch,
698 struct frame_info *next_frame);
700 static CORE_ADDR cris_unwind_sp (struct gdbarch *gdbarch,
701 struct frame_info *next_frame);
703 /* When arguments must be pushed onto the stack, they go on in reverse
704 order. The below implements a FILO (stack) to do this.
705 Copied from d10v-tdep.c. */
710 struct stack_item *prev;
714 static struct stack_item *
715 push_stack_item (struct stack_item *prev, void *contents, int len)
717 struct stack_item *si;
718 si = xmalloc (sizeof (struct stack_item));
719 si->data = xmalloc (len);
722 memcpy (si->data, contents, len);
726 static struct stack_item *
727 pop_stack_item (struct stack_item *si)
729 struct stack_item *dead = si;
736 /* Put here the code to store, into fi->saved_regs, the addresses of
737 the saved registers of frame described by FRAME_INFO. This
738 includes special registers such as pc and fp saved in special ways
739 in the stack frame. sp is even more special: the address we return
740 for it IS the sp for the next frame. */
742 struct cris_unwind_cache *
743 cris_frame_unwind_cache (struct frame_info *next_frame,
744 void **this_prologue_cache)
747 struct cris_unwind_cache *info;
750 if ((*this_prologue_cache))
751 return (*this_prologue_cache);
753 info = FRAME_OBSTACK_ZALLOC (struct cris_unwind_cache);
754 (*this_prologue_cache) = info;
755 info->saved_regs = trad_frame_alloc_saved_regs (next_frame);
757 /* Zero all fields. */
763 info->uses_frame = 0;
765 info->leaf_function = 0;
767 /* Prologue analysis does the rest... */
768 cris_scan_prologue (frame_func_unwind (next_frame), next_frame, info);
773 /* Given a GDB frame, determine the address of the calling function's
774 frame. This will be used to create a new GDB frame struct. */
777 cris_frame_this_id (struct frame_info *next_frame,
778 void **this_prologue_cache,
779 struct frame_id *this_id)
781 struct cris_unwind_cache *info
782 = cris_frame_unwind_cache (next_frame, this_prologue_cache);
787 /* The FUNC is easy. */
788 func = frame_func_unwind (next_frame);
790 /* Hopefully the prologue analysis either correctly determined the
791 frame's base (which is the SP from the previous frame), or set
792 that base to "NULL". */
793 base = info->prev_sp;
797 id = frame_id_build (base, func);
803 cris_frame_prev_register (struct frame_info *next_frame,
804 void **this_prologue_cache,
805 int regnum, int *optimizedp,
806 enum lval_type *lvalp, CORE_ADDR *addrp,
807 int *realnump, void *bufferp)
809 struct cris_unwind_cache *info
810 = cris_frame_unwind_cache (next_frame, this_prologue_cache);
811 trad_frame_get_prev_register (next_frame, info->saved_regs, regnum,
812 optimizedp, lvalp, addrp, realnump, bufferp);
815 /* Assuming NEXT_FRAME->prev is a dummy, return the frame ID of that
816 dummy frame. The frame ID's base needs to match the TOS value
817 saved by save_dummy_frame_tos(), and the PC match the dummy frame's
820 static struct frame_id
821 cris_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame)
823 return frame_id_build (cris_unwind_sp (gdbarch, next_frame),
824 frame_pc_unwind (next_frame));
828 cris_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
830 /* Align to the size of an instruction (so that they can safely be
831 pushed onto the stack). */
836 cris_push_dummy_code (struct gdbarch *gdbarch,
837 CORE_ADDR sp, CORE_ADDR funaddr, int using_gcc,
838 struct value **args, int nargs,
839 struct type *value_type,
840 CORE_ADDR *real_pc, CORE_ADDR *bp_addr)
842 /* Allocate space sufficient for a breakpoint. */
844 /* Store the address of that breakpoint */
846 /* CRIS always starts the call at the callee's entry point. */
852 cris_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
853 struct regcache *regcache, CORE_ADDR bp_addr,
854 int nargs, struct value **args, CORE_ADDR sp,
855 int struct_return, CORE_ADDR struct_addr)
864 /* The function's arguments and memory allocated by gdb for the arguments to
865 point at reside in separate areas on the stack.
866 Both frame pointers grow toward higher addresses. */
870 struct stack_item *si = NULL;
872 /* Push the return address. */
873 regcache_cooked_write_unsigned (regcache, SRP_REGNUM, bp_addr);
875 /* Are we returning a value using a structure return or a normal value
876 return? struct_addr is the address of the reserved space for the return
877 structure to be written on the stack. */
880 regcache_cooked_write_unsigned (regcache, STR_REGNUM, struct_addr);
883 /* Now load as many as possible of the first arguments into registers,
884 and push the rest onto the stack. */
885 argreg = ARG1_REGNUM;
888 for (argnum = 0; argnum < nargs; argnum++)
895 len = TYPE_LENGTH (value_type (args[argnum]));
896 val = (char *) value_contents (args[argnum]);
898 /* How may registers worth of storage do we need for this argument? */
899 reg_demand = (len / 4) + (len % 4 != 0 ? 1 : 0);
901 if (len <= (2 * 4) && (argreg + reg_demand - 1 <= ARG4_REGNUM))
903 /* Data passed by value. Fits in available register(s). */
904 for (i = 0; i < reg_demand; i++)
906 regcache_cooked_write_unsigned (regcache, argreg,
907 *(unsigned long *) val);
912 else if (len <= (2 * 4) && argreg <= ARG4_REGNUM)
914 /* Data passed by value. Does not fit in available register(s).
915 Use the register(s) first, then the stack. */
916 for (i = 0; i < reg_demand; i++)
918 if (argreg <= ARG4_REGNUM)
920 regcache_cooked_write_unsigned (regcache, argreg,
921 *(unsigned long *) val);
927 /* Push item for later so that pushed arguments
928 come in the right order. */
929 si = push_stack_item (si, val, 4);
934 else if (len > (2 * 4))
937 internal_error (__FILE__, __LINE__, "We don't do this");
941 /* Data passed by value. No available registers. Put it on
943 si = push_stack_item (si, val, len);
949 /* fp_arg must be word-aligned (i.e., don't += len) to match
950 the function prologue. */
951 sp = (sp - si->len) & ~3;
952 write_memory (sp, si->data, si->len);
953 si = pop_stack_item (si);
956 /* Finally, update the SP register. */
957 regcache_cooked_write_unsigned (regcache, SP_REGNUM, sp);
962 static const struct frame_unwind cris_frame_unwind = {
965 cris_frame_prev_register
968 const struct frame_unwind *
969 cris_frame_sniffer (struct frame_info *next_frame)
971 return &cris_frame_unwind;
975 cris_frame_base_address (struct frame_info *next_frame, void **this_cache)
977 struct cris_unwind_cache *info
978 = cris_frame_unwind_cache (next_frame, this_cache);
982 static const struct frame_base cris_frame_base = {
984 cris_frame_base_address,
985 cris_frame_base_address,
986 cris_frame_base_address
989 /* Frames information. The definition of the struct frame_info is
993 enum frame_type type;
997 If the compilation option -fno-omit-frame-pointer is present the
998 variable frame will be set to the content of R8 which is the frame
1001 The variable pc contains the address where execution is performed
1002 in the present frame. The innermost frame contains the current content
1003 of the register PC. All other frames contain the content of the
1004 register PC in the next frame.
1006 The variable `type' indicates the frame's type: normal, SIGTRAMP
1007 (associated with a signal handler), dummy (associated with a dummy
1010 The variable return_pc contains the address where execution should be
1011 resumed when the present frame has finished, the return address.
1013 The variable leaf_function is 1 if the return address is in the register
1014 SRP, and 0 if it is on the stack.
1016 Prologue instructions C-code.
1017 The prologue may consist of (-fno-omit-frame-pointer)
1021 move.d sp,r8 move.d sp,r8
1023 movem rY,[sp] movem rY,[sp]
1024 move.S rZ,[r8-U] move.S rZ,[r8-U]
1026 where 1 is a non-terminal function, and 2 is a leaf-function.
1028 Note that this assumption is extremely brittle, and will break at the
1029 slightest change in GCC's prologue.
1031 If local variables are declared or register contents are saved on stack
1032 the subq-instruction will be present with X as the number of bytes
1033 needed for storage. The reshuffle with respect to r8 may be performed
1034 with any size S (b, w, d) and any of the general registers Z={0..13}.
1035 The offset U should be representable by a signed 8-bit value in all cases.
1036 Thus, the prefix word is assumed to be immediate byte offset mode followed
1037 by another word containing the instruction.
1046 Prologue instructions C++-code.
1047 Case 1) and 2) in the C-code may be followed by
1049 move.d r10,rS ; this
1053 move.S [r8+U],rZ ; P4
1055 if any of the call parameters are stored. The host expects these
1056 instructions to be executed in order to get the call parameters right. */
1058 /* Examine the prologue of a function. The variable ip is the address of
1059 the first instruction of the prologue. The variable limit is the address
1060 of the first instruction after the prologue. The variable fi contains the
1061 information in struct frame_info. The variable frameless_p controls whether
1062 the entire prologue is examined (0) or just enough instructions to
1063 determine that it is a prologue (1). */
1066 cris_scan_prologue (CORE_ADDR pc, struct frame_info *next_frame,
1067 struct cris_unwind_cache *info)
1069 /* Present instruction. */
1070 unsigned short insn;
1072 /* Next instruction, lookahead. */
1073 unsigned short insn_next;
1076 /* Is there a push fp? */
1079 /* Number of byte on stack used for local variables and movem. */
1082 /* Highest register number in a movem. */
1085 /* move.d r<source_register>,rS */
1086 short source_register;
1091 /* This frame is with respect to a leaf until a push srp is found. */
1094 info->leaf_function = 1;
1097 /* Assume nothing on stack. */
1101 /* If we were called without a next_frame, that means we were called
1102 from cris_skip_prologue which already tried to find the end of the
1103 prologue through the symbol information. 64 instructions past current
1104 pc is arbitrarily chosen, but at least it means we'll stop eventually. */
1105 limit = next_frame ? frame_pc_unwind (next_frame) : pc + 64;
1107 /* Find the prologue instructions. */
1108 while (pc > 0 && pc < limit)
1110 insn = read_memory_unsigned_integer (pc, 2);
1114 /* push <reg> 32 bit instruction */
1115 insn_next = read_memory_unsigned_integer (pc, 2);
1117 regno = cris_get_operand2 (insn_next);
1120 info->sp_offset += 4;
1122 /* This check, meant to recognize srp, used to be regno ==
1123 (SRP_REGNUM - NUM_GENREGS), but that covers r11 also. */
1124 if (insn_next == 0xBE7E)
1128 info->leaf_function = 0;
1131 else if (insn_next == 0x8FEE)
1136 info->r8_offset = info->sp_offset;
1140 else if (insn == 0x866E)
1145 info->uses_frame = 1;
1149 else if (cris_get_operand2 (insn) == SP_REGNUM
1150 && cris_get_mode (insn) == 0x0000
1151 && cris_get_opcode (insn) == 0x000A)
1156 info->sp_offset += cris_get_quick_value (insn);
1159 else if (cris_get_mode (insn) == 0x0002
1160 && cris_get_opcode (insn) == 0x000F
1161 && cris_get_size (insn) == 0x0003
1162 && cris_get_operand1 (insn) == SP_REGNUM)
1164 /* movem r<regsave>,[sp] */
1165 regsave = cris_get_operand2 (insn);
1167 else if (cris_get_operand2 (insn) == SP_REGNUM
1168 && ((insn & 0x0F00) >> 8) == 0x0001
1169 && (cris_get_signed_offset (insn) < 0))
1171 /* Immediate byte offset addressing prefix word with sp as base
1172 register. Used for CRIS v8 i.e. ETRAX 100 and newer if <val>
1173 is between 64 and 128.
1174 movem r<regsave>,[sp=sp-<val>] */
1177 info->sp_offset += -cris_get_signed_offset (insn);
1179 insn_next = read_memory_unsigned_integer (pc, 2);
1181 if (cris_get_mode (insn_next) == PREFIX_ASSIGN_MODE
1182 && cris_get_opcode (insn_next) == 0x000F
1183 && cris_get_size (insn_next) == 0x0003
1184 && cris_get_operand1 (insn_next) == SP_REGNUM)
1186 regsave = cris_get_operand2 (insn_next);
1190 /* The prologue ended before the limit was reached. */
1195 else if (cris_get_mode (insn) == 0x0001
1196 && cris_get_opcode (insn) == 0x0009
1197 && cris_get_size (insn) == 0x0002)
1199 /* move.d r<10..13>,r<0..15> */
1200 source_register = cris_get_operand1 (insn);
1202 /* FIXME? In the glibc solibs, the prologue might contain something
1203 like (this example taken from relocate_doit):
1205 sub.d 0xfffef426,$r0
1206 which isn't covered by the source_register check below. Question
1207 is whether to add a check for this combo, or make better use of
1208 the limit variable instead. */
1209 if (source_register < ARG1_REGNUM || source_register > ARG4_REGNUM)
1211 /* The prologue ended before the limit was reached. */
1216 else if (cris_get_operand2 (insn) == CRIS_FP_REGNUM
1217 /* The size is a fixed-size. */
1218 && ((insn & 0x0F00) >> 8) == 0x0001
1219 /* A negative offset. */
1220 && (cris_get_signed_offset (insn) < 0))
1222 /* move.S rZ,[r8-U] (?) */
1223 insn_next = read_memory_unsigned_integer (pc, 2);
1225 regno = cris_get_operand2 (insn_next);
1226 if ((regno >= 0 && regno < SP_REGNUM)
1227 && cris_get_mode (insn_next) == PREFIX_OFFSET_MODE
1228 && cris_get_opcode (insn_next) == 0x000F)
1230 /* move.S rZ,[r8-U] */
1235 /* The prologue ended before the limit was reached. */
1240 else if (cris_get_operand2 (insn) == CRIS_FP_REGNUM
1241 /* The size is a fixed-size. */
1242 && ((insn & 0x0F00) >> 8) == 0x0001
1243 /* A positive offset. */
1244 && (cris_get_signed_offset (insn) > 0))
1246 /* move.S [r8+U],rZ (?) */
1247 insn_next = read_memory_unsigned_integer (pc, 2);
1249 regno = cris_get_operand2 (insn_next);
1250 if ((regno >= 0 && regno < SP_REGNUM)
1251 && cris_get_mode (insn_next) == PREFIX_OFFSET_MODE
1252 && cris_get_opcode (insn_next) == 0x0009
1253 && cris_get_operand1 (insn_next) == regno)
1255 /* move.S [r8+U],rZ */
1260 /* The prologue ended before the limit was reached. */
1267 /* The prologue ended before the limit was reached. */
1273 /* We only want to know the end of the prologue when next_frame and info
1274 are NULL (called from cris_skip_prologue i.e.). */
1275 if (next_frame == NULL && info == NULL)
1280 info->size = info->sp_offset;
1282 /* Compute the previous frame's stack pointer (which is also the
1283 frame's ID's stack address), and this frame's base pointer. */
1284 if (info->uses_frame)
1287 /* The SP was moved to the FP. This indicates that a new frame
1288 was created. Get THIS frame's FP value by unwinding it from
1290 frame_unwind_unsigned_register (next_frame, CRIS_FP_REGNUM,
1292 info->base = this_base;
1293 info->saved_regs[CRIS_FP_REGNUM].addr = info->base;
1295 /* The FP points at the last saved register. Adjust the FP back
1296 to before the first saved register giving the SP. */
1297 info->prev_sp = info->base + info->r8_offset;
1302 /* Assume that the FP is this frame's SP but with that pushed
1303 stack space added back. */
1304 frame_unwind_unsigned_register (next_frame, SP_REGNUM, &this_base);
1305 info->base = this_base;
1306 info->prev_sp = info->base + info->size;
1309 /* Calculate the addresses for the saved registers on the stack. */
1310 /* FIXME: The address calculation should really be done on the fly while
1311 we're analyzing the prologue (we only hold one regsave value as it is
1313 val = info->sp_offset;
1315 for (regno = regsave; regno >= 0; regno--)
1317 info->saved_regs[regno].addr = info->base + info->r8_offset - val;
1321 /* The previous frame's SP needed to be computed. Save the computed
1323 trad_frame_set_value (info->saved_regs, SP_REGNUM, info->prev_sp);
1325 if (!info->leaf_function)
1327 /* SRP saved on the stack. But where? */
1328 if (info->r8_offset == 0)
1330 /* R8 not pushed yet. */
1331 info->saved_regs[SRP_REGNUM].addr = info->base;
1335 /* R8 pushed, but SP may or may not be moved to R8 yet. */
1336 info->saved_regs[SRP_REGNUM].addr = info->base + 4;
1340 /* The PC is found in SRP (the actual register or located on the stack). */
1341 info->saved_regs[PC_REGNUM] = info->saved_regs[SRP_REGNUM];
1346 /* Advance pc beyond any function entry prologue instructions at pc
1347 to reach some "real" code. */
1349 /* Given a PC value corresponding to the start of a function, return the PC
1350 of the first instruction after the function prologue. */
1353 cris_skip_prologue (CORE_ADDR pc)
1355 CORE_ADDR func_addr, func_end;
1356 struct symtab_and_line sal;
1357 CORE_ADDR pc_after_prologue;
1359 /* If we have line debugging information, then the end of the prologue
1360 should the first assembly instruction of the first source line. */
1361 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
1363 sal = find_pc_line (func_addr, 0);
1364 if (sal.end > 0 && sal.end < func_end)
1368 pc_after_prologue = cris_scan_prologue (pc, NULL, NULL);
1369 return pc_after_prologue;
1373 cris_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
1376 frame_unwind_unsigned_register (next_frame, PC_REGNUM, &pc);
1381 cris_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
1384 frame_unwind_unsigned_register (next_frame, SP_REGNUM, &sp);
1388 /* Use the program counter to determine the contents and size of a breakpoint
1389 instruction. It returns a pointer to a string of bytes that encode a
1390 breakpoint instruction, stores the length of the string to *lenptr, and
1391 adjusts pcptr (if necessary) to point to the actual memory location where
1392 the breakpoint should be inserted. */
1394 static const unsigned char *
1395 cris_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
1397 static unsigned char break_insn[] = {0x38, 0xe9};
1403 /* Returns 1 if spec_reg is applicable to the current gdbarch's CRIS version,
1407 cris_spec_reg_applicable (struct cris_spec_reg spec_reg)
1409 int version = cris_version ();
1411 switch (spec_reg.applicable_version)
1413 case cris_ver_version_all:
1415 case cris_ver_warning:
1416 /* Indeterminate/obsolete. */
1419 return (version >= 0 && version <= 3);
1421 return (version >= 3);
1423 return (version == 8 || version == 9);
1425 return (version >= 8);
1426 case cris_ver_v0_10:
1427 return (version >= 0 && version <= 10);
1428 case cris_ver_v3_10:
1429 return (version >= 3 && version <= 10);
1430 case cris_ver_v8_10:
1431 return (version >= 8 && version <= 10);
1433 return (version == 10);
1435 return (version >= 10);
1437 return (version >= 32);
1439 /* Invalid cris version. */
1444 /* Returns the register size in unit byte. Returns 0 for an unimplemented
1445 register, -1 for an invalid register. */
1448 cris_register_size (int regno)
1450 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
1454 if (regno >= 0 && regno < NUM_GENREGS)
1456 /* General registers (R0 - R15) are 32 bits. */
1459 else if (regno >= NUM_GENREGS && regno < (NUM_GENREGS + NUM_SPECREGS))
1461 /* Special register (R16 - R31). cris_spec_regs is zero-based.
1462 Adjust regno accordingly. */
1463 spec_regno = regno - NUM_GENREGS;
1465 for (i = 0; cris_spec_regs[i].name != NULL; i++)
1467 if (cris_spec_regs[i].number == spec_regno
1468 && cris_spec_reg_applicable (cris_spec_regs[i]))
1469 /* Go with the first applicable register. */
1470 return cris_spec_regs[i].reg_size;
1472 /* Special register not applicable to this CRIS version. */
1475 else if (regno >= PC_REGNUM && regno < NUM_REGS)
1477 /* This will apply to CRISv32 only where there are additional registers
1478 after the special registers (pseudo PC and support registers). */
1486 /* Nonzero if regno should not be fetched from the target. This is the case
1487 for unimplemented (size 0) and non-existant registers. */
1490 cris_cannot_fetch_register (int regno)
1492 return ((regno < 0 || regno >= NUM_REGS)
1493 || (cris_register_size (regno) == 0));
1496 /* Nonzero if regno should not be written to the target, for various
1500 cris_cannot_store_register (int regno)
1502 /* There are three kinds of registers we refuse to write to.
1503 1. Those that not implemented.
1504 2. Those that are read-only (depends on the processor mode).
1505 3. Those registers to which a write has no effect.
1508 if (regno < 0 || regno >= NUM_REGS || cris_register_size (regno) == 0)
1509 /* Not implemented. */
1512 else if (regno == VR_REGNUM)
1516 else if (regno == P0_REGNUM || regno == P4_REGNUM || regno == P8_REGNUM)
1517 /* Writing has no effect. */
1520 /* IBR, BAR, BRP and IRP are read-only in user mode. Let the debug
1521 agent decide whether they are writable. */
1526 /* Nonzero if regno should not be fetched from the target. This is the case
1527 for unimplemented (size 0) and non-existant registers. */
1530 crisv32_cannot_fetch_register (int regno)
1532 return ((regno < 0 || regno >= NUM_REGS)
1533 || (cris_register_size (regno) == 0));
1536 /* Nonzero if regno should not be written to the target, for various
1540 crisv32_cannot_store_register (int regno)
1542 /* There are three kinds of registers we refuse to write to.
1543 1. Those that not implemented.
1544 2. Those that are read-only (depends on the processor mode).
1545 3. Those registers to which a write has no effect.
1548 if (regno < 0 || regno >= NUM_REGS || cris_register_size (regno) == 0)
1549 /* Not implemented. */
1552 else if (regno == VR_REGNUM)
1556 else if (regno == BZ_REGNUM || regno == WZ_REGNUM || regno == DZ_REGNUM)
1557 /* Writing has no effect. */
1560 /* Many special registers are read-only in user mode. Let the debug
1561 agent decide whether they are writable. */
1566 /* Return the GDB type (defined in gdbtypes.c) for the "standard" data type
1567 of data in register regno. */
1569 static struct type *
1570 cris_register_type (struct gdbarch *gdbarch, int regno)
1572 if (regno == PC_REGNUM)
1573 return builtin_type_void_func_ptr;
1574 else if (regno == SP_REGNUM || regno == CRIS_FP_REGNUM)
1575 return builtin_type_void_data_ptr;
1576 else if ((regno >= 0 && regno < SP_REGNUM)
1577 || (regno >= MOF_REGNUM && regno <= USP_REGNUM))
1578 /* Note: R8 taken care of previous clause. */
1579 return builtin_type_uint32;
1580 else if (regno >= P4_REGNUM && regno <= CCR_REGNUM)
1581 return builtin_type_uint16;
1582 else if (regno >= P0_REGNUM && regno <= VR_REGNUM)
1583 return builtin_type_uint8;
1585 /* Invalid (unimplemented) register. */
1586 return builtin_type_int0;
1589 static struct type *
1590 crisv32_register_type (struct gdbarch *gdbarch, int regno)
1592 if (regno == PC_REGNUM)
1593 return builtin_type_void_func_ptr;
1594 else if (regno == SP_REGNUM || regno == CRIS_FP_REGNUM)
1595 return builtin_type_void_data_ptr;
1596 else if ((regno >= 0 && regno <= ACR_REGNUM)
1597 || (regno >= EXS_REGNUM && regno <= SPC_REGNUM)
1598 || (regno == PID_REGNUM)
1599 || (regno >= S0_REGNUM && regno <= S15_REGNUM))
1600 /* Note: R8 and SP taken care of by previous clause. */
1601 return builtin_type_uint32;
1602 else if (regno == WZ_REGNUM)
1603 return builtin_type_uint16;
1604 else if (regno == BZ_REGNUM || regno == VR_REGNUM || regno == SRS_REGNUM)
1605 return builtin_type_uint8;
1608 /* Invalid (unimplemented) register. Should not happen as there are
1609 no unimplemented CRISv32 registers. */
1610 warning (_("crisv32_register_type: unknown regno %d"), regno);
1611 return builtin_type_int0;
1615 /* Stores a function return value of type type, where valbuf is the address
1616 of the value to be stored. */
1618 /* In the CRIS ABI, R10 and R11 are used to store return values. */
1621 cris_store_return_value (struct type *type, struct regcache *regcache,
1625 int len = TYPE_LENGTH (type);
1629 /* Put the return value in R10. */
1630 val = extract_unsigned_integer (valbuf, len);
1631 regcache_cooked_write_unsigned (regcache, ARG1_REGNUM, val);
1635 /* Put the return value in R10 and R11. */
1636 val = extract_unsigned_integer (valbuf, 4);
1637 regcache_cooked_write_unsigned (regcache, ARG1_REGNUM, val);
1638 val = extract_unsigned_integer ((char *)valbuf + 4, len - 4);
1639 regcache_cooked_write_unsigned (regcache, ARG2_REGNUM, val);
1642 error (_("cris_store_return_value: type length too large."));
1645 /* Return the name of register regno as a string. Return NULL for an invalid or
1646 unimplemented register. */
1649 cris_special_register_name (int regno)
1654 /* Special register (R16 - R31). cris_spec_regs is zero-based.
1655 Adjust regno accordingly. */
1656 spec_regno = regno - NUM_GENREGS;
1658 /* Assume nothing about the layout of the cris_spec_regs struct
1660 for (i = 0; cris_spec_regs[i].name != NULL; i++)
1662 if (cris_spec_regs[i].number == spec_regno
1663 && cris_spec_reg_applicable (cris_spec_regs[i]))
1664 /* Go with the first applicable register. */
1665 return cris_spec_regs[i].name;
1667 /* Special register not applicable to this CRIS version. */
1672 cris_register_name (int regno)
1674 static char *cris_genreg_names[] =
1675 { "r0", "r1", "r2", "r3", \
1676 "r4", "r5", "r6", "r7", \
1677 "r8", "r9", "r10", "r11", \
1678 "r12", "r13", "sp", "pc" };
1680 if (regno >= 0 && regno < NUM_GENREGS)
1682 /* General register. */
1683 return cris_genreg_names[regno];
1685 else if (regno >= NUM_GENREGS && regno < NUM_REGS)
1687 return cris_special_register_name (regno);
1691 /* Invalid register. */
1697 crisv32_register_name (int regno)
1699 static char *crisv32_genreg_names[] =
1700 { "r0", "r1", "r2", "r3", \
1701 "r4", "r5", "r6", "r7", \
1702 "r8", "r9", "r10", "r11", \
1703 "r12", "r13", "sp", "acr"
1706 static char *crisv32_sreg_names[] =
1707 { "s0", "s1", "s2", "s3", \
1708 "s4", "s5", "s6", "s7", \
1709 "s8", "s9", "s10", "s11", \
1710 "s12", "s13", "s14", "s15"
1713 if (regno >= 0 && regno < NUM_GENREGS)
1715 /* General register. */
1716 return crisv32_genreg_names[regno];
1718 else if (regno >= NUM_GENREGS && regno < (NUM_GENREGS + NUM_SPECREGS))
1720 return cris_special_register_name (regno);
1722 else if (regno == PC_REGNUM)
1726 else if (regno >= S0_REGNUM && regno <= S15_REGNUM)
1728 return crisv32_sreg_names[regno - S0_REGNUM];
1732 /* Invalid register. */
1737 /* Convert DWARF register number REG to the appropriate register
1738 number used by GDB. */
1741 cris_dwarf2_reg_to_regnum (int reg)
1743 /* We need to re-map a couple of registers (SRP is 16 in Dwarf-2 register
1744 numbering, MOF is 18).
1745 Adapted from gcc/config/cris/cris.h. */
1746 static int cris_dwarf_regmap[] = {
1758 if (reg >= 0 && reg < ARRAY_SIZE (cris_dwarf_regmap))
1759 regnum = cris_dwarf_regmap[reg];
1762 warning (_("Unmapped DWARF Register #%d encountered."), reg);
1767 /* DWARF-2 frame support. */
1770 cris_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
1771 struct dwarf2_frame_state_reg *reg)
1773 /* The return address column. */
1774 if (regnum == PC_REGNUM)
1775 reg->how = DWARF2_FRAME_REG_RA;
1777 /* The call frame address. */
1778 else if (regnum == SP_REGNUM)
1779 reg->how = DWARF2_FRAME_REG_CFA;
1782 /* Extract from an array regbuf containing the raw register state a function
1783 return value of type type, and copy that, in virtual format, into
1786 /* In the CRIS ABI, R10 and R11 are used to store return values. */
1789 cris_extract_return_value (struct type *type, struct regcache *regcache,
1793 int len = TYPE_LENGTH (type);
1797 /* Get the return value from R10. */
1798 regcache_cooked_read_unsigned (regcache, ARG1_REGNUM, &val);
1799 store_unsigned_integer (valbuf, len, val);
1803 /* Get the return value from R10 and R11. */
1804 regcache_cooked_read_unsigned (regcache, ARG1_REGNUM, &val);
1805 store_unsigned_integer (valbuf, 4, val);
1806 regcache_cooked_read_unsigned (regcache, ARG2_REGNUM, &val);
1807 store_unsigned_integer ((char *)valbuf + 4, len - 4, val);
1810 error (_("cris_extract_return_value: type length too large"));
1813 /* Handle the CRIS return value convention. */
1815 static enum return_value_convention
1816 cris_return_value (struct gdbarch *gdbarch, struct type *type,
1817 struct regcache *regcache, void *readbuf,
1818 const void *writebuf)
1820 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
1821 || TYPE_CODE (type) == TYPE_CODE_UNION
1822 || TYPE_LENGTH (type) > 8)
1823 /* Structs, unions, and anything larger than 8 bytes (2 registers)
1824 goes on the stack. */
1825 return RETURN_VALUE_STRUCT_CONVENTION;
1828 cris_extract_return_value (type, regcache, readbuf);
1830 cris_store_return_value (type, regcache, writebuf);
1832 return RETURN_VALUE_REGISTER_CONVENTION;
1835 /* Returns 1 if the given type will be passed by pointer rather than
1838 /* In the CRIS ABI, arguments shorter than or equal to 64 bits are passed
1842 cris_reg_struct_has_addr (int gcc_p, struct type *type)
1844 return (TYPE_LENGTH (type) > 8);
1847 /* Calculates a value that measures how good inst_args constraints an
1848 instruction. It stems from cris_constraint, found in cris-dis.c. */
1851 constraint (unsigned int insn, const signed char *inst_args,
1852 inst_env_type *inst_env)
1857 const char *s = inst_args;
1863 if ((insn & 0x30) == 0x30)
1868 /* A prefix operand. */
1869 if (inst_env->prefix_found)
1875 /* A "push" prefix. (This check was REMOVED by san 970921.) Check for
1876 valid "push" size. In case of special register, it may be != 4. */
1877 if (inst_env->prefix_found)
1883 retval = (((insn >> 0xC) & 0xF) == (insn & 0xF));
1891 tmp = (insn >> 0xC) & 0xF;
1893 for (i = 0; cris_spec_regs[i].name != NULL; i++)
1895 /* Since we match four bits, we will give a value of
1896 4 - 1 = 3 in a match. If there is a corresponding
1897 exact match of a special register in another pattern, it
1898 will get a value of 4, which will be higher. This should
1899 be correct in that an exact pattern would match better that
1901 Note that there is a reason for not returning zero; the
1902 pattern for "clear" is partly matched in the bit-pattern
1903 (the two lower bits must be zero), while the bit-pattern
1904 for a move from a special register is matched in the
1905 register constraint.
1906 This also means we will will have a race condition if
1907 there is a partly match in three bits in the bit pattern. */
1908 if (tmp == cris_spec_regs[i].number)
1915 if (cris_spec_regs[i].name == NULL)
1922 /* Returns the number of bits set in the variable value. */
1925 number_of_bits (unsigned int value)
1927 int number_of_bits = 0;
1931 number_of_bits += 1;
1932 value &= (value - 1);
1934 return number_of_bits;
1937 /* Finds the address that should contain the single step breakpoint(s).
1938 It stems from code in cris-dis.c. */
1941 find_cris_op (unsigned short insn, inst_env_type *inst_env)
1944 int max_level_of_match = -1;
1945 int max_matched = -1;
1948 for (i = 0; cris_opcodes[i].name != NULL; i++)
1950 if (((cris_opcodes[i].match & insn) == cris_opcodes[i].match)
1951 && ((cris_opcodes[i].lose & insn) == 0)
1952 /* Only CRISv10 instructions, please. */
1953 && (cris_opcodes[i].applicable_version != cris_ver_v32p))
1955 level_of_match = constraint (insn, cris_opcodes[i].args, inst_env);
1956 if (level_of_match >= 0)
1959 number_of_bits (cris_opcodes[i].match | cris_opcodes[i].lose);
1960 if (level_of_match > max_level_of_match)
1963 max_level_of_match = level_of_match;
1964 if (level_of_match == 16)
1966 /* All bits matched, cannot find better. */
1976 /* Attempts to find single-step breakpoints. Returns -1 on failure which is
1977 actually an internal error. */
1980 find_step_target (inst_env_type *inst_env)
1984 unsigned short insn;
1986 /* Create a local register image and set the initial state. */
1987 for (i = 0; i < NUM_GENREGS; i++)
1989 inst_env->reg[i] = (unsigned long) read_register (i);
1991 offset = NUM_GENREGS;
1992 for (i = 0; i < NUM_SPECREGS; i++)
1994 inst_env->preg[i] = (unsigned long) read_register (offset + i);
1996 inst_env->branch_found = 0;
1997 inst_env->slot_needed = 0;
1998 inst_env->delay_slot_pc_active = 0;
1999 inst_env->prefix_found = 0;
2000 inst_env->invalid = 0;
2001 inst_env->xflag_found = 0;
2002 inst_env->disable_interrupt = 0;
2004 /* Look for a step target. */
2007 /* Read an instruction from the client. */
2008 insn = read_memory_unsigned_integer (inst_env->reg[PC_REGNUM], 2);
2010 /* If the instruction is not in a delay slot the new content of the
2011 PC is [PC] + 2. If the instruction is in a delay slot it is not
2012 that simple. Since a instruction in a delay slot cannot change
2013 the content of the PC, it does not matter what value PC will have.
2014 Just make sure it is a valid instruction. */
2015 if (!inst_env->delay_slot_pc_active)
2017 inst_env->reg[PC_REGNUM] += 2;
2021 inst_env->delay_slot_pc_active = 0;
2022 inst_env->reg[PC_REGNUM] = inst_env->delay_slot_pc;
2024 /* Analyse the present instruction. */
2025 i = find_cris_op (insn, inst_env);
2028 inst_env->invalid = 1;
2032 cris_gdb_func (cris_opcodes[i].op, insn, inst_env);
2034 } while (!inst_env->invalid
2035 && (inst_env->prefix_found || inst_env->xflag_found
2036 || inst_env->slot_needed));
2040 /* There is no hardware single-step support. The function find_step_target
2041 digs through the opcodes in order to find all possible targets.
2042 Either one ordinary target or two targets for branches may be found. */
2045 cris_software_single_step (enum target_signal ignore, int insert_breakpoints)
2047 inst_env_type inst_env;
2049 if (insert_breakpoints)
2051 /* Analyse the present instruction environment and insert
2053 int status = find_step_target (&inst_env);
2056 /* Could not find a target. Things are likely to go downhill
2058 warning (_("CRIS software single step could not find a step target."));
2062 /* Insert at most two breakpoints. One for the next PC content
2063 and possibly another one for a branch, jump, etc. */
2064 next_pc = (CORE_ADDR) inst_env.reg[PC_REGNUM];
2065 target_insert_breakpoint (next_pc, break_mem[0]);
2066 if (inst_env.branch_found
2067 && (CORE_ADDR) inst_env.branch_break_address != next_pc)
2069 branch_target_address =
2070 (CORE_ADDR) inst_env.branch_break_address;
2071 target_insert_breakpoint (branch_target_address, break_mem[1]);
2072 branch_break_inserted = 1;
2078 /* Remove breakpoints. */
2079 target_remove_breakpoint (next_pc, break_mem[0]);
2080 if (branch_break_inserted)
2082 target_remove_breakpoint (branch_target_address, break_mem[1]);
2083 branch_break_inserted = 0;
2088 /* Calculates the prefix value for quick offset addressing mode. */
2091 quick_mode_bdap_prefix (unsigned short inst, inst_env_type *inst_env)
2093 /* It's invalid to be in a delay slot. You can't have a prefix to this
2094 instruction (not 100% sure). */
2095 if (inst_env->slot_needed || inst_env->prefix_found)
2097 inst_env->invalid = 1;
2101 inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)];
2102 inst_env->prefix_value += cris_get_bdap_quick_offset (inst);
2104 /* A prefix doesn't change the xflag_found. But the rest of the flags
2106 inst_env->slot_needed = 0;
2107 inst_env->prefix_found = 1;
2110 /* Updates the autoincrement register. The size of the increment is derived
2111 from the size of the operation. The PC is always kept aligned on even
2115 process_autoincrement (int size, unsigned short inst, inst_env_type *inst_env)
2117 if (size == INST_BYTE_SIZE)
2119 inst_env->reg[cris_get_operand1 (inst)] += 1;
2121 /* The PC must be word aligned, so increase the PC with one
2122 word even if the size is byte. */
2123 if (cris_get_operand1 (inst) == REG_PC)
2125 inst_env->reg[REG_PC] += 1;
2128 else if (size == INST_WORD_SIZE)
2130 inst_env->reg[cris_get_operand1 (inst)] += 2;
2132 else if (size == INST_DWORD_SIZE)
2134 inst_env->reg[cris_get_operand1 (inst)] += 4;
2139 inst_env->invalid = 1;
2143 /* Just a forward declaration. */
2145 static unsigned long get_data_from_address (unsigned short *inst,
2148 /* Calculates the prefix value for the general case of offset addressing
2152 bdap_prefix (unsigned short inst, inst_env_type *inst_env)
2157 /* It's invalid to be in a delay slot. */
2158 if (inst_env->slot_needed || inst_env->prefix_found)
2160 inst_env->invalid = 1;
2164 /* The calculation of prefix_value used to be after process_autoincrement,
2165 but that fails for an instruction such as jsr [$r0+12] which is encoded
2166 as 5f0d 0c00 30b9 when compiled with -fpic. Since PC is operand1 it
2167 mustn't be incremented until we have read it and what it points at. */
2168 inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)];
2170 /* The offset is an indirection of the contents of the operand1 register. */
2171 inst_env->prefix_value +=
2172 get_data_from_address (&inst, inst_env->reg[cris_get_operand1 (inst)]);
2174 if (cris_get_mode (inst) == AUTOINC_MODE)
2176 process_autoincrement (cris_get_size (inst), inst, inst_env);
2179 /* A prefix doesn't change the xflag_found. But the rest of the flags
2181 inst_env->slot_needed = 0;
2182 inst_env->prefix_found = 1;
2185 /* Calculates the prefix value for the index addressing mode. */
2188 biap_prefix (unsigned short inst, inst_env_type *inst_env)
2190 /* It's invalid to be in a delay slot. I can't see that it's possible to
2191 have a prefix to this instruction. So I will treat this as invalid. */
2192 if (inst_env->slot_needed || inst_env->prefix_found)
2194 inst_env->invalid = 1;
2198 inst_env->prefix_value = inst_env->reg[cris_get_operand1 (inst)];
2200 /* The offset is the operand2 value shifted the size of the instruction
2202 inst_env->prefix_value +=
2203 inst_env->reg[cris_get_operand2 (inst)] << cris_get_size (inst);
2205 /* If the PC is operand1 (base) the address used is the address after
2206 the main instruction, i.e. address + 2 (the PC is already compensated
2207 for the prefix operation). */
2208 if (cris_get_operand1 (inst) == REG_PC)
2210 inst_env->prefix_value += 2;
2213 /* A prefix doesn't change the xflag_found. But the rest of the flags
2215 inst_env->slot_needed = 0;
2216 inst_env->xflag_found = 0;
2217 inst_env->prefix_found = 1;
2220 /* Calculates the prefix value for the double indirect addressing mode. */
2223 dip_prefix (unsigned short inst, inst_env_type *inst_env)
2228 /* It's invalid to be in a delay slot. */
2229 if (inst_env->slot_needed || inst_env->prefix_found)
2231 inst_env->invalid = 1;
2235 /* The prefix value is one dereference of the contents of the operand1
2237 address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)];
2238 inst_env->prefix_value = read_memory_unsigned_integer (address, 4);
2240 /* Check if the mode is autoincrement. */
2241 if (cris_get_mode (inst) == AUTOINC_MODE)
2243 inst_env->reg[cris_get_operand1 (inst)] += 4;
2246 /* A prefix doesn't change the xflag_found. But the rest of the flags
2248 inst_env->slot_needed = 0;
2249 inst_env->xflag_found = 0;
2250 inst_env->prefix_found = 1;
2253 /* Finds the destination for a branch with 8-bits offset. */
2256 eight_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env)
2261 /* If we have a prefix or are in a delay slot it's bad. */
2262 if (inst_env->slot_needed || inst_env->prefix_found)
2264 inst_env->invalid = 1;
2268 /* We have a branch, find out where the branch will land. */
2269 offset = cris_get_branch_short_offset (inst);
2271 /* Check if the offset is signed. */
2272 if (offset & BRANCH_SIGNED_SHORT_OFFSET_MASK)
2277 /* The offset ends with the sign bit, set it to zero. The address
2278 should always be word aligned. */
2279 offset &= ~BRANCH_SIGNED_SHORT_OFFSET_MASK;
2281 inst_env->branch_found = 1;
2282 inst_env->branch_break_address = inst_env->reg[REG_PC] + offset;
2284 inst_env->slot_needed = 1;
2285 inst_env->prefix_found = 0;
2286 inst_env->xflag_found = 0;
2287 inst_env->disable_interrupt = 1;
2290 /* Finds the destination for a branch with 16-bits offset. */
2293 sixteen_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env)
2297 /* If we have a prefix or is in a delay slot it's bad. */
2298 if (inst_env->slot_needed || inst_env->prefix_found)
2300 inst_env->invalid = 1;
2304 /* We have a branch, find out the offset for the branch. */
2305 offset = read_memory_integer (inst_env->reg[REG_PC], 2);
2307 /* The instruction is one word longer than normal, so add one word
2309 inst_env->reg[REG_PC] += 2;
2311 inst_env->branch_found = 1;
2312 inst_env->branch_break_address = inst_env->reg[REG_PC] + offset;
2315 inst_env->slot_needed = 1;
2316 inst_env->prefix_found = 0;
2317 inst_env->xflag_found = 0;
2318 inst_env->disable_interrupt = 1;
2321 /* Handles the ABS instruction. */
2324 abs_op (unsigned short inst, inst_env_type *inst_env)
2329 /* ABS can't have a prefix, so it's bad if it does. */
2330 if (inst_env->prefix_found)
2332 inst_env->invalid = 1;
2336 /* Check if the operation affects the PC. */
2337 if (cris_get_operand2 (inst) == REG_PC)
2340 /* It's invalid to change to the PC if we are in a delay slot. */
2341 if (inst_env->slot_needed)
2343 inst_env->invalid = 1;
2347 value = (long) inst_env->reg[REG_PC];
2349 /* The value of abs (SIGNED_DWORD_MASK) is SIGNED_DWORD_MASK. */
2350 if (value != SIGNED_DWORD_MASK)
2353 inst_env->reg[REG_PC] = (long) value;
2357 inst_env->slot_needed = 0;
2358 inst_env->prefix_found = 0;
2359 inst_env->xflag_found = 0;
2360 inst_env->disable_interrupt = 0;
2363 /* Handles the ADDI instruction. */
2366 addi_op (unsigned short inst, inst_env_type *inst_env)
2368 /* It's invalid to have the PC as base register. And ADDI can't have
2370 if (inst_env->prefix_found || (cris_get_operand1 (inst) == REG_PC))
2372 inst_env->invalid = 1;
2376 inst_env->slot_needed = 0;
2377 inst_env->prefix_found = 0;
2378 inst_env->xflag_found = 0;
2379 inst_env->disable_interrupt = 0;
2382 /* Handles the ASR instruction. */
2385 asr_op (unsigned short inst, inst_env_type *inst_env)
2388 unsigned long value;
2389 unsigned long signed_extend_mask = 0;
2391 /* ASR can't have a prefix, so check that it doesn't. */
2392 if (inst_env->prefix_found)
2394 inst_env->invalid = 1;
2398 /* Check if the PC is the target register. */
2399 if (cris_get_operand2 (inst) == REG_PC)
2401 /* It's invalid to change the PC in a delay slot. */
2402 if (inst_env->slot_needed)
2404 inst_env->invalid = 1;
2407 /* Get the number of bits to shift. */
2408 shift_steps = cris_get_asr_shift_steps (inst_env->reg[cris_get_operand1 (inst)]);
2409 value = inst_env->reg[REG_PC];
2411 /* Find out how many bits the operation should apply to. */
2412 if (cris_get_size (inst) == INST_BYTE_SIZE)
2414 if (value & SIGNED_BYTE_MASK)
2416 signed_extend_mask = 0xFF;
2417 signed_extend_mask = signed_extend_mask >> shift_steps;
2418 signed_extend_mask = ~signed_extend_mask;
2420 value = value >> shift_steps;
2421 value |= signed_extend_mask;
2423 inst_env->reg[REG_PC] &= 0xFFFFFF00;
2424 inst_env->reg[REG_PC] |= value;
2426 else if (cris_get_size (inst) == INST_WORD_SIZE)
2428 if (value & SIGNED_WORD_MASK)
2430 signed_extend_mask = 0xFFFF;
2431 signed_extend_mask = signed_extend_mask >> shift_steps;
2432 signed_extend_mask = ~signed_extend_mask;
2434 value = value >> shift_steps;
2435 value |= signed_extend_mask;
2437 inst_env->reg[REG_PC] &= 0xFFFF0000;
2438 inst_env->reg[REG_PC] |= value;
2440 else if (cris_get_size (inst) == INST_DWORD_SIZE)
2442 if (value & SIGNED_DWORD_MASK)
2444 signed_extend_mask = 0xFFFFFFFF;
2445 signed_extend_mask = signed_extend_mask >> shift_steps;
2446 signed_extend_mask = ~signed_extend_mask;
2448 value = value >> shift_steps;
2449 value |= signed_extend_mask;
2450 inst_env->reg[REG_PC] = value;
2453 inst_env->slot_needed = 0;
2454 inst_env->prefix_found = 0;
2455 inst_env->xflag_found = 0;
2456 inst_env->disable_interrupt = 0;
2459 /* Handles the ASRQ instruction. */
2462 asrq_op (unsigned short inst, inst_env_type *inst_env)
2466 unsigned long value;
2467 unsigned long signed_extend_mask = 0;
2469 /* ASRQ can't have a prefix, so check that it doesn't. */
2470 if (inst_env->prefix_found)
2472 inst_env->invalid = 1;
2476 /* Check if the PC is the target register. */
2477 if (cris_get_operand2 (inst) == REG_PC)
2480 /* It's invalid to change the PC in a delay slot. */
2481 if (inst_env->slot_needed)
2483 inst_env->invalid = 1;
2486 /* The shift size is given as a 5 bit quick value, i.e. we don't
2487 want the the sign bit of the quick value. */
2488 shift_steps = cris_get_asr_shift_steps (inst);
2489 value = inst_env->reg[REG_PC];
2490 if (value & SIGNED_DWORD_MASK)
2492 signed_extend_mask = 0xFFFFFFFF;
2493 signed_extend_mask = signed_extend_mask >> shift_steps;
2494 signed_extend_mask = ~signed_extend_mask;
2496 value = value >> shift_steps;
2497 value |= signed_extend_mask;
2498 inst_env->reg[REG_PC] = value;
2500 inst_env->slot_needed = 0;
2501 inst_env->prefix_found = 0;
2502 inst_env->xflag_found = 0;
2503 inst_env->disable_interrupt = 0;
2506 /* Handles the AX, EI and SETF instruction. */
2509 ax_ei_setf_op (unsigned short inst, inst_env_type *inst_env)
2511 if (inst_env->prefix_found)
2513 inst_env->invalid = 1;
2516 /* Check if the instruction is setting the X flag. */
2517 if (cris_is_xflag_bit_on (inst))
2519 inst_env->xflag_found = 1;
2523 inst_env->xflag_found = 0;
2525 inst_env->slot_needed = 0;
2526 inst_env->prefix_found = 0;
2527 inst_env->disable_interrupt = 1;
2530 /* Checks if the instruction is in assign mode. If so, it updates the assign
2531 register. Note that check_assign assumes that the caller has checked that
2532 there is a prefix to this instruction. The mode check depends on this. */
2535 check_assign (unsigned short inst, inst_env_type *inst_env)
2537 /* Check if it's an assign addressing mode. */
2538 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2540 /* Assign the prefix value to operand 1. */
2541 inst_env->reg[cris_get_operand1 (inst)] = inst_env->prefix_value;
2545 /* Handles the 2-operand BOUND instruction. */
2548 two_operand_bound_op (unsigned short inst, inst_env_type *inst_env)
2550 /* It's invalid to have the PC as the index operand. */
2551 if (cris_get_operand2 (inst) == REG_PC)
2553 inst_env->invalid = 1;
2556 /* Check if we have a prefix. */
2557 if (inst_env->prefix_found)
2559 check_assign (inst, inst_env);
2561 /* Check if this is an autoincrement mode. */
2562 else if (cris_get_mode (inst) == AUTOINC_MODE)
2564 /* It's invalid to change the PC in a delay slot. */
2565 if (inst_env->slot_needed)
2567 inst_env->invalid = 1;
2570 process_autoincrement (cris_get_size (inst), inst, inst_env);
2572 inst_env->slot_needed = 0;
2573 inst_env->prefix_found = 0;
2574 inst_env->xflag_found = 0;
2575 inst_env->disable_interrupt = 0;
2578 /* Handles the 3-operand BOUND instruction. */
2581 three_operand_bound_op (unsigned short inst, inst_env_type *inst_env)
2583 /* It's an error if we haven't got a prefix. And it's also an error
2584 if the PC is the destination register. */
2585 if ((!inst_env->prefix_found) || (cris_get_operand1 (inst) == REG_PC))
2587 inst_env->invalid = 1;
2590 inst_env->slot_needed = 0;
2591 inst_env->prefix_found = 0;
2592 inst_env->xflag_found = 0;
2593 inst_env->disable_interrupt = 0;
2596 /* Clears the status flags in inst_env. */
2599 btst_nop_op (unsigned short inst, inst_env_type *inst_env)
2601 /* It's an error if we have got a prefix. */
2602 if (inst_env->prefix_found)
2604 inst_env->invalid = 1;
2608 inst_env->slot_needed = 0;
2609 inst_env->prefix_found = 0;
2610 inst_env->xflag_found = 0;
2611 inst_env->disable_interrupt = 0;
2614 /* Clears the status flags in inst_env. */
2617 clearf_di_op (unsigned short inst, inst_env_type *inst_env)
2619 /* It's an error if we have got a prefix. */
2620 if (inst_env->prefix_found)
2622 inst_env->invalid = 1;
2626 inst_env->slot_needed = 0;
2627 inst_env->prefix_found = 0;
2628 inst_env->xflag_found = 0;
2629 inst_env->disable_interrupt = 1;
2632 /* Handles the CLEAR instruction if it's in register mode. */
2635 reg_mode_clear_op (unsigned short inst, inst_env_type *inst_env)
2637 /* Check if the target is the PC. */
2638 if (cris_get_operand2 (inst) == REG_PC)
2640 /* The instruction will clear the instruction's size bits. */
2641 int clear_size = cris_get_clear_size (inst);
2642 if (clear_size == INST_BYTE_SIZE)
2644 inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFFFF00;
2646 if (clear_size == INST_WORD_SIZE)
2648 inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFF0000;
2650 if (clear_size == INST_DWORD_SIZE)
2652 inst_env->delay_slot_pc = 0x0;
2654 /* The jump will be delayed with one delay slot. So we need a delay
2656 inst_env->slot_needed = 1;
2657 inst_env->delay_slot_pc_active = 1;
2661 /* The PC will not change => no delay slot. */
2662 inst_env->slot_needed = 0;
2664 inst_env->prefix_found = 0;
2665 inst_env->xflag_found = 0;
2666 inst_env->disable_interrupt = 0;
2669 /* Handles the TEST instruction if it's in register mode. */
2672 reg_mode_test_op (unsigned short inst, inst_env_type *inst_env)
2674 /* It's an error if we have got a prefix. */
2675 if (inst_env->prefix_found)
2677 inst_env->invalid = 1;
2680 inst_env->slot_needed = 0;
2681 inst_env->prefix_found = 0;
2682 inst_env->xflag_found = 0;
2683 inst_env->disable_interrupt = 0;
2687 /* Handles the CLEAR and TEST instruction if the instruction isn't
2688 in register mode. */
2691 none_reg_mode_clear_test_op (unsigned short inst, inst_env_type *inst_env)
2693 /* Check if we are in a prefix mode. */
2694 if (inst_env->prefix_found)
2696 /* The only way the PC can change is if this instruction is in
2697 assign addressing mode. */
2698 check_assign (inst, inst_env);
2700 /* Indirect mode can't change the PC so just check if the mode is
2702 else if (cris_get_mode (inst) == AUTOINC_MODE)
2704 process_autoincrement (cris_get_size (inst), inst, inst_env);
2706 inst_env->slot_needed = 0;
2707 inst_env->prefix_found = 0;
2708 inst_env->xflag_found = 0;
2709 inst_env->disable_interrupt = 0;
2712 /* Checks that the PC isn't the destination register or the instructions has
2716 dstep_logshift_mstep_neg_not_op (unsigned short inst, inst_env_type *inst_env)
2718 /* It's invalid to have the PC as the destination. The instruction can't
2720 if ((cris_get_operand2 (inst) == REG_PC) || inst_env->prefix_found)
2722 inst_env->invalid = 1;
2726 inst_env->slot_needed = 0;
2727 inst_env->prefix_found = 0;
2728 inst_env->xflag_found = 0;
2729 inst_env->disable_interrupt = 0;
2732 /* Checks that the instruction doesn't have a prefix. */
2735 break_op (unsigned short inst, inst_env_type *inst_env)
2737 /* The instruction can't have a prefix. */
2738 if (inst_env->prefix_found)
2740 inst_env->invalid = 1;
2744 inst_env->slot_needed = 0;
2745 inst_env->prefix_found = 0;
2746 inst_env->xflag_found = 0;
2747 inst_env->disable_interrupt = 1;
2750 /* Checks that the PC isn't the destination register and that the instruction
2751 doesn't have a prefix. */
2754 scc_op (unsigned short inst, inst_env_type *inst_env)
2756 /* It's invalid to have the PC as the destination. The instruction can't
2758 if ((cris_get_operand2 (inst) == REG_PC) || inst_env->prefix_found)
2760 inst_env->invalid = 1;
2764 inst_env->slot_needed = 0;
2765 inst_env->prefix_found = 0;
2766 inst_env->xflag_found = 0;
2767 inst_env->disable_interrupt = 1;
2770 /* Handles the register mode JUMP instruction. */
2773 reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env)
2775 /* It's invalid to do a JUMP in a delay slot. The mode is register, so
2776 you can't have a prefix. */
2777 if ((inst_env->slot_needed) || (inst_env->prefix_found))
2779 inst_env->invalid = 1;
2783 /* Just change the PC. */
2784 inst_env->reg[REG_PC] = inst_env->reg[cris_get_operand1 (inst)];
2785 inst_env->slot_needed = 0;
2786 inst_env->prefix_found = 0;
2787 inst_env->xflag_found = 0;
2788 inst_env->disable_interrupt = 1;
2791 /* Handles the JUMP instruction for all modes except register. */
2794 none_reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env)
2796 unsigned long newpc;
2799 /* It's invalid to do a JUMP in a delay slot. */
2800 if (inst_env->slot_needed)
2802 inst_env->invalid = 1;
2806 /* Check if we have a prefix. */
2807 if (inst_env->prefix_found)
2809 check_assign (inst, inst_env);
2811 /* Get the new value for the the PC. */
2813 read_memory_unsigned_integer ((CORE_ADDR) inst_env->prefix_value,
2818 /* Get the new value for the PC. */
2819 address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)];
2820 newpc = read_memory_unsigned_integer (address, 4);
2822 /* Check if we should increment a register. */
2823 if (cris_get_mode (inst) == AUTOINC_MODE)
2825 inst_env->reg[cris_get_operand1 (inst)] += 4;
2828 inst_env->reg[REG_PC] = newpc;
2830 inst_env->slot_needed = 0;
2831 inst_env->prefix_found = 0;
2832 inst_env->xflag_found = 0;
2833 inst_env->disable_interrupt = 1;
2836 /* Handles moves to special registers (aka P-register) for all modes. */
2839 move_to_preg_op (unsigned short inst, inst_env_type *inst_env)
2841 if (inst_env->prefix_found)
2843 /* The instruction has a prefix that means we are only interested if
2844 the instruction is in assign mode. */
2845 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2847 /* The prefix handles the problem if we are in a delay slot. */
2848 if (cris_get_operand1 (inst) == REG_PC)
2850 /* Just take care of the assign. */
2851 check_assign (inst, inst_env);
2855 else if (cris_get_mode (inst) == AUTOINC_MODE)
2857 /* The instruction doesn't have a prefix, the only case left that we
2858 are interested in is the autoincrement mode. */
2859 if (cris_get_operand1 (inst) == REG_PC)
2861 /* If the PC is to be incremented it's invalid to be in a
2863 if (inst_env->slot_needed)
2865 inst_env->invalid = 1;
2869 /* The increment depends on the size of the special register. */
2870 if (cris_register_size (cris_get_operand2 (inst)) == 1)
2872 process_autoincrement (INST_BYTE_SIZE, inst, inst_env);
2874 else if (cris_register_size (cris_get_operand2 (inst)) == 2)
2876 process_autoincrement (INST_WORD_SIZE, inst, inst_env);
2880 process_autoincrement (INST_DWORD_SIZE, inst, inst_env);
2884 inst_env->slot_needed = 0;
2885 inst_env->prefix_found = 0;
2886 inst_env->xflag_found = 0;
2887 inst_env->disable_interrupt = 1;
2890 /* Handles moves from special registers (aka P-register) for all modes
2894 none_reg_mode_move_from_preg_op (unsigned short inst, inst_env_type *inst_env)
2896 if (inst_env->prefix_found)
2898 /* The instruction has a prefix that means we are only interested if
2899 the instruction is in assign mode. */
2900 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2902 /* The prefix handles the problem if we are in a delay slot. */
2903 if (cris_get_operand1 (inst) == REG_PC)
2905 /* Just take care of the assign. */
2906 check_assign (inst, inst_env);
2910 /* The instruction doesn't have a prefix, the only case left that we
2911 are interested in is the autoincrement mode. */
2912 else if (cris_get_mode (inst) == AUTOINC_MODE)
2914 if (cris_get_operand1 (inst) == REG_PC)
2916 /* If the PC is to be incremented it's invalid to be in a
2918 if (inst_env->slot_needed)
2920 inst_env->invalid = 1;
2924 /* The increment depends on the size of the special register. */
2925 if (cris_register_size (cris_get_operand2 (inst)) == 1)
2927 process_autoincrement (INST_BYTE_SIZE, inst, inst_env);
2929 else if (cris_register_size (cris_get_operand2 (inst)) == 2)
2931 process_autoincrement (INST_WORD_SIZE, inst, inst_env);
2935 process_autoincrement (INST_DWORD_SIZE, inst, inst_env);
2939 inst_env->slot_needed = 0;
2940 inst_env->prefix_found = 0;
2941 inst_env->xflag_found = 0;
2942 inst_env->disable_interrupt = 1;
2945 /* Handles moves from special registers (aka P-register) when the mode
2949 reg_mode_move_from_preg_op (unsigned short inst, inst_env_type *inst_env)
2951 /* Register mode move from special register can't have a prefix. */
2952 if (inst_env->prefix_found)
2954 inst_env->invalid = 1;
2958 if (cris_get_operand1 (inst) == REG_PC)
2960 /* It's invalid to change the PC in a delay slot. */
2961 if (inst_env->slot_needed)
2963 inst_env->invalid = 1;
2966 /* The destination is the PC, the jump will have a delay slot. */
2967 inst_env->delay_slot_pc = inst_env->preg[cris_get_operand2 (inst)];
2968 inst_env->slot_needed = 1;
2969 inst_env->delay_slot_pc_active = 1;
2973 /* If the destination isn't PC, there will be no jump. */
2974 inst_env->slot_needed = 0;
2976 inst_env->prefix_found = 0;
2977 inst_env->xflag_found = 0;
2978 inst_env->disable_interrupt = 1;
2981 /* Handles the MOVEM from memory to general register instruction. */
2984 move_mem_to_reg_movem_op (unsigned short inst, inst_env_type *inst_env)
2986 if (inst_env->prefix_found)
2988 /* The prefix handles the problem if we are in a delay slot. Is the
2989 MOVEM instruction going to change the PC? */
2990 if (cris_get_operand2 (inst) >= REG_PC)
2992 inst_env->reg[REG_PC] =
2993 read_memory_unsigned_integer (inst_env->prefix_value, 4);
2995 /* The assign value is the value after the increment. Normally, the
2996 assign value is the value before the increment. */
2997 if ((cris_get_operand1 (inst) == REG_PC)
2998 && (cris_get_mode (inst) == PREFIX_ASSIGN_MODE))
3000 inst_env->reg[REG_PC] = inst_env->prefix_value;
3001 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
3006 /* Is the MOVEM instruction going to change the PC? */
3007 if (cris_get_operand2 (inst) == REG_PC)
3009 /* It's invalid to change the PC in a delay slot. */
3010 if (inst_env->slot_needed)
3012 inst_env->invalid = 1;
3015 inst_env->reg[REG_PC] =
3016 read_memory_unsigned_integer (inst_env->reg[cris_get_operand1 (inst)],
3019 /* The increment is not depending on the size, instead it's depending
3020 on the number of registers loaded from memory. */
3021 if ((cris_get_operand1 (inst) == REG_PC) && (cris_get_mode (inst) == AUTOINC_MODE))
3023 /* It's invalid to change the PC in a delay slot. */
3024 if (inst_env->slot_needed)
3026 inst_env->invalid = 1;
3029 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
3032 inst_env->slot_needed = 0;
3033 inst_env->prefix_found = 0;
3034 inst_env->xflag_found = 0;
3035 inst_env->disable_interrupt = 0;
3038 /* Handles the MOVEM to memory from general register instruction. */
3041 move_reg_to_mem_movem_op (unsigned short inst, inst_env_type *inst_env)
3043 if (inst_env->prefix_found)
3045 /* The assign value is the value after the increment. Normally, the
3046 assign value is the value before the increment. */
3047 if ((cris_get_operand1 (inst) == REG_PC) &&
3048 (cris_get_mode (inst) == PREFIX_ASSIGN_MODE))
3050 /* The prefix handles the problem if we are in a delay slot. */
3051 inst_env->reg[REG_PC] = inst_env->prefix_value;
3052 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
3057 /* The increment is not depending on the size, instead it's depending
3058 on the number of registers loaded to memory. */
3059 if ((cris_get_operand1 (inst) == REG_PC) && (cris_get_mode (inst) == AUTOINC_MODE))
3061 /* It's invalid to change the PC in a delay slot. */
3062 if (inst_env->slot_needed)
3064 inst_env->invalid = 1;
3067 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
3070 inst_env->slot_needed = 0;
3071 inst_env->prefix_found = 0;
3072 inst_env->xflag_found = 0;
3073 inst_env->disable_interrupt = 0;
3076 /* Handles the intructions that's not yet implemented, by setting
3077 inst_env->invalid to true. */
3080 not_implemented_op (unsigned short inst, inst_env_type *inst_env)
3082 inst_env->invalid = 1;
3085 /* Handles the XOR instruction. */
3088 xor_op (unsigned short inst, inst_env_type *inst_env)
3090 /* XOR can't have a prefix. */
3091 if (inst_env->prefix_found)
3093 inst_env->invalid = 1;
3097 /* Check if the PC is the target. */
3098 if (cris_get_operand2 (inst) == REG_PC)
3100 /* It's invalid to change the PC in a delay slot. */
3101 if (inst_env->slot_needed)
3103 inst_env->invalid = 1;
3106 inst_env->reg[REG_PC] ^= inst_env->reg[cris_get_operand1 (inst)];
3108 inst_env->slot_needed = 0;
3109 inst_env->prefix_found = 0;
3110 inst_env->xflag_found = 0;
3111 inst_env->disable_interrupt = 0;
3114 /* Handles the MULS instruction. */
3117 muls_op (unsigned short inst, inst_env_type *inst_env)
3119 /* MULS/U can't have a prefix. */
3120 if (inst_env->prefix_found)
3122 inst_env->invalid = 1;
3126 /* Consider it invalid if the PC is the target. */
3127 if (cris_get_operand2 (inst) == REG_PC)
3129 inst_env->invalid = 1;
3132 inst_env->slot_needed = 0;
3133 inst_env->prefix_found = 0;
3134 inst_env->xflag_found = 0;
3135 inst_env->disable_interrupt = 0;
3138 /* Handles the MULU instruction. */
3141 mulu_op (unsigned short inst, inst_env_type *inst_env)
3143 /* MULS/U can't have a prefix. */
3144 if (inst_env->prefix_found)
3146 inst_env->invalid = 1;
3150 /* Consider it invalid if the PC is the target. */
3151 if (cris_get_operand2 (inst) == REG_PC)
3153 inst_env->invalid = 1;
3156 inst_env->slot_needed = 0;
3157 inst_env->prefix_found = 0;
3158 inst_env->xflag_found = 0;
3159 inst_env->disable_interrupt = 0;
3162 /* Calculate the result of the instruction for ADD, SUB, CMP AND, OR and MOVE.
3163 The MOVE instruction is the move from source to register. */
3166 add_sub_cmp_and_or_move_action (unsigned short inst, inst_env_type *inst_env,
3167 unsigned long source1, unsigned long source2)
3169 unsigned long pc_mask;
3170 unsigned long operation_mask;
3172 /* Find out how many bits the operation should apply to. */
3173 if (cris_get_size (inst) == INST_BYTE_SIZE)
3175 pc_mask = 0xFFFFFF00;
3176 operation_mask = 0xFF;
3178 else if (cris_get_size (inst) == INST_WORD_SIZE)
3180 pc_mask = 0xFFFF0000;
3181 operation_mask = 0xFFFF;
3183 else if (cris_get_size (inst) == INST_DWORD_SIZE)
3186 operation_mask = 0xFFFFFFFF;
3190 /* The size is out of range. */
3191 inst_env->invalid = 1;
3195 /* The instruction just works on uw_operation_mask bits. */
3196 source2 &= operation_mask;
3197 source1 &= operation_mask;
3199 /* Now calculate the result. The opcode's 3 first bits separates
3200 the different actions. */
3201 switch (cris_get_opcode (inst) & 7)
3211 case 2: /* subtract */
3215 case 3: /* compare */
3227 inst_env->invalid = 1;
3233 /* Make sure that the result doesn't contain more than the instruction
3235 source2 &= operation_mask;
3237 /* Calculate the new breakpoint address. */
3238 inst_env->reg[REG_PC] &= pc_mask;
3239 inst_env->reg[REG_PC] |= source1;
3243 /* Extends the value from either byte or word size to a dword. If the mode
3244 is zero extend then the value is extended with zero. If instead the mode
3245 is signed extend the sign bit of the value is taken into consideration. */
3247 static unsigned long
3248 do_sign_or_zero_extend (unsigned long value, unsigned short *inst)
3250 /* The size can be either byte or word, check which one it is.
3251 Don't check the highest bit, it's indicating if it's a zero
3253 if (cris_get_size (*inst) & INST_WORD_SIZE)
3258 /* Check if the instruction is signed extend. If so, check if value has
3260 if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_WORD_MASK))
3262 value |= SIGNED_WORD_EXTEND_MASK;
3270 /* Check if the instruction is signed extend. If so, check if value has
3272 if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_BYTE_MASK))
3274 value |= SIGNED_BYTE_EXTEND_MASK;
3277 /* The size should now be dword. */
3278 cris_set_size_to_dword (inst);
3282 /* Handles the register mode for the ADD, SUB, CMP, AND, OR and MOVE
3283 instruction. The MOVE instruction is the move from source to register. */
3286 reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst,
3287 inst_env_type *inst_env)
3289 unsigned long operand1;
3290 unsigned long operand2;
3292 /* It's invalid to have a prefix to the instruction. This is a register
3293 mode instruction and can't have a prefix. */
3294 if (inst_env->prefix_found)
3296 inst_env->invalid = 1;
3299 /* Check if the instruction has PC as its target. */
3300 if (cris_get_operand2 (inst) == REG_PC)
3302 if (inst_env->slot_needed)
3304 inst_env->invalid = 1;
3307 /* The instruction has the PC as its target register. */
3308 operand1 = inst_env->reg[cris_get_operand1 (inst)];
3309 operand2 = inst_env->reg[REG_PC];
3311 /* Check if it's a extend, signed or zero instruction. */
3312 if (cris_get_opcode (inst) < 4)
3314 operand1 = do_sign_or_zero_extend (operand1, &inst);
3316 /* Calculate the PC value after the instruction, i.e. where the
3317 breakpoint should be. The order of the udw_operands is vital. */
3318 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3320 inst_env->slot_needed = 0;
3321 inst_env->prefix_found = 0;
3322 inst_env->xflag_found = 0;
3323 inst_env->disable_interrupt = 0;
3326 /* Returns the data contained at address. The size of the data is derived from
3327 the size of the operation. If the instruction is a zero or signed
3328 extend instruction, the size field is changed in instruction. */
3330 static unsigned long
3331 get_data_from_address (unsigned short *inst, CORE_ADDR address)
3333 int size = cris_get_size (*inst);
3334 unsigned long value;
3336 /* If it's an extend instruction we don't want the signed extend bit,
3337 because it influences the size. */
3338 if (cris_get_opcode (*inst) < 4)
3340 size &= ~SIGNED_EXTEND_BIT_MASK;
3342 /* Is there a need for checking the size? Size should contain the number of
3345 value = read_memory_unsigned_integer (address, size);
3347 /* Check if it's an extend, signed or zero instruction. */
3348 if (cris_get_opcode (*inst) < 4)
3350 value = do_sign_or_zero_extend (value, inst);
3355 /* Handles the assign addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
3356 instructions. The MOVE instruction is the move from source to register. */
3359 handle_prefix_assign_mode_for_aritm_op (unsigned short inst,
3360 inst_env_type *inst_env)
3362 unsigned long operand2;
3363 unsigned long operand3;
3365 check_assign (inst, inst_env);
3366 if (cris_get_operand2 (inst) == REG_PC)
3368 operand2 = inst_env->reg[REG_PC];
3370 /* Get the value of the third operand. */
3371 operand3 = get_data_from_address (&inst, inst_env->prefix_value);
3373 /* Calculate the PC value after the instruction, i.e. where the
3374 breakpoint should be. The order of the udw_operands is vital. */
3375 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3377 inst_env->slot_needed = 0;
3378 inst_env->prefix_found = 0;
3379 inst_env->xflag_found = 0;
3380 inst_env->disable_interrupt = 0;
3383 /* Handles the three-operand addressing mode for the ADD, SUB, CMP, AND and
3384 OR instructions. Note that for this to work as expected, the calling
3385 function must have made sure that there is a prefix to this instruction. */
3388 three_operand_add_sub_cmp_and_or_op (unsigned short inst,
3389 inst_env_type *inst_env)
3391 unsigned long operand2;
3392 unsigned long operand3;
3394 if (cris_get_operand1 (inst) == REG_PC)
3396 /* The PC will be changed by the instruction. */
3397 operand2 = inst_env->reg[cris_get_operand2 (inst)];
3399 /* Get the value of the third operand. */
3400 operand3 = get_data_from_address (&inst, inst_env->prefix_value);
3402 /* Calculate the PC value after the instruction, i.e. where the
3403 breakpoint should be. */
3404 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3406 inst_env->slot_needed = 0;
3407 inst_env->prefix_found = 0;
3408 inst_env->xflag_found = 0;
3409 inst_env->disable_interrupt = 0;
3412 /* Handles the index addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
3413 instructions. The MOVE instruction is the move from source to register. */
3416 handle_prefix_index_mode_for_aritm_op (unsigned short inst,
3417 inst_env_type *inst_env)
3419 if (cris_get_operand1 (inst) != cris_get_operand2 (inst))
3421 /* If the instruction is MOVE it's invalid. If the instruction is ADD,
3422 SUB, AND or OR something weird is going on (if everything works these
3423 instructions should end up in the three operand version). */
3424 inst_env->invalid = 1;
3429 /* three_operand_add_sub_cmp_and_or does the same as we should do here
3431 three_operand_add_sub_cmp_and_or_op (inst, inst_env);
3433 inst_env->slot_needed = 0;
3434 inst_env->prefix_found = 0;
3435 inst_env->xflag_found = 0;
3436 inst_env->disable_interrupt = 0;
3439 /* Handles the autoincrement and indirect addresing mode for the ADD, SUB,
3440 CMP, AND OR and MOVE instruction. The MOVE instruction is the move from
3441 source to register. */
3444 handle_inc_and_index_mode_for_aritm_op (unsigned short inst,
3445 inst_env_type *inst_env)
3447 unsigned long operand1;
3448 unsigned long operand2;
3449 unsigned long operand3;
3452 /* The instruction is either an indirect or autoincrement addressing mode.
3453 Check if the destination register is the PC. */
3454 if (cris_get_operand2 (inst) == REG_PC)
3456 /* Must be done here, get_data_from_address may change the size
3458 size = cris_get_size (inst);
3459 operand2 = inst_env->reg[REG_PC];
3461 /* Get the value of the third operand, i.e. the indirect operand. */
3462 operand1 = inst_env->reg[cris_get_operand1 (inst)];
3463 operand3 = get_data_from_address (&inst, operand1);
3465 /* Calculate the PC value after the instruction, i.e. where the
3466 breakpoint should be. The order of the udw_operands is vital. */
3467 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3469 /* If this is an autoincrement addressing mode, check if the increment
3471 if ((cris_get_operand1 (inst) == REG_PC) && (cris_get_mode (inst) == AUTOINC_MODE))
3473 /* Get the size field. */
3474 size = cris_get_size (inst);
3476 /* If it's an extend instruction we don't want the signed extend bit,
3477 because it influences the size. */
3478 if (cris_get_opcode (inst) < 4)
3480 size &= ~SIGNED_EXTEND_BIT_MASK;
3482 process_autoincrement (size, inst, inst_env);
3484 inst_env->slot_needed = 0;
3485 inst_env->prefix_found = 0;
3486 inst_env->xflag_found = 0;
3487 inst_env->disable_interrupt = 0;
3490 /* Handles the two-operand addressing mode, all modes except register, for
3491 the ADD, SUB CMP, AND and OR instruction. */
3494 none_reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst,
3495 inst_env_type *inst_env)
3497 if (inst_env->prefix_found)
3499 if (cris_get_mode (inst) == PREFIX_INDEX_MODE)
3501 handle_prefix_index_mode_for_aritm_op (inst, inst_env);
3503 else if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
3505 handle_prefix_assign_mode_for_aritm_op (inst, inst_env);
3509 /* The mode is invalid for a prefixed base instruction. */
3510 inst_env->invalid = 1;
3516 handle_inc_and_index_mode_for_aritm_op (inst, inst_env);
3520 /* Handles the quick addressing mode for the ADD and SUB instruction. */
3523 quick_mode_add_sub_op (unsigned short inst, inst_env_type *inst_env)
3525 unsigned long operand1;
3526 unsigned long operand2;
3528 /* It's a bad idea to be in a prefix instruction now. This is a quick mode
3529 instruction and can't have a prefix. */
3530 if (inst_env->prefix_found)
3532 inst_env->invalid = 1;
3536 /* Check if the instruction has PC as its target. */
3537 if (cris_get_operand2 (inst) == REG_PC)
3539 if (inst_env->slot_needed)
3541 inst_env->invalid = 1;
3544 operand1 = cris_get_quick_value (inst);
3545 operand2 = inst_env->reg[REG_PC];
3547 /* The size should now be dword. */
3548 cris_set_size_to_dword (&inst);
3550 /* Calculate the PC value after the instruction, i.e. where the
3551 breakpoint should be. */
3552 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3554 inst_env->slot_needed = 0;
3555 inst_env->prefix_found = 0;
3556 inst_env->xflag_found = 0;
3557 inst_env->disable_interrupt = 0;
3560 /* Handles the quick addressing mode for the CMP, AND and OR instruction. */
3563 quick_mode_and_cmp_move_or_op (unsigned short inst, inst_env_type *inst_env)
3565 unsigned long operand1;
3566 unsigned long operand2;
3568 /* It's a bad idea to be in a prefix instruction now. This is a quick mode
3569 instruction and can't have a prefix. */
3570 if (inst_env->prefix_found)
3572 inst_env->invalid = 1;
3575 /* Check if the instruction has PC as its target. */
3576 if (cris_get_operand2 (inst) == REG_PC)
3578 if (inst_env->slot_needed)
3580 inst_env->invalid = 1;
3583 /* The instruction has the PC as its target register. */
3584 operand1 = cris_get_quick_value (inst);
3585 operand2 = inst_env->reg[REG_PC];
3587 /* The quick value is signed, so check if we must do a signed extend. */
3588 if (operand1 & SIGNED_QUICK_VALUE_MASK)
3591 operand1 |= SIGNED_QUICK_VALUE_EXTEND_MASK;
3593 /* The size should now be dword. */
3594 cris_set_size_to_dword (&inst);
3596 /* Calculate the PC value after the instruction, i.e. where the
3597 breakpoint should be. */
3598 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3600 inst_env->slot_needed = 0;
3601 inst_env->prefix_found = 0;
3602 inst_env->xflag_found = 0;
3603 inst_env->disable_interrupt = 0;
3606 /* Translate op_type to a function and call it. */
3609 cris_gdb_func (enum cris_op_type op_type, unsigned short inst,
3610 inst_env_type *inst_env)
3614 case cris_not_implemented_op:
3615 not_implemented_op (inst, inst_env);
3619 abs_op (inst, inst_env);
3623 addi_op (inst, inst_env);
3627 asr_op (inst, inst_env);
3631 asrq_op (inst, inst_env);
3634 case cris_ax_ei_setf_op:
3635 ax_ei_setf_op (inst, inst_env);
3638 case cris_bdap_prefix:
3639 bdap_prefix (inst, inst_env);
3642 case cris_biap_prefix:
3643 biap_prefix (inst, inst_env);
3647 break_op (inst, inst_env);
3650 case cris_btst_nop_op:
3651 btst_nop_op (inst, inst_env);
3654 case cris_clearf_di_op:
3655 clearf_di_op (inst, inst_env);
3658 case cris_dip_prefix:
3659 dip_prefix (inst, inst_env);
3662 case cris_dstep_logshift_mstep_neg_not_op:
3663 dstep_logshift_mstep_neg_not_op (inst, inst_env);
3666 case cris_eight_bit_offset_branch_op:
3667 eight_bit_offset_branch_op (inst, inst_env);
3670 case cris_move_mem_to_reg_movem_op:
3671 move_mem_to_reg_movem_op (inst, inst_env);
3674 case cris_move_reg_to_mem_movem_op:
3675 move_reg_to_mem_movem_op (inst, inst_env);
3678 case cris_move_to_preg_op:
3679 move_to_preg_op (inst, inst_env);
3683 muls_op (inst, inst_env);
3687 mulu_op (inst, inst_env);
3690 case cris_none_reg_mode_add_sub_cmp_and_or_move_op:
3691 none_reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env);
3694 case cris_none_reg_mode_clear_test_op:
3695 none_reg_mode_clear_test_op (inst, inst_env);
3698 case cris_none_reg_mode_jump_op:
3699 none_reg_mode_jump_op (inst, inst_env);
3702 case cris_none_reg_mode_move_from_preg_op:
3703 none_reg_mode_move_from_preg_op (inst, inst_env);
3706 case cris_quick_mode_add_sub_op:
3707 quick_mode_add_sub_op (inst, inst_env);
3710 case cris_quick_mode_and_cmp_move_or_op:
3711 quick_mode_and_cmp_move_or_op (inst, inst_env);
3714 case cris_quick_mode_bdap_prefix:
3715 quick_mode_bdap_prefix (inst, inst_env);
3718 case cris_reg_mode_add_sub_cmp_and_or_move_op:
3719 reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env);
3722 case cris_reg_mode_clear_op:
3723 reg_mode_clear_op (inst, inst_env);
3726 case cris_reg_mode_jump_op:
3727 reg_mode_jump_op (inst, inst_env);
3730 case cris_reg_mode_move_from_preg_op:
3731 reg_mode_move_from_preg_op (inst, inst_env);
3734 case cris_reg_mode_test_op:
3735 reg_mode_test_op (inst, inst_env);
3739 scc_op (inst, inst_env);
3742 case cris_sixteen_bit_offset_branch_op:
3743 sixteen_bit_offset_branch_op (inst, inst_env);
3746 case cris_three_operand_add_sub_cmp_and_or_op:
3747 three_operand_add_sub_cmp_and_or_op (inst, inst_env);
3750 case cris_three_operand_bound_op:
3751 three_operand_bound_op (inst, inst_env);
3754 case cris_two_operand_bound_op:
3755 two_operand_bound_op (inst, inst_env);
3759 xor_op (inst, inst_env);
3764 /* This wrapper is to avoid cris_get_assembler being called before
3765 exec_bfd has been set. */
3768 cris_delayed_get_disassembler (bfd_vma addr, struct disassemble_info *info)
3770 int (*print_insn) (bfd_vma addr, struct disassemble_info *info);
3771 /* FIXME: cagney/2003-08-27: It should be possible to select a CRIS
3772 disassembler, even when there is no BFD. Does something like
3773 "gdb; target remote; disassmeble *0x123" work? */
3774 gdb_assert (exec_bfd != NULL);
3775 print_insn = cris_get_disassembler (exec_bfd);
3776 gdb_assert (print_insn != NULL);
3777 return print_insn (addr, info);
3780 /* Copied from <asm/elf.h>. */
3781 typedef unsigned long elf_greg_t;
3783 /* Same as user_regs_struct struct in <asm/user.h>. */
3784 #define CRISV10_ELF_NGREG 35
3785 typedef elf_greg_t elf_gregset_t[CRISV10_ELF_NGREG];
3787 #define CRISV32_ELF_NGREG 32
3788 typedef elf_greg_t crisv32_elf_gregset_t[CRISV32_ELF_NGREG];
3790 /* Unpack an elf_gregset_t into GDB's register cache. */
3793 supply_gregset (elf_gregset_t *gregsetp)
3795 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3797 elf_greg_t *regp = *gregsetp;
3798 static char zerobuf[4] = {0};
3800 /* The kernel dumps all 32 registers as unsigned longs, but supply_register
3801 knows about the actual size of each register so that's no problem. */
3802 for (i = 0; i < NUM_GENREGS + NUM_SPECREGS; i++)
3804 regcache_raw_supply (current_regcache, i, (char *)®p[i]);
3807 if (tdep->cris_version == 32)
3809 /* Needed to set pseudo-register PC for CRISv32. */
3810 /* FIXME: If ERP is in a delay slot at this point then the PC will
3811 be wrong. Issue a warning to alert the user. */
3812 regcache_raw_supply (current_regcache, PC_REGNUM,
3813 (char *)®p[ERP_REGNUM]);
3815 if (*(char *)®p[ERP_REGNUM] & 0x1)
3816 fprintf_unfiltered (gdb_stderr, "Warning: PC in delay slot\n");
3820 /* Use a local version of this function to get the correct types for
3821 regsets, until multi-arch core support is ready. */
3824 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
3825 int which, CORE_ADDR reg_addr)
3827 elf_gregset_t gregset;
3832 if (core_reg_size != sizeof (elf_gregset_t)
3833 && core_reg_size != sizeof (crisv32_elf_gregset_t))
3835 warning (_("wrong size gregset struct in core file"));
3839 memcpy (&gregset, core_reg_sect, sizeof (gregset));
3840 supply_gregset (&gregset);
3844 /* We've covered all the kinds of registers we know about here,
3845 so this must be something we wouldn't know what to do with
3846 anyway. Just ignore it. */
3851 static struct core_fns cris_elf_core_fns =
3853 bfd_target_elf_flavour, /* core_flavour */
3854 default_check_format, /* check_format */
3855 default_core_sniffer, /* core_sniffer */
3856 fetch_core_registers, /* core_read_registers */
3860 /* Fetch (and possibly build) an appropriate link_map_offsets
3861 structure for native GNU/Linux CRIS targets using the struct
3862 offsets defined in link.h (but without actual reference to that
3865 This makes it possible to access GNU/Linux CRIS shared libraries
3866 from a GDB that was not built on an GNU/Linux CRIS host (for cross
3869 See gdb/solib-svr4.h for an explanation of these fields. */
3871 static struct link_map_offsets *
3872 cris_linux_svr4_fetch_link_map_offsets (void)
3874 static struct link_map_offsets lmo;
3875 static struct link_map_offsets *lmp = NULL;
3881 lmo.r_debug_size = 8; /* The actual size is 20 bytes, but
3882 this is all we need. */
3883 lmo.r_map_offset = 4;
3886 lmo.link_map_size = 20;
3888 lmo.l_addr_offset = 0;
3889 lmo.l_addr_size = 4;
3891 lmo.l_name_offset = 4;
3892 lmo.l_name_size = 4;
3894 lmo.l_next_offset = 12;
3895 lmo.l_next_size = 4;
3897 lmo.l_prev_offset = 16;
3898 lmo.l_prev_size = 4;
3904 extern initialize_file_ftype _initialize_cris_tdep; /* -Wmissing-prototypes */
3907 _initialize_cris_tdep (void)
3909 static struct cmd_list_element *cris_set_cmdlist;
3910 static struct cmd_list_element *cris_show_cmdlist;
3912 struct cmd_list_element *c;
3914 gdbarch_register (bfd_arch_cris, cris_gdbarch_init, cris_dump_tdep);
3916 /* CRIS-specific user-commands. */
3917 add_setshow_uinteger_cmd ("cris-version", class_support,
3918 &usr_cmd_cris_version,
3919 "Set the current CRIS version.",
3920 "Show the current CRIS version.",
3921 "Set if autodetection fails.",
3922 NULL, /* PRINT: Current CRIS version is %s. */
3923 set_cris_version, NULL,
3924 &setlist, &showlist);
3926 add_setshow_boolean_cmd ("cris-dwarf2-cfi", class_support,
3927 &usr_cmd_cris_dwarf2_cfi,
3928 "Set the usage of Dwarf-2 CFI for CRIS.",
3929 "Show the usage of Dwarf-2 CFI for CRIS.",
3930 "Set to \"off\" if using gcc-cris < R59.",
3931 NULL, /* PRINT: Usage of Dwarf-2 CFI for CRIS is %d. */
3932 set_cris_dwarf2_cfi, NULL,
3933 &setlist, &showlist);
3935 deprecated_add_core_fns (&cris_elf_core_fns);
3938 /* Prints out all target specific values. */
3941 cris_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
3943 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3946 fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_version = %i\n",
3947 tdep->cris_version);
3948 fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_dwarf2_cfi = %i\n",
3949 tdep->cris_dwarf2_cfi);
3954 set_cris_version (char *ignore_args, int from_tty,
3955 struct cmd_list_element *c)
3957 struct gdbarch_info info;
3959 usr_cmd_cris_version_valid = 1;
3961 /* Update the current architecture, if needed. */
3962 gdbarch_info_init (&info);
3963 if (!gdbarch_update_p (info))
3964 internal_error (__FILE__, __LINE__,
3965 "cris_gdbarch_update: failed to update architecture.");
3969 set_cris_dwarf2_cfi (char *ignore_args, int from_tty,
3970 struct cmd_list_element *c)
3972 struct gdbarch_info info;
3974 /* Update the current architecture, if needed. */
3975 gdbarch_info_init (&info);
3976 if (!gdbarch_update_p (info))
3977 internal_error (__FILE__, __LINE__,
3978 "cris_gdbarch_update: failed to update architecture.");
3981 static struct gdbarch *
3982 cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
3984 struct gdbarch *gdbarch;
3985 struct gdbarch_tdep *tdep;
3988 if (usr_cmd_cris_version_valid)
3990 /* Trust the user's CRIS version setting. */
3991 cris_version = usr_cmd_cris_version;
3993 else if (info.abfd && bfd_get_mach (info.abfd) == bfd_mach_cris_v32)
3999 /* Assume it's CRIS version 10. */
4003 /* Make the current settings visible to the user. */
4004 usr_cmd_cris_version = cris_version;
4006 /* Find a candidate among the list of pre-declared architectures. Both
4007 CRIS version and ABI must match. */
4008 for (arches = gdbarch_list_lookup_by_info (arches, &info);
4010 arches = gdbarch_list_lookup_by_info (arches->next, &info))
4012 if ((gdbarch_tdep (arches->gdbarch)->cris_version
4013 == usr_cmd_cris_version)
4014 && (gdbarch_tdep (arches->gdbarch)->cris_dwarf2_cfi
4015 == usr_cmd_cris_dwarf2_cfi))
4016 return arches->gdbarch;
4019 /* No matching architecture was found. Create a new one. */
4020 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
4021 gdbarch = gdbarch_alloc (&info, tdep);
4023 tdep->cris_version = usr_cmd_cris_version;
4024 tdep->cris_dwarf2_cfi = usr_cmd_cris_dwarf2_cfi;
4026 /* INIT shall ensure that the INFO.BYTE_ORDER is non-zero. */
4027 switch (info.byte_order)
4029 case BFD_ENDIAN_LITTLE:
4033 case BFD_ENDIAN_BIG:
4034 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: big endian byte order in info");
4038 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unknown byte order in info");
4041 set_gdbarch_return_value (gdbarch, cris_return_value);
4042 set_gdbarch_deprecated_reg_struct_has_addr (gdbarch,
4043 cris_reg_struct_has_addr);
4044 set_gdbarch_deprecated_use_struct_convention (gdbarch, always_use_struct_convention);
4046 set_gdbarch_sp_regnum (gdbarch, 14);
4048 /* Length of ordinary registers used in push_word and a few other
4049 places. register_size() is the real way to know how big a
4052 set_gdbarch_double_bit (gdbarch, 64);
4053 /* The default definition of a long double is 2 * TARGET_DOUBLE_BIT,
4054 which means we have to set this explicitly. */
4055 set_gdbarch_long_double_bit (gdbarch, 64);
4057 /* The total amount of space needed to store (in an array called registers)
4058 GDB's copy of the machine's register state. Note: We can not use
4059 cris_register_size at this point, since it relies on current_gdbarch
4061 switch (tdep->cris_version)
4069 /* Old versions; not supported. */
4070 internal_error (__FILE__, __LINE__,
4071 "cris_gdbarch_init: unsupported CRIS version");
4076 /* CRIS v10 and v11, a.k.a. ETRAX 100LX. In addition to ETRAX 100,
4077 P7 (32 bits), and P15 (32 bits) have been implemented. */
4078 set_gdbarch_pc_regnum (gdbarch, 15);
4079 set_gdbarch_register_type (gdbarch, cris_register_type);
4080 /* There are 32 registers (some of which may not be implemented). */
4081 set_gdbarch_num_regs (gdbarch, 32);
4082 set_gdbarch_register_name (gdbarch, cris_register_name);
4083 set_gdbarch_cannot_store_register (gdbarch, cris_cannot_store_register);
4084 set_gdbarch_cannot_fetch_register (gdbarch, cris_cannot_fetch_register);
4086 set_gdbarch_software_single_step (gdbarch, cris_software_single_step);
4090 /* CRIS v32. General registers R0 - R15 (32 bits), special registers
4091 P0 - P15 (32 bits) except P0, P1, P3 (8 bits) and P4 (16 bits)
4092 and pseudo-register PC (32 bits). */
4093 set_gdbarch_pc_regnum (gdbarch, 32);
4094 set_gdbarch_register_type (gdbarch, crisv32_register_type);
4095 /* 32 registers + pseudo-register PC + 16 support registers. */
4096 set_gdbarch_num_regs (gdbarch, 32 + 1 + 16);
4097 set_gdbarch_register_name (gdbarch, crisv32_register_name);
4099 set_gdbarch_cannot_store_register
4100 (gdbarch, crisv32_cannot_store_register);
4101 set_gdbarch_cannot_fetch_register
4102 (gdbarch, crisv32_cannot_fetch_register);
4104 set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
4106 set_gdbarch_single_step_through_delay
4107 (gdbarch, crisv32_single_step_through_delay);
4112 internal_error (__FILE__, __LINE__,
4113 "cris_gdbarch_init: unknown CRIS version");
4116 /* Dummy frame functions (shared between CRISv10 and CRISv32 since they
4117 have the same ABI). */
4118 set_gdbarch_push_dummy_code (gdbarch, cris_push_dummy_code);
4119 set_gdbarch_push_dummy_call (gdbarch, cris_push_dummy_call);
4120 set_gdbarch_frame_align (gdbarch, cris_frame_align);
4121 set_gdbarch_skip_prologue (gdbarch, cris_skip_prologue);
4123 /* The stack grows downward. */
4124 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
4126 set_gdbarch_breakpoint_from_pc (gdbarch, cris_breakpoint_from_pc);
4128 set_gdbarch_unwind_pc (gdbarch, cris_unwind_pc);
4129 set_gdbarch_unwind_sp (gdbarch, cris_unwind_sp);
4130 set_gdbarch_unwind_dummy_id (gdbarch, cris_unwind_dummy_id);
4132 if (tdep->cris_dwarf2_cfi == 1)
4134 /* Hook in the Dwarf-2 frame sniffer. */
4135 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, cris_dwarf2_reg_to_regnum);
4136 dwarf2_frame_set_init_reg (gdbarch, cris_dwarf2_frame_init_reg);
4137 frame_unwind_append_sniffer (gdbarch, dwarf2_frame_sniffer);
4140 frame_unwind_append_sniffer (gdbarch, cris_sigtramp_frame_sniffer);
4142 frame_unwind_append_sniffer (gdbarch, cris_frame_sniffer);
4143 frame_base_set_default (gdbarch, &cris_frame_base);
4145 /* Use target_specific function to define link map offsets. */
4146 set_solib_svr4_fetch_link_map_offsets
4147 (gdbarch, cris_linux_svr4_fetch_link_map_offsets);
4149 /* FIXME: cagney/2003-08-27: It should be possible to select a CRIS
4150 disassembler, even when there is no BFD. Does something like
4151 "gdb; target remote; disassmeble *0x123" work? */
4152 set_gdbarch_print_insn (gdbarch, cris_delayed_get_disassembler);