1 /* Target dependent code for CRIS, for GDB, the GNU debugger.
2 Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
3 Contributed by Axis Communications AB.
4 Written by Hendrik Ruijter, Stefan Andersson, and Orjan Friberg.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
31 #include "opcode/cris.h"
32 #include "arch-utils.h"
35 /* To get entry_point_address. */
38 #include "solib.h" /* Support for shared libraries. */
39 #include "solib-svr4.h" /* For struct link_map_offsets. */
40 #include "gdb_string.h"
45 /* There are no floating point registers. Used in gdbserver low-linux.c. */
48 /* There are 16 general registers. */
51 /* There are 16 special registers. */
55 /* Register numbers of various important registers.
56 FP_REGNUM Contains address of executing stack frame.
57 STR_REGNUM Contains the address of structure return values.
58 RET_REGNUM Contains the return value when shorter than or equal to 32 bits
59 ARG1_REGNUM Contains the first parameter to a function.
60 ARG2_REGNUM Contains the second parameter to a function.
61 ARG3_REGNUM Contains the third parameter to a function.
62 ARG4_REGNUM Contains the fourth parameter to a function. Rest on stack.
63 SP_REGNUM Contains address of top of stack.
64 PC_REGNUM Contains address of next instruction.
65 SRP_REGNUM Subroutine return pointer register.
66 BRP_REGNUM Breakpoint return pointer register. */
68 /* FP_REGNUM = 8, SP_REGNUM = 14, and PC_REGNUM = 15 have been incorporated
69 into the multi-arch framework. */
73 /* Enums with respect to the general registers, valid for all
82 /* Enums with respect to the special registers, some of which may not be
83 applicable to all CRIS versions. */
101 extern const struct cris_spec_reg cris_spec_regs
[];
103 /* CRIS version, set via the user command 'set cris-version'. Affects
104 register names and sizes.*/
105 static int usr_cmd_cris_version
;
107 /* Indicates whether to trust the above variable. */
108 static int usr_cmd_cris_version_valid
= 0;
110 /* CRIS mode, set via the user command 'set cris-mode'. Affects availability
111 of some registers. */
112 static const char *usr_cmd_cris_mode
;
114 /* Indicates whether to trust the above variable. */
115 static int usr_cmd_cris_mode_valid
= 0;
117 static const char CRIS_MODE_USER
[] = "CRIS_MODE_USER";
118 static const char CRIS_MODE_SUPERVISOR
[] = "CRIS_MODE_SUPERVISOR";
119 static const char *cris_mode_enums
[] =
122 CRIS_MODE_SUPERVISOR
,
126 /* CRIS ABI, set via the user command 'set cris-abi'.
127 There are two flavours:
128 1. Original ABI with 32-bit doubles, where arguments <= 4 bytes are
130 2. New ABI with 64-bit doubles, where arguments <= 8 bytes are passed by
132 static const char *usr_cmd_cris_abi
;
134 /* Indicates whether to trust the above variable. */
135 static int usr_cmd_cris_abi_valid
= 0;
137 /* These variables are strings instead of enums to make them usable as
138 parameters to add_set_enum_cmd. */
139 static const char CRIS_ABI_ORIGINAL
[] = "CRIS_ABI_ORIGINAL";
140 static const char CRIS_ABI_V2
[] = "CRIS_ABI_V2";
141 static const char CRIS_ABI_SYMBOL
[] = ".$CRIS_ABI_V2";
142 static const char *cris_abi_enums
[] =
149 /* CRIS architecture specific information. */
153 const char *cris_mode
;
154 const char *cris_abi
;
157 /* Functions for accessing target dependent data. */
162 return (gdbarch_tdep (current_gdbarch
)->cris_version
);
168 return (gdbarch_tdep (current_gdbarch
)->cris_mode
);
174 return (gdbarch_tdep (current_gdbarch
)->cris_abi
);
177 /* For saving call-clobbered contents in R9 when returning structs. */
178 static CORE_ADDR struct_return_address
;
180 struct frame_extra_info
186 /* The instruction environment needed to find single-step breakpoints. */
188 struct instruction_environment
190 unsigned long reg
[NUM_GENREGS
];
191 unsigned long preg
[NUM_SPECREGS
];
192 unsigned long branch_break_address
;
193 unsigned long delay_slot_pc
;
194 unsigned long prefix_value
;
199 int delay_slot_pc_active
;
201 int disable_interrupt
;
204 /* Save old breakpoints in order to restore the state before a single_step.
205 At most, two breakpoints will have to be remembered. */
207 char binsn_quantum
[BREAKPOINT_MAX
];
208 static binsn_quantum break_mem
[2];
209 static CORE_ADDR next_pc
= 0;
210 static CORE_ADDR branch_target_address
= 0;
211 static unsigned char branch_break_inserted
= 0;
213 /* Machine-dependencies in CRIS for opcodes. */
215 /* Instruction sizes. */
216 enum cris_instruction_sizes
223 /* Addressing modes. */
224 enum cris_addressing_modes
231 /* Prefix addressing modes. */
232 enum cris_prefix_addressing_modes
234 PREFIX_INDEX_MODE
= 2,
235 PREFIX_ASSIGN_MODE
= 3,
237 /* Handle immediate byte offset addressing mode prefix format. */
238 PREFIX_OFFSET_MODE
= 2
241 /* Masks for opcodes. */
242 enum cris_opcode_masks
244 BRANCH_SIGNED_SHORT_OFFSET_MASK
= 0x1,
245 SIGNED_EXTEND_BIT_MASK
= 0x2,
246 SIGNED_BYTE_MASK
= 0x80,
247 SIGNED_BYTE_EXTEND_MASK
= 0xFFFFFF00,
248 SIGNED_WORD_MASK
= 0x8000,
249 SIGNED_WORD_EXTEND_MASK
= 0xFFFF0000,
250 SIGNED_DWORD_MASK
= 0x80000000,
251 SIGNED_QUICK_VALUE_MASK
= 0x20,
252 SIGNED_QUICK_VALUE_EXTEND_MASK
= 0xFFFFFFC0
255 /* Functions for opcodes. The general form of the ETRAX 16-bit instruction:
263 cris_get_operand2 (unsigned short insn
)
265 return ((insn
& 0xF000) >> 12);
269 cris_get_mode (unsigned short insn
)
271 return ((insn
& 0x0C00) >> 10);
275 cris_get_opcode (unsigned short insn
)
277 return ((insn
& 0x03C0) >> 6);
281 cris_get_size (unsigned short insn
)
283 return ((insn
& 0x0030) >> 4);
287 cris_get_operand1 (unsigned short insn
)
289 return (insn
& 0x000F);
292 /* Additional functions in order to handle opcodes. */
295 cris_get_wide_opcode (unsigned short insn
)
297 return ((insn
& 0x03E0) >> 5);
301 cris_get_short_size (unsigned short insn
)
303 return ((insn
& 0x0010) >> 4);
307 cris_get_quick_value (unsigned short insn
)
309 return (insn
& 0x003F);
313 cris_get_bdap_quick_offset (unsigned short insn
)
315 return (insn
& 0x00FF);
319 cris_get_branch_short_offset (unsigned short insn
)
321 return (insn
& 0x00FF);
325 cris_get_asr_shift_steps (unsigned long value
)
327 return (value
& 0x3F);
331 cris_get_asr_quick_shift_steps (unsigned short insn
)
333 return (insn
& 0x1F);
337 cris_get_clear_size (unsigned short insn
)
339 return ((insn
) & 0xC000);
343 cris_is_signed_extend_bit_on (unsigned short insn
)
345 return (((insn
) & 0x20) == 0x20);
349 cris_is_xflag_bit_on (unsigned short insn
)
351 return (((insn
) & 0x1000) == 0x1000);
355 cris_set_size_to_dword (unsigned short *insn
)
362 cris_get_signed_offset (unsigned short insn
)
364 return ((signed char) (insn
& 0x00FF));
367 /* Calls an op function given the op-type, working on the insn and the
369 static void cris_gdb_func (enum cris_op_type
, unsigned short, inst_env_type
*);
371 static CORE_ADDR
cris_skip_prologue_main (CORE_ADDR pc
, int frameless_p
);
373 static struct gdbarch
*cris_gdbarch_init (struct gdbarch_info
,
374 struct gdbarch_list
*);
376 static int cris_delayed_get_disassembler (bfd_vma
, disassemble_info
*);
378 static void cris_dump_tdep (struct gdbarch
*, struct ui_file
*);
380 static void cris_version_update (char *ignore_args
, int from_tty
,
381 struct cmd_list_element
*c
);
383 static void cris_mode_update (char *ignore_args
, int from_tty
,
384 struct cmd_list_element
*c
);
386 static void cris_abi_update (char *ignore_args
, int from_tty
,
387 struct cmd_list_element
*c
);
389 static CORE_ADDR
bfd_lookup_symbol (bfd
*, const char *);
391 /* Frames information. The definition of the struct frame_info is
395 enum frame_type type;
399 If the compilation option -fno-omit-frame-pointer is present the
400 variable frame will be set to the content of R8 which is the frame
403 The variable pc contains the address where execution is performed
404 in the present frame. The innermost frame contains the current content
405 of the register PC. All other frames contain the content of the
406 register PC in the next frame.
408 The variable `type' indicates the frame's type: normal, SIGTRAMP
409 (associated with a signal handler), dummy (associated with a dummy
412 The variable return_pc contains the address where execution should be
413 resumed when the present frame has finished, the return address.
415 The variable leaf_function is 1 if the return address is in the register
416 SRP, and 0 if it is on the stack.
418 Prologue instructions C-code.
419 The prologue may consist of (-fno-omit-frame-pointer)
423 move.d sp,r8 move.d sp,r8
425 movem rY,[sp] movem rY,[sp]
426 move.S rZ,[r8-U] move.S rZ,[r8-U]
428 where 1 is a non-terminal function, and 2 is a leaf-function.
430 Note that this assumption is extremely brittle, and will break at the
431 slightest change in GCC's prologue.
433 If local variables are declared or register contents are saved on stack
434 the subq-instruction will be present with X as the number of bytes
435 needed for storage. The reshuffle with respect to r8 may be performed
436 with any size S (b, w, d) and any of the general registers Z={0..13}.
437 The offset U should be representable by a signed 8-bit value in all cases.
438 Thus, the prefix word is assumed to be immediate byte offset mode followed
439 by another word containing the instruction.
448 Prologue instructions C++-code.
449 Case 1) and 2) in the C-code may be followed by
455 move.S [r8+U],rZ ; P4
457 if any of the call parameters are stored. The host expects these
458 instructions to be executed in order to get the call parameters right. */
460 /* Examine the prologue of a function. The variable ip is the address of
461 the first instruction of the prologue. The variable limit is the address
462 of the first instruction after the prologue. The variable fi contains the
463 information in struct frame_info. The variable frameless_p controls whether
464 the entire prologue is examined (0) or just enough instructions to
465 determine that it is a prologue (1). */
468 cris_examine (CORE_ADDR ip
, CORE_ADDR limit
, struct frame_info
*fi
,
471 /* Present instruction. */
474 /* Next instruction, lookahead. */
475 unsigned short insn_next
;
478 /* Is there a push fp? */
481 /* Number of byte on stack used for local variables and movem. */
484 /* Highest register number in a movem. */
487 /* move.d r<source_register>,rS */
488 short source_register
;
490 /* This frame is with respect to a leaf until a push srp is found. */
491 fi
->extra_info
->leaf_function
= 1;
493 /* This frame is without the FP until a push fp is found. */
496 /* Assume nothing on stack. */
500 /* No information about register contents so far. */
502 /* We only want to know the end of the prologue when fi->saved_regs == 0.
503 When the saved registers are allocated full information is required. */
504 if (get_frame_saved_regs (fi
))
506 for (regno
= 0; regno
< NUM_REGS
; regno
++)
507 get_frame_saved_regs (fi
)[regno
] = 0;
510 /* Find the prologue instructions. */
513 insn
= read_memory_unsigned_integer (ip
, sizeof (short));
514 ip
+= sizeof (short);
517 /* push <reg> 32 bit instruction */
518 insn_next
= read_memory_unsigned_integer (ip
, sizeof (short));
519 ip
+= sizeof (short);
520 regno
= cris_get_operand2 (insn_next
);
522 /* This check, meant to recognize srp, used to be regno ==
523 (SRP_REGNUM - NUM_GENREGS), but that covers r11 also. */
524 if (insn_next
== 0xBE7E)
530 fi
->extra_info
->leaf_function
= 0;
532 else if (regno
== FP_REGNUM
)
537 else if (insn
== 0x866E)
546 else if (cris_get_operand2 (insn
) == SP_REGNUM
547 && cris_get_mode (insn
) == 0x0000
548 && cris_get_opcode (insn
) == 0x000A)
551 val
= cris_get_quick_value (insn
);
553 else if (cris_get_mode (insn
) == 0x0002
554 && cris_get_opcode (insn
) == 0x000F
555 && cris_get_size (insn
) == 0x0003
556 && cris_get_operand1 (insn
) == SP_REGNUM
)
558 /* movem r<regsave>,[sp] */
563 regsave
= cris_get_operand2 (insn
);
565 else if (cris_get_operand2 (insn
) == SP_REGNUM
566 && ((insn
& 0x0F00) >> 8) == 0x0001
567 && (cris_get_signed_offset (insn
) < 0))
569 /* Immediate byte offset addressing prefix word with sp as base
570 register. Used for CRIS v8 i.e. ETRAX 100 and newer if <val>
571 is between 64 and 128.
572 movem r<regsave>,[sp=sp-<val>] */
573 val
= -cris_get_signed_offset (insn
);
574 insn_next
= read_memory_unsigned_integer (ip
, sizeof (short));
575 ip
+= sizeof (short);
576 if (cris_get_mode (insn_next
) == PREFIX_ASSIGN_MODE
577 && cris_get_opcode (insn_next
) == 0x000F
578 && cris_get_size (insn_next
) == 0x0003
579 && cris_get_operand1 (insn_next
) == SP_REGNUM
)
585 regsave
= cris_get_operand2 (insn_next
);
589 /* The prologue ended before the limit was reached. */
590 ip
-= 2 * sizeof (short);
594 else if (cris_get_mode (insn
) == 0x0001
595 && cris_get_opcode (insn
) == 0x0009
596 && cris_get_size (insn
) == 0x0002)
598 /* move.d r<10..13>,r<0..15> */
603 source_register
= cris_get_operand1 (insn
);
605 /* FIXME? In the glibc solibs, the prologue might contain something
606 like (this example taken from relocate_doit):
609 which isn't covered by the source_register check below. Question
610 is whether to add a check for this combo, or make better use of
611 the limit variable instead. */
612 if (source_register
< ARG1_REGNUM
|| source_register
> ARG4_REGNUM
)
614 /* The prologue ended before the limit was reached. */
615 ip
-= sizeof (short);
619 else if (cris_get_operand2 (insn
) == FP_REGNUM
620 /* The size is a fixed-size. */
621 && ((insn
& 0x0F00) >> 8) == 0x0001
622 /* A negative offset. */
623 && (cris_get_signed_offset (insn
) < 0))
625 /* move.S rZ,[r8-U] (?) */
626 insn_next
= read_memory_unsigned_integer (ip
, sizeof (short));
627 ip
+= sizeof (short);
628 regno
= cris_get_operand2 (insn_next
);
629 if ((regno
>= 0 && regno
< SP_REGNUM
)
630 && cris_get_mode (insn_next
) == PREFIX_OFFSET_MODE
631 && cris_get_opcode (insn_next
) == 0x000F)
633 /* move.S rZ,[r8-U] */
638 /* The prologue ended before the limit was reached. */
639 ip
-= 2 * sizeof (short);
643 else if (cris_get_operand2 (insn
) == FP_REGNUM
644 /* The size is a fixed-size. */
645 && ((insn
& 0x0F00) >> 8) == 0x0001
646 /* A positive offset. */
647 && (cris_get_signed_offset (insn
) > 0))
649 /* move.S [r8+U],rZ (?) */
650 insn_next
= read_memory_unsigned_integer (ip
, sizeof (short));
651 ip
+= sizeof (short);
652 regno
= cris_get_operand2 (insn_next
);
653 if ((regno
>= 0 && regno
< SP_REGNUM
)
654 && cris_get_mode (insn_next
) == PREFIX_OFFSET_MODE
655 && cris_get_opcode (insn_next
) == 0x0009
656 && cris_get_operand1 (insn_next
) == regno
)
658 /* move.S [r8+U],rZ */
663 /* The prologue ended before the limit was reached. */
664 ip
-= 2 * sizeof (short);
670 /* The prologue ended before the limit was reached. */
671 ip
-= sizeof (short);
677 /* We only want to know the end of the prologue when
678 fi->saved_regs == 0. */
679 if (!get_frame_saved_regs (fi
))
684 get_frame_saved_regs (fi
)[FP_REGNUM
] = get_frame_base (fi
);
686 /* Calculate the addresses. */
687 for (regno
= regsave
; regno
>= 0; regno
--)
689 get_frame_saved_regs (fi
)[regno
] = get_frame_base (fi
) - val
;
692 if (fi
->extra_info
->leaf_function
)
694 /* Set the register SP to contain the stack pointer of
696 get_frame_saved_regs (fi
)[SP_REGNUM
] = get_frame_base (fi
) + 4;
700 /* Set the register SP to contain the stack pointer of
702 get_frame_saved_regs (fi
)[SP_REGNUM
] = get_frame_base (fi
) + 8;
704 /* Set the register SRP to contain the return address of
706 get_frame_saved_regs (fi
)[SRP_REGNUM
] = get_frame_base (fi
) + 4;
712 /* Advance pc beyond any function entry prologue instructions at pc
713 to reach some "real" code. */
716 cris_skip_prologue (CORE_ADDR pc
)
718 return cris_skip_prologue_main (pc
, 0);
721 /* As cris_skip_prologue, but stops as soon as it knows that the function
722 has a frame. Its result is equal to its input pc if the function is
723 frameless, unequal otherwise. */
726 cris_skip_prologue_frameless_p (CORE_ADDR pc
)
728 return cris_skip_prologue_main (pc
, 1);
731 /* Given a PC value corresponding to the start of a function, return the PC
732 of the first instruction after the function prologue. */
735 cris_skip_prologue_main (CORE_ADDR pc
, int frameless_p
)
737 struct frame_info fi
;
738 static struct frame_extra_info fei
;
739 struct symtab_and_line sal
= find_pc_line (pc
, 0);
741 CORE_ADDR pc_after_prologue
;
743 /* frame_info now contains dynamic memory. Since fi is a dummy here,
744 I use static memory for extra_info, and don't bother allocating
745 memory for saved_regs. */
746 memset (&fi
, 0, sizeof (fi
));
747 fi
.extra_info
= &fei
;
749 /* If there is no symbol information then sal.end == 0, and we end up
750 examining only the first instruction in the function prologue.
751 Exaggerating the limit seems to be harmless. */
753 best_limit
= sal
.end
;
755 best_limit
= pc
+ 100;
757 pc_after_prologue
= cris_examine (pc
, best_limit
, &fi
, frameless_p
);
758 return pc_after_prologue
;
761 /* Use the program counter to determine the contents and size of a breakpoint
762 instruction. It returns a pointer to a string of bytes that encode a
763 breakpoint instruction, stores the length of the string to *lenptr, and
764 adjusts pcptr (if necessary) to point to the actual memory location where
765 the breakpoint should be inserted. */
767 const unsigned char *
768 cris_breakpoint_from_pc (CORE_ADDR
*pcptr
, int *lenptr
)
770 static unsigned char break_insn
[] = {0x38, 0xe9};
776 /* Returns the register SRP (subroutine return pointer) which must contain
777 the content of the register PC after a function call. */
780 cris_saved_pc_after_call (struct frame_info
*frame
)
782 return read_register (SRP_REGNUM
);
785 /* Returns 1 if spec_reg is applicable to the current gdbarch's CRIS version,
789 cris_spec_reg_applicable (struct cris_spec_reg spec_reg
)
791 int version
= cris_version ();
793 switch (spec_reg
.applicable_version
)
795 case cris_ver_version_all
:
797 case cris_ver_warning
:
798 /* Indeterminate/obsolete. */
801 /* Simulator only. */
804 return (version
>= 0 && version
<= 3);
806 return (version
>= 3);
808 return (version
== 8 || version
== 9);
810 return (version
>= 8);
812 return (version
>= 10);
814 /* Invalid cris version. */
819 /* Returns the register size in unit byte. Returns 0 for an unimplemented
820 register, -1 for an invalid register. */
823 cris_register_size (int regno
)
828 if (regno
>= 0 && regno
< NUM_GENREGS
)
830 /* General registers (R0 - R15) are 32 bits. */
833 else if (regno
>= NUM_GENREGS
&& regno
< NUM_REGS
)
835 /* Special register (R16 - R31). cris_spec_regs is zero-based.
836 Adjust regno accordingly. */
837 spec_regno
= regno
- NUM_GENREGS
;
839 /* The entries in cris_spec_regs are stored in register number order,
840 which means we can shortcut into the array when searching it. */
841 for (i
= spec_regno
; cris_spec_regs
[i
].name
!= NULL
; i
++)
843 if (cris_spec_regs
[i
].number
== spec_regno
844 && cris_spec_reg_applicable (cris_spec_regs
[i
]))
845 /* Go with the first applicable register. */
846 return cris_spec_regs
[i
].reg_size
;
848 /* Special register not applicable to this CRIS version. */
853 /* Invalid register. */
858 /* Nonzero if regno should not be fetched from the target. This is the case
859 for unimplemented (size 0) and non-existant registers. */
862 cris_cannot_fetch_register (int regno
)
864 return ((regno
< 0 || regno
>= NUM_REGS
)
865 || (cris_register_size (regno
) == 0));
868 /* Nonzero if regno should not be written to the target, for various
872 cris_cannot_store_register (int regno
)
874 /* There are three kinds of registers we refuse to write to.
875 1. Those that not implemented.
876 2. Those that are read-only (depends on the processor mode).
877 3. Those registers to which a write has no effect.
880 if (regno
< 0 || regno
>= NUM_REGS
|| cris_register_size (regno
) == 0)
881 /* Not implemented. */
884 else if (regno
== VR_REGNUM
)
888 else if (regno
== P0_REGNUM
|| regno
== P4_REGNUM
|| regno
== P8_REGNUM
)
889 /* Writing has no effect. */
892 else if (cris_mode () == CRIS_MODE_USER
)
894 if (regno
== IBR_REGNUM
|| regno
== BAR_REGNUM
|| regno
== BRP_REGNUM
895 || regno
== IRP_REGNUM
)
896 /* Read-only in user mode. */
903 /* Returns the register offset for the first byte of register regno's space
904 in the saved register state. Returns -1 for an invalid or unimplemented
908 cris_register_offset (int regno
)
914 if (regno
>= 0 && regno
< NUM_REGS
)
916 /* FIXME: The offsets should be cached and calculated only once,
917 when the architecture being debugged has changed. */
918 for (i
= 0; i
< regno
; i
++)
919 offset
+= cris_register_size (i
);
925 /* Invalid register. */
930 /* Return the GDB type (defined in gdbtypes.c) for the "standard" data type
931 of data in register regno. */
934 cris_register_virtual_type (int regno
)
936 if (regno
== SP_REGNUM
|| regno
== PC_REGNUM
937 || (regno
> P8_REGNUM
&& regno
< USP_REGNUM
))
939 /* SP, PC, IBR, IRP, SRP, BAR, DCCR, BRP */
940 return lookup_pointer_type (builtin_type_void
);
942 else if (regno
== P8_REGNUM
|| regno
== USP_REGNUM
943 || (regno
>= 0 && regno
< SP_REGNUM
))
945 /* R0 - R13, P8, P15 */
946 return builtin_type_unsigned_long
;
948 else if (regno
> P3_REGNUM
&& regno
< P8_REGNUM
)
950 /* P4, CCR, DCR0, DCR1 */
951 return builtin_type_unsigned_short
;
953 else if (regno
> PC_REGNUM
&& regno
< P4_REGNUM
)
956 return builtin_type_unsigned_char
;
960 /* Invalid register. */
961 return builtin_type_void
;
965 /* Stores a function return value of type type, where valbuf is the address
966 of the value to be stored. */
968 /* In the original CRIS ABI, R10 is used to store return values. */
971 cris_abi_original_store_return_value (struct type
*type
, char *valbuf
)
973 int len
= TYPE_LENGTH (type
);
975 if (len
<= REGISTER_SIZE
)
976 deprecated_write_register_bytes (REGISTER_BYTE (RET_REGNUM
), valbuf
, len
);
978 internal_error (__FILE__
, __LINE__
, "cris_abi_original_store_return_value: type length too large.");
981 /* In the CRIS ABI V2, R10 and R11 are used to store return values. */
984 cris_abi_v2_store_return_value (struct type
*type
, char *valbuf
)
986 int len
= TYPE_LENGTH (type
);
988 if (len
<= 2 * REGISTER_SIZE
)
990 /* Note that this works since R10 and R11 are consecutive registers. */
991 deprecated_write_register_bytes (REGISTER_BYTE (RET_REGNUM
), valbuf
,
995 internal_error (__FILE__
, __LINE__
, "cris_abi_v2_store_return_value: type length too large.");
998 /* Return the name of register regno as a string. Return NULL for an invalid or
999 unimplemented register. */
1002 cris_register_name (int regno
)
1004 static char *cris_genreg_names
[] =
1005 { "r0", "r1", "r2", "r3", \
1006 "r4", "r5", "r6", "r7", \
1007 "r8", "r9", "r10", "r11", \
1008 "r12", "r13", "sp", "pc" };
1013 if (regno
>= 0 && regno
< NUM_GENREGS
)
1015 /* General register. */
1016 return cris_genreg_names
[regno
];
1018 else if (regno
>= NUM_GENREGS
&& regno
< NUM_REGS
)
1020 /* Special register (R16 - R31). cris_spec_regs is zero-based.
1021 Adjust regno accordingly. */
1022 spec_regno
= regno
- NUM_GENREGS
;
1024 /* The entries in cris_spec_regs are stored in register number order,
1025 which means we can shortcut into the array when searching it. */
1026 for (i
= spec_regno
; cris_spec_regs
[i
].name
!= NULL
; i
++)
1028 if (cris_spec_regs
[i
].number
== spec_regno
1029 && cris_spec_reg_applicable (cris_spec_regs
[i
]))
1030 /* Go with the first applicable register. */
1031 return cris_spec_regs
[i
].name
;
1033 /* Special register not applicable to this CRIS version. */
1038 /* Invalid register. */
1044 cris_register_bytes_ok (long bytes
)
1046 return (bytes
== REGISTER_BYTES
);
1049 /* Extract from an array regbuf containing the raw register state a function
1050 return value of type type, and copy that, in virtual format, into
1053 /* In the original CRIS ABI, R10 is used to return values. */
1056 cris_abi_original_extract_return_value (struct type
*type
, char *regbuf
,
1059 int len
= TYPE_LENGTH (type
);
1061 if (len
<= REGISTER_SIZE
)
1062 memcpy (valbuf
, regbuf
+ REGISTER_BYTE (RET_REGNUM
), len
);
1064 internal_error (__FILE__
, __LINE__
, "cris_abi_original_extract_return_value: type length too large");
1067 /* In the CRIS ABI V2, R10 and R11 are used to store return values. */
1070 cris_abi_v2_extract_return_value (struct type
*type
, char *regbuf
,
1073 int len
= TYPE_LENGTH (type
);
1075 if (len
<= 2 * REGISTER_SIZE
)
1076 memcpy (valbuf
, regbuf
+ REGISTER_BYTE (RET_REGNUM
), len
);
1078 internal_error (__FILE__
, __LINE__
, "cris_abi_v2_extract_return_value: type length too large");
1081 /* Store the address of the place in which to copy the structure the
1082 subroutine will return. In the CRIS ABI, R9 is used in order to pass
1083 the address of the allocated area where a structure return value must
1084 be stored. R9 is call-clobbered, which means we must save it here for
1088 cris_store_struct_return (CORE_ADDR addr
, CORE_ADDR sp
)
1090 write_register (STR_REGNUM
, addr
);
1091 struct_return_address
= addr
;
1094 /* Extract from regbuf the address where a function should return a
1095 structure value. It's not there in the CRIS ABI, so we must do it another
1099 cris_extract_struct_value_address (char *regbuf
)
1101 return struct_return_address
;
1104 /* Returns 1 if a value of the given type being returned from a function
1105 must have space allocated for it on the stack. gcc_p is true if the
1106 function being considered is known to have been compiled by GCC.
1107 In the CRIS ABI, structure return values are passed to the called
1108 function by reference in register R9 to a caller-allocated area, so
1109 this is always true. */
1112 cris_use_struct_convention (int gcc_p
, struct type
*type
)
1117 /* Returns 1 if the given type will be passed by pointer rather than
1120 /* In the original CRIS ABI, arguments shorter than or equal to 32 bits are
1124 cris_abi_original_reg_struct_has_addr (int gcc_p
, struct type
*type
)
1126 return (TYPE_LENGTH (type
) > 4);
1129 /* In the CRIS ABI V2, arguments shorter than or equal to 64 bits are passed
1133 cris_abi_v2_reg_struct_has_addr (int gcc_p
, struct type
*type
)
1135 return (TYPE_LENGTH (type
) > 8);
1138 /* Returns 1 if the function invocation represented by fi does not have a
1139 stack frame associated with it. Otherwise return 0. */
1142 cris_frameless_function_invocation (struct frame_info
*fi
)
1144 if ((get_frame_type (fi
) == SIGTRAMP_FRAME
))
1147 return frameless_look_for_prologue (fi
);
1150 /* See frame.h. Determines the address of all registers in the current stack
1151 frame storing each in frame->saved_regs. Space for frame->saved_regs shall
1152 be allocated by FRAME_INIT_SAVED_REGS using either frame_saved_regs_zalloc
1153 or frame_obstack_alloc. */
1156 cris_frame_init_saved_regs (struct frame_info
*fi
)
1159 struct symtab_and_line sal
;
1161 char *dummy_regs
= deprecated_generic_find_dummy_frame (get_frame_pc (fi
), fi
->frame
);
1163 /* Examine the entire prologue. */
1164 register int frameless_p
= 0;
1166 /* Has this frame's registers already been initialized? */
1167 if (get_frame_saved_regs (fi
))
1170 frame_saved_regs_zalloc (fi
);
1174 /* I don't see this ever happening, considering the context in which
1175 cris_frame_init_saved_regs is called (always when we're not in
1177 memcpy (&fi
->saved_regs
, dummy_regs
, sizeof (fi
->saved_regs
));
1181 ip
= get_pc_function_start (get_frame_pc (fi
));
1182 sal
= find_pc_line (ip
, 0);
1184 /* If there is no symbol information then sal.end == 0, and we end up
1185 examining only the first instruction in the function prologue.
1186 Exaggerating the limit seems to be harmless. */
1188 best_limit
= sal
.end
;
1190 best_limit
= ip
+ 100;
1192 cris_examine (ip
, best_limit
, fi
, frameless_p
);
1196 /* Initialises the extra frame information at the creation of a new frame.
1197 The inparameter fromleaf is 0 when the call is from create_new_frame.
1198 When the call is from get_prev_frame_info, fromleaf is determined by
1199 cris_frameless_function_invocation. */
1202 cris_init_extra_frame_info (int fromleaf
, struct frame_info
*fi
)
1206 /* Called from get_prev_frame. */
1207 deprecated_update_frame_pc_hack (fi
, FRAME_SAVED_PC (fi
->next
));
1210 fi
->extra_info
= (struct frame_extra_info
*)
1211 frame_obstack_alloc (sizeof (struct frame_extra_info
));
1213 fi
->extra_info
->return_pc
= 0;
1214 fi
->extra_info
->leaf_function
= 0;
1216 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi
), fi
->frame
, fi
->frame
))
1218 /* We need to setup fi->frame here because run_stack_dummy gets it wrong
1219 by assuming it's always FP. */
1220 deprecated_update_frame_base_hack (fi
, deprecated_read_register_dummy (get_frame_pc (fi
), fi
->frame
,
1222 fi
->extra_info
->return_pc
=
1223 deprecated_read_register_dummy (get_frame_pc (fi
), fi
->frame
, PC_REGNUM
);
1225 /* FIXME: Is this necessarily true? */
1226 fi
->extra_info
->leaf_function
= 0;
1230 cris_frame_init_saved_regs (fi
);
1232 /* Check fromleaf/frameless_function_invocation. (FIXME) */
1234 if (get_frame_saved_regs (fi
)[SRP_REGNUM
] != 0)
1236 /* SRP was saved on the stack; non-leaf function. */
1237 fi
->extra_info
->return_pc
=
1238 read_memory_integer (get_frame_saved_regs (fi
)[SRP_REGNUM
],
1239 REGISTER_RAW_SIZE (SRP_REGNUM
));
1243 /* SRP is still in a register; leaf function. */
1244 fi
->extra_info
->return_pc
= read_register (SRP_REGNUM
);
1245 /* FIXME: Should leaf_function be set to 1 here? */
1246 fi
->extra_info
->leaf_function
= 1;
1251 /* Return the content of the frame pointer in the present frame. In other
1252 words, determine the address of the calling function's frame. */
1255 cris_frame_chain (struct frame_info
*fi
)
1257 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi
), fi
->frame
, fi
->frame
))
1261 else if (!inside_entry_file (get_frame_pc (fi
)))
1263 return read_memory_unsigned_integer (get_frame_base (fi
), 4);
1271 /* Return the saved PC (which equals the return address) of this frame. */
1274 cris_frame_saved_pc (struct frame_info
*fi
)
1276 return fi
->extra_info
->return_pc
;
1279 /* Setup the function arguments for calling a function in the inferior. */
1282 cris_abi_original_push_arguments (int nargs
, struct value
**args
,
1283 CORE_ADDR sp
, int struct_return
,
1284 CORE_ADDR struct_addr
)
1295 /* Data and parameters reside in different areas on the stack.
1296 Both frame pointers grow toward higher addresses. */
1297 CORE_ADDR fp_params
;
1300 /* Are we returning a value using a structure return or a normal value
1301 return? struct_addr is the address of the reserved space for the return
1302 structure to be written on the stack. */
1305 write_register (STR_REGNUM
, struct_addr
);
1308 /* Make sure there's space on the stack. Allocate space for data and a
1309 parameter to refer to that data. */
1310 for (argnum
= 0, stack_alloc
= 0; argnum
< nargs
; argnum
++)
1311 stack_alloc
+= (TYPE_LENGTH (VALUE_TYPE (args
[argnum
])) + REGISTER_SIZE
);
1313 /* We may over-allocate a little here, but that won't hurt anything. */
1315 /* Initialize stack frame pointers. */
1317 fp_data
= sp
+ (nargs
* REGISTER_SIZE
);
1319 /* Now load as many as possible of the first arguments into
1320 registers, and push the rest onto the stack. */
1321 argreg
= ARG1_REGNUM
;
1324 for (argnum
= 0; argnum
< nargs
; argnum
++)
1326 type
= VALUE_TYPE (args
[argnum
]);
1327 len
= TYPE_LENGTH (type
);
1328 val
= (char *) VALUE_CONTENTS (args
[argnum
]);
1330 if (len
<= REGISTER_SIZE
&& argreg
<= ARG4_REGNUM
)
1332 /* Data fits in a register; put it in the first available
1334 write_register (argreg
, *(unsigned long *) val
);
1337 else if (len
> REGISTER_SIZE
&& argreg
<= ARG4_REGNUM
)
1339 /* Data does not fit in register; pass it on the stack and
1340 put its address in the first available register. */
1341 write_memory (fp_data
, val
, len
);
1342 write_register (argreg
, fp_data
);
1346 else if (len
> REGISTER_SIZE
)
1348 /* Data does not fit in register; put both data and
1349 parameter on the stack. */
1350 write_memory (fp_data
, val
, len
);
1351 write_memory (fp_params
, (char *) (&fp_data
), REGISTER_SIZE
);
1353 fp_params
+= REGISTER_SIZE
;
1357 /* Data fits in a register, but we are out of registers;
1358 put the parameter on the stack. */
1359 write_memory (fp_params
, val
, REGISTER_SIZE
);
1360 fp_params
+= REGISTER_SIZE
;
1368 cris_abi_v2_push_arguments (int nargs
, struct value
**args
, CORE_ADDR sp
,
1369 int struct_return
, CORE_ADDR struct_addr
)
1378 /* The function's arguments and memory allocated by gdb for the arguments to
1379 point at reside in separate areas on the stack.
1380 Both frame pointers grow toward higher addresses. */
1384 /* Are we returning a value using a structure return or a normal value
1385 return? struct_addr is the address of the reserved space for the return
1386 structure to be written on the stack. */
1389 write_register (STR_REGNUM
, struct_addr
);
1392 /* Allocate enough to keep things word-aligned on both parts of the
1395 for (argnum
= 0; argnum
< nargs
; argnum
++)
1400 len
= TYPE_LENGTH (VALUE_TYPE (args
[argnum
]));
1401 reg_demand
= (len
/ REGISTER_SIZE
) + (len
% REGISTER_SIZE
!= 0 ? 1 : 0);
1403 /* reg_demand * REGISTER_SIZE is the amount of memory we might need to
1404 allocate for this argument. 2 * REGISTER_SIZE is the amount of stack
1405 space we might need to pass the argument itself (either by value or by
1407 stack_alloc
+= (reg_demand
* REGISTER_SIZE
+ 2 * REGISTER_SIZE
);
1410 /* We may over-allocate a little here, but that won't hurt anything. */
1412 /* Initialize frame pointers. */
1414 fp_mem
= sp
+ (nargs
* (2 * REGISTER_SIZE
));
1416 /* Now load as many as possible of the first arguments into registers,
1417 and push the rest onto the stack. */
1418 argreg
= ARG1_REGNUM
;
1421 for (argnum
= 0; argnum
< nargs
; argnum
++)
1428 len
= TYPE_LENGTH (VALUE_TYPE (args
[argnum
]));
1429 val
= (char *) VALUE_CONTENTS (args
[argnum
]);
1431 /* How may registers worth of storage do we need for this argument? */
1432 reg_demand
= (len
/ REGISTER_SIZE
) + (len
% REGISTER_SIZE
!= 0 ? 1 : 0);
1434 if (len
<= (2 * REGISTER_SIZE
)
1435 && (argreg
+ reg_demand
- 1 <= ARG4_REGNUM
))
1437 /* Data passed by value. Fits in available register(s). */
1438 for (i
= 0; i
< reg_demand
; i
++)
1440 write_register (argreg
, *(unsigned long *) val
);
1442 val
+= REGISTER_SIZE
;
1445 else if (len
<= (2 * REGISTER_SIZE
) && argreg
<= ARG4_REGNUM
)
1447 /* Data passed by value. Does not fit in available register(s).
1448 Use the register(s) first, then the stack. */
1449 for (i
= 0; i
< reg_demand
; i
++)
1451 if (argreg
<= ARG4_REGNUM
)
1453 write_register (argreg
, *(unsigned long *) val
);
1455 val
+= REGISTER_SIZE
;
1459 /* I guess this memory write could write the remaining data
1460 all at once instead of in REGISTER_SIZE chunks. */
1461 write_memory (fp_arg
, val
, REGISTER_SIZE
);
1462 fp_arg
+= REGISTER_SIZE
;
1463 val
+= REGISTER_SIZE
;
1467 else if (len
> (2 * REGISTER_SIZE
))
1469 /* Data passed by reference. Put it on the stack. */
1470 write_memory (fp_mem
, val
, len
);
1471 write_memory (fp_arg
, (char *) (&fp_mem
), REGISTER_SIZE
);
1473 /* fp_mem need not be word-aligned since it's just a chunk of
1474 memory being pointed at. That is, += len would do. */
1475 fp_mem
+= reg_demand
* REGISTER_SIZE
;
1476 fp_arg
+= REGISTER_SIZE
;
1480 /* Data passed by value. No available registers. Put it on
1482 write_memory (fp_arg
, val
, len
);
1484 /* fp_arg must be word-aligned (i.e., don't += len) to match
1485 the function prologue. */
1486 fp_arg
+= reg_demand
* REGISTER_SIZE
;
1493 /* Never put the return address on the stack. The register SRP is pushed
1494 by the called function unless it is a leaf-function. Due to the BRP
1495 register the PC will change when continue is sent. */
1498 cris_push_return_address (CORE_ADDR pc
, CORE_ADDR sp
)
1500 write_register (SRP_REGNUM
, CALL_DUMMY_ADDRESS ());
1504 /* Restore the machine to the state it had before the current frame
1505 was created. Discard the innermost frame from the stack and restore
1506 all saved registers. */
1509 cris_pop_frame (void)
1511 register struct frame_info
*fi
= get_current_frame ();
1513 register int stack_offset
= 0;
1515 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi
), fi
->frame
, fi
->frame
))
1517 /* This happens when we hit a breakpoint set at the entry point,
1518 when returning from a dummy frame. */
1519 generic_pop_dummy_frame ();
1523 cris_frame_init_saved_regs (fi
);
1525 /* For each register, the address of where it was saved on entry to
1526 the frame now lies in fi->saved_regs[regno], or zero if it was not
1527 saved. This includes special registers such as PC and FP saved in
1528 special ways in the stack frame. The SP_REGNUM is even more
1529 special, the address here is the SP for the next frame, not the
1530 address where the SP was saved. */
1532 /* Restore general registers R0 - R7. They were pushed on the stack
1533 after SP was saved. */
1534 for (regno
= 0; regno
< FP_REGNUM
; regno
++)
1536 if (get_frame_saved_regs (fi
)[regno
])
1538 write_register (regno
,
1539 read_memory_integer (get_frame_saved_regs (fi
)[regno
], 4));
1543 if (get_frame_saved_regs (fi
)[FP_REGNUM
])
1545 /* Pop the frame pointer (R8). It was pushed before SP
1547 write_register (FP_REGNUM
,
1548 read_memory_integer (get_frame_saved_regs (fi
)[FP_REGNUM
], 4));
1551 /* Not a leaf function. */
1552 if (get_frame_saved_regs (fi
)[SRP_REGNUM
])
1554 /* SRP was pushed before SP was saved. */
1558 /* Restore the SP and adjust for R8 and (possibly) SRP. */
1559 write_register (SP_REGNUM
, get_frame_saved_regs (fi
)[FP_REGNUM
] + stack_offset
);
1563 /* Currently, we can't get the correct info into fi->saved_regs
1564 without a frame pointer. */
1567 /* Restore the PC. */
1568 write_register (PC_REGNUM
, fi
->extra_info
->return_pc
);
1570 flush_cached_frames ();
1573 /* Calculates a value that measures how good inst_args constraints an
1574 instruction. It stems from cris_constraint, found in cris-dis.c. */
1577 constraint (unsigned int insn
, const signed char *inst_args
,
1578 inst_env_type
*inst_env
)
1583 const char *s
= inst_args
;
1589 if ((insn
& 0x30) == 0x30)
1594 /* A prefix operand. */
1595 if (inst_env
->prefix_found
)
1601 /* A "push" prefix. (This check was REMOVED by san 970921.) Check for
1602 valid "push" size. In case of special register, it may be != 4. */
1603 if (inst_env
->prefix_found
)
1609 retval
= (((insn
>> 0xC) & 0xF) == (insn
& 0xF));
1617 tmp
= (insn
>> 0xC) & 0xF;
1619 for (i
= 0; cris_spec_regs
[i
].name
!= NULL
; i
++)
1621 /* Since we match four bits, we will give a value of
1622 4 - 1 = 3 in a match. If there is a corresponding
1623 exact match of a special register in another pattern, it
1624 will get a value of 4, which will be higher. This should
1625 be correct in that an exact pattern would match better that
1627 Note that there is a reason for not returning zero; the
1628 pattern for "clear" is partly matched in the bit-pattern
1629 (the two lower bits must be zero), while the bit-pattern
1630 for a move from a special register is matched in the
1631 register constraint.
1632 This also means we will will have a race condition if
1633 there is a partly match in three bits in the bit pattern. */
1634 if (tmp
== cris_spec_regs
[i
].number
)
1641 if (cris_spec_regs
[i
].name
== NULL
)
1648 /* Returns the number of bits set in the variable value. */
1651 number_of_bits (unsigned int value
)
1653 int number_of_bits
= 0;
1657 number_of_bits
+= 1;
1658 value
&= (value
- 1);
1660 return number_of_bits
;
1663 /* Finds the address that should contain the single step breakpoint(s).
1664 It stems from code in cris-dis.c. */
1667 find_cris_op (unsigned short insn
, inst_env_type
*inst_env
)
1670 int max_level_of_match
= -1;
1671 int max_matched
= -1;
1674 for (i
= 0; cris_opcodes
[i
].name
!= NULL
; i
++)
1676 if (((cris_opcodes
[i
].match
& insn
) == cris_opcodes
[i
].match
)
1677 && ((cris_opcodes
[i
].lose
& insn
) == 0))
1679 level_of_match
= constraint (insn
, cris_opcodes
[i
].args
, inst_env
);
1680 if (level_of_match
>= 0)
1683 number_of_bits (cris_opcodes
[i
].match
| cris_opcodes
[i
].lose
);
1684 if (level_of_match
> max_level_of_match
)
1687 max_level_of_match
= level_of_match
;
1688 if (level_of_match
== 16)
1690 /* All bits matched, cannot find better. */
1700 /* Attempts to find single-step breakpoints. Returns -1 on failure which is
1701 actually an internal error. */
1704 find_step_target (inst_env_type
*inst_env
)
1708 unsigned short insn
;
1710 /* Create a local register image and set the initial state. */
1711 for (i
= 0; i
< NUM_GENREGS
; i
++)
1713 inst_env
->reg
[i
] = (unsigned long) read_register (i
);
1715 offset
= NUM_GENREGS
;
1716 for (i
= 0; i
< NUM_SPECREGS
; i
++)
1718 inst_env
->preg
[i
] = (unsigned long) read_register (offset
+ i
);
1720 inst_env
->branch_found
= 0;
1721 inst_env
->slot_needed
= 0;
1722 inst_env
->delay_slot_pc_active
= 0;
1723 inst_env
->prefix_found
= 0;
1724 inst_env
->invalid
= 0;
1725 inst_env
->xflag_found
= 0;
1726 inst_env
->disable_interrupt
= 0;
1728 /* Look for a step target. */
1731 /* Read an instruction from the client. */
1732 insn
= read_memory_unsigned_integer (inst_env
->reg
[PC_REGNUM
], 2);
1734 /* If the instruction is not in a delay slot the new content of the
1735 PC is [PC] + 2. If the instruction is in a delay slot it is not
1736 that simple. Since a instruction in a delay slot cannot change
1737 the content of the PC, it does not matter what value PC will have.
1738 Just make sure it is a valid instruction. */
1739 if (!inst_env
->delay_slot_pc_active
)
1741 inst_env
->reg
[PC_REGNUM
] += 2;
1745 inst_env
->delay_slot_pc_active
= 0;
1746 inst_env
->reg
[PC_REGNUM
] = inst_env
->delay_slot_pc
;
1748 /* Analyse the present instruction. */
1749 i
= find_cris_op (insn
, inst_env
);
1752 inst_env
->invalid
= 1;
1756 cris_gdb_func (cris_opcodes
[i
].op
, insn
, inst_env
);
1758 } while (!inst_env
->invalid
1759 && (inst_env
->prefix_found
|| inst_env
->xflag_found
1760 || inst_env
->slot_needed
));
1764 /* There is no hardware single-step support. The function find_step_target
1765 digs through the opcodes in order to find all possible targets.
1766 Either one ordinary target or two targets for branches may be found. */
1769 cris_software_single_step (enum target_signal ignore
, int insert_breakpoints
)
1771 inst_env_type inst_env
;
1773 if (insert_breakpoints
)
1775 /* Analyse the present instruction environment and insert
1777 int status
= find_step_target (&inst_env
);
1780 /* Could not find a target. FIXME: Should do something. */
1784 /* Insert at most two breakpoints. One for the next PC content
1785 and possibly another one for a branch, jump, etc. */
1786 next_pc
= (CORE_ADDR
) inst_env
.reg
[PC_REGNUM
];
1787 target_insert_breakpoint (next_pc
, break_mem
[0]);
1788 if (inst_env
.branch_found
1789 && (CORE_ADDR
) inst_env
.branch_break_address
!= next_pc
)
1791 branch_target_address
=
1792 (CORE_ADDR
) inst_env
.branch_break_address
;
1793 target_insert_breakpoint (branch_target_address
, break_mem
[1]);
1794 branch_break_inserted
= 1;
1800 /* Remove breakpoints. */
1801 target_remove_breakpoint (next_pc
, break_mem
[0]);
1802 if (branch_break_inserted
)
1804 target_remove_breakpoint (branch_target_address
, break_mem
[1]);
1805 branch_break_inserted
= 0;
1810 /* Calculates the prefix value for quick offset addressing mode. */
1813 quick_mode_bdap_prefix (unsigned short inst
, inst_env_type
*inst_env
)
1815 /* It's invalid to be in a delay slot. You can't have a prefix to this
1816 instruction (not 100% sure). */
1817 if (inst_env
->slot_needed
|| inst_env
->prefix_found
)
1819 inst_env
->invalid
= 1;
1823 inst_env
->prefix_value
= inst_env
->reg
[cris_get_operand2 (inst
)];
1824 inst_env
->prefix_value
+= cris_get_bdap_quick_offset (inst
);
1826 /* A prefix doesn't change the xflag_found. But the rest of the flags
1828 inst_env
->slot_needed
= 0;
1829 inst_env
->prefix_found
= 1;
1832 /* Updates the autoincrement register. The size of the increment is derived
1833 from the size of the operation. The PC is always kept aligned on even
1837 process_autoincrement (int size
, unsigned short inst
, inst_env_type
*inst_env
)
1839 if (size
== INST_BYTE_SIZE
)
1841 inst_env
->reg
[cris_get_operand1 (inst
)] += 1;
1843 /* The PC must be word aligned, so increase the PC with one
1844 word even if the size is byte. */
1845 if (cris_get_operand1 (inst
) == REG_PC
)
1847 inst_env
->reg
[REG_PC
] += 1;
1850 else if (size
== INST_WORD_SIZE
)
1852 inst_env
->reg
[cris_get_operand1 (inst
)] += 2;
1854 else if (size
== INST_DWORD_SIZE
)
1856 inst_env
->reg
[cris_get_operand1 (inst
)] += 4;
1861 inst_env
->invalid
= 1;
1865 /* Just a forward declaration. */
1868 get_data_from_address (unsigned short *inst
, CORE_ADDR address
);
1870 /* Calculates the prefix value for the general case of offset addressing
1874 bdap_prefix (unsigned short inst
, inst_env_type
*inst_env
)
1879 /* It's invalid to be in a delay slot. */
1880 if (inst_env
->slot_needed
|| inst_env
->prefix_found
)
1882 inst_env
->invalid
= 1;
1886 /* The calculation of prefix_value used to be after process_autoincrement,
1887 but that fails for an instruction such as jsr [$r0+12] which is encoded
1888 as 5f0d 0c00 30b9 when compiled with -fpic. Since PC is operand1 it
1889 mustn't be incremented until we have read it and what it points at. */
1890 inst_env
->prefix_value
= inst_env
->reg
[cris_get_operand2 (inst
)];
1892 /* The offset is an indirection of the contents of the operand1 register. */
1893 inst_env
->prefix_value
+=
1894 get_data_from_address (&inst
, inst_env
->reg
[cris_get_operand1 (inst
)]);
1896 if (cris_get_mode (inst
) == AUTOINC_MODE
)
1898 process_autoincrement (cris_get_size (inst
), inst
, inst_env
);
1901 /* A prefix doesn't change the xflag_found. But the rest of the flags
1903 inst_env
->slot_needed
= 0;
1904 inst_env
->prefix_found
= 1;
1907 /* Calculates the prefix value for the index addressing mode. */
1910 biap_prefix (unsigned short inst
, inst_env_type
*inst_env
)
1912 /* It's invalid to be in a delay slot. I can't see that it's possible to
1913 have a prefix to this instruction. So I will treat this as invalid. */
1914 if (inst_env
->slot_needed
|| inst_env
->prefix_found
)
1916 inst_env
->invalid
= 1;
1920 inst_env
->prefix_value
= inst_env
->reg
[cris_get_operand1 (inst
)];
1922 /* The offset is the operand2 value shifted the size of the instruction
1924 inst_env
->prefix_value
+=
1925 inst_env
->reg
[cris_get_operand2 (inst
)] << cris_get_size (inst
);
1927 /* If the PC is operand1 (base) the address used is the address after
1928 the main instruction, i.e. address + 2 (the PC is already compensated
1929 for the prefix operation). */
1930 if (cris_get_operand1 (inst
) == REG_PC
)
1932 inst_env
->prefix_value
+= 2;
1935 /* A prefix doesn't change the xflag_found. But the rest of the flags
1937 inst_env
->slot_needed
= 0;
1938 inst_env
->xflag_found
= 0;
1939 inst_env
->prefix_found
= 1;
1942 /* Calculates the prefix value for the double indirect addressing mode. */
1945 dip_prefix (unsigned short inst
, inst_env_type
*inst_env
)
1950 /* It's invalid to be in a delay slot. */
1951 if (inst_env
->slot_needed
|| inst_env
->prefix_found
)
1953 inst_env
->invalid
= 1;
1957 /* The prefix value is one dereference of the contents of the operand1
1959 address
= (CORE_ADDR
) inst_env
->reg
[cris_get_operand1 (inst
)];
1960 inst_env
->prefix_value
= read_memory_unsigned_integer (address
, 4);
1962 /* Check if the mode is autoincrement. */
1963 if (cris_get_mode (inst
) == AUTOINC_MODE
)
1965 inst_env
->reg
[cris_get_operand1 (inst
)] += 4;
1968 /* A prefix doesn't change the xflag_found. But the rest of the flags
1970 inst_env
->slot_needed
= 0;
1971 inst_env
->xflag_found
= 0;
1972 inst_env
->prefix_found
= 1;
1975 /* Finds the destination for a branch with 8-bits offset. */
1978 eight_bit_offset_branch_op (unsigned short inst
, inst_env_type
*inst_env
)
1983 /* If we have a prefix or are in a delay slot it's bad. */
1984 if (inst_env
->slot_needed
|| inst_env
->prefix_found
)
1986 inst_env
->invalid
= 1;
1990 /* We have a branch, find out where the branch will land. */
1991 offset
= cris_get_branch_short_offset (inst
);
1993 /* Check if the offset is signed. */
1994 if (offset
& BRANCH_SIGNED_SHORT_OFFSET_MASK
)
1999 /* The offset ends with the sign bit, set it to zero. The address
2000 should always be word aligned. */
2001 offset
&= ~BRANCH_SIGNED_SHORT_OFFSET_MASK
;
2003 inst_env
->branch_found
= 1;
2004 inst_env
->branch_break_address
= inst_env
->reg
[REG_PC
] + offset
;
2006 inst_env
->slot_needed
= 1;
2007 inst_env
->prefix_found
= 0;
2008 inst_env
->xflag_found
= 0;
2009 inst_env
->disable_interrupt
= 1;
2012 /* Finds the destination for a branch with 16-bits offset. */
2015 sixteen_bit_offset_branch_op (unsigned short inst
, inst_env_type
*inst_env
)
2019 /* If we have a prefix or is in a delay slot it's bad. */
2020 if (inst_env
->slot_needed
|| inst_env
->prefix_found
)
2022 inst_env
->invalid
= 1;
2026 /* We have a branch, find out the offset for the branch. */
2027 offset
= read_memory_integer (inst_env
->reg
[REG_PC
], 2);
2029 /* The instruction is one word longer than normal, so add one word
2031 inst_env
->reg
[REG_PC
] += 2;
2033 inst_env
->branch_found
= 1;
2034 inst_env
->branch_break_address
= inst_env
->reg
[REG_PC
] + offset
;
2037 inst_env
->slot_needed
= 1;
2038 inst_env
->prefix_found
= 0;
2039 inst_env
->xflag_found
= 0;
2040 inst_env
->disable_interrupt
= 1;
2043 /* Handles the ABS instruction. */
2046 abs_op (unsigned short inst
, inst_env_type
*inst_env
)
2051 /* ABS can't have a prefix, so it's bad if it does. */
2052 if (inst_env
->prefix_found
)
2054 inst_env
->invalid
= 1;
2058 /* Check if the operation affects the PC. */
2059 if (cris_get_operand2 (inst
) == REG_PC
)
2062 /* It's invalid to change to the PC if we are in a delay slot. */
2063 if (inst_env
->slot_needed
)
2065 inst_env
->invalid
= 1;
2069 value
= (long) inst_env
->reg
[REG_PC
];
2071 /* The value of abs (SIGNED_DWORD_MASK) is SIGNED_DWORD_MASK. */
2072 if (value
!= SIGNED_DWORD_MASK
)
2075 inst_env
->reg
[REG_PC
] = (long) value
;
2079 inst_env
->slot_needed
= 0;
2080 inst_env
->prefix_found
= 0;
2081 inst_env
->xflag_found
= 0;
2082 inst_env
->disable_interrupt
= 0;
2085 /* Handles the ADDI instruction. */
2088 addi_op (unsigned short inst
, inst_env_type
*inst_env
)
2090 /* It's invalid to have the PC as base register. And ADDI can't have
2092 if (inst_env
->prefix_found
|| (cris_get_operand1 (inst
) == REG_PC
))
2094 inst_env
->invalid
= 1;
2098 inst_env
->slot_needed
= 0;
2099 inst_env
->prefix_found
= 0;
2100 inst_env
->xflag_found
= 0;
2101 inst_env
->disable_interrupt
= 0;
2104 /* Handles the ASR instruction. */
2107 asr_op (unsigned short inst
, inst_env_type
*inst_env
)
2110 unsigned long value
;
2111 unsigned long signed_extend_mask
= 0;
2113 /* ASR can't have a prefix, so check that it doesn't. */
2114 if (inst_env
->prefix_found
)
2116 inst_env
->invalid
= 1;
2120 /* Check if the PC is the target register. */
2121 if (cris_get_operand2 (inst
) == REG_PC
)
2123 /* It's invalid to change the PC in a delay slot. */
2124 if (inst_env
->slot_needed
)
2126 inst_env
->invalid
= 1;
2129 /* Get the number of bits to shift. */
2130 shift_steps
= cris_get_asr_shift_steps (inst_env
->reg
[cris_get_operand1 (inst
)]);
2131 value
= inst_env
->reg
[REG_PC
];
2133 /* Find out how many bits the operation should apply to. */
2134 if (cris_get_size (inst
) == INST_BYTE_SIZE
)
2136 if (value
& SIGNED_BYTE_MASK
)
2138 signed_extend_mask
= 0xFF;
2139 signed_extend_mask
= signed_extend_mask
>> shift_steps
;
2140 signed_extend_mask
= ~signed_extend_mask
;
2142 value
= value
>> shift_steps
;
2143 value
|= signed_extend_mask
;
2145 inst_env
->reg
[REG_PC
] &= 0xFFFFFF00;
2146 inst_env
->reg
[REG_PC
] |= value
;
2148 else if (cris_get_size (inst
) == INST_WORD_SIZE
)
2150 if (value
& SIGNED_WORD_MASK
)
2152 signed_extend_mask
= 0xFFFF;
2153 signed_extend_mask
= signed_extend_mask
>> shift_steps
;
2154 signed_extend_mask
= ~signed_extend_mask
;
2156 value
= value
>> shift_steps
;
2157 value
|= signed_extend_mask
;
2159 inst_env
->reg
[REG_PC
] &= 0xFFFF0000;
2160 inst_env
->reg
[REG_PC
] |= value
;
2162 else if (cris_get_size (inst
) == INST_DWORD_SIZE
)
2164 if (value
& SIGNED_DWORD_MASK
)
2166 signed_extend_mask
= 0xFFFFFFFF;
2167 signed_extend_mask
= signed_extend_mask
>> shift_steps
;
2168 signed_extend_mask
= ~signed_extend_mask
;
2170 value
= value
>> shift_steps
;
2171 value
|= signed_extend_mask
;
2172 inst_env
->reg
[REG_PC
] = value
;
2175 inst_env
->slot_needed
= 0;
2176 inst_env
->prefix_found
= 0;
2177 inst_env
->xflag_found
= 0;
2178 inst_env
->disable_interrupt
= 0;
2181 /* Handles the ASRQ instruction. */
2184 asrq_op (unsigned short inst
, inst_env_type
*inst_env
)
2188 unsigned long value
;
2189 unsigned long signed_extend_mask
= 0;
2191 /* ASRQ can't have a prefix, so check that it doesn't. */
2192 if (inst_env
->prefix_found
)
2194 inst_env
->invalid
= 1;
2198 /* Check if the PC is the target register. */
2199 if (cris_get_operand2 (inst
) == REG_PC
)
2202 /* It's invalid to change the PC in a delay slot. */
2203 if (inst_env
->slot_needed
)
2205 inst_env
->invalid
= 1;
2208 /* The shift size is given as a 5 bit quick value, i.e. we don't
2209 want the the sign bit of the quick value. */
2210 shift_steps
= cris_get_asr_shift_steps (inst
);
2211 value
= inst_env
->reg
[REG_PC
];
2212 if (value
& SIGNED_DWORD_MASK
)
2214 signed_extend_mask
= 0xFFFFFFFF;
2215 signed_extend_mask
= signed_extend_mask
>> shift_steps
;
2216 signed_extend_mask
= ~signed_extend_mask
;
2218 value
= value
>> shift_steps
;
2219 value
|= signed_extend_mask
;
2220 inst_env
->reg
[REG_PC
] = value
;
2222 inst_env
->slot_needed
= 0;
2223 inst_env
->prefix_found
= 0;
2224 inst_env
->xflag_found
= 0;
2225 inst_env
->disable_interrupt
= 0;
2228 /* Handles the AX, EI and SETF instruction. */
2231 ax_ei_setf_op (unsigned short inst
, inst_env_type
*inst_env
)
2233 if (inst_env
->prefix_found
)
2235 inst_env
->invalid
= 1;
2238 /* Check if the instruction is setting the X flag. */
2239 if (cris_is_xflag_bit_on (inst
))
2241 inst_env
->xflag_found
= 1;
2245 inst_env
->xflag_found
= 0;
2247 inst_env
->slot_needed
= 0;
2248 inst_env
->prefix_found
= 0;
2249 inst_env
->disable_interrupt
= 1;
2252 /* Checks if the instruction is in assign mode. If so, it updates the assign
2253 register. Note that check_assign assumes that the caller has checked that
2254 there is a prefix to this instruction. The mode check depends on this. */
2257 check_assign (unsigned short inst
, inst_env_type
*inst_env
)
2259 /* Check if it's an assign addressing mode. */
2260 if (cris_get_mode (inst
) == PREFIX_ASSIGN_MODE
)
2262 /* Assign the prefix value to operand 1. */
2263 inst_env
->reg
[cris_get_operand1 (inst
)] = inst_env
->prefix_value
;
2267 /* Handles the 2-operand BOUND instruction. */
2270 two_operand_bound_op (unsigned short inst
, inst_env_type
*inst_env
)
2272 /* It's invalid to have the PC as the index operand. */
2273 if (cris_get_operand2 (inst
) == REG_PC
)
2275 inst_env
->invalid
= 1;
2278 /* Check if we have a prefix. */
2279 if (inst_env
->prefix_found
)
2281 check_assign (inst
, inst_env
);
2283 /* Check if this is an autoincrement mode. */
2284 else if (cris_get_mode (inst
) == AUTOINC_MODE
)
2286 /* It's invalid to change the PC in a delay slot. */
2287 if (inst_env
->slot_needed
)
2289 inst_env
->invalid
= 1;
2292 process_autoincrement (cris_get_size (inst
), inst
, inst_env
);
2294 inst_env
->slot_needed
= 0;
2295 inst_env
->prefix_found
= 0;
2296 inst_env
->xflag_found
= 0;
2297 inst_env
->disable_interrupt
= 0;
2300 /* Handles the 3-operand BOUND instruction. */
2303 three_operand_bound_op (unsigned short inst
, inst_env_type
*inst_env
)
2305 /* It's an error if we haven't got a prefix. And it's also an error
2306 if the PC is the destination register. */
2307 if ((!inst_env
->prefix_found
) || (cris_get_operand1 (inst
) == REG_PC
))
2309 inst_env
->invalid
= 1;
2312 inst_env
->slot_needed
= 0;
2313 inst_env
->prefix_found
= 0;
2314 inst_env
->xflag_found
= 0;
2315 inst_env
->disable_interrupt
= 0;
2318 /* Clears the status flags in inst_env. */
2321 btst_nop_op (unsigned short inst
, inst_env_type
*inst_env
)
2323 /* It's an error if we have got a prefix. */
2324 if (inst_env
->prefix_found
)
2326 inst_env
->invalid
= 1;
2330 inst_env
->slot_needed
= 0;
2331 inst_env
->prefix_found
= 0;
2332 inst_env
->xflag_found
= 0;
2333 inst_env
->disable_interrupt
= 0;
2336 /* Clears the status flags in inst_env. */
2339 clearf_di_op (unsigned short inst
, inst_env_type
*inst_env
)
2341 /* It's an error if we have got a prefix. */
2342 if (inst_env
->prefix_found
)
2344 inst_env
->invalid
= 1;
2348 inst_env
->slot_needed
= 0;
2349 inst_env
->prefix_found
= 0;
2350 inst_env
->xflag_found
= 0;
2351 inst_env
->disable_interrupt
= 1;
2354 /* Handles the CLEAR instruction if it's in register mode. */
2357 reg_mode_clear_op (unsigned short inst
, inst_env_type
*inst_env
)
2359 /* Check if the target is the PC. */
2360 if (cris_get_operand2 (inst
) == REG_PC
)
2362 /* The instruction will clear the instruction's size bits. */
2363 int clear_size
= cris_get_clear_size (inst
);
2364 if (clear_size
== INST_BYTE_SIZE
)
2366 inst_env
->delay_slot_pc
= inst_env
->reg
[REG_PC
] & 0xFFFFFF00;
2368 if (clear_size
== INST_WORD_SIZE
)
2370 inst_env
->delay_slot_pc
= inst_env
->reg
[REG_PC
] & 0xFFFF0000;
2372 if (clear_size
== INST_DWORD_SIZE
)
2374 inst_env
->delay_slot_pc
= 0x0;
2376 /* The jump will be delayed with one delay slot. So we need a delay
2378 inst_env
->slot_needed
= 1;
2379 inst_env
->delay_slot_pc_active
= 1;
2383 /* The PC will not change => no delay slot. */
2384 inst_env
->slot_needed
= 0;
2386 inst_env
->prefix_found
= 0;
2387 inst_env
->xflag_found
= 0;
2388 inst_env
->disable_interrupt
= 0;
2391 /* Handles the TEST instruction if it's in register mode. */
2394 reg_mode_test_op (unsigned short inst
, inst_env_type
*inst_env
)
2396 /* It's an error if we have got a prefix. */
2397 if (inst_env
->prefix_found
)
2399 inst_env
->invalid
= 1;
2402 inst_env
->slot_needed
= 0;
2403 inst_env
->prefix_found
= 0;
2404 inst_env
->xflag_found
= 0;
2405 inst_env
->disable_interrupt
= 0;
2409 /* Handles the CLEAR and TEST instruction if the instruction isn't
2410 in register mode. */
2413 none_reg_mode_clear_test_op (unsigned short inst
, inst_env_type
*inst_env
)
2415 /* Check if we are in a prefix mode. */
2416 if (inst_env
->prefix_found
)
2418 /* The only way the PC can change is if this instruction is in
2419 assign addressing mode. */
2420 check_assign (inst
, inst_env
);
2422 /* Indirect mode can't change the PC so just check if the mode is
2424 else if (cris_get_mode (inst
) == AUTOINC_MODE
)
2426 process_autoincrement (cris_get_size (inst
), inst
, inst_env
);
2428 inst_env
->slot_needed
= 0;
2429 inst_env
->prefix_found
= 0;
2430 inst_env
->xflag_found
= 0;
2431 inst_env
->disable_interrupt
= 0;
2434 /* Checks that the PC isn't the destination register or the instructions has
2438 dstep_logshift_mstep_neg_not_op (unsigned short inst
, inst_env_type
*inst_env
)
2440 /* It's invalid to have the PC as the destination. The instruction can't
2442 if ((cris_get_operand2 (inst
) == REG_PC
) || inst_env
->prefix_found
)
2444 inst_env
->invalid
= 1;
2448 inst_env
->slot_needed
= 0;
2449 inst_env
->prefix_found
= 0;
2450 inst_env
->xflag_found
= 0;
2451 inst_env
->disable_interrupt
= 0;
2454 /* Checks that the instruction doesn't have a prefix. */
2457 break_op (unsigned short inst
, inst_env_type
*inst_env
)
2459 /* The instruction can't have a prefix. */
2460 if (inst_env
->prefix_found
)
2462 inst_env
->invalid
= 1;
2466 inst_env
->slot_needed
= 0;
2467 inst_env
->prefix_found
= 0;
2468 inst_env
->xflag_found
= 0;
2469 inst_env
->disable_interrupt
= 1;
2472 /* Checks that the PC isn't the destination register and that the instruction
2473 doesn't have a prefix. */
2476 scc_op (unsigned short inst
, inst_env_type
*inst_env
)
2478 /* It's invalid to have the PC as the destination. The instruction can't
2480 if ((cris_get_operand2 (inst
) == REG_PC
) || inst_env
->prefix_found
)
2482 inst_env
->invalid
= 1;
2486 inst_env
->slot_needed
= 0;
2487 inst_env
->prefix_found
= 0;
2488 inst_env
->xflag_found
= 0;
2489 inst_env
->disable_interrupt
= 1;
2492 /* Handles the register mode JUMP instruction. */
2495 reg_mode_jump_op (unsigned short inst
, inst_env_type
*inst_env
)
2497 /* It's invalid to do a JUMP in a delay slot. The mode is register, so
2498 you can't have a prefix. */
2499 if ((inst_env
->slot_needed
) || (inst_env
->prefix_found
))
2501 inst_env
->invalid
= 1;
2505 /* Just change the PC. */
2506 inst_env
->reg
[REG_PC
] = inst_env
->reg
[cris_get_operand1 (inst
)];
2507 inst_env
->slot_needed
= 0;
2508 inst_env
->prefix_found
= 0;
2509 inst_env
->xflag_found
= 0;
2510 inst_env
->disable_interrupt
= 1;
2513 /* Handles the JUMP instruction for all modes except register. */
2515 void none_reg_mode_jump_op (unsigned short inst
, inst_env_type
*inst_env
)
2517 unsigned long newpc
;
2520 /* It's invalid to do a JUMP in a delay slot. */
2521 if (inst_env
->slot_needed
)
2523 inst_env
->invalid
= 1;
2527 /* Check if we have a prefix. */
2528 if (inst_env
->prefix_found
)
2530 check_assign (inst
, inst_env
);
2532 /* Get the new value for the the PC. */
2534 read_memory_unsigned_integer ((CORE_ADDR
) inst_env
->prefix_value
,
2539 /* Get the new value for the PC. */
2540 address
= (CORE_ADDR
) inst_env
->reg
[cris_get_operand1 (inst
)];
2541 newpc
= read_memory_unsigned_integer (address
, 4);
2543 /* Check if we should increment a register. */
2544 if (cris_get_mode (inst
) == AUTOINC_MODE
)
2546 inst_env
->reg
[cris_get_operand1 (inst
)] += 4;
2549 inst_env
->reg
[REG_PC
] = newpc
;
2551 inst_env
->slot_needed
= 0;
2552 inst_env
->prefix_found
= 0;
2553 inst_env
->xflag_found
= 0;
2554 inst_env
->disable_interrupt
= 1;
2557 /* Handles moves to special registers (aka P-register) for all modes. */
2560 move_to_preg_op (unsigned short inst
, inst_env_type
*inst_env
)
2562 if (inst_env
->prefix_found
)
2564 /* The instruction has a prefix that means we are only interested if
2565 the instruction is in assign mode. */
2566 if (cris_get_mode (inst
) == PREFIX_ASSIGN_MODE
)
2568 /* The prefix handles the problem if we are in a delay slot. */
2569 if (cris_get_operand1 (inst
) == REG_PC
)
2571 /* Just take care of the assign. */
2572 check_assign (inst
, inst_env
);
2576 else if (cris_get_mode (inst
) == AUTOINC_MODE
)
2578 /* The instruction doesn't have a prefix, the only case left that we
2579 are interested in is the autoincrement mode. */
2580 if (cris_get_operand1 (inst
) == REG_PC
)
2582 /* If the PC is to be incremented it's invalid to be in a
2584 if (inst_env
->slot_needed
)
2586 inst_env
->invalid
= 1;
2590 /* The increment depends on the size of the special register. */
2591 if (cris_register_size (cris_get_operand2 (inst
)) == 1)
2593 process_autoincrement (INST_BYTE_SIZE
, inst
, inst_env
);
2595 else if (cris_register_size (cris_get_operand2 (inst
)) == 2)
2597 process_autoincrement (INST_WORD_SIZE
, inst
, inst_env
);
2601 process_autoincrement (INST_DWORD_SIZE
, inst
, inst_env
);
2605 inst_env
->slot_needed
= 0;
2606 inst_env
->prefix_found
= 0;
2607 inst_env
->xflag_found
= 0;
2608 inst_env
->disable_interrupt
= 1;
2611 /* Handles moves from special registers (aka P-register) for all modes
2615 none_reg_mode_move_from_preg_op (unsigned short inst
, inst_env_type
*inst_env
)
2617 if (inst_env
->prefix_found
)
2619 /* The instruction has a prefix that means we are only interested if
2620 the instruction is in assign mode. */
2621 if (cris_get_mode (inst
) == PREFIX_ASSIGN_MODE
)
2623 /* The prefix handles the problem if we are in a delay slot. */
2624 if (cris_get_operand1 (inst
) == REG_PC
)
2626 /* Just take care of the assign. */
2627 check_assign (inst
, inst_env
);
2631 /* The instruction doesn't have a prefix, the only case left that we
2632 are interested in is the autoincrement mode. */
2633 else if (cris_get_mode (inst
) == AUTOINC_MODE
)
2635 if (cris_get_operand1 (inst
) == REG_PC
)
2637 /* If the PC is to be incremented it's invalid to be in a
2639 if (inst_env
->slot_needed
)
2641 inst_env
->invalid
= 1;
2645 /* The increment depends on the size of the special register. */
2646 if (cris_register_size (cris_get_operand2 (inst
)) == 1)
2648 process_autoincrement (INST_BYTE_SIZE
, inst
, inst_env
);
2650 else if (cris_register_size (cris_get_operand2 (inst
)) == 2)
2652 process_autoincrement (INST_WORD_SIZE
, inst
, inst_env
);
2656 process_autoincrement (INST_DWORD_SIZE
, inst
, inst_env
);
2660 inst_env
->slot_needed
= 0;
2661 inst_env
->prefix_found
= 0;
2662 inst_env
->xflag_found
= 0;
2663 inst_env
->disable_interrupt
= 1;
2666 /* Handles moves from special registers (aka P-register) when the mode
2670 reg_mode_move_from_preg_op (unsigned short inst
, inst_env_type
*inst_env
)
2672 /* Register mode move from special register can't have a prefix. */
2673 if (inst_env
->prefix_found
)
2675 inst_env
->invalid
= 1;
2679 if (cris_get_operand1 (inst
) == REG_PC
)
2681 /* It's invalid to change the PC in a delay slot. */
2682 if (inst_env
->slot_needed
)
2684 inst_env
->invalid
= 1;
2687 /* The destination is the PC, the jump will have a delay slot. */
2688 inst_env
->delay_slot_pc
= inst_env
->preg
[cris_get_operand2 (inst
)];
2689 inst_env
->slot_needed
= 1;
2690 inst_env
->delay_slot_pc_active
= 1;
2694 /* If the destination isn't PC, there will be no jump. */
2695 inst_env
->slot_needed
= 0;
2697 inst_env
->prefix_found
= 0;
2698 inst_env
->xflag_found
= 0;
2699 inst_env
->disable_interrupt
= 1;
2702 /* Handles the MOVEM from memory to general register instruction. */
2705 move_mem_to_reg_movem_op (unsigned short inst
, inst_env_type
*inst_env
)
2707 if (inst_env
->prefix_found
)
2709 /* The prefix handles the problem if we are in a delay slot. Is the
2710 MOVEM instruction going to change the PC? */
2711 if (cris_get_operand2 (inst
) >= REG_PC
)
2713 inst_env
->reg
[REG_PC
] =
2714 read_memory_unsigned_integer (inst_env
->prefix_value
, 4);
2716 /* The assign value is the value after the increment. Normally, the
2717 assign value is the value before the increment. */
2718 if ((cris_get_operand1 (inst
) == REG_PC
)
2719 && (cris_get_mode (inst
) == PREFIX_ASSIGN_MODE
))
2721 inst_env
->reg
[REG_PC
] = inst_env
->prefix_value
;
2722 inst_env
->reg
[REG_PC
] += 4 * (cris_get_operand2 (inst
) + 1);
2727 /* Is the MOVEM instruction going to change the PC? */
2728 if (cris_get_operand2 (inst
) == REG_PC
)
2730 /* It's invalid to change the PC in a delay slot. */
2731 if (inst_env
->slot_needed
)
2733 inst_env
->invalid
= 1;
2736 inst_env
->reg
[REG_PC
] =
2737 read_memory_unsigned_integer (inst_env
->reg
[cris_get_operand1 (inst
)],
2740 /* The increment is not depending on the size, instead it's depending
2741 on the number of registers loaded from memory. */
2742 if ((cris_get_operand1 (inst
) == REG_PC
) && (cris_get_mode (inst
) == AUTOINC_MODE
))
2744 /* It's invalid to change the PC in a delay slot. */
2745 if (inst_env
->slot_needed
)
2747 inst_env
->invalid
= 1;
2750 inst_env
->reg
[REG_PC
] += 4 * (cris_get_operand2 (inst
) + 1);
2753 inst_env
->slot_needed
= 0;
2754 inst_env
->prefix_found
= 0;
2755 inst_env
->xflag_found
= 0;
2756 inst_env
->disable_interrupt
= 0;
2759 /* Handles the MOVEM to memory from general register instruction. */
2762 move_reg_to_mem_movem_op (unsigned short inst
, inst_env_type
*inst_env
)
2764 if (inst_env
->prefix_found
)
2766 /* The assign value is the value after the increment. Normally, the
2767 assign value is the value before the increment. */
2768 if ((cris_get_operand1 (inst
) == REG_PC
) &&
2769 (cris_get_mode (inst
) == PREFIX_ASSIGN_MODE
))
2771 /* The prefix handles the problem if we are in a delay slot. */
2772 inst_env
->reg
[REG_PC
] = inst_env
->prefix_value
;
2773 inst_env
->reg
[REG_PC
] += 4 * (cris_get_operand2 (inst
) + 1);
2778 /* The increment is not depending on the size, instead it's depending
2779 on the number of registers loaded to memory. */
2780 if ((cris_get_operand1 (inst
) == REG_PC
) && (cris_get_mode (inst
) == AUTOINC_MODE
))
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
] += 4 * (cris_get_operand2 (inst
) + 1);
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 the pop instruction to a general register.
2798 POP is a assembler macro for MOVE.D [SP+], Rd. */
2801 reg_pop_op (unsigned short inst
, inst_env_type
*inst_env
)
2803 /* POP can't have a prefix. */
2804 if (inst_env
->prefix_found
)
2806 inst_env
->invalid
= 1;
2809 if (cris_get_operand2 (inst
) == REG_PC
)
2811 /* It's invalid to change the PC in a delay slot. */
2812 if (inst_env
->slot_needed
)
2814 inst_env
->invalid
= 1;
2817 inst_env
->reg
[REG_PC
] =
2818 read_memory_unsigned_integer (inst_env
->reg
[REG_SP
], 4);
2820 inst_env
->slot_needed
= 0;
2821 inst_env
->prefix_found
= 0;
2822 inst_env
->xflag_found
= 0;
2823 inst_env
->disable_interrupt
= 0;
2826 /* Handles moves from register to memory. */
2829 move_reg_to_mem_index_inc_op (unsigned short inst
, inst_env_type
*inst_env
)
2831 /* Check if we have a prefix. */
2832 if (inst_env
->prefix_found
)
2834 /* The only thing that can change the PC is an assign. */
2835 check_assign (inst
, inst_env
);
2837 else if ((cris_get_operand1 (inst
) == REG_PC
)
2838 && (cris_get_mode (inst
) == AUTOINC_MODE
))
2840 /* It's invalid to change the PC in a delay slot. */
2841 if (inst_env
->slot_needed
)
2843 inst_env
->invalid
= 1;
2846 process_autoincrement (cris_get_size (inst
), inst
, inst_env
);
2848 inst_env
->slot_needed
= 0;
2849 inst_env
->prefix_found
= 0;
2850 inst_env
->xflag_found
= 0;
2851 inst_env
->disable_interrupt
= 0;
2854 /* Handles the intructions that's not yet implemented, by setting
2855 inst_env->invalid to true. */
2858 not_implemented_op (unsigned short inst
, inst_env_type
*inst_env
)
2860 inst_env
->invalid
= 1;
2863 /* Handles the XOR instruction. */
2866 xor_op (unsigned short inst
, inst_env_type
*inst_env
)
2868 /* XOR can't have a prefix. */
2869 if (inst_env
->prefix_found
)
2871 inst_env
->invalid
= 1;
2875 /* Check if the PC is the target. */
2876 if (cris_get_operand2 (inst
) == REG_PC
)
2878 /* It's invalid to change the PC in a delay slot. */
2879 if (inst_env
->slot_needed
)
2881 inst_env
->invalid
= 1;
2884 inst_env
->reg
[REG_PC
] ^= inst_env
->reg
[cris_get_operand1 (inst
)];
2886 inst_env
->slot_needed
= 0;
2887 inst_env
->prefix_found
= 0;
2888 inst_env
->xflag_found
= 0;
2889 inst_env
->disable_interrupt
= 0;
2892 /* Handles the MULS instruction. */
2895 muls_op (unsigned short inst
, inst_env_type
*inst_env
)
2897 /* MULS/U can't have a prefix. */
2898 if (inst_env
->prefix_found
)
2900 inst_env
->invalid
= 1;
2904 /* Consider it invalid if the PC is the target. */
2905 if (cris_get_operand2 (inst
) == REG_PC
)
2907 inst_env
->invalid
= 1;
2910 inst_env
->slot_needed
= 0;
2911 inst_env
->prefix_found
= 0;
2912 inst_env
->xflag_found
= 0;
2913 inst_env
->disable_interrupt
= 0;
2916 /* Handles the MULU instruction. */
2919 mulu_op (unsigned short inst
, inst_env_type
*inst_env
)
2921 /* MULS/U can't have a prefix. */
2922 if (inst_env
->prefix_found
)
2924 inst_env
->invalid
= 1;
2928 /* Consider it invalid if the PC is the target. */
2929 if (cris_get_operand2 (inst
) == REG_PC
)
2931 inst_env
->invalid
= 1;
2934 inst_env
->slot_needed
= 0;
2935 inst_env
->prefix_found
= 0;
2936 inst_env
->xflag_found
= 0;
2937 inst_env
->disable_interrupt
= 0;
2940 /* Calculate the result of the instruction for ADD, SUB, CMP AND, OR and MOVE.
2941 The MOVE instruction is the move from source to register. */
2944 add_sub_cmp_and_or_move_action (unsigned short inst
, inst_env_type
*inst_env
,
2945 unsigned long source1
, unsigned long source2
)
2947 unsigned long pc_mask
;
2948 unsigned long operation_mask
;
2950 /* Find out how many bits the operation should apply to. */
2951 if (cris_get_size (inst
) == INST_BYTE_SIZE
)
2953 pc_mask
= 0xFFFFFF00;
2954 operation_mask
= 0xFF;
2956 else if (cris_get_size (inst
) == INST_WORD_SIZE
)
2958 pc_mask
= 0xFFFF0000;
2959 operation_mask
= 0xFFFF;
2961 else if (cris_get_size (inst
) == INST_DWORD_SIZE
)
2964 operation_mask
= 0xFFFFFFFF;
2968 /* The size is out of range. */
2969 inst_env
->invalid
= 1;
2973 /* The instruction just works on uw_operation_mask bits. */
2974 source2
&= operation_mask
;
2975 source1
&= operation_mask
;
2977 /* Now calculate the result. The opcode's 3 first bits separates
2978 the different actions. */
2979 switch (cris_get_opcode (inst
) & 7)
2989 case 2: /* subtract */
2993 case 3: /* compare */
3005 inst_env
->invalid
= 1;
3011 /* Make sure that the result doesn't contain more than the instruction
3013 source2
&= operation_mask
;
3015 /* Calculate the new breakpoint address. */
3016 inst_env
->reg
[REG_PC
] &= pc_mask
;
3017 inst_env
->reg
[REG_PC
] |= source1
;
3021 /* Extends the value from either byte or word size to a dword. If the mode
3022 is zero extend then the value is extended with zero. If instead the mode
3023 is signed extend the sign bit of the value is taken into consideration. */
3026 do_sign_or_zero_extend (unsigned long value
, unsigned short *inst
)
3028 /* The size can be either byte or word, check which one it is.
3029 Don't check the highest bit, it's indicating if it's a zero
3031 if (cris_get_size (*inst
) & INST_WORD_SIZE
)
3036 /* Check if the instruction is signed extend. If so, check if value has
3038 if (cris_is_signed_extend_bit_on (*inst
) && (value
& SIGNED_WORD_MASK
))
3040 value
|= SIGNED_WORD_EXTEND_MASK
;
3048 /* Check if the instruction is signed extend. If so, check if value has
3050 if (cris_is_signed_extend_bit_on (*inst
) && (value
& SIGNED_BYTE_MASK
))
3052 value
|= SIGNED_BYTE_EXTEND_MASK
;
3055 /* The size should now be dword. */
3056 cris_set_size_to_dword (inst
);
3060 /* Handles the register mode for the ADD, SUB, CMP, AND, OR and MOVE
3061 instruction. The MOVE instruction is the move from source to register. */
3064 reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst
,
3065 inst_env_type
*inst_env
)
3067 unsigned long operand1
;
3068 unsigned long operand2
;
3070 /* It's invalid to have a prefix to the instruction. This is a register
3071 mode instruction and can't have a prefix. */
3072 if (inst_env
->prefix_found
)
3074 inst_env
->invalid
= 1;
3077 /* Check if the instruction has PC as its target. */
3078 if (cris_get_operand2 (inst
) == REG_PC
)
3080 if (inst_env
->slot_needed
)
3082 inst_env
->invalid
= 1;
3085 /* The instruction has the PC as its target register. */
3086 operand1
= inst_env
->reg
[cris_get_operand1 (inst
)];
3087 operand2
= inst_env
->reg
[REG_PC
];
3089 /* Check if it's a extend, signed or zero instruction. */
3090 if (cris_get_opcode (inst
) < 4)
3092 operand1
= do_sign_or_zero_extend (operand1
, &inst
);
3094 /* Calculate the PC value after the instruction, i.e. where the
3095 breakpoint should be. The order of the udw_operands is vital. */
3096 add_sub_cmp_and_or_move_action (inst
, inst_env
, operand2
, operand1
);
3098 inst_env
->slot_needed
= 0;
3099 inst_env
->prefix_found
= 0;
3100 inst_env
->xflag_found
= 0;
3101 inst_env
->disable_interrupt
= 0;
3104 /* Returns the data contained at address. The size of the data is derived from
3105 the size of the operation. If the instruction is a zero or signed
3106 extend instruction, the size field is changed in instruction. */
3109 get_data_from_address (unsigned short *inst
, CORE_ADDR address
)
3111 int size
= cris_get_size (*inst
);
3112 unsigned long value
;
3114 /* If it's an extend instruction we don't want the signed extend bit,
3115 because it influences the size. */
3116 if (cris_get_opcode (*inst
) < 4)
3118 size
&= ~SIGNED_EXTEND_BIT_MASK
;
3120 /* Is there a need for checking the size? Size should contain the number of
3123 value
= read_memory_unsigned_integer (address
, size
);
3125 /* Check if it's an extend, signed or zero instruction. */
3126 if (cris_get_opcode (*inst
) < 4)
3128 value
= do_sign_or_zero_extend (value
, inst
);
3133 /* Handles the assign addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
3134 instructions. The MOVE instruction is the move from source to register. */
3137 handle_prefix_assign_mode_for_aritm_op (unsigned short inst
,
3138 inst_env_type
*inst_env
)
3140 unsigned long operand2
;
3141 unsigned long operand3
;
3143 check_assign (inst
, inst_env
);
3144 if (cris_get_operand2 (inst
) == REG_PC
)
3146 operand2
= inst_env
->reg
[REG_PC
];
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. The order of the udw_operands is vital. */
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 three-operand addressing mode for the ADD, SUB, CMP, AND and
3162 OR instructions. Note that for this to work as expected, the calling
3163 function must have made sure that there is a prefix to this instruction. */
3166 three_operand_add_sub_cmp_and_or_op (unsigned short inst
,
3167 inst_env_type
*inst_env
)
3169 unsigned long operand2
;
3170 unsigned long operand3
;
3172 if (cris_get_operand1 (inst
) == REG_PC
)
3174 /* The PC will be changed by the instruction. */
3175 operand2
= inst_env
->reg
[cris_get_operand2 (inst
)];
3177 /* Get the value of the third operand. */
3178 operand3
= get_data_from_address (&inst
, inst_env
->prefix_value
);
3180 /* Calculate the PC value after the instruction, i.e. where the
3181 breakpoint should be. */
3182 add_sub_cmp_and_or_move_action (inst
, inst_env
, operand2
, operand3
);
3184 inst_env
->slot_needed
= 0;
3185 inst_env
->prefix_found
= 0;
3186 inst_env
->xflag_found
= 0;
3187 inst_env
->disable_interrupt
= 0;
3190 /* Handles the index addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
3191 instructions. The MOVE instruction is the move from source to register. */
3194 handle_prefix_index_mode_for_aritm_op (unsigned short inst
,
3195 inst_env_type
*inst_env
)
3197 if (cris_get_operand1 (inst
) != cris_get_operand2 (inst
))
3199 /* If the instruction is MOVE it's invalid. If the instruction is ADD,
3200 SUB, AND or OR something weird is going on (if everything works these
3201 instructions should end up in the three operand version). */
3202 inst_env
->invalid
= 1;
3207 /* three_operand_add_sub_cmp_and_or does the same as we should do here
3209 three_operand_add_sub_cmp_and_or_op (inst
, inst_env
);
3211 inst_env
->slot_needed
= 0;
3212 inst_env
->prefix_found
= 0;
3213 inst_env
->xflag_found
= 0;
3214 inst_env
->disable_interrupt
= 0;
3217 /* Handles the autoincrement and indirect addresing mode for the ADD, SUB,
3218 CMP, AND OR and MOVE instruction. The MOVE instruction is the move from
3219 source to register. */
3222 handle_inc_and_index_mode_for_aritm_op (unsigned short inst
,
3223 inst_env_type
*inst_env
)
3225 unsigned long operand1
;
3226 unsigned long operand2
;
3227 unsigned long operand3
;
3230 /* The instruction is either an indirect or autoincrement addressing mode.
3231 Check if the destination register is the PC. */
3232 if (cris_get_operand2 (inst
) == REG_PC
)
3234 /* Must be done here, get_data_from_address may change the size
3236 size
= cris_get_size (inst
);
3237 operand2
= inst_env
->reg
[REG_PC
];
3239 /* Get the value of the third operand, i.e. the indirect operand. */
3240 operand1
= inst_env
->reg
[cris_get_operand1 (inst
)];
3241 operand3
= get_data_from_address (&inst
, operand1
);
3243 /* Calculate the PC value after the instruction, i.e. where the
3244 breakpoint should be. The order of the udw_operands is vital. */
3245 add_sub_cmp_and_or_move_action (inst
, inst_env
, operand2
, operand3
);
3247 /* If this is an autoincrement addressing mode, check if the increment
3249 if ((cris_get_operand1 (inst
) == REG_PC
) && (cris_get_mode (inst
) == AUTOINC_MODE
))
3251 /* Get the size field. */
3252 size
= cris_get_size (inst
);
3254 /* If it's an extend instruction we don't want the signed extend bit,
3255 because it influences the size. */
3256 if (cris_get_opcode (inst
) < 4)
3258 size
&= ~SIGNED_EXTEND_BIT_MASK
;
3260 process_autoincrement (size
, inst
, inst_env
);
3262 inst_env
->slot_needed
= 0;
3263 inst_env
->prefix_found
= 0;
3264 inst_env
->xflag_found
= 0;
3265 inst_env
->disable_interrupt
= 0;
3268 /* Handles the two-operand addressing mode, all modes except register, for
3269 the ADD, SUB CMP, AND and OR instruction. */
3272 none_reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst
,
3273 inst_env_type
*inst_env
)
3275 if (inst_env
->prefix_found
)
3277 if (cris_get_mode (inst
) == PREFIX_INDEX_MODE
)
3279 handle_prefix_index_mode_for_aritm_op (inst
, inst_env
);
3281 else if (cris_get_mode (inst
) == PREFIX_ASSIGN_MODE
)
3283 handle_prefix_assign_mode_for_aritm_op (inst
, inst_env
);
3287 /* The mode is invalid for a prefixed base instruction. */
3288 inst_env
->invalid
= 1;
3294 handle_inc_and_index_mode_for_aritm_op (inst
, inst_env
);
3298 /* Handles the quick addressing mode for the ADD and SUB instruction. */
3301 quick_mode_add_sub_op (unsigned short inst
, inst_env_type
*inst_env
)
3303 unsigned long operand1
;
3304 unsigned long operand2
;
3306 /* It's a bad idea to be in a prefix instruction now. This is a quick mode
3307 instruction and can't have a prefix. */
3308 if (inst_env
->prefix_found
)
3310 inst_env
->invalid
= 1;
3314 /* Check if the instruction has PC as its target. */
3315 if (cris_get_operand2 (inst
) == REG_PC
)
3317 if (inst_env
->slot_needed
)
3319 inst_env
->invalid
= 1;
3322 operand1
= cris_get_quick_value (inst
);
3323 operand2
= inst_env
->reg
[REG_PC
];
3325 /* The size should now be dword. */
3326 cris_set_size_to_dword (&inst
);
3328 /* Calculate the PC value after the instruction, i.e. where the
3329 breakpoint should be. */
3330 add_sub_cmp_and_or_move_action (inst
, inst_env
, operand2
, operand1
);
3332 inst_env
->slot_needed
= 0;
3333 inst_env
->prefix_found
= 0;
3334 inst_env
->xflag_found
= 0;
3335 inst_env
->disable_interrupt
= 0;
3338 /* Handles the quick addressing mode for the CMP, AND and OR instruction. */
3341 quick_mode_and_cmp_move_or_op (unsigned short inst
, inst_env_type
*inst_env
)
3343 unsigned long operand1
;
3344 unsigned long operand2
;
3346 /* It's a bad idea to be in a prefix instruction now. This is a quick mode
3347 instruction and can't have a prefix. */
3348 if (inst_env
->prefix_found
)
3350 inst_env
->invalid
= 1;
3353 /* Check if the instruction has PC as its target. */
3354 if (cris_get_operand2 (inst
) == REG_PC
)
3356 if (inst_env
->slot_needed
)
3358 inst_env
->invalid
= 1;
3361 /* The instruction has the PC as its target register. */
3362 operand1
= cris_get_quick_value (inst
);
3363 operand2
= inst_env
->reg
[REG_PC
];
3365 /* The quick value is signed, so check if we must do a signed extend. */
3366 if (operand1
& SIGNED_QUICK_VALUE_MASK
)
3369 operand1
|= SIGNED_QUICK_VALUE_EXTEND_MASK
;
3371 /* The size should now be dword. */
3372 cris_set_size_to_dword (&inst
);
3374 /* Calculate the PC value after the instruction, i.e. where the
3375 breakpoint should be. */
3376 add_sub_cmp_and_or_move_action (inst
, inst_env
, operand2
, operand1
);
3378 inst_env
->slot_needed
= 0;
3379 inst_env
->prefix_found
= 0;
3380 inst_env
->xflag_found
= 0;
3381 inst_env
->disable_interrupt
= 0;
3384 /* Translate op_type to a function and call it. */
3386 static void cris_gdb_func (enum cris_op_type op_type
, unsigned short inst
,
3387 inst_env_type
*inst_env
)
3391 case cris_not_implemented_op
:
3392 not_implemented_op (inst
, inst_env
);
3396 abs_op (inst
, inst_env
);
3400 addi_op (inst
, inst_env
);
3404 asr_op (inst
, inst_env
);
3408 asrq_op (inst
, inst_env
);
3411 case cris_ax_ei_setf_op
:
3412 ax_ei_setf_op (inst
, inst_env
);
3415 case cris_bdap_prefix
:
3416 bdap_prefix (inst
, inst_env
);
3419 case cris_biap_prefix
:
3420 biap_prefix (inst
, inst_env
);
3424 break_op (inst
, inst_env
);
3427 case cris_btst_nop_op
:
3428 btst_nop_op (inst
, inst_env
);
3431 case cris_clearf_di_op
:
3432 clearf_di_op (inst
, inst_env
);
3435 case cris_dip_prefix
:
3436 dip_prefix (inst
, inst_env
);
3439 case cris_dstep_logshift_mstep_neg_not_op
:
3440 dstep_logshift_mstep_neg_not_op (inst
, inst_env
);
3443 case cris_eight_bit_offset_branch_op
:
3444 eight_bit_offset_branch_op (inst
, inst_env
);
3447 case cris_move_mem_to_reg_movem_op
:
3448 move_mem_to_reg_movem_op (inst
, inst_env
);
3451 case cris_move_reg_to_mem_movem_op
:
3452 move_reg_to_mem_movem_op (inst
, inst_env
);
3455 case cris_move_to_preg_op
:
3456 move_to_preg_op (inst
, inst_env
);
3460 muls_op (inst
, inst_env
);
3464 mulu_op (inst
, inst_env
);
3467 case cris_none_reg_mode_add_sub_cmp_and_or_move_op
:
3468 none_reg_mode_add_sub_cmp_and_or_move_op (inst
, inst_env
);
3471 case cris_none_reg_mode_clear_test_op
:
3472 none_reg_mode_clear_test_op (inst
, inst_env
);
3475 case cris_none_reg_mode_jump_op
:
3476 none_reg_mode_jump_op (inst
, inst_env
);
3479 case cris_none_reg_mode_move_from_preg_op
:
3480 none_reg_mode_move_from_preg_op (inst
, inst_env
);
3483 case cris_quick_mode_add_sub_op
:
3484 quick_mode_add_sub_op (inst
, inst_env
);
3487 case cris_quick_mode_and_cmp_move_or_op
:
3488 quick_mode_and_cmp_move_or_op (inst
, inst_env
);
3491 case cris_quick_mode_bdap_prefix
:
3492 quick_mode_bdap_prefix (inst
, inst_env
);
3495 case cris_reg_mode_add_sub_cmp_and_or_move_op
:
3496 reg_mode_add_sub_cmp_and_or_move_op (inst
, inst_env
);
3499 case cris_reg_mode_clear_op
:
3500 reg_mode_clear_op (inst
, inst_env
);
3503 case cris_reg_mode_jump_op
:
3504 reg_mode_jump_op (inst
, inst_env
);
3507 case cris_reg_mode_move_from_preg_op
:
3508 reg_mode_move_from_preg_op (inst
, inst_env
);
3511 case cris_reg_mode_test_op
:
3512 reg_mode_test_op (inst
, inst_env
);
3516 scc_op (inst
, inst_env
);
3519 case cris_sixteen_bit_offset_branch_op
:
3520 sixteen_bit_offset_branch_op (inst
, inst_env
);
3523 case cris_three_operand_add_sub_cmp_and_or_op
:
3524 three_operand_add_sub_cmp_and_or_op (inst
, inst_env
);
3527 case cris_three_operand_bound_op
:
3528 three_operand_bound_op (inst
, inst_env
);
3531 case cris_two_operand_bound_op
:
3532 two_operand_bound_op (inst
, inst_env
);
3536 xor_op (inst
, inst_env
);
3541 /* This wrapper is to avoid cris_get_assembler being called before
3542 exec_bfd has been set. */
3545 cris_delayed_get_disassembler (bfd_vma addr
, disassemble_info
*info
)
3547 tm_print_insn
= cris_get_disassembler (exec_bfd
);
3548 return TARGET_PRINT_INSN (addr
, info
);
3551 /* Copied from <asm/elf.h>. */
3552 typedef unsigned long elf_greg_t
;
3554 /* Same as user_regs_struct struct in <asm/user.h>. */
3555 typedef elf_greg_t elf_gregset_t
[35];
3557 /* Unpack an elf_gregset_t into GDB's register cache. */
3560 supply_gregset (elf_gregset_t
*gregsetp
)
3563 elf_greg_t
*regp
= *gregsetp
;
3564 static char zerobuf
[4] = {0};
3566 /* The kernel dumps all 32 registers as unsigned longs, but supply_register
3567 knows about the actual size of each register so that's no problem. */
3568 for (i
= 0; i
< NUM_GENREGS
+ NUM_SPECREGS
; i
++)
3570 supply_register (i
, (char *)®p
[i
]);
3574 /* Use a local version of this function to get the correct types for
3575 regsets, until multi-arch core support is ready. */
3578 fetch_core_registers (char *core_reg_sect
, unsigned core_reg_size
,
3579 int which
, CORE_ADDR reg_addr
)
3581 elf_gregset_t gregset
;
3586 if (core_reg_size
!= sizeof (gregset
))
3588 warning ("wrong size gregset struct in core file");
3592 memcpy (&gregset
, core_reg_sect
, sizeof (gregset
));
3593 supply_gregset (&gregset
);
3597 /* We've covered all the kinds of registers we know about here,
3598 so this must be something we wouldn't know what to do with
3599 anyway. Just ignore it. */
3604 static struct core_fns cris_elf_core_fns
=
3606 bfd_target_elf_flavour
, /* core_flavour */
3607 default_check_format
, /* check_format */
3608 default_core_sniffer
, /* core_sniffer */
3609 fetch_core_registers
, /* core_read_registers */
3613 /* Fetch (and possibly build) an appropriate link_map_offsets
3614 structure for native GNU/Linux CRIS targets using the struct
3615 offsets defined in link.h (but without actual reference to that
3618 This makes it possible to access GNU/Linux CRIS shared libraries
3619 from a GDB that was not built on an GNU/Linux CRIS host (for cross
3622 See gdb/solib-svr4.h for an explanation of these fields. */
3624 struct link_map_offsets
*
3625 cris_linux_svr4_fetch_link_map_offsets (void)
3627 static struct link_map_offsets lmo
;
3628 static struct link_map_offsets
*lmp
= NULL
;
3634 lmo
.r_debug_size
= 8; /* The actual size is 20 bytes, but
3635 this is all we need. */
3636 lmo
.r_map_offset
= 4;
3639 lmo
.link_map_size
= 20;
3641 lmo
.l_addr_offset
= 0;
3642 lmo
.l_addr_size
= 4;
3644 lmo
.l_name_offset
= 4;
3645 lmo
.l_name_size
= 4;
3647 lmo
.l_next_offset
= 12;
3648 lmo
.l_next_size
= 4;
3650 lmo
.l_prev_offset
= 16;
3651 lmo
.l_prev_size
= 4;
3658 cris_fpless_backtrace (char *noargs
, int from_tty
)
3660 /* Points at the instruction after the jsr (except when in innermost frame
3661 where it points at the original pc). */
3664 /* Temporary variable, used for parsing from the start of the function that
3665 the pc is in, up to the pc. */
3666 CORE_ADDR tmp_pc
= 0;
3669 /* Information about current frame. */
3670 struct symtab_and_line sal
;
3673 /* Present instruction. */
3674 unsigned short insn
;
3676 /* Next instruction, lookahead. */
3677 unsigned short insn_next
;
3679 /* This is to store the offset between sp at start of function and until we
3680 reach push srp (if any). */
3681 int sp_add_later
= 0;
3682 int push_srp_found
= 0;
3686 /* Frame counter. */
3689 /* For the innermost frame, we want to look at srp in case it's a leaf
3690 function (since there's no push srp in that case). */
3691 int innermost_frame
= 1;
3693 deprecated_read_register_gen (PC_REGNUM
, (char *) &pc
);
3694 deprecated_read_register_gen (SP_REGNUM
, (char *) &sp
);
3696 /* We make an explicit return when we can't find an outer frame. */
3699 /* Get file name and line number. */
3700 sal
= find_pc_line (pc
, 0);
3702 /* Get function name. */
3703 find_pc_partial_function (pc
, &func_name
, (CORE_ADDR
*) NULL
,
3704 (CORE_ADDR
*) NULL
);
3706 /* Print information about current frame. */
3707 printf_unfiltered ("#%i 0x%08lx in %s", frame
++, pc
, func_name
);
3710 printf_unfiltered (" at %s:%i", sal
.symtab
->filename
, sal
.line
);
3712 printf_unfiltered ("\n");
3714 /* Get the start address of this function. */
3715 tmp_pc
= get_pc_function_start (pc
);
3717 /* Mini parser, only meant to find push sp and sub ...,sp from the start
3718 of the function, up to the pc. */
3721 insn
= read_memory_unsigned_integer (tmp_pc
, sizeof (short));
3722 tmp_pc
+= sizeof (short);
3725 /* push <reg> 32 bit instruction */
3726 insn_next
= read_memory_unsigned_integer (tmp_pc
,
3728 tmp_pc
+= sizeof (short);
3730 /* Recognize srp. */
3731 if (insn_next
== 0xBE7E)
3733 /* For subsequent (not this one though) push or sub which
3734 affects sp, adjust sp immediately. */
3737 /* Note: this will break if we ever encounter a
3738 push vr (1 byte) or push ccr (2 bytes). */
3743 /* Some other register was pushed. */
3754 else if (cris_get_operand2 (insn
) == SP_REGNUM
3755 && cris_get_mode (insn
) == 0x0000
3756 && cris_get_opcode (insn
) == 0x000A)
3759 val
= cris_get_quick_value (insn
);
3767 sp_add_later
+= val
;
3771 else if (cris_get_operand2 (insn
) == SP_REGNUM
3772 /* Autoincrement addressing mode. */
3773 && cris_get_mode (insn
) == 0x0003
3775 && ((insn
) & 0x03E0) >> 5 == 0x0004)
3778 val
= get_data_from_address (&insn
, tmp_pc
);
3786 sp_add_later
+= val
;
3789 else if (cris_get_operand2 (insn
) == SP_REGNUM
3790 && ((insn
& 0x0F00) >> 8) == 0x0001
3791 && (cris_get_signed_offset (insn
) < 0))
3793 /* Immediate byte offset addressing prefix word with sp as base
3794 register. Used for CRIS v8 i.e. ETRAX 100 and newer if <val>
3795 is between 64 and 128.
3796 movem r<regsave>,[sp=sp-<val>] */
3797 val
= -cris_get_signed_offset (insn
);
3798 insn_next
= read_memory_unsigned_integer (tmp_pc
,
3800 tmp_pc
+= sizeof (short);
3802 if (cris_get_mode (insn_next
) == PREFIX_ASSIGN_MODE
3803 && cris_get_opcode (insn_next
) == 0x000F
3804 && cris_get_size (insn_next
) == 0x0003
3805 && cris_get_operand1 (insn_next
) == SP_REGNUM
)
3813 sp_add_later
+= val
;
3824 /* sp should now point at where srp is stored on the stack. Update
3825 the pc to the srp. */
3826 pc
= read_memory_unsigned_integer (sp
, 4);
3828 else if (innermost_frame
)
3830 /* We couldn't find a push srp in the prologue, so this must be
3831 a leaf function, and thus we use the srp register directly.
3832 This should happen at most once, for the innermost function. */
3833 deprecated_read_register_gen (SRP_REGNUM
, (char *) &pc
);
3837 /* Couldn't find an outer frame. */
3841 /* Reset flag. (In case the innermost frame wasn't a leaf, we don't
3842 want to look at the srp register later either). */
3843 innermost_frame
= 0;
3845 /* Now, add the offset for everything up to, and including push srp,
3846 that was held back during the prologue parsing. */
3853 _initialize_cris_tdep (void)
3855 struct cmd_list_element
*c
;
3857 gdbarch_register (bfd_arch_cris
, cris_gdbarch_init
, cris_dump_tdep
);
3859 /* Used in disassembly. */
3860 tm_print_insn
= cris_delayed_get_disassembler
;
3862 /* CRIS-specific user-commands. */
3863 c
= add_set_cmd ("cris-version", class_support
, var_integer
,
3864 (char *) &usr_cmd_cris_version
,
3865 "Set the current CRIS version.", &setlist
);
3866 set_cmd_sfunc (c
, cris_version_update
);
3867 add_show_from_set (c
, &showlist
);
3869 c
= add_set_enum_cmd ("cris-mode", class_support
, cris_mode_enums
,
3871 "Set the current CRIS mode.", &setlist
);
3872 set_cmd_sfunc (c
, cris_mode_update
);
3873 add_show_from_set (c
, &showlist
);
3875 c
= add_set_enum_cmd ("cris-abi", class_support
, cris_abi_enums
,
3877 "Set the current CRIS ABI version.", &setlist
);
3878 set_cmd_sfunc (c
, cris_abi_update
);
3879 add_show_from_set (c
, &showlist
);
3881 c
= add_cmd ("cris-fpless-backtrace", class_support
, cris_fpless_backtrace
,
3882 "Display call chain using the subroutine return pointer.\n"
3883 "Note that this displays the address after the jump to the "
3884 "subroutine.", &cmdlist
);
3886 add_core_fns (&cris_elf_core_fns
);
3890 /* Prints out all target specific values. */
3893 cris_dump_tdep (struct gdbarch
*gdbarch
, struct ui_file
*file
)
3895 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
3898 fprintf_unfiltered (file
, "cris_dump_tdep: tdep->cris_version = %i\n",
3899 tdep
->cris_version
);
3900 fprintf_unfiltered (file
, "cris_dump_tdep: tdep->cris_mode = %s\n",
3902 fprintf_unfiltered (file
, "cris_dump_tdep: tdep->cris_abi = %s\n",
3909 cris_version_update (char *ignore_args
, int from_tty
,
3910 struct cmd_list_element
*c
)
3912 struct gdbarch_info info
;
3914 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
3915 the set command passed as a parameter. The clone operation will
3916 include (BUG?) any ``set'' command callback, if present.
3917 Commands like ``info set'' call all the ``show'' command
3918 callbacks. Unfortunatly, for ``show'' commands cloned from
3919 ``set'', this includes callbacks belonging to ``set'' commands.
3920 Making this worse, this only occures if add_show_from_set() is
3921 called after add_cmd_sfunc() (BUG?). */
3923 /* From here on, trust the user's CRIS version setting. */
3924 if (cmd_type (c
) == set_cmd
)
3926 usr_cmd_cris_version_valid
= 1;
3928 /* Update the current architecture, if needed. */
3929 gdbarch_info_init (&info
);
3930 if (!gdbarch_update_p (info
))
3931 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_update: failed to update architecture.");
3936 cris_mode_update (char *ignore_args
, int from_tty
,
3937 struct cmd_list_element
*c
)
3939 struct gdbarch_info info
;
3941 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
3942 the set command passed as a parameter. The clone operation will
3943 include (BUG?) any ``set'' command callback, if present.
3944 Commands like ``info set'' call all the ``show'' command
3945 callbacks. Unfortunatly, for ``show'' commands cloned from
3946 ``set'', this includes callbacks belonging to ``set'' commands.
3947 Making this worse, this only occures if add_show_from_set() is
3948 called after add_cmd_sfunc() (BUG?). */
3950 /* From here on, trust the user's CRIS mode setting. */
3951 if (cmd_type (c
) == set_cmd
)
3953 usr_cmd_cris_mode_valid
= 1;
3955 /* Update the current architecture, if needed. */
3956 gdbarch_info_init (&info
);
3957 if (!gdbarch_update_p (info
))
3958 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_update: failed to update architecture.");
3963 cris_abi_update (char *ignore_args
, int from_tty
,
3964 struct cmd_list_element
*c
)
3966 struct gdbarch_info info
;
3968 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
3969 the set command passed as a parameter. The clone operation will
3970 include (BUG?) any ``set'' command callback, if present.
3971 Commands like ``info set'' call all the ``show'' command
3972 callbacks. Unfortunatly, for ``show'' commands cloned from
3973 ``set'', this includes callbacks belonging to ``set'' commands.
3974 Making this worse, this only occures if add_show_from_set() is
3975 called after add_cmd_sfunc() (BUG?). */
3977 /* From here on, trust the user's CRIS ABI setting. */
3978 if (cmd_type (c
) == set_cmd
)
3980 usr_cmd_cris_abi_valid
= 1;
3982 /* Update the current architecture, if needed. */
3983 gdbarch_info_init (&info
);
3984 if (!gdbarch_update_p (info
))
3985 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_update: failed to update architecture.");
3989 /* Copied from pa64solib.c, with a couple of minor changes. */
3992 bfd_lookup_symbol (bfd
*abfd
, const char *symname
)
3994 unsigned int storage_needed
;
3996 asymbol
**symbol_table
;
3997 unsigned int number_of_symbols
;
3999 struct cleanup
*back_to
;
4000 CORE_ADDR symaddr
= 0;
4002 storage_needed
= bfd_get_symtab_upper_bound (abfd
);
4004 if (storage_needed
> 0)
4006 symbol_table
= (asymbol
**) xmalloc (storage_needed
);
4007 back_to
= make_cleanup (free
, (PTR
) symbol_table
);
4008 number_of_symbols
= bfd_canonicalize_symtab (abfd
, symbol_table
);
4010 for (i
= 0; i
< number_of_symbols
; i
++)
4012 sym
= *symbol_table
++;
4013 if (!strcmp (sym
->name
, symname
))
4015 /* Bfd symbols are section relative. */
4016 symaddr
= sym
->value
+ sym
->section
->vma
;
4020 do_cleanups (back_to
);
4025 static struct gdbarch
*
4026 cris_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
4028 struct gdbarch
*gdbarch
;
4029 struct gdbarch_tdep
*tdep
;
4031 const char *cris_mode
;
4032 const char *cris_abi
;
4033 CORE_ADDR cris_abi_sym
= 0;
4036 if (usr_cmd_cris_version_valid
)
4038 /* Trust the user's CRIS version setting. */
4039 cris_version
= usr_cmd_cris_version
;
4043 /* Assume it's CRIS version 10. */
4047 if (usr_cmd_cris_mode_valid
)
4049 /* Trust the user's CRIS mode setting. */
4050 cris_mode
= usr_cmd_cris_mode
;
4052 else if (cris_version
== 10)
4054 /* Assume CRIS version 10 is in user mode. */
4055 cris_mode
= CRIS_MODE_USER
;
4059 /* Strictly speaking, older CRIS version don't have a supervisor mode,
4060 but we regard its only mode as supervisor mode. */
4061 cris_mode
= CRIS_MODE_SUPERVISOR
;
4064 if (usr_cmd_cris_abi_valid
)
4066 /* Trust the user's ABI setting. */
4067 cris_abi
= usr_cmd_cris_abi
;
4071 if (bfd_get_flavour (info
.abfd
) == bfd_target_elf_flavour
)
4073 /* An elf target uses the new ABI. */
4074 cris_abi
= CRIS_ABI_V2
;
4076 else if (bfd_get_flavour (info
.abfd
) == bfd_target_aout_flavour
)
4078 /* An a.out target may use either ABI. Look for hints in the
4080 cris_abi_sym
= bfd_lookup_symbol (info
.abfd
, CRIS_ABI_SYMBOL
);
4081 cris_abi
= cris_abi_sym
? CRIS_ABI_V2
: CRIS_ABI_ORIGINAL
;
4085 /* Unknown bfd flavour. Assume it's the new ABI. */
4086 cris_abi
= CRIS_ABI_V2
;
4089 else if (arches
!= NULL
)
4091 /* No bfd available. Stick with the ABI from the most recently
4092 selected architecture of this same family (the head of arches
4093 always points to this). (This is to avoid changing the ABI
4094 when the user updates the architecture with the 'set
4095 cris-version' command.) */
4096 cris_abi
= gdbarch_tdep (arches
->gdbarch
)->cris_abi
;
4100 /* No bfd, and no previously selected architecture available.
4101 Assume it's the new ABI. */
4102 cris_abi
= CRIS_ABI_V2
;
4105 /* Make the current settings visible to the user. */
4106 usr_cmd_cris_version
= cris_version
;
4107 usr_cmd_cris_mode
= cris_mode
;
4108 usr_cmd_cris_abi
= cris_abi
;
4110 /* Find a candidate among the list of pre-declared architectures. Both
4111 CRIS version and ABI must match. */
4112 for (arches
= gdbarch_list_lookup_by_info (arches
, &info
);
4114 arches
= gdbarch_list_lookup_by_info (arches
->next
, &info
))
4116 if ((gdbarch_tdep (arches
->gdbarch
)->cris_version
== cris_version
)
4117 && (gdbarch_tdep (arches
->gdbarch
)->cris_mode
== cris_mode
)
4118 && (gdbarch_tdep (arches
->gdbarch
)->cris_abi
== cris_abi
))
4119 return arches
->gdbarch
;
4122 /* No matching architecture was found. Create a new one. */
4123 tdep
= (struct gdbarch_tdep
*) xmalloc (sizeof (struct gdbarch_tdep
));
4124 gdbarch
= gdbarch_alloc (&info
, tdep
);
4126 /* NOTE: cagney/2002-12-06: This can be deleted when this arch is
4127 ready to unwind the PC first (see frame.c:get_prev_frame()). */
4128 set_gdbarch_deprecated_init_frame_pc (gdbarch
, init_frame_pc_default
);
4130 tdep
->cris_version
= cris_version
;
4131 tdep
->cris_mode
= cris_mode
;
4132 tdep
->cris_abi
= cris_abi
;
4134 /* INIT shall ensure that the INFO.BYTE_ORDER is non-zero. */
4135 switch (info
.byte_order
)
4137 case BFD_ENDIAN_LITTLE
:
4141 case BFD_ENDIAN_BIG
:
4142 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_init: big endian byte order in info");
4146 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_init: unknown byte order in info");
4149 /* Initialize the ABI dependent things. */
4150 if (tdep
->cris_abi
== CRIS_ABI_ORIGINAL
)
4152 set_gdbarch_double_bit (gdbarch
, 32);
4153 set_gdbarch_push_arguments (gdbarch
, cris_abi_original_push_arguments
);
4154 set_gdbarch_deprecated_store_return_value (gdbarch
,
4155 cris_abi_original_store_return_value
);
4156 set_gdbarch_deprecated_extract_return_value
4157 (gdbarch
, cris_abi_original_extract_return_value
);
4158 set_gdbarch_reg_struct_has_addr
4159 (gdbarch
, cris_abi_original_reg_struct_has_addr
);
4161 else if (tdep
->cris_abi
== CRIS_ABI_V2
)
4163 set_gdbarch_double_bit (gdbarch
, 64);
4164 set_gdbarch_push_arguments (gdbarch
, cris_abi_v2_push_arguments
);
4165 set_gdbarch_deprecated_store_return_value (gdbarch
, cris_abi_v2_store_return_value
);
4166 set_gdbarch_deprecated_extract_return_value
4167 (gdbarch
, cris_abi_v2_extract_return_value
);
4168 set_gdbarch_reg_struct_has_addr (gdbarch
,
4169 cris_abi_v2_reg_struct_has_addr
);
4172 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_init: unknown CRIS ABI");
4174 /* The default definition of a long double is 2 * TARGET_DOUBLE_BIT,
4175 which means we have to set this explicitly. */
4176 set_gdbarch_long_double_bit (gdbarch
, 64);
4178 /* There are 32 registers (some of which may not be implemented). */
4179 set_gdbarch_num_regs (gdbarch
, 32);
4180 set_gdbarch_sp_regnum (gdbarch
, 14);
4181 set_gdbarch_fp_regnum (gdbarch
, 8);
4182 set_gdbarch_pc_regnum (gdbarch
, 15);
4184 set_gdbarch_register_name (gdbarch
, cris_register_name
);
4186 /* Length of ordinary registers used in push_word and a few other places.
4187 REGISTER_RAW_SIZE is the real way to know how big a register is. */
4188 set_gdbarch_register_size (gdbarch
, 4);
4191 set_gdbarch_register_bytes_ok (gdbarch
, cris_register_bytes_ok
);
4192 set_gdbarch_software_single_step (gdbarch
, cris_software_single_step
);
4195 set_gdbarch_cannot_store_register (gdbarch
, cris_cannot_store_register
);
4196 set_gdbarch_cannot_fetch_register (gdbarch
, cris_cannot_fetch_register
);
4199 /* The total amount of space needed to store (in an array called registers)
4200 GDB's copy of the machine's register state. Note: We can not use
4201 cris_register_size at this point, since it relies on current_gdbarch
4203 switch (tdep
->cris_version
)
4209 /* Support for these may be added later. */
4210 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_init: unsupported CRIS version");
4215 /* CRIS v8 and v9, a.k.a. ETRAX 100. General registers R0 - R15
4216 (32 bits), special registers P0 - P1 (8 bits), P4 - P5 (16 bits),
4217 and P8 - P14 (32 bits). */
4218 register_bytes
= (16 * 4) + (2 * 1) + (2 * 2) + (7 * 4);
4223 /* CRIS v10 and v11, a.k.a. ETRAX 100LX. In addition to ETRAX 100,
4224 P7 (32 bits), and P15 (32 bits) have been implemented. */
4225 register_bytes
= (16 * 4) + (2 * 1) + (2 * 2) + (9 * 4);
4229 internal_error (__FILE__
, __LINE__
, "cris_gdbarch_init: unknown CRIS version");
4232 set_gdbarch_register_bytes (gdbarch
, register_bytes
);
4234 /* Returns the register offset for the first byte of register regno's space
4235 in the saved register state. */
4236 set_gdbarch_register_byte (gdbarch
, cris_register_offset
);
4238 /* The length of the registers in the actual machine representation. */
4239 set_gdbarch_register_raw_size (gdbarch
, cris_register_size
);
4241 /* The largest value REGISTER_RAW_SIZE can have. */
4242 set_gdbarch_max_register_raw_size (gdbarch
, 32);
4244 /* The length of the registers in the program's representation. */
4245 set_gdbarch_register_virtual_size (gdbarch
, cris_register_size
);
4247 /* The largest value REGISTER_VIRTUAL_SIZE can have. */
4248 set_gdbarch_max_register_virtual_size (gdbarch
, 32);
4250 set_gdbarch_register_virtual_type (gdbarch
, cris_register_virtual_type
);
4252 /* Use generic dummy frames. */
4254 /* Where to execute the call in the memory segments. */
4255 set_gdbarch_call_dummy_address (gdbarch
, entry_point_address
);
4257 /* Start execution at the beginning of dummy. */
4258 set_gdbarch_call_dummy_start_offset (gdbarch
, 0);
4259 set_gdbarch_call_dummy_breakpoint_offset (gdbarch
, 0);
4261 /* Set to 1 since call_dummy_breakpoint_offset was defined. */
4262 set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch
, 1);
4264 /* Read all about dummy frames in blockframe.c. */
4265 set_gdbarch_call_dummy_length (gdbarch
, 0);
4266 set_gdbarch_deprecated_pc_in_call_dummy (gdbarch
, deprecated_pc_in_call_dummy_at_entry_point
);
4268 /* Defined to 1 to indicate that the target supports inferior function
4270 set_gdbarch_call_dummy_p (gdbarch
, 1);
4271 set_gdbarch_call_dummy_words (gdbarch
, 0);
4272 set_gdbarch_sizeof_call_dummy_words (gdbarch
, 0);
4274 /* No stack adjustment needed when peforming an inferior function call. */
4275 set_gdbarch_call_dummy_stack_adjust_p (gdbarch
, 0);
4276 set_gdbarch_fix_call_dummy (gdbarch
, generic_fix_call_dummy
);
4278 set_gdbarch_get_saved_register (gdbarch
, deprecated_generic_get_saved_register
);
4280 /* No register requires conversion from raw format to virtual format. */
4281 set_gdbarch_register_convertible (gdbarch
, generic_register_convertible_not
);
4283 set_gdbarch_push_dummy_frame (gdbarch
, generic_push_dummy_frame
);
4284 set_gdbarch_push_return_address (gdbarch
, cris_push_return_address
);
4285 set_gdbarch_pop_frame (gdbarch
, cris_pop_frame
);
4287 set_gdbarch_store_struct_return (gdbarch
, cris_store_struct_return
);
4288 set_gdbarch_deprecated_extract_struct_value_address
4289 (gdbarch
, cris_extract_struct_value_address
);
4290 set_gdbarch_use_struct_convention (gdbarch
, cris_use_struct_convention
);
4292 set_gdbarch_frame_init_saved_regs (gdbarch
, cris_frame_init_saved_regs
);
4293 set_gdbarch_init_extra_frame_info (gdbarch
, cris_init_extra_frame_info
);
4294 set_gdbarch_skip_prologue (gdbarch
, cris_skip_prologue
);
4295 set_gdbarch_prologue_frameless_p (gdbarch
, generic_prologue_frameless_p
);
4297 /* The stack grows downward. */
4298 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
4300 set_gdbarch_breakpoint_from_pc (gdbarch
, cris_breakpoint_from_pc
);
4302 /* The PC must not be decremented after a breakpoint. (The breakpoint
4303 handler takes care of that.) */
4304 set_gdbarch_decr_pc_after_break (gdbarch
, 0);
4306 /* Offset from address of function to start of its code. */
4307 set_gdbarch_function_start_offset (gdbarch
, 0);
4309 /* The number of bytes at the start of arglist that are not really args,
4310 0 in the CRIS ABI. */
4311 set_gdbarch_frame_args_skip (gdbarch
, 0);
4312 set_gdbarch_frameless_function_invocation
4313 (gdbarch
, cris_frameless_function_invocation
);
4314 set_gdbarch_frame_chain (gdbarch
, cris_frame_chain
);
4316 set_gdbarch_frame_saved_pc (gdbarch
, cris_frame_saved_pc
);
4317 set_gdbarch_saved_pc_after_call (gdbarch
, cris_saved_pc_after_call
);
4319 set_gdbarch_frame_num_args (gdbarch
, frame_num_args_unknown
);
4321 /* No extra stack alignment needed. Set to 1 by default. */
4322 set_gdbarch_extra_stack_alignment_needed (gdbarch
, 0);
4324 /* Helpful for backtracing and returning in a call dummy. */
4325 set_gdbarch_save_dummy_frame_tos (gdbarch
, generic_save_dummy_frame_tos
);
4327 /* Use target_specific function to define link map offsets. */
4328 set_solib_svr4_fetch_link_map_offsets
4329 (gdbarch
, cris_linux_svr4_fetch_link_map_offsets
);