1 /* Target dependent code for CRIS, for GDB, the GNU debugger.
3 Copyright 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
5 Contributed by Axis Communications AB.
6 Written by Hendrik Ruijter, Stefan Andersson, and Orjan Friberg.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
33 #include "opcode/cris.h"
34 #include "arch-utils.h"
36 #include "gdb_assert.h"
38 /* To get entry_point_address. */
41 #include "solib.h" /* Support for shared libraries. */
42 #include "solib-svr4.h" /* For struct link_map_offsets. */
43 #include "gdb_string.h"
49 /* There are no floating point registers. Used in gdbserver low-linux.c. */
52 /* There are 16 general registers. */
55 /* There are 16 special registers. */
59 /* Register numbers of various important registers.
60 DEPRECATED_FP_REGNUM Contains address of executing stack frame.
61 STR_REGNUM Contains the address of structure return values.
62 RET_REGNUM Contains the return value when shorter than or equal to 32 bits
63 ARG1_REGNUM Contains the first parameter to a function.
64 ARG2_REGNUM Contains the second parameter to a function.
65 ARG3_REGNUM Contains the third parameter to a function.
66 ARG4_REGNUM Contains the fourth parameter to a function. Rest on stack.
67 SP_REGNUM Contains address of top of stack.
68 PC_REGNUM Contains address of next instruction.
69 SRP_REGNUM Subroutine return pointer register.
70 BRP_REGNUM Breakpoint return pointer register. */
72 /* DEPRECATED_FP_REGNUM = 8, SP_REGNUM = 14, and PC_REGNUM = 15 have
73 been incorporated into the multi-arch framework. */
77 /* Enums with respect to the general registers, valid for all
86 /* Enums with respect to the special registers, some of which may not be
87 applicable to all CRIS versions. */
105 extern const struct cris_spec_reg cris_spec_regs
[];
107 /* CRIS version, set via the user command 'set cris-version'. Affects
108 register names and sizes.*/
109 static int usr_cmd_cris_version
;
111 /* Indicates whether to trust the above variable. */
112 static int usr_cmd_cris_version_valid
= 0;
114 /* CRIS mode, set via the user command 'set cris-mode'. Affects availability
115 of some registers. */
116 static const char *usr_cmd_cris_mode
;
118 /* Indicates whether to trust the above variable. */
119 static int usr_cmd_cris_mode_valid
= 0;
121 static const char CRIS_MODE_USER
[] = "CRIS_MODE_USER";
122 static const char CRIS_MODE_SUPERVISOR
[] = "CRIS_MODE_SUPERVISOR";
123 static const char *cris_mode_enums
[] =
126 CRIS_MODE_SUPERVISOR
,
130 /* CRIS ABI, set via the user command 'set cris-abi'.
131 There are two flavours:
132 1. Original ABI with 32-bit doubles, where arguments <= 4 bytes are
134 2. New ABI with 64-bit doubles, where arguments <= 8 bytes are passed by
136 static const char *usr_cmd_cris_abi
;
138 /* Indicates whether to trust the above variable. */
139 static int usr_cmd_cris_abi_valid
= 0;
141 /* These variables are strings instead of enums to make them usable as
142 parameters to add_set_enum_cmd. */
143 static const char CRIS_ABI_ORIGINAL
[] = "CRIS_ABI_ORIGINAL";
144 static const char CRIS_ABI_V2
[] = "CRIS_ABI_V2";
145 static const char CRIS_ABI_SYMBOL
[] = ".$CRIS_ABI_V2";
146 static const char *cris_abi_enums
[] =
153 /* CRIS architecture specific information. */
157 const char *cris_mode
;
158 const char *cris_abi
;
161 /* Functions for accessing target dependent data. */
166 return (gdbarch_tdep (current_gdbarch
)->cris_version
);
172 return (gdbarch_tdep (current_gdbarch
)->cris_mode
);
178 return (gdbarch_tdep (current_gdbarch
)->cris_abi
);
181 struct frame_extra_info
187 /* The instruction environment needed to find single-step breakpoints. */
189 struct instruction_environment
191 unsigned long reg
[NUM_GENREGS
];
192 unsigned long preg
[NUM_SPECREGS
];
193 unsigned long branch_break_address
;
194 unsigned long delay_slot_pc
;
195 unsigned long prefix_value
;
200 int delay_slot_pc_active
;
202 int disable_interrupt
;
205 /* Save old breakpoints in order to restore the state before a single_step.
206 At most, two breakpoints will have to be remembered. */
208 char binsn_quantum
[BREAKPOINT_MAX
];
209 static binsn_quantum break_mem
[2];
210 static CORE_ADDR next_pc
= 0;
211 static CORE_ADDR branch_target_address
= 0;
212 static unsigned char branch_break_inserted
= 0;
214 /* Machine-dependencies in CRIS for opcodes. */
216 /* Instruction sizes. */
217 enum cris_instruction_sizes
224 /* Addressing modes. */
225 enum cris_addressing_modes
232 /* Prefix addressing modes. */
233 enum cris_prefix_addressing_modes
235 PREFIX_INDEX_MODE
= 2,
236 PREFIX_ASSIGN_MODE
= 3,
238 /* Handle immediate byte offset addressing mode prefix format. */
239 PREFIX_OFFSET_MODE
= 2
242 /* Masks for opcodes. */
243 enum cris_opcode_masks
245 BRANCH_SIGNED_SHORT_OFFSET_MASK
= 0x1,
246 SIGNED_EXTEND_BIT_MASK
= 0x2,
247 SIGNED_BYTE_MASK
= 0x80,
248 SIGNED_BYTE_EXTEND_MASK
= 0xFFFFFF00,
249 SIGNED_WORD_MASK
= 0x8000,
250 SIGNED_WORD_EXTEND_MASK
= 0xFFFF0000,
251 SIGNED_DWORD_MASK
= 0x80000000,
252 SIGNED_QUICK_VALUE_MASK
= 0x20,
253 SIGNED_QUICK_VALUE_EXTEND_MASK
= 0xFFFFFFC0
256 /* Functions for opcodes. The general form of the ETRAX 16-bit instruction:
264 cris_get_operand2 (unsigned short insn
)
266 return ((insn
& 0xF000) >> 12);
270 cris_get_mode (unsigned short insn
)
272 return ((insn
& 0x0C00) >> 10);
276 cris_get_opcode (unsigned short insn
)
278 return ((insn
& 0x03C0) >> 6);
282 cris_get_size (unsigned short insn
)
284 return ((insn
& 0x0030) >> 4);
288 cris_get_operand1 (unsigned short insn
)
290 return (insn
& 0x000F);
293 /* Additional functions in order to handle opcodes. */
296 cris_get_wide_opcode (unsigned short insn
)
298 return ((insn
& 0x03E0) >> 5);
302 cris_get_short_size (unsigned short insn
)
304 return ((insn
& 0x0010) >> 4);
308 cris_get_quick_value (unsigned short insn
)
310 return (insn
& 0x003F);
314 cris_get_bdap_quick_offset (unsigned short insn
)
316 return (insn
& 0x00FF);
320 cris_get_branch_short_offset (unsigned short insn
)
322 return (insn
& 0x00FF);
326 cris_get_asr_shift_steps (unsigned long value
)
328 return (value
& 0x3F);
332 cris_get_asr_quick_shift_steps (unsigned short insn
)
334 return (insn
& 0x1F);
338 cris_get_clear_size (unsigned short insn
)
340 return ((insn
) & 0xC000);
344 cris_is_signed_extend_bit_on (unsigned short insn
)
346 return (((insn
) & 0x20) == 0x20);
350 cris_is_xflag_bit_on (unsigned short insn
)
352 return (((insn
) & 0x1000) == 0x1000);
356 cris_set_size_to_dword (unsigned short *insn
)
363 cris_get_signed_offset (unsigned short insn
)
365 return ((signed char) (insn
& 0x00FF));
368 /* Calls an op function given the op-type, working on the insn and the
370 static void cris_gdb_func (enum cris_op_type
, unsigned short, inst_env_type
*);
372 static CORE_ADDR
cris_skip_prologue_main (CORE_ADDR pc
, int frameless_p
);
374 static struct gdbarch
*cris_gdbarch_init (struct gdbarch_info
,
375 struct gdbarch_list
*);
377 static void cris_dump_tdep (struct gdbarch
*, struct ui_file
*);
379 static void cris_version_update (char *ignore_args
, int from_tty
,
380 struct cmd_list_element
*c
);
382 static void cris_mode_update (char *ignore_args
, int from_tty
,
383 struct cmd_list_element
*c
);
385 static void cris_abi_update (char *ignore_args
, int from_tty
,
386 struct cmd_list_element
*c
);
388 static CORE_ADDR
bfd_lookup_symbol (bfd
*, const char *);
390 /* Frames information. The definition of the struct frame_info is
394 enum frame_type type;
398 If the compilation option -fno-omit-frame-pointer is present the
399 variable frame will be set to the content of R8 which is the frame
402 The variable pc contains the address where execution is performed
403 in the present frame. The innermost frame contains the current content
404 of the register PC. All other frames contain the content of the
405 register PC in the next frame.
407 The variable `type' indicates the frame's type: normal, SIGTRAMP
408 (associated with a signal handler), dummy (associated with a dummy
411 The variable return_pc contains the address where execution should be
412 resumed when the present frame has finished, the return address.
414 The variable leaf_function is 1 if the return address is in the register
415 SRP, and 0 if it is on the stack.
417 Prologue instructions C-code.
418 The prologue may consist of (-fno-omit-frame-pointer)
422 move.d sp,r8 move.d sp,r8
424 movem rY,[sp] movem rY,[sp]
425 move.S rZ,[r8-U] move.S rZ,[r8-U]
427 where 1 is a non-terminal function, and 2 is a leaf-function.
429 Note that this assumption is extremely brittle, and will break at the
430 slightest change in GCC's prologue.
432 If local variables are declared or register contents are saved on stack
433 the subq-instruction will be present with X as the number of bytes
434 needed for storage. The reshuffle with respect to r8 may be performed
435 with any size S (b, w, d) and any of the general registers Z={0..13}.
436 The offset U should be representable by a signed 8-bit value in all cases.
437 Thus, the prefix word is assumed to be immediate byte offset mode followed
438 by another word containing the instruction.
447 Prologue instructions C++-code.
448 Case 1) and 2) in the C-code may be followed by
454 move.S [r8+U],rZ ; P4
456 if any of the call parameters are stored. The host expects these
457 instructions to be executed in order to get the call parameters right. */
459 /* Examine the prologue of a function. The variable ip is the address of
460 the first instruction of the prologue. The variable limit is the address
461 of the first instruction after the prologue. The variable fi contains the
462 information in struct frame_info. The variable frameless_p controls whether
463 the entire prologue is examined (0) or just enough instructions to
464 determine that it is a prologue (1). */
467 cris_examine (CORE_ADDR ip
, CORE_ADDR limit
, struct frame_info
*fi
,
470 /* Present instruction. */
473 /* Next instruction, lookahead. */
474 unsigned short insn_next
;
477 /* Is there a push fp? */
480 /* Number of byte on stack used for local variables and movem. */
483 /* Highest register number in a movem. */
486 /* move.d r<source_register>,rS */
487 short source_register
;
489 /* This frame is with respect to a leaf until a push srp is found. */
490 get_frame_extra_info (fi
)->leaf_function
= 1;
492 /* This frame is without the FP until a push fp is found. */
495 /* Assume nothing on stack. */
499 /* No information about register contents so far. */
501 /* We only want to know the end of the prologue when fi->saved_regs == 0.
502 When the saved registers are allocated full information is required. */
503 if (deprecated_get_frame_saved_regs (fi
))
505 for (regno
= 0; regno
< NUM_REGS
; regno
++)
506 deprecated_get_frame_saved_regs (fi
)[regno
] = 0;
509 /* Find the prologue instructions. */
512 insn
= read_memory_unsigned_integer (ip
, sizeof (short));
513 ip
+= sizeof (short);
516 /* push <reg> 32 bit instruction */
517 insn_next
= read_memory_unsigned_integer (ip
, sizeof (short));
518 ip
+= sizeof (short);
519 regno
= cris_get_operand2 (insn_next
);
521 /* This check, meant to recognize srp, used to be regno ==
522 (SRP_REGNUM - NUM_GENREGS), but that covers r11 also. */
523 if (insn_next
== 0xBE7E)
529 get_frame_extra_info (fi
)->leaf_function
= 0;
531 else if (regno
== DEPRECATED_FP_REGNUM
)
536 else if (insn
== 0x866E)
545 else if (cris_get_operand2 (insn
) == SP_REGNUM
546 && cris_get_mode (insn
) == 0x0000
547 && cris_get_opcode (insn
) == 0x000A)
550 val
= cris_get_quick_value (insn
);
552 else if (cris_get_mode (insn
) == 0x0002
553 && cris_get_opcode (insn
) == 0x000F
554 && cris_get_size (insn
) == 0x0003
555 && cris_get_operand1 (insn
) == SP_REGNUM
)
557 /* movem r<regsave>,[sp] */
562 regsave
= cris_get_operand2 (insn
);
564 else if (cris_get_operand2 (insn
) == SP_REGNUM
565 && ((insn
& 0x0F00) >> 8) == 0x0001
566 && (cris_get_signed_offset (insn
) < 0))
568 /* Immediate byte offset addressing prefix word with sp as base
569 register. Used for CRIS v8 i.e. ETRAX 100 and newer if <val>
570 is between 64 and 128.
571 movem r<regsave>,[sp=sp-<val>] */
572 val
= -cris_get_signed_offset (insn
);
573 insn_next
= read_memory_unsigned_integer (ip
, sizeof (short));
574 ip
+= sizeof (short);
575 if (cris_get_mode (insn_next
) == PREFIX_ASSIGN_MODE
576 && cris_get_opcode (insn_next
) == 0x000F
577 && cris_get_size (insn_next
) == 0x0003
578 && cris_get_operand1 (insn_next
) == SP_REGNUM
)
584 regsave
= cris_get_operand2 (insn_next
);
588 /* The prologue ended before the limit was reached. */
589 ip
-= 2 * sizeof (short);
593 else if (cris_get_mode (insn
) == 0x0001
594 && cris_get_opcode (insn
) == 0x0009
595 && cris_get_size (insn
) == 0x0002)
597 /* move.d r<10..13>,r<0..15> */
602 source_register
= cris_get_operand1 (insn
);
604 /* FIXME? In the glibc solibs, the prologue might contain something
605 like (this example taken from relocate_doit):
608 which isn't covered by the source_register check below. Question
609 is whether to add a check for this combo, or make better use of
610 the limit variable instead. */
611 if (source_register
< ARG1_REGNUM
|| source_register
> ARG4_REGNUM
)
613 /* The prologue ended before the limit was reached. */
614 ip
-= sizeof (short);
618 else if (cris_get_operand2 (insn
) == DEPRECATED_FP_REGNUM
619 /* The size is a fixed-size. */
620 && ((insn
& 0x0F00) >> 8) == 0x0001
621 /* A negative offset. */
622 && (cris_get_signed_offset (insn
) < 0))
624 /* move.S rZ,[r8-U] (?) */
625 insn_next
= read_memory_unsigned_integer (ip
, sizeof (short));
626 ip
+= sizeof (short);
627 regno
= cris_get_operand2 (insn_next
);
628 if ((regno
>= 0 && regno
< SP_REGNUM
)
629 && cris_get_mode (insn_next
) == PREFIX_OFFSET_MODE
630 && cris_get_opcode (insn_next
) == 0x000F)
632 /* move.S rZ,[r8-U] */
637 /* The prologue ended before the limit was reached. */
638 ip
-= 2 * sizeof (short);
642 else if (cris_get_operand2 (insn
) == DEPRECATED_FP_REGNUM
643 /* The size is a fixed-size. */
644 && ((insn
& 0x0F00) >> 8) == 0x0001
645 /* A positive offset. */
646 && (cris_get_signed_offset (insn
) > 0))
648 /* move.S [r8+U],rZ (?) */
649 insn_next
= read_memory_unsigned_integer (ip
, sizeof (short));
650 ip
+= sizeof (short);
651 regno
= cris_get_operand2 (insn_next
);
652 if ((regno
>= 0 && regno
< SP_REGNUM
)
653 && cris_get_mode (insn_next
) == PREFIX_OFFSET_MODE
654 && cris_get_opcode (insn_next
) == 0x0009
655 && cris_get_operand1 (insn_next
) == regno
)
657 /* move.S [r8+U],rZ */
662 /* The prologue ended before the limit was reached. */
663 ip
-= 2 * sizeof (short);
669 /* The prologue ended before the limit was reached. */
670 ip
-= sizeof (short);
676 /* We only want to know the end of the prologue when
677 fi->saved_regs == 0. */
678 if (!deprecated_get_frame_saved_regs (fi
))
683 deprecated_get_frame_saved_regs (fi
)[DEPRECATED_FP_REGNUM
] = get_frame_base (fi
);
685 /* Calculate the addresses. */
686 for (regno
= regsave
; regno
>= 0; regno
--)
688 deprecated_get_frame_saved_regs (fi
)[regno
] = get_frame_base (fi
) - val
;
691 if (get_frame_extra_info (fi
)->leaf_function
)
693 /* Set the register SP to contain the stack pointer of
695 deprecated_get_frame_saved_regs (fi
)[SP_REGNUM
] = get_frame_base (fi
) + 4;
699 /* Set the register SP to contain the stack pointer of
701 deprecated_get_frame_saved_regs (fi
)[SP_REGNUM
] = get_frame_base (fi
) + 8;
703 /* Set the register SRP to contain the return address of
705 deprecated_get_frame_saved_regs (fi
)[SRP_REGNUM
] = get_frame_base (fi
) + 4;
711 /* Advance pc beyond any function entry prologue instructions at pc
712 to reach some "real" code. */
715 cris_skip_prologue (CORE_ADDR pc
)
717 return cris_skip_prologue_main (pc
, 0);
720 /* As cris_skip_prologue, but stops as soon as it knows that the function
721 has a frame. Its result is equal to its input pc if the function is
722 frameless, unequal otherwise. */
725 cris_skip_prologue_frameless_p (CORE_ADDR pc
)
727 return cris_skip_prologue_main (pc
, 1);
730 /* Given a PC value corresponding to the start of a function, return the PC
731 of the first instruction after the function prologue. */
734 cris_skip_prologue_main (CORE_ADDR pc
, int frameless_p
)
736 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
737 struct frame_info
*fi
;
738 struct symtab_and_line sal
= find_pc_line (pc
, 0);
740 CORE_ADDR pc_after_prologue
;
742 /* frame_info now contains dynamic memory. Since fi is a dummy
743 here, I don't bother allocating memory for saved_regs. */
744 fi
= deprecated_frame_xmalloc_with_cleanup (0, sizeof (struct frame_extra_info
));
746 /* If there is no symbol information then sal.end == 0, and we end up
747 examining only the first instruction in the function prologue.
748 Exaggerating the limit seems to be harmless. */
750 best_limit
= sal
.end
;
752 best_limit
= pc
+ 100;
754 pc_after_prologue
= cris_examine (pc
, best_limit
, fi
, frameless_p
);
755 do_cleanups (old_chain
);
756 return pc_after_prologue
;
759 /* Use the program counter to determine the contents and size of a breakpoint
760 instruction. It returns a pointer to a string of bytes that encode a
761 breakpoint instruction, stores the length of the string to *lenptr, and
762 adjusts pcptr (if necessary) to point to the actual memory location where
763 the breakpoint should be inserted. */
765 static const unsigned char *
766 cris_breakpoint_from_pc (CORE_ADDR
*pcptr
, int *lenptr
)
768 static unsigned char break_insn
[] = {0x38, 0xe9};
774 /* Returns the register SRP (subroutine return pointer) which must contain
775 the content of the register PC after a function call. */
778 cris_saved_pc_after_call (struct frame_info
*frame
)
780 return read_register (SRP_REGNUM
);
783 /* Returns 1 if spec_reg is applicable to the current gdbarch's CRIS version,
787 cris_spec_reg_applicable (struct cris_spec_reg spec_reg
)
789 int version
= cris_version ();
791 switch (spec_reg
.applicable_version
)
793 case cris_ver_version_all
:
795 case cris_ver_warning
:
796 /* Indeterminate/obsolete. */
799 /* Simulator only. */
802 return (version
>= 0 && version
<= 3);
804 return (version
>= 3);
806 return (version
== 8 || version
== 9);
808 return (version
>= 8);
810 return (version
>= 10);
812 /* Invalid cris version. */
817 /* Returns the register size in unit byte. Returns 0 for an unimplemented
818 register, -1 for an invalid register. */
821 cris_register_size (int regno
)
826 if (regno
>= 0 && regno
< NUM_GENREGS
)
828 /* General registers (R0 - R15) are 32 bits. */
831 else if (regno
>= NUM_GENREGS
&& regno
< NUM_REGS
)
833 /* Special register (R16 - R31). cris_spec_regs is zero-based.
834 Adjust regno accordingly. */
835 spec_regno
= regno
- NUM_GENREGS
;
837 /* The entries in cris_spec_regs are stored in register number order,
838 which means we can shortcut into the array when searching it. */
839 for (i
= spec_regno
; cris_spec_regs
[i
].name
!= NULL
; i
++)
841 if (cris_spec_regs
[i
].number
== spec_regno
842 && cris_spec_reg_applicable (cris_spec_regs
[i
]))
843 /* Go with the first applicable register. */
844 return cris_spec_regs
[i
].reg_size
;
846 /* Special register not applicable to this CRIS version. */
851 /* Invalid register. */
856 /* Nonzero if regno should not be fetched from the target. This is the case
857 for unimplemented (size 0) and non-existant registers. */
860 cris_cannot_fetch_register (int regno
)
862 return ((regno
< 0 || regno
>= NUM_REGS
)
863 || (cris_register_size (regno
) == 0));
866 /* Nonzero if regno should not be written to the target, for various
870 cris_cannot_store_register (int regno
)
872 /* There are three kinds of registers we refuse to write to.
873 1. Those that not implemented.
874 2. Those that are read-only (depends on the processor mode).
875 3. Those registers to which a write has no effect.
878 if (regno
< 0 || regno
>= NUM_REGS
|| cris_register_size (regno
) == 0)
879 /* Not implemented. */
882 else if (regno
== VR_REGNUM
)
886 else if (regno
== P0_REGNUM
|| regno
== P4_REGNUM
|| regno
== P8_REGNUM
)
887 /* Writing has no effect. */
890 else if (cris_mode () == CRIS_MODE_USER
)
892 if (regno
== IBR_REGNUM
|| regno
== BAR_REGNUM
|| regno
== BRP_REGNUM
893 || regno
== IRP_REGNUM
)
894 /* Read-only in user mode. */
901 /* Returns the register offset for the first byte of register regno's space
902 in the saved register state. Returns -1 for an invalid or unimplemented
906 cris_register_offset (int regno
)
912 if (regno
>= 0 && regno
< NUM_REGS
)
914 /* FIXME: The offsets should be cached and calculated only once,
915 when the architecture being debugged has changed. */
916 for (i
= 0; i
< regno
; i
++)
917 offset
+= cris_register_size (i
);
923 /* Invalid register. */
928 /* Return the GDB type (defined in gdbtypes.c) for the "standard" data type
929 of data in register regno. */
932 cris_register_virtual_type (int regno
)
934 if (regno
== SP_REGNUM
|| regno
== PC_REGNUM
935 || (regno
> P8_REGNUM
&& regno
< USP_REGNUM
))
937 /* SP, PC, IBR, IRP, SRP, BAR, DCCR, BRP */
938 return lookup_pointer_type (builtin_type_void
);
940 else if (regno
== P8_REGNUM
|| regno
== USP_REGNUM
941 || (regno
>= 0 && regno
< SP_REGNUM
))
943 /* R0 - R13, P8, P15 */
944 return builtin_type_unsigned_long
;
946 else if (regno
> P3_REGNUM
&& regno
< P8_REGNUM
)
948 /* P4, CCR, DCR0, DCR1 */
949 return builtin_type_unsigned_short
;
951 else if (regno
> PC_REGNUM
&& regno
< P4_REGNUM
)
954 return builtin_type_unsigned_char
;
958 /* Invalid register. */
959 return builtin_type_void
;
963 /* Stores a function return value of type type, where valbuf is the address
964 of the value to be stored. */
966 /* In the original CRIS ABI, R10 is used to store return values. */
969 cris_abi_original_store_return_value (struct type
*type
, char *valbuf
)
971 int len
= TYPE_LENGTH (type
);
973 if (len
<= DEPRECATED_REGISTER_SIZE
)
974 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (RET_REGNUM
), valbuf
, len
);
976 internal_error (__FILE__
, __LINE__
, "cris_abi_original_store_return_value: type length too large.");
979 /* In the CRIS ABI V2, R10 and R11 are used to store return values. */
982 cris_abi_v2_store_return_value (struct type
*type
, char *valbuf
)
984 int len
= TYPE_LENGTH (type
);
986 if (len
<= 2 * DEPRECATED_REGISTER_SIZE
)
988 /* Note that this works since R10 and R11 are consecutive registers. */
989 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (RET_REGNUM
),
993 internal_error (__FILE__
, __LINE__
, "cris_abi_v2_store_return_value: type length too large.");
996 /* Return the name of register regno as a string. Return NULL for an invalid or
997 unimplemented register. */
1000 cris_register_name (int regno
)
1002 static char *cris_genreg_names
[] =
1003 { "r0", "r1", "r2", "r3", \
1004 "r4", "r5", "r6", "r7", \
1005 "r8", "r9", "r10", "r11", \
1006 "r12", "r13", "sp", "pc" };
1011 if (regno
>= 0 && regno
< NUM_GENREGS
)
1013 /* General register. */
1014 return cris_genreg_names
[regno
];
1016 else if (regno
>= NUM_GENREGS
&& regno
< NUM_REGS
)
1018 /* Special register (R16 - R31). cris_spec_regs is zero-based.
1019 Adjust regno accordingly. */
1020 spec_regno
= regno
- NUM_GENREGS
;
1022 /* The entries in cris_spec_regs are stored in register number order,
1023 which means we can shortcut into the array when searching it. */
1024 for (i
= spec_regno
; cris_spec_regs
[i
].name
!= NULL
; i
++)
1026 if (cris_spec_regs
[i
].number
== spec_regno
1027 && cris_spec_reg_applicable (cris_spec_regs
[i
]))
1028 /* Go with the first applicable register. */
1029 return cris_spec_regs
[i
].name
;
1031 /* Special register not applicable to this CRIS version. */
1036 /* Invalid register. */
1042 cris_register_bytes_ok (long bytes
)
1044 return (bytes
== DEPRECATED_REGISTER_BYTES
);
1047 /* Extract from an array regbuf containing the raw register state a function
1048 return value of type type, and copy that, in virtual format, into
1051 /* In the original CRIS ABI, R10 is used to return values. */
1054 cris_abi_original_extract_return_value (struct type
*type
, char *regbuf
,
1057 int len
= TYPE_LENGTH (type
);
1059 if (len
<= DEPRECATED_REGISTER_SIZE
)
1060 memcpy (valbuf
, regbuf
+ DEPRECATED_REGISTER_BYTE (RET_REGNUM
), len
);
1062 internal_error (__FILE__
, __LINE__
, "cris_abi_original_extract_return_value: type length too large");
1065 /* In the CRIS ABI V2, R10 and R11 are used to store return values. */
1068 cris_abi_v2_extract_return_value (struct type
*type
, char *regbuf
,
1071 int len
= TYPE_LENGTH (type
);
1073 if (len
<= 2 * DEPRECATED_REGISTER_SIZE
)
1074 memcpy (valbuf
, regbuf
+ DEPRECATED_REGISTER_BYTE (RET_REGNUM
), len
);
1076 internal_error (__FILE__
, __LINE__
, "cris_abi_v2_extract_return_value: type length too large");
1079 /* Returns 1 if the given type will be passed by pointer rather than
1082 /* In the original CRIS ABI, arguments shorter than or equal to 32 bits are
1086 cris_abi_original_reg_struct_has_addr (int gcc_p
, struct type
*type
)
1088 return (TYPE_LENGTH (type
) > 4);
1091 /* In the CRIS ABI V2, arguments shorter than or equal to 64 bits are passed
1095 cris_abi_v2_reg_struct_has_addr (int gcc_p
, struct type
*type
)
1097 return (TYPE_LENGTH (type
) > 8);
1100 /* Returns 1 if the function invocation represented by fi does not have a
1101 stack frame associated with it. Otherwise return 0. */
1104 cris_frameless_function_invocation (struct frame_info
*fi
)
1106 if ((get_frame_type (fi
) == SIGTRAMP_FRAME
))
1109 return frameless_look_for_prologue (fi
);
1112 /* See frame.h. Determines the address of all registers in the
1113 current stack frame storing each in frame->saved_regs. Space for
1114 frame->saved_regs shall be allocated by
1115 DEPRECATED_FRAME_INIT_SAVED_REGS using frame_saved_regs_zalloc. */
1118 cris_frame_init_saved_regs (struct frame_info
*fi
)
1121 struct symtab_and_line sal
;
1123 char *dummy_regs
= deprecated_generic_find_dummy_frame (get_frame_pc (fi
),
1124 get_frame_base (fi
));
1126 /* Examine the entire prologue. */
1127 int frameless_p
= 0;
1129 /* Has this frame's registers already been initialized? */
1130 if (deprecated_get_frame_saved_regs (fi
))
1133 frame_saved_regs_zalloc (fi
);
1137 /* I don't see this ever happening, considering the context in which
1138 cris_frame_init_saved_regs is called (always when we're not in
1140 memcpy (deprecated_get_frame_saved_regs (fi
), dummy_regs
, SIZEOF_FRAME_SAVED_REGS
);
1144 ip
= get_frame_func (fi
);
1145 sal
= find_pc_line (ip
, 0);
1147 /* If there is no symbol information then sal.end == 0, and we end up
1148 examining only the first instruction in the function prologue.
1149 Exaggerating the limit seems to be harmless. */
1151 best_limit
= sal
.end
;
1153 best_limit
= ip
+ 100;
1155 cris_examine (ip
, best_limit
, fi
, frameless_p
);
1159 /* Initialises the extra frame information at the creation of a new frame.
1160 The inparameter fromleaf is 0 when the call is from create_new_frame.
1161 When the call is from get_prev_frame_info, fromleaf is determined by
1162 cris_frameless_function_invocation. */
1165 cris_init_extra_frame_info (int fromleaf
, struct frame_info
*fi
)
1167 if (get_next_frame (fi
))
1169 /* Called from get_prev_frame. */
1170 deprecated_update_frame_pc_hack (fi
, DEPRECATED_FRAME_SAVED_PC (get_next_frame (fi
)));
1173 frame_extra_info_zalloc (fi
, sizeof (struct frame_extra_info
));
1175 get_frame_extra_info (fi
)->return_pc
= 0;
1176 get_frame_extra_info (fi
)->leaf_function
= 0;
1178 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi
),
1179 get_frame_base (fi
),
1180 get_frame_base (fi
)))
1182 /* We need to setup fi->frame here because call_function_by_hand
1183 gets it wrong by assuming it's always FP. */
1184 deprecated_update_frame_base_hack (fi
, deprecated_read_register_dummy (get_frame_pc (fi
), get_frame_base (fi
), SP_REGNUM
));
1185 get_frame_extra_info (fi
)->return_pc
=
1186 deprecated_read_register_dummy (get_frame_pc (fi
),
1187 get_frame_base (fi
), PC_REGNUM
);
1189 /* FIXME: Is this necessarily true? */
1190 get_frame_extra_info (fi
)->leaf_function
= 0;
1194 cris_frame_init_saved_regs (fi
);
1196 /* Check fromleaf/frameless_function_invocation. (FIXME) */
1198 if (deprecated_get_frame_saved_regs (fi
)[SRP_REGNUM
] != 0)
1200 /* SRP was saved on the stack; non-leaf function. */
1201 get_frame_extra_info (fi
)->return_pc
=
1202 read_memory_integer (deprecated_get_frame_saved_regs (fi
)[SRP_REGNUM
],
1203 DEPRECATED_REGISTER_RAW_SIZE (SRP_REGNUM
));
1207 /* SRP is still in a register; leaf function. */
1208 get_frame_extra_info (fi
)->return_pc
= read_register (SRP_REGNUM
);
1209 /* FIXME: Should leaf_function be set to 1 here? */
1210 get_frame_extra_info (fi
)->leaf_function
= 1;
1215 /* Return the content of the frame pointer in the present frame. In other
1216 words, determine the address of the calling function's frame. */
1219 cris_frame_chain (struct frame_info
*fi
)
1221 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi
),
1222 get_frame_base (fi
),
1223 get_frame_base (fi
)))
1225 return get_frame_base (fi
);
1227 else if (!deprecated_inside_entry_file (get_frame_pc (fi
)))
1229 return read_memory_unsigned_integer (get_frame_base (fi
), 4);
1237 /* Return the saved PC (which equals the return address) of this frame. */
1240 cris_frame_saved_pc (struct frame_info
*fi
)
1242 return get_frame_extra_info (fi
)->return_pc
;
1245 /* Setup the function arguments for calling a function in the inferior. */
1248 cris_abi_original_push_arguments (int nargs
, struct value
**args
,
1249 CORE_ADDR sp
, int struct_return
,
1250 CORE_ADDR struct_addr
)
1261 /* Data and parameters reside in different areas on the stack.
1262 Both frame pointers grow toward higher addresses. */
1263 CORE_ADDR fp_params
;
1266 /* Are we returning a value using a structure return or a normal value
1267 return? struct_addr is the address of the reserved space for the return
1268 structure to be written on the stack. */
1271 write_register (STR_REGNUM
, struct_addr
);
1274 /* Make sure there's space on the stack. Allocate space for data and a
1275 parameter to refer to that data. */
1276 for (argnum
= 0, stack_alloc
= 0; argnum
< nargs
; argnum
++)
1277 stack_alloc
+= (TYPE_LENGTH (VALUE_TYPE (args
[argnum
])) + DEPRECATED_REGISTER_SIZE
);
1279 /* We may over-allocate a little here, but that won't hurt anything. */
1281 /* Initialize stack frame pointers. */
1283 fp_data
= sp
+ (nargs
* DEPRECATED_REGISTER_SIZE
);
1285 /* Now load as many as possible of the first arguments into
1286 registers, and push the rest onto the stack. */
1287 argreg
= ARG1_REGNUM
;
1290 for (argnum
= 0; argnum
< nargs
; argnum
++)
1292 type
= VALUE_TYPE (args
[argnum
]);
1293 len
= TYPE_LENGTH (type
);
1294 val
= (char *) VALUE_CONTENTS (args
[argnum
]);
1296 if (len
<= DEPRECATED_REGISTER_SIZE
&& argreg
<= ARG4_REGNUM
)
1298 /* Data fits in a register; put it in the first available
1300 write_register (argreg
, *(unsigned long *) val
);
1303 else if (len
> DEPRECATED_REGISTER_SIZE
&& argreg
<= ARG4_REGNUM
)
1305 /* Data does not fit in register; pass it on the stack and
1306 put its address in the first available register. */
1307 write_memory (fp_data
, val
, len
);
1308 write_register (argreg
, fp_data
);
1312 else if (len
> DEPRECATED_REGISTER_SIZE
)
1314 /* Data does not fit in register; put both data and
1315 parameter on the stack. */
1316 write_memory (fp_data
, val
, len
);
1317 write_memory (fp_params
, (char *) (&fp_data
), DEPRECATED_REGISTER_SIZE
);
1319 fp_params
+= DEPRECATED_REGISTER_SIZE
;
1323 /* Data fits in a register, but we are out of registers;
1324 put the parameter on the stack. */
1325 write_memory (fp_params
, val
, DEPRECATED_REGISTER_SIZE
);
1326 fp_params
+= DEPRECATED_REGISTER_SIZE
;
1334 cris_abi_v2_push_arguments (int nargs
, struct value
**args
, CORE_ADDR sp
,
1335 int struct_return
, CORE_ADDR struct_addr
)
1344 /* The function's arguments and memory allocated by gdb for the arguments to
1345 point at reside in separate areas on the stack.
1346 Both frame pointers grow toward higher addresses. */
1350 /* Are we returning a value using a structure return or a normal value
1351 return? struct_addr is the address of the reserved space for the return
1352 structure to be written on the stack. */
1355 write_register (STR_REGNUM
, struct_addr
);
1358 /* Allocate enough to keep things word-aligned on both parts of the
1361 for (argnum
= 0; argnum
< nargs
; argnum
++)
1366 len
= TYPE_LENGTH (VALUE_TYPE (args
[argnum
]));
1367 reg_demand
= (len
/ DEPRECATED_REGISTER_SIZE
) + (len
% DEPRECATED_REGISTER_SIZE
!= 0 ? 1 : 0);
1369 /* reg_demand * DEPRECATED_REGISTER_SIZE is the amount of memory
1370 we might need to allocate for this argument. 2 *
1371 DEPRECATED_REGISTER_SIZE is the amount of stack space we
1372 might need to pass the argument itself (either by value or by
1374 stack_alloc
+= (reg_demand
* DEPRECATED_REGISTER_SIZE
+ 2 * DEPRECATED_REGISTER_SIZE
);
1377 /* We may over-allocate a little here, but that won't hurt anything. */
1379 /* Initialize frame pointers. */
1381 fp_mem
= sp
+ (nargs
* (2 * DEPRECATED_REGISTER_SIZE
));
1383 /* Now load as many as possible of the first arguments into registers,
1384 and push the rest onto the stack. */
1385 argreg
= ARG1_REGNUM
;
1388 for (argnum
= 0; argnum
< nargs
; argnum
++)
1395 len
= TYPE_LENGTH (VALUE_TYPE (args
[argnum
]));
1396 val
= (char *) VALUE_CONTENTS (args
[argnum
]);
1398 /* How may registers worth of storage do we need for this argument? */
1399 reg_demand
= (len
/ DEPRECATED_REGISTER_SIZE
) + (len
% DEPRECATED_REGISTER_SIZE
!= 0 ? 1 : 0);
1401 if (len
<= (2 * DEPRECATED_REGISTER_SIZE
)
1402 && (argreg
+ reg_demand
- 1 <= ARG4_REGNUM
))
1404 /* Data passed by value. Fits in available register(s). */
1405 for (i
= 0; i
< reg_demand
; i
++)
1407 write_register (argreg
, *(unsigned long *) val
);
1409 val
+= DEPRECATED_REGISTER_SIZE
;
1412 else if (len
<= (2 * DEPRECATED_REGISTER_SIZE
) && argreg
<= ARG4_REGNUM
)
1414 /* Data passed by value. Does not fit in available register(s).
1415 Use the register(s) first, then the stack. */
1416 for (i
= 0; i
< reg_demand
; i
++)
1418 if (argreg
<= ARG4_REGNUM
)
1420 write_register (argreg
, *(unsigned long *) val
);
1422 val
+= DEPRECATED_REGISTER_SIZE
;
1426 /* I guess this memory write could write the
1427 remaining data all at once instead of in
1428 DEPRECATED_REGISTER_SIZE chunks. */
1429 write_memory (fp_arg
, val
, DEPRECATED_REGISTER_SIZE
);
1430 fp_arg
+= DEPRECATED_REGISTER_SIZE
;
1431 val
+= DEPRECATED_REGISTER_SIZE
;
1435 else if (len
> (2 * DEPRECATED_REGISTER_SIZE
))
1437 /* Data passed by reference. Put it on the stack. */
1438 write_memory (fp_mem
, val
, len
);
1439 write_memory (fp_arg
, (char *) (&fp_mem
), DEPRECATED_REGISTER_SIZE
);
1441 /* fp_mem need not be word-aligned since it's just a chunk of
1442 memory being pointed at. That is, += len would do. */
1443 fp_mem
+= reg_demand
* DEPRECATED_REGISTER_SIZE
;
1444 fp_arg
+= DEPRECATED_REGISTER_SIZE
;
1448 /* Data passed by value. No available registers. Put it on
1450 write_memory (fp_arg
, val
, len
);
1452 /* fp_arg must be word-aligned (i.e., don't += len) to match
1453 the function prologue. */
1454 fp_arg
+= reg_demand
* DEPRECATED_REGISTER_SIZE
;
1461 /* Never put the return address on the stack. The register SRP is pushed
1462 by the called function unless it is a leaf-function. Due to the BRP
1463 register the PC will change when continue is sent. */
1466 cris_push_return_address (CORE_ADDR pc
, CORE_ADDR sp
)
1468 write_register (SRP_REGNUM
, entry_point_address ());
1472 /* Restore the machine to the state it had before the current frame
1473 was created. Discard the innermost frame from the stack and restore
1474 all saved registers. */
1477 cris_pop_frame (void)
1479 struct frame_info
*fi
= get_current_frame ();
1481 int stack_offset
= 0;
1483 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi
),
1484 get_frame_base (fi
),
1485 get_frame_base (fi
)))
1487 /* This happens when we hit a breakpoint set at the entry point,
1488 when returning from a dummy frame. */
1489 generic_pop_dummy_frame ();
1493 cris_frame_init_saved_regs (fi
);
1495 /* For each register, the address of where it was saved on entry to
1496 the frame now lies in fi->saved_regs[regno], or zero if it was not
1497 saved. This includes special registers such as PC and FP saved in
1498 special ways in the stack frame. The SP_REGNUM is even more
1499 special, the address here is the SP for the next frame, not the
1500 address where the SP was saved. */
1502 /* Restore general registers R0 - R7. They were pushed on the stack
1503 after SP was saved. */
1504 for (regno
= 0; regno
< DEPRECATED_FP_REGNUM
; regno
++)
1506 if (deprecated_get_frame_saved_regs (fi
)[regno
])
1508 write_register (regno
,
1509 read_memory_integer (deprecated_get_frame_saved_regs (fi
)[regno
], 4));
1513 if (deprecated_get_frame_saved_regs (fi
)[DEPRECATED_FP_REGNUM
])
1515 /* Pop the frame pointer (R8). It was pushed before SP
1517 write_register (DEPRECATED_FP_REGNUM
,
1518 read_memory_integer (deprecated_get_frame_saved_regs (fi
)[DEPRECATED_FP_REGNUM
], 4));
1521 /* Not a leaf function. */
1522 if (deprecated_get_frame_saved_regs (fi
)[SRP_REGNUM
])
1524 /* SRP was pushed before SP was saved. */
1528 /* Restore the SP and adjust for R8 and (possibly) SRP. */
1529 write_register (SP_REGNUM
, deprecated_get_frame_saved_regs (fi
)[DEPRECATED_FP_REGNUM
] + stack_offset
);
1533 /* Currently, we can't get the correct info into fi->saved_regs
1534 without a frame pointer. */
1537 /* Restore the PC. */
1538 write_register (PC_REGNUM
, get_frame_extra_info (fi
)->return_pc
);
1540 flush_cached_frames ();
1543 /* Calculates a value that measures how good inst_args constraints an
1544 instruction. It stems from cris_constraint, found in cris-dis.c. */
1547 constraint (unsigned int insn
, const signed char *inst_args
,
1548 inst_env_type
*inst_env
)
1553 const char *s
= inst_args
;
1559 if ((insn
& 0x30) == 0x30)
1564 /* A prefix operand. */
1565 if (inst_env
->prefix_found
)
1571 /* A "push" prefix. (This check was REMOVED by san 970921.) Check for
1572 valid "push" size. In case of special register, it may be != 4. */
1573 if (inst_env
->prefix_found
)
1579 retval
= (((insn
>> 0xC) & 0xF) == (insn
& 0xF));
1587 tmp
= (insn
>> 0xC) & 0xF;
1589 for (i
= 0; cris_spec_regs
[i
].name
!= NULL
; i
++)
1591 /* Since we match four bits, we will give a value of
1592 4 - 1 = 3 in a match. If there is a corresponding
1593 exact match of a special register in another pattern, it
1594 will get a value of 4, which will be higher. This should
1595 be correct in that an exact pattern would match better that
1597 Note that there is a reason for not returning zero; the
1598 pattern for "clear" is partly matched in the bit-pattern
1599 (the two lower bits must be zero), while the bit-pattern
1600 for a move from a special register is matched in the
1601 register constraint.
1602 This also means we will will have a race condition if
1603 there is a partly match in three bits in the bit pattern. */
1604 if (tmp
== cris_spec_regs
[i
].number
)
1611 if (cris_spec_regs
[i
].name
== NULL
)
1618 /* Returns the number of bits set in the variable value. */
1621 number_of_bits (unsigned int value
)
1623 int number_of_bits
= 0;
1627 number_of_bits
+= 1;
1628 value
&= (value
- 1);
1630 return number_of_bits
;
1633 /* Finds the address that should contain the single step breakpoint(s).
1634 It stems from code in cris-dis.c. */
1637 find_cris_op (unsigned short insn
, inst_env_type
*inst_env
)
1640 int max_level_of_match
= -1;
1641 int max_matched
= -1;
1644 for (i
= 0; cris_opcodes
[i
].name
!= NULL
; i
++)
1646 if (((cris_opcodes
[i
].match
& insn
) == cris_opcodes
[i
].match
)
1647 && ((cris_opcodes
[i
].lose
& insn
) == 0))
1649 level_of_match
= constraint (insn
, cris_opcodes
[i
].args
, inst_env
);
1650 if (level_of_match
>= 0)
1653 number_of_bits (cris_opcodes
[i
].match
| cris_opcodes
[i
].lose
);
1654 if (level_of_match
> max_level_of_match
)
1657 max_level_of_match
= level_of_match
;
1658 if (level_of_match
== 16)
1660 /* All bits matched, cannot find better. */
1670 /* Attempts to find single-step breakpoints. Returns -1 on failure which is
1671 actually an internal error. */
1674 find_step_target (inst_env_type
*inst_env
)
1678 unsigned short insn
;
1680 /* Create a local register image and set the initial state. */
1681 for (i
= 0; i
< NUM_GENREGS
; i
++)
1683 inst_env
->reg
[i
] = (unsigned long) read_register (i
);
1685 offset
= NUM_GENREGS
;
1686 for (i
= 0; i
< NUM_SPECREGS
; i
++)
1688 inst_env
->preg
[i
] = (unsigned long) read_register (offset
+ i
);
1690 inst_env
->branch_found
= 0;
1691 inst_env
->slot_needed
= 0;
1692 inst_env
->delay_slot_pc_active
= 0;
1693 inst_env
->prefix_found
= 0;
1694 inst_env
->invalid
= 0;
1695 inst_env
->xflag_found
= 0;
1696 inst_env
->disable_interrupt
= 0;
1698 /* Look for a step target. */
1701 /* Read an instruction from the client. */
1702 insn
= read_memory_unsigned_integer (inst_env
->reg
[PC_REGNUM
], 2);
1704 /* If the instruction is not in a delay slot the new content of the
1705 PC is [PC] + 2. If the instruction is in a delay slot it is not
1706 that simple. Since a instruction in a delay slot cannot change
1707 the content of the PC, it does not matter what value PC will have.
1708 Just make sure it is a valid instruction. */
1709 if (!inst_env
->delay_slot_pc_active
)
1711 inst_env
->reg
[PC_REGNUM
] += 2;
1715 inst_env
->delay_slot_pc_active
= 0;
1716 inst_env
->reg
[PC_REGNUM
] = inst_env
->delay_slot_pc
;
1718 /* Analyse the present instruction. */
1719 i
= find_cris_op (insn
, inst_env
);
1722 inst_env
->invalid
= 1;
1726 cris_gdb_func (cris_opcodes
[i
].op
, insn
, inst_env
);
1728 } while (!inst_env
->invalid
1729 && (inst_env
->prefix_found
|| inst_env
->xflag_found
1730 || inst_env
->slot_needed
));
1734 /* There is no hardware single-step support. The function find_step_target
1735 digs through the opcodes in order to find all possible targets.
1736 Either one ordinary target or two targets for branches may be found. */
1739 cris_software_single_step (enum target_signal ignore
, int insert_breakpoints
)
1741 inst_env_type inst_env
;
1743 if (insert_breakpoints
)
1745 /* Analyse the present instruction environment and insert
1747 int status
= find_step_target (&inst_env
);
1750 /* Could not find a target. FIXME: Should do something. */
1754 /* Insert at most two breakpoints. One for the next PC content
1755 and possibly another one for a branch, jump, etc. */
1756 next_pc
= (CORE_ADDR
) inst_env
.reg
[PC_REGNUM
];
1757 target_insert_breakpoint (next_pc
, break_mem
[0]);
1758 if (inst_env
.branch_found
1759 && (CORE_ADDR
) inst_env
.branch_break_address
!= next_pc
)
1761 branch_target_address
=
1762 (CORE_ADDR
) inst_env
.branch_break_address
;
1763 target_insert_breakpoint (branch_target_address
, break_mem
[1]);
1764 branch_break_inserted
= 1;
1770 /* Remove breakpoints. */
1771 target_remove_breakpoint (next_pc
, break_mem
[0]);
1772 if (branch_break_inserted
)
1774 target_remove_breakpoint (branch_target_address
, break_mem
[1]);
1775 branch_break_inserted
= 0;
1780 /* Calculates the prefix value for quick offset addressing mode. */
1783 quick_mode_bdap_prefix (unsigned short inst
, inst_env_type
*inst_env
)
1785 /* It's invalid to be in a delay slot. You can't have a prefix to this
1786 instruction (not 100% sure). */
1787 if (inst_env
->slot_needed
|| inst_env
->prefix_found
)
1789 inst_env
->invalid
= 1;
1793 inst_env
->prefix_value
= inst_env
->reg
[cris_get_operand2 (inst
)];
1794 inst_env
->prefix_value
+= cris_get_bdap_quick_offset (inst
);
1796 /* A prefix doesn't change the xflag_found. But the rest of the flags
1798 inst_env
->slot_needed
= 0;
1799 inst_env
->prefix_found
= 1;
1802 /* Updates the autoincrement register. The size of the increment is derived
1803 from the size of the operation. The PC is always kept aligned on even
1807 process_autoincrement (int size
, unsigned short inst
, inst_env_type
*inst_env
)
1809 if (size
== INST_BYTE_SIZE
)
1811 inst_env
->reg
[cris_get_operand1 (inst
)] += 1;
1813 /* The PC must be word aligned, so increase the PC with one
1814 word even if the size is byte. */
1815 if (cris_get_operand1 (inst
) == REG_PC
)
1817 inst_env
->reg
[REG_PC
] += 1;
1820 else if (size
== INST_WORD_SIZE
)
1822 inst_env
->reg
[cris_get_operand1 (inst
)] += 2;
1824 else if (size
== INST_DWORD_SIZE
)
1826 inst_env
->reg
[cris_get_operand1 (inst
)] += 4;
1831 inst_env
->invalid
= 1;
1835 /* Just a forward declaration. */
1837 static unsigned long get_data_from_address (unsigned short *inst
,
1840 /* Calculates the prefix value for the general case of offset addressing
1844 bdap_prefix (unsigned short inst
, inst_env_type
*inst_env
)
1849 /* It's invalid to be in a delay slot. */
1850 if (inst_env
->slot_needed
|| inst_env
->prefix_found
)
1852 inst_env
->invalid
= 1;
1856 /* The calculation of prefix_value used to be after process_autoincrement,
1857 but that fails for an instruction such as jsr [$r0+12] which is encoded
1858 as 5f0d 0c00 30b9 when compiled with -fpic. Since PC is operand1 it
1859 mustn't be incremented until we have read it and what it points at. */
1860 inst_env
->prefix_value
= inst_env
->reg
[cris_get_operand2 (inst
)];
1862 /* The offset is an indirection of the contents of the operand1 register. */
1863 inst_env
->prefix_value
+=
1864 get_data_from_address (&inst
, inst_env
->reg
[cris_get_operand1 (inst
)]);
1866 if (cris_get_mode (inst
) == AUTOINC_MODE
)
1868 process_autoincrement (cris_get_size (inst
), inst
, inst_env
);
1871 /* A prefix doesn't change the xflag_found. But the rest of the flags
1873 inst_env
->slot_needed
= 0;
1874 inst_env
->prefix_found
= 1;
1877 /* Calculates the prefix value for the index addressing mode. */
1880 biap_prefix (unsigned short inst
, inst_env_type
*inst_env
)
1882 /* It's invalid to be in a delay slot. I can't see that it's possible to
1883 have a prefix to this instruction. So I will treat this as invalid. */
1884 if (inst_env
->slot_needed
|| inst_env
->prefix_found
)
1886 inst_env
->invalid
= 1;
1890 inst_env
->prefix_value
= inst_env
->reg
[cris_get_operand1 (inst
)];
1892 /* The offset is the operand2 value shifted the size of the instruction
1894 inst_env
->prefix_value
+=
1895 inst_env
->reg
[cris_get_operand2 (inst
)] << cris_get_size (inst
);
1897 /* If the PC is operand1 (base) the address used is the address after
1898 the main instruction, i.e. address + 2 (the PC is already compensated
1899 for the prefix operation). */
1900 if (cris_get_operand1 (inst
) == REG_PC
)
1902 inst_env
->prefix_value
+= 2;
1905 /* A prefix doesn't change the xflag_found. But the rest of the flags
1907 inst_env
->slot_needed
= 0;
1908 inst_env
->xflag_found
= 0;
1909 inst_env
->prefix_found
= 1;
1912 /* Calculates the prefix value for the double indirect addressing mode. */
1915 dip_prefix (unsigned short inst
, inst_env_type
*inst_env
)
1920 /* It's invalid to be in a delay slot. */
1921 if (inst_env
->slot_needed
|| inst_env
->prefix_found
)
1923 inst_env
->invalid
= 1;
1927 /* The prefix value is one dereference of the contents of the operand1
1929 address
= (CORE_ADDR
) inst_env
->reg
[cris_get_operand1 (inst
)];
1930 inst_env
->prefix_value
= read_memory_unsigned_integer (address
, 4);
1932 /* Check if the mode is autoincrement. */
1933 if (cris_get_mode (inst
) == AUTOINC_MODE
)
1935 inst_env
->reg
[cris_get_operand1 (inst
)] += 4;
1938 /* A prefix doesn't change the xflag_found. But the rest of the flags
1940 inst_env
->slot_needed
= 0;
1941 inst_env
->xflag_found
= 0;
1942 inst_env
->prefix_found
= 1;
1945 /* Finds the destination for a branch with 8-bits offset. */
1948 eight_bit_offset_branch_op (unsigned short inst
, inst_env_type
*inst_env
)
1953 /* If we have a prefix or are in a delay slot it's bad. */
1954 if (inst_env
->slot_needed
|| inst_env
->prefix_found
)
1956 inst_env
->invalid
= 1;
1960 /* We have a branch, find out where the branch will land. */
1961 offset
= cris_get_branch_short_offset (inst
);
1963 /* Check if the offset is signed. */
1964 if (offset
& BRANCH_SIGNED_SHORT_OFFSET_MASK
)
1969 /* The offset ends with the sign bit, set it to zero. The address
1970 should always be word aligned. */
1971 offset
&= ~BRANCH_SIGNED_SHORT_OFFSET_MASK
;
1973 inst_env
->branch_found
= 1;
1974 inst_env
->branch_break_address
= inst_env
->reg
[REG_PC
] + offset
;
1976 inst_env
->slot_needed
= 1;
1977 inst_env
->prefix_found
= 0;
1978 inst_env
->xflag_found
= 0;
1979 inst_env
->disable_interrupt
= 1;
1982 /* Finds the destination for a branch with 16-bits offset. */
1985 sixteen_bit_offset_branch_op (unsigned short inst
, inst_env_type
*inst_env
)
1989 /* If we have a prefix or is in a delay slot it's bad. */
1990 if (inst_env
->slot_needed
|| inst_env
->prefix_found
)
1992 inst_env
->invalid
= 1;
1996 /* We have a branch, find out the offset for the branch. */
1997 offset
= read_memory_integer (inst_env
->reg
[REG_PC
], 2);
1999 /* The instruction is one word longer than normal, so add one word
2001 inst_env
->reg
[REG_PC
] += 2;
2003 inst_env
->branch_found
= 1;
2004 inst_env
->branch_break_address
= inst_env
->reg
[REG_PC
] + offset
;
2007 inst_env
->slot_needed
= 1;
2008 inst_env
->prefix_found
= 0;
2009 inst_env
->xflag_found
= 0;
2010 inst_env
->disable_interrupt
= 1;
2013 /* Handles the ABS instruction. */
2016 abs_op (unsigned short inst
, inst_env_type
*inst_env
)
2021 /* ABS can't have a prefix, so it's bad if it does. */
2022 if (inst_env
->prefix_found
)
2024 inst_env
->invalid
= 1;
2028 /* Check if the operation affects the PC. */
2029 if (cris_get_operand2 (inst
) == REG_PC
)
2032 /* It's invalid to change to the PC if we are in a delay slot. */
2033 if (inst_env
->slot_needed
)
2035 inst_env
->invalid
= 1;
2039 value
= (long) inst_env
->reg
[REG_PC
];
2041 /* The value of abs (SIGNED_DWORD_MASK) is SIGNED_DWORD_MASK. */
2042 if (value
!= SIGNED_DWORD_MASK
)
2045 inst_env
->reg
[REG_PC
] = (long) value
;
2049 inst_env
->slot_needed
= 0;
2050 inst_env
->prefix_found
= 0;
2051 inst_env
->xflag_found
= 0;
2052 inst_env
->disable_interrupt
= 0;
2055 /* Handles the ADDI instruction. */
2058 addi_op (unsigned short inst
, inst_env_type
*inst_env
)
2060 /* It's invalid to have the PC as base register. And ADDI can't have
2062 if (inst_env
->prefix_found
|| (cris_get_operand1 (inst
) == REG_PC
))
2064 inst_env
->invalid
= 1;
2068 inst_env
->slot_needed
= 0;
2069 inst_env
->prefix_found
= 0;
2070 inst_env
->xflag_found
= 0;
2071 inst_env
->disable_interrupt
= 0;
2074 /* Handles the ASR instruction. */
2077 asr_op (unsigned short inst
, inst_env_type
*inst_env
)
2080 unsigned long value
;
2081 unsigned long signed_extend_mask
= 0;
2083 /* ASR can't have a prefix, so check that it doesn't. */
2084 if (inst_env
->prefix_found
)
2086 inst_env
->invalid
= 1;
2090 /* Check if the PC is the target register. */
2091 if (cris_get_operand2 (inst
) == REG_PC
)
2093 /* It's invalid to change the PC in a delay slot. */
2094 if (inst_env
->slot_needed
)
2096 inst_env
->invalid
= 1;
2099 /* Get the number of bits to shift. */
2100 shift_steps
= cris_get_asr_shift_steps (inst_env
->reg
[cris_get_operand1 (inst
)]);
2101 value
= inst_env
->reg
[REG_PC
];
2103 /* Find out how many bits the operation should apply to. */
2104 if (cris_get_size (inst
) == INST_BYTE_SIZE
)
2106 if (value
& SIGNED_BYTE_MASK
)
2108 signed_extend_mask
= 0xFF;
2109 signed_extend_mask
= signed_extend_mask
>> shift_steps
;
2110 signed_extend_mask
= ~signed_extend_mask
;
2112 value
= value
>> shift_steps
;
2113 value
|= signed_extend_mask
;
2115 inst_env
->reg
[REG_PC
] &= 0xFFFFFF00;
2116 inst_env
->reg
[REG_PC
] |= value
;
2118 else if (cris_get_size (inst
) == INST_WORD_SIZE
)
2120 if (value
& SIGNED_WORD_MASK
)
2122 signed_extend_mask
= 0xFFFF;
2123 signed_extend_mask
= signed_extend_mask
>> shift_steps
;
2124 signed_extend_mask
= ~signed_extend_mask
;
2126 value
= value
>> shift_steps
;
2127 value
|= signed_extend_mask
;
2129 inst_env
->reg
[REG_PC
] &= 0xFFFF0000;
2130 inst_env
->reg
[REG_PC
] |= value
;
2132 else if (cris_get_size (inst
) == INST_DWORD_SIZE
)
2134 if (value
& SIGNED_DWORD_MASK
)
2136 signed_extend_mask
= 0xFFFFFFFF;
2137 signed_extend_mask
= signed_extend_mask
>> shift_steps
;
2138 signed_extend_mask
= ~signed_extend_mask
;
2140 value
= value
>> shift_steps
;
2141 value
|= signed_extend_mask
;
2142 inst_env
->reg
[REG_PC
] = value
;
2145 inst_env
->slot_needed
= 0;
2146 inst_env
->prefix_found
= 0;
2147 inst_env
->xflag_found
= 0;
2148 inst_env
->disable_interrupt
= 0;
2151 /* Handles the ASRQ instruction. */
2154 asrq_op (unsigned short inst
, inst_env_type
*inst_env
)
2158 unsigned long value
;
2159 unsigned long signed_extend_mask
= 0;
2161 /* ASRQ can't have a prefix, so check that it doesn't. */
2162 if (inst_env
->prefix_found
)
2164 inst_env
->invalid
= 1;
2168 /* Check if the PC is the target register. */
2169 if (cris_get_operand2 (inst
) == REG_PC
)
2172 /* It's invalid to change the PC in a delay slot. */
2173 if (inst_env
->slot_needed
)
2175 inst_env
->invalid
= 1;
2178 /* The shift size is given as a 5 bit quick value, i.e. we don't
2179 want the the sign bit of the quick value. */
2180 shift_steps
= cris_get_asr_shift_steps (inst
);
2181 value
= inst_env
->reg
[REG_PC
];
2182 if (value
& SIGNED_DWORD_MASK
)
2184 signed_extend_mask
= 0xFFFFFFFF;
2185 signed_extend_mask
= signed_extend_mask
>> shift_steps
;
2186 signed_extend_mask
= ~signed_extend_mask
;
2188 value
= value
>> shift_steps
;
2189 value
|= signed_extend_mask
;
2190 inst_env
->reg
[REG_PC
] = value
;
2192 inst_env
->slot_needed
= 0;
2193 inst_env
->prefix_found
= 0;
2194 inst_env
->xflag_found
= 0;
2195 inst_env
->disable_interrupt
= 0;
2198 /* Handles the AX, EI and SETF instruction. */
2201 ax_ei_setf_op (unsigned short inst
, inst_env_type
*inst_env
)
2203 if (inst_env
->prefix_found
)
2205 inst_env
->invalid
= 1;
2208 /* Check if the instruction is setting the X flag. */
2209 if (cris_is_xflag_bit_on (inst
))
2211 inst_env
->xflag_found
= 1;
2215 inst_env
->xflag_found
= 0;
2217 inst_env
->slot_needed
= 0;
2218 inst_env
->prefix_found
= 0;
2219 inst_env
->disable_interrupt
= 1;
2222 /* Checks if the instruction is in assign mode. If so, it updates the assign
2223 register. Note that check_assign assumes that the caller has checked that
2224 there is a prefix to this instruction. The mode check depends on this. */
2227 check_assign (unsigned short inst
, inst_env_type
*inst_env
)
2229 /* Check if it's an assign addressing mode. */
2230 if (cris_get_mode (inst
) == PREFIX_ASSIGN_MODE
)
2232 /* Assign the prefix value to operand 1. */
2233 inst_env
->reg
[cris_get_operand1 (inst
)] = inst_env
->prefix_value
;
2237 /* Handles the 2-operand BOUND instruction. */
2240 two_operand_bound_op (unsigned short inst
, inst_env_type
*inst_env
)
2242 /* It's invalid to have the PC as the index operand. */
2243 if (cris_get_operand2 (inst
) == REG_PC
)
2245 inst_env
->invalid
= 1;
2248 /* Check if we have a prefix. */
2249 if (inst_env
->prefix_found
)
2251 check_assign (inst
, inst_env
);
2253 /* Check if this is an autoincrement mode. */
2254 else if (cris_get_mode (inst
) == AUTOINC_MODE
)
2256 /* It's invalid to change the PC in a delay slot. */
2257 if (inst_env
->slot_needed
)
2259 inst_env
->invalid
= 1;
2262 process_autoincrement (cris_get_size (inst
), inst
, inst_env
);
2264 inst_env
->slot_needed
= 0;
2265 inst_env
->prefix_found
= 0;
2266 inst_env
->xflag_found
= 0;
2267 inst_env
->disable_interrupt
= 0;
2270 /* Handles the 3-operand BOUND instruction. */
2273 three_operand_bound_op (unsigned short inst
, inst_env_type
*inst_env
)
2275 /* It's an error if we haven't got a prefix. And it's also an error
2276 if the PC is the destination register. */
2277 if ((!inst_env
->prefix_found
) || (cris_get_operand1 (inst
) == REG_PC
))
2279 inst_env
->invalid
= 1;
2282 inst_env
->slot_needed
= 0;
2283 inst_env
->prefix_found
= 0;
2284 inst_env
->xflag_found
= 0;
2285 inst_env
->disable_interrupt
= 0;
2288 /* Clears the status flags in inst_env. */
2291 btst_nop_op (unsigned short inst
, inst_env_type
*inst_env
)
2293 /* It's an error if we have got a prefix. */
2294 if (inst_env
->prefix_found
)
2296 inst_env
->invalid
= 1;
2300 inst_env
->slot_needed
= 0;
2301 inst_env
->prefix_found
= 0;
2302 inst_env
->xflag_found
= 0;
2303 inst_env
->disable_interrupt
= 0;
2306 /* Clears the status flags in inst_env. */
2309 clearf_di_op (unsigned short inst
, inst_env_type
*inst_env
)
2311 /* It's an error if we have got a prefix. */
2312 if (inst_env
->prefix_found
)
2314 inst_env
->invalid
= 1;
2318 inst_env
->slot_needed
= 0;
2319 inst_env
->prefix_found
= 0;
2320 inst_env
->xflag_found
= 0;
2321 inst_env
->disable_interrupt
= 1;
2324 /* Handles the CLEAR instruction if it's in register mode. */
2327 reg_mode_clear_op (unsigned short inst
, inst_env_type
*inst_env
)
2329 /* Check if the target is the PC. */
2330 if (cris_get_operand2 (inst
) == REG_PC
)
2332 /* The instruction will clear the instruction's size bits. */
2333 int clear_size
= cris_get_clear_size (inst
);
2334 if (clear_size
== INST_BYTE_SIZE
)
2336 inst_env
->delay_slot_pc
= inst_env
->reg
[REG_PC
] & 0xFFFFFF00;
2338 if (clear_size
== INST_WORD_SIZE
)
2340 inst_env
->delay_slot_pc
= inst_env
->reg
[REG_PC
] & 0xFFFF0000;
2342 if (clear_size
== INST_DWORD_SIZE
)
2344 inst_env
->delay_slot_pc
= 0x0;
2346 /* The jump will be delayed with one delay slot. So we need a delay
2348 inst_env
->slot_needed
= 1;
2349 inst_env
->delay_slot_pc_active
= 1;
2353 /* The PC will not change => no delay slot. */
2354 inst_env
->slot_needed
= 0;
2356 inst_env
->prefix_found
= 0;
2357 inst_env
->xflag_found
= 0;
2358 inst_env
->disable_interrupt
= 0;
2361 /* Handles the TEST instruction if it's in register mode. */
2364 reg_mode_test_op (unsigned short inst
, inst_env_type
*inst_env
)
2366 /* It's an error if we have got a prefix. */
2367 if (inst_env
->prefix_found
)
2369 inst_env
->invalid
= 1;
2372 inst_env
->slot_needed
= 0;
2373 inst_env
->prefix_found
= 0;
2374 inst_env
->xflag_found
= 0;
2375 inst_env
->disable_interrupt
= 0;
2379 /* Handles the CLEAR and TEST instruction if the instruction isn't
2380 in register mode. */
2383 none_reg_mode_clear_test_op (unsigned short inst
, inst_env_type
*inst_env
)
2385 /* Check if we are in a prefix mode. */
2386 if (inst_env
->prefix_found
)
2388 /* The only way the PC can change is if this instruction is in
2389 assign addressing mode. */
2390 check_assign (inst
, inst_env
);
2392 /* Indirect mode can't change the PC so just check if the mode is
2394 else if (cris_get_mode (inst
) == AUTOINC_MODE
)
2396 process_autoincrement (cris_get_size (inst
), inst
, inst_env
);
2398 inst_env
->slot_needed
= 0;
2399 inst_env
->prefix_found
= 0;
2400 inst_env
->xflag_found
= 0;
2401 inst_env
->disable_interrupt
= 0;
2404 /* Checks that the PC isn't the destination register or the instructions has
2408 dstep_logshift_mstep_neg_not_op (unsigned short inst
, inst_env_type
*inst_env
)
2410 /* It's invalid to have the PC as the destination. The instruction can't
2412 if ((cris_get_operand2 (inst
) == REG_PC
) || inst_env
->prefix_found
)
2414 inst_env
->invalid
= 1;
2418 inst_env
->slot_needed
= 0;
2419 inst_env
->prefix_found
= 0;
2420 inst_env
->xflag_found
= 0;
2421 inst_env
->disable_interrupt
= 0;
2424 /* Checks that the instruction doesn't have a prefix. */
2427 break_op (unsigned short inst
, inst_env_type
*inst_env
)
2429 /* The instruction can't have a prefix. */
2430 if (inst_env
->prefix_found
)
2432 inst_env
->invalid
= 1;
2436 inst_env
->slot_needed
= 0;
2437 inst_env
->prefix_found
= 0;
2438 inst_env
->xflag_found
= 0;
2439 inst_env
->disable_interrupt
= 1;
2442 /* Checks that the PC isn't the destination register and that the instruction
2443 doesn't have a prefix. */
2446 scc_op (unsigned short inst
, inst_env_type
*inst_env
)
2448 /* It's invalid to have the PC as the destination. The instruction can't
2450 if ((cris_get_operand2 (inst
) == REG_PC
) || inst_env
->prefix_found
)
2452 inst_env
->invalid
= 1;
2456 inst_env
->slot_needed
= 0;
2457 inst_env
->prefix_found
= 0;
2458 inst_env
->xflag_found
= 0;
2459 inst_env
->disable_interrupt
= 1;
2462 /* Handles the register mode JUMP instruction. */
2465 reg_mode_jump_op (unsigned short inst
, inst_env_type
*inst_env
)
2467 /* It's invalid to do a JUMP in a delay slot. The mode is register, so
2468 you can't have a prefix. */
2469 if ((inst_env
->slot_needed
) || (inst_env
->prefix_found
))
2471 inst_env
->invalid
= 1;
2475 /* Just change the PC. */
2476 inst_env
->reg
[REG_PC
] = inst_env
->reg
[cris_get_operand1 (inst
)];
2477 inst_env
->slot_needed
= 0;
2478 inst_env
->prefix_found
= 0;
2479 inst_env
->xflag_found
= 0;
2480 inst_env
->disable_interrupt
= 1;
2483 /* Handles the JUMP instruction for all modes except register. */
2486 none_reg_mode_jump_op (unsigned short inst
, inst_env_type
*inst_env
)
2488 unsigned long newpc
;
2491 /* It's invalid to do a JUMP in a delay slot. */
2492 if (inst_env
->slot_needed
)
2494 inst_env
->invalid
= 1;
2498 /* Check if we have a prefix. */
2499 if (inst_env
->prefix_found
)
2501 check_assign (inst
, inst_env
);
2503 /* Get the new value for the the PC. */
2505 read_memory_unsigned_integer ((CORE_ADDR
) inst_env
->prefix_value
,
2510 /* Get the new value for the PC. */
2511 address
= (CORE_ADDR
) inst_env
->reg
[cris_get_operand1 (inst
)];
2512 newpc
= read_memory_unsigned_integer (address
, 4);
2514 /* Check if we should increment a register. */
2515 if (cris_get_mode (inst
) == AUTOINC_MODE
)
2517 inst_env
->reg
[cris_get_operand1 (inst
)] += 4;
2520 inst_env
->reg
[REG_PC
] = newpc
;
2522 inst_env
->slot_needed
= 0;
2523 inst_env
->prefix_found
= 0;
2524 inst_env
->xflag_found
= 0;
2525 inst_env
->disable_interrupt
= 1;
2528 /* Handles moves to special registers (aka P-register) for all modes. */
2531 move_to_preg_op (unsigned short inst
, inst_env_type
*inst_env
)
2533 if (inst_env
->prefix_found
)
2535 /* The instruction has a prefix that means we are only interested if
2536 the instruction is in assign mode. */
2537 if (cris_get_mode (inst
) == PREFIX_ASSIGN_MODE
)
2539 /* The prefix handles the problem if we are in a delay slot. */
2540 if (cris_get_operand1 (inst
) == REG_PC
)
2542 /* Just take care of the assign. */
2543 check_assign (inst
, inst_env
);
2547 else if (cris_get_mode (inst
) == AUTOINC_MODE
)
2549 /* The instruction doesn't have a prefix, the only case left that we
2550 are interested in is the autoincrement mode. */
2551 if (cris_get_operand1 (inst
) == REG_PC
)
2553 /* If the PC is to be incremented it's invalid to be in a
2555 if (inst_env
->slot_needed
)
2557 inst_env
->invalid
= 1;
2561 /* The increment depends on the size of the special register. */
2562 if (cris_register_size (cris_get_operand2 (inst
)) == 1)
2564 process_autoincrement (INST_BYTE_SIZE
, inst
, inst_env
);
2566 else if (cris_register_size (cris_get_operand2 (inst
)) == 2)
2568 process_autoincrement (INST_WORD_SIZE
, inst
, inst_env
);
2572 process_autoincrement (INST_DWORD_SIZE
, inst
, inst_env
);
2576 inst_env
->slot_needed
= 0;
2577 inst_env
->prefix_found
= 0;
2578 inst_env
->xflag_found
= 0;
2579 inst_env
->disable_interrupt
= 1;
2582 /* Handles moves from special registers (aka P-register) for all modes
2586 none_reg_mode_move_from_preg_op (unsigned short inst
, inst_env_type
*inst_env
)
2588 if (inst_env
->prefix_found
)
2590 /* The instruction has a prefix that means we are only interested if
2591 the instruction is in assign mode. */
2592 if (cris_get_mode (inst
) == PREFIX_ASSIGN_MODE
)
2594 /* The prefix handles the problem if we are in a delay slot. */
2595 if (cris_get_operand1 (inst
) == REG_PC
)
2597 /* Just take care of the assign. */
2598 check_assign (inst
, inst_env
);
2602 /* The instruction doesn't have a prefix, the only case left that we
2603 are interested in is the autoincrement mode. */
2604 else if (cris_get_mode (inst
) == AUTOINC_MODE
)
2606 if (cris_get_operand1 (inst
) == REG_PC
)
2608 /* If the PC is to be incremented it's invalid to be in a
2610 if (inst_env
->slot_needed
)
2612 inst_env
->invalid
= 1;
2616 /* The increment depends on the size of the special register. */
2617 if (cris_register_size (cris_get_operand2 (inst
)) == 1)
2619 process_autoincrement (INST_BYTE_SIZE
, inst
, inst_env
);
2621 else if (cris_register_size (cris_get_operand2 (inst
)) == 2)
2623 process_autoincrement (INST_WORD_SIZE
, inst
, inst_env
);
2627 process_autoincrement (INST_DWORD_SIZE
, inst
, inst_env
);
2631 inst_env
->slot_needed
= 0;
2632 inst_env
->prefix_found
= 0;
2633 inst_env
->xflag_found
= 0;
2634 inst_env
->disable_interrupt
= 1;
2637 /* Handles moves from special registers (aka P-register) when the mode
2641 reg_mode_move_from_preg_op (unsigned short inst
, inst_env_type
*inst_env
)
2643 /* Register mode move from special register can't have a prefix. */
2644 if (inst_env
->prefix_found
)
2646 inst_env
->invalid
= 1;
2650 if (cris_get_operand1 (inst
) == REG_PC
)
2652 /* It's invalid to change the PC in a delay slot. */
2653 if (inst_env
->slot_needed
)
2655 inst_env
->invalid
= 1;
2658 /* The destination is the PC, the jump will have a delay slot. */
2659 inst_env
->delay_slot_pc
= inst_env
->preg
[cris_get_operand2 (inst
)];
2660 inst_env
->slot_needed
= 1;
2661 inst_env
->delay_slot_pc_active
= 1;
2665 /* If the destination isn't PC, there will be no jump. */
2666 inst_env
->slot_needed
= 0;
2668 inst_env
->prefix_found
= 0;
2669 inst_env
->xflag_found
= 0;
2670 inst_env
->disable_interrupt
= 1;
2673 /* Handles the MOVEM from memory to general register instruction. */
2676 move_mem_to_reg_movem_op (unsigned short inst
, inst_env_type
*inst_env
)
2678 if (inst_env
->prefix_found
)
2680 /* The prefix handles the problem if we are in a delay slot. Is the
2681 MOVEM instruction going to change the PC? */
2682 if (cris_get_operand2 (inst
) >= REG_PC
)
2684 inst_env
->reg
[REG_PC
] =
2685 read_memory_unsigned_integer (inst_env
->prefix_value
, 4);
2687 /* The assign value is the value after the increment. Normally, the
2688 assign value is the value before the increment. */
2689 if ((cris_get_operand1 (inst
) == REG_PC
)
2690 && (cris_get_mode (inst
) == PREFIX_ASSIGN_MODE
))
2692 inst_env
->reg
[REG_PC
] = inst_env
->prefix_value
;
2693 inst_env
->reg
[REG_PC
] += 4 * (cris_get_operand2 (inst
) + 1);
2698 /* Is the MOVEM instruction going to change the PC? */
2699 if (cris_get_operand2 (inst
) == REG_PC
)
2701 /* It's invalid to change the PC in a delay slot. */
2702 if (inst_env
->slot_needed
)
2704 inst_env
->invalid
= 1;
2707 inst_env
->reg
[REG_PC
] =
2708 read_memory_unsigned_integer (inst_env
->reg
[cris_get_operand1 (inst
)],
2711 /* The increment is not depending on the size, instead it's depending
2712 on the number of registers loaded from memory. */
2713 if ((cris_get_operand1 (inst
) == REG_PC
) && (cris_get_mode (inst
) == AUTOINC_MODE
))
2715 /* It's invalid to change the PC in a delay slot. */
2716 if (inst_env
->slot_needed
)
2718 inst_env
->invalid
= 1;
2721 inst_env
->reg
[REG_PC
] += 4 * (cris_get_operand2 (inst
) + 1);
2724 inst_env
->slot_needed
= 0;
2725 inst_env
->prefix_found
= 0;
2726 inst_env
->xflag_found
= 0;
2727 inst_env
->disable_interrupt
= 0;
2730 /* Handles the MOVEM to memory from general register instruction. */
2733 move_reg_to_mem_movem_op (unsigned short inst
, inst_env_type
*inst_env
)
2735 if (inst_env
->prefix_found
)
2737 /* The assign value is the value after the increment. Normally, the
2738 assign value is the value before the increment. */
2739 if ((cris_get_operand1 (inst
) == REG_PC
) &&
2740 (cris_get_mode (inst
) == PREFIX_ASSIGN_MODE
))
2742 /* The prefix handles the problem if we are in a delay slot. */
2743 inst_env
->reg
[REG_PC
] = inst_env
->prefix_value
;
2744 inst_env
->reg
[REG_PC
] += 4 * (cris_get_operand2 (inst
) + 1);
2749 /* The increment is not depending on the size, instead it's depending
2750 on the number of registers loaded to memory. */
2751 if ((cris_get_operand1 (inst
) == REG_PC
) && (cris_get_mode (inst
) == AUTOINC_MODE
))
2753 /* It's invalid to change the PC in a delay slot. */
2754 if (inst_env
->slot_needed
)
2756 inst_env
->invalid
= 1;
2759 inst_env
->reg
[REG_PC
] += 4 * (cris_get_operand2 (inst
) + 1);
2762 inst_env
->slot_needed
= 0;
2763 inst_env
->prefix_found
= 0;
2764 inst_env
->xflag_found
= 0;
2765 inst_env
->disable_interrupt
= 0;
2768 /* Handles the pop instruction to a general register.
2769 POP is a assembler macro for MOVE.D [SP+], Rd. */
2772 reg_pop_op (unsigned short inst
, inst_env_type
*inst_env
)
2774 /* POP can't have a prefix. */
2775 if (inst_env
->prefix_found
)
2777 inst_env
->invalid
= 1;
2780 if (cris_get_operand2 (inst
) == REG_PC
)
2782 /* It's invalid to change the PC in a delay slot. */
2783 if (inst_env
->slot_needed
)
2785 inst_env
->invalid
= 1;
2788 inst_env
->reg
[REG_PC
] =
2789 read_memory_unsigned_integer (inst_env
->reg
[REG_SP
], 4);
2791 inst_env
->slot_needed
= 0;
2792 inst_env
->prefix_found
= 0;
2793 inst_env
->xflag_found
= 0;
2794 inst_env
->disable_interrupt
= 0;
2797 /* Handles moves from register to memory. */
2800 move_reg_to_mem_index_inc_op (unsigned short inst
, inst_env_type
*inst_env
)
2802 /* Check if we have a prefix. */
2803 if (inst_env
->prefix_found
)
2805 /* The only thing that can change the PC is an assign. */
2806 check_assign (inst
, inst_env
);
2808 else if ((cris_get_operand1 (inst
) == REG_PC
)
2809 && (cris_get_mode (inst
) == AUTOINC_MODE
))
2811 /* It's invalid to change the PC in a delay slot. */
2812 if (inst_env
->slot_needed
)
2814 inst_env
->invalid
= 1;
2817 process_autoincrement (cris_get_size (inst
), inst
, inst_env
);
2819 inst_env
->slot_needed
= 0;
2820 inst_env
->prefix_found
= 0;
2821 inst_env
->xflag_found
= 0;
2822 inst_env
->disable_interrupt
= 0;
2825 /* Handles the intructions that's not yet implemented, by setting
2826 inst_env->invalid to true. */
2829 not_implemented_op (unsigned short inst
, inst_env_type
*inst_env
)
2831 inst_env
->invalid
= 1;
2834 /* Handles the XOR instruction. */
2837 xor_op (unsigned short inst
, inst_env_type
*inst_env
)
2839 /* XOR can't have a prefix. */
2840 if (inst_env
->prefix_found
)
2842 inst_env
->invalid
= 1;
2846 /* Check if the PC is the target. */
2847 if (cris_get_operand2 (inst
) == REG_PC
)
2849 /* It's invalid to change the PC in a delay slot. */
2850 if (inst_env
->slot_needed
)
2852 inst_env
->invalid
= 1;
2855 inst_env
->reg
[REG_PC
] ^= inst_env
->reg
[cris_get_operand1 (inst
)];
2857 inst_env
->slot_needed
= 0;
2858 inst_env
->prefix_found
= 0;
2859 inst_env
->xflag_found
= 0;
2860 inst_env
->disable_interrupt
= 0;
2863 /* Handles the MULS instruction. */
2866 muls_op (unsigned short inst
, inst_env_type
*inst_env
)
2868 /* MULS/U can't have a prefix. */
2869 if (inst_env
->prefix_found
)
2871 inst_env
->invalid
= 1;
2875 /* Consider it invalid if the PC is the target. */
2876 if (cris_get_operand2 (inst
) == REG_PC
)
2878 inst_env
->invalid
= 1;
2881 inst_env
->slot_needed
= 0;
2882 inst_env
->prefix_found
= 0;
2883 inst_env
->xflag_found
= 0;
2884 inst_env
->disable_interrupt
= 0;
2887 /* Handles the MULU instruction. */
2890 mulu_op (unsigned short inst
, inst_env_type
*inst_env
)
2892 /* MULS/U can't have a prefix. */
2893 if (inst_env
->prefix_found
)
2895 inst_env
->invalid
= 1;
2899 /* Consider it invalid if the PC is the target. */
2900 if (cris_get_operand2 (inst
) == REG_PC
)
2902 inst_env
->invalid
= 1;
2905 inst_env
->slot_needed
= 0;
2906 inst_env
->prefix_found
= 0;
2907 inst_env
->xflag_found
= 0;
2908 inst_env
->disable_interrupt
= 0;
2911 /* Calculate the result of the instruction for ADD, SUB, CMP AND, OR and MOVE.
2912 The MOVE instruction is the move from source to register. */
2915 add_sub_cmp_and_or_move_action (unsigned short inst
, inst_env_type
*inst_env
,
2916 unsigned long source1
, unsigned long source2
)
2918 unsigned long pc_mask
;
2919 unsigned long operation_mask
;
2921 /* Find out how many bits the operation should apply to. */
2922 if (cris_get_size (inst
) == INST_BYTE_SIZE
)
2924 pc_mask
= 0xFFFFFF00;
2925 operation_mask
= 0xFF;
2927 else if (cris_get_size (inst
) == INST_WORD_SIZE
)
2929 pc_mask
= 0xFFFF0000;
2930 operation_mask
= 0xFFFF;
2932 else if (cris_get_size (inst
) == INST_DWORD_SIZE
)
2935 operation_mask
= 0xFFFFFFFF;
2939 /* The size is out of range. */
2940 inst_env
->invalid
= 1;
2944 /* The instruction just works on uw_operation_mask bits. */
2945 source2
&= operation_mask
;
2946 source1
&= operation_mask
;
2948 /* Now calculate the result. The opcode's 3 first bits separates
2949 the different actions. */
2950 switch (cris_get_opcode (inst
) & 7)
2960 case 2: /* subtract */
2964 case 3: /* compare */
2976 inst_env
->invalid
= 1;
2982 /* Make sure that the result doesn't contain more than the instruction
2984 source2
&= operation_mask
;
2986 /* Calculate the new breakpoint address. */
2987 inst_env
->reg
[REG_PC
] &= pc_mask
;
2988 inst_env
->reg
[REG_PC
] |= source1
;
2992 /* Extends the value from either byte or word size to a dword. If the mode
2993 is zero extend then the value is extended with zero. If instead the mode
2994 is signed extend the sign bit of the value is taken into consideration. */
2996 static unsigned long
2997 do_sign_or_zero_extend (unsigned long value
, unsigned short *inst
)
2999 /* The size can be either byte or word, check which one it is.
3000 Don't check the highest bit, it's indicating if it's a zero
3002 if (cris_get_size (*inst
) & INST_WORD_SIZE
)
3007 /* Check if the instruction is signed extend. If so, check if value has
3009 if (cris_is_signed_extend_bit_on (*inst
) && (value
& SIGNED_WORD_MASK
))
3011 value
|= SIGNED_WORD_EXTEND_MASK
;
3019 /* Check if the instruction is signed extend. If so, check if value has
3021 if (cris_is_signed_extend_bit_on (*inst
) && (value
& SIGNED_BYTE_MASK
))
3023 value
|= SIGNED_BYTE_EXTEND_MASK
;
3026 /* The size should now be dword. */
3027 cris_set_size_to_dword (inst
);
3031 /* Handles the register mode for the ADD, SUB, CMP, AND, OR and MOVE
3032 instruction. The MOVE instruction is the move from source to register. */
3035 reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst
,
3036 inst_env_type
*inst_env
)
3038 unsigned long operand1
;
3039 unsigned long operand2
;
3041 /* It's invalid to have a prefix to the instruction. This is a register
3042 mode instruction and can't have a prefix. */
3043 if (inst_env
->prefix_found
)
3045 inst_env
->invalid
= 1;
3048 /* Check if the instruction has PC as its target. */
3049 if (cris_get_operand2 (inst
) == REG_PC
)
3051 if (inst_env
->slot_needed
)
3053 inst_env
->invalid
= 1;
3056 /* The instruction has the PC as its target register. */
3057 operand1
= inst_env
->reg
[cris_get_operand1 (inst
)];
3058 operand2
= inst_env
->reg
[REG_PC
];
3060 /* Check if it's a extend, signed or zero instruction. */
3061 if (cris_get_opcode (inst
) < 4)
3063 operand1
= do_sign_or_zero_extend (operand1
, &inst
);
3065 /* Calculate the PC value after the instruction, i.e. where the
3066 breakpoint should be. The order of the udw_operands is vital. */
3067 add_sub_cmp_and_or_move_action (inst
, inst_env
, operand2
, operand1
);
3069 inst_env
->slot_needed
= 0;
3070 inst_env
->prefix_found
= 0;
3071 inst_env
->xflag_found
= 0;
3072 inst_env
->disable_interrupt
= 0;
3075 /* Returns the data contained at address. The size of the data is derived from
3076 the size of the operation. If the instruction is a zero or signed
3077 extend instruction, the size field is changed in instruction. */
3079 static unsigned long
3080 get_data_from_address (unsigned short *inst
, CORE_ADDR address
)
3082 int size
= cris_get_size (*inst
);
3083 unsigned long value
;
3085 /* If it's an extend instruction we don't want the signed extend bit,
3086 because it influences the size. */
3087 if (cris_get_opcode (*inst
) < 4)
3089 size
&= ~SIGNED_EXTEND_BIT_MASK
;
3091 /* Is there a need for checking the size? Size should contain the number of
3094 value
= read_memory_unsigned_integer (address
, size
);
3096 /* Check if it's an extend, signed or zero instruction. */
3097 if (cris_get_opcode (*inst
) < 4)
3099 value
= do_sign_or_zero_extend (value
, inst
);
3104 /* Handles the assign addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
3105 instructions. The MOVE instruction is the move from source to register. */
3108 handle_prefix_assign_mode_for_aritm_op (unsigned short inst
,
3109 inst_env_type
*inst_env
)
3111 unsigned long operand2
;
3112 unsigned long operand3
;
3114 check_assign (inst
, inst_env
);
3115 if (cris_get_operand2 (inst
) == REG_PC
)
3117 operand2
= inst_env
->reg
[REG_PC
];
3119 /* Get the value of the third operand. */
3120 operand3
= get_data_from_address (&inst
, inst_env
->prefix_value
);
3122 /* Calculate the PC value after the instruction, i.e. where the
3123 breakpoint should be. The order of the udw_operands is vital. */
3124 add_sub_cmp_and_or_move_action (inst
, inst_env
, operand2
, operand3
);
3126 inst_env
->slot_needed
= 0;
3127 inst_env
->prefix_found
= 0;
3128 inst_env
->xflag_found
= 0;
3129 inst_env
->disable_interrupt
= 0;
3132 /* Handles the three-operand addressing mode for the ADD, SUB, CMP, AND and
3133 OR instructions. Note that for this to work as expected, the calling
3134 function must have made sure that there is a prefix to this instruction. */
3137 three_operand_add_sub_cmp_and_or_op (unsigned short inst
,
3138 inst_env_type
*inst_env
)
3140 unsigned long operand2
;
3141 unsigned long operand3
;
3143 if (cris_get_operand1 (inst
) == REG_PC
)
3145 /* The PC will be changed by the instruction. */
3146 operand2
= inst_env
->reg
[cris_get_operand2 (inst
)];
3148 /* Get the value of the third operand. */
3149 operand3
= get_data_from_address (&inst
, inst_env
->prefix_value
);
3151 /* Calculate the PC value after the instruction, i.e. where the
3152 breakpoint should be. */
3153 add_sub_cmp_and_or_move_action (inst
, inst_env
, operand2
, operand3
);
3155 inst_env
->slot_needed
= 0;
3156 inst_env
->prefix_found
= 0;
3157 inst_env
->xflag_found
= 0;
3158 inst_env
->disable_interrupt
= 0;
3161 /* Handles the index addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
3162 instructions. The MOVE instruction is the move from source to register. */
3165 handle_prefix_index_mode_for_aritm_op (unsigned short inst
,
3166 inst_env_type
*inst_env
)
3168 if (cris_get_operand1 (inst
) != cris_get_operand2 (inst
))
3170 /* If the instruction is MOVE it's invalid. If the instruction is ADD,
3171 SUB, AND or OR something weird is going on (if everything works these
3172 instructions should end up in the three operand version). */
3173 inst_env
->invalid
= 1;
3178 /* three_operand_add_sub_cmp_and_or does the same as we should do here
3180 three_operand_add_sub_cmp_and_or_op (inst
, inst_env
);
3182 inst_env
->slot_needed
= 0;
3183 inst_env
->prefix_found
= 0;
3184 inst_env
->xflag_found
= 0;
3185 inst_env
->disable_interrupt
= 0;
3188 /* Handles the autoincrement and indirect addresing mode for the ADD, SUB,
3189 CMP, AND OR and MOVE instruction. The MOVE instruction is the move from
3190 source to register. */
3193 handle_inc_and_index_mode_for_aritm_op (unsigned short inst
,
3194 inst_env_type
*inst_env
)
3196 unsigned long operand1
;
3197 unsigned long operand2
;
3198 unsigned long operand3
;
3201 /* The instruction is either an indirect or autoincrement addressing mode.
3202 Check if the destination register is the PC. */
3203 if (cris_get_operand2 (inst
) == REG_PC
)
3205 /* Must be done here, get_data_from_address may change the size
3207 size
= cris_get_size (inst
);
3208 operand2
= inst_env
->reg
[REG_PC
];
3210 /* Get the value of the third operand, i.e. the indirect operand. */
3211 operand1
= inst_env
->reg
[cris_get_operand1 (inst
)];
3212 operand3
= get_data_from_address (&inst
, operand1
);
3214 /* Calculate the PC value after the instruction, i.e. where the
3215 breakpoint should be. The order of the udw_operands is vital. */
3216 add_sub_cmp_and_or_move_action (inst
, inst_env
, operand2
, operand3
);
3218 /* If this is an autoincrement addressing mode, check if the increment
3220 if ((cris_get_operand1 (inst
) == REG_PC
) && (cris_get_mode (inst
) == AUTOINC_MODE
))
3222 /* Get the size field. */
3223 size
= cris_get_size (inst
);
3225 /* If it's an extend instruction we don't want the signed extend bit,
3226 because it influences the size. */
3227 if (cris_get_opcode (inst
) < 4)
3229 size
&= ~SIGNED_EXTEND_BIT_MASK
;
3231 process_autoincrement (size
, inst
, inst_env
);
3233 inst_env
->slot_needed
= 0;
3234 inst_env
->prefix_found
= 0;
3235 inst_env
->xflag_found
= 0;
3236 inst_env
->disable_interrupt
= 0;
3239 /* Handles the two-operand addressing mode, all modes except register, for
3240 the ADD, SUB CMP, AND and OR instruction. */
3243 none_reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst
,
3244 inst_env_type
*inst_env
)
3246 if (inst_env
->prefix_found
)
3248 if (cris_get_mode (inst
) == PREFIX_INDEX_MODE
)
3250 handle_prefix_index_mode_for_aritm_op (inst
, inst_env
);
3252 else if (cris_get_mode (inst
) == PREFIX_ASSIGN_MODE
)
3254 handle_prefix_assign_mode_for_aritm_op (inst
, inst_env
);
3258 /* The mode is invalid for a prefixed base instruction. */
3259 inst_env
->invalid
= 1;
3265 handle_inc_and_index_mode_for_aritm_op (inst
, inst_env
);
3269 /* Handles the quick addressing mode for the ADD and SUB instruction. */
3272 quick_mode_add_sub_op (unsigned short inst
, inst_env_type
*inst_env
)
3274 unsigned long operand1
;
3275 unsigned long operand2
;
3277 /* It's a bad idea to be in a prefix instruction now. This is a quick mode
3278 instruction and can't have a prefix. */
3279 if (inst_env
->prefix_found
)
3281 inst_env
->invalid
= 1;
3285 /* Check if the instruction has PC as its target. */
3286 if (cris_get_operand2 (inst
) == REG_PC
)
3288 if (inst_env
->slot_needed
)
3290 inst_env
->invalid
= 1;
3293 operand1
= cris_get_quick_value (inst
);
3294 operand2
= inst_env
->reg
[REG_PC
];
3296 /* The size should now be dword. */
3297 cris_set_size_to_dword (&inst
);
3299 /* Calculate the PC value after the instruction, i.e. where the
3300 breakpoint should be. */
3301 add_sub_cmp_and_or_move_action (inst
, inst_env
, operand2
, operand1
);
3303 inst_env
->slot_needed
= 0;
3304 inst_env
->prefix_found
= 0;
3305 inst_env
->xflag_found
= 0;
3306 inst_env
->disable_interrupt
= 0;
3309 /* Handles the quick addressing mode for the CMP, AND and OR instruction. */
3312 quick_mode_and_cmp_move_or_op (unsigned short inst
, inst_env_type
*inst_env
)
3314 unsigned long operand1
;
3315 unsigned long operand2
;
3317 /* It's a bad idea to be in a prefix instruction now. This is a quick mode
3318 instruction and can't have a prefix. */
3319 if (inst_env
->prefix_found
)
3321 inst_env
->invalid
= 1;
3324 /* Check if the instruction has PC as its target. */
3325 if (cris_get_operand2 (inst
) == REG_PC
)
3327 if (inst_env
->slot_needed
)
3329 inst_env
->invalid
= 1;
3332 /* The instruction has the PC as its target register. */
3333 operand1
= cris_get_quick_value (inst
);
3334 operand2
= inst_env
->reg
[REG_PC
];
3336 /* The quick value is signed, so check if we must do a signed extend. */
3337 if (operand1
& SIGNED_QUICK_VALUE_MASK
)
3340 operand1
|= SIGNED_QUICK_VALUE_EXTEND_MASK
;
3342 /* The size should now be dword. */
3343 cris_set_size_to_dword (&inst
);
3345 /* Calculate the PC value after the instruction, i.e. where the
3346 breakpoint should be. */
3347 add_sub_cmp_and_or_move_action (inst
, inst_env
, operand2
, operand1
);
3349 inst_env
->slot_needed
= 0;
3350 inst_env
->prefix_found
= 0;
3351 inst_env
->xflag_found
= 0;
3352 inst_env
->disable_interrupt
= 0;
3355 /* Translate op_type to a function and call it. */
3358 cris_gdb_func (enum cris_op_type op_type
, unsigned short inst
,
3359 inst_env_type
*inst_env
)
3363 case cris_not_implemented_op
:
3364 not_implemented_op (inst
, inst_env
);
3368 abs_op (inst
, inst_env
);
3372 addi_op (inst
, inst_env
);
3376 asr_op (inst
, inst_env
);
3380 asrq_op (inst
, inst_env
);
3383 case cris_ax_ei_setf_op
:
3384 ax_ei_setf_op (inst
, inst_env
);
3387 case cris_bdap_prefix
:
3388 bdap_prefix (inst
, inst_env
);
3391 case cris_biap_prefix
:
3392 biap_prefix (inst
, inst_env
);
3396 break_op (inst
, inst_env
);
3399 case cris_btst_nop_op
:
3400 btst_nop_op (inst
, inst_env
);
3403 case cris_clearf_di_op
:
3404 clearf_di_op (inst
, inst_env
);
3407 case cris_dip_prefix
:
3408 dip_prefix (inst
, inst_env
);
3411 case cris_dstep_logshift_mstep_neg_not_op
:
3412 dstep_logshift_mstep_neg_not_op (inst
, inst_env
);
3415 case cris_eight_bit_offset_branch_op
:
3416 eight_bit_offset_branch_op (inst
, inst_env
);
3419 case cris_move_mem_to_reg_movem_op
:
3420 move_mem_to_reg_movem_op (inst
, inst_env
);
3423 case cris_move_reg_to_mem_movem_op
:
3424 move_reg_to_mem_movem_op (inst
, inst_env
);
3427 case cris_move_to_preg_op
:
3428 move_to_preg_op (inst
, inst_env
);
3432 muls_op (inst
, inst_env
);
3436 mulu_op (inst
, inst_env
);
3439 case cris_none_reg_mode_add_sub_cmp_and_or_move_op
:
3440 none_reg_mode_add_sub_cmp_and_or_move_op (inst
, inst_env
);
3443 case cris_none_reg_mode_clear_test_op
:
3444 none_reg_mode_clear_test_op (inst
, inst_env
);
3447 case cris_none_reg_mode_jump_op
:
3448 none_reg_mode_jump_op (inst
, inst_env
);
3451 case cris_none_reg_mode_move_from_preg_op
:
3452 none_reg_mode_move_from_preg_op (inst
, inst_env
);
3455 case cris_quick_mode_add_sub_op
:
3456 quick_mode_add_sub_op (inst
, inst_env
);
3459 case cris_quick_mode_and_cmp_move_or_op
:
3460 quick_mode_and_cmp_move_or_op (inst
, inst_env
);
3463 case cris_quick_mode_bdap_prefix
:
3464 quick_mode_bdap_prefix (inst
, inst_env
);
3467 case cris_reg_mode_add_sub_cmp_and_or_move_op
:
3468 reg_mode_add_sub_cmp_and_or_move_op (inst
, inst_env
);
3471 case cris_reg_mode_clear_op
:
3472 reg_mode_clear_op (inst
, inst_env
);
3475 case cris_reg_mode_jump_op
:
3476 reg_mode_jump_op (inst
, inst_env
);
3479 case cris_reg_mode_move_from_preg_op
:
3480 reg_mode_move_from_preg_op (inst
, inst_env
);
3483 case cris_reg_mode_test_op
:
3484 reg_mode_test_op (inst
, inst_env
);
3488 scc_op (inst
, inst_env
);
3491 case cris_sixteen_bit_offset_branch_op
:
3492 sixteen_bit_offset_branch_op (inst
, inst_env
);
3495 case cris_three_operand_add_sub_cmp_and_or_op
:
3496 three_operand_add_sub_cmp_and_or_op (inst
, inst_env
);
3499 case cris_three_operand_bound_op
:
3500 three_operand_bound_op (inst
, inst_env
);
3503 case cris_two_operand_bound_op
:
3504 two_operand_bound_op (inst
, inst_env
);
3508 xor_op (inst
, inst_env
);
3513 /* This wrapper is to avoid cris_get_assembler being called before
3514 exec_bfd has been set. */
3517 cris_delayed_get_disassembler (bfd_vma addr
, struct disassemble_info
*info
)
3519 int (*print_insn
) (bfd_vma addr
, struct disassemble_info
*info
);
3520 /* FIXME: cagney/2003-08-27: It should be possible to select a CRIS
3521 disassembler, even when there is no BFD. Does something like
3522 "gdb; target remote; disassmeble *0x123" work? */
3523 gdb_assert (exec_bfd
!= NULL
);
3524 print_insn
= cris_get_disassembler (exec_bfd
);
3525 gdb_assert (print_insn
!= NULL
);
3526 return print_insn (addr
, info
);
3529 /* Copied from <asm/elf.h>. */
3530 typedef unsigned long elf_greg_t
;
3532 /* Same as user_regs_struct struct in <asm/user.h>. */
3533 typedef elf_greg_t elf_gregset_t
[35];
3535 /* Unpack an elf_gregset_t into GDB's register cache. */
3538 supply_gregset (elf_gregset_t
*gregsetp
)
3541 elf_greg_t
*regp
= *gregsetp
;
3542 static char zerobuf
[4] = {0};
3544 /* The kernel dumps all 32 registers as unsigned longs, but supply_register
3545 knows about the actual size of each register so that's no problem. */
3546 for (i
= 0; i
< NUM_GENREGS
+ NUM_SPECREGS
; i
++)
3548 supply_register (i
, (char *)®p
[i
]);
3552 /* Use a local version of this function to get the correct types for
3553 regsets, until multi-arch core support is ready. */
3556 fetch_core_registers (char *core_reg_sect
, unsigned core_reg_size
,
3557 int which
, CORE_ADDR reg_addr
)
3559 elf_gregset_t gregset
;
3564 if (core_reg_size
!= sizeof (gregset
))
3566 warning ("wrong size gregset struct in core file");
3570 memcpy (&gregset
, core_reg_sect
, sizeof (gregset
));
3571 supply_gregset (&gregset
);
3575 /* We've covered all the kinds of registers we know about here,
3576 so this must be something we wouldn't know what to do with
3577 anyway. Just ignore it. */
3582 static struct core_fns cris_elf_core_fns
=
3584 bfd_target_elf_flavour
, /* core_flavour */
3585 default_check_format
, /* check_format */
3586 default_core_sniffer
, /* core_sniffer */
3587 fetch_core_registers
, /* core_read_registers */
3591 /* Fetch (and possibly build) an appropriate link_map_offsets
3592 structure for native GNU/Linux CRIS targets using the struct
3593 offsets defined in link.h (but without actual reference to that
3596 This makes it possible to access GNU/Linux CRIS shared libraries
3597 from a GDB that was not built on an GNU/Linux CRIS host (for cross
3600 See gdb/solib-svr4.h for an explanation of these fields. */
3602 static struct link_map_offsets
*
3603 cris_linux_svr4_fetch_link_map_offsets (void)
3605 static struct link_map_offsets lmo
;
3606 static struct link_map_offsets
*lmp
= NULL
;
3612 lmo
.r_debug_size
= 8; /* The actual size is 20 bytes, but
3613 this is all we need. */
3614 lmo
.r_map_offset
= 4;
3617 lmo
.link_map_size
= 20;
3619 lmo
.l_addr_offset
= 0;
3620 lmo
.l_addr_size
= 4;
3622 lmo
.l_name_offset
= 4;
3623 lmo
.l_name_size
= 4;
3625 lmo
.l_next_offset
= 12;
3626 lmo
.l_next_size
= 4;
3628 lmo
.l_prev_offset
= 16;
3629 lmo
.l_prev_size
= 4;
3636 cris_fpless_backtrace (char *noargs
, int from_tty
)
3638 /* Points at the instruction after the jsr (except when in innermost frame
3639 where it points at the original pc). */
3642 /* Temporary variable, used for parsing from the start of the function that
3643 the pc is in, up to the pc. */
3644 CORE_ADDR tmp_pc
= 0;
3647 /* Information about current frame. */
3648 struct symtab_and_line sal
;
3651 /* Present instruction. */
3652 unsigned short insn
;
3654 /* Next instruction, lookahead. */
3655 unsigned short insn_next
;
3657 /* This is to store the offset between sp at start of function and until we
3658 reach push srp (if any). */
3659 int sp_add_later
= 0;
3660 int push_srp_found
= 0;
3664 /* Frame counter. */
3667 /* For the innermost frame, we want to look at srp in case it's a leaf
3668 function (since there's no push srp in that case). */
3669 int innermost_frame
= 1;
3671 deprecated_read_register_gen (PC_REGNUM
, (char *) &pc
);
3672 deprecated_read_register_gen (SP_REGNUM
, (char *) &sp
);
3674 /* We make an explicit return when we can't find an outer frame. */
3677 /* Get file name and line number. */
3678 sal
= find_pc_line (pc
, 0);
3680 /* Get function name. */
3681 find_pc_partial_function (pc
, &func_name
, (CORE_ADDR
*) NULL
,
3682 (CORE_ADDR
*) NULL
);
3684 /* Print information about current frame. */
3685 printf_unfiltered ("#%i 0x%08lx in %s", frame
++, pc
, func_name
);
3688 printf_unfiltered (" at %s:%i", sal
.symtab
->filename
, sal
.line
);
3690 printf_unfiltered ("\n");
3692 /* Get the start address of this function. */
3693 tmp_pc
= get_pc_function_start (pc
);
3695 /* Mini parser, only meant to find push sp and sub ...,sp from the start
3696 of the function, up to the pc. */
3699 insn
= read_memory_unsigned_integer (tmp_pc
, sizeof (short));
3700 tmp_pc
+= sizeof (short);
3703 /* push <reg> 32 bit instruction */
3704 insn_next
= read_memory_unsigned_integer (tmp_pc
,
3706 tmp_pc
+= sizeof (short);
3708 /* Recognize srp. */
3709 if (insn_next
== 0xBE7E)
3711 /* For subsequent (not this one though) push or sub which
3712 affects sp, adjust sp immediately. */
3715 /* Note: this will break if we ever encounter a
3716 push vr (1 byte) or push ccr (2 bytes). */
3721 /* Some other register was pushed. */
3732 else if (cris_get_operand2 (insn
) == SP_REGNUM
3733 && cris_get_mode (insn
) == 0x0000
3734 && cris_get_opcode (insn
) == 0x000A)
3737 val
= cris_get_quick_value (insn
);
3745 sp_add_later
+= val
;
3749 else if (cris_get_operand2 (insn
) == SP_REGNUM
3750 /* Autoincrement addressing mode. */
3751 && cris_get_mode (insn
) == 0x0003
3753 && ((insn
) & 0x03E0) >> 5 == 0x0004)
3756 val
= get_data_from_address (&insn
, tmp_pc
);
3764 sp_add_later
+= val
;
3767 else if (cris_get_operand2 (insn
) == SP_REGNUM
3768 && ((insn
& 0x0F00) >> 8) == 0x0001
3769 && (cris_get_signed_offset (insn
) < 0))
3771 /* Immediate byte offset addressing prefix word with sp as base
3772 register. Used for CRIS v8 i.e. ETRAX 100 and newer if <val>
3773 is between 64 and 128.
3774 movem r<regsave>,[sp=sp-<val>] */
3775 val
= -cris_get_signed_offset (insn
);
3776 insn_next
= read_memory_unsigned_integer (tmp_pc
,
3778 tmp_pc
+= sizeof (short);
3780 if (cris_get_mode (insn_next
) == PREFIX_ASSIGN_MODE
3781 && cris_get_opcode (insn_next
) == 0x000F
3782 && cris_get_size (insn_next
) == 0x0003
3783 && cris_get_operand1 (insn_next
) == SP_REGNUM
)
3791 sp_add_later
+= val
;
3802 /* sp should now point at where srp is stored on the stack. Update
3803 the pc to the srp. */
3804 pc
= read_memory_unsigned_integer (sp
, 4);
3806 else if (innermost_frame
)
3808 /* We couldn't find a push srp in the prologue, so this must be
3809 a leaf function, and thus we use the srp register directly.
3810 This should happen at most once, for the innermost function. */
3811 deprecated_read_register_gen (SRP_REGNUM
, (char *) &pc
);
3815 /* Couldn't find an outer frame. */
3819 /* Reset flag. (In case the innermost frame wasn't a leaf, we don't
3820 want to look at the srp register later either). */
3821 innermost_frame
= 0;
3823 /* Now, add the offset for everything up to, and including push srp,
3824 that was held back during the prologue parsing. */
3830 extern initialize_file_ftype _initialize_cris_tdep
; /* -Wmissing-prototypes */
3833 _initialize_cris_tdep (void)
3835 struct cmd_list_element
*c
;
3837 gdbarch_register (bfd_arch_cris
, cris_gdbarch_init
, cris_dump_tdep
);
3839 /* CRIS-specific user-commands. */
3840 c
= add_set_cmd ("cris-version", class_support
, var_integer
,
3841 (char *) &usr_cmd_cris_version
,
3842 "Set the current CRIS version.", &setlist
);
3843 set_cmd_sfunc (c
, cris_version_update
);
3844 add_show_from_set (c
, &showlist
);
3846 c
= add_set_enum_cmd ("cris-mode", class_support
, cris_mode_enums
,
3848 "Set the current CRIS mode.", &setlist
);
3849 set_cmd_sfunc (c
, cris_mode_update
);
3850 add_show_from_set (c
, &showlist
);
3852 c
= add_set_enum_cmd ("cris-abi", class_support
, cris_abi_enums
,
3854 "Set the current CRIS ABI version.", &setlist
);
3855 set_cmd_sfunc (c
, cris_abi_update
);
3856 add_show_from_set (c
, &showlist
);
3858 c
= add_cmd ("cris-fpless-backtrace", class_support
, cris_fpless_backtrace
,
3859 "Display call chain using the subroutine return pointer.\n"
3860 "Note that this displays the address after the jump to the "
3861 "subroutine.", &cmdlist
);
3863 add_core_fns (&cris_elf_core_fns
);
3867 /* Prints out all target specific values. */
3870 cris_dump_tdep (struct gdbarch
*gdbarch
, struct ui_file
*file
)
3872 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
3875 fprintf_unfiltered (file
, "cris_dump_tdep: tdep->cris_version = %i\n",
3876 tdep
->cris_version
);
3877 fprintf_unfiltered (file
, "cris_dump_tdep: tdep->cris_mode = %s\n",
3879 fprintf_unfiltered (file
, "cris_dump_tdep: tdep->cris_abi = %s\n",
3886 cris_version_update (char *ignore_args
, int from_tty
,
3887 struct cmd_list_element
*c
)
3889 struct gdbarch_info info
;
3891 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
3892 the set command passed as a parameter. The clone operation will
3893 include (BUG?) any ``set'' command callback, if present.
3894 Commands like ``info set'' call all the ``show'' command
3895 callbacks. Unfortunately, for ``show'' commands cloned from
3896 ``set'', this includes callbacks belonging to ``set'' commands.
3897 Making this worse, this only occures if add_show_from_set() is
3898 called after add_cmd_sfunc() (BUG?). */
3900 /* From here on, trust the user's CRIS version setting. */
3901 if (cmd_type (c
) == set_cmd
)
3903 usr_cmd_cris_version_valid
= 1;
3905 /* Update the current architecture, if needed. */
3906 gdbarch_info_init (&info
);
3907 if (!gdbarch_update_p (info
))
3908 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_update: failed to update architecture.");
3913 cris_mode_update (char *ignore_args
, int from_tty
,
3914 struct cmd_list_element
*c
)
3916 struct gdbarch_info info
;
3918 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
3919 the set command passed as a parameter. The clone operation will
3920 include (BUG?) any ``set'' command callback, if present.
3921 Commands like ``info set'' call all the ``show'' command
3922 callbacks. Unfortunately, for ``show'' commands cloned from
3923 ``set'', this includes callbacks belonging to ``set'' commands.
3924 Making this worse, this only occures if add_show_from_set() is
3925 called after add_cmd_sfunc() (BUG?). */
3927 /* From here on, trust the user's CRIS mode setting. */
3928 if (cmd_type (c
) == set_cmd
)
3930 usr_cmd_cris_mode_valid
= 1;
3932 /* Update the current architecture, if needed. */
3933 gdbarch_info_init (&info
);
3934 if (!gdbarch_update_p (info
))
3935 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_update: failed to update architecture.");
3940 cris_abi_update (char *ignore_args
, int from_tty
,
3941 struct cmd_list_element
*c
)
3943 struct gdbarch_info info
;
3945 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
3946 the set command passed as a parameter. The clone operation will
3947 include (BUG?) any ``set'' command callback, if present.
3948 Commands like ``info set'' call all the ``show'' command
3949 callbacks. Unfortunately, for ``show'' commands cloned from
3950 ``set'', this includes callbacks belonging to ``set'' commands.
3951 Making this worse, this only occures if add_show_from_set() is
3952 called after add_cmd_sfunc() (BUG?). */
3954 /* From here on, trust the user's CRIS ABI setting. */
3955 if (cmd_type (c
) == set_cmd
)
3957 usr_cmd_cris_abi_valid
= 1;
3959 /* Update the current architecture, if needed. */
3960 gdbarch_info_init (&info
);
3961 if (!gdbarch_update_p (info
))
3962 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_update: failed to update architecture.");
3966 /* Copied from pa64solib.c, with a couple of minor changes. */
3969 bfd_lookup_symbol (bfd
*abfd
, const char *symname
)
3971 unsigned int storage_needed
;
3973 asymbol
**symbol_table
;
3974 unsigned int number_of_symbols
;
3976 struct cleanup
*back_to
;
3977 CORE_ADDR symaddr
= 0;
3979 storage_needed
= bfd_get_symtab_upper_bound (abfd
);
3981 if (storage_needed
> 0)
3983 symbol_table
= (asymbol
**) xmalloc (storage_needed
);
3984 back_to
= make_cleanup (free
, symbol_table
);
3985 number_of_symbols
= bfd_canonicalize_symtab (abfd
, symbol_table
);
3987 for (i
= 0; i
< number_of_symbols
; i
++)
3989 sym
= *symbol_table
++;
3990 if (!strcmp (sym
->name
, symname
))
3992 /* Bfd symbols are section relative. */
3993 symaddr
= sym
->value
+ sym
->section
->vma
;
3997 do_cleanups (back_to
);
4002 static struct gdbarch
*
4003 cris_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
4005 struct gdbarch
*gdbarch
;
4006 struct gdbarch_tdep
*tdep
;
4008 const char *cris_mode
;
4009 const char *cris_abi
;
4010 CORE_ADDR cris_abi_sym
= 0;
4013 if (usr_cmd_cris_version_valid
)
4015 /* Trust the user's CRIS version setting. */
4016 cris_version
= usr_cmd_cris_version
;
4020 /* Assume it's CRIS version 10. */
4024 if (usr_cmd_cris_mode_valid
)
4026 /* Trust the user's CRIS mode setting. */
4027 cris_mode
= usr_cmd_cris_mode
;
4029 else if (cris_version
== 10)
4031 /* Assume CRIS version 10 is in user mode. */
4032 cris_mode
= CRIS_MODE_USER
;
4036 /* Strictly speaking, older CRIS version don't have a supervisor mode,
4037 but we regard its only mode as supervisor mode. */
4038 cris_mode
= CRIS_MODE_SUPERVISOR
;
4041 if (usr_cmd_cris_abi_valid
)
4043 /* Trust the user's ABI setting. */
4044 cris_abi
= usr_cmd_cris_abi
;
4048 if (bfd_get_flavour (info
.abfd
) == bfd_target_elf_flavour
)
4050 /* An elf target uses the new ABI. */
4051 cris_abi
= CRIS_ABI_V2
;
4053 else if (bfd_get_flavour (info
.abfd
) == bfd_target_aout_flavour
)
4055 /* An a.out target may use either ABI. Look for hints in the
4057 cris_abi_sym
= bfd_lookup_symbol (info
.abfd
, CRIS_ABI_SYMBOL
);
4058 cris_abi
= cris_abi_sym
? CRIS_ABI_V2
: CRIS_ABI_ORIGINAL
;
4062 /* Unknown bfd flavour. Assume it's the new ABI. */
4063 cris_abi
= CRIS_ABI_V2
;
4066 else if (arches
!= NULL
)
4068 /* No bfd available. Stick with the ABI from the most recently
4069 selected architecture of this same family (the head of arches
4070 always points to this). (This is to avoid changing the ABI
4071 when the user updates the architecture with the 'set
4072 cris-version' command.) */
4073 cris_abi
= gdbarch_tdep (arches
->gdbarch
)->cris_abi
;
4077 /* No bfd, and no previously selected architecture available.
4078 Assume it's the new ABI. */
4079 cris_abi
= CRIS_ABI_V2
;
4082 /* Make the current settings visible to the user. */
4083 usr_cmd_cris_version
= cris_version
;
4084 usr_cmd_cris_mode
= cris_mode
;
4085 usr_cmd_cris_abi
= cris_abi
;
4087 /* Find a candidate among the list of pre-declared architectures. Both
4088 CRIS version and ABI must match. */
4089 for (arches
= gdbarch_list_lookup_by_info (arches
, &info
);
4091 arches
= gdbarch_list_lookup_by_info (arches
->next
, &info
))
4093 if ((gdbarch_tdep (arches
->gdbarch
)->cris_version
== cris_version
)
4094 && (gdbarch_tdep (arches
->gdbarch
)->cris_mode
== cris_mode
)
4095 && (gdbarch_tdep (arches
->gdbarch
)->cris_abi
== cris_abi
))
4096 return arches
->gdbarch
;
4099 /* No matching architecture was found. Create a new one. */
4100 tdep
= (struct gdbarch_tdep
*) xmalloc (sizeof (struct gdbarch_tdep
));
4101 gdbarch
= gdbarch_alloc (&info
, tdep
);
4103 /* NOTE: cagney/2002-12-06: This can be deleted when this arch is
4104 ready to unwind the PC first (see frame.c:get_prev_frame()). */
4105 set_gdbarch_deprecated_init_frame_pc (gdbarch
, deprecated_init_frame_pc_default
);
4107 tdep
->cris_version
= cris_version
;
4108 tdep
->cris_mode
= cris_mode
;
4109 tdep
->cris_abi
= cris_abi
;
4111 /* INIT shall ensure that the INFO.BYTE_ORDER is non-zero. */
4112 switch (info
.byte_order
)
4114 case BFD_ENDIAN_LITTLE
:
4118 case BFD_ENDIAN_BIG
:
4119 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_init: big endian byte order in info");
4123 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_init: unknown byte order in info");
4126 /* Initialize the ABI dependent things. */
4127 if (tdep
->cris_abi
== CRIS_ABI_ORIGINAL
)
4129 set_gdbarch_double_bit (gdbarch
, 32);
4130 set_gdbarch_deprecated_push_arguments (gdbarch
, cris_abi_original_push_arguments
);
4131 set_gdbarch_deprecated_store_return_value (gdbarch
,
4132 cris_abi_original_store_return_value
);
4133 set_gdbarch_deprecated_extract_return_value
4134 (gdbarch
, cris_abi_original_extract_return_value
);
4135 set_gdbarch_deprecated_reg_struct_has_addr
4136 (gdbarch
, cris_abi_original_reg_struct_has_addr
);
4138 else if (tdep
->cris_abi
== CRIS_ABI_V2
)
4140 set_gdbarch_double_bit (gdbarch
, 64);
4141 set_gdbarch_deprecated_push_arguments (gdbarch
, cris_abi_v2_push_arguments
);
4142 set_gdbarch_deprecated_store_return_value (gdbarch
, cris_abi_v2_store_return_value
);
4143 set_gdbarch_deprecated_extract_return_value
4144 (gdbarch
, cris_abi_v2_extract_return_value
);
4145 set_gdbarch_deprecated_reg_struct_has_addr
4146 (gdbarch
, cris_abi_v2_reg_struct_has_addr
);
4149 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_init: unknown CRIS ABI");
4151 /* The default definition of a long double is 2 * TARGET_DOUBLE_BIT,
4152 which means we have to set this explicitly. */
4153 set_gdbarch_long_double_bit (gdbarch
, 64);
4155 /* There are 32 registers (some of which may not be implemented). */
4156 set_gdbarch_num_regs (gdbarch
, 32);
4157 set_gdbarch_sp_regnum (gdbarch
, 14);
4158 set_gdbarch_deprecated_fp_regnum (gdbarch
, 8);
4159 set_gdbarch_pc_regnum (gdbarch
, 15);
4161 set_gdbarch_register_name (gdbarch
, cris_register_name
);
4163 /* Length of ordinary registers used in push_word and a few other
4164 places. DEPRECATED_REGISTER_RAW_SIZE is the real way to know how
4165 big a register is. */
4166 set_gdbarch_deprecated_register_size (gdbarch
, 4);
4169 set_gdbarch_register_bytes_ok (gdbarch
, cris_register_bytes_ok
);
4170 set_gdbarch_software_single_step (gdbarch
, cris_software_single_step
);
4173 set_gdbarch_cannot_store_register (gdbarch
, cris_cannot_store_register
);
4174 set_gdbarch_cannot_fetch_register (gdbarch
, cris_cannot_fetch_register
);
4177 /* The total amount of space needed to store (in an array called registers)
4178 GDB's copy of the machine's register state. Note: We can not use
4179 cris_register_size at this point, since it relies on current_gdbarch
4181 switch (tdep
->cris_version
)
4187 /* Support for these may be added later. */
4188 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_init: unsupported CRIS version");
4193 /* CRIS v8 and v9, a.k.a. ETRAX 100. General registers R0 - R15
4194 (32 bits), special registers P0 - P1 (8 bits), P4 - P5 (16 bits),
4195 and P8 - P14 (32 bits). */
4196 register_bytes
= (16 * 4) + (2 * 1) + (2 * 2) + (7 * 4);
4201 /* CRIS v10 and v11, a.k.a. ETRAX 100LX. In addition to ETRAX 100,
4202 P7 (32 bits), and P15 (32 bits) have been implemented. */
4203 register_bytes
= (16 * 4) + (2 * 1) + (2 * 2) + (9 * 4);
4207 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_init: unknown CRIS version");
4210 set_gdbarch_deprecated_register_bytes (gdbarch
, register_bytes
);
4212 /* Returns the register offset for the first byte of register regno's space
4213 in the saved register state. */
4214 set_gdbarch_deprecated_register_byte (gdbarch
, cris_register_offset
);
4216 /* The length of the registers in the actual machine representation. */
4217 set_gdbarch_deprecated_register_raw_size (gdbarch
, cris_register_size
);
4219 /* The largest value DEPRECATED_REGISTER_RAW_SIZE can have. */
4220 set_gdbarch_deprecated_max_register_raw_size (gdbarch
, 32);
4222 /* The length of the registers in the program's representation. */
4223 set_gdbarch_deprecated_register_virtual_size (gdbarch
, cris_register_size
);
4225 /* The largest value DEPRECATED_REGISTER_VIRTUAL_SIZE can have. */
4226 set_gdbarch_deprecated_max_register_virtual_size (gdbarch
, 32);
4228 set_gdbarch_deprecated_register_virtual_type (gdbarch
, cris_register_virtual_type
);
4230 /* Use generic dummy frames. */
4232 /* Read all about dummy frames in blockframe.c. */
4233 set_gdbarch_deprecated_pc_in_call_dummy (gdbarch
, deprecated_pc_in_call_dummy_at_entry_point
);
4235 /* Defined to 1 to indicate that the target supports inferior function
4237 set_gdbarch_deprecated_call_dummy_words (gdbarch
, 0);
4238 set_gdbarch_deprecated_sizeof_call_dummy_words (gdbarch
, 0);
4240 set_gdbarch_deprecated_get_saved_register (gdbarch
, deprecated_generic_get_saved_register
);
4242 set_gdbarch_deprecated_push_return_address (gdbarch
, cris_push_return_address
);
4243 set_gdbarch_deprecated_pop_frame (gdbarch
, cris_pop_frame
);
4245 set_gdbarch_deprecated_store_struct_return (gdbarch
, cris_store_struct_return
);
4246 set_gdbarch_use_struct_convention (gdbarch
, always_use_struct_convention
);
4248 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch
, cris_frame_init_saved_regs
);
4249 set_gdbarch_deprecated_init_extra_frame_info (gdbarch
, cris_init_extra_frame_info
);
4250 set_gdbarch_skip_prologue (gdbarch
, cris_skip_prologue
);
4251 set_gdbarch_prologue_frameless_p (gdbarch
, generic_prologue_frameless_p
);
4253 /* The stack grows downward. */
4254 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
4256 set_gdbarch_breakpoint_from_pc (gdbarch
, cris_breakpoint_from_pc
);
4258 /* The number of bytes at the start of arglist that are not really args,
4259 0 in the CRIS ABI. */
4260 set_gdbarch_frame_args_skip (gdbarch
, 0);
4261 set_gdbarch_frameless_function_invocation
4262 (gdbarch
, cris_frameless_function_invocation
);
4263 set_gdbarch_deprecated_frame_chain (gdbarch
, cris_frame_chain
);
4265 set_gdbarch_deprecated_frame_saved_pc (gdbarch
, cris_frame_saved_pc
);
4266 set_gdbarch_deprecated_saved_pc_after_call (gdbarch
, cris_saved_pc_after_call
);
4268 /* Helpful for backtracing and returning in a call dummy. */
4269 set_gdbarch_deprecated_save_dummy_frame_tos (gdbarch
, generic_save_dummy_frame_tos
);
4271 /* Should be using push_dummy_call. */
4272 set_gdbarch_deprecated_dummy_write_sp (gdbarch
, deprecated_write_sp
);
4274 /* Use target_specific function to define link map offsets. */
4275 set_solib_svr4_fetch_link_map_offsets
4276 (gdbarch
, cris_linux_svr4_fetch_link_map_offsets
);
4278 /* FIXME: cagney/2003-08-27: It should be possible to select a CRIS
4279 disassembler, even when there is no BFD. Does something like
4280 "gdb; target remote; disassmeble *0x123" work? */
4281 set_gdbarch_print_insn (gdbarch
, cris_delayed_get_disassembler
);