1 /* Common target dependent code for GDB on ARM systems.
3 Copyright (C) 1988-2020 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include <ctype.h> /* XXX for isupper (). */
29 #include "dis-asm.h" /* For register styles. */
32 #include "reggroups.h"
33 #include "target-float.h"
35 #include "arch-utils.h"
37 #include "frame-unwind.h"
38 #include "frame-base.h"
39 #include "trad-frame.h"
41 #include "dwarf2/frame.h"
43 #include "prologue-value.h"
45 #include "target-descriptions.h"
46 #include "user-regs.h"
47 #include "observable.h"
48 #include "count-one-bits.h"
51 #include "arch/arm-get-next-pcs.h"
53 #include "gdb/sim-arm.h"
56 #include "coff/internal.h"
60 #include "record-full.h"
66 #include "gdbsupport/selftest.h"
69 static bool arm_debug
;
71 /* Macros for setting and testing a bit in a minimal symbol that marks
72 it as Thumb function. The MSB of the minimal symbol's "info" field
73 is used for this purpose.
75 MSYMBOL_SET_SPECIAL Actually sets the "special" bit.
76 MSYMBOL_IS_SPECIAL Tests the "special" bit in a minimal symbol. */
78 #define MSYMBOL_SET_SPECIAL(msym) \
79 MSYMBOL_TARGET_FLAG_1 (msym) = 1
81 #define MSYMBOL_IS_SPECIAL(msym) \
82 MSYMBOL_TARGET_FLAG_1 (msym)
84 struct arm_mapping_symbol
89 bool operator< (const arm_mapping_symbol
&other
) const
90 { return this->value
< other
.value
; }
93 typedef std::vector
<arm_mapping_symbol
> arm_mapping_symbol_vec
;
97 explicit arm_per_bfd (size_t num_sections
)
98 : section_maps (new arm_mapping_symbol_vec
[num_sections
]),
99 section_maps_sorted (new bool[num_sections
] ())
102 DISABLE_COPY_AND_ASSIGN (arm_per_bfd
);
104 /* Information about mapping symbols ($a, $d, $t) in the objfile.
106 The format is an array of vectors of arm_mapping_symbols, there is one
107 vector for each section of the objfile (the array is index by BFD section
110 For each section, the vector of arm_mapping_symbol is sorted by
111 symbol value (address). */
112 std::unique_ptr
<arm_mapping_symbol_vec
[]> section_maps
;
114 /* For each corresponding element of section_maps above, is this vector
116 std::unique_ptr
<bool[]> section_maps_sorted
;
119 /* Per-bfd data used for mapping symbols. */
120 static bfd_key
<arm_per_bfd
> arm_bfd_data_key
;
122 /* The list of available "set arm ..." and "show arm ..." commands. */
123 static struct cmd_list_element
*setarmcmdlist
= NULL
;
124 static struct cmd_list_element
*showarmcmdlist
= NULL
;
126 /* The type of floating-point to use. Keep this in sync with enum
127 arm_float_model, and the help string in _initialize_arm_tdep. */
128 static const char *const fp_model_strings
[] =
138 /* A variable that can be configured by the user. */
139 static enum arm_float_model arm_fp_model
= ARM_FLOAT_AUTO
;
140 static const char *current_fp_model
= "auto";
142 /* The ABI to use. Keep this in sync with arm_abi_kind. */
143 static const char *const arm_abi_strings
[] =
151 /* A variable that can be configured by the user. */
152 static enum arm_abi_kind arm_abi_global
= ARM_ABI_AUTO
;
153 static const char *arm_abi_string
= "auto";
155 /* The execution mode to assume. */
156 static const char *const arm_mode_strings
[] =
164 static const char *arm_fallback_mode_string
= "auto";
165 static const char *arm_force_mode_string
= "auto";
167 /* The standard register names, and all the valid aliases for them. Note
168 that `fp', `sp' and `pc' are not added in this alias list, because they
169 have been added as builtin user registers in
170 std-regs.c:_initialize_frame_reg. */
175 } arm_register_aliases
[] = {
176 /* Basic register numbers. */
193 /* Synonyms (argument and variable registers). */
206 /* Other platform-specific names for r9. */
212 /* Names used by GCC (not listed in the ARM EABI). */
214 /* A special name from the older ATPCS. */
218 static const char *const arm_register_names
[] =
219 {"r0", "r1", "r2", "r3", /* 0 1 2 3 */
220 "r4", "r5", "r6", "r7", /* 4 5 6 7 */
221 "r8", "r9", "r10", "r11", /* 8 9 10 11 */
222 "r12", "sp", "lr", "pc", /* 12 13 14 15 */
223 "f0", "f1", "f2", "f3", /* 16 17 18 19 */
224 "f4", "f5", "f6", "f7", /* 20 21 22 23 */
225 "fps", "cpsr" }; /* 24 25 */
227 /* Holds the current set of options to be passed to the disassembler. */
228 static char *arm_disassembler_options
;
230 /* Valid register name styles. */
231 static const char **valid_disassembly_styles
;
233 /* Disassembly style to use. Default to "std" register names. */
234 static const char *disassembly_style
;
236 /* All possible arm target descriptors. */
237 static struct target_desc
*tdesc_arm_list
[ARM_FP_TYPE_INVALID
];
238 static struct target_desc
*tdesc_arm_mprofile_list
[ARM_M_TYPE_INVALID
];
240 /* This is used to keep the bfd arch_info in sync with the disassembly
242 static void set_disassembly_style_sfunc (const char *, int,
243 struct cmd_list_element
*);
244 static void show_disassembly_style_sfunc (struct ui_file
*, int,
245 struct cmd_list_element
*,
248 static enum register_status
arm_neon_quad_read (struct gdbarch
*gdbarch
,
249 readable_regcache
*regcache
,
250 int regnum
, gdb_byte
*buf
);
251 static void arm_neon_quad_write (struct gdbarch
*gdbarch
,
252 struct regcache
*regcache
,
253 int regnum
, const gdb_byte
*buf
);
256 arm_get_next_pcs_syscall_next_pc (struct arm_get_next_pcs
*self
);
259 /* get_next_pcs operations. */
260 static struct arm_get_next_pcs_ops arm_get_next_pcs_ops
= {
261 arm_get_next_pcs_read_memory_unsigned_integer
,
262 arm_get_next_pcs_syscall_next_pc
,
263 arm_get_next_pcs_addr_bits_remove
,
264 arm_get_next_pcs_is_thumb
,
268 struct arm_prologue_cache
270 /* The stack pointer at the time this frame was created; i.e. the
271 caller's stack pointer when this function was called. It is used
272 to identify this frame. */
275 /* The frame base for this frame is just prev_sp - frame size.
276 FRAMESIZE is the distance from the frame pointer to the
277 initial stack pointer. */
281 /* The register used to hold the frame pointer for this frame. */
284 /* Saved register offsets. */
285 struct trad_frame_saved_reg
*saved_regs
;
290 /* Abstract class to read ARM instructions from memory. */
292 class arm_instruction_reader
295 /* Read a 4 bytes instruction from memory using the BYTE_ORDER endianness. */
296 virtual uint32_t read (CORE_ADDR memaddr
, bfd_endian byte_order
) const = 0;
299 /* Read instructions from target memory. */
301 class target_arm_instruction_reader
: public arm_instruction_reader
304 uint32_t read (CORE_ADDR memaddr
, bfd_endian byte_order
) const override
306 return read_code_unsigned_integer (memaddr
, 4, byte_order
);
312 static CORE_ADDR arm_analyze_prologue
313 (struct gdbarch
*gdbarch
, CORE_ADDR prologue_start
, CORE_ADDR prologue_end
,
314 struct arm_prologue_cache
*cache
, const arm_instruction_reader
&insn_reader
);
316 /* Architecture version for displaced stepping. This effects the behaviour of
317 certain instructions, and really should not be hard-wired. */
319 #define DISPLACED_STEPPING_ARCH_VERSION 5
321 /* See arm-tdep.h. */
323 bool arm_apcs_32
= true;
325 /* Return the bit mask in ARM_PS_REGNUM that indicates Thumb mode. */
328 arm_psr_thumb_bit (struct gdbarch
*gdbarch
)
330 if (gdbarch_tdep (gdbarch
)->is_m
)
336 /* Determine if the processor is currently executing in Thumb mode. */
339 arm_is_thumb (struct regcache
*regcache
)
342 ULONGEST t_bit
= arm_psr_thumb_bit (regcache
->arch ());
344 cpsr
= regcache_raw_get_unsigned (regcache
, ARM_PS_REGNUM
);
346 return (cpsr
& t_bit
) != 0;
349 /* Determine if FRAME is executing in Thumb mode. */
352 arm_frame_is_thumb (struct frame_info
*frame
)
355 ULONGEST t_bit
= arm_psr_thumb_bit (get_frame_arch (frame
));
357 /* Every ARM frame unwinder can unwind the T bit of the CPSR, either
358 directly (from a signal frame or dummy frame) or by interpreting
359 the saved LR (from a prologue or DWARF frame). So consult it and
360 trust the unwinders. */
361 cpsr
= get_frame_register_unsigned (frame
, ARM_PS_REGNUM
);
363 return (cpsr
& t_bit
) != 0;
366 /* Search for the mapping symbol covering MEMADDR. If one is found,
367 return its type. Otherwise, return 0. If START is non-NULL,
368 set *START to the location of the mapping symbol. */
371 arm_find_mapping_symbol (CORE_ADDR memaddr
, CORE_ADDR
*start
)
373 struct obj_section
*sec
;
375 /* If there are mapping symbols, consult them. */
376 sec
= find_pc_section (memaddr
);
379 arm_per_bfd
*data
= arm_bfd_data_key
.get (sec
->objfile
->obfd
);
382 unsigned int section_idx
= sec
->the_bfd_section
->index
;
383 arm_mapping_symbol_vec
&map
384 = data
->section_maps
[section_idx
];
386 /* Sort the vector on first use. */
387 if (!data
->section_maps_sorted
[section_idx
])
389 std::sort (map
.begin (), map
.end ());
390 data
->section_maps_sorted
[section_idx
] = true;
393 struct arm_mapping_symbol map_key
394 = { memaddr
- obj_section_addr (sec
), 0 };
395 arm_mapping_symbol_vec::const_iterator it
396 = std::lower_bound (map
.begin (), map
.end (), map_key
);
398 /* std::lower_bound finds the earliest ordered insertion
399 point. If the symbol at this position starts at this exact
400 address, we use that; otherwise, the preceding
401 mapping symbol covers this address. */
404 if (it
->value
== map_key
.value
)
407 *start
= it
->value
+ obj_section_addr (sec
);
412 if (it
> map
.begin ())
414 arm_mapping_symbol_vec::const_iterator prev_it
418 *start
= prev_it
->value
+ obj_section_addr (sec
);
419 return prev_it
->type
;
427 /* Determine if the program counter specified in MEMADDR is in a Thumb
428 function. This function should be called for addresses unrelated to
429 any executing frame; otherwise, prefer arm_frame_is_thumb. */
432 arm_pc_is_thumb (struct gdbarch
*gdbarch
, CORE_ADDR memaddr
)
434 struct bound_minimal_symbol sym
;
436 arm_displaced_step_copy_insn_closure
*dsc
= nullptr;
438 if (gdbarch_displaced_step_copy_insn_closure_by_addr_p (gdbarch
))
439 dsc
= ((arm_displaced_step_copy_insn_closure
* )
440 gdbarch_displaced_step_copy_insn_closure_by_addr
441 (gdbarch
, current_inferior (), memaddr
));
443 /* If checking the mode of displaced instruction in copy area, the mode
444 should be determined by instruction on the original address. */
447 displaced_debug_printf ("check mode of %.8lx instead of %.8lx",
448 (unsigned long) dsc
->insn_addr
,
449 (unsigned long) memaddr
);
450 memaddr
= dsc
->insn_addr
;
453 /* If bit 0 of the address is set, assume this is a Thumb address. */
454 if (IS_THUMB_ADDR (memaddr
))
457 /* If the user wants to override the symbol table, let him. */
458 if (strcmp (arm_force_mode_string
, "arm") == 0)
460 if (strcmp (arm_force_mode_string
, "thumb") == 0)
463 /* ARM v6-M and v7-M are always in Thumb mode. */
464 if (gdbarch_tdep (gdbarch
)->is_m
)
467 /* If there are mapping symbols, consult them. */
468 type
= arm_find_mapping_symbol (memaddr
, NULL
);
472 /* Thumb functions have a "special" bit set in minimal symbols. */
473 sym
= lookup_minimal_symbol_by_pc (memaddr
);
475 return (MSYMBOL_IS_SPECIAL (sym
.minsym
));
477 /* If the user wants to override the fallback mode, let them. */
478 if (strcmp (arm_fallback_mode_string
, "arm") == 0)
480 if (strcmp (arm_fallback_mode_string
, "thumb") == 0)
483 /* If we couldn't find any symbol, but we're talking to a running
484 target, then trust the current value of $cpsr. This lets
485 "display/i $pc" always show the correct mode (though if there is
486 a symbol table we will not reach here, so it still may not be
487 displayed in the mode it will be executed). */
488 if (target_has_registers ())
489 return arm_frame_is_thumb (get_current_frame ());
491 /* Otherwise we're out of luck; we assume ARM. */
495 /* Determine if the address specified equals any of these magic return
496 values, called EXC_RETURN, defined by the ARM v6-M, v7-M and v8-M
499 From ARMv6-M Reference Manual B1.5.8
500 Table B1-5 Exception return behavior
502 EXC_RETURN Return To Return Stack
503 0xFFFFFFF1 Handler mode Main
504 0xFFFFFFF9 Thread mode Main
505 0xFFFFFFFD Thread mode Process
507 From ARMv7-M Reference Manual B1.5.8
508 Table B1-8 EXC_RETURN definition of exception return behavior, no FP
510 EXC_RETURN Return To Return Stack
511 0xFFFFFFF1 Handler mode Main
512 0xFFFFFFF9 Thread mode Main
513 0xFFFFFFFD Thread mode Process
515 Table B1-9 EXC_RETURN definition of exception return behavior, with
518 EXC_RETURN Return To Return Stack Frame Type
519 0xFFFFFFE1 Handler mode Main Extended
520 0xFFFFFFE9 Thread mode Main Extended
521 0xFFFFFFED Thread mode Process Extended
522 0xFFFFFFF1 Handler mode Main Basic
523 0xFFFFFFF9 Thread mode Main Basic
524 0xFFFFFFFD Thread mode Process Basic
526 For more details see "B1.5.8 Exception return behavior"
527 in both ARMv6-M and ARMv7-M Architecture Reference Manuals.
529 In the ARMv8-M Architecture Technical Reference also adds
530 for implementations without the Security Extension:
533 0xFFFFFFB0 Return to Handler mode.
534 0xFFFFFFB8 Return to Thread mode using the main stack.
535 0xFFFFFFBC Return to Thread mode using the process stack. */
538 arm_m_addr_is_magic (CORE_ADDR addr
)
542 /* Values from ARMv8-M Architecture Technical Reference. */
546 /* Values from Tables in B1.5.8 the EXC_RETURN definitions of
547 the exception return behavior. */
554 /* Address is magic. */
558 /* Address is not magic. */
563 /* Remove useless bits from addresses in a running program. */
565 arm_addr_bits_remove (struct gdbarch
*gdbarch
, CORE_ADDR val
)
567 /* On M-profile devices, do not strip the low bit from EXC_RETURN
568 (the magic exception return address). */
569 if (gdbarch_tdep (gdbarch
)->is_m
570 && arm_m_addr_is_magic (val
))
574 return UNMAKE_THUMB_ADDR (val
);
576 return (val
& 0x03fffffc);
579 /* Return 1 if PC is the start of a compiler helper function which
580 can be safely ignored during prologue skipping. IS_THUMB is true
581 if the function is known to be a Thumb function due to the way it
584 skip_prologue_function (struct gdbarch
*gdbarch
, CORE_ADDR pc
, int is_thumb
)
586 enum bfd_endian byte_order_for_code
= gdbarch_byte_order_for_code (gdbarch
);
587 struct bound_minimal_symbol msym
;
589 msym
= lookup_minimal_symbol_by_pc (pc
);
590 if (msym
.minsym
!= NULL
591 && BMSYMBOL_VALUE_ADDRESS (msym
) == pc
592 && msym
.minsym
->linkage_name () != NULL
)
594 const char *name
= msym
.minsym
->linkage_name ();
596 /* The GNU linker's Thumb call stub to foo is named
598 if (strstr (name
, "_from_thumb") != NULL
)
601 /* On soft-float targets, __truncdfsf2 is called to convert promoted
602 arguments to their argument types in non-prototyped
604 if (startswith (name
, "__truncdfsf2"))
606 if (startswith (name
, "__aeabi_d2f"))
609 /* Internal functions related to thread-local storage. */
610 if (startswith (name
, "__tls_get_addr"))
612 if (startswith (name
, "__aeabi_read_tp"))
617 /* If we run against a stripped glibc, we may be unable to identify
618 special functions by name. Check for one important case,
619 __aeabi_read_tp, by comparing the *code* against the default
620 implementation (this is hand-written ARM assembler in glibc). */
623 && read_code_unsigned_integer (pc
, 4, byte_order_for_code
)
624 == 0xe3e00a0f /* mov r0, #0xffff0fff */
625 && read_code_unsigned_integer (pc
+ 4, 4, byte_order_for_code
)
626 == 0xe240f01f) /* sub pc, r0, #31 */
633 /* Extract the immediate from instruction movw/movt of encoding T. INSN1 is
634 the first 16-bit of instruction, and INSN2 is the second 16-bit of
636 #define EXTRACT_MOVW_MOVT_IMM_T(insn1, insn2) \
637 ((bits ((insn1), 0, 3) << 12) \
638 | (bits ((insn1), 10, 10) << 11) \
639 | (bits ((insn2), 12, 14) << 8) \
640 | bits ((insn2), 0, 7))
642 /* Extract the immediate from instruction movw/movt of encoding A. INSN is
643 the 32-bit instruction. */
644 #define EXTRACT_MOVW_MOVT_IMM_A(insn) \
645 ((bits ((insn), 16, 19) << 12) \
646 | bits ((insn), 0, 11))
648 /* Decode immediate value; implements ThumbExpandImmediate pseudo-op. */
651 thumb_expand_immediate (unsigned int imm
)
653 unsigned int count
= imm
>> 7;
661 return (imm
& 0xff) | ((imm
& 0xff) << 16);
663 return ((imm
& 0xff) << 8) | ((imm
& 0xff) << 24);
665 return (imm
& 0xff) | ((imm
& 0xff) << 8)
666 | ((imm
& 0xff) << 16) | ((imm
& 0xff) << 24);
669 return (0x80 | (imm
& 0x7f)) << (32 - count
);
672 /* Return 1 if the 16-bit Thumb instruction INSN restores SP in
673 epilogue, 0 otherwise. */
676 thumb_instruction_restores_sp (unsigned short insn
)
678 return (insn
== 0x46bd /* mov sp, r7 */
679 || (insn
& 0xff80) == 0xb000 /* add sp, imm */
680 || (insn
& 0xfe00) == 0xbc00); /* pop <registers> */
683 /* Analyze a Thumb prologue, looking for a recognizable stack frame
684 and frame pointer. Scan until we encounter a store that could
685 clobber the stack frame unexpectedly, or an unknown instruction.
686 Return the last address which is definitely safe to skip for an
687 initial breakpoint. */
690 thumb_analyze_prologue (struct gdbarch
*gdbarch
,
691 CORE_ADDR start
, CORE_ADDR limit
,
692 struct arm_prologue_cache
*cache
)
694 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
695 enum bfd_endian byte_order_for_code
= gdbarch_byte_order_for_code (gdbarch
);
699 CORE_ADDR unrecognized_pc
= 0;
701 for (i
= 0; i
< 16; i
++)
702 regs
[i
] = pv_register (i
, 0);
703 pv_area
stack (ARM_SP_REGNUM
, gdbarch_addr_bit (gdbarch
));
705 while (start
< limit
)
709 insn
= read_code_unsigned_integer (start
, 2, byte_order_for_code
);
711 if ((insn
& 0xfe00) == 0xb400) /* push { rlist } */
716 if (stack
.store_would_trash (regs
[ARM_SP_REGNUM
]))
719 /* Bits 0-7 contain a mask for registers R0-R7. Bit 8 says
720 whether to save LR (R14). */
721 mask
= (insn
& 0xff) | ((insn
& 0x100) << 6);
723 /* Calculate offsets of saved R0-R7 and LR. */
724 for (regno
= ARM_LR_REGNUM
; regno
>= 0; regno
--)
725 if (mask
& (1 << regno
))
727 regs
[ARM_SP_REGNUM
] = pv_add_constant (regs
[ARM_SP_REGNUM
],
729 stack
.store (regs
[ARM_SP_REGNUM
], 4, regs
[regno
]);
732 else if ((insn
& 0xff80) == 0xb080) /* sub sp, #imm */
734 offset
= (insn
& 0x7f) << 2; /* get scaled offset */
735 regs
[ARM_SP_REGNUM
] = pv_add_constant (regs
[ARM_SP_REGNUM
],
738 else if (thumb_instruction_restores_sp (insn
))
740 /* Don't scan past the epilogue. */
743 else if ((insn
& 0xf800) == 0xa800) /* add Rd, sp, #imm */
744 regs
[bits (insn
, 8, 10)] = pv_add_constant (regs
[ARM_SP_REGNUM
],
746 else if ((insn
& 0xfe00) == 0x1c00 /* add Rd, Rn, #imm */
747 && pv_is_register (regs
[bits (insn
, 3, 5)], ARM_SP_REGNUM
))
748 regs
[bits (insn
, 0, 2)] = pv_add_constant (regs
[bits (insn
, 3, 5)],
750 else if ((insn
& 0xf800) == 0x3000 /* add Rd, #imm */
751 && pv_is_register (regs
[bits (insn
, 8, 10)], ARM_SP_REGNUM
))
752 regs
[bits (insn
, 8, 10)] = pv_add_constant (regs
[bits (insn
, 8, 10)],
754 else if ((insn
& 0xfe00) == 0x1800 /* add Rd, Rn, Rm */
755 && pv_is_register (regs
[bits (insn
, 6, 8)], ARM_SP_REGNUM
)
756 && pv_is_constant (regs
[bits (insn
, 3, 5)]))
757 regs
[bits (insn
, 0, 2)] = pv_add (regs
[bits (insn
, 3, 5)],
758 regs
[bits (insn
, 6, 8)]);
759 else if ((insn
& 0xff00) == 0x4400 /* add Rd, Rm */
760 && pv_is_constant (regs
[bits (insn
, 3, 6)]))
762 int rd
= (bit (insn
, 7) << 3) + bits (insn
, 0, 2);
763 int rm
= bits (insn
, 3, 6);
764 regs
[rd
] = pv_add (regs
[rd
], regs
[rm
]);
766 else if ((insn
& 0xff00) == 0x4600) /* mov hi, lo or mov lo, hi */
768 int dst_reg
= (insn
& 0x7) + ((insn
& 0x80) >> 4);
769 int src_reg
= (insn
& 0x78) >> 3;
770 regs
[dst_reg
] = regs
[src_reg
];
772 else if ((insn
& 0xf800) == 0x9000) /* str rd, [sp, #off] */
774 /* Handle stores to the stack. Normally pushes are used,
775 but with GCC -mtpcs-frame, there may be other stores
776 in the prologue to create the frame. */
777 int regno
= (insn
>> 8) & 0x7;
780 offset
= (insn
& 0xff) << 2;
781 addr
= pv_add_constant (regs
[ARM_SP_REGNUM
], offset
);
783 if (stack
.store_would_trash (addr
))
786 stack
.store (addr
, 4, regs
[regno
]);
788 else if ((insn
& 0xf800) == 0x6000) /* str rd, [rn, #off] */
790 int rd
= bits (insn
, 0, 2);
791 int rn
= bits (insn
, 3, 5);
794 offset
= bits (insn
, 6, 10) << 2;
795 addr
= pv_add_constant (regs
[rn
], offset
);
797 if (stack
.store_would_trash (addr
))
800 stack
.store (addr
, 4, regs
[rd
]);
802 else if (((insn
& 0xf800) == 0x7000 /* strb Rd, [Rn, #off] */
803 || (insn
& 0xf800) == 0x8000) /* strh Rd, [Rn, #off] */
804 && pv_is_register (regs
[bits (insn
, 3, 5)], ARM_SP_REGNUM
))
805 /* Ignore stores of argument registers to the stack. */
807 else if ((insn
& 0xf800) == 0xc800 /* ldmia Rn!, { registers } */
808 && pv_is_register (regs
[bits (insn
, 8, 10)], ARM_SP_REGNUM
))
809 /* Ignore block loads from the stack, potentially copying
810 parameters from memory. */
812 else if ((insn
& 0xf800) == 0x9800 /* ldr Rd, [Rn, #immed] */
813 || ((insn
& 0xf800) == 0x6800 /* ldr Rd, [sp, #immed] */
814 && pv_is_register (regs
[bits (insn
, 3, 5)], ARM_SP_REGNUM
)))
815 /* Similarly ignore single loads from the stack. */
817 else if ((insn
& 0xffc0) == 0x0000 /* lsls Rd, Rm, #0 */
818 || (insn
& 0xffc0) == 0x1c00) /* add Rd, Rn, #0 */
819 /* Skip register copies, i.e. saves to another register
820 instead of the stack. */
822 else if ((insn
& 0xf800) == 0x2000) /* movs Rd, #imm */
823 /* Recognize constant loads; even with small stacks these are necessary
825 regs
[bits (insn
, 8, 10)] = pv_constant (bits (insn
, 0, 7));
826 else if ((insn
& 0xf800) == 0x4800) /* ldr Rd, [pc, #imm] */
828 /* Constant pool loads, for the same reason. */
829 unsigned int constant
;
832 loc
= start
+ 4 + bits (insn
, 0, 7) * 4;
833 constant
= read_memory_unsigned_integer (loc
, 4, byte_order
);
834 regs
[bits (insn
, 8, 10)] = pv_constant (constant
);
836 else if (thumb_insn_size (insn
) == 4) /* 32-bit Thumb-2 instructions. */
838 unsigned short inst2
;
840 inst2
= read_code_unsigned_integer (start
+ 2, 2,
841 byte_order_for_code
);
843 if ((insn
& 0xf800) == 0xf000 && (inst2
& 0xe800) == 0xe800)
845 /* BL, BLX. Allow some special function calls when
846 skipping the prologue; GCC generates these before
847 storing arguments to the stack. */
849 int j1
, j2
, imm1
, imm2
;
851 imm1
= sbits (insn
, 0, 10);
852 imm2
= bits (inst2
, 0, 10);
853 j1
= bit (inst2
, 13);
854 j2
= bit (inst2
, 11);
856 offset
= ((imm1
<< 12) + (imm2
<< 1));
857 offset
^= ((!j2
) << 22) | ((!j1
) << 23);
859 nextpc
= start
+ 4 + offset
;
860 /* For BLX make sure to clear the low bits. */
861 if (bit (inst2
, 12) == 0)
862 nextpc
= nextpc
& 0xfffffffc;
864 if (!skip_prologue_function (gdbarch
, nextpc
,
865 bit (inst2
, 12) != 0))
869 else if ((insn
& 0xffd0) == 0xe900 /* stmdb Rn{!},
871 && pv_is_register (regs
[bits (insn
, 0, 3)], ARM_SP_REGNUM
))
873 pv_t addr
= regs
[bits (insn
, 0, 3)];
876 if (stack
.store_would_trash (addr
))
879 /* Calculate offsets of saved registers. */
880 for (regno
= ARM_LR_REGNUM
; regno
>= 0; regno
--)
881 if (inst2
& (1 << regno
))
883 addr
= pv_add_constant (addr
, -4);
884 stack
.store (addr
, 4, regs
[regno
]);
888 regs
[bits (insn
, 0, 3)] = addr
;
891 else if ((insn
& 0xff50) == 0xe940 /* strd Rt, Rt2,
893 && pv_is_register (regs
[bits (insn
, 0, 3)], ARM_SP_REGNUM
))
895 int regno1
= bits (inst2
, 12, 15);
896 int regno2
= bits (inst2
, 8, 11);
897 pv_t addr
= regs
[bits (insn
, 0, 3)];
899 offset
= inst2
& 0xff;
901 addr
= pv_add_constant (addr
, offset
);
903 addr
= pv_add_constant (addr
, -offset
);
905 if (stack
.store_would_trash (addr
))
908 stack
.store (addr
, 4, regs
[regno1
]);
909 stack
.store (pv_add_constant (addr
, 4),
913 regs
[bits (insn
, 0, 3)] = addr
;
916 else if ((insn
& 0xfff0) == 0xf8c0 /* str Rt,[Rn,+/-#imm]{!} */
917 && (inst2
& 0x0c00) == 0x0c00
918 && pv_is_register (regs
[bits (insn
, 0, 3)], ARM_SP_REGNUM
))
920 int regno
= bits (inst2
, 12, 15);
921 pv_t addr
= regs
[bits (insn
, 0, 3)];
923 offset
= inst2
& 0xff;
925 addr
= pv_add_constant (addr
, offset
);
927 addr
= pv_add_constant (addr
, -offset
);
929 if (stack
.store_would_trash (addr
))
932 stack
.store (addr
, 4, regs
[regno
]);
935 regs
[bits (insn
, 0, 3)] = addr
;
938 else if ((insn
& 0xfff0) == 0xf8c0 /* str.w Rt,[Rn,#imm] */
939 && pv_is_register (regs
[bits (insn
, 0, 3)], ARM_SP_REGNUM
))
941 int regno
= bits (inst2
, 12, 15);
944 offset
= inst2
& 0xfff;
945 addr
= pv_add_constant (regs
[bits (insn
, 0, 3)], offset
);
947 if (stack
.store_would_trash (addr
))
950 stack
.store (addr
, 4, regs
[regno
]);
953 else if ((insn
& 0xffd0) == 0xf880 /* str{bh}.w Rt,[Rn,#imm] */
954 && pv_is_register (regs
[bits (insn
, 0, 3)], ARM_SP_REGNUM
))
955 /* Ignore stores of argument registers to the stack. */
958 else if ((insn
& 0xffd0) == 0xf800 /* str{bh} Rt,[Rn,#+/-imm] */
959 && (inst2
& 0x0d00) == 0x0c00
960 && pv_is_register (regs
[bits (insn
, 0, 3)], ARM_SP_REGNUM
))
961 /* Ignore stores of argument registers to the stack. */
964 else if ((insn
& 0xffd0) == 0xe890 /* ldmia Rn[!],
966 && (inst2
& 0x8000) == 0x0000
967 && pv_is_register (regs
[bits (insn
, 0, 3)], ARM_SP_REGNUM
))
968 /* Ignore block loads from the stack, potentially copying
969 parameters from memory. */
972 else if ((insn
& 0xff70) == 0xe950 /* ldrd Rt, Rt2,
974 && pv_is_register (regs
[bits (insn
, 0, 3)], ARM_SP_REGNUM
))
975 /* Similarly ignore dual loads from the stack. */
978 else if ((insn
& 0xfff0) == 0xf850 /* ldr Rt,[Rn,#+/-imm] */
979 && (inst2
& 0x0d00) == 0x0c00
980 && pv_is_register (regs
[bits (insn
, 0, 3)], ARM_SP_REGNUM
))
981 /* Similarly ignore single loads from the stack. */
984 else if ((insn
& 0xfff0) == 0xf8d0 /* ldr.w Rt,[Rn,#imm] */
985 && pv_is_register (regs
[bits (insn
, 0, 3)], ARM_SP_REGNUM
))
986 /* Similarly ignore single loads from the stack. */
989 else if ((insn
& 0xfbf0) == 0xf100 /* add.w Rd, Rn, #imm */
990 && (inst2
& 0x8000) == 0x0000)
992 unsigned int imm
= ((bits (insn
, 10, 10) << 11)
993 | (bits (inst2
, 12, 14) << 8)
994 | bits (inst2
, 0, 7));
996 regs
[bits (inst2
, 8, 11)]
997 = pv_add_constant (regs
[bits (insn
, 0, 3)],
998 thumb_expand_immediate (imm
));
1001 else if ((insn
& 0xfbf0) == 0xf200 /* addw Rd, Rn, #imm */
1002 && (inst2
& 0x8000) == 0x0000)
1004 unsigned int imm
= ((bits (insn
, 10, 10) << 11)
1005 | (bits (inst2
, 12, 14) << 8)
1006 | bits (inst2
, 0, 7));
1008 regs
[bits (inst2
, 8, 11)]
1009 = pv_add_constant (regs
[bits (insn
, 0, 3)], imm
);
1012 else if ((insn
& 0xfbf0) == 0xf1a0 /* sub.w Rd, Rn, #imm */
1013 && (inst2
& 0x8000) == 0x0000)
1015 unsigned int imm
= ((bits (insn
, 10, 10) << 11)
1016 | (bits (inst2
, 12, 14) << 8)
1017 | bits (inst2
, 0, 7));
1019 regs
[bits (inst2
, 8, 11)]
1020 = pv_add_constant (regs
[bits (insn
, 0, 3)],
1021 - (CORE_ADDR
) thumb_expand_immediate (imm
));
1024 else if ((insn
& 0xfbf0) == 0xf2a0 /* subw Rd, Rn, #imm */
1025 && (inst2
& 0x8000) == 0x0000)
1027 unsigned int imm
= ((bits (insn
, 10, 10) << 11)
1028 | (bits (inst2
, 12, 14) << 8)
1029 | bits (inst2
, 0, 7));
1031 regs
[bits (inst2
, 8, 11)]
1032 = pv_add_constant (regs
[bits (insn
, 0, 3)], - (CORE_ADDR
) imm
);
1035 else if ((insn
& 0xfbff) == 0xf04f) /* mov.w Rd, #const */
1037 unsigned int imm
= ((bits (insn
, 10, 10) << 11)
1038 | (bits (inst2
, 12, 14) << 8)
1039 | bits (inst2
, 0, 7));
1041 regs
[bits (inst2
, 8, 11)]
1042 = pv_constant (thumb_expand_immediate (imm
));
1045 else if ((insn
& 0xfbf0) == 0xf240) /* movw Rd, #const */
1048 = EXTRACT_MOVW_MOVT_IMM_T (insn
, inst2
);
1050 regs
[bits (inst2
, 8, 11)] = pv_constant (imm
);
1053 else if (insn
== 0xea5f /* mov.w Rd,Rm */
1054 && (inst2
& 0xf0f0) == 0)
1056 int dst_reg
= (inst2
& 0x0f00) >> 8;
1057 int src_reg
= inst2
& 0xf;
1058 regs
[dst_reg
] = regs
[src_reg
];
1061 else if ((insn
& 0xff7f) == 0xf85f) /* ldr.w Rt,<label> */
1063 /* Constant pool loads. */
1064 unsigned int constant
;
1067 offset
= bits (inst2
, 0, 11);
1069 loc
= start
+ 4 + offset
;
1071 loc
= start
+ 4 - offset
;
1073 constant
= read_memory_unsigned_integer (loc
, 4, byte_order
);
1074 regs
[bits (inst2
, 12, 15)] = pv_constant (constant
);
1077 else if ((insn
& 0xff7f) == 0xe95f) /* ldrd Rt,Rt2,<label> */
1079 /* Constant pool loads. */
1080 unsigned int constant
;
1083 offset
= bits (inst2
, 0, 7) << 2;
1085 loc
= start
+ 4 + offset
;
1087 loc
= start
+ 4 - offset
;
1089 constant
= read_memory_unsigned_integer (loc
, 4, byte_order
);
1090 regs
[bits (inst2
, 12, 15)] = pv_constant (constant
);
1092 constant
= read_memory_unsigned_integer (loc
+ 4, 4, byte_order
);
1093 regs
[bits (inst2
, 8, 11)] = pv_constant (constant
);
1096 else if (thumb2_instruction_changes_pc (insn
, inst2
))
1098 /* Don't scan past anything that might change control flow. */
1103 /* The optimizer might shove anything into the prologue,
1104 so we just skip what we don't recognize. */
1105 unrecognized_pc
= start
;
1110 else if (thumb_instruction_changes_pc (insn
))
1112 /* Don't scan past anything that might change control flow. */
1117 /* The optimizer might shove anything into the prologue,
1118 so we just skip what we don't recognize. */
1119 unrecognized_pc
= start
;
1126 fprintf_unfiltered (gdb_stdlog
, "Prologue scan stopped at %s\n",
1127 paddress (gdbarch
, start
));
1129 if (unrecognized_pc
== 0)
1130 unrecognized_pc
= start
;
1133 return unrecognized_pc
;
1135 if (pv_is_register (regs
[ARM_FP_REGNUM
], ARM_SP_REGNUM
))
1137 /* Frame pointer is fp. Frame size is constant. */
1138 cache
->framereg
= ARM_FP_REGNUM
;
1139 cache
->framesize
= -regs
[ARM_FP_REGNUM
].k
;
1141 else if (pv_is_register (regs
[THUMB_FP_REGNUM
], ARM_SP_REGNUM
))
1143 /* Frame pointer is r7. Frame size is constant. */
1144 cache
->framereg
= THUMB_FP_REGNUM
;
1145 cache
->framesize
= -regs
[THUMB_FP_REGNUM
].k
;
1149 /* Try the stack pointer... this is a bit desperate. */
1150 cache
->framereg
= ARM_SP_REGNUM
;
1151 cache
->framesize
= -regs
[ARM_SP_REGNUM
].k
;
1154 for (i
= 0; i
< 16; i
++)
1155 if (stack
.find_reg (gdbarch
, i
, &offset
))
1156 cache
->saved_regs
[i
].addr
= offset
;
1158 return unrecognized_pc
;
1162 /* Try to analyze the instructions starting from PC, which load symbol
1163 __stack_chk_guard. Return the address of instruction after loading this
1164 symbol, set the dest register number to *BASEREG, and set the size of
1165 instructions for loading symbol in OFFSET. Return 0 if instructions are
1169 arm_analyze_load_stack_chk_guard(CORE_ADDR pc
, struct gdbarch
*gdbarch
,
1170 unsigned int *destreg
, int *offset
)
1172 enum bfd_endian byte_order_for_code
= gdbarch_byte_order_for_code (gdbarch
);
1173 int is_thumb
= arm_pc_is_thumb (gdbarch
, pc
);
1174 unsigned int low
, high
, address
;
1179 unsigned short insn1
1180 = read_code_unsigned_integer (pc
, 2, byte_order_for_code
);
1182 if ((insn1
& 0xf800) == 0x4800) /* ldr Rd, #immed */
1184 *destreg
= bits (insn1
, 8, 10);
1186 address
= (pc
& 0xfffffffc) + 4 + (bits (insn1
, 0, 7) << 2);
1187 address
= read_memory_unsigned_integer (address
, 4,
1188 byte_order_for_code
);
1190 else if ((insn1
& 0xfbf0) == 0xf240) /* movw Rd, #const */
1192 unsigned short insn2
1193 = read_code_unsigned_integer (pc
+ 2, 2, byte_order_for_code
);
1195 low
= EXTRACT_MOVW_MOVT_IMM_T (insn1
, insn2
);
1198 = read_code_unsigned_integer (pc
+ 4, 2, byte_order_for_code
);
1200 = read_code_unsigned_integer (pc
+ 6, 2, byte_order_for_code
);
1202 /* movt Rd, #const */
1203 if ((insn1
& 0xfbc0) == 0xf2c0)
1205 high
= EXTRACT_MOVW_MOVT_IMM_T (insn1
, insn2
);
1206 *destreg
= bits (insn2
, 8, 11);
1208 address
= (high
<< 16 | low
);
1215 = read_code_unsigned_integer (pc
, 4, byte_order_for_code
);
1217 if ((insn
& 0x0e5f0000) == 0x041f0000) /* ldr Rd, [PC, #immed] */
1219 address
= bits (insn
, 0, 11) + pc
+ 8;
1220 address
= read_memory_unsigned_integer (address
, 4,
1221 byte_order_for_code
);
1223 *destreg
= bits (insn
, 12, 15);
1226 else if ((insn
& 0x0ff00000) == 0x03000000) /* movw Rd, #const */
1228 low
= EXTRACT_MOVW_MOVT_IMM_A (insn
);
1231 = read_code_unsigned_integer (pc
+ 4, 4, byte_order_for_code
);
1233 if ((insn
& 0x0ff00000) == 0x03400000) /* movt Rd, #const */
1235 high
= EXTRACT_MOVW_MOVT_IMM_A (insn
);
1236 *destreg
= bits (insn
, 12, 15);
1238 address
= (high
<< 16 | low
);
1246 /* Try to skip a sequence of instructions used for stack protector. If PC
1247 points to the first instruction of this sequence, return the address of
1248 first instruction after this sequence, otherwise, return original PC.
1250 On arm, this sequence of instructions is composed of mainly three steps,
1251 Step 1: load symbol __stack_chk_guard,
1252 Step 2: load from address of __stack_chk_guard,
1253 Step 3: store it to somewhere else.
1255 Usually, instructions on step 2 and step 3 are the same on various ARM
1256 architectures. On step 2, it is one instruction 'ldr Rx, [Rn, #0]', and
1257 on step 3, it is also one instruction 'str Rx, [r7, #immd]'. However,
1258 instructions in step 1 vary from different ARM architectures. On ARMv7,
1261 movw Rn, #:lower16:__stack_chk_guard
1262 movt Rn, #:upper16:__stack_chk_guard
1269 .word __stack_chk_guard
1271 Since ldr/str is a very popular instruction, we can't use them as
1272 'fingerprint' or 'signature' of stack protector sequence. Here we choose
1273 sequence {movw/movt, ldr}/ldr/str plus symbol __stack_chk_guard, if not
1274 stripped, as the 'fingerprint' of a stack protector cdoe sequence. */
1277 arm_skip_stack_protector(CORE_ADDR pc
, struct gdbarch
*gdbarch
)
1279 enum bfd_endian byte_order_for_code
= gdbarch_byte_order_for_code (gdbarch
);
1280 unsigned int basereg
;
1281 struct bound_minimal_symbol stack_chk_guard
;
1283 int is_thumb
= arm_pc_is_thumb (gdbarch
, pc
);
1286 /* Try to parse the instructions in Step 1. */
1287 addr
= arm_analyze_load_stack_chk_guard (pc
, gdbarch
,
1292 stack_chk_guard
= lookup_minimal_symbol_by_pc (addr
);
1293 /* ADDR must correspond to a symbol whose name is __stack_chk_guard.
1294 Otherwise, this sequence cannot be for stack protector. */
1295 if (stack_chk_guard
.minsym
== NULL
1296 || !startswith (stack_chk_guard
.minsym
->linkage_name (), "__stack_chk_guard"))
1301 unsigned int destreg
;
1303 = read_code_unsigned_integer (pc
+ offset
, 2, byte_order_for_code
);
1305 /* Step 2: ldr Rd, [Rn, #immed], encoding T1. */
1306 if ((insn
& 0xf800) != 0x6800)
1308 if (bits (insn
, 3, 5) != basereg
)
1310 destreg
= bits (insn
, 0, 2);
1312 insn
= read_code_unsigned_integer (pc
+ offset
+ 2, 2,
1313 byte_order_for_code
);
1314 /* Step 3: str Rd, [Rn, #immed], encoding T1. */
1315 if ((insn
& 0xf800) != 0x6000)
1317 if (destreg
!= bits (insn
, 0, 2))
1322 unsigned int destreg
;
1324 = read_code_unsigned_integer (pc
+ offset
, 4, byte_order_for_code
);
1326 /* Step 2: ldr Rd, [Rn, #immed], encoding A1. */
1327 if ((insn
& 0x0e500000) != 0x04100000)
1329 if (bits (insn
, 16, 19) != basereg
)
1331 destreg
= bits (insn
, 12, 15);
1332 /* Step 3: str Rd, [Rn, #immed], encoding A1. */
1333 insn
= read_code_unsigned_integer (pc
+ offset
+ 4,
1334 4, byte_order_for_code
);
1335 if ((insn
& 0x0e500000) != 0x04000000)
1337 if (bits (insn
, 12, 15) != destreg
)
1340 /* The size of total two instructions ldr/str is 4 on Thumb-2, while 8
1343 return pc
+ offset
+ 4;
1345 return pc
+ offset
+ 8;
1348 /* Advance the PC across any function entry prologue instructions to
1349 reach some "real" code.
1351 The APCS (ARM Procedure Call Standard) defines the following
1355 [stmfd sp!, {a1,a2,a3,a4}]
1356 stmfd sp!, {...,fp,ip,lr,pc}
1357 [stfe f7, [sp, #-12]!]
1358 [stfe f6, [sp, #-12]!]
1359 [stfe f5, [sp, #-12]!]
1360 [stfe f4, [sp, #-12]!]
1361 sub fp, ip, #nn @@ nn == 20 or 4 depending on second insn. */
1364 arm_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1366 CORE_ADDR func_addr
, limit_pc
;
1368 /* See if we can determine the end of the prologue via the symbol table.
1369 If so, then return either PC, or the PC after the prologue, whichever
1371 if (find_pc_partial_function (pc
, NULL
, &func_addr
, NULL
))
1373 CORE_ADDR post_prologue_pc
1374 = skip_prologue_using_sal (gdbarch
, func_addr
);
1375 struct compunit_symtab
*cust
= find_pc_compunit_symtab (func_addr
);
1377 if (post_prologue_pc
)
1379 = arm_skip_stack_protector (post_prologue_pc
, gdbarch
);
1382 /* GCC always emits a line note before the prologue and another
1383 one after, even if the two are at the same address or on the
1384 same line. Take advantage of this so that we do not need to
1385 know every instruction that might appear in the prologue. We
1386 will have producer information for most binaries; if it is
1387 missing (e.g. for -gstabs), assuming the GNU tools. */
1388 if (post_prologue_pc
1390 || COMPUNIT_PRODUCER (cust
) == NULL
1391 || startswith (COMPUNIT_PRODUCER (cust
), "GNU ")
1392 || producer_is_llvm (COMPUNIT_PRODUCER (cust
))))
1393 return post_prologue_pc
;
1395 if (post_prologue_pc
!= 0)
1397 CORE_ADDR analyzed_limit
;
1399 /* For non-GCC compilers, make sure the entire line is an
1400 acceptable prologue; GDB will round this function's
1401 return value up to the end of the following line so we
1402 can not skip just part of a line (and we do not want to).
1404 RealView does not treat the prologue specially, but does
1405 associate prologue code with the opening brace; so this
1406 lets us skip the first line if we think it is the opening
1408 if (arm_pc_is_thumb (gdbarch
, func_addr
))
1409 analyzed_limit
= thumb_analyze_prologue (gdbarch
, func_addr
,
1410 post_prologue_pc
, NULL
);
1413 = arm_analyze_prologue (gdbarch
, func_addr
, post_prologue_pc
,
1414 NULL
, target_arm_instruction_reader ());
1416 if (analyzed_limit
!= post_prologue_pc
)
1419 return post_prologue_pc
;
1423 /* Can't determine prologue from the symbol table, need to examine
1426 /* Find an upper limit on the function prologue using the debug
1427 information. If the debug information could not be used to provide
1428 that bound, then use an arbitrary large number as the upper bound. */
1429 /* Like arm_scan_prologue, stop no later than pc + 64. */
1430 limit_pc
= skip_prologue_using_sal (gdbarch
, pc
);
1432 limit_pc
= pc
+ 64; /* Magic. */
1435 /* Check if this is Thumb code. */
1436 if (arm_pc_is_thumb (gdbarch
, pc
))
1437 return thumb_analyze_prologue (gdbarch
, pc
, limit_pc
, NULL
);
1439 return arm_analyze_prologue (gdbarch
, pc
, limit_pc
, NULL
,
1440 target_arm_instruction_reader ());
1444 /* Function: thumb_scan_prologue (helper function for arm_scan_prologue)
1445 This function decodes a Thumb function prologue to determine:
1446 1) the size of the stack frame
1447 2) which registers are saved on it
1448 3) the offsets of saved regs
1449 4) the offset from the stack pointer to the frame pointer
1451 A typical Thumb function prologue would create this stack frame
1452 (offsets relative to FP)
1453 old SP -> 24 stack parameters
1456 R7 -> 0 local variables (16 bytes)
1457 SP -> -12 additional stack space (12 bytes)
1458 The frame size would thus be 36 bytes, and the frame offset would be
1459 12 bytes. The frame register is R7.
1461 The comments for thumb_skip_prolog() describe the algorithm we use
1462 to detect the end of the prolog. */
1466 thumb_scan_prologue (struct gdbarch
*gdbarch
, CORE_ADDR prev_pc
,
1467 CORE_ADDR block_addr
, struct arm_prologue_cache
*cache
)
1469 CORE_ADDR prologue_start
;
1470 CORE_ADDR prologue_end
;
1472 if (find_pc_partial_function (block_addr
, NULL
, &prologue_start
,
1475 /* See comment in arm_scan_prologue for an explanation of
1477 if (prologue_end
> prologue_start
+ 64)
1479 prologue_end
= prologue_start
+ 64;
1483 /* We're in the boondocks: we have no idea where the start of the
1487 prologue_end
= std::min (prologue_end
, prev_pc
);
1489 thumb_analyze_prologue (gdbarch
, prologue_start
, prologue_end
, cache
);
1492 /* Return 1 if the ARM instruction INSN restores SP in epilogue, 0
1496 arm_instruction_restores_sp (unsigned int insn
)
1498 if (bits (insn
, 28, 31) != INST_NV
)
1500 if ((insn
& 0x0df0f000) == 0x0080d000
1501 /* ADD SP (register or immediate). */
1502 || (insn
& 0x0df0f000) == 0x0040d000
1503 /* SUB SP (register or immediate). */
1504 || (insn
& 0x0ffffff0) == 0x01a0d000
1506 || (insn
& 0x0fff0000) == 0x08bd0000
1508 || (insn
& 0x0fff0000) == 0x049d0000)
1509 /* POP of a single register. */
1516 /* Implement immediate value decoding, as described in section A5.2.4
1517 (Modified immediate constants in ARM instructions) of the ARM Architecture
1518 Reference Manual (ARMv7-A and ARMv7-R edition). */
1521 arm_expand_immediate (uint32_t imm
)
1523 /* Immediate values are 12 bits long. */
1524 gdb_assert ((imm
& 0xfffff000) == 0);
1526 uint32_t unrotated_value
= imm
& 0xff;
1527 uint32_t rotate_amount
= (imm
& 0xf00) >> 7;
1529 if (rotate_amount
== 0)
1530 return unrotated_value
;
1532 return ((unrotated_value
>> rotate_amount
)
1533 | (unrotated_value
<< (32 - rotate_amount
)));
1536 /* Analyze an ARM mode prologue starting at PROLOGUE_START and
1537 continuing no further than PROLOGUE_END. If CACHE is non-NULL,
1538 fill it in. Return the first address not recognized as a prologue
1541 We recognize all the instructions typically found in ARM prologues,
1542 plus harmless instructions which can be skipped (either for analysis
1543 purposes, or a more restrictive set that can be skipped when finding
1544 the end of the prologue). */
1547 arm_analyze_prologue (struct gdbarch
*gdbarch
,
1548 CORE_ADDR prologue_start
, CORE_ADDR prologue_end
,
1549 struct arm_prologue_cache
*cache
,
1550 const arm_instruction_reader
&insn_reader
)
1552 enum bfd_endian byte_order_for_code
= gdbarch_byte_order_for_code (gdbarch
);
1554 CORE_ADDR offset
, current_pc
;
1555 pv_t regs
[ARM_FPS_REGNUM
];
1556 CORE_ADDR unrecognized_pc
= 0;
1558 /* Search the prologue looking for instructions that set up the
1559 frame pointer, adjust the stack pointer, and save registers.
1561 Be careful, however, and if it doesn't look like a prologue,
1562 don't try to scan it. If, for instance, a frameless function
1563 begins with stmfd sp!, then we will tell ourselves there is
1564 a frame, which will confuse stack traceback, as well as "finish"
1565 and other operations that rely on a knowledge of the stack
1568 for (regno
= 0; regno
< ARM_FPS_REGNUM
; regno
++)
1569 regs
[regno
] = pv_register (regno
, 0);
1570 pv_area
stack (ARM_SP_REGNUM
, gdbarch_addr_bit (gdbarch
));
1572 for (current_pc
= prologue_start
;
1573 current_pc
< prologue_end
;
1576 uint32_t insn
= insn_reader
.read (current_pc
, byte_order_for_code
);
1578 if (insn
== 0xe1a0c00d) /* mov ip, sp */
1580 regs
[ARM_IP_REGNUM
] = regs
[ARM_SP_REGNUM
];
1583 else if ((insn
& 0xfff00000) == 0xe2800000 /* add Rd, Rn, #n */
1584 && pv_is_register (regs
[bits (insn
, 16, 19)], ARM_SP_REGNUM
))
1586 uint32_t imm
= arm_expand_immediate (insn
& 0xfff);
1587 int rd
= bits (insn
, 12, 15);
1588 regs
[rd
] = pv_add_constant (regs
[bits (insn
, 16, 19)], imm
);
1591 else if ((insn
& 0xfff00000) == 0xe2400000 /* sub Rd, Rn, #n */
1592 && pv_is_register (regs
[bits (insn
, 16, 19)], ARM_SP_REGNUM
))
1594 uint32_t imm
= arm_expand_immediate (insn
& 0xfff);
1595 int rd
= bits (insn
, 12, 15);
1596 regs
[rd
] = pv_add_constant (regs
[bits (insn
, 16, 19)], -imm
);
1599 else if ((insn
& 0xffff0fff) == 0xe52d0004) /* str Rd,
1602 if (stack
.store_would_trash (regs
[ARM_SP_REGNUM
]))
1604 regs
[ARM_SP_REGNUM
] = pv_add_constant (regs
[ARM_SP_REGNUM
], -4);
1605 stack
.store (regs
[ARM_SP_REGNUM
], 4,
1606 regs
[bits (insn
, 12, 15)]);
1609 else if ((insn
& 0xffff0000) == 0xe92d0000)
1610 /* stmfd sp!, {..., fp, ip, lr, pc}
1612 stmfd sp!, {a1, a2, a3, a4} */
1614 int mask
= insn
& 0xffff;
1616 if (stack
.store_would_trash (regs
[ARM_SP_REGNUM
]))
1619 /* Calculate offsets of saved registers. */
1620 for (regno
= ARM_PC_REGNUM
; regno
>= 0; regno
--)
1621 if (mask
& (1 << regno
))
1624 = pv_add_constant (regs
[ARM_SP_REGNUM
], -4);
1625 stack
.store (regs
[ARM_SP_REGNUM
], 4, regs
[regno
]);
1628 else if ((insn
& 0xffff0000) == 0xe54b0000 /* strb rx,[r11,#-n] */
1629 || (insn
& 0xffff00f0) == 0xe14b00b0 /* strh rx,[r11,#-n] */
1630 || (insn
& 0xffffc000) == 0xe50b0000) /* str rx,[r11,#-n] */
1632 /* No need to add this to saved_regs -- it's just an arg reg. */
1635 else if ((insn
& 0xffff0000) == 0xe5cd0000 /* strb rx,[sp,#n] */
1636 || (insn
& 0xffff00f0) == 0xe1cd00b0 /* strh rx,[sp,#n] */
1637 || (insn
& 0xffffc000) == 0xe58d0000) /* str rx,[sp,#n] */
1639 /* No need to add this to saved_regs -- it's just an arg reg. */
1642 else if ((insn
& 0xfff00000) == 0xe8800000 /* stm Rn,
1644 && pv_is_register (regs
[bits (insn
, 16, 19)], ARM_SP_REGNUM
))
1646 /* No need to add this to saved_regs -- it's just arg regs. */
1649 else if ((insn
& 0xfffff000) == 0xe24cb000) /* sub fp, ip #n */
1651 uint32_t imm
= arm_expand_immediate (insn
& 0xfff);
1652 regs
[ARM_FP_REGNUM
] = pv_add_constant (regs
[ARM_IP_REGNUM
], -imm
);
1654 else if ((insn
& 0xfffff000) == 0xe24dd000) /* sub sp, sp #n */
1656 uint32_t imm
= arm_expand_immediate(insn
& 0xfff);
1657 regs
[ARM_SP_REGNUM
] = pv_add_constant (regs
[ARM_SP_REGNUM
], -imm
);
1659 else if ((insn
& 0xffff7fff) == 0xed6d0103 /* stfe f?,
1661 && gdbarch_tdep (gdbarch
)->have_fpa_registers
)
1663 if (stack
.store_would_trash (regs
[ARM_SP_REGNUM
]))
1666 regs
[ARM_SP_REGNUM
] = pv_add_constant (regs
[ARM_SP_REGNUM
], -12);
1667 regno
= ARM_F0_REGNUM
+ ((insn
>> 12) & 0x07);
1668 stack
.store (regs
[ARM_SP_REGNUM
], 12, regs
[regno
]);
1670 else if ((insn
& 0xffbf0fff) == 0xec2d0200 /* sfmfd f0, 4,
1672 && gdbarch_tdep (gdbarch
)->have_fpa_registers
)
1674 int n_saved_fp_regs
;
1675 unsigned int fp_start_reg
, fp_bound_reg
;
1677 if (stack
.store_would_trash (regs
[ARM_SP_REGNUM
]))
1680 if ((insn
& 0x800) == 0x800) /* N0 is set */
1682 if ((insn
& 0x40000) == 0x40000) /* N1 is set */
1683 n_saved_fp_regs
= 3;
1685 n_saved_fp_regs
= 1;
1689 if ((insn
& 0x40000) == 0x40000) /* N1 is set */
1690 n_saved_fp_regs
= 2;
1692 n_saved_fp_regs
= 4;
1695 fp_start_reg
= ARM_F0_REGNUM
+ ((insn
>> 12) & 0x7);
1696 fp_bound_reg
= fp_start_reg
+ n_saved_fp_regs
;
1697 for (; fp_start_reg
< fp_bound_reg
; fp_start_reg
++)
1699 regs
[ARM_SP_REGNUM
] = pv_add_constant (regs
[ARM_SP_REGNUM
], -12);
1700 stack
.store (regs
[ARM_SP_REGNUM
], 12,
1701 regs
[fp_start_reg
++]);
1704 else if ((insn
& 0xff000000) == 0xeb000000 && cache
== NULL
) /* bl */
1706 /* Allow some special function calls when skipping the
1707 prologue; GCC generates these before storing arguments to
1709 CORE_ADDR dest
= BranchDest (current_pc
, insn
);
1711 if (skip_prologue_function (gdbarch
, dest
, 0))
1716 else if ((insn
& 0xf0000000) != 0xe0000000)
1717 break; /* Condition not true, exit early. */
1718 else if (arm_instruction_changes_pc (insn
))
1719 /* Don't scan past anything that might change control flow. */
1721 else if (arm_instruction_restores_sp (insn
))
1723 /* Don't scan past the epilogue. */
1726 else if ((insn
& 0xfe500000) == 0xe8100000 /* ldm */
1727 && pv_is_register (regs
[bits (insn
, 16, 19)], ARM_SP_REGNUM
))
1728 /* Ignore block loads from the stack, potentially copying
1729 parameters from memory. */
1731 else if ((insn
& 0xfc500000) == 0xe4100000
1732 && pv_is_register (regs
[bits (insn
, 16, 19)], ARM_SP_REGNUM
))
1733 /* Similarly ignore single loads from the stack. */
1735 else if ((insn
& 0xffff0ff0) == 0xe1a00000)
1736 /* MOV Rd, Rm. Skip register copies, i.e. saves to another
1737 register instead of the stack. */
1741 /* The optimizer might shove anything into the prologue, if
1742 we build up cache (cache != NULL) from scanning prologue,
1743 we just skip what we don't recognize and scan further to
1744 make cache as complete as possible. However, if we skip
1745 prologue, we'll stop immediately on unrecognized
1747 unrecognized_pc
= current_pc
;
1755 if (unrecognized_pc
== 0)
1756 unrecognized_pc
= current_pc
;
1760 int framereg
, framesize
;
1762 /* The frame size is just the distance from the frame register
1763 to the original stack pointer. */
1764 if (pv_is_register (regs
[ARM_FP_REGNUM
], ARM_SP_REGNUM
))
1766 /* Frame pointer is fp. */
1767 framereg
= ARM_FP_REGNUM
;
1768 framesize
= -regs
[ARM_FP_REGNUM
].k
;
1772 /* Try the stack pointer... this is a bit desperate. */
1773 framereg
= ARM_SP_REGNUM
;
1774 framesize
= -regs
[ARM_SP_REGNUM
].k
;
1777 cache
->framereg
= framereg
;
1778 cache
->framesize
= framesize
;
1780 for (regno
= 0; regno
< ARM_FPS_REGNUM
; regno
++)
1781 if (stack
.find_reg (gdbarch
, regno
, &offset
))
1782 cache
->saved_regs
[regno
].addr
= offset
;
1786 fprintf_unfiltered (gdb_stdlog
, "Prologue scan stopped at %s\n",
1787 paddress (gdbarch
, unrecognized_pc
));
1789 return unrecognized_pc
;
1793 arm_scan_prologue (struct frame_info
*this_frame
,
1794 struct arm_prologue_cache
*cache
)
1796 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1797 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1798 CORE_ADDR prologue_start
, prologue_end
;
1799 CORE_ADDR prev_pc
= get_frame_pc (this_frame
);
1800 CORE_ADDR block_addr
= get_frame_address_in_block (this_frame
);
1802 /* Assume there is no frame until proven otherwise. */
1803 cache
->framereg
= ARM_SP_REGNUM
;
1804 cache
->framesize
= 0;
1806 /* Check for Thumb prologue. */
1807 if (arm_frame_is_thumb (this_frame
))
1809 thumb_scan_prologue (gdbarch
, prev_pc
, block_addr
, cache
);
1813 /* Find the function prologue. If we can't find the function in
1814 the symbol table, peek in the stack frame to find the PC. */
1815 if (find_pc_partial_function (block_addr
, NULL
, &prologue_start
,
1818 /* One way to find the end of the prologue (which works well
1819 for unoptimized code) is to do the following:
1821 struct symtab_and_line sal = find_pc_line (prologue_start, 0);
1824 prologue_end = prev_pc;
1825 else if (sal.end < prologue_end)
1826 prologue_end = sal.end;
1828 This mechanism is very accurate so long as the optimizer
1829 doesn't move any instructions from the function body into the
1830 prologue. If this happens, sal.end will be the last
1831 instruction in the first hunk of prologue code just before
1832 the first instruction that the scheduler has moved from
1833 the body to the prologue.
1835 In order to make sure that we scan all of the prologue
1836 instructions, we use a slightly less accurate mechanism which
1837 may scan more than necessary. To help compensate for this
1838 lack of accuracy, the prologue scanning loop below contains
1839 several clauses which'll cause the loop to terminate early if
1840 an implausible prologue instruction is encountered.
1846 is a suitable endpoint since it accounts for the largest
1847 possible prologue plus up to five instructions inserted by
1850 if (prologue_end
> prologue_start
+ 64)
1852 prologue_end
= prologue_start
+ 64; /* See above. */
1857 /* We have no symbol information. Our only option is to assume this
1858 function has a standard stack frame and the normal frame register.
1859 Then, we can find the value of our frame pointer on entrance to
1860 the callee (or at the present moment if this is the innermost frame).
1861 The value stored there should be the address of the stmfd + 8. */
1862 CORE_ADDR frame_loc
;
1863 ULONGEST return_value
;
1865 /* AAPCS does not use a frame register, so we can abort here. */
1866 if (gdbarch_tdep (gdbarch
)->arm_abi
== ARM_ABI_AAPCS
)
1869 frame_loc
= get_frame_register_unsigned (this_frame
, ARM_FP_REGNUM
);
1870 if (!safe_read_memory_unsigned_integer (frame_loc
, 4, byte_order
,
1875 prologue_start
= gdbarch_addr_bits_remove
1876 (gdbarch
, return_value
) - 8;
1877 prologue_end
= prologue_start
+ 64; /* See above. */
1881 if (prev_pc
< prologue_end
)
1882 prologue_end
= prev_pc
;
1884 arm_analyze_prologue (gdbarch
, prologue_start
, prologue_end
, cache
,
1885 target_arm_instruction_reader ());
1888 static struct arm_prologue_cache
*
1889 arm_make_prologue_cache (struct frame_info
*this_frame
)
1892 struct arm_prologue_cache
*cache
;
1893 CORE_ADDR unwound_fp
;
1895 cache
= FRAME_OBSTACK_ZALLOC (struct arm_prologue_cache
);
1896 cache
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
1898 arm_scan_prologue (this_frame
, cache
);
1900 unwound_fp
= get_frame_register_unsigned (this_frame
, cache
->framereg
);
1901 if (unwound_fp
== 0)
1904 cache
->prev_sp
= unwound_fp
+ cache
->framesize
;
1906 /* Calculate actual addresses of saved registers using offsets
1907 determined by arm_scan_prologue. */
1908 for (reg
= 0; reg
< gdbarch_num_regs (get_frame_arch (this_frame
)); reg
++)
1909 if (trad_frame_addr_p (cache
->saved_regs
, reg
))
1910 cache
->saved_regs
[reg
].addr
+= cache
->prev_sp
;
1915 /* Implementation of the stop_reason hook for arm_prologue frames. */
1917 static enum unwind_stop_reason
1918 arm_prologue_unwind_stop_reason (struct frame_info
*this_frame
,
1921 struct arm_prologue_cache
*cache
;
1924 if (*this_cache
== NULL
)
1925 *this_cache
= arm_make_prologue_cache (this_frame
);
1926 cache
= (struct arm_prologue_cache
*) *this_cache
;
1928 /* This is meant to halt the backtrace at "_start". */
1929 pc
= get_frame_pc (this_frame
);
1930 if (pc
<= gdbarch_tdep (get_frame_arch (this_frame
))->lowest_pc
)
1931 return UNWIND_OUTERMOST
;
1933 /* If we've hit a wall, stop. */
1934 if (cache
->prev_sp
== 0)
1935 return UNWIND_OUTERMOST
;
1937 return UNWIND_NO_REASON
;
1940 /* Our frame ID for a normal frame is the current function's starting PC
1941 and the caller's SP when we were called. */
1944 arm_prologue_this_id (struct frame_info
*this_frame
,
1946 struct frame_id
*this_id
)
1948 struct arm_prologue_cache
*cache
;
1952 if (*this_cache
== NULL
)
1953 *this_cache
= arm_make_prologue_cache (this_frame
);
1954 cache
= (struct arm_prologue_cache
*) *this_cache
;
1956 /* Use function start address as part of the frame ID. If we cannot
1957 identify the start address (due to missing symbol information),
1958 fall back to just using the current PC. */
1959 pc
= get_frame_pc (this_frame
);
1960 func
= get_frame_func (this_frame
);
1964 id
= frame_id_build (cache
->prev_sp
, func
);
1968 static struct value
*
1969 arm_prologue_prev_register (struct frame_info
*this_frame
,
1973 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1974 struct arm_prologue_cache
*cache
;
1976 if (*this_cache
== NULL
)
1977 *this_cache
= arm_make_prologue_cache (this_frame
);
1978 cache
= (struct arm_prologue_cache
*) *this_cache
;
1980 /* If we are asked to unwind the PC, then we need to return the LR
1981 instead. The prologue may save PC, but it will point into this
1982 frame's prologue, not the next frame's resume location. Also
1983 strip the saved T bit. A valid LR may have the low bit set, but
1984 a valid PC never does. */
1985 if (prev_regnum
== ARM_PC_REGNUM
)
1989 lr
= frame_unwind_register_unsigned (this_frame
, ARM_LR_REGNUM
);
1990 return frame_unwind_got_constant (this_frame
, prev_regnum
,
1991 arm_addr_bits_remove (gdbarch
, lr
));
1994 /* SP is generally not saved to the stack, but this frame is
1995 identified by the next frame's stack pointer at the time of the call.
1996 The value was already reconstructed into PREV_SP. */
1997 if (prev_regnum
== ARM_SP_REGNUM
)
1998 return frame_unwind_got_constant (this_frame
, prev_regnum
, cache
->prev_sp
);
2000 /* The CPSR may have been changed by the call instruction and by the
2001 called function. The only bit we can reconstruct is the T bit,
2002 by checking the low bit of LR as of the call. This is a reliable
2003 indicator of Thumb-ness except for some ARM v4T pre-interworking
2004 Thumb code, which could get away with a clear low bit as long as
2005 the called function did not use bx. Guess that all other
2006 bits are unchanged; the condition flags are presumably lost,
2007 but the processor status is likely valid. */
2008 if (prev_regnum
== ARM_PS_REGNUM
)
2011 ULONGEST t_bit
= arm_psr_thumb_bit (gdbarch
);
2013 cpsr
= get_frame_register_unsigned (this_frame
, prev_regnum
);
2014 lr
= frame_unwind_register_unsigned (this_frame
, ARM_LR_REGNUM
);
2015 if (IS_THUMB_ADDR (lr
))
2019 return frame_unwind_got_constant (this_frame
, prev_regnum
, cpsr
);
2022 return trad_frame_get_prev_register (this_frame
, cache
->saved_regs
,
2026 struct frame_unwind arm_prologue_unwind
= {
2028 arm_prologue_unwind_stop_reason
,
2029 arm_prologue_this_id
,
2030 arm_prologue_prev_register
,
2032 default_frame_sniffer
2035 /* Maintain a list of ARM exception table entries per objfile, similar to the
2036 list of mapping symbols. We only cache entries for standard ARM-defined
2037 personality routines; the cache will contain only the frame unwinding
2038 instructions associated with the entry (not the descriptors). */
2040 struct arm_exidx_entry
2045 bool operator< (const arm_exidx_entry
&other
) const
2047 return addr
< other
.addr
;
2051 struct arm_exidx_data
2053 std::vector
<std::vector
<arm_exidx_entry
>> section_maps
;
2056 /* Per-BFD key to store exception handling information. */
2057 static const struct bfd_key
<arm_exidx_data
> arm_exidx_data_key
;
2059 static struct obj_section
*
2060 arm_obj_section_from_vma (struct objfile
*objfile
, bfd_vma vma
)
2062 struct obj_section
*osect
;
2064 ALL_OBJFILE_OSECTIONS (objfile
, osect
)
2065 if (bfd_section_flags (osect
->the_bfd_section
) & SEC_ALLOC
)
2067 bfd_vma start
, size
;
2068 start
= bfd_section_vma (osect
->the_bfd_section
);
2069 size
= bfd_section_size (osect
->the_bfd_section
);
2071 if (start
<= vma
&& vma
< start
+ size
)
2078 /* Parse contents of exception table and exception index sections
2079 of OBJFILE, and fill in the exception table entry cache.
2081 For each entry that refers to a standard ARM-defined personality
2082 routine, extract the frame unwinding instructions (from either
2083 the index or the table section). The unwinding instructions
2085 - extracting them from the rest of the table data
2086 - converting to host endianness
2087 - appending the implicit 0xb0 ("Finish") code
2089 The extracted and normalized instructions are stored for later
2090 retrieval by the arm_find_exidx_entry routine. */
2093 arm_exidx_new_objfile (struct objfile
*objfile
)
2095 struct arm_exidx_data
*data
;
2096 asection
*exidx
, *extab
;
2097 bfd_vma exidx_vma
= 0, extab_vma
= 0;
2100 /* If we've already touched this file, do nothing. */
2101 if (!objfile
|| arm_exidx_data_key
.get (objfile
->obfd
) != NULL
)
2104 /* Read contents of exception table and index. */
2105 exidx
= bfd_get_section_by_name (objfile
->obfd
, ELF_STRING_ARM_unwind
);
2106 gdb::byte_vector exidx_data
;
2109 exidx_vma
= bfd_section_vma (exidx
);
2110 exidx_data
.resize (bfd_section_size (exidx
));
2112 if (!bfd_get_section_contents (objfile
->obfd
, exidx
,
2113 exidx_data
.data (), 0,
2114 exidx_data
.size ()))
2118 extab
= bfd_get_section_by_name (objfile
->obfd
, ".ARM.extab");
2119 gdb::byte_vector extab_data
;
2122 extab_vma
= bfd_section_vma (extab
);
2123 extab_data
.resize (bfd_section_size (extab
));
2125 if (!bfd_get_section_contents (objfile
->obfd
, extab
,
2126 extab_data
.data (), 0,
2127 extab_data
.size ()))
2131 /* Allocate exception table data structure. */
2132 data
= arm_exidx_data_key
.emplace (objfile
->obfd
);
2133 data
->section_maps
.resize (objfile
->obfd
->section_count
);
2135 /* Fill in exception table. */
2136 for (i
= 0; i
< exidx_data
.size () / 8; i
++)
2138 struct arm_exidx_entry new_exidx_entry
;
2139 bfd_vma idx
= bfd_h_get_32 (objfile
->obfd
, exidx_data
.data () + i
* 8);
2140 bfd_vma val
= bfd_h_get_32 (objfile
->obfd
,
2141 exidx_data
.data () + i
* 8 + 4);
2142 bfd_vma addr
= 0, word
= 0;
2143 int n_bytes
= 0, n_words
= 0;
2144 struct obj_section
*sec
;
2145 gdb_byte
*entry
= NULL
;
2147 /* Extract address of start of function. */
2148 idx
= ((idx
& 0x7fffffff) ^ 0x40000000) - 0x40000000;
2149 idx
+= exidx_vma
+ i
* 8;
2151 /* Find section containing function and compute section offset. */
2152 sec
= arm_obj_section_from_vma (objfile
, idx
);
2155 idx
-= bfd_section_vma (sec
->the_bfd_section
);
2157 /* Determine address of exception table entry. */
2160 /* EXIDX_CANTUNWIND -- no exception table entry present. */
2162 else if ((val
& 0xff000000) == 0x80000000)
2164 /* Exception table entry embedded in .ARM.exidx
2165 -- must be short form. */
2169 else if (!(val
& 0x80000000))
2171 /* Exception table entry in .ARM.extab. */
2172 addr
= ((val
& 0x7fffffff) ^ 0x40000000) - 0x40000000;
2173 addr
+= exidx_vma
+ i
* 8 + 4;
2175 if (addr
>= extab_vma
&& addr
+ 4 <= extab_vma
+ extab_data
.size ())
2177 word
= bfd_h_get_32 (objfile
->obfd
,
2178 extab_data
.data () + addr
- extab_vma
);
2181 if ((word
& 0xff000000) == 0x80000000)
2186 else if ((word
& 0xff000000) == 0x81000000
2187 || (word
& 0xff000000) == 0x82000000)
2191 n_words
= ((word
>> 16) & 0xff);
2193 else if (!(word
& 0x80000000))
2196 struct obj_section
*pers_sec
;
2197 int gnu_personality
= 0;
2199 /* Custom personality routine. */
2200 pers
= ((word
& 0x7fffffff) ^ 0x40000000) - 0x40000000;
2201 pers
= UNMAKE_THUMB_ADDR (pers
+ addr
- 4);
2203 /* Check whether we've got one of the variants of the
2204 GNU personality routines. */
2205 pers_sec
= arm_obj_section_from_vma (objfile
, pers
);
2208 static const char *personality
[] =
2210 "__gcc_personality_v0",
2211 "__gxx_personality_v0",
2212 "__gcj_personality_v0",
2213 "__gnu_objc_personality_v0",
2217 CORE_ADDR pc
= pers
+ obj_section_offset (pers_sec
);
2220 for (k
= 0; personality
[k
]; k
++)
2221 if (lookup_minimal_symbol_by_pc_name
2222 (pc
, personality
[k
], objfile
))
2224 gnu_personality
= 1;
2229 /* If so, the next word contains a word count in the high
2230 byte, followed by the same unwind instructions as the
2231 pre-defined forms. */
2233 && addr
+ 4 <= extab_vma
+ extab_data
.size ())
2235 word
= bfd_h_get_32 (objfile
->obfd
,
2237 + addr
- extab_vma
));
2240 n_words
= ((word
>> 24) & 0xff);
2246 /* Sanity check address. */
2248 if (addr
< extab_vma
2249 || addr
+ 4 * n_words
> extab_vma
+ extab_data
.size ())
2250 n_words
= n_bytes
= 0;
2252 /* The unwind instructions reside in WORD (only the N_BYTES least
2253 significant bytes are valid), followed by N_WORDS words in the
2254 extab section starting at ADDR. */
2255 if (n_bytes
|| n_words
)
2258 = (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
,
2259 n_bytes
+ n_words
* 4 + 1);
2262 *p
++ = (gdb_byte
) ((word
>> (8 * n_bytes
)) & 0xff);
2266 word
= bfd_h_get_32 (objfile
->obfd
,
2267 extab_data
.data () + addr
- extab_vma
);
2270 *p
++ = (gdb_byte
) ((word
>> 24) & 0xff);
2271 *p
++ = (gdb_byte
) ((word
>> 16) & 0xff);
2272 *p
++ = (gdb_byte
) ((word
>> 8) & 0xff);
2273 *p
++ = (gdb_byte
) (word
& 0xff);
2276 /* Implied "Finish" to terminate the list. */
2280 /* Push entry onto vector. They are guaranteed to always
2281 appear in order of increasing addresses. */
2282 new_exidx_entry
.addr
= idx
;
2283 new_exidx_entry
.entry
= entry
;
2284 data
->section_maps
[sec
->the_bfd_section
->index
].push_back
2289 /* Search for the exception table entry covering MEMADDR. If one is found,
2290 return a pointer to its data. Otherwise, return 0. If START is non-NULL,
2291 set *START to the start of the region covered by this entry. */
2294 arm_find_exidx_entry (CORE_ADDR memaddr
, CORE_ADDR
*start
)
2296 struct obj_section
*sec
;
2298 sec
= find_pc_section (memaddr
);
2301 struct arm_exidx_data
*data
;
2302 struct arm_exidx_entry map_key
= { memaddr
- obj_section_addr (sec
), 0 };
2304 data
= arm_exidx_data_key
.get (sec
->objfile
->obfd
);
2307 std::vector
<arm_exidx_entry
> &map
2308 = data
->section_maps
[sec
->the_bfd_section
->index
];
2311 auto idx
= std::lower_bound (map
.begin (), map
.end (), map_key
);
2313 /* std::lower_bound finds the earliest ordered insertion
2314 point. If the following symbol starts at this exact
2315 address, we use that; otherwise, the preceding
2316 exception table entry covers this address. */
2317 if (idx
< map
.end ())
2319 if (idx
->addr
== map_key
.addr
)
2322 *start
= idx
->addr
+ obj_section_addr (sec
);
2327 if (idx
> map
.begin ())
2331 *start
= idx
->addr
+ obj_section_addr (sec
);
2341 /* Given the current frame THIS_FRAME, and its associated frame unwinding
2342 instruction list from the ARM exception table entry ENTRY, allocate and
2343 return a prologue cache structure describing how to unwind this frame.
2345 Return NULL if the unwinding instruction list contains a "spare",
2346 "reserved" or "refuse to unwind" instruction as defined in section
2347 "9.3 Frame unwinding instructions" of the "Exception Handling ABI
2348 for the ARM Architecture" document. */
2350 static struct arm_prologue_cache
*
2351 arm_exidx_fill_cache (struct frame_info
*this_frame
, gdb_byte
*entry
)
2356 struct arm_prologue_cache
*cache
;
2357 cache
= FRAME_OBSTACK_ZALLOC (struct arm_prologue_cache
);
2358 cache
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
2364 /* Whenever we reload SP, we actually have to retrieve its
2365 actual value in the current frame. */
2368 if (trad_frame_realreg_p (cache
->saved_regs
, ARM_SP_REGNUM
))
2370 int reg
= cache
->saved_regs
[ARM_SP_REGNUM
].realreg
;
2371 vsp
= get_frame_register_unsigned (this_frame
, reg
);
2375 CORE_ADDR addr
= cache
->saved_regs
[ARM_SP_REGNUM
].addr
;
2376 vsp
= get_frame_memory_unsigned (this_frame
, addr
, 4);
2382 /* Decode next unwind instruction. */
2385 if ((insn
& 0xc0) == 0)
2387 int offset
= insn
& 0x3f;
2388 vsp
+= (offset
<< 2) + 4;
2390 else if ((insn
& 0xc0) == 0x40)
2392 int offset
= insn
& 0x3f;
2393 vsp
-= (offset
<< 2) + 4;
2395 else if ((insn
& 0xf0) == 0x80)
2397 int mask
= ((insn
& 0xf) << 8) | *entry
++;
2400 /* The special case of an all-zero mask identifies
2401 "Refuse to unwind". We return NULL to fall back
2402 to the prologue analyzer. */
2406 /* Pop registers r4..r15 under mask. */
2407 for (i
= 0; i
< 12; i
++)
2408 if (mask
& (1 << i
))
2410 cache
->saved_regs
[4 + i
].addr
= vsp
;
2414 /* Special-case popping SP -- we need to reload vsp. */
2415 if (mask
& (1 << (ARM_SP_REGNUM
- 4)))
2418 else if ((insn
& 0xf0) == 0x90)
2420 int reg
= insn
& 0xf;
2422 /* Reserved cases. */
2423 if (reg
== ARM_SP_REGNUM
|| reg
== ARM_PC_REGNUM
)
2426 /* Set SP from another register and mark VSP for reload. */
2427 cache
->saved_regs
[ARM_SP_REGNUM
] = cache
->saved_regs
[reg
];
2430 else if ((insn
& 0xf0) == 0xa0)
2432 int count
= insn
& 0x7;
2433 int pop_lr
= (insn
& 0x8) != 0;
2436 /* Pop r4..r[4+count]. */
2437 for (i
= 0; i
<= count
; i
++)
2439 cache
->saved_regs
[4 + i
].addr
= vsp
;
2443 /* If indicated by flag, pop LR as well. */
2446 cache
->saved_regs
[ARM_LR_REGNUM
].addr
= vsp
;
2450 else if (insn
== 0xb0)
2452 /* We could only have updated PC by popping into it; if so, it
2453 will show up as address. Otherwise, copy LR into PC. */
2454 if (!trad_frame_addr_p (cache
->saved_regs
, ARM_PC_REGNUM
))
2455 cache
->saved_regs
[ARM_PC_REGNUM
]
2456 = cache
->saved_regs
[ARM_LR_REGNUM
];
2461 else if (insn
== 0xb1)
2463 int mask
= *entry
++;
2466 /* All-zero mask and mask >= 16 is "spare". */
2467 if (mask
== 0 || mask
>= 16)
2470 /* Pop r0..r3 under mask. */
2471 for (i
= 0; i
< 4; i
++)
2472 if (mask
& (1 << i
))
2474 cache
->saved_regs
[i
].addr
= vsp
;
2478 else if (insn
== 0xb2)
2480 ULONGEST offset
= 0;
2485 offset
|= (*entry
& 0x7f) << shift
;
2488 while (*entry
++ & 0x80);
2490 vsp
+= 0x204 + (offset
<< 2);
2492 else if (insn
== 0xb3)
2494 int start
= *entry
>> 4;
2495 int count
= (*entry
++) & 0xf;
2498 /* Only registers D0..D15 are valid here. */
2499 if (start
+ count
>= 16)
2502 /* Pop VFP double-precision registers D[start]..D[start+count]. */
2503 for (i
= 0; i
<= count
; i
++)
2505 cache
->saved_regs
[ARM_D0_REGNUM
+ start
+ i
].addr
= vsp
;
2509 /* Add an extra 4 bytes for FSTMFDX-style stack. */
2512 else if ((insn
& 0xf8) == 0xb8)
2514 int count
= insn
& 0x7;
2517 /* Pop VFP double-precision registers D[8]..D[8+count]. */
2518 for (i
= 0; i
<= count
; i
++)
2520 cache
->saved_regs
[ARM_D0_REGNUM
+ 8 + i
].addr
= vsp
;
2524 /* Add an extra 4 bytes for FSTMFDX-style stack. */
2527 else if (insn
== 0xc6)
2529 int start
= *entry
>> 4;
2530 int count
= (*entry
++) & 0xf;
2533 /* Only registers WR0..WR15 are valid. */
2534 if (start
+ count
>= 16)
2537 /* Pop iwmmx registers WR[start]..WR[start+count]. */
2538 for (i
= 0; i
<= count
; i
++)
2540 cache
->saved_regs
[ARM_WR0_REGNUM
+ start
+ i
].addr
= vsp
;
2544 else if (insn
== 0xc7)
2546 int mask
= *entry
++;
2549 /* All-zero mask and mask >= 16 is "spare". */
2550 if (mask
== 0 || mask
>= 16)
2553 /* Pop iwmmx general-purpose registers WCGR0..WCGR3 under mask. */
2554 for (i
= 0; i
< 4; i
++)
2555 if (mask
& (1 << i
))
2557 cache
->saved_regs
[ARM_WCGR0_REGNUM
+ i
].addr
= vsp
;
2561 else if ((insn
& 0xf8) == 0xc0)
2563 int count
= insn
& 0x7;
2566 /* Pop iwmmx registers WR[10]..WR[10+count]. */
2567 for (i
= 0; i
<= count
; i
++)
2569 cache
->saved_regs
[ARM_WR0_REGNUM
+ 10 + i
].addr
= vsp
;
2573 else if (insn
== 0xc8)
2575 int start
= *entry
>> 4;
2576 int count
= (*entry
++) & 0xf;
2579 /* Only registers D0..D31 are valid. */
2580 if (start
+ count
>= 16)
2583 /* Pop VFP double-precision registers
2584 D[16+start]..D[16+start+count]. */
2585 for (i
= 0; i
<= count
; i
++)
2587 cache
->saved_regs
[ARM_D0_REGNUM
+ 16 + start
+ i
].addr
= vsp
;
2591 else if (insn
== 0xc9)
2593 int start
= *entry
>> 4;
2594 int count
= (*entry
++) & 0xf;
2597 /* Pop VFP double-precision registers D[start]..D[start+count]. */
2598 for (i
= 0; i
<= count
; i
++)
2600 cache
->saved_regs
[ARM_D0_REGNUM
+ start
+ i
].addr
= vsp
;
2604 else if ((insn
& 0xf8) == 0xd0)
2606 int count
= insn
& 0x7;
2609 /* Pop VFP double-precision registers D[8]..D[8+count]. */
2610 for (i
= 0; i
<= count
; i
++)
2612 cache
->saved_regs
[ARM_D0_REGNUM
+ 8 + i
].addr
= vsp
;
2618 /* Everything else is "spare". */
2623 /* If we restore SP from a register, assume this was the frame register.
2624 Otherwise just fall back to SP as frame register. */
2625 if (trad_frame_realreg_p (cache
->saved_regs
, ARM_SP_REGNUM
))
2626 cache
->framereg
= cache
->saved_regs
[ARM_SP_REGNUM
].realreg
;
2628 cache
->framereg
= ARM_SP_REGNUM
;
2630 /* Determine offset to previous frame. */
2632 = vsp
- get_frame_register_unsigned (this_frame
, cache
->framereg
);
2634 /* We already got the previous SP. */
2635 cache
->prev_sp
= vsp
;
2640 /* Unwinding via ARM exception table entries. Note that the sniffer
2641 already computes a filled-in prologue cache, which is then used
2642 with the same arm_prologue_this_id and arm_prologue_prev_register
2643 routines also used for prologue-parsing based unwinding. */
2646 arm_exidx_unwind_sniffer (const struct frame_unwind
*self
,
2647 struct frame_info
*this_frame
,
2648 void **this_prologue_cache
)
2650 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
2651 enum bfd_endian byte_order_for_code
= gdbarch_byte_order_for_code (gdbarch
);
2652 CORE_ADDR addr_in_block
, exidx_region
, func_start
;
2653 struct arm_prologue_cache
*cache
;
2656 /* See if we have an ARM exception table entry covering this address. */
2657 addr_in_block
= get_frame_address_in_block (this_frame
);
2658 entry
= arm_find_exidx_entry (addr_in_block
, &exidx_region
);
2662 /* The ARM exception table does not describe unwind information
2663 for arbitrary PC values, but is guaranteed to be correct only
2664 at call sites. We have to decide here whether we want to use
2665 ARM exception table information for this frame, or fall back
2666 to using prologue parsing. (Note that if we have DWARF CFI,
2667 this sniffer isn't even called -- CFI is always preferred.)
2669 Before we make this decision, however, we check whether we
2670 actually have *symbol* information for the current frame.
2671 If not, prologue parsing would not work anyway, so we might
2672 as well use the exception table and hope for the best. */
2673 if (find_pc_partial_function (addr_in_block
, NULL
, &func_start
, NULL
))
2677 /* If the next frame is "normal", we are at a call site in this
2678 frame, so exception information is guaranteed to be valid. */
2679 if (get_next_frame (this_frame
)
2680 && get_frame_type (get_next_frame (this_frame
)) == NORMAL_FRAME
)
2683 /* We also assume exception information is valid if we're currently
2684 blocked in a system call. The system library is supposed to
2685 ensure this, so that e.g. pthread cancellation works. */
2686 if (arm_frame_is_thumb (this_frame
))
2690 if (safe_read_memory_unsigned_integer (get_frame_pc (this_frame
) - 2,
2691 2, byte_order_for_code
, &insn
)
2692 && (insn
& 0xff00) == 0xdf00 /* svc */)
2699 if (safe_read_memory_unsigned_integer (get_frame_pc (this_frame
) - 4,
2700 4, byte_order_for_code
, &insn
)
2701 && (insn
& 0x0f000000) == 0x0f000000 /* svc */)
2705 /* Bail out if we don't know that exception information is valid. */
2709 /* The ARM exception index does not mark the *end* of the region
2710 covered by the entry, and some functions will not have any entry.
2711 To correctly recognize the end of the covered region, the linker
2712 should have inserted dummy records with a CANTUNWIND marker.
2714 Unfortunately, current versions of GNU ld do not reliably do
2715 this, and thus we may have found an incorrect entry above.
2716 As a (temporary) sanity check, we only use the entry if it
2717 lies *within* the bounds of the function. Note that this check
2718 might reject perfectly valid entries that just happen to cover
2719 multiple functions; therefore this check ought to be removed
2720 once the linker is fixed. */
2721 if (func_start
> exidx_region
)
2725 /* Decode the list of unwinding instructions into a prologue cache.
2726 Note that this may fail due to e.g. a "refuse to unwind" code. */
2727 cache
= arm_exidx_fill_cache (this_frame
, entry
);
2731 *this_prologue_cache
= cache
;
2735 struct frame_unwind arm_exidx_unwind
= {
2737 default_frame_unwind_stop_reason
,
2738 arm_prologue_this_id
,
2739 arm_prologue_prev_register
,
2741 arm_exidx_unwind_sniffer
2744 static struct arm_prologue_cache
*
2745 arm_make_epilogue_frame_cache (struct frame_info
*this_frame
)
2747 struct arm_prologue_cache
*cache
;
2750 cache
= FRAME_OBSTACK_ZALLOC (struct arm_prologue_cache
);
2751 cache
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
2753 /* Still rely on the offset calculated from prologue. */
2754 arm_scan_prologue (this_frame
, cache
);
2756 /* Since we are in epilogue, the SP has been restored. */
2757 cache
->prev_sp
= get_frame_register_unsigned (this_frame
, ARM_SP_REGNUM
);
2759 /* Calculate actual addresses of saved registers using offsets
2760 determined by arm_scan_prologue. */
2761 for (reg
= 0; reg
< gdbarch_num_regs (get_frame_arch (this_frame
)); reg
++)
2762 if (trad_frame_addr_p (cache
->saved_regs
, reg
))
2763 cache
->saved_regs
[reg
].addr
+= cache
->prev_sp
;
2768 /* Implementation of function hook 'this_id' in
2769 'struct frame_uwnind' for epilogue unwinder. */
2772 arm_epilogue_frame_this_id (struct frame_info
*this_frame
,
2774 struct frame_id
*this_id
)
2776 struct arm_prologue_cache
*cache
;
2779 if (*this_cache
== NULL
)
2780 *this_cache
= arm_make_epilogue_frame_cache (this_frame
);
2781 cache
= (struct arm_prologue_cache
*) *this_cache
;
2783 /* Use function start address as part of the frame ID. If we cannot
2784 identify the start address (due to missing symbol information),
2785 fall back to just using the current PC. */
2786 pc
= get_frame_pc (this_frame
);
2787 func
= get_frame_func (this_frame
);
2791 (*this_id
) = frame_id_build (cache
->prev_sp
, pc
);
2794 /* Implementation of function hook 'prev_register' in
2795 'struct frame_uwnind' for epilogue unwinder. */
2797 static struct value
*
2798 arm_epilogue_frame_prev_register (struct frame_info
*this_frame
,
2799 void **this_cache
, int regnum
)
2801 if (*this_cache
== NULL
)
2802 *this_cache
= arm_make_epilogue_frame_cache (this_frame
);
2804 return arm_prologue_prev_register (this_frame
, this_cache
, regnum
);
2807 static int arm_stack_frame_destroyed_p_1 (struct gdbarch
*gdbarch
,
2809 static int thumb_stack_frame_destroyed_p (struct gdbarch
*gdbarch
,
2812 /* Implementation of function hook 'sniffer' in
2813 'struct frame_uwnind' for epilogue unwinder. */
2816 arm_epilogue_frame_sniffer (const struct frame_unwind
*self
,
2817 struct frame_info
*this_frame
,
2818 void **this_prologue_cache
)
2820 if (frame_relative_level (this_frame
) == 0)
2822 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
2823 CORE_ADDR pc
= get_frame_pc (this_frame
);
2825 if (arm_frame_is_thumb (this_frame
))
2826 return thumb_stack_frame_destroyed_p (gdbarch
, pc
);
2828 return arm_stack_frame_destroyed_p_1 (gdbarch
, pc
);
2834 /* Frame unwinder from epilogue. */
2836 static const struct frame_unwind arm_epilogue_frame_unwind
=
2839 default_frame_unwind_stop_reason
,
2840 arm_epilogue_frame_this_id
,
2841 arm_epilogue_frame_prev_register
,
2843 arm_epilogue_frame_sniffer
,
2846 /* Recognize GCC's trampoline for thumb call-indirect. If we are in a
2847 trampoline, return the target PC. Otherwise return 0.
2849 void call0a (char c, short s, int i, long l) {}
2853 (*pointer_to_call0a) (c, s, i, l);
2856 Instead of calling a stub library function _call_via_xx (xx is
2857 the register name), GCC may inline the trampoline in the object
2858 file as below (register r2 has the address of call0a).
2861 .type main, %function
2870 The trampoline 'bx r2' doesn't belong to main. */
2873 arm_skip_bx_reg (struct frame_info
*frame
, CORE_ADDR pc
)
2875 /* The heuristics of recognizing such trampoline is that FRAME is
2876 executing in Thumb mode and the instruction on PC is 'bx Rm'. */
2877 if (arm_frame_is_thumb (frame
))
2881 if (target_read_memory (pc
, buf
, 2) == 0)
2883 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2884 enum bfd_endian byte_order_for_code
2885 = gdbarch_byte_order_for_code (gdbarch
);
2887 = extract_unsigned_integer (buf
, 2, byte_order_for_code
);
2889 if ((insn
& 0xff80) == 0x4700) /* bx <Rm> */
2892 = get_frame_register_unsigned (frame
, bits (insn
, 3, 6));
2894 /* Clear the LSB so that gdb core sets step-resume
2895 breakpoint at the right address. */
2896 return UNMAKE_THUMB_ADDR (dest
);
2904 static struct arm_prologue_cache
*
2905 arm_make_stub_cache (struct frame_info
*this_frame
)
2907 struct arm_prologue_cache
*cache
;
2909 cache
= FRAME_OBSTACK_ZALLOC (struct arm_prologue_cache
);
2910 cache
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
2912 cache
->prev_sp
= get_frame_register_unsigned (this_frame
, ARM_SP_REGNUM
);
2917 /* Our frame ID for a stub frame is the current SP and LR. */
2920 arm_stub_this_id (struct frame_info
*this_frame
,
2922 struct frame_id
*this_id
)
2924 struct arm_prologue_cache
*cache
;
2926 if (*this_cache
== NULL
)
2927 *this_cache
= arm_make_stub_cache (this_frame
);
2928 cache
= (struct arm_prologue_cache
*) *this_cache
;
2930 *this_id
= frame_id_build (cache
->prev_sp
, get_frame_pc (this_frame
));
2934 arm_stub_unwind_sniffer (const struct frame_unwind
*self
,
2935 struct frame_info
*this_frame
,
2936 void **this_prologue_cache
)
2938 CORE_ADDR addr_in_block
;
2940 CORE_ADDR pc
, start_addr
;
2943 addr_in_block
= get_frame_address_in_block (this_frame
);
2944 pc
= get_frame_pc (this_frame
);
2945 if (in_plt_section (addr_in_block
)
2946 /* We also use the stub winder if the target memory is unreadable
2947 to avoid having the prologue unwinder trying to read it. */
2948 || target_read_memory (pc
, dummy
, 4) != 0)
2951 if (find_pc_partial_function (pc
, &name
, &start_addr
, NULL
) == 0
2952 && arm_skip_bx_reg (this_frame
, pc
) != 0)
2958 struct frame_unwind arm_stub_unwind
= {
2960 default_frame_unwind_stop_reason
,
2962 arm_prologue_prev_register
,
2964 arm_stub_unwind_sniffer
2967 /* Put here the code to store, into CACHE->saved_regs, the addresses
2968 of the saved registers of frame described by THIS_FRAME. CACHE is
2971 static struct arm_prologue_cache
*
2972 arm_m_exception_cache (struct frame_info
*this_frame
)
2974 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
2975 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2976 struct arm_prologue_cache
*cache
;
2979 CORE_ADDR unwound_sp
;
2981 uint32_t exc_return
;
2982 uint32_t process_stack_used
;
2983 uint32_t extended_frame_used
;
2984 uint32_t secure_stack_used
;
2986 cache
= FRAME_OBSTACK_ZALLOC (struct arm_prologue_cache
);
2987 cache
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
2989 /* ARMv7-M Architecture Reference "B1.5.6 Exception entry behavior"
2990 describes which bits in LR that define which stack was used prior
2991 to the exception and if FPU is used (causing extended stack frame). */
2993 lr
= get_frame_register_unsigned (this_frame
, ARM_LR_REGNUM
);
2994 sp
= get_frame_register_unsigned (this_frame
, ARM_SP_REGNUM
);
2996 /* Check EXC_RETURN indicator bits. */
2997 exc_return
= (((lr
>> 28) & 0xf) == 0xf);
2999 /* Check EXC_RETURN bit SPSEL if Main or Thread (process) stack used. */
3000 process_stack_used
= ((lr
& (1 << 2)) != 0);
3001 if (exc_return
&& process_stack_used
)
3003 /* Thread (process) stack used.
3004 Potentially this could be other register defined by target, but PSP
3005 can be considered a standard name for the "Process Stack Pointer".
3006 To be fully aware of system registers like MSP and PSP, these could
3007 be added to a separate XML arm-m-system-profile that is valid for
3008 ARMv6-M and ARMv7-M architectures. Also to be able to debug eg a
3009 corefile off-line, then these registers must be defined by GDB,
3010 and also be included in the corefile regsets. */
3012 int psp_regnum
= user_reg_map_name_to_regnum (gdbarch
, "psp", -1);
3013 if (psp_regnum
== -1)
3015 /* Thread (process) stack could not be fetched,
3016 give warning and exit. */
3018 warning (_("no PSP thread stack unwinding supported."));
3020 /* Terminate any further stack unwinding by refer to self. */
3021 cache
->prev_sp
= sp
;
3026 /* Thread (process) stack used, use PSP as SP. */
3027 unwound_sp
= get_frame_register_unsigned (this_frame
, psp_regnum
);
3032 /* Main stack used, use MSP as SP. */
3036 /* The hardware saves eight 32-bit words, comprising xPSR,
3037 ReturnAddress, LR (R14), R12, R3, R2, R1, R0. See details in
3038 "B1.5.6 Exception entry behavior" in
3039 "ARMv7-M Architecture Reference Manual". */
3040 cache
->saved_regs
[0].addr
= unwound_sp
;
3041 cache
->saved_regs
[1].addr
= unwound_sp
+ 4;
3042 cache
->saved_regs
[2].addr
= unwound_sp
+ 8;
3043 cache
->saved_regs
[3].addr
= unwound_sp
+ 12;
3044 cache
->saved_regs
[ARM_IP_REGNUM
].addr
= unwound_sp
+ 16;
3045 cache
->saved_regs
[ARM_LR_REGNUM
].addr
= unwound_sp
+ 20;
3046 cache
->saved_regs
[ARM_PC_REGNUM
].addr
= unwound_sp
+ 24;
3047 cache
->saved_regs
[ARM_PS_REGNUM
].addr
= unwound_sp
+ 28;
3049 /* Check EXC_RETURN bit FTYPE if extended stack frame (FPU regs stored)
3051 extended_frame_used
= ((lr
& (1 << 4)) == 0);
3052 if (exc_return
&& extended_frame_used
)
3055 int fpu_regs_stack_offset
;
3057 /* This code does not take into account the lazy stacking, see "Lazy
3058 context save of FP state", in B1.5.7, also ARM AN298, supported
3059 by Cortex-M4F architecture.
3060 To fully handle this the FPCCR register (Floating-point Context
3061 Control Register) needs to be read out and the bits ASPEN and LSPEN
3062 could be checked to setup correct lazy stacked FP registers.
3063 This register is located at address 0xE000EF34. */
3065 /* Extended stack frame type used. */
3066 fpu_regs_stack_offset
= unwound_sp
+ 0x20;
3067 for (i
= 0; i
< 16; i
++)
3069 cache
->saved_regs
[ARM_D0_REGNUM
+ i
].addr
= fpu_regs_stack_offset
;
3070 fpu_regs_stack_offset
+= 4;
3072 cache
->saved_regs
[ARM_FPSCR_REGNUM
].addr
= unwound_sp
+ 0x60;
3074 /* Offset 0x64 is reserved. */
3075 cache
->prev_sp
= unwound_sp
+ 0x68;
3079 /* Standard stack frame type used. */
3080 cache
->prev_sp
= unwound_sp
+ 0x20;
3083 /* Check EXC_RETURN bit S if Secure or Non-secure stack used. */
3084 secure_stack_used
= ((lr
& (1 << 6)) != 0);
3085 if (exc_return
&& secure_stack_used
)
3087 /* ARMv8-M Exception and interrupt handling is not considered here.
3088 In the ARMv8-M architecture also EXC_RETURN bit S is controlling if
3089 the Secure or Non-secure stack was used. To separate Secure and
3090 Non-secure stacks, processors that are based on the ARMv8-M
3091 architecture support 4 stack pointers: MSP_S, PSP_S, MSP_NS, PSP_NS.
3092 In addition, a stack limit feature is provided using stack limit
3093 registers (accessible using MSR and MRS instructions) in Privileged
3097 /* If bit 9 of the saved xPSR is set, then there is a four-byte
3098 aligner between the top of the 32-byte stack frame and the
3099 previous context's stack pointer. */
3100 if (safe_read_memory_integer (unwound_sp
+ 28, 4, byte_order
, &xpsr
)
3101 && (xpsr
& (1 << 9)) != 0)
3102 cache
->prev_sp
+= 4;
3107 /* Implementation of function hook 'this_id' in
3108 'struct frame_uwnind'. */
3111 arm_m_exception_this_id (struct frame_info
*this_frame
,
3113 struct frame_id
*this_id
)
3115 struct arm_prologue_cache
*cache
;
3117 if (*this_cache
== NULL
)
3118 *this_cache
= arm_m_exception_cache (this_frame
);
3119 cache
= (struct arm_prologue_cache
*) *this_cache
;
3121 /* Our frame ID for a stub frame is the current SP and LR. */
3122 *this_id
= frame_id_build (cache
->prev_sp
,
3123 get_frame_pc (this_frame
));
3126 /* Implementation of function hook 'prev_register' in
3127 'struct frame_uwnind'. */
3129 static struct value
*
3130 arm_m_exception_prev_register (struct frame_info
*this_frame
,
3134 struct arm_prologue_cache
*cache
;
3136 if (*this_cache
== NULL
)
3137 *this_cache
= arm_m_exception_cache (this_frame
);
3138 cache
= (struct arm_prologue_cache
*) *this_cache
;
3140 /* The value was already reconstructed into PREV_SP. */
3141 if (prev_regnum
== ARM_SP_REGNUM
)
3142 return frame_unwind_got_constant (this_frame
, prev_regnum
,
3145 return trad_frame_get_prev_register (this_frame
, cache
->saved_regs
,
3149 /* Implementation of function hook 'sniffer' in
3150 'struct frame_uwnind'. */
3153 arm_m_exception_unwind_sniffer (const struct frame_unwind
*self
,
3154 struct frame_info
*this_frame
,
3155 void **this_prologue_cache
)
3157 CORE_ADDR this_pc
= get_frame_pc (this_frame
);
3159 /* No need to check is_m; this sniffer is only registered for
3160 M-profile architectures. */
3162 /* Check if exception frame returns to a magic PC value. */
3163 return arm_m_addr_is_magic (this_pc
);
3166 /* Frame unwinder for M-profile exceptions. */
3168 struct frame_unwind arm_m_exception_unwind
=
3171 default_frame_unwind_stop_reason
,
3172 arm_m_exception_this_id
,
3173 arm_m_exception_prev_register
,
3175 arm_m_exception_unwind_sniffer
3179 arm_normal_frame_base (struct frame_info
*this_frame
, void **this_cache
)
3181 struct arm_prologue_cache
*cache
;
3183 if (*this_cache
== NULL
)
3184 *this_cache
= arm_make_prologue_cache (this_frame
);
3185 cache
= (struct arm_prologue_cache
*) *this_cache
;
3187 return cache
->prev_sp
- cache
->framesize
;
3190 struct frame_base arm_normal_base
= {
3191 &arm_prologue_unwind
,
3192 arm_normal_frame_base
,
3193 arm_normal_frame_base
,
3194 arm_normal_frame_base
3197 static struct value
*
3198 arm_dwarf2_prev_register (struct frame_info
*this_frame
, void **this_cache
,
3201 struct gdbarch
* gdbarch
= get_frame_arch (this_frame
);
3203 ULONGEST t_bit
= arm_psr_thumb_bit (gdbarch
);
3208 /* The PC is normally copied from the return column, which
3209 describes saves of LR. However, that version may have an
3210 extra bit set to indicate Thumb state. The bit is not
3212 lr
= frame_unwind_register_unsigned (this_frame
, ARM_LR_REGNUM
);
3213 return frame_unwind_got_constant (this_frame
, regnum
,
3214 arm_addr_bits_remove (gdbarch
, lr
));
3217 /* Reconstruct the T bit; see arm_prologue_prev_register for details. */
3218 cpsr
= get_frame_register_unsigned (this_frame
, regnum
);
3219 lr
= frame_unwind_register_unsigned (this_frame
, ARM_LR_REGNUM
);
3220 if (IS_THUMB_ADDR (lr
))
3224 return frame_unwind_got_constant (this_frame
, regnum
, cpsr
);
3227 internal_error (__FILE__
, __LINE__
,
3228 _("Unexpected register %d"), regnum
);
3233 arm_dwarf2_frame_init_reg (struct gdbarch
*gdbarch
, int regnum
,
3234 struct dwarf2_frame_state_reg
*reg
,
3235 struct frame_info
*this_frame
)
3241 reg
->how
= DWARF2_FRAME_REG_FN
;
3242 reg
->loc
.fn
= arm_dwarf2_prev_register
;
3245 reg
->how
= DWARF2_FRAME_REG_CFA
;
3250 /* Implement the stack_frame_destroyed_p gdbarch method. */
3253 thumb_stack_frame_destroyed_p (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
3255 enum bfd_endian byte_order_for_code
= gdbarch_byte_order_for_code (gdbarch
);
3256 unsigned int insn
, insn2
;
3257 int found_return
= 0, found_stack_adjust
= 0;
3258 CORE_ADDR func_start
, func_end
;
3262 if (!find_pc_partial_function (pc
, NULL
, &func_start
, &func_end
))
3265 /* The epilogue is a sequence of instructions along the following lines:
3267 - add stack frame size to SP or FP
3268 - [if frame pointer used] restore SP from FP
3269 - restore registers from SP [may include PC]
3270 - a return-type instruction [if PC wasn't already restored]
3272 In a first pass, we scan forward from the current PC and verify the
3273 instructions we find as compatible with this sequence, ending in a
3276 However, this is not sufficient to distinguish indirect function calls
3277 within a function from indirect tail calls in the epilogue in some cases.
3278 Therefore, if we didn't already find any SP-changing instruction during
3279 forward scan, we add a backward scanning heuristic to ensure we actually
3280 are in the epilogue. */
3283 while (scan_pc
< func_end
&& !found_return
)
3285 if (target_read_memory (scan_pc
, buf
, 2))
3289 insn
= extract_unsigned_integer (buf
, 2, byte_order_for_code
);
3291 if ((insn
& 0xff80) == 0x4700) /* bx <Rm> */
3293 else if (insn
== 0x46f7) /* mov pc, lr */
3295 else if (thumb_instruction_restores_sp (insn
))
3297 if ((insn
& 0xff00) == 0xbd00) /* pop <registers, PC> */
3300 else if (thumb_insn_size (insn
) == 4) /* 32-bit Thumb-2 instruction */
3302 if (target_read_memory (scan_pc
, buf
, 2))
3306 insn2
= extract_unsigned_integer (buf
, 2, byte_order_for_code
);
3308 if (insn
== 0xe8bd) /* ldm.w sp!, <registers> */
3310 if (insn2
& 0x8000) /* <registers> include PC. */
3313 else if (insn
== 0xf85d /* ldr.w <Rt>, [sp], #4 */
3314 && (insn2
& 0x0fff) == 0x0b04)
3316 if ((insn2
& 0xf000) == 0xf000) /* <Rt> is PC. */
3319 else if ((insn
& 0xffbf) == 0xecbd /* vldm sp!, <list> */
3320 && (insn2
& 0x0e00) == 0x0a00)
3332 /* Since any instruction in the epilogue sequence, with the possible
3333 exception of return itself, updates the stack pointer, we need to
3334 scan backwards for at most one instruction. Try either a 16-bit or
3335 a 32-bit instruction. This is just a heuristic, so we do not worry
3336 too much about false positives. */
3338 if (pc
- 4 < func_start
)
3340 if (target_read_memory (pc
- 4, buf
, 4))
3343 insn
= extract_unsigned_integer (buf
, 2, byte_order_for_code
);
3344 insn2
= extract_unsigned_integer (buf
+ 2, 2, byte_order_for_code
);
3346 if (thumb_instruction_restores_sp (insn2
))
3347 found_stack_adjust
= 1;
3348 else if (insn
== 0xe8bd) /* ldm.w sp!, <registers> */
3349 found_stack_adjust
= 1;
3350 else if (insn
== 0xf85d /* ldr.w <Rt>, [sp], #4 */
3351 && (insn2
& 0x0fff) == 0x0b04)
3352 found_stack_adjust
= 1;
3353 else if ((insn
& 0xffbf) == 0xecbd /* vldm sp!, <list> */
3354 && (insn2
& 0x0e00) == 0x0a00)
3355 found_stack_adjust
= 1;
3357 return found_stack_adjust
;
3361 arm_stack_frame_destroyed_p_1 (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
3363 enum bfd_endian byte_order_for_code
= gdbarch_byte_order_for_code (gdbarch
);
3366 CORE_ADDR func_start
, func_end
;
3368 if (!find_pc_partial_function (pc
, NULL
, &func_start
, &func_end
))
3371 /* We are in the epilogue if the previous instruction was a stack
3372 adjustment and the next instruction is a possible return (bx, mov
3373 pc, or pop). We could have to scan backwards to find the stack
3374 adjustment, or forwards to find the return, but this is a decent
3375 approximation. First scan forwards. */
3378 insn
= read_memory_unsigned_integer (pc
, 4, byte_order_for_code
);
3379 if (bits (insn
, 28, 31) != INST_NV
)
3381 if ((insn
& 0x0ffffff0) == 0x012fff10)
3384 else if ((insn
& 0x0ffffff0) == 0x01a0f000)
3387 else if ((insn
& 0x0fff0000) == 0x08bd0000
3388 && (insn
& 0x0000c000) != 0)
3389 /* POP (LDMIA), including PC or LR. */
3396 /* Scan backwards. This is just a heuristic, so do not worry about
3397 false positives from mode changes. */
3399 if (pc
< func_start
+ 4)
3402 insn
= read_memory_unsigned_integer (pc
- 4, 4, byte_order_for_code
);
3403 if (arm_instruction_restores_sp (insn
))
3409 /* Implement the stack_frame_destroyed_p gdbarch method. */
3412 arm_stack_frame_destroyed_p (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
3414 if (arm_pc_is_thumb (gdbarch
, pc
))
3415 return thumb_stack_frame_destroyed_p (gdbarch
, pc
);
3417 return arm_stack_frame_destroyed_p_1 (gdbarch
, pc
);
3420 /* When arguments must be pushed onto the stack, they go on in reverse
3421 order. The code below implements a FILO (stack) to do this. */
3426 struct stack_item
*prev
;
3430 static struct stack_item
*
3431 push_stack_item (struct stack_item
*prev
, const gdb_byte
*contents
, int len
)
3433 struct stack_item
*si
;
3434 si
= XNEW (struct stack_item
);
3435 si
->data
= (gdb_byte
*) xmalloc (len
);
3438 memcpy (si
->data
, contents
, len
);
3442 static struct stack_item
*
3443 pop_stack_item (struct stack_item
*si
)
3445 struct stack_item
*dead
= si
;
3452 /* Implement the gdbarch type alignment method, overrides the generic
3453 alignment algorithm for anything that is arm specific. */
3456 arm_type_align (gdbarch
*gdbarch
, struct type
*t
)
3458 t
= check_typedef (t
);
3459 if (t
->code () == TYPE_CODE_ARRAY
&& t
->is_vector ())
3461 /* Use the natural alignment for vector types (the same for
3462 scalar type), but the maximum alignment is 64-bit. */
3463 if (TYPE_LENGTH (t
) > 8)
3466 return TYPE_LENGTH (t
);
3469 /* Allow the common code to calculate the alignment. */
3473 /* Possible base types for a candidate for passing and returning in
3476 enum arm_vfp_cprc_base_type
3485 /* The length of one element of base type B. */
3488 arm_vfp_cprc_unit_length (enum arm_vfp_cprc_base_type b
)
3492 case VFP_CPRC_SINGLE
:
3494 case VFP_CPRC_DOUBLE
:
3496 case VFP_CPRC_VEC64
:
3498 case VFP_CPRC_VEC128
:
3501 internal_error (__FILE__
, __LINE__
, _("Invalid VFP CPRC type: %d."),
3506 /* The character ('s', 'd' or 'q') for the type of VFP register used
3507 for passing base type B. */
3510 arm_vfp_cprc_reg_char (enum arm_vfp_cprc_base_type b
)
3514 case VFP_CPRC_SINGLE
:
3516 case VFP_CPRC_DOUBLE
:
3518 case VFP_CPRC_VEC64
:
3520 case VFP_CPRC_VEC128
:
3523 internal_error (__FILE__
, __LINE__
, _("Invalid VFP CPRC type: %d."),
3528 /* Determine whether T may be part of a candidate for passing and
3529 returning in VFP registers, ignoring the limit on the total number
3530 of components. If *BASE_TYPE is VFP_CPRC_UNKNOWN, set it to the
3531 classification of the first valid component found; if it is not
3532 VFP_CPRC_UNKNOWN, all components must have the same classification
3533 as *BASE_TYPE. If it is found that T contains a type not permitted
3534 for passing and returning in VFP registers, a type differently
3535 classified from *BASE_TYPE, or two types differently classified
3536 from each other, return -1, otherwise return the total number of
3537 base-type elements found (possibly 0 in an empty structure or
3538 array). Vector types are not currently supported, matching the
3539 generic AAPCS support. */
3542 arm_vfp_cprc_sub_candidate (struct type
*t
,
3543 enum arm_vfp_cprc_base_type
*base_type
)
3545 t
= check_typedef (t
);
3549 switch (TYPE_LENGTH (t
))
3552 if (*base_type
== VFP_CPRC_UNKNOWN
)
3553 *base_type
= VFP_CPRC_SINGLE
;
3554 else if (*base_type
!= VFP_CPRC_SINGLE
)
3559 if (*base_type
== VFP_CPRC_UNKNOWN
)
3560 *base_type
= VFP_CPRC_DOUBLE
;
3561 else if (*base_type
!= VFP_CPRC_DOUBLE
)
3570 case TYPE_CODE_COMPLEX
:
3571 /* Arguments of complex T where T is one of the types float or
3572 double get treated as if they are implemented as:
3581 switch (TYPE_LENGTH (t
))
3584 if (*base_type
== VFP_CPRC_UNKNOWN
)
3585 *base_type
= VFP_CPRC_SINGLE
;
3586 else if (*base_type
!= VFP_CPRC_SINGLE
)
3591 if (*base_type
== VFP_CPRC_UNKNOWN
)
3592 *base_type
= VFP_CPRC_DOUBLE
;
3593 else if (*base_type
!= VFP_CPRC_DOUBLE
)
3602 case TYPE_CODE_ARRAY
:
3604 if (t
->is_vector ())
3606 /* A 64-bit or 128-bit containerized vector type are VFP
3608 switch (TYPE_LENGTH (t
))
3611 if (*base_type
== VFP_CPRC_UNKNOWN
)
3612 *base_type
= VFP_CPRC_VEC64
;
3615 if (*base_type
== VFP_CPRC_UNKNOWN
)
3616 *base_type
= VFP_CPRC_VEC128
;
3627 count
= arm_vfp_cprc_sub_candidate (TYPE_TARGET_TYPE (t
),
3631 if (TYPE_LENGTH (t
) == 0)
3633 gdb_assert (count
== 0);
3636 else if (count
== 0)
3638 unitlen
= arm_vfp_cprc_unit_length (*base_type
);
3639 gdb_assert ((TYPE_LENGTH (t
) % unitlen
) == 0);
3640 return TYPE_LENGTH (t
) / unitlen
;
3645 case TYPE_CODE_STRUCT
:
3650 for (i
= 0; i
< t
->num_fields (); i
++)
3654 if (!field_is_static (&t
->field (i
)))
3655 sub_count
= arm_vfp_cprc_sub_candidate (t
->field (i
).type (),
3657 if (sub_count
== -1)
3661 if (TYPE_LENGTH (t
) == 0)
3663 gdb_assert (count
== 0);
3666 else if (count
== 0)
3668 unitlen
= arm_vfp_cprc_unit_length (*base_type
);
3669 if (TYPE_LENGTH (t
) != unitlen
* count
)
3674 case TYPE_CODE_UNION
:
3679 for (i
= 0; i
< t
->num_fields (); i
++)
3681 int sub_count
= arm_vfp_cprc_sub_candidate (t
->field (i
).type (),
3683 if (sub_count
== -1)
3685 count
= (count
> sub_count
? count
: sub_count
);
3687 if (TYPE_LENGTH (t
) == 0)
3689 gdb_assert (count
== 0);
3692 else if (count
== 0)
3694 unitlen
= arm_vfp_cprc_unit_length (*base_type
);
3695 if (TYPE_LENGTH (t
) != unitlen
* count
)
3707 /* Determine whether T is a VFP co-processor register candidate (CPRC)
3708 if passed to or returned from a non-variadic function with the VFP
3709 ABI in effect. Return 1 if it is, 0 otherwise. If it is, set
3710 *BASE_TYPE to the base type for T and *COUNT to the number of
3711 elements of that base type before returning. */
3714 arm_vfp_call_candidate (struct type
*t
, enum arm_vfp_cprc_base_type
*base_type
,
3717 enum arm_vfp_cprc_base_type b
= VFP_CPRC_UNKNOWN
;
3718 int c
= arm_vfp_cprc_sub_candidate (t
, &b
);
3719 if (c
<= 0 || c
> 4)
3726 /* Return 1 if the VFP ABI should be used for passing arguments to and
3727 returning values from a function of type FUNC_TYPE, 0
3731 arm_vfp_abi_for_function (struct gdbarch
*gdbarch
, struct type
*func_type
)
3733 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
3734 /* Variadic functions always use the base ABI. Assume that functions
3735 without debug info are not variadic. */
3736 if (func_type
&& check_typedef (func_type
)->has_varargs ())
3738 /* The VFP ABI is only supported as a variant of AAPCS. */
3739 if (tdep
->arm_abi
!= ARM_ABI_AAPCS
)
3741 return gdbarch_tdep (gdbarch
)->fp_model
== ARM_FLOAT_VFP
;
3744 /* We currently only support passing parameters in integer registers, which
3745 conforms with GCC's default model, and VFP argument passing following
3746 the VFP variant of AAPCS. Several other variants exist and
3747 we should probably support some of them based on the selected ABI. */
3750 arm_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
3751 struct regcache
*regcache
, CORE_ADDR bp_addr
, int nargs
,
3752 struct value
**args
, CORE_ADDR sp
,
3753 function_call_return_method return_method
,
3754 CORE_ADDR struct_addr
)
3756 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
3760 struct stack_item
*si
= NULL
;
3763 unsigned vfp_regs_free
= (1 << 16) - 1;
3765 /* Determine the type of this function and whether the VFP ABI
3767 ftype
= check_typedef (value_type (function
));
3768 if (ftype
->code () == TYPE_CODE_PTR
)
3769 ftype
= check_typedef (TYPE_TARGET_TYPE (ftype
));
3770 use_vfp_abi
= arm_vfp_abi_for_function (gdbarch
, ftype
);
3772 /* Set the return address. For the ARM, the return breakpoint is
3773 always at BP_ADDR. */
3774 if (arm_pc_is_thumb (gdbarch
, bp_addr
))
3776 regcache_cooked_write_unsigned (regcache
, ARM_LR_REGNUM
, bp_addr
);
3778 /* Walk through the list of args and determine how large a temporary
3779 stack is required. Need to take care here as structs may be
3780 passed on the stack, and we have to push them. */
3783 argreg
= ARM_A1_REGNUM
;
3786 /* The struct_return pointer occupies the first parameter
3787 passing register. */
3788 if (return_method
== return_method_struct
)
3791 fprintf_unfiltered (gdb_stdlog
, "struct return in %s = %s\n",
3792 gdbarch_register_name (gdbarch
, argreg
),
3793 paddress (gdbarch
, struct_addr
));
3794 regcache_cooked_write_unsigned (regcache
, argreg
, struct_addr
);
3798 for (argnum
= 0; argnum
< nargs
; argnum
++)
3801 struct type
*arg_type
;
3802 struct type
*target_type
;
3803 enum type_code typecode
;
3804 const bfd_byte
*val
;
3806 enum arm_vfp_cprc_base_type vfp_base_type
;
3808 int may_use_core_reg
= 1;
3810 arg_type
= check_typedef (value_type (args
[argnum
]));
3811 len
= TYPE_LENGTH (arg_type
);
3812 target_type
= TYPE_TARGET_TYPE (arg_type
);
3813 typecode
= arg_type
->code ();
3814 val
= value_contents (args
[argnum
]);
3816 align
= type_align (arg_type
);
3817 /* Round alignment up to a whole number of words. */
3818 align
= (align
+ ARM_INT_REGISTER_SIZE
- 1)
3819 & ~(ARM_INT_REGISTER_SIZE
- 1);
3820 /* Different ABIs have different maximum alignments. */
3821 if (gdbarch_tdep (gdbarch
)->arm_abi
== ARM_ABI_APCS
)
3823 /* The APCS ABI only requires word alignment. */
3824 align
= ARM_INT_REGISTER_SIZE
;
3828 /* The AAPCS requires at most doubleword alignment. */
3829 if (align
> ARM_INT_REGISTER_SIZE
* 2)
3830 align
= ARM_INT_REGISTER_SIZE
* 2;
3834 && arm_vfp_call_candidate (arg_type
, &vfp_base_type
,
3842 /* Because this is a CPRC it cannot go in a core register or
3843 cause a core register to be skipped for alignment.
3844 Either it goes in VFP registers and the rest of this loop
3845 iteration is skipped for this argument, or it goes on the
3846 stack (and the stack alignment code is correct for this
3848 may_use_core_reg
= 0;
3850 unit_length
= arm_vfp_cprc_unit_length (vfp_base_type
);
3851 shift
= unit_length
/ 4;
3852 mask
= (1 << (shift
* vfp_base_count
)) - 1;
3853 for (regno
= 0; regno
< 16; regno
+= shift
)
3854 if (((vfp_regs_free
>> regno
) & mask
) == mask
)
3863 vfp_regs_free
&= ~(mask
<< regno
);
3864 reg_scaled
= regno
/ shift
;
3865 reg_char
= arm_vfp_cprc_reg_char (vfp_base_type
);
3866 for (i
= 0; i
< vfp_base_count
; i
++)
3870 if (reg_char
== 'q')
3871 arm_neon_quad_write (gdbarch
, regcache
, reg_scaled
+ i
,
3872 val
+ i
* unit_length
);
3875 xsnprintf (name_buf
, sizeof (name_buf
), "%c%d",
3876 reg_char
, reg_scaled
+ i
);
3877 regnum
= user_reg_map_name_to_regnum (gdbarch
, name_buf
,
3879 regcache
->cooked_write (regnum
, val
+ i
* unit_length
);
3886 /* This CPRC could not go in VFP registers, so all VFP
3887 registers are now marked as used. */
3892 /* Push stack padding for doubleword alignment. */
3893 if (nstack
& (align
- 1))
3895 si
= push_stack_item (si
, val
, ARM_INT_REGISTER_SIZE
);
3896 nstack
+= ARM_INT_REGISTER_SIZE
;
3899 /* Doubleword aligned quantities must go in even register pairs. */
3900 if (may_use_core_reg
3901 && argreg
<= ARM_LAST_ARG_REGNUM
3902 && align
> ARM_INT_REGISTER_SIZE
3906 /* If the argument is a pointer to a function, and it is a
3907 Thumb function, create a LOCAL copy of the value and set
3908 the THUMB bit in it. */
3909 if (TYPE_CODE_PTR
== typecode
3910 && target_type
!= NULL
3911 && TYPE_CODE_FUNC
== check_typedef (target_type
)->code ())
3913 CORE_ADDR regval
= extract_unsigned_integer (val
, len
, byte_order
);
3914 if (arm_pc_is_thumb (gdbarch
, regval
))
3916 bfd_byte
*copy
= (bfd_byte
*) alloca (len
);
3917 store_unsigned_integer (copy
, len
, byte_order
,
3918 MAKE_THUMB_ADDR (regval
));
3923 /* Copy the argument to general registers or the stack in
3924 register-sized pieces. Large arguments are split between
3925 registers and stack. */
3928 int partial_len
= len
< ARM_INT_REGISTER_SIZE
3929 ? len
: ARM_INT_REGISTER_SIZE
;
3931 = extract_unsigned_integer (val
, partial_len
, byte_order
);
3933 if (may_use_core_reg
&& argreg
<= ARM_LAST_ARG_REGNUM
)
3935 /* The argument is being passed in a general purpose
3937 if (byte_order
== BFD_ENDIAN_BIG
)
3938 regval
<<= (ARM_INT_REGISTER_SIZE
- partial_len
) * 8;
3940 fprintf_unfiltered (gdb_stdlog
, "arg %d in %s = 0x%s\n",
3942 gdbarch_register_name
3944 phex (regval
, ARM_INT_REGISTER_SIZE
));
3945 regcache_cooked_write_unsigned (regcache
, argreg
, regval
);
3950 gdb_byte buf
[ARM_INT_REGISTER_SIZE
];
3952 memset (buf
, 0, sizeof (buf
));
3953 store_unsigned_integer (buf
, partial_len
, byte_order
, regval
);
3955 /* Push the arguments onto the stack. */
3957 fprintf_unfiltered (gdb_stdlog
, "arg %d @ sp + %d\n",
3959 si
= push_stack_item (si
, buf
, ARM_INT_REGISTER_SIZE
);
3960 nstack
+= ARM_INT_REGISTER_SIZE
;
3967 /* If we have an odd number of words to push, then decrement the stack
3968 by one word now, so first stack argument will be dword aligned. */
3975 write_memory (sp
, si
->data
, si
->len
);
3976 si
= pop_stack_item (si
);
3979 /* Finally, update teh SP register. */
3980 regcache_cooked_write_unsigned (regcache
, ARM_SP_REGNUM
, sp
);
3986 /* Always align the frame to an 8-byte boundary. This is required on
3987 some platforms and harmless on the rest. */
3990 arm_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR sp
)
3992 /* Align the stack to eight bytes. */
3993 return sp
& ~ (CORE_ADDR
) 7;
3997 print_fpu_flags (struct ui_file
*file
, int flags
)
3999 if (flags
& (1 << 0))
4000 fputs_filtered ("IVO ", file
);
4001 if (flags
& (1 << 1))
4002 fputs_filtered ("DVZ ", file
);
4003 if (flags
& (1 << 2))
4004 fputs_filtered ("OFL ", file
);
4005 if (flags
& (1 << 3))
4006 fputs_filtered ("UFL ", file
);
4007 if (flags
& (1 << 4))
4008 fputs_filtered ("INX ", file
);
4009 fputc_filtered ('\n', file
);
4012 /* Print interesting information about the floating point processor
4013 (if present) or emulator. */
4015 arm_print_float_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
4016 struct frame_info
*frame
, const char *args
)
4018 unsigned long status
= get_frame_register_unsigned (frame
, ARM_FPS_REGNUM
);
4021 type
= (status
>> 24) & 127;
4022 if (status
& (1 << 31))
4023 fprintf_filtered (file
, _("Hardware FPU type %d\n"), type
);
4025 fprintf_filtered (file
, _("Software FPU type %d\n"), type
);
4026 /* i18n: [floating point unit] mask */
4027 fputs_filtered (_("mask: "), file
);
4028 print_fpu_flags (file
, status
>> 16);
4029 /* i18n: [floating point unit] flags */
4030 fputs_filtered (_("flags: "), file
);
4031 print_fpu_flags (file
, status
);
4034 /* Construct the ARM extended floating point type. */
4035 static struct type
*
4036 arm_ext_type (struct gdbarch
*gdbarch
)
4038 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
4040 if (!tdep
->arm_ext_type
)
4042 = arch_float_type (gdbarch
, -1, "builtin_type_arm_ext",
4043 floatformats_arm_ext
);
4045 return tdep
->arm_ext_type
;
4048 static struct type
*
4049 arm_neon_double_type (struct gdbarch
*gdbarch
)
4051 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
4053 if (tdep
->neon_double_type
== NULL
)
4055 struct type
*t
, *elem
;
4057 t
= arch_composite_type (gdbarch
, "__gdb_builtin_type_neon_d",
4059 elem
= builtin_type (gdbarch
)->builtin_uint8
;
4060 append_composite_type_field (t
, "u8", init_vector_type (elem
, 8));
4061 elem
= builtin_type (gdbarch
)->builtin_uint16
;
4062 append_composite_type_field (t
, "u16", init_vector_type (elem
, 4));
4063 elem
= builtin_type (gdbarch
)->builtin_uint32
;
4064 append_composite_type_field (t
, "u32", init_vector_type (elem
, 2));
4065 elem
= builtin_type (gdbarch
)->builtin_uint64
;
4066 append_composite_type_field (t
, "u64", elem
);
4067 elem
= builtin_type (gdbarch
)->builtin_float
;
4068 append_composite_type_field (t
, "f32", init_vector_type (elem
, 2));
4069 elem
= builtin_type (gdbarch
)->builtin_double
;
4070 append_composite_type_field (t
, "f64", elem
);
4072 t
->set_is_vector (true);
4073 t
->set_name ("neon_d");
4074 tdep
->neon_double_type
= t
;
4077 return tdep
->neon_double_type
;
4080 /* FIXME: The vector types are not correctly ordered on big-endian
4081 targets. Just as s0 is the low bits of d0, d0[0] is also the low
4082 bits of d0 - regardless of what unit size is being held in d0. So
4083 the offset of the first uint8 in d0 is 7, but the offset of the
4084 first float is 4. This code works as-is for little-endian
4087 static struct type
*
4088 arm_neon_quad_type (struct gdbarch
*gdbarch
)
4090 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
4092 if (tdep
->neon_quad_type
== NULL
)
4094 struct type
*t
, *elem
;
4096 t
= arch_composite_type (gdbarch
, "__gdb_builtin_type_neon_q",
4098 elem
= builtin_type (gdbarch
)->builtin_uint8
;
4099 append_composite_type_field (t
, "u8", init_vector_type (elem
, 16));
4100 elem
= builtin_type (gdbarch
)->builtin_uint16
;
4101 append_composite_type_field (t
, "u16", init_vector_type (elem
, 8));
4102 elem
= builtin_type (gdbarch
)->builtin_uint32
;
4103 append_composite_type_field (t
, "u32", init_vector_type (elem
, 4));
4104 elem
= builtin_type (gdbarch
)->builtin_uint64
;
4105 append_composite_type_field (t
, "u64", init_vector_type (elem
, 2));
4106 elem
= builtin_type (gdbarch
)->builtin_float
;
4107 append_composite_type_field (t
, "f32", init_vector_type (elem
, 4));
4108 elem
= builtin_type (gdbarch
)->builtin_double
;
4109 append_composite_type_field (t
, "f64", init_vector_type (elem
, 2));
4111 t
->set_is_vector (true);
4112 t
->set_name ("neon_q");
4113 tdep
->neon_quad_type
= t
;
4116 return tdep
->neon_quad_type
;
4119 /* Return the GDB type object for the "standard" data type of data in
4122 static struct type
*
4123 arm_register_type (struct gdbarch
*gdbarch
, int regnum
)
4125 int num_regs
= gdbarch_num_regs (gdbarch
);
4127 if (gdbarch_tdep (gdbarch
)->have_vfp_pseudos
4128 && regnum
>= num_regs
&& regnum
< num_regs
+ 32)
4129 return builtin_type (gdbarch
)->builtin_float
;
4131 if (gdbarch_tdep (gdbarch
)->have_neon_pseudos
4132 && regnum
>= num_regs
+ 32 && regnum
< num_regs
+ 32 + 16)
4133 return arm_neon_quad_type (gdbarch
);
4135 /* If the target description has register information, we are only
4136 in this function so that we can override the types of
4137 double-precision registers for NEON. */
4138 if (tdesc_has_registers (gdbarch_target_desc (gdbarch
)))
4140 struct type
*t
= tdesc_register_type (gdbarch
, regnum
);
4142 if (regnum
>= ARM_D0_REGNUM
&& regnum
< ARM_D0_REGNUM
+ 32
4143 && t
->code () == TYPE_CODE_FLT
4144 && gdbarch_tdep (gdbarch
)->have_neon
)
4145 return arm_neon_double_type (gdbarch
);
4150 if (regnum
>= ARM_F0_REGNUM
&& regnum
< ARM_F0_REGNUM
+ NUM_FREGS
)
4152 if (!gdbarch_tdep (gdbarch
)->have_fpa_registers
)
4153 return builtin_type (gdbarch
)->builtin_void
;
4155 return arm_ext_type (gdbarch
);
4157 else if (regnum
== ARM_SP_REGNUM
)
4158 return builtin_type (gdbarch
)->builtin_data_ptr
;
4159 else if (regnum
== ARM_PC_REGNUM
)
4160 return builtin_type (gdbarch
)->builtin_func_ptr
;
4161 else if (regnum
>= ARRAY_SIZE (arm_register_names
))
4162 /* These registers are only supported on targets which supply
4163 an XML description. */
4164 return builtin_type (gdbarch
)->builtin_int0
;
4166 return builtin_type (gdbarch
)->builtin_uint32
;
4169 /* Map a DWARF register REGNUM onto the appropriate GDB register
4173 arm_dwarf_reg_to_regnum (struct gdbarch
*gdbarch
, int reg
)
4175 /* Core integer regs. */
4176 if (reg
>= 0 && reg
<= 15)
4179 /* Legacy FPA encoding. These were once used in a way which
4180 overlapped with VFP register numbering, so their use is
4181 discouraged, but GDB doesn't support the ARM toolchain
4182 which used them for VFP. */
4183 if (reg
>= 16 && reg
<= 23)
4184 return ARM_F0_REGNUM
+ reg
- 16;
4186 /* New assignments for the FPA registers. */
4187 if (reg
>= 96 && reg
<= 103)
4188 return ARM_F0_REGNUM
+ reg
- 96;
4190 /* WMMX register assignments. */
4191 if (reg
>= 104 && reg
<= 111)
4192 return ARM_WCGR0_REGNUM
+ reg
- 104;
4194 if (reg
>= 112 && reg
<= 127)
4195 return ARM_WR0_REGNUM
+ reg
- 112;
4197 if (reg
>= 192 && reg
<= 199)
4198 return ARM_WC0_REGNUM
+ reg
- 192;
4200 /* VFP v2 registers. A double precision value is actually
4201 in d1 rather than s2, but the ABI only defines numbering
4202 for the single precision registers. This will "just work"
4203 in GDB for little endian targets (we'll read eight bytes,
4204 starting in s0 and then progressing to s1), but will be
4205 reversed on big endian targets with VFP. This won't
4206 be a problem for the new Neon quad registers; you're supposed
4207 to use DW_OP_piece for those. */
4208 if (reg
>= 64 && reg
<= 95)
4212 xsnprintf (name_buf
, sizeof (name_buf
), "s%d", reg
- 64);
4213 return user_reg_map_name_to_regnum (gdbarch
, name_buf
,
4217 /* VFP v3 / Neon registers. This range is also used for VFP v2
4218 registers, except that it now describes d0 instead of s0. */
4219 if (reg
>= 256 && reg
<= 287)
4223 xsnprintf (name_buf
, sizeof (name_buf
), "d%d", reg
- 256);
4224 return user_reg_map_name_to_regnum (gdbarch
, name_buf
,
4231 /* Map GDB internal REGNUM onto the Arm simulator register numbers. */
4233 arm_register_sim_regno (struct gdbarch
*gdbarch
, int regnum
)
4236 gdb_assert (reg
>= 0 && reg
< gdbarch_num_regs (gdbarch
));
4238 if (regnum
>= ARM_WR0_REGNUM
&& regnum
<= ARM_WR15_REGNUM
)
4239 return regnum
- ARM_WR0_REGNUM
+ SIM_ARM_IWMMXT_COP0R0_REGNUM
;
4241 if (regnum
>= ARM_WC0_REGNUM
&& regnum
<= ARM_WC7_REGNUM
)
4242 return regnum
- ARM_WC0_REGNUM
+ SIM_ARM_IWMMXT_COP1R0_REGNUM
;
4244 if (regnum
>= ARM_WCGR0_REGNUM
&& regnum
<= ARM_WCGR7_REGNUM
)
4245 return regnum
- ARM_WCGR0_REGNUM
+ SIM_ARM_IWMMXT_COP1R8_REGNUM
;
4247 if (reg
< NUM_GREGS
)
4248 return SIM_ARM_R0_REGNUM
+ reg
;
4251 if (reg
< NUM_FREGS
)
4252 return SIM_ARM_FP0_REGNUM
+ reg
;
4255 if (reg
< NUM_SREGS
)
4256 return SIM_ARM_FPS_REGNUM
+ reg
;
4259 internal_error (__FILE__
, __LINE__
, _("Bad REGNUM %d"), regnum
);
4262 /* Given BUF, which is OLD_LEN bytes ending at ENDADDR, expand
4263 the buffer to be NEW_LEN bytes ending at ENDADDR. Return
4264 NULL if an error occurs. BUF is freed. */
4267 extend_buffer_earlier (gdb_byte
*buf
, CORE_ADDR endaddr
,
4268 int old_len
, int new_len
)
4271 int bytes_to_read
= new_len
- old_len
;
4273 new_buf
= (gdb_byte
*) xmalloc (new_len
);
4274 memcpy (new_buf
+ bytes_to_read
, buf
, old_len
);
4276 if (target_read_code (endaddr
- new_len
, new_buf
, bytes_to_read
) != 0)
4284 /* An IT block is at most the 2-byte IT instruction followed by
4285 four 4-byte instructions. The furthest back we must search to
4286 find an IT block that affects the current instruction is thus
4287 2 + 3 * 4 == 14 bytes. */
4288 #define MAX_IT_BLOCK_PREFIX 14
4290 /* Use a quick scan if there are more than this many bytes of
4292 #define IT_SCAN_THRESHOLD 32
4294 /* Adjust a breakpoint's address to move breakpoints out of IT blocks.
4295 A breakpoint in an IT block may not be hit, depending on the
4298 arm_adjust_breakpoint_address (struct gdbarch
*gdbarch
, CORE_ADDR bpaddr
)
4302 CORE_ADDR boundary
, func_start
;
4304 enum bfd_endian order
= gdbarch_byte_order_for_code (gdbarch
);
4305 int i
, any
, last_it
, last_it_count
;
4307 /* If we are using BKPT breakpoints, none of this is necessary. */
4308 if (gdbarch_tdep (gdbarch
)->thumb2_breakpoint
== NULL
)
4311 /* ARM mode does not have this problem. */
4312 if (!arm_pc_is_thumb (gdbarch
, bpaddr
))
4315 /* We are setting a breakpoint in Thumb code that could potentially
4316 contain an IT block. The first step is to find how much Thumb
4317 code there is; we do not need to read outside of known Thumb
4319 map_type
= arm_find_mapping_symbol (bpaddr
, &boundary
);
4321 /* Thumb-2 code must have mapping symbols to have a chance. */
4324 bpaddr
= gdbarch_addr_bits_remove (gdbarch
, bpaddr
);
4326 if (find_pc_partial_function (bpaddr
, NULL
, &func_start
, NULL
)
4327 && func_start
> boundary
)
4328 boundary
= func_start
;
4330 /* Search for a candidate IT instruction. We have to do some fancy
4331 footwork to distinguish a real IT instruction from the second
4332 half of a 32-bit instruction, but there is no need for that if
4333 there's no candidate. */
4334 buf_len
= std::min (bpaddr
- boundary
, (CORE_ADDR
) MAX_IT_BLOCK_PREFIX
);
4336 /* No room for an IT instruction. */
4339 buf
= (gdb_byte
*) xmalloc (buf_len
);
4340 if (target_read_code (bpaddr
- buf_len
, buf
, buf_len
) != 0)
4343 for (i
= 0; i
< buf_len
; i
+= 2)
4345 unsigned short inst1
= extract_unsigned_integer (&buf
[i
], 2, order
);
4346 if ((inst1
& 0xff00) == 0xbf00 && (inst1
& 0x000f) != 0)
4359 /* OK, the code bytes before this instruction contain at least one
4360 halfword which resembles an IT instruction. We know that it's
4361 Thumb code, but there are still two possibilities. Either the
4362 halfword really is an IT instruction, or it is the second half of
4363 a 32-bit Thumb instruction. The only way we can tell is to
4364 scan forwards from a known instruction boundary. */
4365 if (bpaddr
- boundary
> IT_SCAN_THRESHOLD
)
4369 /* There's a lot of code before this instruction. Start with an
4370 optimistic search; it's easy to recognize halfwords that can
4371 not be the start of a 32-bit instruction, and use that to
4372 lock on to the instruction boundaries. */
4373 buf
= extend_buffer_earlier (buf
, bpaddr
, buf_len
, IT_SCAN_THRESHOLD
);
4376 buf_len
= IT_SCAN_THRESHOLD
;
4379 for (i
= 0; i
< buf_len
- sizeof (buf
) && ! definite
; i
+= 2)
4381 unsigned short inst1
= extract_unsigned_integer (&buf
[i
], 2, order
);
4382 if (thumb_insn_size (inst1
) == 2)
4389 /* At this point, if DEFINITE, BUF[I] is the first place we
4390 are sure that we know the instruction boundaries, and it is far
4391 enough from BPADDR that we could not miss an IT instruction
4392 affecting BPADDR. If ! DEFINITE, give up - start from a
4396 buf
= extend_buffer_earlier (buf
, bpaddr
, buf_len
,
4400 buf_len
= bpaddr
- boundary
;
4406 buf
= extend_buffer_earlier (buf
, bpaddr
, buf_len
, bpaddr
- boundary
);
4409 buf_len
= bpaddr
- boundary
;
4413 /* Scan forwards. Find the last IT instruction before BPADDR. */
4418 unsigned short inst1
= extract_unsigned_integer (&buf
[i
], 2, order
);
4420 if ((inst1
& 0xff00) == 0xbf00 && (inst1
& 0x000f) != 0)
4425 else if (inst1
& 0x0002)
4427 else if (inst1
& 0x0004)
4432 i
+= thumb_insn_size (inst1
);
4438 /* There wasn't really an IT instruction after all. */
4441 if (last_it_count
< 1)
4442 /* It was too far away. */
4445 /* This really is a trouble spot. Move the breakpoint to the IT
4447 return bpaddr
- buf_len
+ last_it
;
4450 /* ARM displaced stepping support.
4452 Generally ARM displaced stepping works as follows:
4454 1. When an instruction is to be single-stepped, it is first decoded by
4455 arm_process_displaced_insn. Depending on the type of instruction, it is
4456 then copied to a scratch location, possibly in a modified form. The
4457 copy_* set of functions performs such modification, as necessary. A
4458 breakpoint is placed after the modified instruction in the scratch space
4459 to return control to GDB. Note in particular that instructions which
4460 modify the PC will no longer do so after modification.
4462 2. The instruction is single-stepped, by setting the PC to the scratch
4463 location address, and resuming. Control returns to GDB when the
4466 3. A cleanup function (cleanup_*) is called corresponding to the copy_*
4467 function used for the current instruction. This function's job is to
4468 put the CPU/memory state back to what it would have been if the
4469 instruction had been executed unmodified in its original location. */
4471 /* NOP instruction (mov r0, r0). */
4472 #define ARM_NOP 0xe1a00000
4473 #define THUMB_NOP 0x4600
4475 /* Helper for register reads for displaced stepping. In particular, this
4476 returns the PC as it would be seen by the instruction at its original
4480 displaced_read_reg (regcache
*regs
, arm_displaced_step_copy_insn_closure
*dsc
,
4484 CORE_ADDR from
= dsc
->insn_addr
;
4486 if (regno
== ARM_PC_REGNUM
)
4488 /* Compute pipeline offset:
4489 - When executing an ARM instruction, PC reads as the address of the
4490 current instruction plus 8.
4491 - When executing a Thumb instruction, PC reads as the address of the
4492 current instruction plus 4. */
4499 displaced_debug_printf ("read pc value %.8lx",
4500 (unsigned long) from
);
4501 return (ULONGEST
) from
;
4505 regcache_cooked_read_unsigned (regs
, regno
, &ret
);
4507 displaced_debug_printf ("read r%d value %.8lx",
4508 regno
, (unsigned long) ret
);
4515 displaced_in_arm_mode (struct regcache
*regs
)
4518 ULONGEST t_bit
= arm_psr_thumb_bit (regs
->arch ());
4520 regcache_cooked_read_unsigned (regs
, ARM_PS_REGNUM
, &ps
);
4522 return (ps
& t_bit
) == 0;
4525 /* Write to the PC as from a branch instruction. */
4528 branch_write_pc (regcache
*regs
, arm_displaced_step_copy_insn_closure
*dsc
,
4532 /* Note: If bits 0/1 are set, this branch would be unpredictable for
4533 architecture versions < 6. */
4534 regcache_cooked_write_unsigned (regs
, ARM_PC_REGNUM
,
4535 val
& ~(ULONGEST
) 0x3);
4537 regcache_cooked_write_unsigned (regs
, ARM_PC_REGNUM
,
4538 val
& ~(ULONGEST
) 0x1);
4541 /* Write to the PC as from a branch-exchange instruction. */
4544 bx_write_pc (struct regcache
*regs
, ULONGEST val
)
4547 ULONGEST t_bit
= arm_psr_thumb_bit (regs
->arch ());
4549 regcache_cooked_read_unsigned (regs
, ARM_PS_REGNUM
, &ps
);
4553 regcache_cooked_write_unsigned (regs
, ARM_PS_REGNUM
, ps
| t_bit
);
4554 regcache_cooked_write_unsigned (regs
, ARM_PC_REGNUM
, val
& 0xfffffffe);
4556 else if ((val
& 2) == 0)
4558 regcache_cooked_write_unsigned (regs
, ARM_PS_REGNUM
, ps
& ~t_bit
);
4559 regcache_cooked_write_unsigned (regs
, ARM_PC_REGNUM
, val
);
4563 /* Unpredictable behaviour. Try to do something sensible (switch to ARM
4564 mode, align dest to 4 bytes). */
4565 warning (_("Single-stepping BX to non-word-aligned ARM instruction."));
4566 regcache_cooked_write_unsigned (regs
, ARM_PS_REGNUM
, ps
& ~t_bit
);
4567 regcache_cooked_write_unsigned (regs
, ARM_PC_REGNUM
, val
& 0xfffffffc);
4571 /* Write to the PC as if from a load instruction. */
4574 load_write_pc (regcache
*regs
, arm_displaced_step_copy_insn_closure
*dsc
,
4577 if (DISPLACED_STEPPING_ARCH_VERSION
>= 5)
4578 bx_write_pc (regs
, val
);
4580 branch_write_pc (regs
, dsc
, val
);
4583 /* Write to the PC as if from an ALU instruction. */
4586 alu_write_pc (regcache
*regs
, arm_displaced_step_copy_insn_closure
*dsc
,
4589 if (DISPLACED_STEPPING_ARCH_VERSION
>= 7 && !dsc
->is_thumb
)
4590 bx_write_pc (regs
, val
);
4592 branch_write_pc (regs
, dsc
, val
);
4595 /* Helper for writing to registers for displaced stepping. Writing to the PC
4596 has a varying effects depending on the instruction which does the write:
4597 this is controlled by the WRITE_PC argument. */
4600 displaced_write_reg (regcache
*regs
, arm_displaced_step_copy_insn_closure
*dsc
,
4601 int regno
, ULONGEST val
, enum pc_write_style write_pc
)
4603 if (regno
== ARM_PC_REGNUM
)
4605 displaced_debug_printf ("writing pc %.8lx", (unsigned long) val
);
4609 case BRANCH_WRITE_PC
:
4610 branch_write_pc (regs
, dsc
, val
);
4614 bx_write_pc (regs
, val
);
4618 load_write_pc (regs
, dsc
, val
);
4622 alu_write_pc (regs
, dsc
, val
);
4625 case CANNOT_WRITE_PC
:
4626 warning (_("Instruction wrote to PC in an unexpected way when "
4627 "single-stepping"));
4631 internal_error (__FILE__
, __LINE__
,
4632 _("Invalid argument to displaced_write_reg"));
4635 dsc
->wrote_to_pc
= 1;
4639 displaced_debug_printf ("writing r%d value %.8lx",
4640 regno
, (unsigned long) val
);
4641 regcache_cooked_write_unsigned (regs
, regno
, val
);
4645 /* This function is used to concisely determine if an instruction INSN
4646 references PC. Register fields of interest in INSN should have the
4647 corresponding fields of BITMASK set to 0b1111. The function
4648 returns return 1 if any of these fields in INSN reference the PC
4649 (also 0b1111, r15), else it returns 0. */
4652 insn_references_pc (uint32_t insn
, uint32_t bitmask
)
4654 uint32_t lowbit
= 1;
4656 while (bitmask
!= 0)
4660 for (; lowbit
&& (bitmask
& lowbit
) == 0; lowbit
<<= 1)
4666 mask
= lowbit
* 0xf;
4668 if ((insn
& mask
) == mask
)
4677 /* The simplest copy function. Many instructions have the same effect no
4678 matter what address they are executed at: in those cases, use this. */
4681 arm_copy_unmodified (struct gdbarch
*gdbarch
, uint32_t insn
, const char *iname
,
4682 arm_displaced_step_copy_insn_closure
*dsc
)
4684 displaced_debug_printf ("copying insn %.8lx, opcode/class '%s' unmodified",
4685 (unsigned long) insn
, iname
);
4687 dsc
->modinsn
[0] = insn
;
4693 thumb_copy_unmodified_32bit (struct gdbarch
*gdbarch
, uint16_t insn1
,
4694 uint16_t insn2
, const char *iname
,
4695 arm_displaced_step_copy_insn_closure
*dsc
)
4697 displaced_debug_printf ("copying insn %.4x %.4x, opcode/class '%s' "
4698 "unmodified", insn1
, insn2
, iname
);
4700 dsc
->modinsn
[0] = insn1
;
4701 dsc
->modinsn
[1] = insn2
;
4707 /* Copy 16-bit Thumb(Thumb and 16-bit Thumb-2) instruction without any
4710 thumb_copy_unmodified_16bit (struct gdbarch
*gdbarch
, uint16_t insn
,
4712 arm_displaced_step_copy_insn_closure
*dsc
)
4714 displaced_debug_printf ("copying insn %.4x, opcode/class '%s' unmodified",
4717 dsc
->modinsn
[0] = insn
;
4722 /* Preload instructions with immediate offset. */
4725 cleanup_preload (struct gdbarch
*gdbarch
, regcache
*regs
,
4726 arm_displaced_step_copy_insn_closure
*dsc
)
4728 displaced_write_reg (regs
, dsc
, 0, dsc
->tmp
[0], CANNOT_WRITE_PC
);
4729 if (!dsc
->u
.preload
.immed
)
4730 displaced_write_reg (regs
, dsc
, 1, dsc
->tmp
[1], CANNOT_WRITE_PC
);
4734 install_preload (struct gdbarch
*gdbarch
, struct regcache
*regs
,
4735 arm_displaced_step_copy_insn_closure
*dsc
, unsigned int rn
)
4738 /* Preload instructions:
4740 {pli/pld} [rn, #+/-imm]
4742 {pli/pld} [r0, #+/-imm]. */
4744 dsc
->tmp
[0] = displaced_read_reg (regs
, dsc
, 0);
4745 rn_val
= displaced_read_reg (regs
, dsc
, rn
);
4746 displaced_write_reg (regs
, dsc
, 0, rn_val
, CANNOT_WRITE_PC
);
4747 dsc
->u
.preload
.immed
= 1;
4749 dsc
->cleanup
= &cleanup_preload
;
4753 arm_copy_preload (struct gdbarch
*gdbarch
, uint32_t insn
, struct regcache
*regs
,
4754 arm_displaced_step_copy_insn_closure
*dsc
)
4756 unsigned int rn
= bits (insn
, 16, 19);
4758 if (!insn_references_pc (insn
, 0x000f0000ul
))
4759 return arm_copy_unmodified (gdbarch
, insn
, "preload", dsc
);
4761 displaced_debug_printf ("copying preload insn %.8lx", (unsigned long) insn
);
4763 dsc
->modinsn
[0] = insn
& 0xfff0ffff;
4765 install_preload (gdbarch
, regs
, dsc
, rn
);
4771 thumb2_copy_preload (struct gdbarch
*gdbarch
, uint16_t insn1
, uint16_t insn2
,
4772 regcache
*regs
, arm_displaced_step_copy_insn_closure
*dsc
)
4774 unsigned int rn
= bits (insn1
, 0, 3);
4775 unsigned int u_bit
= bit (insn1
, 7);
4776 int imm12
= bits (insn2
, 0, 11);
4779 if (rn
!= ARM_PC_REGNUM
)
4780 return thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
, "preload", dsc
);
4782 /* PC is only allowed to use in PLI (immediate,literal) Encoding T3, and
4783 PLD (literal) Encoding T1. */
4784 displaced_debug_printf ("copying pld/pli pc (0x%x) %c imm12 %.4x",
4785 (unsigned int) dsc
->insn_addr
, u_bit
? '+' : '-',
4791 /* Rewrite instruction {pli/pld} PC imm12 into:
4792 Prepare: tmp[0] <- r0, tmp[1] <- r1, r0 <- pc, r1 <- imm12
4796 Cleanup: r0 <- tmp[0], r1 <- tmp[1]. */
4798 dsc
->tmp
[0] = displaced_read_reg (regs
, dsc
, 0);
4799 dsc
->tmp
[1] = displaced_read_reg (regs
, dsc
, 1);
4801 pc_val
= displaced_read_reg (regs
, dsc
, ARM_PC_REGNUM
);
4803 displaced_write_reg (regs
, dsc
, 0, pc_val
, CANNOT_WRITE_PC
);
4804 displaced_write_reg (regs
, dsc
, 1, imm12
, CANNOT_WRITE_PC
);
4805 dsc
->u
.preload
.immed
= 0;
4807 /* {pli/pld} [r0, r1] */
4808 dsc
->modinsn
[0] = insn1
& 0xfff0;
4809 dsc
->modinsn
[1] = 0xf001;
4812 dsc
->cleanup
= &cleanup_preload
;
4816 /* Preload instructions with register offset. */
4819 install_preload_reg(struct gdbarch
*gdbarch
, struct regcache
*regs
,
4820 arm_displaced_step_copy_insn_closure
*dsc
, unsigned int rn
,
4823 ULONGEST rn_val
, rm_val
;
4825 /* Preload register-offset instructions:
4827 {pli/pld} [rn, rm {, shift}]
4829 {pli/pld} [r0, r1 {, shift}]. */
4831 dsc
->tmp
[0] = displaced_read_reg (regs
, dsc
, 0);
4832 dsc
->tmp
[1] = displaced_read_reg (regs
, dsc
, 1);
4833 rn_val
= displaced_read_reg (regs
, dsc
, rn
);
4834 rm_val
= displaced_read_reg (regs
, dsc
, rm
);
4835 displaced_write_reg (regs
, dsc
, 0, rn_val
, CANNOT_WRITE_PC
);
4836 displaced_write_reg (regs
, dsc
, 1, rm_val
, CANNOT_WRITE_PC
);
4837 dsc
->u
.preload
.immed
= 0;
4839 dsc
->cleanup
= &cleanup_preload
;
4843 arm_copy_preload_reg (struct gdbarch
*gdbarch
, uint32_t insn
,
4844 struct regcache
*regs
,
4845 arm_displaced_step_copy_insn_closure
*dsc
)
4847 unsigned int rn
= bits (insn
, 16, 19);
4848 unsigned int rm
= bits (insn
, 0, 3);
4851 if (!insn_references_pc (insn
, 0x000f000ful
))
4852 return arm_copy_unmodified (gdbarch
, insn
, "preload reg", dsc
);
4854 displaced_debug_printf ("copying preload insn %.8lx",
4855 (unsigned long) insn
);
4857 dsc
->modinsn
[0] = (insn
& 0xfff0fff0) | 0x1;
4859 install_preload_reg (gdbarch
, regs
, dsc
, rn
, rm
);
4863 /* Copy/cleanup coprocessor load and store instructions. */
4866 cleanup_copro_load_store (struct gdbarch
*gdbarch
,
4867 struct regcache
*regs
,
4868 arm_displaced_step_copy_insn_closure
*dsc
)
4870 ULONGEST rn_val
= displaced_read_reg (regs
, dsc
, 0);
4872 displaced_write_reg (regs
, dsc
, 0, dsc
->tmp
[0], CANNOT_WRITE_PC
);
4874 if (dsc
->u
.ldst
.writeback
)
4875 displaced_write_reg (regs
, dsc
, dsc
->u
.ldst
.rn
, rn_val
, LOAD_WRITE_PC
);
4879 install_copro_load_store (struct gdbarch
*gdbarch
, struct regcache
*regs
,
4880 arm_displaced_step_copy_insn_closure
*dsc
,
4881 int writeback
, unsigned int rn
)
4885 /* Coprocessor load/store instructions:
4887 {stc/stc2} [<Rn>, #+/-imm] (and other immediate addressing modes)
4889 {stc/stc2} [r0, #+/-imm].
4891 ldc/ldc2 are handled identically. */
4893 dsc
->tmp
[0] = displaced_read_reg (regs
, dsc
, 0);
4894 rn_val
= displaced_read_reg (regs
, dsc
, rn
);
4895 /* PC should be 4-byte aligned. */
4896 rn_val
= rn_val
& 0xfffffffc;
4897 displaced_write_reg (regs
, dsc
, 0, rn_val
, CANNOT_WRITE_PC
);
4899 dsc
->u
.ldst
.writeback
= writeback
;
4900 dsc
->u
.ldst
.rn
= rn
;
4902 dsc
->cleanup
= &cleanup_copro_load_store
;
4906 arm_copy_copro_load_store (struct gdbarch
*gdbarch
, uint32_t insn
,
4907 struct regcache
*regs
,
4908 arm_displaced_step_copy_insn_closure
*dsc
)
4910 unsigned int rn
= bits (insn
, 16, 19);
4912 if (!insn_references_pc (insn
, 0x000f0000ul
))
4913 return arm_copy_unmodified (gdbarch
, insn
, "copro load/store", dsc
);
4915 displaced_debug_printf ("copying coprocessor load/store insn %.8lx",
4916 (unsigned long) insn
);
4918 dsc
->modinsn
[0] = insn
& 0xfff0ffff;
4920 install_copro_load_store (gdbarch
, regs
, dsc
, bit (insn
, 25), rn
);
4926 thumb2_copy_copro_load_store (struct gdbarch
*gdbarch
, uint16_t insn1
,
4927 uint16_t insn2
, struct regcache
*regs
,
4928 arm_displaced_step_copy_insn_closure
*dsc
)
4930 unsigned int rn
= bits (insn1
, 0, 3);
4932 if (rn
!= ARM_PC_REGNUM
)
4933 return thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
,
4934 "copro load/store", dsc
);
4936 displaced_debug_printf ("copying coprocessor load/store insn %.4x%.4x",
4939 dsc
->modinsn
[0] = insn1
& 0xfff0;
4940 dsc
->modinsn
[1] = insn2
;
4943 /* This function is called for copying instruction LDC/LDC2/VLDR, which
4944 doesn't support writeback, so pass 0. */
4945 install_copro_load_store (gdbarch
, regs
, dsc
, 0, rn
);
4950 /* Clean up branch instructions (actually perform the branch, by setting
4954 cleanup_branch (struct gdbarch
*gdbarch
, struct regcache
*regs
,
4955 arm_displaced_step_copy_insn_closure
*dsc
)
4957 uint32_t status
= displaced_read_reg (regs
, dsc
, ARM_PS_REGNUM
);
4958 int branch_taken
= condition_true (dsc
->u
.branch
.cond
, status
);
4959 enum pc_write_style write_pc
= dsc
->u
.branch
.exchange
4960 ? BX_WRITE_PC
: BRANCH_WRITE_PC
;
4965 if (dsc
->u
.branch
.link
)
4967 /* The value of LR should be the next insn of current one. In order
4968 not to confuse logic handling later insn `bx lr', if current insn mode
4969 is Thumb, the bit 0 of LR value should be set to 1. */
4970 ULONGEST next_insn_addr
= dsc
->insn_addr
+ dsc
->insn_size
;
4973 next_insn_addr
|= 0x1;
4975 displaced_write_reg (regs
, dsc
, ARM_LR_REGNUM
, next_insn_addr
,
4979 displaced_write_reg (regs
, dsc
, ARM_PC_REGNUM
, dsc
->u
.branch
.dest
, write_pc
);
4982 /* Copy B/BL/BLX instructions with immediate destinations. */
4985 install_b_bl_blx (struct gdbarch
*gdbarch
, struct regcache
*regs
,
4986 arm_displaced_step_copy_insn_closure
*dsc
,
4987 unsigned int cond
, int exchange
, int link
, long offset
)
4989 /* Implement "BL<cond> <label>" as:
4991 Preparation: cond <- instruction condition
4992 Insn: mov r0, r0 (nop)
4993 Cleanup: if (condition true) { r14 <- pc; pc <- label }.
4995 B<cond> similar, but don't set r14 in cleanup. */
4997 dsc
->u
.branch
.cond
= cond
;
4998 dsc
->u
.branch
.link
= link
;
4999 dsc
->u
.branch
.exchange
= exchange
;
5001 dsc
->u
.branch
.dest
= dsc
->insn_addr
;
5002 if (link
&& exchange
)
5003 /* For BLX, offset is computed from the Align (PC, 4). */
5004 dsc
->u
.branch
.dest
= dsc
->u
.branch
.dest
& 0xfffffffc;
5007 dsc
->u
.branch
.dest
+= 4 + offset
;
5009 dsc
->u
.branch
.dest
+= 8 + offset
;
5011 dsc
->cleanup
= &cleanup_branch
;
5014 arm_copy_b_bl_blx (struct gdbarch
*gdbarch
, uint32_t insn
,
5015 regcache
*regs
, arm_displaced_step_copy_insn_closure
*dsc
)
5017 unsigned int cond
= bits (insn
, 28, 31);
5018 int exchange
= (cond
== 0xf);
5019 int link
= exchange
|| bit (insn
, 24);
5022 displaced_debug_printf ("copying %s immediate insn %.8lx",
5023 (exchange
) ? "blx" : (link
) ? "bl" : "b",
5024 (unsigned long) insn
);
5026 /* For BLX, set bit 0 of the destination. The cleanup_branch function will
5027 then arrange the switch into Thumb mode. */
5028 offset
= (bits (insn
, 0, 23) << 2) | (bit (insn
, 24) << 1) | 1;
5030 offset
= bits (insn
, 0, 23) << 2;
5032 if (bit (offset
, 25))
5033 offset
= offset
| ~0x3ffffff;
5035 dsc
->modinsn
[0] = ARM_NOP
;
5037 install_b_bl_blx (gdbarch
, regs
, dsc
, cond
, exchange
, link
, offset
);
5042 thumb2_copy_b_bl_blx (struct gdbarch
*gdbarch
, uint16_t insn1
,
5043 uint16_t insn2
, struct regcache
*regs
,
5044 arm_displaced_step_copy_insn_closure
*dsc
)
5046 int link
= bit (insn2
, 14);
5047 int exchange
= link
&& !bit (insn2
, 12);
5050 int j1
= bit (insn2
, 13);
5051 int j2
= bit (insn2
, 11);
5052 int s
= sbits (insn1
, 10, 10);
5053 int i1
= !(j1
^ bit (insn1
, 10));
5054 int i2
= !(j2
^ bit (insn1
, 10));
5056 if (!link
&& !exchange
) /* B */
5058 offset
= (bits (insn2
, 0, 10) << 1);
5059 if (bit (insn2
, 12)) /* Encoding T4 */
5061 offset
|= (bits (insn1
, 0, 9) << 12)
5067 else /* Encoding T3 */
5069 offset
|= (bits (insn1
, 0, 5) << 12)
5073 cond
= bits (insn1
, 6, 9);
5078 offset
= (bits (insn1
, 0, 9) << 12);
5079 offset
|= ((i2
<< 22) | (i1
<< 23) | (s
<< 24));
5080 offset
|= exchange
?
5081 (bits (insn2
, 1, 10) << 2) : (bits (insn2
, 0, 10) << 1);
5084 displaced_debug_printf ("copying %s insn %.4x %.4x with offset %.8lx",
5085 link
? (exchange
) ? "blx" : "bl" : "b",
5086 insn1
, insn2
, offset
);
5088 dsc
->modinsn
[0] = THUMB_NOP
;
5090 install_b_bl_blx (gdbarch
, regs
, dsc
, cond
, exchange
, link
, offset
);
5094 /* Copy B Thumb instructions. */
5096 thumb_copy_b (struct gdbarch
*gdbarch
, uint16_t insn
,
5097 arm_displaced_step_copy_insn_closure
*dsc
)
5099 unsigned int cond
= 0;
5101 unsigned short bit_12_15
= bits (insn
, 12, 15);
5102 CORE_ADDR from
= dsc
->insn_addr
;
5104 if (bit_12_15
== 0xd)
5106 /* offset = SignExtend (imm8:0, 32) */
5107 offset
= sbits ((insn
<< 1), 0, 8);
5108 cond
= bits (insn
, 8, 11);
5110 else if (bit_12_15
== 0xe) /* Encoding T2 */
5112 offset
= sbits ((insn
<< 1), 0, 11);
5116 displaced_debug_printf ("copying b immediate insn %.4x with offset %d",
5119 dsc
->u
.branch
.cond
= cond
;
5120 dsc
->u
.branch
.link
= 0;
5121 dsc
->u
.branch
.exchange
= 0;
5122 dsc
->u
.branch
.dest
= from
+ 4 + offset
;
5124 dsc
->modinsn
[0] = THUMB_NOP
;
5126 dsc
->cleanup
= &cleanup_branch
;
5131 /* Copy BX/BLX with register-specified destinations. */
5134 install_bx_blx_reg (struct gdbarch
*gdbarch
, struct regcache
*regs
,
5135 arm_displaced_step_copy_insn_closure
*dsc
, int link
,
5136 unsigned int cond
, unsigned int rm
)
5138 /* Implement {BX,BLX}<cond> <reg>" as:
5140 Preparation: cond <- instruction condition
5141 Insn: mov r0, r0 (nop)
5142 Cleanup: if (condition true) { r14 <- pc; pc <- dest; }.
5144 Don't set r14 in cleanup for BX. */
5146 dsc
->u
.branch
.dest
= displaced_read_reg (regs
, dsc
, rm
);
5148 dsc
->u
.branch
.cond
= cond
;
5149 dsc
->u
.branch
.link
= link
;
5151 dsc
->u
.branch
.exchange
= 1;
5153 dsc
->cleanup
= &cleanup_branch
;
5157 arm_copy_bx_blx_reg (struct gdbarch
*gdbarch
, uint32_t insn
,
5158 regcache
*regs
, arm_displaced_step_copy_insn_closure
*dsc
)
5160 unsigned int cond
= bits (insn
, 28, 31);
5163 int link
= bit (insn
, 5);
5164 unsigned int rm
= bits (insn
, 0, 3);
5166 displaced_debug_printf ("copying insn %.8lx", (unsigned long) insn
);
5168 dsc
->modinsn
[0] = ARM_NOP
;
5170 install_bx_blx_reg (gdbarch
, regs
, dsc
, link
, cond
, rm
);
5175 thumb_copy_bx_blx_reg (struct gdbarch
*gdbarch
, uint16_t insn
,
5176 struct regcache
*regs
,
5177 arm_displaced_step_copy_insn_closure
*dsc
)
5179 int link
= bit (insn
, 7);
5180 unsigned int rm
= bits (insn
, 3, 6);
5182 displaced_debug_printf ("copying insn %.4x", (unsigned short) insn
);
5184 dsc
->modinsn
[0] = THUMB_NOP
;
5186 install_bx_blx_reg (gdbarch
, regs
, dsc
, link
, INST_AL
, rm
);
5192 /* Copy/cleanup arithmetic/logic instruction with immediate RHS. */
5195 cleanup_alu_imm (struct gdbarch
*gdbarch
,
5196 regcache
*regs
, arm_displaced_step_copy_insn_closure
*dsc
)
5198 ULONGEST rd_val
= displaced_read_reg (regs
, dsc
, 0);
5199 displaced_write_reg (regs
, dsc
, 0, dsc
->tmp
[0], CANNOT_WRITE_PC
);
5200 displaced_write_reg (regs
, dsc
, 1, dsc
->tmp
[1], CANNOT_WRITE_PC
);
5201 displaced_write_reg (regs
, dsc
, dsc
->rd
, rd_val
, ALU_WRITE_PC
);
5205 arm_copy_alu_imm (struct gdbarch
*gdbarch
, uint32_t insn
, struct regcache
*regs
,
5206 arm_displaced_step_copy_insn_closure
*dsc
)
5208 unsigned int rn
= bits (insn
, 16, 19);
5209 unsigned int rd
= bits (insn
, 12, 15);
5210 unsigned int op
= bits (insn
, 21, 24);
5211 int is_mov
= (op
== 0xd);
5212 ULONGEST rd_val
, rn_val
;
5214 if (!insn_references_pc (insn
, 0x000ff000ul
))
5215 return arm_copy_unmodified (gdbarch
, insn
, "ALU immediate", dsc
);
5217 displaced_debug_printf ("copying immediate %s insn %.8lx",
5218 is_mov
? "move" : "ALU",
5219 (unsigned long) insn
);
5221 /* Instruction is of form:
5223 <op><cond> rd, [rn,] #imm
5227 Preparation: tmp1, tmp2 <- r0, r1;
5229 Insn: <op><cond> r0, r1, #imm
5230 Cleanup: rd <- r0; r0 <- tmp1; r1 <- tmp2
5233 dsc
->tmp
[0] = displaced_read_reg (regs
, dsc
, 0);
5234 dsc
->tmp
[1] = displaced_read_reg (regs
, dsc
, 1);
5235 rn_val
= displaced_read_reg (regs
, dsc
, rn
);
5236 rd_val
= displaced_read_reg (regs
, dsc
, rd
);
5237 displaced_write_reg (regs
, dsc
, 0, rd_val
, CANNOT_WRITE_PC
);
5238 displaced_write_reg (regs
, dsc
, 1, rn_val
, CANNOT_WRITE_PC
);
5242 dsc
->modinsn
[0] = insn
& 0xfff00fff;
5244 dsc
->modinsn
[0] = (insn
& 0xfff00fff) | 0x10000;
5246 dsc
->cleanup
= &cleanup_alu_imm
;
5252 thumb2_copy_alu_imm (struct gdbarch
*gdbarch
, uint16_t insn1
,
5253 uint16_t insn2
, struct regcache
*regs
,
5254 arm_displaced_step_copy_insn_closure
*dsc
)
5256 unsigned int op
= bits (insn1
, 5, 8);
5257 unsigned int rn
, rm
, rd
;
5258 ULONGEST rd_val
, rn_val
;
5260 rn
= bits (insn1
, 0, 3); /* Rn */
5261 rm
= bits (insn2
, 0, 3); /* Rm */
5262 rd
= bits (insn2
, 8, 11); /* Rd */
5264 /* This routine is only called for instruction MOV. */
5265 gdb_assert (op
== 0x2 && rn
== 0xf);
5267 if (rm
!= ARM_PC_REGNUM
&& rd
!= ARM_PC_REGNUM
)
5268 return thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
, "ALU imm", dsc
);
5270 displaced_debug_printf ("copying reg %s insn %.4x%.4x", "ALU", insn1
, insn2
);
5272 /* Instruction is of form:
5274 <op><cond> rd, [rn,] #imm
5278 Preparation: tmp1, tmp2 <- r0, r1;
5280 Insn: <op><cond> r0, r1, #imm
5281 Cleanup: rd <- r0; r0 <- tmp1; r1 <- tmp2
5284 dsc
->tmp
[0] = displaced_read_reg (regs
, dsc
, 0);
5285 dsc
->tmp
[1] = displaced_read_reg (regs
, dsc
, 1);
5286 rn_val
= displaced_read_reg (regs
, dsc
, rn
);
5287 rd_val
= displaced_read_reg (regs
, dsc
, rd
);
5288 displaced_write_reg (regs
, dsc
, 0, rd_val
, CANNOT_WRITE_PC
);
5289 displaced_write_reg (regs
, dsc
, 1, rn_val
, CANNOT_WRITE_PC
);
5292 dsc
->modinsn
[0] = insn1
;
5293 dsc
->modinsn
[1] = ((insn2
& 0xf0f0) | 0x1);
5296 dsc
->cleanup
= &cleanup_alu_imm
;
5301 /* Copy/cleanup arithmetic/logic insns with register RHS. */
5304 cleanup_alu_reg (struct gdbarch
*gdbarch
,
5305 regcache
*regs
, arm_displaced_step_copy_insn_closure
*dsc
)
5310 rd_val
= displaced_read_reg (regs
, dsc
, 0);
5312 for (i
= 0; i
< 3; i
++)
5313 displaced_write_reg (regs
, dsc
, i
, dsc
->tmp
[i
], CANNOT_WRITE_PC
);
5315 displaced_write_reg (regs
, dsc
, dsc
->rd
, rd_val
, ALU_WRITE_PC
);
5319 install_alu_reg (struct gdbarch
*gdbarch
, struct regcache
*regs
,
5320 arm_displaced_step_copy_insn_closure
*dsc
,
5321 unsigned int rd
, unsigned int rn
, unsigned int rm
)
5323 ULONGEST rd_val
, rn_val
, rm_val
;
5325 /* Instruction is of form:
5327 <op><cond> rd, [rn,] rm [, <shift>]
5331 Preparation: tmp1, tmp2, tmp3 <- r0, r1, r2;
5332 r0, r1, r2 <- rd, rn, rm
5333 Insn: <op><cond> r0, [r1,] r2 [, <shift>]
5334 Cleanup: rd <- r0; r0, r1, r2 <- tmp1, tmp2, tmp3
5337 dsc
->tmp
[0] = displaced_read_reg (regs
, dsc
, 0);
5338 dsc
->tmp
[1] = displaced_read_reg (regs
, dsc
, 1);
5339 dsc
->tmp
[2] = displaced_read_reg (regs
, dsc
, 2);
5340 rd_val
= displaced_read_reg (regs
, dsc
, rd
);
5341 rn_val
= displaced_read_reg (regs
, dsc
, rn
);
5342 rm_val
= displaced_read_reg (regs
, dsc
, rm
);
5343 displaced_write_reg (regs
, dsc
, 0, rd_val
, CANNOT_WRITE_PC
);
5344 displaced_write_reg (regs
, dsc
, 1, rn_val
, CANNOT_WRITE_PC
);
5345 displaced_write_reg (regs
, dsc
, 2, rm_val
, CANNOT_WRITE_PC
);
5348 dsc
->cleanup
= &cleanup_alu_reg
;
5352 arm_copy_alu_reg (struct gdbarch
*gdbarch
, uint32_t insn
, struct regcache
*regs
,
5353 arm_displaced_step_copy_insn_closure
*dsc
)
5355 unsigned int op
= bits (insn
, 21, 24);
5356 int is_mov
= (op
== 0xd);
5358 if (!insn_references_pc (insn
, 0x000ff00ful
))
5359 return arm_copy_unmodified (gdbarch
, insn
, "ALU reg", dsc
);
5361 displaced_debug_printf ("copying reg %s insn %.8lx",
5362 is_mov
? "move" : "ALU", (unsigned long) insn
);
5365 dsc
->modinsn
[0] = (insn
& 0xfff00ff0) | 0x2;
5367 dsc
->modinsn
[0] = (insn
& 0xfff00ff0) | 0x10002;
5369 install_alu_reg (gdbarch
, regs
, dsc
, bits (insn
, 12, 15), bits (insn
, 16, 19),
5375 thumb_copy_alu_reg (struct gdbarch
*gdbarch
, uint16_t insn
,
5376 struct regcache
*regs
,
5377 arm_displaced_step_copy_insn_closure
*dsc
)
5381 rm
= bits (insn
, 3, 6);
5382 rd
= (bit (insn
, 7) << 3) | bits (insn
, 0, 2);
5384 if (rd
!= ARM_PC_REGNUM
&& rm
!= ARM_PC_REGNUM
)
5385 return thumb_copy_unmodified_16bit (gdbarch
, insn
, "ALU reg", dsc
);
5387 displaced_debug_printf ("copying ALU reg insn %.4x", (unsigned short) insn
);
5389 dsc
->modinsn
[0] = ((insn
& 0xff00) | 0x10);
5391 install_alu_reg (gdbarch
, regs
, dsc
, rd
, rd
, rm
);
5396 /* Cleanup/copy arithmetic/logic insns with shifted register RHS. */
5399 cleanup_alu_shifted_reg (struct gdbarch
*gdbarch
,
5400 struct regcache
*regs
,
5401 arm_displaced_step_copy_insn_closure
*dsc
)
5403 ULONGEST rd_val
= displaced_read_reg (regs
, dsc
, 0);
5406 for (i
= 0; i
< 4; i
++)
5407 displaced_write_reg (regs
, dsc
, i
, dsc
->tmp
[i
], CANNOT_WRITE_PC
);
5409 displaced_write_reg (regs
, dsc
, dsc
->rd
, rd_val
, ALU_WRITE_PC
);
5413 install_alu_shifted_reg (struct gdbarch
*gdbarch
, struct regcache
*regs
,
5414 arm_displaced_step_copy_insn_closure
*dsc
,
5415 unsigned int rd
, unsigned int rn
, unsigned int rm
,
5419 ULONGEST rd_val
, rn_val
, rm_val
, rs_val
;
5421 /* Instruction is of form:
5423 <op><cond> rd, [rn,] rm, <shift> rs
5427 Preparation: tmp1, tmp2, tmp3, tmp4 <- r0, r1, r2, r3
5428 r0, r1, r2, r3 <- rd, rn, rm, rs
5429 Insn: <op><cond> r0, r1, r2, <shift> r3
5431 r0, r1, r2, r3 <- tmp1, tmp2, tmp3, tmp4
5435 for (i
= 0; i
< 4; i
++)
5436 dsc
->tmp
[i
] = displaced_read_reg (regs
, dsc
, i
);
5438 rd_val
= displaced_read_reg (regs
, dsc
, rd
);
5439 rn_val
= displaced_read_reg (regs
, dsc
, rn
);
5440 rm_val
= displaced_read_reg (regs
, dsc
, rm
);
5441 rs_val
= displaced_read_reg (regs
, dsc
, rs
);
5442 displaced_write_reg (regs
, dsc
, 0, rd_val
, CANNOT_WRITE_PC
);
5443 displaced_write_reg (regs
, dsc
, 1, rn_val
, CANNOT_WRITE_PC
);
5444 displaced_write_reg (regs
, dsc
, 2, rm_val
, CANNOT_WRITE_PC
);
5445 displaced_write_reg (regs
, dsc
, 3, rs_val
, CANNOT_WRITE_PC
);
5447 dsc
->cleanup
= &cleanup_alu_shifted_reg
;
5451 arm_copy_alu_shifted_reg (struct gdbarch
*gdbarch
, uint32_t insn
,
5452 struct regcache
*regs
,
5453 arm_displaced_step_copy_insn_closure
*dsc
)
5455 unsigned int op
= bits (insn
, 21, 24);
5456 int is_mov
= (op
== 0xd);
5457 unsigned int rd
, rn
, rm
, rs
;
5459 if (!insn_references_pc (insn
, 0x000fff0ful
))
5460 return arm_copy_unmodified (gdbarch
, insn
, "ALU shifted reg", dsc
);
5462 displaced_debug_printf ("copying shifted reg %s insn %.8lx",
5463 is_mov
? "move" : "ALU",
5464 (unsigned long) insn
);
5466 rn
= bits (insn
, 16, 19);
5467 rm
= bits (insn
, 0, 3);
5468 rs
= bits (insn
, 8, 11);
5469 rd
= bits (insn
, 12, 15);
5472 dsc
->modinsn
[0] = (insn
& 0xfff000f0) | 0x302;
5474 dsc
->modinsn
[0] = (insn
& 0xfff000f0) | 0x10302;
5476 install_alu_shifted_reg (gdbarch
, regs
, dsc
, rd
, rn
, rm
, rs
);
5481 /* Clean up load instructions. */
5484 cleanup_load (struct gdbarch
*gdbarch
, struct regcache
*regs
,
5485 arm_displaced_step_copy_insn_closure
*dsc
)
5487 ULONGEST rt_val
, rt_val2
= 0, rn_val
;
5489 rt_val
= displaced_read_reg (regs
, dsc
, 0);
5490 if (dsc
->u
.ldst
.xfersize
== 8)
5491 rt_val2
= displaced_read_reg (regs
, dsc
, 1);
5492 rn_val
= displaced_read_reg (regs
, dsc
, 2);
5494 displaced_write_reg (regs
, dsc
, 0, dsc
->tmp
[0], CANNOT_WRITE_PC
);
5495 if (dsc
->u
.ldst
.xfersize
> 4)
5496 displaced_write_reg (regs
, dsc
, 1, dsc
->tmp
[1], CANNOT_WRITE_PC
);
5497 displaced_write_reg (regs
, dsc
, 2, dsc
->tmp
[2], CANNOT_WRITE_PC
);
5498 if (!dsc
->u
.ldst
.immed
)
5499 displaced_write_reg (regs
, dsc
, 3, dsc
->tmp
[3], CANNOT_WRITE_PC
);
5501 /* Handle register writeback. */
5502 if (dsc
->u
.ldst
.writeback
)
5503 displaced_write_reg (regs
, dsc
, dsc
->u
.ldst
.rn
, rn_val
, CANNOT_WRITE_PC
);
5504 /* Put result in right place. */
5505 displaced_write_reg (regs
, dsc
, dsc
->rd
, rt_val
, LOAD_WRITE_PC
);
5506 if (dsc
->u
.ldst
.xfersize
== 8)
5507 displaced_write_reg (regs
, dsc
, dsc
->rd
+ 1, rt_val2
, LOAD_WRITE_PC
);
5510 /* Clean up store instructions. */
5513 cleanup_store (struct gdbarch
*gdbarch
, struct regcache
*regs
,
5514 arm_displaced_step_copy_insn_closure
*dsc
)
5516 ULONGEST rn_val
= displaced_read_reg (regs
, dsc
, 2);
5518 displaced_write_reg (regs
, dsc
, 0, dsc
->tmp
[0], CANNOT_WRITE_PC
);
5519 if (dsc
->u
.ldst
.xfersize
> 4)
5520 displaced_write_reg (regs
, dsc
, 1, dsc
->tmp
[1], CANNOT_WRITE_PC
);
5521 displaced_write_reg (regs
, dsc
, 2, dsc
->tmp
[2], CANNOT_WRITE_PC
);
5522 if (!dsc
->u
.ldst
.immed
)
5523 displaced_write_reg (regs
, dsc
, 3, dsc
->tmp
[3], CANNOT_WRITE_PC
);
5524 if (!dsc
->u
.ldst
.restore_r4
)
5525 displaced_write_reg (regs
, dsc
, 4, dsc
->tmp
[4], CANNOT_WRITE_PC
);
5528 if (dsc
->u
.ldst
.writeback
)
5529 displaced_write_reg (regs
, dsc
, dsc
->u
.ldst
.rn
, rn_val
, CANNOT_WRITE_PC
);
5532 /* Copy "extra" load/store instructions. These are halfword/doubleword
5533 transfers, which have a different encoding to byte/word transfers. */
5536 arm_copy_extra_ld_st (struct gdbarch
*gdbarch
, uint32_t insn
, int unprivileged
,
5537 regcache
*regs
, arm_displaced_step_copy_insn_closure
*dsc
)
5539 unsigned int op1
= bits (insn
, 20, 24);
5540 unsigned int op2
= bits (insn
, 5, 6);
5541 unsigned int rt
= bits (insn
, 12, 15);
5542 unsigned int rn
= bits (insn
, 16, 19);
5543 unsigned int rm
= bits (insn
, 0, 3);
5544 char load
[12] = {0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1};
5545 char bytesize
[12] = {2, 2, 2, 2, 8, 1, 8, 1, 8, 2, 8, 2};
5546 int immed
= (op1
& 0x4) != 0;
5548 ULONGEST rt_val
, rt_val2
= 0, rn_val
, rm_val
= 0;
5550 if (!insn_references_pc (insn
, 0x000ff00ful
))
5551 return arm_copy_unmodified (gdbarch
, insn
, "extra load/store", dsc
);
5553 displaced_debug_printf ("copying %sextra load/store insn %.8lx",
5554 unprivileged
? "unprivileged " : "",
5555 (unsigned long) insn
);
5557 opcode
= ((op2
<< 2) | (op1
& 0x1) | ((op1
& 0x4) >> 1)) - 4;
5560 internal_error (__FILE__
, __LINE__
,
5561 _("copy_extra_ld_st: instruction decode error"));
5563 dsc
->tmp
[0] = displaced_read_reg (regs
, dsc
, 0);
5564 dsc
->tmp
[1] = displaced_read_reg (regs
, dsc
, 1);
5565 dsc
->tmp
[2] = displaced_read_reg (regs
, dsc
, 2);
5567 dsc
->tmp
[3] = displaced_read_reg (regs
, dsc
, 3);
5569 rt_val
= displaced_read_reg (regs
, dsc
, rt
);
5570 if (bytesize
[opcode
] == 8)
5571 rt_val2
= displaced_read_reg (regs
, dsc
, rt
+ 1);
5572 rn_val
= displaced_read_reg (regs
, dsc
, rn
);
5574 rm_val
= displaced_read_reg (regs
, dsc
, rm
);
5576 displaced_write_reg (regs
, dsc
, 0, rt_val
, CANNOT_WRITE_PC
);
5577 if (bytesize
[opcode
] == 8)
5578 displaced_write_reg (regs
, dsc
, 1, rt_val2
, CANNOT_WRITE_PC
);
5579 displaced_write_reg (regs
, dsc
, 2, rn_val
, CANNOT_WRITE_PC
);
5581 displaced_write_reg (regs
, dsc
, 3, rm_val
, CANNOT_WRITE_PC
);
5584 dsc
->u
.ldst
.xfersize
= bytesize
[opcode
];
5585 dsc
->u
.ldst
.rn
= rn
;
5586 dsc
->u
.ldst
.immed
= immed
;
5587 dsc
->u
.ldst
.writeback
= bit (insn
, 24) == 0 || bit (insn
, 21) != 0;
5588 dsc
->u
.ldst
.restore_r4
= 0;
5591 /* {ldr,str}<width><cond> rt, [rt2,] [rn, #imm]
5593 {ldr,str}<width><cond> r0, [r1,] [r2, #imm]. */
5594 dsc
->modinsn
[0] = (insn
& 0xfff00fff) | 0x20000;
5596 /* {ldr,str}<width><cond> rt, [rt2,] [rn, +/-rm]
5598 {ldr,str}<width><cond> r0, [r1,] [r2, +/-r3]. */
5599 dsc
->modinsn
[0] = (insn
& 0xfff00ff0) | 0x20003;
5601 dsc
->cleanup
= load
[opcode
] ? &cleanup_load
: &cleanup_store
;
5606 /* Copy byte/half word/word loads and stores. */
5609 install_load_store (struct gdbarch
*gdbarch
, struct regcache
*regs
,
5610 arm_displaced_step_copy_insn_closure
*dsc
, int load
,
5611 int immed
, int writeback
, int size
, int usermode
,
5612 int rt
, int rm
, int rn
)
5614 ULONGEST rt_val
, rn_val
, rm_val
= 0;
5616 dsc
->tmp
[0] = displaced_read_reg (regs
, dsc
, 0);
5617 dsc
->tmp
[2] = displaced_read_reg (regs
, dsc
, 2);
5619 dsc
->tmp
[3] = displaced_read_reg (regs
, dsc
, 3);
5621 dsc
->tmp
[4] = displaced_read_reg (regs
, dsc
, 4);
5623 rt_val
= displaced_read_reg (regs
, dsc
, rt
);
5624 rn_val
= displaced_read_reg (regs
, dsc
, rn
);
5626 rm_val
= displaced_read_reg (regs
, dsc
, rm
);
5628 displaced_write_reg (regs
, dsc
, 0, rt_val
, CANNOT_WRITE_PC
);
5629 displaced_write_reg (regs
, dsc
, 2, rn_val
, CANNOT_WRITE_PC
);
5631 displaced_write_reg (regs
, dsc
, 3, rm_val
, CANNOT_WRITE_PC
);
5633 dsc
->u
.ldst
.xfersize
= size
;
5634 dsc
->u
.ldst
.rn
= rn
;
5635 dsc
->u
.ldst
.immed
= immed
;
5636 dsc
->u
.ldst
.writeback
= writeback
;
5638 /* To write PC we can do:
5640 Before this sequence of instructions:
5641 r0 is the PC value got from displaced_read_reg, so r0 = from + 8;
5642 r2 is the Rn value got from displaced_read_reg.
5644 Insn1: push {pc} Write address of STR instruction + offset on stack
5645 Insn2: pop {r4} Read it back from stack, r4 = addr(Insn1) + offset
5646 Insn3: sub r4, r4, pc r4 = addr(Insn1) + offset - pc
5647 = addr(Insn1) + offset - addr(Insn3) - 8
5649 Insn4: add r4, r4, #8 r4 = offset - 8
5650 Insn5: add r0, r0, r4 r0 = from + 8 + offset - 8
5652 Insn6: str r0, [r2, #imm] (or str r0, [r2, r3])
5654 Otherwise we don't know what value to write for PC, since the offset is
5655 architecture-dependent (sometimes PC+8, sometimes PC+12). More details
5656 of this can be found in Section "Saving from r15" in
5657 http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0204g/Cihbjifh.html */
5659 dsc
->cleanup
= load
? &cleanup_load
: &cleanup_store
;
5664 thumb2_copy_load_literal (struct gdbarch
*gdbarch
, uint16_t insn1
,
5665 uint16_t insn2
, struct regcache
*regs
,
5666 arm_displaced_step_copy_insn_closure
*dsc
, int size
)
5668 unsigned int u_bit
= bit (insn1
, 7);
5669 unsigned int rt
= bits (insn2
, 12, 15);
5670 int imm12
= bits (insn2
, 0, 11);
5673 displaced_debug_printf ("copying ldr pc (0x%x) R%d %c imm12 %.4x",
5674 (unsigned int) dsc
->insn_addr
, rt
, u_bit
? '+' : '-',
5680 /* Rewrite instruction LDR Rt imm12 into:
5682 Prepare: tmp[0] <- r0, tmp[1] <- r2, tmp[2] <- r3, r2 <- pc, r3 <- imm12
5686 Cleanup: rt <- r0, r0 <- tmp[0], r2 <- tmp[1], r3 <- tmp[2]. */
5689 dsc
->tmp
[0] = displaced_read_reg (regs
, dsc
, 0);
5690 dsc
->tmp
[2] = displaced_read_reg (regs
, dsc
, 2);
5691 dsc
->tmp
[3] = displaced_read_reg (regs
, dsc
, 3);
5693 pc_val
= displaced_read_reg (regs
, dsc
, ARM_PC_REGNUM
);
5695 pc_val
= pc_val
& 0xfffffffc;
5697 displaced_write_reg (regs
, dsc
, 2, pc_val
, CANNOT_WRITE_PC
);
5698 displaced_write_reg (regs
, dsc
, 3, imm12
, CANNOT_WRITE_PC
);
5702 dsc
->u
.ldst
.xfersize
= size
;
5703 dsc
->u
.ldst
.immed
= 0;
5704 dsc
->u
.ldst
.writeback
= 0;
5705 dsc
->u
.ldst
.restore_r4
= 0;
5707 /* LDR R0, R2, R3 */
5708 dsc
->modinsn
[0] = 0xf852;
5709 dsc
->modinsn
[1] = 0x3;
5712 dsc
->cleanup
= &cleanup_load
;
5718 thumb2_copy_load_reg_imm (struct gdbarch
*gdbarch
, uint16_t insn1
,
5719 uint16_t insn2
, struct regcache
*regs
,
5720 arm_displaced_step_copy_insn_closure
*dsc
,
5721 int writeback
, int immed
)
5723 unsigned int rt
= bits (insn2
, 12, 15);
5724 unsigned int rn
= bits (insn1
, 0, 3);
5725 unsigned int rm
= bits (insn2
, 0, 3); /* Only valid if !immed. */
5726 /* In LDR (register), there is also a register Rm, which is not allowed to
5727 be PC, so we don't have to check it. */
5729 if (rt
!= ARM_PC_REGNUM
&& rn
!= ARM_PC_REGNUM
)
5730 return thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
, "load",
5733 displaced_debug_printf ("copying ldr r%d [r%d] insn %.4x%.4x",
5734 rt
, rn
, insn1
, insn2
);
5736 install_load_store (gdbarch
, regs
, dsc
, 1, immed
, writeback
, 4,
5739 dsc
->u
.ldst
.restore_r4
= 0;
5742 /* ldr[b]<cond> rt, [rn, #imm], etc.
5744 ldr[b]<cond> r0, [r2, #imm]. */
5746 dsc
->modinsn
[0] = (insn1
& 0xfff0) | 0x2;
5747 dsc
->modinsn
[1] = insn2
& 0x0fff;
5750 /* ldr[b]<cond> rt, [rn, rm], etc.
5752 ldr[b]<cond> r0, [r2, r3]. */
5754 dsc
->modinsn
[0] = (insn1
& 0xfff0) | 0x2;
5755 dsc
->modinsn
[1] = (insn2
& 0x0ff0) | 0x3;
5765 arm_copy_ldr_str_ldrb_strb (struct gdbarch
*gdbarch
, uint32_t insn
,
5766 struct regcache
*regs
,
5767 arm_displaced_step_copy_insn_closure
*dsc
,
5768 int load
, int size
, int usermode
)
5770 int immed
= !bit (insn
, 25);
5771 int writeback
= (bit (insn
, 24) == 0 || bit (insn
, 21) != 0);
5772 unsigned int rt
= bits (insn
, 12, 15);
5773 unsigned int rn
= bits (insn
, 16, 19);
5774 unsigned int rm
= bits (insn
, 0, 3); /* Only valid if !immed. */
5776 if (!insn_references_pc (insn
, 0x000ff00ful
))
5777 return arm_copy_unmodified (gdbarch
, insn
, "load/store", dsc
);
5779 displaced_debug_printf ("copying %s%s r%d [r%d] insn %.8lx",
5780 load
? (size
== 1 ? "ldrb" : "ldr")
5781 : (size
== 1 ? "strb" : "str"),
5782 usermode
? "t" : "",
5784 (unsigned long) insn
);
5786 install_load_store (gdbarch
, regs
, dsc
, load
, immed
, writeback
, size
,
5787 usermode
, rt
, rm
, rn
);
5789 if (load
|| rt
!= ARM_PC_REGNUM
)
5791 dsc
->u
.ldst
.restore_r4
= 0;
5794 /* {ldr,str}[b]<cond> rt, [rn, #imm], etc.
5796 {ldr,str}[b]<cond> r0, [r2, #imm]. */
5797 dsc
->modinsn
[0] = (insn
& 0xfff00fff) | 0x20000;
5799 /* {ldr,str}[b]<cond> rt, [rn, rm], etc.
5801 {ldr,str}[b]<cond> r0, [r2, r3]. */
5802 dsc
->modinsn
[0] = (insn
& 0xfff00ff0) | 0x20003;
5806 /* We need to use r4 as scratch. Make sure it's restored afterwards. */
5807 dsc
->u
.ldst
.restore_r4
= 1;
5808 dsc
->modinsn
[0] = 0xe92d8000; /* push {pc} */
5809 dsc
->modinsn
[1] = 0xe8bd0010; /* pop {r4} */
5810 dsc
->modinsn
[2] = 0xe044400f; /* sub r4, r4, pc. */
5811 dsc
->modinsn
[3] = 0xe2844008; /* add r4, r4, #8. */
5812 dsc
->modinsn
[4] = 0xe0800004; /* add r0, r0, r4. */
5816 dsc
->modinsn
[5] = (insn
& 0xfff00fff) | 0x20000;
5818 dsc
->modinsn
[5] = (insn
& 0xfff00ff0) | 0x20003;
5823 dsc
->cleanup
= load
? &cleanup_load
: &cleanup_store
;
5828 /* Cleanup LDM instructions with fully-populated register list. This is an
5829 unfortunate corner case: it's impossible to implement correctly by modifying
5830 the instruction. The issue is as follows: we have an instruction,
5834 which we must rewrite to avoid loading PC. A possible solution would be to
5835 do the load in two halves, something like (with suitable cleanup
5839 ldm[id][ab] r8!, {r0-r7}
5841 ldm[id][ab] r8, {r7-r14}
5844 but at present there's no suitable place for <temp>, since the scratch space
5845 is overwritten before the cleanup routine is called. For now, we simply
5846 emulate the instruction. */
5849 cleanup_block_load_all (struct gdbarch
*gdbarch
, struct regcache
*regs
,
5850 arm_displaced_step_copy_insn_closure
*dsc
)
5852 int inc
= dsc
->u
.block
.increment
;
5853 int bump_before
= dsc
->u
.block
.before
? (inc
? 4 : -4) : 0;
5854 int bump_after
= dsc
->u
.block
.before
? 0 : (inc
? 4 : -4);
5855 uint32_t regmask
= dsc
->u
.block
.regmask
;
5856 int regno
= inc
? 0 : 15;
5857 CORE_ADDR xfer_addr
= dsc
->u
.block
.xfer_addr
;
5858 int exception_return
= dsc
->u
.block
.load
&& dsc
->u
.block
.user
5859 && (regmask
& 0x8000) != 0;
5860 uint32_t status
= displaced_read_reg (regs
, dsc
, ARM_PS_REGNUM
);
5861 int do_transfer
= condition_true (dsc
->u
.block
.cond
, status
);
5862 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
5867 /* If the instruction is ldm rN, {...pc}^, I don't think there's anything
5868 sensible we can do here. Complain loudly. */
5869 if (exception_return
)
5870 error (_("Cannot single-step exception return"));
5872 /* We don't handle any stores here for now. */
5873 gdb_assert (dsc
->u
.block
.load
!= 0);
5875 displaced_debug_printf ("emulating block transfer: %s %s %s",
5876 dsc
->u
.block
.load
? "ldm" : "stm",
5877 dsc
->u
.block
.increment
? "inc" : "dec",
5878 dsc
->u
.block
.before
? "before" : "after");
5885 while (regno
<= ARM_PC_REGNUM
&& (regmask
& (1 << regno
)) == 0)
5888 while (regno
>= 0 && (regmask
& (1 << regno
)) == 0)
5891 xfer_addr
+= bump_before
;
5893 memword
= read_memory_unsigned_integer (xfer_addr
, 4, byte_order
);
5894 displaced_write_reg (regs
, dsc
, regno
, memword
, LOAD_WRITE_PC
);
5896 xfer_addr
+= bump_after
;
5898 regmask
&= ~(1 << regno
);
5901 if (dsc
->u
.block
.writeback
)
5902 displaced_write_reg (regs
, dsc
, dsc
->u
.block
.rn
, xfer_addr
,
5906 /* Clean up an STM which included the PC in the register list. */
5909 cleanup_block_store_pc (struct gdbarch
*gdbarch
, struct regcache
*regs
,
5910 arm_displaced_step_copy_insn_closure
*dsc
)
5912 uint32_t status
= displaced_read_reg (regs
, dsc
, ARM_PS_REGNUM
);
5913 int store_executed
= condition_true (dsc
->u
.block
.cond
, status
);
5914 CORE_ADDR pc_stored_at
, transferred_regs
5915 = count_one_bits (dsc
->u
.block
.regmask
);
5916 CORE_ADDR stm_insn_addr
;
5919 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
5921 /* If condition code fails, there's nothing else to do. */
5922 if (!store_executed
)
5925 if (dsc
->u
.block
.increment
)
5927 pc_stored_at
= dsc
->u
.block
.xfer_addr
+ 4 * transferred_regs
;
5929 if (dsc
->u
.block
.before
)
5934 pc_stored_at
= dsc
->u
.block
.xfer_addr
;
5936 if (dsc
->u
.block
.before
)
5940 pc_val
= read_memory_unsigned_integer (pc_stored_at
, 4, byte_order
);
5941 stm_insn_addr
= dsc
->scratch_base
;
5942 offset
= pc_val
- stm_insn_addr
;
5944 displaced_debug_printf ("detected PC offset %.8lx for STM instruction",
5947 /* Rewrite the stored PC to the proper value for the non-displaced original
5949 write_memory_unsigned_integer (pc_stored_at
, 4, byte_order
,
5950 dsc
->insn_addr
+ offset
);
5953 /* Clean up an LDM which includes the PC in the register list. We clumped all
5954 the registers in the transferred list into a contiguous range r0...rX (to
5955 avoid loading PC directly and losing control of the debugged program), so we
5956 must undo that here. */
5959 cleanup_block_load_pc (struct gdbarch
*gdbarch
,
5960 struct regcache
*regs
,
5961 arm_displaced_step_copy_insn_closure
*dsc
)
5963 uint32_t status
= displaced_read_reg (regs
, dsc
, ARM_PS_REGNUM
);
5964 int load_executed
= condition_true (dsc
->u
.block
.cond
, status
);
5965 unsigned int mask
= dsc
->u
.block
.regmask
, write_reg
= ARM_PC_REGNUM
;
5966 unsigned int regs_loaded
= count_one_bits (mask
);
5967 unsigned int num_to_shuffle
= regs_loaded
, clobbered
;
5969 /* The method employed here will fail if the register list is fully populated
5970 (we need to avoid loading PC directly). */
5971 gdb_assert (num_to_shuffle
< 16);
5976 clobbered
= (1 << num_to_shuffle
) - 1;
5978 while (num_to_shuffle
> 0)
5980 if ((mask
& (1 << write_reg
)) != 0)
5982 unsigned int read_reg
= num_to_shuffle
- 1;
5984 if (read_reg
!= write_reg
)
5986 ULONGEST rval
= displaced_read_reg (regs
, dsc
, read_reg
);
5987 displaced_write_reg (regs
, dsc
, write_reg
, rval
, LOAD_WRITE_PC
);
5988 displaced_debug_printf ("LDM: move loaded register r%d to r%d",
5989 read_reg
, write_reg
);
5992 displaced_debug_printf ("LDM: register r%d already in the right "
5993 "place", write_reg
);
5995 clobbered
&= ~(1 << write_reg
);
6003 /* Restore any registers we scribbled over. */
6004 for (write_reg
= 0; clobbered
!= 0; write_reg
++)
6006 if ((clobbered
& (1 << write_reg
)) != 0)
6008 displaced_write_reg (regs
, dsc
, write_reg
, dsc
->tmp
[write_reg
],
6010 displaced_debug_printf ("LDM: restored clobbered register r%d",
6012 clobbered
&= ~(1 << write_reg
);
6016 /* Perform register writeback manually. */
6017 if (dsc
->u
.block
.writeback
)
6019 ULONGEST new_rn_val
= dsc
->u
.block
.xfer_addr
;
6021 if (dsc
->u
.block
.increment
)
6022 new_rn_val
+= regs_loaded
* 4;
6024 new_rn_val
-= regs_loaded
* 4;
6026 displaced_write_reg (regs
, dsc
, dsc
->u
.block
.rn
, new_rn_val
,
6031 /* Handle ldm/stm, apart from some tricky cases which are unlikely to occur
6032 in user-level code (in particular exception return, ldm rn, {...pc}^). */
6035 arm_copy_block_xfer (struct gdbarch
*gdbarch
, uint32_t insn
,
6036 struct regcache
*regs
,
6037 arm_displaced_step_copy_insn_closure
*dsc
)
6039 int load
= bit (insn
, 20);
6040 int user
= bit (insn
, 22);
6041 int increment
= bit (insn
, 23);
6042 int before
= bit (insn
, 24);
6043 int writeback
= bit (insn
, 21);
6044 int rn
= bits (insn
, 16, 19);
6046 /* Block transfers which don't mention PC can be run directly
6048 if (rn
!= ARM_PC_REGNUM
&& (insn
& 0x8000) == 0)
6049 return arm_copy_unmodified (gdbarch
, insn
, "ldm/stm", dsc
);
6051 if (rn
== ARM_PC_REGNUM
)
6053 warning (_("displaced: Unpredictable LDM or STM with "
6054 "base register r15"));
6055 return arm_copy_unmodified (gdbarch
, insn
, "unpredictable ldm/stm", dsc
);
6058 displaced_debug_printf ("copying block transfer insn %.8lx",
6059 (unsigned long) insn
);
6061 dsc
->u
.block
.xfer_addr
= displaced_read_reg (regs
, dsc
, rn
);
6062 dsc
->u
.block
.rn
= rn
;
6064 dsc
->u
.block
.load
= load
;
6065 dsc
->u
.block
.user
= user
;
6066 dsc
->u
.block
.increment
= increment
;
6067 dsc
->u
.block
.before
= before
;
6068 dsc
->u
.block
.writeback
= writeback
;
6069 dsc
->u
.block
.cond
= bits (insn
, 28, 31);
6071 dsc
->u
.block
.regmask
= insn
& 0xffff;
6075 if ((insn
& 0xffff) == 0xffff)
6077 /* LDM with a fully-populated register list. This case is
6078 particularly tricky. Implement for now by fully emulating the
6079 instruction (which might not behave perfectly in all cases, but
6080 these instructions should be rare enough for that not to matter
6082 dsc
->modinsn
[0] = ARM_NOP
;
6084 dsc
->cleanup
= &cleanup_block_load_all
;
6088 /* LDM of a list of registers which includes PC. Implement by
6089 rewriting the list of registers to be transferred into a
6090 contiguous chunk r0...rX before doing the transfer, then shuffling
6091 registers into the correct places in the cleanup routine. */
6092 unsigned int regmask
= insn
& 0xffff;
6093 unsigned int num_in_list
= count_one_bits (regmask
), new_regmask
;
6096 for (i
= 0; i
< num_in_list
; i
++)
6097 dsc
->tmp
[i
] = displaced_read_reg (regs
, dsc
, i
);
6099 /* Writeback makes things complicated. We need to avoid clobbering
6100 the base register with one of the registers in our modified
6101 register list, but just using a different register can't work in
6104 ldm r14!, {r0-r13,pc}
6106 which would need to be rewritten as:
6110 but that can't work, because there's no free register for N.
6112 Solve this by turning off the writeback bit, and emulating
6113 writeback manually in the cleanup routine. */
6118 new_regmask
= (1 << num_in_list
) - 1;
6120 displaced_debug_printf ("LDM r%d%s, {..., pc}: original reg list "
6121 "%.4x, modified list %.4x",
6122 rn
, writeback
? "!" : "",
6123 (int) insn
& 0xffff, new_regmask
);
6125 dsc
->modinsn
[0] = (insn
& ~0xffff) | (new_regmask
& 0xffff);
6127 dsc
->cleanup
= &cleanup_block_load_pc
;
6132 /* STM of a list of registers which includes PC. Run the instruction
6133 as-is, but out of line: this will store the wrong value for the PC,
6134 so we must manually fix up the memory in the cleanup routine.
6135 Doing things this way has the advantage that we can auto-detect
6136 the offset of the PC write (which is architecture-dependent) in
6137 the cleanup routine. */
6138 dsc
->modinsn
[0] = insn
;
6140 dsc
->cleanup
= &cleanup_block_store_pc
;
6147 thumb2_copy_block_xfer (struct gdbarch
*gdbarch
, uint16_t insn1
, uint16_t insn2
,
6148 struct regcache
*regs
,
6149 arm_displaced_step_copy_insn_closure
*dsc
)
6151 int rn
= bits (insn1
, 0, 3);
6152 int load
= bit (insn1
, 4);
6153 int writeback
= bit (insn1
, 5);
6155 /* Block transfers which don't mention PC can be run directly
6157 if (rn
!= ARM_PC_REGNUM
&& (insn2
& 0x8000) == 0)
6158 return thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
, "ldm/stm", dsc
);
6160 if (rn
== ARM_PC_REGNUM
)
6162 warning (_("displaced: Unpredictable LDM or STM with "
6163 "base register r15"));
6164 return thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
,
6165 "unpredictable ldm/stm", dsc
);
6168 displaced_debug_printf ("copying block transfer insn %.4x%.4x",
6171 /* Clear bit 13, since it should be always zero. */
6172 dsc
->u
.block
.regmask
= (insn2
& 0xdfff);
6173 dsc
->u
.block
.rn
= rn
;
6175 dsc
->u
.block
.load
= load
;
6176 dsc
->u
.block
.user
= 0;
6177 dsc
->u
.block
.increment
= bit (insn1
, 7);
6178 dsc
->u
.block
.before
= bit (insn1
, 8);
6179 dsc
->u
.block
.writeback
= writeback
;
6180 dsc
->u
.block
.cond
= INST_AL
;
6181 dsc
->u
.block
.xfer_addr
= displaced_read_reg (regs
, dsc
, rn
);
6185 if (dsc
->u
.block
.regmask
== 0xffff)
6187 /* This branch is impossible to happen. */
6192 unsigned int regmask
= dsc
->u
.block
.regmask
;
6193 unsigned int num_in_list
= count_one_bits (regmask
), new_regmask
;
6196 for (i
= 0; i
< num_in_list
; i
++)
6197 dsc
->tmp
[i
] = displaced_read_reg (regs
, dsc
, i
);
6202 new_regmask
= (1 << num_in_list
) - 1;
6204 displaced_debug_printf ("LDM r%d%s, {..., pc}: original reg list "
6205 "%.4x, modified list %.4x",
6206 rn
, writeback
? "!" : "",
6207 (int) dsc
->u
.block
.regmask
, new_regmask
);
6209 dsc
->modinsn
[0] = insn1
;
6210 dsc
->modinsn
[1] = (new_regmask
& 0xffff);
6213 dsc
->cleanup
= &cleanup_block_load_pc
;
6218 dsc
->modinsn
[0] = insn1
;
6219 dsc
->modinsn
[1] = insn2
;
6221 dsc
->cleanup
= &cleanup_block_store_pc
;
6226 /* Wrapper over read_memory_unsigned_integer for use in arm_get_next_pcs.
6227 This is used to avoid a dependency on BFD's bfd_endian enum. */
6230 arm_get_next_pcs_read_memory_unsigned_integer (CORE_ADDR memaddr
, int len
,
6233 return read_memory_unsigned_integer (memaddr
, len
,
6234 (enum bfd_endian
) byte_order
);
6237 /* Wrapper over gdbarch_addr_bits_remove for use in arm_get_next_pcs. */
6240 arm_get_next_pcs_addr_bits_remove (struct arm_get_next_pcs
*self
,
6243 return gdbarch_addr_bits_remove (self
->regcache
->arch (), val
);
6246 /* Wrapper over syscall_next_pc for use in get_next_pcs. */
6249 arm_get_next_pcs_syscall_next_pc (struct arm_get_next_pcs
*self
)
6254 /* Wrapper over arm_is_thumb for use in arm_get_next_pcs. */
6257 arm_get_next_pcs_is_thumb (struct arm_get_next_pcs
*self
)
6259 return arm_is_thumb (self
->regcache
);
6262 /* single_step() is called just before we want to resume the inferior,
6263 if we want to single-step it but there is no hardware or kernel
6264 single-step support. We find the target of the coming instructions
6265 and breakpoint them. */
6267 std::vector
<CORE_ADDR
>
6268 arm_software_single_step (struct regcache
*regcache
)
6270 struct gdbarch
*gdbarch
= regcache
->arch ();
6271 struct arm_get_next_pcs next_pcs_ctx
;
6273 arm_get_next_pcs_ctor (&next_pcs_ctx
,
6274 &arm_get_next_pcs_ops
,
6275 gdbarch_byte_order (gdbarch
),
6276 gdbarch_byte_order_for_code (gdbarch
),
6280 std::vector
<CORE_ADDR
> next_pcs
= arm_get_next_pcs (&next_pcs_ctx
);
6282 for (CORE_ADDR
&pc_ref
: next_pcs
)
6283 pc_ref
= gdbarch_addr_bits_remove (gdbarch
, pc_ref
);
6288 /* Cleanup/copy SVC (SWI) instructions. These two functions are overridden
6289 for Linux, where some SVC instructions must be treated specially. */
6292 cleanup_svc (struct gdbarch
*gdbarch
, struct regcache
*regs
,
6293 arm_displaced_step_copy_insn_closure
*dsc
)
6295 CORE_ADDR resume_addr
= dsc
->insn_addr
+ dsc
->insn_size
;
6297 displaced_debug_printf ("cleanup for svc, resume at %.8lx",
6298 (unsigned long) resume_addr
);
6300 displaced_write_reg (regs
, dsc
, ARM_PC_REGNUM
, resume_addr
, BRANCH_WRITE_PC
);
6304 /* Common copy routine for svc instruction. */
6307 install_svc (struct gdbarch
*gdbarch
, struct regcache
*regs
,
6308 arm_displaced_step_copy_insn_closure
*dsc
)
6310 /* Preparation: none.
6311 Insn: unmodified svc.
6312 Cleanup: pc <- insn_addr + insn_size. */
6314 /* Pretend we wrote to the PC, so cleanup doesn't set PC to the next
6316 dsc
->wrote_to_pc
= 1;
6318 /* Allow OS-specific code to override SVC handling. */
6319 if (dsc
->u
.svc
.copy_svc_os
)
6320 return dsc
->u
.svc
.copy_svc_os (gdbarch
, regs
, dsc
);
6323 dsc
->cleanup
= &cleanup_svc
;
6329 arm_copy_svc (struct gdbarch
*gdbarch
, uint32_t insn
,
6330 regcache
*regs
, arm_displaced_step_copy_insn_closure
*dsc
)
6333 displaced_debug_printf ("copying svc insn %.8lx",
6334 (unsigned long) insn
);
6336 dsc
->modinsn
[0] = insn
;
6338 return install_svc (gdbarch
, regs
, dsc
);
6342 thumb_copy_svc (struct gdbarch
*gdbarch
, uint16_t insn
,
6343 regcache
*regs
, arm_displaced_step_copy_insn_closure
*dsc
)
6346 displaced_debug_printf ("copying svc insn %.4x", insn
);
6348 dsc
->modinsn
[0] = insn
;
6350 return install_svc (gdbarch
, regs
, dsc
);
6353 /* Copy undefined instructions. */
6356 arm_copy_undef (struct gdbarch
*gdbarch
, uint32_t insn
,
6357 arm_displaced_step_copy_insn_closure
*dsc
)
6359 displaced_debug_printf ("copying undefined insn %.8lx",
6360 (unsigned long) insn
);
6362 dsc
->modinsn
[0] = insn
;
6368 thumb_32bit_copy_undef (struct gdbarch
*gdbarch
, uint16_t insn1
, uint16_t insn2
,
6369 arm_displaced_step_copy_insn_closure
*dsc
)
6372 displaced_debug_printf ("copying undefined insn %.4x %.4x",
6373 (unsigned short) insn1
, (unsigned short) insn2
);
6375 dsc
->modinsn
[0] = insn1
;
6376 dsc
->modinsn
[1] = insn2
;
6382 /* Copy unpredictable instructions. */
6385 arm_copy_unpred (struct gdbarch
*gdbarch
, uint32_t insn
,
6386 arm_displaced_step_copy_insn_closure
*dsc
)
6388 displaced_debug_printf ("copying unpredictable insn %.8lx",
6389 (unsigned long) insn
);
6391 dsc
->modinsn
[0] = insn
;
6396 /* The decode_* functions are instruction decoding helpers. They mostly follow
6397 the presentation in the ARM ARM. */
6400 arm_decode_misc_memhint_neon (struct gdbarch
*gdbarch
, uint32_t insn
,
6401 struct regcache
*regs
,
6402 arm_displaced_step_copy_insn_closure
*dsc
)
6404 unsigned int op1
= bits (insn
, 20, 26), op2
= bits (insn
, 4, 7);
6405 unsigned int rn
= bits (insn
, 16, 19);
6407 if (op1
== 0x10 && (op2
& 0x2) == 0x0 && (rn
& 0x1) == 0x0)
6408 return arm_copy_unmodified (gdbarch
, insn
, "cps", dsc
);
6409 else if (op1
== 0x10 && op2
== 0x0 && (rn
& 0x1) == 0x1)
6410 return arm_copy_unmodified (gdbarch
, insn
, "setend", dsc
);
6411 else if ((op1
& 0x60) == 0x20)
6412 return arm_copy_unmodified (gdbarch
, insn
, "neon dataproc", dsc
);
6413 else if ((op1
& 0x71) == 0x40)
6414 return arm_copy_unmodified (gdbarch
, insn
, "neon elt/struct load/store",
6416 else if ((op1
& 0x77) == 0x41)
6417 return arm_copy_unmodified (gdbarch
, insn
, "unallocated mem hint", dsc
);
6418 else if ((op1
& 0x77) == 0x45)
6419 return arm_copy_preload (gdbarch
, insn
, regs
, dsc
); /* pli. */
6420 else if ((op1
& 0x77) == 0x51)
6423 return arm_copy_preload (gdbarch
, insn
, regs
, dsc
); /* pld/pldw. */
6425 return arm_copy_unpred (gdbarch
, insn
, dsc
);
6427 else if ((op1
& 0x77) == 0x55)
6428 return arm_copy_preload (gdbarch
, insn
, regs
, dsc
); /* pld/pldw. */
6429 else if (op1
== 0x57)
6432 case 0x1: return arm_copy_unmodified (gdbarch
, insn
, "clrex", dsc
);
6433 case 0x4: return arm_copy_unmodified (gdbarch
, insn
, "dsb", dsc
);
6434 case 0x5: return arm_copy_unmodified (gdbarch
, insn
, "dmb", dsc
);
6435 case 0x6: return arm_copy_unmodified (gdbarch
, insn
, "isb", dsc
);
6436 default: return arm_copy_unpred (gdbarch
, insn
, dsc
);
6438 else if ((op1
& 0x63) == 0x43)
6439 return arm_copy_unpred (gdbarch
, insn
, dsc
);
6440 else if ((op2
& 0x1) == 0x0)
6441 switch (op1
& ~0x80)
6444 return arm_copy_unmodified (gdbarch
, insn
, "unallocated mem hint", dsc
);
6446 return arm_copy_preload_reg (gdbarch
, insn
, regs
, dsc
); /* pli reg. */
6447 case 0x71: case 0x75:
6449 return arm_copy_preload_reg (gdbarch
, insn
, regs
, dsc
);
6450 case 0x63: case 0x67: case 0x73: case 0x77:
6451 return arm_copy_unpred (gdbarch
, insn
, dsc
);
6453 return arm_copy_undef (gdbarch
, insn
, dsc
);
6456 return arm_copy_undef (gdbarch
, insn
, dsc
); /* Probably unreachable. */
6460 arm_decode_unconditional (struct gdbarch
*gdbarch
, uint32_t insn
,
6461 struct regcache
*regs
,
6462 arm_displaced_step_copy_insn_closure
*dsc
)
6464 if (bit (insn
, 27) == 0)
6465 return arm_decode_misc_memhint_neon (gdbarch
, insn
, regs
, dsc
);
6466 /* Switch on bits: 0bxxxxx321xxx0xxxxxxxxxxxxxxxxxxxx. */
6467 else switch (((insn
& 0x7000000) >> 23) | ((insn
& 0x100000) >> 20))
6470 return arm_copy_unmodified (gdbarch
, insn
, "srs", dsc
);
6473 return arm_copy_unmodified (gdbarch
, insn
, "rfe", dsc
);
6475 case 0x4: case 0x5: case 0x6: case 0x7:
6476 return arm_copy_b_bl_blx (gdbarch
, insn
, regs
, dsc
);
6479 switch ((insn
& 0xe00000) >> 21)
6481 case 0x1: case 0x3: case 0x4: case 0x5: case 0x6: case 0x7:
6483 return arm_copy_copro_load_store (gdbarch
, insn
, regs
, dsc
);
6486 return arm_copy_unmodified (gdbarch
, insn
, "mcrr/mcrr2", dsc
);
6489 return arm_copy_undef (gdbarch
, insn
, dsc
);
6494 int rn_f
= (bits (insn
, 16, 19) == 0xf);
6495 switch ((insn
& 0xe00000) >> 21)
6498 /* ldc/ldc2 imm (undefined for rn == pc). */
6499 return rn_f
? arm_copy_undef (gdbarch
, insn
, dsc
)
6500 : arm_copy_copro_load_store (gdbarch
, insn
, regs
, dsc
);
6503 return arm_copy_unmodified (gdbarch
, insn
, "mrrc/mrrc2", dsc
);
6505 case 0x4: case 0x5: case 0x6: case 0x7:
6506 /* ldc/ldc2 lit (undefined for rn != pc). */
6507 return rn_f
? arm_copy_copro_load_store (gdbarch
, insn
, regs
, dsc
)
6508 : arm_copy_undef (gdbarch
, insn
, dsc
);
6511 return arm_copy_undef (gdbarch
, insn
, dsc
);
6516 return arm_copy_unmodified (gdbarch
, insn
, "stc/stc2", dsc
);
6519 if (bits (insn
, 16, 19) == 0xf)
6521 return arm_copy_copro_load_store (gdbarch
, insn
, regs
, dsc
);
6523 return arm_copy_undef (gdbarch
, insn
, dsc
);
6527 return arm_copy_unmodified (gdbarch
, insn
, "mcr/mcr2", dsc
);
6529 return arm_copy_unmodified (gdbarch
, insn
, "cdp/cdp2", dsc
);
6533 return arm_copy_unmodified (gdbarch
, insn
, "mrc/mrc2", dsc
);
6535 return arm_copy_unmodified (gdbarch
, insn
, "cdp/cdp2", dsc
);
6538 return arm_copy_undef (gdbarch
, insn
, dsc
);
6542 /* Decode miscellaneous instructions in dp/misc encoding space. */
6545 arm_decode_miscellaneous (struct gdbarch
*gdbarch
, uint32_t insn
,
6546 struct regcache
*regs
,
6547 arm_displaced_step_copy_insn_closure
*dsc
)
6549 unsigned int op2
= bits (insn
, 4, 6);
6550 unsigned int op
= bits (insn
, 21, 22);
6555 return arm_copy_unmodified (gdbarch
, insn
, "mrs/msr", dsc
);
6558 if (op
== 0x1) /* bx. */
6559 return arm_copy_bx_blx_reg (gdbarch
, insn
, regs
, dsc
);
6561 return arm_copy_unmodified (gdbarch
, insn
, "clz", dsc
);
6563 return arm_copy_undef (gdbarch
, insn
, dsc
);
6567 /* Not really supported. */
6568 return arm_copy_unmodified (gdbarch
, insn
, "bxj", dsc
);
6570 return arm_copy_undef (gdbarch
, insn
, dsc
);
6574 return arm_copy_bx_blx_reg (gdbarch
, insn
,
6575 regs
, dsc
); /* blx register. */
6577 return arm_copy_undef (gdbarch
, insn
, dsc
);
6580 return arm_copy_unmodified (gdbarch
, insn
, "saturating add/sub", dsc
);
6584 return arm_copy_unmodified (gdbarch
, insn
, "bkpt", dsc
);
6586 /* Not really supported. */
6587 return arm_copy_unmodified (gdbarch
, insn
, "smc", dsc
);
6591 return arm_copy_undef (gdbarch
, insn
, dsc
);
6596 arm_decode_dp_misc (struct gdbarch
*gdbarch
, uint32_t insn
,
6597 struct regcache
*regs
,
6598 arm_displaced_step_copy_insn_closure
*dsc
)
6601 switch (bits (insn
, 20, 24))
6604 return arm_copy_unmodified (gdbarch
, insn
, "movw", dsc
);
6607 return arm_copy_unmodified (gdbarch
, insn
, "movt", dsc
);
6609 case 0x12: case 0x16:
6610 return arm_copy_unmodified (gdbarch
, insn
, "msr imm", dsc
);
6613 return arm_copy_alu_imm (gdbarch
, insn
, regs
, dsc
);
6617 uint32_t op1
= bits (insn
, 20, 24), op2
= bits (insn
, 4, 7);
6619 if ((op1
& 0x19) != 0x10 && (op2
& 0x1) == 0x0)
6620 return arm_copy_alu_reg (gdbarch
, insn
, regs
, dsc
);
6621 else if ((op1
& 0x19) != 0x10 && (op2
& 0x9) == 0x1)
6622 return arm_copy_alu_shifted_reg (gdbarch
, insn
, regs
, dsc
);
6623 else if ((op1
& 0x19) == 0x10 && (op2
& 0x8) == 0x0)
6624 return arm_decode_miscellaneous (gdbarch
, insn
, regs
, dsc
);
6625 else if ((op1
& 0x19) == 0x10 && (op2
& 0x9) == 0x8)
6626 return arm_copy_unmodified (gdbarch
, insn
, "halfword mul/mla", dsc
);
6627 else if ((op1
& 0x10) == 0x00 && op2
== 0x9)
6628 return arm_copy_unmodified (gdbarch
, insn
, "mul/mla", dsc
);
6629 else if ((op1
& 0x10) == 0x10 && op2
== 0x9)
6630 return arm_copy_unmodified (gdbarch
, insn
, "synch", dsc
);
6631 else if (op2
== 0xb || (op2
& 0xd) == 0xd)
6632 /* 2nd arg means "unprivileged". */
6633 return arm_copy_extra_ld_st (gdbarch
, insn
, (op1
& 0x12) == 0x02, regs
,
6637 /* Should be unreachable. */
6642 arm_decode_ld_st_word_ubyte (struct gdbarch
*gdbarch
, uint32_t insn
,
6643 struct regcache
*regs
,
6644 arm_displaced_step_copy_insn_closure
*dsc
)
6646 int a
= bit (insn
, 25), b
= bit (insn
, 4);
6647 uint32_t op1
= bits (insn
, 20, 24);
6649 if ((!a
&& (op1
& 0x05) == 0x00 && (op1
& 0x17) != 0x02)
6650 || (a
&& (op1
& 0x05) == 0x00 && (op1
& 0x17) != 0x02 && !b
))
6651 return arm_copy_ldr_str_ldrb_strb (gdbarch
, insn
, regs
, dsc
, 0, 4, 0);
6652 else if ((!a
&& (op1
& 0x17) == 0x02)
6653 || (a
&& (op1
& 0x17) == 0x02 && !b
))
6654 return arm_copy_ldr_str_ldrb_strb (gdbarch
, insn
, regs
, dsc
, 0, 4, 1);
6655 else if ((!a
&& (op1
& 0x05) == 0x01 && (op1
& 0x17) != 0x03)
6656 || (a
&& (op1
& 0x05) == 0x01 && (op1
& 0x17) != 0x03 && !b
))
6657 return arm_copy_ldr_str_ldrb_strb (gdbarch
, insn
, regs
, dsc
, 1, 4, 0);
6658 else if ((!a
&& (op1
& 0x17) == 0x03)
6659 || (a
&& (op1
& 0x17) == 0x03 && !b
))
6660 return arm_copy_ldr_str_ldrb_strb (gdbarch
, insn
, regs
, dsc
, 1, 4, 1);
6661 else if ((!a
&& (op1
& 0x05) == 0x04 && (op1
& 0x17) != 0x06)
6662 || (a
&& (op1
& 0x05) == 0x04 && (op1
& 0x17) != 0x06 && !b
))
6663 return arm_copy_ldr_str_ldrb_strb (gdbarch
, insn
, regs
, dsc
, 0, 1, 0);
6664 else if ((!a
&& (op1
& 0x17) == 0x06)
6665 || (a
&& (op1
& 0x17) == 0x06 && !b
))
6666 return arm_copy_ldr_str_ldrb_strb (gdbarch
, insn
, regs
, dsc
, 0, 1, 1);
6667 else if ((!a
&& (op1
& 0x05) == 0x05 && (op1
& 0x17) != 0x07)
6668 || (a
&& (op1
& 0x05) == 0x05 && (op1
& 0x17) != 0x07 && !b
))
6669 return arm_copy_ldr_str_ldrb_strb (gdbarch
, insn
, regs
, dsc
, 1, 1, 0);
6670 else if ((!a
&& (op1
& 0x17) == 0x07)
6671 || (a
&& (op1
& 0x17) == 0x07 && !b
))
6672 return arm_copy_ldr_str_ldrb_strb (gdbarch
, insn
, regs
, dsc
, 1, 1, 1);
6674 /* Should be unreachable. */
6679 arm_decode_media (struct gdbarch
*gdbarch
, uint32_t insn
,
6680 arm_displaced_step_copy_insn_closure
*dsc
)
6682 switch (bits (insn
, 20, 24))
6684 case 0x00: case 0x01: case 0x02: case 0x03:
6685 return arm_copy_unmodified (gdbarch
, insn
, "parallel add/sub signed", dsc
);
6687 case 0x04: case 0x05: case 0x06: case 0x07:
6688 return arm_copy_unmodified (gdbarch
, insn
, "parallel add/sub unsigned", dsc
);
6690 case 0x08: case 0x09: case 0x0a: case 0x0b:
6691 case 0x0c: case 0x0d: case 0x0e: case 0x0f:
6692 return arm_copy_unmodified (gdbarch
, insn
,
6693 "decode/pack/unpack/saturate/reverse", dsc
);
6696 if (bits (insn
, 5, 7) == 0) /* op2. */
6698 if (bits (insn
, 12, 15) == 0xf)
6699 return arm_copy_unmodified (gdbarch
, insn
, "usad8", dsc
);
6701 return arm_copy_unmodified (gdbarch
, insn
, "usada8", dsc
);
6704 return arm_copy_undef (gdbarch
, insn
, dsc
);
6706 case 0x1a: case 0x1b:
6707 if (bits (insn
, 5, 6) == 0x2) /* op2[1:0]. */
6708 return arm_copy_unmodified (gdbarch
, insn
, "sbfx", dsc
);
6710 return arm_copy_undef (gdbarch
, insn
, dsc
);
6712 case 0x1c: case 0x1d:
6713 if (bits (insn
, 5, 6) == 0x0) /* op2[1:0]. */
6715 if (bits (insn
, 0, 3) == 0xf)
6716 return arm_copy_unmodified (gdbarch
, insn
, "bfc", dsc
);
6718 return arm_copy_unmodified (gdbarch
, insn
, "bfi", dsc
);
6721 return arm_copy_undef (gdbarch
, insn
, dsc
);
6723 case 0x1e: case 0x1f:
6724 if (bits (insn
, 5, 6) == 0x2) /* op2[1:0]. */
6725 return arm_copy_unmodified (gdbarch
, insn
, "ubfx", dsc
);
6727 return arm_copy_undef (gdbarch
, insn
, dsc
);
6730 /* Should be unreachable. */
6735 arm_decode_b_bl_ldmstm (struct gdbarch
*gdbarch
, uint32_t insn
,
6736 struct regcache
*regs
,
6737 arm_displaced_step_copy_insn_closure
*dsc
)
6740 return arm_copy_b_bl_blx (gdbarch
, insn
, regs
, dsc
);
6742 return arm_copy_block_xfer (gdbarch
, insn
, regs
, dsc
);
6746 arm_decode_ext_reg_ld_st (struct gdbarch
*gdbarch
, uint32_t insn
,
6747 struct regcache
*regs
,
6748 arm_displaced_step_copy_insn_closure
*dsc
)
6750 unsigned int opcode
= bits (insn
, 20, 24);
6754 case 0x04: case 0x05: /* VFP/Neon mrrc/mcrr. */
6755 return arm_copy_unmodified (gdbarch
, insn
, "vfp/neon mrrc/mcrr", dsc
);
6757 case 0x08: case 0x0a: case 0x0c: case 0x0e:
6758 case 0x12: case 0x16:
6759 return arm_copy_unmodified (gdbarch
, insn
, "vfp/neon vstm/vpush", dsc
);
6761 case 0x09: case 0x0b: case 0x0d: case 0x0f:
6762 case 0x13: case 0x17:
6763 return arm_copy_unmodified (gdbarch
, insn
, "vfp/neon vldm/vpop", dsc
);
6765 case 0x10: case 0x14: case 0x18: case 0x1c: /* vstr. */
6766 case 0x11: case 0x15: case 0x19: case 0x1d: /* vldr. */
6767 /* Note: no writeback for these instructions. Bit 25 will always be
6768 zero though (via caller), so the following works OK. */
6769 return arm_copy_copro_load_store (gdbarch
, insn
, regs
, dsc
);
6772 /* Should be unreachable. */
6776 /* Decode shifted register instructions. */
6779 thumb2_decode_dp_shift_reg (struct gdbarch
*gdbarch
, uint16_t insn1
,
6780 uint16_t insn2
, struct regcache
*regs
,
6781 arm_displaced_step_copy_insn_closure
*dsc
)
6783 /* PC is only allowed to be used in instruction MOV. */
6785 unsigned int op
= bits (insn1
, 5, 8);
6786 unsigned int rn
= bits (insn1
, 0, 3);
6788 if (op
== 0x2 && rn
== 0xf) /* MOV */
6789 return thumb2_copy_alu_imm (gdbarch
, insn1
, insn2
, regs
, dsc
);
6791 return thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
,
6792 "dp (shift reg)", dsc
);
6796 /* Decode extension register load/store. Exactly the same as
6797 arm_decode_ext_reg_ld_st. */
6800 thumb2_decode_ext_reg_ld_st (struct gdbarch
*gdbarch
, uint16_t insn1
,
6801 uint16_t insn2
, struct regcache
*regs
,
6802 arm_displaced_step_copy_insn_closure
*dsc
)
6804 unsigned int opcode
= bits (insn1
, 4, 8);
6808 case 0x04: case 0x05:
6809 return thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
,
6810 "vfp/neon vmov", dsc
);
6812 case 0x08: case 0x0c: /* 01x00 */
6813 case 0x0a: case 0x0e: /* 01x10 */
6814 case 0x12: case 0x16: /* 10x10 */
6815 return thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
,
6816 "vfp/neon vstm/vpush", dsc
);
6818 case 0x09: case 0x0d: /* 01x01 */
6819 case 0x0b: case 0x0f: /* 01x11 */
6820 case 0x13: case 0x17: /* 10x11 */
6821 return thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
,
6822 "vfp/neon vldm/vpop", dsc
);
6824 case 0x10: case 0x14: case 0x18: case 0x1c: /* vstr. */
6825 return thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
,
6827 case 0x11: case 0x15: case 0x19: case 0x1d: /* vldr. */
6828 return thumb2_copy_copro_load_store (gdbarch
, insn1
, insn2
, regs
, dsc
);
6831 /* Should be unreachable. */
6836 arm_decode_svc_copro (struct gdbarch
*gdbarch
, uint32_t insn
,
6837 regcache
*regs
, arm_displaced_step_copy_insn_closure
*dsc
)
6839 unsigned int op1
= bits (insn
, 20, 25);
6840 int op
= bit (insn
, 4);
6841 unsigned int coproc
= bits (insn
, 8, 11);
6843 if ((op1
& 0x20) == 0x00 && (op1
& 0x3a) != 0x00 && (coproc
& 0xe) == 0xa)
6844 return arm_decode_ext_reg_ld_st (gdbarch
, insn
, regs
, dsc
);
6845 else if ((op1
& 0x21) == 0x00 && (op1
& 0x3a) != 0x00
6846 && (coproc
& 0xe) != 0xa)
6848 return arm_copy_copro_load_store (gdbarch
, insn
, regs
, dsc
);
6849 else if ((op1
& 0x21) == 0x01 && (op1
& 0x3a) != 0x00
6850 && (coproc
& 0xe) != 0xa)
6851 /* ldc/ldc2 imm/lit. */
6852 return arm_copy_copro_load_store (gdbarch
, insn
, regs
, dsc
);
6853 else if ((op1
& 0x3e) == 0x00)
6854 return arm_copy_undef (gdbarch
, insn
, dsc
);
6855 else if ((op1
& 0x3e) == 0x04 && (coproc
& 0xe) == 0xa)
6856 return arm_copy_unmodified (gdbarch
, insn
, "neon 64bit xfer", dsc
);
6857 else if (op1
== 0x04 && (coproc
& 0xe) != 0xa)
6858 return arm_copy_unmodified (gdbarch
, insn
, "mcrr/mcrr2", dsc
);
6859 else if (op1
== 0x05 && (coproc
& 0xe) != 0xa)
6860 return arm_copy_unmodified (gdbarch
, insn
, "mrrc/mrrc2", dsc
);
6861 else if ((op1
& 0x30) == 0x20 && !op
)
6863 if ((coproc
& 0xe) == 0xa)
6864 return arm_copy_unmodified (gdbarch
, insn
, "vfp dataproc", dsc
);
6866 return arm_copy_unmodified (gdbarch
, insn
, "cdp/cdp2", dsc
);
6868 else if ((op1
& 0x30) == 0x20 && op
)
6869 return arm_copy_unmodified (gdbarch
, insn
, "neon 8/16/32 bit xfer", dsc
);
6870 else if ((op1
& 0x31) == 0x20 && op
&& (coproc
& 0xe) != 0xa)
6871 return arm_copy_unmodified (gdbarch
, insn
, "mcr/mcr2", dsc
);
6872 else if ((op1
& 0x31) == 0x21 && op
&& (coproc
& 0xe) != 0xa)
6873 return arm_copy_unmodified (gdbarch
, insn
, "mrc/mrc2", dsc
);
6874 else if ((op1
& 0x30) == 0x30)
6875 return arm_copy_svc (gdbarch
, insn
, regs
, dsc
);
6877 return arm_copy_undef (gdbarch
, insn
, dsc
); /* Possibly unreachable. */
6881 thumb2_decode_svc_copro (struct gdbarch
*gdbarch
, uint16_t insn1
,
6882 uint16_t insn2
, struct regcache
*regs
,
6883 arm_displaced_step_copy_insn_closure
*dsc
)
6885 unsigned int coproc
= bits (insn2
, 8, 11);
6886 unsigned int bit_5_8
= bits (insn1
, 5, 8);
6887 unsigned int bit_9
= bit (insn1
, 9);
6888 unsigned int bit_4
= bit (insn1
, 4);
6893 return thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
,
6894 "neon 64bit xfer/mrrc/mrrc2/mcrr/mcrr2",
6896 else if (bit_5_8
== 0) /* UNDEFINED. */
6897 return thumb_32bit_copy_undef (gdbarch
, insn1
, insn2
, dsc
);
6900 /*coproc is 101x. SIMD/VFP, ext registers load/store. */
6901 if ((coproc
& 0xe) == 0xa)
6902 return thumb2_decode_ext_reg_ld_st (gdbarch
, insn1
, insn2
, regs
,
6904 else /* coproc is not 101x. */
6906 if (bit_4
== 0) /* STC/STC2. */
6907 return thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
,
6909 else /* LDC/LDC2 {literal, immediate}. */
6910 return thumb2_copy_copro_load_store (gdbarch
, insn1
, insn2
,
6916 return thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
, "coproc", dsc
);
6922 install_pc_relative (struct gdbarch
*gdbarch
, struct regcache
*regs
,
6923 arm_displaced_step_copy_insn_closure
*dsc
, int rd
)
6929 Preparation: Rd <- PC
6935 int val
= displaced_read_reg (regs
, dsc
, ARM_PC_REGNUM
);
6936 displaced_write_reg (regs
, dsc
, rd
, val
, CANNOT_WRITE_PC
);
6940 thumb_copy_pc_relative_16bit (struct gdbarch
*gdbarch
, struct regcache
*regs
,
6941 arm_displaced_step_copy_insn_closure
*dsc
,
6942 int rd
, unsigned int imm
)
6945 /* Encoding T2: ADDS Rd, #imm */
6946 dsc
->modinsn
[0] = (0x3000 | (rd
<< 8) | imm
);
6948 install_pc_relative (gdbarch
, regs
, dsc
, rd
);
6954 thumb_decode_pc_relative_16bit (struct gdbarch
*gdbarch
, uint16_t insn
,
6955 struct regcache
*regs
,
6956 arm_displaced_step_copy_insn_closure
*dsc
)
6958 unsigned int rd
= bits (insn
, 8, 10);
6959 unsigned int imm8
= bits (insn
, 0, 7);
6961 displaced_debug_printf ("copying thumb adr r%d, #%d insn %.4x",
6964 return thumb_copy_pc_relative_16bit (gdbarch
, regs
, dsc
, rd
, imm8
);
6968 thumb_copy_pc_relative_32bit (struct gdbarch
*gdbarch
, uint16_t insn1
,
6969 uint16_t insn2
, struct regcache
*regs
,
6970 arm_displaced_step_copy_insn_closure
*dsc
)
6972 unsigned int rd
= bits (insn2
, 8, 11);
6973 /* Since immediate has the same encoding in ADR ADD and SUB, so we simply
6974 extract raw immediate encoding rather than computing immediate. When
6975 generating ADD or SUB instruction, we can simply perform OR operation to
6976 set immediate into ADD. */
6977 unsigned int imm_3_8
= insn2
& 0x70ff;
6978 unsigned int imm_i
= insn1
& 0x0400; /* Clear all bits except bit 10. */
6980 displaced_debug_printf ("copying thumb adr r%d, #%d:%d insn %.4x%.4x",
6981 rd
, imm_i
, imm_3_8
, insn1
, insn2
);
6983 if (bit (insn1
, 7)) /* Encoding T2 */
6985 /* Encoding T3: SUB Rd, Rd, #imm */
6986 dsc
->modinsn
[0] = (0xf1a0 | rd
| imm_i
);
6987 dsc
->modinsn
[1] = ((rd
<< 8) | imm_3_8
);
6989 else /* Encoding T3 */
6991 /* Encoding T3: ADD Rd, Rd, #imm */
6992 dsc
->modinsn
[0] = (0xf100 | rd
| imm_i
);
6993 dsc
->modinsn
[1] = ((rd
<< 8) | imm_3_8
);
6997 install_pc_relative (gdbarch
, regs
, dsc
, rd
);
7003 thumb_copy_16bit_ldr_literal (struct gdbarch
*gdbarch
, uint16_t insn1
,
7004 struct regcache
*regs
,
7005 arm_displaced_step_copy_insn_closure
*dsc
)
7007 unsigned int rt
= bits (insn1
, 8, 10);
7009 int imm8
= (bits (insn1
, 0, 7) << 2);
7015 Preparation: tmp0 <- R0, tmp2 <- R2, tmp3 <- R3, R2 <- PC, R3 <- #imm8;
7017 Insn: LDR R0, [R2, R3];
7018 Cleanup: R2 <- tmp2, R3 <- tmp3, Rd <- R0, R0 <- tmp0 */
7020 displaced_debug_printf ("copying thumb ldr r%d [pc #%d]", rt
, imm8
);
7022 dsc
->tmp
[0] = displaced_read_reg (regs
, dsc
, 0);
7023 dsc
->tmp
[2] = displaced_read_reg (regs
, dsc
, 2);
7024 dsc
->tmp
[3] = displaced_read_reg (regs
, dsc
, 3);
7025 pc
= displaced_read_reg (regs
, dsc
, ARM_PC_REGNUM
);
7026 /* The assembler calculates the required value of the offset from the
7027 Align(PC,4) value of this instruction to the label. */
7028 pc
= pc
& 0xfffffffc;
7030 displaced_write_reg (regs
, dsc
, 2, pc
, CANNOT_WRITE_PC
);
7031 displaced_write_reg (regs
, dsc
, 3, imm8
, CANNOT_WRITE_PC
);
7034 dsc
->u
.ldst
.xfersize
= 4;
7036 dsc
->u
.ldst
.immed
= 0;
7037 dsc
->u
.ldst
.writeback
= 0;
7038 dsc
->u
.ldst
.restore_r4
= 0;
7040 dsc
->modinsn
[0] = 0x58d0; /* ldr r0, [r2, r3]*/
7042 dsc
->cleanup
= &cleanup_load
;
7047 /* Copy Thumb cbnz/cbz instruction. */
7050 thumb_copy_cbnz_cbz (struct gdbarch
*gdbarch
, uint16_t insn1
,
7051 struct regcache
*regs
,
7052 arm_displaced_step_copy_insn_closure
*dsc
)
7054 int non_zero
= bit (insn1
, 11);
7055 unsigned int imm5
= (bit (insn1
, 9) << 6) | (bits (insn1
, 3, 7) << 1);
7056 CORE_ADDR from
= dsc
->insn_addr
;
7057 int rn
= bits (insn1
, 0, 2);
7058 int rn_val
= displaced_read_reg (regs
, dsc
, rn
);
7060 dsc
->u
.branch
.cond
= (rn_val
&& non_zero
) || (!rn_val
&& !non_zero
);
7061 /* CBNZ and CBZ do not affect the condition flags. If condition is true,
7062 set it INST_AL, so cleanup_branch will know branch is taken, otherwise,
7063 condition is false, let it be, cleanup_branch will do nothing. */
7064 if (dsc
->u
.branch
.cond
)
7066 dsc
->u
.branch
.cond
= INST_AL
;
7067 dsc
->u
.branch
.dest
= from
+ 4 + imm5
;
7070 dsc
->u
.branch
.dest
= from
+ 2;
7072 dsc
->u
.branch
.link
= 0;
7073 dsc
->u
.branch
.exchange
= 0;
7075 displaced_debug_printf ("copying %s [r%d = 0x%x] insn %.4x to %.8lx",
7076 non_zero
? "cbnz" : "cbz",
7077 rn
, rn_val
, insn1
, dsc
->u
.branch
.dest
);
7079 dsc
->modinsn
[0] = THUMB_NOP
;
7081 dsc
->cleanup
= &cleanup_branch
;
7085 /* Copy Table Branch Byte/Halfword */
7087 thumb2_copy_table_branch (struct gdbarch
*gdbarch
, uint16_t insn1
,
7088 uint16_t insn2
, struct regcache
*regs
,
7089 arm_displaced_step_copy_insn_closure
*dsc
)
7091 ULONGEST rn_val
, rm_val
;
7092 int is_tbh
= bit (insn2
, 4);
7093 CORE_ADDR halfwords
= 0;
7094 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
7096 rn_val
= displaced_read_reg (regs
, dsc
, bits (insn1
, 0, 3));
7097 rm_val
= displaced_read_reg (regs
, dsc
, bits (insn2
, 0, 3));
7103 target_read_memory (rn_val
+ 2 * rm_val
, buf
, 2);
7104 halfwords
= extract_unsigned_integer (buf
, 2, byte_order
);
7110 target_read_memory (rn_val
+ rm_val
, buf
, 1);
7111 halfwords
= extract_unsigned_integer (buf
, 1, byte_order
);
7114 displaced_debug_printf ("%s base 0x%x offset 0x%x offset 0x%x",
7115 is_tbh
? "tbh" : "tbb",
7116 (unsigned int) rn_val
, (unsigned int) rm_val
,
7117 (unsigned int) halfwords
);
7119 dsc
->u
.branch
.cond
= INST_AL
;
7120 dsc
->u
.branch
.link
= 0;
7121 dsc
->u
.branch
.exchange
= 0;
7122 dsc
->u
.branch
.dest
= dsc
->insn_addr
+ 4 + 2 * halfwords
;
7124 dsc
->cleanup
= &cleanup_branch
;
7130 cleanup_pop_pc_16bit_all (struct gdbarch
*gdbarch
, struct regcache
*regs
,
7131 arm_displaced_step_copy_insn_closure
*dsc
)
7134 int val
= displaced_read_reg (regs
, dsc
, 7);
7135 displaced_write_reg (regs
, dsc
, ARM_PC_REGNUM
, val
, BX_WRITE_PC
);
7138 val
= displaced_read_reg (regs
, dsc
, 8);
7139 displaced_write_reg (regs
, dsc
, 7, val
, CANNOT_WRITE_PC
);
7142 displaced_write_reg (regs
, dsc
, 8, dsc
->tmp
[0], CANNOT_WRITE_PC
);
7147 thumb_copy_pop_pc_16bit (struct gdbarch
*gdbarch
, uint16_t insn1
,
7148 struct regcache
*regs
,
7149 arm_displaced_step_copy_insn_closure
*dsc
)
7151 dsc
->u
.block
.regmask
= insn1
& 0x00ff;
7153 /* Rewrite instruction: POP {rX, rY, ...,rZ, PC}
7156 (1) register list is full, that is, r0-r7 are used.
7157 Prepare: tmp[0] <- r8
7159 POP {r0, r1, ...., r6, r7}; remove PC from reglist
7160 MOV r8, r7; Move value of r7 to r8;
7161 POP {r7}; Store PC value into r7.
7163 Cleanup: PC <- r7, r7 <- r8, r8 <-tmp[0]
7165 (2) register list is not full, supposing there are N registers in
7166 register list (except PC, 0 <= N <= 7).
7167 Prepare: for each i, 0 - N, tmp[i] <- ri.
7169 POP {r0, r1, ...., rN};
7171 Cleanup: Set registers in original reglist from r0 - rN. Restore r0 - rN
7172 from tmp[] properly.
7174 displaced_debug_printf ("copying thumb pop {%.8x, pc} insn %.4x",
7175 dsc
->u
.block
.regmask
, insn1
);
7177 if (dsc
->u
.block
.regmask
== 0xff)
7179 dsc
->tmp
[0] = displaced_read_reg (regs
, dsc
, 8);
7181 dsc
->modinsn
[0] = (insn1
& 0xfeff); /* POP {r0,r1,...,r6, r7} */
7182 dsc
->modinsn
[1] = 0x46b8; /* MOV r8, r7 */
7183 dsc
->modinsn
[2] = 0xbc80; /* POP {r7} */
7186 dsc
->cleanup
= &cleanup_pop_pc_16bit_all
;
7190 unsigned int num_in_list
= count_one_bits (dsc
->u
.block
.regmask
);
7192 unsigned int new_regmask
;
7194 for (i
= 0; i
< num_in_list
+ 1; i
++)
7195 dsc
->tmp
[i
] = displaced_read_reg (regs
, dsc
, i
);
7197 new_regmask
= (1 << (num_in_list
+ 1)) - 1;
7199 displaced_debug_printf ("POP {..., pc}: original reg list %.4x, "
7200 "modified list %.4x",
7201 (int) dsc
->u
.block
.regmask
, new_regmask
);
7203 dsc
->u
.block
.regmask
|= 0x8000;
7204 dsc
->u
.block
.writeback
= 0;
7205 dsc
->u
.block
.cond
= INST_AL
;
7207 dsc
->modinsn
[0] = (insn1
& ~0x1ff) | (new_regmask
& 0xff);
7209 dsc
->cleanup
= &cleanup_block_load_pc
;
7216 thumb_process_displaced_16bit_insn (struct gdbarch
*gdbarch
, uint16_t insn1
,
7217 struct regcache
*regs
,
7218 arm_displaced_step_copy_insn_closure
*dsc
)
7220 unsigned short op_bit_12_15
= bits (insn1
, 12, 15);
7221 unsigned short op_bit_10_11
= bits (insn1
, 10, 11);
7224 /* 16-bit thumb instructions. */
7225 switch (op_bit_12_15
)
7227 /* Shift (imme), add, subtract, move and compare. */
7228 case 0: case 1: case 2: case 3:
7229 err
= thumb_copy_unmodified_16bit (gdbarch
, insn1
,
7230 "shift/add/sub/mov/cmp",
7234 switch (op_bit_10_11
)
7236 case 0: /* Data-processing */
7237 err
= thumb_copy_unmodified_16bit (gdbarch
, insn1
,
7241 case 1: /* Special data instructions and branch and exchange. */
7243 unsigned short op
= bits (insn1
, 7, 9);
7244 if (op
== 6 || op
== 7) /* BX or BLX */
7245 err
= thumb_copy_bx_blx_reg (gdbarch
, insn1
, regs
, dsc
);
7246 else if (bits (insn1
, 6, 7) != 0) /* ADD/MOV/CMP high registers. */
7247 err
= thumb_copy_alu_reg (gdbarch
, insn1
, regs
, dsc
);
7249 err
= thumb_copy_unmodified_16bit (gdbarch
, insn1
, "special data",
7253 default: /* LDR (literal) */
7254 err
= thumb_copy_16bit_ldr_literal (gdbarch
, insn1
, regs
, dsc
);
7257 case 5: case 6: case 7: case 8: case 9: /* Load/Store single data item */
7258 err
= thumb_copy_unmodified_16bit (gdbarch
, insn1
, "ldr/str", dsc
);
7261 if (op_bit_10_11
< 2) /* Generate PC-relative address */
7262 err
= thumb_decode_pc_relative_16bit (gdbarch
, insn1
, regs
, dsc
);
7263 else /* Generate SP-relative address */
7264 err
= thumb_copy_unmodified_16bit (gdbarch
, insn1
, "sp-relative", dsc
);
7266 case 11: /* Misc 16-bit instructions */
7268 switch (bits (insn1
, 8, 11))
7270 case 1: case 3: case 9: case 11: /* CBNZ, CBZ */
7271 err
= thumb_copy_cbnz_cbz (gdbarch
, insn1
, regs
, dsc
);
7273 case 12: case 13: /* POP */
7274 if (bit (insn1
, 8)) /* PC is in register list. */
7275 err
= thumb_copy_pop_pc_16bit (gdbarch
, insn1
, regs
, dsc
);
7277 err
= thumb_copy_unmodified_16bit (gdbarch
, insn1
, "pop", dsc
);
7279 case 15: /* If-Then, and hints */
7280 if (bits (insn1
, 0, 3))
7281 /* If-Then makes up to four following instructions conditional.
7282 IT instruction itself is not conditional, so handle it as a
7283 common unmodified instruction. */
7284 err
= thumb_copy_unmodified_16bit (gdbarch
, insn1
, "If-Then",
7287 err
= thumb_copy_unmodified_16bit (gdbarch
, insn1
, "hints", dsc
);
7290 err
= thumb_copy_unmodified_16bit (gdbarch
, insn1
, "misc", dsc
);
7295 if (op_bit_10_11
< 2) /* Store multiple registers */
7296 err
= thumb_copy_unmodified_16bit (gdbarch
, insn1
, "stm", dsc
);
7297 else /* Load multiple registers */
7298 err
= thumb_copy_unmodified_16bit (gdbarch
, insn1
, "ldm", dsc
);
7300 case 13: /* Conditional branch and supervisor call */
7301 if (bits (insn1
, 9, 11) != 7) /* conditional branch */
7302 err
= thumb_copy_b (gdbarch
, insn1
, dsc
);
7304 err
= thumb_copy_svc (gdbarch
, insn1
, regs
, dsc
);
7306 case 14: /* Unconditional branch */
7307 err
= thumb_copy_b (gdbarch
, insn1
, dsc
);
7314 internal_error (__FILE__
, __LINE__
,
7315 _("thumb_process_displaced_16bit_insn: Instruction decode error"));
7319 decode_thumb_32bit_ld_mem_hints (struct gdbarch
*gdbarch
,
7320 uint16_t insn1
, uint16_t insn2
,
7321 struct regcache
*regs
,
7322 arm_displaced_step_copy_insn_closure
*dsc
)
7324 int rt
= bits (insn2
, 12, 15);
7325 int rn
= bits (insn1
, 0, 3);
7326 int op1
= bits (insn1
, 7, 8);
7328 switch (bits (insn1
, 5, 6))
7330 case 0: /* Load byte and memory hints */
7331 if (rt
== 0xf) /* PLD/PLI */
7334 /* PLD literal or Encoding T3 of PLI(immediate, literal). */
7335 return thumb2_copy_preload (gdbarch
, insn1
, insn2
, regs
, dsc
);
7337 return thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
,
7342 if (rn
== 0xf) /* LDRB/LDRSB (literal) */
7343 return thumb2_copy_load_literal (gdbarch
, insn1
, insn2
, regs
, dsc
,
7346 return thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
,
7347 "ldrb{reg, immediate}/ldrbt",
7352 case 1: /* Load halfword and memory hints. */
7353 if (rt
== 0xf) /* PLD{W} and Unalloc memory hint. */
7354 return thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
,
7355 "pld/unalloc memhint", dsc
);
7359 return thumb2_copy_load_literal (gdbarch
, insn1
, insn2
, regs
, dsc
,
7362 return thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
,
7366 case 2: /* Load word */
7368 int insn2_bit_8_11
= bits (insn2
, 8, 11);
7371 return thumb2_copy_load_literal (gdbarch
, insn1
, insn2
, regs
, dsc
, 4);
7372 else if (op1
== 0x1) /* Encoding T3 */
7373 return thumb2_copy_load_reg_imm (gdbarch
, insn1
, insn2
, regs
, dsc
,
7375 else /* op1 == 0x0 */
7377 if (insn2_bit_8_11
== 0xc || (insn2_bit_8_11
& 0x9) == 0x9)
7378 /* LDR (immediate) */
7379 return thumb2_copy_load_reg_imm (gdbarch
, insn1
, insn2
, regs
,
7380 dsc
, bit (insn2
, 8), 1);
7381 else if (insn2_bit_8_11
== 0xe) /* LDRT */
7382 return thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
,
7385 /* LDR (register) */
7386 return thumb2_copy_load_reg_imm (gdbarch
, insn1
, insn2
, regs
,
7392 return thumb_32bit_copy_undef (gdbarch
, insn1
, insn2
, dsc
);
7399 thumb_process_displaced_32bit_insn (struct gdbarch
*gdbarch
, uint16_t insn1
,
7400 uint16_t insn2
, struct regcache
*regs
,
7401 arm_displaced_step_copy_insn_closure
*dsc
)
7404 unsigned short op
= bit (insn2
, 15);
7405 unsigned int op1
= bits (insn1
, 11, 12);
7411 switch (bits (insn1
, 9, 10))
7416 /* Load/store {dual, exclusive}, table branch. */
7417 if (bits (insn1
, 7, 8) == 1 && bits (insn1
, 4, 5) == 1
7418 && bits (insn2
, 5, 7) == 0)
7419 err
= thumb2_copy_table_branch (gdbarch
, insn1
, insn2
, regs
,
7422 /* PC is not allowed to use in load/store {dual, exclusive}
7424 err
= thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
,
7425 "load/store dual/ex", dsc
);
7427 else /* load/store multiple */
7429 switch (bits (insn1
, 7, 8))
7431 case 0: case 3: /* SRS, RFE */
7432 err
= thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
,
7435 case 1: case 2: /* LDM/STM/PUSH/POP */
7436 err
= thumb2_copy_block_xfer (gdbarch
, insn1
, insn2
, regs
, dsc
);
7443 /* Data-processing (shift register). */
7444 err
= thumb2_decode_dp_shift_reg (gdbarch
, insn1
, insn2
, regs
,
7447 default: /* Coprocessor instructions. */
7448 err
= thumb2_decode_svc_copro (gdbarch
, insn1
, insn2
, regs
, dsc
);
7453 case 2: /* op1 = 2 */
7454 if (op
) /* Branch and misc control. */
7456 if (bit (insn2
, 14) /* BLX/BL */
7457 || bit (insn2
, 12) /* Unconditional branch */
7458 || (bits (insn1
, 7, 9) != 0x7)) /* Conditional branch */
7459 err
= thumb2_copy_b_bl_blx (gdbarch
, insn1
, insn2
, regs
, dsc
);
7461 err
= thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
,
7466 if (bit (insn1
, 9)) /* Data processing (plain binary imm). */
7468 int dp_op
= bits (insn1
, 4, 8);
7469 int rn
= bits (insn1
, 0, 3);
7470 if ((dp_op
== 0 || dp_op
== 0xa) && rn
== 0xf)
7471 err
= thumb_copy_pc_relative_32bit (gdbarch
, insn1
, insn2
,
7474 err
= thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
,
7477 else /* Data processing (modified immediate) */
7478 err
= thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
,
7482 case 3: /* op1 = 3 */
7483 switch (bits (insn1
, 9, 10))
7487 err
= decode_thumb_32bit_ld_mem_hints (gdbarch
, insn1
, insn2
,
7489 else /* NEON Load/Store and Store single data item */
7490 err
= thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
,
7491 "neon elt/struct load/store",
7494 case 1: /* op1 = 3, bits (9, 10) == 1 */
7495 switch (bits (insn1
, 7, 8))
7497 case 0: case 1: /* Data processing (register) */
7498 err
= thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
,
7501 case 2: /* Multiply and absolute difference */
7502 err
= thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
,
7503 "mul/mua/diff", dsc
);
7505 case 3: /* Long multiply and divide */
7506 err
= thumb_copy_unmodified_32bit (gdbarch
, insn1
, insn2
,
7511 default: /* Coprocessor instructions */
7512 err
= thumb2_decode_svc_copro (gdbarch
, insn1
, insn2
, regs
, dsc
);
7521 internal_error (__FILE__
, __LINE__
,
7522 _("thumb_process_displaced_32bit_insn: Instruction decode error"));
7527 thumb_process_displaced_insn (struct gdbarch
*gdbarch
, CORE_ADDR from
,
7528 struct regcache
*regs
,
7529 arm_displaced_step_copy_insn_closure
*dsc
)
7531 enum bfd_endian byte_order_for_code
= gdbarch_byte_order_for_code (gdbarch
);
7533 = read_memory_unsigned_integer (from
, 2, byte_order_for_code
);
7535 displaced_debug_printf ("process thumb insn %.4x at %.8lx",
7536 insn1
, (unsigned long) from
);
7539 dsc
->insn_size
= thumb_insn_size (insn1
);
7540 if (thumb_insn_size (insn1
) == 4)
7543 = read_memory_unsigned_integer (from
+ 2, 2, byte_order_for_code
);
7544 thumb_process_displaced_32bit_insn (gdbarch
, insn1
, insn2
, regs
, dsc
);
7547 thumb_process_displaced_16bit_insn (gdbarch
, insn1
, regs
, dsc
);
7551 arm_process_displaced_insn (struct gdbarch
*gdbarch
, CORE_ADDR from
,
7552 CORE_ADDR to
, struct regcache
*regs
,
7553 arm_displaced_step_copy_insn_closure
*dsc
)
7556 enum bfd_endian byte_order_for_code
= gdbarch_byte_order_for_code (gdbarch
);
7559 /* Most displaced instructions use a 1-instruction scratch space, so set this
7560 here and override below if/when necessary. */
7562 dsc
->insn_addr
= from
;
7563 dsc
->scratch_base
= to
;
7564 dsc
->cleanup
= NULL
;
7565 dsc
->wrote_to_pc
= 0;
7567 if (!displaced_in_arm_mode (regs
))
7568 return thumb_process_displaced_insn (gdbarch
, from
, regs
, dsc
);
7572 insn
= read_memory_unsigned_integer (from
, 4, byte_order_for_code
);
7573 displaced_debug_printf ("stepping insn %.8lx at %.8lx",
7574 (unsigned long) insn
, (unsigned long) from
);
7576 if ((insn
& 0xf0000000) == 0xf0000000)
7577 err
= arm_decode_unconditional (gdbarch
, insn
, regs
, dsc
);
7578 else switch (((insn
& 0x10) >> 4) | ((insn
& 0xe000000) >> 24))
7580 case 0x0: case 0x1: case 0x2: case 0x3:
7581 err
= arm_decode_dp_misc (gdbarch
, insn
, regs
, dsc
);
7584 case 0x4: case 0x5: case 0x6:
7585 err
= arm_decode_ld_st_word_ubyte (gdbarch
, insn
, regs
, dsc
);
7589 err
= arm_decode_media (gdbarch
, insn
, dsc
);
7592 case 0x8: case 0x9: case 0xa: case 0xb:
7593 err
= arm_decode_b_bl_ldmstm (gdbarch
, insn
, regs
, dsc
);
7596 case 0xc: case 0xd: case 0xe: case 0xf:
7597 err
= arm_decode_svc_copro (gdbarch
, insn
, regs
, dsc
);
7602 internal_error (__FILE__
, __LINE__
,
7603 _("arm_process_displaced_insn: Instruction decode error"));
7606 /* Actually set up the scratch space for a displaced instruction. */
7609 arm_displaced_init_closure (struct gdbarch
*gdbarch
, CORE_ADDR from
,
7611 arm_displaced_step_copy_insn_closure
*dsc
)
7613 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
7614 unsigned int i
, len
, offset
;
7615 enum bfd_endian byte_order_for_code
= gdbarch_byte_order_for_code (gdbarch
);
7616 int size
= dsc
->is_thumb
? 2 : 4;
7617 const gdb_byte
*bkp_insn
;
7620 /* Poke modified instruction(s). */
7621 for (i
= 0; i
< dsc
->numinsns
; i
++)
7624 displaced_debug_printf ("writing insn %.8lx at %.8lx",
7625 dsc
->modinsn
[i
], (unsigned long) to
+ offset
);
7627 displaced_debug_printf ("writing insn %.4x at %.8lx",
7628 (unsigned short) dsc
->modinsn
[i
],
7629 (unsigned long) to
+ offset
);
7631 write_memory_unsigned_integer (to
+ offset
, size
,
7632 byte_order_for_code
,
7637 /* Choose the correct breakpoint instruction. */
7640 bkp_insn
= tdep
->thumb_breakpoint
;
7641 len
= tdep
->thumb_breakpoint_size
;
7645 bkp_insn
= tdep
->arm_breakpoint
;
7646 len
= tdep
->arm_breakpoint_size
;
7649 /* Put breakpoint afterwards. */
7650 write_memory (to
+ offset
, bkp_insn
, len
);
7652 displaced_debug_printf ("copy %s->%s", paddress (gdbarch
, from
),
7653 paddress (gdbarch
, to
));
7656 /* Entry point for cleaning things up after a displaced instruction has been
7660 arm_displaced_step_fixup (struct gdbarch
*gdbarch
,
7661 struct displaced_step_copy_insn_closure
*dsc_
,
7662 CORE_ADDR from
, CORE_ADDR to
,
7663 struct regcache
*regs
)
7665 arm_displaced_step_copy_insn_closure
*dsc
7666 = (arm_displaced_step_copy_insn_closure
*) dsc_
;
7669 dsc
->cleanup (gdbarch
, regs
, dsc
);
7671 if (!dsc
->wrote_to_pc
)
7672 regcache_cooked_write_unsigned (regs
, ARM_PC_REGNUM
,
7673 dsc
->insn_addr
+ dsc
->insn_size
);
7677 #include "bfd-in2.h"
7678 #include "libcoff.h"
7681 gdb_print_insn_arm (bfd_vma memaddr
, disassemble_info
*info
)
7683 gdb_disassembler
*di
7684 = static_cast<gdb_disassembler
*>(info
->application_data
);
7685 struct gdbarch
*gdbarch
= di
->arch ();
7687 if (arm_pc_is_thumb (gdbarch
, memaddr
))
7689 static asymbol
*asym
;
7690 static combined_entry_type ce
;
7691 static struct coff_symbol_struct csym
;
7692 static struct bfd fake_bfd
;
7693 static bfd_target fake_target
;
7695 if (csym
.native
== NULL
)
7697 /* Create a fake symbol vector containing a Thumb symbol.
7698 This is solely so that the code in print_insn_little_arm()
7699 and print_insn_big_arm() in opcodes/arm-dis.c will detect
7700 the presence of a Thumb symbol and switch to decoding
7701 Thumb instructions. */
7703 fake_target
.flavour
= bfd_target_coff_flavour
;
7704 fake_bfd
.xvec
= &fake_target
;
7705 ce
.u
.syment
.n_sclass
= C_THUMBEXTFUNC
;
7707 csym
.symbol
.the_bfd
= &fake_bfd
;
7708 csym
.symbol
.name
= "fake";
7709 asym
= (asymbol
*) & csym
;
7712 memaddr
= UNMAKE_THUMB_ADDR (memaddr
);
7713 info
->symbols
= &asym
;
7716 info
->symbols
= NULL
;
7718 /* GDB is able to get bfd_mach from the exe_bfd, info->mach is
7719 accurate, so mark USER_SPECIFIED_MACHINE_TYPE bit. Otherwise,
7720 opcodes/arm-dis.c:print_insn reset info->mach, and it will trigger
7721 the assert on the mismatch of info->mach and
7722 bfd_get_mach (current_program_space->exec_bfd ()) in
7723 default_print_insn. */
7724 if (current_program_space
->exec_bfd () != NULL
)
7725 info
->flags
|= USER_SPECIFIED_MACHINE_TYPE
;
7727 return default_print_insn (memaddr
, info
);
7730 /* The following define instruction sequences that will cause ARM
7731 cpu's to take an undefined instruction trap. These are used to
7732 signal a breakpoint to GDB.
7734 The newer ARMv4T cpu's are capable of operating in ARM or Thumb
7735 modes. A different instruction is required for each mode. The ARM
7736 cpu's can also be big or little endian. Thus four different
7737 instructions are needed to support all cases.
7739 Note: ARMv4 defines several new instructions that will take the
7740 undefined instruction trap. ARM7TDMI is nominally ARMv4T, but does
7741 not in fact add the new instructions. The new undefined
7742 instructions in ARMv4 are all instructions that had no defined
7743 behaviour in earlier chips. There is no guarantee that they will
7744 raise an exception, but may be treated as NOP's. In practice, it
7745 may only safe to rely on instructions matching:
7747 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
7748 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
7749 C C C C 0 1 1 x x x x x x x x x x x x x x x x x x x x 1 x x x x
7751 Even this may only true if the condition predicate is true. The
7752 following use a condition predicate of ALWAYS so it is always TRUE.
7754 There are other ways of forcing a breakpoint. GNU/Linux, RISC iX,
7755 and NetBSD all use a software interrupt rather than an undefined
7756 instruction to force a trap. This can be handled by by the
7757 abi-specific code during establishment of the gdbarch vector. */
7759 #define ARM_LE_BREAKPOINT {0xFE,0xDE,0xFF,0xE7}
7760 #define ARM_BE_BREAKPOINT {0xE7,0xFF,0xDE,0xFE}
7761 #define THUMB_LE_BREAKPOINT {0xbe,0xbe}
7762 #define THUMB_BE_BREAKPOINT {0xbe,0xbe}
7764 static const gdb_byte arm_default_arm_le_breakpoint
[] = ARM_LE_BREAKPOINT
;
7765 static const gdb_byte arm_default_arm_be_breakpoint
[] = ARM_BE_BREAKPOINT
;
7766 static const gdb_byte arm_default_thumb_le_breakpoint
[] = THUMB_LE_BREAKPOINT
;
7767 static const gdb_byte arm_default_thumb_be_breakpoint
[] = THUMB_BE_BREAKPOINT
;
7769 /* Implement the breakpoint_kind_from_pc gdbarch method. */
7772 arm_breakpoint_kind_from_pc (struct gdbarch
*gdbarch
, CORE_ADDR
*pcptr
)
7774 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
7775 enum bfd_endian byte_order_for_code
= gdbarch_byte_order_for_code (gdbarch
);
7777 if (arm_pc_is_thumb (gdbarch
, *pcptr
))
7779 *pcptr
= UNMAKE_THUMB_ADDR (*pcptr
);
7781 /* If we have a separate 32-bit breakpoint instruction for Thumb-2,
7782 check whether we are replacing a 32-bit instruction. */
7783 if (tdep
->thumb2_breakpoint
!= NULL
)
7787 if (target_read_memory (*pcptr
, buf
, 2) == 0)
7789 unsigned short inst1
;
7791 inst1
= extract_unsigned_integer (buf
, 2, byte_order_for_code
);
7792 if (thumb_insn_size (inst1
) == 4)
7793 return ARM_BP_KIND_THUMB2
;
7797 return ARM_BP_KIND_THUMB
;
7800 return ARM_BP_KIND_ARM
;
7804 /* Implement the sw_breakpoint_from_kind gdbarch method. */
7806 static const gdb_byte
*
7807 arm_sw_breakpoint_from_kind (struct gdbarch
*gdbarch
, int kind
, int *size
)
7809 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
7813 case ARM_BP_KIND_ARM
:
7814 *size
= tdep
->arm_breakpoint_size
;
7815 return tdep
->arm_breakpoint
;
7816 case ARM_BP_KIND_THUMB
:
7817 *size
= tdep
->thumb_breakpoint_size
;
7818 return tdep
->thumb_breakpoint
;
7819 case ARM_BP_KIND_THUMB2
:
7820 *size
= tdep
->thumb2_breakpoint_size
;
7821 return tdep
->thumb2_breakpoint
;
7823 gdb_assert_not_reached ("unexpected arm breakpoint kind");
7827 /* Implement the breakpoint_kind_from_current_state gdbarch method. */
7830 arm_breakpoint_kind_from_current_state (struct gdbarch
*gdbarch
,
7831 struct regcache
*regcache
,
7836 /* Check the memory pointed by PC is readable. */
7837 if (target_read_memory (regcache_read_pc (regcache
), buf
, 4) == 0)
7839 struct arm_get_next_pcs next_pcs_ctx
;
7841 arm_get_next_pcs_ctor (&next_pcs_ctx
,
7842 &arm_get_next_pcs_ops
,
7843 gdbarch_byte_order (gdbarch
),
7844 gdbarch_byte_order_for_code (gdbarch
),
7848 std::vector
<CORE_ADDR
> next_pcs
= arm_get_next_pcs (&next_pcs_ctx
);
7850 /* If MEMADDR is the next instruction of current pc, do the
7851 software single step computation, and get the thumb mode by
7852 the destination address. */
7853 for (CORE_ADDR pc
: next_pcs
)
7855 if (UNMAKE_THUMB_ADDR (pc
) == *pcptr
)
7857 if (IS_THUMB_ADDR (pc
))
7859 *pcptr
= MAKE_THUMB_ADDR (*pcptr
);
7860 return arm_breakpoint_kind_from_pc (gdbarch
, pcptr
);
7863 return ARM_BP_KIND_ARM
;
7868 return arm_breakpoint_kind_from_pc (gdbarch
, pcptr
);
7871 /* Extract from an array REGBUF containing the (raw) register state a
7872 function return value of type TYPE, and copy that, in virtual
7873 format, into VALBUF. */
7876 arm_extract_return_value (struct type
*type
, struct regcache
*regs
,
7879 struct gdbarch
*gdbarch
= regs
->arch ();
7880 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
7882 if (TYPE_CODE_FLT
== type
->code ())
7884 switch (gdbarch_tdep (gdbarch
)->fp_model
)
7888 /* The value is in register F0 in internal format. We need to
7889 extract the raw value and then convert it to the desired
7891 bfd_byte tmpbuf
[ARM_FP_REGISTER_SIZE
];
7893 regs
->cooked_read (ARM_F0_REGNUM
, tmpbuf
);
7894 target_float_convert (tmpbuf
, arm_ext_type (gdbarch
),
7899 case ARM_FLOAT_SOFT_FPA
:
7900 case ARM_FLOAT_SOFT_VFP
:
7901 /* ARM_FLOAT_VFP can arise if this is a variadic function so
7902 not using the VFP ABI code. */
7904 regs
->cooked_read (ARM_A1_REGNUM
, valbuf
);
7905 if (TYPE_LENGTH (type
) > 4)
7906 regs
->cooked_read (ARM_A1_REGNUM
+ 1,
7907 valbuf
+ ARM_INT_REGISTER_SIZE
);
7911 internal_error (__FILE__
, __LINE__
,
7912 _("arm_extract_return_value: "
7913 "Floating point model not supported"));
7917 else if (type
->code () == TYPE_CODE_INT
7918 || type
->code () == TYPE_CODE_CHAR
7919 || type
->code () == TYPE_CODE_BOOL
7920 || type
->code () == TYPE_CODE_PTR
7921 || TYPE_IS_REFERENCE (type
)
7922 || type
->code () == TYPE_CODE_ENUM
)
7924 /* If the type is a plain integer, then the access is
7925 straight-forward. Otherwise we have to play around a bit
7927 int len
= TYPE_LENGTH (type
);
7928 int regno
= ARM_A1_REGNUM
;
7933 /* By using store_unsigned_integer we avoid having to do
7934 anything special for small big-endian values. */
7935 regcache_cooked_read_unsigned (regs
, regno
++, &tmp
);
7936 store_unsigned_integer (valbuf
,
7937 (len
> ARM_INT_REGISTER_SIZE
7938 ? ARM_INT_REGISTER_SIZE
: len
),
7940 len
-= ARM_INT_REGISTER_SIZE
;
7941 valbuf
+= ARM_INT_REGISTER_SIZE
;
7946 /* For a structure or union the behaviour is as if the value had
7947 been stored to word-aligned memory and then loaded into
7948 registers with 32-bit load instruction(s). */
7949 int len
= TYPE_LENGTH (type
);
7950 int regno
= ARM_A1_REGNUM
;
7951 bfd_byte tmpbuf
[ARM_INT_REGISTER_SIZE
];
7955 regs
->cooked_read (regno
++, tmpbuf
);
7956 memcpy (valbuf
, tmpbuf
,
7957 len
> ARM_INT_REGISTER_SIZE
? ARM_INT_REGISTER_SIZE
: len
);
7958 len
-= ARM_INT_REGISTER_SIZE
;
7959 valbuf
+= ARM_INT_REGISTER_SIZE
;
7965 /* Will a function return an aggregate type in memory or in a
7966 register? Return 0 if an aggregate type can be returned in a
7967 register, 1 if it must be returned in memory. */
7970 arm_return_in_memory (struct gdbarch
*gdbarch
, struct type
*type
)
7972 enum type_code code
;
7974 type
= check_typedef (type
);
7976 /* Simple, non-aggregate types (ie not including vectors and
7977 complex) are always returned in a register (or registers). */
7978 code
= type
->code ();
7979 if (TYPE_CODE_STRUCT
!= code
&& TYPE_CODE_UNION
!= code
7980 && TYPE_CODE_ARRAY
!= code
&& TYPE_CODE_COMPLEX
!= code
)
7983 if (TYPE_CODE_ARRAY
== code
&& type
->is_vector ())
7985 /* Vector values should be returned using ARM registers if they
7986 are not over 16 bytes. */
7987 return (TYPE_LENGTH (type
) > 16);
7990 if (gdbarch_tdep (gdbarch
)->arm_abi
!= ARM_ABI_APCS
)
7992 /* The AAPCS says all aggregates not larger than a word are returned
7994 if (TYPE_LENGTH (type
) <= ARM_INT_REGISTER_SIZE
)
8003 /* All aggregate types that won't fit in a register must be returned
8005 if (TYPE_LENGTH (type
) > ARM_INT_REGISTER_SIZE
)
8008 /* In the ARM ABI, "integer" like aggregate types are returned in
8009 registers. For an aggregate type to be integer like, its size
8010 must be less than or equal to ARM_INT_REGISTER_SIZE and the
8011 offset of each addressable subfield must be zero. Note that bit
8012 fields are not addressable, and all addressable subfields of
8013 unions always start at offset zero.
8015 This function is based on the behaviour of GCC 2.95.1.
8016 See: gcc/arm.c: arm_return_in_memory() for details.
8018 Note: All versions of GCC before GCC 2.95.2 do not set up the
8019 parameters correctly for a function returning the following
8020 structure: struct { float f;}; This should be returned in memory,
8021 not a register. Richard Earnshaw sent me a patch, but I do not
8022 know of any way to detect if a function like the above has been
8023 compiled with the correct calling convention. */
8025 /* Assume all other aggregate types can be returned in a register.
8026 Run a check for structures, unions and arrays. */
8029 if ((TYPE_CODE_STRUCT
== code
) || (TYPE_CODE_UNION
== code
))
8032 /* Need to check if this struct/union is "integer" like. For
8033 this to be true, its size must be less than or equal to
8034 ARM_INT_REGISTER_SIZE and the offset of each addressable
8035 subfield must be zero. Note that bit fields are not
8036 addressable, and unions always start at offset zero. If any
8037 of the subfields is a floating point type, the struct/union
8038 cannot be an integer type. */
8040 /* For each field in the object, check:
8041 1) Is it FP? --> yes, nRc = 1;
8042 2) Is it addressable (bitpos != 0) and
8043 not packed (bitsize == 0)?
8047 for (i
= 0; i
< type
->num_fields (); i
++)
8049 enum type_code field_type_code
;
8052 = check_typedef (type
->field (i
).type ())->code ();
8054 /* Is it a floating point type field? */
8055 if (field_type_code
== TYPE_CODE_FLT
)
8061 /* If bitpos != 0, then we have to care about it. */
8062 if (TYPE_FIELD_BITPOS (type
, i
) != 0)
8064 /* Bitfields are not addressable. If the field bitsize is
8065 zero, then the field is not packed. Hence it cannot be
8066 a bitfield or any other packed type. */
8067 if (TYPE_FIELD_BITSIZE (type
, i
) == 0)
8080 /* Write into appropriate registers a function return value of type
8081 TYPE, given in virtual format. */
8084 arm_store_return_value (struct type
*type
, struct regcache
*regs
,
8085 const gdb_byte
*valbuf
)
8087 struct gdbarch
*gdbarch
= regs
->arch ();
8088 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
8090 if (type
->code () == TYPE_CODE_FLT
)
8092 gdb_byte buf
[ARM_FP_REGISTER_SIZE
];
8094 switch (gdbarch_tdep (gdbarch
)->fp_model
)
8098 target_float_convert (valbuf
, type
, buf
, arm_ext_type (gdbarch
));
8099 regs
->cooked_write (ARM_F0_REGNUM
, buf
);
8102 case ARM_FLOAT_SOFT_FPA
:
8103 case ARM_FLOAT_SOFT_VFP
:
8104 /* ARM_FLOAT_VFP can arise if this is a variadic function so
8105 not using the VFP ABI code. */
8107 regs
->cooked_write (ARM_A1_REGNUM
, valbuf
);
8108 if (TYPE_LENGTH (type
) > 4)
8109 regs
->cooked_write (ARM_A1_REGNUM
+ 1,
8110 valbuf
+ ARM_INT_REGISTER_SIZE
);
8114 internal_error (__FILE__
, __LINE__
,
8115 _("arm_store_return_value: Floating "
8116 "point model not supported"));
8120 else if (type
->code () == TYPE_CODE_INT
8121 || type
->code () == TYPE_CODE_CHAR
8122 || type
->code () == TYPE_CODE_BOOL
8123 || type
->code () == TYPE_CODE_PTR
8124 || TYPE_IS_REFERENCE (type
)
8125 || type
->code () == TYPE_CODE_ENUM
)
8127 if (TYPE_LENGTH (type
) <= 4)
8129 /* Values of one word or less are zero/sign-extended and
8131 bfd_byte tmpbuf
[ARM_INT_REGISTER_SIZE
];
8132 LONGEST val
= unpack_long (type
, valbuf
);
8134 store_signed_integer (tmpbuf
, ARM_INT_REGISTER_SIZE
, byte_order
, val
);
8135 regs
->cooked_write (ARM_A1_REGNUM
, tmpbuf
);
8139 /* Integral values greater than one word are stored in consecutive
8140 registers starting with r0. This will always be a multiple of
8141 the regiser size. */
8142 int len
= TYPE_LENGTH (type
);
8143 int regno
= ARM_A1_REGNUM
;
8147 regs
->cooked_write (regno
++, valbuf
);
8148 len
-= ARM_INT_REGISTER_SIZE
;
8149 valbuf
+= ARM_INT_REGISTER_SIZE
;
8155 /* For a structure or union the behaviour is as if the value had
8156 been stored to word-aligned memory and then loaded into
8157 registers with 32-bit load instruction(s). */
8158 int len
= TYPE_LENGTH (type
);
8159 int regno
= ARM_A1_REGNUM
;
8160 bfd_byte tmpbuf
[ARM_INT_REGISTER_SIZE
];
8164 memcpy (tmpbuf
, valbuf
,
8165 len
> ARM_INT_REGISTER_SIZE
? ARM_INT_REGISTER_SIZE
: len
);
8166 regs
->cooked_write (regno
++, tmpbuf
);
8167 len
-= ARM_INT_REGISTER_SIZE
;
8168 valbuf
+= ARM_INT_REGISTER_SIZE
;
8174 /* Handle function return values. */
8176 static enum return_value_convention
8177 arm_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
8178 struct type
*valtype
, struct regcache
*regcache
,
8179 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
8181 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
8182 struct type
*func_type
= function
? value_type (function
) : NULL
;
8183 enum arm_vfp_cprc_base_type vfp_base_type
;
8186 if (arm_vfp_abi_for_function (gdbarch
, func_type
)
8187 && arm_vfp_call_candidate (valtype
, &vfp_base_type
, &vfp_base_count
))
8189 int reg_char
= arm_vfp_cprc_reg_char (vfp_base_type
);
8190 int unit_length
= arm_vfp_cprc_unit_length (vfp_base_type
);
8192 for (i
= 0; i
< vfp_base_count
; i
++)
8194 if (reg_char
== 'q')
8197 arm_neon_quad_write (gdbarch
, regcache
, i
,
8198 writebuf
+ i
* unit_length
);
8201 arm_neon_quad_read (gdbarch
, regcache
, i
,
8202 readbuf
+ i
* unit_length
);
8209 xsnprintf (name_buf
, sizeof (name_buf
), "%c%d", reg_char
, i
);
8210 regnum
= user_reg_map_name_to_regnum (gdbarch
, name_buf
,
8213 regcache
->cooked_write (regnum
, writebuf
+ i
* unit_length
);
8215 regcache
->cooked_read (regnum
, readbuf
+ i
* unit_length
);
8218 return RETURN_VALUE_REGISTER_CONVENTION
;
8221 if (valtype
->code () == TYPE_CODE_STRUCT
8222 || valtype
->code () == TYPE_CODE_UNION
8223 || valtype
->code () == TYPE_CODE_ARRAY
)
8225 if (tdep
->struct_return
== pcc_struct_return
8226 || arm_return_in_memory (gdbarch
, valtype
))
8227 return RETURN_VALUE_STRUCT_CONVENTION
;
8229 else if (valtype
->code () == TYPE_CODE_COMPLEX
)
8231 if (arm_return_in_memory (gdbarch
, valtype
))
8232 return RETURN_VALUE_STRUCT_CONVENTION
;
8236 arm_store_return_value (valtype
, regcache
, writebuf
);
8239 arm_extract_return_value (valtype
, regcache
, readbuf
);
8241 return RETURN_VALUE_REGISTER_CONVENTION
;
8246 arm_get_longjmp_target (struct frame_info
*frame
, CORE_ADDR
*pc
)
8248 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
8249 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
8250 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
8252 gdb_byte buf
[ARM_INT_REGISTER_SIZE
];
8254 jb_addr
= get_frame_register_unsigned (frame
, ARM_A1_REGNUM
);
8256 if (target_read_memory (jb_addr
+ tdep
->jb_pc
* tdep
->jb_elt_size
, buf
,
8257 ARM_INT_REGISTER_SIZE
))
8260 *pc
= extract_unsigned_integer (buf
, ARM_INT_REGISTER_SIZE
, byte_order
);
8263 /* A call to cmse secure entry function "foo" at "a" is modified by
8270 b) bl yyyy <__acle_se_foo>
8272 section .gnu.sgstubs:
8274 yyyy: sg // secure gateway
8275 b.w xxxx <__acle_se_foo> // original_branch_dest
8280 When the control at "b", the pc contains "yyyy" (sg address) which is a
8281 trampoline and does not exist in source code. This function returns the
8282 target pc "xxxx". For more details please refer to section 5.4
8283 (Entry functions) and section 3.4.4 (C level development flow of secure code)
8284 of "armv8-m-security-extensions-requirements-on-development-tools-engineering-specification"
8285 document on www.developer.arm.com. */
8288 arm_skip_cmse_entry (CORE_ADDR pc
, const char *name
, struct objfile
*objfile
)
8290 int target_len
= strlen (name
) + strlen ("__acle_se_") + 1;
8291 char *target_name
= (char *) alloca (target_len
);
8292 xsnprintf (target_name
, target_len
, "%s%s", "__acle_se_", name
);
8294 struct bound_minimal_symbol minsym
8295 = lookup_minimal_symbol (target_name
, NULL
, objfile
);
8297 if (minsym
.minsym
!= nullptr)
8298 return BMSYMBOL_VALUE_ADDRESS (minsym
);
8303 /* Return true when SEC points to ".gnu.sgstubs" section. */
8306 arm_is_sgstubs_section (struct obj_section
*sec
)
8308 return (sec
!= nullptr
8309 && sec
->the_bfd_section
!= nullptr
8310 && sec
->the_bfd_section
->name
!= nullptr
8311 && streq (sec
->the_bfd_section
->name
, ".gnu.sgstubs"));
8314 /* Recognize GCC and GNU ld's trampolines. If we are in a trampoline,
8315 return the target PC. Otherwise return 0. */
8318 arm_skip_stub (struct frame_info
*frame
, CORE_ADDR pc
)
8322 CORE_ADDR start_addr
;
8324 /* Find the starting address and name of the function containing the PC. */
8325 if (find_pc_partial_function (pc
, &name
, &start_addr
, NULL
) == 0)
8327 /* Trampoline 'bx reg' doesn't belong to any functions. Do the
8329 start_addr
= arm_skip_bx_reg (frame
, pc
);
8330 if (start_addr
!= 0)
8336 /* If PC is in a Thumb call or return stub, return the address of the
8337 target PC, which is in a register. The thunk functions are called
8338 _call_via_xx, where x is the register name. The possible names
8339 are r0-r9, sl, fp, ip, sp, and lr. ARM RealView has similar
8340 functions, named __ARM_call_via_r[0-7]. */
8341 if (startswith (name
, "_call_via_")
8342 || startswith (name
, "__ARM_call_via_"))
8344 /* Use the name suffix to determine which register contains the
8346 static const char *table
[15] =
8347 {"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
8348 "r8", "r9", "sl", "fp", "ip", "sp", "lr"
8351 int offset
= strlen (name
) - 2;
8353 for (regno
= 0; regno
<= 14; regno
++)
8354 if (strcmp (&name
[offset
], table
[regno
]) == 0)
8355 return get_frame_register_unsigned (frame
, regno
);
8358 /* GNU ld generates __foo_from_arm or __foo_from_thumb for
8359 non-interworking calls to foo. We could decode the stubs
8360 to find the target but it's easier to use the symbol table. */
8361 namelen
= strlen (name
);
8362 if (name
[0] == '_' && name
[1] == '_'
8363 && ((namelen
> 2 + strlen ("_from_thumb")
8364 && startswith (name
+ namelen
- strlen ("_from_thumb"), "_from_thumb"))
8365 || (namelen
> 2 + strlen ("_from_arm")
8366 && startswith (name
+ namelen
- strlen ("_from_arm"), "_from_arm"))))
8369 int target_len
= namelen
- 2;
8370 struct bound_minimal_symbol minsym
;
8371 struct objfile
*objfile
;
8372 struct obj_section
*sec
;
8374 if (name
[namelen
- 1] == 'b')
8375 target_len
-= strlen ("_from_thumb");
8377 target_len
-= strlen ("_from_arm");
8379 target_name
= (char *) alloca (target_len
+ 1);
8380 memcpy (target_name
, name
+ 2, target_len
);
8381 target_name
[target_len
] = '\0';
8383 sec
= find_pc_section (pc
);
8384 objfile
= (sec
== NULL
) ? NULL
: sec
->objfile
;
8385 minsym
= lookup_minimal_symbol (target_name
, NULL
, objfile
);
8386 if (minsym
.minsym
!= NULL
)
8387 return BMSYMBOL_VALUE_ADDRESS (minsym
);
8392 struct obj_section
*section
= find_pc_section (pc
);
8394 /* Check whether SECTION points to the ".gnu.sgstubs" section. */
8395 if (arm_is_sgstubs_section (section
))
8396 return arm_skip_cmse_entry (pc
, name
, section
->objfile
);
8398 return 0; /* not a stub */
8402 arm_update_current_architecture (void)
8404 struct gdbarch_info info
;
8406 /* If the current architecture is not ARM, we have nothing to do. */
8407 if (gdbarch_bfd_arch_info (target_gdbarch ())->arch
!= bfd_arch_arm
)
8410 /* Update the architecture. */
8411 gdbarch_info_init (&info
);
8413 if (!gdbarch_update_p (info
))
8414 internal_error (__FILE__
, __LINE__
, _("could not update architecture"));
8418 set_fp_model_sfunc (const char *args
, int from_tty
,
8419 struct cmd_list_element
*c
)
8423 for (fp_model
= ARM_FLOAT_AUTO
; fp_model
!= ARM_FLOAT_LAST
; fp_model
++)
8424 if (strcmp (current_fp_model
, fp_model_strings
[fp_model
]) == 0)
8426 arm_fp_model
= (enum arm_float_model
) fp_model
;
8430 if (fp_model
== ARM_FLOAT_LAST
)
8431 internal_error (__FILE__
, __LINE__
, _("Invalid fp model accepted: %s."),
8434 arm_update_current_architecture ();
8438 show_fp_model (struct ui_file
*file
, int from_tty
,
8439 struct cmd_list_element
*c
, const char *value
)
8441 struct gdbarch_tdep
*tdep
= gdbarch_tdep (target_gdbarch ());
8443 if (arm_fp_model
== ARM_FLOAT_AUTO
8444 && gdbarch_bfd_arch_info (target_gdbarch ())->arch
== bfd_arch_arm
)
8445 fprintf_filtered (file
, _("\
8446 The current ARM floating point model is \"auto\" (currently \"%s\").\n"),
8447 fp_model_strings
[tdep
->fp_model
]);
8449 fprintf_filtered (file
, _("\
8450 The current ARM floating point model is \"%s\".\n"),
8451 fp_model_strings
[arm_fp_model
]);
8455 arm_set_abi (const char *args
, int from_tty
,
8456 struct cmd_list_element
*c
)
8460 for (arm_abi
= ARM_ABI_AUTO
; arm_abi
!= ARM_ABI_LAST
; arm_abi
++)
8461 if (strcmp (arm_abi_string
, arm_abi_strings
[arm_abi
]) == 0)
8463 arm_abi_global
= (enum arm_abi_kind
) arm_abi
;
8467 if (arm_abi
== ARM_ABI_LAST
)
8468 internal_error (__FILE__
, __LINE__
, _("Invalid ABI accepted: %s."),
8471 arm_update_current_architecture ();
8475 arm_show_abi (struct ui_file
*file
, int from_tty
,
8476 struct cmd_list_element
*c
, const char *value
)
8478 struct gdbarch_tdep
*tdep
= gdbarch_tdep (target_gdbarch ());
8480 if (arm_abi_global
== ARM_ABI_AUTO
8481 && gdbarch_bfd_arch_info (target_gdbarch ())->arch
== bfd_arch_arm
)
8482 fprintf_filtered (file
, _("\
8483 The current ARM ABI is \"auto\" (currently \"%s\").\n"),
8484 arm_abi_strings
[tdep
->arm_abi
]);
8486 fprintf_filtered (file
, _("The current ARM ABI is \"%s\".\n"),
8491 arm_show_fallback_mode (struct ui_file
*file
, int from_tty
,
8492 struct cmd_list_element
*c
, const char *value
)
8494 fprintf_filtered (file
,
8495 _("The current execution mode assumed "
8496 "(when symbols are unavailable) is \"%s\".\n"),
8497 arm_fallback_mode_string
);
8501 arm_show_force_mode (struct ui_file
*file
, int from_tty
,
8502 struct cmd_list_element
*c
, const char *value
)
8504 fprintf_filtered (file
,
8505 _("The current execution mode assumed "
8506 "(even when symbols are available) is \"%s\".\n"),
8507 arm_force_mode_string
);
8510 /* If the user changes the register disassembly style used for info
8511 register and other commands, we have to also switch the style used
8512 in opcodes for disassembly output. This function is run in the "set
8513 arm disassembly" command, and does that. */
8516 set_disassembly_style_sfunc (const char *args
, int from_tty
,
8517 struct cmd_list_element
*c
)
8519 /* Convert the short style name into the long style name (eg, reg-names-*)
8520 before calling the generic set_disassembler_options() function. */
8521 std::string long_name
= std::string ("reg-names-") + disassembly_style
;
8522 set_disassembler_options (&long_name
[0]);
8526 show_disassembly_style_sfunc (struct ui_file
*file
, int from_tty
,
8527 struct cmd_list_element
*c
, const char *value
)
8529 struct gdbarch
*gdbarch
= get_current_arch ();
8530 char *options
= get_disassembler_options (gdbarch
);
8531 const char *style
= "";
8535 FOR_EACH_DISASSEMBLER_OPTION (opt
, options
)
8536 if (CONST_STRNEQ (opt
, "reg-names-"))
8538 style
= &opt
[strlen ("reg-names-")];
8539 len
= strcspn (style
, ",");
8542 fprintf_unfiltered (file
, "The disassembly style is \"%.*s\".\n", len
, style
);
8545 /* Return the ARM register name corresponding to register I. */
8547 arm_register_name (struct gdbarch
*gdbarch
, int i
)
8549 const int num_regs
= gdbarch_num_regs (gdbarch
);
8551 if (gdbarch_tdep (gdbarch
)->have_vfp_pseudos
8552 && i
>= num_regs
&& i
< num_regs
+ 32)
8554 static const char *const vfp_pseudo_names
[] = {
8555 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
8556 "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15",
8557 "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23",
8558 "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31",
8561 return vfp_pseudo_names
[i
- num_regs
];
8564 if (gdbarch_tdep (gdbarch
)->have_neon_pseudos
8565 && i
>= num_regs
+ 32 && i
< num_regs
+ 32 + 16)
8567 static const char *const neon_pseudo_names
[] = {
8568 "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7",
8569 "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15",
8572 return neon_pseudo_names
[i
- num_regs
- 32];
8575 if (i
>= ARRAY_SIZE (arm_register_names
))
8576 /* These registers are only supported on targets which supply
8577 an XML description. */
8580 return arm_register_names
[i
];
8583 /* Test whether the coff symbol specific value corresponds to a Thumb
8587 coff_sym_is_thumb (int val
)
8589 return (val
== C_THUMBEXT
8590 || val
== C_THUMBSTAT
8591 || val
== C_THUMBEXTFUNC
8592 || val
== C_THUMBSTATFUNC
8593 || val
== C_THUMBLABEL
);
8596 /* arm_coff_make_msymbol_special()
8597 arm_elf_make_msymbol_special()
8599 These functions test whether the COFF or ELF symbol corresponds to
8600 an address in thumb code, and set a "special" bit in a minimal
8601 symbol to indicate that it does. */
8604 arm_elf_make_msymbol_special(asymbol
*sym
, struct minimal_symbol
*msym
)
8606 elf_symbol_type
*elfsym
= (elf_symbol_type
*) sym
;
8608 if (ARM_GET_SYM_BRANCH_TYPE (elfsym
->internal_elf_sym
.st_target_internal
)
8609 == ST_BRANCH_TO_THUMB
)
8610 MSYMBOL_SET_SPECIAL (msym
);
8614 arm_coff_make_msymbol_special(int val
, struct minimal_symbol
*msym
)
8616 if (coff_sym_is_thumb (val
))
8617 MSYMBOL_SET_SPECIAL (msym
);
8621 arm_record_special_symbol (struct gdbarch
*gdbarch
, struct objfile
*objfile
,
8624 const char *name
= bfd_asymbol_name (sym
);
8625 struct arm_per_bfd
*data
;
8626 struct arm_mapping_symbol new_map_sym
;
8628 gdb_assert (name
[0] == '$');
8629 if (name
[1] != 'a' && name
[1] != 't' && name
[1] != 'd')
8632 data
= arm_bfd_data_key
.get (objfile
->obfd
);
8634 data
= arm_bfd_data_key
.emplace (objfile
->obfd
,
8635 objfile
->obfd
->section_count
);
8636 arm_mapping_symbol_vec
&map
8637 = data
->section_maps
[bfd_asymbol_section (sym
)->index
];
8639 new_map_sym
.value
= sym
->value
;
8640 new_map_sym
.type
= name
[1];
8642 /* Insert at the end, the vector will be sorted on first use. */
8643 map
.push_back (new_map_sym
);
8647 arm_write_pc (struct regcache
*regcache
, CORE_ADDR pc
)
8649 struct gdbarch
*gdbarch
= regcache
->arch ();
8650 regcache_cooked_write_unsigned (regcache
, ARM_PC_REGNUM
, pc
);
8652 /* If necessary, set the T bit. */
8655 ULONGEST val
, t_bit
;
8656 regcache_cooked_read_unsigned (regcache
, ARM_PS_REGNUM
, &val
);
8657 t_bit
= arm_psr_thumb_bit (gdbarch
);
8658 if (arm_pc_is_thumb (gdbarch
, pc
))
8659 regcache_cooked_write_unsigned (regcache
, ARM_PS_REGNUM
,
8662 regcache_cooked_write_unsigned (regcache
, ARM_PS_REGNUM
,
8667 /* Read the contents of a NEON quad register, by reading from two
8668 double registers. This is used to implement the quad pseudo
8669 registers, and for argument passing in case the quad registers are
8670 missing; vectors are passed in quad registers when using the VFP
8671 ABI, even if a NEON unit is not present. REGNUM is the index of
8672 the quad register, in [0, 15]. */
8674 static enum register_status
8675 arm_neon_quad_read (struct gdbarch
*gdbarch
, readable_regcache
*regcache
,
8676 int regnum
, gdb_byte
*buf
)
8679 gdb_byte reg_buf
[8];
8680 int offset
, double_regnum
;
8681 enum register_status status
;
8683 xsnprintf (name_buf
, sizeof (name_buf
), "d%d", regnum
<< 1);
8684 double_regnum
= user_reg_map_name_to_regnum (gdbarch
, name_buf
,
8687 /* d0 is always the least significant half of q0. */
8688 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
8693 status
= regcache
->raw_read (double_regnum
, reg_buf
);
8694 if (status
!= REG_VALID
)
8696 memcpy (buf
+ offset
, reg_buf
, 8);
8698 offset
= 8 - offset
;
8699 status
= regcache
->raw_read (double_regnum
+ 1, reg_buf
);
8700 if (status
!= REG_VALID
)
8702 memcpy (buf
+ offset
, reg_buf
, 8);
8707 static enum register_status
8708 arm_pseudo_read (struct gdbarch
*gdbarch
, readable_regcache
*regcache
,
8709 int regnum
, gdb_byte
*buf
)
8711 const int num_regs
= gdbarch_num_regs (gdbarch
);
8713 gdb_byte reg_buf
[8];
8714 int offset
, double_regnum
;
8716 gdb_assert (regnum
>= num_regs
);
8719 if (gdbarch_tdep (gdbarch
)->have_neon_pseudos
&& regnum
>= 32 && regnum
< 48)
8720 /* Quad-precision register. */
8721 return arm_neon_quad_read (gdbarch
, regcache
, regnum
- 32, buf
);
8724 enum register_status status
;
8726 /* Single-precision register. */
8727 gdb_assert (regnum
< 32);
8729 /* s0 is always the least significant half of d0. */
8730 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
8731 offset
= (regnum
& 1) ? 0 : 4;
8733 offset
= (regnum
& 1) ? 4 : 0;
8735 xsnprintf (name_buf
, sizeof (name_buf
), "d%d", regnum
>> 1);
8736 double_regnum
= user_reg_map_name_to_regnum (gdbarch
, name_buf
,
8739 status
= regcache
->raw_read (double_regnum
, reg_buf
);
8740 if (status
== REG_VALID
)
8741 memcpy (buf
, reg_buf
+ offset
, 4);
8746 /* Store the contents of BUF to a NEON quad register, by writing to
8747 two double registers. This is used to implement the quad pseudo
8748 registers, and for argument passing in case the quad registers are
8749 missing; vectors are passed in quad registers when using the VFP
8750 ABI, even if a NEON unit is not present. REGNUM is the index
8751 of the quad register, in [0, 15]. */
8754 arm_neon_quad_write (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
8755 int regnum
, const gdb_byte
*buf
)
8758 int offset
, double_regnum
;
8760 xsnprintf (name_buf
, sizeof (name_buf
), "d%d", regnum
<< 1);
8761 double_regnum
= user_reg_map_name_to_regnum (gdbarch
, name_buf
,
8764 /* d0 is always the least significant half of q0. */
8765 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
8770 regcache
->raw_write (double_regnum
, buf
+ offset
);
8771 offset
= 8 - offset
;
8772 regcache
->raw_write (double_regnum
+ 1, buf
+ offset
);
8776 arm_pseudo_write (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
8777 int regnum
, const gdb_byte
*buf
)
8779 const int num_regs
= gdbarch_num_regs (gdbarch
);
8781 gdb_byte reg_buf
[8];
8782 int offset
, double_regnum
;
8784 gdb_assert (regnum
>= num_regs
);
8787 if (gdbarch_tdep (gdbarch
)->have_neon_pseudos
&& regnum
>= 32 && regnum
< 48)
8788 /* Quad-precision register. */
8789 arm_neon_quad_write (gdbarch
, regcache
, regnum
- 32, buf
);
8792 /* Single-precision register. */
8793 gdb_assert (regnum
< 32);
8795 /* s0 is always the least significant half of d0. */
8796 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
8797 offset
= (regnum
& 1) ? 0 : 4;
8799 offset
= (regnum
& 1) ? 4 : 0;
8801 xsnprintf (name_buf
, sizeof (name_buf
), "d%d", regnum
>> 1);
8802 double_regnum
= user_reg_map_name_to_regnum (gdbarch
, name_buf
,
8805 regcache
->raw_read (double_regnum
, reg_buf
);
8806 memcpy (reg_buf
+ offset
, buf
, 4);
8807 regcache
->raw_write (double_regnum
, reg_buf
);
8811 static struct value
*
8812 value_of_arm_user_reg (struct frame_info
*frame
, const void *baton
)
8814 const int *reg_p
= (const int *) baton
;
8815 return value_of_register (*reg_p
, frame
);
8818 static enum gdb_osabi
8819 arm_elf_osabi_sniffer (bfd
*abfd
)
8821 unsigned int elfosabi
;
8822 enum gdb_osabi osabi
= GDB_OSABI_UNKNOWN
;
8824 elfosabi
= elf_elfheader (abfd
)->e_ident
[EI_OSABI
];
8826 if (elfosabi
== ELFOSABI_ARM
)
8827 /* GNU tools use this value. Check note sections in this case,
8830 for (asection
*sect
: gdb_bfd_sections (abfd
))
8831 generic_elf_osabi_sniff_abi_tag_sections (abfd
, sect
, &osabi
);
8834 /* Anything else will be handled by the generic ELF sniffer. */
8839 arm_register_reggroup_p (struct gdbarch
*gdbarch
, int regnum
,
8840 struct reggroup
*group
)
8842 /* FPS register's type is INT, but belongs to float_reggroup. Beside
8843 this, FPS register belongs to save_regroup, restore_reggroup, and
8844 all_reggroup, of course. */
8845 if (regnum
== ARM_FPS_REGNUM
)
8846 return (group
== float_reggroup
8847 || group
== save_reggroup
8848 || group
== restore_reggroup
8849 || group
== all_reggroup
);
8851 return default_register_reggroup_p (gdbarch
, regnum
, group
);
8854 /* For backward-compatibility we allow two 'g' packet lengths with
8855 the remote protocol depending on whether FPA registers are
8856 supplied. M-profile targets do not have FPA registers, but some
8857 stubs already exist in the wild which use a 'g' packet which
8858 supplies them albeit with dummy values. The packet format which
8859 includes FPA registers should be considered deprecated for
8860 M-profile targets. */
8863 arm_register_g_packet_guesses (struct gdbarch
*gdbarch
)
8865 if (gdbarch_tdep (gdbarch
)->is_m
)
8867 const target_desc
*tdesc
;
8869 /* If we know from the executable this is an M-profile target,
8870 cater for remote targets whose register set layout is the
8871 same as the FPA layout. */
8872 tdesc
= arm_read_mprofile_description (ARM_M_TYPE_WITH_FPA
);
8873 register_remote_g_packet_guess (gdbarch
,
8874 ARM_CORE_REGS_SIZE
+ ARM_FP_REGS_SIZE
,
8877 /* The regular M-profile layout. */
8878 tdesc
= arm_read_mprofile_description (ARM_M_TYPE_M_PROFILE
);
8879 register_remote_g_packet_guess (gdbarch
, ARM_CORE_REGS_SIZE
,
8882 /* M-profile plus M4F VFP. */
8883 tdesc
= arm_read_mprofile_description (ARM_M_TYPE_VFP_D16
);
8884 register_remote_g_packet_guess (gdbarch
,
8885 ARM_CORE_REGS_SIZE
+ ARM_VFP2_REGS_SIZE
,
8889 /* Otherwise we don't have a useful guess. */
8892 /* Implement the code_of_frame_writable gdbarch method. */
8895 arm_code_of_frame_writable (struct gdbarch
*gdbarch
, struct frame_info
*frame
)
8897 if (gdbarch_tdep (gdbarch
)->is_m
8898 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
8900 /* M-profile exception frames return to some magic PCs, where
8901 isn't writable at all. */
8908 /* Implement gdbarch_gnu_triplet_regexp. If the arch name is arm then allow it
8909 to be postfixed by a version (eg armv7hl). */
8912 arm_gnu_triplet_regexp (struct gdbarch
*gdbarch
)
8914 if (strcmp (gdbarch_bfd_arch_info (gdbarch
)->arch_name
, "arm") == 0)
8915 return "arm(v[^- ]*)?";
8916 return gdbarch_bfd_arch_info (gdbarch
)->arch_name
;
8919 /* Initialize the current architecture based on INFO. If possible,
8920 re-use an architecture from ARCHES, which is a list of
8921 architectures already created during this debugging session.
8923 Called e.g. at program startup, when reading a core file, and when
8924 reading a binary file. */
8926 static struct gdbarch
*
8927 arm_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
8929 struct gdbarch_tdep
*tdep
;
8930 struct gdbarch
*gdbarch
;
8931 struct gdbarch_list
*best_arch
;
8932 enum arm_abi_kind arm_abi
= arm_abi_global
;
8933 enum arm_float_model fp_model
= arm_fp_model
;
8934 tdesc_arch_data_up tdesc_data
;
8937 int vfp_register_count
= 0;
8938 bool have_vfp_pseudos
= false, have_neon_pseudos
= false;
8939 bool have_wmmx_registers
= false;
8940 bool have_neon
= false;
8941 bool have_fpa_registers
= true;
8942 const struct target_desc
*tdesc
= info
.target_desc
;
8944 /* If we have an object to base this architecture on, try to determine
8947 if (arm_abi
== ARM_ABI_AUTO
&& info
.abfd
!= NULL
)
8949 int ei_osabi
, e_flags
;
8951 switch (bfd_get_flavour (info
.abfd
))
8953 case bfd_target_coff_flavour
:
8954 /* Assume it's an old APCS-style ABI. */
8956 arm_abi
= ARM_ABI_APCS
;
8959 case bfd_target_elf_flavour
:
8960 ei_osabi
= elf_elfheader (info
.abfd
)->e_ident
[EI_OSABI
];
8961 e_flags
= elf_elfheader (info
.abfd
)->e_flags
;
8963 if (ei_osabi
== ELFOSABI_ARM
)
8965 /* GNU tools used to use this value, but do not for EABI
8966 objects. There's nowhere to tag an EABI version
8967 anyway, so assume APCS. */
8968 arm_abi
= ARM_ABI_APCS
;
8970 else if (ei_osabi
== ELFOSABI_NONE
|| ei_osabi
== ELFOSABI_GNU
)
8972 int eabi_ver
= EF_ARM_EABI_VERSION (e_flags
);
8976 case EF_ARM_EABI_UNKNOWN
:
8977 /* Assume GNU tools. */
8978 arm_abi
= ARM_ABI_APCS
;
8981 case EF_ARM_EABI_VER4
:
8982 case EF_ARM_EABI_VER5
:
8983 arm_abi
= ARM_ABI_AAPCS
;
8984 /* EABI binaries default to VFP float ordering.
8985 They may also contain build attributes that can
8986 be used to identify if the VFP argument-passing
8988 if (fp_model
== ARM_FLOAT_AUTO
)
8991 switch (bfd_elf_get_obj_attr_int (info
.abfd
,
8995 case AEABI_VFP_args_base
:
8996 /* "The user intended FP parameter/result
8997 passing to conform to AAPCS, base
8999 fp_model
= ARM_FLOAT_SOFT_VFP
;
9001 case AEABI_VFP_args_vfp
:
9002 /* "The user intended FP parameter/result
9003 passing to conform to AAPCS, VFP
9005 fp_model
= ARM_FLOAT_VFP
;
9007 case AEABI_VFP_args_toolchain
:
9008 /* "The user intended FP parameter/result
9009 passing to conform to tool chain-specific
9010 conventions" - we don't know any such
9011 conventions, so leave it as "auto". */
9013 case AEABI_VFP_args_compatible
:
9014 /* "Code is compatible with both the base
9015 and VFP variants; the user did not permit
9016 non-variadic functions to pass FP
9017 parameters/results" - leave it as
9021 /* Attribute value not mentioned in the
9022 November 2012 ABI, so leave it as
9027 fp_model
= ARM_FLOAT_SOFT_VFP
;
9033 /* Leave it as "auto". */
9034 warning (_("unknown ARM EABI version 0x%x"), eabi_ver
);
9039 /* Detect M-profile programs. This only works if the
9040 executable file includes build attributes; GCC does
9041 copy them to the executable, but e.g. RealView does
9044 = bfd_elf_get_obj_attr_int (info
.abfd
, OBJ_ATTR_PROC
,
9047 = bfd_elf_get_obj_attr_int (info
.abfd
, OBJ_ATTR_PROC
,
9048 Tag_CPU_arch_profile
);
9050 /* GCC specifies the profile for v6-M; RealView only
9051 specifies the profile for architectures starting with
9052 V7 (as opposed to architectures with a tag
9053 numerically greater than TAG_CPU_ARCH_V7). */
9054 if (!tdesc_has_registers (tdesc
)
9055 && (attr_arch
== TAG_CPU_ARCH_V6_M
9056 || attr_arch
== TAG_CPU_ARCH_V6S_M
9057 || attr_profile
== 'M'))
9062 if (fp_model
== ARM_FLOAT_AUTO
)
9064 switch (e_flags
& (EF_ARM_SOFT_FLOAT
| EF_ARM_VFP_FLOAT
))
9067 /* Leave it as "auto". Strictly speaking this case
9068 means FPA, but almost nobody uses that now, and
9069 many toolchains fail to set the appropriate bits
9070 for the floating-point model they use. */
9072 case EF_ARM_SOFT_FLOAT
:
9073 fp_model
= ARM_FLOAT_SOFT_FPA
;
9075 case EF_ARM_VFP_FLOAT
:
9076 fp_model
= ARM_FLOAT_VFP
;
9078 case EF_ARM_SOFT_FLOAT
| EF_ARM_VFP_FLOAT
:
9079 fp_model
= ARM_FLOAT_SOFT_VFP
;
9084 if (e_flags
& EF_ARM_BE8
)
9085 info
.byte_order_for_code
= BFD_ENDIAN_LITTLE
;
9090 /* Leave it as "auto". */
9095 /* Check any target description for validity. */
9096 if (tdesc_has_registers (tdesc
))
9098 /* For most registers we require GDB's default names; but also allow
9099 the numeric names for sp / lr / pc, as a convenience. */
9100 static const char *const arm_sp_names
[] = { "r13", "sp", NULL
};
9101 static const char *const arm_lr_names
[] = { "r14", "lr", NULL
};
9102 static const char *const arm_pc_names
[] = { "r15", "pc", NULL
};
9104 const struct tdesc_feature
*feature
;
9107 feature
= tdesc_find_feature (tdesc
,
9108 "org.gnu.gdb.arm.core");
9109 if (feature
== NULL
)
9111 feature
= tdesc_find_feature (tdesc
,
9112 "org.gnu.gdb.arm.m-profile");
9113 if (feature
== NULL
)
9119 tdesc_data
= tdesc_data_alloc ();
9122 for (i
= 0; i
< ARM_SP_REGNUM
; i
++)
9123 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (), i
,
9124 arm_register_names
[i
]);
9125 valid_p
&= tdesc_numbered_register_choices (feature
, tdesc_data
.get (),
9128 valid_p
&= tdesc_numbered_register_choices (feature
, tdesc_data
.get (),
9131 valid_p
&= tdesc_numbered_register_choices (feature
, tdesc_data
.get (),
9135 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (),
9136 ARM_PS_REGNUM
, "xpsr");
9138 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (),
9139 ARM_PS_REGNUM
, "cpsr");
9144 feature
= tdesc_find_feature (tdesc
,
9145 "org.gnu.gdb.arm.fpa");
9146 if (feature
!= NULL
)
9149 for (i
= ARM_F0_REGNUM
; i
<= ARM_FPS_REGNUM
; i
++)
9150 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (), i
,
9151 arm_register_names
[i
]);
9156 have_fpa_registers
= false;
9158 feature
= tdesc_find_feature (tdesc
,
9159 "org.gnu.gdb.xscale.iwmmxt");
9160 if (feature
!= NULL
)
9162 static const char *const iwmmxt_names
[] = {
9163 "wR0", "wR1", "wR2", "wR3", "wR4", "wR5", "wR6", "wR7",
9164 "wR8", "wR9", "wR10", "wR11", "wR12", "wR13", "wR14", "wR15",
9165 "wCID", "wCon", "wCSSF", "wCASF", "", "", "", "",
9166 "wCGR0", "wCGR1", "wCGR2", "wCGR3", "", "", "", "",
9170 for (i
= ARM_WR0_REGNUM
; i
<= ARM_WR15_REGNUM
; i
++)
9172 &= tdesc_numbered_register (feature
, tdesc_data
.get (), i
,
9173 iwmmxt_names
[i
- ARM_WR0_REGNUM
]);
9175 /* Check for the control registers, but do not fail if they
9177 for (i
= ARM_WC0_REGNUM
; i
<= ARM_WCASF_REGNUM
; i
++)
9178 tdesc_numbered_register (feature
, tdesc_data
.get (), i
,
9179 iwmmxt_names
[i
- ARM_WR0_REGNUM
]);
9181 for (i
= ARM_WCGR0_REGNUM
; i
<= ARM_WCGR3_REGNUM
; i
++)
9183 &= tdesc_numbered_register (feature
, tdesc_data
.get (), i
,
9184 iwmmxt_names
[i
- ARM_WR0_REGNUM
]);
9189 have_wmmx_registers
= true;
9192 /* If we have a VFP unit, check whether the single precision registers
9193 are present. If not, then we will synthesize them as pseudo
9195 feature
= tdesc_find_feature (tdesc
,
9196 "org.gnu.gdb.arm.vfp");
9197 if (feature
!= NULL
)
9199 static const char *const vfp_double_names
[] = {
9200 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
9201 "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15",
9202 "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23",
9203 "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31",
9206 /* Require the double precision registers. There must be either
9209 for (i
= 0; i
< 32; i
++)
9211 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (),
9213 vfp_double_names
[i
]);
9217 if (!valid_p
&& i
== 16)
9220 /* Also require FPSCR. */
9221 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (),
9222 ARM_FPSCR_REGNUM
, "fpscr");
9226 if (tdesc_unnumbered_register (feature
, "s0") == 0)
9227 have_vfp_pseudos
= true;
9229 vfp_register_count
= i
;
9231 /* If we have VFP, also check for NEON. The architecture allows
9232 NEON without VFP (integer vector operations only), but GDB
9233 does not support that. */
9234 feature
= tdesc_find_feature (tdesc
,
9235 "org.gnu.gdb.arm.neon");
9236 if (feature
!= NULL
)
9238 /* NEON requires 32 double-precision registers. */
9242 /* If there are quad registers defined by the stub, use
9243 their type; otherwise (normally) provide them with
9244 the default type. */
9245 if (tdesc_unnumbered_register (feature
, "q0") == 0)
9246 have_neon_pseudos
= true;
9253 /* If there is already a candidate, use it. */
9254 for (best_arch
= gdbarch_list_lookup_by_info (arches
, &info
);
9256 best_arch
= gdbarch_list_lookup_by_info (best_arch
->next
, &info
))
9258 if (arm_abi
!= ARM_ABI_AUTO
9259 && arm_abi
!= gdbarch_tdep (best_arch
->gdbarch
)->arm_abi
)
9262 if (fp_model
!= ARM_FLOAT_AUTO
9263 && fp_model
!= gdbarch_tdep (best_arch
->gdbarch
)->fp_model
)
9266 /* There are various other properties in tdep that we do not
9267 need to check here: those derived from a target description,
9268 since gdbarches with a different target description are
9269 automatically disqualified. */
9271 /* Do check is_m, though, since it might come from the binary. */
9272 if (is_m
!= gdbarch_tdep (best_arch
->gdbarch
)->is_m
)
9275 /* Found a match. */
9279 if (best_arch
!= NULL
)
9280 return best_arch
->gdbarch
;
9282 tdep
= XCNEW (struct gdbarch_tdep
);
9283 gdbarch
= gdbarch_alloc (&info
, tdep
);
9285 /* Record additional information about the architecture we are defining.
9286 These are gdbarch discriminators, like the OSABI. */
9287 tdep
->arm_abi
= arm_abi
;
9288 tdep
->fp_model
= fp_model
;
9290 tdep
->have_fpa_registers
= have_fpa_registers
;
9291 tdep
->have_wmmx_registers
= have_wmmx_registers
;
9292 gdb_assert (vfp_register_count
== 0
9293 || vfp_register_count
== 16
9294 || vfp_register_count
== 32);
9295 tdep
->vfp_register_count
= vfp_register_count
;
9296 tdep
->have_vfp_pseudos
= have_vfp_pseudos
;
9297 tdep
->have_neon_pseudos
= have_neon_pseudos
;
9298 tdep
->have_neon
= have_neon
;
9300 arm_register_g_packet_guesses (gdbarch
);
9303 switch (info
.byte_order_for_code
)
9305 case BFD_ENDIAN_BIG
:
9306 tdep
->arm_breakpoint
= arm_default_arm_be_breakpoint
;
9307 tdep
->arm_breakpoint_size
= sizeof (arm_default_arm_be_breakpoint
);
9308 tdep
->thumb_breakpoint
= arm_default_thumb_be_breakpoint
;
9309 tdep
->thumb_breakpoint_size
= sizeof (arm_default_thumb_be_breakpoint
);
9313 case BFD_ENDIAN_LITTLE
:
9314 tdep
->arm_breakpoint
= arm_default_arm_le_breakpoint
;
9315 tdep
->arm_breakpoint_size
= sizeof (arm_default_arm_le_breakpoint
);
9316 tdep
->thumb_breakpoint
= arm_default_thumb_le_breakpoint
;
9317 tdep
->thumb_breakpoint_size
= sizeof (arm_default_thumb_le_breakpoint
);
9322 internal_error (__FILE__
, __LINE__
,
9323 _("arm_gdbarch_init: bad byte order for float format"));
9326 /* On ARM targets char defaults to unsigned. */
9327 set_gdbarch_char_signed (gdbarch
, 0);
9329 /* wchar_t is unsigned under the AAPCS. */
9330 if (tdep
->arm_abi
== ARM_ABI_AAPCS
)
9331 set_gdbarch_wchar_signed (gdbarch
, 0);
9333 set_gdbarch_wchar_signed (gdbarch
, 1);
9335 /* Compute type alignment. */
9336 set_gdbarch_type_align (gdbarch
, arm_type_align
);
9338 /* Note: for displaced stepping, this includes the breakpoint, and one word
9339 of additional scratch space. This setting isn't used for anything beside
9340 displaced stepping at present. */
9341 set_gdbarch_max_insn_length (gdbarch
, 4 * ARM_DISPLACED_MODIFIED_INSNS
);
9343 /* This should be low enough for everything. */
9344 tdep
->lowest_pc
= 0x20;
9345 tdep
->jb_pc
= -1; /* Longjump support not enabled by default. */
9347 /* The default, for both APCS and AAPCS, is to return small
9348 structures in registers. */
9349 tdep
->struct_return
= reg_struct_return
;
9351 set_gdbarch_push_dummy_call (gdbarch
, arm_push_dummy_call
);
9352 set_gdbarch_frame_align (gdbarch
, arm_frame_align
);
9355 set_gdbarch_code_of_frame_writable (gdbarch
, arm_code_of_frame_writable
);
9357 set_gdbarch_write_pc (gdbarch
, arm_write_pc
);
9359 frame_base_set_default (gdbarch
, &arm_normal_base
);
9361 /* Address manipulation. */
9362 set_gdbarch_addr_bits_remove (gdbarch
, arm_addr_bits_remove
);
9364 /* Advance PC across function entry code. */
9365 set_gdbarch_skip_prologue (gdbarch
, arm_skip_prologue
);
9367 /* Detect whether PC is at a point where the stack has been destroyed. */
9368 set_gdbarch_stack_frame_destroyed_p (gdbarch
, arm_stack_frame_destroyed_p
);
9370 /* Skip trampolines. */
9371 set_gdbarch_skip_trampoline_code (gdbarch
, arm_skip_stub
);
9373 /* The stack grows downward. */
9374 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
9376 /* Breakpoint manipulation. */
9377 set_gdbarch_breakpoint_kind_from_pc (gdbarch
, arm_breakpoint_kind_from_pc
);
9378 set_gdbarch_sw_breakpoint_from_kind (gdbarch
, arm_sw_breakpoint_from_kind
);
9379 set_gdbarch_breakpoint_kind_from_current_state (gdbarch
,
9380 arm_breakpoint_kind_from_current_state
);
9382 /* Information about registers, etc. */
9383 set_gdbarch_sp_regnum (gdbarch
, ARM_SP_REGNUM
);
9384 set_gdbarch_pc_regnum (gdbarch
, ARM_PC_REGNUM
);
9385 set_gdbarch_num_regs (gdbarch
, ARM_NUM_REGS
);
9386 set_gdbarch_register_type (gdbarch
, arm_register_type
);
9387 set_gdbarch_register_reggroup_p (gdbarch
, arm_register_reggroup_p
);
9389 /* This "info float" is FPA-specific. Use the generic version if we
9391 if (gdbarch_tdep (gdbarch
)->have_fpa_registers
)
9392 set_gdbarch_print_float_info (gdbarch
, arm_print_float_info
);
9394 /* Internal <-> external register number maps. */
9395 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, arm_dwarf_reg_to_regnum
);
9396 set_gdbarch_register_sim_regno (gdbarch
, arm_register_sim_regno
);
9398 set_gdbarch_register_name (gdbarch
, arm_register_name
);
9400 /* Returning results. */
9401 set_gdbarch_return_value (gdbarch
, arm_return_value
);
9404 set_gdbarch_print_insn (gdbarch
, gdb_print_insn_arm
);
9406 /* Minsymbol frobbing. */
9407 set_gdbarch_elf_make_msymbol_special (gdbarch
, arm_elf_make_msymbol_special
);
9408 set_gdbarch_coff_make_msymbol_special (gdbarch
,
9409 arm_coff_make_msymbol_special
);
9410 set_gdbarch_record_special_symbol (gdbarch
, arm_record_special_symbol
);
9412 /* Thumb-2 IT block support. */
9413 set_gdbarch_adjust_breakpoint_address (gdbarch
,
9414 arm_adjust_breakpoint_address
);
9416 /* Virtual tables. */
9417 set_gdbarch_vbit_in_delta (gdbarch
, 1);
9419 /* Hook in the ABI-specific overrides, if they have been registered. */
9420 gdbarch_init_osabi (info
, gdbarch
);
9422 dwarf2_frame_set_init_reg (gdbarch
, arm_dwarf2_frame_init_reg
);
9424 /* Add some default predicates. */
9426 frame_unwind_append_unwinder (gdbarch
, &arm_m_exception_unwind
);
9427 frame_unwind_append_unwinder (gdbarch
, &arm_stub_unwind
);
9428 dwarf2_append_unwinders (gdbarch
);
9429 frame_unwind_append_unwinder (gdbarch
, &arm_exidx_unwind
);
9430 frame_unwind_append_unwinder (gdbarch
, &arm_epilogue_frame_unwind
);
9431 frame_unwind_append_unwinder (gdbarch
, &arm_prologue_unwind
);
9433 /* Now we have tuned the configuration, set a few final things,
9434 based on what the OS ABI has told us. */
9436 /* If the ABI is not otherwise marked, assume the old GNU APCS. EABI
9437 binaries are always marked. */
9438 if (tdep
->arm_abi
== ARM_ABI_AUTO
)
9439 tdep
->arm_abi
= ARM_ABI_APCS
;
9441 /* Watchpoints are not steppable. */
9442 set_gdbarch_have_nonsteppable_watchpoint (gdbarch
, 1);
9444 /* We used to default to FPA for generic ARM, but almost nobody
9445 uses that now, and we now provide a way for the user to force
9446 the model. So default to the most useful variant. */
9447 if (tdep
->fp_model
== ARM_FLOAT_AUTO
)
9448 tdep
->fp_model
= ARM_FLOAT_SOFT_FPA
;
9450 if (tdep
->jb_pc
>= 0)
9451 set_gdbarch_get_longjmp_target (gdbarch
, arm_get_longjmp_target
);
9453 /* Floating point sizes and format. */
9454 set_gdbarch_float_format (gdbarch
, floatformats_ieee_single
);
9455 if (tdep
->fp_model
== ARM_FLOAT_SOFT_FPA
|| tdep
->fp_model
== ARM_FLOAT_FPA
)
9457 set_gdbarch_double_format
9458 (gdbarch
, floatformats_ieee_double_littlebyte_bigword
);
9459 set_gdbarch_long_double_format
9460 (gdbarch
, floatformats_ieee_double_littlebyte_bigword
);
9464 set_gdbarch_double_format (gdbarch
, floatformats_ieee_double
);
9465 set_gdbarch_long_double_format (gdbarch
, floatformats_ieee_double
);
9468 if (have_vfp_pseudos
)
9470 /* NOTE: These are the only pseudo registers used by
9471 the ARM target at the moment. If more are added, a
9472 little more care in numbering will be needed. */
9474 int num_pseudos
= 32;
9475 if (have_neon_pseudos
)
9477 set_gdbarch_num_pseudo_regs (gdbarch
, num_pseudos
);
9478 set_gdbarch_pseudo_register_read (gdbarch
, arm_pseudo_read
);
9479 set_gdbarch_pseudo_register_write (gdbarch
, arm_pseudo_write
);
9482 if (tdesc_data
!= nullptr)
9484 set_tdesc_pseudo_register_name (gdbarch
, arm_register_name
);
9486 tdesc_use_registers (gdbarch
, tdesc
, std::move (tdesc_data
));
9488 /* Override tdesc_register_type to adjust the types of VFP
9489 registers for NEON. */
9490 set_gdbarch_register_type (gdbarch
, arm_register_type
);
9493 /* Add standard register aliases. We add aliases even for those
9494 names which are used by the current architecture - it's simpler,
9495 and does no harm, since nothing ever lists user registers. */
9496 for (i
= 0; i
< ARRAY_SIZE (arm_register_aliases
); i
++)
9497 user_reg_add (gdbarch
, arm_register_aliases
[i
].name
,
9498 value_of_arm_user_reg
, &arm_register_aliases
[i
].regnum
);
9500 set_gdbarch_disassembler_options (gdbarch
, &arm_disassembler_options
);
9501 set_gdbarch_valid_disassembler_options (gdbarch
, disassembler_options_arm ());
9503 set_gdbarch_gnu_triplet_regexp (gdbarch
, arm_gnu_triplet_regexp
);
9509 arm_dump_tdep (struct gdbarch
*gdbarch
, struct ui_file
*file
)
9511 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
9516 fprintf_unfiltered (file
, _("arm_dump_tdep: fp_model = %i\n"),
9517 (int) tdep
->fp_model
);
9518 fprintf_unfiltered (file
, _("arm_dump_tdep: have_fpa_registers = %i\n"),
9519 (int) tdep
->have_fpa_registers
);
9520 fprintf_unfiltered (file
, _("arm_dump_tdep: have_wmmx_registers = %i\n"),
9521 (int) tdep
->have_wmmx_registers
);
9522 fprintf_unfiltered (file
, _("arm_dump_tdep: vfp_register_count = %i\n"),
9523 (int) tdep
->vfp_register_count
);
9524 fprintf_unfiltered (file
, _("arm_dump_tdep: have_vfp_pseudos = %i\n"),
9525 (int) tdep
->have_vfp_pseudos
);
9526 fprintf_unfiltered (file
, _("arm_dump_tdep: have_neon_pseudos = %i\n"),
9527 (int) tdep
->have_neon_pseudos
);
9528 fprintf_unfiltered (file
, _("arm_dump_tdep: have_neon = %i\n"),
9529 (int) tdep
->have_neon
);
9530 fprintf_unfiltered (file
, _("arm_dump_tdep: Lowest pc = 0x%lx\n"),
9531 (unsigned long) tdep
->lowest_pc
);
9537 static void arm_record_test (void);
9538 static void arm_analyze_prologue_test ();
9542 void _initialize_arm_tdep ();
9544 _initialize_arm_tdep ()
9548 char regdesc
[1024], *rdptr
= regdesc
;
9549 size_t rest
= sizeof (regdesc
);
9551 gdbarch_register (bfd_arch_arm
, arm_gdbarch_init
, arm_dump_tdep
);
9553 /* Add ourselves to objfile event chain. */
9554 gdb::observers::new_objfile
.attach (arm_exidx_new_objfile
);
9556 /* Register an ELF OS ABI sniffer for ARM binaries. */
9557 gdbarch_register_osabi_sniffer (bfd_arch_arm
,
9558 bfd_target_elf_flavour
,
9559 arm_elf_osabi_sniffer
);
9561 /* Add root prefix command for all "set arm"/"show arm" commands. */
9562 add_basic_prefix_cmd ("arm", no_class
,
9563 _("Various ARM-specific commands."),
9564 &setarmcmdlist
, "set arm ", 0, &setlist
);
9566 add_show_prefix_cmd ("arm", no_class
,
9567 _("Various ARM-specific commands."),
9568 &showarmcmdlist
, "show arm ", 0, &showlist
);
9571 arm_disassembler_options
= xstrdup ("reg-names-std");
9572 const disasm_options_t
*disasm_options
9573 = &disassembler_options_arm ()->options
;
9574 int num_disassembly_styles
= 0;
9575 for (i
= 0; disasm_options
->name
[i
] != NULL
; i
++)
9576 if (CONST_STRNEQ (disasm_options
->name
[i
], "reg-names-"))
9577 num_disassembly_styles
++;
9579 /* Initialize the array that will be passed to add_setshow_enum_cmd(). */
9580 valid_disassembly_styles
= XNEWVEC (const char *,
9581 num_disassembly_styles
+ 1);
9582 for (i
= j
= 0; disasm_options
->name
[i
] != NULL
; i
++)
9583 if (CONST_STRNEQ (disasm_options
->name
[i
], "reg-names-"))
9585 size_t offset
= strlen ("reg-names-");
9586 const char *style
= disasm_options
->name
[i
];
9587 valid_disassembly_styles
[j
++] = &style
[offset
];
9588 length
= snprintf (rdptr
, rest
, "%s - %s\n", &style
[offset
],
9589 disasm_options
->description
[i
]);
9593 /* Mark the end of valid options. */
9594 valid_disassembly_styles
[num_disassembly_styles
] = NULL
;
9596 /* Create the help text. */
9597 std::string helptext
= string_printf ("%s%s%s",
9598 _("The valid values are:\n"),
9600 _("The default is \"std\"."));
9602 add_setshow_enum_cmd("disassembler", no_class
,
9603 valid_disassembly_styles
, &disassembly_style
,
9604 _("Set the disassembly style."),
9605 _("Show the disassembly style."),
9607 set_disassembly_style_sfunc
,
9608 show_disassembly_style_sfunc
,
9609 &setarmcmdlist
, &showarmcmdlist
);
9611 add_setshow_boolean_cmd ("apcs32", no_class
, &arm_apcs_32
,
9612 _("Set usage of ARM 32-bit mode."),
9613 _("Show usage of ARM 32-bit mode."),
9614 _("When off, a 26-bit PC will be used."),
9616 NULL
, /* FIXME: i18n: Usage of ARM 32-bit
9618 &setarmcmdlist
, &showarmcmdlist
);
9620 /* Add a command to allow the user to force the FPU model. */
9621 add_setshow_enum_cmd ("fpu", no_class
, fp_model_strings
, ¤t_fp_model
,
9622 _("Set the floating point type."),
9623 _("Show the floating point type."),
9624 _("auto - Determine the FP typefrom the OS-ABI.\n\
9625 softfpa - Software FP, mixed-endian doubles on little-endian ARMs.\n\
9626 fpa - FPA co-processor (GCC compiled).\n\
9627 softvfp - Software FP with pure-endian doubles.\n\
9628 vfp - VFP co-processor."),
9629 set_fp_model_sfunc
, show_fp_model
,
9630 &setarmcmdlist
, &showarmcmdlist
);
9632 /* Add a command to allow the user to force the ABI. */
9633 add_setshow_enum_cmd ("abi", class_support
, arm_abi_strings
, &arm_abi_string
,
9636 NULL
, arm_set_abi
, arm_show_abi
,
9637 &setarmcmdlist
, &showarmcmdlist
);
9639 /* Add two commands to allow the user to force the assumed
9641 add_setshow_enum_cmd ("fallback-mode", class_support
,
9642 arm_mode_strings
, &arm_fallback_mode_string
,
9643 _("Set the mode assumed when symbols are unavailable."),
9644 _("Show the mode assumed when symbols are unavailable."),
9645 NULL
, NULL
, arm_show_fallback_mode
,
9646 &setarmcmdlist
, &showarmcmdlist
);
9647 add_setshow_enum_cmd ("force-mode", class_support
,
9648 arm_mode_strings
, &arm_force_mode_string
,
9649 _("Set the mode assumed even when symbols are available."),
9650 _("Show the mode assumed even when symbols are available."),
9651 NULL
, NULL
, arm_show_force_mode
,
9652 &setarmcmdlist
, &showarmcmdlist
);
9654 /* Debugging flag. */
9655 add_setshow_boolean_cmd ("arm", class_maintenance
, &arm_debug
,
9656 _("Set ARM debugging."),
9657 _("Show ARM debugging."),
9658 _("When on, arm-specific debugging is enabled."),
9660 NULL
, /* FIXME: i18n: "ARM debugging is %s. */
9661 &setdebuglist
, &showdebuglist
);
9664 selftests::register_test ("arm-record", selftests::arm_record_test
);
9665 selftests::register_test ("arm_analyze_prologue", selftests::arm_analyze_prologue_test
);
9670 /* ARM-reversible process record data structures. */
9672 #define ARM_INSN_SIZE_BYTES 4
9673 #define THUMB_INSN_SIZE_BYTES 2
9674 #define THUMB2_INSN_SIZE_BYTES 4
9677 /* Position of the bit within a 32-bit ARM instruction
9678 that defines whether the instruction is a load or store. */
9679 #define INSN_S_L_BIT_NUM 20
9681 #define REG_ALLOC(REGS, LENGTH, RECORD_BUF) \
9684 unsigned int reg_len = LENGTH; \
9687 REGS = XNEWVEC (uint32_t, reg_len); \
9688 memcpy(®S[0], &RECORD_BUF[0], sizeof(uint32_t)*LENGTH); \
9693 #define MEM_ALLOC(MEMS, LENGTH, RECORD_BUF) \
9696 unsigned int mem_len = LENGTH; \
9699 MEMS = XNEWVEC (struct arm_mem_r, mem_len); \
9700 memcpy(&MEMS->len, &RECORD_BUF[0], \
9701 sizeof(struct arm_mem_r) * LENGTH); \
9706 /* Checks whether insn is already recorded or yet to be decoded. (boolean expression). */
9707 #define INSN_RECORDED(ARM_RECORD) \
9708 (0 != (ARM_RECORD)->reg_rec_count || 0 != (ARM_RECORD)->mem_rec_count)
9710 /* ARM memory record structure. */
9713 uint32_t len
; /* Record length. */
9714 uint32_t addr
; /* Memory address. */
9717 /* ARM instruction record contains opcode of current insn
9718 and execution state (before entry to decode_insn()),
9719 contains list of to-be-modified registers and
9720 memory blocks (on return from decode_insn()). */
9722 typedef struct insn_decode_record_t
9724 struct gdbarch
*gdbarch
;
9725 struct regcache
*regcache
;
9726 CORE_ADDR this_addr
; /* Address of the insn being decoded. */
9727 uint32_t arm_insn
; /* Should accommodate thumb. */
9728 uint32_t cond
; /* Condition code. */
9729 uint32_t opcode
; /* Insn opcode. */
9730 uint32_t decode
; /* Insn decode bits. */
9731 uint32_t mem_rec_count
; /* No of mem records. */
9732 uint32_t reg_rec_count
; /* No of reg records. */
9733 uint32_t *arm_regs
; /* Registers to be saved for this record. */
9734 struct arm_mem_r
*arm_mems
; /* Memory to be saved for this record. */
9735 } insn_decode_record
;
9738 /* Checks ARM SBZ and SBO mandatory fields. */
9741 sbo_sbz (uint32_t insn
, uint32_t bit_num
, uint32_t len
, uint32_t sbo
)
9743 uint32_t ones
= bits (insn
, bit_num
- 1, (bit_num
-1) + (len
- 1));
9762 enum arm_record_result
9764 ARM_RECORD_SUCCESS
= 0,
9765 ARM_RECORD_FAILURE
= 1
9772 } arm_record_strx_t
;
9783 arm_record_strx (insn_decode_record
*arm_insn_r
, uint32_t *record_buf
,
9784 uint32_t *record_buf_mem
, arm_record_strx_t str_type
)
9787 struct regcache
*reg_cache
= arm_insn_r
->regcache
;
9788 ULONGEST u_regval
[2]= {0};
9790 uint32_t reg_src1
= 0, reg_src2
= 0;
9791 uint32_t immed_high
= 0, immed_low
= 0,offset_8
= 0, tgt_mem_addr
= 0;
9793 arm_insn_r
->opcode
= bits (arm_insn_r
->arm_insn
, 21, 24);
9794 arm_insn_r
->decode
= bits (arm_insn_r
->arm_insn
, 4, 7);
9796 if (14 == arm_insn_r
->opcode
|| 10 == arm_insn_r
->opcode
)
9798 /* 1) Handle misc store, immediate offset. */
9799 immed_low
= bits (arm_insn_r
->arm_insn
, 0, 3);
9800 immed_high
= bits (arm_insn_r
->arm_insn
, 8, 11);
9801 reg_src1
= bits (arm_insn_r
->arm_insn
, 16, 19);
9802 regcache_raw_read_unsigned (reg_cache
, reg_src1
,
9804 if (ARM_PC_REGNUM
== reg_src1
)
9806 /* If R15 was used as Rn, hence current PC+8. */
9807 u_regval
[0] = u_regval
[0] + 8;
9809 offset_8
= (immed_high
<< 4) | immed_low
;
9810 /* Calculate target store address. */
9811 if (14 == arm_insn_r
->opcode
)
9813 tgt_mem_addr
= u_regval
[0] + offset_8
;
9817 tgt_mem_addr
= u_regval
[0] - offset_8
;
9819 if (ARM_RECORD_STRH
== str_type
)
9821 record_buf_mem
[0] = 2;
9822 record_buf_mem
[1] = tgt_mem_addr
;
9823 arm_insn_r
->mem_rec_count
= 1;
9825 else if (ARM_RECORD_STRD
== str_type
)
9827 record_buf_mem
[0] = 4;
9828 record_buf_mem
[1] = tgt_mem_addr
;
9829 record_buf_mem
[2] = 4;
9830 record_buf_mem
[3] = tgt_mem_addr
+ 4;
9831 arm_insn_r
->mem_rec_count
= 2;
9834 else if (12 == arm_insn_r
->opcode
|| 8 == arm_insn_r
->opcode
)
9836 /* 2) Store, register offset. */
9838 reg_src1
= bits (arm_insn_r
->arm_insn
, 0, 3);
9840 reg_src2
= bits (arm_insn_r
->arm_insn
, 16, 19);
9841 regcache_raw_read_unsigned (reg_cache
, reg_src1
, &u_regval
[0]);
9842 regcache_raw_read_unsigned (reg_cache
, reg_src2
, &u_regval
[1]);
9845 /* If R15 was used as Rn, hence current PC+8. */
9846 u_regval
[0] = u_regval
[0] + 8;
9848 /* Calculate target store address, Rn +/- Rm, register offset. */
9849 if (12 == arm_insn_r
->opcode
)
9851 tgt_mem_addr
= u_regval
[0] + u_regval
[1];
9855 tgt_mem_addr
= u_regval
[1] - u_regval
[0];
9857 if (ARM_RECORD_STRH
== str_type
)
9859 record_buf_mem
[0] = 2;
9860 record_buf_mem
[1] = tgt_mem_addr
;
9861 arm_insn_r
->mem_rec_count
= 1;
9863 else if (ARM_RECORD_STRD
== str_type
)
9865 record_buf_mem
[0] = 4;
9866 record_buf_mem
[1] = tgt_mem_addr
;
9867 record_buf_mem
[2] = 4;
9868 record_buf_mem
[3] = tgt_mem_addr
+ 4;
9869 arm_insn_r
->mem_rec_count
= 2;
9872 else if (11 == arm_insn_r
->opcode
|| 15 == arm_insn_r
->opcode
9873 || 2 == arm_insn_r
->opcode
|| 6 == arm_insn_r
->opcode
)
9875 /* 3) Store, immediate pre-indexed. */
9876 /* 5) Store, immediate post-indexed. */
9877 immed_low
= bits (arm_insn_r
->arm_insn
, 0, 3);
9878 immed_high
= bits (arm_insn_r
->arm_insn
, 8, 11);
9879 offset_8
= (immed_high
<< 4) | immed_low
;
9880 reg_src1
= bits (arm_insn_r
->arm_insn
, 16, 19);
9881 regcache_raw_read_unsigned (reg_cache
, reg_src1
, &u_regval
[0]);
9882 /* Calculate target store address, Rn +/- Rm, register offset. */
9883 if (15 == arm_insn_r
->opcode
|| 6 == arm_insn_r
->opcode
)
9885 tgt_mem_addr
= u_regval
[0] + offset_8
;
9889 tgt_mem_addr
= u_regval
[0] - offset_8
;
9891 if (ARM_RECORD_STRH
== str_type
)
9893 record_buf_mem
[0] = 2;
9894 record_buf_mem
[1] = tgt_mem_addr
;
9895 arm_insn_r
->mem_rec_count
= 1;
9897 else if (ARM_RECORD_STRD
== str_type
)
9899 record_buf_mem
[0] = 4;
9900 record_buf_mem
[1] = tgt_mem_addr
;
9901 record_buf_mem
[2] = 4;
9902 record_buf_mem
[3] = tgt_mem_addr
+ 4;
9903 arm_insn_r
->mem_rec_count
= 2;
9905 /* Record Rn also as it changes. */
9906 *(record_buf
) = bits (arm_insn_r
->arm_insn
, 16, 19);
9907 arm_insn_r
->reg_rec_count
= 1;
9909 else if (9 == arm_insn_r
->opcode
|| 13 == arm_insn_r
->opcode
9910 || 0 == arm_insn_r
->opcode
|| 4 == arm_insn_r
->opcode
)
9912 /* 4) Store, register pre-indexed. */
9913 /* 6) Store, register post -indexed. */
9914 reg_src1
= bits (arm_insn_r
->arm_insn
, 0, 3);
9915 reg_src2
= bits (arm_insn_r
->arm_insn
, 16, 19);
9916 regcache_raw_read_unsigned (reg_cache
, reg_src1
, &u_regval
[0]);
9917 regcache_raw_read_unsigned (reg_cache
, reg_src2
, &u_regval
[1]);
9918 /* Calculate target store address, Rn +/- Rm, register offset. */
9919 if (13 == arm_insn_r
->opcode
|| 4 == arm_insn_r
->opcode
)
9921 tgt_mem_addr
= u_regval
[0] + u_regval
[1];
9925 tgt_mem_addr
= u_regval
[1] - u_regval
[0];
9927 if (ARM_RECORD_STRH
== str_type
)
9929 record_buf_mem
[0] = 2;
9930 record_buf_mem
[1] = tgt_mem_addr
;
9931 arm_insn_r
->mem_rec_count
= 1;
9933 else if (ARM_RECORD_STRD
== str_type
)
9935 record_buf_mem
[0] = 4;
9936 record_buf_mem
[1] = tgt_mem_addr
;
9937 record_buf_mem
[2] = 4;
9938 record_buf_mem
[3] = tgt_mem_addr
+ 4;
9939 arm_insn_r
->mem_rec_count
= 2;
9941 /* Record Rn also as it changes. */
9942 *(record_buf
) = bits (arm_insn_r
->arm_insn
, 16, 19);
9943 arm_insn_r
->reg_rec_count
= 1;
9948 /* Handling ARM extension space insns. */
9951 arm_record_extension_space (insn_decode_record
*arm_insn_r
)
9953 int ret
= 0; /* Return value: -1:record failure ; 0:success */
9954 uint32_t opcode1
= 0, opcode2
= 0, insn_op1
= 0;
9955 uint32_t record_buf
[8], record_buf_mem
[8];
9956 uint32_t reg_src1
= 0;
9957 struct regcache
*reg_cache
= arm_insn_r
->regcache
;
9958 ULONGEST u_regval
= 0;
9960 gdb_assert (!INSN_RECORDED(arm_insn_r
));
9961 /* Handle unconditional insn extension space. */
9963 opcode1
= bits (arm_insn_r
->arm_insn
, 20, 27);
9964 opcode2
= bits (arm_insn_r
->arm_insn
, 4, 7);
9965 if (arm_insn_r
->cond
)
9967 /* PLD has no affect on architectural state, it just affects
9969 if (5 == ((opcode1
& 0xE0) >> 5))
9972 record_buf
[0] = ARM_PS_REGNUM
;
9973 record_buf
[1] = ARM_LR_REGNUM
;
9974 arm_insn_r
->reg_rec_count
= 2;
9976 /* STC2, LDC2, MCR2, MRC2, CDP2: <TBD>, co-processor insn. */
9980 opcode1
= bits (arm_insn_r
->arm_insn
, 25, 27);
9981 if (3 == opcode1
&& bit (arm_insn_r
->arm_insn
, 4))
9984 /* Undefined instruction on ARM V5; need to handle if later
9985 versions define it. */
9988 opcode1
= bits (arm_insn_r
->arm_insn
, 24, 27);
9989 opcode2
= bits (arm_insn_r
->arm_insn
, 4, 7);
9990 insn_op1
= bits (arm_insn_r
->arm_insn
, 20, 23);
9992 /* Handle arithmetic insn extension space. */
9993 if (!opcode1
&& 9 == opcode2
&& 1 != arm_insn_r
->cond
9994 && !INSN_RECORDED(arm_insn_r
))
9996 /* Handle MLA(S) and MUL(S). */
9997 if (in_inclusive_range (insn_op1
, 0U, 3U))
9999 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
10000 record_buf
[1] = ARM_PS_REGNUM
;
10001 arm_insn_r
->reg_rec_count
= 2;
10003 else if (in_inclusive_range (insn_op1
, 4U, 15U))
10005 /* Handle SMLAL(S), SMULL(S), UMLAL(S), UMULL(S). */
10006 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 16, 19);
10007 record_buf
[1] = bits (arm_insn_r
->arm_insn
, 12, 15);
10008 record_buf
[2] = ARM_PS_REGNUM
;
10009 arm_insn_r
->reg_rec_count
= 3;
10013 opcode1
= bits (arm_insn_r
->arm_insn
, 26, 27);
10014 opcode2
= bits (arm_insn_r
->arm_insn
, 23, 24);
10015 insn_op1
= bits (arm_insn_r
->arm_insn
, 21, 22);
10017 /* Handle control insn extension space. */
10019 if (!opcode1
&& 2 == opcode2
&& !bit (arm_insn_r
->arm_insn
, 20)
10020 && 1 != arm_insn_r
->cond
&& !INSN_RECORDED(arm_insn_r
))
10022 if (!bit (arm_insn_r
->arm_insn
,25))
10024 if (!bits (arm_insn_r
->arm_insn
, 4, 7))
10026 if ((0 == insn_op1
) || (2 == insn_op1
))
10029 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
10030 arm_insn_r
->reg_rec_count
= 1;
10032 else if (1 == insn_op1
)
10034 /* CSPR is going to be changed. */
10035 record_buf
[0] = ARM_PS_REGNUM
;
10036 arm_insn_r
->reg_rec_count
= 1;
10038 else if (3 == insn_op1
)
10040 /* SPSR is going to be changed. */
10041 /* We need to get SPSR value, which is yet to be done. */
10045 else if (1 == bits (arm_insn_r
->arm_insn
, 4, 7))
10050 record_buf
[0] = ARM_PS_REGNUM
;
10051 arm_insn_r
->reg_rec_count
= 1;
10053 else if (3 == insn_op1
)
10056 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
10057 arm_insn_r
->reg_rec_count
= 1;
10060 else if (3 == bits (arm_insn_r
->arm_insn
, 4, 7))
10063 record_buf
[0] = ARM_PS_REGNUM
;
10064 record_buf
[1] = ARM_LR_REGNUM
;
10065 arm_insn_r
->reg_rec_count
= 2;
10067 else if (5 == bits (arm_insn_r
->arm_insn
, 4, 7))
10069 /* QADD, QSUB, QDADD, QDSUB */
10070 record_buf
[0] = ARM_PS_REGNUM
;
10071 record_buf
[1] = bits (arm_insn_r
->arm_insn
, 12, 15);
10072 arm_insn_r
->reg_rec_count
= 2;
10074 else if (7 == bits (arm_insn_r
->arm_insn
, 4, 7))
10077 record_buf
[0] = ARM_PS_REGNUM
;
10078 record_buf
[1] = ARM_LR_REGNUM
;
10079 arm_insn_r
->reg_rec_count
= 2;
10081 /* Save SPSR also;how? */
10084 else if(8 == bits (arm_insn_r
->arm_insn
, 4, 7)
10085 || 10 == bits (arm_insn_r
->arm_insn
, 4, 7)
10086 || 12 == bits (arm_insn_r
->arm_insn
, 4, 7)
10087 || 14 == bits (arm_insn_r
->arm_insn
, 4, 7)
10090 if (0 == insn_op1
|| 1 == insn_op1
)
10092 /* SMLA<x><y>, SMLAW<y>, SMULW<y>. */
10093 /* We dont do optimization for SMULW<y> where we
10095 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
10096 record_buf
[1] = ARM_PS_REGNUM
;
10097 arm_insn_r
->reg_rec_count
= 2;
10099 else if (2 == insn_op1
)
10102 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
10103 record_buf
[1] = bits (arm_insn_r
->arm_insn
, 16, 19);
10104 arm_insn_r
->reg_rec_count
= 2;
10106 else if (3 == insn_op1
)
10109 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
10110 arm_insn_r
->reg_rec_count
= 1;
10116 /* MSR : immediate form. */
10119 /* CSPR is going to be changed. */
10120 record_buf
[0] = ARM_PS_REGNUM
;
10121 arm_insn_r
->reg_rec_count
= 1;
10123 else if (3 == insn_op1
)
10125 /* SPSR is going to be changed. */
10126 /* we need to get SPSR value, which is yet to be done */
10132 opcode1
= bits (arm_insn_r
->arm_insn
, 25, 27);
10133 opcode2
= bits (arm_insn_r
->arm_insn
, 20, 24);
10134 insn_op1
= bits (arm_insn_r
->arm_insn
, 5, 6);
10136 /* Handle load/store insn extension space. */
10138 if (!opcode1
&& bit (arm_insn_r
->arm_insn
, 7)
10139 && bit (arm_insn_r
->arm_insn
, 4) && 1 != arm_insn_r
->cond
10140 && !INSN_RECORDED(arm_insn_r
))
10145 /* These insn, changes register and memory as well. */
10146 /* SWP or SWPB insn. */
10147 /* Get memory address given by Rn. */
10148 reg_src1
= bits (arm_insn_r
->arm_insn
, 16, 19);
10149 regcache_raw_read_unsigned (reg_cache
, reg_src1
, &u_regval
);
10150 /* SWP insn ?, swaps word. */
10151 if (8 == arm_insn_r
->opcode
)
10153 record_buf_mem
[0] = 4;
10157 /* SWPB insn, swaps only byte. */
10158 record_buf_mem
[0] = 1;
10160 record_buf_mem
[1] = u_regval
;
10161 arm_insn_r
->mem_rec_count
= 1;
10162 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
10163 arm_insn_r
->reg_rec_count
= 1;
10165 else if (1 == insn_op1
&& !bit (arm_insn_r
->arm_insn
, 20))
10168 arm_record_strx(arm_insn_r
, &record_buf
[0], &record_buf_mem
[0],
10171 else if (2 == insn_op1
&& !bit (arm_insn_r
->arm_insn
, 20))
10174 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
10175 record_buf
[1] = record_buf
[0] + 1;
10176 arm_insn_r
->reg_rec_count
= 2;
10178 else if (3 == insn_op1
&& !bit (arm_insn_r
->arm_insn
, 20))
10181 arm_record_strx(arm_insn_r
, &record_buf
[0], &record_buf_mem
[0],
10184 else if (bit (arm_insn_r
->arm_insn
, 20) && insn_op1
<= 3)
10186 /* LDRH, LDRSB, LDRSH. */
10187 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
10188 arm_insn_r
->reg_rec_count
= 1;
10193 opcode1
= bits (arm_insn_r
->arm_insn
, 23, 27);
10194 if (24 == opcode1
&& bit (arm_insn_r
->arm_insn
, 21)
10195 && !INSN_RECORDED(arm_insn_r
))
10198 /* Handle coprocessor insn extension space. */
10201 /* To be done for ARMv5 and later; as of now we return -1. */
10205 REG_ALLOC (arm_insn_r
->arm_regs
, arm_insn_r
->reg_rec_count
, record_buf
);
10206 MEM_ALLOC (arm_insn_r
->arm_mems
, arm_insn_r
->mem_rec_count
, record_buf_mem
);
10211 /* Handling opcode 000 insns. */
10214 arm_record_data_proc_misc_ld_str (insn_decode_record
*arm_insn_r
)
10216 struct regcache
*reg_cache
= arm_insn_r
->regcache
;
10217 uint32_t record_buf
[8], record_buf_mem
[8];
10218 ULONGEST u_regval
[2] = {0};
10220 uint32_t reg_src1
= 0;
10221 uint32_t opcode1
= 0;
10223 arm_insn_r
->opcode
= bits (arm_insn_r
->arm_insn
, 21, 24);
10224 arm_insn_r
->decode
= bits (arm_insn_r
->arm_insn
, 4, 7);
10225 opcode1
= bits (arm_insn_r
->arm_insn
, 20, 24);
10227 if (!((opcode1
& 0x19) == 0x10))
10229 /* Data-processing (register) and Data-processing (register-shifted
10231 /* Out of 11 shifter operands mode, all the insn modifies destination
10232 register, which is specified by 13-16 decode. */
10233 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
10234 record_buf
[1] = ARM_PS_REGNUM
;
10235 arm_insn_r
->reg_rec_count
= 2;
10237 else if ((arm_insn_r
->decode
< 8) && ((opcode1
& 0x19) == 0x10))
10239 /* Miscellaneous instructions */
10241 if (3 == arm_insn_r
->decode
&& 0x12 == opcode1
10242 && sbo_sbz (arm_insn_r
->arm_insn
, 9, 12, 1))
10244 /* Handle BLX, branch and link/exchange. */
10245 if (9 == arm_insn_r
->opcode
)
10247 /* Branch is chosen by setting T bit of CSPR, bitp[0] of Rm,
10248 and R14 stores the return address. */
10249 record_buf
[0] = ARM_PS_REGNUM
;
10250 record_buf
[1] = ARM_LR_REGNUM
;
10251 arm_insn_r
->reg_rec_count
= 2;
10254 else if (7 == arm_insn_r
->decode
&& 0x12 == opcode1
)
10256 /* Handle enhanced software breakpoint insn, BKPT. */
10257 /* CPSR is changed to be executed in ARM state, disabling normal
10258 interrupts, entering abort mode. */
10259 /* According to high vector configuration PC is set. */
10260 /* user hit breakpoint and type reverse, in
10261 that case, we need to go back with previous CPSR and
10262 Program Counter. */
10263 record_buf
[0] = ARM_PS_REGNUM
;
10264 record_buf
[1] = ARM_LR_REGNUM
;
10265 arm_insn_r
->reg_rec_count
= 2;
10267 /* Save SPSR also; how? */
10270 else if (1 == arm_insn_r
->decode
&& 0x12 == opcode1
10271 && sbo_sbz (arm_insn_r
->arm_insn
, 9, 12, 1))
10273 /* Handle BX, branch and link/exchange. */
10274 /* Branch is chosen by setting T bit of CSPR, bitp[0] of Rm. */
10275 record_buf
[0] = ARM_PS_REGNUM
;
10276 arm_insn_r
->reg_rec_count
= 1;
10278 else if (1 == arm_insn_r
->decode
&& 0x16 == opcode1
10279 && sbo_sbz (arm_insn_r
->arm_insn
, 9, 4, 1)
10280 && sbo_sbz (arm_insn_r
->arm_insn
, 17, 4, 1))
10282 /* Count leading zeros: CLZ. */
10283 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
10284 arm_insn_r
->reg_rec_count
= 1;
10286 else if (!bit (arm_insn_r
->arm_insn
, INSN_S_L_BIT_NUM
)
10287 && (8 == arm_insn_r
->opcode
|| 10 == arm_insn_r
->opcode
)
10288 && sbo_sbz (arm_insn_r
->arm_insn
, 17, 4, 1)
10289 && sbo_sbz (arm_insn_r
->arm_insn
, 1, 12, 0))
10291 /* Handle MRS insn. */
10292 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
10293 arm_insn_r
->reg_rec_count
= 1;
10296 else if (9 == arm_insn_r
->decode
&& opcode1
< 0x10)
10298 /* Multiply and multiply-accumulate */
10300 /* Handle multiply instructions. */
10301 /* MLA, MUL, SMLAL, SMULL, UMLAL, UMULL. */
10302 if (0 == arm_insn_r
->opcode
|| 1 == arm_insn_r
->opcode
)
10304 /* Handle MLA and MUL. */
10305 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 16, 19);
10306 record_buf
[1] = ARM_PS_REGNUM
;
10307 arm_insn_r
->reg_rec_count
= 2;
10309 else if (4 <= arm_insn_r
->opcode
&& 7 >= arm_insn_r
->opcode
)
10311 /* Handle SMLAL, SMULL, UMLAL, UMULL. */
10312 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 16, 19);
10313 record_buf
[1] = bits (arm_insn_r
->arm_insn
, 12, 15);
10314 record_buf
[2] = ARM_PS_REGNUM
;
10315 arm_insn_r
->reg_rec_count
= 3;
10318 else if (9 == arm_insn_r
->decode
&& opcode1
> 0x10)
10320 /* Synchronization primitives */
10322 /* Handling SWP, SWPB. */
10323 /* These insn, changes register and memory as well. */
10324 /* SWP or SWPB insn. */
10326 reg_src1
= bits (arm_insn_r
->arm_insn
, 16, 19);
10327 regcache_raw_read_unsigned (reg_cache
, reg_src1
, &u_regval
[0]);
10328 /* SWP insn ?, swaps word. */
10329 if (8 == arm_insn_r
->opcode
)
10331 record_buf_mem
[0] = 4;
10335 /* SWPB insn, swaps only byte. */
10336 record_buf_mem
[0] = 1;
10338 record_buf_mem
[1] = u_regval
[0];
10339 arm_insn_r
->mem_rec_count
= 1;
10340 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
10341 arm_insn_r
->reg_rec_count
= 1;
10343 else if (11 == arm_insn_r
->decode
|| 13 == arm_insn_r
->decode
10344 || 15 == arm_insn_r
->decode
)
10346 if ((opcode1
& 0x12) == 2)
10348 /* Extra load/store (unprivileged) */
10353 /* Extra load/store */
10354 switch (bits (arm_insn_r
->arm_insn
, 5, 6))
10357 if ((opcode1
& 0x05) == 0x0 || (opcode1
& 0x05) == 0x4)
10359 /* STRH (register), STRH (immediate) */
10360 arm_record_strx (arm_insn_r
, &record_buf
[0],
10361 &record_buf_mem
[0], ARM_RECORD_STRH
);
10363 else if ((opcode1
& 0x05) == 0x1)
10365 /* LDRH (register) */
10366 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
10367 arm_insn_r
->reg_rec_count
= 1;
10369 if (bit (arm_insn_r
->arm_insn
, 21))
10371 /* Write back to Rn. */
10372 record_buf
[arm_insn_r
->reg_rec_count
++]
10373 = bits (arm_insn_r
->arm_insn
, 16, 19);
10376 else if ((opcode1
& 0x05) == 0x5)
10378 /* LDRH (immediate), LDRH (literal) */
10379 int rn
= bits (arm_insn_r
->arm_insn
, 16, 19);
10381 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
10382 arm_insn_r
->reg_rec_count
= 1;
10386 /*LDRH (immediate) */
10387 if (bit (arm_insn_r
->arm_insn
, 21))
10389 /* Write back to Rn. */
10390 record_buf
[arm_insn_r
->reg_rec_count
++] = rn
;
10398 if ((opcode1
& 0x05) == 0x0)
10400 /* LDRD (register) */
10401 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
10402 record_buf
[1] = record_buf
[0] + 1;
10403 arm_insn_r
->reg_rec_count
= 2;
10405 if (bit (arm_insn_r
->arm_insn
, 21))
10407 /* Write back to Rn. */
10408 record_buf
[arm_insn_r
->reg_rec_count
++]
10409 = bits (arm_insn_r
->arm_insn
, 16, 19);
10412 else if ((opcode1
& 0x05) == 0x1)
10414 /* LDRSB (register) */
10415 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
10416 arm_insn_r
->reg_rec_count
= 1;
10418 if (bit (arm_insn_r
->arm_insn
, 21))
10420 /* Write back to Rn. */
10421 record_buf
[arm_insn_r
->reg_rec_count
++]
10422 = bits (arm_insn_r
->arm_insn
, 16, 19);
10425 else if ((opcode1
& 0x05) == 0x4 || (opcode1
& 0x05) == 0x5)
10427 /* LDRD (immediate), LDRD (literal), LDRSB (immediate),
10429 int rn
= bits (arm_insn_r
->arm_insn
, 16, 19);
10431 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
10432 arm_insn_r
->reg_rec_count
= 1;
10436 /*LDRD (immediate), LDRSB (immediate) */
10437 if (bit (arm_insn_r
->arm_insn
, 21))
10439 /* Write back to Rn. */
10440 record_buf
[arm_insn_r
->reg_rec_count
++] = rn
;
10448 if ((opcode1
& 0x05) == 0x0)
10450 /* STRD (register) */
10451 arm_record_strx (arm_insn_r
, &record_buf
[0],
10452 &record_buf_mem
[0], ARM_RECORD_STRD
);
10454 else if ((opcode1
& 0x05) == 0x1)
10456 /* LDRSH (register) */
10457 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
10458 arm_insn_r
->reg_rec_count
= 1;
10460 if (bit (arm_insn_r
->arm_insn
, 21))
10462 /* Write back to Rn. */
10463 record_buf
[arm_insn_r
->reg_rec_count
++]
10464 = bits (arm_insn_r
->arm_insn
, 16, 19);
10467 else if ((opcode1
& 0x05) == 0x4)
10469 /* STRD (immediate) */
10470 arm_record_strx (arm_insn_r
, &record_buf
[0],
10471 &record_buf_mem
[0], ARM_RECORD_STRD
);
10473 else if ((opcode1
& 0x05) == 0x5)
10475 /* LDRSH (immediate), LDRSH (literal) */
10476 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
10477 arm_insn_r
->reg_rec_count
= 1;
10479 if (bit (arm_insn_r
->arm_insn
, 21))
10481 /* Write back to Rn. */
10482 record_buf
[arm_insn_r
->reg_rec_count
++]
10483 = bits (arm_insn_r
->arm_insn
, 16, 19);
10499 REG_ALLOC (arm_insn_r
->arm_regs
, arm_insn_r
->reg_rec_count
, record_buf
);
10500 MEM_ALLOC (arm_insn_r
->arm_mems
, arm_insn_r
->mem_rec_count
, record_buf_mem
);
10504 /* Handling opcode 001 insns. */
10507 arm_record_data_proc_imm (insn_decode_record
*arm_insn_r
)
10509 uint32_t record_buf
[8], record_buf_mem
[8];
10511 arm_insn_r
->opcode
= bits (arm_insn_r
->arm_insn
, 21, 24);
10512 arm_insn_r
->decode
= bits (arm_insn_r
->arm_insn
, 4, 7);
10514 if ((9 == arm_insn_r
->opcode
|| 11 == arm_insn_r
->opcode
)
10515 && 2 == bits (arm_insn_r
->arm_insn
, 20, 21)
10516 && sbo_sbz (arm_insn_r
->arm_insn
, 13, 4, 1)
10519 /* Handle MSR insn. */
10520 if (9 == arm_insn_r
->opcode
)
10522 /* CSPR is going to be changed. */
10523 record_buf
[0] = ARM_PS_REGNUM
;
10524 arm_insn_r
->reg_rec_count
= 1;
10528 /* SPSR is going to be changed. */
10531 else if (arm_insn_r
->opcode
<= 15)
10533 /* Normal data processing insns. */
10534 /* Out of 11 shifter operands mode, all the insn modifies destination
10535 register, which is specified by 13-16 decode. */
10536 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
10537 record_buf
[1] = ARM_PS_REGNUM
;
10538 arm_insn_r
->reg_rec_count
= 2;
10545 REG_ALLOC (arm_insn_r
->arm_regs
, arm_insn_r
->reg_rec_count
, record_buf
);
10546 MEM_ALLOC (arm_insn_r
->arm_mems
, arm_insn_r
->mem_rec_count
, record_buf_mem
);
10551 arm_record_media (insn_decode_record
*arm_insn_r
)
10553 uint32_t record_buf
[8];
10555 switch (bits (arm_insn_r
->arm_insn
, 22, 24))
10558 /* Parallel addition and subtraction, signed */
10560 /* Parallel addition and subtraction, unsigned */
10563 /* Packing, unpacking, saturation and reversal */
10565 int rd
= bits (arm_insn_r
->arm_insn
, 12, 15);
10567 record_buf
[arm_insn_r
->reg_rec_count
++] = rd
;
10573 /* Signed multiplies */
10575 int rd
= bits (arm_insn_r
->arm_insn
, 16, 19);
10576 unsigned int op1
= bits (arm_insn_r
->arm_insn
, 20, 22);
10578 record_buf
[arm_insn_r
->reg_rec_count
++] = rd
;
10580 record_buf
[arm_insn_r
->reg_rec_count
++] = ARM_PS_REGNUM
;
10581 else if (op1
== 0x4)
10582 record_buf
[arm_insn_r
->reg_rec_count
++]
10583 = bits (arm_insn_r
->arm_insn
, 12, 15);
10589 if (bit (arm_insn_r
->arm_insn
, 21)
10590 && bits (arm_insn_r
->arm_insn
, 5, 6) == 0x2)
10593 record_buf
[arm_insn_r
->reg_rec_count
++]
10594 = bits (arm_insn_r
->arm_insn
, 12, 15);
10596 else if (bits (arm_insn_r
->arm_insn
, 20, 21) == 0x0
10597 && bits (arm_insn_r
->arm_insn
, 5, 7) == 0x0)
10599 /* USAD8 and USADA8 */
10600 record_buf
[arm_insn_r
->reg_rec_count
++]
10601 = bits (arm_insn_r
->arm_insn
, 16, 19);
10608 if (bits (arm_insn_r
->arm_insn
, 20, 21) == 0x3
10609 && bits (arm_insn_r
->arm_insn
, 5, 7) == 0x7)
10611 /* Permanently UNDEFINED */
10616 /* BFC, BFI and UBFX */
10617 record_buf
[arm_insn_r
->reg_rec_count
++]
10618 = bits (arm_insn_r
->arm_insn
, 12, 15);
10627 REG_ALLOC (arm_insn_r
->arm_regs
, arm_insn_r
->reg_rec_count
, record_buf
);
10632 /* Handle ARM mode instructions with opcode 010. */
10635 arm_record_ld_st_imm_offset (insn_decode_record
*arm_insn_r
)
10637 struct regcache
*reg_cache
= arm_insn_r
->regcache
;
10639 uint32_t reg_base
, reg_dest
;
10640 uint32_t offset_12
, tgt_mem_addr
;
10641 uint32_t record_buf
[8], record_buf_mem
[8];
10642 unsigned char wback
;
10645 /* Calculate wback. */
10646 wback
= (bit (arm_insn_r
->arm_insn
, 24) == 0)
10647 || (bit (arm_insn_r
->arm_insn
, 21) == 1);
10649 arm_insn_r
->reg_rec_count
= 0;
10650 reg_base
= bits (arm_insn_r
->arm_insn
, 16, 19);
10652 if (bit (arm_insn_r
->arm_insn
, INSN_S_L_BIT_NUM
))
10654 /* LDR (immediate), LDR (literal), LDRB (immediate), LDRB (literal), LDRBT
10657 reg_dest
= bits (arm_insn_r
->arm_insn
, 12, 15);
10658 record_buf
[arm_insn_r
->reg_rec_count
++] = reg_dest
;
10660 /* The LDR instruction is capable of doing branching. If MOV LR, PC
10661 preceeds a LDR instruction having R15 as reg_base, it
10662 emulates a branch and link instruction, and hence we need to save
10663 CPSR and PC as well. */
10664 if (ARM_PC_REGNUM
== reg_dest
)
10665 record_buf
[arm_insn_r
->reg_rec_count
++] = ARM_PS_REGNUM
;
10667 /* If wback is true, also save the base register, which is going to be
10670 record_buf
[arm_insn_r
->reg_rec_count
++] = reg_base
;
10674 /* STR (immediate), STRB (immediate), STRBT and STRT. */
10676 offset_12
= bits (arm_insn_r
->arm_insn
, 0, 11);
10677 regcache_raw_read_unsigned (reg_cache
, reg_base
, &u_regval
);
10679 /* Handle bit U. */
10680 if (bit (arm_insn_r
->arm_insn
, 23))
10682 /* U == 1: Add the offset. */
10683 tgt_mem_addr
= (uint32_t) u_regval
+ offset_12
;
10687 /* U == 0: subtract the offset. */
10688 tgt_mem_addr
= (uint32_t) u_regval
- offset_12
;
10691 /* Bit 22 tells us whether the store instruction writes 1 byte or 4
10693 if (bit (arm_insn_r
->arm_insn
, 22))
10695 /* STRB and STRBT: 1 byte. */
10696 record_buf_mem
[0] = 1;
10700 /* STR and STRT: 4 bytes. */
10701 record_buf_mem
[0] = 4;
10704 /* Handle bit P. */
10705 if (bit (arm_insn_r
->arm_insn
, 24))
10706 record_buf_mem
[1] = tgt_mem_addr
;
10708 record_buf_mem
[1] = (uint32_t) u_regval
;
10710 arm_insn_r
->mem_rec_count
= 1;
10712 /* If wback is true, also save the base register, which is going to be
10715 record_buf
[arm_insn_r
->reg_rec_count
++] = reg_base
;
10718 REG_ALLOC (arm_insn_r
->arm_regs
, arm_insn_r
->reg_rec_count
, record_buf
);
10719 MEM_ALLOC (arm_insn_r
->arm_mems
, arm_insn_r
->mem_rec_count
, record_buf_mem
);
10723 /* Handling opcode 011 insns. */
10726 arm_record_ld_st_reg_offset (insn_decode_record
*arm_insn_r
)
10728 struct regcache
*reg_cache
= arm_insn_r
->regcache
;
10730 uint32_t shift_imm
= 0;
10731 uint32_t reg_src1
= 0, reg_src2
= 0, reg_dest
= 0;
10732 uint32_t offset_12
= 0, tgt_mem_addr
= 0;
10733 uint32_t record_buf
[8], record_buf_mem
[8];
10736 ULONGEST u_regval
[2];
10738 if (bit (arm_insn_r
->arm_insn
, 4))
10739 return arm_record_media (arm_insn_r
);
10741 arm_insn_r
->opcode
= bits (arm_insn_r
->arm_insn
, 21, 24);
10742 arm_insn_r
->decode
= bits (arm_insn_r
->arm_insn
, 4, 7);
10744 /* Handle enhanced store insns and LDRD DSP insn,
10745 order begins according to addressing modes for store insns
10749 if (bit (arm_insn_r
->arm_insn
, INSN_S_L_BIT_NUM
))
10751 reg_dest
= bits (arm_insn_r
->arm_insn
, 12, 15);
10752 /* LDR insn has a capability to do branching, if
10753 MOV LR, PC is preceded by LDR insn having Rn as R15
10754 in that case, it emulates branch and link insn, and hence we
10755 need to save CSPR and PC as well. */
10756 if (15 != reg_dest
)
10758 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
10759 arm_insn_r
->reg_rec_count
= 1;
10763 record_buf
[0] = reg_dest
;
10764 record_buf
[1] = ARM_PS_REGNUM
;
10765 arm_insn_r
->reg_rec_count
= 2;
10770 if (! bits (arm_insn_r
->arm_insn
, 4, 11))
10772 /* Store insn, register offset and register pre-indexed,
10773 register post-indexed. */
10775 reg_src1
= bits (arm_insn_r
->arm_insn
, 0, 3);
10777 reg_src2
= bits (arm_insn_r
->arm_insn
, 16, 19);
10778 regcache_raw_read_unsigned (reg_cache
, reg_src1
10780 regcache_raw_read_unsigned (reg_cache
, reg_src2
10782 if (15 == reg_src2
)
10784 /* If R15 was used as Rn, hence current PC+8. */
10785 /* Pre-indexed mode doesnt reach here ; illegal insn. */
10786 u_regval
[0] = u_regval
[0] + 8;
10788 /* Calculate target store address, Rn +/- Rm, register offset. */
10790 if (bit (arm_insn_r
->arm_insn
, 23))
10792 tgt_mem_addr
= u_regval
[0] + u_regval
[1];
10796 tgt_mem_addr
= u_regval
[1] - u_regval
[0];
10799 switch (arm_insn_r
->opcode
)
10813 record_buf_mem
[0] = 4;
10828 record_buf_mem
[0] = 1;
10832 gdb_assert_not_reached ("no decoding pattern found");
10835 record_buf_mem
[1] = tgt_mem_addr
;
10836 arm_insn_r
->mem_rec_count
= 1;
10838 if (9 == arm_insn_r
->opcode
|| 11 == arm_insn_r
->opcode
10839 || 13 == arm_insn_r
->opcode
|| 15 == arm_insn_r
->opcode
10840 || 0 == arm_insn_r
->opcode
|| 2 == arm_insn_r
->opcode
10841 || 4 == arm_insn_r
->opcode
|| 6 == arm_insn_r
->opcode
10842 || 1 == arm_insn_r
->opcode
|| 3 == arm_insn_r
->opcode
10843 || 5 == arm_insn_r
->opcode
|| 7 == arm_insn_r
->opcode
10846 /* Rn is going to be changed in pre-indexed mode and
10847 post-indexed mode as well. */
10848 record_buf
[0] = reg_src2
;
10849 arm_insn_r
->reg_rec_count
= 1;
10854 /* Store insn, scaled register offset; scaled pre-indexed. */
10855 offset_12
= bits (arm_insn_r
->arm_insn
, 5, 6);
10857 reg_src1
= bits (arm_insn_r
->arm_insn
, 0, 3);
10859 reg_src2
= bits (arm_insn_r
->arm_insn
, 16, 19);
10860 /* Get shift_imm. */
10861 shift_imm
= bits (arm_insn_r
->arm_insn
, 7, 11);
10862 regcache_raw_read_unsigned (reg_cache
, reg_src1
, &u_regval
[0]);
10863 regcache_raw_read_signed (reg_cache
, reg_src1
, &s_word
);
10864 regcache_raw_read_unsigned (reg_cache
, reg_src2
, &u_regval
[1]);
10865 /* Offset_12 used as shift. */
10869 /* Offset_12 used as index. */
10870 offset_12
= u_regval
[0] << shift_imm
;
10874 offset_12
= (!shift_imm
)?0:u_regval
[0] >> shift_imm
;
10880 if (bit (u_regval
[0], 31))
10882 offset_12
= 0xFFFFFFFF;
10891 /* This is arithmetic shift. */
10892 offset_12
= s_word
>> shift_imm
;
10899 regcache_raw_read_unsigned (reg_cache
, ARM_PS_REGNUM
,
10901 /* Get C flag value and shift it by 31. */
10902 offset_12
= (((bit (u_regval
[1], 29)) << 31) \
10903 | (u_regval
[0]) >> 1);
10907 offset_12
= (u_regval
[0] >> shift_imm
) \
10909 (sizeof(uint32_t) - shift_imm
));
10914 gdb_assert_not_reached ("no decoding pattern found");
10918 regcache_raw_read_unsigned (reg_cache
, reg_src2
, &u_regval
[1]);
10920 if (bit (arm_insn_r
->arm_insn
, 23))
10922 tgt_mem_addr
= u_regval
[1] + offset_12
;
10926 tgt_mem_addr
= u_regval
[1] - offset_12
;
10929 switch (arm_insn_r
->opcode
)
10943 record_buf_mem
[0] = 4;
10958 record_buf_mem
[0] = 1;
10962 gdb_assert_not_reached ("no decoding pattern found");
10965 record_buf_mem
[1] = tgt_mem_addr
;
10966 arm_insn_r
->mem_rec_count
= 1;
10968 if (9 == arm_insn_r
->opcode
|| 11 == arm_insn_r
->opcode
10969 || 13 == arm_insn_r
->opcode
|| 15 == arm_insn_r
->opcode
10970 || 0 == arm_insn_r
->opcode
|| 2 == arm_insn_r
->opcode
10971 || 4 == arm_insn_r
->opcode
|| 6 == arm_insn_r
->opcode
10972 || 1 == arm_insn_r
->opcode
|| 3 == arm_insn_r
->opcode
10973 || 5 == arm_insn_r
->opcode
|| 7 == arm_insn_r
->opcode
10976 /* Rn is going to be changed in register scaled pre-indexed
10977 mode,and scaled post indexed mode. */
10978 record_buf
[0] = reg_src2
;
10979 arm_insn_r
->reg_rec_count
= 1;
10984 REG_ALLOC (arm_insn_r
->arm_regs
, arm_insn_r
->reg_rec_count
, record_buf
);
10985 MEM_ALLOC (arm_insn_r
->arm_mems
, arm_insn_r
->mem_rec_count
, record_buf_mem
);
10989 /* Handle ARM mode instructions with opcode 100. */
10992 arm_record_ld_st_multiple (insn_decode_record
*arm_insn_r
)
10994 struct regcache
*reg_cache
= arm_insn_r
->regcache
;
10995 uint32_t register_count
= 0, register_bits
;
10996 uint32_t reg_base
, addr_mode
;
10997 uint32_t record_buf
[24], record_buf_mem
[48];
11001 /* Fetch the list of registers. */
11002 register_bits
= bits (arm_insn_r
->arm_insn
, 0, 15);
11003 arm_insn_r
->reg_rec_count
= 0;
11005 /* Fetch the base register that contains the address we are loading data
11007 reg_base
= bits (arm_insn_r
->arm_insn
, 16, 19);
11009 /* Calculate wback. */
11010 wback
= (bit (arm_insn_r
->arm_insn
, 21) == 1);
11012 if (bit (arm_insn_r
->arm_insn
, INSN_S_L_BIT_NUM
))
11014 /* LDM/LDMIA/LDMFD, LDMDA/LDMFA, LDMDB and LDMIB. */
11016 /* Find out which registers are going to be loaded from memory. */
11017 while (register_bits
)
11019 if (register_bits
& 0x00000001)
11020 record_buf
[arm_insn_r
->reg_rec_count
++] = register_count
;
11021 register_bits
= register_bits
>> 1;
11026 /* If wback is true, also save the base register, which is going to be
11029 record_buf
[arm_insn_r
->reg_rec_count
++] = reg_base
;
11031 /* Save the CPSR register. */
11032 record_buf
[arm_insn_r
->reg_rec_count
++] = ARM_PS_REGNUM
;
11036 /* STM (STMIA, STMEA), STMDA (STMED), STMDB (STMFD) and STMIB (STMFA). */
11038 addr_mode
= bits (arm_insn_r
->arm_insn
, 23, 24);
11040 regcache_raw_read_unsigned (reg_cache
, reg_base
, &u_regval
);
11042 /* Find out how many registers are going to be stored to memory. */
11043 while (register_bits
)
11045 if (register_bits
& 0x00000001)
11047 register_bits
= register_bits
>> 1;
11052 /* STMDA (STMED): Decrement after. */
11054 record_buf_mem
[1] = (uint32_t) u_regval
11055 - register_count
* ARM_INT_REGISTER_SIZE
+ 4;
11057 /* STM (STMIA, STMEA): Increment after. */
11059 record_buf_mem
[1] = (uint32_t) u_regval
;
11061 /* STMDB (STMFD): Decrement before. */
11063 record_buf_mem
[1] = (uint32_t) u_regval
11064 - register_count
* ARM_INT_REGISTER_SIZE
;
11066 /* STMIB (STMFA): Increment before. */
11068 record_buf_mem
[1] = (uint32_t) u_regval
+ ARM_INT_REGISTER_SIZE
;
11071 gdb_assert_not_reached ("no decoding pattern found");
11075 record_buf_mem
[0] = register_count
* ARM_INT_REGISTER_SIZE
;
11076 arm_insn_r
->mem_rec_count
= 1;
11078 /* If wback is true, also save the base register, which is going to be
11081 record_buf
[arm_insn_r
->reg_rec_count
++] = reg_base
;
11084 REG_ALLOC (arm_insn_r
->arm_regs
, arm_insn_r
->reg_rec_count
, record_buf
);
11085 MEM_ALLOC (arm_insn_r
->arm_mems
, arm_insn_r
->mem_rec_count
, record_buf_mem
);
11089 /* Handling opcode 101 insns. */
11092 arm_record_b_bl (insn_decode_record
*arm_insn_r
)
11094 uint32_t record_buf
[8];
11096 /* Handle B, BL, BLX(1) insns. */
11097 /* B simply branches so we do nothing here. */
11098 /* Note: BLX(1) doesnt fall here but instead it falls into
11099 extension space. */
11100 if (bit (arm_insn_r
->arm_insn
, 24))
11102 record_buf
[0] = ARM_LR_REGNUM
;
11103 arm_insn_r
->reg_rec_count
= 1;
11106 REG_ALLOC (arm_insn_r
->arm_regs
, arm_insn_r
->reg_rec_count
, record_buf
);
11112 arm_record_unsupported_insn (insn_decode_record
*arm_insn_r
)
11114 printf_unfiltered (_("Process record does not support instruction "
11115 "0x%0x at address %s.\n"),arm_insn_r
->arm_insn
,
11116 paddress (arm_insn_r
->gdbarch
, arm_insn_r
->this_addr
));
11121 /* Record handler for vector data transfer instructions. */
11124 arm_record_vdata_transfer_insn (insn_decode_record
*arm_insn_r
)
11126 uint32_t bits_a
, bit_c
, bit_l
, reg_t
, reg_v
;
11127 uint32_t record_buf
[4];
11129 reg_t
= bits (arm_insn_r
->arm_insn
, 12, 15);
11130 reg_v
= bits (arm_insn_r
->arm_insn
, 21, 23);
11131 bits_a
= bits (arm_insn_r
->arm_insn
, 21, 23);
11132 bit_l
= bit (arm_insn_r
->arm_insn
, 20);
11133 bit_c
= bit (arm_insn_r
->arm_insn
, 8);
11135 /* Handle VMOV instruction. */
11136 if (bit_l
&& bit_c
)
11138 record_buf
[0] = reg_t
;
11139 arm_insn_r
->reg_rec_count
= 1;
11141 else if (bit_l
&& !bit_c
)
11143 /* Handle VMOV instruction. */
11144 if (bits_a
== 0x00)
11146 record_buf
[0] = reg_t
;
11147 arm_insn_r
->reg_rec_count
= 1;
11149 /* Handle VMRS instruction. */
11150 else if (bits_a
== 0x07)
11153 reg_t
= ARM_PS_REGNUM
;
11155 record_buf
[0] = reg_t
;
11156 arm_insn_r
->reg_rec_count
= 1;
11159 else if (!bit_l
&& !bit_c
)
11161 /* Handle VMOV instruction. */
11162 if (bits_a
== 0x00)
11164 record_buf
[0] = ARM_D0_REGNUM
+ reg_v
;
11166 arm_insn_r
->reg_rec_count
= 1;
11168 /* Handle VMSR instruction. */
11169 else if (bits_a
== 0x07)
11171 record_buf
[0] = ARM_FPSCR_REGNUM
;
11172 arm_insn_r
->reg_rec_count
= 1;
11175 else if (!bit_l
&& bit_c
)
11177 /* Handle VMOV instruction. */
11178 if (!(bits_a
& 0x04))
11180 record_buf
[0] = (reg_v
| (bit (arm_insn_r
->arm_insn
, 7) << 4))
11182 arm_insn_r
->reg_rec_count
= 1;
11184 /* Handle VDUP instruction. */
11187 if (bit (arm_insn_r
->arm_insn
, 21))
11189 reg_v
= reg_v
| (bit (arm_insn_r
->arm_insn
, 7) << 4);
11190 record_buf
[0] = reg_v
+ ARM_D0_REGNUM
;
11191 record_buf
[1] = reg_v
+ ARM_D0_REGNUM
+ 1;
11192 arm_insn_r
->reg_rec_count
= 2;
11196 reg_v
= reg_v
| (bit (arm_insn_r
->arm_insn
, 7) << 4);
11197 record_buf
[0] = reg_v
+ ARM_D0_REGNUM
;
11198 arm_insn_r
->reg_rec_count
= 1;
11203 REG_ALLOC (arm_insn_r
->arm_regs
, arm_insn_r
->reg_rec_count
, record_buf
);
11207 /* Record handler for extension register load/store instructions. */
11210 arm_record_exreg_ld_st_insn (insn_decode_record
*arm_insn_r
)
11212 uint32_t opcode
, single_reg
;
11213 uint8_t op_vldm_vstm
;
11214 uint32_t record_buf
[8], record_buf_mem
[128];
11215 ULONGEST u_regval
= 0;
11217 struct regcache
*reg_cache
= arm_insn_r
->regcache
;
11219 opcode
= bits (arm_insn_r
->arm_insn
, 20, 24);
11220 single_reg
= !bit (arm_insn_r
->arm_insn
, 8);
11221 op_vldm_vstm
= opcode
& 0x1b;
11223 /* Handle VMOV instructions. */
11224 if ((opcode
& 0x1e) == 0x04)
11226 if (bit (arm_insn_r
->arm_insn
, 20)) /* to_arm_registers bit 20? */
11228 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
11229 record_buf
[1] = bits (arm_insn_r
->arm_insn
, 16, 19);
11230 arm_insn_r
->reg_rec_count
= 2;
11234 uint8_t reg_m
= bits (arm_insn_r
->arm_insn
, 0, 3);
11235 uint8_t bit_m
= bit (arm_insn_r
->arm_insn
, 5);
11239 /* The first S register number m is REG_M:M (M is bit 5),
11240 the corresponding D register number is REG_M:M / 2, which
11242 record_buf
[arm_insn_r
->reg_rec_count
++] = ARM_D0_REGNUM
+ reg_m
;
11243 /* The second S register number is REG_M:M + 1, the
11244 corresponding D register number is (REG_M:M + 1) / 2.
11245 IOW, if bit M is 1, the first and second S registers
11246 are mapped to different D registers, otherwise, they are
11247 in the same D register. */
11250 record_buf
[arm_insn_r
->reg_rec_count
++]
11251 = ARM_D0_REGNUM
+ reg_m
+ 1;
11256 record_buf
[0] = ((bit_m
<< 4) + reg_m
+ ARM_D0_REGNUM
);
11257 arm_insn_r
->reg_rec_count
= 1;
11261 /* Handle VSTM and VPUSH instructions. */
11262 else if (op_vldm_vstm
== 0x08 || op_vldm_vstm
== 0x0a
11263 || op_vldm_vstm
== 0x12)
11265 uint32_t start_address
, reg_rn
, imm_off32
, imm_off8
, memory_count
;
11266 uint32_t memory_index
= 0;
11268 reg_rn
= bits (arm_insn_r
->arm_insn
, 16, 19);
11269 regcache_raw_read_unsigned (reg_cache
, reg_rn
, &u_regval
);
11270 imm_off8
= bits (arm_insn_r
->arm_insn
, 0, 7);
11271 imm_off32
= imm_off8
<< 2;
11272 memory_count
= imm_off8
;
11274 if (bit (arm_insn_r
->arm_insn
, 23))
11275 start_address
= u_regval
;
11277 start_address
= u_regval
- imm_off32
;
11279 if (bit (arm_insn_r
->arm_insn
, 21))
11281 record_buf
[0] = reg_rn
;
11282 arm_insn_r
->reg_rec_count
= 1;
11285 while (memory_count
> 0)
11289 record_buf_mem
[memory_index
] = 4;
11290 record_buf_mem
[memory_index
+ 1] = start_address
;
11291 start_address
= start_address
+ 4;
11292 memory_index
= memory_index
+ 2;
11296 record_buf_mem
[memory_index
] = 4;
11297 record_buf_mem
[memory_index
+ 1] = start_address
;
11298 record_buf_mem
[memory_index
+ 2] = 4;
11299 record_buf_mem
[memory_index
+ 3] = start_address
+ 4;
11300 start_address
= start_address
+ 8;
11301 memory_index
= memory_index
+ 4;
11305 arm_insn_r
->mem_rec_count
= (memory_index
>> 1);
11307 /* Handle VLDM instructions. */
11308 else if (op_vldm_vstm
== 0x09 || op_vldm_vstm
== 0x0b
11309 || op_vldm_vstm
== 0x13)
11311 uint32_t reg_count
, reg_vd
;
11312 uint32_t reg_index
= 0;
11313 uint32_t bit_d
= bit (arm_insn_r
->arm_insn
, 22);
11315 reg_vd
= bits (arm_insn_r
->arm_insn
, 12, 15);
11316 reg_count
= bits (arm_insn_r
->arm_insn
, 0, 7);
11318 /* REG_VD is the first D register number. If the instruction
11319 loads memory to S registers (SINGLE_REG is TRUE), the register
11320 number is (REG_VD << 1 | bit D), so the corresponding D
11321 register number is (REG_VD << 1 | bit D) / 2 = REG_VD. */
11323 reg_vd
= reg_vd
| (bit_d
<< 4);
11325 if (bit (arm_insn_r
->arm_insn
, 21) /* write back */)
11326 record_buf
[reg_index
++] = bits (arm_insn_r
->arm_insn
, 16, 19);
11328 /* If the instruction loads memory to D register, REG_COUNT should
11329 be divided by 2, according to the ARM Architecture Reference
11330 Manual. If the instruction loads memory to S register, divide by
11331 2 as well because two S registers are mapped to D register. */
11332 reg_count
= reg_count
/ 2;
11333 if (single_reg
&& bit_d
)
11335 /* Increase the register count if S register list starts from
11336 an odd number (bit d is one). */
11340 while (reg_count
> 0)
11342 record_buf
[reg_index
++] = ARM_D0_REGNUM
+ reg_vd
+ reg_count
- 1;
11345 arm_insn_r
->reg_rec_count
= reg_index
;
11347 /* VSTR Vector store register. */
11348 else if ((opcode
& 0x13) == 0x10)
11350 uint32_t start_address
, reg_rn
, imm_off32
, imm_off8
;
11351 uint32_t memory_index
= 0;
11353 reg_rn
= bits (arm_insn_r
->arm_insn
, 16, 19);
11354 regcache_raw_read_unsigned (reg_cache
, reg_rn
, &u_regval
);
11355 imm_off8
= bits (arm_insn_r
->arm_insn
, 0, 7);
11356 imm_off32
= imm_off8
<< 2;
11358 if (bit (arm_insn_r
->arm_insn
, 23))
11359 start_address
= u_regval
+ imm_off32
;
11361 start_address
= u_regval
- imm_off32
;
11365 record_buf_mem
[memory_index
] = 4;
11366 record_buf_mem
[memory_index
+ 1] = start_address
;
11367 arm_insn_r
->mem_rec_count
= 1;
11371 record_buf_mem
[memory_index
] = 4;
11372 record_buf_mem
[memory_index
+ 1] = start_address
;
11373 record_buf_mem
[memory_index
+ 2] = 4;
11374 record_buf_mem
[memory_index
+ 3] = start_address
+ 4;
11375 arm_insn_r
->mem_rec_count
= 2;
11378 /* VLDR Vector load register. */
11379 else if ((opcode
& 0x13) == 0x11)
11381 uint32_t reg_vd
= bits (arm_insn_r
->arm_insn
, 12, 15);
11385 reg_vd
= reg_vd
| (bit (arm_insn_r
->arm_insn
, 22) << 4);
11386 record_buf
[0] = ARM_D0_REGNUM
+ reg_vd
;
11390 reg_vd
= (reg_vd
<< 1) | bit (arm_insn_r
->arm_insn
, 22);
11391 /* Record register D rather than pseudo register S. */
11392 record_buf
[0] = ARM_D0_REGNUM
+ reg_vd
/ 2;
11394 arm_insn_r
->reg_rec_count
= 1;
11397 REG_ALLOC (arm_insn_r
->arm_regs
, arm_insn_r
->reg_rec_count
, record_buf
);
11398 MEM_ALLOC (arm_insn_r
->arm_mems
, arm_insn_r
->mem_rec_count
, record_buf_mem
);
11402 /* Record handler for arm/thumb mode VFP data processing instructions. */
11405 arm_record_vfp_data_proc_insn (insn_decode_record
*arm_insn_r
)
11407 uint32_t opc1
, opc2
, opc3
, dp_op_sz
, bit_d
, reg_vd
;
11408 uint32_t record_buf
[4];
11409 enum insn_types
{INSN_T0
, INSN_T1
, INSN_T2
, INSN_T3
, INSN_INV
};
11410 enum insn_types curr_insn_type
= INSN_INV
;
11412 reg_vd
= bits (arm_insn_r
->arm_insn
, 12, 15);
11413 opc1
= bits (arm_insn_r
->arm_insn
, 20, 23);
11414 opc2
= bits (arm_insn_r
->arm_insn
, 16, 19);
11415 opc3
= bits (arm_insn_r
->arm_insn
, 6, 7);
11416 dp_op_sz
= bit (arm_insn_r
->arm_insn
, 8);
11417 bit_d
= bit (arm_insn_r
->arm_insn
, 22);
11418 /* Mask off the "D" bit. */
11419 opc1
= opc1
& ~0x04;
11421 /* Handle VMLA, VMLS. */
11424 if (bit (arm_insn_r
->arm_insn
, 10))
11426 if (bit (arm_insn_r
->arm_insn
, 6))
11427 curr_insn_type
= INSN_T0
;
11429 curr_insn_type
= INSN_T1
;
11434 curr_insn_type
= INSN_T1
;
11436 curr_insn_type
= INSN_T2
;
11439 /* Handle VNMLA, VNMLS, VNMUL. */
11440 else if (opc1
== 0x01)
11443 curr_insn_type
= INSN_T1
;
11445 curr_insn_type
= INSN_T2
;
11448 else if (opc1
== 0x02 && !(opc3
& 0x01))
11450 if (bit (arm_insn_r
->arm_insn
, 10))
11452 if (bit (arm_insn_r
->arm_insn
, 6))
11453 curr_insn_type
= INSN_T0
;
11455 curr_insn_type
= INSN_T1
;
11460 curr_insn_type
= INSN_T1
;
11462 curr_insn_type
= INSN_T2
;
11465 /* Handle VADD, VSUB. */
11466 else if (opc1
== 0x03)
11468 if (!bit (arm_insn_r
->arm_insn
, 9))
11470 if (bit (arm_insn_r
->arm_insn
, 6))
11471 curr_insn_type
= INSN_T0
;
11473 curr_insn_type
= INSN_T1
;
11478 curr_insn_type
= INSN_T1
;
11480 curr_insn_type
= INSN_T2
;
11484 else if (opc1
== 0x08)
11487 curr_insn_type
= INSN_T1
;
11489 curr_insn_type
= INSN_T2
;
11491 /* Handle all other vfp data processing instructions. */
11492 else if (opc1
== 0x0b)
11495 if (!(opc3
& 0x01) || (opc2
== 0x00 && opc3
== 0x01))
11497 if (bit (arm_insn_r
->arm_insn
, 4))
11499 if (bit (arm_insn_r
->arm_insn
, 6))
11500 curr_insn_type
= INSN_T0
;
11502 curr_insn_type
= INSN_T1
;
11507 curr_insn_type
= INSN_T1
;
11509 curr_insn_type
= INSN_T2
;
11512 /* Handle VNEG and VABS. */
11513 else if ((opc2
== 0x01 && opc3
== 0x01)
11514 || (opc2
== 0x00 && opc3
== 0x03))
11516 if (!bit (arm_insn_r
->arm_insn
, 11))
11518 if (bit (arm_insn_r
->arm_insn
, 6))
11519 curr_insn_type
= INSN_T0
;
11521 curr_insn_type
= INSN_T1
;
11526 curr_insn_type
= INSN_T1
;
11528 curr_insn_type
= INSN_T2
;
11531 /* Handle VSQRT. */
11532 else if (opc2
== 0x01 && opc3
== 0x03)
11535 curr_insn_type
= INSN_T1
;
11537 curr_insn_type
= INSN_T2
;
11540 else if (opc2
== 0x07 && opc3
== 0x03)
11543 curr_insn_type
= INSN_T1
;
11545 curr_insn_type
= INSN_T2
;
11547 else if (opc3
& 0x01)
11550 if ((opc2
== 0x08) || (opc2
& 0x0e) == 0x0c)
11552 if (!bit (arm_insn_r
->arm_insn
, 18))
11553 curr_insn_type
= INSN_T2
;
11557 curr_insn_type
= INSN_T1
;
11559 curr_insn_type
= INSN_T2
;
11563 else if ((opc2
& 0x0e) == 0x0a || (opc2
& 0x0e) == 0x0e)
11566 curr_insn_type
= INSN_T1
;
11568 curr_insn_type
= INSN_T2
;
11570 /* Handle VCVTB, VCVTT. */
11571 else if ((opc2
& 0x0e) == 0x02)
11572 curr_insn_type
= INSN_T2
;
11573 /* Handle VCMP, VCMPE. */
11574 else if ((opc2
& 0x0e) == 0x04)
11575 curr_insn_type
= INSN_T3
;
11579 switch (curr_insn_type
)
11582 reg_vd
= reg_vd
| (bit_d
<< 4);
11583 record_buf
[0] = reg_vd
+ ARM_D0_REGNUM
;
11584 record_buf
[1] = reg_vd
+ ARM_D0_REGNUM
+ 1;
11585 arm_insn_r
->reg_rec_count
= 2;
11589 reg_vd
= reg_vd
| (bit_d
<< 4);
11590 record_buf
[0] = reg_vd
+ ARM_D0_REGNUM
;
11591 arm_insn_r
->reg_rec_count
= 1;
11595 reg_vd
= (reg_vd
<< 1) | bit_d
;
11596 record_buf
[0] = reg_vd
+ ARM_D0_REGNUM
;
11597 arm_insn_r
->reg_rec_count
= 1;
11601 record_buf
[0] = ARM_FPSCR_REGNUM
;
11602 arm_insn_r
->reg_rec_count
= 1;
11606 gdb_assert_not_reached ("no decoding pattern found");
11610 REG_ALLOC (arm_insn_r
->arm_regs
, arm_insn_r
->reg_rec_count
, record_buf
);
11614 /* Handling opcode 110 insns. */
11617 arm_record_asimd_vfp_coproc (insn_decode_record
*arm_insn_r
)
11619 uint32_t op1
, op1_ebit
, coproc
;
11621 coproc
= bits (arm_insn_r
->arm_insn
, 8, 11);
11622 op1
= bits (arm_insn_r
->arm_insn
, 20, 25);
11623 op1_ebit
= bit (arm_insn_r
->arm_insn
, 20);
11625 if ((coproc
& 0x0e) == 0x0a)
11627 /* Handle extension register ld/st instructions. */
11629 return arm_record_exreg_ld_st_insn (arm_insn_r
);
11631 /* 64-bit transfers between arm core and extension registers. */
11632 if ((op1
& 0x3e) == 0x04)
11633 return arm_record_exreg_ld_st_insn (arm_insn_r
);
11637 /* Handle coprocessor ld/st instructions. */
11642 return arm_record_unsupported_insn (arm_insn_r
);
11645 return arm_record_unsupported_insn (arm_insn_r
);
11648 /* Move to coprocessor from two arm core registers. */
11650 return arm_record_unsupported_insn (arm_insn_r
);
11652 /* Move to two arm core registers from coprocessor. */
11657 reg_t
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
11658 reg_t
[1] = bits (arm_insn_r
->arm_insn
, 16, 19);
11659 arm_insn_r
->reg_rec_count
= 2;
11661 REG_ALLOC (arm_insn_r
->arm_regs
, arm_insn_r
->reg_rec_count
, reg_t
);
11665 return arm_record_unsupported_insn (arm_insn_r
);
11668 /* Handling opcode 111 insns. */
11671 arm_record_coproc_data_proc (insn_decode_record
*arm_insn_r
)
11673 uint32_t op
, op1_ebit
, coproc
, bits_24_25
;
11674 struct gdbarch_tdep
*tdep
= gdbarch_tdep (arm_insn_r
->gdbarch
);
11675 struct regcache
*reg_cache
= arm_insn_r
->regcache
;
11677 arm_insn_r
->opcode
= bits (arm_insn_r
->arm_insn
, 24, 27);
11678 coproc
= bits (arm_insn_r
->arm_insn
, 8, 11);
11679 op1_ebit
= bit (arm_insn_r
->arm_insn
, 20);
11680 op
= bit (arm_insn_r
->arm_insn
, 4);
11681 bits_24_25
= bits (arm_insn_r
->arm_insn
, 24, 25);
11683 /* Handle arm SWI/SVC system call instructions. */
11684 if (bits_24_25
== 0x3)
11686 if (tdep
->arm_syscall_record
!= NULL
)
11688 ULONGEST svc_operand
, svc_number
;
11690 svc_operand
= (0x00ffffff & arm_insn_r
->arm_insn
);
11692 if (svc_operand
) /* OABI. */
11693 svc_number
= svc_operand
- 0x900000;
11695 regcache_raw_read_unsigned (reg_cache
, 7, &svc_number
);
11697 return tdep
->arm_syscall_record (reg_cache
, svc_number
);
11701 printf_unfiltered (_("no syscall record support\n"));
11705 else if (bits_24_25
== 0x02)
11709 if ((coproc
& 0x0e) == 0x0a)
11711 /* 8, 16, and 32-bit transfer */
11712 return arm_record_vdata_transfer_insn (arm_insn_r
);
11719 uint32_t record_buf
[1];
11721 record_buf
[0] = bits (arm_insn_r
->arm_insn
, 12, 15);
11722 if (record_buf
[0] == 15)
11723 record_buf
[0] = ARM_PS_REGNUM
;
11725 arm_insn_r
->reg_rec_count
= 1;
11726 REG_ALLOC (arm_insn_r
->arm_regs
, arm_insn_r
->reg_rec_count
,
11739 if ((coproc
& 0x0e) == 0x0a)
11741 /* VFP data-processing instructions. */
11742 return arm_record_vfp_data_proc_insn (arm_insn_r
);
11753 unsigned int op1
= bits (arm_insn_r
->arm_insn
, 20, 25);
11757 if ((coproc
& 0x0e) != 0x0a)
11763 else if (op1
== 4 || op1
== 5)
11765 if ((coproc
& 0x0e) == 0x0a)
11767 /* 64-bit transfers between ARM core and extension */
11776 else if (op1
== 0 || op1
== 1)
11783 if ((coproc
& 0x0e) == 0x0a)
11785 /* Extension register load/store */
11789 /* STC, STC2, LDC, LDC2 */
11798 /* Handling opcode 000 insns. */
11801 thumb_record_shift_add_sub (insn_decode_record
*thumb_insn_r
)
11803 uint32_t record_buf
[8];
11804 uint32_t reg_src1
= 0;
11806 reg_src1
= bits (thumb_insn_r
->arm_insn
, 0, 2);
11808 record_buf
[0] = ARM_PS_REGNUM
;
11809 record_buf
[1] = reg_src1
;
11810 thumb_insn_r
->reg_rec_count
= 2;
11812 REG_ALLOC (thumb_insn_r
->arm_regs
, thumb_insn_r
->reg_rec_count
, record_buf
);
11818 /* Handling opcode 001 insns. */
11821 thumb_record_add_sub_cmp_mov (insn_decode_record
*thumb_insn_r
)
11823 uint32_t record_buf
[8];
11824 uint32_t reg_src1
= 0;
11826 reg_src1
= bits (thumb_insn_r
->arm_insn
, 8, 10);
11828 record_buf
[0] = ARM_PS_REGNUM
;
11829 record_buf
[1] = reg_src1
;
11830 thumb_insn_r
->reg_rec_count
= 2;
11832 REG_ALLOC (thumb_insn_r
->arm_regs
, thumb_insn_r
->reg_rec_count
, record_buf
);
11837 /* Handling opcode 010 insns. */
11840 thumb_record_ld_st_reg_offset (insn_decode_record
*thumb_insn_r
)
11842 struct regcache
*reg_cache
= thumb_insn_r
->regcache
;
11843 uint32_t record_buf
[8], record_buf_mem
[8];
11845 uint32_t reg_src1
= 0, reg_src2
= 0;
11846 uint32_t opcode1
= 0, opcode2
= 0, opcode3
= 0;
11848 ULONGEST u_regval
[2] = {0};
11850 opcode1
= bits (thumb_insn_r
->arm_insn
, 10, 12);
11852 if (bit (thumb_insn_r
->arm_insn
, 12))
11854 /* Handle load/store register offset. */
11855 uint32_t opB
= bits (thumb_insn_r
->arm_insn
, 9, 11);
11857 if (in_inclusive_range (opB
, 4U, 7U))
11859 /* LDR(2), LDRB(2) , LDRH(2), LDRSB, LDRSH. */
11860 reg_src1
= bits (thumb_insn_r
->arm_insn
,0, 2);
11861 record_buf
[0] = reg_src1
;
11862 thumb_insn_r
->reg_rec_count
= 1;
11864 else if (in_inclusive_range (opB
, 0U, 2U))
11866 /* STR(2), STRB(2), STRH(2) . */
11867 reg_src1
= bits (thumb_insn_r
->arm_insn
, 3, 5);
11868 reg_src2
= bits (thumb_insn_r
->arm_insn
, 6, 8);
11869 regcache_raw_read_unsigned (reg_cache
, reg_src1
, &u_regval
[0]);
11870 regcache_raw_read_unsigned (reg_cache
, reg_src2
, &u_regval
[1]);
11872 record_buf_mem
[0] = 4; /* STR (2). */
11874 record_buf_mem
[0] = 1; /* STRB (2). */
11876 record_buf_mem
[0] = 2; /* STRH (2). */
11877 record_buf_mem
[1] = u_regval
[0] + u_regval
[1];
11878 thumb_insn_r
->mem_rec_count
= 1;
11881 else if (bit (thumb_insn_r
->arm_insn
, 11))
11883 /* Handle load from literal pool. */
11885 reg_src1
= bits (thumb_insn_r
->arm_insn
, 8, 10);
11886 record_buf
[0] = reg_src1
;
11887 thumb_insn_r
->reg_rec_count
= 1;
11891 /* Special data instructions and branch and exchange */
11892 opcode2
= bits (thumb_insn_r
->arm_insn
, 8, 9);
11893 opcode3
= bits (thumb_insn_r
->arm_insn
, 0, 2);
11894 if ((3 == opcode2
) && (!opcode3
))
11896 /* Branch with exchange. */
11897 record_buf
[0] = ARM_PS_REGNUM
;
11898 thumb_insn_r
->reg_rec_count
= 1;
11902 /* Format 8; special data processing insns. */
11903 record_buf
[0] = ARM_PS_REGNUM
;
11904 record_buf
[1] = (bit (thumb_insn_r
->arm_insn
, 7) << 3
11905 | bits (thumb_insn_r
->arm_insn
, 0, 2));
11906 thumb_insn_r
->reg_rec_count
= 2;
11911 /* Format 5; data processing insns. */
11912 reg_src1
= bits (thumb_insn_r
->arm_insn
, 0, 2);
11913 if (bit (thumb_insn_r
->arm_insn
, 7))
11915 reg_src1
= reg_src1
+ 8;
11917 record_buf
[0] = ARM_PS_REGNUM
;
11918 record_buf
[1] = reg_src1
;
11919 thumb_insn_r
->reg_rec_count
= 2;
11922 REG_ALLOC (thumb_insn_r
->arm_regs
, thumb_insn_r
->reg_rec_count
, record_buf
);
11923 MEM_ALLOC (thumb_insn_r
->arm_mems
, thumb_insn_r
->mem_rec_count
,
11929 /* Handling opcode 001 insns. */
11932 thumb_record_ld_st_imm_offset (insn_decode_record
*thumb_insn_r
)
11934 struct regcache
*reg_cache
= thumb_insn_r
->regcache
;
11935 uint32_t record_buf
[8], record_buf_mem
[8];
11937 uint32_t reg_src1
= 0;
11938 uint32_t opcode
= 0, immed_5
= 0;
11940 ULONGEST u_regval
= 0;
11942 opcode
= bits (thumb_insn_r
->arm_insn
, 11, 12);
11947 reg_src1
= bits (thumb_insn_r
->arm_insn
, 0, 2);
11948 record_buf
[0] = reg_src1
;
11949 thumb_insn_r
->reg_rec_count
= 1;
11954 reg_src1
= bits (thumb_insn_r
->arm_insn
, 3, 5);
11955 immed_5
= bits (thumb_insn_r
->arm_insn
, 6, 10);
11956 regcache_raw_read_unsigned (reg_cache
, reg_src1
, &u_regval
);
11957 record_buf_mem
[0] = 4;
11958 record_buf_mem
[1] = u_regval
+ (immed_5
* 4);
11959 thumb_insn_r
->mem_rec_count
= 1;
11962 REG_ALLOC (thumb_insn_r
->arm_regs
, thumb_insn_r
->reg_rec_count
, record_buf
);
11963 MEM_ALLOC (thumb_insn_r
->arm_mems
, thumb_insn_r
->mem_rec_count
,
11969 /* Handling opcode 100 insns. */
11972 thumb_record_ld_st_stack (insn_decode_record
*thumb_insn_r
)
11974 struct regcache
*reg_cache
= thumb_insn_r
->regcache
;
11975 uint32_t record_buf
[8], record_buf_mem
[8];
11977 uint32_t reg_src1
= 0;
11978 uint32_t opcode
= 0, immed_8
= 0, immed_5
= 0;
11980 ULONGEST u_regval
= 0;
11982 opcode
= bits (thumb_insn_r
->arm_insn
, 11, 12);
11987 reg_src1
= bits (thumb_insn_r
->arm_insn
, 8, 10);
11988 record_buf
[0] = reg_src1
;
11989 thumb_insn_r
->reg_rec_count
= 1;
11991 else if (1 == opcode
)
11994 reg_src1
= bits (thumb_insn_r
->arm_insn
, 0, 2);
11995 record_buf
[0] = reg_src1
;
11996 thumb_insn_r
->reg_rec_count
= 1;
11998 else if (2 == opcode
)
12001 immed_8
= bits (thumb_insn_r
->arm_insn
, 0, 7);
12002 regcache_raw_read_unsigned (reg_cache
, ARM_SP_REGNUM
, &u_regval
);
12003 record_buf_mem
[0] = 4;
12004 record_buf_mem
[1] = u_regval
+ (immed_8
* 4);
12005 thumb_insn_r
->mem_rec_count
= 1;
12007 else if (0 == opcode
)
12010 immed_5
= bits (thumb_insn_r
->arm_insn
, 6, 10);
12011 reg_src1
= bits (thumb_insn_r
->arm_insn
, 3, 5);
12012 regcache_raw_read_unsigned (reg_cache
, reg_src1
, &u_regval
);
12013 record_buf_mem
[0] = 2;
12014 record_buf_mem
[1] = u_regval
+ (immed_5
* 2);
12015 thumb_insn_r
->mem_rec_count
= 1;
12018 REG_ALLOC (thumb_insn_r
->arm_regs
, thumb_insn_r
->reg_rec_count
, record_buf
);
12019 MEM_ALLOC (thumb_insn_r
->arm_mems
, thumb_insn_r
->mem_rec_count
,
12025 /* Handling opcode 101 insns. */
12028 thumb_record_misc (insn_decode_record
*thumb_insn_r
)
12030 struct regcache
*reg_cache
= thumb_insn_r
->regcache
;
12032 uint32_t opcode
= 0;
12033 uint32_t register_bits
= 0, register_count
= 0;
12034 uint32_t index
= 0, start_address
= 0;
12035 uint32_t record_buf
[24], record_buf_mem
[48];
12038 ULONGEST u_regval
= 0;
12040 opcode
= bits (thumb_insn_r
->arm_insn
, 11, 12);
12042 if (opcode
== 0 || opcode
== 1)
12044 /* ADR and ADD (SP plus immediate) */
12046 reg_src1
= bits (thumb_insn_r
->arm_insn
, 8, 10);
12047 record_buf
[0] = reg_src1
;
12048 thumb_insn_r
->reg_rec_count
= 1;
12052 /* Miscellaneous 16-bit instructions */
12053 uint32_t opcode2
= bits (thumb_insn_r
->arm_insn
, 8, 11);
12058 /* SETEND and CPS */
12061 /* ADD/SUB (SP plus immediate) */
12062 reg_src1
= bits (thumb_insn_r
->arm_insn
, 8, 10);
12063 record_buf
[0] = ARM_SP_REGNUM
;
12064 thumb_insn_r
->reg_rec_count
= 1;
12066 case 1: /* fall through */
12067 case 3: /* fall through */
12068 case 9: /* fall through */
12073 /* SXTH, SXTB, UXTH, UXTB */
12074 record_buf
[0] = bits (thumb_insn_r
->arm_insn
, 0, 2);
12075 thumb_insn_r
->reg_rec_count
= 1;
12077 case 4: /* fall through */
12080 register_bits
= bits (thumb_insn_r
->arm_insn
, 0, 7);
12081 regcache_raw_read_unsigned (reg_cache
, ARM_SP_REGNUM
, &u_regval
);
12082 while (register_bits
)
12084 if (register_bits
& 0x00000001)
12086 register_bits
= register_bits
>> 1;
12088 start_address
= u_regval
- \
12089 (4 * (bit (thumb_insn_r
->arm_insn
, 8) + register_count
));
12090 thumb_insn_r
->mem_rec_count
= register_count
;
12091 while (register_count
)
12093 record_buf_mem
[(register_count
* 2) - 1] = start_address
;
12094 record_buf_mem
[(register_count
* 2) - 2] = 4;
12095 start_address
= start_address
+ 4;
12098 record_buf
[0] = ARM_SP_REGNUM
;
12099 thumb_insn_r
->reg_rec_count
= 1;
12102 /* REV, REV16, REVSH */
12103 record_buf
[0] = bits (thumb_insn_r
->arm_insn
, 0, 2);
12104 thumb_insn_r
->reg_rec_count
= 1;
12106 case 12: /* fall through */
12109 register_bits
= bits (thumb_insn_r
->arm_insn
, 0, 7);
12110 while (register_bits
)
12112 if (register_bits
& 0x00000001)
12113 record_buf
[index
++] = register_count
;
12114 register_bits
= register_bits
>> 1;
12117 record_buf
[index
++] = ARM_PS_REGNUM
;
12118 record_buf
[index
++] = ARM_SP_REGNUM
;
12119 thumb_insn_r
->reg_rec_count
= index
;
12123 /* Handle enhanced software breakpoint insn, BKPT. */
12124 /* CPSR is changed to be executed in ARM state, disabling normal
12125 interrupts, entering abort mode. */
12126 /* According to high vector configuration PC is set. */
12127 /* User hits breakpoint and type reverse, in that case, we need to go back with
12128 previous CPSR and Program Counter. */
12129 record_buf
[0] = ARM_PS_REGNUM
;
12130 record_buf
[1] = ARM_LR_REGNUM
;
12131 thumb_insn_r
->reg_rec_count
= 2;
12132 /* We need to save SPSR value, which is not yet done. */
12133 printf_unfiltered (_("Process record does not support instruction "
12134 "0x%0x at address %s.\n"),
12135 thumb_insn_r
->arm_insn
,
12136 paddress (thumb_insn_r
->gdbarch
,
12137 thumb_insn_r
->this_addr
));
12141 /* If-Then, and hints */
12148 REG_ALLOC (thumb_insn_r
->arm_regs
, thumb_insn_r
->reg_rec_count
, record_buf
);
12149 MEM_ALLOC (thumb_insn_r
->arm_mems
, thumb_insn_r
->mem_rec_count
,
12155 /* Handling opcode 110 insns. */
12158 thumb_record_ldm_stm_swi (insn_decode_record
*thumb_insn_r
)
12160 struct gdbarch_tdep
*tdep
= gdbarch_tdep (thumb_insn_r
->gdbarch
);
12161 struct regcache
*reg_cache
= thumb_insn_r
->regcache
;
12163 uint32_t ret
= 0; /* function return value: -1:record failure ; 0:success */
12164 uint32_t reg_src1
= 0;
12165 uint32_t opcode1
= 0, opcode2
= 0, register_bits
= 0, register_count
= 0;
12166 uint32_t index
= 0, start_address
= 0;
12167 uint32_t record_buf
[24], record_buf_mem
[48];
12169 ULONGEST u_regval
= 0;
12171 opcode1
= bits (thumb_insn_r
->arm_insn
, 8, 12);
12172 opcode2
= bits (thumb_insn_r
->arm_insn
, 11, 12);
12178 register_bits
= bits (thumb_insn_r
->arm_insn
, 0, 7);
12180 reg_src1
= bits (thumb_insn_r
->arm_insn
, 8, 10);
12181 while (register_bits
)
12183 if (register_bits
& 0x00000001)
12184 record_buf
[index
++] = register_count
;
12185 register_bits
= register_bits
>> 1;
12188 record_buf
[index
++] = reg_src1
;
12189 thumb_insn_r
->reg_rec_count
= index
;
12191 else if (0 == opcode2
)
12193 /* It handles both STMIA. */
12194 register_bits
= bits (thumb_insn_r
->arm_insn
, 0, 7);
12196 reg_src1
= bits (thumb_insn_r
->arm_insn
, 8, 10);
12197 regcache_raw_read_unsigned (reg_cache
, reg_src1
, &u_regval
);
12198 while (register_bits
)
12200 if (register_bits
& 0x00000001)
12202 register_bits
= register_bits
>> 1;
12204 start_address
= u_regval
;
12205 thumb_insn_r
->mem_rec_count
= register_count
;
12206 while (register_count
)
12208 record_buf_mem
[(register_count
* 2) - 1] = start_address
;
12209 record_buf_mem
[(register_count
* 2) - 2] = 4;
12210 start_address
= start_address
+ 4;
12214 else if (0x1F == opcode1
)
12216 /* Handle arm syscall insn. */
12217 if (tdep
->arm_syscall_record
!= NULL
)
12219 regcache_raw_read_unsigned (reg_cache
, 7, &u_regval
);
12220 ret
= tdep
->arm_syscall_record (reg_cache
, u_regval
);
12224 printf_unfiltered (_("no syscall record support\n"));
12229 /* B (1), conditional branch is automatically taken care in process_record,
12230 as PC is saved there. */
12232 REG_ALLOC (thumb_insn_r
->arm_regs
, thumb_insn_r
->reg_rec_count
, record_buf
);
12233 MEM_ALLOC (thumb_insn_r
->arm_mems
, thumb_insn_r
->mem_rec_count
,
12239 /* Handling opcode 111 insns. */
12242 thumb_record_branch (insn_decode_record
*thumb_insn_r
)
12244 uint32_t record_buf
[8];
12245 uint32_t bits_h
= 0;
12247 bits_h
= bits (thumb_insn_r
->arm_insn
, 11, 12);
12249 if (2 == bits_h
|| 3 == bits_h
)
12252 record_buf
[0] = ARM_LR_REGNUM
;
12253 thumb_insn_r
->reg_rec_count
= 1;
12255 else if (1 == bits_h
)
12258 record_buf
[0] = ARM_PS_REGNUM
;
12259 record_buf
[1] = ARM_LR_REGNUM
;
12260 thumb_insn_r
->reg_rec_count
= 2;
12263 /* B(2) is automatically taken care in process_record, as PC is
12266 REG_ALLOC (thumb_insn_r
->arm_regs
, thumb_insn_r
->reg_rec_count
, record_buf
);
12271 /* Handler for thumb2 load/store multiple instructions. */
12274 thumb2_record_ld_st_multiple (insn_decode_record
*thumb2_insn_r
)
12276 struct regcache
*reg_cache
= thumb2_insn_r
->regcache
;
12278 uint32_t reg_rn
, op
;
12279 uint32_t register_bits
= 0, register_count
= 0;
12280 uint32_t index
= 0, start_address
= 0;
12281 uint32_t record_buf
[24], record_buf_mem
[48];
12283 ULONGEST u_regval
= 0;
12285 reg_rn
= bits (thumb2_insn_r
->arm_insn
, 16, 19);
12286 op
= bits (thumb2_insn_r
->arm_insn
, 23, 24);
12288 if (0 == op
|| 3 == op
)
12290 if (bit (thumb2_insn_r
->arm_insn
, INSN_S_L_BIT_NUM
))
12292 /* Handle RFE instruction. */
12293 record_buf
[0] = ARM_PS_REGNUM
;
12294 thumb2_insn_r
->reg_rec_count
= 1;
12298 /* Handle SRS instruction after reading banked SP. */
12299 return arm_record_unsupported_insn (thumb2_insn_r
);
12302 else if (1 == op
|| 2 == op
)
12304 if (bit (thumb2_insn_r
->arm_insn
, INSN_S_L_BIT_NUM
))
12306 /* Handle LDM/LDMIA/LDMFD and LDMDB/LDMEA instructions. */
12307 register_bits
= bits (thumb2_insn_r
->arm_insn
, 0, 15);
12308 while (register_bits
)
12310 if (register_bits
& 0x00000001)
12311 record_buf
[index
++] = register_count
;
12314 register_bits
= register_bits
>> 1;
12316 record_buf
[index
++] = reg_rn
;
12317 record_buf
[index
++] = ARM_PS_REGNUM
;
12318 thumb2_insn_r
->reg_rec_count
= index
;
12322 /* Handle STM/STMIA/STMEA and STMDB/STMFD. */
12323 register_bits
= bits (thumb2_insn_r
->arm_insn
, 0, 15);
12324 regcache_raw_read_unsigned (reg_cache
, reg_rn
, &u_regval
);
12325 while (register_bits
)
12327 if (register_bits
& 0x00000001)
12330 register_bits
= register_bits
>> 1;
12335 /* Start address calculation for LDMDB/LDMEA. */
12336 start_address
= u_regval
;
12340 /* Start address calculation for LDMDB/LDMEA. */
12341 start_address
= u_regval
- register_count
* 4;
12344 thumb2_insn_r
->mem_rec_count
= register_count
;
12345 while (register_count
)
12347 record_buf_mem
[register_count
* 2 - 1] = start_address
;
12348 record_buf_mem
[register_count
* 2 - 2] = 4;
12349 start_address
= start_address
+ 4;
12352 record_buf
[0] = reg_rn
;
12353 record_buf
[1] = ARM_PS_REGNUM
;
12354 thumb2_insn_r
->reg_rec_count
= 2;
12358 MEM_ALLOC (thumb2_insn_r
->arm_mems
, thumb2_insn_r
->mem_rec_count
,
12360 REG_ALLOC (thumb2_insn_r
->arm_regs
, thumb2_insn_r
->reg_rec_count
,
12362 return ARM_RECORD_SUCCESS
;
12365 /* Handler for thumb2 load/store (dual/exclusive) and table branch
12369 thumb2_record_ld_st_dual_ex_tbb (insn_decode_record
*thumb2_insn_r
)
12371 struct regcache
*reg_cache
= thumb2_insn_r
->regcache
;
12373 uint32_t reg_rd
, reg_rn
, offset_imm
;
12374 uint32_t reg_dest1
, reg_dest2
;
12375 uint32_t address
, offset_addr
;
12376 uint32_t record_buf
[8], record_buf_mem
[8];
12377 uint32_t op1
, op2
, op3
;
12379 ULONGEST u_regval
[2];
12381 op1
= bits (thumb2_insn_r
->arm_insn
, 23, 24);
12382 op2
= bits (thumb2_insn_r
->arm_insn
, 20, 21);
12383 op3
= bits (thumb2_insn_r
->arm_insn
, 4, 7);
12385 if (bit (thumb2_insn_r
->arm_insn
, INSN_S_L_BIT_NUM
))
12387 if(!(1 == op1
&& 1 == op2
&& (0 == op3
|| 1 == op3
)))
12389 reg_dest1
= bits (thumb2_insn_r
->arm_insn
, 12, 15);
12390 record_buf
[0] = reg_dest1
;
12391 record_buf
[1] = ARM_PS_REGNUM
;
12392 thumb2_insn_r
->reg_rec_count
= 2;
12395 if (3 == op2
|| (op1
& 2) || (1 == op1
&& 1 == op2
&& 7 == op3
))
12397 reg_dest2
= bits (thumb2_insn_r
->arm_insn
, 8, 11);
12398 record_buf
[2] = reg_dest2
;
12399 thumb2_insn_r
->reg_rec_count
= 3;
12404 reg_rn
= bits (thumb2_insn_r
->arm_insn
, 16, 19);
12405 regcache_raw_read_unsigned (reg_cache
, reg_rn
, &u_regval
[0]);
12407 if (0 == op1
&& 0 == op2
)
12409 /* Handle STREX. */
12410 offset_imm
= bits (thumb2_insn_r
->arm_insn
, 0, 7);
12411 address
= u_regval
[0] + (offset_imm
* 4);
12412 record_buf_mem
[0] = 4;
12413 record_buf_mem
[1] = address
;
12414 thumb2_insn_r
->mem_rec_count
= 1;
12415 reg_rd
= bits (thumb2_insn_r
->arm_insn
, 0, 3);
12416 record_buf
[0] = reg_rd
;
12417 thumb2_insn_r
->reg_rec_count
= 1;
12419 else if (1 == op1
&& 0 == op2
)
12421 reg_rd
= bits (thumb2_insn_r
->arm_insn
, 0, 3);
12422 record_buf
[0] = reg_rd
;
12423 thumb2_insn_r
->reg_rec_count
= 1;
12424 address
= u_regval
[0];
12425 record_buf_mem
[1] = address
;
12429 /* Handle STREXB. */
12430 record_buf_mem
[0] = 1;
12431 thumb2_insn_r
->mem_rec_count
= 1;
12435 /* Handle STREXH. */
12436 record_buf_mem
[0] = 2 ;
12437 thumb2_insn_r
->mem_rec_count
= 1;
12441 /* Handle STREXD. */
12442 address
= u_regval
[0];
12443 record_buf_mem
[0] = 4;
12444 record_buf_mem
[2] = 4;
12445 record_buf_mem
[3] = address
+ 4;
12446 thumb2_insn_r
->mem_rec_count
= 2;
12451 offset_imm
= bits (thumb2_insn_r
->arm_insn
, 0, 7);
12453 if (bit (thumb2_insn_r
->arm_insn
, 24))
12455 if (bit (thumb2_insn_r
->arm_insn
, 23))
12456 offset_addr
= u_regval
[0] + (offset_imm
* 4);
12458 offset_addr
= u_regval
[0] - (offset_imm
* 4);
12460 address
= offset_addr
;
12463 address
= u_regval
[0];
12465 record_buf_mem
[0] = 4;
12466 record_buf_mem
[1] = address
;
12467 record_buf_mem
[2] = 4;
12468 record_buf_mem
[3] = address
+ 4;
12469 thumb2_insn_r
->mem_rec_count
= 2;
12470 record_buf
[0] = reg_rn
;
12471 thumb2_insn_r
->reg_rec_count
= 1;
12475 REG_ALLOC (thumb2_insn_r
->arm_regs
, thumb2_insn_r
->reg_rec_count
,
12477 MEM_ALLOC (thumb2_insn_r
->arm_mems
, thumb2_insn_r
->mem_rec_count
,
12479 return ARM_RECORD_SUCCESS
;
12482 /* Handler for thumb2 data processing (shift register and modified immediate)
12486 thumb2_record_data_proc_sreg_mimm (insn_decode_record
*thumb2_insn_r
)
12488 uint32_t reg_rd
, op
;
12489 uint32_t record_buf
[8];
12491 op
= bits (thumb2_insn_r
->arm_insn
, 21, 24);
12492 reg_rd
= bits (thumb2_insn_r
->arm_insn
, 8, 11);
12494 if ((0 == op
|| 4 == op
|| 8 == op
|| 13 == op
) && 15 == reg_rd
)
12496 record_buf
[0] = ARM_PS_REGNUM
;
12497 thumb2_insn_r
->reg_rec_count
= 1;
12501 record_buf
[0] = reg_rd
;
12502 record_buf
[1] = ARM_PS_REGNUM
;
12503 thumb2_insn_r
->reg_rec_count
= 2;
12506 REG_ALLOC (thumb2_insn_r
->arm_regs
, thumb2_insn_r
->reg_rec_count
,
12508 return ARM_RECORD_SUCCESS
;
12511 /* Generic handler for thumb2 instructions which effect destination and PS
12515 thumb2_record_ps_dest_generic (insn_decode_record
*thumb2_insn_r
)
12518 uint32_t record_buf
[8];
12520 reg_rd
= bits (thumb2_insn_r
->arm_insn
, 8, 11);
12522 record_buf
[0] = reg_rd
;
12523 record_buf
[1] = ARM_PS_REGNUM
;
12524 thumb2_insn_r
->reg_rec_count
= 2;
12526 REG_ALLOC (thumb2_insn_r
->arm_regs
, thumb2_insn_r
->reg_rec_count
,
12528 return ARM_RECORD_SUCCESS
;
12531 /* Handler for thumb2 branch and miscellaneous control instructions. */
12534 thumb2_record_branch_misc_cntrl (insn_decode_record
*thumb2_insn_r
)
12536 uint32_t op
, op1
, op2
;
12537 uint32_t record_buf
[8];
12539 op
= bits (thumb2_insn_r
->arm_insn
, 20, 26);
12540 op1
= bits (thumb2_insn_r
->arm_insn
, 12, 14);
12541 op2
= bits (thumb2_insn_r
->arm_insn
, 8, 11);
12543 /* Handle MSR insn. */
12544 if (!(op1
& 0x2) && 0x38 == op
)
12548 /* CPSR is going to be changed. */
12549 record_buf
[0] = ARM_PS_REGNUM
;
12550 thumb2_insn_r
->reg_rec_count
= 1;
12554 arm_record_unsupported_insn(thumb2_insn_r
);
12558 else if (4 == (op1
& 0x5) || 5 == (op1
& 0x5))
12561 record_buf
[0] = ARM_PS_REGNUM
;
12562 record_buf
[1] = ARM_LR_REGNUM
;
12563 thumb2_insn_r
->reg_rec_count
= 2;
12566 REG_ALLOC (thumb2_insn_r
->arm_regs
, thumb2_insn_r
->reg_rec_count
,
12568 return ARM_RECORD_SUCCESS
;
12571 /* Handler for thumb2 store single data item instructions. */
12574 thumb2_record_str_single_data (insn_decode_record
*thumb2_insn_r
)
12576 struct regcache
*reg_cache
= thumb2_insn_r
->regcache
;
12578 uint32_t reg_rn
, reg_rm
, offset_imm
, shift_imm
;
12579 uint32_t address
, offset_addr
;
12580 uint32_t record_buf
[8], record_buf_mem
[8];
12583 ULONGEST u_regval
[2];
12585 op1
= bits (thumb2_insn_r
->arm_insn
, 21, 23);
12586 op2
= bits (thumb2_insn_r
->arm_insn
, 6, 11);
12587 reg_rn
= bits (thumb2_insn_r
->arm_insn
, 16, 19);
12588 regcache_raw_read_unsigned (reg_cache
, reg_rn
, &u_regval
[0]);
12590 if (bit (thumb2_insn_r
->arm_insn
, 23))
12593 offset_imm
= bits (thumb2_insn_r
->arm_insn
, 0, 11);
12594 offset_addr
= u_regval
[0] + offset_imm
;
12595 address
= offset_addr
;
12600 if ((0 == op1
|| 1 == op1
|| 2 == op1
) && !(op2
& 0x20))
12602 /* Handle STRB (register). */
12603 reg_rm
= bits (thumb2_insn_r
->arm_insn
, 0, 3);
12604 regcache_raw_read_unsigned (reg_cache
, reg_rm
, &u_regval
[1]);
12605 shift_imm
= bits (thumb2_insn_r
->arm_insn
, 4, 5);
12606 offset_addr
= u_regval
[1] << shift_imm
;
12607 address
= u_regval
[0] + offset_addr
;
12611 offset_imm
= bits (thumb2_insn_r
->arm_insn
, 0, 7);
12612 if (bit (thumb2_insn_r
->arm_insn
, 10))
12614 if (bit (thumb2_insn_r
->arm_insn
, 9))
12615 offset_addr
= u_regval
[0] + offset_imm
;
12617 offset_addr
= u_regval
[0] - offset_imm
;
12619 address
= offset_addr
;
12622 address
= u_regval
[0];
12628 /* Store byte instructions. */
12631 record_buf_mem
[0] = 1;
12633 /* Store half word instructions. */
12636 record_buf_mem
[0] = 2;
12638 /* Store word instructions. */
12641 record_buf_mem
[0] = 4;
12645 gdb_assert_not_reached ("no decoding pattern found");
12649 record_buf_mem
[1] = address
;
12650 thumb2_insn_r
->mem_rec_count
= 1;
12651 record_buf
[0] = reg_rn
;
12652 thumb2_insn_r
->reg_rec_count
= 1;
12654 REG_ALLOC (thumb2_insn_r
->arm_regs
, thumb2_insn_r
->reg_rec_count
,
12656 MEM_ALLOC (thumb2_insn_r
->arm_mems
, thumb2_insn_r
->mem_rec_count
,
12658 return ARM_RECORD_SUCCESS
;
12661 /* Handler for thumb2 load memory hints instructions. */
12664 thumb2_record_ld_mem_hints (insn_decode_record
*thumb2_insn_r
)
12666 uint32_t record_buf
[8];
12667 uint32_t reg_rt
, reg_rn
;
12669 reg_rt
= bits (thumb2_insn_r
->arm_insn
, 12, 15);
12670 reg_rn
= bits (thumb2_insn_r
->arm_insn
, 16, 19);
12672 if (ARM_PC_REGNUM
!= reg_rt
)
12674 record_buf
[0] = reg_rt
;
12675 record_buf
[1] = reg_rn
;
12676 record_buf
[2] = ARM_PS_REGNUM
;
12677 thumb2_insn_r
->reg_rec_count
= 3;
12679 REG_ALLOC (thumb2_insn_r
->arm_regs
, thumb2_insn_r
->reg_rec_count
,
12681 return ARM_RECORD_SUCCESS
;
12684 return ARM_RECORD_FAILURE
;
12687 /* Handler for thumb2 load word instructions. */
12690 thumb2_record_ld_word (insn_decode_record
*thumb2_insn_r
)
12692 uint32_t record_buf
[8];
12694 record_buf
[0] = bits (thumb2_insn_r
->arm_insn
, 12, 15);
12695 record_buf
[1] = ARM_PS_REGNUM
;
12696 thumb2_insn_r
->reg_rec_count
= 2;
12698 REG_ALLOC (thumb2_insn_r
->arm_regs
, thumb2_insn_r
->reg_rec_count
,
12700 return ARM_RECORD_SUCCESS
;
12703 /* Handler for thumb2 long multiply, long multiply accumulate, and
12704 divide instructions. */
12707 thumb2_record_lmul_lmla_div (insn_decode_record
*thumb2_insn_r
)
12709 uint32_t opcode1
= 0, opcode2
= 0;
12710 uint32_t record_buf
[8];
12712 opcode1
= bits (thumb2_insn_r
->arm_insn
, 20, 22);
12713 opcode2
= bits (thumb2_insn_r
->arm_insn
, 4, 7);
12715 if (0 == opcode1
|| 2 == opcode1
|| (opcode1
>= 4 && opcode1
<= 6))
12717 /* Handle SMULL, UMULL, SMULAL. */
12718 /* Handle SMLAL(S), SMULL(S), UMLAL(S), UMULL(S). */
12719 record_buf
[0] = bits (thumb2_insn_r
->arm_insn
, 16, 19);
12720 record_buf
[1] = bits (thumb2_insn_r
->arm_insn
, 12, 15);
12721 record_buf
[2] = ARM_PS_REGNUM
;
12722 thumb2_insn_r
->reg_rec_count
= 3;
12724 else if (1 == opcode1
|| 3 == opcode2
)
12726 /* Handle SDIV and UDIV. */
12727 record_buf
[0] = bits (thumb2_insn_r
->arm_insn
, 16, 19);
12728 record_buf
[1] = bits (thumb2_insn_r
->arm_insn
, 12, 15);
12729 record_buf
[2] = ARM_PS_REGNUM
;
12730 thumb2_insn_r
->reg_rec_count
= 3;
12733 return ARM_RECORD_FAILURE
;
12735 REG_ALLOC (thumb2_insn_r
->arm_regs
, thumb2_insn_r
->reg_rec_count
,
12737 return ARM_RECORD_SUCCESS
;
12740 /* Record handler for thumb32 coprocessor instructions. */
12743 thumb2_record_coproc_insn (insn_decode_record
*thumb2_insn_r
)
12745 if (bit (thumb2_insn_r
->arm_insn
, 25))
12746 return arm_record_coproc_data_proc (thumb2_insn_r
);
12748 return arm_record_asimd_vfp_coproc (thumb2_insn_r
);
12751 /* Record handler for advance SIMD structure load/store instructions. */
12754 thumb2_record_asimd_struct_ld_st (insn_decode_record
*thumb2_insn_r
)
12756 struct regcache
*reg_cache
= thumb2_insn_r
->regcache
;
12757 uint32_t l_bit
, a_bit
, b_bits
;
12758 uint32_t record_buf
[128], record_buf_mem
[128];
12759 uint32_t reg_rn
, reg_vd
, address
, f_elem
;
12760 uint32_t index_r
= 0, index_e
= 0, bf_regs
= 0, index_m
= 0, loop_t
= 0;
12763 l_bit
= bit (thumb2_insn_r
->arm_insn
, 21);
12764 a_bit
= bit (thumb2_insn_r
->arm_insn
, 23);
12765 b_bits
= bits (thumb2_insn_r
->arm_insn
, 8, 11);
12766 reg_rn
= bits (thumb2_insn_r
->arm_insn
, 16, 19);
12767 reg_vd
= bits (thumb2_insn_r
->arm_insn
, 12, 15);
12768 reg_vd
= (bit (thumb2_insn_r
->arm_insn
, 22) << 4) | reg_vd
;
12769 f_ebytes
= (1 << bits (thumb2_insn_r
->arm_insn
, 6, 7));
12770 f_elem
= 8 / f_ebytes
;
12774 ULONGEST u_regval
= 0;
12775 regcache_raw_read_unsigned (reg_cache
, reg_rn
, &u_regval
);
12776 address
= u_regval
;
12781 if (b_bits
== 0x02 || b_bits
== 0x0a || (b_bits
& 0x0e) == 0x06)
12783 if (b_bits
== 0x07)
12785 else if (b_bits
== 0x0a)
12787 else if (b_bits
== 0x06)
12789 else if (b_bits
== 0x02)
12794 for (index_r
= 0; index_r
< bf_regs
; index_r
++)
12796 for (index_e
= 0; index_e
< f_elem
; index_e
++)
12798 record_buf_mem
[index_m
++] = f_ebytes
;
12799 record_buf_mem
[index_m
++] = address
;
12800 address
= address
+ f_ebytes
;
12801 thumb2_insn_r
->mem_rec_count
+= 1;
12806 else if (b_bits
== 0x03 || (b_bits
& 0x0e) == 0x08)
12808 if (b_bits
== 0x09 || b_bits
== 0x08)
12810 else if (b_bits
== 0x03)
12815 for (index_r
= 0; index_r
< bf_regs
; index_r
++)
12816 for (index_e
= 0; index_e
< f_elem
; index_e
++)
12818 for (loop_t
= 0; loop_t
< 2; loop_t
++)
12820 record_buf_mem
[index_m
++] = f_ebytes
;
12821 record_buf_mem
[index_m
++] = address
+ (loop_t
* f_ebytes
);
12822 thumb2_insn_r
->mem_rec_count
+= 1;
12824 address
= address
+ (2 * f_ebytes
);
12828 else if ((b_bits
& 0x0e) == 0x04)
12830 for (index_e
= 0; index_e
< f_elem
; index_e
++)
12832 for (loop_t
= 0; loop_t
< 3; loop_t
++)
12834 record_buf_mem
[index_m
++] = f_ebytes
;
12835 record_buf_mem
[index_m
++] = address
+ (loop_t
* f_ebytes
);
12836 thumb2_insn_r
->mem_rec_count
+= 1;
12838 address
= address
+ (3 * f_ebytes
);
12842 else if (!(b_bits
& 0x0e))
12844 for (index_e
= 0; index_e
< f_elem
; index_e
++)
12846 for (loop_t
= 0; loop_t
< 4; loop_t
++)
12848 record_buf_mem
[index_m
++] = f_ebytes
;
12849 record_buf_mem
[index_m
++] = address
+ (loop_t
* f_ebytes
);
12850 thumb2_insn_r
->mem_rec_count
+= 1;
12852 address
= address
+ (4 * f_ebytes
);
12858 uint8_t bft_size
= bits (thumb2_insn_r
->arm_insn
, 10, 11);
12860 if (bft_size
== 0x00)
12862 else if (bft_size
== 0x01)
12864 else if (bft_size
== 0x02)
12870 if (!(b_bits
& 0x0b) || b_bits
== 0x08)
12871 thumb2_insn_r
->mem_rec_count
= 1;
12873 else if ((b_bits
& 0x0b) == 0x01 || b_bits
== 0x09)
12874 thumb2_insn_r
->mem_rec_count
= 2;
12876 else if ((b_bits
& 0x0b) == 0x02 || b_bits
== 0x0a)
12877 thumb2_insn_r
->mem_rec_count
= 3;
12879 else if ((b_bits
& 0x0b) == 0x03 || b_bits
== 0x0b)
12880 thumb2_insn_r
->mem_rec_count
= 4;
12882 for (index_m
= 0; index_m
< thumb2_insn_r
->mem_rec_count
; index_m
++)
12884 record_buf_mem
[index_m
] = f_ebytes
;
12885 record_buf_mem
[index_m
] = address
+ (index_m
* f_ebytes
);
12894 if (b_bits
== 0x02 || b_bits
== 0x0a || (b_bits
& 0x0e) == 0x06)
12895 thumb2_insn_r
->reg_rec_count
= 1;
12897 else if (b_bits
== 0x03 || (b_bits
& 0x0e) == 0x08)
12898 thumb2_insn_r
->reg_rec_count
= 2;
12900 else if ((b_bits
& 0x0e) == 0x04)
12901 thumb2_insn_r
->reg_rec_count
= 3;
12903 else if (!(b_bits
& 0x0e))
12904 thumb2_insn_r
->reg_rec_count
= 4;
12909 if (!(b_bits
& 0x0b) || b_bits
== 0x08 || b_bits
== 0x0c)
12910 thumb2_insn_r
->reg_rec_count
= 1;
12912 else if ((b_bits
& 0x0b) == 0x01 || b_bits
== 0x09 || b_bits
== 0x0d)
12913 thumb2_insn_r
->reg_rec_count
= 2;
12915 else if ((b_bits
& 0x0b) == 0x02 || b_bits
== 0x0a || b_bits
== 0x0e)
12916 thumb2_insn_r
->reg_rec_count
= 3;
12918 else if ((b_bits
& 0x0b) == 0x03 || b_bits
== 0x0b || b_bits
== 0x0f)
12919 thumb2_insn_r
->reg_rec_count
= 4;
12921 for (index_r
= 0; index_r
< thumb2_insn_r
->reg_rec_count
; index_r
++)
12922 record_buf
[index_r
] = reg_vd
+ ARM_D0_REGNUM
+ index_r
;
12926 if (bits (thumb2_insn_r
->arm_insn
, 0, 3) != 15)
12928 record_buf
[index_r
] = reg_rn
;
12929 thumb2_insn_r
->reg_rec_count
+= 1;
12932 REG_ALLOC (thumb2_insn_r
->arm_regs
, thumb2_insn_r
->reg_rec_count
,
12934 MEM_ALLOC (thumb2_insn_r
->arm_mems
, thumb2_insn_r
->mem_rec_count
,
12939 /* Decodes thumb2 instruction type and invokes its record handler. */
12941 static unsigned int
12942 thumb2_record_decode_insn_handler (insn_decode_record
*thumb2_insn_r
)
12944 uint32_t op
, op1
, op2
;
12946 op
= bit (thumb2_insn_r
->arm_insn
, 15);
12947 op1
= bits (thumb2_insn_r
->arm_insn
, 27, 28);
12948 op2
= bits (thumb2_insn_r
->arm_insn
, 20, 26);
12952 if (!(op2
& 0x64 ))
12954 /* Load/store multiple instruction. */
12955 return thumb2_record_ld_st_multiple (thumb2_insn_r
);
12957 else if ((op2
& 0x64) == 0x4)
12959 /* Load/store (dual/exclusive) and table branch instruction. */
12960 return thumb2_record_ld_st_dual_ex_tbb (thumb2_insn_r
);
12962 else if ((op2
& 0x60) == 0x20)
12964 /* Data-processing (shifted register). */
12965 return thumb2_record_data_proc_sreg_mimm (thumb2_insn_r
);
12967 else if (op2
& 0x40)
12969 /* Co-processor instructions. */
12970 return thumb2_record_coproc_insn (thumb2_insn_r
);
12973 else if (op1
== 0x02)
12977 /* Branches and miscellaneous control instructions. */
12978 return thumb2_record_branch_misc_cntrl (thumb2_insn_r
);
12980 else if (op2
& 0x20)
12982 /* Data-processing (plain binary immediate) instruction. */
12983 return thumb2_record_ps_dest_generic (thumb2_insn_r
);
12987 /* Data-processing (modified immediate). */
12988 return thumb2_record_data_proc_sreg_mimm (thumb2_insn_r
);
12991 else if (op1
== 0x03)
12993 if (!(op2
& 0x71 ))
12995 /* Store single data item. */
12996 return thumb2_record_str_single_data (thumb2_insn_r
);
12998 else if (!((op2
& 0x71) ^ 0x10))
13000 /* Advanced SIMD or structure load/store instructions. */
13001 return thumb2_record_asimd_struct_ld_st (thumb2_insn_r
);
13003 else if (!((op2
& 0x67) ^ 0x01))
13005 /* Load byte, memory hints instruction. */
13006 return thumb2_record_ld_mem_hints (thumb2_insn_r
);
13008 else if (!((op2
& 0x67) ^ 0x03))
13010 /* Load halfword, memory hints instruction. */
13011 return thumb2_record_ld_mem_hints (thumb2_insn_r
);
13013 else if (!((op2
& 0x67) ^ 0x05))
13015 /* Load word instruction. */
13016 return thumb2_record_ld_word (thumb2_insn_r
);
13018 else if (!((op2
& 0x70) ^ 0x20))
13020 /* Data-processing (register) instruction. */
13021 return thumb2_record_ps_dest_generic (thumb2_insn_r
);
13023 else if (!((op2
& 0x78) ^ 0x30))
13025 /* Multiply, multiply accumulate, abs diff instruction. */
13026 return thumb2_record_ps_dest_generic (thumb2_insn_r
);
13028 else if (!((op2
& 0x78) ^ 0x38))
13030 /* Long multiply, long multiply accumulate, and divide. */
13031 return thumb2_record_lmul_lmla_div (thumb2_insn_r
);
13033 else if (op2
& 0x40)
13035 /* Co-processor instructions. */
13036 return thumb2_record_coproc_insn (thumb2_insn_r
);
13044 /* Abstract memory reader. */
13046 class abstract_memory_reader
13049 /* Read LEN bytes of target memory at address MEMADDR, placing the
13050 results in GDB's memory at BUF. Return true on success. */
13052 virtual bool read (CORE_ADDR memaddr
, gdb_byte
*buf
, const size_t len
) = 0;
13055 /* Instruction reader from real target. */
13057 class instruction_reader
: public abstract_memory_reader
13060 bool read (CORE_ADDR memaddr
, gdb_byte
*buf
, const size_t len
) override
13062 if (target_read_memory (memaddr
, buf
, len
))
13071 /* Extracts arm/thumb/thumb2 insn depending on the size, and returns 0 on success
13072 and positive val on failure. */
13075 extract_arm_insn (abstract_memory_reader
& reader
,
13076 insn_decode_record
*insn_record
, uint32_t insn_size
)
13078 gdb_byte buf
[insn_size
];
13080 memset (&buf
[0], 0, insn_size
);
13082 if (!reader
.read (insn_record
->this_addr
, buf
, insn_size
))
13084 insn_record
->arm_insn
= (uint32_t) extract_unsigned_integer (&buf
[0],
13086 gdbarch_byte_order_for_code (insn_record
->gdbarch
));
13090 typedef int (*sti_arm_hdl_fp_t
) (insn_decode_record
*);
13092 /* Decode arm/thumb insn depending on condition cods and opcodes; and
13096 decode_insn (abstract_memory_reader
&reader
, insn_decode_record
*arm_record
,
13097 record_type_t record_type
, uint32_t insn_size
)
13100 /* (Starting from numerical 0); bits 25, 26, 27 decodes type of arm
13102 static const sti_arm_hdl_fp_t arm_handle_insn
[8] =
13104 arm_record_data_proc_misc_ld_str
, /* 000. */
13105 arm_record_data_proc_imm
, /* 001. */
13106 arm_record_ld_st_imm_offset
, /* 010. */
13107 arm_record_ld_st_reg_offset
, /* 011. */
13108 arm_record_ld_st_multiple
, /* 100. */
13109 arm_record_b_bl
, /* 101. */
13110 arm_record_asimd_vfp_coproc
, /* 110. */
13111 arm_record_coproc_data_proc
/* 111. */
13114 /* (Starting from numerical 0); bits 13,14,15 decodes type of thumb
13116 static const sti_arm_hdl_fp_t thumb_handle_insn
[8] =
13118 thumb_record_shift_add_sub
, /* 000. */
13119 thumb_record_add_sub_cmp_mov
, /* 001. */
13120 thumb_record_ld_st_reg_offset
, /* 010. */
13121 thumb_record_ld_st_imm_offset
, /* 011. */
13122 thumb_record_ld_st_stack
, /* 100. */
13123 thumb_record_misc
, /* 101. */
13124 thumb_record_ldm_stm_swi
, /* 110. */
13125 thumb_record_branch
/* 111. */
13128 uint32_t ret
= 0; /* return value: negative:failure 0:success. */
13129 uint32_t insn_id
= 0;
13131 if (extract_arm_insn (reader
, arm_record
, insn_size
))
13135 printf_unfiltered (_("Process record: error reading memory at "
13136 "addr %s len = %d.\n"),
13137 paddress (arm_record
->gdbarch
,
13138 arm_record
->this_addr
), insn_size
);
13142 else if (ARM_RECORD
== record_type
)
13144 arm_record
->cond
= bits (arm_record
->arm_insn
, 28, 31);
13145 insn_id
= bits (arm_record
->arm_insn
, 25, 27);
13147 if (arm_record
->cond
== 0xf)
13148 ret
= arm_record_extension_space (arm_record
);
13151 /* If this insn has fallen into extension space
13152 then we need not decode it anymore. */
13153 ret
= arm_handle_insn
[insn_id
] (arm_record
);
13155 if (ret
!= ARM_RECORD_SUCCESS
)
13157 arm_record_unsupported_insn (arm_record
);
13161 else if (THUMB_RECORD
== record_type
)
13163 /* As thumb does not have condition codes, we set negative. */
13164 arm_record
->cond
= -1;
13165 insn_id
= bits (arm_record
->arm_insn
, 13, 15);
13166 ret
= thumb_handle_insn
[insn_id
] (arm_record
);
13167 if (ret
!= ARM_RECORD_SUCCESS
)
13169 arm_record_unsupported_insn (arm_record
);
13173 else if (THUMB2_RECORD
== record_type
)
13175 /* As thumb does not have condition codes, we set negative. */
13176 arm_record
->cond
= -1;
13178 /* Swap first half of 32bit thumb instruction with second half. */
13179 arm_record
->arm_insn
13180 = (arm_record
->arm_insn
>> 16) | (arm_record
->arm_insn
<< 16);
13182 ret
= thumb2_record_decode_insn_handler (arm_record
);
13184 if (ret
!= ARM_RECORD_SUCCESS
)
13186 arm_record_unsupported_insn (arm_record
);
13192 /* Throw assertion. */
13193 gdb_assert_not_reached ("not a valid instruction, could not decode");
13200 namespace selftests
{
13202 /* Provide both 16-bit and 32-bit thumb instructions. */
13204 class instruction_reader_thumb
: public abstract_memory_reader
13207 template<size_t SIZE
>
13208 instruction_reader_thumb (enum bfd_endian endian
,
13209 const uint16_t (&insns
)[SIZE
])
13210 : m_endian (endian
), m_insns (insns
), m_insns_size (SIZE
)
13213 bool read (CORE_ADDR memaddr
, gdb_byte
*buf
, const size_t len
) override
13215 SELF_CHECK (len
== 4 || len
== 2);
13216 SELF_CHECK (memaddr
% 2 == 0);
13217 SELF_CHECK ((memaddr
/ 2) < m_insns_size
);
13219 store_unsigned_integer (buf
, 2, m_endian
, m_insns
[memaddr
/ 2]);
13222 store_unsigned_integer (&buf
[2], 2, m_endian
,
13223 m_insns
[memaddr
/ 2 + 1]);
13229 enum bfd_endian m_endian
;
13230 const uint16_t *m_insns
;
13231 size_t m_insns_size
;
13235 arm_record_test (void)
13237 struct gdbarch_info info
;
13238 gdbarch_info_init (&info
);
13239 info
.bfd_arch_info
= bfd_scan_arch ("arm");
13241 struct gdbarch
*gdbarch
= gdbarch_find_by_info (info
);
13243 SELF_CHECK (gdbarch
!= NULL
);
13245 /* 16-bit Thumb instructions. */
13247 insn_decode_record arm_record
;
13249 memset (&arm_record
, 0, sizeof (insn_decode_record
));
13250 arm_record
.gdbarch
= gdbarch
;
13252 static const uint16_t insns
[] = {
13253 /* db b2 uxtb r3, r3 */
13255 /* cd 58 ldr r5, [r1, r3] */
13259 enum bfd_endian endian
= gdbarch_byte_order_for_code (arm_record
.gdbarch
);
13260 instruction_reader_thumb
reader (endian
, insns
);
13261 int ret
= decode_insn (reader
, &arm_record
, THUMB_RECORD
,
13262 THUMB_INSN_SIZE_BYTES
);
13264 SELF_CHECK (ret
== 0);
13265 SELF_CHECK (arm_record
.mem_rec_count
== 0);
13266 SELF_CHECK (arm_record
.reg_rec_count
== 1);
13267 SELF_CHECK (arm_record
.arm_regs
[0] == 3);
13269 arm_record
.this_addr
+= 2;
13270 ret
= decode_insn (reader
, &arm_record
, THUMB_RECORD
,
13271 THUMB_INSN_SIZE_BYTES
);
13273 SELF_CHECK (ret
== 0);
13274 SELF_CHECK (arm_record
.mem_rec_count
== 0);
13275 SELF_CHECK (arm_record
.reg_rec_count
== 1);
13276 SELF_CHECK (arm_record
.arm_regs
[0] == 5);
13279 /* 32-bit Thumb-2 instructions. */
13281 insn_decode_record arm_record
;
13283 memset (&arm_record
, 0, sizeof (insn_decode_record
));
13284 arm_record
.gdbarch
= gdbarch
;
13286 static const uint16_t insns
[] = {
13287 /* 1d ee 70 7f mrc 15, 0, r7, cr13, cr0, {3} */
13291 enum bfd_endian endian
= gdbarch_byte_order_for_code (arm_record
.gdbarch
);
13292 instruction_reader_thumb
reader (endian
, insns
);
13293 int ret
= decode_insn (reader
, &arm_record
, THUMB2_RECORD
,
13294 THUMB2_INSN_SIZE_BYTES
);
13296 SELF_CHECK (ret
== 0);
13297 SELF_CHECK (arm_record
.mem_rec_count
== 0);
13298 SELF_CHECK (arm_record
.reg_rec_count
== 1);
13299 SELF_CHECK (arm_record
.arm_regs
[0] == 7);
13303 /* Instruction reader from manually cooked instruction sequences. */
13305 class test_arm_instruction_reader
: public arm_instruction_reader
13308 explicit test_arm_instruction_reader (gdb::array_view
<const uint32_t> insns
)
13312 uint32_t read (CORE_ADDR memaddr
, enum bfd_endian byte_order
) const override
13314 SELF_CHECK (memaddr
% 4 == 0);
13315 SELF_CHECK (memaddr
/ 4 < m_insns
.size ());
13317 return m_insns
[memaddr
/ 4];
13321 const gdb::array_view
<const uint32_t> m_insns
;
13325 arm_analyze_prologue_test ()
13327 for (bfd_endian endianness
: {BFD_ENDIAN_LITTLE
, BFD_ENDIAN_BIG
})
13329 struct gdbarch_info info
;
13330 gdbarch_info_init (&info
);
13331 info
.byte_order
= endianness
;
13332 info
.byte_order_for_code
= endianness
;
13333 info
.bfd_arch_info
= bfd_scan_arch ("arm");
13335 struct gdbarch
*gdbarch
= gdbarch_find_by_info (info
);
13337 SELF_CHECK (gdbarch
!= NULL
);
13339 /* The "sub" instruction contains an immediate value rotate count of 0,
13340 which resulted in a 32-bit shift of a 32-bit value, caught by
13342 const uint32_t insns
[] = {
13343 0xe92d4ff0, /* push {r4, r5, r6, r7, r8, r9, sl, fp, lr} */
13344 0xe1a05000, /* mov r5, r0 */
13345 0xe5903020, /* ldr r3, [r0, #32] */
13346 0xe24dd044, /* sub sp, sp, #68 ; 0x44 */
13349 test_arm_instruction_reader
mem_reader (insns
);
13350 arm_prologue_cache cache
;
13351 cache
.saved_regs
= trad_frame_alloc_saved_regs (gdbarch
);
13353 arm_analyze_prologue (gdbarch
, 0, sizeof (insns
) - 1, &cache
, mem_reader
);
13357 } // namespace selftests
13358 #endif /* GDB_SELF_TEST */
13360 /* Cleans up local record registers and memory allocations. */
13363 deallocate_reg_mem (insn_decode_record
*record
)
13365 xfree (record
->arm_regs
);
13366 xfree (record
->arm_mems
);
13370 /* Parse the current instruction and record the values of the registers and
13371 memory that will be changed in current instruction to record_arch_list".
13372 Return -1 if something is wrong. */
13375 arm_process_record (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
13376 CORE_ADDR insn_addr
)
13379 uint32_t no_of_rec
= 0;
13380 uint32_t ret
= 0; /* return value: -1:record failure ; 0:success */
13381 ULONGEST t_bit
= 0, insn_id
= 0;
13383 ULONGEST u_regval
= 0;
13385 insn_decode_record arm_record
;
13387 memset (&arm_record
, 0, sizeof (insn_decode_record
));
13388 arm_record
.regcache
= regcache
;
13389 arm_record
.this_addr
= insn_addr
;
13390 arm_record
.gdbarch
= gdbarch
;
13393 if (record_debug
> 1)
13395 fprintf_unfiltered (gdb_stdlog
, "Process record: arm_process_record "
13397 paddress (gdbarch
, arm_record
.this_addr
));
13400 instruction_reader reader
;
13401 if (extract_arm_insn (reader
, &arm_record
, 2))
13405 printf_unfiltered (_("Process record: error reading memory at "
13406 "addr %s len = %d.\n"),
13407 paddress (arm_record
.gdbarch
,
13408 arm_record
.this_addr
), 2);
13413 /* Check the insn, whether it is thumb or arm one. */
13415 t_bit
= arm_psr_thumb_bit (arm_record
.gdbarch
);
13416 regcache_raw_read_unsigned (arm_record
.regcache
, ARM_PS_REGNUM
, &u_regval
);
13419 if (!(u_regval
& t_bit
))
13421 /* We are decoding arm insn. */
13422 ret
= decode_insn (reader
, &arm_record
, ARM_RECORD
, ARM_INSN_SIZE_BYTES
);
13426 insn_id
= bits (arm_record
.arm_insn
, 11, 15);
13427 /* is it thumb2 insn? */
13428 if ((0x1D == insn_id
) || (0x1E == insn_id
) || (0x1F == insn_id
))
13430 ret
= decode_insn (reader
, &arm_record
, THUMB2_RECORD
,
13431 THUMB2_INSN_SIZE_BYTES
);
13435 /* We are decoding thumb insn. */
13436 ret
= decode_insn (reader
, &arm_record
, THUMB_RECORD
,
13437 THUMB_INSN_SIZE_BYTES
);
13443 /* Record registers. */
13444 record_full_arch_list_add_reg (arm_record
.regcache
, ARM_PC_REGNUM
);
13445 if (arm_record
.arm_regs
)
13447 for (no_of_rec
= 0; no_of_rec
< arm_record
.reg_rec_count
; no_of_rec
++)
13449 if (record_full_arch_list_add_reg
13450 (arm_record
.regcache
, arm_record
.arm_regs
[no_of_rec
]))
13454 /* Record memories. */
13455 if (arm_record
.arm_mems
)
13457 for (no_of_rec
= 0; no_of_rec
< arm_record
.mem_rec_count
; no_of_rec
++)
13459 if (record_full_arch_list_add_mem
13460 ((CORE_ADDR
)arm_record
.arm_mems
[no_of_rec
].addr
,
13461 arm_record
.arm_mems
[no_of_rec
].len
))
13466 if (record_full_arch_list_add_end ())
13471 deallocate_reg_mem (&arm_record
);
13476 /* See arm-tdep.h. */
13478 const target_desc
*
13479 arm_read_description (arm_fp_type fp_type
)
13481 struct target_desc
*tdesc
= tdesc_arm_list
[fp_type
];
13483 if (tdesc
== nullptr)
13485 tdesc
= arm_create_target_description (fp_type
);
13486 tdesc_arm_list
[fp_type
] = tdesc
;
13492 /* See arm-tdep.h. */
13494 const target_desc
*
13495 arm_read_mprofile_description (arm_m_profile_type m_type
)
13497 struct target_desc
*tdesc
= tdesc_arm_mprofile_list
[m_type
];
13499 if (tdesc
== nullptr)
13501 tdesc
= arm_create_mprofile_target_description (m_type
);
13502 tdesc_arm_mprofile_list
[m_type
] = tdesc
;