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. */
40 /* There are no floating point registers. Used in gdbserver low-linux.c. */
43 /* There are 16 general registers. */
46 /* There are 16 special registers. */
50 /* Register numbers of various important registers.
51 FP_REGNUM Contains address of executing stack frame.
52 STR_REGNUM Contains the address of structure return values.
53 RET_REGNUM Contains the return value when shorter than or equal to 32 bits
54 ARG1_REGNUM Contains the first parameter to a function.
55 ARG2_REGNUM Contains the second parameter to a function.
56 ARG3_REGNUM Contains the third parameter to a function.
57 ARG4_REGNUM Contains the fourth parameter to a function. Rest on stack.
58 SP_REGNUM Contains address of top of stack.
59 PC_REGNUM Contains address of next instruction.
60 SRP_REGNUM Subroutine return pointer register.
61 BRP_REGNUM Breakpoint return pointer register. */
63 /* FP_REGNUM = 8, SP_REGNUM = 14, and PC_REGNUM = 15 have been incorporated
64 into the multi-arch framework. */
68 /* Enums with respect to the general registers, valid for all
77 /* Enums with respect to the special registers, some of which may not be
78 applicable to all CRIS versions. */
95 extern const struct cris_spec_reg cris_spec_regs[];
97 /* CRIS version, set via the user command 'set cris-version'. Affects
98 register names and sizes.*/
99 static int usr_cmd_cris_version;
101 /* Indicates whether to trust the above variable. */
102 static int usr_cmd_cris_version_valid = 0;
104 /* CRIS mode, set via the user command 'set cris-mode'. Affects availability
105 of some registers. */
106 static const char *usr_cmd_cris_mode;
108 /* Indicates whether to trust the above variable. */
109 static int usr_cmd_cris_mode_valid = 0;
111 static const char CRIS_MODE_USER[] = "CRIS_MODE_USER";
112 static const char CRIS_MODE_SUPERVISOR[] = "CRIS_MODE_SUPERVISOR";
113 static const char *cris_mode_enums[] =
116 CRIS_MODE_SUPERVISOR,
120 /* CRIS ABI, set via the user command 'set cris-abi'.
121 There are two flavours:
122 1. Original ABI with 32-bit doubles, where arguments <= 4 bytes are
124 2. New ABI with 64-bit doubles, where arguments <= 8 bytes are passed by
126 static const char *usr_cmd_cris_abi;
128 /* Indicates whether to trust the above variable. */
129 static int usr_cmd_cris_abi_valid = 0;
131 /* These variables are strings instead of enums to make them usable as
132 parameters to add_set_enum_cmd. */
133 static const char CRIS_ABI_ORIGINAL[] = "CRIS_ABI_ORIGINAL";
134 static const char CRIS_ABI_V2[] = "CRIS_ABI_V2";
135 static const char CRIS_ABI_SYMBOL[] = ".$CRIS_ABI_V2";
136 static const char *cris_abi_enums[] =
143 /* CRIS architecture specific information. */
147 const char *cris_mode;
148 const char *cris_abi;
151 /* Functions for accessing target dependent data. */
156 return (gdbarch_tdep (current_gdbarch)->cris_version);
162 return (gdbarch_tdep (current_gdbarch)->cris_mode);
168 return (gdbarch_tdep (current_gdbarch)->cris_abi);
171 /* For saving call-clobbered contents in R9 when returning structs. */
172 static CORE_ADDR struct_return_address;
174 struct frame_extra_info
180 /* The instruction environment needed to find single-step breakpoints. */
182 struct instruction_environment
184 unsigned long reg[NUM_GENREGS];
185 unsigned long preg[NUM_SPECREGS];
186 unsigned long branch_break_address;
187 unsigned long delay_slot_pc;
188 unsigned long prefix_value;
193 int delay_slot_pc_active;
195 int disable_interrupt;
198 /* Save old breakpoints in order to restore the state before a single_step.
199 At most, two breakpoints will have to be remembered. */
201 char binsn_quantum[BREAKPOINT_MAX];
202 static binsn_quantum break_mem[2];
203 static CORE_ADDR next_pc = 0;
204 static CORE_ADDR branch_target_address = 0;
205 static unsigned char branch_break_inserted = 0;
207 /* Machine-dependencies in CRIS for opcodes. */
209 /* Instruction sizes. */
210 enum cris_instruction_sizes
217 /* Addressing modes. */
218 enum cris_addressing_modes
225 /* Prefix addressing modes. */
226 enum cris_prefix_addressing_modes
228 PREFIX_INDEX_MODE = 2,
229 PREFIX_ASSIGN_MODE = 3,
231 /* Handle immediate byte offset addressing mode prefix format. */
232 PREFIX_OFFSET_MODE = 2
235 /* Masks for opcodes. */
236 enum cris_opcode_masks
238 BRANCH_SIGNED_SHORT_OFFSET_MASK = 0x1,
239 SIGNED_EXTEND_BIT_MASK = 0x2,
240 SIGNED_BYTE_MASK = 0x80,
241 SIGNED_BYTE_EXTEND_MASK = 0xFFFFFF00,
242 SIGNED_WORD_MASK = 0x8000,
243 SIGNED_WORD_EXTEND_MASK = 0xFFFF0000,
244 SIGNED_DWORD_MASK = 0x80000000,
245 SIGNED_QUICK_VALUE_MASK = 0x20,
246 SIGNED_QUICK_VALUE_EXTEND_MASK = 0xFFFFFFC0
249 /* Functions for opcodes. The general form of the ETRAX 16-bit instruction:
257 cris_get_operand2 (unsigned short insn)
259 return ((insn & 0xF000) >> 12);
263 cris_get_mode (unsigned short insn)
265 return ((insn & 0x0C00) >> 10);
269 cris_get_opcode (unsigned short insn)
271 return ((insn & 0x03C0) >> 6);
275 cris_get_size (unsigned short insn)
277 return ((insn & 0x0030) >> 4);
281 cris_get_operand1 (unsigned short insn)
283 return (insn & 0x000F);
286 /* Additional functions in order to handle opcodes. */
289 cris_get_wide_opcode (unsigned short insn)
291 return ((insn & 0x03E0) >> 5);
295 cris_get_short_size (unsigned short insn)
297 return ((insn & 0x0010) >> 4);
301 cris_get_quick_value (unsigned short insn)
303 return (insn & 0x003F);
307 cris_get_bdap_quick_offset (unsigned short insn)
309 return (insn & 0x00FF);
313 cris_get_branch_short_offset (unsigned short insn)
315 return (insn & 0x00FF);
319 cris_get_asr_shift_steps (unsigned long value)
321 return (value & 0x3F);
325 cris_get_asr_quick_shift_steps (unsigned short insn)
327 return (insn & 0x1F);
331 cris_get_clear_size (unsigned short insn)
333 return ((insn) & 0xC000);
337 cris_is_signed_extend_bit_on (unsigned short insn)
339 return (((insn) & 0x20) == 0x20);
343 cris_is_xflag_bit_on (unsigned short insn)
345 return (((insn) & 0x1000) == 0x1000);
349 cris_set_size_to_dword (unsigned short *insn)
356 cris_get_signed_offset (unsigned short insn)
358 return ((char) (insn & 0x00FF));
361 /* Calls an op function given the op-type, working on the insn and the
363 static void cris_gdb_func (enum cris_op_type, unsigned short, inst_env_type *);
365 static CORE_ADDR cris_skip_prologue_main (CORE_ADDR pc, int frameless_p);
367 static struct gdbarch *cris_gdbarch_init (struct gdbarch_info,
368 struct gdbarch_list *);
370 static int cris_delayed_get_disassembler (bfd_vma, disassemble_info *);
372 static void cris_dump_tdep (struct gdbarch *, struct ui_file *);
374 static void cris_version_update (char *ignore_args, int from_tty,
375 struct cmd_list_element *c);
377 static void cris_mode_update (char *ignore_args, int from_tty,
378 struct cmd_list_element *c);
380 static void cris_abi_update (char *ignore_args, int from_tty,
381 struct cmd_list_element *c);
383 static CORE_ADDR bfd_lookup_symbol (bfd *, const char *);
385 /* Frames information. The definition of the struct frame_info is
389 int signal_handler_caller
393 If the compilation option -fno-omit-frame-pointer is present the
394 variable frame will be set to the content of R8 which is the frame
397 The variable pc contains the address where execution is performed
398 in the present frame. The innermost frame contains the current content
399 of the register PC. All other frames contain the content of the
400 register PC in the next frame.
402 The variable signal_handler_caller is non-zero when the frame is
403 associated with the call of a signal handler.
405 The variable return_pc contains the address where execution should be
406 resumed when the present frame has finished, the return address.
408 The variable leaf_function is 1 if the return address is in the register
409 SRP, and 0 if it is on the stack.
411 Prologue instructions C-code.
412 The prologue may consist of (-fno-omit-frame-pointer)
416 move.d sp,r8 move.d sp,r8
418 movem rY,[sp] movem rY,[sp]
419 move.S rZ,[r8-U] move.S rZ,[r8-U]
421 where 1 is a non-terminal function, and 2 is a leaf-function.
423 Note that this assumption is extremely brittle, and will break at the
424 slightest change in GCC's prologue.
426 If local variables are declared or register contents are saved on stack
427 the subq-instruction will be present with X as the number of bytes
428 needed for storage. The reshuffle with respect to r8 may be performed
429 with any size S (b, w, d) and any of the general registers Z={0..13}.
430 The offset U should be representable by a signed 8-bit value in all cases.
431 Thus, the prefix word is assumed to be immediate byte offset mode followed
432 by another word containing the instruction.
441 Prologue instructions C++-code.
442 Case 1) and 2) in the C-code may be followed by
448 move.S [r8+U],rZ ; P4
450 if any of the call parameters are stored. The host expects these
451 instructions to be executed in order to get the call parameters right. */
453 /* Examine the prologue of a function. The variable ip is the address of
454 the first instruction of the prologue. The variable limit is the address
455 of the first instruction after the prologue. The variable fi contains the
456 information in struct frame_info. The variable frameless_p controls whether
457 the entire prologue is examined (0) or just enough instructions to
458 determine that it is a prologue (1). */
461 cris_examine (CORE_ADDR ip, CORE_ADDR limit, struct frame_info *fi,
464 /* Present instruction. */
467 /* Next instruction, lookahead. */
468 unsigned short insn_next;
471 /* Is there a push fp? */
474 /* Number of byte on stack used for local variables and movem. */
477 /* Highest register number in a movem. */
480 /* move.d r<source_register>,rS */
481 short source_register;
483 /* This frame is with respect to a leaf until a push srp is found. */
484 fi->extra_info->leaf_function = 1;
486 /* This frame is without the FP until a push fp is found. */
489 /* Assume nothing on stack. */
493 /* No information about register contents so far. */
495 /* We only want to know the end of the prologue when fi->saved_regs == 0.
496 When the saved registers are allocated full information is required. */
499 for (regno = 0; regno < NUM_REGS; regno++)
500 fi->saved_regs[regno] = 0;
503 /* Find the prologue instructions. */
506 insn = read_memory_unsigned_integer (ip, sizeof (short));
507 ip += sizeof (short);
510 /* push <reg> 32 bit instruction */
511 insn_next = read_memory_unsigned_integer (ip, sizeof (short));
512 ip += sizeof (short);
513 regno = cris_get_operand2 (insn_next);
514 if (regno == (SRP_REGNUM - NUM_GENREGS))
520 fi->extra_info->leaf_function = 0;
522 else if (regno == FP_REGNUM)
527 else if (insn == 0x866E)
536 else if (cris_get_operand2 (insn) == SP_REGNUM
537 && cris_get_mode (insn) == 0x0000
538 && cris_get_opcode (insn) == 0x000A)
541 val = cris_get_quick_value (insn);
543 else if (cris_get_mode (insn) == 0x0002
544 && cris_get_opcode (insn) == 0x000F
545 && cris_get_size (insn) == 0x0003
546 && cris_get_operand1 (insn) == SP_REGNUM)
548 /* movem r<regsave>,[sp] */
553 regsave = cris_get_operand2 (insn);
555 else if (cris_get_operand2 (insn) == SP_REGNUM
556 && ((insn & 0x0F00) >> 8) == 0x0001
557 && (cris_get_signed_offset (insn) < 0))
559 /* Immediate byte offset addressing prefix word with sp as base
560 register. Used for CRIS v8 i.e. ETRAX 100 and newer if <val>
561 is between 64 and 128.
562 movem r<regsave>,[sp=sp-<val>] */
563 val = -cris_get_signed_offset (insn);
564 insn_next = read_memory_unsigned_integer (ip, sizeof (short));
565 ip += sizeof (short);
566 if (cris_get_mode (insn_next) == PREFIX_ASSIGN_MODE
567 && cris_get_opcode (insn_next) == 0x000F
568 && cris_get_size (insn_next) == 0x0003
569 && cris_get_operand1 (insn_next) == SP_REGNUM)
575 regsave = cris_get_operand2 (insn_next);
579 /* The prologue ended before the limit was reached. */
580 ip -= 2 * sizeof (short);
584 else if (cris_get_mode (insn) == 0x0001
585 && cris_get_opcode (insn) == 0x0009
586 && cris_get_size (insn) == 0x0002)
588 /* move.d r<10..13>,r<0..15> */
593 source_register = cris_get_operand1 (insn);
594 if (source_register < ARG1_REGNUM || source_register > ARG4_REGNUM)
596 /* The prologue ended before the limit was reached. */
597 ip -= sizeof (short);
601 else if (cris_get_operand2 (insn) == FP_REGNUM
602 /* The size is a fixed-size. */
603 && ((insn & 0x0F00) >> 8) == 0x0001
604 /* A negative offset. */
605 && (cris_get_signed_offset (insn) < 0))
607 /* move.S rZ,[r8-U] (?) */
608 insn_next = read_memory_unsigned_integer (ip, sizeof (short));
609 ip += sizeof (short);
610 regno = cris_get_operand2 (insn_next);
611 if ((regno >= 0 && regno < SP_REGNUM)
612 && cris_get_mode (insn_next) == PREFIX_OFFSET_MODE
613 && cris_get_opcode (insn_next) == 0x000F)
615 /* move.S rZ,[r8-U] */
620 /* The prologue ended before the limit was reached. */
621 ip -= 2 * sizeof (short);
625 else if (cris_get_operand2 (insn) == FP_REGNUM
626 /* The size is a fixed-size. */
627 && ((insn & 0x0F00) >> 8) == 0x0001
628 /* A positive offset. */
629 && (cris_get_signed_offset (insn) > 0))
631 /* move.S [r8+U],rZ (?) */
632 insn_next = read_memory_unsigned_integer (ip, sizeof (short));
633 ip += sizeof (short);
634 regno = cris_get_operand2 (insn_next);
635 if ((regno >= 0 && regno < SP_REGNUM)
636 && cris_get_mode (insn_next) == PREFIX_OFFSET_MODE
637 && cris_get_opcode (insn_next) == 0x0009
638 && cris_get_operand1 (insn_next) == regno)
640 /* move.S [r8+U],rZ */
645 /* The prologue ended before the limit was reached. */
646 ip -= 2 * sizeof (short);
652 /* The prologue ended before the limit was reached. */
653 ip -= sizeof (short);
659 /* We only want to know the end of the prologue when
660 fi->saved_regs == 0. */
666 fi->saved_regs[FP_REGNUM] = FRAME_FP (fi);
668 /* Calculate the addresses. */
669 for (regno = regsave; regno >= 0; regno--)
671 fi->saved_regs[regno] = FRAME_FP (fi) - val;
674 if (fi->extra_info->leaf_function)
676 /* Set the register SP to contain the stack pointer of
678 fi->saved_regs[SP_REGNUM] = FRAME_FP (fi) + 4;
682 /* Set the register SP to contain the stack pointer of
684 fi->saved_regs[SP_REGNUM] = FRAME_FP (fi) + 8;
686 /* Set the register SRP to contain the return address of
688 fi->saved_regs[SRP_REGNUM] = FRAME_FP (fi) + 4;
694 /* Advance pc beyond any function entry prologue instructions at pc
695 to reach some "real" code. */
698 cris_skip_prologue (CORE_ADDR pc)
700 return cris_skip_prologue_main (pc, 0);
703 /* As cris_skip_prologue, but stops as soon as it knows that the function
704 has a frame. Its result is equal to its input pc if the function is
705 frameless, unequal otherwise. */
708 cris_skip_prologue_frameless_p (CORE_ADDR pc)
710 return cris_skip_prologue_main (pc, 1);
713 /* Given a PC value corresponding to the start of a function, return the PC
714 of the first instruction after the function prologue. */
717 cris_skip_prologue_main (CORE_ADDR pc, int frameless_p)
719 struct frame_info fi;
720 static struct frame_extra_info fei;
721 struct symtab_and_line sal = find_pc_line (pc, 0);
723 CORE_ADDR pc_after_prologue;
725 /* frame_info now contains dynamic memory. Since fi is a dummy here,
726 I use static memory for extra_info, and don't bother allocating
727 memory for saved_regs. */
729 fi.extra_info = &fei;
731 /* If there is no symbol information then sal.end == 0, and we end up
732 examining only the first instruction in the function prologue.
733 Exaggerating the limit seems to be harmless. */
735 best_limit = sal.end;
737 best_limit = pc + 100;
739 pc_after_prologue = cris_examine (pc, best_limit, &fi, frameless_p);
740 return pc_after_prologue;
743 /* Use the program counter to determine the contents and size of a breakpoint
744 instruction. It returns a pointer to a string of bytes that encode a
745 breakpoint instruction, stores the length of the string to *lenptr, and
746 adjusts pcptr (if necessary) to point to the actual memory location where
747 the breakpoint should be inserted. */
750 cris_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
752 static unsigned char break_insn[] = {0x38, 0xe9};
758 /* Returns the register SRP (subroutine return pointer) which must contain
759 the content of the register PC after a function call. */
762 cris_saved_pc_after_call ()
764 return read_register (SRP_REGNUM);
767 /* Returns 1 if spec_reg is applicable to the current gdbarch's CRIS version,
771 cris_spec_reg_applicable (struct cris_spec_reg spec_reg)
773 int version = cris_version ();
775 switch (spec_reg.applicable_version)
777 case cris_ver_version_all:
779 case cris_ver_warning:
780 /* Indeterminate/obsolete. */
783 /* Simulator only. */
786 return (version >= 0 && version <= 3);
788 return (version >= 3);
790 return (version == 8 || version == 9);
792 return (version >= 8);
794 return (version >= 10);
796 /* Invalid cris version. */
801 /* Returns the register size in unit byte. Returns 0 for an unimplemented
802 register, -1 for an invalid register. */
805 cris_register_size (int regno)
810 if (regno >= 0 && regno < NUM_GENREGS)
812 /* General registers (R0 - R15) are 32 bits. */
815 else if (regno >= NUM_GENREGS && regno < NUM_REGS)
817 /* Special register (R16 - R31). cris_spec_regs is zero-based.
818 Adjust regno accordingly. */
819 spec_regno = regno - NUM_GENREGS;
821 /* The entries in cris_spec_regs are stored in register number order,
822 which means we can shortcut into the array when searching it. */
823 for (i = spec_regno; cris_spec_regs[i].name != NULL; i++)
825 if (cris_spec_regs[i].number == spec_regno
826 && cris_spec_reg_applicable (cris_spec_regs[i]))
827 /* Go with the first applicable register. */
828 return cris_spec_regs[i].reg_size;
830 /* Special register not applicable to this CRIS version. */
835 /* Invalid register. */
840 /* Nonzero if regno should not be fetched from the target. This is the case
841 for unimplemented (size 0) and non-existant registers. */
844 cris_cannot_fetch_register (int regno)
846 return ((regno < 0 || regno >= NUM_REGS)
847 || (cris_register_size (regno) == 0));
850 /* Nonzero if regno should not be written to the target, for various
854 cris_cannot_store_register (int regno)
856 /* There are three kinds of registers we refuse to write to.
857 1. Those that not implemented.
858 2. Those that are read-only (depends on the processor mode).
859 3. Those registers to which a write has no effect.
862 if (regno < 0 || regno >= NUM_REGS || cris_register_size (regno) == 0)
863 /* Not implemented. */
866 else if (regno == VR_REGNUM)
870 else if (regno == P0_REGNUM || regno == P4_REGNUM || regno == P8_REGNUM)
871 /* Writing has no effect. */
874 else if (cris_mode () == CRIS_MODE_USER)
876 if (regno == IBR_REGNUM || regno == BAR_REGNUM || regno == BRP_REGNUM
877 || regno == IRP_REGNUM)
878 /* Read-only in user mode. */
885 /* Returns the register offset for the first byte of register regno's space
886 in the saved register state. Returns -1 for an invalid or unimplemented
890 cris_register_offset (int regno)
896 if (regno >= 0 && regno < NUM_REGS)
898 /* FIXME: The offsets should be cached and calculated only once,
899 when the architecture being debugged has changed. */
900 for (i = 0; i < regno; i++)
901 offset += cris_register_size (i);
907 /* Invalid register. */
912 /* Return the GDB type (defined in gdbtypes.c) for the "standard" data type
913 of data in register regno. */
916 cris_register_virtual_type (int regno)
918 if (regno == SP_REGNUM || regno == PC_REGNUM
919 || (regno > P8_REGNUM && regno < USP_REGNUM))
921 /* SP, PC, IBR, IRP, SRP, BAR, DCCR, BRP */
922 return lookup_pointer_type (builtin_type_void);
924 else if (regno == P8_REGNUM || regno == USP_REGNUM
925 || (regno >= 0 && regno < SP_REGNUM))
927 /* R0 - R13, P8, P15 */
928 return builtin_type_unsigned_long;
930 else if (regno > P3_REGNUM && regno < P8_REGNUM)
932 /* P4, CCR, DCR0, DCR1 */
933 return builtin_type_unsigned_short;
935 else if (regno > PC_REGNUM && regno < P4_REGNUM)
938 return builtin_type_unsigned_char;
942 /* Invalid register. */
943 return builtin_type_void;
947 /* Stores a function return value of type type, where valbuf is the address
948 of the value to be stored. */
950 /* In the original CRIS ABI, R10 is used to store return values. */
953 cris_abi_original_store_return_value (struct type *type, char *valbuf)
955 int len = TYPE_LENGTH (type);
957 if (len <= REGISTER_SIZE)
958 write_register_bytes (REGISTER_BYTE (RET_REGNUM), valbuf, len);
960 internal_error (__FILE__, __LINE__, "cris_abi_original_store_return_value: type length too large.");
963 /* In the CRIS ABI V2, R10 and R11 are used to store return values. */
966 cris_abi_v2_store_return_value (struct type *type, char *valbuf)
968 int len = TYPE_LENGTH (type);
970 if (len <= 2 * REGISTER_SIZE)
972 /* Note that this works since R10 and R11 are consecutive registers. */
973 write_register_bytes (REGISTER_BYTE (RET_REGNUM), valbuf, len);
976 internal_error (__FILE__, __LINE__, "cris_abi_v2_store_return_value: type length too large.");
979 /* Return the name of register regno as a string. Return NULL for an invalid or
980 unimplemented register. */
983 cris_register_name (int regno)
985 static char *cris_genreg_names[] =
986 { "r0", "r1", "r2", "r3", \
987 "r4", "r5", "r6", "r7", \
988 "r8", "r9", "r10", "r11", \
989 "r12", "r13", "sp", "pc" };
994 if (regno >= 0 && regno < NUM_GENREGS)
996 /* General register. */
997 return cris_genreg_names[regno];
999 else if (regno >= NUM_GENREGS && regno < NUM_REGS)
1001 /* Special register (R16 - R31). cris_spec_regs is zero-based.
1002 Adjust regno accordingly. */
1003 spec_regno = regno - NUM_GENREGS;
1005 /* The entries in cris_spec_regs are stored in register number order,
1006 which means we can shortcut into the array when searching it. */
1007 for (i = spec_regno; cris_spec_regs[i].name != NULL; i++)
1009 if (cris_spec_regs[i].number == spec_regno
1010 && cris_spec_reg_applicable (cris_spec_regs[i]))
1011 /* Go with the first applicable register. */
1012 return cris_spec_regs[i].name;
1014 /* Special register not applicable to this CRIS version. */
1019 /* Invalid register. */
1025 cris_register_bytes_ok (long bytes)
1027 return (bytes == REGISTER_BYTES);
1030 /* Extract from an array regbuf containing the raw register state a function
1031 return value of type type, and copy that, in virtual format, into
1034 /* In the original CRIS ABI, R10 is used to return values. */
1037 cris_abi_original_extract_return_value (struct type *type, char *regbuf,
1040 int len = TYPE_LENGTH (type);
1042 if (len <= REGISTER_SIZE)
1043 memcpy (valbuf, regbuf + REGISTER_BYTE (RET_REGNUM), len);
1045 internal_error (__FILE__, __LINE__, "cris_abi_original_extract_return_value: type length too large");
1048 /* In the CRIS ABI V2, R10 and R11 are used to store return values. */
1051 cris_abi_v2_extract_return_value (struct type *type, char *regbuf,
1054 int len = TYPE_LENGTH (type);
1056 if (len <= 2 * REGISTER_SIZE)
1057 memcpy (valbuf, regbuf + REGISTER_BYTE (RET_REGNUM), len);
1059 internal_error (__FILE__, __LINE__, "cris_abi_v2_extract_return_value: type length too large");
1062 /* Store the address of the place in which to copy the structure the
1063 subroutine will return. In the CRIS ABI, R9 is used in order to pass
1064 the address of the allocated area where a structure return value must
1065 be stored. R9 is call-clobbered, which means we must save it here for
1069 cris_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
1071 write_register (STR_REGNUM, addr);
1072 struct_return_address = addr;
1075 /* Extract from regbuf the address where a function should return a
1076 structure value. It's not there in the CRIS ABI, so we must do it another
1080 cris_extract_struct_value_address (char *regbuf)
1082 return struct_return_address;
1085 /* Returns 1 if a value of the given type being returned from a function
1086 must have space allocated for it on the stack. gcc_p is true if the
1087 function being considered is known to have been compiled by GCC.
1088 In the CRIS ABI, structure return values are passed to the called
1089 function by reference in register R9 to a caller-allocated area, so
1090 this is always true. */
1093 cris_use_struct_convention (int gcc_p, struct type *type)
1098 /* Returns 1 if the given type will be passed by pointer rather than
1101 /* In the original CRIS ABI, arguments shorter than or equal to 32 bits are
1105 cris_abi_original_reg_struct_has_addr (int gcc_p, struct type *type)
1107 return (TYPE_LENGTH (type) > 4);
1110 /* In the CRIS ABI V2, arguments shorter than or equal to 64 bits are passed
1114 cris_abi_v2_reg_struct_has_addr (int gcc_p, struct type *type)
1116 return (TYPE_LENGTH (type) > 8);
1119 /* Returns 1 if the function invocation represented by fi does not have a
1120 stack frame associated with it. Otherwise return 0. */
1123 cris_frameless_function_invocation (struct frame_info *fi)
1125 if (fi->signal_handler_caller)
1128 return frameless_look_for_prologue (fi);
1131 /* See frame.h. Determines the address of all registers in the current stack
1132 frame storing each in frame->saved_regs. Space for frame->saved_regs shall
1133 be allocated by FRAME_INIT_SAVED_REGS using either frame_saved_regs_zalloc
1134 or frame_obstack_alloc. */
1137 cris_frame_init_saved_regs (struct frame_info *fi)
1140 struct symtab_and_line sal;
1142 char *dummy_regs = generic_find_dummy_frame (fi->pc, fi->frame);
1144 /* Examine the entire prologue. */
1145 register int frameless_p = 0;
1147 /* Has this frame's registers already been initialized? */
1151 frame_saved_regs_zalloc (fi);
1155 /* I don't see this ever happening, considering the context in which
1156 cris_frame_init_saved_regs is called (always when we're not in
1158 memcpy (&fi->saved_regs, dummy_regs, sizeof (fi->saved_regs));
1162 ip = get_pc_function_start (fi->pc);
1163 sal = find_pc_line (ip, 0);
1165 /* If there is no symbol information then sal.end == 0, and we end up
1166 examining only the first instruction in the function prologue.
1167 Exaggerating the limit seems to be harmless. */
1169 best_limit = sal.end;
1171 best_limit = ip + 100;
1173 cris_examine (ip, best_limit, fi, frameless_p);
1177 /* Initialises the extra frame information at the creation of a new frame.
1178 The inparameter fromleaf is 0 when the call is from create_new_frame.
1179 When the call is from get_prev_frame_info, fromleaf is determined by
1180 cris_frameless_function_invocation. */
1183 cris_init_extra_frame_info (int fromleaf, struct frame_info *fi)
1187 /* Called from get_prev_frame. */
1188 fi->pc = FRAME_SAVED_PC (fi->next);
1191 fi->extra_info = (struct frame_extra_info *)
1192 frame_obstack_alloc (sizeof (struct frame_extra_info));
1194 fi->extra_info->return_pc = 0;
1195 fi->extra_info->leaf_function = 0;
1197 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
1199 /* We need to setup fi->frame here because run_stack_dummy gets it wrong
1200 by assuming it's always FP. */
1201 fi->frame = generic_read_register_dummy (fi->pc, fi->frame, SP_REGNUM);
1202 fi->extra_info->return_pc =
1203 generic_read_register_dummy (fi->pc, fi->frame, PC_REGNUM);
1205 /* FIXME: Is this necessarily true? */
1206 fi->extra_info->leaf_function = 0;
1210 cris_frame_init_saved_regs (fi);
1212 /* Check fromleaf/frameless_function_invocation. (FIXME) */
1214 if (fi->saved_regs[SRP_REGNUM] != 0)
1216 /* SRP was saved on the stack; non-leaf function. */
1217 fi->extra_info->return_pc =
1218 read_memory_integer (fi->saved_regs[SRP_REGNUM],
1219 REGISTER_RAW_SIZE (SRP_REGNUM));
1223 /* SRP is still in a register; leaf function. */
1224 fi->extra_info->return_pc = read_register (SRP_REGNUM);
1225 /* FIXME: Should leaf_function be set to 1 here? */
1226 fi->extra_info->leaf_function = 1;
1231 /* Return the content of the frame pointer in the present frame. In other
1232 words, determine the address of the calling function's frame. */
1235 cris_frame_chain (struct frame_info *fi)
1237 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
1241 else if (!inside_entry_file (fi->pc))
1243 return read_memory_unsigned_integer (FRAME_FP (fi), 4);
1251 /* Return the saved PC (which equals the return address) of this frame. */
1254 cris_frame_saved_pc (struct frame_info *fi)
1256 return fi->extra_info->return_pc;
1259 /* Return the address of the argument block for the frame described
1260 by struct frame_info. */
1263 cris_frame_args_address (struct frame_info *fi)
1265 return FRAME_FP (fi);
1268 /* Return the address of the locals block for the frame
1269 described by struct frame_info. */
1272 cris_frame_locals_address (struct frame_info *fi)
1274 return FRAME_FP (fi);
1277 /* Setup the function arguments for calling a function in the inferior. */
1280 cris_abi_original_push_arguments (int nargs, struct value **args,
1281 CORE_ADDR sp, int struct_return,
1282 CORE_ADDR struct_addr)
1293 /* Data and parameters reside in different areas on the stack.
1294 Both frame pointers grow toward higher addresses. */
1295 CORE_ADDR fp_params;
1298 /* Are we returning a value using a structure return or a normal value
1299 return? struct_addr is the address of the reserved space for the return
1300 structure to be written on the stack. */
1303 write_register (STR_REGNUM, struct_addr);
1306 /* Make sure there's space on the stack. Allocate space for data and a
1307 parameter to refer to that data. */
1308 for (argnum = 0, stack_alloc = 0; argnum < nargs; argnum++)
1309 stack_alloc += (TYPE_LENGTH (VALUE_TYPE (args[argnum])) + REGISTER_SIZE);
1311 /* We may over-allocate a little here, but that won't hurt anything. */
1313 /* Initialize stack frame pointers. */
1315 fp_data = sp + (nargs * REGISTER_SIZE);
1317 /* Now load as many as possible of the first arguments into
1318 registers, and push the rest onto the stack. */
1319 argreg = ARG1_REGNUM;
1322 for (argnum = 0; argnum < nargs; argnum++)
1324 type = VALUE_TYPE (args[argnum]);
1325 len = TYPE_LENGTH (type);
1326 val = (char *) VALUE_CONTENTS (args[argnum]);
1328 if (len <= REGISTER_SIZE && argreg <= ARG4_REGNUM)
1330 /* Data fits in a register; put it in the first available
1332 write_register (argreg, *(unsigned long *) val);
1335 else if (len > REGISTER_SIZE && argreg <= ARG4_REGNUM)
1337 /* Data does not fit in register; pass it on the stack and
1338 put its address in the first available register. */
1339 write_memory (fp_data, val, len);
1340 write_register (argreg, fp_data);
1344 else if (len > REGISTER_SIZE)
1346 /* Data does not fit in register; put both data and
1347 parameter on the stack. */
1348 write_memory (fp_data, val, len);
1349 write_memory (fp_params, (char *) (&fp_data), REGISTER_SIZE);
1351 fp_params += REGISTER_SIZE;
1355 /* Data fits in a register, but we are out of registers;
1356 put the parameter on the stack. */
1357 write_memory (fp_params, val, REGISTER_SIZE);
1358 fp_params += REGISTER_SIZE;
1366 cris_abi_v2_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
1367 int struct_return, CORE_ADDR struct_addr)
1376 /* The function's arguments and memory allocated by gdb for the arguments to
1377 point at reside in separate areas on the stack.
1378 Both frame pointers grow toward higher addresses. */
1382 /* Are we returning a value using a structure return or a normal value
1383 return? struct_addr is the address of the reserved space for the return
1384 structure to be written on the stack. */
1387 write_register (STR_REGNUM, struct_addr);
1390 /* Allocate enough to keep things word-aligned on both parts of the
1393 for (argnum = 0; argnum < nargs; argnum++)
1398 len = TYPE_LENGTH (VALUE_TYPE (args[argnum]));
1399 reg_demand = (len / REGISTER_SIZE) + (len % REGISTER_SIZE != 0 ? 1 : 0);
1401 /* reg_demand * REGISTER_SIZE is the amount of memory we might need to
1402 allocate for this argument. 2 * REGISTER_SIZE is the amount of stack
1403 space we might need to pass the argument itself (either by value or by
1405 stack_alloc += (reg_demand * REGISTER_SIZE + 2 * REGISTER_SIZE);
1408 /* We may over-allocate a little here, but that won't hurt anything. */
1410 /* Initialize frame pointers. */
1412 fp_mem = sp + (nargs * (2 * REGISTER_SIZE));
1414 /* Now load as many as possible of the first arguments into registers,
1415 and push the rest onto the stack. */
1416 argreg = ARG1_REGNUM;
1419 for (argnum = 0; argnum < nargs; argnum++)
1426 len = TYPE_LENGTH (VALUE_TYPE (args[argnum]));
1427 val = (char *) VALUE_CONTENTS (args[argnum]);
1429 /* How may registers worth of storage do we need for this argument? */
1430 reg_demand = (len / REGISTER_SIZE) + (len % REGISTER_SIZE != 0 ? 1 : 0);
1432 if (len <= (2 * REGISTER_SIZE)
1433 && (argreg + reg_demand - 1 <= ARG4_REGNUM))
1435 /* Data passed by value. Fits in available register(s). */
1436 for (i = 0; i < reg_demand; i++)
1438 write_register (argreg, *(unsigned long *) val);
1440 val += REGISTER_SIZE;
1443 else if (len <= (2 * REGISTER_SIZE) && argreg <= ARG4_REGNUM)
1445 /* Data passed by value. Does not fit in available register(s).
1446 Use the register(s) first, then the stack. */
1447 for (i = 0; i < reg_demand; i++)
1449 if (argreg <= ARG4_REGNUM)
1451 write_register (argreg, *(unsigned long *) val);
1453 val += REGISTER_SIZE;
1457 /* I guess this memory write could write the remaining data
1458 all at once instead of in REGISTER_SIZE chunks. */
1459 write_memory (fp_arg, val, REGISTER_SIZE);
1460 fp_arg += REGISTER_SIZE;
1461 val += REGISTER_SIZE;
1465 else if (len > (2 * REGISTER_SIZE))
1467 /* Data passed by reference. Put it on the stack. */
1468 write_memory (fp_mem, val, len);
1469 write_memory (fp_arg, (char *) (&fp_mem), REGISTER_SIZE);
1471 /* fp_mem need not be word-aligned since it's just a chunk of
1472 memory being pointed at. That is, += len would do. */
1473 fp_mem += reg_demand * REGISTER_SIZE;
1474 fp_arg += REGISTER_SIZE;
1478 /* Data passed by value. No available registers. Put it on
1480 write_memory (fp_arg, val, len);
1482 /* fp_arg must be word-aligned (i.e., don't += len) to match
1483 the function prologue. */
1484 fp_arg += reg_demand * REGISTER_SIZE;
1491 /* Never put the return address on the stack. The register SRP is pushed
1492 by the called function unless it is a leaf-function. Due to the BRP
1493 register the PC will change when continue is sent. */
1496 cris_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
1498 write_register (SRP_REGNUM, CALL_DUMMY_ADDRESS ());
1502 /* Restore the machine to the state it had before the current frame
1503 was created. Discard the innermost frame from the stack and restore
1504 all saved registers. */
1509 register struct frame_info *fi = get_current_frame ();
1511 register int stack_offset = 0;
1513 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
1515 /* This happens when we hit a breakpoint set at the entry point,
1516 when returning from a dummy frame. */
1517 generic_pop_dummy_frame ();
1521 cris_frame_init_saved_regs (fi);
1523 /* For each register, the address of where it was saved on entry to
1524 the frame now lies in fi->saved_regs[regno], or zero if it was not
1525 saved. This includes special registers such as PC and FP saved in
1526 special ways in the stack frame. The SP_REGNUM is even more
1527 special, the address here is the SP for the next frame, not the
1528 address where the SP was saved. */
1530 /* Restore general registers R0 - R7. They were pushed on the stack
1531 after SP was saved. */
1532 for (regno = 0; regno < FP_REGNUM; regno++)
1534 if (fi->saved_regs[regno])
1536 write_register (regno,
1537 read_memory_integer (fi->saved_regs[regno], 4));
1541 if (fi->saved_regs[FP_REGNUM])
1543 /* Pop the frame pointer (R8). It was pushed before SP
1545 write_register (FP_REGNUM,
1546 read_memory_integer (fi->saved_regs[FP_REGNUM], 4));
1549 /* Not a leaf function. */
1550 if (fi->saved_regs[SRP_REGNUM])
1552 /* SRP was pushed before SP was saved. */
1556 /* Restore the SP and adjust for R8 and (possibly) SRP. */
1557 write_register (SP_REGNUM, fi->saved_regs[FP_REGNUM] + stack_offset);
1561 /* Currently, we can't get the correct info into fi->saved_regs
1562 without a frame pointer. */
1565 /* Restore the PC. */
1566 write_register (PC_REGNUM, fi->extra_info->return_pc);
1568 flush_cached_frames ();
1571 /* Calculates a value that measures how good inst_args constraints an
1572 instruction. It stems from cris_constraint, found in cris-dis.c. */
1575 constraint (unsigned int insn, const signed char *inst_args,
1576 inst_env_type *inst_env)
1581 const char *s = inst_args;
1587 if ((insn & 0x30) == 0x30)
1592 /* A prefix operand. */
1593 if (inst_env->prefix_found)
1599 /* A "push" prefix. (This check was REMOVED by san 970921.) Check for
1600 valid "push" size. In case of special register, it may be != 4. */
1601 if (inst_env->prefix_found)
1607 retval = (((insn >> 0xC) & 0xF) == (insn & 0xF));
1615 tmp = (insn >> 0xC) & 0xF;
1616 for (i = 0; i < NUM_SPECREGS; i++)
1617 /* Since we match four bits, we will give a value of
1618 4 - 1 = 3 in a match. If there is a corresponding
1619 exact match of a special register in another pattern, it
1620 will get a value of 4, which will be higher. This should
1621 be correct in that an exact pattern would match better that
1623 Note that there is a reason for not returning zero; the
1624 pattern for "clear" is partly matched in the bit-pattern
1625 (the two lower bits must be zero), while the bit-pattern
1626 for a move from a special register is matched in the
1627 register constraint.
1628 This also means we will will have a race condition if
1629 there is a partly match in three bits in the bit pattern. */
1630 if (tmp == cris_spec_regs[i].number)
1635 if (i == NUM_SPECREGS)
1642 /* Returns the number of bits set in the variable value. */
1645 number_of_bits (unsigned int value)
1647 int number_of_bits = 0;
1651 number_of_bits += 1;
1652 value &= (value - 1);
1654 return number_of_bits;
1657 /* Finds the address that should contain the single step breakpoint(s).
1658 It stems from code in cris-dis.c. */
1661 find_cris_op (unsigned short insn, inst_env_type *inst_env)
1664 int max_level_of_match = -1;
1665 int max_matched = -1;
1668 for (i = 0; cris_opcodes[i].name != NULL; i++)
1670 if (((cris_opcodes[i].match & insn) == cris_opcodes[i].match)
1671 && ((cris_opcodes[i].lose & insn) == 0))
1673 level_of_match = constraint (insn, cris_opcodes[i].args, inst_env);
1674 if (level_of_match >= 0)
1677 number_of_bits (cris_opcodes[i].match | cris_opcodes[i].lose);
1678 if (level_of_match > max_level_of_match)
1681 max_level_of_match = level_of_match;
1682 if (level_of_match == 16)
1684 /* All bits matched, cannot find better. */
1694 /* Attempts to find single-step breakpoints. Returns -1 on failure which is
1695 actually an internal error. */
1698 find_step_target (inst_env_type *inst_env)
1702 unsigned short insn;
1704 /* Create a local register image and set the initial state. */
1705 for (i = 0; i < NUM_GENREGS; i++)
1707 inst_env->reg[i] = (unsigned long) read_register (i);
1709 offset = NUM_GENREGS;
1710 for (i = 0; i < NUM_SPECREGS; i++)
1712 inst_env->preg[i] = (unsigned long) read_register (offset + i);
1714 inst_env->branch_found = 0;
1715 inst_env->slot_needed = 0;
1716 inst_env->delay_slot_pc_active = 0;
1717 inst_env->prefix_found = 0;
1718 inst_env->invalid = 0;
1719 inst_env->xflag_found = 0;
1720 inst_env->disable_interrupt = 0;
1722 /* Look for a step target. */
1725 /* Read an instruction from the client. */
1726 insn = read_memory_unsigned_integer (inst_env->reg[PC_REGNUM], 2);
1728 /* If the instruction is not in a delay slot the new content of the
1729 PC is [PC] + 2. If the instruction is in a delay slot it is not
1730 that simple. Since a instruction in a delay slot cannot change
1731 the content of the PC, it does not matter what value PC will have.
1732 Just make sure it is a valid instruction. */
1733 if (!inst_env->delay_slot_pc_active)
1735 inst_env->reg[PC_REGNUM] += 2;
1739 inst_env->delay_slot_pc_active = 0;
1740 inst_env->reg[PC_REGNUM] = inst_env->delay_slot_pc;
1742 /* Analyse the present instruction. */
1743 i = find_cris_op (insn, inst_env);
1746 inst_env->invalid = 1;
1750 cris_gdb_func (cris_opcodes[i].op, insn, inst_env);
1752 } while (!inst_env->invalid
1753 && (inst_env->prefix_found || inst_env->xflag_found
1754 || inst_env->slot_needed));
1758 /* There is no hardware single-step support. The function find_step_target
1759 digs through the opcodes in order to find all possible targets.
1760 Either one ordinary target or two targets for branches may be found. */
1763 cris_software_single_step (enum target_signal ignore, int insert_breakpoints)
1765 inst_env_type inst_env;
1767 if (insert_breakpoints)
1769 /* Analyse the present instruction environment and insert
1771 int status = find_step_target (&inst_env);
1774 /* Could not find a target. FIXME: Should do something. */
1778 /* Insert at most two breakpoints. One for the next PC content
1779 and possibly another one for a branch, jump, etc. */
1780 next_pc = (CORE_ADDR) inst_env.reg[PC_REGNUM];
1781 target_insert_breakpoint (next_pc, break_mem[0]);
1782 if (inst_env.branch_found
1783 && (CORE_ADDR) inst_env.branch_break_address != next_pc)
1785 branch_target_address =
1786 (CORE_ADDR) inst_env.branch_break_address;
1787 target_insert_breakpoint (branch_target_address, break_mem[1]);
1788 branch_break_inserted = 1;
1794 /* Remove breakpoints. */
1795 target_remove_breakpoint (next_pc, break_mem[0]);
1796 if (branch_break_inserted)
1798 target_remove_breakpoint (branch_target_address, break_mem[1]);
1799 branch_break_inserted = 0;
1804 /* Calculates the prefix value for quick offset addressing mode. */
1807 quick_mode_bdap_prefix (unsigned short inst, inst_env_type *inst_env)
1809 /* It's invalid to be in a delay slot. You can't have a prefix to this
1810 instruction (not 100% sure). */
1811 if (inst_env->slot_needed || inst_env->prefix_found)
1813 inst_env->invalid = 1;
1817 inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)];
1818 inst_env->prefix_value += cris_get_bdap_quick_offset (inst);
1820 /* A prefix doesn't change the xflag_found. But the rest of the flags
1822 inst_env->slot_needed = 0;
1823 inst_env->prefix_found = 1;
1826 /* Updates the autoincrement register. The size of the increment is derived
1827 from the size of the operation. The PC is always kept aligned on even
1831 process_autoincrement (int size, unsigned short inst, inst_env_type *inst_env)
1833 if (size == INST_BYTE_SIZE)
1835 inst_env->reg[cris_get_operand1 (inst)] += 1;
1837 /* The PC must be word aligned, so increase the PC with one
1838 word even if the size is byte. */
1839 if (cris_get_operand1 (inst) == REG_PC)
1841 inst_env->reg[REG_PC] += 1;
1844 else if (size == INST_WORD_SIZE)
1846 inst_env->reg[cris_get_operand1 (inst)] += 2;
1848 else if (size == INST_DWORD_SIZE)
1850 inst_env->reg[cris_get_operand1 (inst)] += 4;
1855 inst_env->invalid = 1;
1859 /* Calculates the prefix value for the general case of offset addressing
1863 bdap_prefix (unsigned short inst, inst_env_type *inst_env)
1868 /* It's invalid to be in a delay slot. */
1869 if (inst_env->slot_needed || inst_env->prefix_found)
1871 inst_env->invalid = 1;
1875 if (cris_get_mode (inst) == AUTOINC_MODE)
1877 process_autoincrement (cris_get_size (inst), inst, inst_env);
1880 inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)];
1882 /* The offset is an indirection of the contents of the operand1 register. */
1883 inst_env->prefix_value +=
1884 read_memory_integer (inst_env->reg[cris_get_operand1 (inst)], cris_get_size (inst));
1886 /* A prefix doesn't change the xflag_found. But the rest of the flags
1888 inst_env->slot_needed = 0;
1889 inst_env->prefix_found = 1;
1892 /* Calculates the prefix value for the index addressing mode. */
1895 biap_prefix (unsigned short inst, inst_env_type *inst_env)
1897 /* It's invalid to be in a delay slot. I can't see that it's possible to
1898 have a prefix to this instruction. So I will treat this as invalid. */
1899 if (inst_env->slot_needed || inst_env->prefix_found)
1901 inst_env->invalid = 1;
1905 inst_env->prefix_value = inst_env->reg[cris_get_operand1 (inst)];
1907 /* The offset is the operand2 value shifted the size of the instruction
1909 inst_env->prefix_value +=
1910 inst_env->reg[cris_get_operand2 (inst)] << cris_get_size (inst);
1912 /* If the PC is operand1 (base) the address used is the address after
1913 the main instruction, i.e. address + 2 (the PC is already compensated
1914 for the prefix operation). */
1915 if (cris_get_operand1 (inst) == REG_PC)
1917 inst_env->prefix_value += 2;
1920 /* A prefix doesn't change the xflag_found. But the rest of the flags
1922 inst_env->slot_needed = 0;
1923 inst_env->xflag_found = 0;
1924 inst_env->prefix_found = 1;
1927 /* Calculates the prefix value for the double indirect addressing mode. */
1930 dip_prefix (unsigned short inst, inst_env_type *inst_env)
1935 /* It's invalid to be in a delay slot. */
1936 if (inst_env->slot_needed || inst_env->prefix_found)
1938 inst_env->invalid = 1;
1942 /* The prefix value is one dereference of the contents of the operand1
1944 address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)];
1945 inst_env->prefix_value = read_memory_unsigned_integer (address, 4);
1947 /* Check if the mode is autoincrement. */
1948 if (cris_get_mode (inst) == AUTOINC_MODE)
1950 inst_env->reg[cris_get_operand1 (inst)] += 4;
1953 /* A prefix doesn't change the xflag_found. But the rest of the flags
1955 inst_env->slot_needed = 0;
1956 inst_env->xflag_found = 0;
1957 inst_env->prefix_found = 1;
1960 /* Finds the destination for a branch with 8-bits offset. */
1963 eight_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env)
1968 /* If we have a prefix or are in a delay slot it's bad. */
1969 if (inst_env->slot_needed || inst_env->prefix_found)
1971 inst_env->invalid = 1;
1975 /* We have a branch, find out where the branch will land. */
1976 offset = cris_get_branch_short_offset (inst);
1978 /* Check if the offset is signed. */
1979 if (offset & BRANCH_SIGNED_SHORT_OFFSET_MASK)
1984 /* The offset ends with the sign bit, set it to zero. The address
1985 should always be word aligned. */
1986 offset &= ~BRANCH_SIGNED_SHORT_OFFSET_MASK;
1988 inst_env->branch_found = 1;
1989 inst_env->branch_break_address = inst_env->reg[REG_PC] + offset;
1991 inst_env->slot_needed = 1;
1992 inst_env->prefix_found = 0;
1993 inst_env->xflag_found = 0;
1994 inst_env->disable_interrupt = 1;
1997 /* Finds the destination for a branch with 16-bits offset. */
2000 sixteen_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env)
2004 /* If we have a prefix or is in a delay slot it's bad. */
2005 if (inst_env->slot_needed || inst_env->prefix_found)
2007 inst_env->invalid = 1;
2011 /* We have a branch, find out the offset for the branch. */
2012 offset = read_memory_integer (inst_env->reg[REG_PC], 2);
2014 /* The instruction is one word longer than normal, so add one word
2016 inst_env->reg[REG_PC] += 2;
2018 inst_env->branch_found = 1;
2019 inst_env->branch_break_address = inst_env->reg[REG_PC] + offset;
2022 inst_env->slot_needed = 1;
2023 inst_env->prefix_found = 0;
2024 inst_env->xflag_found = 0;
2025 inst_env->disable_interrupt = 1;
2028 /* Handles the ABS instruction. */
2031 abs_op (unsigned short inst, inst_env_type *inst_env)
2036 /* ABS can't have a prefix, so it's bad if it does. */
2037 if (inst_env->prefix_found)
2039 inst_env->invalid = 1;
2043 /* Check if the operation affects the PC. */
2044 if (cris_get_operand2 (inst) == REG_PC)
2047 /* It's invalid to change to the PC if we are in a delay slot. */
2048 if (inst_env->slot_needed)
2050 inst_env->invalid = 1;
2054 value = (long) inst_env->reg[REG_PC];
2056 /* The value of abs (SIGNED_DWORD_MASK) is SIGNED_DWORD_MASK. */
2057 if (value != SIGNED_DWORD_MASK)
2060 inst_env->reg[REG_PC] = (long) value;
2064 inst_env->slot_needed = 0;
2065 inst_env->prefix_found = 0;
2066 inst_env->xflag_found = 0;
2067 inst_env->disable_interrupt = 0;
2070 /* Handles the ADDI instruction. */
2073 addi_op (unsigned short inst, inst_env_type *inst_env)
2075 /* It's invalid to have the PC as base register. And ADDI can't have
2077 if (inst_env->prefix_found || (cris_get_operand1 (inst) == REG_PC))
2079 inst_env->invalid = 1;
2083 inst_env->slot_needed = 0;
2084 inst_env->prefix_found = 0;
2085 inst_env->xflag_found = 0;
2086 inst_env->disable_interrupt = 0;
2089 /* Handles the ASR instruction. */
2092 asr_op (unsigned short inst, inst_env_type *inst_env)
2095 unsigned long value;
2096 unsigned long signed_extend_mask = 0;
2098 /* ASR can't have a prefix, so check that it doesn't. */
2099 if (inst_env->prefix_found)
2101 inst_env->invalid = 1;
2105 /* Check if the PC is the target register. */
2106 if (cris_get_operand2 (inst) == REG_PC)
2108 /* It's invalid to change the PC in a delay slot. */
2109 if (inst_env->slot_needed)
2111 inst_env->invalid = 1;
2114 /* Get the number of bits to shift. */
2115 shift_steps = cris_get_asr_shift_steps (inst_env->reg[cris_get_operand1 (inst)]);
2116 value = inst_env->reg[REG_PC];
2118 /* Find out how many bits the operation should apply to. */
2119 if (cris_get_size (inst) == INST_BYTE_SIZE)
2121 if (value & SIGNED_BYTE_MASK)
2123 signed_extend_mask = 0xFF;
2124 signed_extend_mask = signed_extend_mask >> shift_steps;
2125 signed_extend_mask = ~signed_extend_mask;
2127 value = value >> shift_steps;
2128 value |= signed_extend_mask;
2130 inst_env->reg[REG_PC] &= 0xFFFFFF00;
2131 inst_env->reg[REG_PC] |= value;
2133 else if (cris_get_size (inst) == INST_WORD_SIZE)
2135 if (value & SIGNED_WORD_MASK)
2137 signed_extend_mask = 0xFFFF;
2138 signed_extend_mask = signed_extend_mask >> shift_steps;
2139 signed_extend_mask = ~signed_extend_mask;
2141 value = value >> shift_steps;
2142 value |= signed_extend_mask;
2144 inst_env->reg[REG_PC] &= 0xFFFF0000;
2145 inst_env->reg[REG_PC] |= value;
2147 else if (cris_get_size (inst) == INST_DWORD_SIZE)
2149 if (value & SIGNED_DWORD_MASK)
2151 signed_extend_mask = 0xFFFFFFFF;
2152 signed_extend_mask = signed_extend_mask >> shift_steps;
2153 signed_extend_mask = ~signed_extend_mask;
2155 value = value >> shift_steps;
2156 value |= signed_extend_mask;
2157 inst_env->reg[REG_PC] = value;
2160 inst_env->slot_needed = 0;
2161 inst_env->prefix_found = 0;
2162 inst_env->xflag_found = 0;
2163 inst_env->disable_interrupt = 0;
2166 /* Handles the ASRQ instruction. */
2169 asrq_op (unsigned short inst, inst_env_type *inst_env)
2173 unsigned long value;
2174 unsigned long signed_extend_mask = 0;
2176 /* ASRQ can't have a prefix, so check that it doesn't. */
2177 if (inst_env->prefix_found)
2179 inst_env->invalid = 1;
2183 /* Check if the PC is the target register. */
2184 if (cris_get_operand2 (inst) == REG_PC)
2187 /* It's invalid to change the PC in a delay slot. */
2188 if (inst_env->slot_needed)
2190 inst_env->invalid = 1;
2193 /* The shift size is given as a 5 bit quick value, i.e. we don't
2194 want the the sign bit of the quick value. */
2195 shift_steps = cris_get_asr_shift_steps (inst);
2196 value = inst_env->reg[REG_PC];
2197 if (value & SIGNED_DWORD_MASK)
2199 signed_extend_mask = 0xFFFFFFFF;
2200 signed_extend_mask = signed_extend_mask >> shift_steps;
2201 signed_extend_mask = ~signed_extend_mask;
2203 value = value >> shift_steps;
2204 value |= signed_extend_mask;
2205 inst_env->reg[REG_PC] = value;
2207 inst_env->slot_needed = 0;
2208 inst_env->prefix_found = 0;
2209 inst_env->xflag_found = 0;
2210 inst_env->disable_interrupt = 0;
2213 /* Handles the AX, EI and SETF instruction. */
2216 ax_ei_setf_op (unsigned short inst, inst_env_type *inst_env)
2218 if (inst_env->prefix_found)
2220 inst_env->invalid = 1;
2223 /* Check if the instruction is setting the X flag. */
2224 if (cris_is_xflag_bit_on (inst))
2226 inst_env->xflag_found = 1;
2230 inst_env->xflag_found = 0;
2232 inst_env->slot_needed = 0;
2233 inst_env->prefix_found = 0;
2234 inst_env->disable_interrupt = 1;
2237 /* Checks if the instruction is in assign mode. If so, it updates the assign
2238 register. Note that check_assign assumes that the caller has checked that
2239 there is a prefix to this instruction. The mode check depends on this. */
2242 check_assign (unsigned short inst, inst_env_type *inst_env)
2244 /* Check if it's an assign addressing mode. */
2245 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2247 /* Assign the prefix value to operand 1. */
2248 inst_env->reg[cris_get_operand1 (inst)] = inst_env->prefix_value;
2252 /* Handles the 2-operand BOUND instruction. */
2255 two_operand_bound_op (unsigned short inst, inst_env_type *inst_env)
2257 /* It's invalid to have the PC as the index operand. */
2258 if (cris_get_operand2 (inst) == REG_PC)
2260 inst_env->invalid = 1;
2263 /* Check if we have a prefix. */
2264 if (inst_env->prefix_found)
2266 check_assign (inst, inst_env);
2268 /* Check if this is an autoincrement mode. */
2269 else if (cris_get_mode (inst) == AUTOINC_MODE)
2271 /* It's invalid to change the PC in a delay slot. */
2272 if (inst_env->slot_needed)
2274 inst_env->invalid = 1;
2277 process_autoincrement (cris_get_size (inst), inst, inst_env);
2279 inst_env->slot_needed = 0;
2280 inst_env->prefix_found = 0;
2281 inst_env->xflag_found = 0;
2282 inst_env->disable_interrupt = 0;
2285 /* Handles the 3-operand BOUND instruction. */
2288 three_operand_bound_op (unsigned short inst, inst_env_type *inst_env)
2290 /* It's an error if we haven't got a prefix. And it's also an error
2291 if the PC is the destination register. */
2292 if ((!inst_env->prefix_found) || (cris_get_operand1 (inst) == REG_PC))
2294 inst_env->invalid = 1;
2297 inst_env->slot_needed = 0;
2298 inst_env->prefix_found = 0;
2299 inst_env->xflag_found = 0;
2300 inst_env->disable_interrupt = 0;
2303 /* Clears the status flags in inst_env. */
2306 btst_nop_op (unsigned short inst, inst_env_type *inst_env)
2308 /* It's an error if we have got a prefix. */
2309 if (inst_env->prefix_found)
2311 inst_env->invalid = 1;
2315 inst_env->slot_needed = 0;
2316 inst_env->prefix_found = 0;
2317 inst_env->xflag_found = 0;
2318 inst_env->disable_interrupt = 0;
2321 /* Clears the status flags in inst_env. */
2324 clearf_di_op (unsigned short inst, inst_env_type *inst_env)
2326 /* It's an error if we have got a prefix. */
2327 if (inst_env->prefix_found)
2329 inst_env->invalid = 1;
2333 inst_env->slot_needed = 0;
2334 inst_env->prefix_found = 0;
2335 inst_env->xflag_found = 0;
2336 inst_env->disable_interrupt = 1;
2339 /* Handles the CLEAR instruction if it's in register mode. */
2342 reg_mode_clear_op (unsigned short inst, inst_env_type *inst_env)
2344 /* Check if the target is the PC. */
2345 if (cris_get_operand2 (inst) == REG_PC)
2347 /* The instruction will clear the instruction's size bits. */
2348 int clear_size = cris_get_clear_size (inst);
2349 if (clear_size == INST_BYTE_SIZE)
2351 inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFFFF00;
2353 if (clear_size == INST_WORD_SIZE)
2355 inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFF0000;
2357 if (clear_size == INST_DWORD_SIZE)
2359 inst_env->delay_slot_pc = 0x0;
2361 /* The jump will be delayed with one delay slot. So we need a delay
2363 inst_env->slot_needed = 1;
2364 inst_env->delay_slot_pc_active = 1;
2368 /* The PC will not change => no delay slot. */
2369 inst_env->slot_needed = 0;
2371 inst_env->prefix_found = 0;
2372 inst_env->xflag_found = 0;
2373 inst_env->disable_interrupt = 0;
2376 /* Handles the TEST instruction if it's in register mode. */
2379 reg_mode_test_op (unsigned short inst, inst_env_type *inst_env)
2381 /* It's an error if we have got a prefix. */
2382 if (inst_env->prefix_found)
2384 inst_env->invalid = 1;
2387 inst_env->slot_needed = 0;
2388 inst_env->prefix_found = 0;
2389 inst_env->xflag_found = 0;
2390 inst_env->disable_interrupt = 0;
2394 /* Handles the CLEAR and TEST instruction if the instruction isn't
2395 in register mode. */
2398 none_reg_mode_clear_test_op (unsigned short inst, inst_env_type *inst_env)
2400 /* Check if we are in a prefix mode. */
2401 if (inst_env->prefix_found)
2403 /* The only way the PC can change is if this instruction is in
2404 assign addressing mode. */
2405 check_assign (inst, inst_env);
2407 /* Indirect mode can't change the PC so just check if the mode is
2409 else if (cris_get_mode (inst) == AUTOINC_MODE)
2411 process_autoincrement (cris_get_size (inst), inst, inst_env);
2413 inst_env->slot_needed = 0;
2414 inst_env->prefix_found = 0;
2415 inst_env->xflag_found = 0;
2416 inst_env->disable_interrupt = 0;
2419 /* Checks that the PC isn't the destination register or the instructions has
2423 dstep_logshift_mstep_neg_not_op (unsigned short inst, inst_env_type *inst_env)
2425 /* It's invalid to have the PC as the destination. The instruction can't
2427 if ((cris_get_operand2 (inst) == REG_PC) || inst_env->prefix_found)
2429 inst_env->invalid = 1;
2433 inst_env->slot_needed = 0;
2434 inst_env->prefix_found = 0;
2435 inst_env->xflag_found = 0;
2436 inst_env->disable_interrupt = 0;
2439 /* Checks that the instruction doesn't have a prefix. */
2442 break_op (unsigned short inst, inst_env_type *inst_env)
2444 /* The instruction can't have a prefix. */
2445 if (inst_env->prefix_found)
2447 inst_env->invalid = 1;
2451 inst_env->slot_needed = 0;
2452 inst_env->prefix_found = 0;
2453 inst_env->xflag_found = 0;
2454 inst_env->disable_interrupt = 1;
2457 /* Checks that the PC isn't the destination register and that the instruction
2458 doesn't have a prefix. */
2461 scc_op (unsigned short inst, inst_env_type *inst_env)
2463 /* It's invalid to have the PC as the destination. The instruction can't
2465 if ((cris_get_operand2 (inst) == REG_PC) || inst_env->prefix_found)
2467 inst_env->invalid = 1;
2471 inst_env->slot_needed = 0;
2472 inst_env->prefix_found = 0;
2473 inst_env->xflag_found = 0;
2474 inst_env->disable_interrupt = 1;
2477 /* Handles the register mode JUMP instruction. */
2480 reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env)
2482 /* It's invalid to do a JUMP in a delay slot. The mode is register, so
2483 you can't have a prefix. */
2484 if ((inst_env->slot_needed) || (inst_env->prefix_found))
2486 inst_env->invalid = 1;
2490 /* Just change the PC. */
2491 inst_env->reg[REG_PC] = inst_env->reg[cris_get_operand1 (inst)];
2492 inst_env->slot_needed = 0;
2493 inst_env->prefix_found = 0;
2494 inst_env->xflag_found = 0;
2495 inst_env->disable_interrupt = 1;
2498 /* Handles the JUMP instruction for all modes except register. */
2500 void none_reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env)
2502 unsigned long newpc;
2505 /* It's invalid to do a JUMP in a delay slot. */
2506 if (inst_env->slot_needed)
2508 inst_env->invalid = 1;
2512 /* Check if we have a prefix. */
2513 if (inst_env->prefix_found)
2515 check_assign (inst, inst_env);
2517 /* Get the new value for the the PC. */
2519 read_memory_unsigned_integer ((CORE_ADDR) inst_env->prefix_value,
2524 /* Get the new value for the PC. */
2525 address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)];
2526 newpc = read_memory_unsigned_integer (address, 4);
2528 /* Check if we should increment a register. */
2529 if (cris_get_mode (inst) == AUTOINC_MODE)
2531 inst_env->reg[cris_get_operand1 (inst)] += 4;
2534 inst_env->reg[REG_PC] = newpc;
2536 inst_env->slot_needed = 0;
2537 inst_env->prefix_found = 0;
2538 inst_env->xflag_found = 0;
2539 inst_env->disable_interrupt = 1;
2542 /* Handles moves to special registers (aka P-register) for all modes. */
2545 move_to_preg_op (unsigned short inst, inst_env_type *inst_env)
2547 if (inst_env->prefix_found)
2549 /* The instruction has a prefix that means we are only interested if
2550 the instruction is in assign mode. */
2551 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2553 /* The prefix handles the problem if we are in a delay slot. */
2554 if (cris_get_operand1 (inst) == REG_PC)
2556 /* Just take care of the assign. */
2557 check_assign (inst, inst_env);
2561 else if (cris_get_mode (inst) == AUTOINC_MODE)
2563 /* The instruction doesn't have a prefix, the only case left that we
2564 are interested in is the autoincrement mode. */
2565 if (cris_get_operand1 (inst) == REG_PC)
2567 /* If the PC is to be incremented it's invalid to be in a
2569 if (inst_env->slot_needed)
2571 inst_env->invalid = 1;
2574 /* The increment depends on the size of the special register.
2575 Register P0 to P3 has the size byte, register P4 to P7 has the
2576 size word and register P8 to P15 has the size dword. */
2577 if (cris_get_operand2 (inst) < 4)
2579 process_autoincrement (INST_BYTE_SIZE, inst, inst_env);
2581 if (cris_get_operand2 (inst) < 8)
2583 process_autoincrement (INST_WORD_SIZE, inst, inst_env);
2587 process_autoincrement (INST_DWORD_SIZE, inst, inst_env);
2591 inst_env->slot_needed = 0;
2592 inst_env->prefix_found = 0;
2593 inst_env->xflag_found = 0;
2594 inst_env->disable_interrupt = 1;
2597 /* Handles moves from special registers (aka P-register) for all modes
2601 none_reg_mode_move_from_preg_op (unsigned short inst, inst_env_type *inst_env)
2603 if (inst_env->prefix_found)
2605 /* The instruction has a prefix that means we are only interested if
2606 the instruction is in assign mode. */
2607 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2609 /* The prefix handles the problem if we are in a delay slot. */
2610 if (cris_get_operand1 (inst) == REG_PC)
2612 /* Just take care of the assign. */
2613 check_assign (inst, inst_env);
2617 /* The instruction doesn't have a prefix, the only case left that we
2618 are interested in is the autoincrement mode. */
2619 else if (cris_get_mode (inst) == AUTOINC_MODE)
2621 if (cris_get_operand1 (inst) == REG_PC)
2623 /* If the PC is to be incremented it's invalid to be in a
2625 if (inst_env->slot_needed)
2627 inst_env->invalid = 1;
2630 /* The increment depends on the size of the special register.
2631 Register P0 to P3 has the size byte, register P4 to P7 has
2632 the size word and register P8 to P15 has the size dword. */
2633 if (cris_get_operand2 (inst) < 4)
2635 process_autoincrement (INST_BYTE_SIZE, inst, inst_env);
2637 if (cris_get_operand2 (inst) < 8)
2639 process_autoincrement (INST_WORD_SIZE, inst, inst_env);
2643 process_autoincrement (INST_DWORD_SIZE, inst, inst_env);
2647 inst_env->slot_needed = 0;
2648 inst_env->prefix_found = 0;
2649 inst_env->xflag_found = 0;
2650 inst_env->disable_interrupt = 1;
2653 /* Handles moves from special registers (aka P-register) when the mode
2657 reg_mode_move_from_preg_op (unsigned short inst, inst_env_type *inst_env)
2659 /* Register mode move from special register can't have a prefix. */
2660 if (inst_env->prefix_found)
2662 inst_env->invalid = 1;
2666 if (cris_get_operand1 (inst) == REG_PC)
2668 /* It's invalid to change the PC in a delay slot. */
2669 if (inst_env->slot_needed)
2671 inst_env->invalid = 1;
2674 /* The destination is the PC, the jump will have a delay slot. */
2675 inst_env->delay_slot_pc = inst_env->preg[cris_get_operand2 (inst)];
2676 inst_env->slot_needed = 1;
2677 inst_env->delay_slot_pc_active = 1;
2681 /* If the destination isn't PC, there will be no jump. */
2682 inst_env->slot_needed = 0;
2684 inst_env->prefix_found = 0;
2685 inst_env->xflag_found = 0;
2686 inst_env->disable_interrupt = 1;
2689 /* Handles the MOVEM from memory to general register instruction. */
2692 move_mem_to_reg_movem_op (unsigned short inst, inst_env_type *inst_env)
2694 if (inst_env->prefix_found)
2696 /* The prefix handles the problem if we are in a delay slot. Is the
2697 MOVEM instruction going to change the PC? */
2698 if (cris_get_operand2 (inst) >= REG_PC)
2700 inst_env->reg[REG_PC] =
2701 read_memory_unsigned_integer (inst_env->prefix_value, 4);
2703 /* The assign value is the value after the increment. Normally, the
2704 assign value is the value before the increment. */
2705 if ((cris_get_operand1 (inst) == REG_PC)
2706 && (cris_get_mode (inst) == PREFIX_ASSIGN_MODE))
2708 inst_env->reg[REG_PC] = inst_env->prefix_value;
2709 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
2714 /* Is the MOVEM instruction going to change the PC? */
2715 if (cris_get_operand2 (inst) == REG_PC)
2717 /* It's invalid to change the PC in a delay slot. */
2718 if (inst_env->slot_needed)
2720 inst_env->invalid = 1;
2723 inst_env->reg[REG_PC] =
2724 read_memory_unsigned_integer (inst_env->reg[cris_get_operand1 (inst)],
2727 /* The increment is not depending on the size, instead it's depending
2728 on the number of registers loaded from memory. */
2729 if ((cris_get_operand1 (inst) == REG_PC) && (cris_get_mode (inst) == AUTOINC_MODE))
2731 /* It's invalid to change the PC in a delay slot. */
2732 if (inst_env->slot_needed)
2734 inst_env->invalid = 1;
2737 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
2740 inst_env->slot_needed = 0;
2741 inst_env->prefix_found = 0;
2742 inst_env->xflag_found = 0;
2743 inst_env->disable_interrupt = 0;
2746 /* Handles the MOVEM to memory from general register instruction. */
2749 move_reg_to_mem_movem_op (unsigned short inst, inst_env_type *inst_env)
2751 if (inst_env->prefix_found)
2753 /* The assign value is the value after the increment. Normally, the
2754 assign value is the value before the increment. */
2755 if ((cris_get_operand1 (inst) == REG_PC) &&
2756 (cris_get_mode (inst) == PREFIX_ASSIGN_MODE))
2758 /* The prefix handles the problem if we are in a delay slot. */
2759 inst_env->reg[REG_PC] = inst_env->prefix_value;
2760 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
2765 /* The increment is not depending on the size, instead it's depending
2766 on the number of registers loaded to memory. */
2767 if ((cris_get_operand1 (inst) == REG_PC) && (cris_get_mode (inst) == AUTOINC_MODE))
2769 /* It's invalid to change the PC in a delay slot. */
2770 if (inst_env->slot_needed)
2772 inst_env->invalid = 1;
2775 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
2778 inst_env->slot_needed = 0;
2779 inst_env->prefix_found = 0;
2780 inst_env->xflag_found = 0;
2781 inst_env->disable_interrupt = 0;
2784 /* Handles the pop instruction to a general register.
2785 POP is a assembler macro for MOVE.D [SP+], Rd. */
2788 reg_pop_op (unsigned short inst, inst_env_type *inst_env)
2790 /* POP can't have a prefix. */
2791 if (inst_env->prefix_found)
2793 inst_env->invalid = 1;
2796 if (cris_get_operand2 (inst) == REG_PC)
2798 /* It's invalid to change the PC in a delay slot. */
2799 if (inst_env->slot_needed)
2801 inst_env->invalid = 1;
2804 inst_env->reg[REG_PC] =
2805 read_memory_unsigned_integer (inst_env->reg[REG_SP], 4);
2807 inst_env->slot_needed = 0;
2808 inst_env->prefix_found = 0;
2809 inst_env->xflag_found = 0;
2810 inst_env->disable_interrupt = 0;
2813 /* Handles moves from register to memory. */
2816 move_reg_to_mem_index_inc_op (unsigned short inst, inst_env_type *inst_env)
2818 /* Check if we have a prefix. */
2819 if (inst_env->prefix_found)
2821 /* The only thing that can change the PC is an assign. */
2822 check_assign (inst, inst_env);
2824 else if ((cris_get_operand1 (inst) == REG_PC)
2825 && (cris_get_mode (inst) == AUTOINC_MODE))
2827 /* It's invalid to change the PC in a delay slot. */
2828 if (inst_env->slot_needed)
2830 inst_env->invalid = 1;
2833 process_autoincrement (cris_get_size (inst), inst, inst_env);
2835 inst_env->slot_needed = 0;
2836 inst_env->prefix_found = 0;
2837 inst_env->xflag_found = 0;
2838 inst_env->disable_interrupt = 0;
2841 /* Handles the intructions that's not yet implemented, by setting
2842 inst_env->invalid to true. */
2845 not_implemented_op (unsigned short inst, inst_env_type *inst_env)
2847 inst_env->invalid = 1;
2850 /* Handles the XOR instruction. */
2853 xor_op (unsigned short inst, inst_env_type *inst_env)
2855 /* XOR can't have a prefix. */
2856 if (inst_env->prefix_found)
2858 inst_env->invalid = 1;
2862 /* Check if the PC is the target. */
2863 if (cris_get_operand2 (inst) == REG_PC)
2865 /* It's invalid to change the PC in a delay slot. */
2866 if (inst_env->slot_needed)
2868 inst_env->invalid = 1;
2871 inst_env->reg[REG_PC] ^= inst_env->reg[cris_get_operand1 (inst)];
2873 inst_env->slot_needed = 0;
2874 inst_env->prefix_found = 0;
2875 inst_env->xflag_found = 0;
2876 inst_env->disable_interrupt = 0;
2879 /* Handles the MULS instruction. */
2882 muls_op (unsigned short inst, inst_env_type *inst_env)
2884 /* MULS/U can't have a prefix. */
2885 if (inst_env->prefix_found)
2887 inst_env->invalid = 1;
2891 /* Consider it invalid if the PC is the target. */
2892 if (cris_get_operand2 (inst) == REG_PC)
2894 inst_env->invalid = 1;
2897 inst_env->slot_needed = 0;
2898 inst_env->prefix_found = 0;
2899 inst_env->xflag_found = 0;
2900 inst_env->disable_interrupt = 0;
2903 /* Handles the MULU instruction. */
2906 mulu_op (unsigned short inst, inst_env_type *inst_env)
2908 /* MULS/U can't have a prefix. */
2909 if (inst_env->prefix_found)
2911 inst_env->invalid = 1;
2915 /* Consider it invalid if the PC is the target. */
2916 if (cris_get_operand2 (inst) == REG_PC)
2918 inst_env->invalid = 1;
2921 inst_env->slot_needed = 0;
2922 inst_env->prefix_found = 0;
2923 inst_env->xflag_found = 0;
2924 inst_env->disable_interrupt = 0;
2927 /* Calculate the result of the instruction for ADD, SUB, CMP AND, OR and MOVE.
2928 The MOVE instruction is the move from source to register. */
2931 add_sub_cmp_and_or_move_action (unsigned short inst, inst_env_type *inst_env,
2932 unsigned long source1, unsigned long source2)
2934 unsigned long pc_mask;
2935 unsigned long operation_mask;
2937 /* Find out how many bits the operation should apply to. */
2938 if (cris_get_size (inst) == INST_BYTE_SIZE)
2940 pc_mask = 0xFFFFFF00;
2941 operation_mask = 0xFF;
2943 else if (cris_get_size (inst) == INST_WORD_SIZE)
2945 pc_mask = 0xFFFF0000;
2946 operation_mask = 0xFFFF;
2948 else if (cris_get_size (inst) == INST_DWORD_SIZE)
2951 operation_mask = 0xFFFFFFFF;
2955 /* The size is out of range. */
2956 inst_env->invalid = 1;
2960 /* The instruction just works on uw_operation_mask bits. */
2961 source2 &= operation_mask;
2962 source1 &= operation_mask;
2964 /* Now calculate the result. The opcode's 3 first bits separates
2965 the different actions. */
2966 switch (cris_get_opcode (inst) & 7)
2976 case 2: /* subtract */
2980 case 3: /* compare */
2992 inst_env->invalid = 1;
2998 /* Make sure that the result doesn't contain more than the instruction
3000 source2 &= operation_mask;
3002 /* Calculate the new breakpoint address. */
3003 inst_env->reg[REG_PC] &= pc_mask;
3004 inst_env->reg[REG_PC] |= source1;
3008 /* Extends the value from either byte or word size to a dword. If the mode
3009 is zero extend then the value is extended with zero. If instead the mode
3010 is signed extend the sign bit of the value is taken into consideration. */
3013 do_sign_or_zero_extend (unsigned long value, unsigned short *inst)
3015 /* The size can be either byte or word, check which one it is.
3016 Don't check the highest bit, it's indicating if it's a zero
3018 if (cris_get_size (*inst) & INST_WORD_SIZE)
3023 /* Check if the instruction is signed extend. If so, check if value has
3025 if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_WORD_MASK))
3027 value |= SIGNED_WORD_EXTEND_MASK;
3035 /* Check if the instruction is signed extend. If so, check if value has
3037 if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_BYTE_MASK))
3039 value |= SIGNED_BYTE_EXTEND_MASK;
3042 /* The size should now be dword. */
3043 cris_set_size_to_dword (inst);
3047 /* Handles the register mode for the ADD, SUB, CMP, AND, OR and MOVE
3048 instruction. The MOVE instruction is the move from source to register. */
3051 reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst,
3052 inst_env_type *inst_env)
3054 unsigned long operand1;
3055 unsigned long operand2;
3057 /* It's invalid to have a prefix to the instruction. This is a register
3058 mode instruction and can't have a prefix. */
3059 if (inst_env->prefix_found)
3061 inst_env->invalid = 1;
3064 /* Check if the instruction has PC as its target. */
3065 if (cris_get_operand2 (inst) == REG_PC)
3067 if (inst_env->slot_needed)
3069 inst_env->invalid = 1;
3072 /* The instruction has the PC as its target register. */
3073 operand1 = inst_env->reg[operand1];
3074 operand2 = inst_env->reg[REG_PC];
3076 /* Check if it's a extend, signed or zero instruction. */
3077 if (cris_get_opcode (inst) < 4)
3079 operand1 = do_sign_or_zero_extend (operand1, &inst);
3081 /* Calculate the PC value after the instruction, i.e. where the
3082 breakpoint should be. The order of the udw_operands is vital. */
3083 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3085 inst_env->slot_needed = 0;
3086 inst_env->prefix_found = 0;
3087 inst_env->xflag_found = 0;
3088 inst_env->disable_interrupt = 0;
3091 /* Returns the data contained at address. The size of the data is derived from
3092 the size of the operation. If the instruction is a zero or signed
3093 extend instruction, the size field is changed in instruction. */
3096 get_data_from_address (unsigned short *inst, CORE_ADDR address)
3098 int size = cris_get_size (*inst);
3099 unsigned long value;
3101 /* If it's an extend instruction we don't want the signed extend bit,
3102 because it influences the size. */
3103 if (cris_get_opcode (*inst) < 4)
3105 size &= ~SIGNED_EXTEND_BIT_MASK;
3107 /* Is there a need for checking the size? Size should contain the number of
3110 value = read_memory_unsigned_integer (address, size);
3112 /* Check if it's an extend, signed or zero instruction. */
3113 if (cris_get_opcode (*inst) < 4)
3115 value = do_sign_or_zero_extend (value, inst);
3120 /* Handles the assign addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
3121 instructions. The MOVE instruction is the move from source to register. */
3124 handle_prefix_assign_mode_for_aritm_op (unsigned short inst,
3125 inst_env_type *inst_env)
3127 unsigned long operand2;
3128 unsigned long operand3;
3130 check_assign (inst, inst_env);
3131 if (cris_get_operand2 (inst) == REG_PC)
3133 operand2 = inst_env->reg[REG_PC];
3135 /* Get the value of the third operand. */
3136 operand3 = get_data_from_address (&inst, inst_env->prefix_value);
3138 /* Calculate the PC value after the instruction, i.e. where the
3139 breakpoint should be. The order of the udw_operands is vital. */
3140 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3142 inst_env->slot_needed = 0;
3143 inst_env->prefix_found = 0;
3144 inst_env->xflag_found = 0;
3145 inst_env->disable_interrupt = 0;
3148 /* Handles the three-operand addressing mode for the ADD, SUB, CMP, AND and
3149 OR instructions. Note that for this to work as expected, the calling
3150 function must have made sure that there is a prefix to this instruction. */
3153 three_operand_add_sub_cmp_and_or_op (unsigned short inst,
3154 inst_env_type *inst_env)
3156 unsigned long operand2;
3157 unsigned long operand3;
3159 if (cris_get_operand1 (inst) == REG_PC)
3161 /* The PC will be changed by the instruction. */
3162 operand2 = inst_env->reg[cris_get_operand2 (inst)];
3164 /* Get the value of the third operand. */
3165 operand3 = get_data_from_address (&inst, inst_env->prefix_value);
3167 /* Calculate the PC value after the instruction, i.e. where the
3168 breakpoint should be. */
3169 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3171 inst_env->slot_needed = 0;
3172 inst_env->prefix_found = 0;
3173 inst_env->xflag_found = 0;
3174 inst_env->disable_interrupt = 0;
3177 /* Handles the index addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
3178 instructions. The MOVE instruction is the move from source to register. */
3181 handle_prefix_index_mode_for_aritm_op (unsigned short inst,
3182 inst_env_type *inst_env)
3184 if (cris_get_operand1 (inst) != cris_get_operand2 (inst))
3186 /* If the instruction is MOVE it's invalid. If the instruction is ADD,
3187 SUB, AND or OR something weird is going on (if everything works these
3188 instructions should end up in the three operand version). */
3189 inst_env->invalid = 1;
3194 /* three_operand_add_sub_cmp_and_or does the same as we should do here
3196 three_operand_add_sub_cmp_and_or_op (inst, inst_env);
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 autoincrement and indirect addresing mode for the ADD, SUB,
3205 CMP, AND OR and MOVE instruction. The MOVE instruction is the move from
3206 source to register. */
3209 handle_inc_and_index_mode_for_aritm_op (unsigned short inst,
3210 inst_env_type *inst_env)
3212 unsigned long operand1;
3213 unsigned long operand2;
3214 unsigned long operand3;
3217 /* The instruction is either an indirect or autoincrement addressing mode.
3218 Check if the destination register is the PC. */
3219 if (cris_get_operand2 (inst) == REG_PC)
3221 /* Must be done here, get_data_from_address may change the size
3223 size = cris_get_size (inst);
3224 operand2 = inst_env->reg[REG_PC];
3226 /* Get the value of the third operand, i.e. the indirect operand. */
3227 operand1 = inst_env->reg[cris_get_operand1 (inst)];
3228 operand3 = get_data_from_address (&inst, operand1);
3230 /* Calculate the PC value after the instruction, i.e. where the
3231 breakpoint should be. The order of the udw_operands is vital. */
3232 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3234 /* If this is an autoincrement addressing mode, check if the increment
3236 if ((cris_get_operand1 (inst) == REG_PC) && (cris_get_mode (inst) == AUTOINC_MODE))
3238 /* Get the size field. */
3239 size = cris_get_size (inst);
3241 /* If it's an extend instruction we don't want the signed extend bit,
3242 because it influences the size. */
3243 if (cris_get_opcode (inst) < 4)
3245 size &= ~SIGNED_EXTEND_BIT_MASK;
3247 process_autoincrement (size, inst, inst_env);
3249 inst_env->slot_needed = 0;
3250 inst_env->prefix_found = 0;
3251 inst_env->xflag_found = 0;
3252 inst_env->disable_interrupt = 0;
3255 /* Handles the two-operand addressing mode, all modes except register, for
3256 the ADD, SUB CMP, AND and OR instruction. */
3259 none_reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst,
3260 inst_env_type *inst_env)
3262 if (inst_env->prefix_found)
3264 if (cris_get_mode (inst) == PREFIX_INDEX_MODE)
3266 handle_prefix_index_mode_for_aritm_op (inst, inst_env);
3268 else if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
3270 handle_prefix_assign_mode_for_aritm_op (inst, inst_env);
3274 /* The mode is invalid for a prefixed base instruction. */
3275 inst_env->invalid = 1;
3281 handle_inc_and_index_mode_for_aritm_op (inst, inst_env);
3285 /* Handles the quick addressing mode for the ADD and SUB instruction. */
3288 quick_mode_add_sub_op (unsigned short inst, inst_env_type *inst_env)
3290 unsigned long operand1;
3291 unsigned long operand2;
3293 /* It's a bad idea to be in a prefix instruction now. This is a quick mode
3294 instruction and can't have a prefix. */
3295 if (inst_env->prefix_found)
3297 inst_env->invalid = 1;
3301 /* Check if the instruction has PC as its target. */
3302 if (cris_get_operand2 (inst) == REG_PC)
3304 if (inst_env->slot_needed)
3306 inst_env->invalid = 1;
3309 operand1 = cris_get_quick_value (inst);
3310 operand2 = inst_env->reg[REG_PC];
3312 /* The size should now be dword. */
3313 cris_set_size_to_dword (&inst);
3315 /* Calculate the PC value after the instruction, i.e. where the
3316 breakpoint should be. */
3317 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3319 inst_env->slot_needed = 0;
3320 inst_env->prefix_found = 0;
3321 inst_env->xflag_found = 0;
3322 inst_env->disable_interrupt = 0;
3325 /* Handles the quick addressing mode for the CMP, AND and OR instruction. */
3328 quick_mode_and_cmp_move_or_op (unsigned short inst, inst_env_type *inst_env)
3330 unsigned long operand1;
3331 unsigned long operand2;
3333 /* It's a bad idea to be in a prefix instruction now. This is a quick mode
3334 instruction and can't have a prefix. */
3335 if (inst_env->prefix_found)
3337 inst_env->invalid = 1;
3340 /* Check if the instruction has PC as its target. */
3341 if (cris_get_operand2 (inst) == REG_PC)
3343 if (inst_env->slot_needed)
3345 inst_env->invalid = 1;
3348 /* The instruction has the PC as its target register. */
3349 operand1 = cris_get_quick_value (inst);
3350 operand2 = inst_env->reg[REG_PC];
3352 /* The quick value is signed, so check if we must do a signed extend. */
3353 if (operand1 & SIGNED_QUICK_VALUE_MASK)
3356 operand1 |= SIGNED_QUICK_VALUE_EXTEND_MASK;
3358 /* The size should now be dword. */
3359 cris_set_size_to_dword (&inst);
3361 /* Calculate the PC value after the instruction, i.e. where the
3362 breakpoint should be. */
3363 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3365 inst_env->slot_needed = 0;
3366 inst_env->prefix_found = 0;
3367 inst_env->xflag_found = 0;
3368 inst_env->disable_interrupt = 0;
3371 /* Translate op_type to a function and call it. */
3373 static void cris_gdb_func (enum cris_op_type op_type, unsigned short inst,
3374 inst_env_type *inst_env)
3378 case cris_not_implemented_op:
3379 not_implemented_op (inst, inst_env);
3383 abs_op (inst, inst_env);
3387 addi_op (inst, inst_env);
3391 asr_op (inst, inst_env);
3395 asrq_op (inst, inst_env);
3398 case cris_ax_ei_setf_op:
3399 ax_ei_setf_op (inst, inst_env);
3402 case cris_bdap_prefix:
3403 bdap_prefix (inst, inst_env);
3406 case cris_biap_prefix:
3407 biap_prefix (inst, inst_env);
3411 break_op (inst, inst_env);
3414 case cris_btst_nop_op:
3415 btst_nop_op (inst, inst_env);
3418 case cris_clearf_di_op:
3419 clearf_di_op (inst, inst_env);
3422 case cris_dip_prefix:
3423 dip_prefix (inst, inst_env);
3426 case cris_dstep_logshift_mstep_neg_not_op:
3427 dstep_logshift_mstep_neg_not_op (inst, inst_env);
3430 case cris_eight_bit_offset_branch_op:
3431 eight_bit_offset_branch_op (inst, inst_env);
3434 case cris_move_mem_to_reg_movem_op:
3435 move_mem_to_reg_movem_op (inst, inst_env);
3438 case cris_move_reg_to_mem_movem_op:
3439 move_reg_to_mem_movem_op (inst, inst_env);
3442 case cris_move_to_preg_op:
3443 move_to_preg_op (inst, inst_env);
3447 muls_op (inst, inst_env);
3451 mulu_op (inst, inst_env);
3454 case cris_none_reg_mode_add_sub_cmp_and_or_move_op:
3455 none_reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env);
3458 case cris_none_reg_mode_clear_test_op:
3459 none_reg_mode_clear_test_op (inst, inst_env);
3462 case cris_none_reg_mode_jump_op:
3463 none_reg_mode_jump_op (inst, inst_env);
3466 case cris_none_reg_mode_move_from_preg_op:
3467 none_reg_mode_move_from_preg_op (inst, inst_env);
3470 case cris_quick_mode_add_sub_op:
3471 quick_mode_add_sub_op (inst, inst_env);
3474 case cris_quick_mode_and_cmp_move_or_op:
3475 quick_mode_and_cmp_move_or_op (inst, inst_env);
3478 case cris_quick_mode_bdap_prefix:
3479 quick_mode_bdap_prefix (inst, inst_env);
3482 case cris_reg_mode_add_sub_cmp_and_or_move_op:
3483 reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env);
3486 case cris_reg_mode_clear_op:
3487 reg_mode_clear_op (inst, inst_env);
3490 case cris_reg_mode_jump_op:
3491 reg_mode_jump_op (inst, inst_env);
3494 case cris_reg_mode_move_from_preg_op:
3495 reg_mode_move_from_preg_op (inst, inst_env);
3498 case cris_reg_mode_test_op:
3499 reg_mode_test_op (inst, inst_env);
3503 scc_op (inst, inst_env);
3506 case cris_sixteen_bit_offset_branch_op:
3507 sixteen_bit_offset_branch_op (inst, inst_env);
3510 case cris_three_operand_add_sub_cmp_and_or_op:
3511 three_operand_add_sub_cmp_and_or_op (inst, inst_env);
3514 case cris_three_operand_bound_op:
3515 three_operand_bound_op (inst, inst_env);
3518 case cris_two_operand_bound_op:
3519 two_operand_bound_op (inst, inst_env);
3523 xor_op (inst, inst_env);
3528 /* This wrapper is to avoid cris_get_assembler being called before
3529 exec_bfd has been set. */
3532 cris_delayed_get_disassembler (bfd_vma addr, disassemble_info *info)
3534 tm_print_insn = cris_get_disassembler (exec_bfd);
3535 return (*tm_print_insn) (addr, info);
3539 _initialize_cris_tdep (void)
3541 struct cmd_list_element *c;
3543 gdbarch_register (bfd_arch_cris, cris_gdbarch_init, cris_dump_tdep);
3545 /* Used in disassembly. */
3546 tm_print_insn = cris_delayed_get_disassembler;
3548 /* CRIS-specific user-commands. */
3549 c = add_set_cmd ("cris-version", class_support, var_integer,
3550 (char *) &usr_cmd_cris_version,
3551 "Set the current CRIS version.", &setlist);
3552 c->function.sfunc = cris_version_update;
3553 add_show_from_set (c, &showlist);
3555 c = add_set_enum_cmd ("cris-mode", class_support, cris_mode_enums,
3557 "Set the current CRIS mode.", &setlist);
3558 c->function.sfunc = cris_mode_update;
3559 add_show_from_set (c, &showlist);
3561 c = add_set_enum_cmd ("cris-abi", class_support, cris_abi_enums,
3563 "Set the current CRIS ABI version.", &setlist);
3564 c->function.sfunc = cris_abi_update;
3565 add_show_from_set (c, &showlist);
3568 /* Prints out all target specific values. */
3571 cris_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
3573 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3576 fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_version = %i\n",
3577 tdep->cris_version);
3578 fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_mode = %s\n",
3580 fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_abi = %s\n",
3587 cris_version_update (char *ignore_args, int from_tty,
3588 struct cmd_list_element *c)
3590 struct gdbarch_info info;
3592 /* From here on, trust the user's CRIS version setting. */
3593 if (c->type == set_cmd)
3595 usr_cmd_cris_version_valid = 1;
3597 /* Update the current architecture, if needed. */
3598 memset (&info, 0, sizeof info);
3599 if (!gdbarch_update_p (info))
3600 internal_error (__FILE__, __LINE__, "cris_gdbarch_update: failed to update architecture.");
3605 cris_mode_update (char *ignore_args, int from_tty,
3606 struct cmd_list_element *c)
3608 struct gdbarch_info info;
3610 /* From here on, trust the user's CRIS mode setting. */
3611 if (c->type == set_cmd)
3613 usr_cmd_cris_mode_valid = 1;
3615 /* Update the current architecture, if needed. */
3616 memset (&info, 0, sizeof info);
3617 if (!gdbarch_update_p (info))
3618 internal_error (__FILE__, __LINE__, "cris_gdbarch_update: failed to update architecture.");
3623 cris_abi_update (char *ignore_args, int from_tty,
3624 struct cmd_list_element *c)
3626 struct gdbarch_info info;
3628 /* From here on, trust the user's CRIS ABI setting. */
3629 if (c->type == set_cmd)
3631 usr_cmd_cris_abi_valid = 1;
3633 /* Update the current architecture, if needed. */
3634 memset (&info, 0, sizeof info);
3635 if (!gdbarch_update_p (info))
3636 internal_error (__FILE__, __LINE__, "cris_gdbarch_update: failed to update architecture.");
3640 /* Copied from pa64solib.c, with a couple of minor changes. */
3643 bfd_lookup_symbol (bfd *abfd, const char *symname)
3645 unsigned int storage_needed;
3647 asymbol **symbol_table;
3648 unsigned int number_of_symbols;
3650 struct cleanup *back_to;
3651 CORE_ADDR symaddr = 0;
3653 storage_needed = bfd_get_symtab_upper_bound (abfd);
3655 if (storage_needed > 0)
3657 symbol_table = (asymbol **) xmalloc (storage_needed);
3658 back_to = make_cleanup (free, (PTR) symbol_table);
3659 number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
3661 for (i = 0; i < number_of_symbols; i++)
3663 sym = *symbol_table++;
3664 if (!strcmp (sym->name, symname))
3666 /* Bfd symbols are section relative. */
3667 symaddr = sym->value + sym->section->vma;
3671 do_cleanups (back_to);
3676 static struct gdbarch *
3677 cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
3679 struct gdbarch *gdbarch;
3680 struct gdbarch_tdep *tdep;
3682 const char *cris_mode;
3683 const char *cris_abi;
3684 CORE_ADDR cris_abi_sym = 0;
3687 if (usr_cmd_cris_version_valid)
3689 /* Trust the user's CRIS version setting. */
3690 cris_version = usr_cmd_cris_version;
3694 /* Assume it's CRIS version 10. */
3698 if (usr_cmd_cris_mode_valid)
3700 /* Trust the user's CRIS mode setting. */
3701 cris_mode = usr_cmd_cris_mode;
3703 else if (cris_version == 10)
3705 /* Assume CRIS version 10 is in user mode. */
3706 cris_mode = CRIS_MODE_USER;
3710 /* Strictly speaking, older CRIS version don't have a supervisor mode,
3711 but we regard its only mode as supervisor mode. */
3712 cris_mode = CRIS_MODE_SUPERVISOR;
3715 if (usr_cmd_cris_abi_valid)
3717 /* Trust the user's ABI setting. */
3718 cris_abi = usr_cmd_cris_abi;
3722 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
3724 /* An elf target uses the new ABI. */
3725 cris_abi = CRIS_ABI_V2;
3727 else if (bfd_get_flavour (info.abfd) == bfd_target_aout_flavour)
3729 /* An a.out target may use either ABI. Look for hints in the
3731 cris_abi_sym = bfd_lookup_symbol (info.abfd, CRIS_ABI_SYMBOL);
3732 cris_abi = cris_abi_sym ? CRIS_ABI_V2 : CRIS_ABI_ORIGINAL;
3736 /* Unknown bfd flavour. Assume it's the new ABI. */
3737 cris_abi = CRIS_ABI_V2;
3740 else if (gdbarch_tdep (current_gdbarch))
3742 /* No bfd available. Stick with whatever ABI we're currently using.
3743 (This is to avoid changing the ABI when the user updates the
3744 architecture with the 'set cris-version' command.) */
3745 cris_abi = gdbarch_tdep (current_gdbarch)->cris_abi;
3749 /* No bfd, and no current architecture available. Assume it's the
3751 cris_abi = CRIS_ABI_V2;
3754 /* Make the current settings visible to the user. */
3755 usr_cmd_cris_version = cris_version;
3756 usr_cmd_cris_mode = cris_mode;
3757 usr_cmd_cris_abi = cris_abi;
3759 /* Find a candidate among the list of pre-declared architectures. Both
3760 CRIS version and ABI must match. */
3761 for (arches = gdbarch_list_lookup_by_info (arches, &info);
3763 arches = gdbarch_list_lookup_by_info (arches->next, &info))
3765 if ((gdbarch_tdep (arches->gdbarch)->cris_version == cris_version)
3766 && (gdbarch_tdep (arches->gdbarch)->cris_mode == cris_mode)
3767 && (gdbarch_tdep (arches->gdbarch)->cris_abi == cris_abi))
3768 return arches->gdbarch;
3771 /* No matching architecture was found. Create a new one. */
3772 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
3773 gdbarch = gdbarch_alloc (&info, tdep);
3775 tdep->cris_version = cris_version;
3776 tdep->cris_mode = cris_mode;
3777 tdep->cris_abi = cris_abi;
3779 /* INIT shall ensure that the INFO.BYTE_ORDER is non-zero. */
3780 switch (info.byte_order)
3787 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: big endian byte order in info");
3791 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unknown byte order in info");
3794 /* Initialize the ABI dependent things. */
3795 if (tdep->cris_abi == CRIS_ABI_ORIGINAL)
3797 set_gdbarch_double_bit (gdbarch, 32);
3798 set_gdbarch_push_arguments (gdbarch, cris_abi_original_push_arguments);
3799 set_gdbarch_store_return_value (gdbarch,
3800 cris_abi_original_store_return_value);
3801 set_gdbarch_extract_return_value
3802 (gdbarch, cris_abi_original_extract_return_value);
3803 set_gdbarch_reg_struct_has_addr
3804 (gdbarch, cris_abi_original_reg_struct_has_addr);
3806 else if (tdep->cris_abi == CRIS_ABI_V2)
3808 set_gdbarch_double_bit (gdbarch, 64);
3809 set_gdbarch_push_arguments (gdbarch, cris_abi_v2_push_arguments);
3810 set_gdbarch_store_return_value (gdbarch, cris_abi_v2_store_return_value);
3811 set_gdbarch_extract_return_value (gdbarch,
3812 cris_abi_v2_extract_return_value);
3813 set_gdbarch_reg_struct_has_addr (gdbarch,
3814 cris_abi_v2_reg_struct_has_addr);
3817 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unknown CRIS ABI");
3819 /* The default definition of a long double is 2 * TARGET_DOUBLE_BIT,
3820 which means we have to set this explicitly. */
3821 set_gdbarch_long_double_bit (gdbarch, 64);
3823 /* Floating point is IEEE compatible. */
3824 set_gdbarch_ieee_float (gdbarch, 1);
3826 /* There are 32 registers (some of which may not be implemented). */
3827 set_gdbarch_num_regs (gdbarch, 32);
3828 set_gdbarch_sp_regnum (gdbarch, 14);
3829 set_gdbarch_fp_regnum (gdbarch, 8);
3830 set_gdbarch_pc_regnum (gdbarch, 15);
3832 set_gdbarch_register_name (gdbarch, cris_register_name);
3834 /* Length of ordinary registers used in push_word and a few other places.
3835 REGISTER_RAW_SIZE is the real way to know how big a register is. */
3836 set_gdbarch_register_size (gdbarch, 4);
3839 set_gdbarch_register_bytes_ok (gdbarch, cris_register_bytes_ok);
3840 set_gdbarch_software_single_step (gdbarch, cris_software_single_step);
3843 set_gdbarch_cannot_store_register (gdbarch, cris_cannot_store_register);
3844 set_gdbarch_cannot_fetch_register (gdbarch, cris_cannot_fetch_register);
3847 /* The total amount of space needed to store (in an array called registers)
3848 GDB's copy of the machine's register state. Note: We can not use
3849 cris_register_size at this point, since it relies on current_gdbarch
3851 switch (tdep->cris_version)
3857 /* Support for these may be added later. */
3858 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unsupported CRIS version");
3863 /* CRIS v8 and v9, a.k.a. ETRAX 100. General registers R0 - R15
3864 (32 bits), special registers P0 - P1 (8 bits), P4 - P5 (16 bits),
3865 and P8 - P14 (32 bits). */
3866 register_bytes = (16 * 4) + (2 * 1) + (2 * 2) + (7 * 4);
3871 /* CRIS v10 and v11, a.k.a. ETRAX 100LX. In addition to ETRAX 100,
3872 P7 (32 bits), and P15 (32 bits) have been implemented. */
3873 register_bytes = (16 * 4) + (2 * 1) + (2 * 2) + (9 * 4);
3877 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unknown CRIS version");
3880 set_gdbarch_register_bytes (gdbarch, register_bytes);
3882 /* Returns the register offset for the first byte of register regno's space
3883 in the saved register state. */
3884 set_gdbarch_register_byte (gdbarch, cris_register_offset);
3886 /* The length of the registers in the actual machine representation. */
3887 set_gdbarch_register_raw_size (gdbarch, cris_register_size);
3889 /* The largest value REGISTER_RAW_SIZE can have. */
3890 set_gdbarch_max_register_raw_size (gdbarch, 32);
3892 /* The length of the registers in the program's representation. */
3893 set_gdbarch_register_virtual_size (gdbarch, cris_register_size);
3895 /* The largest value REGISTER_VIRTUAL_SIZE can have. */
3896 set_gdbarch_max_register_virtual_size (gdbarch, 32);
3898 set_gdbarch_register_virtual_type (gdbarch, cris_register_virtual_type);
3900 /* Use generic dummy frames. */
3901 set_gdbarch_use_generic_dummy_frames (gdbarch, 1);
3903 /* Where to execute the call in the memory segments. */
3904 set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT);
3905 set_gdbarch_call_dummy_address (gdbarch, entry_point_address);
3907 /* Start execution at the beginning of dummy. */
3908 set_gdbarch_call_dummy_start_offset (gdbarch, 0);
3909 set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 0);
3911 /* Set to 1 since call_dummy_breakpoint_offset was defined. */
3912 set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1);
3914 /* Read all about dummy frames in blockframe.c. */
3915 set_gdbarch_call_dummy_length (gdbarch, 0);
3916 set_gdbarch_pc_in_call_dummy (gdbarch, pc_in_call_dummy_at_entry_point);
3918 /* Defined to 1 to indicate that the target supports inferior function
3920 set_gdbarch_call_dummy_p (gdbarch, 1);
3921 set_gdbarch_call_dummy_words (gdbarch, 0);
3922 set_gdbarch_sizeof_call_dummy_words (gdbarch, 0);
3924 /* No stack adjustment needed when peforming an inferior function call. */
3925 set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
3926 set_gdbarch_fix_call_dummy (gdbarch, generic_fix_call_dummy);
3928 set_gdbarch_get_saved_register (gdbarch, generic_get_saved_register);
3930 /* No register requires conversion from raw format to virtual format. */
3931 set_gdbarch_register_convertible (gdbarch, generic_register_convertible_not);
3933 set_gdbarch_push_dummy_frame (gdbarch, generic_push_dummy_frame);
3934 set_gdbarch_push_return_address (gdbarch, cris_push_return_address);
3935 set_gdbarch_pop_frame (gdbarch, cris_pop_frame);
3937 set_gdbarch_store_struct_return (gdbarch, cris_store_struct_return);
3938 set_gdbarch_extract_struct_value_address (gdbarch,
3939 cris_extract_struct_value_address);
3940 set_gdbarch_use_struct_convention (gdbarch, cris_use_struct_convention);
3942 set_gdbarch_frame_init_saved_regs (gdbarch, cris_frame_init_saved_regs);
3943 set_gdbarch_init_extra_frame_info (gdbarch, cris_init_extra_frame_info);
3944 set_gdbarch_skip_prologue (gdbarch, cris_skip_prologue);
3945 set_gdbarch_prologue_frameless_p (gdbarch, generic_prologue_frameless_p);
3947 /* The stack grows downward. */
3948 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
3950 set_gdbarch_breakpoint_from_pc (gdbarch, cris_breakpoint_from_pc);
3952 /* The PC must not be decremented after a breakpoint. (The breakpoint
3953 handler takes care of that.) */
3954 set_gdbarch_decr_pc_after_break (gdbarch, 0);
3956 /* Offset from address of function to start of its code. */
3957 set_gdbarch_function_start_offset (gdbarch, 0);
3959 /* The number of bytes at the start of arglist that are not really args,
3960 0 in the CRIS ABI. */
3961 set_gdbarch_frame_args_skip (gdbarch, 0);
3962 set_gdbarch_frameless_function_invocation
3963 (gdbarch, cris_frameless_function_invocation);
3964 set_gdbarch_frame_chain (gdbarch, cris_frame_chain);
3965 set_gdbarch_frame_chain_valid (gdbarch, generic_file_frame_chain_valid);
3967 set_gdbarch_frame_saved_pc (gdbarch, cris_frame_saved_pc);
3968 set_gdbarch_frame_args_address (gdbarch, cris_frame_args_address);
3969 set_gdbarch_frame_locals_address (gdbarch, cris_frame_locals_address);
3970 set_gdbarch_saved_pc_after_call (gdbarch, cris_saved_pc_after_call);
3972 set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
3974 /* No extra stack alignment needed. Set to 1 by default. */
3975 set_gdbarch_extra_stack_alignment_needed (gdbarch, 0);
3977 /* Helpful for backtracing and returning in a call dummy. */
3978 set_gdbarch_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos);