1 /* Target dependent code for CRIS, for GDB, the GNU debugger.
2 Copyright 2001 Free Software Foundation, Inc.
3 Contributed by Axis Communications AB.
4 Written by Hendrik Ruijter, Stefan Andersson, and Orjan Friberg.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
31 #include "opcode/cris.h"
32 #include "arch-utils.h"
35 /* To get entry_point_address. */
38 #include "solib.h" /* Support for shared libraries. */
39 #include "solib-svr4.h" /* For struct link_map_offsets. */
44 /* There are no floating point registers. Used in gdbserver low-linux.c. */
47 /* There are 16 general registers. */
50 /* There are 16 special registers. */
54 /* Register numbers of various important registers.
55 FP_REGNUM Contains address of executing stack frame.
56 STR_REGNUM Contains the address of structure return values.
57 RET_REGNUM Contains the return value when shorter than or equal to 32 bits
58 ARG1_REGNUM Contains the first parameter to a function.
59 ARG2_REGNUM Contains the second parameter to a function.
60 ARG3_REGNUM Contains the third parameter to a function.
61 ARG4_REGNUM Contains the fourth parameter to a function. Rest on stack.
62 SP_REGNUM Contains address of top of stack.
63 PC_REGNUM Contains address of next instruction.
64 SRP_REGNUM Subroutine return pointer register.
65 BRP_REGNUM Breakpoint return pointer register. */
67 /* FP_REGNUM = 8, SP_REGNUM = 14, and PC_REGNUM = 15 have been incorporated
68 into the multi-arch framework. */
72 /* Enums with respect to the general registers, valid for all
81 /* Enums with respect to the special registers, some of which may not be
82 applicable to all CRIS versions. */
100 extern const struct cris_spec_reg cris_spec_regs[];
102 /* CRIS version, set via the user command 'set cris-version'. Affects
103 register names and sizes.*/
104 static int usr_cmd_cris_version;
106 /* Indicates whether to trust the above variable. */
107 static int usr_cmd_cris_version_valid = 0;
109 /* CRIS mode, set via the user command 'set cris-mode'. Affects availability
110 of some registers. */
111 static const char *usr_cmd_cris_mode;
113 /* Indicates whether to trust the above variable. */
114 static int usr_cmd_cris_mode_valid = 0;
116 static const char CRIS_MODE_USER[] = "CRIS_MODE_USER";
117 static const char CRIS_MODE_SUPERVISOR[] = "CRIS_MODE_SUPERVISOR";
118 static const char *cris_mode_enums[] =
121 CRIS_MODE_SUPERVISOR,
125 /* CRIS ABI, set via the user command 'set cris-abi'.
126 There are two flavours:
127 1. Original ABI with 32-bit doubles, where arguments <= 4 bytes are
129 2. New ABI with 64-bit doubles, where arguments <= 8 bytes are passed by
131 static const char *usr_cmd_cris_abi;
133 /* Indicates whether to trust the above variable. */
134 static int usr_cmd_cris_abi_valid = 0;
136 /* These variables are strings instead of enums to make them usable as
137 parameters to add_set_enum_cmd. */
138 static const char CRIS_ABI_ORIGINAL[] = "CRIS_ABI_ORIGINAL";
139 static const char CRIS_ABI_V2[] = "CRIS_ABI_V2";
140 static const char CRIS_ABI_SYMBOL[] = ".$CRIS_ABI_V2";
141 static const char *cris_abi_enums[] =
148 /* CRIS architecture specific information. */
152 const char *cris_mode;
153 const char *cris_abi;
156 /* Functions for accessing target dependent data. */
161 return (gdbarch_tdep (current_gdbarch)->cris_version);
167 return (gdbarch_tdep (current_gdbarch)->cris_mode);
173 return (gdbarch_tdep (current_gdbarch)->cris_abi);
176 /* For saving call-clobbered contents in R9 when returning structs. */
177 static CORE_ADDR struct_return_address;
179 struct frame_extra_info
185 /* The instruction environment needed to find single-step breakpoints. */
187 struct instruction_environment
189 unsigned long reg[NUM_GENREGS];
190 unsigned long preg[NUM_SPECREGS];
191 unsigned long branch_break_address;
192 unsigned long delay_slot_pc;
193 unsigned long prefix_value;
198 int delay_slot_pc_active;
200 int disable_interrupt;
203 /* Save old breakpoints in order to restore the state before a single_step.
204 At most, two breakpoints will have to be remembered. */
206 char binsn_quantum[BREAKPOINT_MAX];
207 static binsn_quantum break_mem[2];
208 static CORE_ADDR next_pc = 0;
209 static CORE_ADDR branch_target_address = 0;
210 static unsigned char branch_break_inserted = 0;
212 /* Machine-dependencies in CRIS for opcodes. */
214 /* Instruction sizes. */
215 enum cris_instruction_sizes
222 /* Addressing modes. */
223 enum cris_addressing_modes
230 /* Prefix addressing modes. */
231 enum cris_prefix_addressing_modes
233 PREFIX_INDEX_MODE = 2,
234 PREFIX_ASSIGN_MODE = 3,
236 /* Handle immediate byte offset addressing mode prefix format. */
237 PREFIX_OFFSET_MODE = 2
240 /* Masks for opcodes. */
241 enum cris_opcode_masks
243 BRANCH_SIGNED_SHORT_OFFSET_MASK = 0x1,
244 SIGNED_EXTEND_BIT_MASK = 0x2,
245 SIGNED_BYTE_MASK = 0x80,
246 SIGNED_BYTE_EXTEND_MASK = 0xFFFFFF00,
247 SIGNED_WORD_MASK = 0x8000,
248 SIGNED_WORD_EXTEND_MASK = 0xFFFF0000,
249 SIGNED_DWORD_MASK = 0x80000000,
250 SIGNED_QUICK_VALUE_MASK = 0x20,
251 SIGNED_QUICK_VALUE_EXTEND_MASK = 0xFFFFFFC0
254 /* Functions for opcodes. The general form of the ETRAX 16-bit instruction:
262 cris_get_operand2 (unsigned short insn)
264 return ((insn & 0xF000) >> 12);
268 cris_get_mode (unsigned short insn)
270 return ((insn & 0x0C00) >> 10);
274 cris_get_opcode (unsigned short insn)
276 return ((insn & 0x03C0) >> 6);
280 cris_get_size (unsigned short insn)
282 return ((insn & 0x0030) >> 4);
286 cris_get_operand1 (unsigned short insn)
288 return (insn & 0x000F);
291 /* Additional functions in order to handle opcodes. */
294 cris_get_wide_opcode (unsigned short insn)
296 return ((insn & 0x03E0) >> 5);
300 cris_get_short_size (unsigned short insn)
302 return ((insn & 0x0010) >> 4);
306 cris_get_quick_value (unsigned short insn)
308 return (insn & 0x003F);
312 cris_get_bdap_quick_offset (unsigned short insn)
314 return (insn & 0x00FF);
318 cris_get_branch_short_offset (unsigned short insn)
320 return (insn & 0x00FF);
324 cris_get_asr_shift_steps (unsigned long value)
326 return (value & 0x3F);
330 cris_get_asr_quick_shift_steps (unsigned short insn)
332 return (insn & 0x1F);
336 cris_get_clear_size (unsigned short insn)
338 return ((insn) & 0xC000);
342 cris_is_signed_extend_bit_on (unsigned short insn)
344 return (((insn) & 0x20) == 0x20);
348 cris_is_xflag_bit_on (unsigned short insn)
350 return (((insn) & 0x1000) == 0x1000);
354 cris_set_size_to_dword (unsigned short *insn)
361 cris_get_signed_offset (unsigned short insn)
363 return ((signed char) (insn & 0x00FF));
366 /* Calls an op function given the op-type, working on the insn and the
368 static void cris_gdb_func (enum cris_op_type, unsigned short, inst_env_type *);
370 static CORE_ADDR cris_skip_prologue_main (CORE_ADDR pc, int frameless_p);
372 static struct gdbarch *cris_gdbarch_init (struct gdbarch_info,
373 struct gdbarch_list *);
375 static int cris_delayed_get_disassembler (bfd_vma, disassemble_info *);
377 static void cris_dump_tdep (struct gdbarch *, struct ui_file *);
379 static void cris_version_update (char *ignore_args, int from_tty,
380 struct cmd_list_element *c);
382 static void cris_mode_update (char *ignore_args, int from_tty,
383 struct cmd_list_element *c);
385 static void cris_abi_update (char *ignore_args, int from_tty,
386 struct cmd_list_element *c);
388 static CORE_ADDR bfd_lookup_symbol (bfd *, const char *);
390 /* Frames information. The definition of the struct frame_info is
394 int signal_handler_caller
398 If the compilation option -fno-omit-frame-pointer is present the
399 variable frame will be set to the content of R8 which is the frame
402 The variable pc contains the address where execution is performed
403 in the present frame. The innermost frame contains the current content
404 of the register PC. All other frames contain the content of the
405 register PC in the next frame.
407 The variable signal_handler_caller is non-zero when the frame is
408 associated with the call of a signal handler.
410 The variable return_pc contains the address where execution should be
411 resumed when the present frame has finished, the return address.
413 The variable leaf_function is 1 if the return address is in the register
414 SRP, and 0 if it is on the stack.
416 Prologue instructions C-code.
417 The prologue may consist of (-fno-omit-frame-pointer)
421 move.d sp,r8 move.d sp,r8
423 movem rY,[sp] movem rY,[sp]
424 move.S rZ,[r8-U] move.S rZ,[r8-U]
426 where 1 is a non-terminal function, and 2 is a leaf-function.
428 Note that this assumption is extremely brittle, and will break at the
429 slightest change in GCC's prologue.
431 If local variables are declared or register contents are saved on stack
432 the subq-instruction will be present with X as the number of bytes
433 needed for storage. The reshuffle with respect to r8 may be performed
434 with any size S (b, w, d) and any of the general registers Z={0..13}.
435 The offset U should be representable by a signed 8-bit value in all cases.
436 Thus, the prefix word is assumed to be immediate byte offset mode followed
437 by another word containing the instruction.
446 Prologue instructions C++-code.
447 Case 1) and 2) in the C-code may be followed by
453 move.S [r8+U],rZ ; P4
455 if any of the call parameters are stored. The host expects these
456 instructions to be executed in order to get the call parameters right. */
458 /* Examine the prologue of a function. The variable ip is the address of
459 the first instruction of the prologue. The variable limit is the address
460 of the first instruction after the prologue. The variable fi contains the
461 information in struct frame_info. The variable frameless_p controls whether
462 the entire prologue is examined (0) or just enough instructions to
463 determine that it is a prologue (1). */
466 cris_examine (CORE_ADDR ip, CORE_ADDR limit, struct frame_info *fi,
469 /* Present instruction. */
472 /* Next instruction, lookahead. */
473 unsigned short insn_next;
476 /* Is there a push fp? */
479 /* Number of byte on stack used for local variables and movem. */
482 /* Highest register number in a movem. */
485 /* move.d r<source_register>,rS */
486 short source_register;
488 /* This frame is with respect to a leaf until a push srp is found. */
489 fi->extra_info->leaf_function = 1;
491 /* This frame is without the FP until a push fp is found. */
494 /* Assume nothing on stack. */
498 /* No information about register contents so far. */
500 /* We only want to know the end of the prologue when fi->saved_regs == 0.
501 When the saved registers are allocated full information is required. */
504 for (regno = 0; regno < NUM_REGS; regno++)
505 fi->saved_regs[regno] = 0;
508 /* Find the prologue instructions. */
511 insn = read_memory_unsigned_integer (ip, sizeof (short));
512 ip += sizeof (short);
515 /* push <reg> 32 bit instruction */
516 insn_next = read_memory_unsigned_integer (ip, sizeof (short));
517 ip += sizeof (short);
518 regno = cris_get_operand2 (insn_next);
520 /* This check, meant to recognize srp, used to be regno ==
521 (SRP_REGNUM - NUM_GENREGS), but that covers r11 also. */
522 if (insn_next == 0xBE7E)
528 fi->extra_info->leaf_function = 0;
530 else if (regno == FP_REGNUM)
535 else if (insn == 0x866E)
544 else if (cris_get_operand2 (insn) == SP_REGNUM
545 && cris_get_mode (insn) == 0x0000
546 && cris_get_opcode (insn) == 0x000A)
549 val = cris_get_quick_value (insn);
551 else if (cris_get_mode (insn) == 0x0002
552 && cris_get_opcode (insn) == 0x000F
553 && cris_get_size (insn) == 0x0003
554 && cris_get_operand1 (insn) == SP_REGNUM)
556 /* movem r<regsave>,[sp] */
561 regsave = cris_get_operand2 (insn);
563 else if (cris_get_operand2 (insn) == SP_REGNUM
564 && ((insn & 0x0F00) >> 8) == 0x0001
565 && (cris_get_signed_offset (insn) < 0))
567 /* Immediate byte offset addressing prefix word with sp as base
568 register. Used for CRIS v8 i.e. ETRAX 100 and newer if <val>
569 is between 64 and 128.
570 movem r<regsave>,[sp=sp-<val>] */
571 val = -cris_get_signed_offset (insn);
572 insn_next = read_memory_unsigned_integer (ip, sizeof (short));
573 ip += sizeof (short);
574 if (cris_get_mode (insn_next) == PREFIX_ASSIGN_MODE
575 && cris_get_opcode (insn_next) == 0x000F
576 && cris_get_size (insn_next) == 0x0003
577 && cris_get_operand1 (insn_next) == SP_REGNUM)
583 regsave = cris_get_operand2 (insn_next);
587 /* The prologue ended before the limit was reached. */
588 ip -= 2 * sizeof (short);
592 else if (cris_get_mode (insn) == 0x0001
593 && cris_get_opcode (insn) == 0x0009
594 && cris_get_size (insn) == 0x0002)
596 /* move.d r<10..13>,r<0..15> */
601 source_register = cris_get_operand1 (insn);
603 /* FIXME? In the glibc solibs, the prologue might contain something
604 like (this example taken from relocate_doit):
607 which isn't covered by the source_register check below. Question
608 is whether to add a check for this combo, or make better use of
609 the limit variable instead. */
610 if (source_register < ARG1_REGNUM || source_register > ARG4_REGNUM)
612 /* The prologue ended before the limit was reached. */
613 ip -= sizeof (short);
617 else if (cris_get_operand2 (insn) == FP_REGNUM
618 /* The size is a fixed-size. */
619 && ((insn & 0x0F00) >> 8) == 0x0001
620 /* A negative offset. */
621 && (cris_get_signed_offset (insn) < 0))
623 /* move.S rZ,[r8-U] (?) */
624 insn_next = read_memory_unsigned_integer (ip, sizeof (short));
625 ip += sizeof (short);
626 regno = cris_get_operand2 (insn_next);
627 if ((regno >= 0 && regno < SP_REGNUM)
628 && cris_get_mode (insn_next) == PREFIX_OFFSET_MODE
629 && cris_get_opcode (insn_next) == 0x000F)
631 /* move.S rZ,[r8-U] */
636 /* The prologue ended before the limit was reached. */
637 ip -= 2 * sizeof (short);
641 else if (cris_get_operand2 (insn) == FP_REGNUM
642 /* The size is a fixed-size. */
643 && ((insn & 0x0F00) >> 8) == 0x0001
644 /* A positive offset. */
645 && (cris_get_signed_offset (insn) > 0))
647 /* move.S [r8+U],rZ (?) */
648 insn_next = read_memory_unsigned_integer (ip, sizeof (short));
649 ip += sizeof (short);
650 regno = cris_get_operand2 (insn_next);
651 if ((regno >= 0 && regno < SP_REGNUM)
652 && cris_get_mode (insn_next) == PREFIX_OFFSET_MODE
653 && cris_get_opcode (insn_next) == 0x0009
654 && cris_get_operand1 (insn_next) == regno)
656 /* move.S [r8+U],rZ */
661 /* The prologue ended before the limit was reached. */
662 ip -= 2 * sizeof (short);
668 /* The prologue ended before the limit was reached. */
669 ip -= sizeof (short);
675 /* We only want to know the end of the prologue when
676 fi->saved_regs == 0. */
682 fi->saved_regs[FP_REGNUM] = FRAME_FP (fi);
684 /* Calculate the addresses. */
685 for (regno = regsave; regno >= 0; regno--)
687 fi->saved_regs[regno] = FRAME_FP (fi) - val;
690 if (fi->extra_info->leaf_function)
692 /* Set the register SP to contain the stack pointer of
694 fi->saved_regs[SP_REGNUM] = FRAME_FP (fi) + 4;
698 /* Set the register SP to contain the stack pointer of
700 fi->saved_regs[SP_REGNUM] = FRAME_FP (fi) + 8;
702 /* Set the register SRP to contain the return address of
704 fi->saved_regs[SRP_REGNUM] = FRAME_FP (fi) + 4;
710 /* Advance pc beyond any function entry prologue instructions at pc
711 to reach some "real" code. */
714 cris_skip_prologue (CORE_ADDR pc)
716 return cris_skip_prologue_main (pc, 0);
719 /* As cris_skip_prologue, but stops as soon as it knows that the function
720 has a frame. Its result is equal to its input pc if the function is
721 frameless, unequal otherwise. */
724 cris_skip_prologue_frameless_p (CORE_ADDR pc)
726 return cris_skip_prologue_main (pc, 1);
729 /* Given a PC value corresponding to the start of a function, return the PC
730 of the first instruction after the function prologue. */
733 cris_skip_prologue_main (CORE_ADDR pc, int frameless_p)
735 struct frame_info fi;
736 static struct frame_extra_info fei;
737 struct symtab_and_line sal = find_pc_line (pc, 0);
739 CORE_ADDR pc_after_prologue;
741 /* frame_info now contains dynamic memory. Since fi is a dummy here,
742 I use static memory for extra_info, and don't bother allocating
743 memory for saved_regs. */
745 fi.extra_info = &fei;
747 /* If there is no symbol information then sal.end == 0, and we end up
748 examining only the first instruction in the function prologue.
749 Exaggerating the limit seems to be harmless. */
751 best_limit = sal.end;
753 best_limit = pc + 100;
755 pc_after_prologue = cris_examine (pc, best_limit, &fi, frameless_p);
756 return pc_after_prologue;
759 /* Use the program counter to determine the contents and size of a breakpoint
760 instruction. It returns a pointer to a string of bytes that encode a
761 breakpoint instruction, stores the length of the string to *lenptr, and
762 adjusts pcptr (if necessary) to point to the actual memory location where
763 the breakpoint should be inserted. */
765 const unsigned char *
766 cris_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
768 static unsigned char break_insn[] = {0x38, 0xe9};
774 /* Returns the register SRP (subroutine return pointer) which must contain
775 the content of the register PC after a function call. */
778 cris_saved_pc_after_call (struct frame_info *frame)
780 return read_register (SRP_REGNUM);
783 /* Returns 1 if spec_reg is applicable to the current gdbarch's CRIS version,
787 cris_spec_reg_applicable (struct cris_spec_reg spec_reg)
789 int version = cris_version ();
791 switch (spec_reg.applicable_version)
793 case cris_ver_version_all:
795 case cris_ver_warning:
796 /* Indeterminate/obsolete. */
799 /* Simulator only. */
802 return (version >= 0 && version <= 3);
804 return (version >= 3);
806 return (version == 8 || version == 9);
808 return (version >= 8);
810 return (version >= 10);
812 /* Invalid cris version. */
817 /* Returns the register size in unit byte. Returns 0 for an unimplemented
818 register, -1 for an invalid register. */
821 cris_register_size (int regno)
826 if (regno >= 0 && regno < NUM_GENREGS)
828 /* General registers (R0 - R15) are 32 bits. */
831 else if (regno >= NUM_GENREGS && regno < NUM_REGS)
833 /* Special register (R16 - R31). cris_spec_regs is zero-based.
834 Adjust regno accordingly. */
835 spec_regno = regno - NUM_GENREGS;
837 /* The entries in cris_spec_regs are stored in register number order,
838 which means we can shortcut into the array when searching it. */
839 for (i = spec_regno; cris_spec_regs[i].name != NULL; i++)
841 if (cris_spec_regs[i].number == spec_regno
842 && cris_spec_reg_applicable (cris_spec_regs[i]))
843 /* Go with the first applicable register. */
844 return cris_spec_regs[i].reg_size;
846 /* Special register not applicable to this CRIS version. */
851 /* Invalid register. */
856 /* Nonzero if regno should not be fetched from the target. This is the case
857 for unimplemented (size 0) and non-existant registers. */
860 cris_cannot_fetch_register (int regno)
862 return ((regno < 0 || regno >= NUM_REGS)
863 || (cris_register_size (regno) == 0));
866 /* Nonzero if regno should not be written to the target, for various
870 cris_cannot_store_register (int regno)
872 /* There are three kinds of registers we refuse to write to.
873 1. Those that not implemented.
874 2. Those that are read-only (depends on the processor mode).
875 3. Those registers to which a write has no effect.
878 if (regno < 0 || regno >= NUM_REGS || cris_register_size (regno) == 0)
879 /* Not implemented. */
882 else if (regno == VR_REGNUM)
886 else if (regno == P0_REGNUM || regno == P4_REGNUM || regno == P8_REGNUM)
887 /* Writing has no effect. */
890 else if (cris_mode () == CRIS_MODE_USER)
892 if (regno == IBR_REGNUM || regno == BAR_REGNUM || regno == BRP_REGNUM
893 || regno == IRP_REGNUM)
894 /* Read-only in user mode. */
901 /* Returns the register offset for the first byte of register regno's space
902 in the saved register state. Returns -1 for an invalid or unimplemented
906 cris_register_offset (int regno)
912 if (regno >= 0 && regno < NUM_REGS)
914 /* FIXME: The offsets should be cached and calculated only once,
915 when the architecture being debugged has changed. */
916 for (i = 0; i < regno; i++)
917 offset += cris_register_size (i);
923 /* Invalid register. */
928 /* Return the GDB type (defined in gdbtypes.c) for the "standard" data type
929 of data in register regno. */
932 cris_register_virtual_type (int regno)
934 if (regno == SP_REGNUM || regno == PC_REGNUM
935 || (regno > P8_REGNUM && regno < USP_REGNUM))
937 /* SP, PC, IBR, IRP, SRP, BAR, DCCR, BRP */
938 return lookup_pointer_type (builtin_type_void);
940 else if (regno == P8_REGNUM || regno == USP_REGNUM
941 || (regno >= 0 && regno < SP_REGNUM))
943 /* R0 - R13, P8, P15 */
944 return builtin_type_unsigned_long;
946 else if (regno > P3_REGNUM && regno < P8_REGNUM)
948 /* P4, CCR, DCR0, DCR1 */
949 return builtin_type_unsigned_short;
951 else if (regno > PC_REGNUM && regno < P4_REGNUM)
954 return builtin_type_unsigned_char;
958 /* Invalid register. */
959 return builtin_type_void;
963 /* Stores a function return value of type type, where valbuf is the address
964 of the value to be stored. */
966 /* In the original CRIS ABI, R10 is used to store return values. */
969 cris_abi_original_store_return_value (struct type *type, char *valbuf)
971 int len = TYPE_LENGTH (type);
973 if (len <= REGISTER_SIZE)
974 write_register_bytes (REGISTER_BYTE (RET_REGNUM), valbuf, len);
976 internal_error (__FILE__, __LINE__, "cris_abi_original_store_return_value: type length too large.");
979 /* In the CRIS ABI V2, R10 and R11 are used to store return values. */
982 cris_abi_v2_store_return_value (struct type *type, char *valbuf)
984 int len = TYPE_LENGTH (type);
986 if (len <= 2 * REGISTER_SIZE)
988 /* Note that this works since R10 and R11 are consecutive registers. */
989 write_register_bytes (REGISTER_BYTE (RET_REGNUM), valbuf, len);
992 internal_error (__FILE__, __LINE__, "cris_abi_v2_store_return_value: type length too large.");
995 /* Return the name of register regno as a string. Return NULL for an invalid or
996 unimplemented register. */
999 cris_register_name (int regno)
1001 static char *cris_genreg_names[] =
1002 { "r0", "r1", "r2", "r3", \
1003 "r4", "r5", "r6", "r7", \
1004 "r8", "r9", "r10", "r11", \
1005 "r12", "r13", "sp", "pc" };
1010 if (regno >= 0 && regno < NUM_GENREGS)
1012 /* General register. */
1013 return cris_genreg_names[regno];
1015 else if (regno >= NUM_GENREGS && regno < NUM_REGS)
1017 /* Special register (R16 - R31). cris_spec_regs is zero-based.
1018 Adjust regno accordingly. */
1019 spec_regno = regno - NUM_GENREGS;
1021 /* The entries in cris_spec_regs are stored in register number order,
1022 which means we can shortcut into the array when searching it. */
1023 for (i = spec_regno; cris_spec_regs[i].name != NULL; i++)
1025 if (cris_spec_regs[i].number == spec_regno
1026 && cris_spec_reg_applicable (cris_spec_regs[i]))
1027 /* Go with the first applicable register. */
1028 return cris_spec_regs[i].name;
1030 /* Special register not applicable to this CRIS version. */
1035 /* Invalid register. */
1041 cris_register_bytes_ok (long bytes)
1043 return (bytes == REGISTER_BYTES);
1046 /* Extract from an array regbuf containing the raw register state a function
1047 return value of type type, and copy that, in virtual format, into
1050 /* In the original CRIS ABI, R10 is used to return values. */
1053 cris_abi_original_extract_return_value (struct type *type, char *regbuf,
1056 int len = TYPE_LENGTH (type);
1058 if (len <= REGISTER_SIZE)
1059 memcpy (valbuf, regbuf + REGISTER_BYTE (RET_REGNUM), len);
1061 internal_error (__FILE__, __LINE__, "cris_abi_original_extract_return_value: type length too large");
1064 /* In the CRIS ABI V2, R10 and R11 are used to store return values. */
1067 cris_abi_v2_extract_return_value (struct type *type, char *regbuf,
1070 int len = TYPE_LENGTH (type);
1072 if (len <= 2 * REGISTER_SIZE)
1073 memcpy (valbuf, regbuf + REGISTER_BYTE (RET_REGNUM), len);
1075 internal_error (__FILE__, __LINE__, "cris_abi_v2_extract_return_value: type length too large");
1078 /* Store the address of the place in which to copy the structure the
1079 subroutine will return. In the CRIS ABI, R9 is used in order to pass
1080 the address of the allocated area where a structure return value must
1081 be stored. R9 is call-clobbered, which means we must save it here for
1085 cris_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
1087 write_register (STR_REGNUM, addr);
1088 struct_return_address = addr;
1091 /* Extract from regbuf the address where a function should return a
1092 structure value. It's not there in the CRIS ABI, so we must do it another
1096 cris_extract_struct_value_address (char *regbuf)
1098 return struct_return_address;
1101 /* Returns 1 if a value of the given type being returned from a function
1102 must have space allocated for it on the stack. gcc_p is true if the
1103 function being considered is known to have been compiled by GCC.
1104 In the CRIS ABI, structure return values are passed to the called
1105 function by reference in register R9 to a caller-allocated area, so
1106 this is always true. */
1109 cris_use_struct_convention (int gcc_p, struct type *type)
1114 /* Returns 1 if the given type will be passed by pointer rather than
1117 /* In the original CRIS ABI, arguments shorter than or equal to 32 bits are
1121 cris_abi_original_reg_struct_has_addr (int gcc_p, struct type *type)
1123 return (TYPE_LENGTH (type) > 4);
1126 /* In the CRIS ABI V2, arguments shorter than or equal to 64 bits are passed
1130 cris_abi_v2_reg_struct_has_addr (int gcc_p, struct type *type)
1132 return (TYPE_LENGTH (type) > 8);
1135 /* Returns 1 if the function invocation represented by fi does not have a
1136 stack frame associated with it. Otherwise return 0. */
1139 cris_frameless_function_invocation (struct frame_info *fi)
1141 if (fi->signal_handler_caller)
1144 return frameless_look_for_prologue (fi);
1147 /* See frame.h. Determines the address of all registers in the current stack
1148 frame storing each in frame->saved_regs. Space for frame->saved_regs shall
1149 be allocated by FRAME_INIT_SAVED_REGS using either frame_saved_regs_zalloc
1150 or frame_obstack_alloc. */
1153 cris_frame_init_saved_regs (struct frame_info *fi)
1156 struct symtab_and_line sal;
1158 char *dummy_regs = deprecated_generic_find_dummy_frame (fi->pc, fi->frame);
1160 /* Examine the entire prologue. */
1161 register int frameless_p = 0;
1163 /* Has this frame's registers already been initialized? */
1167 frame_saved_regs_zalloc (fi);
1171 /* I don't see this ever happening, considering the context in which
1172 cris_frame_init_saved_regs is called (always when we're not in
1174 memcpy (&fi->saved_regs, dummy_regs, sizeof (fi->saved_regs));
1178 ip = get_pc_function_start (fi->pc);
1179 sal = find_pc_line (ip, 0);
1181 /* If there is no symbol information then sal.end == 0, and we end up
1182 examining only the first instruction in the function prologue.
1183 Exaggerating the limit seems to be harmless. */
1185 best_limit = sal.end;
1187 best_limit = ip + 100;
1189 cris_examine (ip, best_limit, fi, frameless_p);
1193 /* Initialises the extra frame information at the creation of a new frame.
1194 The inparameter fromleaf is 0 when the call is from create_new_frame.
1195 When the call is from get_prev_frame_info, fromleaf is determined by
1196 cris_frameless_function_invocation. */
1199 cris_init_extra_frame_info (int fromleaf, struct frame_info *fi)
1203 /* Called from get_prev_frame. */
1204 fi->pc = FRAME_SAVED_PC (fi->next);
1207 fi->extra_info = (struct frame_extra_info *)
1208 frame_obstack_alloc (sizeof (struct frame_extra_info));
1210 fi->extra_info->return_pc = 0;
1211 fi->extra_info->leaf_function = 0;
1213 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
1215 /* We need to setup fi->frame here because run_stack_dummy gets it wrong
1216 by assuming it's always FP. */
1217 fi->frame = generic_read_register_dummy (fi->pc, fi->frame, SP_REGNUM);
1218 fi->extra_info->return_pc =
1219 generic_read_register_dummy (fi->pc, fi->frame, PC_REGNUM);
1221 /* FIXME: Is this necessarily true? */
1222 fi->extra_info->leaf_function = 0;
1226 cris_frame_init_saved_regs (fi);
1228 /* Check fromleaf/frameless_function_invocation. (FIXME) */
1230 if (fi->saved_regs[SRP_REGNUM] != 0)
1232 /* SRP was saved on the stack; non-leaf function. */
1233 fi->extra_info->return_pc =
1234 read_memory_integer (fi->saved_regs[SRP_REGNUM],
1235 REGISTER_RAW_SIZE (SRP_REGNUM));
1239 /* SRP is still in a register; leaf function. */
1240 fi->extra_info->return_pc = read_register (SRP_REGNUM);
1241 /* FIXME: Should leaf_function be set to 1 here? */
1242 fi->extra_info->leaf_function = 1;
1247 /* Return the content of the frame pointer in the present frame. In other
1248 words, determine the address of the calling function's frame. */
1251 cris_frame_chain (struct frame_info *fi)
1253 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
1257 else if (!inside_entry_file (fi->pc))
1259 return read_memory_unsigned_integer (FRAME_FP (fi), 4);
1267 /* Return the saved PC (which equals the return address) of this frame. */
1270 cris_frame_saved_pc (struct frame_info *fi)
1272 return fi->extra_info->return_pc;
1275 /* Return the address of the argument block for the frame described
1276 by struct frame_info. */
1279 cris_frame_args_address (struct frame_info *fi)
1281 return FRAME_FP (fi);
1284 /* Return the address of the locals block for the frame
1285 described by struct frame_info. */
1288 cris_frame_locals_address (struct frame_info *fi)
1290 return FRAME_FP (fi);
1293 /* Setup the function arguments for calling a function in the inferior. */
1296 cris_abi_original_push_arguments (int nargs, struct value **args,
1297 CORE_ADDR sp, int struct_return,
1298 CORE_ADDR struct_addr)
1309 /* Data and parameters reside in different areas on the stack.
1310 Both frame pointers grow toward higher addresses. */
1311 CORE_ADDR fp_params;
1314 /* Are we returning a value using a structure return or a normal value
1315 return? struct_addr is the address of the reserved space for the return
1316 structure to be written on the stack. */
1319 write_register (STR_REGNUM, struct_addr);
1322 /* Make sure there's space on the stack. Allocate space for data and a
1323 parameter to refer to that data. */
1324 for (argnum = 0, stack_alloc = 0; argnum < nargs; argnum++)
1325 stack_alloc += (TYPE_LENGTH (VALUE_TYPE (args[argnum])) + REGISTER_SIZE);
1327 /* We may over-allocate a little here, but that won't hurt anything. */
1329 /* Initialize stack frame pointers. */
1331 fp_data = sp + (nargs * REGISTER_SIZE);
1333 /* Now load as many as possible of the first arguments into
1334 registers, and push the rest onto the stack. */
1335 argreg = ARG1_REGNUM;
1338 for (argnum = 0; argnum < nargs; argnum++)
1340 type = VALUE_TYPE (args[argnum]);
1341 len = TYPE_LENGTH (type);
1342 val = (char *) VALUE_CONTENTS (args[argnum]);
1344 if (len <= REGISTER_SIZE && argreg <= ARG4_REGNUM)
1346 /* Data fits in a register; put it in the first available
1348 write_register (argreg, *(unsigned long *) val);
1351 else if (len > REGISTER_SIZE && argreg <= ARG4_REGNUM)
1353 /* Data does not fit in register; pass it on the stack and
1354 put its address in the first available register. */
1355 write_memory (fp_data, val, len);
1356 write_register (argreg, fp_data);
1360 else if (len > REGISTER_SIZE)
1362 /* Data does not fit in register; put both data and
1363 parameter on the stack. */
1364 write_memory (fp_data, val, len);
1365 write_memory (fp_params, (char *) (&fp_data), REGISTER_SIZE);
1367 fp_params += REGISTER_SIZE;
1371 /* Data fits in a register, but we are out of registers;
1372 put the parameter on the stack. */
1373 write_memory (fp_params, val, REGISTER_SIZE);
1374 fp_params += REGISTER_SIZE;
1382 cris_abi_v2_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
1383 int struct_return, CORE_ADDR struct_addr)
1392 /* The function's arguments and memory allocated by gdb for the arguments to
1393 point at reside in separate areas on the stack.
1394 Both frame pointers grow toward higher addresses. */
1398 /* Are we returning a value using a structure return or a normal value
1399 return? struct_addr is the address of the reserved space for the return
1400 structure to be written on the stack. */
1403 write_register (STR_REGNUM, struct_addr);
1406 /* Allocate enough to keep things word-aligned on both parts of the
1409 for (argnum = 0; argnum < nargs; argnum++)
1414 len = TYPE_LENGTH (VALUE_TYPE (args[argnum]));
1415 reg_demand = (len / REGISTER_SIZE) + (len % REGISTER_SIZE != 0 ? 1 : 0);
1417 /* reg_demand * REGISTER_SIZE is the amount of memory we might need to
1418 allocate for this argument. 2 * REGISTER_SIZE is the amount of stack
1419 space we might need to pass the argument itself (either by value or by
1421 stack_alloc += (reg_demand * REGISTER_SIZE + 2 * REGISTER_SIZE);
1424 /* We may over-allocate a little here, but that won't hurt anything. */
1426 /* Initialize frame pointers. */
1428 fp_mem = sp + (nargs * (2 * REGISTER_SIZE));
1430 /* Now load as many as possible of the first arguments into registers,
1431 and push the rest onto the stack. */
1432 argreg = ARG1_REGNUM;
1435 for (argnum = 0; argnum < nargs; argnum++)
1442 len = TYPE_LENGTH (VALUE_TYPE (args[argnum]));
1443 val = (char *) VALUE_CONTENTS (args[argnum]);
1445 /* How may registers worth of storage do we need for this argument? */
1446 reg_demand = (len / REGISTER_SIZE) + (len % REGISTER_SIZE != 0 ? 1 : 0);
1448 if (len <= (2 * REGISTER_SIZE)
1449 && (argreg + reg_demand - 1 <= ARG4_REGNUM))
1451 /* Data passed by value. Fits in available register(s). */
1452 for (i = 0; i < reg_demand; i++)
1454 write_register (argreg, *(unsigned long *) val);
1456 val += REGISTER_SIZE;
1459 else if (len <= (2 * REGISTER_SIZE) && argreg <= ARG4_REGNUM)
1461 /* Data passed by value. Does not fit in available register(s).
1462 Use the register(s) first, then the stack. */
1463 for (i = 0; i < reg_demand; i++)
1465 if (argreg <= ARG4_REGNUM)
1467 write_register (argreg, *(unsigned long *) val);
1469 val += REGISTER_SIZE;
1473 /* I guess this memory write could write the remaining data
1474 all at once instead of in REGISTER_SIZE chunks. */
1475 write_memory (fp_arg, val, REGISTER_SIZE);
1476 fp_arg += REGISTER_SIZE;
1477 val += REGISTER_SIZE;
1481 else if (len > (2 * REGISTER_SIZE))
1483 /* Data passed by reference. Put it on the stack. */
1484 write_memory (fp_mem, val, len);
1485 write_memory (fp_arg, (char *) (&fp_mem), REGISTER_SIZE);
1487 /* fp_mem need not be word-aligned since it's just a chunk of
1488 memory being pointed at. That is, += len would do. */
1489 fp_mem += reg_demand * REGISTER_SIZE;
1490 fp_arg += REGISTER_SIZE;
1494 /* Data passed by value. No available registers. Put it on
1496 write_memory (fp_arg, val, len);
1498 /* fp_arg must be word-aligned (i.e., don't += len) to match
1499 the function prologue. */
1500 fp_arg += reg_demand * REGISTER_SIZE;
1507 /* Never put the return address on the stack. The register SRP is pushed
1508 by the called function unless it is a leaf-function. Due to the BRP
1509 register the PC will change when continue is sent. */
1512 cris_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
1514 write_register (SRP_REGNUM, CALL_DUMMY_ADDRESS ());
1518 /* Restore the machine to the state it had before the current frame
1519 was created. Discard the innermost frame from the stack and restore
1520 all saved registers. */
1523 cris_pop_frame (void)
1525 register struct frame_info *fi = get_current_frame ();
1527 register int stack_offset = 0;
1529 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
1531 /* This happens when we hit a breakpoint set at the entry point,
1532 when returning from a dummy frame. */
1533 generic_pop_dummy_frame ();
1537 cris_frame_init_saved_regs (fi);
1539 /* For each register, the address of where it was saved on entry to
1540 the frame now lies in fi->saved_regs[regno], or zero if it was not
1541 saved. This includes special registers such as PC and FP saved in
1542 special ways in the stack frame. The SP_REGNUM is even more
1543 special, the address here is the SP for the next frame, not the
1544 address where the SP was saved. */
1546 /* Restore general registers R0 - R7. They were pushed on the stack
1547 after SP was saved. */
1548 for (regno = 0; regno < FP_REGNUM; regno++)
1550 if (fi->saved_regs[regno])
1552 write_register (regno,
1553 read_memory_integer (fi->saved_regs[regno], 4));
1557 if (fi->saved_regs[FP_REGNUM])
1559 /* Pop the frame pointer (R8). It was pushed before SP
1561 write_register (FP_REGNUM,
1562 read_memory_integer (fi->saved_regs[FP_REGNUM], 4));
1565 /* Not a leaf function. */
1566 if (fi->saved_regs[SRP_REGNUM])
1568 /* SRP was pushed before SP was saved. */
1572 /* Restore the SP and adjust for R8 and (possibly) SRP. */
1573 write_register (SP_REGNUM, fi->saved_regs[FP_REGNUM] + stack_offset);
1577 /* Currently, we can't get the correct info into fi->saved_regs
1578 without a frame pointer. */
1581 /* Restore the PC. */
1582 write_register (PC_REGNUM, fi->extra_info->return_pc);
1584 flush_cached_frames ();
1587 /* Calculates a value that measures how good inst_args constraints an
1588 instruction. It stems from cris_constraint, found in cris-dis.c. */
1591 constraint (unsigned int insn, const signed char *inst_args,
1592 inst_env_type *inst_env)
1597 const char *s = inst_args;
1603 if ((insn & 0x30) == 0x30)
1608 /* A prefix operand. */
1609 if (inst_env->prefix_found)
1615 /* A "push" prefix. (This check was REMOVED by san 970921.) Check for
1616 valid "push" size. In case of special register, it may be != 4. */
1617 if (inst_env->prefix_found)
1623 retval = (((insn >> 0xC) & 0xF) == (insn & 0xF));
1631 tmp = (insn >> 0xC) & 0xF;
1633 for (i = 0; cris_spec_regs[i].name != NULL; i++)
1635 /* Since we match four bits, we will give a value of
1636 4 - 1 = 3 in a match. If there is a corresponding
1637 exact match of a special register in another pattern, it
1638 will get a value of 4, which will be higher. This should
1639 be correct in that an exact pattern would match better that
1641 Note that there is a reason for not returning zero; the
1642 pattern for "clear" is partly matched in the bit-pattern
1643 (the two lower bits must be zero), while the bit-pattern
1644 for a move from a special register is matched in the
1645 register constraint.
1646 This also means we will will have a race condition if
1647 there is a partly match in three bits in the bit pattern. */
1648 if (tmp == cris_spec_regs[i].number)
1655 if (cris_spec_regs[i].name == NULL)
1662 /* Returns the number of bits set in the variable value. */
1665 number_of_bits (unsigned int value)
1667 int number_of_bits = 0;
1671 number_of_bits += 1;
1672 value &= (value - 1);
1674 return number_of_bits;
1677 /* Finds the address that should contain the single step breakpoint(s).
1678 It stems from code in cris-dis.c. */
1681 find_cris_op (unsigned short insn, inst_env_type *inst_env)
1684 int max_level_of_match = -1;
1685 int max_matched = -1;
1688 for (i = 0; cris_opcodes[i].name != NULL; i++)
1690 if (((cris_opcodes[i].match & insn) == cris_opcodes[i].match)
1691 && ((cris_opcodes[i].lose & insn) == 0))
1693 level_of_match = constraint (insn, cris_opcodes[i].args, inst_env);
1694 if (level_of_match >= 0)
1697 number_of_bits (cris_opcodes[i].match | cris_opcodes[i].lose);
1698 if (level_of_match > max_level_of_match)
1701 max_level_of_match = level_of_match;
1702 if (level_of_match == 16)
1704 /* All bits matched, cannot find better. */
1714 /* Attempts to find single-step breakpoints. Returns -1 on failure which is
1715 actually an internal error. */
1718 find_step_target (inst_env_type *inst_env)
1722 unsigned short insn;
1724 /* Create a local register image and set the initial state. */
1725 for (i = 0; i < NUM_GENREGS; i++)
1727 inst_env->reg[i] = (unsigned long) read_register (i);
1729 offset = NUM_GENREGS;
1730 for (i = 0; i < NUM_SPECREGS; i++)
1732 inst_env->preg[i] = (unsigned long) read_register (offset + i);
1734 inst_env->branch_found = 0;
1735 inst_env->slot_needed = 0;
1736 inst_env->delay_slot_pc_active = 0;
1737 inst_env->prefix_found = 0;
1738 inst_env->invalid = 0;
1739 inst_env->xflag_found = 0;
1740 inst_env->disable_interrupt = 0;
1742 /* Look for a step target. */
1745 /* Read an instruction from the client. */
1746 insn = read_memory_unsigned_integer (inst_env->reg[PC_REGNUM], 2);
1748 /* If the instruction is not in a delay slot the new content of the
1749 PC is [PC] + 2. If the instruction is in a delay slot it is not
1750 that simple. Since a instruction in a delay slot cannot change
1751 the content of the PC, it does not matter what value PC will have.
1752 Just make sure it is a valid instruction. */
1753 if (!inst_env->delay_slot_pc_active)
1755 inst_env->reg[PC_REGNUM] += 2;
1759 inst_env->delay_slot_pc_active = 0;
1760 inst_env->reg[PC_REGNUM] = inst_env->delay_slot_pc;
1762 /* Analyse the present instruction. */
1763 i = find_cris_op (insn, inst_env);
1766 inst_env->invalid = 1;
1770 cris_gdb_func (cris_opcodes[i].op, insn, inst_env);
1772 } while (!inst_env->invalid
1773 && (inst_env->prefix_found || inst_env->xflag_found
1774 || inst_env->slot_needed));
1778 /* There is no hardware single-step support. The function find_step_target
1779 digs through the opcodes in order to find all possible targets.
1780 Either one ordinary target or two targets for branches may be found. */
1783 cris_software_single_step (enum target_signal ignore, int insert_breakpoints)
1785 inst_env_type inst_env;
1787 if (insert_breakpoints)
1789 /* Analyse the present instruction environment and insert
1791 int status = find_step_target (&inst_env);
1794 /* Could not find a target. FIXME: Should do something. */
1798 /* Insert at most two breakpoints. One for the next PC content
1799 and possibly another one for a branch, jump, etc. */
1800 next_pc = (CORE_ADDR) inst_env.reg[PC_REGNUM];
1801 target_insert_breakpoint (next_pc, break_mem[0]);
1802 if (inst_env.branch_found
1803 && (CORE_ADDR) inst_env.branch_break_address != next_pc)
1805 branch_target_address =
1806 (CORE_ADDR) inst_env.branch_break_address;
1807 target_insert_breakpoint (branch_target_address, break_mem[1]);
1808 branch_break_inserted = 1;
1814 /* Remove breakpoints. */
1815 target_remove_breakpoint (next_pc, break_mem[0]);
1816 if (branch_break_inserted)
1818 target_remove_breakpoint (branch_target_address, break_mem[1]);
1819 branch_break_inserted = 0;
1824 /* Calculates the prefix value for quick offset addressing mode. */
1827 quick_mode_bdap_prefix (unsigned short inst, inst_env_type *inst_env)
1829 /* It's invalid to be in a delay slot. You can't have a prefix to this
1830 instruction (not 100% sure). */
1831 if (inst_env->slot_needed || inst_env->prefix_found)
1833 inst_env->invalid = 1;
1837 inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)];
1838 inst_env->prefix_value += cris_get_bdap_quick_offset (inst);
1840 /* A prefix doesn't change the xflag_found. But the rest of the flags
1842 inst_env->slot_needed = 0;
1843 inst_env->prefix_found = 1;
1846 /* Updates the autoincrement register. The size of the increment is derived
1847 from the size of the operation. The PC is always kept aligned on even
1851 process_autoincrement (int size, unsigned short inst, inst_env_type *inst_env)
1853 if (size == INST_BYTE_SIZE)
1855 inst_env->reg[cris_get_operand1 (inst)] += 1;
1857 /* The PC must be word aligned, so increase the PC with one
1858 word even if the size is byte. */
1859 if (cris_get_operand1 (inst) == REG_PC)
1861 inst_env->reg[REG_PC] += 1;
1864 else if (size == INST_WORD_SIZE)
1866 inst_env->reg[cris_get_operand1 (inst)] += 2;
1868 else if (size == INST_DWORD_SIZE)
1870 inst_env->reg[cris_get_operand1 (inst)] += 4;
1875 inst_env->invalid = 1;
1879 /* Just a forward declaration. */
1882 get_data_from_address (unsigned short *inst, CORE_ADDR address);
1884 /* Calculates the prefix value for the general case of offset addressing
1888 bdap_prefix (unsigned short inst, inst_env_type *inst_env)
1893 /* It's invalid to be in a delay slot. */
1894 if (inst_env->slot_needed || inst_env->prefix_found)
1896 inst_env->invalid = 1;
1900 /* The calculation of prefix_value used to be after process_autoincrement,
1901 but that fails for an instruction such as jsr [$r0+12] which is encoded
1902 as 5f0d 0c00 30b9 when compiled with -fpic. Since PC is operand1 it
1903 mustn't be incremented until we have read it and what it points at. */
1904 inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)];
1906 /* The offset is an indirection of the contents of the operand1 register. */
1907 inst_env->prefix_value +=
1908 get_data_from_address (&inst, inst_env->reg[cris_get_operand1 (inst)]);
1910 if (cris_get_mode (inst) == AUTOINC_MODE)
1912 process_autoincrement (cris_get_size (inst), inst, inst_env);
1915 /* A prefix doesn't change the xflag_found. But the rest of the flags
1917 inst_env->slot_needed = 0;
1918 inst_env->prefix_found = 1;
1921 /* Calculates the prefix value for the index addressing mode. */
1924 biap_prefix (unsigned short inst, inst_env_type *inst_env)
1926 /* It's invalid to be in a delay slot. I can't see that it's possible to
1927 have a prefix to this instruction. So I will treat this as invalid. */
1928 if (inst_env->slot_needed || inst_env->prefix_found)
1930 inst_env->invalid = 1;
1934 inst_env->prefix_value = inst_env->reg[cris_get_operand1 (inst)];
1936 /* The offset is the operand2 value shifted the size of the instruction
1938 inst_env->prefix_value +=
1939 inst_env->reg[cris_get_operand2 (inst)] << cris_get_size (inst);
1941 /* If the PC is operand1 (base) the address used is the address after
1942 the main instruction, i.e. address + 2 (the PC is already compensated
1943 for the prefix operation). */
1944 if (cris_get_operand1 (inst) == REG_PC)
1946 inst_env->prefix_value += 2;
1949 /* A prefix doesn't change the xflag_found. But the rest of the flags
1951 inst_env->slot_needed = 0;
1952 inst_env->xflag_found = 0;
1953 inst_env->prefix_found = 1;
1956 /* Calculates the prefix value for the double indirect addressing mode. */
1959 dip_prefix (unsigned short inst, inst_env_type *inst_env)
1964 /* It's invalid to be in a delay slot. */
1965 if (inst_env->slot_needed || inst_env->prefix_found)
1967 inst_env->invalid = 1;
1971 /* The prefix value is one dereference of the contents of the operand1
1973 address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)];
1974 inst_env->prefix_value = read_memory_unsigned_integer (address, 4);
1976 /* Check if the mode is autoincrement. */
1977 if (cris_get_mode (inst) == AUTOINC_MODE)
1979 inst_env->reg[cris_get_operand1 (inst)] += 4;
1982 /* A prefix doesn't change the xflag_found. But the rest of the flags
1984 inst_env->slot_needed = 0;
1985 inst_env->xflag_found = 0;
1986 inst_env->prefix_found = 1;
1989 /* Finds the destination for a branch with 8-bits offset. */
1992 eight_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env)
1997 /* If we have a prefix or are in a delay slot it's bad. */
1998 if (inst_env->slot_needed || inst_env->prefix_found)
2000 inst_env->invalid = 1;
2004 /* We have a branch, find out where the branch will land. */
2005 offset = cris_get_branch_short_offset (inst);
2007 /* Check if the offset is signed. */
2008 if (offset & BRANCH_SIGNED_SHORT_OFFSET_MASK)
2013 /* The offset ends with the sign bit, set it to zero. The address
2014 should always be word aligned. */
2015 offset &= ~BRANCH_SIGNED_SHORT_OFFSET_MASK;
2017 inst_env->branch_found = 1;
2018 inst_env->branch_break_address = inst_env->reg[REG_PC] + offset;
2020 inst_env->slot_needed = 1;
2021 inst_env->prefix_found = 0;
2022 inst_env->xflag_found = 0;
2023 inst_env->disable_interrupt = 1;
2026 /* Finds the destination for a branch with 16-bits offset. */
2029 sixteen_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env)
2033 /* If we have a prefix or is in a delay slot it's bad. */
2034 if (inst_env->slot_needed || inst_env->prefix_found)
2036 inst_env->invalid = 1;
2040 /* We have a branch, find out the offset for the branch. */
2041 offset = read_memory_integer (inst_env->reg[REG_PC], 2);
2043 /* The instruction is one word longer than normal, so add one word
2045 inst_env->reg[REG_PC] += 2;
2047 inst_env->branch_found = 1;
2048 inst_env->branch_break_address = inst_env->reg[REG_PC] + offset;
2051 inst_env->slot_needed = 1;
2052 inst_env->prefix_found = 0;
2053 inst_env->xflag_found = 0;
2054 inst_env->disable_interrupt = 1;
2057 /* Handles the ABS instruction. */
2060 abs_op (unsigned short inst, inst_env_type *inst_env)
2065 /* ABS can't have a prefix, so it's bad if it does. */
2066 if (inst_env->prefix_found)
2068 inst_env->invalid = 1;
2072 /* Check if the operation affects the PC. */
2073 if (cris_get_operand2 (inst) == REG_PC)
2076 /* It's invalid to change to the PC if we are in a delay slot. */
2077 if (inst_env->slot_needed)
2079 inst_env->invalid = 1;
2083 value = (long) inst_env->reg[REG_PC];
2085 /* The value of abs (SIGNED_DWORD_MASK) is SIGNED_DWORD_MASK. */
2086 if (value != SIGNED_DWORD_MASK)
2089 inst_env->reg[REG_PC] = (long) value;
2093 inst_env->slot_needed = 0;
2094 inst_env->prefix_found = 0;
2095 inst_env->xflag_found = 0;
2096 inst_env->disable_interrupt = 0;
2099 /* Handles the ADDI instruction. */
2102 addi_op (unsigned short inst, inst_env_type *inst_env)
2104 /* It's invalid to have the PC as base register. And ADDI can't have
2106 if (inst_env->prefix_found || (cris_get_operand1 (inst) == REG_PC))
2108 inst_env->invalid = 1;
2112 inst_env->slot_needed = 0;
2113 inst_env->prefix_found = 0;
2114 inst_env->xflag_found = 0;
2115 inst_env->disable_interrupt = 0;
2118 /* Handles the ASR instruction. */
2121 asr_op (unsigned short inst, inst_env_type *inst_env)
2124 unsigned long value;
2125 unsigned long signed_extend_mask = 0;
2127 /* ASR can't have a prefix, so check that it doesn't. */
2128 if (inst_env->prefix_found)
2130 inst_env->invalid = 1;
2134 /* Check if the PC is the target register. */
2135 if (cris_get_operand2 (inst) == REG_PC)
2137 /* It's invalid to change the PC in a delay slot. */
2138 if (inst_env->slot_needed)
2140 inst_env->invalid = 1;
2143 /* Get the number of bits to shift. */
2144 shift_steps = cris_get_asr_shift_steps (inst_env->reg[cris_get_operand1 (inst)]);
2145 value = inst_env->reg[REG_PC];
2147 /* Find out how many bits the operation should apply to. */
2148 if (cris_get_size (inst) == INST_BYTE_SIZE)
2150 if (value & SIGNED_BYTE_MASK)
2152 signed_extend_mask = 0xFF;
2153 signed_extend_mask = signed_extend_mask >> shift_steps;
2154 signed_extend_mask = ~signed_extend_mask;
2156 value = value >> shift_steps;
2157 value |= signed_extend_mask;
2159 inst_env->reg[REG_PC] &= 0xFFFFFF00;
2160 inst_env->reg[REG_PC] |= value;
2162 else if (cris_get_size (inst) == INST_WORD_SIZE)
2164 if (value & SIGNED_WORD_MASK)
2166 signed_extend_mask = 0xFFFF;
2167 signed_extend_mask = signed_extend_mask >> shift_steps;
2168 signed_extend_mask = ~signed_extend_mask;
2170 value = value >> shift_steps;
2171 value |= signed_extend_mask;
2173 inst_env->reg[REG_PC] &= 0xFFFF0000;
2174 inst_env->reg[REG_PC] |= value;
2176 else if (cris_get_size (inst) == INST_DWORD_SIZE)
2178 if (value & SIGNED_DWORD_MASK)
2180 signed_extend_mask = 0xFFFFFFFF;
2181 signed_extend_mask = signed_extend_mask >> shift_steps;
2182 signed_extend_mask = ~signed_extend_mask;
2184 value = value >> shift_steps;
2185 value |= signed_extend_mask;
2186 inst_env->reg[REG_PC] = value;
2189 inst_env->slot_needed = 0;
2190 inst_env->prefix_found = 0;
2191 inst_env->xflag_found = 0;
2192 inst_env->disable_interrupt = 0;
2195 /* Handles the ASRQ instruction. */
2198 asrq_op (unsigned short inst, inst_env_type *inst_env)
2202 unsigned long value;
2203 unsigned long signed_extend_mask = 0;
2205 /* ASRQ can't have a prefix, so check that it doesn't. */
2206 if (inst_env->prefix_found)
2208 inst_env->invalid = 1;
2212 /* Check if the PC is the target register. */
2213 if (cris_get_operand2 (inst) == REG_PC)
2216 /* It's invalid to change the PC in a delay slot. */
2217 if (inst_env->slot_needed)
2219 inst_env->invalid = 1;
2222 /* The shift size is given as a 5 bit quick value, i.e. we don't
2223 want the the sign bit of the quick value. */
2224 shift_steps = cris_get_asr_shift_steps (inst);
2225 value = inst_env->reg[REG_PC];
2226 if (value & SIGNED_DWORD_MASK)
2228 signed_extend_mask = 0xFFFFFFFF;
2229 signed_extend_mask = signed_extend_mask >> shift_steps;
2230 signed_extend_mask = ~signed_extend_mask;
2232 value = value >> shift_steps;
2233 value |= signed_extend_mask;
2234 inst_env->reg[REG_PC] = value;
2236 inst_env->slot_needed = 0;
2237 inst_env->prefix_found = 0;
2238 inst_env->xflag_found = 0;
2239 inst_env->disable_interrupt = 0;
2242 /* Handles the AX, EI and SETF instruction. */
2245 ax_ei_setf_op (unsigned short inst, inst_env_type *inst_env)
2247 if (inst_env->prefix_found)
2249 inst_env->invalid = 1;
2252 /* Check if the instruction is setting the X flag. */
2253 if (cris_is_xflag_bit_on (inst))
2255 inst_env->xflag_found = 1;
2259 inst_env->xflag_found = 0;
2261 inst_env->slot_needed = 0;
2262 inst_env->prefix_found = 0;
2263 inst_env->disable_interrupt = 1;
2266 /* Checks if the instruction is in assign mode. If so, it updates the assign
2267 register. Note that check_assign assumes that the caller has checked that
2268 there is a prefix to this instruction. The mode check depends on this. */
2271 check_assign (unsigned short inst, inst_env_type *inst_env)
2273 /* Check if it's an assign addressing mode. */
2274 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2276 /* Assign the prefix value to operand 1. */
2277 inst_env->reg[cris_get_operand1 (inst)] = inst_env->prefix_value;
2281 /* Handles the 2-operand BOUND instruction. */
2284 two_operand_bound_op (unsigned short inst, inst_env_type *inst_env)
2286 /* It's invalid to have the PC as the index operand. */
2287 if (cris_get_operand2 (inst) == REG_PC)
2289 inst_env->invalid = 1;
2292 /* Check if we have a prefix. */
2293 if (inst_env->prefix_found)
2295 check_assign (inst, inst_env);
2297 /* Check if this is an autoincrement mode. */
2298 else if (cris_get_mode (inst) == AUTOINC_MODE)
2300 /* It's invalid to change the PC in a delay slot. */
2301 if (inst_env->slot_needed)
2303 inst_env->invalid = 1;
2306 process_autoincrement (cris_get_size (inst), inst, inst_env);
2308 inst_env->slot_needed = 0;
2309 inst_env->prefix_found = 0;
2310 inst_env->xflag_found = 0;
2311 inst_env->disable_interrupt = 0;
2314 /* Handles the 3-operand BOUND instruction. */
2317 three_operand_bound_op (unsigned short inst, inst_env_type *inst_env)
2319 /* It's an error if we haven't got a prefix. And it's also an error
2320 if the PC is the destination register. */
2321 if ((!inst_env->prefix_found) || (cris_get_operand1 (inst) == REG_PC))
2323 inst_env->invalid = 1;
2326 inst_env->slot_needed = 0;
2327 inst_env->prefix_found = 0;
2328 inst_env->xflag_found = 0;
2329 inst_env->disable_interrupt = 0;
2332 /* Clears the status flags in inst_env. */
2335 btst_nop_op (unsigned short inst, inst_env_type *inst_env)
2337 /* It's an error if we have got a prefix. */
2338 if (inst_env->prefix_found)
2340 inst_env->invalid = 1;
2344 inst_env->slot_needed = 0;
2345 inst_env->prefix_found = 0;
2346 inst_env->xflag_found = 0;
2347 inst_env->disable_interrupt = 0;
2350 /* Clears the status flags in inst_env. */
2353 clearf_di_op (unsigned short inst, inst_env_type *inst_env)
2355 /* It's an error if we have got a prefix. */
2356 if (inst_env->prefix_found)
2358 inst_env->invalid = 1;
2362 inst_env->slot_needed = 0;
2363 inst_env->prefix_found = 0;
2364 inst_env->xflag_found = 0;
2365 inst_env->disable_interrupt = 1;
2368 /* Handles the CLEAR instruction if it's in register mode. */
2371 reg_mode_clear_op (unsigned short inst, inst_env_type *inst_env)
2373 /* Check if the target is the PC. */
2374 if (cris_get_operand2 (inst) == REG_PC)
2376 /* The instruction will clear the instruction's size bits. */
2377 int clear_size = cris_get_clear_size (inst);
2378 if (clear_size == INST_BYTE_SIZE)
2380 inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFFFF00;
2382 if (clear_size == INST_WORD_SIZE)
2384 inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFF0000;
2386 if (clear_size == INST_DWORD_SIZE)
2388 inst_env->delay_slot_pc = 0x0;
2390 /* The jump will be delayed with one delay slot. So we need a delay
2392 inst_env->slot_needed = 1;
2393 inst_env->delay_slot_pc_active = 1;
2397 /* The PC will not change => no delay slot. */
2398 inst_env->slot_needed = 0;
2400 inst_env->prefix_found = 0;
2401 inst_env->xflag_found = 0;
2402 inst_env->disable_interrupt = 0;
2405 /* Handles the TEST instruction if it's in register mode. */
2408 reg_mode_test_op (unsigned short inst, inst_env_type *inst_env)
2410 /* It's an error if we have got a prefix. */
2411 if (inst_env->prefix_found)
2413 inst_env->invalid = 1;
2416 inst_env->slot_needed = 0;
2417 inst_env->prefix_found = 0;
2418 inst_env->xflag_found = 0;
2419 inst_env->disable_interrupt = 0;
2423 /* Handles the CLEAR and TEST instruction if the instruction isn't
2424 in register mode. */
2427 none_reg_mode_clear_test_op (unsigned short inst, inst_env_type *inst_env)
2429 /* Check if we are in a prefix mode. */
2430 if (inst_env->prefix_found)
2432 /* The only way the PC can change is if this instruction is in
2433 assign addressing mode. */
2434 check_assign (inst, inst_env);
2436 /* Indirect mode can't change the PC so just check if the mode is
2438 else if (cris_get_mode (inst) == AUTOINC_MODE)
2440 process_autoincrement (cris_get_size (inst), inst, inst_env);
2442 inst_env->slot_needed = 0;
2443 inst_env->prefix_found = 0;
2444 inst_env->xflag_found = 0;
2445 inst_env->disable_interrupt = 0;
2448 /* Checks that the PC isn't the destination register or the instructions has
2452 dstep_logshift_mstep_neg_not_op (unsigned short inst, inst_env_type *inst_env)
2454 /* It's invalid to have the PC as the destination. The instruction can't
2456 if ((cris_get_operand2 (inst) == REG_PC) || inst_env->prefix_found)
2458 inst_env->invalid = 1;
2462 inst_env->slot_needed = 0;
2463 inst_env->prefix_found = 0;
2464 inst_env->xflag_found = 0;
2465 inst_env->disable_interrupt = 0;
2468 /* Checks that the instruction doesn't have a prefix. */
2471 break_op (unsigned short inst, inst_env_type *inst_env)
2473 /* The instruction can't have a prefix. */
2474 if (inst_env->prefix_found)
2476 inst_env->invalid = 1;
2480 inst_env->slot_needed = 0;
2481 inst_env->prefix_found = 0;
2482 inst_env->xflag_found = 0;
2483 inst_env->disable_interrupt = 1;
2486 /* Checks that the PC isn't the destination register and that the instruction
2487 doesn't have a prefix. */
2490 scc_op (unsigned short inst, inst_env_type *inst_env)
2492 /* It's invalid to have the PC as the destination. The instruction can't
2494 if ((cris_get_operand2 (inst) == REG_PC) || inst_env->prefix_found)
2496 inst_env->invalid = 1;
2500 inst_env->slot_needed = 0;
2501 inst_env->prefix_found = 0;
2502 inst_env->xflag_found = 0;
2503 inst_env->disable_interrupt = 1;
2506 /* Handles the register mode JUMP instruction. */
2509 reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env)
2511 /* It's invalid to do a JUMP in a delay slot. The mode is register, so
2512 you can't have a prefix. */
2513 if ((inst_env->slot_needed) || (inst_env->prefix_found))
2515 inst_env->invalid = 1;
2519 /* Just change the PC. */
2520 inst_env->reg[REG_PC] = inst_env->reg[cris_get_operand1 (inst)];
2521 inst_env->slot_needed = 0;
2522 inst_env->prefix_found = 0;
2523 inst_env->xflag_found = 0;
2524 inst_env->disable_interrupt = 1;
2527 /* Handles the JUMP instruction for all modes except register. */
2529 void none_reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env)
2531 unsigned long newpc;
2534 /* It's invalid to do a JUMP in a delay slot. */
2535 if (inst_env->slot_needed)
2537 inst_env->invalid = 1;
2541 /* Check if we have a prefix. */
2542 if (inst_env->prefix_found)
2544 check_assign (inst, inst_env);
2546 /* Get the new value for the the PC. */
2548 read_memory_unsigned_integer ((CORE_ADDR) inst_env->prefix_value,
2553 /* Get the new value for the PC. */
2554 address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)];
2555 newpc = read_memory_unsigned_integer (address, 4);
2557 /* Check if we should increment a register. */
2558 if (cris_get_mode (inst) == AUTOINC_MODE)
2560 inst_env->reg[cris_get_operand1 (inst)] += 4;
2563 inst_env->reg[REG_PC] = newpc;
2565 inst_env->slot_needed = 0;
2566 inst_env->prefix_found = 0;
2567 inst_env->xflag_found = 0;
2568 inst_env->disable_interrupt = 1;
2571 /* Handles moves to special registers (aka P-register) for all modes. */
2574 move_to_preg_op (unsigned short inst, inst_env_type *inst_env)
2576 if (inst_env->prefix_found)
2578 /* The instruction has a prefix that means we are only interested if
2579 the instruction is in assign mode. */
2580 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2582 /* The prefix handles the problem if we are in a delay slot. */
2583 if (cris_get_operand1 (inst) == REG_PC)
2585 /* Just take care of the assign. */
2586 check_assign (inst, inst_env);
2590 else if (cris_get_mode (inst) == AUTOINC_MODE)
2592 /* The instruction doesn't have a prefix, the only case left that we
2593 are interested in is the autoincrement mode. */
2594 if (cris_get_operand1 (inst) == REG_PC)
2596 /* If the PC is to be incremented it's invalid to be in a
2598 if (inst_env->slot_needed)
2600 inst_env->invalid = 1;
2604 /* The increment depends on the size of the special register. */
2605 if (cris_register_size (cris_get_operand2 (inst)) == 1)
2607 process_autoincrement (INST_BYTE_SIZE, inst, inst_env);
2609 else if (cris_register_size (cris_get_operand2 (inst)) == 2)
2611 process_autoincrement (INST_WORD_SIZE, inst, inst_env);
2615 process_autoincrement (INST_DWORD_SIZE, inst, inst_env);
2619 inst_env->slot_needed = 0;
2620 inst_env->prefix_found = 0;
2621 inst_env->xflag_found = 0;
2622 inst_env->disable_interrupt = 1;
2625 /* Handles moves from special registers (aka P-register) for all modes
2629 none_reg_mode_move_from_preg_op (unsigned short inst, inst_env_type *inst_env)
2631 if (inst_env->prefix_found)
2633 /* The instruction has a prefix that means we are only interested if
2634 the instruction is in assign mode. */
2635 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2637 /* The prefix handles the problem if we are in a delay slot. */
2638 if (cris_get_operand1 (inst) == REG_PC)
2640 /* Just take care of the assign. */
2641 check_assign (inst, inst_env);
2645 /* The instruction doesn't have a prefix, the only case left that we
2646 are interested in is the autoincrement mode. */
2647 else if (cris_get_mode (inst) == AUTOINC_MODE)
2649 if (cris_get_operand1 (inst) == REG_PC)
2651 /* If the PC is to be incremented it's invalid to be in a
2653 if (inst_env->slot_needed)
2655 inst_env->invalid = 1;
2659 /* The increment depends on the size of the special register. */
2660 if (cris_register_size (cris_get_operand2 (inst)) == 1)
2662 process_autoincrement (INST_BYTE_SIZE, inst, inst_env);
2664 else if (cris_register_size (cris_get_operand2 (inst)) == 2)
2666 process_autoincrement (INST_WORD_SIZE, inst, inst_env);
2670 process_autoincrement (INST_DWORD_SIZE, inst, inst_env);
2674 inst_env->slot_needed = 0;
2675 inst_env->prefix_found = 0;
2676 inst_env->xflag_found = 0;
2677 inst_env->disable_interrupt = 1;
2680 /* Handles moves from special registers (aka P-register) when the mode
2684 reg_mode_move_from_preg_op (unsigned short inst, inst_env_type *inst_env)
2686 /* Register mode move from special register can't have a prefix. */
2687 if (inst_env->prefix_found)
2689 inst_env->invalid = 1;
2693 if (cris_get_operand1 (inst) == REG_PC)
2695 /* It's invalid to change the PC in a delay slot. */
2696 if (inst_env->slot_needed)
2698 inst_env->invalid = 1;
2701 /* The destination is the PC, the jump will have a delay slot. */
2702 inst_env->delay_slot_pc = inst_env->preg[cris_get_operand2 (inst)];
2703 inst_env->slot_needed = 1;
2704 inst_env->delay_slot_pc_active = 1;
2708 /* If the destination isn't PC, there will be no jump. */
2709 inst_env->slot_needed = 0;
2711 inst_env->prefix_found = 0;
2712 inst_env->xflag_found = 0;
2713 inst_env->disable_interrupt = 1;
2716 /* Handles the MOVEM from memory to general register instruction. */
2719 move_mem_to_reg_movem_op (unsigned short inst, inst_env_type *inst_env)
2721 if (inst_env->prefix_found)
2723 /* The prefix handles the problem if we are in a delay slot. Is the
2724 MOVEM instruction going to change the PC? */
2725 if (cris_get_operand2 (inst) >= REG_PC)
2727 inst_env->reg[REG_PC] =
2728 read_memory_unsigned_integer (inst_env->prefix_value, 4);
2730 /* The assign value is the value after the increment. Normally, the
2731 assign value is the value before the increment. */
2732 if ((cris_get_operand1 (inst) == REG_PC)
2733 && (cris_get_mode (inst) == PREFIX_ASSIGN_MODE))
2735 inst_env->reg[REG_PC] = inst_env->prefix_value;
2736 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
2741 /* Is the MOVEM instruction going to change the PC? */
2742 if (cris_get_operand2 (inst) == REG_PC)
2744 /* It's invalid to change the PC in a delay slot. */
2745 if (inst_env->slot_needed)
2747 inst_env->invalid = 1;
2750 inst_env->reg[REG_PC] =
2751 read_memory_unsigned_integer (inst_env->reg[cris_get_operand1 (inst)],
2754 /* The increment is not depending on the size, instead it's depending
2755 on the number of registers loaded from memory. */
2756 if ((cris_get_operand1 (inst) == REG_PC) && (cris_get_mode (inst) == AUTOINC_MODE))
2758 /* It's invalid to change the PC in a delay slot. */
2759 if (inst_env->slot_needed)
2761 inst_env->invalid = 1;
2764 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
2767 inst_env->slot_needed = 0;
2768 inst_env->prefix_found = 0;
2769 inst_env->xflag_found = 0;
2770 inst_env->disable_interrupt = 0;
2773 /* Handles the MOVEM to memory from general register instruction. */
2776 move_reg_to_mem_movem_op (unsigned short inst, inst_env_type *inst_env)
2778 if (inst_env->prefix_found)
2780 /* The assign value is the value after the increment. Normally, the
2781 assign value is the value before the increment. */
2782 if ((cris_get_operand1 (inst) == REG_PC) &&
2783 (cris_get_mode (inst) == PREFIX_ASSIGN_MODE))
2785 /* The prefix handles the problem if we are in a delay slot. */
2786 inst_env->reg[REG_PC] = inst_env->prefix_value;
2787 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
2792 /* The increment is not depending on the size, instead it's depending
2793 on the number of registers loaded to memory. */
2794 if ((cris_get_operand1 (inst) == REG_PC) && (cris_get_mode (inst) == AUTOINC_MODE))
2796 /* It's invalid to change the PC in a delay slot. */
2797 if (inst_env->slot_needed)
2799 inst_env->invalid = 1;
2802 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
2805 inst_env->slot_needed = 0;
2806 inst_env->prefix_found = 0;
2807 inst_env->xflag_found = 0;
2808 inst_env->disable_interrupt = 0;
2811 /* Handles the pop instruction to a general register.
2812 POP is a assembler macro for MOVE.D [SP+], Rd. */
2815 reg_pop_op (unsigned short inst, inst_env_type *inst_env)
2817 /* POP can't have a prefix. */
2818 if (inst_env->prefix_found)
2820 inst_env->invalid = 1;
2823 if (cris_get_operand2 (inst) == REG_PC)
2825 /* It's invalid to change the PC in a delay slot. */
2826 if (inst_env->slot_needed)
2828 inst_env->invalid = 1;
2831 inst_env->reg[REG_PC] =
2832 read_memory_unsigned_integer (inst_env->reg[REG_SP], 4);
2834 inst_env->slot_needed = 0;
2835 inst_env->prefix_found = 0;
2836 inst_env->xflag_found = 0;
2837 inst_env->disable_interrupt = 0;
2840 /* Handles moves from register to memory. */
2843 move_reg_to_mem_index_inc_op (unsigned short inst, inst_env_type *inst_env)
2845 /* Check if we have a prefix. */
2846 if (inst_env->prefix_found)
2848 /* The only thing that can change the PC is an assign. */
2849 check_assign (inst, inst_env);
2851 else if ((cris_get_operand1 (inst) == REG_PC)
2852 && (cris_get_mode (inst) == AUTOINC_MODE))
2854 /* It's invalid to change the PC in a delay slot. */
2855 if (inst_env->slot_needed)
2857 inst_env->invalid = 1;
2860 process_autoincrement (cris_get_size (inst), inst, inst_env);
2862 inst_env->slot_needed = 0;
2863 inst_env->prefix_found = 0;
2864 inst_env->xflag_found = 0;
2865 inst_env->disable_interrupt = 0;
2868 /* Handles the intructions that's not yet implemented, by setting
2869 inst_env->invalid to true. */
2872 not_implemented_op (unsigned short inst, inst_env_type *inst_env)
2874 inst_env->invalid = 1;
2877 /* Handles the XOR instruction. */
2880 xor_op (unsigned short inst, inst_env_type *inst_env)
2882 /* XOR can't have a prefix. */
2883 if (inst_env->prefix_found)
2885 inst_env->invalid = 1;
2889 /* Check if the PC is the target. */
2890 if (cris_get_operand2 (inst) == REG_PC)
2892 /* It's invalid to change the PC in a delay slot. */
2893 if (inst_env->slot_needed)
2895 inst_env->invalid = 1;
2898 inst_env->reg[REG_PC] ^= inst_env->reg[cris_get_operand1 (inst)];
2900 inst_env->slot_needed = 0;
2901 inst_env->prefix_found = 0;
2902 inst_env->xflag_found = 0;
2903 inst_env->disable_interrupt = 0;
2906 /* Handles the MULS instruction. */
2909 muls_op (unsigned short inst, inst_env_type *inst_env)
2911 /* MULS/U can't have a prefix. */
2912 if (inst_env->prefix_found)
2914 inst_env->invalid = 1;
2918 /* Consider it invalid if the PC is the target. */
2919 if (cris_get_operand2 (inst) == REG_PC)
2921 inst_env->invalid = 1;
2924 inst_env->slot_needed = 0;
2925 inst_env->prefix_found = 0;
2926 inst_env->xflag_found = 0;
2927 inst_env->disable_interrupt = 0;
2930 /* Handles the MULU instruction. */
2933 mulu_op (unsigned short inst, inst_env_type *inst_env)
2935 /* MULS/U can't have a prefix. */
2936 if (inst_env->prefix_found)
2938 inst_env->invalid = 1;
2942 /* Consider it invalid if the PC is the target. */
2943 if (cris_get_operand2 (inst) == REG_PC)
2945 inst_env->invalid = 1;
2948 inst_env->slot_needed = 0;
2949 inst_env->prefix_found = 0;
2950 inst_env->xflag_found = 0;
2951 inst_env->disable_interrupt = 0;
2954 /* Calculate the result of the instruction for ADD, SUB, CMP AND, OR and MOVE.
2955 The MOVE instruction is the move from source to register. */
2958 add_sub_cmp_and_or_move_action (unsigned short inst, inst_env_type *inst_env,
2959 unsigned long source1, unsigned long source2)
2961 unsigned long pc_mask;
2962 unsigned long operation_mask;
2964 /* Find out how many bits the operation should apply to. */
2965 if (cris_get_size (inst) == INST_BYTE_SIZE)
2967 pc_mask = 0xFFFFFF00;
2968 operation_mask = 0xFF;
2970 else if (cris_get_size (inst) == INST_WORD_SIZE)
2972 pc_mask = 0xFFFF0000;
2973 operation_mask = 0xFFFF;
2975 else if (cris_get_size (inst) == INST_DWORD_SIZE)
2978 operation_mask = 0xFFFFFFFF;
2982 /* The size is out of range. */
2983 inst_env->invalid = 1;
2987 /* The instruction just works on uw_operation_mask bits. */
2988 source2 &= operation_mask;
2989 source1 &= operation_mask;
2991 /* Now calculate the result. The opcode's 3 first bits separates
2992 the different actions. */
2993 switch (cris_get_opcode (inst) & 7)
3003 case 2: /* subtract */
3007 case 3: /* compare */
3019 inst_env->invalid = 1;
3025 /* Make sure that the result doesn't contain more than the instruction
3027 source2 &= operation_mask;
3029 /* Calculate the new breakpoint address. */
3030 inst_env->reg[REG_PC] &= pc_mask;
3031 inst_env->reg[REG_PC] |= source1;
3035 /* Extends the value from either byte or word size to a dword. If the mode
3036 is zero extend then the value is extended with zero. If instead the mode
3037 is signed extend the sign bit of the value is taken into consideration. */
3040 do_sign_or_zero_extend (unsigned long value, unsigned short *inst)
3042 /* The size can be either byte or word, check which one it is.
3043 Don't check the highest bit, it's indicating if it's a zero
3045 if (cris_get_size (*inst) & INST_WORD_SIZE)
3050 /* Check if the instruction is signed extend. If so, check if value has
3052 if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_WORD_MASK))
3054 value |= SIGNED_WORD_EXTEND_MASK;
3062 /* Check if the instruction is signed extend. If so, check if value has
3064 if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_BYTE_MASK))
3066 value |= SIGNED_BYTE_EXTEND_MASK;
3069 /* The size should now be dword. */
3070 cris_set_size_to_dword (inst);
3074 /* Handles the register mode for the ADD, SUB, CMP, AND, OR and MOVE
3075 instruction. The MOVE instruction is the move from source to register. */
3078 reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst,
3079 inst_env_type *inst_env)
3081 unsigned long operand1;
3082 unsigned long operand2;
3084 /* It's invalid to have a prefix to the instruction. This is a register
3085 mode instruction and can't have a prefix. */
3086 if (inst_env->prefix_found)
3088 inst_env->invalid = 1;
3091 /* Check if the instruction has PC as its target. */
3092 if (cris_get_operand2 (inst) == REG_PC)
3094 if (inst_env->slot_needed)
3096 inst_env->invalid = 1;
3099 /* The instruction has the PC as its target register. */
3100 operand1 = inst_env->reg[cris_get_operand1 (inst)];
3101 operand2 = inst_env->reg[REG_PC];
3103 /* Check if it's a extend, signed or zero instruction. */
3104 if (cris_get_opcode (inst) < 4)
3106 operand1 = do_sign_or_zero_extend (operand1, &inst);
3108 /* Calculate the PC value after the instruction, i.e. where the
3109 breakpoint should be. The order of the udw_operands is vital. */
3110 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3112 inst_env->slot_needed = 0;
3113 inst_env->prefix_found = 0;
3114 inst_env->xflag_found = 0;
3115 inst_env->disable_interrupt = 0;
3118 /* Returns the data contained at address. The size of the data is derived from
3119 the size of the operation. If the instruction is a zero or signed
3120 extend instruction, the size field is changed in instruction. */
3123 get_data_from_address (unsigned short *inst, CORE_ADDR address)
3125 int size = cris_get_size (*inst);
3126 unsigned long value;
3128 /* If it's an extend instruction we don't want the signed extend bit,
3129 because it influences the size. */
3130 if (cris_get_opcode (*inst) < 4)
3132 size &= ~SIGNED_EXTEND_BIT_MASK;
3134 /* Is there a need for checking the size? Size should contain the number of
3137 value = read_memory_unsigned_integer (address, size);
3139 /* Check if it's an extend, signed or zero instruction. */
3140 if (cris_get_opcode (*inst) < 4)
3142 value = do_sign_or_zero_extend (value, inst);
3147 /* Handles the assign addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
3148 instructions. The MOVE instruction is the move from source to register. */
3151 handle_prefix_assign_mode_for_aritm_op (unsigned short inst,
3152 inst_env_type *inst_env)
3154 unsigned long operand2;
3155 unsigned long operand3;
3157 check_assign (inst, inst_env);
3158 if (cris_get_operand2 (inst) == REG_PC)
3160 operand2 = inst_env->reg[REG_PC];
3162 /* Get the value of the third operand. */
3163 operand3 = get_data_from_address (&inst, inst_env->prefix_value);
3165 /* Calculate the PC value after the instruction, i.e. where the
3166 breakpoint should be. The order of the udw_operands is vital. */
3167 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3169 inst_env->slot_needed = 0;
3170 inst_env->prefix_found = 0;
3171 inst_env->xflag_found = 0;
3172 inst_env->disable_interrupt = 0;
3175 /* Handles the three-operand addressing mode for the ADD, SUB, CMP, AND and
3176 OR instructions. Note that for this to work as expected, the calling
3177 function must have made sure that there is a prefix to this instruction. */
3180 three_operand_add_sub_cmp_and_or_op (unsigned short inst,
3181 inst_env_type *inst_env)
3183 unsigned long operand2;
3184 unsigned long operand3;
3186 if (cris_get_operand1 (inst) == REG_PC)
3188 /* The PC will be changed by the instruction. */
3189 operand2 = inst_env->reg[cris_get_operand2 (inst)];
3191 /* Get the value of the third operand. */
3192 operand3 = get_data_from_address (&inst, inst_env->prefix_value);
3194 /* Calculate the PC value after the instruction, i.e. where the
3195 breakpoint should be. */
3196 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3198 inst_env->slot_needed = 0;
3199 inst_env->prefix_found = 0;
3200 inst_env->xflag_found = 0;
3201 inst_env->disable_interrupt = 0;
3204 /* Handles the index addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
3205 instructions. The MOVE instruction is the move from source to register. */
3208 handle_prefix_index_mode_for_aritm_op (unsigned short inst,
3209 inst_env_type *inst_env)
3211 if (cris_get_operand1 (inst) != cris_get_operand2 (inst))
3213 /* If the instruction is MOVE it's invalid. If the instruction is ADD,
3214 SUB, AND or OR something weird is going on (if everything works these
3215 instructions should end up in the three operand version). */
3216 inst_env->invalid = 1;
3221 /* three_operand_add_sub_cmp_and_or does the same as we should do here
3223 three_operand_add_sub_cmp_and_or_op (inst, inst_env);
3225 inst_env->slot_needed = 0;
3226 inst_env->prefix_found = 0;
3227 inst_env->xflag_found = 0;
3228 inst_env->disable_interrupt = 0;
3231 /* Handles the autoincrement and indirect addresing mode for the ADD, SUB,
3232 CMP, AND OR and MOVE instruction. The MOVE instruction is the move from
3233 source to register. */
3236 handle_inc_and_index_mode_for_aritm_op (unsigned short inst,
3237 inst_env_type *inst_env)
3239 unsigned long operand1;
3240 unsigned long operand2;
3241 unsigned long operand3;
3244 /* The instruction is either an indirect or autoincrement addressing mode.
3245 Check if the destination register is the PC. */
3246 if (cris_get_operand2 (inst) == REG_PC)
3248 /* Must be done here, get_data_from_address may change the size
3250 size = cris_get_size (inst);
3251 operand2 = inst_env->reg[REG_PC];
3253 /* Get the value of the third operand, i.e. the indirect operand. */
3254 operand1 = inst_env->reg[cris_get_operand1 (inst)];
3255 operand3 = get_data_from_address (&inst, operand1);
3257 /* Calculate the PC value after the instruction, i.e. where the
3258 breakpoint should be. The order of the udw_operands is vital. */
3259 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3261 /* If this is an autoincrement addressing mode, check if the increment
3263 if ((cris_get_operand1 (inst) == REG_PC) && (cris_get_mode (inst) == AUTOINC_MODE))
3265 /* Get the size field. */
3266 size = cris_get_size (inst);
3268 /* If it's an extend instruction we don't want the signed extend bit,
3269 because it influences the size. */
3270 if (cris_get_opcode (inst) < 4)
3272 size &= ~SIGNED_EXTEND_BIT_MASK;
3274 process_autoincrement (size, inst, inst_env);
3276 inst_env->slot_needed = 0;
3277 inst_env->prefix_found = 0;
3278 inst_env->xflag_found = 0;
3279 inst_env->disable_interrupt = 0;
3282 /* Handles the two-operand addressing mode, all modes except register, for
3283 the ADD, SUB CMP, AND and OR instruction. */
3286 none_reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst,
3287 inst_env_type *inst_env)
3289 if (inst_env->prefix_found)
3291 if (cris_get_mode (inst) == PREFIX_INDEX_MODE)
3293 handle_prefix_index_mode_for_aritm_op (inst, inst_env);
3295 else if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
3297 handle_prefix_assign_mode_for_aritm_op (inst, inst_env);
3301 /* The mode is invalid for a prefixed base instruction. */
3302 inst_env->invalid = 1;
3308 handle_inc_and_index_mode_for_aritm_op (inst, inst_env);
3312 /* Handles the quick addressing mode for the ADD and SUB instruction. */
3315 quick_mode_add_sub_op (unsigned short inst, inst_env_type *inst_env)
3317 unsigned long operand1;
3318 unsigned long operand2;
3320 /* It's a bad idea to be in a prefix instruction now. This is a quick mode
3321 instruction and can't have a prefix. */
3322 if (inst_env->prefix_found)
3324 inst_env->invalid = 1;
3328 /* Check if the instruction has PC as its target. */
3329 if (cris_get_operand2 (inst) == REG_PC)
3331 if (inst_env->slot_needed)
3333 inst_env->invalid = 1;
3336 operand1 = cris_get_quick_value (inst);
3337 operand2 = inst_env->reg[REG_PC];
3339 /* The size should now be dword. */
3340 cris_set_size_to_dword (&inst);
3342 /* Calculate the PC value after the instruction, i.e. where the
3343 breakpoint should be. */
3344 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3346 inst_env->slot_needed = 0;
3347 inst_env->prefix_found = 0;
3348 inst_env->xflag_found = 0;
3349 inst_env->disable_interrupt = 0;
3352 /* Handles the quick addressing mode for the CMP, AND and OR instruction. */
3355 quick_mode_and_cmp_move_or_op (unsigned short inst, inst_env_type *inst_env)
3357 unsigned long operand1;
3358 unsigned long operand2;
3360 /* It's a bad idea to be in a prefix instruction now. This is a quick mode
3361 instruction and can't have a prefix. */
3362 if (inst_env->prefix_found)
3364 inst_env->invalid = 1;
3367 /* Check if the instruction has PC as its target. */
3368 if (cris_get_operand2 (inst) == REG_PC)
3370 if (inst_env->slot_needed)
3372 inst_env->invalid = 1;
3375 /* The instruction has the PC as its target register. */
3376 operand1 = cris_get_quick_value (inst);
3377 operand2 = inst_env->reg[REG_PC];
3379 /* The quick value is signed, so check if we must do a signed extend. */
3380 if (operand1 & SIGNED_QUICK_VALUE_MASK)
3383 operand1 |= SIGNED_QUICK_VALUE_EXTEND_MASK;
3385 /* The size should now be dword. */
3386 cris_set_size_to_dword (&inst);
3388 /* Calculate the PC value after the instruction, i.e. where the
3389 breakpoint should be. */
3390 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3392 inst_env->slot_needed = 0;
3393 inst_env->prefix_found = 0;
3394 inst_env->xflag_found = 0;
3395 inst_env->disable_interrupt = 0;
3398 /* Translate op_type to a function and call it. */
3400 static void cris_gdb_func (enum cris_op_type op_type, unsigned short inst,
3401 inst_env_type *inst_env)
3405 case cris_not_implemented_op:
3406 not_implemented_op (inst, inst_env);
3410 abs_op (inst, inst_env);
3414 addi_op (inst, inst_env);
3418 asr_op (inst, inst_env);
3422 asrq_op (inst, inst_env);
3425 case cris_ax_ei_setf_op:
3426 ax_ei_setf_op (inst, inst_env);
3429 case cris_bdap_prefix:
3430 bdap_prefix (inst, inst_env);
3433 case cris_biap_prefix:
3434 biap_prefix (inst, inst_env);
3438 break_op (inst, inst_env);
3441 case cris_btst_nop_op:
3442 btst_nop_op (inst, inst_env);
3445 case cris_clearf_di_op:
3446 clearf_di_op (inst, inst_env);
3449 case cris_dip_prefix:
3450 dip_prefix (inst, inst_env);
3453 case cris_dstep_logshift_mstep_neg_not_op:
3454 dstep_logshift_mstep_neg_not_op (inst, inst_env);
3457 case cris_eight_bit_offset_branch_op:
3458 eight_bit_offset_branch_op (inst, inst_env);
3461 case cris_move_mem_to_reg_movem_op:
3462 move_mem_to_reg_movem_op (inst, inst_env);
3465 case cris_move_reg_to_mem_movem_op:
3466 move_reg_to_mem_movem_op (inst, inst_env);
3469 case cris_move_to_preg_op:
3470 move_to_preg_op (inst, inst_env);
3474 muls_op (inst, inst_env);
3478 mulu_op (inst, inst_env);
3481 case cris_none_reg_mode_add_sub_cmp_and_or_move_op:
3482 none_reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env);
3485 case cris_none_reg_mode_clear_test_op:
3486 none_reg_mode_clear_test_op (inst, inst_env);
3489 case cris_none_reg_mode_jump_op:
3490 none_reg_mode_jump_op (inst, inst_env);
3493 case cris_none_reg_mode_move_from_preg_op:
3494 none_reg_mode_move_from_preg_op (inst, inst_env);
3497 case cris_quick_mode_add_sub_op:
3498 quick_mode_add_sub_op (inst, inst_env);
3501 case cris_quick_mode_and_cmp_move_or_op:
3502 quick_mode_and_cmp_move_or_op (inst, inst_env);
3505 case cris_quick_mode_bdap_prefix:
3506 quick_mode_bdap_prefix (inst, inst_env);
3509 case cris_reg_mode_add_sub_cmp_and_or_move_op:
3510 reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env);
3513 case cris_reg_mode_clear_op:
3514 reg_mode_clear_op (inst, inst_env);
3517 case cris_reg_mode_jump_op:
3518 reg_mode_jump_op (inst, inst_env);
3521 case cris_reg_mode_move_from_preg_op:
3522 reg_mode_move_from_preg_op (inst, inst_env);
3525 case cris_reg_mode_test_op:
3526 reg_mode_test_op (inst, inst_env);
3530 scc_op (inst, inst_env);
3533 case cris_sixteen_bit_offset_branch_op:
3534 sixteen_bit_offset_branch_op (inst, inst_env);
3537 case cris_three_operand_add_sub_cmp_and_or_op:
3538 three_operand_add_sub_cmp_and_or_op (inst, inst_env);
3541 case cris_three_operand_bound_op:
3542 three_operand_bound_op (inst, inst_env);
3545 case cris_two_operand_bound_op:
3546 two_operand_bound_op (inst, inst_env);
3550 xor_op (inst, inst_env);
3555 /* This wrapper is to avoid cris_get_assembler being called before
3556 exec_bfd has been set. */
3559 cris_delayed_get_disassembler (bfd_vma addr, disassemble_info *info)
3561 tm_print_insn = cris_get_disassembler (exec_bfd);
3562 return TARGET_PRINT_INSN (addr, info);
3565 /* Copied from <asm/elf.h>. */
3566 typedef unsigned long elf_greg_t;
3568 /* Same as user_regs_struct struct in <asm/user.h>. */
3569 typedef elf_greg_t elf_gregset_t[35];
3571 /* Unpack an elf_gregset_t into GDB's register cache. */
3574 supply_gregset (elf_gregset_t *gregsetp)
3577 elf_greg_t *regp = *gregsetp;
3578 static char zerobuf[4] = {0};
3580 /* The kernel dumps all 32 registers as unsigned longs, but supply_register
3581 knows about the actual size of each register so that's no problem. */
3582 for (i = 0; i < NUM_GENREGS + NUM_SPECREGS; i++)
3584 supply_register (i, (char *)®p[i]);
3588 /* Use a local version of this function to get the correct types for
3589 regsets, until multi-arch core support is ready. */
3592 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
3593 int which, CORE_ADDR reg_addr)
3595 elf_gregset_t gregset;
3600 if (core_reg_size != sizeof (gregset))
3602 warning ("wrong size gregset struct in core file");
3606 memcpy (&gregset, core_reg_sect, sizeof (gregset));
3607 supply_gregset (&gregset);
3611 /* We've covered all the kinds of registers we know about here,
3612 so this must be something we wouldn't know what to do with
3613 anyway. Just ignore it. */
3618 static struct core_fns cris_elf_core_fns =
3620 bfd_target_elf_flavour, /* core_flavour */
3621 default_check_format, /* check_format */
3622 default_core_sniffer, /* core_sniffer */
3623 fetch_core_registers, /* core_read_registers */
3627 /* Fetch (and possibly build) an appropriate link_map_offsets
3628 structure for native GNU/Linux CRIS targets using the struct
3629 offsets defined in link.h (but without actual reference to that
3632 This makes it possible to access GNU/Linux CRIS shared libraries
3633 from a GDB that was not built on an GNU/Linux CRIS host (for cross
3636 See gdb/solib-svr4.h for an explanation of these fields. */
3638 struct link_map_offsets *
3639 cris_linux_svr4_fetch_link_map_offsets (void)
3641 static struct link_map_offsets lmo;
3642 static struct link_map_offsets *lmp = NULL;
3648 lmo.r_debug_size = 8; /* The actual size is 20 bytes, but
3649 this is all we need. */
3650 lmo.r_map_offset = 4;
3653 lmo.link_map_size = 20;
3655 lmo.l_addr_offset = 0;
3656 lmo.l_addr_size = 4;
3658 lmo.l_name_offset = 4;
3659 lmo.l_name_size = 4;
3661 lmo.l_next_offset = 12;
3662 lmo.l_next_size = 4;
3664 lmo.l_prev_offset = 16;
3665 lmo.l_prev_size = 4;
3672 cris_fpless_backtrace (char *noargs, int from_tty)
3674 /* Points at the instruction after the jsr (except when in innermost frame
3675 where it points at the original pc). */
3678 /* Temporary variable, used for parsing from the start of the function that
3679 the pc is in, up to the pc. */
3680 CORE_ADDR tmp_pc = 0;
3683 /* Information about current frame. */
3684 struct symtab_and_line sal;
3687 /* Present instruction. */
3688 unsigned short insn;
3690 /* Next instruction, lookahead. */
3691 unsigned short insn_next;
3693 /* This is to store the offset between sp at start of function and until we
3694 reach push srp (if any). */
3695 int sp_add_later = 0;
3696 int push_srp_found = 0;
3700 /* Frame counter. */
3703 /* For the innermost frame, we want to look at srp in case it's a leaf
3704 function (since there's no push srp in that case). */
3705 int innermost_frame = 1;
3707 read_register_gen (PC_REGNUM, (char *) &pc);
3708 read_register_gen (SP_REGNUM, (char *) &sp);
3710 /* We make an explicit return when we can't find an outer frame. */
3713 /* Get file name and line number. */
3714 sal = find_pc_line (pc, 0);
3716 /* Get function name. */
3717 find_pc_partial_function (pc, &func_name, (CORE_ADDR *) NULL,
3718 (CORE_ADDR *) NULL);
3720 /* Print information about current frame. */
3721 printf_unfiltered ("#%i 0x%08lx in %s", frame++, pc, func_name);
3724 printf_unfiltered (" at %s:%i", sal.symtab->filename, sal.line);
3726 printf_unfiltered ("\n");
3728 /* Get the start address of this function. */
3729 tmp_pc = get_pc_function_start (pc);
3731 /* Mini parser, only meant to find push sp and sub ...,sp from the start
3732 of the function, up to the pc. */
3735 insn = read_memory_unsigned_integer (tmp_pc, sizeof (short));
3736 tmp_pc += sizeof (short);
3739 /* push <reg> 32 bit instruction */
3740 insn_next = read_memory_unsigned_integer (tmp_pc,
3742 tmp_pc += sizeof (short);
3744 /* Recognize srp. */
3745 if (insn_next == 0xBE7E)
3747 /* For subsequent (not this one though) push or sub which
3748 affects sp, adjust sp immediately. */
3751 /* Note: this will break if we ever encounter a
3752 push vr (1 byte) or push ccr (2 bytes). */
3757 /* Some other register was pushed. */
3768 else if (cris_get_operand2 (insn) == SP_REGNUM
3769 && cris_get_mode (insn) == 0x0000
3770 && cris_get_opcode (insn) == 0x000A)
3773 val = cris_get_quick_value (insn);
3781 sp_add_later += val;
3785 else if (cris_get_operand2 (insn) == SP_REGNUM
3786 /* Autoincrement addressing mode. */
3787 && cris_get_mode (insn) == 0x0003
3789 && ((insn) & 0x03E0) >> 5 == 0x0004)
3792 val = get_data_from_address (&insn, tmp_pc);
3800 sp_add_later += val;
3803 else if (cris_get_operand2 (insn) == SP_REGNUM
3804 && ((insn & 0x0F00) >> 8) == 0x0001
3805 && (cris_get_signed_offset (insn) < 0))
3807 /* Immediate byte offset addressing prefix word with sp as base
3808 register. Used for CRIS v8 i.e. ETRAX 100 and newer if <val>
3809 is between 64 and 128.
3810 movem r<regsave>,[sp=sp-<val>] */
3811 val = -cris_get_signed_offset (insn);
3812 insn_next = read_memory_unsigned_integer (tmp_pc,
3814 tmp_pc += sizeof (short);
3816 if (cris_get_mode (insn_next) == PREFIX_ASSIGN_MODE
3817 && cris_get_opcode (insn_next) == 0x000F
3818 && cris_get_size (insn_next) == 0x0003
3819 && cris_get_operand1 (insn_next) == SP_REGNUM)
3827 sp_add_later += val;
3838 /* sp should now point at where srp is stored on the stack. Update
3839 the pc to the srp. */
3840 pc = read_memory_unsigned_integer (sp, 4);
3842 else if (innermost_frame)
3844 /* We couldn't find a push srp in the prologue, so this must be
3845 a leaf function, and thus we use the srp register directly.
3846 This should happen at most once, for the innermost function. */
3847 read_register_gen (SRP_REGNUM, (char *) &pc);
3851 /* Couldn't find an outer frame. */
3855 /* Reset flag. (In case the innermost frame wasn't a leaf, we don't
3856 want to look at the srp register later either). */
3857 innermost_frame = 0;
3859 /* Now, add the offset for everything up to, and including push srp,
3860 that was held back during the prologue parsing. */
3867 _initialize_cris_tdep (void)
3869 struct cmd_list_element *c;
3871 gdbarch_register (bfd_arch_cris, cris_gdbarch_init, cris_dump_tdep);
3873 /* Used in disassembly. */
3874 tm_print_insn = cris_delayed_get_disassembler;
3876 /* CRIS-specific user-commands. */
3877 c = add_set_cmd ("cris-version", class_support, var_integer,
3878 (char *) &usr_cmd_cris_version,
3879 "Set the current CRIS version.", &setlist);
3880 set_cmd_sfunc (c, cris_version_update);
3881 add_show_from_set (c, &showlist);
3883 c = add_set_enum_cmd ("cris-mode", class_support, cris_mode_enums,
3885 "Set the current CRIS mode.", &setlist);
3886 set_cmd_sfunc (c, cris_mode_update);
3887 add_show_from_set (c, &showlist);
3889 c = add_set_enum_cmd ("cris-abi", class_support, cris_abi_enums,
3891 "Set the current CRIS ABI version.", &setlist);
3892 set_cmd_sfunc (c, cris_abi_update);
3893 add_show_from_set (c, &showlist);
3895 c = add_cmd ("cris-fpless-backtrace", class_support, cris_fpless_backtrace,
3896 "Display call chain using the subroutine return pointer.\n"
3897 "Note that this displays the address after the jump to the "
3898 "subroutine.", &cmdlist);
3900 add_core_fns (&cris_elf_core_fns);
3904 /* Prints out all target specific values. */
3907 cris_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
3909 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3912 fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_version = %i\n",
3913 tdep->cris_version);
3914 fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_mode = %s\n",
3916 fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_abi = %s\n",
3923 cris_version_update (char *ignore_args, int from_tty,
3924 struct cmd_list_element *c)
3926 struct gdbarch_info info;
3928 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
3929 the set command passed as a parameter. The clone operation will
3930 include (BUG?) any ``set'' command callback, if present.
3931 Commands like ``info set'' call all the ``show'' command
3932 callbacks. Unfortunatly, for ``show'' commands cloned from
3933 ``set'', this includes callbacks belonging to ``set'' commands.
3934 Making this worse, this only occures if add_show_from_set() is
3935 called after add_cmd_sfunc() (BUG?). */
3937 /* From here on, trust the user's CRIS version setting. */
3938 if (cmd_type (c) == set_cmd)
3940 usr_cmd_cris_version_valid = 1;
3942 /* Update the current architecture, if needed. */
3943 gdbarch_info_init (&info);
3944 if (!gdbarch_update_p (info))
3945 internal_error (__FILE__, __LINE__, "cris_gdbarch_update: failed to update architecture.");
3950 cris_mode_update (char *ignore_args, int from_tty,
3951 struct cmd_list_element *c)
3953 struct gdbarch_info info;
3955 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
3956 the set command passed as a parameter. The clone operation will
3957 include (BUG?) any ``set'' command callback, if present.
3958 Commands like ``info set'' call all the ``show'' command
3959 callbacks. Unfortunatly, for ``show'' commands cloned from
3960 ``set'', this includes callbacks belonging to ``set'' commands.
3961 Making this worse, this only occures if add_show_from_set() is
3962 called after add_cmd_sfunc() (BUG?). */
3964 /* From here on, trust the user's CRIS mode setting. */
3965 if (cmd_type (c) == set_cmd)
3967 usr_cmd_cris_mode_valid = 1;
3969 /* Update the current architecture, if needed. */
3970 gdbarch_info_init (&info);
3971 if (!gdbarch_update_p (info))
3972 internal_error (__FILE__, __LINE__, "cris_gdbarch_update: failed to update architecture.");
3977 cris_abi_update (char *ignore_args, int from_tty,
3978 struct cmd_list_element *c)
3980 struct gdbarch_info info;
3982 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
3983 the set command passed as a parameter. The clone operation will
3984 include (BUG?) any ``set'' command callback, if present.
3985 Commands like ``info set'' call all the ``show'' command
3986 callbacks. Unfortunatly, for ``show'' commands cloned from
3987 ``set'', this includes callbacks belonging to ``set'' commands.
3988 Making this worse, this only occures if add_show_from_set() is
3989 called after add_cmd_sfunc() (BUG?). */
3991 /* From here on, trust the user's CRIS ABI setting. */
3992 if (cmd_type (c) == set_cmd)
3994 usr_cmd_cris_abi_valid = 1;
3996 /* Update the current architecture, if needed. */
3997 gdbarch_info_init (&info);
3998 if (!gdbarch_update_p (info))
3999 internal_error (__FILE__, __LINE__, "cris_gdbarch_update: failed to update architecture.");
4003 /* Copied from pa64solib.c, with a couple of minor changes. */
4006 bfd_lookup_symbol (bfd *abfd, const char *symname)
4008 unsigned int storage_needed;
4010 asymbol **symbol_table;
4011 unsigned int number_of_symbols;
4013 struct cleanup *back_to;
4014 CORE_ADDR symaddr = 0;
4016 storage_needed = bfd_get_symtab_upper_bound (abfd);
4018 if (storage_needed > 0)
4020 symbol_table = (asymbol **) xmalloc (storage_needed);
4021 back_to = make_cleanup (free, (PTR) symbol_table);
4022 number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
4024 for (i = 0; i < number_of_symbols; i++)
4026 sym = *symbol_table++;
4027 if (!strcmp (sym->name, symname))
4029 /* Bfd symbols are section relative. */
4030 symaddr = sym->value + sym->section->vma;
4034 do_cleanups (back_to);
4039 static struct gdbarch *
4040 cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
4042 struct gdbarch *gdbarch;
4043 struct gdbarch_tdep *tdep;
4045 const char *cris_mode;
4046 const char *cris_abi;
4047 CORE_ADDR cris_abi_sym = 0;
4050 if (usr_cmd_cris_version_valid)
4052 /* Trust the user's CRIS version setting. */
4053 cris_version = usr_cmd_cris_version;
4057 /* Assume it's CRIS version 10. */
4061 if (usr_cmd_cris_mode_valid)
4063 /* Trust the user's CRIS mode setting. */
4064 cris_mode = usr_cmd_cris_mode;
4066 else if (cris_version == 10)
4068 /* Assume CRIS version 10 is in user mode. */
4069 cris_mode = CRIS_MODE_USER;
4073 /* Strictly speaking, older CRIS version don't have a supervisor mode,
4074 but we regard its only mode as supervisor mode. */
4075 cris_mode = CRIS_MODE_SUPERVISOR;
4078 if (usr_cmd_cris_abi_valid)
4080 /* Trust the user's ABI setting. */
4081 cris_abi = usr_cmd_cris_abi;
4085 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
4087 /* An elf target uses the new ABI. */
4088 cris_abi = CRIS_ABI_V2;
4090 else if (bfd_get_flavour (info.abfd) == bfd_target_aout_flavour)
4092 /* An a.out target may use either ABI. Look for hints in the
4094 cris_abi_sym = bfd_lookup_symbol (info.abfd, CRIS_ABI_SYMBOL);
4095 cris_abi = cris_abi_sym ? CRIS_ABI_V2 : CRIS_ABI_ORIGINAL;
4099 /* Unknown bfd flavour. Assume it's the new ABI. */
4100 cris_abi = CRIS_ABI_V2;
4103 else if (arches != NULL)
4105 /* No bfd available. Stick with the ABI from the most recently
4106 selected architecture of this same family (the head of arches
4107 always points to this). (This is to avoid changing the ABI
4108 when the user updates the architecture with the 'set
4109 cris-version' command.) */
4110 cris_abi = gdbarch_tdep (arches->gdbarch)->cris_abi;
4114 /* No bfd, and no previously selected architecture available.
4115 Assume it's the new ABI. */
4116 cris_abi = CRIS_ABI_V2;
4119 /* Make the current settings visible to the user. */
4120 usr_cmd_cris_version = cris_version;
4121 usr_cmd_cris_mode = cris_mode;
4122 usr_cmd_cris_abi = cris_abi;
4124 /* Find a candidate among the list of pre-declared architectures. Both
4125 CRIS version and ABI must match. */
4126 for (arches = gdbarch_list_lookup_by_info (arches, &info);
4128 arches = gdbarch_list_lookup_by_info (arches->next, &info))
4130 if ((gdbarch_tdep (arches->gdbarch)->cris_version == cris_version)
4131 && (gdbarch_tdep (arches->gdbarch)->cris_mode == cris_mode)
4132 && (gdbarch_tdep (arches->gdbarch)->cris_abi == cris_abi))
4133 return arches->gdbarch;
4136 /* No matching architecture was found. Create a new one. */
4137 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
4138 gdbarch = gdbarch_alloc (&info, tdep);
4140 tdep->cris_version = cris_version;
4141 tdep->cris_mode = cris_mode;
4142 tdep->cris_abi = cris_abi;
4144 /* INIT shall ensure that the INFO.BYTE_ORDER is non-zero. */
4145 switch (info.byte_order)
4147 case BFD_ENDIAN_LITTLE:
4151 case BFD_ENDIAN_BIG:
4152 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: big endian byte order in info");
4156 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unknown byte order in info");
4159 /* Initialize the ABI dependent things. */
4160 if (tdep->cris_abi == CRIS_ABI_ORIGINAL)
4162 set_gdbarch_double_bit (gdbarch, 32);
4163 set_gdbarch_push_arguments (gdbarch, cris_abi_original_push_arguments);
4164 set_gdbarch_deprecated_store_return_value (gdbarch,
4165 cris_abi_original_store_return_value);
4166 set_gdbarch_deprecated_extract_return_value
4167 (gdbarch, cris_abi_original_extract_return_value);
4168 set_gdbarch_reg_struct_has_addr
4169 (gdbarch, cris_abi_original_reg_struct_has_addr);
4171 else if (tdep->cris_abi == CRIS_ABI_V2)
4173 set_gdbarch_double_bit (gdbarch, 64);
4174 set_gdbarch_push_arguments (gdbarch, cris_abi_v2_push_arguments);
4175 set_gdbarch_deprecated_store_return_value (gdbarch, cris_abi_v2_store_return_value);
4176 set_gdbarch_deprecated_extract_return_value
4177 (gdbarch, cris_abi_v2_extract_return_value);
4178 set_gdbarch_reg_struct_has_addr (gdbarch,
4179 cris_abi_v2_reg_struct_has_addr);
4182 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unknown CRIS ABI");
4184 /* The default definition of a long double is 2 * TARGET_DOUBLE_BIT,
4185 which means we have to set this explicitly. */
4186 set_gdbarch_long_double_bit (gdbarch, 64);
4188 /* There are 32 registers (some of which may not be implemented). */
4189 set_gdbarch_num_regs (gdbarch, 32);
4190 set_gdbarch_sp_regnum (gdbarch, 14);
4191 set_gdbarch_fp_regnum (gdbarch, 8);
4192 set_gdbarch_pc_regnum (gdbarch, 15);
4194 set_gdbarch_register_name (gdbarch, cris_register_name);
4196 /* Length of ordinary registers used in push_word and a few other places.
4197 REGISTER_RAW_SIZE is the real way to know how big a register is. */
4198 set_gdbarch_register_size (gdbarch, 4);
4201 set_gdbarch_register_bytes_ok (gdbarch, cris_register_bytes_ok);
4202 set_gdbarch_software_single_step (gdbarch, cris_software_single_step);
4205 set_gdbarch_cannot_store_register (gdbarch, cris_cannot_store_register);
4206 set_gdbarch_cannot_fetch_register (gdbarch, cris_cannot_fetch_register);
4209 /* The total amount of space needed to store (in an array called registers)
4210 GDB's copy of the machine's register state. Note: We can not use
4211 cris_register_size at this point, since it relies on current_gdbarch
4213 switch (tdep->cris_version)
4219 /* Support for these may be added later. */
4220 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unsupported CRIS version");
4225 /* CRIS v8 and v9, a.k.a. ETRAX 100. General registers R0 - R15
4226 (32 bits), special registers P0 - P1 (8 bits), P4 - P5 (16 bits),
4227 and P8 - P14 (32 bits). */
4228 register_bytes = (16 * 4) + (2 * 1) + (2 * 2) + (7 * 4);
4233 /* CRIS v10 and v11, a.k.a. ETRAX 100LX. In addition to ETRAX 100,
4234 P7 (32 bits), and P15 (32 bits) have been implemented. */
4235 register_bytes = (16 * 4) + (2 * 1) + (2 * 2) + (9 * 4);
4239 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unknown CRIS version");
4242 set_gdbarch_register_bytes (gdbarch, register_bytes);
4244 /* Returns the register offset for the first byte of register regno's space
4245 in the saved register state. */
4246 set_gdbarch_register_byte (gdbarch, cris_register_offset);
4248 /* The length of the registers in the actual machine representation. */
4249 set_gdbarch_register_raw_size (gdbarch, cris_register_size);
4251 /* The largest value REGISTER_RAW_SIZE can have. */
4252 set_gdbarch_max_register_raw_size (gdbarch, 32);
4254 /* The length of the registers in the program's representation. */
4255 set_gdbarch_register_virtual_size (gdbarch, cris_register_size);
4257 /* The largest value REGISTER_VIRTUAL_SIZE can have. */
4258 set_gdbarch_max_register_virtual_size (gdbarch, 32);
4260 set_gdbarch_register_virtual_type (gdbarch, cris_register_virtual_type);
4262 /* Use generic dummy frames. */
4263 set_gdbarch_use_generic_dummy_frames (gdbarch, 1);
4265 /* Where to execute the call in the memory segments. */
4266 set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT);
4267 set_gdbarch_call_dummy_address (gdbarch, entry_point_address);
4269 /* Start execution at the beginning of dummy. */
4270 set_gdbarch_call_dummy_start_offset (gdbarch, 0);
4271 set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 0);
4273 /* Set to 1 since call_dummy_breakpoint_offset was defined. */
4274 set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1);
4276 /* Read all about dummy frames in blockframe.c. */
4277 set_gdbarch_call_dummy_length (gdbarch, 0);
4278 set_gdbarch_pc_in_call_dummy (gdbarch, pc_in_call_dummy_at_entry_point);
4280 /* Defined to 1 to indicate that the target supports inferior function
4282 set_gdbarch_call_dummy_p (gdbarch, 1);
4283 set_gdbarch_call_dummy_words (gdbarch, 0);
4284 set_gdbarch_sizeof_call_dummy_words (gdbarch, 0);
4286 /* No stack adjustment needed when peforming an inferior function call. */
4287 set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
4288 set_gdbarch_fix_call_dummy (gdbarch, generic_fix_call_dummy);
4290 set_gdbarch_get_saved_register (gdbarch, generic_get_saved_register);
4292 /* No register requires conversion from raw format to virtual format. */
4293 set_gdbarch_register_convertible (gdbarch, generic_register_convertible_not);
4295 set_gdbarch_push_dummy_frame (gdbarch, generic_push_dummy_frame);
4296 set_gdbarch_push_return_address (gdbarch, cris_push_return_address);
4297 set_gdbarch_pop_frame (gdbarch, cris_pop_frame);
4299 set_gdbarch_store_struct_return (gdbarch, cris_store_struct_return);
4300 set_gdbarch_deprecated_extract_struct_value_address
4301 (gdbarch, cris_extract_struct_value_address);
4302 set_gdbarch_use_struct_convention (gdbarch, cris_use_struct_convention);
4304 set_gdbarch_frame_init_saved_regs (gdbarch, cris_frame_init_saved_regs);
4305 set_gdbarch_init_extra_frame_info (gdbarch, cris_init_extra_frame_info);
4306 set_gdbarch_skip_prologue (gdbarch, cris_skip_prologue);
4307 set_gdbarch_prologue_frameless_p (gdbarch, generic_prologue_frameless_p);
4309 /* The stack grows downward. */
4310 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
4312 set_gdbarch_breakpoint_from_pc (gdbarch, cris_breakpoint_from_pc);
4314 /* The PC must not be decremented after a breakpoint. (The breakpoint
4315 handler takes care of that.) */
4316 set_gdbarch_decr_pc_after_break (gdbarch, 0);
4318 /* Offset from address of function to start of its code. */
4319 set_gdbarch_function_start_offset (gdbarch, 0);
4321 /* The number of bytes at the start of arglist that are not really args,
4322 0 in the CRIS ABI. */
4323 set_gdbarch_frame_args_skip (gdbarch, 0);
4324 set_gdbarch_frameless_function_invocation
4325 (gdbarch, cris_frameless_function_invocation);
4326 set_gdbarch_frame_chain (gdbarch, cris_frame_chain);
4327 set_gdbarch_frame_chain_valid (gdbarch, generic_file_frame_chain_valid);
4329 set_gdbarch_frame_saved_pc (gdbarch, cris_frame_saved_pc);
4330 set_gdbarch_frame_args_address (gdbarch, cris_frame_args_address);
4331 set_gdbarch_frame_locals_address (gdbarch, cris_frame_locals_address);
4332 set_gdbarch_saved_pc_after_call (gdbarch, cris_saved_pc_after_call);
4334 set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
4336 /* No extra stack alignment needed. Set to 1 by default. */
4337 set_gdbarch_extra_stack_alignment_needed (gdbarch, 0);
4339 /* Helpful for backtracing and returning in a call dummy. */
4340 set_gdbarch_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos);
4342 /* Use target_specific function to define link map offsets. */
4343 set_solib_svr4_fetch_link_map_offsets
4344 (gdbarch, cris_linux_svr4_fetch_link_map_offsets);