1 /* Target dependent code for CRIS, for GDB, the GNU debugger.
3 Copyright 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
5 Contributed by Axis Communications AB.
6 Written by Hendrik Ruijter, Stefan Andersson, and Orjan Friberg.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
33 #include "opcode/cris.h"
34 #include "arch-utils.h"
36 #include "gdb_assert.h"
38 /* To get entry_point_address. */
41 #include "solib.h" /* Support for shared libraries. */
42 #include "solib-svr4.h" /* For struct link_map_offsets. */
43 #include "gdb_string.h"
49 /* There are no floating point registers. Used in gdbserver low-linux.c. */
52 /* There are 16 general registers. */
55 /* There are 16 special registers. */
59 /* Register numbers of various important registers.
60 DEPRECATED_FP_REGNUM Contains address of executing stack frame.
61 STR_REGNUM Contains the address of structure return values.
62 RET_REGNUM Contains the return value when shorter than or equal to 32 bits
63 ARG1_REGNUM Contains the first parameter to a function.
64 ARG2_REGNUM Contains the second parameter to a function.
65 ARG3_REGNUM Contains the third parameter to a function.
66 ARG4_REGNUM Contains the fourth parameter to a function. Rest on stack.
67 SP_REGNUM Contains address of top of stack.
68 PC_REGNUM Contains address of next instruction.
69 SRP_REGNUM Subroutine return pointer register.
70 BRP_REGNUM Breakpoint return pointer register. */
72 /* DEPRECATED_FP_REGNUM = 8, SP_REGNUM = 14, and PC_REGNUM = 15 have
73 been incorporated into the multi-arch framework. */
77 /* Enums with respect to the general registers, valid for all
86 /* Enums with respect to the special registers, some of which may not be
87 applicable to all CRIS versions. */
105 extern const struct cris_spec_reg cris_spec_regs[];
107 /* CRIS version, set via the user command 'set cris-version'. Affects
108 register names and sizes.*/
109 static int usr_cmd_cris_version;
111 /* Indicates whether to trust the above variable. */
112 static int usr_cmd_cris_version_valid = 0;
114 /* CRIS mode, set via the user command 'set cris-mode'. Affects availability
115 of some registers. */
116 static const char *usr_cmd_cris_mode;
118 /* Indicates whether to trust the above variable. */
119 static int usr_cmd_cris_mode_valid = 0;
121 static const char CRIS_MODE_USER[] = "CRIS_MODE_USER";
122 static const char CRIS_MODE_SUPERVISOR[] = "CRIS_MODE_SUPERVISOR";
123 static const char *cris_mode_enums[] =
126 CRIS_MODE_SUPERVISOR,
130 /* CRIS ABI, set via the user command 'set cris-abi'.
131 There are two flavours:
132 1. Original ABI with 32-bit doubles, where arguments <= 4 bytes are
134 2. New ABI with 64-bit doubles, where arguments <= 8 bytes are passed by
136 static const char *usr_cmd_cris_abi;
138 /* Indicates whether to trust the above variable. */
139 static int usr_cmd_cris_abi_valid = 0;
141 /* These variables are strings instead of enums to make them usable as
142 parameters to add_set_enum_cmd. */
143 static const char CRIS_ABI_ORIGINAL[] = "CRIS_ABI_ORIGINAL";
144 static const char CRIS_ABI_V2[] = "CRIS_ABI_V2";
145 static const char CRIS_ABI_SYMBOL[] = ".$CRIS_ABI_V2";
146 static const char *cris_abi_enums[] =
153 /* CRIS architecture specific information. */
157 const char *cris_mode;
158 const char *cris_abi;
161 /* Functions for accessing target dependent data. */
166 return (gdbarch_tdep (current_gdbarch)->cris_version);
172 return (gdbarch_tdep (current_gdbarch)->cris_mode);
178 return (gdbarch_tdep (current_gdbarch)->cris_abi);
181 struct frame_extra_info
187 /* The instruction environment needed to find single-step breakpoints. */
189 struct instruction_environment
191 unsigned long reg[NUM_GENREGS];
192 unsigned long preg[NUM_SPECREGS];
193 unsigned long branch_break_address;
194 unsigned long delay_slot_pc;
195 unsigned long prefix_value;
200 int delay_slot_pc_active;
202 int disable_interrupt;
205 /* Save old breakpoints in order to restore the state before a single_step.
206 At most, two breakpoints will have to be remembered. */
208 char binsn_quantum[BREAKPOINT_MAX];
209 static binsn_quantum break_mem[2];
210 static CORE_ADDR next_pc = 0;
211 static CORE_ADDR branch_target_address = 0;
212 static unsigned char branch_break_inserted = 0;
214 /* Machine-dependencies in CRIS for opcodes. */
216 /* Instruction sizes. */
217 enum cris_instruction_sizes
224 /* Addressing modes. */
225 enum cris_addressing_modes
232 /* Prefix addressing modes. */
233 enum cris_prefix_addressing_modes
235 PREFIX_INDEX_MODE = 2,
236 PREFIX_ASSIGN_MODE = 3,
238 /* Handle immediate byte offset addressing mode prefix format. */
239 PREFIX_OFFSET_MODE = 2
242 /* Masks for opcodes. */
243 enum cris_opcode_masks
245 BRANCH_SIGNED_SHORT_OFFSET_MASK = 0x1,
246 SIGNED_EXTEND_BIT_MASK = 0x2,
247 SIGNED_BYTE_MASK = 0x80,
248 SIGNED_BYTE_EXTEND_MASK = 0xFFFFFF00,
249 SIGNED_WORD_MASK = 0x8000,
250 SIGNED_WORD_EXTEND_MASK = 0xFFFF0000,
251 SIGNED_DWORD_MASK = 0x80000000,
252 SIGNED_QUICK_VALUE_MASK = 0x20,
253 SIGNED_QUICK_VALUE_EXTEND_MASK = 0xFFFFFFC0
256 /* Functions for opcodes. The general form of the ETRAX 16-bit instruction:
264 cris_get_operand2 (unsigned short insn)
266 return ((insn & 0xF000) >> 12);
270 cris_get_mode (unsigned short insn)
272 return ((insn & 0x0C00) >> 10);
276 cris_get_opcode (unsigned short insn)
278 return ((insn & 0x03C0) >> 6);
282 cris_get_size (unsigned short insn)
284 return ((insn & 0x0030) >> 4);
288 cris_get_operand1 (unsigned short insn)
290 return (insn & 0x000F);
293 /* Additional functions in order to handle opcodes. */
296 cris_get_wide_opcode (unsigned short insn)
298 return ((insn & 0x03E0) >> 5);
302 cris_get_short_size (unsigned short insn)
304 return ((insn & 0x0010) >> 4);
308 cris_get_quick_value (unsigned short insn)
310 return (insn & 0x003F);
314 cris_get_bdap_quick_offset (unsigned short insn)
316 return (insn & 0x00FF);
320 cris_get_branch_short_offset (unsigned short insn)
322 return (insn & 0x00FF);
326 cris_get_asr_shift_steps (unsigned long value)
328 return (value & 0x3F);
332 cris_get_asr_quick_shift_steps (unsigned short insn)
334 return (insn & 0x1F);
338 cris_get_clear_size (unsigned short insn)
340 return ((insn) & 0xC000);
344 cris_is_signed_extend_bit_on (unsigned short insn)
346 return (((insn) & 0x20) == 0x20);
350 cris_is_xflag_bit_on (unsigned short insn)
352 return (((insn) & 0x1000) == 0x1000);
356 cris_set_size_to_dword (unsigned short *insn)
363 cris_get_signed_offset (unsigned short insn)
365 return ((signed char) (insn & 0x00FF));
368 /* Calls an op function given the op-type, working on the insn and the
370 static void cris_gdb_func (enum cris_op_type, unsigned short, inst_env_type *);
372 static CORE_ADDR cris_skip_prologue_main (CORE_ADDR pc, int frameless_p);
374 static struct gdbarch *cris_gdbarch_init (struct gdbarch_info,
375 struct gdbarch_list *);
377 static void cris_dump_tdep (struct gdbarch *, struct ui_file *);
379 static void cris_version_update (char *ignore_args, int from_tty,
380 struct cmd_list_element *c);
382 static void cris_mode_update (char *ignore_args, int from_tty,
383 struct cmd_list_element *c);
385 static void cris_abi_update (char *ignore_args, int from_tty,
386 struct cmd_list_element *c);
388 static CORE_ADDR bfd_lookup_symbol (bfd *, const char *);
390 /* Frames information. The definition of the struct frame_info is
394 enum frame_type type;
398 If the compilation option -fno-omit-frame-pointer is present the
399 variable frame will be set to the content of R8 which is the frame
402 The variable pc contains the address where execution is performed
403 in the present frame. The innermost frame contains the current content
404 of the register PC. All other frames contain the content of the
405 register PC in the next frame.
407 The variable `type' indicates the frame's type: normal, SIGTRAMP
408 (associated with a signal handler), dummy (associated with a dummy
411 The variable return_pc contains the address where execution should be
412 resumed when the present frame has finished, the return address.
414 The variable leaf_function is 1 if the return address is in the register
415 SRP, and 0 if it is on the stack.
417 Prologue instructions C-code.
418 The prologue may consist of (-fno-omit-frame-pointer)
422 move.d sp,r8 move.d sp,r8
424 movem rY,[sp] movem rY,[sp]
425 move.S rZ,[r8-U] move.S rZ,[r8-U]
427 where 1 is a non-terminal function, and 2 is a leaf-function.
429 Note that this assumption is extremely brittle, and will break at the
430 slightest change in GCC's prologue.
432 If local variables are declared or register contents are saved on stack
433 the subq-instruction will be present with X as the number of bytes
434 needed for storage. The reshuffle with respect to r8 may be performed
435 with any size S (b, w, d) and any of the general registers Z={0..13}.
436 The offset U should be representable by a signed 8-bit value in all cases.
437 Thus, the prefix word is assumed to be immediate byte offset mode followed
438 by another word containing the instruction.
447 Prologue instructions C++-code.
448 Case 1) and 2) in the C-code may be followed by
454 move.S [r8+U],rZ ; P4
456 if any of the call parameters are stored. The host expects these
457 instructions to be executed in order to get the call parameters right. */
459 /* Examine the prologue of a function. The variable ip is the address of
460 the first instruction of the prologue. The variable limit is the address
461 of the first instruction after the prologue. The variable fi contains the
462 information in struct frame_info. The variable frameless_p controls whether
463 the entire prologue is examined (0) or just enough instructions to
464 determine that it is a prologue (1). */
467 cris_examine (CORE_ADDR ip, CORE_ADDR limit, struct frame_info *fi,
470 /* Present instruction. */
473 /* Next instruction, lookahead. */
474 unsigned short insn_next;
477 /* Is there a push fp? */
480 /* Number of byte on stack used for local variables and movem. */
483 /* Highest register number in a movem. */
486 /* move.d r<source_register>,rS */
487 short source_register;
489 /* This frame is with respect to a leaf until a push srp is found. */
490 get_frame_extra_info (fi)->leaf_function = 1;
492 /* This frame is without the FP until a push fp is found. */
495 /* Assume nothing on stack. */
499 /* No information about register contents so far. */
501 /* We only want to know the end of the prologue when fi->saved_regs == 0.
502 When the saved registers are allocated full information is required. */
503 if (deprecated_get_frame_saved_regs (fi))
505 for (regno = 0; regno < NUM_REGS; regno++)
506 deprecated_get_frame_saved_regs (fi)[regno] = 0;
509 /* Find the prologue instructions. */
512 insn = read_memory_unsigned_integer (ip, sizeof (short));
513 ip += sizeof (short);
516 /* push <reg> 32 bit instruction */
517 insn_next = read_memory_unsigned_integer (ip, sizeof (short));
518 ip += sizeof (short);
519 regno = cris_get_operand2 (insn_next);
521 /* This check, meant to recognize srp, used to be regno ==
522 (SRP_REGNUM - NUM_GENREGS), but that covers r11 also. */
523 if (insn_next == 0xBE7E)
529 get_frame_extra_info (fi)->leaf_function = 0;
531 else if (regno == DEPRECATED_FP_REGNUM)
536 else if (insn == 0x866E)
545 else if (cris_get_operand2 (insn) == SP_REGNUM
546 && cris_get_mode (insn) == 0x0000
547 && cris_get_opcode (insn) == 0x000A)
550 val = cris_get_quick_value (insn);
552 else if (cris_get_mode (insn) == 0x0002
553 && cris_get_opcode (insn) == 0x000F
554 && cris_get_size (insn) == 0x0003
555 && cris_get_operand1 (insn) == SP_REGNUM)
557 /* movem r<regsave>,[sp] */
562 regsave = cris_get_operand2 (insn);
564 else if (cris_get_operand2 (insn) == SP_REGNUM
565 && ((insn & 0x0F00) >> 8) == 0x0001
566 && (cris_get_signed_offset (insn) < 0))
568 /* Immediate byte offset addressing prefix word with sp as base
569 register. Used for CRIS v8 i.e. ETRAX 100 and newer if <val>
570 is between 64 and 128.
571 movem r<regsave>,[sp=sp-<val>] */
572 val = -cris_get_signed_offset (insn);
573 insn_next = read_memory_unsigned_integer (ip, sizeof (short));
574 ip += sizeof (short);
575 if (cris_get_mode (insn_next) == PREFIX_ASSIGN_MODE
576 && cris_get_opcode (insn_next) == 0x000F
577 && cris_get_size (insn_next) == 0x0003
578 && cris_get_operand1 (insn_next) == SP_REGNUM)
584 regsave = cris_get_operand2 (insn_next);
588 /* The prologue ended before the limit was reached. */
589 ip -= 2 * sizeof (short);
593 else if (cris_get_mode (insn) == 0x0001
594 && cris_get_opcode (insn) == 0x0009
595 && cris_get_size (insn) == 0x0002)
597 /* move.d r<10..13>,r<0..15> */
602 source_register = cris_get_operand1 (insn);
604 /* FIXME? In the glibc solibs, the prologue might contain something
605 like (this example taken from relocate_doit):
608 which isn't covered by the source_register check below. Question
609 is whether to add a check for this combo, or make better use of
610 the limit variable instead. */
611 if (source_register < ARG1_REGNUM || source_register > ARG4_REGNUM)
613 /* The prologue ended before the limit was reached. */
614 ip -= sizeof (short);
618 else if (cris_get_operand2 (insn) == DEPRECATED_FP_REGNUM
619 /* The size is a fixed-size. */
620 && ((insn & 0x0F00) >> 8) == 0x0001
621 /* A negative offset. */
622 && (cris_get_signed_offset (insn) < 0))
624 /* move.S rZ,[r8-U] (?) */
625 insn_next = read_memory_unsigned_integer (ip, sizeof (short));
626 ip += sizeof (short);
627 regno = cris_get_operand2 (insn_next);
628 if ((regno >= 0 && regno < SP_REGNUM)
629 && cris_get_mode (insn_next) == PREFIX_OFFSET_MODE
630 && cris_get_opcode (insn_next) == 0x000F)
632 /* move.S rZ,[r8-U] */
637 /* The prologue ended before the limit was reached. */
638 ip -= 2 * sizeof (short);
642 else if (cris_get_operand2 (insn) == DEPRECATED_FP_REGNUM
643 /* The size is a fixed-size. */
644 && ((insn & 0x0F00) >> 8) == 0x0001
645 /* A positive offset. */
646 && (cris_get_signed_offset (insn) > 0))
648 /* move.S [r8+U],rZ (?) */
649 insn_next = read_memory_unsigned_integer (ip, sizeof (short));
650 ip += sizeof (short);
651 regno = cris_get_operand2 (insn_next);
652 if ((regno >= 0 && regno < SP_REGNUM)
653 && cris_get_mode (insn_next) == PREFIX_OFFSET_MODE
654 && cris_get_opcode (insn_next) == 0x0009
655 && cris_get_operand1 (insn_next) == regno)
657 /* move.S [r8+U],rZ */
662 /* The prologue ended before the limit was reached. */
663 ip -= 2 * sizeof (short);
669 /* The prologue ended before the limit was reached. */
670 ip -= sizeof (short);
676 /* We only want to know the end of the prologue when
677 fi->saved_regs == 0. */
678 if (!deprecated_get_frame_saved_regs (fi))
683 deprecated_get_frame_saved_regs (fi)[DEPRECATED_FP_REGNUM] = get_frame_base (fi);
685 /* Calculate the addresses. */
686 for (regno = regsave; regno >= 0; regno--)
688 deprecated_get_frame_saved_regs (fi)[regno] = get_frame_base (fi) - val;
691 if (get_frame_extra_info (fi)->leaf_function)
693 /* Set the register SP to contain the stack pointer of
695 deprecated_get_frame_saved_regs (fi)[SP_REGNUM] = get_frame_base (fi) + 4;
699 /* Set the register SP to contain the stack pointer of
701 deprecated_get_frame_saved_regs (fi)[SP_REGNUM] = get_frame_base (fi) + 8;
703 /* Set the register SRP to contain the return address of
705 deprecated_get_frame_saved_regs (fi)[SRP_REGNUM] = get_frame_base (fi) + 4;
711 /* Advance pc beyond any function entry prologue instructions at pc
712 to reach some "real" code. */
715 cris_skip_prologue (CORE_ADDR pc)
717 return cris_skip_prologue_main (pc, 0);
720 /* As cris_skip_prologue, but stops as soon as it knows that the function
721 has a frame. Its result is equal to its input pc if the function is
722 frameless, unequal otherwise. */
725 cris_skip_prologue_frameless_p (CORE_ADDR pc)
727 return cris_skip_prologue_main (pc, 1);
730 /* Given a PC value corresponding to the start of a function, return the PC
731 of the first instruction after the function prologue. */
734 cris_skip_prologue_main (CORE_ADDR pc, int frameless_p)
736 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
737 struct frame_info *fi;
738 struct symtab_and_line sal = find_pc_line (pc, 0);
740 CORE_ADDR pc_after_prologue;
742 /* frame_info now contains dynamic memory. Since fi is a dummy
743 here, I don't bother allocating memory for saved_regs. */
744 fi = deprecated_frame_xmalloc_with_cleanup (0, sizeof (struct frame_extra_info));
746 /* If there is no symbol information then sal.end == 0, and we end up
747 examining only the first instruction in the function prologue.
748 Exaggerating the limit seems to be harmless. */
750 best_limit = sal.end;
752 best_limit = pc + 100;
754 pc_after_prologue = cris_examine (pc, best_limit, fi, frameless_p);
755 do_cleanups (old_chain);
756 return pc_after_prologue;
759 /* Use the program counter to determine the contents and size of a breakpoint
760 instruction. It returns a pointer to a string of bytes that encode a
761 breakpoint instruction, stores the length of the string to *lenptr, and
762 adjusts pcptr (if necessary) to point to the actual memory location where
763 the breakpoint should be inserted. */
765 static const unsigned char *
766 cris_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
768 static unsigned char break_insn[] = {0x38, 0xe9};
774 /* Returns the register SRP (subroutine return pointer) which must contain
775 the content of the register PC after a function call. */
778 cris_saved_pc_after_call (struct frame_info *frame)
780 return read_register (SRP_REGNUM);
783 /* Returns 1 if spec_reg is applicable to the current gdbarch's CRIS version,
787 cris_spec_reg_applicable (struct cris_spec_reg spec_reg)
789 int version = cris_version ();
791 switch (spec_reg.applicable_version)
793 case cris_ver_version_all:
795 case cris_ver_warning:
796 /* Indeterminate/obsolete. */
799 /* Simulator only. */
802 return (version >= 0 && version <= 3);
804 return (version >= 3);
806 return (version == 8 || version == 9);
808 return (version >= 8);
810 return (version >= 10);
812 /* Invalid cris version. */
817 /* Returns the register size in unit byte. Returns 0 for an unimplemented
818 register, -1 for an invalid register. */
821 cris_register_size (int regno)
826 if (regno >= 0 && regno < NUM_GENREGS)
828 /* General registers (R0 - R15) are 32 bits. */
831 else if (regno >= NUM_GENREGS && regno < NUM_REGS)
833 /* Special register (R16 - R31). cris_spec_regs is zero-based.
834 Adjust regno accordingly. */
835 spec_regno = regno - NUM_GENREGS;
837 /* The entries in cris_spec_regs are stored in register number order,
838 which means we can shortcut into the array when searching it. */
839 for (i = spec_regno; cris_spec_regs[i].name != NULL; i++)
841 if (cris_spec_regs[i].number == spec_regno
842 && cris_spec_reg_applicable (cris_spec_regs[i]))
843 /* Go with the first applicable register. */
844 return cris_spec_regs[i].reg_size;
846 /* Special register not applicable to this CRIS version. */
851 /* Invalid register. */
856 /* Nonzero if regno should not be fetched from the target. This is the case
857 for unimplemented (size 0) and non-existant registers. */
860 cris_cannot_fetch_register (int regno)
862 return ((regno < 0 || regno >= NUM_REGS)
863 || (cris_register_size (regno) == 0));
866 /* Nonzero if regno should not be written to the target, for various
870 cris_cannot_store_register (int regno)
872 /* There are three kinds of registers we refuse to write to.
873 1. Those that not implemented.
874 2. Those that are read-only (depends on the processor mode).
875 3. Those registers to which a write has no effect.
878 if (regno < 0 || regno >= NUM_REGS || cris_register_size (regno) == 0)
879 /* Not implemented. */
882 else if (regno == VR_REGNUM)
886 else if (regno == P0_REGNUM || regno == P4_REGNUM || regno == P8_REGNUM)
887 /* Writing has no effect. */
890 else if (cris_mode () == CRIS_MODE_USER)
892 if (regno == IBR_REGNUM || regno == BAR_REGNUM || regno == BRP_REGNUM
893 || regno == IRP_REGNUM)
894 /* Read-only in user mode. */
901 /* Returns the register offset for the first byte of register regno's space
902 in the saved register state. Returns -1 for an invalid or unimplemented
906 cris_register_offset (int regno)
912 if (regno >= 0 && regno < NUM_REGS)
914 /* FIXME: The offsets should be cached and calculated only once,
915 when the architecture being debugged has changed. */
916 for (i = 0; i < regno; i++)
917 offset += cris_register_size (i);
923 /* Invalid register. */
928 /* Return the GDB type (defined in gdbtypes.c) for the "standard" data type
929 of data in register regno. */
932 cris_register_virtual_type (int regno)
934 if (regno == SP_REGNUM || regno == PC_REGNUM
935 || (regno > P8_REGNUM && regno < USP_REGNUM))
937 /* SP, PC, IBR, IRP, SRP, BAR, DCCR, BRP */
938 return lookup_pointer_type (builtin_type_void);
940 else if (regno == P8_REGNUM || regno == USP_REGNUM
941 || (regno >= 0 && regno < SP_REGNUM))
943 /* R0 - R13, P8, P15 */
944 return builtin_type_unsigned_long;
946 else if (regno > P3_REGNUM && regno < P8_REGNUM)
948 /* P4, CCR, DCR0, DCR1 */
949 return builtin_type_unsigned_short;
951 else if (regno > PC_REGNUM && regno < P4_REGNUM)
954 return builtin_type_unsigned_char;
958 /* Invalid register. */
959 return builtin_type_void;
963 /* Stores a function return value of type type, where valbuf is the address
964 of the value to be stored. */
966 /* In the original CRIS ABI, R10 is used to store return values. */
969 cris_abi_original_store_return_value (struct type *type, char *valbuf)
971 int len = TYPE_LENGTH (type);
973 if (len <= DEPRECATED_REGISTER_SIZE)
974 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (RET_REGNUM), valbuf, len);
976 internal_error (__FILE__, __LINE__, "cris_abi_original_store_return_value: type length too large.");
979 /* In the CRIS ABI V2, R10 and R11 are used to store return values. */
982 cris_abi_v2_store_return_value (struct type *type, char *valbuf)
984 int len = TYPE_LENGTH (type);
986 if (len <= 2 * DEPRECATED_REGISTER_SIZE)
988 /* Note that this works since R10 and R11 are consecutive registers. */
989 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (RET_REGNUM),
993 internal_error (__FILE__, __LINE__, "cris_abi_v2_store_return_value: type length too large.");
996 /* Return the name of register regno as a string. Return NULL for an invalid or
997 unimplemented register. */
1000 cris_register_name (int regno)
1002 static char *cris_genreg_names[] =
1003 { "r0", "r1", "r2", "r3", \
1004 "r4", "r5", "r6", "r7", \
1005 "r8", "r9", "r10", "r11", \
1006 "r12", "r13", "sp", "pc" };
1011 if (regno >= 0 && regno < NUM_GENREGS)
1013 /* General register. */
1014 return cris_genreg_names[regno];
1016 else if (regno >= NUM_GENREGS && regno < NUM_REGS)
1018 /* Special register (R16 - R31). cris_spec_regs is zero-based.
1019 Adjust regno accordingly. */
1020 spec_regno = regno - NUM_GENREGS;
1022 /* The entries in cris_spec_regs are stored in register number order,
1023 which means we can shortcut into the array when searching it. */
1024 for (i = spec_regno; cris_spec_regs[i].name != NULL; i++)
1026 if (cris_spec_regs[i].number == spec_regno
1027 && cris_spec_reg_applicable (cris_spec_regs[i]))
1028 /* Go with the first applicable register. */
1029 return cris_spec_regs[i].name;
1031 /* Special register not applicable to this CRIS version. */
1036 /* Invalid register. */
1042 cris_register_bytes_ok (long bytes)
1044 return (bytes == DEPRECATED_REGISTER_BYTES);
1047 /* Extract from an array regbuf containing the raw register state a function
1048 return value of type type, and copy that, in virtual format, into
1051 /* In the original CRIS ABI, R10 is used to return values. */
1054 cris_abi_original_extract_return_value (struct type *type, char *regbuf,
1057 int len = TYPE_LENGTH (type);
1059 if (len <= DEPRECATED_REGISTER_SIZE)
1060 memcpy (valbuf, regbuf + DEPRECATED_REGISTER_BYTE (RET_REGNUM), len);
1062 internal_error (__FILE__, __LINE__, "cris_abi_original_extract_return_value: type length too large");
1065 /* In the CRIS ABI V2, R10 and R11 are used to store return values. */
1068 cris_abi_v2_extract_return_value (struct type *type, char *regbuf,
1071 int len = TYPE_LENGTH (type);
1073 if (len <= 2 * DEPRECATED_REGISTER_SIZE)
1074 memcpy (valbuf, regbuf + DEPRECATED_REGISTER_BYTE (RET_REGNUM), len);
1076 internal_error (__FILE__, __LINE__, "cris_abi_v2_extract_return_value: type length too large");
1079 /* Store the address of the place in which to copy the structure the
1080 subroutine will return. In the CRIS ABI, R9 is used in order to
1081 pass the address of the allocated area where a structure return
1082 value must be stored. */
1085 cris_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
1087 write_register (STR_REGNUM, addr);
1090 /* Returns 1 if the given type will be passed by pointer rather than
1093 /* In the original CRIS ABI, arguments shorter than or equal to 32 bits are
1097 cris_abi_original_reg_struct_has_addr (int gcc_p, struct type *type)
1099 return (TYPE_LENGTH (type) > 4);
1102 /* In the CRIS ABI V2, arguments shorter than or equal to 64 bits are passed
1106 cris_abi_v2_reg_struct_has_addr (int gcc_p, struct type *type)
1108 return (TYPE_LENGTH (type) > 8);
1111 /* Returns 1 if the function invocation represented by fi does not have a
1112 stack frame associated with it. Otherwise return 0. */
1115 cris_frameless_function_invocation (struct frame_info *fi)
1117 if ((get_frame_type (fi) == SIGTRAMP_FRAME))
1120 return frameless_look_for_prologue (fi);
1123 /* See frame.h. Determines the address of all registers in the
1124 current stack frame storing each in frame->saved_regs. Space for
1125 frame->saved_regs shall be allocated by
1126 DEPRECATED_FRAME_INIT_SAVED_REGS using frame_saved_regs_zalloc. */
1129 cris_frame_init_saved_regs (struct frame_info *fi)
1132 struct symtab_and_line sal;
1134 char *dummy_regs = deprecated_generic_find_dummy_frame (get_frame_pc (fi),
1135 get_frame_base (fi));
1137 /* Examine the entire prologue. */
1138 int frameless_p = 0;
1140 /* Has this frame's registers already been initialized? */
1141 if (deprecated_get_frame_saved_regs (fi))
1144 frame_saved_regs_zalloc (fi);
1148 /* I don't see this ever happening, considering the context in which
1149 cris_frame_init_saved_regs is called (always when we're not in
1151 memcpy (deprecated_get_frame_saved_regs (fi), dummy_regs, SIZEOF_FRAME_SAVED_REGS);
1155 ip = get_frame_func (fi);
1156 sal = find_pc_line (ip, 0);
1158 /* If there is no symbol information then sal.end == 0, and we end up
1159 examining only the first instruction in the function prologue.
1160 Exaggerating the limit seems to be harmless. */
1162 best_limit = sal.end;
1164 best_limit = ip + 100;
1166 cris_examine (ip, best_limit, fi, frameless_p);
1170 /* Initialises the extra frame information at the creation of a new frame.
1171 The inparameter fromleaf is 0 when the call is from create_new_frame.
1172 When the call is from get_prev_frame_info, fromleaf is determined by
1173 cris_frameless_function_invocation. */
1176 cris_init_extra_frame_info (int fromleaf, struct frame_info *fi)
1178 if (get_next_frame (fi))
1180 /* Called from get_prev_frame. */
1181 deprecated_update_frame_pc_hack (fi, DEPRECATED_FRAME_SAVED_PC (get_next_frame (fi)));
1184 frame_extra_info_zalloc (fi, sizeof (struct frame_extra_info));
1186 get_frame_extra_info (fi)->return_pc = 0;
1187 get_frame_extra_info (fi)->leaf_function = 0;
1189 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi),
1190 get_frame_base (fi),
1191 get_frame_base (fi)))
1193 /* We need to setup fi->frame here because call_function_by_hand
1194 gets it wrong by assuming it's always FP. */
1195 deprecated_update_frame_base_hack (fi, deprecated_read_register_dummy (get_frame_pc (fi), get_frame_base (fi), SP_REGNUM));
1196 get_frame_extra_info (fi)->return_pc =
1197 deprecated_read_register_dummy (get_frame_pc (fi),
1198 get_frame_base (fi), PC_REGNUM);
1200 /* FIXME: Is this necessarily true? */
1201 get_frame_extra_info (fi)->leaf_function = 0;
1205 cris_frame_init_saved_regs (fi);
1207 /* Check fromleaf/frameless_function_invocation. (FIXME) */
1209 if (deprecated_get_frame_saved_regs (fi)[SRP_REGNUM] != 0)
1211 /* SRP was saved on the stack; non-leaf function. */
1212 get_frame_extra_info (fi)->return_pc =
1213 read_memory_integer (deprecated_get_frame_saved_regs (fi)[SRP_REGNUM],
1214 DEPRECATED_REGISTER_RAW_SIZE (SRP_REGNUM));
1218 /* SRP is still in a register; leaf function. */
1219 get_frame_extra_info (fi)->return_pc = read_register (SRP_REGNUM);
1220 /* FIXME: Should leaf_function be set to 1 here? */
1221 get_frame_extra_info (fi)->leaf_function = 1;
1226 /* Return the content of the frame pointer in the present frame. In other
1227 words, determine the address of the calling function's frame. */
1230 cris_frame_chain (struct frame_info *fi)
1232 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi),
1233 get_frame_base (fi),
1234 get_frame_base (fi)))
1236 return get_frame_base (fi);
1238 else if (!deprecated_inside_entry_file (get_frame_pc (fi)))
1240 return read_memory_unsigned_integer (get_frame_base (fi), 4);
1248 /* Return the saved PC (which equals the return address) of this frame. */
1251 cris_frame_saved_pc (struct frame_info *fi)
1253 return get_frame_extra_info (fi)->return_pc;
1256 /* Setup the function arguments for calling a function in the inferior. */
1259 cris_abi_original_push_arguments (int nargs, struct value **args,
1260 CORE_ADDR sp, int struct_return,
1261 CORE_ADDR struct_addr)
1272 /* Data and parameters reside in different areas on the stack.
1273 Both frame pointers grow toward higher addresses. */
1274 CORE_ADDR fp_params;
1277 /* Are we returning a value using a structure return or a normal value
1278 return? struct_addr is the address of the reserved space for the return
1279 structure to be written on the stack. */
1282 write_register (STR_REGNUM, struct_addr);
1285 /* Make sure there's space on the stack. Allocate space for data and a
1286 parameter to refer to that data. */
1287 for (argnum = 0, stack_alloc = 0; argnum < nargs; argnum++)
1288 stack_alloc += (TYPE_LENGTH (VALUE_TYPE (args[argnum])) + DEPRECATED_REGISTER_SIZE);
1290 /* We may over-allocate a little here, but that won't hurt anything. */
1292 /* Initialize stack frame pointers. */
1294 fp_data = sp + (nargs * DEPRECATED_REGISTER_SIZE);
1296 /* Now load as many as possible of the first arguments into
1297 registers, and push the rest onto the stack. */
1298 argreg = ARG1_REGNUM;
1301 for (argnum = 0; argnum < nargs; argnum++)
1303 type = VALUE_TYPE (args[argnum]);
1304 len = TYPE_LENGTH (type);
1305 val = (char *) VALUE_CONTENTS (args[argnum]);
1307 if (len <= DEPRECATED_REGISTER_SIZE && argreg <= ARG4_REGNUM)
1309 /* Data fits in a register; put it in the first available
1311 write_register (argreg, *(unsigned long *) val);
1314 else if (len > DEPRECATED_REGISTER_SIZE && argreg <= ARG4_REGNUM)
1316 /* Data does not fit in register; pass it on the stack and
1317 put its address in the first available register. */
1318 write_memory (fp_data, val, len);
1319 write_register (argreg, fp_data);
1323 else if (len > DEPRECATED_REGISTER_SIZE)
1325 /* Data does not fit in register; put both data and
1326 parameter on the stack. */
1327 write_memory (fp_data, val, len);
1328 write_memory (fp_params, (char *) (&fp_data), DEPRECATED_REGISTER_SIZE);
1330 fp_params += DEPRECATED_REGISTER_SIZE;
1334 /* Data fits in a register, but we are out of registers;
1335 put the parameter on the stack. */
1336 write_memory (fp_params, val, DEPRECATED_REGISTER_SIZE);
1337 fp_params += DEPRECATED_REGISTER_SIZE;
1345 cris_abi_v2_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
1346 int struct_return, CORE_ADDR struct_addr)
1355 /* The function's arguments and memory allocated by gdb for the arguments to
1356 point at reside in separate areas on the stack.
1357 Both frame pointers grow toward higher addresses. */
1361 /* Are we returning a value using a structure return or a normal value
1362 return? struct_addr is the address of the reserved space for the return
1363 structure to be written on the stack. */
1366 write_register (STR_REGNUM, struct_addr);
1369 /* Allocate enough to keep things word-aligned on both parts of the
1372 for (argnum = 0; argnum < nargs; argnum++)
1377 len = TYPE_LENGTH (VALUE_TYPE (args[argnum]));
1378 reg_demand = (len / DEPRECATED_REGISTER_SIZE) + (len % DEPRECATED_REGISTER_SIZE != 0 ? 1 : 0);
1380 /* reg_demand * DEPRECATED_REGISTER_SIZE is the amount of memory
1381 we might need to allocate for this argument. 2 *
1382 DEPRECATED_REGISTER_SIZE is the amount of stack space we
1383 might need to pass the argument itself (either by value or by
1385 stack_alloc += (reg_demand * DEPRECATED_REGISTER_SIZE + 2 * DEPRECATED_REGISTER_SIZE);
1388 /* We may over-allocate a little here, but that won't hurt anything. */
1390 /* Initialize frame pointers. */
1392 fp_mem = sp + (nargs * (2 * DEPRECATED_REGISTER_SIZE));
1394 /* Now load as many as possible of the first arguments into registers,
1395 and push the rest onto the stack. */
1396 argreg = ARG1_REGNUM;
1399 for (argnum = 0; argnum < nargs; argnum++)
1406 len = TYPE_LENGTH (VALUE_TYPE (args[argnum]));
1407 val = (char *) VALUE_CONTENTS (args[argnum]);
1409 /* How may registers worth of storage do we need for this argument? */
1410 reg_demand = (len / DEPRECATED_REGISTER_SIZE) + (len % DEPRECATED_REGISTER_SIZE != 0 ? 1 : 0);
1412 if (len <= (2 * DEPRECATED_REGISTER_SIZE)
1413 && (argreg + reg_demand - 1 <= ARG4_REGNUM))
1415 /* Data passed by value. Fits in available register(s). */
1416 for (i = 0; i < reg_demand; i++)
1418 write_register (argreg, *(unsigned long *) val);
1420 val += DEPRECATED_REGISTER_SIZE;
1423 else if (len <= (2 * DEPRECATED_REGISTER_SIZE) && argreg <= ARG4_REGNUM)
1425 /* Data passed by value. Does not fit in available register(s).
1426 Use the register(s) first, then the stack. */
1427 for (i = 0; i < reg_demand; i++)
1429 if (argreg <= ARG4_REGNUM)
1431 write_register (argreg, *(unsigned long *) val);
1433 val += DEPRECATED_REGISTER_SIZE;
1437 /* I guess this memory write could write the
1438 remaining data all at once instead of in
1439 DEPRECATED_REGISTER_SIZE chunks. */
1440 write_memory (fp_arg, val, DEPRECATED_REGISTER_SIZE);
1441 fp_arg += DEPRECATED_REGISTER_SIZE;
1442 val += DEPRECATED_REGISTER_SIZE;
1446 else if (len > (2 * DEPRECATED_REGISTER_SIZE))
1448 /* Data passed by reference. Put it on the stack. */
1449 write_memory (fp_mem, val, len);
1450 write_memory (fp_arg, (char *) (&fp_mem), DEPRECATED_REGISTER_SIZE);
1452 /* fp_mem need not be word-aligned since it's just a chunk of
1453 memory being pointed at. That is, += len would do. */
1454 fp_mem += reg_demand * DEPRECATED_REGISTER_SIZE;
1455 fp_arg += DEPRECATED_REGISTER_SIZE;
1459 /* Data passed by value. No available registers. Put it on
1461 write_memory (fp_arg, val, len);
1463 /* fp_arg must be word-aligned (i.e., don't += len) to match
1464 the function prologue. */
1465 fp_arg += reg_demand * DEPRECATED_REGISTER_SIZE;
1472 /* Never put the return address on the stack. The register SRP is pushed
1473 by the called function unless it is a leaf-function. Due to the BRP
1474 register the PC will change when continue is sent. */
1477 cris_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
1479 write_register (SRP_REGNUM, entry_point_address ());
1483 /* Restore the machine to the state it had before the current frame
1484 was created. Discard the innermost frame from the stack and restore
1485 all saved registers. */
1488 cris_pop_frame (void)
1490 struct frame_info *fi = get_current_frame ();
1492 int stack_offset = 0;
1494 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi),
1495 get_frame_base (fi),
1496 get_frame_base (fi)))
1498 /* This happens when we hit a breakpoint set at the entry point,
1499 when returning from a dummy frame. */
1500 generic_pop_dummy_frame ();
1504 cris_frame_init_saved_regs (fi);
1506 /* For each register, the address of where it was saved on entry to
1507 the frame now lies in fi->saved_regs[regno], or zero if it was not
1508 saved. This includes special registers such as PC and FP saved in
1509 special ways in the stack frame. The SP_REGNUM is even more
1510 special, the address here is the SP for the next frame, not the
1511 address where the SP was saved. */
1513 /* Restore general registers R0 - R7. They were pushed on the stack
1514 after SP was saved. */
1515 for (regno = 0; regno < DEPRECATED_FP_REGNUM; regno++)
1517 if (deprecated_get_frame_saved_regs (fi)[regno])
1519 write_register (regno,
1520 read_memory_integer (deprecated_get_frame_saved_regs (fi)[regno], 4));
1524 if (deprecated_get_frame_saved_regs (fi)[DEPRECATED_FP_REGNUM])
1526 /* Pop the frame pointer (R8). It was pushed before SP
1528 write_register (DEPRECATED_FP_REGNUM,
1529 read_memory_integer (deprecated_get_frame_saved_regs (fi)[DEPRECATED_FP_REGNUM], 4));
1532 /* Not a leaf function. */
1533 if (deprecated_get_frame_saved_regs (fi)[SRP_REGNUM])
1535 /* SRP was pushed before SP was saved. */
1539 /* Restore the SP and adjust for R8 and (possibly) SRP. */
1540 write_register (SP_REGNUM, deprecated_get_frame_saved_regs (fi)[DEPRECATED_FP_REGNUM] + stack_offset);
1544 /* Currently, we can't get the correct info into fi->saved_regs
1545 without a frame pointer. */
1548 /* Restore the PC. */
1549 write_register (PC_REGNUM, get_frame_extra_info (fi)->return_pc);
1551 flush_cached_frames ();
1554 /* Calculates a value that measures how good inst_args constraints an
1555 instruction. It stems from cris_constraint, found in cris-dis.c. */
1558 constraint (unsigned int insn, const signed char *inst_args,
1559 inst_env_type *inst_env)
1564 const char *s = inst_args;
1570 if ((insn & 0x30) == 0x30)
1575 /* A prefix operand. */
1576 if (inst_env->prefix_found)
1582 /* A "push" prefix. (This check was REMOVED by san 970921.) Check for
1583 valid "push" size. In case of special register, it may be != 4. */
1584 if (inst_env->prefix_found)
1590 retval = (((insn >> 0xC) & 0xF) == (insn & 0xF));
1598 tmp = (insn >> 0xC) & 0xF;
1600 for (i = 0; cris_spec_regs[i].name != NULL; i++)
1602 /* Since we match four bits, we will give a value of
1603 4 - 1 = 3 in a match. If there is a corresponding
1604 exact match of a special register in another pattern, it
1605 will get a value of 4, which will be higher. This should
1606 be correct in that an exact pattern would match better that
1608 Note that there is a reason for not returning zero; the
1609 pattern for "clear" is partly matched in the bit-pattern
1610 (the two lower bits must be zero), while the bit-pattern
1611 for a move from a special register is matched in the
1612 register constraint.
1613 This also means we will will have a race condition if
1614 there is a partly match in three bits in the bit pattern. */
1615 if (tmp == cris_spec_regs[i].number)
1622 if (cris_spec_regs[i].name == NULL)
1629 /* Returns the number of bits set in the variable value. */
1632 number_of_bits (unsigned int value)
1634 int number_of_bits = 0;
1638 number_of_bits += 1;
1639 value &= (value - 1);
1641 return number_of_bits;
1644 /* Finds the address that should contain the single step breakpoint(s).
1645 It stems from code in cris-dis.c. */
1648 find_cris_op (unsigned short insn, inst_env_type *inst_env)
1651 int max_level_of_match = -1;
1652 int max_matched = -1;
1655 for (i = 0; cris_opcodes[i].name != NULL; i++)
1657 if (((cris_opcodes[i].match & insn) == cris_opcodes[i].match)
1658 && ((cris_opcodes[i].lose & insn) == 0))
1660 level_of_match = constraint (insn, cris_opcodes[i].args, inst_env);
1661 if (level_of_match >= 0)
1664 number_of_bits (cris_opcodes[i].match | cris_opcodes[i].lose);
1665 if (level_of_match > max_level_of_match)
1668 max_level_of_match = level_of_match;
1669 if (level_of_match == 16)
1671 /* All bits matched, cannot find better. */
1681 /* Attempts to find single-step breakpoints. Returns -1 on failure which is
1682 actually an internal error. */
1685 find_step_target (inst_env_type *inst_env)
1689 unsigned short insn;
1691 /* Create a local register image and set the initial state. */
1692 for (i = 0; i < NUM_GENREGS; i++)
1694 inst_env->reg[i] = (unsigned long) read_register (i);
1696 offset = NUM_GENREGS;
1697 for (i = 0; i < NUM_SPECREGS; i++)
1699 inst_env->preg[i] = (unsigned long) read_register (offset + i);
1701 inst_env->branch_found = 0;
1702 inst_env->slot_needed = 0;
1703 inst_env->delay_slot_pc_active = 0;
1704 inst_env->prefix_found = 0;
1705 inst_env->invalid = 0;
1706 inst_env->xflag_found = 0;
1707 inst_env->disable_interrupt = 0;
1709 /* Look for a step target. */
1712 /* Read an instruction from the client. */
1713 insn = read_memory_unsigned_integer (inst_env->reg[PC_REGNUM], 2);
1715 /* If the instruction is not in a delay slot the new content of the
1716 PC is [PC] + 2. If the instruction is in a delay slot it is not
1717 that simple. Since a instruction in a delay slot cannot change
1718 the content of the PC, it does not matter what value PC will have.
1719 Just make sure it is a valid instruction. */
1720 if (!inst_env->delay_slot_pc_active)
1722 inst_env->reg[PC_REGNUM] += 2;
1726 inst_env->delay_slot_pc_active = 0;
1727 inst_env->reg[PC_REGNUM] = inst_env->delay_slot_pc;
1729 /* Analyse the present instruction. */
1730 i = find_cris_op (insn, inst_env);
1733 inst_env->invalid = 1;
1737 cris_gdb_func (cris_opcodes[i].op, insn, inst_env);
1739 } while (!inst_env->invalid
1740 && (inst_env->prefix_found || inst_env->xflag_found
1741 || inst_env->slot_needed));
1745 /* There is no hardware single-step support. The function find_step_target
1746 digs through the opcodes in order to find all possible targets.
1747 Either one ordinary target or two targets for branches may be found. */
1750 cris_software_single_step (enum target_signal ignore, int insert_breakpoints)
1752 inst_env_type inst_env;
1754 if (insert_breakpoints)
1756 /* Analyse the present instruction environment and insert
1758 int status = find_step_target (&inst_env);
1761 /* Could not find a target. FIXME: Should do something. */
1765 /* Insert at most two breakpoints. One for the next PC content
1766 and possibly another one for a branch, jump, etc. */
1767 next_pc = (CORE_ADDR) inst_env.reg[PC_REGNUM];
1768 target_insert_breakpoint (next_pc, break_mem[0]);
1769 if (inst_env.branch_found
1770 && (CORE_ADDR) inst_env.branch_break_address != next_pc)
1772 branch_target_address =
1773 (CORE_ADDR) inst_env.branch_break_address;
1774 target_insert_breakpoint (branch_target_address, break_mem[1]);
1775 branch_break_inserted = 1;
1781 /* Remove breakpoints. */
1782 target_remove_breakpoint (next_pc, break_mem[0]);
1783 if (branch_break_inserted)
1785 target_remove_breakpoint (branch_target_address, break_mem[1]);
1786 branch_break_inserted = 0;
1791 /* Calculates the prefix value for quick offset addressing mode. */
1794 quick_mode_bdap_prefix (unsigned short inst, inst_env_type *inst_env)
1796 /* It's invalid to be in a delay slot. You can't have a prefix to this
1797 instruction (not 100% sure). */
1798 if (inst_env->slot_needed || inst_env->prefix_found)
1800 inst_env->invalid = 1;
1804 inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)];
1805 inst_env->prefix_value += cris_get_bdap_quick_offset (inst);
1807 /* A prefix doesn't change the xflag_found. But the rest of the flags
1809 inst_env->slot_needed = 0;
1810 inst_env->prefix_found = 1;
1813 /* Updates the autoincrement register. The size of the increment is derived
1814 from the size of the operation. The PC is always kept aligned on even
1818 process_autoincrement (int size, unsigned short inst, inst_env_type *inst_env)
1820 if (size == INST_BYTE_SIZE)
1822 inst_env->reg[cris_get_operand1 (inst)] += 1;
1824 /* The PC must be word aligned, so increase the PC with one
1825 word even if the size is byte. */
1826 if (cris_get_operand1 (inst) == REG_PC)
1828 inst_env->reg[REG_PC] += 1;
1831 else if (size == INST_WORD_SIZE)
1833 inst_env->reg[cris_get_operand1 (inst)] += 2;
1835 else if (size == INST_DWORD_SIZE)
1837 inst_env->reg[cris_get_operand1 (inst)] += 4;
1842 inst_env->invalid = 1;
1846 /* Just a forward declaration. */
1848 static unsigned long get_data_from_address (unsigned short *inst,
1851 /* Calculates the prefix value for the general case of offset addressing
1855 bdap_prefix (unsigned short inst, inst_env_type *inst_env)
1860 /* It's invalid to be in a delay slot. */
1861 if (inst_env->slot_needed || inst_env->prefix_found)
1863 inst_env->invalid = 1;
1867 /* The calculation of prefix_value used to be after process_autoincrement,
1868 but that fails for an instruction such as jsr [$r0+12] which is encoded
1869 as 5f0d 0c00 30b9 when compiled with -fpic. Since PC is operand1 it
1870 mustn't be incremented until we have read it and what it points at. */
1871 inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)];
1873 /* The offset is an indirection of the contents of the operand1 register. */
1874 inst_env->prefix_value +=
1875 get_data_from_address (&inst, inst_env->reg[cris_get_operand1 (inst)]);
1877 if (cris_get_mode (inst) == AUTOINC_MODE)
1879 process_autoincrement (cris_get_size (inst), inst, inst_env);
1882 /* A prefix doesn't change the xflag_found. But the rest of the flags
1884 inst_env->slot_needed = 0;
1885 inst_env->prefix_found = 1;
1888 /* Calculates the prefix value for the index addressing mode. */
1891 biap_prefix (unsigned short inst, inst_env_type *inst_env)
1893 /* It's invalid to be in a delay slot. I can't see that it's possible to
1894 have a prefix to this instruction. So I will treat this as invalid. */
1895 if (inst_env->slot_needed || inst_env->prefix_found)
1897 inst_env->invalid = 1;
1901 inst_env->prefix_value = inst_env->reg[cris_get_operand1 (inst)];
1903 /* The offset is the operand2 value shifted the size of the instruction
1905 inst_env->prefix_value +=
1906 inst_env->reg[cris_get_operand2 (inst)] << cris_get_size (inst);
1908 /* If the PC is operand1 (base) the address used is the address after
1909 the main instruction, i.e. address + 2 (the PC is already compensated
1910 for the prefix operation). */
1911 if (cris_get_operand1 (inst) == REG_PC)
1913 inst_env->prefix_value += 2;
1916 /* A prefix doesn't change the xflag_found. But the rest of the flags
1918 inst_env->slot_needed = 0;
1919 inst_env->xflag_found = 0;
1920 inst_env->prefix_found = 1;
1923 /* Calculates the prefix value for the double indirect addressing mode. */
1926 dip_prefix (unsigned short inst, inst_env_type *inst_env)
1931 /* It's invalid to be in a delay slot. */
1932 if (inst_env->slot_needed || inst_env->prefix_found)
1934 inst_env->invalid = 1;
1938 /* The prefix value is one dereference of the contents of the operand1
1940 address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)];
1941 inst_env->prefix_value = read_memory_unsigned_integer (address, 4);
1943 /* Check if the mode is autoincrement. */
1944 if (cris_get_mode (inst) == AUTOINC_MODE)
1946 inst_env->reg[cris_get_operand1 (inst)] += 4;
1949 /* A prefix doesn't change the xflag_found. But the rest of the flags
1951 inst_env->slot_needed = 0;
1952 inst_env->xflag_found = 0;
1953 inst_env->prefix_found = 1;
1956 /* Finds the destination for a branch with 8-bits offset. */
1959 eight_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env)
1964 /* If we have a prefix or are in a delay slot it's bad. */
1965 if (inst_env->slot_needed || inst_env->prefix_found)
1967 inst_env->invalid = 1;
1971 /* We have a branch, find out where the branch will land. */
1972 offset = cris_get_branch_short_offset (inst);
1974 /* Check if the offset is signed. */
1975 if (offset & BRANCH_SIGNED_SHORT_OFFSET_MASK)
1980 /* The offset ends with the sign bit, set it to zero. The address
1981 should always be word aligned. */
1982 offset &= ~BRANCH_SIGNED_SHORT_OFFSET_MASK;
1984 inst_env->branch_found = 1;
1985 inst_env->branch_break_address = inst_env->reg[REG_PC] + offset;
1987 inst_env->slot_needed = 1;
1988 inst_env->prefix_found = 0;
1989 inst_env->xflag_found = 0;
1990 inst_env->disable_interrupt = 1;
1993 /* Finds the destination for a branch with 16-bits offset. */
1996 sixteen_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env)
2000 /* If we have a prefix or is in a delay slot it's bad. */
2001 if (inst_env->slot_needed || inst_env->prefix_found)
2003 inst_env->invalid = 1;
2007 /* We have a branch, find out the offset for the branch. */
2008 offset = read_memory_integer (inst_env->reg[REG_PC], 2);
2010 /* The instruction is one word longer than normal, so add one word
2012 inst_env->reg[REG_PC] += 2;
2014 inst_env->branch_found = 1;
2015 inst_env->branch_break_address = inst_env->reg[REG_PC] + offset;
2018 inst_env->slot_needed = 1;
2019 inst_env->prefix_found = 0;
2020 inst_env->xflag_found = 0;
2021 inst_env->disable_interrupt = 1;
2024 /* Handles the ABS instruction. */
2027 abs_op (unsigned short inst, inst_env_type *inst_env)
2032 /* ABS can't have a prefix, so it's bad if it does. */
2033 if (inst_env->prefix_found)
2035 inst_env->invalid = 1;
2039 /* Check if the operation affects the PC. */
2040 if (cris_get_operand2 (inst) == REG_PC)
2043 /* It's invalid to change to the PC if we are in a delay slot. */
2044 if (inst_env->slot_needed)
2046 inst_env->invalid = 1;
2050 value = (long) inst_env->reg[REG_PC];
2052 /* The value of abs (SIGNED_DWORD_MASK) is SIGNED_DWORD_MASK. */
2053 if (value != SIGNED_DWORD_MASK)
2056 inst_env->reg[REG_PC] = (long) value;
2060 inst_env->slot_needed = 0;
2061 inst_env->prefix_found = 0;
2062 inst_env->xflag_found = 0;
2063 inst_env->disable_interrupt = 0;
2066 /* Handles the ADDI instruction. */
2069 addi_op (unsigned short inst, inst_env_type *inst_env)
2071 /* It's invalid to have the PC as base register. And ADDI can't have
2073 if (inst_env->prefix_found || (cris_get_operand1 (inst) == REG_PC))
2075 inst_env->invalid = 1;
2079 inst_env->slot_needed = 0;
2080 inst_env->prefix_found = 0;
2081 inst_env->xflag_found = 0;
2082 inst_env->disable_interrupt = 0;
2085 /* Handles the ASR instruction. */
2088 asr_op (unsigned short inst, inst_env_type *inst_env)
2091 unsigned long value;
2092 unsigned long signed_extend_mask = 0;
2094 /* ASR can't have a prefix, so check that it doesn't. */
2095 if (inst_env->prefix_found)
2097 inst_env->invalid = 1;
2101 /* Check if the PC is the target register. */
2102 if (cris_get_operand2 (inst) == REG_PC)
2104 /* It's invalid to change the PC in a delay slot. */
2105 if (inst_env->slot_needed)
2107 inst_env->invalid = 1;
2110 /* Get the number of bits to shift. */
2111 shift_steps = cris_get_asr_shift_steps (inst_env->reg[cris_get_operand1 (inst)]);
2112 value = inst_env->reg[REG_PC];
2114 /* Find out how many bits the operation should apply to. */
2115 if (cris_get_size (inst) == INST_BYTE_SIZE)
2117 if (value & SIGNED_BYTE_MASK)
2119 signed_extend_mask = 0xFF;
2120 signed_extend_mask = signed_extend_mask >> shift_steps;
2121 signed_extend_mask = ~signed_extend_mask;
2123 value = value >> shift_steps;
2124 value |= signed_extend_mask;
2126 inst_env->reg[REG_PC] &= 0xFFFFFF00;
2127 inst_env->reg[REG_PC] |= value;
2129 else if (cris_get_size (inst) == INST_WORD_SIZE)
2131 if (value & SIGNED_WORD_MASK)
2133 signed_extend_mask = 0xFFFF;
2134 signed_extend_mask = signed_extend_mask >> shift_steps;
2135 signed_extend_mask = ~signed_extend_mask;
2137 value = value >> shift_steps;
2138 value |= signed_extend_mask;
2140 inst_env->reg[REG_PC] &= 0xFFFF0000;
2141 inst_env->reg[REG_PC] |= value;
2143 else if (cris_get_size (inst) == INST_DWORD_SIZE)
2145 if (value & SIGNED_DWORD_MASK)
2147 signed_extend_mask = 0xFFFFFFFF;
2148 signed_extend_mask = signed_extend_mask >> shift_steps;
2149 signed_extend_mask = ~signed_extend_mask;
2151 value = value >> shift_steps;
2152 value |= signed_extend_mask;
2153 inst_env->reg[REG_PC] = value;
2156 inst_env->slot_needed = 0;
2157 inst_env->prefix_found = 0;
2158 inst_env->xflag_found = 0;
2159 inst_env->disable_interrupt = 0;
2162 /* Handles the ASRQ instruction. */
2165 asrq_op (unsigned short inst, inst_env_type *inst_env)
2169 unsigned long value;
2170 unsigned long signed_extend_mask = 0;
2172 /* ASRQ can't have a prefix, so check that it doesn't. */
2173 if (inst_env->prefix_found)
2175 inst_env->invalid = 1;
2179 /* Check if the PC is the target register. */
2180 if (cris_get_operand2 (inst) == REG_PC)
2183 /* It's invalid to change the PC in a delay slot. */
2184 if (inst_env->slot_needed)
2186 inst_env->invalid = 1;
2189 /* The shift size is given as a 5 bit quick value, i.e. we don't
2190 want the the sign bit of the quick value. */
2191 shift_steps = cris_get_asr_shift_steps (inst);
2192 value = inst_env->reg[REG_PC];
2193 if (value & SIGNED_DWORD_MASK)
2195 signed_extend_mask = 0xFFFFFFFF;
2196 signed_extend_mask = signed_extend_mask >> shift_steps;
2197 signed_extend_mask = ~signed_extend_mask;
2199 value = value >> shift_steps;
2200 value |= signed_extend_mask;
2201 inst_env->reg[REG_PC] = value;
2203 inst_env->slot_needed = 0;
2204 inst_env->prefix_found = 0;
2205 inst_env->xflag_found = 0;
2206 inst_env->disable_interrupt = 0;
2209 /* Handles the AX, EI and SETF instruction. */
2212 ax_ei_setf_op (unsigned short inst, inst_env_type *inst_env)
2214 if (inst_env->prefix_found)
2216 inst_env->invalid = 1;
2219 /* Check if the instruction is setting the X flag. */
2220 if (cris_is_xflag_bit_on (inst))
2222 inst_env->xflag_found = 1;
2226 inst_env->xflag_found = 0;
2228 inst_env->slot_needed = 0;
2229 inst_env->prefix_found = 0;
2230 inst_env->disable_interrupt = 1;
2233 /* Checks if the instruction is in assign mode. If so, it updates the assign
2234 register. Note that check_assign assumes that the caller has checked that
2235 there is a prefix to this instruction. The mode check depends on this. */
2238 check_assign (unsigned short inst, inst_env_type *inst_env)
2240 /* Check if it's an assign addressing mode. */
2241 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2243 /* Assign the prefix value to operand 1. */
2244 inst_env->reg[cris_get_operand1 (inst)] = inst_env->prefix_value;
2248 /* Handles the 2-operand BOUND instruction. */
2251 two_operand_bound_op (unsigned short inst, inst_env_type *inst_env)
2253 /* It's invalid to have the PC as the index operand. */
2254 if (cris_get_operand2 (inst) == REG_PC)
2256 inst_env->invalid = 1;
2259 /* Check if we have a prefix. */
2260 if (inst_env->prefix_found)
2262 check_assign (inst, inst_env);
2264 /* Check if this is an autoincrement mode. */
2265 else if (cris_get_mode (inst) == AUTOINC_MODE)
2267 /* It's invalid to change the PC in a delay slot. */
2268 if (inst_env->slot_needed)
2270 inst_env->invalid = 1;
2273 process_autoincrement (cris_get_size (inst), inst, inst_env);
2275 inst_env->slot_needed = 0;
2276 inst_env->prefix_found = 0;
2277 inst_env->xflag_found = 0;
2278 inst_env->disable_interrupt = 0;
2281 /* Handles the 3-operand BOUND instruction. */
2284 three_operand_bound_op (unsigned short inst, inst_env_type *inst_env)
2286 /* It's an error if we haven't got a prefix. And it's also an error
2287 if the PC is the destination register. */
2288 if ((!inst_env->prefix_found) || (cris_get_operand1 (inst) == REG_PC))
2290 inst_env->invalid = 1;
2293 inst_env->slot_needed = 0;
2294 inst_env->prefix_found = 0;
2295 inst_env->xflag_found = 0;
2296 inst_env->disable_interrupt = 0;
2299 /* Clears the status flags in inst_env. */
2302 btst_nop_op (unsigned short inst, inst_env_type *inst_env)
2304 /* It's an error if we have got a prefix. */
2305 if (inst_env->prefix_found)
2307 inst_env->invalid = 1;
2311 inst_env->slot_needed = 0;
2312 inst_env->prefix_found = 0;
2313 inst_env->xflag_found = 0;
2314 inst_env->disable_interrupt = 0;
2317 /* Clears the status flags in inst_env. */
2320 clearf_di_op (unsigned short inst, inst_env_type *inst_env)
2322 /* It's an error if we have got a prefix. */
2323 if (inst_env->prefix_found)
2325 inst_env->invalid = 1;
2329 inst_env->slot_needed = 0;
2330 inst_env->prefix_found = 0;
2331 inst_env->xflag_found = 0;
2332 inst_env->disable_interrupt = 1;
2335 /* Handles the CLEAR instruction if it's in register mode. */
2338 reg_mode_clear_op (unsigned short inst, inst_env_type *inst_env)
2340 /* Check if the target is the PC. */
2341 if (cris_get_operand2 (inst) == REG_PC)
2343 /* The instruction will clear the instruction's size bits. */
2344 int clear_size = cris_get_clear_size (inst);
2345 if (clear_size == INST_BYTE_SIZE)
2347 inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFFFF00;
2349 if (clear_size == INST_WORD_SIZE)
2351 inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFF0000;
2353 if (clear_size == INST_DWORD_SIZE)
2355 inst_env->delay_slot_pc = 0x0;
2357 /* The jump will be delayed with one delay slot. So we need a delay
2359 inst_env->slot_needed = 1;
2360 inst_env->delay_slot_pc_active = 1;
2364 /* The PC will not change => no delay slot. */
2365 inst_env->slot_needed = 0;
2367 inst_env->prefix_found = 0;
2368 inst_env->xflag_found = 0;
2369 inst_env->disable_interrupt = 0;
2372 /* Handles the TEST instruction if it's in register mode. */
2375 reg_mode_test_op (unsigned short inst, inst_env_type *inst_env)
2377 /* It's an error if we have got a prefix. */
2378 if (inst_env->prefix_found)
2380 inst_env->invalid = 1;
2383 inst_env->slot_needed = 0;
2384 inst_env->prefix_found = 0;
2385 inst_env->xflag_found = 0;
2386 inst_env->disable_interrupt = 0;
2390 /* Handles the CLEAR and TEST instruction if the instruction isn't
2391 in register mode. */
2394 none_reg_mode_clear_test_op (unsigned short inst, inst_env_type *inst_env)
2396 /* Check if we are in a prefix mode. */
2397 if (inst_env->prefix_found)
2399 /* The only way the PC can change is if this instruction is in
2400 assign addressing mode. */
2401 check_assign (inst, inst_env);
2403 /* Indirect mode can't change the PC so just check if the mode is
2405 else if (cris_get_mode (inst) == AUTOINC_MODE)
2407 process_autoincrement (cris_get_size (inst), inst, inst_env);
2409 inst_env->slot_needed = 0;
2410 inst_env->prefix_found = 0;
2411 inst_env->xflag_found = 0;
2412 inst_env->disable_interrupt = 0;
2415 /* Checks that the PC isn't the destination register or the instructions has
2419 dstep_logshift_mstep_neg_not_op (unsigned short inst, inst_env_type *inst_env)
2421 /* It's invalid to have the PC as the destination. The instruction can't
2423 if ((cris_get_operand2 (inst) == REG_PC) || inst_env->prefix_found)
2425 inst_env->invalid = 1;
2429 inst_env->slot_needed = 0;
2430 inst_env->prefix_found = 0;
2431 inst_env->xflag_found = 0;
2432 inst_env->disable_interrupt = 0;
2435 /* Checks that the instruction doesn't have a prefix. */
2438 break_op (unsigned short inst, inst_env_type *inst_env)
2440 /* The instruction can't have a prefix. */
2441 if (inst_env->prefix_found)
2443 inst_env->invalid = 1;
2447 inst_env->slot_needed = 0;
2448 inst_env->prefix_found = 0;
2449 inst_env->xflag_found = 0;
2450 inst_env->disable_interrupt = 1;
2453 /* Checks that the PC isn't the destination register and that the instruction
2454 doesn't have a prefix. */
2457 scc_op (unsigned short inst, inst_env_type *inst_env)
2459 /* It's invalid to have the PC as the destination. The instruction can't
2461 if ((cris_get_operand2 (inst) == REG_PC) || inst_env->prefix_found)
2463 inst_env->invalid = 1;
2467 inst_env->slot_needed = 0;
2468 inst_env->prefix_found = 0;
2469 inst_env->xflag_found = 0;
2470 inst_env->disable_interrupt = 1;
2473 /* Handles the register mode JUMP instruction. */
2476 reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env)
2478 /* It's invalid to do a JUMP in a delay slot. The mode is register, so
2479 you can't have a prefix. */
2480 if ((inst_env->slot_needed) || (inst_env->prefix_found))
2482 inst_env->invalid = 1;
2486 /* Just change the PC. */
2487 inst_env->reg[REG_PC] = inst_env->reg[cris_get_operand1 (inst)];
2488 inst_env->slot_needed = 0;
2489 inst_env->prefix_found = 0;
2490 inst_env->xflag_found = 0;
2491 inst_env->disable_interrupt = 1;
2494 /* Handles the JUMP instruction for all modes except register. */
2497 none_reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env)
2499 unsigned long newpc;
2502 /* It's invalid to do a JUMP in a delay slot. */
2503 if (inst_env->slot_needed)
2505 inst_env->invalid = 1;
2509 /* Check if we have a prefix. */
2510 if (inst_env->prefix_found)
2512 check_assign (inst, inst_env);
2514 /* Get the new value for the the PC. */
2516 read_memory_unsigned_integer ((CORE_ADDR) inst_env->prefix_value,
2521 /* Get the new value for the PC. */
2522 address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)];
2523 newpc = read_memory_unsigned_integer (address, 4);
2525 /* Check if we should increment a register. */
2526 if (cris_get_mode (inst) == AUTOINC_MODE)
2528 inst_env->reg[cris_get_operand1 (inst)] += 4;
2531 inst_env->reg[REG_PC] = newpc;
2533 inst_env->slot_needed = 0;
2534 inst_env->prefix_found = 0;
2535 inst_env->xflag_found = 0;
2536 inst_env->disable_interrupt = 1;
2539 /* Handles moves to special registers (aka P-register) for all modes. */
2542 move_to_preg_op (unsigned short inst, inst_env_type *inst_env)
2544 if (inst_env->prefix_found)
2546 /* The instruction has a prefix that means we are only interested if
2547 the instruction is in assign mode. */
2548 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2550 /* The prefix handles the problem if we are in a delay slot. */
2551 if (cris_get_operand1 (inst) == REG_PC)
2553 /* Just take care of the assign. */
2554 check_assign (inst, inst_env);
2558 else if (cris_get_mode (inst) == AUTOINC_MODE)
2560 /* The instruction doesn't have a prefix, the only case left that we
2561 are interested in is the autoincrement mode. */
2562 if (cris_get_operand1 (inst) == REG_PC)
2564 /* If the PC is to be incremented it's invalid to be in a
2566 if (inst_env->slot_needed)
2568 inst_env->invalid = 1;
2572 /* The increment depends on the size of the special register. */
2573 if (cris_register_size (cris_get_operand2 (inst)) == 1)
2575 process_autoincrement (INST_BYTE_SIZE, inst, inst_env);
2577 else if (cris_register_size (cris_get_operand2 (inst)) == 2)
2579 process_autoincrement (INST_WORD_SIZE, inst, inst_env);
2583 process_autoincrement (INST_DWORD_SIZE, inst, inst_env);
2587 inst_env->slot_needed = 0;
2588 inst_env->prefix_found = 0;
2589 inst_env->xflag_found = 0;
2590 inst_env->disable_interrupt = 1;
2593 /* Handles moves from special registers (aka P-register) for all modes
2597 none_reg_mode_move_from_preg_op (unsigned short inst, inst_env_type *inst_env)
2599 if (inst_env->prefix_found)
2601 /* The instruction has a prefix that means we are only interested if
2602 the instruction is in assign mode. */
2603 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2605 /* The prefix handles the problem if we are in a delay slot. */
2606 if (cris_get_operand1 (inst) == REG_PC)
2608 /* Just take care of the assign. */
2609 check_assign (inst, inst_env);
2613 /* The instruction doesn't have a prefix, the only case left that we
2614 are interested in is the autoincrement mode. */
2615 else if (cris_get_mode (inst) == AUTOINC_MODE)
2617 if (cris_get_operand1 (inst) == REG_PC)
2619 /* If the PC is to be incremented it's invalid to be in a
2621 if (inst_env->slot_needed)
2623 inst_env->invalid = 1;
2627 /* The increment depends on the size of the special register. */
2628 if (cris_register_size (cris_get_operand2 (inst)) == 1)
2630 process_autoincrement (INST_BYTE_SIZE, inst, inst_env);
2632 else if (cris_register_size (cris_get_operand2 (inst)) == 2)
2634 process_autoincrement (INST_WORD_SIZE, inst, inst_env);
2638 process_autoincrement (INST_DWORD_SIZE, inst, inst_env);
2642 inst_env->slot_needed = 0;
2643 inst_env->prefix_found = 0;
2644 inst_env->xflag_found = 0;
2645 inst_env->disable_interrupt = 1;
2648 /* Handles moves from special registers (aka P-register) when the mode
2652 reg_mode_move_from_preg_op (unsigned short inst, inst_env_type *inst_env)
2654 /* Register mode move from special register can't have a prefix. */
2655 if (inst_env->prefix_found)
2657 inst_env->invalid = 1;
2661 if (cris_get_operand1 (inst) == REG_PC)
2663 /* It's invalid to change the PC in a delay slot. */
2664 if (inst_env->slot_needed)
2666 inst_env->invalid = 1;
2669 /* The destination is the PC, the jump will have a delay slot. */
2670 inst_env->delay_slot_pc = inst_env->preg[cris_get_operand2 (inst)];
2671 inst_env->slot_needed = 1;
2672 inst_env->delay_slot_pc_active = 1;
2676 /* If the destination isn't PC, there will be no jump. */
2677 inst_env->slot_needed = 0;
2679 inst_env->prefix_found = 0;
2680 inst_env->xflag_found = 0;
2681 inst_env->disable_interrupt = 1;
2684 /* Handles the MOVEM from memory to general register instruction. */
2687 move_mem_to_reg_movem_op (unsigned short inst, inst_env_type *inst_env)
2689 if (inst_env->prefix_found)
2691 /* The prefix handles the problem if we are in a delay slot. Is the
2692 MOVEM instruction going to change the PC? */
2693 if (cris_get_operand2 (inst) >= REG_PC)
2695 inst_env->reg[REG_PC] =
2696 read_memory_unsigned_integer (inst_env->prefix_value, 4);
2698 /* The assign value is the value after the increment. Normally, the
2699 assign value is the value before the increment. */
2700 if ((cris_get_operand1 (inst) == REG_PC)
2701 && (cris_get_mode (inst) == PREFIX_ASSIGN_MODE))
2703 inst_env->reg[REG_PC] = inst_env->prefix_value;
2704 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
2709 /* Is the MOVEM instruction going to change the PC? */
2710 if (cris_get_operand2 (inst) == REG_PC)
2712 /* It's invalid to change the PC in a delay slot. */
2713 if (inst_env->slot_needed)
2715 inst_env->invalid = 1;
2718 inst_env->reg[REG_PC] =
2719 read_memory_unsigned_integer (inst_env->reg[cris_get_operand1 (inst)],
2722 /* The increment is not depending on the size, instead it's depending
2723 on the number of registers loaded from memory. */
2724 if ((cris_get_operand1 (inst) == REG_PC) && (cris_get_mode (inst) == AUTOINC_MODE))
2726 /* It's invalid to change the PC in a delay slot. */
2727 if (inst_env->slot_needed)
2729 inst_env->invalid = 1;
2732 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
2735 inst_env->slot_needed = 0;
2736 inst_env->prefix_found = 0;
2737 inst_env->xflag_found = 0;
2738 inst_env->disable_interrupt = 0;
2741 /* Handles the MOVEM to memory from general register instruction. */
2744 move_reg_to_mem_movem_op (unsigned short inst, inst_env_type *inst_env)
2746 if (inst_env->prefix_found)
2748 /* The assign value is the value after the increment. Normally, the
2749 assign value is the value before the increment. */
2750 if ((cris_get_operand1 (inst) == REG_PC) &&
2751 (cris_get_mode (inst) == PREFIX_ASSIGN_MODE))
2753 /* The prefix handles the problem if we are in a delay slot. */
2754 inst_env->reg[REG_PC] = inst_env->prefix_value;
2755 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
2760 /* The increment is not depending on the size, instead it's depending
2761 on the number of registers loaded to memory. */
2762 if ((cris_get_operand1 (inst) == REG_PC) && (cris_get_mode (inst) == AUTOINC_MODE))
2764 /* It's invalid to change the PC in a delay slot. */
2765 if (inst_env->slot_needed)
2767 inst_env->invalid = 1;
2770 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
2773 inst_env->slot_needed = 0;
2774 inst_env->prefix_found = 0;
2775 inst_env->xflag_found = 0;
2776 inst_env->disable_interrupt = 0;
2779 /* Handles the pop instruction to a general register.
2780 POP is a assembler macro for MOVE.D [SP+], Rd. */
2783 reg_pop_op (unsigned short inst, inst_env_type *inst_env)
2785 /* POP can't have a prefix. */
2786 if (inst_env->prefix_found)
2788 inst_env->invalid = 1;
2791 if (cris_get_operand2 (inst) == REG_PC)
2793 /* It's invalid to change the PC in a delay slot. */
2794 if (inst_env->slot_needed)
2796 inst_env->invalid = 1;
2799 inst_env->reg[REG_PC] =
2800 read_memory_unsigned_integer (inst_env->reg[REG_SP], 4);
2802 inst_env->slot_needed = 0;
2803 inst_env->prefix_found = 0;
2804 inst_env->xflag_found = 0;
2805 inst_env->disable_interrupt = 0;
2808 /* Handles moves from register to memory. */
2811 move_reg_to_mem_index_inc_op (unsigned short inst, inst_env_type *inst_env)
2813 /* Check if we have a prefix. */
2814 if (inst_env->prefix_found)
2816 /* The only thing that can change the PC is an assign. */
2817 check_assign (inst, inst_env);
2819 else if ((cris_get_operand1 (inst) == REG_PC)
2820 && (cris_get_mode (inst) == AUTOINC_MODE))
2822 /* It's invalid to change the PC in a delay slot. */
2823 if (inst_env->slot_needed)
2825 inst_env->invalid = 1;
2828 process_autoincrement (cris_get_size (inst), inst, inst_env);
2830 inst_env->slot_needed = 0;
2831 inst_env->prefix_found = 0;
2832 inst_env->xflag_found = 0;
2833 inst_env->disable_interrupt = 0;
2836 /* Handles the intructions that's not yet implemented, by setting
2837 inst_env->invalid to true. */
2840 not_implemented_op (unsigned short inst, inst_env_type *inst_env)
2842 inst_env->invalid = 1;
2845 /* Handles the XOR instruction. */
2848 xor_op (unsigned short inst, inst_env_type *inst_env)
2850 /* XOR can't have a prefix. */
2851 if (inst_env->prefix_found)
2853 inst_env->invalid = 1;
2857 /* Check if the PC is the target. */
2858 if (cris_get_operand2 (inst) == REG_PC)
2860 /* It's invalid to change the PC in a delay slot. */
2861 if (inst_env->slot_needed)
2863 inst_env->invalid = 1;
2866 inst_env->reg[REG_PC] ^= inst_env->reg[cris_get_operand1 (inst)];
2868 inst_env->slot_needed = 0;
2869 inst_env->prefix_found = 0;
2870 inst_env->xflag_found = 0;
2871 inst_env->disable_interrupt = 0;
2874 /* Handles the MULS instruction. */
2877 muls_op (unsigned short inst, inst_env_type *inst_env)
2879 /* MULS/U can't have a prefix. */
2880 if (inst_env->prefix_found)
2882 inst_env->invalid = 1;
2886 /* Consider it invalid if the PC is the target. */
2887 if (cris_get_operand2 (inst) == REG_PC)
2889 inst_env->invalid = 1;
2892 inst_env->slot_needed = 0;
2893 inst_env->prefix_found = 0;
2894 inst_env->xflag_found = 0;
2895 inst_env->disable_interrupt = 0;
2898 /* Handles the MULU instruction. */
2901 mulu_op (unsigned short inst, inst_env_type *inst_env)
2903 /* MULS/U can't have a prefix. */
2904 if (inst_env->prefix_found)
2906 inst_env->invalid = 1;
2910 /* Consider it invalid if the PC is the target. */
2911 if (cris_get_operand2 (inst) == REG_PC)
2913 inst_env->invalid = 1;
2916 inst_env->slot_needed = 0;
2917 inst_env->prefix_found = 0;
2918 inst_env->xflag_found = 0;
2919 inst_env->disable_interrupt = 0;
2922 /* Calculate the result of the instruction for ADD, SUB, CMP AND, OR and MOVE.
2923 The MOVE instruction is the move from source to register. */
2926 add_sub_cmp_and_or_move_action (unsigned short inst, inst_env_type *inst_env,
2927 unsigned long source1, unsigned long source2)
2929 unsigned long pc_mask;
2930 unsigned long operation_mask;
2932 /* Find out how many bits the operation should apply to. */
2933 if (cris_get_size (inst) == INST_BYTE_SIZE)
2935 pc_mask = 0xFFFFFF00;
2936 operation_mask = 0xFF;
2938 else if (cris_get_size (inst) == INST_WORD_SIZE)
2940 pc_mask = 0xFFFF0000;
2941 operation_mask = 0xFFFF;
2943 else if (cris_get_size (inst) == INST_DWORD_SIZE)
2946 operation_mask = 0xFFFFFFFF;
2950 /* The size is out of range. */
2951 inst_env->invalid = 1;
2955 /* The instruction just works on uw_operation_mask bits. */
2956 source2 &= operation_mask;
2957 source1 &= operation_mask;
2959 /* Now calculate the result. The opcode's 3 first bits separates
2960 the different actions. */
2961 switch (cris_get_opcode (inst) & 7)
2971 case 2: /* subtract */
2975 case 3: /* compare */
2987 inst_env->invalid = 1;
2993 /* Make sure that the result doesn't contain more than the instruction
2995 source2 &= operation_mask;
2997 /* Calculate the new breakpoint address. */
2998 inst_env->reg[REG_PC] &= pc_mask;
2999 inst_env->reg[REG_PC] |= source1;
3003 /* Extends the value from either byte or word size to a dword. If the mode
3004 is zero extend then the value is extended with zero. If instead the mode
3005 is signed extend the sign bit of the value is taken into consideration. */
3007 static unsigned long
3008 do_sign_or_zero_extend (unsigned long value, unsigned short *inst)
3010 /* The size can be either byte or word, check which one it is.
3011 Don't check the highest bit, it's indicating if it's a zero
3013 if (cris_get_size (*inst) & INST_WORD_SIZE)
3018 /* Check if the instruction is signed extend. If so, check if value has
3020 if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_WORD_MASK))
3022 value |= SIGNED_WORD_EXTEND_MASK;
3030 /* Check if the instruction is signed extend. If so, check if value has
3032 if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_BYTE_MASK))
3034 value |= SIGNED_BYTE_EXTEND_MASK;
3037 /* The size should now be dword. */
3038 cris_set_size_to_dword (inst);
3042 /* Handles the register mode for the ADD, SUB, CMP, AND, OR and MOVE
3043 instruction. The MOVE instruction is the move from source to register. */
3046 reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst,
3047 inst_env_type *inst_env)
3049 unsigned long operand1;
3050 unsigned long operand2;
3052 /* It's invalid to have a prefix to the instruction. This is a register
3053 mode instruction and can't have a prefix. */
3054 if (inst_env->prefix_found)
3056 inst_env->invalid = 1;
3059 /* Check if the instruction has PC as its target. */
3060 if (cris_get_operand2 (inst) == REG_PC)
3062 if (inst_env->slot_needed)
3064 inst_env->invalid = 1;
3067 /* The instruction has the PC as its target register. */
3068 operand1 = inst_env->reg[cris_get_operand1 (inst)];
3069 operand2 = inst_env->reg[REG_PC];
3071 /* Check if it's a extend, signed or zero instruction. */
3072 if (cris_get_opcode (inst) < 4)
3074 operand1 = do_sign_or_zero_extend (operand1, &inst);
3076 /* Calculate the PC value after the instruction, i.e. where the
3077 breakpoint should be. The order of the udw_operands is vital. */
3078 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3080 inst_env->slot_needed = 0;
3081 inst_env->prefix_found = 0;
3082 inst_env->xflag_found = 0;
3083 inst_env->disable_interrupt = 0;
3086 /* Returns the data contained at address. The size of the data is derived from
3087 the size of the operation. If the instruction is a zero or signed
3088 extend instruction, the size field is changed in instruction. */
3090 static unsigned long
3091 get_data_from_address (unsigned short *inst, CORE_ADDR address)
3093 int size = cris_get_size (*inst);
3094 unsigned long value;
3096 /* If it's an extend instruction we don't want the signed extend bit,
3097 because it influences the size. */
3098 if (cris_get_opcode (*inst) < 4)
3100 size &= ~SIGNED_EXTEND_BIT_MASK;
3102 /* Is there a need for checking the size? Size should contain the number of
3105 value = read_memory_unsigned_integer (address, size);
3107 /* Check if it's an extend, signed or zero instruction. */
3108 if (cris_get_opcode (*inst) < 4)
3110 value = do_sign_or_zero_extend (value, inst);
3115 /* Handles the assign addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
3116 instructions. The MOVE instruction is the move from source to register. */
3119 handle_prefix_assign_mode_for_aritm_op (unsigned short inst,
3120 inst_env_type *inst_env)
3122 unsigned long operand2;
3123 unsigned long operand3;
3125 check_assign (inst, inst_env);
3126 if (cris_get_operand2 (inst) == REG_PC)
3128 operand2 = inst_env->reg[REG_PC];
3130 /* Get the value of the third operand. */
3131 operand3 = get_data_from_address (&inst, inst_env->prefix_value);
3133 /* Calculate the PC value after the instruction, i.e. where the
3134 breakpoint should be. The order of the udw_operands is vital. */
3135 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3137 inst_env->slot_needed = 0;
3138 inst_env->prefix_found = 0;
3139 inst_env->xflag_found = 0;
3140 inst_env->disable_interrupt = 0;
3143 /* Handles the three-operand addressing mode for the ADD, SUB, CMP, AND and
3144 OR instructions. Note that for this to work as expected, the calling
3145 function must have made sure that there is a prefix to this instruction. */
3148 three_operand_add_sub_cmp_and_or_op (unsigned short inst,
3149 inst_env_type *inst_env)
3151 unsigned long operand2;
3152 unsigned long operand3;
3154 if (cris_get_operand1 (inst) == REG_PC)
3156 /* The PC will be changed by the instruction. */
3157 operand2 = inst_env->reg[cris_get_operand2 (inst)];
3159 /* Get the value of the third operand. */
3160 operand3 = get_data_from_address (&inst, inst_env->prefix_value);
3162 /* Calculate the PC value after the instruction, i.e. where the
3163 breakpoint should be. */
3164 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3166 inst_env->slot_needed = 0;
3167 inst_env->prefix_found = 0;
3168 inst_env->xflag_found = 0;
3169 inst_env->disable_interrupt = 0;
3172 /* Handles the index addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
3173 instructions. The MOVE instruction is the move from source to register. */
3176 handle_prefix_index_mode_for_aritm_op (unsigned short inst,
3177 inst_env_type *inst_env)
3179 if (cris_get_operand1 (inst) != cris_get_operand2 (inst))
3181 /* If the instruction is MOVE it's invalid. If the instruction is ADD,
3182 SUB, AND or OR something weird is going on (if everything works these
3183 instructions should end up in the three operand version). */
3184 inst_env->invalid = 1;
3189 /* three_operand_add_sub_cmp_and_or does the same as we should do here
3191 three_operand_add_sub_cmp_and_or_op (inst, inst_env);
3193 inst_env->slot_needed = 0;
3194 inst_env->prefix_found = 0;
3195 inst_env->xflag_found = 0;
3196 inst_env->disable_interrupt = 0;
3199 /* Handles the autoincrement and indirect addresing mode for the ADD, SUB,
3200 CMP, AND OR and MOVE instruction. The MOVE instruction is the move from
3201 source to register. */
3204 handle_inc_and_index_mode_for_aritm_op (unsigned short inst,
3205 inst_env_type *inst_env)
3207 unsigned long operand1;
3208 unsigned long operand2;
3209 unsigned long operand3;
3212 /* The instruction is either an indirect or autoincrement addressing mode.
3213 Check if the destination register is the PC. */
3214 if (cris_get_operand2 (inst) == REG_PC)
3216 /* Must be done here, get_data_from_address may change the size
3218 size = cris_get_size (inst);
3219 operand2 = inst_env->reg[REG_PC];
3221 /* Get the value of the third operand, i.e. the indirect operand. */
3222 operand1 = inst_env->reg[cris_get_operand1 (inst)];
3223 operand3 = get_data_from_address (&inst, operand1);
3225 /* Calculate the PC value after the instruction, i.e. where the
3226 breakpoint should be. The order of the udw_operands is vital. */
3227 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3229 /* If this is an autoincrement addressing mode, check if the increment
3231 if ((cris_get_operand1 (inst) == REG_PC) && (cris_get_mode (inst) == AUTOINC_MODE))
3233 /* Get the size field. */
3234 size = cris_get_size (inst);
3236 /* If it's an extend instruction we don't want the signed extend bit,
3237 because it influences the size. */
3238 if (cris_get_opcode (inst) < 4)
3240 size &= ~SIGNED_EXTEND_BIT_MASK;
3242 process_autoincrement (size, inst, inst_env);
3244 inst_env->slot_needed = 0;
3245 inst_env->prefix_found = 0;
3246 inst_env->xflag_found = 0;
3247 inst_env->disable_interrupt = 0;
3250 /* Handles the two-operand addressing mode, all modes except register, for
3251 the ADD, SUB CMP, AND and OR instruction. */
3254 none_reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst,
3255 inst_env_type *inst_env)
3257 if (inst_env->prefix_found)
3259 if (cris_get_mode (inst) == PREFIX_INDEX_MODE)
3261 handle_prefix_index_mode_for_aritm_op (inst, inst_env);
3263 else if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
3265 handle_prefix_assign_mode_for_aritm_op (inst, inst_env);
3269 /* The mode is invalid for a prefixed base instruction. */
3270 inst_env->invalid = 1;
3276 handle_inc_and_index_mode_for_aritm_op (inst, inst_env);
3280 /* Handles the quick addressing mode for the ADD and SUB instruction. */
3283 quick_mode_add_sub_op (unsigned short inst, inst_env_type *inst_env)
3285 unsigned long operand1;
3286 unsigned long operand2;
3288 /* It's a bad idea to be in a prefix instruction now. This is a quick mode
3289 instruction and can't have a prefix. */
3290 if (inst_env->prefix_found)
3292 inst_env->invalid = 1;
3296 /* Check if the instruction has PC as its target. */
3297 if (cris_get_operand2 (inst) == REG_PC)
3299 if (inst_env->slot_needed)
3301 inst_env->invalid = 1;
3304 operand1 = cris_get_quick_value (inst);
3305 operand2 = inst_env->reg[REG_PC];
3307 /* The size should now be dword. */
3308 cris_set_size_to_dword (&inst);
3310 /* Calculate the PC value after the instruction, i.e. where the
3311 breakpoint should be. */
3312 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3314 inst_env->slot_needed = 0;
3315 inst_env->prefix_found = 0;
3316 inst_env->xflag_found = 0;
3317 inst_env->disable_interrupt = 0;
3320 /* Handles the quick addressing mode for the CMP, AND and OR instruction. */
3323 quick_mode_and_cmp_move_or_op (unsigned short inst, inst_env_type *inst_env)
3325 unsigned long operand1;
3326 unsigned long operand2;
3328 /* It's a bad idea to be in a prefix instruction now. This is a quick mode
3329 instruction and can't have a prefix. */
3330 if (inst_env->prefix_found)
3332 inst_env->invalid = 1;
3335 /* Check if the instruction has PC as its target. */
3336 if (cris_get_operand2 (inst) == REG_PC)
3338 if (inst_env->slot_needed)
3340 inst_env->invalid = 1;
3343 /* The instruction has the PC as its target register. */
3344 operand1 = cris_get_quick_value (inst);
3345 operand2 = inst_env->reg[REG_PC];
3347 /* The quick value is signed, so check if we must do a signed extend. */
3348 if (operand1 & SIGNED_QUICK_VALUE_MASK)
3351 operand1 |= SIGNED_QUICK_VALUE_EXTEND_MASK;
3353 /* The size should now be dword. */
3354 cris_set_size_to_dword (&inst);
3356 /* Calculate the PC value after the instruction, i.e. where the
3357 breakpoint should be. */
3358 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3360 inst_env->slot_needed = 0;
3361 inst_env->prefix_found = 0;
3362 inst_env->xflag_found = 0;
3363 inst_env->disable_interrupt = 0;
3366 /* Translate op_type to a function and call it. */
3369 cris_gdb_func (enum cris_op_type op_type, unsigned short inst,
3370 inst_env_type *inst_env)
3374 case cris_not_implemented_op:
3375 not_implemented_op (inst, inst_env);
3379 abs_op (inst, inst_env);
3383 addi_op (inst, inst_env);
3387 asr_op (inst, inst_env);
3391 asrq_op (inst, inst_env);
3394 case cris_ax_ei_setf_op:
3395 ax_ei_setf_op (inst, inst_env);
3398 case cris_bdap_prefix:
3399 bdap_prefix (inst, inst_env);
3402 case cris_biap_prefix:
3403 biap_prefix (inst, inst_env);
3407 break_op (inst, inst_env);
3410 case cris_btst_nop_op:
3411 btst_nop_op (inst, inst_env);
3414 case cris_clearf_di_op:
3415 clearf_di_op (inst, inst_env);
3418 case cris_dip_prefix:
3419 dip_prefix (inst, inst_env);
3422 case cris_dstep_logshift_mstep_neg_not_op:
3423 dstep_logshift_mstep_neg_not_op (inst, inst_env);
3426 case cris_eight_bit_offset_branch_op:
3427 eight_bit_offset_branch_op (inst, inst_env);
3430 case cris_move_mem_to_reg_movem_op:
3431 move_mem_to_reg_movem_op (inst, inst_env);
3434 case cris_move_reg_to_mem_movem_op:
3435 move_reg_to_mem_movem_op (inst, inst_env);
3438 case cris_move_to_preg_op:
3439 move_to_preg_op (inst, inst_env);
3443 muls_op (inst, inst_env);
3447 mulu_op (inst, inst_env);
3450 case cris_none_reg_mode_add_sub_cmp_and_or_move_op:
3451 none_reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env);
3454 case cris_none_reg_mode_clear_test_op:
3455 none_reg_mode_clear_test_op (inst, inst_env);
3458 case cris_none_reg_mode_jump_op:
3459 none_reg_mode_jump_op (inst, inst_env);
3462 case cris_none_reg_mode_move_from_preg_op:
3463 none_reg_mode_move_from_preg_op (inst, inst_env);
3466 case cris_quick_mode_add_sub_op:
3467 quick_mode_add_sub_op (inst, inst_env);
3470 case cris_quick_mode_and_cmp_move_or_op:
3471 quick_mode_and_cmp_move_or_op (inst, inst_env);
3474 case cris_quick_mode_bdap_prefix:
3475 quick_mode_bdap_prefix (inst, inst_env);
3478 case cris_reg_mode_add_sub_cmp_and_or_move_op:
3479 reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env);
3482 case cris_reg_mode_clear_op:
3483 reg_mode_clear_op (inst, inst_env);
3486 case cris_reg_mode_jump_op:
3487 reg_mode_jump_op (inst, inst_env);
3490 case cris_reg_mode_move_from_preg_op:
3491 reg_mode_move_from_preg_op (inst, inst_env);
3494 case cris_reg_mode_test_op:
3495 reg_mode_test_op (inst, inst_env);
3499 scc_op (inst, inst_env);
3502 case cris_sixteen_bit_offset_branch_op:
3503 sixteen_bit_offset_branch_op (inst, inst_env);
3506 case cris_three_operand_add_sub_cmp_and_or_op:
3507 three_operand_add_sub_cmp_and_or_op (inst, inst_env);
3510 case cris_three_operand_bound_op:
3511 three_operand_bound_op (inst, inst_env);
3514 case cris_two_operand_bound_op:
3515 two_operand_bound_op (inst, inst_env);
3519 xor_op (inst, inst_env);
3524 /* This wrapper is to avoid cris_get_assembler being called before
3525 exec_bfd has been set. */
3528 cris_delayed_get_disassembler (bfd_vma addr, struct disassemble_info *info)
3530 int (*print_insn) (bfd_vma addr, struct disassemble_info *info);
3531 /* FIXME: cagney/2003-08-27: It should be possible to select a CRIS
3532 disassembler, even when there is no BFD. Does something like
3533 "gdb; target remote; disassmeble *0x123" work? */
3534 gdb_assert (exec_bfd != NULL);
3535 print_insn = cris_get_disassembler (exec_bfd);
3536 gdb_assert (print_insn != NULL);
3537 return print_insn (addr, info);
3540 /* Copied from <asm/elf.h>. */
3541 typedef unsigned long elf_greg_t;
3543 /* Same as user_regs_struct struct in <asm/user.h>. */
3544 typedef elf_greg_t elf_gregset_t[35];
3546 /* Unpack an elf_gregset_t into GDB's register cache. */
3549 supply_gregset (elf_gregset_t *gregsetp)
3552 elf_greg_t *regp = *gregsetp;
3553 static char zerobuf[4] = {0};
3555 /* The kernel dumps all 32 registers as unsigned longs, but supply_register
3556 knows about the actual size of each register so that's no problem. */
3557 for (i = 0; i < NUM_GENREGS + NUM_SPECREGS; i++)
3559 supply_register (i, (char *)®p[i]);
3563 /* Use a local version of this function to get the correct types for
3564 regsets, until multi-arch core support is ready. */
3567 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
3568 int which, CORE_ADDR reg_addr)
3570 elf_gregset_t gregset;
3575 if (core_reg_size != sizeof (gregset))
3577 warning ("wrong size gregset struct in core file");
3581 memcpy (&gregset, core_reg_sect, sizeof (gregset));
3582 supply_gregset (&gregset);
3586 /* We've covered all the kinds of registers we know about here,
3587 so this must be something we wouldn't know what to do with
3588 anyway. Just ignore it. */
3593 static struct core_fns cris_elf_core_fns =
3595 bfd_target_elf_flavour, /* core_flavour */
3596 default_check_format, /* check_format */
3597 default_core_sniffer, /* core_sniffer */
3598 fetch_core_registers, /* core_read_registers */
3602 /* Fetch (and possibly build) an appropriate link_map_offsets
3603 structure for native GNU/Linux CRIS targets using the struct
3604 offsets defined in link.h (but without actual reference to that
3607 This makes it possible to access GNU/Linux CRIS shared libraries
3608 from a GDB that was not built on an GNU/Linux CRIS host (for cross
3611 See gdb/solib-svr4.h for an explanation of these fields. */
3613 static struct link_map_offsets *
3614 cris_linux_svr4_fetch_link_map_offsets (void)
3616 static struct link_map_offsets lmo;
3617 static struct link_map_offsets *lmp = NULL;
3623 lmo.r_debug_size = 8; /* The actual size is 20 bytes, but
3624 this is all we need. */
3625 lmo.r_map_offset = 4;
3628 lmo.link_map_size = 20;
3630 lmo.l_addr_offset = 0;
3631 lmo.l_addr_size = 4;
3633 lmo.l_name_offset = 4;
3634 lmo.l_name_size = 4;
3636 lmo.l_next_offset = 12;
3637 lmo.l_next_size = 4;
3639 lmo.l_prev_offset = 16;
3640 lmo.l_prev_size = 4;
3647 cris_fpless_backtrace (char *noargs, int from_tty)
3649 /* Points at the instruction after the jsr (except when in innermost frame
3650 where it points at the original pc). */
3653 /* Temporary variable, used for parsing from the start of the function that
3654 the pc is in, up to the pc. */
3655 CORE_ADDR tmp_pc = 0;
3658 /* Information about current frame. */
3659 struct symtab_and_line sal;
3662 /* Present instruction. */
3663 unsigned short insn;
3665 /* Next instruction, lookahead. */
3666 unsigned short insn_next;
3668 /* This is to store the offset between sp at start of function and until we
3669 reach push srp (if any). */
3670 int sp_add_later = 0;
3671 int push_srp_found = 0;
3675 /* Frame counter. */
3678 /* For the innermost frame, we want to look at srp in case it's a leaf
3679 function (since there's no push srp in that case). */
3680 int innermost_frame = 1;
3682 deprecated_read_register_gen (PC_REGNUM, (char *) &pc);
3683 deprecated_read_register_gen (SP_REGNUM, (char *) &sp);
3685 /* We make an explicit return when we can't find an outer frame. */
3688 /* Get file name and line number. */
3689 sal = find_pc_line (pc, 0);
3691 /* Get function name. */
3692 find_pc_partial_function (pc, &func_name, (CORE_ADDR *) NULL,
3693 (CORE_ADDR *) NULL);
3695 /* Print information about current frame. */
3696 printf_unfiltered ("#%i 0x%08lx in %s", frame++, pc, func_name);
3699 printf_unfiltered (" at %s:%i", sal.symtab->filename, sal.line);
3701 printf_unfiltered ("\n");
3703 /* Get the start address of this function. */
3704 tmp_pc = get_pc_function_start (pc);
3706 /* Mini parser, only meant to find push sp and sub ...,sp from the start
3707 of the function, up to the pc. */
3710 insn = read_memory_unsigned_integer (tmp_pc, sizeof (short));
3711 tmp_pc += sizeof (short);
3714 /* push <reg> 32 bit instruction */
3715 insn_next = read_memory_unsigned_integer (tmp_pc,
3717 tmp_pc += sizeof (short);
3719 /* Recognize srp. */
3720 if (insn_next == 0xBE7E)
3722 /* For subsequent (not this one though) push or sub which
3723 affects sp, adjust sp immediately. */
3726 /* Note: this will break if we ever encounter a
3727 push vr (1 byte) or push ccr (2 bytes). */
3732 /* Some other register was pushed. */
3743 else if (cris_get_operand2 (insn) == SP_REGNUM
3744 && cris_get_mode (insn) == 0x0000
3745 && cris_get_opcode (insn) == 0x000A)
3748 val = cris_get_quick_value (insn);
3756 sp_add_later += val;
3760 else if (cris_get_operand2 (insn) == SP_REGNUM
3761 /* Autoincrement addressing mode. */
3762 && cris_get_mode (insn) == 0x0003
3764 && ((insn) & 0x03E0) >> 5 == 0x0004)
3767 val = get_data_from_address (&insn, tmp_pc);
3775 sp_add_later += val;
3778 else if (cris_get_operand2 (insn) == SP_REGNUM
3779 && ((insn & 0x0F00) >> 8) == 0x0001
3780 && (cris_get_signed_offset (insn) < 0))
3782 /* Immediate byte offset addressing prefix word with sp as base
3783 register. Used for CRIS v8 i.e. ETRAX 100 and newer if <val>
3784 is between 64 and 128.
3785 movem r<regsave>,[sp=sp-<val>] */
3786 val = -cris_get_signed_offset (insn);
3787 insn_next = read_memory_unsigned_integer (tmp_pc,
3789 tmp_pc += sizeof (short);
3791 if (cris_get_mode (insn_next) == PREFIX_ASSIGN_MODE
3792 && cris_get_opcode (insn_next) == 0x000F
3793 && cris_get_size (insn_next) == 0x0003
3794 && cris_get_operand1 (insn_next) == SP_REGNUM)
3802 sp_add_later += val;
3813 /* sp should now point at where srp is stored on the stack. Update
3814 the pc to the srp. */
3815 pc = read_memory_unsigned_integer (sp, 4);
3817 else if (innermost_frame)
3819 /* We couldn't find a push srp in the prologue, so this must be
3820 a leaf function, and thus we use the srp register directly.
3821 This should happen at most once, for the innermost function. */
3822 deprecated_read_register_gen (SRP_REGNUM, (char *) &pc);
3826 /* Couldn't find an outer frame. */
3830 /* Reset flag. (In case the innermost frame wasn't a leaf, we don't
3831 want to look at the srp register later either). */
3832 innermost_frame = 0;
3834 /* Now, add the offset for everything up to, and including push srp,
3835 that was held back during the prologue parsing. */
3841 extern initialize_file_ftype _initialize_cris_tdep; /* -Wmissing-prototypes */
3844 _initialize_cris_tdep (void)
3846 struct cmd_list_element *c;
3848 gdbarch_register (bfd_arch_cris, cris_gdbarch_init, cris_dump_tdep);
3850 /* CRIS-specific user-commands. */
3851 c = add_set_cmd ("cris-version", class_support, var_integer,
3852 (char *) &usr_cmd_cris_version,
3853 "Set the current CRIS version.", &setlist);
3854 set_cmd_sfunc (c, cris_version_update);
3855 add_show_from_set (c, &showlist);
3857 c = add_set_enum_cmd ("cris-mode", class_support, cris_mode_enums,
3859 "Set the current CRIS mode.", &setlist);
3860 set_cmd_sfunc (c, cris_mode_update);
3861 add_show_from_set (c, &showlist);
3863 c = add_set_enum_cmd ("cris-abi", class_support, cris_abi_enums,
3865 "Set the current CRIS ABI version.", &setlist);
3866 set_cmd_sfunc (c, cris_abi_update);
3867 add_show_from_set (c, &showlist);
3869 c = add_cmd ("cris-fpless-backtrace", class_support, cris_fpless_backtrace,
3870 "Display call chain using the subroutine return pointer.\n"
3871 "Note that this displays the address after the jump to the "
3872 "subroutine.", &cmdlist);
3874 add_core_fns (&cris_elf_core_fns);
3878 /* Prints out all target specific values. */
3881 cris_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
3883 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3886 fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_version = %i\n",
3887 tdep->cris_version);
3888 fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_mode = %s\n",
3890 fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_abi = %s\n",
3897 cris_version_update (char *ignore_args, int from_tty,
3898 struct cmd_list_element *c)
3900 struct gdbarch_info info;
3902 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
3903 the set command passed as a parameter. The clone operation will
3904 include (BUG?) any ``set'' command callback, if present.
3905 Commands like ``info set'' call all the ``show'' command
3906 callbacks. Unfortunately, for ``show'' commands cloned from
3907 ``set'', this includes callbacks belonging to ``set'' commands.
3908 Making this worse, this only occures if add_show_from_set() is
3909 called after add_cmd_sfunc() (BUG?). */
3911 /* From here on, trust the user's CRIS version setting. */
3912 if (cmd_type (c) == set_cmd)
3914 usr_cmd_cris_version_valid = 1;
3916 /* Update the current architecture, if needed. */
3917 gdbarch_info_init (&info);
3918 if (!gdbarch_update_p (info))
3919 internal_error (__FILE__, __LINE__, "cris_gdbarch_update: failed to update architecture.");
3924 cris_mode_update (char *ignore_args, int from_tty,
3925 struct cmd_list_element *c)
3927 struct gdbarch_info info;
3929 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
3930 the set command passed as a parameter. The clone operation will
3931 include (BUG?) any ``set'' command callback, if present.
3932 Commands like ``info set'' call all the ``show'' command
3933 callbacks. Unfortunately, for ``show'' commands cloned from
3934 ``set'', this includes callbacks belonging to ``set'' commands.
3935 Making this worse, this only occures if add_show_from_set() is
3936 called after add_cmd_sfunc() (BUG?). */
3938 /* From here on, trust the user's CRIS mode setting. */
3939 if (cmd_type (c) == set_cmd)
3941 usr_cmd_cris_mode_valid = 1;
3943 /* Update the current architecture, if needed. */
3944 gdbarch_info_init (&info);
3945 if (!gdbarch_update_p (info))
3946 internal_error (__FILE__, __LINE__, "cris_gdbarch_update: failed to update architecture.");
3951 cris_abi_update (char *ignore_args, int from_tty,
3952 struct cmd_list_element *c)
3954 struct gdbarch_info info;
3956 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
3957 the set command passed as a parameter. The clone operation will
3958 include (BUG?) any ``set'' command callback, if present.
3959 Commands like ``info set'' call all the ``show'' command
3960 callbacks. Unfortunately, for ``show'' commands cloned from
3961 ``set'', this includes callbacks belonging to ``set'' commands.
3962 Making this worse, this only occures if add_show_from_set() is
3963 called after add_cmd_sfunc() (BUG?). */
3965 /* From here on, trust the user's CRIS ABI setting. */
3966 if (cmd_type (c) == set_cmd)
3968 usr_cmd_cris_abi_valid = 1;
3970 /* Update the current architecture, if needed. */
3971 gdbarch_info_init (&info);
3972 if (!gdbarch_update_p (info))
3973 internal_error (__FILE__, __LINE__, "cris_gdbarch_update: failed to update architecture.");
3977 /* Copied from pa64solib.c, with a couple of minor changes. */
3980 bfd_lookup_symbol (bfd *abfd, const char *symname)
3982 unsigned int storage_needed;
3984 asymbol **symbol_table;
3985 unsigned int number_of_symbols;
3987 struct cleanup *back_to;
3988 CORE_ADDR symaddr = 0;
3990 storage_needed = bfd_get_symtab_upper_bound (abfd);
3992 if (storage_needed > 0)
3994 symbol_table = (asymbol **) xmalloc (storage_needed);
3995 back_to = make_cleanup (free, symbol_table);
3996 number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
3998 for (i = 0; i < number_of_symbols; i++)
4000 sym = *symbol_table++;
4001 if (!strcmp (sym->name, symname))
4003 /* Bfd symbols are section relative. */
4004 symaddr = sym->value + sym->section->vma;
4008 do_cleanups (back_to);
4013 static struct gdbarch *
4014 cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
4016 struct gdbarch *gdbarch;
4017 struct gdbarch_tdep *tdep;
4019 const char *cris_mode;
4020 const char *cris_abi;
4021 CORE_ADDR cris_abi_sym = 0;
4024 if (usr_cmd_cris_version_valid)
4026 /* Trust the user's CRIS version setting. */
4027 cris_version = usr_cmd_cris_version;
4031 /* Assume it's CRIS version 10. */
4035 if (usr_cmd_cris_mode_valid)
4037 /* Trust the user's CRIS mode setting. */
4038 cris_mode = usr_cmd_cris_mode;
4040 else if (cris_version == 10)
4042 /* Assume CRIS version 10 is in user mode. */
4043 cris_mode = CRIS_MODE_USER;
4047 /* Strictly speaking, older CRIS version don't have a supervisor mode,
4048 but we regard its only mode as supervisor mode. */
4049 cris_mode = CRIS_MODE_SUPERVISOR;
4052 if (usr_cmd_cris_abi_valid)
4054 /* Trust the user's ABI setting. */
4055 cris_abi = usr_cmd_cris_abi;
4059 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
4061 /* An elf target uses the new ABI. */
4062 cris_abi = CRIS_ABI_V2;
4064 else if (bfd_get_flavour (info.abfd) == bfd_target_aout_flavour)
4066 /* An a.out target may use either ABI. Look for hints in the
4068 cris_abi_sym = bfd_lookup_symbol (info.abfd, CRIS_ABI_SYMBOL);
4069 cris_abi = cris_abi_sym ? CRIS_ABI_V2 : CRIS_ABI_ORIGINAL;
4073 /* Unknown bfd flavour. Assume it's the new ABI. */
4074 cris_abi = CRIS_ABI_V2;
4077 else if (arches != NULL)
4079 /* No bfd available. Stick with the ABI from the most recently
4080 selected architecture of this same family (the head of arches
4081 always points to this). (This is to avoid changing the ABI
4082 when the user updates the architecture with the 'set
4083 cris-version' command.) */
4084 cris_abi = gdbarch_tdep (arches->gdbarch)->cris_abi;
4088 /* No bfd, and no previously selected architecture available.
4089 Assume it's the new ABI. */
4090 cris_abi = CRIS_ABI_V2;
4093 /* Make the current settings visible to the user. */
4094 usr_cmd_cris_version = cris_version;
4095 usr_cmd_cris_mode = cris_mode;
4096 usr_cmd_cris_abi = cris_abi;
4098 /* Find a candidate among the list of pre-declared architectures. Both
4099 CRIS version and ABI must match. */
4100 for (arches = gdbarch_list_lookup_by_info (arches, &info);
4102 arches = gdbarch_list_lookup_by_info (arches->next, &info))
4104 if ((gdbarch_tdep (arches->gdbarch)->cris_version == cris_version)
4105 && (gdbarch_tdep (arches->gdbarch)->cris_mode == cris_mode)
4106 && (gdbarch_tdep (arches->gdbarch)->cris_abi == cris_abi))
4107 return arches->gdbarch;
4110 /* No matching architecture was found. Create a new one. */
4111 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
4112 gdbarch = gdbarch_alloc (&info, tdep);
4114 /* NOTE: cagney/2002-12-06: This can be deleted when this arch is
4115 ready to unwind the PC first (see frame.c:get_prev_frame()). */
4116 set_gdbarch_deprecated_init_frame_pc (gdbarch, deprecated_init_frame_pc_default);
4118 tdep->cris_version = cris_version;
4119 tdep->cris_mode = cris_mode;
4120 tdep->cris_abi = cris_abi;
4122 /* INIT shall ensure that the INFO.BYTE_ORDER is non-zero. */
4123 switch (info.byte_order)
4125 case BFD_ENDIAN_LITTLE:
4129 case BFD_ENDIAN_BIG:
4130 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: big endian byte order in info");
4134 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unknown byte order in info");
4137 /* Initialize the ABI dependent things. */
4138 if (tdep->cris_abi == CRIS_ABI_ORIGINAL)
4140 set_gdbarch_double_bit (gdbarch, 32);
4141 set_gdbarch_deprecated_push_arguments (gdbarch, cris_abi_original_push_arguments);
4142 set_gdbarch_deprecated_store_return_value (gdbarch,
4143 cris_abi_original_store_return_value);
4144 set_gdbarch_deprecated_extract_return_value
4145 (gdbarch, cris_abi_original_extract_return_value);
4146 set_gdbarch_deprecated_reg_struct_has_addr
4147 (gdbarch, cris_abi_original_reg_struct_has_addr);
4149 else if (tdep->cris_abi == CRIS_ABI_V2)
4151 set_gdbarch_double_bit (gdbarch, 64);
4152 set_gdbarch_deprecated_push_arguments (gdbarch, cris_abi_v2_push_arguments);
4153 set_gdbarch_deprecated_store_return_value (gdbarch, cris_abi_v2_store_return_value);
4154 set_gdbarch_deprecated_extract_return_value
4155 (gdbarch, cris_abi_v2_extract_return_value);
4156 set_gdbarch_deprecated_reg_struct_has_addr
4157 (gdbarch, cris_abi_v2_reg_struct_has_addr);
4160 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unknown CRIS ABI");
4162 /* The default definition of a long double is 2 * TARGET_DOUBLE_BIT,
4163 which means we have to set this explicitly. */
4164 set_gdbarch_long_double_bit (gdbarch, 64);
4166 /* There are 32 registers (some of which may not be implemented). */
4167 set_gdbarch_num_regs (gdbarch, 32);
4168 set_gdbarch_sp_regnum (gdbarch, 14);
4169 set_gdbarch_deprecated_fp_regnum (gdbarch, 8);
4170 set_gdbarch_pc_regnum (gdbarch, 15);
4172 set_gdbarch_register_name (gdbarch, cris_register_name);
4174 /* Length of ordinary registers used in push_word and a few other
4175 places. DEPRECATED_REGISTER_RAW_SIZE is the real way to know how
4176 big a register is. */
4177 set_gdbarch_deprecated_register_size (gdbarch, 4);
4180 set_gdbarch_register_bytes_ok (gdbarch, cris_register_bytes_ok);
4181 set_gdbarch_software_single_step (gdbarch, cris_software_single_step);
4184 set_gdbarch_cannot_store_register (gdbarch, cris_cannot_store_register);
4185 set_gdbarch_cannot_fetch_register (gdbarch, cris_cannot_fetch_register);
4188 /* The total amount of space needed to store (in an array called registers)
4189 GDB's copy of the machine's register state. Note: We can not use
4190 cris_register_size at this point, since it relies on current_gdbarch
4192 switch (tdep->cris_version)
4198 /* Support for these may be added later. */
4199 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unsupported CRIS version");
4204 /* CRIS v8 and v9, a.k.a. ETRAX 100. General registers R0 - R15
4205 (32 bits), special registers P0 - P1 (8 bits), P4 - P5 (16 bits),
4206 and P8 - P14 (32 bits). */
4207 register_bytes = (16 * 4) + (2 * 1) + (2 * 2) + (7 * 4);
4212 /* CRIS v10 and v11, a.k.a. ETRAX 100LX. In addition to ETRAX 100,
4213 P7 (32 bits), and P15 (32 bits) have been implemented. */
4214 register_bytes = (16 * 4) + (2 * 1) + (2 * 2) + (9 * 4);
4218 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unknown CRIS version");
4221 set_gdbarch_deprecated_register_bytes (gdbarch, register_bytes);
4223 /* Returns the register offset for the first byte of register regno's space
4224 in the saved register state. */
4225 set_gdbarch_deprecated_register_byte (gdbarch, cris_register_offset);
4227 /* The length of the registers in the actual machine representation. */
4228 set_gdbarch_deprecated_register_raw_size (gdbarch, cris_register_size);
4230 /* The largest value DEPRECATED_REGISTER_RAW_SIZE can have. */
4231 set_gdbarch_deprecated_max_register_raw_size (gdbarch, 32);
4233 /* The length of the registers in the program's representation. */
4234 set_gdbarch_deprecated_register_virtual_size (gdbarch, cris_register_size);
4236 /* The largest value DEPRECATED_REGISTER_VIRTUAL_SIZE can have. */
4237 set_gdbarch_deprecated_max_register_virtual_size (gdbarch, 32);
4239 set_gdbarch_deprecated_register_virtual_type (gdbarch, cris_register_virtual_type);
4241 /* Use generic dummy frames. */
4243 /* Read all about dummy frames in blockframe.c. */
4244 set_gdbarch_deprecated_pc_in_call_dummy (gdbarch, deprecated_pc_in_call_dummy_at_entry_point);
4246 /* Defined to 1 to indicate that the target supports inferior function
4248 set_gdbarch_deprecated_call_dummy_words (gdbarch, 0);
4249 set_gdbarch_deprecated_sizeof_call_dummy_words (gdbarch, 0);
4251 set_gdbarch_deprecated_get_saved_register (gdbarch, deprecated_generic_get_saved_register);
4253 set_gdbarch_deprecated_push_return_address (gdbarch, cris_push_return_address);
4254 set_gdbarch_deprecated_pop_frame (gdbarch, cris_pop_frame);
4256 set_gdbarch_deprecated_store_struct_return (gdbarch, cris_store_struct_return);
4257 set_gdbarch_use_struct_convention (gdbarch, always_use_struct_convention);
4259 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, cris_frame_init_saved_regs);
4260 set_gdbarch_deprecated_init_extra_frame_info (gdbarch, cris_init_extra_frame_info);
4261 set_gdbarch_skip_prologue (gdbarch, cris_skip_prologue);
4262 set_gdbarch_prologue_frameless_p (gdbarch, generic_prologue_frameless_p);
4264 /* The stack grows downward. */
4265 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
4267 set_gdbarch_breakpoint_from_pc (gdbarch, cris_breakpoint_from_pc);
4269 set_gdbarch_frameless_function_invocation
4270 (gdbarch, cris_frameless_function_invocation);
4271 set_gdbarch_deprecated_frame_chain (gdbarch, cris_frame_chain);
4273 set_gdbarch_deprecated_frame_saved_pc (gdbarch, cris_frame_saved_pc);
4274 set_gdbarch_deprecated_saved_pc_after_call (gdbarch, cris_saved_pc_after_call);
4276 /* Helpful for backtracing and returning in a call dummy. */
4277 set_gdbarch_deprecated_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos);
4279 /* Should be using push_dummy_call. */
4280 set_gdbarch_deprecated_dummy_write_sp (gdbarch, deprecated_write_sp);
4282 /* Use target_specific function to define link map offsets. */
4283 set_solib_svr4_fetch_link_map_offsets
4284 (gdbarch, cris_linux_svr4_fetch_link_map_offsets);
4286 /* FIXME: cagney/2003-08-27: It should be possible to select a CRIS
4287 disassembler, even when there is no BFD. Does something like
4288 "gdb; target remote; disassmeble *0x123" work? */
4289 set_gdbarch_print_insn (gdbarch, cris_delayed_get_disassembler);