1 /* Target dependent code for CRIS, for GDB, the GNU debugger.
2 Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
3 Contributed by Axis Communications AB.
4 Written by Hendrik Ruijter, Stefan Andersson, and Orjan Friberg.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
31 #include "opcode/cris.h"
32 #include "arch-utils.h"
34 #include "gdb_assert.h"
36 /* To get entry_point_address. */
39 #include "solib.h" /* Support for shared libraries. */
40 #include "solib-svr4.h" /* For struct link_map_offsets. */
41 #include "gdb_string.h"
46 /* There are no floating point registers. Used in gdbserver low-linux.c. */
49 /* There are 16 general registers. */
52 /* There are 16 special registers. */
56 /* Register numbers of various important registers.
57 DEPRECATED_FP_REGNUM Contains address of executing stack frame.
58 STR_REGNUM Contains the address of structure return values.
59 RET_REGNUM Contains the return value when shorter than or equal to 32 bits
60 ARG1_REGNUM Contains the first parameter to a function.
61 ARG2_REGNUM Contains the second parameter to a function.
62 ARG3_REGNUM Contains the third parameter to a function.
63 ARG4_REGNUM Contains the fourth parameter to a function. Rest on stack.
64 SP_REGNUM Contains address of top of stack.
65 PC_REGNUM Contains address of next instruction.
66 SRP_REGNUM Subroutine return pointer register.
67 BRP_REGNUM Breakpoint return pointer register. */
69 /* DEPRECATED_FP_REGNUM = 8, SP_REGNUM = 14, and PC_REGNUM = 15 have
70 been incorporated into the multi-arch framework. */
74 /* Enums with respect to the general registers, valid for all
83 /* Enums with respect to the special registers, some of which may not be
84 applicable to all CRIS versions. */
102 extern const struct cris_spec_reg cris_spec_regs
[];
104 /* CRIS version, set via the user command 'set cris-version'. Affects
105 register names and sizes.*/
106 static int usr_cmd_cris_version
;
108 /* Indicates whether to trust the above variable. */
109 static int usr_cmd_cris_version_valid
= 0;
111 /* CRIS mode, set via the user command 'set cris-mode'. Affects availability
112 of some registers. */
113 static const char *usr_cmd_cris_mode
;
115 /* Indicates whether to trust the above variable. */
116 static int usr_cmd_cris_mode_valid
= 0;
118 static const char CRIS_MODE_USER
[] = "CRIS_MODE_USER";
119 static const char CRIS_MODE_SUPERVISOR
[] = "CRIS_MODE_SUPERVISOR";
120 static const char *cris_mode_enums
[] =
123 CRIS_MODE_SUPERVISOR
,
127 /* CRIS ABI, set via the user command 'set cris-abi'.
128 There are two flavours:
129 1. Original ABI with 32-bit doubles, where arguments <= 4 bytes are
131 2. New ABI with 64-bit doubles, where arguments <= 8 bytes are passed by
133 static const char *usr_cmd_cris_abi
;
135 /* Indicates whether to trust the above variable. */
136 static int usr_cmd_cris_abi_valid
= 0;
138 /* These variables are strings instead of enums to make them usable as
139 parameters to add_set_enum_cmd. */
140 static const char CRIS_ABI_ORIGINAL
[] = "CRIS_ABI_ORIGINAL";
141 static const char CRIS_ABI_V2
[] = "CRIS_ABI_V2";
142 static const char CRIS_ABI_SYMBOL
[] = ".$CRIS_ABI_V2";
143 static const char *cris_abi_enums
[] =
150 /* CRIS architecture specific information. */
154 const char *cris_mode
;
155 const char *cris_abi
;
158 /* Functions for accessing target dependent data. */
163 return (gdbarch_tdep (current_gdbarch
)->cris_version
);
169 return (gdbarch_tdep (current_gdbarch
)->cris_mode
);
175 return (gdbarch_tdep (current_gdbarch
)->cris_abi
);
178 /* For saving call-clobbered contents in R9 when returning structs. */
179 static CORE_ADDR struct_return_address
;
181 struct frame_extra_info
187 /* The instruction environment needed to find single-step breakpoints. */
189 struct instruction_environment
191 unsigned long reg
[NUM_GENREGS
];
192 unsigned long preg
[NUM_SPECREGS
];
193 unsigned long branch_break_address
;
194 unsigned long delay_slot_pc
;
195 unsigned long prefix_value
;
200 int delay_slot_pc_active
;
202 int disable_interrupt
;
205 /* Save old breakpoints in order to restore the state before a single_step.
206 At most, two breakpoints will have to be remembered. */
208 char binsn_quantum
[BREAKPOINT_MAX
];
209 static binsn_quantum break_mem
[2];
210 static CORE_ADDR next_pc
= 0;
211 static CORE_ADDR branch_target_address
= 0;
212 static unsigned char branch_break_inserted
= 0;
214 /* Machine-dependencies in CRIS for opcodes. */
216 /* Instruction sizes. */
217 enum cris_instruction_sizes
224 /* Addressing modes. */
225 enum cris_addressing_modes
232 /* Prefix addressing modes. */
233 enum cris_prefix_addressing_modes
235 PREFIX_INDEX_MODE
= 2,
236 PREFIX_ASSIGN_MODE
= 3,
238 /* Handle immediate byte offset addressing mode prefix format. */
239 PREFIX_OFFSET_MODE
= 2
242 /* Masks for opcodes. */
243 enum cris_opcode_masks
245 BRANCH_SIGNED_SHORT_OFFSET_MASK
= 0x1,
246 SIGNED_EXTEND_BIT_MASK
= 0x2,
247 SIGNED_BYTE_MASK
= 0x80,
248 SIGNED_BYTE_EXTEND_MASK
= 0xFFFFFF00,
249 SIGNED_WORD_MASK
= 0x8000,
250 SIGNED_WORD_EXTEND_MASK
= 0xFFFF0000,
251 SIGNED_DWORD_MASK
= 0x80000000,
252 SIGNED_QUICK_VALUE_MASK
= 0x20,
253 SIGNED_QUICK_VALUE_EXTEND_MASK
= 0xFFFFFFC0
256 /* Functions for opcodes. The general form of the ETRAX 16-bit instruction:
264 cris_get_operand2 (unsigned short insn
)
266 return ((insn
& 0xF000) >> 12);
270 cris_get_mode (unsigned short insn
)
272 return ((insn
& 0x0C00) >> 10);
276 cris_get_opcode (unsigned short insn
)
278 return ((insn
& 0x03C0) >> 6);
282 cris_get_size (unsigned short insn
)
284 return ((insn
& 0x0030) >> 4);
288 cris_get_operand1 (unsigned short insn
)
290 return (insn
& 0x000F);
293 /* Additional functions in order to handle opcodes. */
296 cris_get_wide_opcode (unsigned short insn
)
298 return ((insn
& 0x03E0) >> 5);
302 cris_get_short_size (unsigned short insn
)
304 return ((insn
& 0x0010) >> 4);
308 cris_get_quick_value (unsigned short insn
)
310 return (insn
& 0x003F);
314 cris_get_bdap_quick_offset (unsigned short insn
)
316 return (insn
& 0x00FF);
320 cris_get_branch_short_offset (unsigned short insn
)
322 return (insn
& 0x00FF);
326 cris_get_asr_shift_steps (unsigned long value
)
328 return (value
& 0x3F);
332 cris_get_asr_quick_shift_steps (unsigned short insn
)
334 return (insn
& 0x1F);
338 cris_get_clear_size (unsigned short insn
)
340 return ((insn
) & 0xC000);
344 cris_is_signed_extend_bit_on (unsigned short insn
)
346 return (((insn
) & 0x20) == 0x20);
350 cris_is_xflag_bit_on (unsigned short insn
)
352 return (((insn
) & 0x1000) == 0x1000);
356 cris_set_size_to_dword (unsigned short *insn
)
363 cris_get_signed_offset (unsigned short insn
)
365 return ((signed char) (insn
& 0x00FF));
368 /* Calls an op function given the op-type, working on the insn and the
370 static void cris_gdb_func (enum cris_op_type
, unsigned short, inst_env_type
*);
372 static CORE_ADDR
cris_skip_prologue_main (CORE_ADDR pc
, int frameless_p
);
374 static struct gdbarch
*cris_gdbarch_init (struct gdbarch_info
,
375 struct gdbarch_list
*);
377 static int cris_delayed_get_disassembler (bfd_vma
, disassemble_info
*);
379 static void cris_dump_tdep (struct gdbarch
*, struct ui_file
*);
381 static void cris_version_update (char *ignore_args
, int from_tty
,
382 struct cmd_list_element
*c
);
384 static void cris_mode_update (char *ignore_args
, int from_tty
,
385 struct cmd_list_element
*c
);
387 static void cris_abi_update (char *ignore_args
, int from_tty
,
388 struct cmd_list_element
*c
);
390 static CORE_ADDR
bfd_lookup_symbol (bfd
*, const char *);
392 /* Frames information. The definition of the struct frame_info is
396 enum frame_type type;
400 If the compilation option -fno-omit-frame-pointer is present the
401 variable frame will be set to the content of R8 which is the frame
404 The variable pc contains the address where execution is performed
405 in the present frame. The innermost frame contains the current content
406 of the register PC. All other frames contain the content of the
407 register PC in the next frame.
409 The variable `type' indicates the frame's type: normal, SIGTRAMP
410 (associated with a signal handler), dummy (associated with a dummy
413 The variable return_pc contains the address where execution should be
414 resumed when the present frame has finished, the return address.
416 The variable leaf_function is 1 if the return address is in the register
417 SRP, and 0 if it is on the stack.
419 Prologue instructions C-code.
420 The prologue may consist of (-fno-omit-frame-pointer)
424 move.d sp,r8 move.d sp,r8
426 movem rY,[sp] movem rY,[sp]
427 move.S rZ,[r8-U] move.S rZ,[r8-U]
429 where 1 is a non-terminal function, and 2 is a leaf-function.
431 Note that this assumption is extremely brittle, and will break at the
432 slightest change in GCC's prologue.
434 If local variables are declared or register contents are saved on stack
435 the subq-instruction will be present with X as the number of bytes
436 needed for storage. The reshuffle with respect to r8 may be performed
437 with any size S (b, w, d) and any of the general registers Z={0..13}.
438 The offset U should be representable by a signed 8-bit value in all cases.
439 Thus, the prefix word is assumed to be immediate byte offset mode followed
440 by another word containing the instruction.
449 Prologue instructions C++-code.
450 Case 1) and 2) in the C-code may be followed by
456 move.S [r8+U],rZ ; P4
458 if any of the call parameters are stored. The host expects these
459 instructions to be executed in order to get the call parameters right. */
461 /* Examine the prologue of a function. The variable ip is the address of
462 the first instruction of the prologue. The variable limit is the address
463 of the first instruction after the prologue. The variable fi contains the
464 information in struct frame_info. The variable frameless_p controls whether
465 the entire prologue is examined (0) or just enough instructions to
466 determine that it is a prologue (1). */
469 cris_examine (CORE_ADDR ip
, CORE_ADDR limit
, struct frame_info
*fi
,
472 /* Present instruction. */
475 /* Next instruction, lookahead. */
476 unsigned short insn_next
;
479 /* Is there a push fp? */
482 /* Number of byte on stack used for local variables and movem. */
485 /* Highest register number in a movem. */
488 /* move.d r<source_register>,rS */
489 short source_register
;
491 /* This frame is with respect to a leaf until a push srp is found. */
492 get_frame_extra_info (fi
)->leaf_function
= 1;
494 /* This frame is without the FP until a push fp is found. */
497 /* Assume nothing on stack. */
501 /* No information about register contents so far. */
503 /* We only want to know the end of the prologue when fi->saved_regs == 0.
504 When the saved registers are allocated full information is required. */
505 if (get_frame_saved_regs (fi
))
507 for (regno
= 0; regno
< NUM_REGS
; regno
++)
508 get_frame_saved_regs (fi
)[regno
] = 0;
511 /* Find the prologue instructions. */
514 insn
= read_memory_unsigned_integer (ip
, sizeof (short));
515 ip
+= sizeof (short);
518 /* push <reg> 32 bit instruction */
519 insn_next
= read_memory_unsigned_integer (ip
, sizeof (short));
520 ip
+= sizeof (short);
521 regno
= cris_get_operand2 (insn_next
);
523 /* This check, meant to recognize srp, used to be regno ==
524 (SRP_REGNUM - NUM_GENREGS), but that covers r11 also. */
525 if (insn_next
== 0xBE7E)
531 get_frame_extra_info (fi
)->leaf_function
= 0;
533 else if (regno
== DEPRECATED_FP_REGNUM
)
538 else if (insn
== 0x866E)
547 else if (cris_get_operand2 (insn
) == SP_REGNUM
548 && cris_get_mode (insn
) == 0x0000
549 && cris_get_opcode (insn
) == 0x000A)
552 val
= cris_get_quick_value (insn
);
554 else if (cris_get_mode (insn
) == 0x0002
555 && cris_get_opcode (insn
) == 0x000F
556 && cris_get_size (insn
) == 0x0003
557 && cris_get_operand1 (insn
) == SP_REGNUM
)
559 /* movem r<regsave>,[sp] */
564 regsave
= cris_get_operand2 (insn
);
566 else if (cris_get_operand2 (insn
) == SP_REGNUM
567 && ((insn
& 0x0F00) >> 8) == 0x0001
568 && (cris_get_signed_offset (insn
) < 0))
570 /* Immediate byte offset addressing prefix word with sp as base
571 register. Used for CRIS v8 i.e. ETRAX 100 and newer if <val>
572 is between 64 and 128.
573 movem r<regsave>,[sp=sp-<val>] */
574 val
= -cris_get_signed_offset (insn
);
575 insn_next
= read_memory_unsigned_integer (ip
, sizeof (short));
576 ip
+= sizeof (short);
577 if (cris_get_mode (insn_next
) == PREFIX_ASSIGN_MODE
578 && cris_get_opcode (insn_next
) == 0x000F
579 && cris_get_size (insn_next
) == 0x0003
580 && cris_get_operand1 (insn_next
) == SP_REGNUM
)
586 regsave
= cris_get_operand2 (insn_next
);
590 /* The prologue ended before the limit was reached. */
591 ip
-= 2 * sizeof (short);
595 else if (cris_get_mode (insn
) == 0x0001
596 && cris_get_opcode (insn
) == 0x0009
597 && cris_get_size (insn
) == 0x0002)
599 /* move.d r<10..13>,r<0..15> */
604 source_register
= cris_get_operand1 (insn
);
606 /* FIXME? In the glibc solibs, the prologue might contain something
607 like (this example taken from relocate_doit):
610 which isn't covered by the source_register check below. Question
611 is whether to add a check for this combo, or make better use of
612 the limit variable instead. */
613 if (source_register
< ARG1_REGNUM
|| source_register
> ARG4_REGNUM
)
615 /* The prologue ended before the limit was reached. */
616 ip
-= sizeof (short);
620 else if (cris_get_operand2 (insn
) == DEPRECATED_FP_REGNUM
621 /* The size is a fixed-size. */
622 && ((insn
& 0x0F00) >> 8) == 0x0001
623 /* A negative offset. */
624 && (cris_get_signed_offset (insn
) < 0))
626 /* move.S rZ,[r8-U] (?) */
627 insn_next
= read_memory_unsigned_integer (ip
, sizeof (short));
628 ip
+= sizeof (short);
629 regno
= cris_get_operand2 (insn_next
);
630 if ((regno
>= 0 && regno
< SP_REGNUM
)
631 && cris_get_mode (insn_next
) == PREFIX_OFFSET_MODE
632 && cris_get_opcode (insn_next
) == 0x000F)
634 /* move.S rZ,[r8-U] */
639 /* The prologue ended before the limit was reached. */
640 ip
-= 2 * sizeof (short);
644 else if (cris_get_operand2 (insn
) == DEPRECATED_FP_REGNUM
645 /* The size is a fixed-size. */
646 && ((insn
& 0x0F00) >> 8) == 0x0001
647 /* A positive offset. */
648 && (cris_get_signed_offset (insn
) > 0))
650 /* move.S [r8+U],rZ (?) */
651 insn_next
= read_memory_unsigned_integer (ip
, sizeof (short));
652 ip
+= sizeof (short);
653 regno
= cris_get_operand2 (insn_next
);
654 if ((regno
>= 0 && regno
< SP_REGNUM
)
655 && cris_get_mode (insn_next
) == PREFIX_OFFSET_MODE
656 && cris_get_opcode (insn_next
) == 0x0009
657 && cris_get_operand1 (insn_next
) == regno
)
659 /* move.S [r8+U],rZ */
664 /* The prologue ended before the limit was reached. */
665 ip
-= 2 * sizeof (short);
671 /* The prologue ended before the limit was reached. */
672 ip
-= sizeof (short);
678 /* We only want to know the end of the prologue when
679 fi->saved_regs == 0. */
680 if (!get_frame_saved_regs (fi
))
685 get_frame_saved_regs (fi
)[DEPRECATED_FP_REGNUM
] = get_frame_base (fi
);
687 /* Calculate the addresses. */
688 for (regno
= regsave
; regno
>= 0; regno
--)
690 get_frame_saved_regs (fi
)[regno
] = get_frame_base (fi
) - val
;
693 if (get_frame_extra_info (fi
)->leaf_function
)
695 /* Set the register SP to contain the stack pointer of
697 get_frame_saved_regs (fi
)[SP_REGNUM
] = get_frame_base (fi
) + 4;
701 /* Set the register SP to contain the stack pointer of
703 get_frame_saved_regs (fi
)[SP_REGNUM
] = get_frame_base (fi
) + 8;
705 /* Set the register SRP to contain the return address of
707 get_frame_saved_regs (fi
)[SRP_REGNUM
] = get_frame_base (fi
) + 4;
713 /* Advance pc beyond any function entry prologue instructions at pc
714 to reach some "real" code. */
717 cris_skip_prologue (CORE_ADDR pc
)
719 return cris_skip_prologue_main (pc
, 0);
722 /* As cris_skip_prologue, but stops as soon as it knows that the function
723 has a frame. Its result is equal to its input pc if the function is
724 frameless, unequal otherwise. */
727 cris_skip_prologue_frameless_p (CORE_ADDR pc
)
729 return cris_skip_prologue_main (pc
, 1);
732 /* Given a PC value corresponding to the start of a function, return the PC
733 of the first instruction after the function prologue. */
736 cris_skip_prologue_main (CORE_ADDR pc
, int frameless_p
)
738 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
739 struct frame_info
*fi
;
740 struct symtab_and_line sal
= find_pc_line (pc
, 0);
742 CORE_ADDR pc_after_prologue
;
744 /* frame_info now contains dynamic memory. Since fi is a dummy
745 here, I don't bother allocating memory for saved_regs. */
746 fi
= deprecated_frame_xmalloc_with_cleanup (0, sizeof (struct frame_extra_info
));
748 /* If there is no symbol information then sal.end == 0, and we end up
749 examining only the first instruction in the function prologue.
750 Exaggerating the limit seems to be harmless. */
752 best_limit
= sal
.end
;
754 best_limit
= pc
+ 100;
756 pc_after_prologue
= cris_examine (pc
, best_limit
, fi
, frameless_p
);
757 do_cleanups (old_chain
);
758 return pc_after_prologue
;
761 /* Use the program counter to determine the contents and size of a breakpoint
762 instruction. It returns a pointer to a string of bytes that encode a
763 breakpoint instruction, stores the length of the string to *lenptr, and
764 adjusts pcptr (if necessary) to point to the actual memory location where
765 the breakpoint should be inserted. */
767 static const unsigned char *
768 cris_breakpoint_from_pc (CORE_ADDR
*pcptr
, int *lenptr
)
770 static unsigned char break_insn
[] = {0x38, 0xe9};
776 /* Returns the register SRP (subroutine return pointer) which must contain
777 the content of the register PC after a function call. */
780 cris_saved_pc_after_call (struct frame_info
*frame
)
782 return read_register (SRP_REGNUM
);
785 /* Returns 1 if spec_reg is applicable to the current gdbarch's CRIS version,
789 cris_spec_reg_applicable (struct cris_spec_reg spec_reg
)
791 int version
= cris_version ();
793 switch (spec_reg
.applicable_version
)
795 case cris_ver_version_all
:
797 case cris_ver_warning
:
798 /* Indeterminate/obsolete. */
801 /* Simulator only. */
804 return (version
>= 0 && version
<= 3);
806 return (version
>= 3);
808 return (version
== 8 || version
== 9);
810 return (version
>= 8);
812 return (version
>= 10);
814 /* Invalid cris version. */
819 /* Returns the register size in unit byte. Returns 0 for an unimplemented
820 register, -1 for an invalid register. */
823 cris_register_size (int regno
)
828 if (regno
>= 0 && regno
< NUM_GENREGS
)
830 /* General registers (R0 - R15) are 32 bits. */
833 else if (regno
>= NUM_GENREGS
&& regno
< NUM_REGS
)
835 /* Special register (R16 - R31). cris_spec_regs is zero-based.
836 Adjust regno accordingly. */
837 spec_regno
= regno
- NUM_GENREGS
;
839 /* The entries in cris_spec_regs are stored in register number order,
840 which means we can shortcut into the array when searching it. */
841 for (i
= spec_regno
; cris_spec_regs
[i
].name
!= NULL
; i
++)
843 if (cris_spec_regs
[i
].number
== spec_regno
844 && cris_spec_reg_applicable (cris_spec_regs
[i
]))
845 /* Go with the first applicable register. */
846 return cris_spec_regs
[i
].reg_size
;
848 /* Special register not applicable to this CRIS version. */
853 /* Invalid register. */
858 /* Nonzero if regno should not be fetched from the target. This is the case
859 for unimplemented (size 0) and non-existant registers. */
862 cris_cannot_fetch_register (int regno
)
864 return ((regno
< 0 || regno
>= NUM_REGS
)
865 || (cris_register_size (regno
) == 0));
868 /* Nonzero if regno should not be written to the target, for various
872 cris_cannot_store_register (int regno
)
874 /* There are three kinds of registers we refuse to write to.
875 1. Those that not implemented.
876 2. Those that are read-only (depends on the processor mode).
877 3. Those registers to which a write has no effect.
880 if (regno
< 0 || regno
>= NUM_REGS
|| cris_register_size (regno
) == 0)
881 /* Not implemented. */
884 else if (regno
== VR_REGNUM
)
888 else if (regno
== P0_REGNUM
|| regno
== P4_REGNUM
|| regno
== P8_REGNUM
)
889 /* Writing has no effect. */
892 else if (cris_mode () == CRIS_MODE_USER
)
894 if (regno
== IBR_REGNUM
|| regno
== BAR_REGNUM
|| regno
== BRP_REGNUM
895 || regno
== IRP_REGNUM
)
896 /* Read-only in user mode. */
903 /* Returns the register offset for the first byte of register regno's space
904 in the saved register state. Returns -1 for an invalid or unimplemented
908 cris_register_offset (int regno
)
914 if (regno
>= 0 && regno
< NUM_REGS
)
916 /* FIXME: The offsets should be cached and calculated only once,
917 when the architecture being debugged has changed. */
918 for (i
= 0; i
< regno
; i
++)
919 offset
+= cris_register_size (i
);
925 /* Invalid register. */
930 /* Return the GDB type (defined in gdbtypes.c) for the "standard" data type
931 of data in register regno. */
934 cris_register_virtual_type (int regno
)
936 if (regno
== SP_REGNUM
|| regno
== PC_REGNUM
937 || (regno
> P8_REGNUM
&& regno
< USP_REGNUM
))
939 /* SP, PC, IBR, IRP, SRP, BAR, DCCR, BRP */
940 return lookup_pointer_type (builtin_type_void
);
942 else if (regno
== P8_REGNUM
|| regno
== USP_REGNUM
943 || (regno
>= 0 && regno
< SP_REGNUM
))
945 /* R0 - R13, P8, P15 */
946 return builtin_type_unsigned_long
;
948 else if (regno
> P3_REGNUM
&& regno
< P8_REGNUM
)
950 /* P4, CCR, DCR0, DCR1 */
951 return builtin_type_unsigned_short
;
953 else if (regno
> PC_REGNUM
&& regno
< P4_REGNUM
)
956 return builtin_type_unsigned_char
;
960 /* Invalid register. */
961 return builtin_type_void
;
965 /* Stores a function return value of type type, where valbuf is the address
966 of the value to be stored. */
968 /* In the original CRIS ABI, R10 is used to store return values. */
971 cris_abi_original_store_return_value (struct type
*type
, char *valbuf
)
973 int len
= TYPE_LENGTH (type
);
975 if (len
<= DEPRECATED_REGISTER_SIZE
)
976 deprecated_write_register_bytes (REGISTER_BYTE (RET_REGNUM
), valbuf
, len
);
978 internal_error (__FILE__
, __LINE__
, "cris_abi_original_store_return_value: type length too large.");
981 /* In the CRIS ABI V2, R10 and R11 are used to store return values. */
984 cris_abi_v2_store_return_value (struct type
*type
, char *valbuf
)
986 int len
= TYPE_LENGTH (type
);
988 if (len
<= 2 * DEPRECATED_REGISTER_SIZE
)
990 /* Note that this works since R10 and R11 are consecutive registers. */
991 deprecated_write_register_bytes (REGISTER_BYTE (RET_REGNUM
), valbuf
,
995 internal_error (__FILE__
, __LINE__
, "cris_abi_v2_store_return_value: type length too large.");
998 /* Return the name of register regno as a string. Return NULL for an invalid or
999 unimplemented register. */
1002 cris_register_name (int regno
)
1004 static char *cris_genreg_names
[] =
1005 { "r0", "r1", "r2", "r3", \
1006 "r4", "r5", "r6", "r7", \
1007 "r8", "r9", "r10", "r11", \
1008 "r12", "r13", "sp", "pc" };
1013 if (regno
>= 0 && regno
< NUM_GENREGS
)
1015 /* General register. */
1016 return cris_genreg_names
[regno
];
1018 else if (regno
>= NUM_GENREGS
&& regno
< NUM_REGS
)
1020 /* Special register (R16 - R31). cris_spec_regs is zero-based.
1021 Adjust regno accordingly. */
1022 spec_regno
= regno
- NUM_GENREGS
;
1024 /* The entries in cris_spec_regs are stored in register number order,
1025 which means we can shortcut into the array when searching it. */
1026 for (i
= spec_regno
; cris_spec_regs
[i
].name
!= NULL
; i
++)
1028 if (cris_spec_regs
[i
].number
== spec_regno
1029 && cris_spec_reg_applicable (cris_spec_regs
[i
]))
1030 /* Go with the first applicable register. */
1031 return cris_spec_regs
[i
].name
;
1033 /* Special register not applicable to this CRIS version. */
1038 /* Invalid register. */
1044 cris_register_bytes_ok (long bytes
)
1046 return (bytes
== DEPRECATED_REGISTER_BYTES
);
1049 /* Extract from an array regbuf containing the raw register state a function
1050 return value of type type, and copy that, in virtual format, into
1053 /* In the original CRIS ABI, R10 is used to return values. */
1056 cris_abi_original_extract_return_value (struct type
*type
, char *regbuf
,
1059 int len
= TYPE_LENGTH (type
);
1061 if (len
<= DEPRECATED_REGISTER_SIZE
)
1062 memcpy (valbuf
, regbuf
+ REGISTER_BYTE (RET_REGNUM
), len
);
1064 internal_error (__FILE__
, __LINE__
, "cris_abi_original_extract_return_value: type length too large");
1067 /* In the CRIS ABI V2, R10 and R11 are used to store return values. */
1070 cris_abi_v2_extract_return_value (struct type
*type
, char *regbuf
,
1073 int len
= TYPE_LENGTH (type
);
1075 if (len
<= 2 * DEPRECATED_REGISTER_SIZE
)
1076 memcpy (valbuf
, regbuf
+ REGISTER_BYTE (RET_REGNUM
), len
);
1078 internal_error (__FILE__
, __LINE__
, "cris_abi_v2_extract_return_value: type length too large");
1081 /* Store the address of the place in which to copy the structure the
1082 subroutine will return. In the CRIS ABI, R9 is used in order to pass
1083 the address of the allocated area where a structure return value must
1084 be stored. R9 is call-clobbered, which means we must save it here for
1088 cris_store_struct_return (CORE_ADDR addr
, CORE_ADDR sp
)
1090 write_register (STR_REGNUM
, addr
);
1091 struct_return_address
= addr
;
1094 /* Extract from regbuf the address where a function should return a
1095 structure value. It's not there in the CRIS ABI, so we must do it another
1099 cris_extract_struct_value_address (char *regbuf
)
1101 return struct_return_address
;
1104 /* Returns 1 if the given type will be passed by pointer rather than
1107 /* In the original CRIS ABI, arguments shorter than or equal to 32 bits are
1111 cris_abi_original_reg_struct_has_addr (int gcc_p
, struct type
*type
)
1113 return (TYPE_LENGTH (type
) > 4);
1116 /* In the CRIS ABI V2, arguments shorter than or equal to 64 bits are passed
1120 cris_abi_v2_reg_struct_has_addr (int gcc_p
, struct type
*type
)
1122 return (TYPE_LENGTH (type
) > 8);
1125 /* Returns 1 if the function invocation represented by fi does not have a
1126 stack frame associated with it. Otherwise return 0. */
1129 cris_frameless_function_invocation (struct frame_info
*fi
)
1131 if ((get_frame_type (fi
) == SIGTRAMP_FRAME
))
1134 return frameless_look_for_prologue (fi
);
1137 /* See frame.h. Determines the address of all registers in the
1138 current stack frame storing each in frame->saved_regs. Space for
1139 frame->saved_regs shall be allocated by
1140 DEPRECATED_FRAME_INIT_SAVED_REGS using frame_saved_regs_zalloc. */
1143 cris_frame_init_saved_regs (struct frame_info
*fi
)
1146 struct symtab_and_line sal
;
1148 char *dummy_regs
= deprecated_generic_find_dummy_frame (get_frame_pc (fi
),
1149 get_frame_base (fi
));
1151 /* Examine the entire prologue. */
1152 register int frameless_p
= 0;
1154 /* Has this frame's registers already been initialized? */
1155 if (get_frame_saved_regs (fi
))
1158 frame_saved_regs_zalloc (fi
);
1162 /* I don't see this ever happening, considering the context in which
1163 cris_frame_init_saved_regs is called (always when we're not in
1165 memcpy (get_frame_saved_regs (fi
), dummy_regs
, SIZEOF_FRAME_SAVED_REGS
);
1169 ip
= get_frame_func (fi
);
1170 sal
= find_pc_line (ip
, 0);
1172 /* If there is no symbol information then sal.end == 0, and we end up
1173 examining only the first instruction in the function prologue.
1174 Exaggerating the limit seems to be harmless. */
1176 best_limit
= sal
.end
;
1178 best_limit
= ip
+ 100;
1180 cris_examine (ip
, best_limit
, fi
, frameless_p
);
1184 /* Initialises the extra frame information at the creation of a new frame.
1185 The inparameter fromleaf is 0 when the call is from create_new_frame.
1186 When the call is from get_prev_frame_info, fromleaf is determined by
1187 cris_frameless_function_invocation. */
1190 cris_init_extra_frame_info (int fromleaf
, struct frame_info
*fi
)
1192 if (get_next_frame (fi
))
1194 /* Called from get_prev_frame. */
1195 deprecated_update_frame_pc_hack (fi
, DEPRECATED_FRAME_SAVED_PC (get_next_frame (fi
)));
1198 frame_extra_info_zalloc (fi
, sizeof (struct frame_extra_info
));
1200 get_frame_extra_info (fi
)->return_pc
= 0;
1201 get_frame_extra_info (fi
)->leaf_function
= 0;
1203 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi
),
1204 get_frame_base (fi
),
1205 get_frame_base (fi
)))
1207 /* We need to setup fi->frame here because call_function_by_hand
1208 gets it wrong by assuming it's always FP. */
1209 deprecated_update_frame_base_hack (fi
, deprecated_read_register_dummy (get_frame_pc (fi
), get_frame_base (fi
), SP_REGNUM
));
1210 get_frame_extra_info (fi
)->return_pc
=
1211 deprecated_read_register_dummy (get_frame_pc (fi
),
1212 get_frame_base (fi
), PC_REGNUM
);
1214 /* FIXME: Is this necessarily true? */
1215 get_frame_extra_info (fi
)->leaf_function
= 0;
1219 cris_frame_init_saved_regs (fi
);
1221 /* Check fromleaf/frameless_function_invocation. (FIXME) */
1223 if (get_frame_saved_regs (fi
)[SRP_REGNUM
] != 0)
1225 /* SRP was saved on the stack; non-leaf function. */
1226 get_frame_extra_info (fi
)->return_pc
=
1227 read_memory_integer (get_frame_saved_regs (fi
)[SRP_REGNUM
],
1228 REGISTER_RAW_SIZE (SRP_REGNUM
));
1232 /* SRP is still in a register; leaf function. */
1233 get_frame_extra_info (fi
)->return_pc
= read_register (SRP_REGNUM
);
1234 /* FIXME: Should leaf_function be set to 1 here? */
1235 get_frame_extra_info (fi
)->leaf_function
= 1;
1240 /* Return the content of the frame pointer in the present frame. In other
1241 words, determine the address of the calling function's frame. */
1244 cris_frame_chain (struct frame_info
*fi
)
1246 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi
),
1247 get_frame_base (fi
),
1248 get_frame_base (fi
)))
1250 return get_frame_base (fi
);
1252 else if (!inside_entry_file (get_frame_pc (fi
)))
1254 return read_memory_unsigned_integer (get_frame_base (fi
), 4);
1262 /* Return the saved PC (which equals the return address) of this frame. */
1265 cris_frame_saved_pc (struct frame_info
*fi
)
1267 return get_frame_extra_info (fi
)->return_pc
;
1270 /* Setup the function arguments for calling a function in the inferior. */
1273 cris_abi_original_push_arguments (int nargs
, struct value
**args
,
1274 CORE_ADDR sp
, int struct_return
,
1275 CORE_ADDR struct_addr
)
1286 /* Data and parameters reside in different areas on the stack.
1287 Both frame pointers grow toward higher addresses. */
1288 CORE_ADDR fp_params
;
1291 /* Are we returning a value using a structure return or a normal value
1292 return? struct_addr is the address of the reserved space for the return
1293 structure to be written on the stack. */
1296 write_register (STR_REGNUM
, struct_addr
);
1299 /* Make sure there's space on the stack. Allocate space for data and a
1300 parameter to refer to that data. */
1301 for (argnum
= 0, stack_alloc
= 0; argnum
< nargs
; argnum
++)
1302 stack_alloc
+= (TYPE_LENGTH (VALUE_TYPE (args
[argnum
])) + DEPRECATED_REGISTER_SIZE
);
1304 /* We may over-allocate a little here, but that won't hurt anything. */
1306 /* Initialize stack frame pointers. */
1308 fp_data
= sp
+ (nargs
* DEPRECATED_REGISTER_SIZE
);
1310 /* Now load as many as possible of the first arguments into
1311 registers, and push the rest onto the stack. */
1312 argreg
= ARG1_REGNUM
;
1315 for (argnum
= 0; argnum
< nargs
; argnum
++)
1317 type
= VALUE_TYPE (args
[argnum
]);
1318 len
= TYPE_LENGTH (type
);
1319 val
= (char *) VALUE_CONTENTS (args
[argnum
]);
1321 if (len
<= DEPRECATED_REGISTER_SIZE
&& argreg
<= ARG4_REGNUM
)
1323 /* Data fits in a register; put it in the first available
1325 write_register (argreg
, *(unsigned long *) val
);
1328 else if (len
> DEPRECATED_REGISTER_SIZE
&& argreg
<= ARG4_REGNUM
)
1330 /* Data does not fit in register; pass it on the stack and
1331 put its address in the first available register. */
1332 write_memory (fp_data
, val
, len
);
1333 write_register (argreg
, fp_data
);
1337 else if (len
> DEPRECATED_REGISTER_SIZE
)
1339 /* Data does not fit in register; put both data and
1340 parameter on the stack. */
1341 write_memory (fp_data
, val
, len
);
1342 write_memory (fp_params
, (char *) (&fp_data
), DEPRECATED_REGISTER_SIZE
);
1344 fp_params
+= DEPRECATED_REGISTER_SIZE
;
1348 /* Data fits in a register, but we are out of registers;
1349 put the parameter on the stack. */
1350 write_memory (fp_params
, val
, DEPRECATED_REGISTER_SIZE
);
1351 fp_params
+= DEPRECATED_REGISTER_SIZE
;
1359 cris_abi_v2_push_arguments (int nargs
, struct value
**args
, CORE_ADDR sp
,
1360 int struct_return
, CORE_ADDR struct_addr
)
1369 /* The function's arguments and memory allocated by gdb for the arguments to
1370 point at reside in separate areas on the stack.
1371 Both frame pointers grow toward higher addresses. */
1375 /* Are we returning a value using a structure return or a normal value
1376 return? struct_addr is the address of the reserved space for the return
1377 structure to be written on the stack. */
1380 write_register (STR_REGNUM
, struct_addr
);
1383 /* Allocate enough to keep things word-aligned on both parts of the
1386 for (argnum
= 0; argnum
< nargs
; argnum
++)
1391 len
= TYPE_LENGTH (VALUE_TYPE (args
[argnum
]));
1392 reg_demand
= (len
/ DEPRECATED_REGISTER_SIZE
) + (len
% DEPRECATED_REGISTER_SIZE
!= 0 ? 1 : 0);
1394 /* reg_demand * DEPRECATED_REGISTER_SIZE is the amount of memory
1395 we might need to allocate for this argument. 2 *
1396 DEPRECATED_REGISTER_SIZE is the amount of stack space we
1397 might need to pass the argument itself (either by value or by
1399 stack_alloc
+= (reg_demand
* DEPRECATED_REGISTER_SIZE
+ 2 * DEPRECATED_REGISTER_SIZE
);
1402 /* We may over-allocate a little here, but that won't hurt anything. */
1404 /* Initialize frame pointers. */
1406 fp_mem
= sp
+ (nargs
* (2 * DEPRECATED_REGISTER_SIZE
));
1408 /* Now load as many as possible of the first arguments into registers,
1409 and push the rest onto the stack. */
1410 argreg
= ARG1_REGNUM
;
1413 for (argnum
= 0; argnum
< nargs
; argnum
++)
1420 len
= TYPE_LENGTH (VALUE_TYPE (args
[argnum
]));
1421 val
= (char *) VALUE_CONTENTS (args
[argnum
]);
1423 /* How may registers worth of storage do we need for this argument? */
1424 reg_demand
= (len
/ DEPRECATED_REGISTER_SIZE
) + (len
% DEPRECATED_REGISTER_SIZE
!= 0 ? 1 : 0);
1426 if (len
<= (2 * DEPRECATED_REGISTER_SIZE
)
1427 && (argreg
+ reg_demand
- 1 <= ARG4_REGNUM
))
1429 /* Data passed by value. Fits in available register(s). */
1430 for (i
= 0; i
< reg_demand
; i
++)
1432 write_register (argreg
, *(unsigned long *) val
);
1434 val
+= DEPRECATED_REGISTER_SIZE
;
1437 else if (len
<= (2 * DEPRECATED_REGISTER_SIZE
) && argreg
<= ARG4_REGNUM
)
1439 /* Data passed by value. Does not fit in available register(s).
1440 Use the register(s) first, then the stack. */
1441 for (i
= 0; i
< reg_demand
; i
++)
1443 if (argreg
<= ARG4_REGNUM
)
1445 write_register (argreg
, *(unsigned long *) val
);
1447 val
+= DEPRECATED_REGISTER_SIZE
;
1451 /* I guess this memory write could write the
1452 remaining data all at once instead of in
1453 DEPRECATED_REGISTER_SIZE chunks. */
1454 write_memory (fp_arg
, val
, DEPRECATED_REGISTER_SIZE
);
1455 fp_arg
+= DEPRECATED_REGISTER_SIZE
;
1456 val
+= DEPRECATED_REGISTER_SIZE
;
1460 else if (len
> (2 * DEPRECATED_REGISTER_SIZE
))
1462 /* Data passed by reference. Put it on the stack. */
1463 write_memory (fp_mem
, val
, len
);
1464 write_memory (fp_arg
, (char *) (&fp_mem
), DEPRECATED_REGISTER_SIZE
);
1466 /* fp_mem need not be word-aligned since it's just a chunk of
1467 memory being pointed at. That is, += len would do. */
1468 fp_mem
+= reg_demand
* DEPRECATED_REGISTER_SIZE
;
1469 fp_arg
+= DEPRECATED_REGISTER_SIZE
;
1473 /* Data passed by value. No available registers. Put it on
1475 write_memory (fp_arg
, val
, len
);
1477 /* fp_arg must be word-aligned (i.e., don't += len) to match
1478 the function prologue. */
1479 fp_arg
+= reg_demand
* DEPRECATED_REGISTER_SIZE
;
1486 /* Never put the return address on the stack. The register SRP is pushed
1487 by the called function unless it is a leaf-function. Due to the BRP
1488 register the PC will change when continue is sent. */
1491 cris_push_return_address (CORE_ADDR pc
, CORE_ADDR sp
)
1493 write_register (SRP_REGNUM
, entry_point_address ());
1497 /* Restore the machine to the state it had before the current frame
1498 was created. Discard the innermost frame from the stack and restore
1499 all saved registers. */
1502 cris_pop_frame (void)
1504 register struct frame_info
*fi
= get_current_frame ();
1506 register int stack_offset
= 0;
1508 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi
),
1509 get_frame_base (fi
),
1510 get_frame_base (fi
)))
1512 /* This happens when we hit a breakpoint set at the entry point,
1513 when returning from a dummy frame. */
1514 generic_pop_dummy_frame ();
1518 cris_frame_init_saved_regs (fi
);
1520 /* For each register, the address of where it was saved on entry to
1521 the frame now lies in fi->saved_regs[regno], or zero if it was not
1522 saved. This includes special registers such as PC and FP saved in
1523 special ways in the stack frame. The SP_REGNUM is even more
1524 special, the address here is the SP for the next frame, not the
1525 address where the SP was saved. */
1527 /* Restore general registers R0 - R7. They were pushed on the stack
1528 after SP was saved. */
1529 for (regno
= 0; regno
< DEPRECATED_FP_REGNUM
; regno
++)
1531 if (get_frame_saved_regs (fi
)[regno
])
1533 write_register (regno
,
1534 read_memory_integer (get_frame_saved_regs (fi
)[regno
], 4));
1538 if (get_frame_saved_regs (fi
)[DEPRECATED_FP_REGNUM
])
1540 /* Pop the frame pointer (R8). It was pushed before SP
1542 write_register (DEPRECATED_FP_REGNUM
,
1543 read_memory_integer (get_frame_saved_regs (fi
)[DEPRECATED_FP_REGNUM
], 4));
1546 /* Not a leaf function. */
1547 if (get_frame_saved_regs (fi
)[SRP_REGNUM
])
1549 /* SRP was pushed before SP was saved. */
1553 /* Restore the SP and adjust for R8 and (possibly) SRP. */
1554 write_register (SP_REGNUM
, get_frame_saved_regs (fi
)[DEPRECATED_FP_REGNUM
] + stack_offset
);
1558 /* Currently, we can't get the correct info into fi->saved_regs
1559 without a frame pointer. */
1562 /* Restore the PC. */
1563 write_register (PC_REGNUM
, get_frame_extra_info (fi
)->return_pc
);
1565 flush_cached_frames ();
1568 /* Calculates a value that measures how good inst_args constraints an
1569 instruction. It stems from cris_constraint, found in cris-dis.c. */
1572 constraint (unsigned int insn
, const signed char *inst_args
,
1573 inst_env_type
*inst_env
)
1578 const char *s
= inst_args
;
1584 if ((insn
& 0x30) == 0x30)
1589 /* A prefix operand. */
1590 if (inst_env
->prefix_found
)
1596 /* A "push" prefix. (This check was REMOVED by san 970921.) Check for
1597 valid "push" size. In case of special register, it may be != 4. */
1598 if (inst_env
->prefix_found
)
1604 retval
= (((insn
>> 0xC) & 0xF) == (insn
& 0xF));
1612 tmp
= (insn
>> 0xC) & 0xF;
1614 for (i
= 0; cris_spec_regs
[i
].name
!= NULL
; i
++)
1616 /* Since we match four bits, we will give a value of
1617 4 - 1 = 3 in a match. If there is a corresponding
1618 exact match of a special register in another pattern, it
1619 will get a value of 4, which will be higher. This should
1620 be correct in that an exact pattern would match better that
1622 Note that there is a reason for not returning zero; the
1623 pattern for "clear" is partly matched in the bit-pattern
1624 (the two lower bits must be zero), while the bit-pattern
1625 for a move from a special register is matched in the
1626 register constraint.
1627 This also means we will will have a race condition if
1628 there is a partly match in three bits in the bit pattern. */
1629 if (tmp
== cris_spec_regs
[i
].number
)
1636 if (cris_spec_regs
[i
].name
== NULL
)
1643 /* Returns the number of bits set in the variable value. */
1646 number_of_bits (unsigned int value
)
1648 int number_of_bits
= 0;
1652 number_of_bits
+= 1;
1653 value
&= (value
- 1);
1655 return number_of_bits
;
1658 /* Finds the address that should contain the single step breakpoint(s).
1659 It stems from code in cris-dis.c. */
1662 find_cris_op (unsigned short insn
, inst_env_type
*inst_env
)
1665 int max_level_of_match
= -1;
1666 int max_matched
= -1;
1669 for (i
= 0; cris_opcodes
[i
].name
!= NULL
; i
++)
1671 if (((cris_opcodes
[i
].match
& insn
) == cris_opcodes
[i
].match
)
1672 && ((cris_opcodes
[i
].lose
& insn
) == 0))
1674 level_of_match
= constraint (insn
, cris_opcodes
[i
].args
, inst_env
);
1675 if (level_of_match
>= 0)
1678 number_of_bits (cris_opcodes
[i
].match
| cris_opcodes
[i
].lose
);
1679 if (level_of_match
> max_level_of_match
)
1682 max_level_of_match
= level_of_match
;
1683 if (level_of_match
== 16)
1685 /* All bits matched, cannot find better. */
1695 /* Attempts to find single-step breakpoints. Returns -1 on failure which is
1696 actually an internal error. */
1699 find_step_target (inst_env_type
*inst_env
)
1703 unsigned short insn
;
1705 /* Create a local register image and set the initial state. */
1706 for (i
= 0; i
< NUM_GENREGS
; i
++)
1708 inst_env
->reg
[i
] = (unsigned long) read_register (i
);
1710 offset
= NUM_GENREGS
;
1711 for (i
= 0; i
< NUM_SPECREGS
; i
++)
1713 inst_env
->preg
[i
] = (unsigned long) read_register (offset
+ i
);
1715 inst_env
->branch_found
= 0;
1716 inst_env
->slot_needed
= 0;
1717 inst_env
->delay_slot_pc_active
= 0;
1718 inst_env
->prefix_found
= 0;
1719 inst_env
->invalid
= 0;
1720 inst_env
->xflag_found
= 0;
1721 inst_env
->disable_interrupt
= 0;
1723 /* Look for a step target. */
1726 /* Read an instruction from the client. */
1727 insn
= read_memory_unsigned_integer (inst_env
->reg
[PC_REGNUM
], 2);
1729 /* If the instruction is not in a delay slot the new content of the
1730 PC is [PC] + 2. If the instruction is in a delay slot it is not
1731 that simple. Since a instruction in a delay slot cannot change
1732 the content of the PC, it does not matter what value PC will have.
1733 Just make sure it is a valid instruction. */
1734 if (!inst_env
->delay_slot_pc_active
)
1736 inst_env
->reg
[PC_REGNUM
] += 2;
1740 inst_env
->delay_slot_pc_active
= 0;
1741 inst_env
->reg
[PC_REGNUM
] = inst_env
->delay_slot_pc
;
1743 /* Analyse the present instruction. */
1744 i
= find_cris_op (insn
, inst_env
);
1747 inst_env
->invalid
= 1;
1751 cris_gdb_func (cris_opcodes
[i
].op
, insn
, inst_env
);
1753 } while (!inst_env
->invalid
1754 && (inst_env
->prefix_found
|| inst_env
->xflag_found
1755 || inst_env
->slot_needed
));
1759 /* There is no hardware single-step support. The function find_step_target
1760 digs through the opcodes in order to find all possible targets.
1761 Either one ordinary target or two targets for branches may be found. */
1764 cris_software_single_step (enum target_signal ignore
, int insert_breakpoints
)
1766 inst_env_type inst_env
;
1768 if (insert_breakpoints
)
1770 /* Analyse the present instruction environment and insert
1772 int status
= find_step_target (&inst_env
);
1775 /* Could not find a target. FIXME: Should do something. */
1779 /* Insert at most two breakpoints. One for the next PC content
1780 and possibly another one for a branch, jump, etc. */
1781 next_pc
= (CORE_ADDR
) inst_env
.reg
[PC_REGNUM
];
1782 target_insert_breakpoint (next_pc
, break_mem
[0]);
1783 if (inst_env
.branch_found
1784 && (CORE_ADDR
) inst_env
.branch_break_address
!= next_pc
)
1786 branch_target_address
=
1787 (CORE_ADDR
) inst_env
.branch_break_address
;
1788 target_insert_breakpoint (branch_target_address
, break_mem
[1]);
1789 branch_break_inserted
= 1;
1795 /* Remove breakpoints. */
1796 target_remove_breakpoint (next_pc
, break_mem
[0]);
1797 if (branch_break_inserted
)
1799 target_remove_breakpoint (branch_target_address
, break_mem
[1]);
1800 branch_break_inserted
= 0;
1805 /* Calculates the prefix value for quick offset addressing mode. */
1808 quick_mode_bdap_prefix (unsigned short inst
, inst_env_type
*inst_env
)
1810 /* It's invalid to be in a delay slot. You can't have a prefix to this
1811 instruction (not 100% sure). */
1812 if (inst_env
->slot_needed
|| inst_env
->prefix_found
)
1814 inst_env
->invalid
= 1;
1818 inst_env
->prefix_value
= inst_env
->reg
[cris_get_operand2 (inst
)];
1819 inst_env
->prefix_value
+= cris_get_bdap_quick_offset (inst
);
1821 /* A prefix doesn't change the xflag_found. But the rest of the flags
1823 inst_env
->slot_needed
= 0;
1824 inst_env
->prefix_found
= 1;
1827 /* Updates the autoincrement register. The size of the increment is derived
1828 from the size of the operation. The PC is always kept aligned on even
1832 process_autoincrement (int size
, unsigned short inst
, inst_env_type
*inst_env
)
1834 if (size
== INST_BYTE_SIZE
)
1836 inst_env
->reg
[cris_get_operand1 (inst
)] += 1;
1838 /* The PC must be word aligned, so increase the PC with one
1839 word even if the size is byte. */
1840 if (cris_get_operand1 (inst
) == REG_PC
)
1842 inst_env
->reg
[REG_PC
] += 1;
1845 else if (size
== INST_WORD_SIZE
)
1847 inst_env
->reg
[cris_get_operand1 (inst
)] += 2;
1849 else if (size
== INST_DWORD_SIZE
)
1851 inst_env
->reg
[cris_get_operand1 (inst
)] += 4;
1856 inst_env
->invalid
= 1;
1860 /* Just a forward declaration. */
1862 static unsigned long get_data_from_address (unsigned short *inst
,
1865 /* Calculates the prefix value for the general case of offset addressing
1869 bdap_prefix (unsigned short inst
, inst_env_type
*inst_env
)
1874 /* It's invalid to be in a delay slot. */
1875 if (inst_env
->slot_needed
|| inst_env
->prefix_found
)
1877 inst_env
->invalid
= 1;
1881 /* The calculation of prefix_value used to be after process_autoincrement,
1882 but that fails for an instruction such as jsr [$r0+12] which is encoded
1883 as 5f0d 0c00 30b9 when compiled with -fpic. Since PC is operand1 it
1884 mustn't be incremented until we have read it and what it points at. */
1885 inst_env
->prefix_value
= inst_env
->reg
[cris_get_operand2 (inst
)];
1887 /* The offset is an indirection of the contents of the operand1 register. */
1888 inst_env
->prefix_value
+=
1889 get_data_from_address (&inst
, inst_env
->reg
[cris_get_operand1 (inst
)]);
1891 if (cris_get_mode (inst
) == AUTOINC_MODE
)
1893 process_autoincrement (cris_get_size (inst
), inst
, inst_env
);
1896 /* A prefix doesn't change the xflag_found. But the rest of the flags
1898 inst_env
->slot_needed
= 0;
1899 inst_env
->prefix_found
= 1;
1902 /* Calculates the prefix value for the index addressing mode. */
1905 biap_prefix (unsigned short inst
, inst_env_type
*inst_env
)
1907 /* It's invalid to be in a delay slot. I can't see that it's possible to
1908 have a prefix to this instruction. So I will treat this as invalid. */
1909 if (inst_env
->slot_needed
|| inst_env
->prefix_found
)
1911 inst_env
->invalid
= 1;
1915 inst_env
->prefix_value
= inst_env
->reg
[cris_get_operand1 (inst
)];
1917 /* The offset is the operand2 value shifted the size of the instruction
1919 inst_env
->prefix_value
+=
1920 inst_env
->reg
[cris_get_operand2 (inst
)] << cris_get_size (inst
);
1922 /* If the PC is operand1 (base) the address used is the address after
1923 the main instruction, i.e. address + 2 (the PC is already compensated
1924 for the prefix operation). */
1925 if (cris_get_operand1 (inst
) == REG_PC
)
1927 inst_env
->prefix_value
+= 2;
1930 /* A prefix doesn't change the xflag_found. But the rest of the flags
1932 inst_env
->slot_needed
= 0;
1933 inst_env
->xflag_found
= 0;
1934 inst_env
->prefix_found
= 1;
1937 /* Calculates the prefix value for the double indirect addressing mode. */
1940 dip_prefix (unsigned short inst
, inst_env_type
*inst_env
)
1945 /* It's invalid to be in a delay slot. */
1946 if (inst_env
->slot_needed
|| inst_env
->prefix_found
)
1948 inst_env
->invalid
= 1;
1952 /* The prefix value is one dereference of the contents of the operand1
1954 address
= (CORE_ADDR
) inst_env
->reg
[cris_get_operand1 (inst
)];
1955 inst_env
->prefix_value
= read_memory_unsigned_integer (address
, 4);
1957 /* Check if the mode is autoincrement. */
1958 if (cris_get_mode (inst
) == AUTOINC_MODE
)
1960 inst_env
->reg
[cris_get_operand1 (inst
)] += 4;
1963 /* A prefix doesn't change the xflag_found. But the rest of the flags
1965 inst_env
->slot_needed
= 0;
1966 inst_env
->xflag_found
= 0;
1967 inst_env
->prefix_found
= 1;
1970 /* Finds the destination for a branch with 8-bits offset. */
1973 eight_bit_offset_branch_op (unsigned short inst
, inst_env_type
*inst_env
)
1978 /* If we have a prefix or are in a delay slot it's bad. */
1979 if (inst_env
->slot_needed
|| inst_env
->prefix_found
)
1981 inst_env
->invalid
= 1;
1985 /* We have a branch, find out where the branch will land. */
1986 offset
= cris_get_branch_short_offset (inst
);
1988 /* Check if the offset is signed. */
1989 if (offset
& BRANCH_SIGNED_SHORT_OFFSET_MASK
)
1994 /* The offset ends with the sign bit, set it to zero. The address
1995 should always be word aligned. */
1996 offset
&= ~BRANCH_SIGNED_SHORT_OFFSET_MASK
;
1998 inst_env
->branch_found
= 1;
1999 inst_env
->branch_break_address
= inst_env
->reg
[REG_PC
] + offset
;
2001 inst_env
->slot_needed
= 1;
2002 inst_env
->prefix_found
= 0;
2003 inst_env
->xflag_found
= 0;
2004 inst_env
->disable_interrupt
= 1;
2007 /* Finds the destination for a branch with 16-bits offset. */
2010 sixteen_bit_offset_branch_op (unsigned short inst
, inst_env_type
*inst_env
)
2014 /* If we have a prefix or is in a delay slot it's bad. */
2015 if (inst_env
->slot_needed
|| inst_env
->prefix_found
)
2017 inst_env
->invalid
= 1;
2021 /* We have a branch, find out the offset for the branch. */
2022 offset
= read_memory_integer (inst_env
->reg
[REG_PC
], 2);
2024 /* The instruction is one word longer than normal, so add one word
2026 inst_env
->reg
[REG_PC
] += 2;
2028 inst_env
->branch_found
= 1;
2029 inst_env
->branch_break_address
= inst_env
->reg
[REG_PC
] + offset
;
2032 inst_env
->slot_needed
= 1;
2033 inst_env
->prefix_found
= 0;
2034 inst_env
->xflag_found
= 0;
2035 inst_env
->disable_interrupt
= 1;
2038 /* Handles the ABS instruction. */
2041 abs_op (unsigned short inst
, inst_env_type
*inst_env
)
2046 /* ABS can't have a prefix, so it's bad if it does. */
2047 if (inst_env
->prefix_found
)
2049 inst_env
->invalid
= 1;
2053 /* Check if the operation affects the PC. */
2054 if (cris_get_operand2 (inst
) == REG_PC
)
2057 /* It's invalid to change to the PC if we are in a delay slot. */
2058 if (inst_env
->slot_needed
)
2060 inst_env
->invalid
= 1;
2064 value
= (long) inst_env
->reg
[REG_PC
];
2066 /* The value of abs (SIGNED_DWORD_MASK) is SIGNED_DWORD_MASK. */
2067 if (value
!= SIGNED_DWORD_MASK
)
2070 inst_env
->reg
[REG_PC
] = (long) value
;
2074 inst_env
->slot_needed
= 0;
2075 inst_env
->prefix_found
= 0;
2076 inst_env
->xflag_found
= 0;
2077 inst_env
->disable_interrupt
= 0;
2080 /* Handles the ADDI instruction. */
2083 addi_op (unsigned short inst
, inst_env_type
*inst_env
)
2085 /* It's invalid to have the PC as base register. And ADDI can't have
2087 if (inst_env
->prefix_found
|| (cris_get_operand1 (inst
) == REG_PC
))
2089 inst_env
->invalid
= 1;
2093 inst_env
->slot_needed
= 0;
2094 inst_env
->prefix_found
= 0;
2095 inst_env
->xflag_found
= 0;
2096 inst_env
->disable_interrupt
= 0;
2099 /* Handles the ASR instruction. */
2102 asr_op (unsigned short inst
, inst_env_type
*inst_env
)
2105 unsigned long value
;
2106 unsigned long signed_extend_mask
= 0;
2108 /* ASR can't have a prefix, so check that it doesn't. */
2109 if (inst_env
->prefix_found
)
2111 inst_env
->invalid
= 1;
2115 /* Check if the PC is the target register. */
2116 if (cris_get_operand2 (inst
) == REG_PC
)
2118 /* It's invalid to change the PC in a delay slot. */
2119 if (inst_env
->slot_needed
)
2121 inst_env
->invalid
= 1;
2124 /* Get the number of bits to shift. */
2125 shift_steps
= cris_get_asr_shift_steps (inst_env
->reg
[cris_get_operand1 (inst
)]);
2126 value
= inst_env
->reg
[REG_PC
];
2128 /* Find out how many bits the operation should apply to. */
2129 if (cris_get_size (inst
) == INST_BYTE_SIZE
)
2131 if (value
& SIGNED_BYTE_MASK
)
2133 signed_extend_mask
= 0xFF;
2134 signed_extend_mask
= signed_extend_mask
>> shift_steps
;
2135 signed_extend_mask
= ~signed_extend_mask
;
2137 value
= value
>> shift_steps
;
2138 value
|= signed_extend_mask
;
2140 inst_env
->reg
[REG_PC
] &= 0xFFFFFF00;
2141 inst_env
->reg
[REG_PC
] |= value
;
2143 else if (cris_get_size (inst
) == INST_WORD_SIZE
)
2145 if (value
& SIGNED_WORD_MASK
)
2147 signed_extend_mask
= 0xFFFF;
2148 signed_extend_mask
= signed_extend_mask
>> shift_steps
;
2149 signed_extend_mask
= ~signed_extend_mask
;
2151 value
= value
>> shift_steps
;
2152 value
|= signed_extend_mask
;
2154 inst_env
->reg
[REG_PC
] &= 0xFFFF0000;
2155 inst_env
->reg
[REG_PC
] |= value
;
2157 else if (cris_get_size (inst
) == INST_DWORD_SIZE
)
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
;
2170 inst_env
->slot_needed
= 0;
2171 inst_env
->prefix_found
= 0;
2172 inst_env
->xflag_found
= 0;
2173 inst_env
->disable_interrupt
= 0;
2176 /* Handles the ASRQ instruction. */
2179 asrq_op (unsigned short inst
, inst_env_type
*inst_env
)
2183 unsigned long value
;
2184 unsigned long signed_extend_mask
= 0;
2186 /* ASRQ can't have a prefix, so check that it doesn't. */
2187 if (inst_env
->prefix_found
)
2189 inst_env
->invalid
= 1;
2193 /* Check if the PC is the target register. */
2194 if (cris_get_operand2 (inst
) == REG_PC
)
2197 /* It's invalid to change the PC in a delay slot. */
2198 if (inst_env
->slot_needed
)
2200 inst_env
->invalid
= 1;
2203 /* The shift size is given as a 5 bit quick value, i.e. we don't
2204 want the the sign bit of the quick value. */
2205 shift_steps
= cris_get_asr_shift_steps (inst
);
2206 value
= inst_env
->reg
[REG_PC
];
2207 if (value
& SIGNED_DWORD_MASK
)
2209 signed_extend_mask
= 0xFFFFFFFF;
2210 signed_extend_mask
= signed_extend_mask
>> shift_steps
;
2211 signed_extend_mask
= ~signed_extend_mask
;
2213 value
= value
>> shift_steps
;
2214 value
|= signed_extend_mask
;
2215 inst_env
->reg
[REG_PC
] = value
;
2217 inst_env
->slot_needed
= 0;
2218 inst_env
->prefix_found
= 0;
2219 inst_env
->xflag_found
= 0;
2220 inst_env
->disable_interrupt
= 0;
2223 /* Handles the AX, EI and SETF instruction. */
2226 ax_ei_setf_op (unsigned short inst
, inst_env_type
*inst_env
)
2228 if (inst_env
->prefix_found
)
2230 inst_env
->invalid
= 1;
2233 /* Check if the instruction is setting the X flag. */
2234 if (cris_is_xflag_bit_on (inst
))
2236 inst_env
->xflag_found
= 1;
2240 inst_env
->xflag_found
= 0;
2242 inst_env
->slot_needed
= 0;
2243 inst_env
->prefix_found
= 0;
2244 inst_env
->disable_interrupt
= 1;
2247 /* Checks if the instruction is in assign mode. If so, it updates the assign
2248 register. Note that check_assign assumes that the caller has checked that
2249 there is a prefix to this instruction. The mode check depends on this. */
2252 check_assign (unsigned short inst
, inst_env_type
*inst_env
)
2254 /* Check if it's an assign addressing mode. */
2255 if (cris_get_mode (inst
) == PREFIX_ASSIGN_MODE
)
2257 /* Assign the prefix value to operand 1. */
2258 inst_env
->reg
[cris_get_operand1 (inst
)] = inst_env
->prefix_value
;
2262 /* Handles the 2-operand BOUND instruction. */
2265 two_operand_bound_op (unsigned short inst
, inst_env_type
*inst_env
)
2267 /* It's invalid to have the PC as the index operand. */
2268 if (cris_get_operand2 (inst
) == REG_PC
)
2270 inst_env
->invalid
= 1;
2273 /* Check if we have a prefix. */
2274 if (inst_env
->prefix_found
)
2276 check_assign (inst
, inst_env
);
2278 /* Check if this is an autoincrement mode. */
2279 else if (cris_get_mode (inst
) == AUTOINC_MODE
)
2281 /* It's invalid to change the PC in a delay slot. */
2282 if (inst_env
->slot_needed
)
2284 inst_env
->invalid
= 1;
2287 process_autoincrement (cris_get_size (inst
), inst
, inst_env
);
2289 inst_env
->slot_needed
= 0;
2290 inst_env
->prefix_found
= 0;
2291 inst_env
->xflag_found
= 0;
2292 inst_env
->disable_interrupt
= 0;
2295 /* Handles the 3-operand BOUND instruction. */
2298 three_operand_bound_op (unsigned short inst
, inst_env_type
*inst_env
)
2300 /* It's an error if we haven't got a prefix. And it's also an error
2301 if the PC is the destination register. */
2302 if ((!inst_env
->prefix_found
) || (cris_get_operand1 (inst
) == REG_PC
))
2304 inst_env
->invalid
= 1;
2307 inst_env
->slot_needed
= 0;
2308 inst_env
->prefix_found
= 0;
2309 inst_env
->xflag_found
= 0;
2310 inst_env
->disable_interrupt
= 0;
2313 /* Clears the status flags in inst_env. */
2316 btst_nop_op (unsigned short inst
, inst_env_type
*inst_env
)
2318 /* It's an error if we have got a prefix. */
2319 if (inst_env
->prefix_found
)
2321 inst_env
->invalid
= 1;
2325 inst_env
->slot_needed
= 0;
2326 inst_env
->prefix_found
= 0;
2327 inst_env
->xflag_found
= 0;
2328 inst_env
->disable_interrupt
= 0;
2331 /* Clears the status flags in inst_env. */
2334 clearf_di_op (unsigned short inst
, inst_env_type
*inst_env
)
2336 /* It's an error if we have got a prefix. */
2337 if (inst_env
->prefix_found
)
2339 inst_env
->invalid
= 1;
2343 inst_env
->slot_needed
= 0;
2344 inst_env
->prefix_found
= 0;
2345 inst_env
->xflag_found
= 0;
2346 inst_env
->disable_interrupt
= 1;
2349 /* Handles the CLEAR instruction if it's in register mode. */
2352 reg_mode_clear_op (unsigned short inst
, inst_env_type
*inst_env
)
2354 /* Check if the target is the PC. */
2355 if (cris_get_operand2 (inst
) == REG_PC
)
2357 /* The instruction will clear the instruction's size bits. */
2358 int clear_size
= cris_get_clear_size (inst
);
2359 if (clear_size
== INST_BYTE_SIZE
)
2361 inst_env
->delay_slot_pc
= inst_env
->reg
[REG_PC
] & 0xFFFFFF00;
2363 if (clear_size
== INST_WORD_SIZE
)
2365 inst_env
->delay_slot_pc
= inst_env
->reg
[REG_PC
] & 0xFFFF0000;
2367 if (clear_size
== INST_DWORD_SIZE
)
2369 inst_env
->delay_slot_pc
= 0x0;
2371 /* The jump will be delayed with one delay slot. So we need a delay
2373 inst_env
->slot_needed
= 1;
2374 inst_env
->delay_slot_pc_active
= 1;
2378 /* The PC will not change => no delay slot. */
2379 inst_env
->slot_needed
= 0;
2381 inst_env
->prefix_found
= 0;
2382 inst_env
->xflag_found
= 0;
2383 inst_env
->disable_interrupt
= 0;
2386 /* Handles the TEST instruction if it's in register mode. */
2389 reg_mode_test_op (unsigned short inst
, inst_env_type
*inst_env
)
2391 /* It's an error if we have got a prefix. */
2392 if (inst_env
->prefix_found
)
2394 inst_env
->invalid
= 1;
2397 inst_env
->slot_needed
= 0;
2398 inst_env
->prefix_found
= 0;
2399 inst_env
->xflag_found
= 0;
2400 inst_env
->disable_interrupt
= 0;
2404 /* Handles the CLEAR and TEST instruction if the instruction isn't
2405 in register mode. */
2408 none_reg_mode_clear_test_op (unsigned short inst
, inst_env_type
*inst_env
)
2410 /* Check if we are in a prefix mode. */
2411 if (inst_env
->prefix_found
)
2413 /* The only way the PC can change is if this instruction is in
2414 assign addressing mode. */
2415 check_assign (inst
, inst_env
);
2417 /* Indirect mode can't change the PC so just check if the mode is
2419 else if (cris_get_mode (inst
) == AUTOINC_MODE
)
2421 process_autoincrement (cris_get_size (inst
), inst
, inst_env
);
2423 inst_env
->slot_needed
= 0;
2424 inst_env
->prefix_found
= 0;
2425 inst_env
->xflag_found
= 0;
2426 inst_env
->disable_interrupt
= 0;
2429 /* Checks that the PC isn't the destination register or the instructions has
2433 dstep_logshift_mstep_neg_not_op (unsigned short inst
, inst_env_type
*inst_env
)
2435 /* It's invalid to have the PC as the destination. The instruction can't
2437 if ((cris_get_operand2 (inst
) == REG_PC
) || inst_env
->prefix_found
)
2439 inst_env
->invalid
= 1;
2443 inst_env
->slot_needed
= 0;
2444 inst_env
->prefix_found
= 0;
2445 inst_env
->xflag_found
= 0;
2446 inst_env
->disable_interrupt
= 0;
2449 /* Checks that the instruction doesn't have a prefix. */
2452 break_op (unsigned short inst
, inst_env_type
*inst_env
)
2454 /* The instruction can't have a prefix. */
2455 if (inst_env
->prefix_found
)
2457 inst_env
->invalid
= 1;
2461 inst_env
->slot_needed
= 0;
2462 inst_env
->prefix_found
= 0;
2463 inst_env
->xflag_found
= 0;
2464 inst_env
->disable_interrupt
= 1;
2467 /* Checks that the PC isn't the destination register and that the instruction
2468 doesn't have a prefix. */
2471 scc_op (unsigned short inst
, inst_env_type
*inst_env
)
2473 /* It's invalid to have the PC as the destination. The instruction can't
2475 if ((cris_get_operand2 (inst
) == REG_PC
) || inst_env
->prefix_found
)
2477 inst_env
->invalid
= 1;
2481 inst_env
->slot_needed
= 0;
2482 inst_env
->prefix_found
= 0;
2483 inst_env
->xflag_found
= 0;
2484 inst_env
->disable_interrupt
= 1;
2487 /* Handles the register mode JUMP instruction. */
2490 reg_mode_jump_op (unsigned short inst
, inst_env_type
*inst_env
)
2492 /* It's invalid to do a JUMP in a delay slot. The mode is register, so
2493 you can't have a prefix. */
2494 if ((inst_env
->slot_needed
) || (inst_env
->prefix_found
))
2496 inst_env
->invalid
= 1;
2500 /* Just change the PC. */
2501 inst_env
->reg
[REG_PC
] = inst_env
->reg
[cris_get_operand1 (inst
)];
2502 inst_env
->slot_needed
= 0;
2503 inst_env
->prefix_found
= 0;
2504 inst_env
->xflag_found
= 0;
2505 inst_env
->disable_interrupt
= 1;
2508 /* Handles the JUMP instruction for all modes except register. */
2511 none_reg_mode_jump_op (unsigned short inst
, inst_env_type
*inst_env
)
2513 unsigned long newpc
;
2516 /* It's invalid to do a JUMP in a delay slot. */
2517 if (inst_env
->slot_needed
)
2519 inst_env
->invalid
= 1;
2523 /* Check if we have a prefix. */
2524 if (inst_env
->prefix_found
)
2526 check_assign (inst
, inst_env
);
2528 /* Get the new value for the the PC. */
2530 read_memory_unsigned_integer ((CORE_ADDR
) inst_env
->prefix_value
,
2535 /* Get the new value for the PC. */
2536 address
= (CORE_ADDR
) inst_env
->reg
[cris_get_operand1 (inst
)];
2537 newpc
= read_memory_unsigned_integer (address
, 4);
2539 /* Check if we should increment a register. */
2540 if (cris_get_mode (inst
) == AUTOINC_MODE
)
2542 inst_env
->reg
[cris_get_operand1 (inst
)] += 4;
2545 inst_env
->reg
[REG_PC
] = newpc
;
2547 inst_env
->slot_needed
= 0;
2548 inst_env
->prefix_found
= 0;
2549 inst_env
->xflag_found
= 0;
2550 inst_env
->disable_interrupt
= 1;
2553 /* Handles moves to special registers (aka P-register) for all modes. */
2556 move_to_preg_op (unsigned short inst
, inst_env_type
*inst_env
)
2558 if (inst_env
->prefix_found
)
2560 /* The instruction has a prefix that means we are only interested if
2561 the instruction is in assign mode. */
2562 if (cris_get_mode (inst
) == PREFIX_ASSIGN_MODE
)
2564 /* The prefix handles the problem if we are in a delay slot. */
2565 if (cris_get_operand1 (inst
) == REG_PC
)
2567 /* Just take care of the assign. */
2568 check_assign (inst
, inst_env
);
2572 else if (cris_get_mode (inst
) == AUTOINC_MODE
)
2574 /* The instruction doesn't have a prefix, the only case left that we
2575 are interested in is the autoincrement mode. */
2576 if (cris_get_operand1 (inst
) == REG_PC
)
2578 /* If the PC is to be incremented it's invalid to be in a
2580 if (inst_env
->slot_needed
)
2582 inst_env
->invalid
= 1;
2586 /* The increment depends on the size of the special register. */
2587 if (cris_register_size (cris_get_operand2 (inst
)) == 1)
2589 process_autoincrement (INST_BYTE_SIZE
, inst
, inst_env
);
2591 else if (cris_register_size (cris_get_operand2 (inst
)) == 2)
2593 process_autoincrement (INST_WORD_SIZE
, inst
, inst_env
);
2597 process_autoincrement (INST_DWORD_SIZE
, inst
, inst_env
);
2601 inst_env
->slot_needed
= 0;
2602 inst_env
->prefix_found
= 0;
2603 inst_env
->xflag_found
= 0;
2604 inst_env
->disable_interrupt
= 1;
2607 /* Handles moves from special registers (aka P-register) for all modes
2611 none_reg_mode_move_from_preg_op (unsigned short inst
, inst_env_type
*inst_env
)
2613 if (inst_env
->prefix_found
)
2615 /* The instruction has a prefix that means we are only interested if
2616 the instruction is in assign mode. */
2617 if (cris_get_mode (inst
) == PREFIX_ASSIGN_MODE
)
2619 /* The prefix handles the problem if we are in a delay slot. */
2620 if (cris_get_operand1 (inst
) == REG_PC
)
2622 /* Just take care of the assign. */
2623 check_assign (inst
, inst_env
);
2627 /* The instruction doesn't have a prefix, the only case left that we
2628 are interested in is the autoincrement mode. */
2629 else if (cris_get_mode (inst
) == AUTOINC_MODE
)
2631 if (cris_get_operand1 (inst
) == REG_PC
)
2633 /* If the PC is to be incremented it's invalid to be in a
2635 if (inst_env
->slot_needed
)
2637 inst_env
->invalid
= 1;
2641 /* The increment depends on the size of the special register. */
2642 if (cris_register_size (cris_get_operand2 (inst
)) == 1)
2644 process_autoincrement (INST_BYTE_SIZE
, inst
, inst_env
);
2646 else if (cris_register_size (cris_get_operand2 (inst
)) == 2)
2648 process_autoincrement (INST_WORD_SIZE
, inst
, inst_env
);
2652 process_autoincrement (INST_DWORD_SIZE
, inst
, inst_env
);
2656 inst_env
->slot_needed
= 0;
2657 inst_env
->prefix_found
= 0;
2658 inst_env
->xflag_found
= 0;
2659 inst_env
->disable_interrupt
= 1;
2662 /* Handles moves from special registers (aka P-register) when the mode
2666 reg_mode_move_from_preg_op (unsigned short inst
, inst_env_type
*inst_env
)
2668 /* Register mode move from special register can't have a prefix. */
2669 if (inst_env
->prefix_found
)
2671 inst_env
->invalid
= 1;
2675 if (cris_get_operand1 (inst
) == REG_PC
)
2677 /* It's invalid to change the PC in a delay slot. */
2678 if (inst_env
->slot_needed
)
2680 inst_env
->invalid
= 1;
2683 /* The destination is the PC, the jump will have a delay slot. */
2684 inst_env
->delay_slot_pc
= inst_env
->preg
[cris_get_operand2 (inst
)];
2685 inst_env
->slot_needed
= 1;
2686 inst_env
->delay_slot_pc_active
= 1;
2690 /* If the destination isn't PC, there will be no jump. */
2691 inst_env
->slot_needed
= 0;
2693 inst_env
->prefix_found
= 0;
2694 inst_env
->xflag_found
= 0;
2695 inst_env
->disable_interrupt
= 1;
2698 /* Handles the MOVEM from memory to general register instruction. */
2701 move_mem_to_reg_movem_op (unsigned short inst
, inst_env_type
*inst_env
)
2703 if (inst_env
->prefix_found
)
2705 /* The prefix handles the problem if we are in a delay slot. Is the
2706 MOVEM instruction going to change the PC? */
2707 if (cris_get_operand2 (inst
) >= REG_PC
)
2709 inst_env
->reg
[REG_PC
] =
2710 read_memory_unsigned_integer (inst_env
->prefix_value
, 4);
2712 /* The assign value is the value after the increment. Normally, the
2713 assign value is the value before the increment. */
2714 if ((cris_get_operand1 (inst
) == REG_PC
)
2715 && (cris_get_mode (inst
) == PREFIX_ASSIGN_MODE
))
2717 inst_env
->reg
[REG_PC
] = inst_env
->prefix_value
;
2718 inst_env
->reg
[REG_PC
] += 4 * (cris_get_operand2 (inst
) + 1);
2723 /* Is the MOVEM instruction going to change the PC? */
2724 if (cris_get_operand2 (inst
) == REG_PC
)
2726 /* It's invalid to change the PC in a delay slot. */
2727 if (inst_env
->slot_needed
)
2729 inst_env
->invalid
= 1;
2732 inst_env
->reg
[REG_PC
] =
2733 read_memory_unsigned_integer (inst_env
->reg
[cris_get_operand1 (inst
)],
2736 /* The increment is not depending on the size, instead it's depending
2737 on the number of registers loaded from memory. */
2738 if ((cris_get_operand1 (inst
) == REG_PC
) && (cris_get_mode (inst
) == AUTOINC_MODE
))
2740 /* It's invalid to change the PC in a delay slot. */
2741 if (inst_env
->slot_needed
)
2743 inst_env
->invalid
= 1;
2746 inst_env
->reg
[REG_PC
] += 4 * (cris_get_operand2 (inst
) + 1);
2749 inst_env
->slot_needed
= 0;
2750 inst_env
->prefix_found
= 0;
2751 inst_env
->xflag_found
= 0;
2752 inst_env
->disable_interrupt
= 0;
2755 /* Handles the MOVEM to memory from general register instruction. */
2758 move_reg_to_mem_movem_op (unsigned short inst
, inst_env_type
*inst_env
)
2760 if (inst_env
->prefix_found
)
2762 /* The assign value is the value after the increment. Normally, the
2763 assign value is the value before the increment. */
2764 if ((cris_get_operand1 (inst
) == REG_PC
) &&
2765 (cris_get_mode (inst
) == PREFIX_ASSIGN_MODE
))
2767 /* The prefix handles the problem if we are in a delay slot. */
2768 inst_env
->reg
[REG_PC
] = inst_env
->prefix_value
;
2769 inst_env
->reg
[REG_PC
] += 4 * (cris_get_operand2 (inst
) + 1);
2774 /* The increment is not depending on the size, instead it's depending
2775 on the number of registers loaded to memory. */
2776 if ((cris_get_operand1 (inst
) == REG_PC
) && (cris_get_mode (inst
) == AUTOINC_MODE
))
2778 /* It's invalid to change the PC in a delay slot. */
2779 if (inst_env
->slot_needed
)
2781 inst_env
->invalid
= 1;
2784 inst_env
->reg
[REG_PC
] += 4 * (cris_get_operand2 (inst
) + 1);
2787 inst_env
->slot_needed
= 0;
2788 inst_env
->prefix_found
= 0;
2789 inst_env
->xflag_found
= 0;
2790 inst_env
->disable_interrupt
= 0;
2793 /* Handles the pop instruction to a general register.
2794 POP is a assembler macro for MOVE.D [SP+], Rd. */
2797 reg_pop_op (unsigned short inst
, inst_env_type
*inst_env
)
2799 /* POP can't have a prefix. */
2800 if (inst_env
->prefix_found
)
2802 inst_env
->invalid
= 1;
2805 if (cris_get_operand2 (inst
) == REG_PC
)
2807 /* It's invalid to change the PC in a delay slot. */
2808 if (inst_env
->slot_needed
)
2810 inst_env
->invalid
= 1;
2813 inst_env
->reg
[REG_PC
] =
2814 read_memory_unsigned_integer (inst_env
->reg
[REG_SP
], 4);
2816 inst_env
->slot_needed
= 0;
2817 inst_env
->prefix_found
= 0;
2818 inst_env
->xflag_found
= 0;
2819 inst_env
->disable_interrupt
= 0;
2822 /* Handles moves from register to memory. */
2825 move_reg_to_mem_index_inc_op (unsigned short inst
, inst_env_type
*inst_env
)
2827 /* Check if we have a prefix. */
2828 if (inst_env
->prefix_found
)
2830 /* The only thing that can change the PC is an assign. */
2831 check_assign (inst
, inst_env
);
2833 else if ((cris_get_operand1 (inst
) == REG_PC
)
2834 && (cris_get_mode (inst
) == AUTOINC_MODE
))
2836 /* It's invalid to change the PC in a delay slot. */
2837 if (inst_env
->slot_needed
)
2839 inst_env
->invalid
= 1;
2842 process_autoincrement (cris_get_size (inst
), inst
, inst_env
);
2844 inst_env
->slot_needed
= 0;
2845 inst_env
->prefix_found
= 0;
2846 inst_env
->xflag_found
= 0;
2847 inst_env
->disable_interrupt
= 0;
2850 /* Handles the intructions that's not yet implemented, by setting
2851 inst_env->invalid to true. */
2854 not_implemented_op (unsigned short inst
, inst_env_type
*inst_env
)
2856 inst_env
->invalid
= 1;
2859 /* Handles the XOR instruction. */
2862 xor_op (unsigned short inst
, inst_env_type
*inst_env
)
2864 /* XOR can't have a prefix. */
2865 if (inst_env
->prefix_found
)
2867 inst_env
->invalid
= 1;
2871 /* Check if the PC is the target. */
2872 if (cris_get_operand2 (inst
) == REG_PC
)
2874 /* It's invalid to change the PC in a delay slot. */
2875 if (inst_env
->slot_needed
)
2877 inst_env
->invalid
= 1;
2880 inst_env
->reg
[REG_PC
] ^= inst_env
->reg
[cris_get_operand1 (inst
)];
2882 inst_env
->slot_needed
= 0;
2883 inst_env
->prefix_found
= 0;
2884 inst_env
->xflag_found
= 0;
2885 inst_env
->disable_interrupt
= 0;
2888 /* Handles the MULS instruction. */
2891 muls_op (unsigned short inst
, inst_env_type
*inst_env
)
2893 /* MULS/U can't have a prefix. */
2894 if (inst_env
->prefix_found
)
2896 inst_env
->invalid
= 1;
2900 /* Consider it invalid if the PC is the target. */
2901 if (cris_get_operand2 (inst
) == REG_PC
)
2903 inst_env
->invalid
= 1;
2906 inst_env
->slot_needed
= 0;
2907 inst_env
->prefix_found
= 0;
2908 inst_env
->xflag_found
= 0;
2909 inst_env
->disable_interrupt
= 0;
2912 /* Handles the MULU instruction. */
2915 mulu_op (unsigned short inst
, inst_env_type
*inst_env
)
2917 /* MULS/U can't have a prefix. */
2918 if (inst_env
->prefix_found
)
2920 inst_env
->invalid
= 1;
2924 /* Consider it invalid if the PC is the target. */
2925 if (cris_get_operand2 (inst
) == REG_PC
)
2927 inst_env
->invalid
= 1;
2930 inst_env
->slot_needed
= 0;
2931 inst_env
->prefix_found
= 0;
2932 inst_env
->xflag_found
= 0;
2933 inst_env
->disable_interrupt
= 0;
2936 /* Calculate the result of the instruction for ADD, SUB, CMP AND, OR and MOVE.
2937 The MOVE instruction is the move from source to register. */
2940 add_sub_cmp_and_or_move_action (unsigned short inst
, inst_env_type
*inst_env
,
2941 unsigned long source1
, unsigned long source2
)
2943 unsigned long pc_mask
;
2944 unsigned long operation_mask
;
2946 /* Find out how many bits the operation should apply to. */
2947 if (cris_get_size (inst
) == INST_BYTE_SIZE
)
2949 pc_mask
= 0xFFFFFF00;
2950 operation_mask
= 0xFF;
2952 else if (cris_get_size (inst
) == INST_WORD_SIZE
)
2954 pc_mask
= 0xFFFF0000;
2955 operation_mask
= 0xFFFF;
2957 else if (cris_get_size (inst
) == INST_DWORD_SIZE
)
2960 operation_mask
= 0xFFFFFFFF;
2964 /* The size is out of range. */
2965 inst_env
->invalid
= 1;
2969 /* The instruction just works on uw_operation_mask bits. */
2970 source2
&= operation_mask
;
2971 source1
&= operation_mask
;
2973 /* Now calculate the result. The opcode's 3 first bits separates
2974 the different actions. */
2975 switch (cris_get_opcode (inst
) & 7)
2985 case 2: /* subtract */
2989 case 3: /* compare */
3001 inst_env
->invalid
= 1;
3007 /* Make sure that the result doesn't contain more than the instruction
3009 source2
&= operation_mask
;
3011 /* Calculate the new breakpoint address. */
3012 inst_env
->reg
[REG_PC
] &= pc_mask
;
3013 inst_env
->reg
[REG_PC
] |= source1
;
3017 /* Extends the value from either byte or word size to a dword. If the mode
3018 is zero extend then the value is extended with zero. If instead the mode
3019 is signed extend the sign bit of the value is taken into consideration. */
3021 static unsigned long
3022 do_sign_or_zero_extend (unsigned long value
, unsigned short *inst
)
3024 /* The size can be either byte or word, check which one it is.
3025 Don't check the highest bit, it's indicating if it's a zero
3027 if (cris_get_size (*inst
) & INST_WORD_SIZE
)
3032 /* Check if the instruction is signed extend. If so, check if value has
3034 if (cris_is_signed_extend_bit_on (*inst
) && (value
& SIGNED_WORD_MASK
))
3036 value
|= SIGNED_WORD_EXTEND_MASK
;
3044 /* Check if the instruction is signed extend. If so, check if value has
3046 if (cris_is_signed_extend_bit_on (*inst
) && (value
& SIGNED_BYTE_MASK
))
3048 value
|= SIGNED_BYTE_EXTEND_MASK
;
3051 /* The size should now be dword. */
3052 cris_set_size_to_dword (inst
);
3056 /* Handles the register mode for the ADD, SUB, CMP, AND, OR and MOVE
3057 instruction. The MOVE instruction is the move from source to register. */
3060 reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst
,
3061 inst_env_type
*inst_env
)
3063 unsigned long operand1
;
3064 unsigned long operand2
;
3066 /* It's invalid to have a prefix to the instruction. This is a register
3067 mode instruction and can't have a prefix. */
3068 if (inst_env
->prefix_found
)
3070 inst_env
->invalid
= 1;
3073 /* Check if the instruction has PC as its target. */
3074 if (cris_get_operand2 (inst
) == REG_PC
)
3076 if (inst_env
->slot_needed
)
3078 inst_env
->invalid
= 1;
3081 /* The instruction has the PC as its target register. */
3082 operand1
= inst_env
->reg
[cris_get_operand1 (inst
)];
3083 operand2
= inst_env
->reg
[REG_PC
];
3085 /* Check if it's a extend, signed or zero instruction. */
3086 if (cris_get_opcode (inst
) < 4)
3088 operand1
= do_sign_or_zero_extend (operand1
, &inst
);
3090 /* Calculate the PC value after the instruction, i.e. where the
3091 breakpoint should be. The order of the udw_operands is vital. */
3092 add_sub_cmp_and_or_move_action (inst
, inst_env
, operand2
, operand1
);
3094 inst_env
->slot_needed
= 0;
3095 inst_env
->prefix_found
= 0;
3096 inst_env
->xflag_found
= 0;
3097 inst_env
->disable_interrupt
= 0;
3100 /* Returns the data contained at address. The size of the data is derived from
3101 the size of the operation. If the instruction is a zero or signed
3102 extend instruction, the size field is changed in instruction. */
3104 static unsigned long
3105 get_data_from_address (unsigned short *inst
, CORE_ADDR address
)
3107 int size
= cris_get_size (*inst
);
3108 unsigned long value
;
3110 /* If it's an extend instruction we don't want the signed extend bit,
3111 because it influences the size. */
3112 if (cris_get_opcode (*inst
) < 4)
3114 size
&= ~SIGNED_EXTEND_BIT_MASK
;
3116 /* Is there a need for checking the size? Size should contain the number of
3119 value
= read_memory_unsigned_integer (address
, size
);
3121 /* Check if it's an extend, signed or zero instruction. */
3122 if (cris_get_opcode (*inst
) < 4)
3124 value
= do_sign_or_zero_extend (value
, inst
);
3129 /* Handles the assign addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
3130 instructions. The MOVE instruction is the move from source to register. */
3133 handle_prefix_assign_mode_for_aritm_op (unsigned short inst
,
3134 inst_env_type
*inst_env
)
3136 unsigned long operand2
;
3137 unsigned long operand3
;
3139 check_assign (inst
, inst_env
);
3140 if (cris_get_operand2 (inst
) == REG_PC
)
3142 operand2
= inst_env
->reg
[REG_PC
];
3144 /* Get the value of the third operand. */
3145 operand3
= get_data_from_address (&inst
, inst_env
->prefix_value
);
3147 /* Calculate the PC value after the instruction, i.e. where the
3148 breakpoint should be. The order of the udw_operands is vital. */
3149 add_sub_cmp_and_or_move_action (inst
, inst_env
, operand2
, operand3
);
3151 inst_env
->slot_needed
= 0;
3152 inst_env
->prefix_found
= 0;
3153 inst_env
->xflag_found
= 0;
3154 inst_env
->disable_interrupt
= 0;
3157 /* Handles the three-operand addressing mode for the ADD, SUB, CMP, AND and
3158 OR instructions. Note that for this to work as expected, the calling
3159 function must have made sure that there is a prefix to this instruction. */
3162 three_operand_add_sub_cmp_and_or_op (unsigned short inst
,
3163 inst_env_type
*inst_env
)
3165 unsigned long operand2
;
3166 unsigned long operand3
;
3168 if (cris_get_operand1 (inst
) == REG_PC
)
3170 /* The PC will be changed by the instruction. */
3171 operand2
= inst_env
->reg
[cris_get_operand2 (inst
)];
3173 /* Get the value of the third operand. */
3174 operand3
= get_data_from_address (&inst
, inst_env
->prefix_value
);
3176 /* Calculate the PC value after the instruction, i.e. where the
3177 breakpoint should be. */
3178 add_sub_cmp_and_or_move_action (inst
, inst_env
, operand2
, operand3
);
3180 inst_env
->slot_needed
= 0;
3181 inst_env
->prefix_found
= 0;
3182 inst_env
->xflag_found
= 0;
3183 inst_env
->disable_interrupt
= 0;
3186 /* Handles the index addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
3187 instructions. The MOVE instruction is the move from source to register. */
3190 handle_prefix_index_mode_for_aritm_op (unsigned short inst
,
3191 inst_env_type
*inst_env
)
3193 if (cris_get_operand1 (inst
) != cris_get_operand2 (inst
))
3195 /* If the instruction is MOVE it's invalid. If the instruction is ADD,
3196 SUB, AND or OR something weird is going on (if everything works these
3197 instructions should end up in the three operand version). */
3198 inst_env
->invalid
= 1;
3203 /* three_operand_add_sub_cmp_and_or does the same as we should do here
3205 three_operand_add_sub_cmp_and_or_op (inst
, inst_env
);
3207 inst_env
->slot_needed
= 0;
3208 inst_env
->prefix_found
= 0;
3209 inst_env
->xflag_found
= 0;
3210 inst_env
->disable_interrupt
= 0;
3213 /* Handles the autoincrement and indirect addresing mode for the ADD, SUB,
3214 CMP, AND OR and MOVE instruction. The MOVE instruction is the move from
3215 source to register. */
3218 handle_inc_and_index_mode_for_aritm_op (unsigned short inst
,
3219 inst_env_type
*inst_env
)
3221 unsigned long operand1
;
3222 unsigned long operand2
;
3223 unsigned long operand3
;
3226 /* The instruction is either an indirect or autoincrement addressing mode.
3227 Check if the destination register is the PC. */
3228 if (cris_get_operand2 (inst
) == REG_PC
)
3230 /* Must be done here, get_data_from_address may change the size
3232 size
= cris_get_size (inst
);
3233 operand2
= inst_env
->reg
[REG_PC
];
3235 /* Get the value of the third operand, i.e. the indirect operand. */
3236 operand1
= inst_env
->reg
[cris_get_operand1 (inst
)];
3237 operand3
= get_data_from_address (&inst
, operand1
);
3239 /* Calculate the PC value after the instruction, i.e. where the
3240 breakpoint should be. The order of the udw_operands is vital. */
3241 add_sub_cmp_and_or_move_action (inst
, inst_env
, operand2
, operand3
);
3243 /* If this is an autoincrement addressing mode, check if the increment
3245 if ((cris_get_operand1 (inst
) == REG_PC
) && (cris_get_mode (inst
) == AUTOINC_MODE
))
3247 /* Get the size field. */
3248 size
= cris_get_size (inst
);
3250 /* If it's an extend instruction we don't want the signed extend bit,
3251 because it influences the size. */
3252 if (cris_get_opcode (inst
) < 4)
3254 size
&= ~SIGNED_EXTEND_BIT_MASK
;
3256 process_autoincrement (size
, inst
, inst_env
);
3258 inst_env
->slot_needed
= 0;
3259 inst_env
->prefix_found
= 0;
3260 inst_env
->xflag_found
= 0;
3261 inst_env
->disable_interrupt
= 0;
3264 /* Handles the two-operand addressing mode, all modes except register, for
3265 the ADD, SUB CMP, AND and OR instruction. */
3268 none_reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst
,
3269 inst_env_type
*inst_env
)
3271 if (inst_env
->prefix_found
)
3273 if (cris_get_mode (inst
) == PREFIX_INDEX_MODE
)
3275 handle_prefix_index_mode_for_aritm_op (inst
, inst_env
);
3277 else if (cris_get_mode (inst
) == PREFIX_ASSIGN_MODE
)
3279 handle_prefix_assign_mode_for_aritm_op (inst
, inst_env
);
3283 /* The mode is invalid for a prefixed base instruction. */
3284 inst_env
->invalid
= 1;
3290 handle_inc_and_index_mode_for_aritm_op (inst
, inst_env
);
3294 /* Handles the quick addressing mode for the ADD and SUB instruction. */
3297 quick_mode_add_sub_op (unsigned short inst
, inst_env_type
*inst_env
)
3299 unsigned long operand1
;
3300 unsigned long operand2
;
3302 /* It's a bad idea to be in a prefix instruction now. This is a quick mode
3303 instruction and can't have a prefix. */
3304 if (inst_env
->prefix_found
)
3306 inst_env
->invalid
= 1;
3310 /* Check if the instruction has PC as its target. */
3311 if (cris_get_operand2 (inst
) == REG_PC
)
3313 if (inst_env
->slot_needed
)
3315 inst_env
->invalid
= 1;
3318 operand1
= cris_get_quick_value (inst
);
3319 operand2
= inst_env
->reg
[REG_PC
];
3321 /* The size should now be dword. */
3322 cris_set_size_to_dword (&inst
);
3324 /* Calculate the PC value after the instruction, i.e. where the
3325 breakpoint should be. */
3326 add_sub_cmp_and_or_move_action (inst
, inst_env
, operand2
, operand1
);
3328 inst_env
->slot_needed
= 0;
3329 inst_env
->prefix_found
= 0;
3330 inst_env
->xflag_found
= 0;
3331 inst_env
->disable_interrupt
= 0;
3334 /* Handles the quick addressing mode for the CMP, AND and OR instruction. */
3337 quick_mode_and_cmp_move_or_op (unsigned short inst
, inst_env_type
*inst_env
)
3339 unsigned long operand1
;
3340 unsigned long operand2
;
3342 /* It's a bad idea to be in a prefix instruction now. This is a quick mode
3343 instruction and can't have a prefix. */
3344 if (inst_env
->prefix_found
)
3346 inst_env
->invalid
= 1;
3349 /* Check if the instruction has PC as its target. */
3350 if (cris_get_operand2 (inst
) == REG_PC
)
3352 if (inst_env
->slot_needed
)
3354 inst_env
->invalid
= 1;
3357 /* The instruction has the PC as its target register. */
3358 operand1
= cris_get_quick_value (inst
);
3359 operand2
= inst_env
->reg
[REG_PC
];
3361 /* The quick value is signed, so check if we must do a signed extend. */
3362 if (operand1
& SIGNED_QUICK_VALUE_MASK
)
3365 operand1
|= SIGNED_QUICK_VALUE_EXTEND_MASK
;
3367 /* The size should now be dword. */
3368 cris_set_size_to_dword (&inst
);
3370 /* Calculate the PC value after the instruction, i.e. where the
3371 breakpoint should be. */
3372 add_sub_cmp_and_or_move_action (inst
, inst_env
, operand2
, operand1
);
3374 inst_env
->slot_needed
= 0;
3375 inst_env
->prefix_found
= 0;
3376 inst_env
->xflag_found
= 0;
3377 inst_env
->disable_interrupt
= 0;
3380 /* Translate op_type to a function and call it. */
3383 cris_gdb_func (enum cris_op_type op_type
, unsigned short inst
,
3384 inst_env_type
*inst_env
)
3388 case cris_not_implemented_op
:
3389 not_implemented_op (inst
, inst_env
);
3393 abs_op (inst
, inst_env
);
3397 addi_op (inst
, inst_env
);
3401 asr_op (inst
, inst_env
);
3405 asrq_op (inst
, inst_env
);
3408 case cris_ax_ei_setf_op
:
3409 ax_ei_setf_op (inst
, inst_env
);
3412 case cris_bdap_prefix
:
3413 bdap_prefix (inst
, inst_env
);
3416 case cris_biap_prefix
:
3417 biap_prefix (inst
, inst_env
);
3421 break_op (inst
, inst_env
);
3424 case cris_btst_nop_op
:
3425 btst_nop_op (inst
, inst_env
);
3428 case cris_clearf_di_op
:
3429 clearf_di_op (inst
, inst_env
);
3432 case cris_dip_prefix
:
3433 dip_prefix (inst
, inst_env
);
3436 case cris_dstep_logshift_mstep_neg_not_op
:
3437 dstep_logshift_mstep_neg_not_op (inst
, inst_env
);
3440 case cris_eight_bit_offset_branch_op
:
3441 eight_bit_offset_branch_op (inst
, inst_env
);
3444 case cris_move_mem_to_reg_movem_op
:
3445 move_mem_to_reg_movem_op (inst
, inst_env
);
3448 case cris_move_reg_to_mem_movem_op
:
3449 move_reg_to_mem_movem_op (inst
, inst_env
);
3452 case cris_move_to_preg_op
:
3453 move_to_preg_op (inst
, inst_env
);
3457 muls_op (inst
, inst_env
);
3461 mulu_op (inst
, inst_env
);
3464 case cris_none_reg_mode_add_sub_cmp_and_or_move_op
:
3465 none_reg_mode_add_sub_cmp_and_or_move_op (inst
, inst_env
);
3468 case cris_none_reg_mode_clear_test_op
:
3469 none_reg_mode_clear_test_op (inst
, inst_env
);
3472 case cris_none_reg_mode_jump_op
:
3473 none_reg_mode_jump_op (inst
, inst_env
);
3476 case cris_none_reg_mode_move_from_preg_op
:
3477 none_reg_mode_move_from_preg_op (inst
, inst_env
);
3480 case cris_quick_mode_add_sub_op
:
3481 quick_mode_add_sub_op (inst
, inst_env
);
3484 case cris_quick_mode_and_cmp_move_or_op
:
3485 quick_mode_and_cmp_move_or_op (inst
, inst_env
);
3488 case cris_quick_mode_bdap_prefix
:
3489 quick_mode_bdap_prefix (inst
, inst_env
);
3492 case cris_reg_mode_add_sub_cmp_and_or_move_op
:
3493 reg_mode_add_sub_cmp_and_or_move_op (inst
, inst_env
);
3496 case cris_reg_mode_clear_op
:
3497 reg_mode_clear_op (inst
, inst_env
);
3500 case cris_reg_mode_jump_op
:
3501 reg_mode_jump_op (inst
, inst_env
);
3504 case cris_reg_mode_move_from_preg_op
:
3505 reg_mode_move_from_preg_op (inst
, inst_env
);
3508 case cris_reg_mode_test_op
:
3509 reg_mode_test_op (inst
, inst_env
);
3513 scc_op (inst
, inst_env
);
3516 case cris_sixteen_bit_offset_branch_op
:
3517 sixteen_bit_offset_branch_op (inst
, inst_env
);
3520 case cris_three_operand_add_sub_cmp_and_or_op
:
3521 three_operand_add_sub_cmp_and_or_op (inst
, inst_env
);
3524 case cris_three_operand_bound_op
:
3525 three_operand_bound_op (inst
, inst_env
);
3528 case cris_two_operand_bound_op
:
3529 two_operand_bound_op (inst
, inst_env
);
3533 xor_op (inst
, inst_env
);
3538 /* This wrapper is to avoid cris_get_assembler being called before
3539 exec_bfd has been set. */
3542 cris_delayed_get_disassembler (bfd_vma addr
, disassemble_info
*info
)
3544 int (*print_insn
) (bfd_vma addr
, disassemble_info
*info
);
3545 /* FIXME: cagney/2003-08-27: It should be possible to select a CRIS
3546 disassembler, even when there is no BFD. Does something like
3547 "gdb; target remote; disassmeble *0x123" work? */
3548 gdb_assert (exec_bfd
!= NULL
);
3549 print_insn
= cris_get_disassembler (exec_bfd
);
3550 gdb_assert (print_insn
!= NULL
);
3551 return print_insn (addr
, info
);
3554 /* Copied from <asm/elf.h>. */
3555 typedef unsigned long elf_greg_t
;
3557 /* Same as user_regs_struct struct in <asm/user.h>. */
3558 typedef elf_greg_t elf_gregset_t
[35];
3560 /* Unpack an elf_gregset_t into GDB's register cache. */
3563 supply_gregset (elf_gregset_t
*gregsetp
)
3566 elf_greg_t
*regp
= *gregsetp
;
3567 static char zerobuf
[4] = {0};
3569 /* The kernel dumps all 32 registers as unsigned longs, but supply_register
3570 knows about the actual size of each register so that's no problem. */
3571 for (i
= 0; i
< NUM_GENREGS
+ NUM_SPECREGS
; i
++)
3573 supply_register (i
, (char *)®p
[i
]);
3577 /* Use a local version of this function to get the correct types for
3578 regsets, until multi-arch core support is ready. */
3581 fetch_core_registers (char *core_reg_sect
, unsigned core_reg_size
,
3582 int which
, CORE_ADDR reg_addr
)
3584 elf_gregset_t gregset
;
3589 if (core_reg_size
!= sizeof (gregset
))
3591 warning ("wrong size gregset struct in core file");
3595 memcpy (&gregset
, core_reg_sect
, sizeof (gregset
));
3596 supply_gregset (&gregset
);
3600 /* We've covered all the kinds of registers we know about here,
3601 so this must be something we wouldn't know what to do with
3602 anyway. Just ignore it. */
3607 static struct core_fns cris_elf_core_fns
=
3609 bfd_target_elf_flavour
, /* core_flavour */
3610 default_check_format
, /* check_format */
3611 default_core_sniffer
, /* core_sniffer */
3612 fetch_core_registers
, /* core_read_registers */
3616 /* Fetch (and possibly build) an appropriate link_map_offsets
3617 structure for native GNU/Linux CRIS targets using the struct
3618 offsets defined in link.h (but without actual reference to that
3621 This makes it possible to access GNU/Linux CRIS shared libraries
3622 from a GDB that was not built on an GNU/Linux CRIS host (for cross
3625 See gdb/solib-svr4.h for an explanation of these fields. */
3627 static struct link_map_offsets
*
3628 cris_linux_svr4_fetch_link_map_offsets (void)
3630 static struct link_map_offsets lmo
;
3631 static struct link_map_offsets
*lmp
= NULL
;
3637 lmo
.r_debug_size
= 8; /* The actual size is 20 bytes, but
3638 this is all we need. */
3639 lmo
.r_map_offset
= 4;
3642 lmo
.link_map_size
= 20;
3644 lmo
.l_addr_offset
= 0;
3645 lmo
.l_addr_size
= 4;
3647 lmo
.l_name_offset
= 4;
3648 lmo
.l_name_size
= 4;
3650 lmo
.l_next_offset
= 12;
3651 lmo
.l_next_size
= 4;
3653 lmo
.l_prev_offset
= 16;
3654 lmo
.l_prev_size
= 4;
3661 cris_fpless_backtrace (char *noargs
, int from_tty
)
3663 /* Points at the instruction after the jsr (except when in innermost frame
3664 where it points at the original pc). */
3667 /* Temporary variable, used for parsing from the start of the function that
3668 the pc is in, up to the pc. */
3669 CORE_ADDR tmp_pc
= 0;
3672 /* Information about current frame. */
3673 struct symtab_and_line sal
;
3676 /* Present instruction. */
3677 unsigned short insn
;
3679 /* Next instruction, lookahead. */
3680 unsigned short insn_next
;
3682 /* This is to store the offset between sp at start of function and until we
3683 reach push srp (if any). */
3684 int sp_add_later
= 0;
3685 int push_srp_found
= 0;
3689 /* Frame counter. */
3692 /* For the innermost frame, we want to look at srp in case it's a leaf
3693 function (since there's no push srp in that case). */
3694 int innermost_frame
= 1;
3696 deprecated_read_register_gen (PC_REGNUM
, (char *) &pc
);
3697 deprecated_read_register_gen (SP_REGNUM
, (char *) &sp
);
3699 /* We make an explicit return when we can't find an outer frame. */
3702 /* Get file name and line number. */
3703 sal
= find_pc_line (pc
, 0);
3705 /* Get function name. */
3706 find_pc_partial_function (pc
, &func_name
, (CORE_ADDR
*) NULL
,
3707 (CORE_ADDR
*) NULL
);
3709 /* Print information about current frame. */
3710 printf_unfiltered ("#%i 0x%08lx in %s", frame
++, pc
, func_name
);
3713 printf_unfiltered (" at %s:%i", sal
.symtab
->filename
, sal
.line
);
3715 printf_unfiltered ("\n");
3717 /* Get the start address of this function. */
3718 tmp_pc
= get_pc_function_start (pc
);
3720 /* Mini parser, only meant to find push sp and sub ...,sp from the start
3721 of the function, up to the pc. */
3724 insn
= read_memory_unsigned_integer (tmp_pc
, sizeof (short));
3725 tmp_pc
+= sizeof (short);
3728 /* push <reg> 32 bit instruction */
3729 insn_next
= read_memory_unsigned_integer (tmp_pc
,
3731 tmp_pc
+= sizeof (short);
3733 /* Recognize srp. */
3734 if (insn_next
== 0xBE7E)
3736 /* For subsequent (not this one though) push or sub which
3737 affects sp, adjust sp immediately. */
3740 /* Note: this will break if we ever encounter a
3741 push vr (1 byte) or push ccr (2 bytes). */
3746 /* Some other register was pushed. */
3757 else if (cris_get_operand2 (insn
) == SP_REGNUM
3758 && cris_get_mode (insn
) == 0x0000
3759 && cris_get_opcode (insn
) == 0x000A)
3762 val
= cris_get_quick_value (insn
);
3770 sp_add_later
+= val
;
3774 else if (cris_get_operand2 (insn
) == SP_REGNUM
3775 /* Autoincrement addressing mode. */
3776 && cris_get_mode (insn
) == 0x0003
3778 && ((insn
) & 0x03E0) >> 5 == 0x0004)
3781 val
= get_data_from_address (&insn
, tmp_pc
);
3789 sp_add_later
+= val
;
3792 else if (cris_get_operand2 (insn
) == SP_REGNUM
3793 && ((insn
& 0x0F00) >> 8) == 0x0001
3794 && (cris_get_signed_offset (insn
) < 0))
3796 /* Immediate byte offset addressing prefix word with sp as base
3797 register. Used for CRIS v8 i.e. ETRAX 100 and newer if <val>
3798 is between 64 and 128.
3799 movem r<regsave>,[sp=sp-<val>] */
3800 val
= -cris_get_signed_offset (insn
);
3801 insn_next
= read_memory_unsigned_integer (tmp_pc
,
3803 tmp_pc
+= sizeof (short);
3805 if (cris_get_mode (insn_next
) == PREFIX_ASSIGN_MODE
3806 && cris_get_opcode (insn_next
) == 0x000F
3807 && cris_get_size (insn_next
) == 0x0003
3808 && cris_get_operand1 (insn_next
) == SP_REGNUM
)
3816 sp_add_later
+= val
;
3827 /* sp should now point at where srp is stored on the stack. Update
3828 the pc to the srp. */
3829 pc
= read_memory_unsigned_integer (sp
, 4);
3831 else if (innermost_frame
)
3833 /* We couldn't find a push srp in the prologue, so this must be
3834 a leaf function, and thus we use the srp register directly.
3835 This should happen at most once, for the innermost function. */
3836 deprecated_read_register_gen (SRP_REGNUM
, (char *) &pc
);
3840 /* Couldn't find an outer frame. */
3844 /* Reset flag. (In case the innermost frame wasn't a leaf, we don't
3845 want to look at the srp register later either). */
3846 innermost_frame
= 0;
3848 /* Now, add the offset for everything up to, and including push srp,
3849 that was held back during the prologue parsing. */
3855 extern initialize_file_ftype _initialize_cris_tdep
; /* -Wmissing-prototypes */
3858 _initialize_cris_tdep (void)
3860 struct cmd_list_element
*c
;
3862 gdbarch_register (bfd_arch_cris
, cris_gdbarch_init
, cris_dump_tdep
);
3864 /* CRIS-specific user-commands. */
3865 c
= add_set_cmd ("cris-version", class_support
, var_integer
,
3866 (char *) &usr_cmd_cris_version
,
3867 "Set the current CRIS version.", &setlist
);
3868 set_cmd_sfunc (c
, cris_version_update
);
3869 add_show_from_set (c
, &showlist
);
3871 c
= add_set_enum_cmd ("cris-mode", class_support
, cris_mode_enums
,
3873 "Set the current CRIS mode.", &setlist
);
3874 set_cmd_sfunc (c
, cris_mode_update
);
3875 add_show_from_set (c
, &showlist
);
3877 c
= add_set_enum_cmd ("cris-abi", class_support
, cris_abi_enums
,
3879 "Set the current CRIS ABI version.", &setlist
);
3880 set_cmd_sfunc (c
, cris_abi_update
);
3881 add_show_from_set (c
, &showlist
);
3883 c
= add_cmd ("cris-fpless-backtrace", class_support
, cris_fpless_backtrace
,
3884 "Display call chain using the subroutine return pointer.\n"
3885 "Note that this displays the address after the jump to the "
3886 "subroutine.", &cmdlist
);
3888 add_core_fns (&cris_elf_core_fns
);
3892 /* Prints out all target specific values. */
3895 cris_dump_tdep (struct gdbarch
*gdbarch
, struct ui_file
*file
)
3897 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
3900 fprintf_unfiltered (file
, "cris_dump_tdep: tdep->cris_version = %i\n",
3901 tdep
->cris_version
);
3902 fprintf_unfiltered (file
, "cris_dump_tdep: tdep->cris_mode = %s\n",
3904 fprintf_unfiltered (file
, "cris_dump_tdep: tdep->cris_abi = %s\n",
3911 cris_version_update (char *ignore_args
, int from_tty
,
3912 struct cmd_list_element
*c
)
3914 struct gdbarch_info info
;
3916 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
3917 the set command passed as a parameter. The clone operation will
3918 include (BUG?) any ``set'' command callback, if present.
3919 Commands like ``info set'' call all the ``show'' command
3920 callbacks. Unfortunatly, for ``show'' commands cloned from
3921 ``set'', this includes callbacks belonging to ``set'' commands.
3922 Making this worse, this only occures if add_show_from_set() is
3923 called after add_cmd_sfunc() (BUG?). */
3925 /* From here on, trust the user's CRIS version setting. */
3926 if (cmd_type (c
) == set_cmd
)
3928 usr_cmd_cris_version_valid
= 1;
3930 /* Update the current architecture, if needed. */
3931 gdbarch_info_init (&info
);
3932 if (!gdbarch_update_p (info
))
3933 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_update: failed to update architecture.");
3938 cris_mode_update (char *ignore_args
, int from_tty
,
3939 struct cmd_list_element
*c
)
3941 struct gdbarch_info info
;
3943 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
3944 the set command passed as a parameter. The clone operation will
3945 include (BUG?) any ``set'' command callback, if present.
3946 Commands like ``info set'' call all the ``show'' command
3947 callbacks. Unfortunatly, for ``show'' commands cloned from
3948 ``set'', this includes callbacks belonging to ``set'' commands.
3949 Making this worse, this only occures if add_show_from_set() is
3950 called after add_cmd_sfunc() (BUG?). */
3952 /* From here on, trust the user's CRIS mode setting. */
3953 if (cmd_type (c
) == set_cmd
)
3955 usr_cmd_cris_mode_valid
= 1;
3957 /* Update the current architecture, if needed. */
3958 gdbarch_info_init (&info
);
3959 if (!gdbarch_update_p (info
))
3960 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_update: failed to update architecture.");
3965 cris_abi_update (char *ignore_args
, int from_tty
,
3966 struct cmd_list_element
*c
)
3968 struct gdbarch_info info
;
3970 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
3971 the set command passed as a parameter. The clone operation will
3972 include (BUG?) any ``set'' command callback, if present.
3973 Commands like ``info set'' call all the ``show'' command
3974 callbacks. Unfortunatly, for ``show'' commands cloned from
3975 ``set'', this includes callbacks belonging to ``set'' commands.
3976 Making this worse, this only occures if add_show_from_set() is
3977 called after add_cmd_sfunc() (BUG?). */
3979 /* From here on, trust the user's CRIS ABI setting. */
3980 if (cmd_type (c
) == set_cmd
)
3982 usr_cmd_cris_abi_valid
= 1;
3984 /* Update the current architecture, if needed. */
3985 gdbarch_info_init (&info
);
3986 if (!gdbarch_update_p (info
))
3987 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_update: failed to update architecture.");
3991 /* Copied from pa64solib.c, with a couple of minor changes. */
3994 bfd_lookup_symbol (bfd
*abfd
, const char *symname
)
3996 unsigned int storage_needed
;
3998 asymbol
**symbol_table
;
3999 unsigned int number_of_symbols
;
4001 struct cleanup
*back_to
;
4002 CORE_ADDR symaddr
= 0;
4004 storage_needed
= bfd_get_symtab_upper_bound (abfd
);
4006 if (storage_needed
> 0)
4008 symbol_table
= (asymbol
**) xmalloc (storage_needed
);
4009 back_to
= make_cleanup (free
, symbol_table
);
4010 number_of_symbols
= bfd_canonicalize_symtab (abfd
, symbol_table
);
4012 for (i
= 0; i
< number_of_symbols
; i
++)
4014 sym
= *symbol_table
++;
4015 if (!strcmp (sym
->name
, symname
))
4017 /* Bfd symbols are section relative. */
4018 symaddr
= sym
->value
+ sym
->section
->vma
;
4022 do_cleanups (back_to
);
4027 static struct gdbarch
*
4028 cris_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
4030 struct gdbarch
*gdbarch
;
4031 struct gdbarch_tdep
*tdep
;
4033 const char *cris_mode
;
4034 const char *cris_abi
;
4035 CORE_ADDR cris_abi_sym
= 0;
4038 if (usr_cmd_cris_version_valid
)
4040 /* Trust the user's CRIS version setting. */
4041 cris_version
= usr_cmd_cris_version
;
4045 /* Assume it's CRIS version 10. */
4049 if (usr_cmd_cris_mode_valid
)
4051 /* Trust the user's CRIS mode setting. */
4052 cris_mode
= usr_cmd_cris_mode
;
4054 else if (cris_version
== 10)
4056 /* Assume CRIS version 10 is in user mode. */
4057 cris_mode
= CRIS_MODE_USER
;
4061 /* Strictly speaking, older CRIS version don't have a supervisor mode,
4062 but we regard its only mode as supervisor mode. */
4063 cris_mode
= CRIS_MODE_SUPERVISOR
;
4066 if (usr_cmd_cris_abi_valid
)
4068 /* Trust the user's ABI setting. */
4069 cris_abi
= usr_cmd_cris_abi
;
4073 if (bfd_get_flavour (info
.abfd
) == bfd_target_elf_flavour
)
4075 /* An elf target uses the new ABI. */
4076 cris_abi
= CRIS_ABI_V2
;
4078 else if (bfd_get_flavour (info
.abfd
) == bfd_target_aout_flavour
)
4080 /* An a.out target may use either ABI. Look for hints in the
4082 cris_abi_sym
= bfd_lookup_symbol (info
.abfd
, CRIS_ABI_SYMBOL
);
4083 cris_abi
= cris_abi_sym
? CRIS_ABI_V2
: CRIS_ABI_ORIGINAL
;
4087 /* Unknown bfd flavour. Assume it's the new ABI. */
4088 cris_abi
= CRIS_ABI_V2
;
4091 else if (arches
!= NULL
)
4093 /* No bfd available. Stick with the ABI from the most recently
4094 selected architecture of this same family (the head of arches
4095 always points to this). (This is to avoid changing the ABI
4096 when the user updates the architecture with the 'set
4097 cris-version' command.) */
4098 cris_abi
= gdbarch_tdep (arches
->gdbarch
)->cris_abi
;
4102 /* No bfd, and no previously selected architecture available.
4103 Assume it's the new ABI. */
4104 cris_abi
= CRIS_ABI_V2
;
4107 /* Make the current settings visible to the user. */
4108 usr_cmd_cris_version
= cris_version
;
4109 usr_cmd_cris_mode
= cris_mode
;
4110 usr_cmd_cris_abi
= cris_abi
;
4112 /* Find a candidate among the list of pre-declared architectures. Both
4113 CRIS version and ABI must match. */
4114 for (arches
= gdbarch_list_lookup_by_info (arches
, &info
);
4116 arches
= gdbarch_list_lookup_by_info (arches
->next
, &info
))
4118 if ((gdbarch_tdep (arches
->gdbarch
)->cris_version
== cris_version
)
4119 && (gdbarch_tdep (arches
->gdbarch
)->cris_mode
== cris_mode
)
4120 && (gdbarch_tdep (arches
->gdbarch
)->cris_abi
== cris_abi
))
4121 return arches
->gdbarch
;
4124 /* No matching architecture was found. Create a new one. */
4125 tdep
= (struct gdbarch_tdep
*) xmalloc (sizeof (struct gdbarch_tdep
));
4126 gdbarch
= gdbarch_alloc (&info
, tdep
);
4128 /* NOTE: cagney/2002-12-06: This can be deleted when this arch is
4129 ready to unwind the PC first (see frame.c:get_prev_frame()). */
4130 set_gdbarch_deprecated_init_frame_pc (gdbarch
, init_frame_pc_default
);
4132 tdep
->cris_version
= cris_version
;
4133 tdep
->cris_mode
= cris_mode
;
4134 tdep
->cris_abi
= cris_abi
;
4136 /* INIT shall ensure that the INFO.BYTE_ORDER is non-zero. */
4137 switch (info
.byte_order
)
4139 case BFD_ENDIAN_LITTLE
:
4143 case BFD_ENDIAN_BIG
:
4144 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_init: big endian byte order in info");
4148 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_init: unknown byte order in info");
4151 /* Initialize the ABI dependent things. */
4152 if (tdep
->cris_abi
== CRIS_ABI_ORIGINAL
)
4154 set_gdbarch_double_bit (gdbarch
, 32);
4155 set_gdbarch_deprecated_push_arguments (gdbarch
, cris_abi_original_push_arguments
);
4156 set_gdbarch_deprecated_store_return_value (gdbarch
,
4157 cris_abi_original_store_return_value
);
4158 set_gdbarch_deprecated_extract_return_value
4159 (gdbarch
, cris_abi_original_extract_return_value
);
4160 set_gdbarch_reg_struct_has_addr
4161 (gdbarch
, cris_abi_original_reg_struct_has_addr
);
4163 else if (tdep
->cris_abi
== CRIS_ABI_V2
)
4165 set_gdbarch_double_bit (gdbarch
, 64);
4166 set_gdbarch_deprecated_push_arguments (gdbarch
, cris_abi_v2_push_arguments
);
4167 set_gdbarch_deprecated_store_return_value (gdbarch
, cris_abi_v2_store_return_value
);
4168 set_gdbarch_deprecated_extract_return_value
4169 (gdbarch
, cris_abi_v2_extract_return_value
);
4170 set_gdbarch_reg_struct_has_addr (gdbarch
,
4171 cris_abi_v2_reg_struct_has_addr
);
4174 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_init: unknown CRIS ABI");
4176 /* The default definition of a long double is 2 * TARGET_DOUBLE_BIT,
4177 which means we have to set this explicitly. */
4178 set_gdbarch_long_double_bit (gdbarch
, 64);
4180 /* There are 32 registers (some of which may not be implemented). */
4181 set_gdbarch_num_regs (gdbarch
, 32);
4182 set_gdbarch_sp_regnum (gdbarch
, 14);
4183 set_gdbarch_deprecated_fp_regnum (gdbarch
, 8);
4184 set_gdbarch_pc_regnum (gdbarch
, 15);
4186 set_gdbarch_register_name (gdbarch
, cris_register_name
);
4188 /* Length of ordinary registers used in push_word and a few other places.
4189 REGISTER_RAW_SIZE is the real way to know how big a register is. */
4190 set_gdbarch_deprecated_register_size (gdbarch
, 4);
4193 set_gdbarch_register_bytes_ok (gdbarch
, cris_register_bytes_ok
);
4194 set_gdbarch_software_single_step (gdbarch
, cris_software_single_step
);
4197 set_gdbarch_cannot_store_register (gdbarch
, cris_cannot_store_register
);
4198 set_gdbarch_cannot_fetch_register (gdbarch
, cris_cannot_fetch_register
);
4201 /* The total amount of space needed to store (in an array called registers)
4202 GDB's copy of the machine's register state. Note: We can not use
4203 cris_register_size at this point, since it relies on current_gdbarch
4205 switch (tdep
->cris_version
)
4211 /* Support for these may be added later. */
4212 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_init: unsupported CRIS version");
4217 /* CRIS v8 and v9, a.k.a. ETRAX 100. General registers R0 - R15
4218 (32 bits), special registers P0 - P1 (8 bits), P4 - P5 (16 bits),
4219 and P8 - P14 (32 bits). */
4220 register_bytes
= (16 * 4) + (2 * 1) + (2 * 2) + (7 * 4);
4225 /* CRIS v10 and v11, a.k.a. ETRAX 100LX. In addition to ETRAX 100,
4226 P7 (32 bits), and P15 (32 bits) have been implemented. */
4227 register_bytes
= (16 * 4) + (2 * 1) + (2 * 2) + (9 * 4);
4231 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_init: unknown CRIS version");
4234 set_gdbarch_deprecated_register_bytes (gdbarch
, register_bytes
);
4236 /* Returns the register offset for the first byte of register regno's space
4237 in the saved register state. */
4238 set_gdbarch_deprecated_register_byte (gdbarch
, cris_register_offset
);
4240 /* The length of the registers in the actual machine representation. */
4241 set_gdbarch_deprecated_register_raw_size (gdbarch
, cris_register_size
);
4243 /* The largest value REGISTER_RAW_SIZE can have. */
4244 set_gdbarch_deprecated_max_register_raw_size (gdbarch
, 32);
4246 /* The length of the registers in the program's representation. */
4247 set_gdbarch_deprecated_register_virtual_size (gdbarch
, cris_register_size
);
4249 /* The largest value REGISTER_VIRTUAL_SIZE can have. */
4250 set_gdbarch_deprecated_max_register_virtual_size (gdbarch
, 32);
4252 set_gdbarch_deprecated_register_virtual_type (gdbarch
, cris_register_virtual_type
);
4254 /* Use generic dummy frames. */
4256 /* Read all about dummy frames in blockframe.c. */
4257 set_gdbarch_deprecated_pc_in_call_dummy (gdbarch
, deprecated_pc_in_call_dummy_at_entry_point
);
4259 /* Defined to 1 to indicate that the target supports inferior function
4261 set_gdbarch_deprecated_call_dummy_words (gdbarch
, 0);
4262 set_gdbarch_deprecated_sizeof_call_dummy_words (gdbarch
, 0);
4264 set_gdbarch_deprecated_get_saved_register (gdbarch
, deprecated_generic_get_saved_register
);
4266 set_gdbarch_deprecated_push_return_address (gdbarch
, cris_push_return_address
);
4267 set_gdbarch_deprecated_pop_frame (gdbarch
, cris_pop_frame
);
4269 set_gdbarch_deprecated_store_struct_return (gdbarch
, cris_store_struct_return
);
4270 set_gdbarch_deprecated_extract_struct_value_address
4271 (gdbarch
, cris_extract_struct_value_address
);
4272 set_gdbarch_use_struct_convention (gdbarch
, always_use_struct_convention
);
4274 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch
, cris_frame_init_saved_regs
);
4275 set_gdbarch_deprecated_init_extra_frame_info (gdbarch
, cris_init_extra_frame_info
);
4276 set_gdbarch_skip_prologue (gdbarch
, cris_skip_prologue
);
4277 set_gdbarch_prologue_frameless_p (gdbarch
, generic_prologue_frameless_p
);
4279 /* The stack grows downward. */
4280 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
4282 set_gdbarch_breakpoint_from_pc (gdbarch
, cris_breakpoint_from_pc
);
4284 /* The PC must not be decremented after a breakpoint. (The breakpoint
4285 handler takes care of that.) */
4286 set_gdbarch_decr_pc_after_break (gdbarch
, 0);
4288 /* Offset from address of function to start of its code. */
4289 set_gdbarch_function_start_offset (gdbarch
, 0);
4291 /* The number of bytes at the start of arglist that are not really args,
4292 0 in the CRIS ABI. */
4293 set_gdbarch_frame_args_skip (gdbarch
, 0);
4294 set_gdbarch_frameless_function_invocation
4295 (gdbarch
, cris_frameless_function_invocation
);
4296 set_gdbarch_deprecated_frame_chain (gdbarch
, cris_frame_chain
);
4298 set_gdbarch_deprecated_frame_saved_pc (gdbarch
, cris_frame_saved_pc
);
4299 set_gdbarch_deprecated_saved_pc_after_call (gdbarch
, cris_saved_pc_after_call
);
4301 /* Helpful for backtracing and returning in a call dummy. */
4302 set_gdbarch_deprecated_save_dummy_frame_tos (gdbarch
, generic_save_dummy_frame_tos
);
4304 /* Should be using push_dummy_call. */
4305 set_gdbarch_deprecated_dummy_write_sp (gdbarch
, deprecated_write_sp
);
4307 /* Use target_specific function to define link map offsets. */
4308 set_solib_svr4_fetch_link_map_offsets
4309 (gdbarch
, cris_linux_svr4_fetch_link_map_offsets
);
4311 /* FIXME: cagney/2003-08-27: It should be possible to select a CRIS
4312 disassembler, even when there is no BFD. Does something like
4313 "gdb; target remote; disassmeble *0x123" work? */
4314 set_gdbarch_print_insn (gdbarch
, cris_delayed_get_disassembler
);