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);
175 struct frame_extra_info
181 /* The instruction environment needed to find single-step breakpoints. */
183 struct instruction_environment
185 unsigned long reg[NUM_GENREGS];
186 unsigned long preg[NUM_SPECREGS];
187 unsigned long branch_break_address;
188 unsigned long delay_slot_pc;
189 unsigned long prefix_value;
194 int delay_slot_pc_active;
196 int disable_interrupt;
199 /* Save old breakpoints in order to restore the state before a single_step.
200 At most, two breakpoints will have to be remembered. */
202 char binsn_quantum[BREAKPOINT_MAX];
203 static binsn_quantum break_mem[2];
204 static CORE_ADDR next_pc = 0;
205 static CORE_ADDR branch_target_address = 0;
206 static unsigned char branch_break_inserted = 0;
208 /* Machine-dependencies in CRIS for opcodes. */
210 /* Instruction sizes. */
211 enum cris_instruction_sizes
218 /* Addressing modes. */
219 enum cris_addressing_modes
226 /* Prefix addressing modes. */
227 enum cris_prefix_addressing_modes
229 PREFIX_INDEX_MODE = 2,
230 PREFIX_ASSIGN_MODE = 3,
232 /* Handle immediate byte offset addressing mode prefix format. */
233 PREFIX_OFFSET_MODE = 2
236 /* Masks for opcodes. */
237 enum cris_opcode_masks
239 BRANCH_SIGNED_SHORT_OFFSET_MASK = 0x1,
240 SIGNED_EXTEND_BIT_MASK = 0x2,
241 SIGNED_BYTE_MASK = 0x80,
242 SIGNED_BYTE_EXTEND_MASK = 0xFFFFFF00,
243 SIGNED_WORD_MASK = 0x8000,
244 SIGNED_WORD_EXTEND_MASK = 0xFFFF0000,
245 SIGNED_DWORD_MASK = 0x80000000,
246 SIGNED_QUICK_VALUE_MASK = 0x20,
247 SIGNED_QUICK_VALUE_EXTEND_MASK = 0xFFFFFFC0
250 /* Functions for opcodes. The general form of the ETRAX 16-bit instruction:
258 cris_get_operand2 (unsigned short insn)
260 return ((insn & 0xF000) >> 12);
264 cris_get_mode (unsigned short insn)
266 return ((insn & 0x0C00) >> 10);
270 cris_get_opcode (unsigned short insn)
272 return ((insn & 0x03C0) >> 6);
276 cris_get_size (unsigned short insn)
278 return ((insn & 0x0030) >> 4);
282 cris_get_operand1 (unsigned short insn)
284 return (insn & 0x000F);
287 /* Additional functions in order to handle opcodes. */
290 cris_get_quick_value (unsigned short insn)
292 return (insn & 0x003F);
296 cris_get_bdap_quick_offset (unsigned short insn)
298 return (insn & 0x00FF);
302 cris_get_branch_short_offset (unsigned short insn)
304 return (insn & 0x00FF);
308 cris_get_asr_shift_steps (unsigned long value)
310 return (value & 0x3F);
314 cris_get_clear_size (unsigned short insn)
316 return ((insn) & 0xC000);
320 cris_is_signed_extend_bit_on (unsigned short insn)
322 return (((insn) & 0x20) == 0x20);
326 cris_is_xflag_bit_on (unsigned short insn)
328 return (((insn) & 0x1000) == 0x1000);
332 cris_set_size_to_dword (unsigned short *insn)
339 cris_get_signed_offset (unsigned short insn)
341 return ((signed char) (insn & 0x00FF));
344 /* Calls an op function given the op-type, working on the insn and the
346 static void cris_gdb_func (enum cris_op_type, unsigned short, inst_env_type *);
348 static CORE_ADDR cris_skip_prologue_main (CORE_ADDR pc, int frameless_p);
350 static struct gdbarch *cris_gdbarch_init (struct gdbarch_info,
351 struct gdbarch_list *);
353 static void cris_dump_tdep (struct gdbarch *, struct ui_file *);
355 static void cris_version_update (char *ignore_args, int from_tty,
356 struct cmd_list_element *c);
358 static void cris_mode_update (char *ignore_args, int from_tty,
359 struct cmd_list_element *c);
361 static void cris_abi_update (char *ignore_args, int from_tty,
362 struct cmd_list_element *c);
364 static CORE_ADDR bfd_lookup_symbol (bfd *, const char *);
366 /* Frames information. The definition of the struct frame_info is
370 enum frame_type type;
374 If the compilation option -fno-omit-frame-pointer is present the
375 variable frame will be set to the content of R8 which is the frame
378 The variable pc contains the address where execution is performed
379 in the present frame. The innermost frame contains the current content
380 of the register PC. All other frames contain the content of the
381 register PC in the next frame.
383 The variable `type' indicates the frame's type: normal, SIGTRAMP
384 (associated with a signal handler), dummy (associated with a dummy
387 The variable return_pc contains the address where execution should be
388 resumed when the present frame has finished, the return address.
390 The variable leaf_function is 1 if the return address is in the register
391 SRP, and 0 if it is on the stack.
393 Prologue instructions C-code.
394 The prologue may consist of (-fno-omit-frame-pointer)
398 move.d sp,r8 move.d sp,r8
400 movem rY,[sp] movem rY,[sp]
401 move.S rZ,[r8-U] move.S rZ,[r8-U]
403 where 1 is a non-terminal function, and 2 is a leaf-function.
405 Note that this assumption is extremely brittle, and will break at the
406 slightest change in GCC's prologue.
408 If local variables are declared or register contents are saved on stack
409 the subq-instruction will be present with X as the number of bytes
410 needed for storage. The reshuffle with respect to r8 may be performed
411 with any size S (b, w, d) and any of the general registers Z={0..13}.
412 The offset U should be representable by a signed 8-bit value in all cases.
413 Thus, the prefix word is assumed to be immediate byte offset mode followed
414 by another word containing the instruction.
423 Prologue instructions C++-code.
424 Case 1) and 2) in the C-code may be followed by
430 move.S [r8+U],rZ ; P4
432 if any of the call parameters are stored. The host expects these
433 instructions to be executed in order to get the call parameters right. */
435 /* Examine the prologue of a function. The variable ip is the address of
436 the first instruction of the prologue. The variable limit is the address
437 of the first instruction after the prologue. The variable fi contains the
438 information in struct frame_info. The variable frameless_p controls whether
439 the entire prologue is examined (0) or just enough instructions to
440 determine that it is a prologue (1). */
443 cris_examine (CORE_ADDR ip, CORE_ADDR limit, struct frame_info *fi,
446 /* Present instruction. */
449 /* Next instruction, lookahead. */
450 unsigned short insn_next;
453 /* Is there a push fp? */
456 /* Number of byte on stack used for local variables and movem. */
459 /* Highest register number in a movem. */
462 /* move.d r<source_register>,rS */
463 short source_register;
465 /* This frame is with respect to a leaf until a push srp is found. */
466 get_frame_extra_info (fi)->leaf_function = 1;
468 /* This frame is without the FP until a push fp is found. */
471 /* Assume nothing on stack. */
475 /* No information about register contents so far. */
477 /* We only want to know the end of the prologue when fi->saved_regs == 0.
478 When the saved registers are allocated full information is required. */
479 if (deprecated_get_frame_saved_regs (fi))
481 for (regno = 0; regno < NUM_REGS; regno++)
482 deprecated_get_frame_saved_regs (fi)[regno] = 0;
485 /* Find the prologue instructions. */
488 insn = read_memory_unsigned_integer (ip, sizeof (short));
489 ip += sizeof (short);
492 /* push <reg> 32 bit instruction */
493 insn_next = read_memory_unsigned_integer (ip, sizeof (short));
494 ip += sizeof (short);
495 regno = cris_get_operand2 (insn_next);
497 /* This check, meant to recognize srp, used to be regno ==
498 (SRP_REGNUM - NUM_GENREGS), but that covers r11 also. */
499 if (insn_next == 0xBE7E)
505 get_frame_extra_info (fi)->leaf_function = 0;
507 else if (regno == DEPRECATED_FP_REGNUM)
512 else if (insn == 0x866E)
521 else if (cris_get_operand2 (insn) == SP_REGNUM
522 && cris_get_mode (insn) == 0x0000
523 && cris_get_opcode (insn) == 0x000A)
526 val = cris_get_quick_value (insn);
528 else if (cris_get_mode (insn) == 0x0002
529 && cris_get_opcode (insn) == 0x000F
530 && cris_get_size (insn) == 0x0003
531 && cris_get_operand1 (insn) == SP_REGNUM)
533 /* movem r<regsave>,[sp] */
538 regsave = cris_get_operand2 (insn);
540 else if (cris_get_operand2 (insn) == SP_REGNUM
541 && ((insn & 0x0F00) >> 8) == 0x0001
542 && (cris_get_signed_offset (insn) < 0))
544 /* Immediate byte offset addressing prefix word with sp as base
545 register. Used for CRIS v8 i.e. ETRAX 100 and newer if <val>
546 is between 64 and 128.
547 movem r<regsave>,[sp=sp-<val>] */
548 val = -cris_get_signed_offset (insn);
549 insn_next = read_memory_unsigned_integer (ip, sizeof (short));
550 ip += sizeof (short);
551 if (cris_get_mode (insn_next) == PREFIX_ASSIGN_MODE
552 && cris_get_opcode (insn_next) == 0x000F
553 && cris_get_size (insn_next) == 0x0003
554 && cris_get_operand1 (insn_next) == SP_REGNUM)
560 regsave = cris_get_operand2 (insn_next);
564 /* The prologue ended before the limit was reached. */
565 ip -= 2 * sizeof (short);
569 else if (cris_get_mode (insn) == 0x0001
570 && cris_get_opcode (insn) == 0x0009
571 && cris_get_size (insn) == 0x0002)
573 /* move.d r<10..13>,r<0..15> */
578 source_register = cris_get_operand1 (insn);
580 /* FIXME? In the glibc solibs, the prologue might contain something
581 like (this example taken from relocate_doit):
584 which isn't covered by the source_register check below. Question
585 is whether to add a check for this combo, or make better use of
586 the limit variable instead. */
587 if (source_register < ARG1_REGNUM || source_register > ARG4_REGNUM)
589 /* The prologue ended before the limit was reached. */
590 ip -= sizeof (short);
594 else if (cris_get_operand2 (insn) == DEPRECATED_FP_REGNUM
595 /* The size is a fixed-size. */
596 && ((insn & 0x0F00) >> 8) == 0x0001
597 /* A negative offset. */
598 && (cris_get_signed_offset (insn) < 0))
600 /* move.S rZ,[r8-U] (?) */
601 insn_next = read_memory_unsigned_integer (ip, sizeof (short));
602 ip += sizeof (short);
603 regno = cris_get_operand2 (insn_next);
604 if ((regno >= 0 && regno < SP_REGNUM)
605 && cris_get_mode (insn_next) == PREFIX_OFFSET_MODE
606 && cris_get_opcode (insn_next) == 0x000F)
608 /* move.S rZ,[r8-U] */
613 /* The prologue ended before the limit was reached. */
614 ip -= 2 * 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 positive offset. */
622 && (cris_get_signed_offset (insn) > 0))
624 /* move.S [r8+U],rZ (?) */
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) == 0x0009
631 && cris_get_operand1 (insn_next) == regno)
633 /* move.S [r8+U],rZ */
638 /* The prologue ended before the limit was reached. */
639 ip -= 2 * sizeof (short);
645 /* The prologue ended before the limit was reached. */
646 ip -= sizeof (short);
652 /* We only want to know the end of the prologue when
653 fi->saved_regs == 0. */
654 if (!deprecated_get_frame_saved_regs (fi))
659 deprecated_get_frame_saved_regs (fi)[DEPRECATED_FP_REGNUM] = get_frame_base (fi);
661 /* Calculate the addresses. */
662 for (regno = regsave; regno >= 0; regno--)
664 deprecated_get_frame_saved_regs (fi)[regno] = get_frame_base (fi) - val;
667 if (get_frame_extra_info (fi)->leaf_function)
669 /* Set the register SP to contain the stack pointer of
671 deprecated_get_frame_saved_regs (fi)[SP_REGNUM] = get_frame_base (fi) + 4;
675 /* Set the register SP to contain the stack pointer of
677 deprecated_get_frame_saved_regs (fi)[SP_REGNUM] = get_frame_base (fi) + 8;
679 /* Set the register SRP to contain the return address of
681 deprecated_get_frame_saved_regs (fi)[SRP_REGNUM] = get_frame_base (fi) + 4;
687 /* Advance pc beyond any function entry prologue instructions at pc
688 to reach some "real" code. */
691 cris_skip_prologue (CORE_ADDR pc)
693 return cris_skip_prologue_main (pc, 0);
696 /* Given a PC value corresponding to the start of a function, return the PC
697 of the first instruction after the function prologue. */
700 cris_skip_prologue_main (CORE_ADDR pc, int frameless_p)
702 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
703 struct frame_info *fi;
704 struct symtab_and_line sal = find_pc_line (pc, 0);
706 CORE_ADDR pc_after_prologue;
708 /* frame_info now contains dynamic memory. Since fi is a dummy
709 here, I don't bother allocating memory for saved_regs. */
710 fi = deprecated_frame_xmalloc_with_cleanup (0, sizeof (struct frame_extra_info));
712 /* If there is no symbol information then sal.end == 0, and we end up
713 examining only the first instruction in the function prologue.
714 Exaggerating the limit seems to be harmless. */
716 best_limit = sal.end;
718 best_limit = pc + 100;
720 pc_after_prologue = cris_examine (pc, best_limit, fi, frameless_p);
721 do_cleanups (old_chain);
722 return pc_after_prologue;
725 /* Use the program counter to determine the contents and size of a breakpoint
726 instruction. It returns a pointer to a string of bytes that encode a
727 breakpoint instruction, stores the length of the string to *lenptr, and
728 adjusts pcptr (if necessary) to point to the actual memory location where
729 the breakpoint should be inserted. */
731 static const unsigned char *
732 cris_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
734 static unsigned char break_insn[] = {0x38, 0xe9};
740 /* Returns the register SRP (subroutine return pointer) which must contain
741 the content of the register PC after a function call. */
744 cris_saved_pc_after_call (struct frame_info *frame)
746 return read_register (SRP_REGNUM);
749 /* Returns 1 if spec_reg is applicable to the current gdbarch's CRIS version,
753 cris_spec_reg_applicable (struct cris_spec_reg spec_reg)
755 int version = cris_version ();
757 switch (spec_reg.applicable_version)
759 case cris_ver_version_all:
761 case cris_ver_warning:
762 /* Indeterminate/obsolete. */
765 /* Simulator only. */
768 return (version >= 0 && version <= 3);
770 return (version >= 3);
772 return (version == 8 || version == 9);
774 return (version >= 8);
776 return (version >= 10);
778 /* Invalid cris version. */
783 /* Returns the register size in unit byte. Returns 0 for an unimplemented
784 register, -1 for an invalid register. */
787 cris_register_size (int regno)
792 if (regno >= 0 && regno < NUM_GENREGS)
794 /* General registers (R0 - R15) are 32 bits. */
797 else if (regno >= NUM_GENREGS && regno < NUM_REGS)
799 /* Special register (R16 - R31). cris_spec_regs is zero-based.
800 Adjust regno accordingly. */
801 spec_regno = regno - NUM_GENREGS;
803 /* The entries in cris_spec_regs are stored in register number order,
804 which means we can shortcut into the array when searching it. */
805 for (i = spec_regno; cris_spec_regs[i].name != NULL; i++)
807 if (cris_spec_regs[i].number == spec_regno
808 && cris_spec_reg_applicable (cris_spec_regs[i]))
809 /* Go with the first applicable register. */
810 return cris_spec_regs[i].reg_size;
812 /* Special register not applicable to this CRIS version. */
817 /* Invalid register. */
822 /* Nonzero if regno should not be fetched from the target. This is the case
823 for unimplemented (size 0) and non-existant registers. */
826 cris_cannot_fetch_register (int regno)
828 return ((regno < 0 || regno >= NUM_REGS)
829 || (cris_register_size (regno) == 0));
832 /* Nonzero if regno should not be written to the target, for various
836 cris_cannot_store_register (int regno)
838 /* There are three kinds of registers we refuse to write to.
839 1. Those that not implemented.
840 2. Those that are read-only (depends on the processor mode).
841 3. Those registers to which a write has no effect.
844 if (regno < 0 || regno >= NUM_REGS || cris_register_size (regno) == 0)
845 /* Not implemented. */
848 else if (regno == VR_REGNUM)
852 else if (regno == P0_REGNUM || regno == P4_REGNUM || regno == P8_REGNUM)
853 /* Writing has no effect. */
856 else if (cris_mode () == CRIS_MODE_USER)
858 if (regno == IBR_REGNUM || regno == BAR_REGNUM || regno == BRP_REGNUM
859 || regno == IRP_REGNUM)
860 /* Read-only in user mode. */
867 /* Returns the register offset for the first byte of register regno's space
868 in the saved register state. Returns -1 for an invalid or unimplemented
872 cris_register_offset (int regno)
878 if (regno >= 0 && regno < NUM_REGS)
880 /* FIXME: The offsets should be cached and calculated only once,
881 when the architecture being debugged has changed. */
882 for (i = 0; i < regno; i++)
883 offset += cris_register_size (i);
889 /* Invalid register. */
894 /* Return the GDB type (defined in gdbtypes.c) for the "standard" data type
895 of data in register regno. */
898 cris_register_virtual_type (int regno)
900 if (regno == SP_REGNUM || regno == PC_REGNUM
901 || (regno > P8_REGNUM && regno < USP_REGNUM))
903 /* SP, PC, IBR, IRP, SRP, BAR, DCCR, BRP */
904 return lookup_pointer_type (builtin_type_void);
906 else if (regno == P8_REGNUM || regno == USP_REGNUM
907 || (regno >= 0 && regno < SP_REGNUM))
909 /* R0 - R13, P8, P15 */
910 return builtin_type_unsigned_long;
912 else if (regno > P3_REGNUM && regno < P8_REGNUM)
914 /* P4, CCR, DCR0, DCR1 */
915 return builtin_type_unsigned_short;
917 else if (regno > PC_REGNUM && regno < P4_REGNUM)
920 return builtin_type_unsigned_char;
924 /* Invalid register. */
925 return builtin_type_void;
929 /* Stores a function return value of type type, where valbuf is the address
930 of the value to be stored. */
932 /* In the original CRIS ABI, R10 is used to store return values. */
935 cris_abi_original_store_return_value (struct type *type, char *valbuf)
937 int len = TYPE_LENGTH (type);
939 if (len <= DEPRECATED_REGISTER_SIZE)
940 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (RET_REGNUM), valbuf, len);
942 internal_error (__FILE__, __LINE__, "cris_abi_original_store_return_value: type length too large.");
945 /* In the CRIS ABI V2, R10 and R11 are used to store return values. */
948 cris_abi_v2_store_return_value (struct type *type, char *valbuf)
950 int len = TYPE_LENGTH (type);
952 if (len <= 2 * DEPRECATED_REGISTER_SIZE)
954 /* Note that this works since R10 and R11 are consecutive registers. */
955 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (RET_REGNUM),
959 internal_error (__FILE__, __LINE__, "cris_abi_v2_store_return_value: type length too large.");
962 /* Return the name of register regno as a string. Return NULL for an invalid or
963 unimplemented register. */
966 cris_register_name (int regno)
968 static char *cris_genreg_names[] =
969 { "r0", "r1", "r2", "r3", \
970 "r4", "r5", "r6", "r7", \
971 "r8", "r9", "r10", "r11", \
972 "r12", "r13", "sp", "pc" };
977 if (regno >= 0 && regno < NUM_GENREGS)
979 /* General register. */
980 return cris_genreg_names[regno];
982 else if (regno >= NUM_GENREGS && regno < NUM_REGS)
984 /* Special register (R16 - R31). cris_spec_regs is zero-based.
985 Adjust regno accordingly. */
986 spec_regno = regno - NUM_GENREGS;
988 /* The entries in cris_spec_regs are stored in register number order,
989 which means we can shortcut into the array when searching it. */
990 for (i = spec_regno; cris_spec_regs[i].name != NULL; i++)
992 if (cris_spec_regs[i].number == spec_regno
993 && cris_spec_reg_applicable (cris_spec_regs[i]))
994 /* Go with the first applicable register. */
995 return cris_spec_regs[i].name;
997 /* Special register not applicable to this CRIS version. */
1002 /* Invalid register. */
1008 cris_register_bytes_ok (long bytes)
1010 return (bytes == DEPRECATED_REGISTER_BYTES);
1013 /* Extract from an array regbuf containing the raw register state a function
1014 return value of type type, and copy that, in virtual format, into
1017 /* In the original CRIS ABI, R10 is used to return values. */
1020 cris_abi_original_extract_return_value (struct type *type, char *regbuf,
1023 int len = TYPE_LENGTH (type);
1025 if (len <= DEPRECATED_REGISTER_SIZE)
1026 memcpy (valbuf, regbuf + DEPRECATED_REGISTER_BYTE (RET_REGNUM), len);
1028 internal_error (__FILE__, __LINE__, "cris_abi_original_extract_return_value: type length too large");
1031 /* In the CRIS ABI V2, R10 and R11 are used to store return values. */
1034 cris_abi_v2_extract_return_value (struct type *type, char *regbuf,
1037 int len = TYPE_LENGTH (type);
1039 if (len <= 2 * DEPRECATED_REGISTER_SIZE)
1040 memcpy (valbuf, regbuf + DEPRECATED_REGISTER_BYTE (RET_REGNUM), len);
1042 internal_error (__FILE__, __LINE__, "cris_abi_v2_extract_return_value: type length too large");
1045 /* Store the address of the place in which to copy the structure the
1046 subroutine will return. In the CRIS ABI, R9 is used in order to
1047 pass the address of the allocated area where a structure return
1048 value must be stored. */
1051 cris_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
1053 write_register (STR_REGNUM, addr);
1056 /* Returns 1 if the given type will be passed by pointer rather than
1059 /* In the original CRIS ABI, arguments shorter than or equal to 32 bits are
1063 cris_abi_original_reg_struct_has_addr (int gcc_p, struct type *type)
1065 return (TYPE_LENGTH (type) > 4);
1068 /* In the CRIS ABI V2, arguments shorter than or equal to 64 bits are passed
1072 cris_abi_v2_reg_struct_has_addr (int gcc_p, struct type *type)
1074 return (TYPE_LENGTH (type) > 8);
1077 /* Returns 1 if the function invocation represented by fi does not have a
1078 stack frame associated with it. Otherwise return 0. */
1081 cris_frameless_function_invocation (struct frame_info *fi)
1083 if ((get_frame_type (fi) == SIGTRAMP_FRAME))
1086 return frameless_look_for_prologue (fi);
1089 /* See frame.h. Determines the address of all registers in the
1090 current stack frame storing each in frame->saved_regs. Space for
1091 frame->saved_regs shall be allocated by
1092 DEPRECATED_FRAME_INIT_SAVED_REGS using frame_saved_regs_zalloc. */
1095 cris_frame_init_saved_regs (struct frame_info *fi)
1098 struct symtab_and_line sal;
1100 char *dummy_regs = deprecated_generic_find_dummy_frame (get_frame_pc (fi),
1101 get_frame_base (fi));
1103 /* Examine the entire prologue. */
1104 int frameless_p = 0;
1106 /* Has this frame's registers already been initialized? */
1107 if (deprecated_get_frame_saved_regs (fi))
1110 frame_saved_regs_zalloc (fi);
1114 /* I don't see this ever happening, considering the context in which
1115 cris_frame_init_saved_regs is called (always when we're not in
1117 memcpy (deprecated_get_frame_saved_regs (fi), dummy_regs, SIZEOF_FRAME_SAVED_REGS);
1121 ip = get_frame_func (fi);
1122 sal = find_pc_line (ip, 0);
1124 /* If there is no symbol information then sal.end == 0, and we end up
1125 examining only the first instruction in the function prologue.
1126 Exaggerating the limit seems to be harmless. */
1128 best_limit = sal.end;
1130 best_limit = ip + 100;
1132 cris_examine (ip, best_limit, fi, frameless_p);
1136 /* Initialises the extra frame information at the creation of a new frame.
1137 The inparameter fromleaf is 0 when the call is from create_new_frame.
1138 When the call is from get_prev_frame_info, fromleaf is determined by
1139 cris_frameless_function_invocation. */
1142 cris_init_extra_frame_info (int fromleaf, struct frame_info *fi)
1144 if (get_next_frame (fi))
1146 /* Called from get_prev_frame. */
1147 deprecated_update_frame_pc_hack (fi, DEPRECATED_FRAME_SAVED_PC (get_next_frame (fi)));
1150 frame_extra_info_zalloc (fi, sizeof (struct frame_extra_info));
1152 get_frame_extra_info (fi)->return_pc = 0;
1153 get_frame_extra_info (fi)->leaf_function = 0;
1155 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi),
1156 get_frame_base (fi),
1157 get_frame_base (fi)))
1159 /* We need to setup fi->frame here because call_function_by_hand
1160 gets it wrong by assuming it's always FP. */
1161 deprecated_update_frame_base_hack (fi, deprecated_read_register_dummy (get_frame_pc (fi), get_frame_base (fi), SP_REGNUM));
1162 get_frame_extra_info (fi)->return_pc =
1163 deprecated_read_register_dummy (get_frame_pc (fi),
1164 get_frame_base (fi), PC_REGNUM);
1166 /* FIXME: Is this necessarily true? */
1167 get_frame_extra_info (fi)->leaf_function = 0;
1171 cris_frame_init_saved_regs (fi);
1173 /* Check fromleaf/frameless_function_invocation. (FIXME) */
1175 if (deprecated_get_frame_saved_regs (fi)[SRP_REGNUM] != 0)
1177 /* SRP was saved on the stack; non-leaf function. */
1178 get_frame_extra_info (fi)->return_pc =
1179 read_memory_integer (deprecated_get_frame_saved_regs (fi)[SRP_REGNUM],
1180 DEPRECATED_REGISTER_RAW_SIZE (SRP_REGNUM));
1184 /* SRP is still in a register; leaf function. */
1185 get_frame_extra_info (fi)->return_pc = read_register (SRP_REGNUM);
1186 /* FIXME: Should leaf_function be set to 1 here? */
1187 get_frame_extra_info (fi)->leaf_function = 1;
1192 /* Return the content of the frame pointer in the present frame. In other
1193 words, determine the address of the calling function's frame. */
1196 cris_frame_chain (struct frame_info *fi)
1198 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi),
1199 get_frame_base (fi),
1200 get_frame_base (fi)))
1202 return get_frame_base (fi);
1204 else if (!deprecated_inside_entry_file (get_frame_pc (fi)))
1206 return read_memory_unsigned_integer (get_frame_base (fi), 4);
1214 /* Return the saved PC (which equals the return address) of this frame. */
1217 cris_frame_saved_pc (struct frame_info *fi)
1219 return get_frame_extra_info (fi)->return_pc;
1222 /* Setup the function arguments for calling a function in the inferior. */
1225 cris_abi_original_push_arguments (int nargs, struct value **args,
1226 CORE_ADDR sp, int struct_return,
1227 CORE_ADDR struct_addr)
1238 /* Data and parameters reside in different areas on the stack.
1239 Both frame pointers grow toward higher addresses. */
1240 CORE_ADDR fp_params;
1243 /* Are we returning a value using a structure return or a normal value
1244 return? struct_addr is the address of the reserved space for the return
1245 structure to be written on the stack. */
1248 write_register (STR_REGNUM, struct_addr);
1251 /* Make sure there's space on the stack. Allocate space for data and a
1252 parameter to refer to that data. */
1253 for (argnum = 0, stack_alloc = 0; argnum < nargs; argnum++)
1254 stack_alloc += (TYPE_LENGTH (VALUE_TYPE (args[argnum])) + DEPRECATED_REGISTER_SIZE);
1256 /* We may over-allocate a little here, but that won't hurt anything. */
1258 /* Initialize stack frame pointers. */
1260 fp_data = sp + (nargs * DEPRECATED_REGISTER_SIZE);
1262 /* Now load as many as possible of the first arguments into
1263 registers, and push the rest onto the stack. */
1264 argreg = ARG1_REGNUM;
1267 for (argnum = 0; argnum < nargs; argnum++)
1269 type = VALUE_TYPE (args[argnum]);
1270 len = TYPE_LENGTH (type);
1271 val = (char *) VALUE_CONTENTS (args[argnum]);
1273 if (len <= DEPRECATED_REGISTER_SIZE && argreg <= ARG4_REGNUM)
1275 /* Data fits in a register; put it in the first available
1277 write_register (argreg, *(unsigned long *) val);
1280 else if (len > DEPRECATED_REGISTER_SIZE && argreg <= ARG4_REGNUM)
1282 /* Data does not fit in register; pass it on the stack and
1283 put its address in the first available register. */
1284 write_memory (fp_data, val, len);
1285 write_register (argreg, fp_data);
1289 else if (len > DEPRECATED_REGISTER_SIZE)
1291 /* Data does not fit in register; put both data and
1292 parameter on the stack. */
1293 write_memory (fp_data, val, len);
1294 write_memory (fp_params, (char *) (&fp_data), DEPRECATED_REGISTER_SIZE);
1296 fp_params += DEPRECATED_REGISTER_SIZE;
1300 /* Data fits in a register, but we are out of registers;
1301 put the parameter on the stack. */
1302 write_memory (fp_params, val, DEPRECATED_REGISTER_SIZE);
1303 fp_params += DEPRECATED_REGISTER_SIZE;
1311 cris_abi_v2_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
1312 int struct_return, CORE_ADDR struct_addr)
1321 /* The function's arguments and memory allocated by gdb for the arguments to
1322 point at reside in separate areas on the stack.
1323 Both frame pointers grow toward higher addresses. */
1327 /* Are we returning a value using a structure return or a normal value
1328 return? struct_addr is the address of the reserved space for the return
1329 structure to be written on the stack. */
1332 write_register (STR_REGNUM, struct_addr);
1335 /* Allocate enough to keep things word-aligned on both parts of the
1338 for (argnum = 0; argnum < nargs; argnum++)
1343 len = TYPE_LENGTH (VALUE_TYPE (args[argnum]));
1344 reg_demand = (len / DEPRECATED_REGISTER_SIZE) + (len % DEPRECATED_REGISTER_SIZE != 0 ? 1 : 0);
1346 /* reg_demand * DEPRECATED_REGISTER_SIZE is the amount of memory
1347 we might need to allocate for this argument. 2 *
1348 DEPRECATED_REGISTER_SIZE is the amount of stack space we
1349 might need to pass the argument itself (either by value or by
1351 stack_alloc += (reg_demand * DEPRECATED_REGISTER_SIZE + 2 * DEPRECATED_REGISTER_SIZE);
1354 /* We may over-allocate a little here, but that won't hurt anything. */
1356 /* Initialize frame pointers. */
1358 fp_mem = sp + (nargs * (2 * DEPRECATED_REGISTER_SIZE));
1360 /* Now load as many as possible of the first arguments into registers,
1361 and push the rest onto the stack. */
1362 argreg = ARG1_REGNUM;
1365 for (argnum = 0; argnum < nargs; argnum++)
1372 len = TYPE_LENGTH (VALUE_TYPE (args[argnum]));
1373 val = (char *) VALUE_CONTENTS (args[argnum]);
1375 /* How may registers worth of storage do we need for this argument? */
1376 reg_demand = (len / DEPRECATED_REGISTER_SIZE) + (len % DEPRECATED_REGISTER_SIZE != 0 ? 1 : 0);
1378 if (len <= (2 * DEPRECATED_REGISTER_SIZE)
1379 && (argreg + reg_demand - 1 <= ARG4_REGNUM))
1381 /* Data passed by value. Fits in available register(s). */
1382 for (i = 0; i < reg_demand; i++)
1384 write_register (argreg, *(unsigned long *) val);
1386 val += DEPRECATED_REGISTER_SIZE;
1389 else if (len <= (2 * DEPRECATED_REGISTER_SIZE) && argreg <= ARG4_REGNUM)
1391 /* Data passed by value. Does not fit in available register(s).
1392 Use the register(s) first, then the stack. */
1393 for (i = 0; i < reg_demand; i++)
1395 if (argreg <= ARG4_REGNUM)
1397 write_register (argreg, *(unsigned long *) val);
1399 val += DEPRECATED_REGISTER_SIZE;
1403 /* I guess this memory write could write the
1404 remaining data all at once instead of in
1405 DEPRECATED_REGISTER_SIZE chunks. */
1406 write_memory (fp_arg, val, DEPRECATED_REGISTER_SIZE);
1407 fp_arg += DEPRECATED_REGISTER_SIZE;
1408 val += DEPRECATED_REGISTER_SIZE;
1412 else if (len > (2 * DEPRECATED_REGISTER_SIZE))
1414 /* Data passed by reference. Put it on the stack. */
1415 write_memory (fp_mem, val, len);
1416 write_memory (fp_arg, (char *) (&fp_mem), DEPRECATED_REGISTER_SIZE);
1418 /* fp_mem need not be word-aligned since it's just a chunk of
1419 memory being pointed at. That is, += len would do. */
1420 fp_mem += reg_demand * DEPRECATED_REGISTER_SIZE;
1421 fp_arg += DEPRECATED_REGISTER_SIZE;
1425 /* Data passed by value. No available registers. Put it on
1427 write_memory (fp_arg, val, len);
1429 /* fp_arg must be word-aligned (i.e., don't += len) to match
1430 the function prologue. */
1431 fp_arg += reg_demand * DEPRECATED_REGISTER_SIZE;
1438 /* Never put the return address on the stack. The register SRP is pushed
1439 by the called function unless it is a leaf-function. Due to the BRP
1440 register the PC will change when continue is sent. */
1443 cris_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
1445 write_register (SRP_REGNUM, entry_point_address ());
1449 /* Restore the machine to the state it had before the current frame
1450 was created. Discard the innermost frame from the stack and restore
1451 all saved registers. */
1454 cris_pop_frame (void)
1456 struct frame_info *fi = get_current_frame ();
1458 int stack_offset = 0;
1460 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi),
1461 get_frame_base (fi),
1462 get_frame_base (fi)))
1464 /* This happens when we hit a breakpoint set at the entry point,
1465 when returning from a dummy frame. */
1466 generic_pop_dummy_frame ();
1470 cris_frame_init_saved_regs (fi);
1472 /* For each register, the address of where it was saved on entry to
1473 the frame now lies in fi->saved_regs[regno], or zero if it was not
1474 saved. This includes special registers such as PC and FP saved in
1475 special ways in the stack frame. The SP_REGNUM is even more
1476 special, the address here is the SP for the next frame, not the
1477 address where the SP was saved. */
1479 /* Restore general registers R0 - R7. They were pushed on the stack
1480 after SP was saved. */
1481 for (regno = 0; regno < DEPRECATED_FP_REGNUM; regno++)
1483 if (deprecated_get_frame_saved_regs (fi)[regno])
1485 write_register (regno,
1486 read_memory_integer (deprecated_get_frame_saved_regs (fi)[regno], 4));
1490 if (deprecated_get_frame_saved_regs (fi)[DEPRECATED_FP_REGNUM])
1492 /* Pop the frame pointer (R8). It was pushed before SP
1494 write_register (DEPRECATED_FP_REGNUM,
1495 read_memory_integer (deprecated_get_frame_saved_regs (fi)[DEPRECATED_FP_REGNUM], 4));
1498 /* Not a leaf function. */
1499 if (deprecated_get_frame_saved_regs (fi)[SRP_REGNUM])
1501 /* SRP was pushed before SP was saved. */
1505 /* Restore the SP and adjust for R8 and (possibly) SRP. */
1506 write_register (SP_REGNUM, deprecated_get_frame_saved_regs (fi)[DEPRECATED_FP_REGNUM] + stack_offset);
1510 /* Currently, we can't get the correct info into fi->saved_regs
1511 without a frame pointer. */
1514 /* Restore the PC. */
1515 write_register (PC_REGNUM, get_frame_extra_info (fi)->return_pc);
1517 flush_cached_frames ();
1520 /* Calculates a value that measures how good inst_args constraints an
1521 instruction. It stems from cris_constraint, found in cris-dis.c. */
1524 constraint (unsigned int insn, const signed char *inst_args,
1525 inst_env_type *inst_env)
1530 const char *s = inst_args;
1536 if ((insn & 0x30) == 0x30)
1541 /* A prefix operand. */
1542 if (inst_env->prefix_found)
1548 /* A "push" prefix. (This check was REMOVED by san 970921.) Check for
1549 valid "push" size. In case of special register, it may be != 4. */
1550 if (inst_env->prefix_found)
1556 retval = (((insn >> 0xC) & 0xF) == (insn & 0xF));
1564 tmp = (insn >> 0xC) & 0xF;
1566 for (i = 0; cris_spec_regs[i].name != NULL; i++)
1568 /* Since we match four bits, we will give a value of
1569 4 - 1 = 3 in a match. If there is a corresponding
1570 exact match of a special register in another pattern, it
1571 will get a value of 4, which will be higher. This should
1572 be correct in that an exact pattern would match better that
1574 Note that there is a reason for not returning zero; the
1575 pattern for "clear" is partly matched in the bit-pattern
1576 (the two lower bits must be zero), while the bit-pattern
1577 for a move from a special register is matched in the
1578 register constraint.
1579 This also means we will will have a race condition if
1580 there is a partly match in three bits in the bit pattern. */
1581 if (tmp == cris_spec_regs[i].number)
1588 if (cris_spec_regs[i].name == NULL)
1595 /* Returns the number of bits set in the variable value. */
1598 number_of_bits (unsigned int value)
1600 int number_of_bits = 0;
1604 number_of_bits += 1;
1605 value &= (value - 1);
1607 return number_of_bits;
1610 /* Finds the address that should contain the single step breakpoint(s).
1611 It stems from code in cris-dis.c. */
1614 find_cris_op (unsigned short insn, inst_env_type *inst_env)
1617 int max_level_of_match = -1;
1618 int max_matched = -1;
1621 for (i = 0; cris_opcodes[i].name != NULL; i++)
1623 if (((cris_opcodes[i].match & insn) == cris_opcodes[i].match)
1624 && ((cris_opcodes[i].lose & insn) == 0))
1626 level_of_match = constraint (insn, cris_opcodes[i].args, inst_env);
1627 if (level_of_match >= 0)
1630 number_of_bits (cris_opcodes[i].match | cris_opcodes[i].lose);
1631 if (level_of_match > max_level_of_match)
1634 max_level_of_match = level_of_match;
1635 if (level_of_match == 16)
1637 /* All bits matched, cannot find better. */
1647 /* Attempts to find single-step breakpoints. Returns -1 on failure which is
1648 actually an internal error. */
1651 find_step_target (inst_env_type *inst_env)
1655 unsigned short insn;
1657 /* Create a local register image and set the initial state. */
1658 for (i = 0; i < NUM_GENREGS; i++)
1660 inst_env->reg[i] = (unsigned long) read_register (i);
1662 offset = NUM_GENREGS;
1663 for (i = 0; i < NUM_SPECREGS; i++)
1665 inst_env->preg[i] = (unsigned long) read_register (offset + i);
1667 inst_env->branch_found = 0;
1668 inst_env->slot_needed = 0;
1669 inst_env->delay_slot_pc_active = 0;
1670 inst_env->prefix_found = 0;
1671 inst_env->invalid = 0;
1672 inst_env->xflag_found = 0;
1673 inst_env->disable_interrupt = 0;
1675 /* Look for a step target. */
1678 /* Read an instruction from the client. */
1679 insn = read_memory_unsigned_integer (inst_env->reg[PC_REGNUM], 2);
1681 /* If the instruction is not in a delay slot the new content of the
1682 PC is [PC] + 2. If the instruction is in a delay slot it is not
1683 that simple. Since a instruction in a delay slot cannot change
1684 the content of the PC, it does not matter what value PC will have.
1685 Just make sure it is a valid instruction. */
1686 if (!inst_env->delay_slot_pc_active)
1688 inst_env->reg[PC_REGNUM] += 2;
1692 inst_env->delay_slot_pc_active = 0;
1693 inst_env->reg[PC_REGNUM] = inst_env->delay_slot_pc;
1695 /* Analyse the present instruction. */
1696 i = find_cris_op (insn, inst_env);
1699 inst_env->invalid = 1;
1703 cris_gdb_func (cris_opcodes[i].op, insn, inst_env);
1705 } while (!inst_env->invalid
1706 && (inst_env->prefix_found || inst_env->xflag_found
1707 || inst_env->slot_needed));
1711 /* There is no hardware single-step support. The function find_step_target
1712 digs through the opcodes in order to find all possible targets.
1713 Either one ordinary target or two targets for branches may be found. */
1716 cris_software_single_step (enum target_signal ignore, int insert_breakpoints)
1718 inst_env_type inst_env;
1720 if (insert_breakpoints)
1722 /* Analyse the present instruction environment and insert
1724 int status = find_step_target (&inst_env);
1727 /* Could not find a target. FIXME: Should do something. */
1731 /* Insert at most two breakpoints. One for the next PC content
1732 and possibly another one for a branch, jump, etc. */
1733 next_pc = (CORE_ADDR) inst_env.reg[PC_REGNUM];
1734 target_insert_breakpoint (next_pc, break_mem[0]);
1735 if (inst_env.branch_found
1736 && (CORE_ADDR) inst_env.branch_break_address != next_pc)
1738 branch_target_address =
1739 (CORE_ADDR) inst_env.branch_break_address;
1740 target_insert_breakpoint (branch_target_address, break_mem[1]);
1741 branch_break_inserted = 1;
1747 /* Remove breakpoints. */
1748 target_remove_breakpoint (next_pc, break_mem[0]);
1749 if (branch_break_inserted)
1751 target_remove_breakpoint (branch_target_address, break_mem[1]);
1752 branch_break_inserted = 0;
1757 /* Calculates the prefix value for quick offset addressing mode. */
1760 quick_mode_bdap_prefix (unsigned short inst, inst_env_type *inst_env)
1762 /* It's invalid to be in a delay slot. You can't have a prefix to this
1763 instruction (not 100% sure). */
1764 if (inst_env->slot_needed || inst_env->prefix_found)
1766 inst_env->invalid = 1;
1770 inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)];
1771 inst_env->prefix_value += cris_get_bdap_quick_offset (inst);
1773 /* A prefix doesn't change the xflag_found. But the rest of the flags
1775 inst_env->slot_needed = 0;
1776 inst_env->prefix_found = 1;
1779 /* Updates the autoincrement register. The size of the increment is derived
1780 from the size of the operation. The PC is always kept aligned on even
1784 process_autoincrement (int size, unsigned short inst, inst_env_type *inst_env)
1786 if (size == INST_BYTE_SIZE)
1788 inst_env->reg[cris_get_operand1 (inst)] += 1;
1790 /* The PC must be word aligned, so increase the PC with one
1791 word even if the size is byte. */
1792 if (cris_get_operand1 (inst) == REG_PC)
1794 inst_env->reg[REG_PC] += 1;
1797 else if (size == INST_WORD_SIZE)
1799 inst_env->reg[cris_get_operand1 (inst)] += 2;
1801 else if (size == INST_DWORD_SIZE)
1803 inst_env->reg[cris_get_operand1 (inst)] += 4;
1808 inst_env->invalid = 1;
1812 /* Just a forward declaration. */
1814 static unsigned long get_data_from_address (unsigned short *inst,
1817 /* Calculates the prefix value for the general case of offset addressing
1821 bdap_prefix (unsigned short inst, inst_env_type *inst_env)
1826 /* It's invalid to be in a delay slot. */
1827 if (inst_env->slot_needed || inst_env->prefix_found)
1829 inst_env->invalid = 1;
1833 /* The calculation of prefix_value used to be after process_autoincrement,
1834 but that fails for an instruction such as jsr [$r0+12] which is encoded
1835 as 5f0d 0c00 30b9 when compiled with -fpic. Since PC is operand1 it
1836 mustn't be incremented until we have read it and what it points at. */
1837 inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)];
1839 /* The offset is an indirection of the contents of the operand1 register. */
1840 inst_env->prefix_value +=
1841 get_data_from_address (&inst, inst_env->reg[cris_get_operand1 (inst)]);
1843 if (cris_get_mode (inst) == AUTOINC_MODE)
1845 process_autoincrement (cris_get_size (inst), inst, inst_env);
1848 /* A prefix doesn't change the xflag_found. But the rest of the flags
1850 inst_env->slot_needed = 0;
1851 inst_env->prefix_found = 1;
1854 /* Calculates the prefix value for the index addressing mode. */
1857 biap_prefix (unsigned short inst, inst_env_type *inst_env)
1859 /* It's invalid to be in a delay slot. I can't see that it's possible to
1860 have a prefix to this instruction. So I will treat this as invalid. */
1861 if (inst_env->slot_needed || inst_env->prefix_found)
1863 inst_env->invalid = 1;
1867 inst_env->prefix_value = inst_env->reg[cris_get_operand1 (inst)];
1869 /* The offset is the operand2 value shifted the size of the instruction
1871 inst_env->prefix_value +=
1872 inst_env->reg[cris_get_operand2 (inst)] << cris_get_size (inst);
1874 /* If the PC is operand1 (base) the address used is the address after
1875 the main instruction, i.e. address + 2 (the PC is already compensated
1876 for the prefix operation). */
1877 if (cris_get_operand1 (inst) == REG_PC)
1879 inst_env->prefix_value += 2;
1882 /* A prefix doesn't change the xflag_found. But the rest of the flags
1884 inst_env->slot_needed = 0;
1885 inst_env->xflag_found = 0;
1886 inst_env->prefix_found = 1;
1889 /* Calculates the prefix value for the double indirect addressing mode. */
1892 dip_prefix (unsigned short inst, inst_env_type *inst_env)
1897 /* It's invalid to be in a delay slot. */
1898 if (inst_env->slot_needed || inst_env->prefix_found)
1900 inst_env->invalid = 1;
1904 /* The prefix value is one dereference of the contents of the operand1
1906 address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)];
1907 inst_env->prefix_value = read_memory_unsigned_integer (address, 4);
1909 /* Check if the mode is autoincrement. */
1910 if (cris_get_mode (inst) == AUTOINC_MODE)
1912 inst_env->reg[cris_get_operand1 (inst)] += 4;
1915 /* A prefix doesn't change the xflag_found. But the rest of the flags
1917 inst_env->slot_needed = 0;
1918 inst_env->xflag_found = 0;
1919 inst_env->prefix_found = 1;
1922 /* Finds the destination for a branch with 8-bits offset. */
1925 eight_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env)
1930 /* If we have a prefix or are in a delay slot it's bad. */
1931 if (inst_env->slot_needed || inst_env->prefix_found)
1933 inst_env->invalid = 1;
1937 /* We have a branch, find out where the branch will land. */
1938 offset = cris_get_branch_short_offset (inst);
1940 /* Check if the offset is signed. */
1941 if (offset & BRANCH_SIGNED_SHORT_OFFSET_MASK)
1946 /* The offset ends with the sign bit, set it to zero. The address
1947 should always be word aligned. */
1948 offset &= ~BRANCH_SIGNED_SHORT_OFFSET_MASK;
1950 inst_env->branch_found = 1;
1951 inst_env->branch_break_address = inst_env->reg[REG_PC] + offset;
1953 inst_env->slot_needed = 1;
1954 inst_env->prefix_found = 0;
1955 inst_env->xflag_found = 0;
1956 inst_env->disable_interrupt = 1;
1959 /* Finds the destination for a branch with 16-bits offset. */
1962 sixteen_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env)
1966 /* If we have a prefix or is in a delay slot it's bad. */
1967 if (inst_env->slot_needed || inst_env->prefix_found)
1969 inst_env->invalid = 1;
1973 /* We have a branch, find out the offset for the branch. */
1974 offset = read_memory_integer (inst_env->reg[REG_PC], 2);
1976 /* The instruction is one word longer than normal, so add one word
1978 inst_env->reg[REG_PC] += 2;
1980 inst_env->branch_found = 1;
1981 inst_env->branch_break_address = inst_env->reg[REG_PC] + offset;
1984 inst_env->slot_needed = 1;
1985 inst_env->prefix_found = 0;
1986 inst_env->xflag_found = 0;
1987 inst_env->disable_interrupt = 1;
1990 /* Handles the ABS instruction. */
1993 abs_op (unsigned short inst, inst_env_type *inst_env)
1998 /* ABS can't have a prefix, so it's bad if it does. */
1999 if (inst_env->prefix_found)
2001 inst_env->invalid = 1;
2005 /* Check if the operation affects the PC. */
2006 if (cris_get_operand2 (inst) == REG_PC)
2009 /* It's invalid to change to the PC if we are in a delay slot. */
2010 if (inst_env->slot_needed)
2012 inst_env->invalid = 1;
2016 value = (long) inst_env->reg[REG_PC];
2018 /* The value of abs (SIGNED_DWORD_MASK) is SIGNED_DWORD_MASK. */
2019 if (value != SIGNED_DWORD_MASK)
2022 inst_env->reg[REG_PC] = (long) value;
2026 inst_env->slot_needed = 0;
2027 inst_env->prefix_found = 0;
2028 inst_env->xflag_found = 0;
2029 inst_env->disable_interrupt = 0;
2032 /* Handles the ADDI instruction. */
2035 addi_op (unsigned short inst, inst_env_type *inst_env)
2037 /* It's invalid to have the PC as base register. And ADDI can't have
2039 if (inst_env->prefix_found || (cris_get_operand1 (inst) == REG_PC))
2041 inst_env->invalid = 1;
2045 inst_env->slot_needed = 0;
2046 inst_env->prefix_found = 0;
2047 inst_env->xflag_found = 0;
2048 inst_env->disable_interrupt = 0;
2051 /* Handles the ASR instruction. */
2054 asr_op (unsigned short inst, inst_env_type *inst_env)
2057 unsigned long value;
2058 unsigned long signed_extend_mask = 0;
2060 /* ASR can't have a prefix, so check that it doesn't. */
2061 if (inst_env->prefix_found)
2063 inst_env->invalid = 1;
2067 /* Check if the PC is the target register. */
2068 if (cris_get_operand2 (inst) == REG_PC)
2070 /* It's invalid to change the PC in a delay slot. */
2071 if (inst_env->slot_needed)
2073 inst_env->invalid = 1;
2076 /* Get the number of bits to shift. */
2077 shift_steps = cris_get_asr_shift_steps (inst_env->reg[cris_get_operand1 (inst)]);
2078 value = inst_env->reg[REG_PC];
2080 /* Find out how many bits the operation should apply to. */
2081 if (cris_get_size (inst) == INST_BYTE_SIZE)
2083 if (value & SIGNED_BYTE_MASK)
2085 signed_extend_mask = 0xFF;
2086 signed_extend_mask = signed_extend_mask >> shift_steps;
2087 signed_extend_mask = ~signed_extend_mask;
2089 value = value >> shift_steps;
2090 value |= signed_extend_mask;
2092 inst_env->reg[REG_PC] &= 0xFFFFFF00;
2093 inst_env->reg[REG_PC] |= value;
2095 else if (cris_get_size (inst) == INST_WORD_SIZE)
2097 if (value & SIGNED_WORD_MASK)
2099 signed_extend_mask = 0xFFFF;
2100 signed_extend_mask = signed_extend_mask >> shift_steps;
2101 signed_extend_mask = ~signed_extend_mask;
2103 value = value >> shift_steps;
2104 value |= signed_extend_mask;
2106 inst_env->reg[REG_PC] &= 0xFFFF0000;
2107 inst_env->reg[REG_PC] |= value;
2109 else if (cris_get_size (inst) == INST_DWORD_SIZE)
2111 if (value & SIGNED_DWORD_MASK)
2113 signed_extend_mask = 0xFFFFFFFF;
2114 signed_extend_mask = signed_extend_mask >> shift_steps;
2115 signed_extend_mask = ~signed_extend_mask;
2117 value = value >> shift_steps;
2118 value |= signed_extend_mask;
2119 inst_env->reg[REG_PC] = value;
2122 inst_env->slot_needed = 0;
2123 inst_env->prefix_found = 0;
2124 inst_env->xflag_found = 0;
2125 inst_env->disable_interrupt = 0;
2128 /* Handles the ASRQ instruction. */
2131 asrq_op (unsigned short inst, inst_env_type *inst_env)
2135 unsigned long value;
2136 unsigned long signed_extend_mask = 0;
2138 /* ASRQ can't have a prefix, so check that it doesn't. */
2139 if (inst_env->prefix_found)
2141 inst_env->invalid = 1;
2145 /* Check if the PC is the target register. */
2146 if (cris_get_operand2 (inst) == REG_PC)
2149 /* It's invalid to change the PC in a delay slot. */
2150 if (inst_env->slot_needed)
2152 inst_env->invalid = 1;
2155 /* The shift size is given as a 5 bit quick value, i.e. we don't
2156 want the the sign bit of the quick value. */
2157 shift_steps = cris_get_asr_shift_steps (inst);
2158 value = inst_env->reg[REG_PC];
2159 if (value & SIGNED_DWORD_MASK)
2161 signed_extend_mask = 0xFFFFFFFF;
2162 signed_extend_mask = signed_extend_mask >> shift_steps;
2163 signed_extend_mask = ~signed_extend_mask;
2165 value = value >> shift_steps;
2166 value |= signed_extend_mask;
2167 inst_env->reg[REG_PC] = value;
2169 inst_env->slot_needed = 0;
2170 inst_env->prefix_found = 0;
2171 inst_env->xflag_found = 0;
2172 inst_env->disable_interrupt = 0;
2175 /* Handles the AX, EI and SETF instruction. */
2178 ax_ei_setf_op (unsigned short inst, inst_env_type *inst_env)
2180 if (inst_env->prefix_found)
2182 inst_env->invalid = 1;
2185 /* Check if the instruction is setting the X flag. */
2186 if (cris_is_xflag_bit_on (inst))
2188 inst_env->xflag_found = 1;
2192 inst_env->xflag_found = 0;
2194 inst_env->slot_needed = 0;
2195 inst_env->prefix_found = 0;
2196 inst_env->disable_interrupt = 1;
2199 /* Checks if the instruction is in assign mode. If so, it updates the assign
2200 register. Note that check_assign assumes that the caller has checked that
2201 there is a prefix to this instruction. The mode check depends on this. */
2204 check_assign (unsigned short inst, inst_env_type *inst_env)
2206 /* Check if it's an assign addressing mode. */
2207 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2209 /* Assign the prefix value to operand 1. */
2210 inst_env->reg[cris_get_operand1 (inst)] = inst_env->prefix_value;
2214 /* Handles the 2-operand BOUND instruction. */
2217 two_operand_bound_op (unsigned short inst, inst_env_type *inst_env)
2219 /* It's invalid to have the PC as the index operand. */
2220 if (cris_get_operand2 (inst) == REG_PC)
2222 inst_env->invalid = 1;
2225 /* Check if we have a prefix. */
2226 if (inst_env->prefix_found)
2228 check_assign (inst, inst_env);
2230 /* Check if this is an autoincrement mode. */
2231 else if (cris_get_mode (inst) == AUTOINC_MODE)
2233 /* It's invalid to change the PC in a delay slot. */
2234 if (inst_env->slot_needed)
2236 inst_env->invalid = 1;
2239 process_autoincrement (cris_get_size (inst), inst, inst_env);
2241 inst_env->slot_needed = 0;
2242 inst_env->prefix_found = 0;
2243 inst_env->xflag_found = 0;
2244 inst_env->disable_interrupt = 0;
2247 /* Handles the 3-operand BOUND instruction. */
2250 three_operand_bound_op (unsigned short inst, inst_env_type *inst_env)
2252 /* It's an error if we haven't got a prefix. And it's also an error
2253 if the PC is the destination register. */
2254 if ((!inst_env->prefix_found) || (cris_get_operand1 (inst) == REG_PC))
2256 inst_env->invalid = 1;
2259 inst_env->slot_needed = 0;
2260 inst_env->prefix_found = 0;
2261 inst_env->xflag_found = 0;
2262 inst_env->disable_interrupt = 0;
2265 /* Clears the status flags in inst_env. */
2268 btst_nop_op (unsigned short inst, inst_env_type *inst_env)
2270 /* It's an error if we have got a prefix. */
2271 if (inst_env->prefix_found)
2273 inst_env->invalid = 1;
2277 inst_env->slot_needed = 0;
2278 inst_env->prefix_found = 0;
2279 inst_env->xflag_found = 0;
2280 inst_env->disable_interrupt = 0;
2283 /* Clears the status flags in inst_env. */
2286 clearf_di_op (unsigned short inst, inst_env_type *inst_env)
2288 /* It's an error if we have got a prefix. */
2289 if (inst_env->prefix_found)
2291 inst_env->invalid = 1;
2295 inst_env->slot_needed = 0;
2296 inst_env->prefix_found = 0;
2297 inst_env->xflag_found = 0;
2298 inst_env->disable_interrupt = 1;
2301 /* Handles the CLEAR instruction if it's in register mode. */
2304 reg_mode_clear_op (unsigned short inst, inst_env_type *inst_env)
2306 /* Check if the target is the PC. */
2307 if (cris_get_operand2 (inst) == REG_PC)
2309 /* The instruction will clear the instruction's size bits. */
2310 int clear_size = cris_get_clear_size (inst);
2311 if (clear_size == INST_BYTE_SIZE)
2313 inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFFFF00;
2315 if (clear_size == INST_WORD_SIZE)
2317 inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFF0000;
2319 if (clear_size == INST_DWORD_SIZE)
2321 inst_env->delay_slot_pc = 0x0;
2323 /* The jump will be delayed with one delay slot. So we need a delay
2325 inst_env->slot_needed = 1;
2326 inst_env->delay_slot_pc_active = 1;
2330 /* The PC will not change => no delay slot. */
2331 inst_env->slot_needed = 0;
2333 inst_env->prefix_found = 0;
2334 inst_env->xflag_found = 0;
2335 inst_env->disable_interrupt = 0;
2338 /* Handles the TEST instruction if it's in register mode. */
2341 reg_mode_test_op (unsigned short inst, inst_env_type *inst_env)
2343 /* It's an error if we have got a prefix. */
2344 if (inst_env->prefix_found)
2346 inst_env->invalid = 1;
2349 inst_env->slot_needed = 0;
2350 inst_env->prefix_found = 0;
2351 inst_env->xflag_found = 0;
2352 inst_env->disable_interrupt = 0;
2356 /* Handles the CLEAR and TEST instruction if the instruction isn't
2357 in register mode. */
2360 none_reg_mode_clear_test_op (unsigned short inst, inst_env_type *inst_env)
2362 /* Check if we are in a prefix mode. */
2363 if (inst_env->prefix_found)
2365 /* The only way the PC can change is if this instruction is in
2366 assign addressing mode. */
2367 check_assign (inst, inst_env);
2369 /* Indirect mode can't change the PC so just check if the mode is
2371 else if (cris_get_mode (inst) == AUTOINC_MODE)
2373 process_autoincrement (cris_get_size (inst), inst, inst_env);
2375 inst_env->slot_needed = 0;
2376 inst_env->prefix_found = 0;
2377 inst_env->xflag_found = 0;
2378 inst_env->disable_interrupt = 0;
2381 /* Checks that the PC isn't the destination register or the instructions has
2385 dstep_logshift_mstep_neg_not_op (unsigned short inst, inst_env_type *inst_env)
2387 /* It's invalid to have the PC as the destination. The instruction can't
2389 if ((cris_get_operand2 (inst) == REG_PC) || inst_env->prefix_found)
2391 inst_env->invalid = 1;
2395 inst_env->slot_needed = 0;
2396 inst_env->prefix_found = 0;
2397 inst_env->xflag_found = 0;
2398 inst_env->disable_interrupt = 0;
2401 /* Checks that the instruction doesn't have a prefix. */
2404 break_op (unsigned short inst, inst_env_type *inst_env)
2406 /* The instruction can't have a prefix. */
2407 if (inst_env->prefix_found)
2409 inst_env->invalid = 1;
2413 inst_env->slot_needed = 0;
2414 inst_env->prefix_found = 0;
2415 inst_env->xflag_found = 0;
2416 inst_env->disable_interrupt = 1;
2419 /* Checks that the PC isn't the destination register and that the instruction
2420 doesn't have a prefix. */
2423 scc_op (unsigned short inst, inst_env_type *inst_env)
2425 /* It's invalid to have the PC as the destination. The instruction can't
2427 if ((cris_get_operand2 (inst) == REG_PC) || inst_env->prefix_found)
2429 inst_env->invalid = 1;
2433 inst_env->slot_needed = 0;
2434 inst_env->prefix_found = 0;
2435 inst_env->xflag_found = 0;
2436 inst_env->disable_interrupt = 1;
2439 /* Handles the register mode JUMP instruction. */
2442 reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env)
2444 /* It's invalid to do a JUMP in a delay slot. The mode is register, so
2445 you can't have a prefix. */
2446 if ((inst_env->slot_needed) || (inst_env->prefix_found))
2448 inst_env->invalid = 1;
2452 /* Just change the PC. */
2453 inst_env->reg[REG_PC] = inst_env->reg[cris_get_operand1 (inst)];
2454 inst_env->slot_needed = 0;
2455 inst_env->prefix_found = 0;
2456 inst_env->xflag_found = 0;
2457 inst_env->disable_interrupt = 1;
2460 /* Handles the JUMP instruction for all modes except register. */
2463 none_reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env)
2465 unsigned long newpc;
2468 /* It's invalid to do a JUMP in a delay slot. */
2469 if (inst_env->slot_needed)
2471 inst_env->invalid = 1;
2475 /* Check if we have a prefix. */
2476 if (inst_env->prefix_found)
2478 check_assign (inst, inst_env);
2480 /* Get the new value for the the PC. */
2482 read_memory_unsigned_integer ((CORE_ADDR) inst_env->prefix_value,
2487 /* Get the new value for the PC. */
2488 address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)];
2489 newpc = read_memory_unsigned_integer (address, 4);
2491 /* Check if we should increment a register. */
2492 if (cris_get_mode (inst) == AUTOINC_MODE)
2494 inst_env->reg[cris_get_operand1 (inst)] += 4;
2497 inst_env->reg[REG_PC] = newpc;
2499 inst_env->slot_needed = 0;
2500 inst_env->prefix_found = 0;
2501 inst_env->xflag_found = 0;
2502 inst_env->disable_interrupt = 1;
2505 /* Handles moves to special registers (aka P-register) for all modes. */
2508 move_to_preg_op (unsigned short inst, inst_env_type *inst_env)
2510 if (inst_env->prefix_found)
2512 /* The instruction has a prefix that means we are only interested if
2513 the instruction is in assign mode. */
2514 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2516 /* The prefix handles the problem if we are in a delay slot. */
2517 if (cris_get_operand1 (inst) == REG_PC)
2519 /* Just take care of the assign. */
2520 check_assign (inst, inst_env);
2524 else if (cris_get_mode (inst) == AUTOINC_MODE)
2526 /* The instruction doesn't have a prefix, the only case left that we
2527 are interested in is the autoincrement mode. */
2528 if (cris_get_operand1 (inst) == REG_PC)
2530 /* If the PC is to be incremented it's invalid to be in a
2532 if (inst_env->slot_needed)
2534 inst_env->invalid = 1;
2538 /* The increment depends on the size of the special register. */
2539 if (cris_register_size (cris_get_operand2 (inst)) == 1)
2541 process_autoincrement (INST_BYTE_SIZE, inst, inst_env);
2543 else if (cris_register_size (cris_get_operand2 (inst)) == 2)
2545 process_autoincrement (INST_WORD_SIZE, inst, inst_env);
2549 process_autoincrement (INST_DWORD_SIZE, inst, inst_env);
2553 inst_env->slot_needed = 0;
2554 inst_env->prefix_found = 0;
2555 inst_env->xflag_found = 0;
2556 inst_env->disable_interrupt = 1;
2559 /* Handles moves from special registers (aka P-register) for all modes
2563 none_reg_mode_move_from_preg_op (unsigned short inst, inst_env_type *inst_env)
2565 if (inst_env->prefix_found)
2567 /* The instruction has a prefix that means we are only interested if
2568 the instruction is in assign mode. */
2569 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2571 /* The prefix handles the problem if we are in a delay slot. */
2572 if (cris_get_operand1 (inst) == REG_PC)
2574 /* Just take care of the assign. */
2575 check_assign (inst, inst_env);
2579 /* The instruction doesn't have a prefix, the only case left that we
2580 are interested in is the autoincrement mode. */
2581 else if (cris_get_mode (inst) == AUTOINC_MODE)
2583 if (cris_get_operand1 (inst) == REG_PC)
2585 /* If the PC is to be incremented it's invalid to be in a
2587 if (inst_env->slot_needed)
2589 inst_env->invalid = 1;
2593 /* The increment depends on the size of the special register. */
2594 if (cris_register_size (cris_get_operand2 (inst)) == 1)
2596 process_autoincrement (INST_BYTE_SIZE, inst, inst_env);
2598 else if (cris_register_size (cris_get_operand2 (inst)) == 2)
2600 process_autoincrement (INST_WORD_SIZE, inst, inst_env);
2604 process_autoincrement (INST_DWORD_SIZE, inst, inst_env);
2608 inst_env->slot_needed = 0;
2609 inst_env->prefix_found = 0;
2610 inst_env->xflag_found = 0;
2611 inst_env->disable_interrupt = 1;
2614 /* Handles moves from special registers (aka P-register) when the mode
2618 reg_mode_move_from_preg_op (unsigned short inst, inst_env_type *inst_env)
2620 /* Register mode move from special register can't have a prefix. */
2621 if (inst_env->prefix_found)
2623 inst_env->invalid = 1;
2627 if (cris_get_operand1 (inst) == REG_PC)
2629 /* It's invalid to change the PC in a delay slot. */
2630 if (inst_env->slot_needed)
2632 inst_env->invalid = 1;
2635 /* The destination is the PC, the jump will have a delay slot. */
2636 inst_env->delay_slot_pc = inst_env->preg[cris_get_operand2 (inst)];
2637 inst_env->slot_needed = 1;
2638 inst_env->delay_slot_pc_active = 1;
2642 /* If the destination isn't PC, there will be no jump. */
2643 inst_env->slot_needed = 0;
2645 inst_env->prefix_found = 0;
2646 inst_env->xflag_found = 0;
2647 inst_env->disable_interrupt = 1;
2650 /* Handles the MOVEM from memory to general register instruction. */
2653 move_mem_to_reg_movem_op (unsigned short inst, inst_env_type *inst_env)
2655 if (inst_env->prefix_found)
2657 /* The prefix handles the problem if we are in a delay slot. Is the
2658 MOVEM instruction going to change the PC? */
2659 if (cris_get_operand2 (inst) >= REG_PC)
2661 inst_env->reg[REG_PC] =
2662 read_memory_unsigned_integer (inst_env->prefix_value, 4);
2664 /* The assign value is the value after the increment. Normally, the
2665 assign value is the value before the increment. */
2666 if ((cris_get_operand1 (inst) == REG_PC)
2667 && (cris_get_mode (inst) == PREFIX_ASSIGN_MODE))
2669 inst_env->reg[REG_PC] = inst_env->prefix_value;
2670 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
2675 /* Is the MOVEM instruction going to change the PC? */
2676 if (cris_get_operand2 (inst) == REG_PC)
2678 /* It's invalid to change the PC in a delay slot. */
2679 if (inst_env->slot_needed)
2681 inst_env->invalid = 1;
2684 inst_env->reg[REG_PC] =
2685 read_memory_unsigned_integer (inst_env->reg[cris_get_operand1 (inst)],
2688 /* The increment is not depending on the size, instead it's depending
2689 on the number of registers loaded from memory. */
2690 if ((cris_get_operand1 (inst) == REG_PC) && (cris_get_mode (inst) == AUTOINC_MODE))
2692 /* It's invalid to change the PC in a delay slot. */
2693 if (inst_env->slot_needed)
2695 inst_env->invalid = 1;
2698 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
2701 inst_env->slot_needed = 0;
2702 inst_env->prefix_found = 0;
2703 inst_env->xflag_found = 0;
2704 inst_env->disable_interrupt = 0;
2707 /* Handles the MOVEM to memory from general register instruction. */
2710 move_reg_to_mem_movem_op (unsigned short inst, inst_env_type *inst_env)
2712 if (inst_env->prefix_found)
2714 /* The assign value is the value after the increment. Normally, the
2715 assign value is the value before the increment. */
2716 if ((cris_get_operand1 (inst) == REG_PC) &&
2717 (cris_get_mode (inst) == PREFIX_ASSIGN_MODE))
2719 /* The prefix handles the problem if we are in a delay slot. */
2720 inst_env->reg[REG_PC] = inst_env->prefix_value;
2721 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
2726 /* The increment is not depending on the size, instead it's depending
2727 on the number of registers loaded to memory. */
2728 if ((cris_get_operand1 (inst) == REG_PC) && (cris_get_mode (inst) == AUTOINC_MODE))
2730 /* It's invalid to change the PC in a delay slot. */
2731 if (inst_env->slot_needed)
2733 inst_env->invalid = 1;
2736 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
2739 inst_env->slot_needed = 0;
2740 inst_env->prefix_found = 0;
2741 inst_env->xflag_found = 0;
2742 inst_env->disable_interrupt = 0;
2745 /* Handles the intructions that's not yet implemented, by setting
2746 inst_env->invalid to true. */
2749 not_implemented_op (unsigned short inst, inst_env_type *inst_env)
2751 inst_env->invalid = 1;
2754 /* Handles the XOR instruction. */
2757 xor_op (unsigned short inst, inst_env_type *inst_env)
2759 /* XOR can't have a prefix. */
2760 if (inst_env->prefix_found)
2762 inst_env->invalid = 1;
2766 /* Check if the PC is the target. */
2767 if (cris_get_operand2 (inst) == REG_PC)
2769 /* It's invalid to change the PC in a delay slot. */
2770 if (inst_env->slot_needed)
2772 inst_env->invalid = 1;
2775 inst_env->reg[REG_PC] ^= inst_env->reg[cris_get_operand1 (inst)];
2777 inst_env->slot_needed = 0;
2778 inst_env->prefix_found = 0;
2779 inst_env->xflag_found = 0;
2780 inst_env->disable_interrupt = 0;
2783 /* Handles the MULS instruction. */
2786 muls_op (unsigned short inst, inst_env_type *inst_env)
2788 /* MULS/U can't have a prefix. */
2789 if (inst_env->prefix_found)
2791 inst_env->invalid = 1;
2795 /* Consider it invalid if the PC is the target. */
2796 if (cris_get_operand2 (inst) == REG_PC)
2798 inst_env->invalid = 1;
2801 inst_env->slot_needed = 0;
2802 inst_env->prefix_found = 0;
2803 inst_env->xflag_found = 0;
2804 inst_env->disable_interrupt = 0;
2807 /* Handles the MULU instruction. */
2810 mulu_op (unsigned short inst, inst_env_type *inst_env)
2812 /* MULS/U can't have a prefix. */
2813 if (inst_env->prefix_found)
2815 inst_env->invalid = 1;
2819 /* Consider it invalid if the PC is the target. */
2820 if (cris_get_operand2 (inst) == REG_PC)
2822 inst_env->invalid = 1;
2825 inst_env->slot_needed = 0;
2826 inst_env->prefix_found = 0;
2827 inst_env->xflag_found = 0;
2828 inst_env->disable_interrupt = 0;
2831 /* Calculate the result of the instruction for ADD, SUB, CMP AND, OR and MOVE.
2832 The MOVE instruction is the move from source to register. */
2835 add_sub_cmp_and_or_move_action (unsigned short inst, inst_env_type *inst_env,
2836 unsigned long source1, unsigned long source2)
2838 unsigned long pc_mask;
2839 unsigned long operation_mask;
2841 /* Find out how many bits the operation should apply to. */
2842 if (cris_get_size (inst) == INST_BYTE_SIZE)
2844 pc_mask = 0xFFFFFF00;
2845 operation_mask = 0xFF;
2847 else if (cris_get_size (inst) == INST_WORD_SIZE)
2849 pc_mask = 0xFFFF0000;
2850 operation_mask = 0xFFFF;
2852 else if (cris_get_size (inst) == INST_DWORD_SIZE)
2855 operation_mask = 0xFFFFFFFF;
2859 /* The size is out of range. */
2860 inst_env->invalid = 1;
2864 /* The instruction just works on uw_operation_mask bits. */
2865 source2 &= operation_mask;
2866 source1 &= operation_mask;
2868 /* Now calculate the result. The opcode's 3 first bits separates
2869 the different actions. */
2870 switch (cris_get_opcode (inst) & 7)
2880 case 2: /* subtract */
2884 case 3: /* compare */
2896 inst_env->invalid = 1;
2902 /* Make sure that the result doesn't contain more than the instruction
2904 source2 &= operation_mask;
2906 /* Calculate the new breakpoint address. */
2907 inst_env->reg[REG_PC] &= pc_mask;
2908 inst_env->reg[REG_PC] |= source1;
2912 /* Extends the value from either byte or word size to a dword. If the mode
2913 is zero extend then the value is extended with zero. If instead the mode
2914 is signed extend the sign bit of the value is taken into consideration. */
2916 static unsigned long
2917 do_sign_or_zero_extend (unsigned long value, unsigned short *inst)
2919 /* The size can be either byte or word, check which one it is.
2920 Don't check the highest bit, it's indicating if it's a zero
2922 if (cris_get_size (*inst) & INST_WORD_SIZE)
2927 /* Check if the instruction is signed extend. If so, check if value has
2929 if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_WORD_MASK))
2931 value |= SIGNED_WORD_EXTEND_MASK;
2939 /* Check if the instruction is signed extend. If so, check if value has
2941 if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_BYTE_MASK))
2943 value |= SIGNED_BYTE_EXTEND_MASK;
2946 /* The size should now be dword. */
2947 cris_set_size_to_dword (inst);
2951 /* Handles the register mode for the ADD, SUB, CMP, AND, OR and MOVE
2952 instruction. The MOVE instruction is the move from source to register. */
2955 reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst,
2956 inst_env_type *inst_env)
2958 unsigned long operand1;
2959 unsigned long operand2;
2961 /* It's invalid to have a prefix to the instruction. This is a register
2962 mode instruction and can't have a prefix. */
2963 if (inst_env->prefix_found)
2965 inst_env->invalid = 1;
2968 /* Check if the instruction has PC as its target. */
2969 if (cris_get_operand2 (inst) == REG_PC)
2971 if (inst_env->slot_needed)
2973 inst_env->invalid = 1;
2976 /* The instruction has the PC as its target register. */
2977 operand1 = inst_env->reg[cris_get_operand1 (inst)];
2978 operand2 = inst_env->reg[REG_PC];
2980 /* Check if it's a extend, signed or zero instruction. */
2981 if (cris_get_opcode (inst) < 4)
2983 operand1 = do_sign_or_zero_extend (operand1, &inst);
2985 /* Calculate the PC value after the instruction, i.e. where the
2986 breakpoint should be. The order of the udw_operands is vital. */
2987 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
2989 inst_env->slot_needed = 0;
2990 inst_env->prefix_found = 0;
2991 inst_env->xflag_found = 0;
2992 inst_env->disable_interrupt = 0;
2995 /* Returns the data contained at address. The size of the data is derived from
2996 the size of the operation. If the instruction is a zero or signed
2997 extend instruction, the size field is changed in instruction. */
2999 static unsigned long
3000 get_data_from_address (unsigned short *inst, CORE_ADDR address)
3002 int size = cris_get_size (*inst);
3003 unsigned long value;
3005 /* If it's an extend instruction we don't want the signed extend bit,
3006 because it influences the size. */
3007 if (cris_get_opcode (*inst) < 4)
3009 size &= ~SIGNED_EXTEND_BIT_MASK;
3011 /* Is there a need for checking the size? Size should contain the number of
3014 value = read_memory_unsigned_integer (address, size);
3016 /* Check if it's an extend, signed or zero instruction. */
3017 if (cris_get_opcode (*inst) < 4)
3019 value = do_sign_or_zero_extend (value, inst);
3024 /* Handles the assign addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
3025 instructions. The MOVE instruction is the move from source to register. */
3028 handle_prefix_assign_mode_for_aritm_op (unsigned short inst,
3029 inst_env_type *inst_env)
3031 unsigned long operand2;
3032 unsigned long operand3;
3034 check_assign (inst, inst_env);
3035 if (cris_get_operand2 (inst) == REG_PC)
3037 operand2 = inst_env->reg[REG_PC];
3039 /* Get the value of the third operand. */
3040 operand3 = get_data_from_address (&inst, inst_env->prefix_value);
3042 /* Calculate the PC value after the instruction, i.e. where the
3043 breakpoint should be. The order of the udw_operands is vital. */
3044 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3046 inst_env->slot_needed = 0;
3047 inst_env->prefix_found = 0;
3048 inst_env->xflag_found = 0;
3049 inst_env->disable_interrupt = 0;
3052 /* Handles the three-operand addressing mode for the ADD, SUB, CMP, AND and
3053 OR instructions. Note that for this to work as expected, the calling
3054 function must have made sure that there is a prefix to this instruction. */
3057 three_operand_add_sub_cmp_and_or_op (unsigned short inst,
3058 inst_env_type *inst_env)
3060 unsigned long operand2;
3061 unsigned long operand3;
3063 if (cris_get_operand1 (inst) == REG_PC)
3065 /* The PC will be changed by the instruction. */
3066 operand2 = inst_env->reg[cris_get_operand2 (inst)];
3068 /* Get the value of the third operand. */
3069 operand3 = get_data_from_address (&inst, inst_env->prefix_value);
3071 /* Calculate the PC value after the instruction, i.e. where the
3072 breakpoint should be. */
3073 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3075 inst_env->slot_needed = 0;
3076 inst_env->prefix_found = 0;
3077 inst_env->xflag_found = 0;
3078 inst_env->disable_interrupt = 0;
3081 /* Handles the index addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
3082 instructions. The MOVE instruction is the move from source to register. */
3085 handle_prefix_index_mode_for_aritm_op (unsigned short inst,
3086 inst_env_type *inst_env)
3088 if (cris_get_operand1 (inst) != cris_get_operand2 (inst))
3090 /* If the instruction is MOVE it's invalid. If the instruction is ADD,
3091 SUB, AND or OR something weird is going on (if everything works these
3092 instructions should end up in the three operand version). */
3093 inst_env->invalid = 1;
3098 /* three_operand_add_sub_cmp_and_or does the same as we should do here
3100 three_operand_add_sub_cmp_and_or_op (inst, inst_env);
3102 inst_env->slot_needed = 0;
3103 inst_env->prefix_found = 0;
3104 inst_env->xflag_found = 0;
3105 inst_env->disable_interrupt = 0;
3108 /* Handles the autoincrement and indirect addresing mode for the ADD, SUB,
3109 CMP, AND OR and MOVE instruction. The MOVE instruction is the move from
3110 source to register. */
3113 handle_inc_and_index_mode_for_aritm_op (unsigned short inst,
3114 inst_env_type *inst_env)
3116 unsigned long operand1;
3117 unsigned long operand2;
3118 unsigned long operand3;
3121 /* The instruction is either an indirect or autoincrement addressing mode.
3122 Check if the destination register is the PC. */
3123 if (cris_get_operand2 (inst) == REG_PC)
3125 /* Must be done here, get_data_from_address may change the size
3127 size = cris_get_size (inst);
3128 operand2 = inst_env->reg[REG_PC];
3130 /* Get the value of the third operand, i.e. the indirect operand. */
3131 operand1 = inst_env->reg[cris_get_operand1 (inst)];
3132 operand3 = get_data_from_address (&inst, operand1);
3134 /* Calculate the PC value after the instruction, i.e. where the
3135 breakpoint should be. The order of the udw_operands is vital. */
3136 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3138 /* If this is an autoincrement addressing mode, check if the increment
3140 if ((cris_get_operand1 (inst) == REG_PC) && (cris_get_mode (inst) == AUTOINC_MODE))
3142 /* Get the size field. */
3143 size = cris_get_size (inst);
3145 /* If it's an extend instruction we don't want the signed extend bit,
3146 because it influences the size. */
3147 if (cris_get_opcode (inst) < 4)
3149 size &= ~SIGNED_EXTEND_BIT_MASK;
3151 process_autoincrement (size, inst, inst_env);
3153 inst_env->slot_needed = 0;
3154 inst_env->prefix_found = 0;
3155 inst_env->xflag_found = 0;
3156 inst_env->disable_interrupt = 0;
3159 /* Handles the two-operand addressing mode, all modes except register, for
3160 the ADD, SUB CMP, AND and OR instruction. */
3163 none_reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst,
3164 inst_env_type *inst_env)
3166 if (inst_env->prefix_found)
3168 if (cris_get_mode (inst) == PREFIX_INDEX_MODE)
3170 handle_prefix_index_mode_for_aritm_op (inst, inst_env);
3172 else if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
3174 handle_prefix_assign_mode_for_aritm_op (inst, inst_env);
3178 /* The mode is invalid for a prefixed base instruction. */
3179 inst_env->invalid = 1;
3185 handle_inc_and_index_mode_for_aritm_op (inst, inst_env);
3189 /* Handles the quick addressing mode for the ADD and SUB instruction. */
3192 quick_mode_add_sub_op (unsigned short inst, inst_env_type *inst_env)
3194 unsigned long operand1;
3195 unsigned long operand2;
3197 /* It's a bad idea to be in a prefix instruction now. This is a quick mode
3198 instruction and can't have a prefix. */
3199 if (inst_env->prefix_found)
3201 inst_env->invalid = 1;
3205 /* Check if the instruction has PC as its target. */
3206 if (cris_get_operand2 (inst) == REG_PC)
3208 if (inst_env->slot_needed)
3210 inst_env->invalid = 1;
3213 operand1 = cris_get_quick_value (inst);
3214 operand2 = inst_env->reg[REG_PC];
3216 /* The size should now be dword. */
3217 cris_set_size_to_dword (&inst);
3219 /* Calculate the PC value after the instruction, i.e. where the
3220 breakpoint should be. */
3221 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3223 inst_env->slot_needed = 0;
3224 inst_env->prefix_found = 0;
3225 inst_env->xflag_found = 0;
3226 inst_env->disable_interrupt = 0;
3229 /* Handles the quick addressing mode for the CMP, AND and OR instruction. */
3232 quick_mode_and_cmp_move_or_op (unsigned short inst, inst_env_type *inst_env)
3234 unsigned long operand1;
3235 unsigned long operand2;
3237 /* It's a bad idea to be in a prefix instruction now. This is a quick mode
3238 instruction and can't have a prefix. */
3239 if (inst_env->prefix_found)
3241 inst_env->invalid = 1;
3244 /* Check if the instruction has PC as its target. */
3245 if (cris_get_operand2 (inst) == REG_PC)
3247 if (inst_env->slot_needed)
3249 inst_env->invalid = 1;
3252 /* The instruction has the PC as its target register. */
3253 operand1 = cris_get_quick_value (inst);
3254 operand2 = inst_env->reg[REG_PC];
3256 /* The quick value is signed, so check if we must do a signed extend. */
3257 if (operand1 & SIGNED_QUICK_VALUE_MASK)
3260 operand1 |= SIGNED_QUICK_VALUE_EXTEND_MASK;
3262 /* The size should now be dword. */
3263 cris_set_size_to_dword (&inst);
3265 /* Calculate the PC value after the instruction, i.e. where the
3266 breakpoint should be. */
3267 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3269 inst_env->slot_needed = 0;
3270 inst_env->prefix_found = 0;
3271 inst_env->xflag_found = 0;
3272 inst_env->disable_interrupt = 0;
3275 /* Translate op_type to a function and call it. */
3278 cris_gdb_func (enum cris_op_type op_type, unsigned short inst,
3279 inst_env_type *inst_env)
3283 case cris_not_implemented_op:
3284 not_implemented_op (inst, inst_env);
3288 abs_op (inst, inst_env);
3292 addi_op (inst, inst_env);
3296 asr_op (inst, inst_env);
3300 asrq_op (inst, inst_env);
3303 case cris_ax_ei_setf_op:
3304 ax_ei_setf_op (inst, inst_env);
3307 case cris_bdap_prefix:
3308 bdap_prefix (inst, inst_env);
3311 case cris_biap_prefix:
3312 biap_prefix (inst, inst_env);
3316 break_op (inst, inst_env);
3319 case cris_btst_nop_op:
3320 btst_nop_op (inst, inst_env);
3323 case cris_clearf_di_op:
3324 clearf_di_op (inst, inst_env);
3327 case cris_dip_prefix:
3328 dip_prefix (inst, inst_env);
3331 case cris_dstep_logshift_mstep_neg_not_op:
3332 dstep_logshift_mstep_neg_not_op (inst, inst_env);
3335 case cris_eight_bit_offset_branch_op:
3336 eight_bit_offset_branch_op (inst, inst_env);
3339 case cris_move_mem_to_reg_movem_op:
3340 move_mem_to_reg_movem_op (inst, inst_env);
3343 case cris_move_reg_to_mem_movem_op:
3344 move_reg_to_mem_movem_op (inst, inst_env);
3347 case cris_move_to_preg_op:
3348 move_to_preg_op (inst, inst_env);
3352 muls_op (inst, inst_env);
3356 mulu_op (inst, inst_env);
3359 case cris_none_reg_mode_add_sub_cmp_and_or_move_op:
3360 none_reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env);
3363 case cris_none_reg_mode_clear_test_op:
3364 none_reg_mode_clear_test_op (inst, inst_env);
3367 case cris_none_reg_mode_jump_op:
3368 none_reg_mode_jump_op (inst, inst_env);
3371 case cris_none_reg_mode_move_from_preg_op:
3372 none_reg_mode_move_from_preg_op (inst, inst_env);
3375 case cris_quick_mode_add_sub_op:
3376 quick_mode_add_sub_op (inst, inst_env);
3379 case cris_quick_mode_and_cmp_move_or_op:
3380 quick_mode_and_cmp_move_or_op (inst, inst_env);
3383 case cris_quick_mode_bdap_prefix:
3384 quick_mode_bdap_prefix (inst, inst_env);
3387 case cris_reg_mode_add_sub_cmp_and_or_move_op:
3388 reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env);
3391 case cris_reg_mode_clear_op:
3392 reg_mode_clear_op (inst, inst_env);
3395 case cris_reg_mode_jump_op:
3396 reg_mode_jump_op (inst, inst_env);
3399 case cris_reg_mode_move_from_preg_op:
3400 reg_mode_move_from_preg_op (inst, inst_env);
3403 case cris_reg_mode_test_op:
3404 reg_mode_test_op (inst, inst_env);
3408 scc_op (inst, inst_env);
3411 case cris_sixteen_bit_offset_branch_op:
3412 sixteen_bit_offset_branch_op (inst, inst_env);
3415 case cris_three_operand_add_sub_cmp_and_or_op:
3416 three_operand_add_sub_cmp_and_or_op (inst, inst_env);
3419 case cris_three_operand_bound_op:
3420 three_operand_bound_op (inst, inst_env);
3423 case cris_two_operand_bound_op:
3424 two_operand_bound_op (inst, inst_env);
3428 xor_op (inst, inst_env);
3433 /* This wrapper is to avoid cris_get_assembler being called before
3434 exec_bfd has been set. */
3437 cris_delayed_get_disassembler (bfd_vma addr, struct disassemble_info *info)
3439 int (*print_insn) (bfd_vma addr, struct disassemble_info *info);
3440 /* FIXME: cagney/2003-08-27: It should be possible to select a CRIS
3441 disassembler, even when there is no BFD. Does something like
3442 "gdb; target remote; disassmeble *0x123" work? */
3443 gdb_assert (exec_bfd != NULL);
3444 print_insn = cris_get_disassembler (exec_bfd);
3445 gdb_assert (print_insn != NULL);
3446 return print_insn (addr, info);
3449 /* Copied from <asm/elf.h>. */
3450 typedef unsigned long elf_greg_t;
3452 /* Same as user_regs_struct struct in <asm/user.h>. */
3453 typedef elf_greg_t elf_gregset_t[35];
3455 /* Unpack an elf_gregset_t into GDB's register cache. */
3458 supply_gregset (elf_gregset_t *gregsetp)
3461 elf_greg_t *regp = *gregsetp;
3462 static char zerobuf[4] = {0};
3464 /* The kernel dumps all 32 registers as unsigned longs, but supply_register
3465 knows about the actual size of each register so that's no problem. */
3466 for (i = 0; i < NUM_GENREGS + NUM_SPECREGS; i++)
3468 supply_register (i, (char *)®p[i]);
3472 /* Use a local version of this function to get the correct types for
3473 regsets, until multi-arch core support is ready. */
3476 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
3477 int which, CORE_ADDR reg_addr)
3479 elf_gregset_t gregset;
3484 if (core_reg_size != sizeof (gregset))
3486 warning ("wrong size gregset struct in core file");
3490 memcpy (&gregset, core_reg_sect, sizeof (gregset));
3491 supply_gregset (&gregset);
3495 /* We've covered all the kinds of registers we know about here,
3496 so this must be something we wouldn't know what to do with
3497 anyway. Just ignore it. */
3502 static struct core_fns cris_elf_core_fns =
3504 bfd_target_elf_flavour, /* core_flavour */
3505 default_check_format, /* check_format */
3506 default_core_sniffer, /* core_sniffer */
3507 fetch_core_registers, /* core_read_registers */
3511 /* Fetch (and possibly build) an appropriate link_map_offsets
3512 structure for native GNU/Linux CRIS targets using the struct
3513 offsets defined in link.h (but without actual reference to that
3516 This makes it possible to access GNU/Linux CRIS shared libraries
3517 from a GDB that was not built on an GNU/Linux CRIS host (for cross
3520 See gdb/solib-svr4.h for an explanation of these fields. */
3522 static struct link_map_offsets *
3523 cris_linux_svr4_fetch_link_map_offsets (void)
3525 static struct link_map_offsets lmo;
3526 static struct link_map_offsets *lmp = NULL;
3532 lmo.r_debug_size = 8; /* The actual size is 20 bytes, but
3533 this is all we need. */
3534 lmo.r_map_offset = 4;
3537 lmo.link_map_size = 20;
3539 lmo.l_addr_offset = 0;
3540 lmo.l_addr_size = 4;
3542 lmo.l_name_offset = 4;
3543 lmo.l_name_size = 4;
3545 lmo.l_next_offset = 12;
3546 lmo.l_next_size = 4;
3548 lmo.l_prev_offset = 16;
3549 lmo.l_prev_size = 4;
3556 cris_fpless_backtrace (char *noargs, int from_tty)
3558 /* Points at the instruction after the jsr (except when in innermost frame
3559 where it points at the original pc). */
3562 /* Temporary variable, used for parsing from the start of the function that
3563 the pc is in, up to the pc. */
3564 CORE_ADDR tmp_pc = 0;
3567 /* Information about current frame. */
3568 struct symtab_and_line sal;
3571 /* Present instruction. */
3572 unsigned short insn;
3574 /* Next instruction, lookahead. */
3575 unsigned short insn_next;
3577 /* This is to store the offset between sp at start of function and until we
3578 reach push srp (if any). */
3579 int sp_add_later = 0;
3580 int push_srp_found = 0;
3584 /* Frame counter. */
3587 /* For the innermost frame, we want to look at srp in case it's a leaf
3588 function (since there's no push srp in that case). */
3589 int innermost_frame = 1;
3591 deprecated_read_register_gen (PC_REGNUM, (char *) &pc);
3592 deprecated_read_register_gen (SP_REGNUM, (char *) &sp);
3594 /* We make an explicit return when we can't find an outer frame. */
3597 /* Get file name and line number. */
3598 sal = find_pc_line (pc, 0);
3600 /* Get function name. */
3601 find_pc_partial_function (pc, &func_name, (CORE_ADDR *) NULL,
3602 (CORE_ADDR *) NULL);
3604 /* Print information about current frame. */
3605 printf_unfiltered ("#%i 0x%08lx in %s", frame++, pc, func_name);
3608 printf_unfiltered (" at %s:%i", sal.symtab->filename, sal.line);
3610 printf_unfiltered ("\n");
3612 /* Get the start address of this function. */
3613 tmp_pc = get_pc_function_start (pc);
3615 /* Mini parser, only meant to find push sp and sub ...,sp from the start
3616 of the function, up to the pc. */
3619 insn = read_memory_unsigned_integer (tmp_pc, sizeof (short));
3620 tmp_pc += sizeof (short);
3623 /* push <reg> 32 bit instruction */
3624 insn_next = read_memory_unsigned_integer (tmp_pc,
3626 tmp_pc += sizeof (short);
3628 /* Recognize srp. */
3629 if (insn_next == 0xBE7E)
3631 /* For subsequent (not this one though) push or sub which
3632 affects sp, adjust sp immediately. */
3635 /* Note: this will break if we ever encounter a
3636 push vr (1 byte) or push ccr (2 bytes). */
3641 /* Some other register was pushed. */
3652 else if (cris_get_operand2 (insn) == SP_REGNUM
3653 && cris_get_mode (insn) == 0x0000
3654 && cris_get_opcode (insn) == 0x000A)
3657 val = cris_get_quick_value (insn);
3665 sp_add_later += val;
3669 else if (cris_get_operand2 (insn) == SP_REGNUM
3670 /* Autoincrement addressing mode. */
3671 && cris_get_mode (insn) == 0x0003
3673 && ((insn) & 0x03E0) >> 5 == 0x0004)
3676 val = get_data_from_address (&insn, tmp_pc);
3684 sp_add_later += val;
3687 else if (cris_get_operand2 (insn) == SP_REGNUM
3688 && ((insn & 0x0F00) >> 8) == 0x0001
3689 && (cris_get_signed_offset (insn) < 0))
3691 /* Immediate byte offset addressing prefix word with sp as base
3692 register. Used for CRIS v8 i.e. ETRAX 100 and newer if <val>
3693 is between 64 and 128.
3694 movem r<regsave>,[sp=sp-<val>] */
3695 val = -cris_get_signed_offset (insn);
3696 insn_next = read_memory_unsigned_integer (tmp_pc,
3698 tmp_pc += sizeof (short);
3700 if (cris_get_mode (insn_next) == PREFIX_ASSIGN_MODE
3701 && cris_get_opcode (insn_next) == 0x000F
3702 && cris_get_size (insn_next) == 0x0003
3703 && cris_get_operand1 (insn_next) == SP_REGNUM)
3711 sp_add_later += val;
3722 /* sp should now point at where srp is stored on the stack. Update
3723 the pc to the srp. */
3724 pc = read_memory_unsigned_integer (sp, 4);
3726 else if (innermost_frame)
3728 /* We couldn't find a push srp in the prologue, so this must be
3729 a leaf function, and thus we use the srp register directly.
3730 This should happen at most once, for the innermost function. */
3731 deprecated_read_register_gen (SRP_REGNUM, (char *) &pc);
3735 /* Couldn't find an outer frame. */
3739 /* Reset flag. (In case the innermost frame wasn't a leaf, we don't
3740 want to look at the srp register later either). */
3741 innermost_frame = 0;
3743 /* Now, add the offset for everything up to, and including push srp,
3744 that was held back during the prologue parsing. */
3750 extern initialize_file_ftype _initialize_cris_tdep; /* -Wmissing-prototypes */
3753 _initialize_cris_tdep (void)
3755 struct cmd_list_element *c;
3757 gdbarch_register (bfd_arch_cris, cris_gdbarch_init, cris_dump_tdep);
3759 /* CRIS-specific user-commands. */
3760 c = add_set_cmd ("cris-version", class_support, var_integer,
3761 (char *) &usr_cmd_cris_version,
3762 "Set the current CRIS version.", &setlist);
3763 set_cmd_sfunc (c, cris_version_update);
3764 add_show_from_set (c, &showlist);
3766 c = add_set_enum_cmd ("cris-mode", class_support, cris_mode_enums,
3768 "Set the current CRIS mode.", &setlist);
3769 set_cmd_sfunc (c, cris_mode_update);
3770 add_show_from_set (c, &showlist);
3772 c = add_set_enum_cmd ("cris-abi", class_support, cris_abi_enums,
3774 "Set the current CRIS ABI version.", &setlist);
3775 set_cmd_sfunc (c, cris_abi_update);
3776 add_show_from_set (c, &showlist);
3778 c = add_cmd ("cris-fpless-backtrace", class_support, cris_fpless_backtrace,
3779 "Display call chain using the subroutine return pointer.\n"
3780 "Note that this displays the address after the jump to the "
3781 "subroutine.", &cmdlist);
3783 add_core_fns (&cris_elf_core_fns);
3787 /* Prints out all target specific values. */
3790 cris_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
3792 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3795 fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_version = %i\n",
3796 tdep->cris_version);
3797 fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_mode = %s\n",
3799 fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_abi = %s\n",
3806 cris_version_update (char *ignore_args, int from_tty,
3807 struct cmd_list_element *c)
3809 struct gdbarch_info info;
3811 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
3812 the set command passed as a parameter. The clone operation will
3813 include (BUG?) any ``set'' command callback, if present.
3814 Commands like ``info set'' call all the ``show'' command
3815 callbacks. Unfortunately, for ``show'' commands cloned from
3816 ``set'', this includes callbacks belonging to ``set'' commands.
3817 Making this worse, this only occures if add_show_from_set() is
3818 called after add_cmd_sfunc() (BUG?). */
3820 /* From here on, trust the user's CRIS version setting. */
3821 if (cmd_type (c) == set_cmd)
3823 usr_cmd_cris_version_valid = 1;
3825 /* Update the current architecture, if needed. */
3826 gdbarch_info_init (&info);
3827 if (!gdbarch_update_p (info))
3828 internal_error (__FILE__, __LINE__, "cris_gdbarch_update: failed to update architecture.");
3833 cris_mode_update (char *ignore_args, int from_tty,
3834 struct cmd_list_element *c)
3836 struct gdbarch_info info;
3838 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
3839 the set command passed as a parameter. The clone operation will
3840 include (BUG?) any ``set'' command callback, if present.
3841 Commands like ``info set'' call all the ``show'' command
3842 callbacks. Unfortunately, for ``show'' commands cloned from
3843 ``set'', this includes callbacks belonging to ``set'' commands.
3844 Making this worse, this only occures if add_show_from_set() is
3845 called after add_cmd_sfunc() (BUG?). */
3847 /* From here on, trust the user's CRIS mode setting. */
3848 if (cmd_type (c) == set_cmd)
3850 usr_cmd_cris_mode_valid = 1;
3852 /* Update the current architecture, if needed. */
3853 gdbarch_info_init (&info);
3854 if (!gdbarch_update_p (info))
3855 internal_error (__FILE__, __LINE__, "cris_gdbarch_update: failed to update architecture.");
3860 cris_abi_update (char *ignore_args, int from_tty,
3861 struct cmd_list_element *c)
3863 struct gdbarch_info info;
3865 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
3866 the set command passed as a parameter. The clone operation will
3867 include (BUG?) any ``set'' command callback, if present.
3868 Commands like ``info set'' call all the ``show'' command
3869 callbacks. Unfortunately, for ``show'' commands cloned from
3870 ``set'', this includes callbacks belonging to ``set'' commands.
3871 Making this worse, this only occures if add_show_from_set() is
3872 called after add_cmd_sfunc() (BUG?). */
3874 /* From here on, trust the user's CRIS ABI setting. */
3875 if (cmd_type (c) == set_cmd)
3877 usr_cmd_cris_abi_valid = 1;
3879 /* Update the current architecture, if needed. */
3880 gdbarch_info_init (&info);
3881 if (!gdbarch_update_p (info))
3882 internal_error (__FILE__, __LINE__, "cris_gdbarch_update: failed to update architecture.");
3886 /* Copied from pa64solib.c, with a couple of minor changes. */
3889 bfd_lookup_symbol (bfd *abfd, const char *symname)
3891 unsigned int storage_needed;
3893 asymbol **symbol_table;
3894 unsigned int number_of_symbols;
3896 struct cleanup *back_to;
3897 CORE_ADDR symaddr = 0;
3899 storage_needed = bfd_get_symtab_upper_bound (abfd);
3901 if (storage_needed > 0)
3903 symbol_table = (asymbol **) xmalloc (storage_needed);
3904 back_to = make_cleanup (free, symbol_table);
3905 number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
3907 for (i = 0; i < number_of_symbols; i++)
3909 sym = *symbol_table++;
3910 if (!strcmp (sym->name, symname))
3912 /* Bfd symbols are section relative. */
3913 symaddr = sym->value + sym->section->vma;
3917 do_cleanups (back_to);
3922 static struct gdbarch *
3923 cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
3925 struct gdbarch *gdbarch;
3926 struct gdbarch_tdep *tdep;
3928 const char *cris_mode;
3929 const char *cris_abi;
3930 CORE_ADDR cris_abi_sym = 0;
3933 if (usr_cmd_cris_version_valid)
3935 /* Trust the user's CRIS version setting. */
3936 cris_version = usr_cmd_cris_version;
3940 /* Assume it's CRIS version 10. */
3944 if (usr_cmd_cris_mode_valid)
3946 /* Trust the user's CRIS mode setting. */
3947 cris_mode = usr_cmd_cris_mode;
3949 else if (cris_version == 10)
3951 /* Assume CRIS version 10 is in user mode. */
3952 cris_mode = CRIS_MODE_USER;
3956 /* Strictly speaking, older CRIS version don't have a supervisor mode,
3957 but we regard its only mode as supervisor mode. */
3958 cris_mode = CRIS_MODE_SUPERVISOR;
3961 if (usr_cmd_cris_abi_valid)
3963 /* Trust the user's ABI setting. */
3964 cris_abi = usr_cmd_cris_abi;
3968 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
3970 /* An elf target uses the new ABI. */
3971 cris_abi = CRIS_ABI_V2;
3973 else if (bfd_get_flavour (info.abfd) == bfd_target_aout_flavour)
3975 /* An a.out target may use either ABI. Look for hints in the
3977 cris_abi_sym = bfd_lookup_symbol (info.abfd, CRIS_ABI_SYMBOL);
3978 cris_abi = cris_abi_sym ? CRIS_ABI_V2 : CRIS_ABI_ORIGINAL;
3982 /* Unknown bfd flavour. Assume it's the new ABI. */
3983 cris_abi = CRIS_ABI_V2;
3986 else if (arches != NULL)
3988 /* No bfd available. Stick with the ABI from the most recently
3989 selected architecture of this same family (the head of arches
3990 always points to this). (This is to avoid changing the ABI
3991 when the user updates the architecture with the 'set
3992 cris-version' command.) */
3993 cris_abi = gdbarch_tdep (arches->gdbarch)->cris_abi;
3997 /* No bfd, and no previously selected architecture available.
3998 Assume it's the new ABI. */
3999 cris_abi = CRIS_ABI_V2;
4002 /* Make the current settings visible to the user. */
4003 usr_cmd_cris_version = cris_version;
4004 usr_cmd_cris_mode = cris_mode;
4005 usr_cmd_cris_abi = cris_abi;
4007 /* Find a candidate among the list of pre-declared architectures. Both
4008 CRIS version and ABI must match. */
4009 for (arches = gdbarch_list_lookup_by_info (arches, &info);
4011 arches = gdbarch_list_lookup_by_info (arches->next, &info))
4013 if ((gdbarch_tdep (arches->gdbarch)->cris_version == cris_version)
4014 && (gdbarch_tdep (arches->gdbarch)->cris_mode == cris_mode)
4015 && (gdbarch_tdep (arches->gdbarch)->cris_abi == cris_abi))
4016 return arches->gdbarch;
4019 /* No matching architecture was found. Create a new one. */
4020 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
4021 gdbarch = gdbarch_alloc (&info, tdep);
4023 /* NOTE: cagney/2002-12-06: This can be deleted when this arch is
4024 ready to unwind the PC first (see frame.c:get_prev_frame()). */
4025 set_gdbarch_deprecated_init_frame_pc (gdbarch, deprecated_init_frame_pc_default);
4027 tdep->cris_version = cris_version;
4028 tdep->cris_mode = cris_mode;
4029 tdep->cris_abi = cris_abi;
4031 /* INIT shall ensure that the INFO.BYTE_ORDER is non-zero. */
4032 switch (info.byte_order)
4034 case BFD_ENDIAN_LITTLE:
4038 case BFD_ENDIAN_BIG:
4039 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: big endian byte order in info");
4043 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unknown byte order in info");
4046 /* Initialize the ABI dependent things. */
4047 if (tdep->cris_abi == CRIS_ABI_ORIGINAL)
4049 set_gdbarch_double_bit (gdbarch, 32);
4050 set_gdbarch_deprecated_push_arguments (gdbarch, cris_abi_original_push_arguments);
4051 set_gdbarch_deprecated_store_return_value (gdbarch,
4052 cris_abi_original_store_return_value);
4053 set_gdbarch_deprecated_extract_return_value
4054 (gdbarch, cris_abi_original_extract_return_value);
4055 set_gdbarch_deprecated_reg_struct_has_addr
4056 (gdbarch, cris_abi_original_reg_struct_has_addr);
4058 else if (tdep->cris_abi == CRIS_ABI_V2)
4060 set_gdbarch_double_bit (gdbarch, 64);
4061 set_gdbarch_deprecated_push_arguments (gdbarch, cris_abi_v2_push_arguments);
4062 set_gdbarch_deprecated_store_return_value (gdbarch, cris_abi_v2_store_return_value);
4063 set_gdbarch_deprecated_extract_return_value
4064 (gdbarch, cris_abi_v2_extract_return_value);
4065 set_gdbarch_deprecated_reg_struct_has_addr
4066 (gdbarch, cris_abi_v2_reg_struct_has_addr);
4069 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unknown CRIS ABI");
4071 /* The default definition of a long double is 2 * TARGET_DOUBLE_BIT,
4072 which means we have to set this explicitly. */
4073 set_gdbarch_long_double_bit (gdbarch, 64);
4075 /* There are 32 registers (some of which may not be implemented). */
4076 set_gdbarch_num_regs (gdbarch, 32);
4077 set_gdbarch_sp_regnum (gdbarch, 14);
4078 set_gdbarch_deprecated_fp_regnum (gdbarch, 8);
4079 set_gdbarch_pc_regnum (gdbarch, 15);
4081 set_gdbarch_register_name (gdbarch, cris_register_name);
4083 /* Length of ordinary registers used in push_word and a few other
4084 places. DEPRECATED_REGISTER_RAW_SIZE is the real way to know how
4085 big a register is. */
4086 set_gdbarch_deprecated_register_size (gdbarch, 4);
4089 set_gdbarch_register_bytes_ok (gdbarch, cris_register_bytes_ok);
4090 set_gdbarch_software_single_step (gdbarch, cris_software_single_step);
4093 set_gdbarch_cannot_store_register (gdbarch, cris_cannot_store_register);
4094 set_gdbarch_cannot_fetch_register (gdbarch, cris_cannot_fetch_register);
4097 /* The total amount of space needed to store (in an array called registers)
4098 GDB's copy of the machine's register state. Note: We can not use
4099 cris_register_size at this point, since it relies on current_gdbarch
4101 switch (tdep->cris_version)
4107 /* Support for these may be added later. */
4108 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unsupported CRIS version");
4113 /* CRIS v8 and v9, a.k.a. ETRAX 100. General registers R0 - R15
4114 (32 bits), special registers P0 - P1 (8 bits), P4 - P5 (16 bits),
4115 and P8 - P14 (32 bits). */
4116 register_bytes = (16 * 4) + (2 * 1) + (2 * 2) + (7 * 4);
4121 /* CRIS v10 and v11, a.k.a. ETRAX 100LX. In addition to ETRAX 100,
4122 P7 (32 bits), and P15 (32 bits) have been implemented. */
4123 register_bytes = (16 * 4) + (2 * 1) + (2 * 2) + (9 * 4);
4127 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unknown CRIS version");
4130 set_gdbarch_deprecated_register_bytes (gdbarch, register_bytes);
4132 /* Returns the register offset for the first byte of register regno's space
4133 in the saved register state. */
4134 set_gdbarch_deprecated_register_byte (gdbarch, cris_register_offset);
4136 /* The length of the registers in the actual machine representation. */
4137 set_gdbarch_deprecated_register_raw_size (gdbarch, cris_register_size);
4139 /* The largest value DEPRECATED_REGISTER_RAW_SIZE can have. */
4140 set_gdbarch_deprecated_max_register_raw_size (gdbarch, 32);
4142 /* The length of the registers in the program's representation. */
4143 set_gdbarch_deprecated_register_virtual_size (gdbarch, cris_register_size);
4145 /* The largest value DEPRECATED_REGISTER_VIRTUAL_SIZE can have. */
4146 set_gdbarch_deprecated_max_register_virtual_size (gdbarch, 32);
4148 set_gdbarch_deprecated_register_virtual_type (gdbarch, cris_register_virtual_type);
4150 /* Use generic dummy frames. */
4152 /* Read all about dummy frames in blockframe.c. */
4153 set_gdbarch_deprecated_pc_in_call_dummy (gdbarch, deprecated_pc_in_call_dummy_at_entry_point);
4155 /* Defined to 1 to indicate that the target supports inferior function
4157 set_gdbarch_deprecated_call_dummy_words (gdbarch, 0);
4158 set_gdbarch_deprecated_sizeof_call_dummy_words (gdbarch, 0);
4160 set_gdbarch_deprecated_get_saved_register (gdbarch, deprecated_generic_get_saved_register);
4162 set_gdbarch_deprecated_push_return_address (gdbarch, cris_push_return_address);
4163 set_gdbarch_deprecated_pop_frame (gdbarch, cris_pop_frame);
4165 set_gdbarch_deprecated_store_struct_return (gdbarch, cris_store_struct_return);
4166 set_gdbarch_use_struct_convention (gdbarch, always_use_struct_convention);
4168 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, cris_frame_init_saved_regs);
4169 set_gdbarch_deprecated_init_extra_frame_info (gdbarch, cris_init_extra_frame_info);
4170 set_gdbarch_skip_prologue (gdbarch, cris_skip_prologue);
4172 /* The stack grows downward. */
4173 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
4175 set_gdbarch_breakpoint_from_pc (gdbarch, cris_breakpoint_from_pc);
4177 set_gdbarch_frameless_function_invocation
4178 (gdbarch, cris_frameless_function_invocation);
4179 set_gdbarch_deprecated_frame_chain (gdbarch, cris_frame_chain);
4181 set_gdbarch_deprecated_frame_saved_pc (gdbarch, cris_frame_saved_pc);
4182 set_gdbarch_deprecated_saved_pc_after_call (gdbarch, cris_saved_pc_after_call);
4184 /* Helpful for backtracing and returning in a call dummy. */
4185 set_gdbarch_deprecated_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos);
4187 /* Should be using push_dummy_call. */
4188 set_gdbarch_deprecated_dummy_write_sp (gdbarch, deprecated_write_sp);
4190 /* Use target_specific function to define link map offsets. */
4191 set_solib_svr4_fetch_link_map_offsets
4192 (gdbarch, cris_linux_svr4_fetch_link_map_offsets);
4194 /* FIXME: cagney/2003-08-27: It should be possible to select a CRIS
4195 disassembler, even when there is no BFD. Does something like
4196 "gdb; target remote; disassmeble *0x123" work? */
4197 set_gdbarch_print_insn (gdbarch, cris_delayed_get_disassembler);