1 /* Common target dependent code for GDB on ARM systems.
3 Copyright (C) 1988-2019 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"
50 #include "arch/arm-get-next-pcs.h"
52 #include "gdb/sim-arm.h"
55 #include "coff/internal.h"
58 #include "common/vec.h"
61 #include "record-full.h"
64 #include "features/arm/arm-with-m.c"
65 #include "features/arm/arm-with-m-fpa-layout.c"
66 #include "features/arm/arm-with-m-vfp-d16.c"
67 #include "features/arm/arm-with-iwmmxt.c"
68 #include "features/arm/arm-with-vfpv2.c"
69 #include "features/arm/arm-with-vfpv3.c"
70 #include "features/arm/arm-with-neon.c"
73 #include "common/selftest.h"
78 /* Macros for setting and testing a bit in a minimal symbol that marks
79 it as Thumb function. The MSB of the minimal symbol's "info" field
80 is used for this purpose.
82 MSYMBOL_SET_SPECIAL Actually sets the "special" bit.
83 MSYMBOL_IS_SPECIAL Tests the "special" bit in a minimal symbol. */
85 #define MSYMBOL_SET_SPECIAL(msym) \
86 MSYMBOL_TARGET_FLAG_1 (msym) = 1
88 #define MSYMBOL_IS_SPECIAL(msym) \
89 MSYMBOL_TARGET_FLAG_1 (msym)
91 /* Per-objfile data used for mapping symbols. */
92 static const struct objfile_data *arm_objfile_data_key;
94 struct arm_mapping_symbol
99 typedef struct arm_mapping_symbol arm_mapping_symbol_s;
100 DEF_VEC_O(arm_mapping_symbol_s);
102 struct arm_per_objfile
104 VEC(arm_mapping_symbol_s) **section_maps;
107 /* The list of available "set arm ..." and "show arm ..." commands. */
108 static struct cmd_list_element *setarmcmdlist = NULL;
109 static struct cmd_list_element *showarmcmdlist = NULL;
111 /* The type of floating-point to use. Keep this in sync with enum
112 arm_float_model, and the help string in _initialize_arm_tdep. */
113 static const char *const fp_model_strings[] =
123 /* A variable that can be configured by the user. */
124 static enum arm_float_model arm_fp_model = ARM_FLOAT_AUTO;
125 static const char *current_fp_model = "auto";
127 /* The ABI to use. Keep this in sync with arm_abi_kind. */
128 static const char *const arm_abi_strings[] =
136 /* A variable that can be configured by the user. */
137 static enum arm_abi_kind arm_abi_global = ARM_ABI_AUTO;
138 static const char *arm_abi_string = "auto";
140 /* The execution mode to assume. */
141 static const char *const arm_mode_strings[] =
149 static const char *arm_fallback_mode_string = "auto";
150 static const char *arm_force_mode_string = "auto";
152 /* The standard register names, and all the valid aliases for them. Note
153 that `fp', `sp' and `pc' are not added in this alias list, because they
154 have been added as builtin user registers in
155 std-regs.c:_initialize_frame_reg. */
160 } arm_register_aliases[] = {
161 /* Basic register numbers. */
178 /* Synonyms (argument and variable registers). */
191 /* Other platform-specific names for r9. */
197 /* Names used by GCC (not listed in the ARM EABI). */
199 /* A special name from the older ATPCS. */
203 static const char *const arm_register_names[] =
204 {"r0", "r1", "r2", "r3", /* 0 1 2 3 */
205 "r4", "r5", "r6", "r7", /* 4 5 6 7 */
206 "r8", "r9", "r10", "r11", /* 8 9 10 11 */
207 "r12", "sp", "lr", "pc", /* 12 13 14 15 */
208 "f0", "f1", "f2", "f3", /* 16 17 18 19 */
209 "f4", "f5", "f6", "f7", /* 20 21 22 23 */
210 "fps", "cpsr" }; /* 24 25 */
212 /* Holds the current set of options to be passed to the disassembler. */
213 static char *arm_disassembler_options;
215 /* Valid register name styles. */
216 static const char **valid_disassembly_styles;
218 /* Disassembly style to use. Default to "std" register names. */
219 static const char *disassembly_style;
221 /* This is used to keep the bfd arch_info in sync with the disassembly
223 static void set_disassembly_style_sfunc (const char *, int,
224 struct cmd_list_element *);
225 static void show_disassembly_style_sfunc (struct ui_file *, int,
226 struct cmd_list_element *,
229 static enum register_status arm_neon_quad_read (struct gdbarch *gdbarch,
230 readable_regcache *regcache,
231 int regnum, gdb_byte *buf);
232 static void arm_neon_quad_write (struct gdbarch *gdbarch,
233 struct regcache *regcache,
234 int regnum, const gdb_byte *buf);
237 arm_get_next_pcs_syscall_next_pc (struct arm_get_next_pcs *self);
240 /* get_next_pcs operations. */
241 static struct arm_get_next_pcs_ops arm_get_next_pcs_ops = {
242 arm_get_next_pcs_read_memory_unsigned_integer,
243 arm_get_next_pcs_syscall_next_pc,
244 arm_get_next_pcs_addr_bits_remove,
245 arm_get_next_pcs_is_thumb,
249 struct arm_prologue_cache
251 /* The stack pointer at the time this frame was created; i.e. the
252 caller's stack pointer when this function was called. It is used
253 to identify this frame. */
256 /* The frame base for this frame is just prev_sp - frame size.
257 FRAMESIZE is the distance from the frame pointer to the
258 initial stack pointer. */
262 /* The register used to hold the frame pointer for this frame. */
265 /* Saved register offsets. */
266 struct trad_frame_saved_reg *saved_regs;
269 static CORE_ADDR arm_analyze_prologue (struct gdbarch *gdbarch,
270 CORE_ADDR prologue_start,
271 CORE_ADDR prologue_end,
272 struct arm_prologue_cache *cache);
274 /* Architecture version for displaced stepping. This effects the behaviour of
275 certain instructions, and really should not be hard-wired. */
277 #define DISPLACED_STEPPING_ARCH_VERSION 5
279 /* Set to true if the 32-bit mode is in use. */
283 /* Return the bit mask in ARM_PS_REGNUM that indicates Thumb mode. */
286 arm_psr_thumb_bit (struct gdbarch *gdbarch)
288 if (gdbarch_tdep (gdbarch)->is_m)
294 /* Determine if the processor is currently executing in Thumb mode. */
297 arm_is_thumb (struct regcache *regcache)
300 ULONGEST t_bit = arm_psr_thumb_bit (regcache->arch ());
302 cpsr = regcache_raw_get_unsigned (regcache, ARM_PS_REGNUM);
304 return (cpsr & t_bit) != 0;
307 /* Determine if FRAME is executing in Thumb mode. */
310 arm_frame_is_thumb (struct frame_info *frame)
313 ULONGEST t_bit = arm_psr_thumb_bit (get_frame_arch (frame));
315 /* Every ARM frame unwinder can unwind the T bit of the CPSR, either
316 directly (from a signal frame or dummy frame) or by interpreting
317 the saved LR (from a prologue or DWARF frame). So consult it and
318 trust the unwinders. */
319 cpsr = get_frame_register_unsigned (frame, ARM_PS_REGNUM);
321 return (cpsr & t_bit) != 0;
324 /* Callback for VEC_lower_bound. */
327 arm_compare_mapping_symbols (const struct arm_mapping_symbol *lhs,
328 const struct arm_mapping_symbol *rhs)
330 return lhs->value < rhs->value;
333 /* Search for the mapping symbol covering MEMADDR. If one is found,
334 return its type. Otherwise, return 0. If START is non-NULL,
335 set *START to the location of the mapping symbol. */
338 arm_find_mapping_symbol (CORE_ADDR memaddr, CORE_ADDR *start)
340 struct obj_section *sec;
342 /* If there are mapping symbols, consult them. */
343 sec = find_pc_section (memaddr);
346 struct arm_per_objfile *data;
347 VEC(arm_mapping_symbol_s) *map;
348 struct arm_mapping_symbol map_key = { memaddr - obj_section_addr (sec),
352 data = (struct arm_per_objfile *) objfile_data (sec->objfile,
353 arm_objfile_data_key);
356 map = data->section_maps[sec->the_bfd_section->index];
357 if (!VEC_empty (arm_mapping_symbol_s, map))
359 struct arm_mapping_symbol *map_sym;
361 idx = VEC_lower_bound (arm_mapping_symbol_s, map, &map_key,
362 arm_compare_mapping_symbols);
364 /* VEC_lower_bound finds the earliest ordered insertion
365 point. If the following symbol starts at this exact
366 address, we use that; otherwise, the preceding
367 mapping symbol covers this address. */
368 if (idx < VEC_length (arm_mapping_symbol_s, map))
370 map_sym = VEC_index (arm_mapping_symbol_s, map, idx);
371 if (map_sym->value == map_key.value)
374 *start = map_sym->value + obj_section_addr (sec);
375 return map_sym->type;
381 map_sym = VEC_index (arm_mapping_symbol_s, map, idx - 1);
383 *start = map_sym->value + obj_section_addr (sec);
384 return map_sym->type;
393 /* Determine if the program counter specified in MEMADDR is in a Thumb
394 function. This function should be called for addresses unrelated to
395 any executing frame; otherwise, prefer arm_frame_is_thumb. */
398 arm_pc_is_thumb (struct gdbarch *gdbarch, CORE_ADDR memaddr)
400 struct bound_minimal_symbol sym;
402 arm_displaced_step_closure *dsc
403 = ((arm_displaced_step_closure * )
404 get_displaced_step_closure_by_addr (memaddr));
406 /* If checking the mode of displaced instruction in copy area, the mode
407 should be determined by instruction on the original address. */
411 fprintf_unfiltered (gdb_stdlog,
412 "displaced: check mode of %.8lx instead of %.8lx\n",
413 (unsigned long) dsc->insn_addr,
414 (unsigned long) memaddr);
415 memaddr = dsc->insn_addr;
418 /* If bit 0 of the address is set, assume this is a Thumb address. */
419 if (IS_THUMB_ADDR (memaddr))
422 /* If the user wants to override the symbol table, let him. */
423 if (strcmp (arm_force_mode_string, "arm") == 0)
425 if (strcmp (arm_force_mode_string, "thumb") == 0)
428 /* ARM v6-M and v7-M are always in Thumb mode. */
429 if (gdbarch_tdep (gdbarch)->is_m)
432 /* If there are mapping symbols, consult them. */
433 type = arm_find_mapping_symbol (memaddr, NULL);
437 /* Thumb functions have a "special" bit set in minimal symbols. */
438 sym = lookup_minimal_symbol_by_pc (memaddr);
440 return (MSYMBOL_IS_SPECIAL (sym.minsym));
442 /* If the user wants to override the fallback mode, let them. */
443 if (strcmp (arm_fallback_mode_string, "arm") == 0)
445 if (strcmp (arm_fallback_mode_string, "thumb") == 0)
448 /* If we couldn't find any symbol, but we're talking to a running
449 target, then trust the current value of $cpsr. This lets
450 "display/i $pc" always show the correct mode (though if there is
451 a symbol table we will not reach here, so it still may not be
452 displayed in the mode it will be executed). */
453 if (target_has_registers)
454 return arm_frame_is_thumb (get_current_frame ());
456 /* Otherwise we're out of luck; we assume ARM. */
460 /* Determine if the address specified equals any of these magic return
461 values, called EXC_RETURN, defined by the ARM v6-M and v7-M
464 From ARMv6-M Reference Manual B1.5.8
465 Table B1-5 Exception return behavior
467 EXC_RETURN Return To Return Stack
468 0xFFFFFFF1 Handler mode Main
469 0xFFFFFFF9 Thread mode Main
470 0xFFFFFFFD Thread mode Process
472 From ARMv7-M Reference Manual B1.5.8
473 Table B1-8 EXC_RETURN definition of exception return behavior, no FP
475 EXC_RETURN Return To Return Stack
476 0xFFFFFFF1 Handler mode Main
477 0xFFFFFFF9 Thread mode Main
478 0xFFFFFFFD Thread mode Process
480 Table B1-9 EXC_RETURN definition of exception return behavior, with
483 EXC_RETURN Return To Return Stack Frame Type
484 0xFFFFFFE1 Handler mode Main Extended
485 0xFFFFFFE9 Thread mode Main Extended
486 0xFFFFFFED Thread mode Process Extended
487 0xFFFFFFF1 Handler mode Main Basic
488 0xFFFFFFF9 Thread mode Main Basic
489 0xFFFFFFFD Thread mode Process Basic
491 For more details see "B1.5.8 Exception return behavior"
492 in both ARMv6-M and ARMv7-M Architecture Reference Manuals. */
495 arm_m_addr_is_magic (CORE_ADDR addr)
499 /* Values from Tables in B1.5.8 the EXC_RETURN definitions of
500 the exception return behavior. */
507 /* Address is magic. */
511 /* Address is not magic. */
516 /* Remove useless bits from addresses in a running program. */
518 arm_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR val)
520 /* On M-profile devices, do not strip the low bit from EXC_RETURN
521 (the magic exception return address). */
522 if (gdbarch_tdep (gdbarch)->is_m
523 && arm_m_addr_is_magic (val))
527 return UNMAKE_THUMB_ADDR (val);
529 return (val & 0x03fffffc);
532 /* Return 1 if PC is the start of a compiler helper function which
533 can be safely ignored during prologue skipping. IS_THUMB is true
534 if the function is known to be a Thumb function due to the way it
537 skip_prologue_function (struct gdbarch *gdbarch, CORE_ADDR pc, int is_thumb)
539 enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
540 struct bound_minimal_symbol msym;
542 msym = lookup_minimal_symbol_by_pc (pc);
543 if (msym.minsym != NULL
544 && BMSYMBOL_VALUE_ADDRESS (msym) == pc
545 && MSYMBOL_LINKAGE_NAME (msym.minsym) != NULL)
547 const char *name = MSYMBOL_LINKAGE_NAME (msym.minsym);
549 /* The GNU linker's Thumb call stub to foo is named
551 if (strstr (name, "_from_thumb") != NULL)
554 /* On soft-float targets, __truncdfsf2 is called to convert promoted
555 arguments to their argument types in non-prototyped
557 if (startswith (name, "__truncdfsf2"))
559 if (startswith (name, "__aeabi_d2f"))
562 /* Internal functions related to thread-local storage. */
563 if (startswith (name, "__tls_get_addr"))
565 if (startswith (name, "__aeabi_read_tp"))
570 /* If we run against a stripped glibc, we may be unable to identify
571 special functions by name. Check for one important case,
572 __aeabi_read_tp, by comparing the *code* against the default
573 implementation (this is hand-written ARM assembler in glibc). */
576 && read_code_unsigned_integer (pc, 4, byte_order_for_code)
577 == 0xe3e00a0f /* mov r0, #0xffff0fff */
578 && read_code_unsigned_integer (pc + 4, 4, byte_order_for_code)
579 == 0xe240f01f) /* sub pc, r0, #31 */
586 /* Extract the immediate from instruction movw/movt of encoding T. INSN1 is
587 the first 16-bit of instruction, and INSN2 is the second 16-bit of
589 #define EXTRACT_MOVW_MOVT_IMM_T(insn1, insn2) \
590 ((bits ((insn1), 0, 3) << 12) \
591 | (bits ((insn1), 10, 10) << 11) \
592 | (bits ((insn2), 12, 14) << 8) \
593 | bits ((insn2), 0, 7))
595 /* Extract the immediate from instruction movw/movt of encoding A. INSN is
596 the 32-bit instruction. */
597 #define EXTRACT_MOVW_MOVT_IMM_A(insn) \
598 ((bits ((insn), 16, 19) << 12) \
599 | bits ((insn), 0, 11))
601 /* Decode immediate value; implements ThumbExpandImmediate pseudo-op. */
604 thumb_expand_immediate (unsigned int imm)
606 unsigned int count = imm >> 7;
614 return (imm & 0xff) | ((imm & 0xff) << 16);
616 return ((imm & 0xff) << 8) | ((imm & 0xff) << 24);
618 return (imm & 0xff) | ((imm & 0xff) << 8)
619 | ((imm & 0xff) << 16) | ((imm & 0xff) << 24);
622 return (0x80 | (imm & 0x7f)) << (32 - count);
625 /* Return 1 if the 16-bit Thumb instruction INSN restores SP in
626 epilogue, 0 otherwise. */
629 thumb_instruction_restores_sp (unsigned short insn)
631 return (insn == 0x46bd /* mov sp, r7 */
632 || (insn & 0xff80) == 0xb000 /* add sp, imm */
633 || (insn & 0xfe00) == 0xbc00); /* pop <registers> */
636 /* Analyze a Thumb prologue, looking for a recognizable stack frame
637 and frame pointer. Scan until we encounter a store that could
638 clobber the stack frame unexpectedly, or an unknown instruction.
639 Return the last address which is definitely safe to skip for an
640 initial breakpoint. */
643 thumb_analyze_prologue (struct gdbarch *gdbarch,
644 CORE_ADDR start, CORE_ADDR limit,
645 struct arm_prologue_cache *cache)
647 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
648 enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
652 CORE_ADDR unrecognized_pc = 0;
654 for (i = 0; i < 16; i++)
655 regs[i] = pv_register (i, 0);
656 pv_area stack (ARM_SP_REGNUM, gdbarch_addr_bit (gdbarch));
658 while (start < limit)
662 insn = read_code_unsigned_integer (start, 2, byte_order_for_code);
664 if ((insn & 0xfe00) == 0xb400) /* push { rlist } */
669 if (stack.store_would_trash (regs[ARM_SP_REGNUM]))
672 /* Bits 0-7 contain a mask for registers R0-R7. Bit 8 says
673 whether to save LR (R14). */
674 mask = (insn & 0xff) | ((insn & 0x100) << 6);
676 /* Calculate offsets of saved R0-R7 and LR. */
677 for (regno = ARM_LR_REGNUM; regno >= 0; regno--)
678 if (mask & (1 << regno))
680 regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM],
682 stack.store (regs[ARM_SP_REGNUM], 4, regs[regno]);
685 else if ((insn & 0xff80) == 0xb080) /* sub sp, #imm */
687 offset = (insn & 0x7f) << 2; /* get scaled offset */
688 regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM],
691 else if (thumb_instruction_restores_sp (insn))
693 /* Don't scan past the epilogue. */
696 else if ((insn & 0xf800) == 0xa800) /* add Rd, sp, #imm */
697 regs[bits (insn, 8, 10)] = pv_add_constant (regs[ARM_SP_REGNUM],
699 else if ((insn & 0xfe00) == 0x1c00 /* add Rd, Rn, #imm */
700 && pv_is_register (regs[bits (insn, 3, 5)], ARM_SP_REGNUM))
701 regs[bits (insn, 0, 2)] = pv_add_constant (regs[bits (insn, 3, 5)],
703 else if ((insn & 0xf800) == 0x3000 /* add Rd, #imm */
704 && pv_is_register (regs[bits (insn, 8, 10)], ARM_SP_REGNUM))
705 regs[bits (insn, 8, 10)] = pv_add_constant (regs[bits (insn, 8, 10)],
707 else if ((insn & 0xfe00) == 0x1800 /* add Rd, Rn, Rm */
708 && pv_is_register (regs[bits (insn, 6, 8)], ARM_SP_REGNUM)
709 && pv_is_constant (regs[bits (insn, 3, 5)]))
710 regs[bits (insn, 0, 2)] = pv_add (regs[bits (insn, 3, 5)],
711 regs[bits (insn, 6, 8)]);
712 else if ((insn & 0xff00) == 0x4400 /* add Rd, Rm */
713 && pv_is_constant (regs[bits (insn, 3, 6)]))
715 int rd = (bit (insn, 7) << 3) + bits (insn, 0, 2);
716 int rm = bits (insn, 3, 6);
717 regs[rd] = pv_add (regs[rd], regs[rm]);
719 else if ((insn & 0xff00) == 0x4600) /* mov hi, lo or mov lo, hi */
721 int dst_reg = (insn & 0x7) + ((insn & 0x80) >> 4);
722 int src_reg = (insn & 0x78) >> 3;
723 regs[dst_reg] = regs[src_reg];
725 else if ((insn & 0xf800) == 0x9000) /* str rd, [sp, #off] */
727 /* Handle stores to the stack. Normally pushes are used,
728 but with GCC -mtpcs-frame, there may be other stores
729 in the prologue to create the frame. */
730 int regno = (insn >> 8) & 0x7;
733 offset = (insn & 0xff) << 2;
734 addr = pv_add_constant (regs[ARM_SP_REGNUM], offset);
736 if (stack.store_would_trash (addr))
739 stack.store (addr, 4, regs[regno]);
741 else if ((insn & 0xf800) == 0x6000) /* str rd, [rn, #off] */
743 int rd = bits (insn, 0, 2);
744 int rn = bits (insn, 3, 5);
747 offset = bits (insn, 6, 10) << 2;
748 addr = pv_add_constant (regs[rn], offset);
750 if (stack.store_would_trash (addr))
753 stack.store (addr, 4, regs[rd]);
755 else if (((insn & 0xf800) == 0x7000 /* strb Rd, [Rn, #off] */
756 || (insn & 0xf800) == 0x8000) /* strh Rd, [Rn, #off] */
757 && pv_is_register (regs[bits (insn, 3, 5)], ARM_SP_REGNUM))
758 /* Ignore stores of argument registers to the stack. */
760 else if ((insn & 0xf800) == 0xc800 /* ldmia Rn!, { registers } */
761 && pv_is_register (regs[bits (insn, 8, 10)], ARM_SP_REGNUM))
762 /* Ignore block loads from the stack, potentially copying
763 parameters from memory. */
765 else if ((insn & 0xf800) == 0x9800 /* ldr Rd, [Rn, #immed] */
766 || ((insn & 0xf800) == 0x6800 /* ldr Rd, [sp, #immed] */
767 && pv_is_register (regs[bits (insn, 3, 5)], ARM_SP_REGNUM)))
768 /* Similarly ignore single loads from the stack. */
770 else if ((insn & 0xffc0) == 0x0000 /* lsls Rd, Rm, #0 */
771 || (insn & 0xffc0) == 0x1c00) /* add Rd, Rn, #0 */
772 /* Skip register copies, i.e. saves to another register
773 instead of the stack. */
775 else if ((insn & 0xf800) == 0x2000) /* movs Rd, #imm */
776 /* Recognize constant loads; even with small stacks these are necessary
778 regs[bits (insn, 8, 10)] = pv_constant (bits (insn, 0, 7));
779 else if ((insn & 0xf800) == 0x4800) /* ldr Rd, [pc, #imm] */
781 /* Constant pool loads, for the same reason. */
782 unsigned int constant;
785 loc = start + 4 + bits (insn, 0, 7) * 4;
786 constant = read_memory_unsigned_integer (loc, 4, byte_order);
787 regs[bits (insn, 8, 10)] = pv_constant (constant);
789 else if (thumb_insn_size (insn) == 4) /* 32-bit Thumb-2 instructions. */
791 unsigned short inst2;
793 inst2 = read_code_unsigned_integer (start + 2, 2,
794 byte_order_for_code);
796 if ((insn & 0xf800) == 0xf000 && (inst2 & 0xe800) == 0xe800)
798 /* BL, BLX. Allow some special function calls when
799 skipping the prologue; GCC generates these before
800 storing arguments to the stack. */
802 int j1, j2, imm1, imm2;
804 imm1 = sbits (insn, 0, 10);
805 imm2 = bits (inst2, 0, 10);
806 j1 = bit (inst2, 13);
807 j2 = bit (inst2, 11);
809 offset = ((imm1 << 12) + (imm2 << 1));
810 offset ^= ((!j2) << 22) | ((!j1) << 23);
812 nextpc = start + 4 + offset;
813 /* For BLX make sure to clear the low bits. */
814 if (bit (inst2, 12) == 0)
815 nextpc = nextpc & 0xfffffffc;
817 if (!skip_prologue_function (gdbarch, nextpc,
818 bit (inst2, 12) != 0))
822 else if ((insn & 0xffd0) == 0xe900 /* stmdb Rn{!},
824 && pv_is_register (regs[bits (insn, 0, 3)], ARM_SP_REGNUM))
826 pv_t addr = regs[bits (insn, 0, 3)];
829 if (stack.store_would_trash (addr))
832 /* Calculate offsets of saved registers. */
833 for (regno = ARM_LR_REGNUM; regno >= 0; regno--)
834 if (inst2 & (1 << regno))
836 addr = pv_add_constant (addr, -4);
837 stack.store (addr, 4, regs[regno]);
841 regs[bits (insn, 0, 3)] = addr;
844 else if ((insn & 0xff50) == 0xe940 /* strd Rt, Rt2,
846 && pv_is_register (regs[bits (insn, 0, 3)], ARM_SP_REGNUM))
848 int regno1 = bits (inst2, 12, 15);
849 int regno2 = bits (inst2, 8, 11);
850 pv_t addr = regs[bits (insn, 0, 3)];
852 offset = inst2 & 0xff;
854 addr = pv_add_constant (addr, offset);
856 addr = pv_add_constant (addr, -offset);
858 if (stack.store_would_trash (addr))
861 stack.store (addr, 4, regs[regno1]);
862 stack.store (pv_add_constant (addr, 4),
866 regs[bits (insn, 0, 3)] = addr;
869 else if ((insn & 0xfff0) == 0xf8c0 /* str Rt,[Rn,+/-#imm]{!} */
870 && (inst2 & 0x0c00) == 0x0c00
871 && pv_is_register (regs[bits (insn, 0, 3)], ARM_SP_REGNUM))
873 int regno = bits (inst2, 12, 15);
874 pv_t addr = regs[bits (insn, 0, 3)];
876 offset = inst2 & 0xff;
878 addr = pv_add_constant (addr, offset);
880 addr = pv_add_constant (addr, -offset);
882 if (stack.store_would_trash (addr))
885 stack.store (addr, 4, regs[regno]);
888 regs[bits (insn, 0, 3)] = addr;
891 else if ((insn & 0xfff0) == 0xf8c0 /* str.w Rt,[Rn,#imm] */
892 && pv_is_register (regs[bits (insn, 0, 3)], ARM_SP_REGNUM))
894 int regno = bits (inst2, 12, 15);
897 offset = inst2 & 0xfff;
898 addr = pv_add_constant (regs[bits (insn, 0, 3)], offset);
900 if (stack.store_would_trash (addr))
903 stack.store (addr, 4, regs[regno]);
906 else if ((insn & 0xffd0) == 0xf880 /* str{bh}.w Rt,[Rn,#imm] */
907 && pv_is_register (regs[bits (insn, 0, 3)], ARM_SP_REGNUM))
908 /* Ignore stores of argument registers to the stack. */
911 else if ((insn & 0xffd0) == 0xf800 /* str{bh} Rt,[Rn,#+/-imm] */
912 && (inst2 & 0x0d00) == 0x0c00
913 && pv_is_register (regs[bits (insn, 0, 3)], ARM_SP_REGNUM))
914 /* Ignore stores of argument registers to the stack. */
917 else if ((insn & 0xffd0) == 0xe890 /* ldmia Rn[!],
919 && (inst2 & 0x8000) == 0x0000
920 && pv_is_register (regs[bits (insn, 0, 3)], ARM_SP_REGNUM))
921 /* Ignore block loads from the stack, potentially copying
922 parameters from memory. */
925 else if ((insn & 0xffb0) == 0xe950 /* ldrd Rt, Rt2,
927 && pv_is_register (regs[bits (insn, 0, 3)], ARM_SP_REGNUM))
928 /* Similarly ignore dual loads from the stack. */
931 else if ((insn & 0xfff0) == 0xf850 /* ldr Rt,[Rn,#+/-imm] */
932 && (inst2 & 0x0d00) == 0x0c00
933 && pv_is_register (regs[bits (insn, 0, 3)], ARM_SP_REGNUM))
934 /* Similarly ignore single loads from the stack. */
937 else if ((insn & 0xfff0) == 0xf8d0 /* ldr.w Rt,[Rn,#imm] */
938 && pv_is_register (regs[bits (insn, 0, 3)], ARM_SP_REGNUM))
939 /* Similarly ignore single loads from the stack. */
942 else if ((insn & 0xfbf0) == 0xf100 /* add.w Rd, Rn, #imm */
943 && (inst2 & 0x8000) == 0x0000)
945 unsigned int imm = ((bits (insn, 10, 10) << 11)
946 | (bits (inst2, 12, 14) << 8)
947 | bits (inst2, 0, 7));
949 regs[bits (inst2, 8, 11)]
950 = pv_add_constant (regs[bits (insn, 0, 3)],
951 thumb_expand_immediate (imm));
954 else if ((insn & 0xfbf0) == 0xf200 /* addw Rd, Rn, #imm */
955 && (inst2 & 0x8000) == 0x0000)
957 unsigned int imm = ((bits (insn, 10, 10) << 11)
958 | (bits (inst2, 12, 14) << 8)
959 | bits (inst2, 0, 7));
961 regs[bits (inst2, 8, 11)]
962 = pv_add_constant (regs[bits (insn, 0, 3)], imm);
965 else if ((insn & 0xfbf0) == 0xf1a0 /* sub.w Rd, Rn, #imm */
966 && (inst2 & 0x8000) == 0x0000)
968 unsigned int imm = ((bits (insn, 10, 10) << 11)
969 | (bits (inst2, 12, 14) << 8)
970 | bits (inst2, 0, 7));
972 regs[bits (inst2, 8, 11)]
973 = pv_add_constant (regs[bits (insn, 0, 3)],
974 - (CORE_ADDR) thumb_expand_immediate (imm));
977 else if ((insn & 0xfbf0) == 0xf2a0 /* subw Rd, Rn, #imm */
978 && (inst2 & 0x8000) == 0x0000)
980 unsigned int imm = ((bits (insn, 10, 10) << 11)
981 | (bits (inst2, 12, 14) << 8)
982 | bits (inst2, 0, 7));
984 regs[bits (inst2, 8, 11)]
985 = pv_add_constant (regs[bits (insn, 0, 3)], - (CORE_ADDR) imm);
988 else if ((insn & 0xfbff) == 0xf04f) /* mov.w Rd, #const */
990 unsigned int imm = ((bits (insn, 10, 10) << 11)
991 | (bits (inst2, 12, 14) << 8)
992 | bits (inst2, 0, 7));
994 regs[bits (inst2, 8, 11)]
995 = pv_constant (thumb_expand_immediate (imm));
998 else if ((insn & 0xfbf0) == 0xf240) /* movw Rd, #const */
1001 = EXTRACT_MOVW_MOVT_IMM_T (insn, inst2);
1003 regs[bits (inst2, 8, 11)] = pv_constant (imm);
1006 else if (insn == 0xea5f /* mov.w Rd,Rm */
1007 && (inst2 & 0xf0f0) == 0)
1009 int dst_reg = (inst2 & 0x0f00) >> 8;
1010 int src_reg = inst2 & 0xf;
1011 regs[dst_reg] = regs[src_reg];
1014 else if ((insn & 0xff7f) == 0xf85f) /* ldr.w Rt,<label> */
1016 /* Constant pool loads. */
1017 unsigned int constant;
1020 offset = bits (inst2, 0, 11);
1022 loc = start + 4 + offset;
1024 loc = start + 4 - offset;
1026 constant = read_memory_unsigned_integer (loc, 4, byte_order);
1027 regs[bits (inst2, 12, 15)] = pv_constant (constant);
1030 else if ((insn & 0xff7f) == 0xe95f) /* ldrd Rt,Rt2,<label> */
1032 /* Constant pool loads. */
1033 unsigned int constant;
1036 offset = bits (inst2, 0, 7) << 2;
1038 loc = start + 4 + offset;
1040 loc = start + 4 - offset;
1042 constant = read_memory_unsigned_integer (loc, 4, byte_order);
1043 regs[bits (inst2, 12, 15)] = pv_constant (constant);
1045 constant = read_memory_unsigned_integer (loc + 4, 4, byte_order);
1046 regs[bits (inst2, 8, 11)] = pv_constant (constant);
1049 else if (thumb2_instruction_changes_pc (insn, inst2))
1051 /* Don't scan past anything that might change control flow. */
1056 /* The optimizer might shove anything into the prologue,
1057 so we just skip what we don't recognize. */
1058 unrecognized_pc = start;
1063 else if (thumb_instruction_changes_pc (insn))
1065 /* Don't scan past anything that might change control flow. */
1070 /* The optimizer might shove anything into the prologue,
1071 so we just skip what we don't recognize. */
1072 unrecognized_pc = start;
1079 fprintf_unfiltered (gdb_stdlog, "Prologue scan stopped at %s\n",
1080 paddress (gdbarch, start));
1082 if (unrecognized_pc == 0)
1083 unrecognized_pc = start;
1086 return unrecognized_pc;
1088 if (pv_is_register (regs[ARM_FP_REGNUM], ARM_SP_REGNUM))
1090 /* Frame pointer is fp. Frame size is constant. */
1091 cache->framereg = ARM_FP_REGNUM;
1092 cache->framesize = -regs[ARM_FP_REGNUM].k;
1094 else if (pv_is_register (regs[THUMB_FP_REGNUM], ARM_SP_REGNUM))
1096 /* Frame pointer is r7. Frame size is constant. */
1097 cache->framereg = THUMB_FP_REGNUM;
1098 cache->framesize = -regs[THUMB_FP_REGNUM].k;
1102 /* Try the stack pointer... this is a bit desperate. */
1103 cache->framereg = ARM_SP_REGNUM;
1104 cache->framesize = -regs[ARM_SP_REGNUM].k;
1107 for (i = 0; i < 16; i++)
1108 if (stack.find_reg (gdbarch, i, &offset))
1109 cache->saved_regs[i].addr = offset;
1111 return unrecognized_pc;
1115 /* Try to analyze the instructions starting from PC, which load symbol
1116 __stack_chk_guard. Return the address of instruction after loading this
1117 symbol, set the dest register number to *BASEREG, and set the size of
1118 instructions for loading symbol in OFFSET. Return 0 if instructions are
1122 arm_analyze_load_stack_chk_guard(CORE_ADDR pc, struct gdbarch *gdbarch,
1123 unsigned int *destreg, int *offset)
1125 enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
1126 int is_thumb = arm_pc_is_thumb (gdbarch, pc);
1127 unsigned int low, high, address;
1132 unsigned short insn1
1133 = read_code_unsigned_integer (pc, 2, byte_order_for_code);
1135 if ((insn1 & 0xf800) == 0x4800) /* ldr Rd, #immed */
1137 *destreg = bits (insn1, 8, 10);
1139 address = (pc & 0xfffffffc) + 4 + (bits (insn1, 0, 7) << 2);
1140 address = read_memory_unsigned_integer (address, 4,
1141 byte_order_for_code);
1143 else if ((insn1 & 0xfbf0) == 0xf240) /* movw Rd, #const */
1145 unsigned short insn2
1146 = read_code_unsigned_integer (pc + 2, 2, byte_order_for_code);
1148 low = EXTRACT_MOVW_MOVT_IMM_T (insn1, insn2);
1151 = read_code_unsigned_integer (pc + 4, 2, byte_order_for_code);
1153 = read_code_unsigned_integer (pc + 6, 2, byte_order_for_code);
1155 /* movt Rd, #const */
1156 if ((insn1 & 0xfbc0) == 0xf2c0)
1158 high = EXTRACT_MOVW_MOVT_IMM_T (insn1, insn2);
1159 *destreg = bits (insn2, 8, 11);
1161 address = (high << 16 | low);
1168 = read_code_unsigned_integer (pc, 4, byte_order_for_code);
1170 if ((insn & 0x0e5f0000) == 0x041f0000) /* ldr Rd, [PC, #immed] */
1172 address = bits (insn, 0, 11) + pc + 8;
1173 address = read_memory_unsigned_integer (address, 4,
1174 byte_order_for_code);
1176 *destreg = bits (insn, 12, 15);
1179 else if ((insn & 0x0ff00000) == 0x03000000) /* movw Rd, #const */
1181 low = EXTRACT_MOVW_MOVT_IMM_A (insn);
1184 = read_code_unsigned_integer (pc + 4, 4, byte_order_for_code);
1186 if ((insn & 0x0ff00000) == 0x03400000) /* movt Rd, #const */
1188 high = EXTRACT_MOVW_MOVT_IMM_A (insn);
1189 *destreg = bits (insn, 12, 15);
1191 address = (high << 16 | low);
1199 /* Try to skip a sequence of instructions used for stack protector. If PC
1200 points to the first instruction of this sequence, return the address of
1201 first instruction after this sequence, otherwise, return original PC.
1203 On arm, this sequence of instructions is composed of mainly three steps,
1204 Step 1: load symbol __stack_chk_guard,
1205 Step 2: load from address of __stack_chk_guard,
1206 Step 3: store it to somewhere else.
1208 Usually, instructions on step 2 and step 3 are the same on various ARM
1209 architectures. On step 2, it is one instruction 'ldr Rx, [Rn, #0]', and
1210 on step 3, it is also one instruction 'str Rx, [r7, #immd]'. However,
1211 instructions in step 1 vary from different ARM architectures. On ARMv7,
1214 movw Rn, #:lower16:__stack_chk_guard
1215 movt Rn, #:upper16:__stack_chk_guard
1222 .word __stack_chk_guard
1224 Since ldr/str is a very popular instruction, we can't use them as
1225 'fingerprint' or 'signature' of stack protector sequence. Here we choose
1226 sequence {movw/movt, ldr}/ldr/str plus symbol __stack_chk_guard, if not
1227 stripped, as the 'fingerprint' of a stack protector cdoe sequence. */
1230 arm_skip_stack_protector(CORE_ADDR pc, struct gdbarch *gdbarch)
1232 enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
1233 unsigned int basereg;
1234 struct bound_minimal_symbol stack_chk_guard;
1236 int is_thumb = arm_pc_is_thumb (gdbarch, pc);
1239 /* Try to parse the instructions in Step 1. */
1240 addr = arm_analyze_load_stack_chk_guard (pc, gdbarch,
1245 stack_chk_guard = lookup_minimal_symbol_by_pc (addr);
1246 /* ADDR must correspond to a symbol whose name is __stack_chk_guard.
1247 Otherwise, this sequence cannot be for stack protector. */
1248 if (stack_chk_guard.minsym == NULL
1249 || !startswith (MSYMBOL_LINKAGE_NAME (stack_chk_guard.minsym), "__stack_chk_guard"))
1254 unsigned int destreg;
1256 = read_code_unsigned_integer (pc + offset, 2, byte_order_for_code);
1258 /* Step 2: ldr Rd, [Rn, #immed], encoding T1. */
1259 if ((insn & 0xf800) != 0x6800)
1261 if (bits (insn, 3, 5) != basereg)
1263 destreg = bits (insn, 0, 2);
1265 insn = read_code_unsigned_integer (pc + offset + 2, 2,
1266 byte_order_for_code);
1267 /* Step 3: str Rd, [Rn, #immed], encoding T1. */
1268 if ((insn & 0xf800) != 0x6000)
1270 if (destreg != bits (insn, 0, 2))
1275 unsigned int destreg;
1277 = read_code_unsigned_integer (pc + offset, 4, byte_order_for_code);
1279 /* Step 2: ldr Rd, [Rn, #immed], encoding A1. */
1280 if ((insn & 0x0e500000) != 0x04100000)
1282 if (bits (insn, 16, 19) != basereg)
1284 destreg = bits (insn, 12, 15);
1285 /* Step 3: str Rd, [Rn, #immed], encoding A1. */
1286 insn = read_code_unsigned_integer (pc + offset + 4,
1287 4, byte_order_for_code);
1288 if ((insn & 0x0e500000) != 0x04000000)
1290 if (bits (insn, 12, 15) != destreg)
1293 /* The size of total two instructions ldr/str is 4 on Thumb-2, while 8
1296 return pc + offset + 4;
1298 return pc + offset + 8;
1301 /* Advance the PC across any function entry prologue instructions to
1302 reach some "real" code.
1304 The APCS (ARM Procedure Call Standard) defines the following
1308 [stmfd sp!, {a1,a2,a3,a4}]
1309 stmfd sp!, {...,fp,ip,lr,pc}
1310 [stfe f7, [sp, #-12]!]
1311 [stfe f6, [sp, #-12]!]
1312 [stfe f5, [sp, #-12]!]
1313 [stfe f4, [sp, #-12]!]
1314 sub fp, ip, #nn @@ nn == 20 or 4 depending on second insn. */
1317 arm_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
1319 CORE_ADDR func_addr, limit_pc;
1321 /* See if we can determine the end of the prologue via the symbol table.
1322 If so, then return either PC, or the PC after the prologue, whichever
1324 if (find_pc_partial_function (pc, NULL, &func_addr, NULL))
1326 CORE_ADDR post_prologue_pc
1327 = skip_prologue_using_sal (gdbarch, func_addr);
1328 struct compunit_symtab *cust = find_pc_compunit_symtab (func_addr);
1330 if (post_prologue_pc)
1332 = arm_skip_stack_protector (post_prologue_pc, gdbarch);
1335 /* GCC always emits a line note before the prologue and another
1336 one after, even if the two are at the same address or on the
1337 same line. Take advantage of this so that we do not need to
1338 know every instruction that might appear in the prologue. We
1339 will have producer information for most binaries; if it is
1340 missing (e.g. for -gstabs), assuming the GNU tools. */
1341 if (post_prologue_pc
1343 || COMPUNIT_PRODUCER (cust) == NULL
1344 || startswith (COMPUNIT_PRODUCER (cust), "GNU ")
1345 || startswith (COMPUNIT_PRODUCER (cust), "clang ")))
1346 return post_prologue_pc;
1348 if (post_prologue_pc != 0)
1350 CORE_ADDR analyzed_limit;
1352 /* For non-GCC compilers, make sure the entire line is an
1353 acceptable prologue; GDB will round this function's
1354 return value up to the end of the following line so we
1355 can not skip just part of a line (and we do not want to).
1357 RealView does not treat the prologue specially, but does
1358 associate prologue code with the opening brace; so this
1359 lets us skip the first line if we think it is the opening
1361 if (arm_pc_is_thumb (gdbarch, func_addr))
1362 analyzed_limit = thumb_analyze_prologue (gdbarch, func_addr,
1363 post_prologue_pc, NULL);
1365 analyzed_limit = arm_analyze_prologue (gdbarch, func_addr,
1366 post_prologue_pc, NULL);
1368 if (analyzed_limit != post_prologue_pc)
1371 return post_prologue_pc;
1375 /* Can't determine prologue from the symbol table, need to examine
1378 /* Find an upper limit on the function prologue using the debug
1379 information. If the debug information could not be used to provide
1380 that bound, then use an arbitrary large number as the upper bound. */
1381 /* Like arm_scan_prologue, stop no later than pc + 64. */
1382 limit_pc = skip_prologue_using_sal (gdbarch, pc);
1384 limit_pc = pc + 64; /* Magic. */
1387 /* Check if this is Thumb code. */
1388 if (arm_pc_is_thumb (gdbarch, pc))
1389 return thumb_analyze_prologue (gdbarch, pc, limit_pc, NULL);
1391 return arm_analyze_prologue (gdbarch, pc, limit_pc, NULL);
1395 /* Function: thumb_scan_prologue (helper function for arm_scan_prologue)
1396 This function decodes a Thumb function prologue to determine:
1397 1) the size of the stack frame
1398 2) which registers are saved on it
1399 3) the offsets of saved regs
1400 4) the offset from the stack pointer to the frame pointer
1402 A typical Thumb function prologue would create this stack frame
1403 (offsets relative to FP)
1404 old SP -> 24 stack parameters
1407 R7 -> 0 local variables (16 bytes)
1408 SP -> -12 additional stack space (12 bytes)
1409 The frame size would thus be 36 bytes, and the frame offset would be
1410 12 bytes. The frame register is R7.
1412 The comments for thumb_skip_prolog() describe the algorithm we use
1413 to detect the end of the prolog. */
1417 thumb_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR prev_pc,
1418 CORE_ADDR block_addr, struct arm_prologue_cache *cache)
1420 CORE_ADDR prologue_start;
1421 CORE_ADDR prologue_end;
1423 if (find_pc_partial_function (block_addr, NULL, &prologue_start,
1426 /* See comment in arm_scan_prologue for an explanation of
1428 if (prologue_end > prologue_start + 64)
1430 prologue_end = prologue_start + 64;
1434 /* We're in the boondocks: we have no idea where the start of the
1438 prologue_end = std::min (prologue_end, prev_pc);
1440 thumb_analyze_prologue (gdbarch, prologue_start, prologue_end, cache);
1443 /* Return 1 if the ARM instruction INSN restores SP in epilogue, 0
1447 arm_instruction_restores_sp (unsigned int insn)
1449 if (bits (insn, 28, 31) != INST_NV)
1451 if ((insn & 0x0df0f000) == 0x0080d000
1452 /* ADD SP (register or immediate). */
1453 || (insn & 0x0df0f000) == 0x0040d000
1454 /* SUB SP (register or immediate). */
1455 || (insn & 0x0ffffff0) == 0x01a0d000
1457 || (insn & 0x0fff0000) == 0x08bd0000
1459 || (insn & 0x0fff0000) == 0x049d0000)
1460 /* POP of a single register. */
1467 /* Analyze an ARM mode prologue starting at PROLOGUE_START and
1468 continuing no further than PROLOGUE_END. If CACHE is non-NULL,
1469 fill it in. Return the first address not recognized as a prologue
1472 We recognize all the instructions typically found in ARM prologues,
1473 plus harmless instructions which can be skipped (either for analysis
1474 purposes, or a more restrictive set that can be skipped when finding
1475 the end of the prologue). */
1478 arm_analyze_prologue (struct gdbarch *gdbarch,
1479 CORE_ADDR prologue_start, CORE_ADDR prologue_end,
1480 struct arm_prologue_cache *cache)
1482 enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
1484 CORE_ADDR offset, current_pc;
1485 pv_t regs[ARM_FPS_REGNUM];
1486 CORE_ADDR unrecognized_pc = 0;
1488 /* Search the prologue looking for instructions that set up the
1489 frame pointer, adjust the stack pointer, and save registers.
1491 Be careful, however, and if it doesn't look like a prologue,
1492 don't try to scan it. If, for instance, a frameless function
1493 begins with stmfd sp!, then we will tell ourselves there is
1494 a frame, which will confuse stack traceback, as well as "finish"
1495 and other operations that rely on a knowledge of the stack
1498 for (regno = 0; regno < ARM_FPS_REGNUM; regno++)
1499 regs[regno] = pv_register (regno, 0);
1500 pv_area stack (ARM_SP_REGNUM, gdbarch_addr_bit (gdbarch));
1502 for (current_pc = prologue_start;
1503 current_pc < prologue_end;
1507 = read_code_unsigned_integer (current_pc, 4, byte_order_for_code);
1509 if (insn == 0xe1a0c00d) /* mov ip, sp */
1511 regs[ARM_IP_REGNUM] = regs[ARM_SP_REGNUM];
1514 else if ((insn & 0xfff00000) == 0xe2800000 /* add Rd, Rn, #n */
1515 && pv_is_register (regs[bits (insn, 16, 19)], ARM_SP_REGNUM))
1517 unsigned imm = insn & 0xff; /* immediate value */
1518 unsigned rot = (insn & 0xf00) >> 7; /* rotate amount */
1519 int rd = bits (insn, 12, 15);
1520 imm = (imm >> rot) | (imm << (32 - rot));
1521 regs[rd] = pv_add_constant (regs[bits (insn, 16, 19)], imm);
1524 else if ((insn & 0xfff00000) == 0xe2400000 /* sub Rd, Rn, #n */
1525 && pv_is_register (regs[bits (insn, 16, 19)], ARM_SP_REGNUM))
1527 unsigned imm = insn & 0xff; /* immediate value */
1528 unsigned rot = (insn & 0xf00) >> 7; /* rotate amount */
1529 int rd = bits (insn, 12, 15);
1530 imm = (imm >> rot) | (imm << (32 - rot));
1531 regs[rd] = pv_add_constant (regs[bits (insn, 16, 19)], -imm);
1534 else if ((insn & 0xffff0fff) == 0xe52d0004) /* str Rd,
1537 if (stack.store_would_trash (regs[ARM_SP_REGNUM]))
1539 regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM], -4);
1540 stack.store (regs[ARM_SP_REGNUM], 4,
1541 regs[bits (insn, 12, 15)]);
1544 else if ((insn & 0xffff0000) == 0xe92d0000)
1545 /* stmfd sp!, {..., fp, ip, lr, pc}
1547 stmfd sp!, {a1, a2, a3, a4} */
1549 int mask = insn & 0xffff;
1551 if (stack.store_would_trash (regs[ARM_SP_REGNUM]))
1554 /* Calculate offsets of saved registers. */
1555 for (regno = ARM_PC_REGNUM; regno >= 0; regno--)
1556 if (mask & (1 << regno))
1559 = pv_add_constant (regs[ARM_SP_REGNUM], -4);
1560 stack.store (regs[ARM_SP_REGNUM], 4, regs[regno]);
1563 else if ((insn & 0xffff0000) == 0xe54b0000 /* strb rx,[r11,#-n] */
1564 || (insn & 0xffff00f0) == 0xe14b00b0 /* strh rx,[r11,#-n] */
1565 || (insn & 0xffffc000) == 0xe50b0000) /* str rx,[r11,#-n] */
1567 /* No need to add this to saved_regs -- it's just an arg reg. */
1570 else if ((insn & 0xffff0000) == 0xe5cd0000 /* strb rx,[sp,#n] */
1571 || (insn & 0xffff00f0) == 0xe1cd00b0 /* strh rx,[sp,#n] */
1572 || (insn & 0xffffc000) == 0xe58d0000) /* str rx,[sp,#n] */
1574 /* No need to add this to saved_regs -- it's just an arg reg. */
1577 else if ((insn & 0xfff00000) == 0xe8800000 /* stm Rn,
1579 && pv_is_register (regs[bits (insn, 16, 19)], ARM_SP_REGNUM))
1581 /* No need to add this to saved_regs -- it's just arg regs. */
1584 else if ((insn & 0xfffff000) == 0xe24cb000) /* sub fp, ip #n */
1586 unsigned imm = insn & 0xff; /* immediate value */
1587 unsigned rot = (insn & 0xf00) >> 7; /* rotate amount */
1588 imm = (imm >> rot) | (imm << (32 - rot));
1589 regs[ARM_FP_REGNUM] = pv_add_constant (regs[ARM_IP_REGNUM], -imm);
1591 else if ((insn & 0xfffff000) == 0xe24dd000) /* sub sp, sp #n */
1593 unsigned imm = insn & 0xff; /* immediate value */
1594 unsigned rot = (insn & 0xf00) >> 7; /* rotate amount */
1595 imm = (imm >> rot) | (imm << (32 - rot));
1596 regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM], -imm);
1598 else if ((insn & 0xffff7fff) == 0xed6d0103 /* stfe f?,
1600 && gdbarch_tdep (gdbarch)->have_fpa_registers)
1602 if (stack.store_would_trash (regs[ARM_SP_REGNUM]))
1605 regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM], -12);
1606 regno = ARM_F0_REGNUM + ((insn >> 12) & 0x07);
1607 stack.store (regs[ARM_SP_REGNUM], 12, regs[regno]);
1609 else if ((insn & 0xffbf0fff) == 0xec2d0200 /* sfmfd f0, 4,
1611 && gdbarch_tdep (gdbarch)->have_fpa_registers)
1613 int n_saved_fp_regs;
1614 unsigned int fp_start_reg, fp_bound_reg;
1616 if (stack.store_would_trash (regs[ARM_SP_REGNUM]))
1619 if ((insn & 0x800) == 0x800) /* N0 is set */
1621 if ((insn & 0x40000) == 0x40000) /* N1 is set */
1622 n_saved_fp_regs = 3;
1624 n_saved_fp_regs = 1;
1628 if ((insn & 0x40000) == 0x40000) /* N1 is set */
1629 n_saved_fp_regs = 2;
1631 n_saved_fp_regs = 4;
1634 fp_start_reg = ARM_F0_REGNUM + ((insn >> 12) & 0x7);
1635 fp_bound_reg = fp_start_reg + n_saved_fp_regs;
1636 for (; fp_start_reg < fp_bound_reg; fp_start_reg++)
1638 regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM], -12);
1639 stack.store (regs[ARM_SP_REGNUM], 12,
1640 regs[fp_start_reg++]);
1643 else if ((insn & 0xff000000) == 0xeb000000 && cache == NULL) /* bl */
1645 /* Allow some special function calls when skipping the
1646 prologue; GCC generates these before storing arguments to
1648 CORE_ADDR dest = BranchDest (current_pc, insn);
1650 if (skip_prologue_function (gdbarch, dest, 0))
1655 else if ((insn & 0xf0000000) != 0xe0000000)
1656 break; /* Condition not true, exit early. */
1657 else if (arm_instruction_changes_pc (insn))
1658 /* Don't scan past anything that might change control flow. */
1660 else if (arm_instruction_restores_sp (insn))
1662 /* Don't scan past the epilogue. */
1665 else if ((insn & 0xfe500000) == 0xe8100000 /* ldm */
1666 && pv_is_register (regs[bits (insn, 16, 19)], ARM_SP_REGNUM))
1667 /* Ignore block loads from the stack, potentially copying
1668 parameters from memory. */
1670 else if ((insn & 0xfc500000) == 0xe4100000
1671 && pv_is_register (regs[bits (insn, 16, 19)], ARM_SP_REGNUM))
1672 /* Similarly ignore single loads from the stack. */
1674 else if ((insn & 0xffff0ff0) == 0xe1a00000)
1675 /* MOV Rd, Rm. Skip register copies, i.e. saves to another
1676 register instead of the stack. */
1680 /* The optimizer might shove anything into the prologue, if
1681 we build up cache (cache != NULL) from scanning prologue,
1682 we just skip what we don't recognize and scan further to
1683 make cache as complete as possible. However, if we skip
1684 prologue, we'll stop immediately on unrecognized
1686 unrecognized_pc = current_pc;
1694 if (unrecognized_pc == 0)
1695 unrecognized_pc = current_pc;
1699 int framereg, framesize;
1701 /* The frame size is just the distance from the frame register
1702 to the original stack pointer. */
1703 if (pv_is_register (regs[ARM_FP_REGNUM], ARM_SP_REGNUM))
1705 /* Frame pointer is fp. */
1706 framereg = ARM_FP_REGNUM;
1707 framesize = -regs[ARM_FP_REGNUM].k;
1711 /* Try the stack pointer... this is a bit desperate. */
1712 framereg = ARM_SP_REGNUM;
1713 framesize = -regs[ARM_SP_REGNUM].k;
1716 cache->framereg = framereg;
1717 cache->framesize = framesize;
1719 for (regno = 0; regno < ARM_FPS_REGNUM; regno++)
1720 if (stack.find_reg (gdbarch, regno, &offset))
1721 cache->saved_regs[regno].addr = offset;
1725 fprintf_unfiltered (gdb_stdlog, "Prologue scan stopped at %s\n",
1726 paddress (gdbarch, unrecognized_pc));
1728 return unrecognized_pc;
1732 arm_scan_prologue (struct frame_info *this_frame,
1733 struct arm_prologue_cache *cache)
1735 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1736 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1737 CORE_ADDR prologue_start, prologue_end;
1738 CORE_ADDR prev_pc = get_frame_pc (this_frame);
1739 CORE_ADDR block_addr = get_frame_address_in_block (this_frame);
1741 /* Assume there is no frame until proven otherwise. */
1742 cache->framereg = ARM_SP_REGNUM;
1743 cache->framesize = 0;
1745 /* Check for Thumb prologue. */
1746 if (arm_frame_is_thumb (this_frame))
1748 thumb_scan_prologue (gdbarch, prev_pc, block_addr, cache);
1752 /* Find the function prologue. If we can't find the function in
1753 the symbol table, peek in the stack frame to find the PC. */
1754 if (find_pc_partial_function (block_addr, NULL, &prologue_start,
1757 /* One way to find the end of the prologue (which works well
1758 for unoptimized code) is to do the following:
1760 struct symtab_and_line sal = find_pc_line (prologue_start, 0);
1763 prologue_end = prev_pc;
1764 else if (sal.end < prologue_end)
1765 prologue_end = sal.end;
1767 This mechanism is very accurate so long as the optimizer
1768 doesn't move any instructions from the function body into the
1769 prologue. If this happens, sal.end will be the last
1770 instruction in the first hunk of prologue code just before
1771 the first instruction that the scheduler has moved from
1772 the body to the prologue.
1774 In order to make sure that we scan all of the prologue
1775 instructions, we use a slightly less accurate mechanism which
1776 may scan more than necessary. To help compensate for this
1777 lack of accuracy, the prologue scanning loop below contains
1778 several clauses which'll cause the loop to terminate early if
1779 an implausible prologue instruction is encountered.
1785 is a suitable endpoint since it accounts for the largest
1786 possible prologue plus up to five instructions inserted by
1789 if (prologue_end > prologue_start + 64)
1791 prologue_end = prologue_start + 64; /* See above. */
1796 /* We have no symbol information. Our only option is to assume this
1797 function has a standard stack frame and the normal frame register.
1798 Then, we can find the value of our frame pointer on entrance to
1799 the callee (or at the present moment if this is the innermost frame).
1800 The value stored there should be the address of the stmfd + 8. */
1801 CORE_ADDR frame_loc;
1802 ULONGEST return_value;
1804 /* AAPCS does not use a frame register, so we can abort here. */
1805 if (gdbarch_tdep (gdbarch)->arm_abi == ARM_ABI_AAPCS)
1808 frame_loc = get_frame_register_unsigned (this_frame, ARM_FP_REGNUM);
1809 if (!safe_read_memory_unsigned_integer (frame_loc, 4, byte_order,
1814 prologue_start = gdbarch_addr_bits_remove
1815 (gdbarch, return_value) - 8;
1816 prologue_end = prologue_start + 64; /* See above. */
1820 if (prev_pc < prologue_end)
1821 prologue_end = prev_pc;
1823 arm_analyze_prologue (gdbarch, prologue_start, prologue_end, cache);
1826 static struct arm_prologue_cache *
1827 arm_make_prologue_cache (struct frame_info *this_frame)
1830 struct arm_prologue_cache *cache;
1831 CORE_ADDR unwound_fp;
1833 cache = FRAME_OBSTACK_ZALLOC (struct arm_prologue_cache);
1834 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
1836 arm_scan_prologue (this_frame, cache);
1838 unwound_fp = get_frame_register_unsigned (this_frame, cache->framereg);
1839 if (unwound_fp == 0)
1842 cache->prev_sp = unwound_fp + cache->framesize;
1844 /* Calculate actual addresses of saved registers using offsets
1845 determined by arm_scan_prologue. */
1846 for (reg = 0; reg < gdbarch_num_regs (get_frame_arch (this_frame)); reg++)
1847 if (trad_frame_addr_p (cache->saved_regs, reg))
1848 cache->saved_regs[reg].addr += cache->prev_sp;
1853 /* Implementation of the stop_reason hook for arm_prologue frames. */
1855 static enum unwind_stop_reason
1856 arm_prologue_unwind_stop_reason (struct frame_info *this_frame,
1859 struct arm_prologue_cache *cache;
1862 if (*this_cache == NULL)
1863 *this_cache = arm_make_prologue_cache (this_frame);
1864 cache = (struct arm_prologue_cache *) *this_cache;
1866 /* This is meant to halt the backtrace at "_start". */
1867 pc = get_frame_pc (this_frame);
1868 if (pc <= gdbarch_tdep (get_frame_arch (this_frame))->lowest_pc)
1869 return UNWIND_OUTERMOST;
1871 /* If we've hit a wall, stop. */
1872 if (cache->prev_sp == 0)
1873 return UNWIND_OUTERMOST;
1875 return UNWIND_NO_REASON;
1878 /* Our frame ID for a normal frame is the current function's starting PC
1879 and the caller's SP when we were called. */
1882 arm_prologue_this_id (struct frame_info *this_frame,
1884 struct frame_id *this_id)
1886 struct arm_prologue_cache *cache;
1890 if (*this_cache == NULL)
1891 *this_cache = arm_make_prologue_cache (this_frame);
1892 cache = (struct arm_prologue_cache *) *this_cache;
1894 /* Use function start address as part of the frame ID. If we cannot
1895 identify the start address (due to missing symbol information),
1896 fall back to just using the current PC. */
1897 pc = get_frame_pc (this_frame);
1898 func = get_frame_func (this_frame);
1902 id = frame_id_build (cache->prev_sp, func);
1906 static struct value *
1907 arm_prologue_prev_register (struct frame_info *this_frame,
1911 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1912 struct arm_prologue_cache *cache;
1914 if (*this_cache == NULL)
1915 *this_cache = arm_make_prologue_cache (this_frame);
1916 cache = (struct arm_prologue_cache *) *this_cache;
1918 /* If we are asked to unwind the PC, then we need to return the LR
1919 instead. The prologue may save PC, but it will point into this
1920 frame's prologue, not the next frame's resume location. Also
1921 strip the saved T bit. A valid LR may have the low bit set, but
1922 a valid PC never does. */
1923 if (prev_regnum == ARM_PC_REGNUM)
1927 lr = frame_unwind_register_unsigned (this_frame, ARM_LR_REGNUM);
1928 return frame_unwind_got_constant (this_frame, prev_regnum,
1929 arm_addr_bits_remove (gdbarch, lr));
1932 /* SP is generally not saved to the stack, but this frame is
1933 identified by the next frame's stack pointer at the time of the call.
1934 The value was already reconstructed into PREV_SP. */
1935 if (prev_regnum == ARM_SP_REGNUM)
1936 return frame_unwind_got_constant (this_frame, prev_regnum, cache->prev_sp);
1938 /* The CPSR may have been changed by the call instruction and by the
1939 called function. The only bit we can reconstruct is the T bit,
1940 by checking the low bit of LR as of the call. This is a reliable
1941 indicator of Thumb-ness except for some ARM v4T pre-interworking
1942 Thumb code, which could get away with a clear low bit as long as
1943 the called function did not use bx. Guess that all other
1944 bits are unchanged; the condition flags are presumably lost,
1945 but the processor status is likely valid. */
1946 if (prev_regnum == ARM_PS_REGNUM)
1949 ULONGEST t_bit = arm_psr_thumb_bit (gdbarch);
1951 cpsr = get_frame_register_unsigned (this_frame, prev_regnum);
1952 lr = frame_unwind_register_unsigned (this_frame, ARM_LR_REGNUM);
1953 if (IS_THUMB_ADDR (lr))
1957 return frame_unwind_got_constant (this_frame, prev_regnum, cpsr);
1960 return trad_frame_get_prev_register (this_frame, cache->saved_regs,
1964 struct frame_unwind arm_prologue_unwind = {
1966 arm_prologue_unwind_stop_reason,
1967 arm_prologue_this_id,
1968 arm_prologue_prev_register,
1970 default_frame_sniffer
1973 /* Maintain a list of ARM exception table entries per objfile, similar to the
1974 list of mapping symbols. We only cache entries for standard ARM-defined
1975 personality routines; the cache will contain only the frame unwinding
1976 instructions associated with the entry (not the descriptors). */
1978 static const struct objfile_data *arm_exidx_data_key;
1980 struct arm_exidx_entry
1985 typedef struct arm_exidx_entry arm_exidx_entry_s;
1986 DEF_VEC_O(arm_exidx_entry_s);
1988 struct arm_exidx_data
1990 VEC(arm_exidx_entry_s) **section_maps;
1994 arm_exidx_data_free (struct objfile *objfile, void *arg)
1996 struct arm_exidx_data *data = (struct arm_exidx_data *) arg;
1999 for (i = 0; i < objfile->obfd->section_count; i++)
2000 VEC_free (arm_exidx_entry_s, data->section_maps[i]);
2004 arm_compare_exidx_entries (const struct arm_exidx_entry *lhs,
2005 const struct arm_exidx_entry *rhs)
2007 return lhs->addr < rhs->addr;
2010 static struct obj_section *
2011 arm_obj_section_from_vma (struct objfile *objfile, bfd_vma vma)
2013 struct obj_section *osect;
2015 ALL_OBJFILE_OSECTIONS (objfile, osect)
2016 if (bfd_get_section_flags (objfile->obfd,
2017 osect->the_bfd_section) & SEC_ALLOC)
2019 bfd_vma start, size;
2020 start = bfd_get_section_vma (objfile->obfd, osect->the_bfd_section);
2021 size = bfd_get_section_size (osect->the_bfd_section);
2023 if (start <= vma && vma < start + size)
2030 /* Parse contents of exception table and exception index sections
2031 of OBJFILE, and fill in the exception table entry cache.
2033 For each entry that refers to a standard ARM-defined personality
2034 routine, extract the frame unwinding instructions (from either
2035 the index or the table section). The unwinding instructions
2037 - extracting them from the rest of the table data
2038 - converting to host endianness
2039 - appending the implicit 0xb0 ("Finish") code
2041 The extracted and normalized instructions are stored for later
2042 retrieval by the arm_find_exidx_entry routine. */
2045 arm_exidx_new_objfile (struct objfile *objfile)
2047 struct arm_exidx_data *data;
2048 asection *exidx, *extab;
2049 bfd_vma exidx_vma = 0, extab_vma = 0;
2052 /* If we've already touched this file, do nothing. */
2053 if (!objfile || objfile_data (objfile, arm_exidx_data_key) != NULL)
2056 /* Read contents of exception table and index. */
2057 exidx = bfd_get_section_by_name (objfile->obfd, ELF_STRING_ARM_unwind);
2058 gdb::byte_vector exidx_data;
2061 exidx_vma = bfd_section_vma (objfile->obfd, exidx);
2062 exidx_data.resize (bfd_get_section_size (exidx));
2064 if (!bfd_get_section_contents (objfile->obfd, exidx,
2065 exidx_data.data (), 0,
2066 exidx_data.size ()))
2070 extab = bfd_get_section_by_name (objfile->obfd, ".ARM.extab");
2071 gdb::byte_vector extab_data;
2074 extab_vma = bfd_section_vma (objfile->obfd, extab);
2075 extab_data.resize (bfd_get_section_size (extab));
2077 if (!bfd_get_section_contents (objfile->obfd, extab,
2078 extab_data.data (), 0,
2079 extab_data.size ()))
2083 /* Allocate exception table data structure. */
2084 data = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct arm_exidx_data);
2085 set_objfile_data (objfile, arm_exidx_data_key, data);
2086 data->section_maps = OBSTACK_CALLOC (&objfile->objfile_obstack,
2087 objfile->obfd->section_count,
2088 VEC(arm_exidx_entry_s) *);
2090 /* Fill in exception table. */
2091 for (i = 0; i < exidx_data.size () / 8; i++)
2093 struct arm_exidx_entry new_exidx_entry;
2094 bfd_vma idx = bfd_h_get_32 (objfile->obfd, exidx_data.data () + i * 8);
2095 bfd_vma val = bfd_h_get_32 (objfile->obfd,
2096 exidx_data.data () + i * 8 + 4);
2097 bfd_vma addr = 0, word = 0;
2098 int n_bytes = 0, n_words = 0;
2099 struct obj_section *sec;
2100 gdb_byte *entry = NULL;
2102 /* Extract address of start of function. */
2103 idx = ((idx & 0x7fffffff) ^ 0x40000000) - 0x40000000;
2104 idx += exidx_vma + i * 8;
2106 /* Find section containing function and compute section offset. */
2107 sec = arm_obj_section_from_vma (objfile, idx);
2110 idx -= bfd_get_section_vma (objfile->obfd, sec->the_bfd_section);
2112 /* Determine address of exception table entry. */
2115 /* EXIDX_CANTUNWIND -- no exception table entry present. */
2117 else if ((val & 0xff000000) == 0x80000000)
2119 /* Exception table entry embedded in .ARM.exidx
2120 -- must be short form. */
2124 else if (!(val & 0x80000000))
2126 /* Exception table entry in .ARM.extab. */
2127 addr = ((val & 0x7fffffff) ^ 0x40000000) - 0x40000000;
2128 addr += exidx_vma + i * 8 + 4;
2130 if (addr >= extab_vma && addr + 4 <= extab_vma + extab_data.size ())
2132 word = bfd_h_get_32 (objfile->obfd,
2133 extab_data.data () + addr - extab_vma);
2136 if ((word & 0xff000000) == 0x80000000)
2141 else if ((word & 0xff000000) == 0x81000000
2142 || (word & 0xff000000) == 0x82000000)
2146 n_words = ((word >> 16) & 0xff);
2148 else if (!(word & 0x80000000))
2151 struct obj_section *pers_sec;
2152 int gnu_personality = 0;
2154 /* Custom personality routine. */
2155 pers = ((word & 0x7fffffff) ^ 0x40000000) - 0x40000000;
2156 pers = UNMAKE_THUMB_ADDR (pers + addr - 4);
2158 /* Check whether we've got one of the variants of the
2159 GNU personality routines. */
2160 pers_sec = arm_obj_section_from_vma (objfile, pers);
2163 static const char *personality[] =
2165 "__gcc_personality_v0",
2166 "__gxx_personality_v0",
2167 "__gcj_personality_v0",
2168 "__gnu_objc_personality_v0",
2172 CORE_ADDR pc = pers + obj_section_offset (pers_sec);
2175 for (k = 0; personality[k]; k++)
2176 if (lookup_minimal_symbol_by_pc_name
2177 (pc, personality[k], objfile))
2179 gnu_personality = 1;
2184 /* If so, the next word contains a word count in the high
2185 byte, followed by the same unwind instructions as the
2186 pre-defined forms. */
2188 && addr + 4 <= extab_vma + extab_data.size ())
2190 word = bfd_h_get_32 (objfile->obfd,
2192 + addr - extab_vma));
2195 n_words = ((word >> 24) & 0xff);
2201 /* Sanity check address. */
2203 if (addr < extab_vma
2204 || addr + 4 * n_words > extab_vma + extab_data.size ())
2205 n_words = n_bytes = 0;
2207 /* The unwind instructions reside in WORD (only the N_BYTES least
2208 significant bytes are valid), followed by N_WORDS words in the
2209 extab section starting at ADDR. */
2210 if (n_bytes || n_words)
2213 = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack,
2214 n_bytes + n_words * 4 + 1);
2217 *p++ = (gdb_byte) ((word >> (8 * n_bytes)) & 0xff);
2221 word = bfd_h_get_32 (objfile->obfd,
2222 extab_data.data () + addr - extab_vma);
2225 *p++ = (gdb_byte) ((word >> 24) & 0xff);
2226 *p++ = (gdb_byte) ((word >> 16) & 0xff);
2227 *p++ = (gdb_byte) ((word >> 8) & 0xff);
2228 *p++ = (gdb_byte) (word & 0xff);
2231 /* Implied "Finish" to terminate the list. */
2235 /* Push entry onto vector. They are guaranteed to always
2236 appear in order of increasing addresses. */
2237 new_exidx_entry.addr = idx;
2238 new_exidx_entry.entry = entry;
2239 VEC_safe_push (arm_exidx_entry_s,
2240 data->section_maps[sec->the_bfd_section->index],
2245 /* Search for the exception table entry covering MEMADDR. If one is found,
2246 return a pointer to its data. Otherwise, return 0. If START is non-NULL,
2247 set *START to the start of the region covered by this entry. */
2250 arm_find_exidx_entry (CORE_ADDR memaddr, CORE_ADDR *start)
2252 struct obj_section *sec;
2254 sec = find_pc_section (memaddr);
2257 struct arm_exidx_data *data;
2258 VEC(arm_exidx_entry_s) *map;
2259 struct arm_exidx_entry map_key = { memaddr - obj_section_addr (sec), 0 };
2262 data = ((struct arm_exidx_data *)
2263 objfile_data (sec->objfile, arm_exidx_data_key));
2266 map = data->section_maps[sec->the_bfd_section->index];
2267 if (!VEC_empty (arm_exidx_entry_s, map))
2269 struct arm_exidx_entry *map_sym;
2271 idx = VEC_lower_bound (arm_exidx_entry_s, map, &map_key,
2272 arm_compare_exidx_entries);
2274 /* VEC_lower_bound finds the earliest ordered insertion
2275 point. If the following symbol starts at this exact
2276 address, we use that; otherwise, the preceding
2277 exception table entry covers this address. */
2278 if (idx < VEC_length (arm_exidx_entry_s, map))
2280 map_sym = VEC_index (arm_exidx_entry_s, map, idx);
2281 if (map_sym->addr == map_key.addr)
2284 *start = map_sym->addr + obj_section_addr (sec);
2285 return map_sym->entry;
2291 map_sym = VEC_index (arm_exidx_entry_s, map, idx - 1);
2293 *start = map_sym->addr + obj_section_addr (sec);
2294 return map_sym->entry;
2303 /* Given the current frame THIS_FRAME, and its associated frame unwinding
2304 instruction list from the ARM exception table entry ENTRY, allocate and
2305 return a prologue cache structure describing how to unwind this frame.
2307 Return NULL if the unwinding instruction list contains a "spare",
2308 "reserved" or "refuse to unwind" instruction as defined in section
2309 "9.3 Frame unwinding instructions" of the "Exception Handling ABI
2310 for the ARM Architecture" document. */
2312 static struct arm_prologue_cache *
2313 arm_exidx_fill_cache (struct frame_info *this_frame, gdb_byte *entry)
2318 struct arm_prologue_cache *cache;
2319 cache = FRAME_OBSTACK_ZALLOC (struct arm_prologue_cache);
2320 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
2326 /* Whenever we reload SP, we actually have to retrieve its
2327 actual value in the current frame. */
2330 if (trad_frame_realreg_p (cache->saved_regs, ARM_SP_REGNUM))
2332 int reg = cache->saved_regs[ARM_SP_REGNUM].realreg;
2333 vsp = get_frame_register_unsigned (this_frame, reg);
2337 CORE_ADDR addr = cache->saved_regs[ARM_SP_REGNUM].addr;
2338 vsp = get_frame_memory_unsigned (this_frame, addr, 4);
2344 /* Decode next unwind instruction. */
2347 if ((insn & 0xc0) == 0)
2349 int offset = insn & 0x3f;
2350 vsp += (offset << 2) + 4;
2352 else if ((insn & 0xc0) == 0x40)
2354 int offset = insn & 0x3f;
2355 vsp -= (offset << 2) + 4;
2357 else if ((insn & 0xf0) == 0x80)
2359 int mask = ((insn & 0xf) << 8) | *entry++;
2362 /* The special case of an all-zero mask identifies
2363 "Refuse to unwind". We return NULL to fall back
2364 to the prologue analyzer. */
2368 /* Pop registers r4..r15 under mask. */
2369 for (i = 0; i < 12; i++)
2370 if (mask & (1 << i))
2372 cache->saved_regs[4 + i].addr = vsp;
2376 /* Special-case popping SP -- we need to reload vsp. */
2377 if (mask & (1 << (ARM_SP_REGNUM - 4)))
2380 else if ((insn & 0xf0) == 0x90)
2382 int reg = insn & 0xf;
2384 /* Reserved cases. */
2385 if (reg == ARM_SP_REGNUM || reg == ARM_PC_REGNUM)
2388 /* Set SP from another register and mark VSP for reload. */
2389 cache->saved_regs[ARM_SP_REGNUM] = cache->saved_regs[reg];
2392 else if ((insn & 0xf0) == 0xa0)
2394 int count = insn & 0x7;
2395 int pop_lr = (insn & 0x8) != 0;
2398 /* Pop r4..r[4+count]. */
2399 for (i = 0; i <= count; i++)
2401 cache->saved_regs[4 + i].addr = vsp;
2405 /* If indicated by flag, pop LR as well. */
2408 cache->saved_regs[ARM_LR_REGNUM].addr = vsp;
2412 else if (insn == 0xb0)
2414 /* We could only have updated PC by popping into it; if so, it
2415 will show up as address. Otherwise, copy LR into PC. */
2416 if (!trad_frame_addr_p (cache->saved_regs, ARM_PC_REGNUM))
2417 cache->saved_regs[ARM_PC_REGNUM]
2418 = cache->saved_regs[ARM_LR_REGNUM];
2423 else if (insn == 0xb1)
2425 int mask = *entry++;
2428 /* All-zero mask and mask >= 16 is "spare". */
2429 if (mask == 0 || mask >= 16)
2432 /* Pop r0..r3 under mask. */
2433 for (i = 0; i < 4; i++)
2434 if (mask & (1 << i))
2436 cache->saved_regs[i].addr = vsp;
2440 else if (insn == 0xb2)
2442 ULONGEST offset = 0;
2447 offset |= (*entry & 0x7f) << shift;
2450 while (*entry++ & 0x80);
2452 vsp += 0x204 + (offset << 2);
2454 else if (insn == 0xb3)
2456 int start = *entry >> 4;
2457 int count = (*entry++) & 0xf;
2460 /* Only registers D0..D15 are valid here. */
2461 if (start + count >= 16)
2464 /* Pop VFP double-precision registers D[start]..D[start+count]. */
2465 for (i = 0; i <= count; i++)
2467 cache->saved_regs[ARM_D0_REGNUM + start + i].addr = vsp;
2471 /* Add an extra 4 bytes for FSTMFDX-style stack. */
2474 else if ((insn & 0xf8) == 0xb8)
2476 int count = insn & 0x7;
2479 /* Pop VFP double-precision registers D[8]..D[8+count]. */
2480 for (i = 0; i <= count; i++)
2482 cache->saved_regs[ARM_D0_REGNUM + 8 + i].addr = vsp;
2486 /* Add an extra 4 bytes for FSTMFDX-style stack. */
2489 else if (insn == 0xc6)
2491 int start = *entry >> 4;
2492 int count = (*entry++) & 0xf;
2495 /* Only registers WR0..WR15 are valid. */
2496 if (start + count >= 16)
2499 /* Pop iwmmx registers WR[start]..WR[start+count]. */
2500 for (i = 0; i <= count; i++)
2502 cache->saved_regs[ARM_WR0_REGNUM + start + i].addr = vsp;
2506 else if (insn == 0xc7)
2508 int mask = *entry++;
2511 /* All-zero mask and mask >= 16 is "spare". */
2512 if (mask == 0 || mask >= 16)
2515 /* Pop iwmmx general-purpose registers WCGR0..WCGR3 under mask. */
2516 for (i = 0; i < 4; i++)
2517 if (mask & (1 << i))
2519 cache->saved_regs[ARM_WCGR0_REGNUM + i].addr = vsp;
2523 else if ((insn & 0xf8) == 0xc0)
2525 int count = insn & 0x7;
2528 /* Pop iwmmx registers WR[10]..WR[10+count]. */
2529 for (i = 0; i <= count; i++)
2531 cache->saved_regs[ARM_WR0_REGNUM + 10 + i].addr = vsp;
2535 else if (insn == 0xc8)
2537 int start = *entry >> 4;
2538 int count = (*entry++) & 0xf;
2541 /* Only registers D0..D31 are valid. */
2542 if (start + count >= 16)
2545 /* Pop VFP double-precision registers
2546 D[16+start]..D[16+start+count]. */
2547 for (i = 0; i <= count; i++)
2549 cache->saved_regs[ARM_D0_REGNUM + 16 + start + i].addr = vsp;
2553 else if (insn == 0xc9)
2555 int start = *entry >> 4;
2556 int count = (*entry++) & 0xf;
2559 /* Pop VFP double-precision registers D[start]..D[start+count]. */
2560 for (i = 0; i <= count; i++)
2562 cache->saved_regs[ARM_D0_REGNUM + start + i].addr = vsp;
2566 else if ((insn & 0xf8) == 0xd0)
2568 int count = insn & 0x7;
2571 /* Pop VFP double-precision registers D[8]..D[8+count]. */
2572 for (i = 0; i <= count; i++)
2574 cache->saved_regs[ARM_D0_REGNUM + 8 + i].addr = vsp;
2580 /* Everything else is "spare". */
2585 /* If we restore SP from a register, assume this was the frame register.
2586 Otherwise just fall back to SP as frame register. */
2587 if (trad_frame_realreg_p (cache->saved_regs, ARM_SP_REGNUM))
2588 cache->framereg = cache->saved_regs[ARM_SP_REGNUM].realreg;
2590 cache->framereg = ARM_SP_REGNUM;
2592 /* Determine offset to previous frame. */
2594 = vsp - get_frame_register_unsigned (this_frame, cache->framereg);
2596 /* We already got the previous SP. */
2597 cache->prev_sp = vsp;
2602 /* Unwinding via ARM exception table entries. Note that the sniffer
2603 already computes a filled-in prologue cache, which is then used
2604 with the same arm_prologue_this_id and arm_prologue_prev_register
2605 routines also used for prologue-parsing based unwinding. */
2608 arm_exidx_unwind_sniffer (const struct frame_unwind *self,
2609 struct frame_info *this_frame,
2610 void **this_prologue_cache)
2612 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2613 enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
2614 CORE_ADDR addr_in_block, exidx_region, func_start;
2615 struct arm_prologue_cache *cache;
2618 /* See if we have an ARM exception table entry covering this address. */
2619 addr_in_block = get_frame_address_in_block (this_frame);
2620 entry = arm_find_exidx_entry (addr_in_block, &exidx_region);
2624 /* The ARM exception table does not describe unwind information
2625 for arbitrary PC values, but is guaranteed to be correct only
2626 at call sites. We have to decide here whether we want to use
2627 ARM exception table information for this frame, or fall back
2628 to using prologue parsing. (Note that if we have DWARF CFI,
2629 this sniffer isn't even called -- CFI is always preferred.)
2631 Before we make this decision, however, we check whether we
2632 actually have *symbol* information for the current frame.
2633 If not, prologue parsing would not work anyway, so we might
2634 as well use the exception table and hope for the best. */
2635 if (find_pc_partial_function (addr_in_block, NULL, &func_start, NULL))
2639 /* If the next frame is "normal", we are at a call site in this
2640 frame, so exception information is guaranteed to be valid. */
2641 if (get_next_frame (this_frame)
2642 && get_frame_type (get_next_frame (this_frame)) == NORMAL_FRAME)
2645 /* We also assume exception information is valid if we're currently
2646 blocked in a system call. The system library is supposed to
2647 ensure this, so that e.g. pthread cancellation works. */
2648 if (arm_frame_is_thumb (this_frame))
2652 if (safe_read_memory_unsigned_integer (get_frame_pc (this_frame) - 2,
2653 2, byte_order_for_code, &insn)
2654 && (insn & 0xff00) == 0xdf00 /* svc */)
2661 if (safe_read_memory_unsigned_integer (get_frame_pc (this_frame) - 4,
2662 4, byte_order_for_code, &insn)
2663 && (insn & 0x0f000000) == 0x0f000000 /* svc */)
2667 /* Bail out if we don't know that exception information is valid. */
2671 /* The ARM exception index does not mark the *end* of the region
2672 covered by the entry, and some functions will not have any entry.
2673 To correctly recognize the end of the covered region, the linker
2674 should have inserted dummy records with a CANTUNWIND marker.
2676 Unfortunately, current versions of GNU ld do not reliably do
2677 this, and thus we may have found an incorrect entry above.
2678 As a (temporary) sanity check, we only use the entry if it
2679 lies *within* the bounds of the function. Note that this check
2680 might reject perfectly valid entries that just happen to cover
2681 multiple functions; therefore this check ought to be removed
2682 once the linker is fixed. */
2683 if (func_start > exidx_region)
2687 /* Decode the list of unwinding instructions into a prologue cache.
2688 Note that this may fail due to e.g. a "refuse to unwind" code. */
2689 cache = arm_exidx_fill_cache (this_frame, entry);
2693 *this_prologue_cache = cache;
2697 struct frame_unwind arm_exidx_unwind = {
2699 default_frame_unwind_stop_reason,
2700 arm_prologue_this_id,
2701 arm_prologue_prev_register,
2703 arm_exidx_unwind_sniffer
2706 static struct arm_prologue_cache *
2707 arm_make_epilogue_frame_cache (struct frame_info *this_frame)
2709 struct arm_prologue_cache *cache;
2712 cache = FRAME_OBSTACK_ZALLOC (struct arm_prologue_cache);
2713 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
2715 /* Still rely on the offset calculated from prologue. */
2716 arm_scan_prologue (this_frame, cache);
2718 /* Since we are in epilogue, the SP has been restored. */
2719 cache->prev_sp = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM);
2721 /* Calculate actual addresses of saved registers using offsets
2722 determined by arm_scan_prologue. */
2723 for (reg = 0; reg < gdbarch_num_regs (get_frame_arch (this_frame)); reg++)
2724 if (trad_frame_addr_p (cache->saved_regs, reg))
2725 cache->saved_regs[reg].addr += cache->prev_sp;
2730 /* Implementation of function hook 'this_id' in
2731 'struct frame_uwnind' for epilogue unwinder. */
2734 arm_epilogue_frame_this_id (struct frame_info *this_frame,
2736 struct frame_id *this_id)
2738 struct arm_prologue_cache *cache;
2741 if (*this_cache == NULL)
2742 *this_cache = arm_make_epilogue_frame_cache (this_frame);
2743 cache = (struct arm_prologue_cache *) *this_cache;
2745 /* Use function start address as part of the frame ID. If we cannot
2746 identify the start address (due to missing symbol information),
2747 fall back to just using the current PC. */
2748 pc = get_frame_pc (this_frame);
2749 func = get_frame_func (this_frame);
2753 (*this_id) = frame_id_build (cache->prev_sp, pc);
2756 /* Implementation of function hook 'prev_register' in
2757 'struct frame_uwnind' for epilogue unwinder. */
2759 static struct value *
2760 arm_epilogue_frame_prev_register (struct frame_info *this_frame,
2761 void **this_cache, int regnum)
2763 if (*this_cache == NULL)
2764 *this_cache = arm_make_epilogue_frame_cache (this_frame);
2766 return arm_prologue_prev_register (this_frame, this_cache, regnum);
2769 static int arm_stack_frame_destroyed_p_1 (struct gdbarch *gdbarch,
2771 static int thumb_stack_frame_destroyed_p (struct gdbarch *gdbarch,
2774 /* Implementation of function hook 'sniffer' in
2775 'struct frame_uwnind' for epilogue unwinder. */
2778 arm_epilogue_frame_sniffer (const struct frame_unwind *self,
2779 struct frame_info *this_frame,
2780 void **this_prologue_cache)
2782 if (frame_relative_level (this_frame) == 0)
2784 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2785 CORE_ADDR pc = get_frame_pc (this_frame);
2787 if (arm_frame_is_thumb (this_frame))
2788 return thumb_stack_frame_destroyed_p (gdbarch, pc);
2790 return arm_stack_frame_destroyed_p_1 (gdbarch, pc);
2796 /* Frame unwinder from epilogue. */
2798 static const struct frame_unwind arm_epilogue_frame_unwind =
2801 default_frame_unwind_stop_reason,
2802 arm_epilogue_frame_this_id,
2803 arm_epilogue_frame_prev_register,
2805 arm_epilogue_frame_sniffer,
2808 /* Recognize GCC's trampoline for thumb call-indirect. If we are in a
2809 trampoline, return the target PC. Otherwise return 0.
2811 void call0a (char c, short s, int i, long l) {}
2815 (*pointer_to_call0a) (c, s, i, l);
2818 Instead of calling a stub library function _call_via_xx (xx is
2819 the register name), GCC may inline the trampoline in the object
2820 file as below (register r2 has the address of call0a).
2823 .type main, %function
2832 The trampoline 'bx r2' doesn't belong to main. */
2835 arm_skip_bx_reg (struct frame_info *frame, CORE_ADDR pc)
2837 /* The heuristics of recognizing such trampoline is that FRAME is
2838 executing in Thumb mode and the instruction on PC is 'bx Rm'. */
2839 if (arm_frame_is_thumb (frame))
2843 if (target_read_memory (pc, buf, 2) == 0)
2845 struct gdbarch *gdbarch = get_frame_arch (frame);
2846 enum bfd_endian byte_order_for_code
2847 = gdbarch_byte_order_for_code (gdbarch);
2849 = extract_unsigned_integer (buf, 2, byte_order_for_code);
2851 if ((insn & 0xff80) == 0x4700) /* bx <Rm> */
2854 = get_frame_register_unsigned (frame, bits (insn, 3, 6));
2856 /* Clear the LSB so that gdb core sets step-resume
2857 breakpoint at the right address. */
2858 return UNMAKE_THUMB_ADDR (dest);
2866 static struct arm_prologue_cache *
2867 arm_make_stub_cache (struct frame_info *this_frame)
2869 struct arm_prologue_cache *cache;
2871 cache = FRAME_OBSTACK_ZALLOC (struct arm_prologue_cache);
2872 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
2874 cache->prev_sp = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM);
2879 /* Our frame ID for a stub frame is the current SP and LR. */
2882 arm_stub_this_id (struct frame_info *this_frame,
2884 struct frame_id *this_id)
2886 struct arm_prologue_cache *cache;
2888 if (*this_cache == NULL)
2889 *this_cache = arm_make_stub_cache (this_frame);
2890 cache = (struct arm_prologue_cache *) *this_cache;
2892 *this_id = frame_id_build (cache->prev_sp, get_frame_pc (this_frame));
2896 arm_stub_unwind_sniffer (const struct frame_unwind *self,
2897 struct frame_info *this_frame,
2898 void **this_prologue_cache)
2900 CORE_ADDR addr_in_block;
2902 CORE_ADDR pc, start_addr;
2905 addr_in_block = get_frame_address_in_block (this_frame);
2906 pc = get_frame_pc (this_frame);
2907 if (in_plt_section (addr_in_block)
2908 /* We also use the stub winder if the target memory is unreadable
2909 to avoid having the prologue unwinder trying to read it. */
2910 || target_read_memory (pc, dummy, 4) != 0)
2913 if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0
2914 && arm_skip_bx_reg (this_frame, pc) != 0)
2920 struct frame_unwind arm_stub_unwind = {
2922 default_frame_unwind_stop_reason,
2924 arm_prologue_prev_register,
2926 arm_stub_unwind_sniffer
2929 /* Put here the code to store, into CACHE->saved_regs, the addresses
2930 of the saved registers of frame described by THIS_FRAME. CACHE is
2933 static struct arm_prologue_cache *
2934 arm_m_exception_cache (struct frame_info *this_frame)
2936 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2937 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2938 struct arm_prologue_cache *cache;
2939 CORE_ADDR unwound_sp;
2942 cache = FRAME_OBSTACK_ZALLOC (struct arm_prologue_cache);
2943 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
2945 unwound_sp = get_frame_register_unsigned (this_frame,
2948 /* The hardware saves eight 32-bit words, comprising xPSR,
2949 ReturnAddress, LR (R14), R12, R3, R2, R1, R0. See details in
2950 "B1.5.6 Exception entry behavior" in
2951 "ARMv7-M Architecture Reference Manual". */
2952 cache->saved_regs[0].addr = unwound_sp;
2953 cache->saved_regs[1].addr = unwound_sp + 4;
2954 cache->saved_regs[2].addr = unwound_sp + 8;
2955 cache->saved_regs[3].addr = unwound_sp + 12;
2956 cache->saved_regs[12].addr = unwound_sp + 16;
2957 cache->saved_regs[14].addr = unwound_sp + 20;
2958 cache->saved_regs[15].addr = unwound_sp + 24;
2959 cache->saved_regs[ARM_PS_REGNUM].addr = unwound_sp + 28;
2961 /* If bit 9 of the saved xPSR is set, then there is a four-byte
2962 aligner between the top of the 32-byte stack frame and the
2963 previous context's stack pointer. */
2964 cache->prev_sp = unwound_sp + 32;
2965 if (safe_read_memory_integer (unwound_sp + 28, 4, byte_order, &xpsr)
2966 && (xpsr & (1 << 9)) != 0)
2967 cache->prev_sp += 4;
2972 /* Implementation of function hook 'this_id' in
2973 'struct frame_uwnind'. */
2976 arm_m_exception_this_id (struct frame_info *this_frame,
2978 struct frame_id *this_id)
2980 struct arm_prologue_cache *cache;
2982 if (*this_cache == NULL)
2983 *this_cache = arm_m_exception_cache (this_frame);
2984 cache = (struct arm_prologue_cache *) *this_cache;
2986 /* Our frame ID for a stub frame is the current SP and LR. */
2987 *this_id = frame_id_build (cache->prev_sp,
2988 get_frame_pc (this_frame));
2991 /* Implementation of function hook 'prev_register' in
2992 'struct frame_uwnind'. */
2994 static struct value *
2995 arm_m_exception_prev_register (struct frame_info *this_frame,
2999 struct arm_prologue_cache *cache;
3001 if (*this_cache == NULL)
3002 *this_cache = arm_m_exception_cache (this_frame);
3003 cache = (struct arm_prologue_cache *) *this_cache;
3005 /* The value was already reconstructed into PREV_SP. */
3006 if (prev_regnum == ARM_SP_REGNUM)
3007 return frame_unwind_got_constant (this_frame, prev_regnum,
3010 return trad_frame_get_prev_register (this_frame, cache->saved_regs,
3014 /* Implementation of function hook 'sniffer' in
3015 'struct frame_uwnind'. */
3018 arm_m_exception_unwind_sniffer (const struct frame_unwind *self,
3019 struct frame_info *this_frame,
3020 void **this_prologue_cache)
3022 CORE_ADDR this_pc = get_frame_pc (this_frame);
3024 /* No need to check is_m; this sniffer is only registered for
3025 M-profile architectures. */
3027 /* Check if exception frame returns to a magic PC value. */
3028 return arm_m_addr_is_magic (this_pc);
3031 /* Frame unwinder for M-profile exceptions. */
3033 struct frame_unwind arm_m_exception_unwind =
3036 default_frame_unwind_stop_reason,
3037 arm_m_exception_this_id,
3038 arm_m_exception_prev_register,
3040 arm_m_exception_unwind_sniffer
3044 arm_normal_frame_base (struct frame_info *this_frame, void **this_cache)
3046 struct arm_prologue_cache *cache;
3048 if (*this_cache == NULL)
3049 *this_cache = arm_make_prologue_cache (this_frame);
3050 cache = (struct arm_prologue_cache *) *this_cache;
3052 return cache->prev_sp - cache->framesize;
3055 struct frame_base arm_normal_base = {
3056 &arm_prologue_unwind,
3057 arm_normal_frame_base,
3058 arm_normal_frame_base,
3059 arm_normal_frame_base
3062 static struct value *
3063 arm_dwarf2_prev_register (struct frame_info *this_frame, void **this_cache,
3066 struct gdbarch * gdbarch = get_frame_arch (this_frame);
3068 ULONGEST t_bit = arm_psr_thumb_bit (gdbarch);
3073 /* The PC is normally copied from the return column, which
3074 describes saves of LR. However, that version may have an
3075 extra bit set to indicate Thumb state. The bit is not
3077 lr = frame_unwind_register_unsigned (this_frame, ARM_LR_REGNUM);
3078 return frame_unwind_got_constant (this_frame, regnum,
3079 arm_addr_bits_remove (gdbarch, lr));
3082 /* Reconstruct the T bit; see arm_prologue_prev_register for details. */
3083 cpsr = get_frame_register_unsigned (this_frame, regnum);
3084 lr = frame_unwind_register_unsigned (this_frame, ARM_LR_REGNUM);
3085 if (IS_THUMB_ADDR (lr))
3089 return frame_unwind_got_constant (this_frame, regnum, cpsr);
3092 internal_error (__FILE__, __LINE__,
3093 _("Unexpected register %d"), regnum);
3098 arm_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
3099 struct dwarf2_frame_state_reg *reg,
3100 struct frame_info *this_frame)
3106 reg->how = DWARF2_FRAME_REG_FN;
3107 reg->loc.fn = arm_dwarf2_prev_register;
3110 reg->how = DWARF2_FRAME_REG_CFA;
3115 /* Implement the stack_frame_destroyed_p gdbarch method. */
3118 thumb_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
3120 enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
3121 unsigned int insn, insn2;
3122 int found_return = 0, found_stack_adjust = 0;
3123 CORE_ADDR func_start, func_end;
3127 if (!find_pc_partial_function (pc, NULL, &func_start, &func_end))
3130 /* The epilogue is a sequence of instructions along the following lines:
3132 - add stack frame size to SP or FP
3133 - [if frame pointer used] restore SP from FP
3134 - restore registers from SP [may include PC]
3135 - a return-type instruction [if PC wasn't already restored]
3137 In a first pass, we scan forward from the current PC and verify the
3138 instructions we find as compatible with this sequence, ending in a
3141 However, this is not sufficient to distinguish indirect function calls
3142 within a function from indirect tail calls in the epilogue in some cases.
3143 Therefore, if we didn't already find any SP-changing instruction during
3144 forward scan, we add a backward scanning heuristic to ensure we actually
3145 are in the epilogue. */
3148 while (scan_pc < func_end && !found_return)
3150 if (target_read_memory (scan_pc, buf, 2))
3154 insn = extract_unsigned_integer (buf, 2, byte_order_for_code);
3156 if ((insn & 0xff80) == 0x4700) /* bx <Rm> */
3158 else if (insn == 0x46f7) /* mov pc, lr */
3160 else if (thumb_instruction_restores_sp (insn))
3162 if ((insn & 0xff00) == 0xbd00) /* pop <registers, PC> */
3165 else if (thumb_insn_size (insn) == 4) /* 32-bit Thumb-2 instruction */
3167 if (target_read_memory (scan_pc, buf, 2))
3171 insn2 = extract_unsigned_integer (buf, 2, byte_order_for_code);
3173 if (insn == 0xe8bd) /* ldm.w sp!, <registers> */
3175 if (insn2 & 0x8000) /* <registers> include PC. */
3178 else if (insn == 0xf85d /* ldr.w <Rt>, [sp], #4 */
3179 && (insn2 & 0x0fff) == 0x0b04)
3181 if ((insn2 & 0xf000) == 0xf000) /* <Rt> is PC. */
3184 else if ((insn & 0xffbf) == 0xecbd /* vldm sp!, <list> */
3185 && (insn2 & 0x0e00) == 0x0a00)
3197 /* Since any instruction in the epilogue sequence, with the possible
3198 exception of return itself, updates the stack pointer, we need to
3199 scan backwards for at most one instruction. Try either a 16-bit or
3200 a 32-bit instruction. This is just a heuristic, so we do not worry
3201 too much about false positives. */
3203 if (pc - 4 < func_start)
3205 if (target_read_memory (pc - 4, buf, 4))
3208 insn = extract_unsigned_integer (buf, 2, byte_order_for_code);
3209 insn2 = extract_unsigned_integer (buf + 2, 2, byte_order_for_code);
3211 if (thumb_instruction_restores_sp (insn2))
3212 found_stack_adjust = 1;
3213 else if (insn == 0xe8bd) /* ldm.w sp!, <registers> */
3214 found_stack_adjust = 1;
3215 else if (insn == 0xf85d /* ldr.w <Rt>, [sp], #4 */
3216 && (insn2 & 0x0fff) == 0x0b04)
3217 found_stack_adjust = 1;
3218 else if ((insn & 0xffbf) == 0xecbd /* vldm sp!, <list> */
3219 && (insn2 & 0x0e00) == 0x0a00)
3220 found_stack_adjust = 1;
3222 return found_stack_adjust;
3226 arm_stack_frame_destroyed_p_1 (struct gdbarch *gdbarch, CORE_ADDR pc)
3228 enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
3231 CORE_ADDR func_start, func_end;
3233 if (!find_pc_partial_function (pc, NULL, &func_start, &func_end))
3236 /* We are in the epilogue if the previous instruction was a stack
3237 adjustment and the next instruction is a possible return (bx, mov
3238 pc, or pop). We could have to scan backwards to find the stack
3239 adjustment, or forwards to find the return, but this is a decent
3240 approximation. First scan forwards. */
3243 insn = read_memory_unsigned_integer (pc, 4, byte_order_for_code);
3244 if (bits (insn, 28, 31) != INST_NV)
3246 if ((insn & 0x0ffffff0) == 0x012fff10)
3249 else if ((insn & 0x0ffffff0) == 0x01a0f000)
3252 else if ((insn & 0x0fff0000) == 0x08bd0000
3253 && (insn & 0x0000c000) != 0)
3254 /* POP (LDMIA), including PC or LR. */
3261 /* Scan backwards. This is just a heuristic, so do not worry about
3262 false positives from mode changes. */
3264 if (pc < func_start + 4)
3267 insn = read_memory_unsigned_integer (pc - 4, 4, byte_order_for_code);
3268 if (arm_instruction_restores_sp (insn))
3274 /* Implement the stack_frame_destroyed_p gdbarch method. */
3277 arm_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
3279 if (arm_pc_is_thumb (gdbarch, pc))
3280 return thumb_stack_frame_destroyed_p (gdbarch, pc);
3282 return arm_stack_frame_destroyed_p_1 (gdbarch, pc);
3285 /* When arguments must be pushed onto the stack, they go on in reverse
3286 order. The code below implements a FILO (stack) to do this. */
3291 struct stack_item *prev;
3295 static struct stack_item *
3296 push_stack_item (struct stack_item *prev, const gdb_byte *contents, int len)
3298 struct stack_item *si;
3299 si = XNEW (struct stack_item);
3300 si->data = (gdb_byte *) xmalloc (len);
3303 memcpy (si->data, contents, len);
3307 static struct stack_item *
3308 pop_stack_item (struct stack_item *si)
3310 struct stack_item *dead = si;
3318 /* Return the alignment (in bytes) of the given type. */
3321 arm_type_align (struct type *t)
3327 t = check_typedef (t);
3328 switch (TYPE_CODE (t))
3331 /* Should never happen. */
3332 internal_error (__FILE__, __LINE__, _("unknown type alignment"));
3336 case TYPE_CODE_ENUM:
3340 case TYPE_CODE_RANGE:
3342 case TYPE_CODE_RVALUE_REF:
3343 case TYPE_CODE_CHAR:
3344 case TYPE_CODE_BOOL:
3345 return TYPE_LENGTH (t);
3347 case TYPE_CODE_ARRAY:
3348 if (TYPE_VECTOR (t))
3350 /* Use the natural alignment for vector types (the same for
3351 scalar type), but the maximum alignment is 64-bit. */
3352 if (TYPE_LENGTH (t) > 8)
3355 return TYPE_LENGTH (t);
3358 return arm_type_align (TYPE_TARGET_TYPE (t));
3359 case TYPE_CODE_COMPLEX:
3360 return arm_type_align (TYPE_TARGET_TYPE (t));
3362 case TYPE_CODE_STRUCT:
3363 case TYPE_CODE_UNION:
3365 for (n = 0; n < TYPE_NFIELDS (t); n++)
3367 falign = arm_type_align (TYPE_FIELD_TYPE (t, n));
3375 /* Possible base types for a candidate for passing and returning in
3378 enum arm_vfp_cprc_base_type
3387 /* The length of one element of base type B. */
3390 arm_vfp_cprc_unit_length (enum arm_vfp_cprc_base_type b)
3394 case VFP_CPRC_SINGLE:
3396 case VFP_CPRC_DOUBLE:
3398 case VFP_CPRC_VEC64:
3400 case VFP_CPRC_VEC128:
3403 internal_error (__FILE__, __LINE__, _("Invalid VFP CPRC type: %d."),
3408 /* The character ('s', 'd' or 'q') for the type of VFP register used
3409 for passing base type B. */
3412 arm_vfp_cprc_reg_char (enum arm_vfp_cprc_base_type b)
3416 case VFP_CPRC_SINGLE:
3418 case VFP_CPRC_DOUBLE:
3420 case VFP_CPRC_VEC64:
3422 case VFP_CPRC_VEC128:
3425 internal_error (__FILE__, __LINE__, _("Invalid VFP CPRC type: %d."),
3430 /* Determine whether T may be part of a candidate for passing and
3431 returning in VFP registers, ignoring the limit on the total number
3432 of components. If *BASE_TYPE is VFP_CPRC_UNKNOWN, set it to the
3433 classification of the first valid component found; if it is not
3434 VFP_CPRC_UNKNOWN, all components must have the same classification
3435 as *BASE_TYPE. If it is found that T contains a type not permitted
3436 for passing and returning in VFP registers, a type differently
3437 classified from *BASE_TYPE, or two types differently classified
3438 from each other, return -1, otherwise return the total number of
3439 base-type elements found (possibly 0 in an empty structure or
3440 array). Vector types are not currently supported, matching the
3441 generic AAPCS support. */
3444 arm_vfp_cprc_sub_candidate (struct type *t,
3445 enum arm_vfp_cprc_base_type *base_type)
3447 t = check_typedef (t);
3448 switch (TYPE_CODE (t))
3451 switch (TYPE_LENGTH (t))
3454 if (*base_type == VFP_CPRC_UNKNOWN)
3455 *base_type = VFP_CPRC_SINGLE;
3456 else if (*base_type != VFP_CPRC_SINGLE)
3461 if (*base_type == VFP_CPRC_UNKNOWN)
3462 *base_type = VFP_CPRC_DOUBLE;
3463 else if (*base_type != VFP_CPRC_DOUBLE)
3472 case TYPE_CODE_COMPLEX:
3473 /* Arguments of complex T where T is one of the types float or
3474 double get treated as if they are implemented as:
3483 switch (TYPE_LENGTH (t))
3486 if (*base_type == VFP_CPRC_UNKNOWN)
3487 *base_type = VFP_CPRC_SINGLE;
3488 else if (*base_type != VFP_CPRC_SINGLE)
3493 if (*base_type == VFP_CPRC_UNKNOWN)
3494 *base_type = VFP_CPRC_DOUBLE;
3495 else if (*base_type != VFP_CPRC_DOUBLE)
3504 case TYPE_CODE_ARRAY:
3506 if (TYPE_VECTOR (t))
3508 /* A 64-bit or 128-bit containerized vector type are VFP
3510 switch (TYPE_LENGTH (t))
3513 if (*base_type == VFP_CPRC_UNKNOWN)
3514 *base_type = VFP_CPRC_VEC64;
3517 if (*base_type == VFP_CPRC_UNKNOWN)
3518 *base_type = VFP_CPRC_VEC128;
3529 count = arm_vfp_cprc_sub_candidate (TYPE_TARGET_TYPE (t),
3533 if (TYPE_LENGTH (t) == 0)
3535 gdb_assert (count == 0);
3538 else if (count == 0)
3540 unitlen = arm_vfp_cprc_unit_length (*base_type);
3541 gdb_assert ((TYPE_LENGTH (t) % unitlen) == 0);
3542 return TYPE_LENGTH (t) / unitlen;
3547 case TYPE_CODE_STRUCT:
3552 for (i = 0; i < TYPE_NFIELDS (t); i++)
3556 if (!field_is_static (&TYPE_FIELD (t, i)))
3557 sub_count = arm_vfp_cprc_sub_candidate (TYPE_FIELD_TYPE (t, i),
3559 if (sub_count == -1)
3563 if (TYPE_LENGTH (t) == 0)
3565 gdb_assert (count == 0);
3568 else if (count == 0)
3570 unitlen = arm_vfp_cprc_unit_length (*base_type);
3571 if (TYPE_LENGTH (t) != unitlen * count)
3576 case TYPE_CODE_UNION:
3581 for (i = 0; i < TYPE_NFIELDS (t); i++)
3583 int sub_count = arm_vfp_cprc_sub_candidate (TYPE_FIELD_TYPE (t, i),
3585 if (sub_count == -1)
3587 count = (count > sub_count ? count : sub_count);
3589 if (TYPE_LENGTH (t) == 0)
3591 gdb_assert (count == 0);
3594 else if (count == 0)
3596 unitlen = arm_vfp_cprc_unit_length (*base_type);
3597 if (TYPE_LENGTH (t) != unitlen * count)
3609 /* Determine whether T is a VFP co-processor register candidate (CPRC)
3610 if passed to or returned from a non-variadic function with the VFP
3611 ABI in effect. Return 1 if it is, 0 otherwise. If it is, set
3612 *BASE_TYPE to the base type for T and *COUNT to the number of
3613 elements of that base type before returning. */
3616 arm_vfp_call_candidate (struct type *t, enum arm_vfp_cprc_base_type *base_type,
3619 enum arm_vfp_cprc_base_type b = VFP_CPRC_UNKNOWN;
3620 int c = arm_vfp_cprc_sub_candidate (t, &b);
3621 if (c <= 0 || c > 4)
3628 /* Return 1 if the VFP ABI should be used for passing arguments to and
3629 returning values from a function of type FUNC_TYPE, 0
3633 arm_vfp_abi_for_function (struct gdbarch *gdbarch, struct type *func_type)
3635 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3636 /* Variadic functions always use the base ABI. Assume that functions
3637 without debug info are not variadic. */
3638 if (func_type && TYPE_VARARGS (check_typedef (func_type)))
3640 /* The VFP ABI is only supported as a variant of AAPCS. */
3641 if (tdep->arm_abi != ARM_ABI_AAPCS)
3643 return gdbarch_tdep (gdbarch)->fp_model == ARM_FLOAT_VFP;
3646 /* We currently only support passing parameters in integer registers, which
3647 conforms with GCC's default model, and VFP argument passing following
3648 the VFP variant of AAPCS. Several other variants exist and
3649 we should probably support some of them based on the selected ABI. */
3652 arm_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
3653 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
3654 struct value **args, CORE_ADDR sp,
3655 function_call_return_method return_method,
3656 CORE_ADDR struct_addr)
3658 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
3662 struct stack_item *si = NULL;
3665 unsigned vfp_regs_free = (1 << 16) - 1;
3667 /* Determine the type of this function and whether the VFP ABI
3669 ftype = check_typedef (value_type (function));
3670 if (TYPE_CODE (ftype) == TYPE_CODE_PTR)
3671 ftype = check_typedef (TYPE_TARGET_TYPE (ftype));
3672 use_vfp_abi = arm_vfp_abi_for_function (gdbarch, ftype);
3674 /* Set the return address. For the ARM, the return breakpoint is
3675 always at BP_ADDR. */
3676 if (arm_pc_is_thumb (gdbarch, bp_addr))
3678 regcache_cooked_write_unsigned (regcache, ARM_LR_REGNUM, bp_addr);
3680 /* Walk through the list of args and determine how large a temporary
3681 stack is required. Need to take care here as structs may be
3682 passed on the stack, and we have to push them. */
3685 argreg = ARM_A1_REGNUM;
3688 /* The struct_return pointer occupies the first parameter
3689 passing register. */
3690 if (return_method == return_method_struct)
3693 fprintf_unfiltered (gdb_stdlog, "struct return in %s = %s\n",
3694 gdbarch_register_name (gdbarch, argreg),
3695 paddress (gdbarch, struct_addr));
3696 regcache_cooked_write_unsigned (regcache, argreg, struct_addr);
3700 for (argnum = 0; argnum < nargs; argnum++)
3703 struct type *arg_type;
3704 struct type *target_type;
3705 enum type_code typecode;
3706 const bfd_byte *val;
3708 enum arm_vfp_cprc_base_type vfp_base_type;
3710 int may_use_core_reg = 1;
3712 arg_type = check_typedef (value_type (args[argnum]));
3713 len = TYPE_LENGTH (arg_type);
3714 target_type = TYPE_TARGET_TYPE (arg_type);
3715 typecode = TYPE_CODE (arg_type);
3716 val = value_contents (args[argnum]);
3718 align = arm_type_align (arg_type);
3719 /* Round alignment up to a whole number of words. */
3720 align = (align + INT_REGISTER_SIZE - 1) & ~(INT_REGISTER_SIZE - 1);
3721 /* Different ABIs have different maximum alignments. */
3722 if (gdbarch_tdep (gdbarch)->arm_abi == ARM_ABI_APCS)
3724 /* The APCS ABI only requires word alignment. */
3725 align = INT_REGISTER_SIZE;
3729 /* The AAPCS requires at most doubleword alignment. */
3730 if (align > INT_REGISTER_SIZE * 2)
3731 align = INT_REGISTER_SIZE * 2;
3735 && arm_vfp_call_candidate (arg_type, &vfp_base_type,
3743 /* Because this is a CPRC it cannot go in a core register or
3744 cause a core register to be skipped for alignment.
3745 Either it goes in VFP registers and the rest of this loop
3746 iteration is skipped for this argument, or it goes on the
3747 stack (and the stack alignment code is correct for this
3749 may_use_core_reg = 0;
3751 unit_length = arm_vfp_cprc_unit_length (vfp_base_type);
3752 shift = unit_length / 4;
3753 mask = (1 << (shift * vfp_base_count)) - 1;
3754 for (regno = 0; regno < 16; regno += shift)
3755 if (((vfp_regs_free >> regno) & mask) == mask)
3764 vfp_regs_free &= ~(mask << regno);
3765 reg_scaled = regno / shift;
3766 reg_char = arm_vfp_cprc_reg_char (vfp_base_type);
3767 for (i = 0; i < vfp_base_count; i++)
3771 if (reg_char == 'q')
3772 arm_neon_quad_write (gdbarch, regcache, reg_scaled + i,
3773 val + i * unit_length);
3776 xsnprintf (name_buf, sizeof (name_buf), "%c%d",
3777 reg_char, reg_scaled + i);
3778 regnum = user_reg_map_name_to_regnum (gdbarch, name_buf,
3780 regcache->cooked_write (regnum, val + i * unit_length);
3787 /* This CPRC could not go in VFP registers, so all VFP
3788 registers are now marked as used. */
3793 /* Push stack padding for dowubleword alignment. */
3794 if (nstack & (align - 1))
3796 si = push_stack_item (si, val, INT_REGISTER_SIZE);
3797 nstack += INT_REGISTER_SIZE;
3800 /* Doubleword aligned quantities must go in even register pairs. */
3801 if (may_use_core_reg
3802 && argreg <= ARM_LAST_ARG_REGNUM
3803 && align > INT_REGISTER_SIZE
3807 /* If the argument is a pointer to a function, and it is a
3808 Thumb function, create a LOCAL copy of the value and set
3809 the THUMB bit in it. */
3810 if (TYPE_CODE_PTR == typecode
3811 && target_type != NULL
3812 && TYPE_CODE_FUNC == TYPE_CODE (check_typedef (target_type)))
3814 CORE_ADDR regval = extract_unsigned_integer (val, len, byte_order);
3815 if (arm_pc_is_thumb (gdbarch, regval))
3817 bfd_byte *copy = (bfd_byte *) alloca (len);
3818 store_unsigned_integer (copy, len, byte_order,
3819 MAKE_THUMB_ADDR (regval));
3824 /* Copy the argument to general registers or the stack in
3825 register-sized pieces. Large arguments are split between
3826 registers and stack. */
3829 int partial_len = len < INT_REGISTER_SIZE ? len : INT_REGISTER_SIZE;
3831 = extract_unsigned_integer (val, partial_len, byte_order);
3833 if (may_use_core_reg && argreg <= ARM_LAST_ARG_REGNUM)
3835 /* The argument is being passed in a general purpose
3837 if (byte_order == BFD_ENDIAN_BIG)
3838 regval <<= (INT_REGISTER_SIZE - partial_len) * 8;
3840 fprintf_unfiltered (gdb_stdlog, "arg %d in %s = 0x%s\n",
3842 gdbarch_register_name
3844 phex (regval, INT_REGISTER_SIZE));
3845 regcache_cooked_write_unsigned (regcache, argreg, regval);
3850 gdb_byte buf[INT_REGISTER_SIZE];
3852 memset (buf, 0, sizeof (buf));
3853 store_unsigned_integer (buf, partial_len, byte_order, regval);
3855 /* Push the arguments onto the stack. */
3857 fprintf_unfiltered (gdb_stdlog, "arg %d @ sp + %d\n",
3859 si = push_stack_item (si, buf, INT_REGISTER_SIZE);
3860 nstack += INT_REGISTER_SIZE;
3867 /* If we have an odd number of words to push, then decrement the stack
3868 by one word now, so first stack argument will be dword aligned. */
3875 write_memory (sp, si->data, si->len);
3876 si = pop_stack_item (si);
3879 /* Finally, update teh SP register. */
3880 regcache_cooked_write_unsigned (regcache, ARM_SP_REGNUM, sp);
3886 /* Always align the frame to an 8-byte boundary. This is required on
3887 some platforms and harmless on the rest. */
3890 arm_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
3892 /* Align the stack to eight bytes. */
3893 return sp & ~ (CORE_ADDR) 7;
3897 print_fpu_flags (struct ui_file *file, int flags)
3899 if (flags & (1 << 0))
3900 fputs_filtered ("IVO ", file);
3901 if (flags & (1 << 1))
3902 fputs_filtered ("DVZ ", file);
3903 if (flags & (1 << 2))
3904 fputs_filtered ("OFL ", file);
3905 if (flags & (1 << 3))
3906 fputs_filtered ("UFL ", file);
3907 if (flags & (1 << 4))
3908 fputs_filtered ("INX ", file);
3909 fputc_filtered ('\n', file);
3912 /* Print interesting information about the floating point processor
3913 (if present) or emulator. */
3915 arm_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
3916 struct frame_info *frame, const char *args)
3918 unsigned long status = get_frame_register_unsigned (frame, ARM_FPS_REGNUM);
3921 type = (status >> 24) & 127;
3922 if (status & (1 << 31))
3923 fprintf_filtered (file, _("Hardware FPU type %d\n"), type);
3925 fprintf_filtered (file, _("Software FPU type %d\n"), type);
3926 /* i18n: [floating point unit] mask */
3927 fputs_filtered (_("mask: "), file);
3928 print_fpu_flags (file, status >> 16);
3929 /* i18n: [floating point unit] flags */
3930 fputs_filtered (_("flags: "), file);
3931 print_fpu_flags (file, status);
3934 /* Construct the ARM extended floating point type. */
3935 static struct type *
3936 arm_ext_type (struct gdbarch *gdbarch)
3938 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3940 if (!tdep->arm_ext_type)
3942 = arch_float_type (gdbarch, -1, "builtin_type_arm_ext",
3943 floatformats_arm_ext);
3945 return tdep->arm_ext_type;
3948 static struct type *
3949 arm_neon_double_type (struct gdbarch *gdbarch)
3951 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3953 if (tdep->neon_double_type == NULL)
3955 struct type *t, *elem;
3957 t = arch_composite_type (gdbarch, "__gdb_builtin_type_neon_d",
3959 elem = builtin_type (gdbarch)->builtin_uint8;
3960 append_composite_type_field (t, "u8", init_vector_type (elem, 8));
3961 elem = builtin_type (gdbarch)->builtin_uint16;
3962 append_composite_type_field (t, "u16", init_vector_type (elem, 4));
3963 elem = builtin_type (gdbarch)->builtin_uint32;
3964 append_composite_type_field (t, "u32", init_vector_type (elem, 2));
3965 elem = builtin_type (gdbarch)->builtin_uint64;
3966 append_composite_type_field (t, "u64", elem);
3967 elem = builtin_type (gdbarch)->builtin_float;
3968 append_composite_type_field (t, "f32", init_vector_type (elem, 2));
3969 elem = builtin_type (gdbarch)->builtin_double;
3970 append_composite_type_field (t, "f64", elem);
3972 TYPE_VECTOR (t) = 1;
3973 TYPE_NAME (t) = "neon_d";
3974 tdep->neon_double_type = t;
3977 return tdep->neon_double_type;
3980 /* FIXME: The vector types are not correctly ordered on big-endian
3981 targets. Just as s0 is the low bits of d0, d0[0] is also the low
3982 bits of d0 - regardless of what unit size is being held in d0. So
3983 the offset of the first uint8 in d0 is 7, but the offset of the
3984 first float is 4. This code works as-is for little-endian
3987 static struct type *
3988 arm_neon_quad_type (struct gdbarch *gdbarch)
3990 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3992 if (tdep->neon_quad_type == NULL)
3994 struct type *t, *elem;
3996 t = arch_composite_type (gdbarch, "__gdb_builtin_type_neon_q",
3998 elem = builtin_type (gdbarch)->builtin_uint8;
3999 append_composite_type_field (t, "u8", init_vector_type (elem, 16));
4000 elem = builtin_type (gdbarch)->builtin_uint16;
4001 append_composite_type_field (t, "u16", init_vector_type (elem, 8));
4002 elem = builtin_type (gdbarch)->builtin_uint32;
4003 append_composite_type_field (t, "u32", init_vector_type (elem, 4));
4004 elem = builtin_type (gdbarch)->builtin_uint64;
4005 append_composite_type_field (t, "u64", init_vector_type (elem, 2));
4006 elem = builtin_type (gdbarch)->builtin_float;
4007 append_composite_type_field (t, "f32", init_vector_type (elem, 4));
4008 elem = builtin_type (gdbarch)->builtin_double;
4009 append_composite_type_field (t, "f64", init_vector_type (elem, 2));
4011 TYPE_VECTOR (t) = 1;
4012 TYPE_NAME (t) = "neon_q";
4013 tdep->neon_quad_type = t;
4016 return tdep->neon_quad_type;
4019 /* Return the GDB type object for the "standard" data type of data in
4022 static struct type *
4023 arm_register_type (struct gdbarch *gdbarch, int regnum)
4025 int num_regs = gdbarch_num_regs (gdbarch);
4027 if (gdbarch_tdep (gdbarch)->have_vfp_pseudos
4028 && regnum >= num_regs && regnum < num_regs + 32)
4029 return builtin_type (gdbarch)->builtin_float;
4031 if (gdbarch_tdep (gdbarch)->have_neon_pseudos
4032 && regnum >= num_regs + 32 && regnum < num_regs + 32 + 16)
4033 return arm_neon_quad_type (gdbarch);
4035 /* If the target description has register information, we are only
4036 in this function so that we can override the types of
4037 double-precision registers for NEON. */
4038 if (tdesc_has_registers (gdbarch_target_desc (gdbarch)))
4040 struct type *t = tdesc_register_type (gdbarch, regnum);
4042 if (regnum >= ARM_D0_REGNUM && regnum < ARM_D0_REGNUM + 32
4043 && TYPE_CODE (t) == TYPE_CODE_FLT
4044 && gdbarch_tdep (gdbarch)->have_neon)
4045 return arm_neon_double_type (gdbarch);
4050 if (regnum >= ARM_F0_REGNUM && regnum < ARM_F0_REGNUM + NUM_FREGS)
4052 if (!gdbarch_tdep (gdbarch)->have_fpa_registers)
4053 return builtin_type (gdbarch)->builtin_void;
4055 return arm_ext_type (gdbarch);
4057 else if (regnum == ARM_SP_REGNUM)
4058 return builtin_type (gdbarch)->builtin_data_ptr;
4059 else if (regnum == ARM_PC_REGNUM)
4060 return builtin_type (gdbarch)->builtin_func_ptr;
4061 else if (regnum >= ARRAY_SIZE (arm_register_names))
4062 /* These registers are only supported on targets which supply
4063 an XML description. */
4064 return builtin_type (gdbarch)->builtin_int0;
4066 return builtin_type (gdbarch)->builtin_uint32;
4069 /* Map a DWARF register REGNUM onto the appropriate GDB register
4073 arm_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
4075 /* Core integer regs. */
4076 if (reg >= 0 && reg <= 15)
4079 /* Legacy FPA encoding. These were once used in a way which
4080 overlapped with VFP register numbering, so their use is
4081 discouraged, but GDB doesn't support the ARM toolchain
4082 which used them for VFP. */
4083 if (reg >= 16 && reg <= 23)
4084 return ARM_F0_REGNUM + reg - 16;
4086 /* New assignments for the FPA registers. */
4087 if (reg >= 96 && reg <= 103)
4088 return ARM_F0_REGNUM + reg - 96;
4090 /* WMMX register assignments. */
4091 if (reg >= 104 && reg <= 111)
4092 return ARM_WCGR0_REGNUM + reg - 104;
4094 if (reg >= 112 && reg <= 127)
4095 return ARM_WR0_REGNUM + reg - 112;
4097 if (reg >= 192 && reg <= 199)
4098 return ARM_WC0_REGNUM + reg - 192;
4100 /* VFP v2 registers. A double precision value is actually
4101 in d1 rather than s2, but the ABI only defines numbering
4102 for the single precision registers. This will "just work"
4103 in GDB for little endian targets (we'll read eight bytes,
4104 starting in s0 and then progressing to s1), but will be
4105 reversed on big endian targets with VFP. This won't
4106 be a problem for the new Neon quad registers; you're supposed
4107 to use DW_OP_piece for those. */
4108 if (reg >= 64 && reg <= 95)
4112 xsnprintf (name_buf, sizeof (name_buf), "s%d", reg - 64);
4113 return user_reg_map_name_to_regnum (gdbarch, name_buf,
4117 /* VFP v3 / Neon registers. This range is also used for VFP v2
4118 registers, except that it now describes d0 instead of s0. */
4119 if (reg >= 256 && reg <= 287)
4123 xsnprintf (name_buf, sizeof (name_buf), "d%d", reg - 256);
4124 return user_reg_map_name_to_regnum (gdbarch, name_buf,
4131 /* Map GDB internal REGNUM onto the Arm simulator register numbers. */
4133 arm_register_sim_regno (struct gdbarch *gdbarch, int regnum)
4136 gdb_assert (reg >= 0 && reg < gdbarch_num_regs (gdbarch));
4138 if (regnum >= ARM_WR0_REGNUM && regnum <= ARM_WR15_REGNUM)
4139 return regnum - ARM_WR0_REGNUM + SIM_ARM_IWMMXT_COP0R0_REGNUM;
4141 if (regnum >= ARM_WC0_REGNUM && regnum <= ARM_WC7_REGNUM)
4142 return regnum - ARM_WC0_REGNUM + SIM_ARM_IWMMXT_COP1R0_REGNUM;
4144 if (regnum >= ARM_WCGR0_REGNUM && regnum <= ARM_WCGR7_REGNUM)
4145 return regnum - ARM_WCGR0_REGNUM + SIM_ARM_IWMMXT_COP1R8_REGNUM;
4147 if (reg < NUM_GREGS)
4148 return SIM_ARM_R0_REGNUM + reg;
4151 if (reg < NUM_FREGS)
4152 return SIM_ARM_FP0_REGNUM + reg;
4155 if (reg < NUM_SREGS)
4156 return SIM_ARM_FPS_REGNUM + reg;
4159 internal_error (__FILE__, __LINE__, _("Bad REGNUM %d"), regnum);
4162 /* Given BUF, which is OLD_LEN bytes ending at ENDADDR, expand
4163 the buffer to be NEW_LEN bytes ending at ENDADDR. Return
4164 NULL if an error occurs. BUF is freed. */
4167 extend_buffer_earlier (gdb_byte *buf, CORE_ADDR endaddr,
4168 int old_len, int new_len)
4171 int bytes_to_read = new_len - old_len;
4173 new_buf = (gdb_byte *) xmalloc (new_len);
4174 memcpy (new_buf + bytes_to_read, buf, old_len);
4176 if (target_read_code (endaddr - new_len, new_buf, bytes_to_read) != 0)
4184 /* An IT block is at most the 2-byte IT instruction followed by
4185 four 4-byte instructions. The furthest back we must search to
4186 find an IT block that affects the current instruction is thus
4187 2 + 3 * 4 == 14 bytes. */
4188 #define MAX_IT_BLOCK_PREFIX 14
4190 /* Use a quick scan if there are more than this many bytes of
4192 #define IT_SCAN_THRESHOLD 32
4194 /* Adjust a breakpoint's address to move breakpoints out of IT blocks.
4195 A breakpoint in an IT block may not be hit, depending on the
4198 arm_adjust_breakpoint_address (struct gdbarch *gdbarch, CORE_ADDR bpaddr)
4202 CORE_ADDR boundary, func_start;
4204 enum bfd_endian order = gdbarch_byte_order_for_code (gdbarch);
4205 int i, any, last_it, last_it_count;
4207 /* If we are using BKPT breakpoints, none of this is necessary. */
4208 if (gdbarch_tdep (gdbarch)->thumb2_breakpoint == NULL)
4211 /* ARM mode does not have this problem. */
4212 if (!arm_pc_is_thumb (gdbarch, bpaddr))
4215 /* We are setting a breakpoint in Thumb code that could potentially
4216 contain an IT block. The first step is to find how much Thumb
4217 code there is; we do not need to read outside of known Thumb
4219 map_type = arm_find_mapping_symbol (bpaddr, &boundary);
4221 /* Thumb-2 code must have mapping symbols to have a chance. */
4224 bpaddr = gdbarch_addr_bits_remove (gdbarch, bpaddr);
4226 if (find_pc_partial_function (bpaddr, NULL, &func_start, NULL)
4227 && func_start > boundary)
4228 boundary = func_start;
4230 /* Search for a candidate IT instruction. We have to do some fancy
4231 footwork to distinguish a real IT instruction from the second
4232 half of a 32-bit instruction, but there is no need for that if
4233 there's no candidate. */
4234 buf_len = std::min (bpaddr - boundary, (CORE_ADDR) MAX_IT_BLOCK_PREFIX);
4236 /* No room for an IT instruction. */
4239 buf = (gdb_byte *) xmalloc (buf_len);
4240 if (target_read_code (bpaddr - buf_len, buf, buf_len) != 0)
4243 for (i = 0; i < buf_len; i += 2)
4245 unsigned short inst1 = extract_unsigned_integer (&buf[i], 2, order);
4246 if ((inst1 & 0xff00) == 0xbf00 && (inst1 & 0x000f) != 0)
4259 /* OK, the code bytes before this instruction contain at least one
4260 halfword which resembles an IT instruction. We know that it's
4261 Thumb code, but there are still two possibilities. Either the
4262 halfword really is an IT instruction, or it is the second half of
4263 a 32-bit Thumb instruction. The only way we can tell is to
4264 scan forwards from a known instruction boundary. */
4265 if (bpaddr - boundary > IT_SCAN_THRESHOLD)
4269 /* There's a lot of code before this instruction. Start with an
4270 optimistic search; it's easy to recognize halfwords that can
4271 not be the start of a 32-bit instruction, and use that to
4272 lock on to the instruction boundaries. */
4273 buf = extend_buffer_earlier (buf, bpaddr, buf_len, IT_SCAN_THRESHOLD);
4276 buf_len = IT_SCAN_THRESHOLD;
4279 for (i = 0; i < buf_len - sizeof (buf) && ! definite; i += 2)
4281 unsigned short inst1 = extract_unsigned_integer (&buf[i], 2, order);
4282 if (thumb_insn_size (inst1) == 2)
4289 /* At this point, if DEFINITE, BUF[I] is the first place we
4290 are sure that we know the instruction boundaries, and it is far
4291 enough from BPADDR that we could not miss an IT instruction
4292 affecting BPADDR. If ! DEFINITE, give up - start from a
4296 buf = extend_buffer_earlier (buf, bpaddr, buf_len,
4300 buf_len = bpaddr - boundary;
4306 buf = extend_buffer_earlier (buf, bpaddr, buf_len, bpaddr - boundary);
4309 buf_len = bpaddr - boundary;
4313 /* Scan forwards. Find the last IT instruction before BPADDR. */
4318 unsigned short inst1 = extract_unsigned_integer (&buf[i], 2, order);
4320 if ((inst1 & 0xff00) == 0xbf00 && (inst1 & 0x000f) != 0)
4325 else if (inst1 & 0x0002)
4327 else if (inst1 & 0x0004)
4332 i += thumb_insn_size (inst1);
4338 /* There wasn't really an IT instruction after all. */
4341 if (last_it_count < 1)
4342 /* It was too far away. */
4345 /* This really is a trouble spot. Move the breakpoint to the IT
4347 return bpaddr - buf_len + last_it;
4350 /* ARM displaced stepping support.
4352 Generally ARM displaced stepping works as follows:
4354 1. When an instruction is to be single-stepped, it is first decoded by
4355 arm_process_displaced_insn. Depending on the type of instruction, it is
4356 then copied to a scratch location, possibly in a modified form. The
4357 copy_* set of functions performs such modification, as necessary. A
4358 breakpoint is placed after the modified instruction in the scratch space
4359 to return control to GDB. Note in particular that instructions which
4360 modify the PC will no longer do so after modification.
4362 2. The instruction is single-stepped, by setting the PC to the scratch
4363 location address, and resuming. Control returns to GDB when the
4366 3. A cleanup function (cleanup_*) is called corresponding to the copy_*
4367 function used for the current instruction. This function's job is to
4368 put the CPU/memory state back to what it would have been if the
4369 instruction had been executed unmodified in its original location. */
4371 /* NOP instruction (mov r0, r0). */
4372 #define ARM_NOP 0xe1a00000
4373 #define THUMB_NOP 0x4600
4375 /* Helper for register reads for displaced stepping. In particular, this
4376 returns the PC as it would be seen by the instruction at its original
4380 displaced_read_reg (struct regcache *regs, arm_displaced_step_closure *dsc,
4384 CORE_ADDR from = dsc->insn_addr;
4386 if (regno == ARM_PC_REGNUM)
4388 /* Compute pipeline offset:
4389 - When executing an ARM instruction, PC reads as the address of the
4390 current instruction plus 8.
4391 - When executing a Thumb instruction, PC reads as the address of the
4392 current instruction plus 4. */
4399 if (debug_displaced)
4400 fprintf_unfiltered (gdb_stdlog, "displaced: read pc value %.8lx\n",
4401 (unsigned long) from);
4402 return (ULONGEST) from;
4406 regcache_cooked_read_unsigned (regs, regno, &ret);
4407 if (debug_displaced)
4408 fprintf_unfiltered (gdb_stdlog, "displaced: read r%d value %.8lx\n",
4409 regno, (unsigned long) ret);
4415 displaced_in_arm_mode (struct regcache *regs)
4418 ULONGEST t_bit = arm_psr_thumb_bit (regs->arch ());
4420 regcache_cooked_read_unsigned (regs, ARM_PS_REGNUM, &ps);
4422 return (ps & t_bit) == 0;
4425 /* Write to the PC as from a branch instruction. */
4428 branch_write_pc (struct regcache *regs, arm_displaced_step_closure *dsc,
4432 /* Note: If bits 0/1 are set, this branch would be unpredictable for
4433 architecture versions < 6. */
4434 regcache_cooked_write_unsigned (regs, ARM_PC_REGNUM,
4435 val & ~(ULONGEST) 0x3);
4437 regcache_cooked_write_unsigned (regs, ARM_PC_REGNUM,
4438 val & ~(ULONGEST) 0x1);
4441 /* Write to the PC as from a branch-exchange instruction. */
4444 bx_write_pc (struct regcache *regs, ULONGEST val)
4447 ULONGEST t_bit = arm_psr_thumb_bit (regs->arch ());
4449 regcache_cooked_read_unsigned (regs, ARM_PS_REGNUM, &ps);
4453 regcache_cooked_write_unsigned (regs, ARM_PS_REGNUM, ps | t_bit);
4454 regcache_cooked_write_unsigned (regs, ARM_PC_REGNUM, val & 0xfffffffe);
4456 else if ((val & 2) == 0)
4458 regcache_cooked_write_unsigned (regs, ARM_PS_REGNUM, ps & ~t_bit);
4459 regcache_cooked_write_unsigned (regs, ARM_PC_REGNUM, val);
4463 /* Unpredictable behaviour. Try to do something sensible (switch to ARM
4464 mode, align dest to 4 bytes). */
4465 warning (_("Single-stepping BX to non-word-aligned ARM instruction."));
4466 regcache_cooked_write_unsigned (regs, ARM_PS_REGNUM, ps & ~t_bit);
4467 regcache_cooked_write_unsigned (regs, ARM_PC_REGNUM, val & 0xfffffffc);
4471 /* Write to the PC as if from a load instruction. */
4474 load_write_pc (struct regcache *regs, arm_displaced_step_closure *dsc,
4477 if (DISPLACED_STEPPING_ARCH_VERSION >= 5)
4478 bx_write_pc (regs, val);
4480 branch_write_pc (regs, dsc, val);
4483 /* Write to the PC as if from an ALU instruction. */
4486 alu_write_pc (struct regcache *regs, arm_displaced_step_closure *dsc,
4489 if (DISPLACED_STEPPING_ARCH_VERSION >= 7 && !dsc->is_thumb)
4490 bx_write_pc (regs, val);
4492 branch_write_pc (regs, dsc, val);
4495 /* Helper for writing to registers for displaced stepping. Writing to the PC
4496 has a varying effects depending on the instruction which does the write:
4497 this is controlled by the WRITE_PC argument. */
4500 displaced_write_reg (struct regcache *regs, arm_displaced_step_closure *dsc,
4501 int regno, ULONGEST val, enum pc_write_style write_pc)
4503 if (regno == ARM_PC_REGNUM)
4505 if (debug_displaced)
4506 fprintf_unfiltered (gdb_stdlog, "displaced: writing pc %.8lx\n",
4507 (unsigned long) val);
4510 case BRANCH_WRITE_PC:
4511 branch_write_pc (regs, dsc, val);
4515 bx_write_pc (regs, val);
4519 load_write_pc (regs, dsc, val);
4523 alu_write_pc (regs, dsc, val);
4526 case CANNOT_WRITE_PC:
4527 warning (_("Instruction wrote to PC in an unexpected way when "
4528 "single-stepping"));
4532 internal_error (__FILE__, __LINE__,
4533 _("Invalid argument to displaced_write_reg"));
4536 dsc->wrote_to_pc = 1;
4540 if (debug_displaced)
4541 fprintf_unfiltered (gdb_stdlog, "displaced: writing r%d value %.8lx\n",
4542 regno, (unsigned long) val);
4543 regcache_cooked_write_unsigned (regs, regno, val);
4547 /* This function is used to concisely determine if an instruction INSN
4548 references PC. Register fields of interest in INSN should have the
4549 corresponding fields of BITMASK set to 0b1111. The function
4550 returns return 1 if any of these fields in INSN reference the PC
4551 (also 0b1111, r15), else it returns 0. */
4554 insn_references_pc (uint32_t insn, uint32_t bitmask)
4556 uint32_t lowbit = 1;
4558 while (bitmask != 0)
4562 for (; lowbit && (bitmask & lowbit) == 0; lowbit <<= 1)
4568 mask = lowbit * 0xf;
4570 if ((insn & mask) == mask)
4579 /* The simplest copy function. Many instructions have the same effect no
4580 matter what address they are executed at: in those cases, use this. */
4583 arm_copy_unmodified (struct gdbarch *gdbarch, uint32_t insn,
4584 const char *iname, arm_displaced_step_closure *dsc)
4586 if (debug_displaced)
4587 fprintf_unfiltered (gdb_stdlog, "displaced: copying insn %.8lx, "
4588 "opcode/class '%s' unmodified\n", (unsigned long) insn,
4591 dsc->modinsn[0] = insn;
4597 thumb_copy_unmodified_32bit (struct gdbarch *gdbarch, uint16_t insn1,
4598 uint16_t insn2, const char *iname,
4599 arm_displaced_step_closure *dsc)
4601 if (debug_displaced)
4602 fprintf_unfiltered (gdb_stdlog, "displaced: copying insn %.4x %.4x, "
4603 "opcode/class '%s' unmodified\n", insn1, insn2,
4606 dsc->modinsn[0] = insn1;
4607 dsc->modinsn[1] = insn2;
4613 /* Copy 16-bit Thumb(Thumb and 16-bit Thumb-2) instruction without any
4616 thumb_copy_unmodified_16bit (struct gdbarch *gdbarch, uint16_t insn,
4618 arm_displaced_step_closure *dsc)
4620 if (debug_displaced)
4621 fprintf_unfiltered (gdb_stdlog, "displaced: copying insn %.4x, "
4622 "opcode/class '%s' unmodified\n", insn,
4625 dsc->modinsn[0] = insn;
4630 /* Preload instructions with immediate offset. */
4633 cleanup_preload (struct gdbarch *gdbarch,
4634 struct regcache *regs, arm_displaced_step_closure *dsc)
4636 displaced_write_reg (regs, dsc, 0, dsc->tmp[0], CANNOT_WRITE_PC);
4637 if (!dsc->u.preload.immed)
4638 displaced_write_reg (regs, dsc, 1, dsc->tmp[1], CANNOT_WRITE_PC);
4642 install_preload (struct gdbarch *gdbarch, struct regcache *regs,
4643 arm_displaced_step_closure *dsc, unsigned int rn)
4646 /* Preload instructions:
4648 {pli/pld} [rn, #+/-imm]
4650 {pli/pld} [r0, #+/-imm]. */
4652 dsc->tmp[0] = displaced_read_reg (regs, dsc, 0);
4653 rn_val = displaced_read_reg (regs, dsc, rn);
4654 displaced_write_reg (regs, dsc, 0, rn_val, CANNOT_WRITE_PC);
4655 dsc->u.preload.immed = 1;
4657 dsc->cleanup = &cleanup_preload;
4661 arm_copy_preload (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs,
4662 arm_displaced_step_closure *dsc)
4664 unsigned int rn = bits (insn, 16, 19);
4666 if (!insn_references_pc (insn, 0x000f0000ul))
4667 return arm_copy_unmodified (gdbarch, insn, "preload", dsc);
4669 if (debug_displaced)
4670 fprintf_unfiltered (gdb_stdlog, "displaced: copying preload insn %.8lx\n",
4671 (unsigned long) insn);
4673 dsc->modinsn[0] = insn & 0xfff0ffff;
4675 install_preload (gdbarch, regs, dsc, rn);
4681 thumb2_copy_preload (struct gdbarch *gdbarch, uint16_t insn1, uint16_t insn2,
4682 struct regcache *regs, arm_displaced_step_closure *dsc)
4684 unsigned int rn = bits (insn1, 0, 3);
4685 unsigned int u_bit = bit (insn1, 7);
4686 int imm12 = bits (insn2, 0, 11);
4689 if (rn != ARM_PC_REGNUM)
4690 return thumb_copy_unmodified_32bit (gdbarch, insn1, insn2, "preload", dsc);
4692 /* PC is only allowed to use in PLI (immediate,literal) Encoding T3, and
4693 PLD (literal) Encoding T1. */
4694 if (debug_displaced)
4695 fprintf_unfiltered (gdb_stdlog,
4696 "displaced: copying pld/pli pc (0x%x) %c imm12 %.4x\n",
4697 (unsigned int) dsc->insn_addr, u_bit ? '+' : '-',
4703 /* Rewrite instruction {pli/pld} PC imm12 into:
4704 Prepare: tmp[0] <- r0, tmp[1] <- r1, r0 <- pc, r1 <- imm12
4708 Cleanup: r0 <- tmp[0], r1 <- tmp[1]. */
4710 dsc->tmp[0] = displaced_read_reg (regs, dsc, 0);
4711 dsc->tmp[1] = displaced_read_reg (regs, dsc, 1);
4713 pc_val = displaced_read_reg (regs, dsc, ARM_PC_REGNUM);
4715 displaced_write_reg (regs, dsc, 0, pc_val, CANNOT_WRITE_PC);
4716 displaced_write_reg (regs, dsc, 1, imm12, CANNOT_WRITE_PC);
4717 dsc->u.preload.immed = 0;
4719 /* {pli/pld} [r0, r1] */
4720 dsc->modinsn[0] = insn1 & 0xfff0;
4721 dsc->modinsn[1] = 0xf001;
4724 dsc->cleanup = &cleanup_preload;
4728 /* Preload instructions with register offset. */
4731 install_preload_reg(struct gdbarch *gdbarch, struct regcache *regs,
4732 arm_displaced_step_closure *dsc, unsigned int rn,
4735 ULONGEST rn_val, rm_val;
4737 /* Preload register-offset instructions:
4739 {pli/pld} [rn, rm {, shift}]
4741 {pli/pld} [r0, r1 {, shift}]. */
4743 dsc->tmp[0] = displaced_read_reg (regs, dsc, 0);
4744 dsc->tmp[1] = displaced_read_reg (regs, dsc, 1);
4745 rn_val = displaced_read_reg (regs, dsc, rn);
4746 rm_val = displaced_read_reg (regs, dsc, rm);
4747 displaced_write_reg (regs, dsc, 0, rn_val, CANNOT_WRITE_PC);
4748 displaced_write_reg (regs, dsc, 1, rm_val, CANNOT_WRITE_PC);
4749 dsc->u.preload.immed = 0;
4751 dsc->cleanup = &cleanup_preload;
4755 arm_copy_preload_reg (struct gdbarch *gdbarch, uint32_t insn,
4756 struct regcache *regs,
4757 arm_displaced_step_closure *dsc)
4759 unsigned int rn = bits (insn, 16, 19);
4760 unsigned int rm = bits (insn, 0, 3);
4763 if (!insn_references_pc (insn, 0x000f000ful))
4764 return arm_copy_unmodified (gdbarch, insn, "preload reg", dsc);
4766 if (debug_displaced)
4767 fprintf_unfiltered (gdb_stdlog, "displaced: copying preload insn %.8lx\n",
4768 (unsigned long) insn);
4770 dsc->modinsn[0] = (insn & 0xfff0fff0) | 0x1;
4772 install_preload_reg (gdbarch, regs, dsc, rn, rm);
4776 /* Copy/cleanup coprocessor load and store instructions. */
4779 cleanup_copro_load_store (struct gdbarch *gdbarch,
4780 struct regcache *regs,
4781 arm_displaced_step_closure *dsc)
4783 ULONGEST rn_val = displaced_read_reg (regs, dsc, 0);
4785 displaced_write_reg (regs, dsc, 0, dsc->tmp[0], CANNOT_WRITE_PC);
4787 if (dsc->u.ldst.writeback)
4788 displaced_write_reg (regs, dsc, dsc->u.ldst.rn, rn_val, LOAD_WRITE_PC);
4792 install_copro_load_store (struct gdbarch *gdbarch, struct regcache *regs,
4793 arm_displaced_step_closure *dsc,
4794 int writeback, unsigned int rn)
4798 /* Coprocessor load/store instructions:
4800 {stc/stc2} [<Rn>, #+/-imm] (and other immediate addressing modes)
4802 {stc/stc2} [r0, #+/-imm].
4804 ldc/ldc2 are handled identically. */
4806 dsc->tmp[0] = displaced_read_reg (regs, dsc, 0);
4807 rn_val = displaced_read_reg (regs, dsc, rn);
4808 /* PC should be 4-byte aligned. */
4809 rn_val = rn_val & 0xfffffffc;
4810 displaced_write_reg (regs, dsc, 0, rn_val, CANNOT_WRITE_PC);
4812 dsc->u.ldst.writeback = writeback;
4813 dsc->u.ldst.rn = rn;
4815 dsc->cleanup = &cleanup_copro_load_store;
4819 arm_copy_copro_load_store (struct gdbarch *gdbarch, uint32_t insn,
4820 struct regcache *regs,
4821 arm_displaced_step_closure *dsc)
4823 unsigned int rn = bits (insn, 16, 19);
4825 if (!insn_references_pc (insn, 0x000f0000ul))
4826 return arm_copy_unmodified (gdbarch, insn, "copro load/store", dsc);
4828 if (debug_displaced)
4829 fprintf_unfiltered (gdb_stdlog, "displaced: copying coprocessor "
4830 "load/store insn %.8lx\n", (unsigned long) insn);
4832 dsc->modinsn[0] = insn & 0xfff0ffff;
4834 install_copro_load_store (gdbarch, regs, dsc, bit (insn, 25), rn);
4840 thumb2_copy_copro_load_store (struct gdbarch *gdbarch, uint16_t insn1,
4841 uint16_t insn2, struct regcache *regs,
4842 arm_displaced_step_closure *dsc)
4844 unsigned int rn = bits (insn1, 0, 3);
4846 if (rn != ARM_PC_REGNUM)
4847 return thumb_copy_unmodified_32bit (gdbarch, insn1, insn2,
4848 "copro load/store", dsc);
4850 if (debug_displaced)
4851 fprintf_unfiltered (gdb_stdlog, "displaced: copying coprocessor "
4852 "load/store insn %.4x%.4x\n", insn1, insn2);
4854 dsc->modinsn[0] = insn1 & 0xfff0;
4855 dsc->modinsn[1] = insn2;
4858 /* This function is called for copying instruction LDC/LDC2/VLDR, which
4859 doesn't support writeback, so pass 0. */
4860 install_copro_load_store (gdbarch, regs, dsc, 0, rn);
4865 /* Clean up branch instructions (actually perform the branch, by setting
4869 cleanup_branch (struct gdbarch *gdbarch, struct regcache *regs,
4870 arm_displaced_step_closure *dsc)
4872 uint32_t status = displaced_read_reg (regs, dsc, ARM_PS_REGNUM);
4873 int branch_taken = condition_true (dsc->u.branch.cond, status);
4874 enum pc_write_style write_pc = dsc->u.branch.exchange
4875 ? BX_WRITE_PC : BRANCH_WRITE_PC;
4880 if (dsc->u.branch.link)
4882 /* The value of LR should be the next insn of current one. In order
4883 not to confuse logic hanlding later insn `bx lr', if current insn mode
4884 is Thumb, the bit 0 of LR value should be set to 1. */
4885 ULONGEST next_insn_addr = dsc->insn_addr + dsc->insn_size;
4888 next_insn_addr |= 0x1;
4890 displaced_write_reg (regs, dsc, ARM_LR_REGNUM, next_insn_addr,
4894 displaced_write_reg (regs, dsc, ARM_PC_REGNUM, dsc->u.branch.dest, write_pc);
4897 /* Copy B/BL/BLX instructions with immediate destinations. */
4900 install_b_bl_blx (struct gdbarch *gdbarch, struct regcache *regs,
4901 arm_displaced_step_closure *dsc,
4902 unsigned int cond, int exchange, int link, long offset)
4904 /* Implement "BL<cond> <label>" as:
4906 Preparation: cond <- instruction condition
4907 Insn: mov r0, r0 (nop)
4908 Cleanup: if (condition true) { r14 <- pc; pc <- label }.
4910 B<cond> similar, but don't set r14 in cleanup. */
4912 dsc->u.branch.cond = cond;
4913 dsc->u.branch.link = link;
4914 dsc->u.branch.exchange = exchange;
4916 dsc->u.branch.dest = dsc->insn_addr;
4917 if (link && exchange)
4918 /* For BLX, offset is computed from the Align (PC, 4). */
4919 dsc->u.branch.dest = dsc->u.branch.dest & 0xfffffffc;
4922 dsc->u.branch.dest += 4 + offset;
4924 dsc->u.branch.dest += 8 + offset;
4926 dsc->cleanup = &cleanup_branch;
4929 arm_copy_b_bl_blx (struct gdbarch *gdbarch, uint32_t insn,
4930 struct regcache *regs, arm_displaced_step_closure *dsc)
4932 unsigned int cond = bits (insn, 28, 31);
4933 int exchange = (cond == 0xf);
4934 int link = exchange || bit (insn, 24);
4937 if (debug_displaced)
4938 fprintf_unfiltered (gdb_stdlog, "displaced: copying %s immediate insn "
4939 "%.8lx\n", (exchange) ? "blx" : (link) ? "bl" : "b",
4940 (unsigned long) insn);
4942 /* For BLX, set bit 0 of the destination. The cleanup_branch function will
4943 then arrange the switch into Thumb mode. */
4944 offset = (bits (insn, 0, 23) << 2) | (bit (insn, 24) << 1) | 1;
4946 offset = bits (insn, 0, 23) << 2;
4948 if (bit (offset, 25))
4949 offset = offset | ~0x3ffffff;
4951 dsc->modinsn[0] = ARM_NOP;
4953 install_b_bl_blx (gdbarch, regs, dsc, cond, exchange, link, offset);
4958 thumb2_copy_b_bl_blx (struct gdbarch *gdbarch, uint16_t insn1,
4959 uint16_t insn2, struct regcache *regs,
4960 arm_displaced_step_closure *dsc)
4962 int link = bit (insn2, 14);
4963 int exchange = link && !bit (insn2, 12);
4966 int j1 = bit (insn2, 13);
4967 int j2 = bit (insn2, 11);
4968 int s = sbits (insn1, 10, 10);
4969 int i1 = !(j1 ^ bit (insn1, 10));
4970 int i2 = !(j2 ^ bit (insn1, 10));
4972 if (!link && !exchange) /* B */
4974 offset = (bits (insn2, 0, 10) << 1);
4975 if (bit (insn2, 12)) /* Encoding T4 */
4977 offset |= (bits (insn1, 0, 9) << 12)
4983 else /* Encoding T3 */
4985 offset |= (bits (insn1, 0, 5) << 12)
4989 cond = bits (insn1, 6, 9);
4994 offset = (bits (insn1, 0, 9) << 12);
4995 offset |= ((i2 << 22) | (i1 << 23) | (s << 24));
4996 offset |= exchange ?
4997 (bits (insn2, 1, 10) << 2) : (bits (insn2, 0, 10) << 1);
5000 if (debug_displaced)
5001 fprintf_unfiltered (gdb_stdlog, "displaced: copying %s insn "
5002 "%.4x %.4x with offset %.8lx\n",
5003 link ? (exchange) ? "blx" : "bl" : "b",
5004 insn1, insn2, offset);
5006 dsc->modinsn[0] = THUMB_NOP;
5008 install_b_bl_blx (gdbarch, regs, dsc, cond, exchange, link, offset);
5012 /* Copy B Thumb instructions. */
5014 thumb_copy_b (struct gdbarch *gdbarch, uint16_t insn,
5015 arm_displaced_step_closure *dsc)
5017 unsigned int cond = 0;
5019 unsigned short bit_12_15 = bits (insn, 12, 15);
5020 CORE_ADDR from = dsc->insn_addr;
5022 if (bit_12_15 == 0xd)
5024 /* offset = SignExtend (imm8:0, 32) */
5025 offset = sbits ((insn << 1), 0, 8);
5026 cond = bits (insn, 8, 11);
5028 else if (bit_12_15 == 0xe) /* Encoding T2 */
5030 offset = sbits ((insn << 1), 0, 11);
5034 if (debug_displaced)
5035 fprintf_unfiltered (gdb_stdlog,
5036 "displaced: copying b immediate insn %.4x "
5037 "with offset %d\n", insn, offset);
5039 dsc->u.branch.cond = cond;
5040 dsc->u.branch.link = 0;
5041 dsc->u.branch.exchange = 0;
5042 dsc->u.branch.dest = from + 4 + offset;
5044 dsc->modinsn[0] = THUMB_NOP;
5046 dsc->cleanup = &cleanup_branch;
5051 /* Copy BX/BLX with register-specified destinations. */
5054 install_bx_blx_reg (struct gdbarch *gdbarch, struct regcache *regs,
5055 arm_displaced_step_closure *dsc, int link,
5056 unsigned int cond, unsigned int rm)
5058 /* Implement {BX,BLX}<cond> <reg>" as:
5060 Preparation: cond <- instruction condition
5061 Insn: mov r0, r0 (nop)
5062 Cleanup: if (condition true) { r14 <- pc; pc <- dest; }.
5064 Don't set r14 in cleanup for BX. */
5066 dsc->u.branch.dest = displaced_read_reg (regs, dsc, rm);
5068 dsc->u.branch.cond = cond;
5069 dsc->u.branch.link = link;
5071 dsc->u.branch.exchange = 1;
5073 dsc->cleanup = &cleanup_branch;
5077 arm_copy_bx_blx_reg (struct gdbarch *gdbarch, uint32_t insn,
5078 struct regcache *regs, arm_displaced_step_closure *dsc)
5080 unsigned int cond = bits (insn, 28, 31);
5083 int link = bit (insn, 5);
5084 unsigned int rm = bits (insn, 0, 3);
5086 if (debug_displaced)
5087 fprintf_unfiltered (gdb_stdlog, "displaced: copying insn %.8lx",
5088 (unsigned long) insn);
5090 dsc->modinsn[0] = ARM_NOP;
5092 install_bx_blx_reg (gdbarch, regs, dsc, link, cond, rm);
5097 thumb_copy_bx_blx_reg (struct gdbarch *gdbarch, uint16_t insn,
5098 struct regcache *regs,
5099 arm_displaced_step_closure *dsc)
5101 int link = bit (insn, 7);
5102 unsigned int rm = bits (insn, 3, 6);
5104 if (debug_displaced)
5105 fprintf_unfiltered (gdb_stdlog, "displaced: copying insn %.4x",
5106 (unsigned short) insn);
5108 dsc->modinsn[0] = THUMB_NOP;
5110 install_bx_blx_reg (gdbarch, regs, dsc, link, INST_AL, rm);
5116 /* Copy/cleanup arithmetic/logic instruction with immediate RHS. */
5119 cleanup_alu_imm (struct gdbarch *gdbarch,
5120 struct regcache *regs, arm_displaced_step_closure *dsc)
5122 ULONGEST rd_val = displaced_read_reg (regs, dsc, 0);
5123 displaced_write_reg (regs, dsc, 0, dsc->tmp[0], CANNOT_WRITE_PC);
5124 displaced_write_reg (regs, dsc, 1, dsc->tmp[1], CANNOT_WRITE_PC);
5125 displaced_write_reg (regs, dsc, dsc->rd, rd_val, ALU_WRITE_PC);
5129 arm_copy_alu_imm (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs,
5130 arm_displaced_step_closure *dsc)
5132 unsigned int rn = bits (insn, 16, 19);
5133 unsigned int rd = bits (insn, 12, 15);
5134 unsigned int op = bits (insn, 21, 24);
5135 int is_mov = (op == 0xd);
5136 ULONGEST rd_val, rn_val;
5138 if (!insn_references_pc (insn, 0x000ff000ul))
5139 return arm_copy_unmodified (gdbarch, insn, "ALU immediate", dsc);
5141 if (debug_displaced)
5142 fprintf_unfiltered (gdb_stdlog, "displaced: copying immediate %s insn "
5143 "%.8lx\n", is_mov ? "move" : "ALU",
5144 (unsigned long) insn);
5146 /* Instruction is of form:
5148 <op><cond> rd, [rn,] #imm
5152 Preparation: tmp1, tmp2 <- r0, r1;
5154 Insn: <op><cond> r0, r1, #imm
5155 Cleanup: rd <- r0; r0 <- tmp1; r1 <- tmp2
5158 dsc->tmp[0] = displaced_read_reg (regs, dsc, 0);
5159 dsc->tmp[1] = displaced_read_reg (regs, dsc, 1);
5160 rn_val = displaced_read_reg (regs, dsc, rn);
5161 rd_val = displaced_read_reg (regs, dsc, rd);
5162 displaced_write_reg (regs, dsc, 0, rd_val, CANNOT_WRITE_PC);
5163 displaced_write_reg (regs, dsc, 1, rn_val, CANNOT_WRITE_PC);
5167 dsc->modinsn[0] = insn & 0xfff00fff;
5169 dsc->modinsn[0] = (insn & 0xfff00fff) | 0x10000;
5171 dsc->cleanup = &cleanup_alu_imm;
5177 thumb2_copy_alu_imm (struct gdbarch *gdbarch, uint16_t insn1,
5178 uint16_t insn2, struct regcache *regs,
5179 arm_displaced_step_closure *dsc)
5181 unsigned int op = bits (insn1, 5, 8);
5182 unsigned int rn, rm, rd;
5183 ULONGEST rd_val, rn_val;
5185 rn = bits (insn1, 0, 3); /* Rn */
5186 rm = bits (insn2, 0, 3); /* Rm */
5187 rd = bits (insn2, 8, 11); /* Rd */
5189 /* This routine is only called for instruction MOV. */
5190 gdb_assert (op == 0x2 && rn == 0xf);
5192 if (rm != ARM_PC_REGNUM && rd != ARM_PC_REGNUM)
5193 return thumb_copy_unmodified_32bit (gdbarch, insn1, insn2, "ALU imm", dsc);
5195 if (debug_displaced)
5196 fprintf_unfiltered (gdb_stdlog, "displaced: copying reg %s insn %.4x%.4x\n",
5197 "ALU", insn1, insn2);
5199 /* Instruction is of form:
5201 <op><cond> rd, [rn,] #imm
5205 Preparation: tmp1, tmp2 <- r0, r1;
5207 Insn: <op><cond> r0, r1, #imm
5208 Cleanup: rd <- r0; r0 <- tmp1; r1 <- tmp2
5211 dsc->tmp[0] = displaced_read_reg (regs, dsc, 0);
5212 dsc->tmp[1] = displaced_read_reg (regs, dsc, 1);
5213 rn_val = displaced_read_reg (regs, dsc, rn);
5214 rd_val = displaced_read_reg (regs, dsc, rd);
5215 displaced_write_reg (regs, dsc, 0, rd_val, CANNOT_WRITE_PC);
5216 displaced_write_reg (regs, dsc, 1, rn_val, CANNOT_WRITE_PC);
5219 dsc->modinsn[0] = insn1;
5220 dsc->modinsn[1] = ((insn2 & 0xf0f0) | 0x1);
5223 dsc->cleanup = &cleanup_alu_imm;
5228 /* Copy/cleanup arithmetic/logic insns with register RHS. */
5231 cleanup_alu_reg (struct gdbarch *gdbarch,
5232 struct regcache *regs, arm_displaced_step_closure *dsc)
5237 rd_val = displaced_read_reg (regs, dsc, 0);
5239 for (i = 0; i < 3; i++)
5240 displaced_write_reg (regs, dsc, i, dsc->tmp[i], CANNOT_WRITE_PC);
5242 displaced_write_reg (regs, dsc, dsc->rd, rd_val, ALU_WRITE_PC);
5246 install_alu_reg (struct gdbarch *gdbarch, struct regcache *regs,
5247 arm_displaced_step_closure *dsc,
5248 unsigned int rd, unsigned int rn, unsigned int rm)
5250 ULONGEST rd_val, rn_val, rm_val;
5252 /* Instruction is of form:
5254 <op><cond> rd, [rn,] rm [, <shift>]
5258 Preparation: tmp1, tmp2, tmp3 <- r0, r1, r2;
5259 r0, r1, r2 <- rd, rn, rm
5260 Insn: <op><cond> r0, [r1,] r2 [, <shift>]
5261 Cleanup: rd <- r0; r0, r1, r2 <- tmp1, tmp2, tmp3
5264 dsc->tmp[0] = displaced_read_reg (regs, dsc, 0);
5265 dsc->tmp[1] = displaced_read_reg (regs, dsc, 1);
5266 dsc->tmp[2] = displaced_read_reg (regs, dsc, 2);
5267 rd_val = displaced_read_reg (regs, dsc, rd);
5268 rn_val = displaced_read_reg (regs, dsc, rn);
5269 rm_val = displaced_read_reg (regs, dsc, rm);
5270 displaced_write_reg (regs, dsc, 0, rd_val, CANNOT_WRITE_PC);
5271 displaced_write_reg (regs, dsc, 1, rn_val, CANNOT_WRITE_PC);
5272 displaced_write_reg (regs, dsc, 2, rm_val, CANNOT_WRITE_PC);
5275 dsc->cleanup = &cleanup_alu_reg;
5279 arm_copy_alu_reg (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs,
5280 arm_displaced_step_closure *dsc)
5282 unsigned int op = bits (insn, 21, 24);
5283 int is_mov = (op == 0xd);
5285 if (!insn_references_pc (insn, 0x000ff00ful))
5286 return arm_copy_unmodified (gdbarch, insn, "ALU reg", dsc);
5288 if (debug_displaced)
5289 fprintf_unfiltered (gdb_stdlog, "displaced: copying reg %s insn %.8lx\n",
5290 is_mov ? "move" : "ALU", (unsigned long) insn);
5293 dsc->modinsn[0] = (insn & 0xfff00ff0) | 0x2;
5295 dsc->modinsn[0] = (insn & 0xfff00ff0) | 0x10002;
5297 install_alu_reg (gdbarch, regs, dsc, bits (insn, 12, 15), bits (insn, 16, 19),
5303 thumb_copy_alu_reg (struct gdbarch *gdbarch, uint16_t insn,
5304 struct regcache *regs,
5305 arm_displaced_step_closure *dsc)
5309 rm = bits (insn, 3, 6);
5310 rd = (bit (insn, 7) << 3) | bits (insn, 0, 2);
5312 if (rd != ARM_PC_REGNUM && rm != ARM_PC_REGNUM)
5313 return thumb_copy_unmodified_16bit (gdbarch, insn, "ALU reg", dsc);
5315 if (debug_displaced)
5316 fprintf_unfiltered (gdb_stdlog, "displaced: copying ALU reg insn %.4x\n",
5317 (unsigned short) insn);
5319 dsc->modinsn[0] = ((insn & 0xff00) | 0x10);
5321 install_alu_reg (gdbarch, regs, dsc, rd, rd, rm);
5326 /* Cleanup/copy arithmetic/logic insns with shifted register RHS. */
5329 cleanup_alu_shifted_reg (struct gdbarch *gdbarch,
5330 struct regcache *regs,
5331 arm_displaced_step_closure *dsc)
5333 ULONGEST rd_val = displaced_read_reg (regs, dsc, 0);
5336 for (i = 0; i < 4; i++)
5337 displaced_write_reg (regs, dsc, i, dsc->tmp[i], CANNOT_WRITE_PC);
5339 displaced_write_reg (regs, dsc, dsc->rd, rd_val, ALU_WRITE_PC);
5343 install_alu_shifted_reg (struct gdbarch *gdbarch, struct regcache *regs,
5344 arm_displaced_step_closure *dsc,
5345 unsigned int rd, unsigned int rn, unsigned int rm,
5349 ULONGEST rd_val, rn_val, rm_val, rs_val;
5351 /* Instruction is of form:
5353 <op><cond> rd, [rn,] rm, <shift> rs
5357 Preparation: tmp1, tmp2, tmp3, tmp4 <- r0, r1, r2, r3
5358 r0, r1, r2, r3 <- rd, rn, rm, rs
5359 Insn: <op><cond> r0, r1, r2, <shift> r3
5361 r0, r1, r2, r3 <- tmp1, tmp2, tmp3, tmp4
5365 for (i = 0; i < 4; i++)
5366 dsc->tmp[i] = displaced_read_reg (regs, dsc, i);
5368 rd_val = displaced_read_reg (regs, dsc, rd);
5369 rn_val = displaced_read_reg (regs, dsc, rn);
5370 rm_val = displaced_read_reg (regs, dsc, rm);
5371 rs_val = displaced_read_reg (regs, dsc, rs);
5372 displaced_write_reg (regs, dsc, 0, rd_val, CANNOT_WRITE_PC);
5373 displaced_write_reg (regs, dsc, 1, rn_val, CANNOT_WRITE_PC);
5374 displaced_write_reg (regs, dsc, 2, rm_val, CANNOT_WRITE_PC);
5375 displaced_write_reg (regs, dsc, 3, rs_val, CANNOT_WRITE_PC);
5377 dsc->cleanup = &cleanup_alu_shifted_reg;
5381 arm_copy_alu_shifted_reg (struct gdbarch *gdbarch, uint32_t insn,
5382 struct regcache *regs,
5383 arm_displaced_step_closure *dsc)
5385 unsigned int op = bits (insn, 21, 24);
5386 int is_mov = (op == 0xd);
5387 unsigned int rd, rn, rm, rs;
5389 if (!insn_references_pc (insn, 0x000fff0ful))
5390 return arm_copy_unmodified (gdbarch, insn, "ALU shifted reg", dsc);
5392 if (debug_displaced)
5393 fprintf_unfiltered (gdb_stdlog, "displaced: copying shifted reg %s insn "
5394 "%.8lx\n", is_mov ? "move" : "ALU",
5395 (unsigned long) insn);
5397 rn = bits (insn, 16, 19);
5398 rm = bits (insn, 0, 3);
5399 rs = bits (insn, 8, 11);
5400 rd = bits (insn, 12, 15);
5403 dsc->modinsn[0] = (insn & 0xfff000f0) | 0x302;
5405 dsc->modinsn[0] = (insn & 0xfff000f0) | 0x10302;
5407 install_alu_shifted_reg (gdbarch, regs, dsc, rd, rn, rm, rs);
5412 /* Clean up load instructions. */
5415 cleanup_load (struct gdbarch *gdbarch, struct regcache *regs,
5416 arm_displaced_step_closure *dsc)
5418 ULONGEST rt_val, rt_val2 = 0, rn_val;
5420 rt_val = displaced_read_reg (regs, dsc, 0);
5421 if (dsc->u.ldst.xfersize == 8)
5422 rt_val2 = displaced_read_reg (regs, dsc, 1);
5423 rn_val = displaced_read_reg (regs, dsc, 2);
5425 displaced_write_reg (regs, dsc, 0, dsc->tmp[0], CANNOT_WRITE_PC);
5426 if (dsc->u.ldst.xfersize > 4)
5427 displaced_write_reg (regs, dsc, 1, dsc->tmp[1], CANNOT_WRITE_PC);
5428 displaced_write_reg (regs, dsc, 2, dsc->tmp[2], CANNOT_WRITE_PC);
5429 if (!dsc->u.ldst.immed)
5430 displaced_write_reg (regs, dsc, 3, dsc->tmp[3], CANNOT_WRITE_PC);
5432 /* Handle register writeback. */
5433 if (dsc->u.ldst.writeback)
5434 displaced_write_reg (regs, dsc, dsc->u.ldst.rn, rn_val, CANNOT_WRITE_PC);
5435 /* Put result in right place. */
5436 displaced_write_reg (regs, dsc, dsc->rd, rt_val, LOAD_WRITE_PC);
5437 if (dsc->u.ldst.xfersize == 8)
5438 displaced_write_reg (regs, dsc, dsc->rd + 1, rt_val2, LOAD_WRITE_PC);
5441 /* Clean up store instructions. */
5444 cleanup_store (struct gdbarch *gdbarch, struct regcache *regs,
5445 arm_displaced_step_closure *dsc)
5447 ULONGEST rn_val = displaced_read_reg (regs, dsc, 2);
5449 displaced_write_reg (regs, dsc, 0, dsc->tmp[0], CANNOT_WRITE_PC);
5450 if (dsc->u.ldst.xfersize > 4)
5451 displaced_write_reg (regs, dsc, 1, dsc->tmp[1], CANNOT_WRITE_PC);
5452 displaced_write_reg (regs, dsc, 2, dsc->tmp[2], CANNOT_WRITE_PC);
5453 if (!dsc->u.ldst.immed)
5454 displaced_write_reg (regs, dsc, 3, dsc->tmp[3], CANNOT_WRITE_PC);
5455 if (!dsc->u.ldst.restore_r4)
5456 displaced_write_reg (regs, dsc, 4, dsc->tmp[4], CANNOT_WRITE_PC);
5459 if (dsc->u.ldst.writeback)
5460 displaced_write_reg (regs, dsc, dsc->u.ldst.rn, rn_val, CANNOT_WRITE_PC);
5463 /* Copy "extra" load/store instructions. These are halfword/doubleword
5464 transfers, which have a different encoding to byte/word transfers. */
5467 arm_copy_extra_ld_st (struct gdbarch *gdbarch, uint32_t insn, int unprivileged,
5468 struct regcache *regs, arm_displaced_step_closure *dsc)
5470 unsigned int op1 = bits (insn, 20, 24);
5471 unsigned int op2 = bits (insn, 5, 6);
5472 unsigned int rt = bits (insn, 12, 15);
5473 unsigned int rn = bits (insn, 16, 19);
5474 unsigned int rm = bits (insn, 0, 3);
5475 char load[12] = {0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1};
5476 char bytesize[12] = {2, 2, 2, 2, 8, 1, 8, 1, 8, 2, 8, 2};
5477 int immed = (op1 & 0x4) != 0;
5479 ULONGEST rt_val, rt_val2 = 0, rn_val, rm_val = 0;
5481 if (!insn_references_pc (insn, 0x000ff00ful))
5482 return arm_copy_unmodified (gdbarch, insn, "extra load/store", dsc);
5484 if (debug_displaced)
5485 fprintf_unfiltered (gdb_stdlog, "displaced: copying %sextra load/store "
5486 "insn %.8lx\n", unprivileged ? "unprivileged " : "",
5487 (unsigned long) insn);
5489 opcode = ((op2 << 2) | (op1 & 0x1) | ((op1 & 0x4) >> 1)) - 4;
5492 internal_error (__FILE__, __LINE__,
5493 _("copy_extra_ld_st: instruction decode error"));
5495 dsc->tmp[0] = displaced_read_reg (regs, dsc, 0);
5496 dsc->tmp[1] = displaced_read_reg (regs, dsc, 1);
5497 dsc->tmp[2] = displaced_read_reg (regs, dsc, 2);
5499 dsc->tmp[3] = displaced_read_reg (regs, dsc, 3);
5501 rt_val = displaced_read_reg (regs, dsc, rt);
5502 if (bytesize[opcode] == 8)
5503 rt_val2 = displaced_read_reg (regs, dsc, rt + 1);
5504 rn_val = displaced_read_reg (regs, dsc, rn);
5506 rm_val = displaced_read_reg (regs, dsc, rm);
5508 displaced_write_reg (regs, dsc, 0, rt_val, CANNOT_WRITE_PC);
5509 if (bytesize[opcode] == 8)
5510 displaced_write_reg (regs, dsc, 1, rt_val2, CANNOT_WRITE_PC);
5511 displaced_write_reg (regs, dsc, 2, rn_val, CANNOT_WRITE_PC);
5513 displaced_write_reg (regs, dsc, 3, rm_val, CANNOT_WRITE_PC);
5516 dsc->u.ldst.xfersize = bytesize[opcode];
5517 dsc->u.ldst.rn = rn;
5518 dsc->u.ldst.immed = immed;
5519 dsc->u.ldst.writeback = bit (insn, 24) == 0 || bit (insn, 21) != 0;
5520 dsc->u.ldst.restore_r4 = 0;
5523 /* {ldr,str}<width><cond> rt, [rt2,] [rn, #imm]
5525 {ldr,str}<width><cond> r0, [r1,] [r2, #imm]. */
5526 dsc->modinsn[0] = (insn & 0xfff00fff) | 0x20000;
5528 /* {ldr,str}<width><cond> rt, [rt2,] [rn, +/-rm]
5530 {ldr,str}<width><cond> r0, [r1,] [r2, +/-r3]. */
5531 dsc->modinsn[0] = (insn & 0xfff00ff0) | 0x20003;
5533 dsc->cleanup = load[opcode] ? &cleanup_load : &cleanup_store;
5538 /* Copy byte/half word/word loads and stores. */
5541 install_load_store (struct gdbarch *gdbarch, struct regcache *regs,
5542 arm_displaced_step_closure *dsc, int load,
5543 int immed, int writeback, int size, int usermode,
5544 int rt, int rm, int rn)
5546 ULONGEST rt_val, rn_val, rm_val = 0;
5548 dsc->tmp[0] = displaced_read_reg (regs, dsc, 0);
5549 dsc->tmp[2] = displaced_read_reg (regs, dsc, 2);
5551 dsc->tmp[3] = displaced_read_reg (regs, dsc, 3);
5553 dsc->tmp[4] = displaced_read_reg (regs, dsc, 4);
5555 rt_val = displaced_read_reg (regs, dsc, rt);
5556 rn_val = displaced_read_reg (regs, dsc, rn);
5558 rm_val = displaced_read_reg (regs, dsc, rm);
5560 displaced_write_reg (regs, dsc, 0, rt_val, CANNOT_WRITE_PC);
5561 displaced_write_reg (regs, dsc, 2, rn_val, CANNOT_WRITE_PC);
5563 displaced_write_reg (regs, dsc, 3, rm_val, CANNOT_WRITE_PC);
5565 dsc->u.ldst.xfersize = size;
5566 dsc->u.ldst.rn = rn;
5567 dsc->u.ldst.immed = immed;
5568 dsc->u.ldst.writeback = writeback;
5570 /* To write PC we can do:
5572 Before this sequence of instructions:
5573 r0 is the PC value got from displaced_read_reg, so r0 = from + 8;
5574 r2 is the Rn value got from dispalced_read_reg.
5576 Insn1: push {pc} Write address of STR instruction + offset on stack
5577 Insn2: pop {r4} Read it back from stack, r4 = addr(Insn1) + offset
5578 Insn3: sub r4, r4, pc r4 = addr(Insn1) + offset - pc
5579 = addr(Insn1) + offset - addr(Insn3) - 8
5581 Insn4: add r4, r4, #8 r4 = offset - 8
5582 Insn5: add r0, r0, r4 r0 = from + 8 + offset - 8
5584 Insn6: str r0, [r2, #imm] (or str r0, [r2, r3])
5586 Otherwise we don't know what value to write for PC, since the offset is
5587 architecture-dependent (sometimes PC+8, sometimes PC+12). More details
5588 of this can be found in Section "Saving from r15" in
5589 http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0204g/Cihbjifh.html */
5591 dsc->cleanup = load ? &cleanup_load : &cleanup_store;
5596 thumb2_copy_load_literal (struct gdbarch *gdbarch, uint16_t insn1,
5597 uint16_t insn2, struct regcache *regs,
5598 arm_displaced_step_closure *dsc, int size)
5600 unsigned int u_bit = bit (insn1, 7);
5601 unsigned int rt = bits (insn2, 12, 15);
5602 int imm12 = bits (insn2, 0, 11);
5605 if (debug_displaced)
5606 fprintf_unfiltered (gdb_stdlog,
5607 "displaced: copying ldr pc (0x%x) R%d %c imm12 %.4x\n",
5608 (unsigned int) dsc->insn_addr, rt, u_bit ? '+' : '-',
5614 /* Rewrite instruction LDR Rt imm12 into:
5616 Prepare: tmp[0] <- r0, tmp[1] <- r2, tmp[2] <- r3, r2 <- pc, r3 <- imm12
5620 Cleanup: rt <- r0, r0 <- tmp[0], r2 <- tmp[1], r3 <- tmp[2]. */
5623 dsc->tmp[0] = displaced_read_reg (regs, dsc, 0);
5624 dsc->tmp[2] = displaced_read_reg (regs, dsc, 2);
5625 dsc->tmp[3] = displaced_read_reg (regs, dsc, 3);
5627 pc_val = displaced_read_reg (regs, dsc, ARM_PC_REGNUM);
5629 pc_val = pc_val & 0xfffffffc;
5631 displaced_write_reg (regs, dsc, 2, pc_val, CANNOT_WRITE_PC);
5632 displaced_write_reg (regs, dsc, 3, imm12, CANNOT_WRITE_PC);
5636 dsc->u.ldst.xfersize = size;
5637 dsc->u.ldst.immed = 0;
5638 dsc->u.ldst.writeback = 0;
5639 dsc->u.ldst.restore_r4 = 0;
5641 /* LDR R0, R2, R3 */
5642 dsc->modinsn[0] = 0xf852;
5643 dsc->modinsn[1] = 0x3;
5646 dsc->cleanup = &cleanup_load;
5652 thumb2_copy_load_reg_imm (struct gdbarch *gdbarch, uint16_t insn1,
5653 uint16_t insn2, struct regcache *regs,
5654 arm_displaced_step_closure *dsc,
5655 int writeback, int immed)
5657 unsigned int rt = bits (insn2, 12, 15);
5658 unsigned int rn = bits (insn1, 0, 3);
5659 unsigned int rm = bits (insn2, 0, 3); /* Only valid if !immed. */
5660 /* In LDR (register), there is also a register Rm, which is not allowed to
5661 be PC, so we don't have to check it. */
5663 if (rt != ARM_PC_REGNUM && rn != ARM_PC_REGNUM)
5664 return thumb_copy_unmodified_32bit (gdbarch, insn1, insn2, "load",
5667 if (debug_displaced)
5668 fprintf_unfiltered (gdb_stdlog,
5669 "displaced: copying ldr r%d [r%d] insn %.4x%.4x\n",
5670 rt, rn, insn1, insn2);
5672 install_load_store (gdbarch, regs, dsc, 1, immed, writeback, 4,
5675 dsc->u.ldst.restore_r4 = 0;
5678 /* ldr[b]<cond> rt, [rn, #imm], etc.
5680 ldr[b]<cond> r0, [r2, #imm]. */
5682 dsc->modinsn[0] = (insn1 & 0xfff0) | 0x2;
5683 dsc->modinsn[1] = insn2 & 0x0fff;
5686 /* ldr[b]<cond> rt, [rn, rm], etc.
5688 ldr[b]<cond> r0, [r2, r3]. */
5690 dsc->modinsn[0] = (insn1 & 0xfff0) | 0x2;
5691 dsc->modinsn[1] = (insn2 & 0x0ff0) | 0x3;
5701 arm_copy_ldr_str_ldrb_strb (struct gdbarch *gdbarch, uint32_t insn,
5702 struct regcache *regs,
5703 arm_displaced_step_closure *dsc,
5704 int load, int size, int usermode)
5706 int immed = !bit (insn, 25);
5707 int writeback = (bit (insn, 24) == 0 || bit (insn, 21) != 0);
5708 unsigned int rt = bits (insn, 12, 15);
5709 unsigned int rn = bits (insn, 16, 19);
5710 unsigned int rm = bits (insn, 0, 3); /* Only valid if !immed. */
5712 if (!insn_references_pc (insn, 0x000ff00ful))
5713 return arm_copy_unmodified (gdbarch, insn, "load/store", dsc);
5715 if (debug_displaced)
5716 fprintf_unfiltered (gdb_stdlog,
5717 "displaced: copying %s%s r%d [r%d] insn %.8lx\n",
5718 load ? (size == 1 ? "ldrb" : "ldr")
5719 : (size == 1 ? "strb" : "str"), usermode ? "t" : "",
5721 (unsigned long) insn);
5723 install_load_store (gdbarch, regs, dsc, load, immed, writeback, size,
5724 usermode, rt, rm, rn);
5726 if (load || rt != ARM_PC_REGNUM)
5728 dsc->u.ldst.restore_r4 = 0;
5731 /* {ldr,str}[b]<cond> rt, [rn, #imm], etc.
5733 {ldr,str}[b]<cond> r0, [r2, #imm]. */
5734 dsc->modinsn[0] = (insn & 0xfff00fff) | 0x20000;
5736 /* {ldr,str}[b]<cond> rt, [rn, rm], etc.
5738 {ldr,str}[b]<cond> r0, [r2, r3]. */
5739 dsc->modinsn[0] = (insn & 0xfff00ff0) | 0x20003;
5743 /* We need to use r4 as scratch. Make sure it's restored afterwards. */
5744 dsc->u.ldst.restore_r4 = 1;
5745 dsc->modinsn[0] = 0xe92d8000; /* push {pc} */
5746 dsc->modinsn[1] = 0xe8bd0010; /* pop {r4} */
5747 dsc->modinsn[2] = 0xe044400f; /* sub r4, r4, pc. */
5748 dsc->modinsn[3] = 0xe2844008; /* add r4, r4, #8. */
5749 dsc->modinsn[4] = 0xe0800004; /* add r0, r0, r4. */
5753 dsc->modinsn[5] = (insn & 0xfff00fff) | 0x20000;
5755 dsc->modinsn[5] = (insn & 0xfff00ff0) | 0x20003;
5760 dsc->cleanup = load ? &cleanup_load : &cleanup_store;
5765 /* Cleanup LDM instructions with fully-populated register list. This is an
5766 unfortunate corner case: it's impossible to implement correctly by modifying
5767 the instruction. The issue is as follows: we have an instruction,
5771 which we must rewrite to avoid loading PC. A possible solution would be to
5772 do the load in two halves, something like (with suitable cleanup
5776 ldm[id][ab] r8!, {r0-r7}
5778 ldm[id][ab] r8, {r7-r14}
5781 but at present there's no suitable place for <temp>, since the scratch space
5782 is overwritten before the cleanup routine is called. For now, we simply
5783 emulate the instruction. */
5786 cleanup_block_load_all (struct gdbarch *gdbarch, struct regcache *regs,
5787 arm_displaced_step_closure *dsc)
5789 int inc = dsc->u.block.increment;
5790 int bump_before = dsc->u.block.before ? (inc ? 4 : -4) : 0;
5791 int bump_after = dsc->u.block.before ? 0 : (inc ? 4 : -4);
5792 uint32_t regmask = dsc->u.block.regmask;
5793 int regno = inc ? 0 : 15;
5794 CORE_ADDR xfer_addr = dsc->u.block.xfer_addr;
5795 int exception_return = dsc->u.block.load && dsc->u.block.user
5796 && (regmask & 0x8000) != 0;
5797 uint32_t status = displaced_read_reg (regs, dsc, ARM_PS_REGNUM);
5798 int do_transfer = condition_true (dsc->u.block.cond, status);
5799 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
5804 /* If the instruction is ldm rN, {...pc}^, I don't think there's anything
5805 sensible we can do here. Complain loudly. */
5806 if (exception_return)
5807 error (_("Cannot single-step exception return"));
5809 /* We don't handle any stores here for now. */
5810 gdb_assert (dsc->u.block.load != 0);
5812 if (debug_displaced)
5813 fprintf_unfiltered (gdb_stdlog, "displaced: emulating block transfer: "
5814 "%s %s %s\n", dsc->u.block.load ? "ldm" : "stm",
5815 dsc->u.block.increment ? "inc" : "dec",
5816 dsc->u.block.before ? "before" : "after");
5823 while (regno <= ARM_PC_REGNUM && (regmask & (1 << regno)) == 0)
5826 while (regno >= 0 && (regmask & (1 << regno)) == 0)
5829 xfer_addr += bump_before;
5831 memword = read_memory_unsigned_integer (xfer_addr, 4, byte_order);
5832 displaced_write_reg (regs, dsc, regno, memword, LOAD_WRITE_PC);
5834 xfer_addr += bump_after;
5836 regmask &= ~(1 << regno);
5839 if (dsc->u.block.writeback)
5840 displaced_write_reg (regs, dsc, dsc->u.block.rn, xfer_addr,
5844 /* Clean up an STM which included the PC in the register list. */
5847 cleanup_block_store_pc (struct gdbarch *gdbarch, struct regcache *regs,
5848 arm_displaced_step_closure *dsc)
5850 uint32_t status = displaced_read_reg (regs, dsc, ARM_PS_REGNUM);
5851 int store_executed = condition_true (dsc->u.block.cond, status);
5852 CORE_ADDR pc_stored_at, transferred_regs = bitcount (dsc->u.block.regmask);
5853 CORE_ADDR stm_insn_addr;
5856 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
5858 /* If condition code fails, there's nothing else to do. */
5859 if (!store_executed)
5862 if (dsc->u.block.increment)
5864 pc_stored_at = dsc->u.block.xfer_addr + 4 * transferred_regs;
5866 if (dsc->u.block.before)
5871 pc_stored_at = dsc->u.block.xfer_addr;
5873 if (dsc->u.block.before)
5877 pc_val = read_memory_unsigned_integer (pc_stored_at, 4, byte_order);
5878 stm_insn_addr = dsc->scratch_base;
5879 offset = pc_val - stm_insn_addr;
5881 if (debug_displaced)
5882 fprintf_unfiltered (gdb_stdlog, "displaced: detected PC offset %.8lx for "
5883 "STM instruction\n", offset);
5885 /* Rewrite the stored PC to the proper value for the non-displaced original
5887 write_memory_unsigned_integer (pc_stored_at, 4, byte_order,
5888 dsc->insn_addr + offset);
5891 /* Clean up an LDM which includes the PC in the register list. We clumped all
5892 the registers in the transferred list into a contiguous range r0...rX (to
5893 avoid loading PC directly and losing control of the debugged program), so we
5894 must undo that here. */
5897 cleanup_block_load_pc (struct gdbarch *gdbarch,
5898 struct regcache *regs,
5899 arm_displaced_step_closure *dsc)
5901 uint32_t status = displaced_read_reg (regs, dsc, ARM_PS_REGNUM);
5902 int load_executed = condition_true (dsc->u.block.cond, status);
5903 unsigned int mask = dsc->u.block.regmask, write_reg = ARM_PC_REGNUM;
5904 unsigned int regs_loaded = bitcount (mask);
5905 unsigned int num_to_shuffle = regs_loaded, clobbered;
5907 /* The method employed here will fail if the register list is fully populated
5908 (we need to avoid loading PC directly). */
5909 gdb_assert (num_to_shuffle < 16);
5914 clobbered = (1 << num_to_shuffle) - 1;
5916 while (num_to_shuffle > 0)
5918 if ((mask & (1 << write_reg)) != 0)
5920 unsigned int read_reg = num_to_shuffle - 1;
5922 if (read_reg != write_reg)
5924 ULONGEST rval = displaced_read_reg (regs, dsc, read_reg);
5925 displaced_write_reg (regs, dsc, write_reg, rval, LOAD_WRITE_PC);
5926 if (debug_displaced)
5927 fprintf_unfiltered (gdb_stdlog, _("displaced: LDM: move "
5928 "loaded register r%d to r%d\n"), read_reg,
5931 else if (debug_displaced)
5932 fprintf_unfiltered (gdb_stdlog, _("displaced: LDM: register "
5933 "r%d already in the right place\n"),
5936 clobbered &= ~(1 << write_reg);
5944 /* Restore any registers we scribbled over. */
5945 for (write_reg = 0; clobbered != 0; write_reg++)
5947 if ((clobbered & (1 << write_reg)) != 0)
5949 displaced_write_reg (regs, dsc, write_reg, dsc->tmp[write_reg],
5951 if (debug_displaced)
5952 fprintf_unfiltered (gdb_stdlog, _("displaced: LDM: restored "
5953 "clobbered register r%d\n"), write_reg);
5954 clobbered &= ~(1 << write_reg);
5958 /* Perform register writeback manually. */
5959 if (dsc->u.block.writeback)
5961 ULONGEST new_rn_val = dsc->u.block.xfer_addr;
5963 if (dsc->u.block.increment)
5964 new_rn_val += regs_loaded * 4;
5966 new_rn_val -= regs_loaded * 4;
5968 displaced_write_reg (regs, dsc, dsc->u.block.rn, new_rn_val,
5973 /* Handle ldm/stm, apart from some tricky cases which are unlikely to occur
5974 in user-level code (in particular exception return, ldm rn, {...pc}^). */
5977 arm_copy_block_xfer (struct gdbarch *gdbarch, uint32_t insn,
5978 struct regcache *regs,
5979 arm_displaced_step_closure *dsc)
5981 int load = bit (insn, 20);
5982 int user = bit (insn, 22);
5983 int increment = bit (insn, 23);
5984 int before = bit (insn, 24);
5985 int writeback = bit (insn, 21);
5986 int rn = bits (insn, 16, 19);
5988 /* Block transfers which don't mention PC can be run directly
5990 if (rn != ARM_PC_REGNUM && (insn & 0x8000) == 0)
5991 return arm_copy_unmodified (gdbarch, insn, "ldm/stm", dsc);
5993 if (rn == ARM_PC_REGNUM)
5995 warning (_("displaced: Unpredictable LDM or STM with "
5996 "base register r15"));
5997 return arm_copy_unmodified (gdbarch, insn, "unpredictable ldm/stm", dsc);
6000 if (debug_displaced)
6001 fprintf_unfiltered (gdb_stdlog, "displaced: copying block transfer insn "
6002 "%.8lx\n", (unsigned long) insn);
6004 dsc->u.block.xfer_addr = displaced_read_reg (regs, dsc, rn);
6005 dsc->u.block.rn = rn;
6007 dsc->u.block.load = load;
6008 dsc->u.block.user = user;
6009 dsc->u.block.increment = increment;
6010 dsc->u.block.before = before;
6011 dsc->u.block.writeback = writeback;
6012 dsc->u.block.cond = bits (insn, 28, 31);
6014 dsc->u.block.regmask = insn & 0xffff;
6018 if ((insn & 0xffff) == 0xffff)
6020 /* LDM with a fully-populated register list. This case is
6021 particularly tricky. Implement for now by fully emulating the
6022 instruction (which might not behave perfectly in all cases, but
6023 these instructions should be rare enough for that not to matter
6025 dsc->modinsn[0] = ARM_NOP;
6027 dsc->cleanup = &cleanup_block_load_all;
6031 /* LDM of a list of registers which includes PC. Implement by
6032 rewriting the list of registers to be transferred into a
6033 contiguous chunk r0...rX before doing the transfer, then shuffling
6034 registers into the correct places in the cleanup routine. */
6035 unsigned int regmask = insn & 0xffff;
6036 unsigned int num_in_list = bitcount (regmask), new_regmask;
6039 for (i = 0; i < num_in_list; i++)
6040 dsc->tmp[i] = displaced_read_reg (regs, dsc, i);
6042 /* Writeback makes things complicated. We need to avoid clobbering
6043 the base register with one of the registers in our modified
6044 register list, but just using a different register can't work in
6047 ldm r14!, {r0-r13,pc}
6049 which would need to be rewritten as:
6053 but that can't work, because there's no free register for N.
6055 Solve this by turning off the writeback bit, and emulating
6056 writeback manually in the cleanup routine. */
6061 new_regmask = (1 << num_in_list) - 1;
6063 if (debug_displaced)
6064 fprintf_unfiltered (gdb_stdlog, _("displaced: LDM r%d%s, "
6065 "{..., pc}: original reg list %.4x, modified "
6066 "list %.4x\n"), rn, writeback ? "!" : "",
6067 (int) insn & 0xffff, new_regmask);
6069 dsc->modinsn[0] = (insn & ~0xffff) | (new_regmask & 0xffff);
6071 dsc->cleanup = &cleanup_block_load_pc;
6076 /* STM of a list of registers which includes PC. Run the instruction
6077 as-is, but out of line: this will store the wrong value for the PC,
6078 so we must manually fix up the memory in the cleanup routine.
6079 Doing things this way has the advantage that we can auto-detect
6080 the offset of the PC write (which is architecture-dependent) in
6081 the cleanup routine. */
6082 dsc->modinsn[0] = insn;
6084 dsc->cleanup = &cleanup_block_store_pc;
6091 thumb2_copy_block_xfer (struct gdbarch *gdbarch, uint16_t insn1, uint16_t insn2,
6092 struct regcache *regs,
6093 arm_displaced_step_closure *dsc)
6095 int rn = bits (insn1, 0, 3);
6096 int load = bit (insn1, 4);
6097 int writeback = bit (insn1, 5);
6099 /* Block transfers which don't mention PC can be run directly
6101 if (rn != ARM_PC_REGNUM && (insn2 & 0x8000) == 0)
6102 return thumb_copy_unmodified_32bit (gdbarch, insn1, insn2, "ldm/stm", dsc);
6104 if (rn == ARM_PC_REGNUM)
6106 warning (_("displaced: Unpredictable LDM or STM with "
6107 "base register r15"));
6108 return thumb_copy_unmodified_32bit (gdbarch, insn1, insn2,
6109 "unpredictable ldm/stm", dsc);
6112 if (debug_displaced)
6113 fprintf_unfiltered (gdb_stdlog, "displaced: copying block transfer insn "
6114 "%.4x%.4x\n", insn1, insn2);
6116 /* Clear bit 13, since it should be always zero. */
6117 dsc->u.block.regmask = (insn2 & 0xdfff);
6118 dsc->u.block.rn = rn;
6120 dsc->u.block.load = load;
6121 dsc->u.block.user = 0;
6122 dsc->u.block.increment = bit (insn1, 7);
6123 dsc->u.block.before = bit (insn1, 8);
6124 dsc->u.block.writeback = writeback;
6125 dsc->u.block.cond = INST_AL;
6126 dsc->u.block.xfer_addr = displaced_read_reg (regs, dsc, rn);
6130 if (dsc->u.block.regmask == 0xffff)
6132 /* This branch is impossible to happen. */
6137 unsigned int regmask = dsc->u.block.regmask;
6138 unsigned int num_in_list = bitcount (regmask), new_regmask;
6141 for (i = 0; i < num_in_list; i++)
6142 dsc->tmp[i] = displaced_read_reg (regs, dsc, i);
6147 new_regmask = (1 << num_in_list) - 1;
6149 if (debug_displaced)
6150 fprintf_unfiltered (gdb_stdlog, _("displaced: LDM r%d%s, "
6151 "{..., pc}: original reg list %.4x, modified "
6152 "list %.4x\n"), rn, writeback ? "!" : "",
6153 (int) dsc->u.block.regmask, new_regmask);
6155 dsc->modinsn[0] = insn1;
6156 dsc->modinsn[1] = (new_regmask & 0xffff);
6159 dsc->cleanup = &cleanup_block_load_pc;
6164 dsc->modinsn[0] = insn1;
6165 dsc->modinsn[1] = insn2;
6167 dsc->cleanup = &cleanup_block_store_pc;
6172 /* Wrapper over read_memory_unsigned_integer for use in arm_get_next_pcs.
6173 This is used to avoid a dependency on BFD's bfd_endian enum. */
6176 arm_get_next_pcs_read_memory_unsigned_integer (CORE_ADDR memaddr, int len,
6179 return read_memory_unsigned_integer (memaddr, len,
6180 (enum bfd_endian) byte_order);
6183 /* Wrapper over gdbarch_addr_bits_remove for use in arm_get_next_pcs. */
6186 arm_get_next_pcs_addr_bits_remove (struct arm_get_next_pcs *self,
6189 return gdbarch_addr_bits_remove (self->regcache->arch (), val);
6192 /* Wrapper over syscall_next_pc for use in get_next_pcs. */
6195 arm_get_next_pcs_syscall_next_pc (struct arm_get_next_pcs *self)
6200 /* Wrapper over arm_is_thumb for use in arm_get_next_pcs. */
6203 arm_get_next_pcs_is_thumb (struct arm_get_next_pcs *self)
6205 return arm_is_thumb (self->regcache);
6208 /* single_step() is called just before we want to resume the inferior,
6209 if we want to single-step it but there is no hardware or kernel
6210 single-step support. We find the target of the coming instructions
6211 and breakpoint them. */
6213 std::vector<CORE_ADDR>
6214 arm_software_single_step (struct regcache *regcache)
6216 struct gdbarch *gdbarch = regcache->arch ();
6217 struct arm_get_next_pcs next_pcs_ctx;
6219 arm_get_next_pcs_ctor (&next_pcs_ctx,
6220 &arm_get_next_pcs_ops,
6221 gdbarch_byte_order (gdbarch),
6222 gdbarch_byte_order_for_code (gdbarch),
6226 std::vector<CORE_ADDR> next_pcs = arm_get_next_pcs (&next_pcs_ctx);
6228 for (CORE_ADDR &pc_ref : next_pcs)
6229 pc_ref = gdbarch_addr_bits_remove (gdbarch, pc_ref);
6234 /* Cleanup/copy SVC (SWI) instructions. These two functions are overridden
6235 for Linux, where some SVC instructions must be treated specially. */
6238 cleanup_svc (struct gdbarch *gdbarch, struct regcache *regs,
6239 arm_displaced_step_closure *dsc)
6241 CORE_ADDR resume_addr = dsc->insn_addr + dsc->insn_size;
6243 if (debug_displaced)
6244 fprintf_unfiltered (gdb_stdlog, "displaced: cleanup for svc, resume at "
6245 "%.8lx\n", (unsigned long) resume_addr);
6247 displaced_write_reg (regs, dsc, ARM_PC_REGNUM, resume_addr, BRANCH_WRITE_PC);
6251 /* Common copy routine for svc instruciton. */
6254 install_svc (struct gdbarch *gdbarch, struct regcache *regs,
6255 arm_displaced_step_closure *dsc)
6257 /* Preparation: none.
6258 Insn: unmodified svc.
6259 Cleanup: pc <- insn_addr + insn_size. */
6261 /* Pretend we wrote to the PC, so cleanup doesn't set PC to the next
6263 dsc->wrote_to_pc = 1;
6265 /* Allow OS-specific code to override SVC handling. */
6266 if (dsc->u.svc.copy_svc_os)
6267 return dsc->u.svc.copy_svc_os (gdbarch, regs, dsc);
6270 dsc->cleanup = &cleanup_svc;
6276 arm_copy_svc (struct gdbarch *gdbarch, uint32_t insn,
6277 struct regcache *regs, arm_displaced_step_closure *dsc)
6280 if (debug_displaced)
6281 fprintf_unfiltered (gdb_stdlog, "displaced: copying svc insn %.8lx\n",
6282 (unsigned long) insn);
6284 dsc->modinsn[0] = insn;
6286 return install_svc (gdbarch, regs, dsc);
6290 thumb_copy_svc (struct gdbarch *gdbarch, uint16_t insn,
6291 struct regcache *regs, arm_displaced_step_closure *dsc)
6294 if (debug_displaced)
6295 fprintf_unfiltered (gdb_stdlog, "displaced: copying svc insn %.4x\n",
6298 dsc->modinsn[0] = insn;
6300 return install_svc (gdbarch, regs, dsc);
6303 /* Copy undefined instructions. */
6306 arm_copy_undef (struct gdbarch *gdbarch, uint32_t insn,
6307 arm_displaced_step_closure *dsc)
6309 if (debug_displaced)
6310 fprintf_unfiltered (gdb_stdlog,
6311 "displaced: copying undefined insn %.8lx\n",
6312 (unsigned long) insn);
6314 dsc->modinsn[0] = insn;
6320 thumb_32bit_copy_undef (struct gdbarch *gdbarch, uint16_t insn1, uint16_t insn2,
6321 arm_displaced_step_closure *dsc)
6324 if (debug_displaced)
6325 fprintf_unfiltered (gdb_stdlog, "displaced: copying undefined insn "
6326 "%.4x %.4x\n", (unsigned short) insn1,
6327 (unsigned short) insn2);
6329 dsc->modinsn[0] = insn1;
6330 dsc->modinsn[1] = insn2;
6336 /* Copy unpredictable instructions. */
6339 arm_copy_unpred (struct gdbarch *gdbarch, uint32_t insn,
6340 arm_displaced_step_closure *dsc)
6342 if (debug_displaced)
6343 fprintf_unfiltered (gdb_stdlog, "displaced: copying unpredictable insn "
6344 "%.8lx\n", (unsigned long) insn);
6346 dsc->modinsn[0] = insn;
6351 /* The decode_* functions are instruction decoding helpers. They mostly follow
6352 the presentation in the ARM ARM. */
6355 arm_decode_misc_memhint_neon (struct gdbarch *gdbarch, uint32_t insn,
6356 struct regcache *regs,
6357 arm_displaced_step_closure *dsc)
6359 unsigned int op1 = bits (insn, 20, 26), op2 = bits (insn, 4, 7);
6360 unsigned int rn = bits (insn, 16, 19);
6362 if (op1 == 0x10 && (op2 & 0x2) == 0x0 && (rn & 0x1) == 0x0)
6363 return arm_copy_unmodified (gdbarch, insn, "cps", dsc);
6364 else if (op1 == 0x10 && op2 == 0x0 && (rn & 0x1) == 0x1)
6365 return arm_copy_unmodified (gdbarch, insn, "setend", dsc);
6366 else if ((op1 & 0x60) == 0x20)
6367 return arm_copy_unmodified (gdbarch, insn, "neon dataproc", dsc);
6368 else if ((op1 & 0x71) == 0x40)
6369 return arm_copy_unmodified (gdbarch, insn, "neon elt/struct load/store",
6371 else if ((op1 & 0x77) == 0x41)
6372 return arm_copy_unmodified (gdbarch, insn, "unallocated mem hint", dsc);
6373 else if ((op1 & 0x77) == 0x45)
6374 return arm_copy_preload (gdbarch, insn, regs, dsc); /* pli. */
6375 else if ((op1 & 0x77) == 0x51)
6378 return arm_copy_preload (gdbarch, insn, regs, dsc); /* pld/pldw. */
6380 return arm_copy_unpred (gdbarch, insn, dsc);
6382 else if ((op1 & 0x77) == 0x55)
6383 return arm_copy_preload (gdbarch, insn, regs, dsc); /* pld/pldw. */
6384 else if (op1 == 0x57)
6387 case 0x1: return arm_copy_unmodified (gdbarch, insn, "clrex", dsc);
6388 case 0x4: return arm_copy_unmodified (gdbarch, insn, "dsb", dsc);
6389 case 0x5: return arm_copy_unmodified (gdbarch, insn, "dmb", dsc);
6390 case 0x6: return arm_copy_unmodified (gdbarch, insn, "isb", dsc);
6391 default: return arm_copy_unpred (gdbarch, insn, dsc);
6393 else if ((op1 & 0x63) == 0x43)
6394 return arm_copy_unpred (gdbarch, insn, dsc);
6395 else if ((op2 & 0x1) == 0x0)
6396 switch (op1 & ~0x80)
6399 return arm_copy_unmodified (gdbarch, insn, "unallocated mem hint", dsc);
6401 return arm_copy_preload_reg (gdbarch, insn, regs, dsc); /* pli reg. */
6402 case 0x71: case 0x75:
6404 return arm_copy_preload_reg (gdbarch, insn, regs, dsc);
6405 case 0x63: case 0x67: case 0x73: case 0x77:
6406 return arm_copy_unpred (gdbarch, insn, dsc);
6408 return arm_copy_undef (gdbarch, insn, dsc);
6411 return arm_copy_undef (gdbarch, insn, dsc); /* Probably unreachable. */
6415 arm_decode_unconditional (struct gdbarch *gdbarch, uint32_t insn,
6416 struct regcache *regs,
6417 arm_displaced_step_closure *dsc)
6419 if (bit (insn, 27) == 0)
6420 return arm_decode_misc_memhint_neon (gdbarch, insn, regs, dsc);
6421 /* Switch on bits: 0bxxxxx321xxx0xxxxxxxxxxxxxxxxxxxx. */
6422 else switch (((insn & 0x7000000) >> 23) | ((insn & 0x100000) >> 20))
6425 return arm_copy_unmodified (gdbarch, insn, "srs", dsc);
6428 return arm_copy_unmodified (gdbarch, insn, "rfe", dsc);
6430 case 0x4: case 0x5: case 0x6: case 0x7:
6431 return arm_copy_b_bl_blx (gdbarch, insn, regs, dsc);
6434 switch ((insn & 0xe00000) >> 21)
6436 case 0x1: case 0x3: case 0x4: case 0x5: case 0x6: case 0x7:
6438 return arm_copy_copro_load_store (gdbarch, insn, regs, dsc);
6441 return arm_copy_unmodified (gdbarch, insn, "mcrr/mcrr2", dsc);
6444 return arm_copy_undef (gdbarch, insn, dsc);
6449 int rn_f = (bits (insn, 16, 19) == 0xf);
6450 switch ((insn & 0xe00000) >> 21)
6453 /* ldc/ldc2 imm (undefined for rn == pc). */
6454 return rn_f ? arm_copy_undef (gdbarch, insn, dsc)
6455 : arm_copy_copro_load_store (gdbarch, insn, regs, dsc);
6458 return arm_copy_unmodified (gdbarch, insn, "mrrc/mrrc2", dsc);
6460 case 0x4: case 0x5: case 0x6: case 0x7:
6461 /* ldc/ldc2 lit (undefined for rn != pc). */
6462 return rn_f ? arm_copy_copro_load_store (gdbarch, insn, regs, dsc)
6463 : arm_copy_undef (gdbarch, insn, dsc);
6466 return arm_copy_undef (gdbarch, insn, dsc);
6471 return arm_copy_unmodified (gdbarch, insn, "stc/stc2", dsc);
6474 if (bits (insn, 16, 19) == 0xf)
6476 return arm_copy_copro_load_store (gdbarch, insn, regs, dsc);
6478 return arm_copy_undef (gdbarch, insn, dsc);
6482 return arm_copy_unmodified (gdbarch, insn, "mcr/mcr2", dsc);
6484 return arm_copy_unmodified (gdbarch, insn, "cdp/cdp2", dsc);
6488 return arm_copy_unmodified (gdbarch, insn, "mrc/mrc2", dsc);
6490 return arm_copy_unmodified (gdbarch, insn, "cdp/cdp2", dsc);
6493 return arm_copy_undef (gdbarch, insn, dsc);
6497 /* Decode miscellaneous instructions in dp/misc encoding space. */
6500 arm_decode_miscellaneous (struct gdbarch *gdbarch, uint32_t insn,
6501 struct regcache *regs,
6502 arm_displaced_step_closure *dsc)
6504 unsigned int op2 = bits (insn, 4, 6);
6505 unsigned int op = bits (insn, 21, 22);
6510 return arm_copy_unmodified (gdbarch, insn, "mrs/msr", dsc);
6513 if (op == 0x1) /* bx. */
6514 return arm_copy_bx_blx_reg (gdbarch, insn, regs, dsc);
6516 return arm_copy_unmodified (gdbarch, insn, "clz", dsc);
6518 return arm_copy_undef (gdbarch, insn, dsc);
6522 /* Not really supported. */
6523 return arm_copy_unmodified (gdbarch, insn, "bxj", dsc);
6525 return arm_copy_undef (gdbarch, insn, dsc);
6529 return arm_copy_bx_blx_reg (gdbarch, insn,
6530 regs, dsc); /* blx register. */
6532 return arm_copy_undef (gdbarch, insn, dsc);
6535 return arm_copy_unmodified (gdbarch, insn, "saturating add/sub", dsc);
6539 return arm_copy_unmodified (gdbarch, insn, "bkpt", dsc);
6541 /* Not really supported. */
6542 return arm_copy_unmodified (gdbarch, insn, "smc", dsc);
6546 return arm_copy_undef (gdbarch, insn, dsc);
6551 arm_decode_dp_misc (struct gdbarch *gdbarch, uint32_t insn,
6552 struct regcache *regs,
6553 arm_displaced_step_closure *dsc)
6556 switch (bits (insn, 20, 24))
6559 return arm_copy_unmodified (gdbarch, insn, "movw", dsc);
6562 return arm_copy_unmodified (gdbarch, insn, "movt", dsc);
6564 case 0x12: case 0x16:
6565 return arm_copy_unmodified (gdbarch, insn, "msr imm", dsc);
6568 return arm_copy_alu_imm (gdbarch, insn, regs, dsc);
6572 uint32_t op1 = bits (insn, 20, 24), op2 = bits (insn, 4, 7);
6574 if ((op1 & 0x19) != 0x10 && (op2 & 0x1) == 0x0)
6575 return arm_copy_alu_reg (gdbarch, insn, regs, dsc);
6576 else if ((op1 & 0x19) != 0x10 && (op2 & 0x9) == 0x1)
6577 return arm_copy_alu_shifted_reg (gdbarch, insn, regs, dsc);
6578 else if ((op1 & 0x19) == 0x10 && (op2 & 0x8) == 0x0)
6579 return arm_decode_miscellaneous (gdbarch, insn, regs, dsc);
6580 else if ((op1 & 0x19) == 0x10 && (op2 & 0x9) == 0x8)
6581 return arm_copy_unmodified (gdbarch, insn, "halfword mul/mla", dsc);
6582 else if ((op1 & 0x10) == 0x00 && op2 == 0x9)
6583 return arm_copy_unmodified (gdbarch, insn, "mul/mla", dsc);
6584 else if ((op1 & 0x10) == 0x10 && op2 == 0x9)
6585 return arm_copy_unmodified (gdbarch, insn, "synch", dsc);
6586 else if (op2 == 0xb || (op2 & 0xd) == 0xd)
6587 /* 2nd arg means "unprivileged". */
6588 return arm_copy_extra_ld_st (gdbarch, insn, (op1 & 0x12) == 0x02, regs,
6592 /* Should be unreachable. */
6597 arm_decode_ld_st_word_ubyte (struct gdbarch *gdbarch, uint32_t insn,
6598 struct regcache *regs,
6599 arm_displaced_step_closure *dsc)
6601 int a = bit (insn, 25), b = bit (insn, 4);
6602 uint32_t op1 = bits (insn, 20, 24);
6604 if ((!a && (op1 & 0x05) == 0x00 && (op1 & 0x17) != 0x02)
6605 || (a && (op1 & 0x05) == 0x00 && (op1 & 0x17) != 0x02 && !b))
6606 return arm_copy_ldr_str_ldrb_strb (gdbarch, insn, regs, dsc, 0, 4, 0);
6607 else if ((!a && (op1 & 0x17) == 0x02)
6608 || (a && (op1 & 0x17) == 0x02 && !b))
6609 return arm_copy_ldr_str_ldrb_strb (gdbarch, insn, regs, dsc, 0, 4, 1);
6610 else if ((!a && (op1 & 0x05) == 0x01 && (op1 & 0x17) != 0x03)
6611 || (a && (op1 & 0x05) == 0x01 && (op1 & 0x17) != 0x03 && !b))
6612 return arm_copy_ldr_str_ldrb_strb (gdbarch, insn, regs, dsc, 1, 4, 0);
6613 else if ((!a && (op1 & 0x17) == 0x03)
6614 || (a && (op1 & 0x17) == 0x03 && !b))
6615 return arm_copy_ldr_str_ldrb_strb (gdbarch, insn, regs, dsc, 1, 4, 1);
6616 else if ((!a && (op1 & 0x05) == 0x04 && (op1 & 0x17) != 0x06)
6617 || (a && (op1 & 0x05) == 0x04 && (op1 & 0x17) != 0x06 && !b))
6618 return arm_copy_ldr_str_ldrb_strb (gdbarch, insn, regs, dsc, 0, 1, 0);
6619 else if ((!a && (op1 & 0x17) == 0x06)
6620 || (a && (op1 & 0x17) == 0x06 && !b))
6621 return arm_copy_ldr_str_ldrb_strb (gdbarch, insn, regs, dsc, 0, 1, 1);
6622 else if ((!a && (op1 & 0x05) == 0x05 && (op1 & 0x17) != 0x07)
6623 || (a && (op1 & 0x05) == 0x05 && (op1 & 0x17) != 0x07 && !b))
6624 return arm_copy_ldr_str_ldrb_strb (gdbarch, insn, regs, dsc, 1, 1, 0);
6625 else if ((!a && (op1 & 0x17) == 0x07)
6626 || (a && (op1 & 0x17) == 0x07 && !b))
6627 return arm_copy_ldr_str_ldrb_strb (gdbarch, insn, regs, dsc, 1, 1, 1);
6629 /* Should be unreachable. */
6634 arm_decode_media (struct gdbarch *gdbarch, uint32_t insn,
6635 arm_displaced_step_closure *dsc)
6637 switch (bits (insn, 20, 24))
6639 case 0x00: case 0x01: case 0x02: case 0x03:
6640 return arm_copy_unmodified (gdbarch, insn, "parallel add/sub signed", dsc);
6642 case 0x04: case 0x05: case 0x06: case 0x07:
6643 return arm_copy_unmodified (gdbarch, insn, "parallel add/sub unsigned", dsc);
6645 case 0x08: case 0x09: case 0x0a: case 0x0b:
6646 case 0x0c: case 0x0d: case 0x0e: case 0x0f:
6647 return arm_copy_unmodified (gdbarch, insn,
6648 "decode/pack/unpack/saturate/reverse", dsc);
6651 if (bits (insn, 5, 7) == 0) /* op2. */
6653 if (bits (insn, 12, 15) == 0xf)
6654 return arm_copy_unmodified (gdbarch, insn, "usad8", dsc);
6656 return arm_copy_unmodified (gdbarch, insn, "usada8", dsc);
6659 return arm_copy_undef (gdbarch, insn, dsc);
6661 case 0x1a: case 0x1b:
6662 if (bits (insn, 5, 6) == 0x2) /* op2[1:0]. */
6663 return arm_copy_unmodified (gdbarch, insn, "sbfx", dsc);
6665 return arm_copy_undef (gdbarch, insn, dsc);
6667 case 0x1c: case 0x1d:
6668 if (bits (insn, 5, 6) == 0x0) /* op2[1:0]. */
6670 if (bits (insn, 0, 3) == 0xf)
6671 return arm_copy_unmodified (gdbarch, insn, "bfc", dsc);
6673 return arm_copy_unmodified (gdbarch, insn, "bfi", dsc);
6676 return arm_copy_undef (gdbarch, insn, dsc);
6678 case 0x1e: case 0x1f:
6679 if (bits (insn, 5, 6) == 0x2) /* op2[1:0]. */
6680 return arm_copy_unmodified (gdbarch, insn, "ubfx", dsc);
6682 return arm_copy_undef (gdbarch, insn, dsc);
6685 /* Should be unreachable. */
6690 arm_decode_b_bl_ldmstm (struct gdbarch *gdbarch, uint32_t insn,
6691 struct regcache *regs,
6692 arm_displaced_step_closure *dsc)
6695 return arm_copy_b_bl_blx (gdbarch, insn, regs, dsc);
6697 return arm_copy_block_xfer (gdbarch, insn, regs, dsc);
6701 arm_decode_ext_reg_ld_st (struct gdbarch *gdbarch, uint32_t insn,
6702 struct regcache *regs,
6703 arm_displaced_step_closure *dsc)
6705 unsigned int opcode = bits (insn, 20, 24);
6709 case 0x04: case 0x05: /* VFP/Neon mrrc/mcrr. */
6710 return arm_copy_unmodified (gdbarch, insn, "vfp/neon mrrc/mcrr", dsc);
6712 case 0x08: case 0x0a: case 0x0c: case 0x0e:
6713 case 0x12: case 0x16:
6714 return arm_copy_unmodified (gdbarch, insn, "vfp/neon vstm/vpush", dsc);
6716 case 0x09: case 0x0b: case 0x0d: case 0x0f:
6717 case 0x13: case 0x17:
6718 return arm_copy_unmodified (gdbarch, insn, "vfp/neon vldm/vpop", dsc);
6720 case 0x10: case 0x14: case 0x18: case 0x1c: /* vstr. */
6721 case 0x11: case 0x15: case 0x19: case 0x1d: /* vldr. */
6722 /* Note: no writeback for these instructions. Bit 25 will always be
6723 zero though (via caller), so the following works OK. */
6724 return arm_copy_copro_load_store (gdbarch, insn, regs, dsc);
6727 /* Should be unreachable. */
6731 /* Decode shifted register instructions. */
6734 thumb2_decode_dp_shift_reg (struct gdbarch *gdbarch, uint16_t insn1,
6735 uint16_t insn2, struct regcache *regs,
6736 arm_displaced_step_closure *dsc)
6738 /* PC is only allowed to be used in instruction MOV. */
6740 unsigned int op = bits (insn1, 5, 8);
6741 unsigned int rn = bits (insn1, 0, 3);
6743 if (op == 0x2 && rn == 0xf) /* MOV */
6744 return thumb2_copy_alu_imm (gdbarch, insn1, insn2, regs, dsc);
6746 return thumb_copy_unmodified_32bit (gdbarch, insn1, insn2,
6747 "dp (shift reg)", dsc);
6751 /* Decode extension register load/store. Exactly the same as
6752 arm_decode_ext_reg_ld_st. */
6755 thumb2_decode_ext_reg_ld_st (struct gdbarch *gdbarch, uint16_t insn1,
6756 uint16_t insn2, struct regcache *regs,
6757 arm_displaced_step_closure *dsc)
6759 unsigned int opcode = bits (insn1, 4, 8);
6763 case 0x04: case 0x05:
6764 return thumb_copy_unmodified_32bit (gdbarch, insn1, insn2,
6765 "vfp/neon vmov", dsc);
6767 case 0x08: case 0x0c: /* 01x00 */
6768 case 0x0a: case 0x0e: /* 01x10 */
6769 case 0x12: case 0x16: /* 10x10 */
6770 return thumb_copy_unmodified_32bit (gdbarch, insn1, insn2,
6771 "vfp/neon vstm/vpush", dsc);
6773 case 0x09: case 0x0d: /* 01x01 */
6774 case 0x0b: case 0x0f: /* 01x11 */
6775 case 0x13: case 0x17: /* 10x11 */
6776 return thumb_copy_unmodified_32bit (gdbarch, insn1, insn2,
6777 "vfp/neon vldm/vpop", dsc);
6779 case 0x10: case 0x14: case 0x18: case 0x1c: /* vstr. */
6780 return thumb_copy_unmodified_32bit (gdbarch, insn1, insn2,
6782 case 0x11: case 0x15: case 0x19: case 0x1d: /* vldr. */
6783 return thumb2_copy_copro_load_store (gdbarch, insn1, insn2, regs, dsc);
6786 /* Should be unreachable. */
6791 arm_decode_svc_copro (struct gdbarch *gdbarch, uint32_t insn,
6792 struct regcache *regs, arm_displaced_step_closure *dsc)
6794 unsigned int op1 = bits (insn, 20, 25);
6795 int op = bit (insn, 4);
6796 unsigned int coproc = bits (insn, 8, 11);
6798 if ((op1 & 0x20) == 0x00 && (op1 & 0x3a) != 0x00 && (coproc & 0xe) == 0xa)
6799 return arm_decode_ext_reg_ld_st (gdbarch, insn, regs, dsc);
6800 else if ((op1 & 0x21) == 0x00 && (op1 & 0x3a) != 0x00
6801 && (coproc & 0xe) != 0xa)
6803 return arm_copy_copro_load_store (gdbarch, insn, regs, dsc);
6804 else if ((op1 & 0x21) == 0x01 && (op1 & 0x3a) != 0x00
6805 && (coproc & 0xe) != 0xa)
6806 /* ldc/ldc2 imm/lit. */
6807 return arm_copy_copro_load_store (gdbarch, insn, regs, dsc);
6808 else if ((op1 & 0x3e) == 0x00)
6809 return arm_copy_undef (gdbarch, insn, dsc);
6810 else if ((op1 & 0x3e) == 0x04 && (coproc & 0xe) == 0xa)
6811 return arm_copy_unmodified (gdbarch, insn, "neon 64bit xfer", dsc);
6812 else if (op1 == 0x04 && (coproc & 0xe) != 0xa)
6813 return arm_copy_unmodified (gdbarch, insn, "mcrr/mcrr2", dsc);
6814 else if (op1 == 0x05 && (coproc & 0xe) != 0xa)
6815 return arm_copy_unmodified (gdbarch, insn, "mrrc/mrrc2", dsc);
6816 else if ((op1 & 0x30) == 0x20 && !op)
6818 if ((coproc & 0xe) == 0xa)
6819 return arm_copy_unmodified (gdbarch, insn, "vfp dataproc", dsc);
6821 return arm_copy_unmodified (gdbarch, insn, "cdp/cdp2", dsc);
6823 else if ((op1 & 0x30) == 0x20 && op)
6824 return arm_copy_unmodified (gdbarch, insn, "neon 8/16/32 bit xfer", dsc);
6825 else if ((op1 & 0x31) == 0x20 && op && (coproc & 0xe) != 0xa)
6826 return arm_copy_unmodified (gdbarch, insn, "mcr/mcr2", dsc);
6827 else if ((op1 & 0x31) == 0x21 && op && (coproc & 0xe) != 0xa)
6828 return arm_copy_unmodified (gdbarch, insn, "mrc/mrc2", dsc);
6829 else if ((op1 & 0x30) == 0x30)
6830 return arm_copy_svc (gdbarch, insn, regs, dsc);
6832 return arm_copy_undef (gdbarch, insn, dsc); /* Possibly unreachable. */
6836 thumb2_decode_svc_copro (struct gdbarch *gdbarch, uint16_t insn1,
6837 uint16_t insn2, struct regcache *regs,
6838 arm_displaced_step_closure *dsc)
6840 unsigned int coproc = bits (insn2, 8, 11);
6841 unsigned int bit_5_8 = bits (insn1, 5, 8);
6842 unsigned int bit_9 = bit (insn1, 9);
6843 unsigned int bit_4 = bit (insn1, 4);
6848 return thumb_copy_unmodified_32bit (gdbarch, insn1, insn2,
6849 "neon 64bit xfer/mrrc/mrrc2/mcrr/mcrr2",
6851 else if (bit_5_8 == 0) /* UNDEFINED. */
6852 return thumb_32bit_copy_undef (gdbarch, insn1, insn2, dsc);
6855 /*coproc is 101x. SIMD/VFP, ext registers load/store. */
6856 if ((coproc & 0xe) == 0xa)
6857 return thumb2_decode_ext_reg_ld_st (gdbarch, insn1, insn2, regs,
6859 else /* coproc is not 101x. */
6861 if (bit_4 == 0) /* STC/STC2. */
6862 return thumb_copy_unmodified_32bit (gdbarch, insn1, insn2,
6864 else /* LDC/LDC2 {literal, immeidate}. */
6865 return thumb2_copy_copro_load_store (gdbarch, insn1, insn2,
6871 return thumb_copy_unmodified_32bit (gdbarch, insn1, insn2, "coproc", dsc);
6877 install_pc_relative (struct gdbarch *gdbarch, struct regcache *regs,
6878 arm_displaced_step_closure *dsc, int rd)
6884 Preparation: Rd <- PC
6890 int val = displaced_read_reg (regs, dsc, ARM_PC_REGNUM);
6891 displaced_write_reg (regs, dsc, rd, val, CANNOT_WRITE_PC);
6895 thumb_copy_pc_relative_16bit (struct gdbarch *gdbarch, struct regcache *regs,
6896 arm_displaced_step_closure *dsc,
6897 int rd, unsigned int imm)
6900 /* Encoding T2: ADDS Rd, #imm */
6901 dsc->modinsn[0] = (0x3000 | (rd << 8) | imm);
6903 install_pc_relative (gdbarch, regs, dsc, rd);
6909 thumb_decode_pc_relative_16bit (struct gdbarch *gdbarch, uint16_t insn,
6910 struct regcache *regs,
6911 arm_displaced_step_closure *dsc)
6913 unsigned int rd = bits (insn, 8, 10);
6914 unsigned int imm8 = bits (insn, 0, 7);
6916 if (debug_displaced)
6917 fprintf_unfiltered (gdb_stdlog,
6918 "displaced: copying thumb adr r%d, #%d insn %.4x\n",
6921 return thumb_copy_pc_relative_16bit (gdbarch, regs, dsc, rd, imm8);
6925 thumb_copy_pc_relative_32bit (struct gdbarch *gdbarch, uint16_t insn1,
6926 uint16_t insn2, struct regcache *regs,
6927 arm_displaced_step_closure *dsc)
6929 unsigned int rd = bits (insn2, 8, 11);
6930 /* Since immediate has the same encoding in ADR ADD and SUB, so we simply
6931 extract raw immediate encoding rather than computing immediate. When
6932 generating ADD or SUB instruction, we can simply perform OR operation to
6933 set immediate into ADD. */
6934 unsigned int imm_3_8 = insn2 & 0x70ff;
6935 unsigned int imm_i = insn1 & 0x0400; /* Clear all bits except bit 10. */
6937 if (debug_displaced)
6938 fprintf_unfiltered (gdb_stdlog,
6939 "displaced: copying thumb adr r%d, #%d:%d insn %.4x%.4x\n",
6940 rd, imm_i, imm_3_8, insn1, insn2);
6942 if (bit (insn1, 7)) /* Encoding T2 */
6944 /* Encoding T3: SUB Rd, Rd, #imm */
6945 dsc->modinsn[0] = (0xf1a0 | rd | imm_i);
6946 dsc->modinsn[1] = ((rd << 8) | imm_3_8);
6948 else /* Encoding T3 */
6950 /* Encoding T3: ADD Rd, Rd, #imm */
6951 dsc->modinsn[0] = (0xf100 | rd | imm_i);
6952 dsc->modinsn[1] = ((rd << 8) | imm_3_8);
6956 install_pc_relative (gdbarch, regs, dsc, rd);
6962 thumb_copy_16bit_ldr_literal (struct gdbarch *gdbarch, uint16_t insn1,
6963 struct regcache *regs,
6964 arm_displaced_step_closure *dsc)
6966 unsigned int rt = bits (insn1, 8, 10);
6968 int imm8 = (bits (insn1, 0, 7) << 2);
6974 Preparation: tmp0 <- R0, tmp2 <- R2, tmp3 <- R3, R2 <- PC, R3 <- #imm8;
6976 Insn: LDR R0, [R2, R3];
6977 Cleanup: R2 <- tmp2, R3 <- tmp3, Rd <- R0, R0 <- tmp0 */
6979 if (debug_displaced)
6980 fprintf_unfiltered (gdb_stdlog,
6981 "displaced: copying thumb ldr r%d [pc #%d]\n"
6984 dsc->tmp[0] = displaced_read_reg (regs, dsc, 0);
6985 dsc->tmp[2] = displaced_read_reg (regs, dsc, 2);
6986 dsc->tmp[3] = displaced_read_reg (regs, dsc, 3);
6987 pc = displaced_read_reg (regs, dsc, ARM_PC_REGNUM);
6988 /* The assembler calculates the required value of the offset from the
6989 Align(PC,4) value of this instruction to the label. */
6990 pc = pc & 0xfffffffc;
6992 displaced_write_reg (regs, dsc, 2, pc, CANNOT_WRITE_PC);
6993 displaced_write_reg (regs, dsc, 3, imm8, CANNOT_WRITE_PC);
6996 dsc->u.ldst.xfersize = 4;
6998 dsc->u.ldst.immed = 0;
6999 dsc->u.ldst.writeback = 0;
7000 dsc->u.ldst.restore_r4 = 0;
7002 dsc->modinsn[0] = 0x58d0; /* ldr r0, [r2, r3]*/
7004 dsc->cleanup = &cleanup_load;
7009 /* Copy Thumb cbnz/cbz insruction. */
7012 thumb_copy_cbnz_cbz (struct gdbarch *gdbarch, uint16_t insn1,
7013 struct regcache *regs,
7014 arm_displaced_step_closure *dsc)
7016 int non_zero = bit (insn1, 11);
7017 unsigned int imm5 = (bit (insn1, 9) << 6) | (bits (insn1, 3, 7) << 1);
7018 CORE_ADDR from = dsc->insn_addr;
7019 int rn = bits (insn1, 0, 2);
7020 int rn_val = displaced_read_reg (regs, dsc, rn);
7022 dsc->u.branch.cond = (rn_val && non_zero) || (!rn_val && !non_zero);
7023 /* CBNZ and CBZ do not affect the condition flags. If condition is true,
7024 set it INST_AL, so cleanup_branch will know branch is taken, otherwise,
7025 condition is false, let it be, cleanup_branch will do nothing. */
7026 if (dsc->u.branch.cond)
7028 dsc->u.branch.cond = INST_AL;
7029 dsc->u.branch.dest = from + 4 + imm5;
7032 dsc->u.branch.dest = from + 2;
7034 dsc->u.branch.link = 0;
7035 dsc->u.branch.exchange = 0;
7037 if (debug_displaced)
7038 fprintf_unfiltered (gdb_stdlog, "displaced: copying %s [r%d = 0x%x]"
7039 " insn %.4x to %.8lx\n", non_zero ? "cbnz" : "cbz",
7040 rn, rn_val, insn1, dsc->u.branch.dest);
7042 dsc->modinsn[0] = THUMB_NOP;
7044 dsc->cleanup = &cleanup_branch;
7048 /* Copy Table Branch Byte/Halfword */
7050 thumb2_copy_table_branch (struct gdbarch *gdbarch, uint16_t insn1,
7051 uint16_t insn2, struct regcache *regs,
7052 arm_displaced_step_closure *dsc)
7054 ULONGEST rn_val, rm_val;
7055 int is_tbh = bit (insn2, 4);
7056 CORE_ADDR halfwords = 0;
7057 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
7059 rn_val = displaced_read_reg (regs, dsc, bits (insn1, 0, 3));
7060 rm_val = displaced_read_reg (regs, dsc, bits (insn2, 0, 3));
7066 target_read_memory (rn_val + 2 * rm_val, buf, 2);
7067 halfwords = extract_unsigned_integer (buf, 2, byte_order);
7073 target_read_memory (rn_val + rm_val, buf, 1);
7074 halfwords = extract_unsigned_integer (buf, 1, byte_order);
7077 if (debug_displaced)
7078 fprintf_unfiltered (gdb_stdlog, "displaced: %s base 0x%x offset 0x%x"
7079 " offset 0x%x\n", is_tbh ? "tbh" : "tbb",
7080 (unsigned int) rn_val, (unsigned int) rm_val,
7081 (unsigned int) halfwords);
7083 dsc->u.branch.cond = INST_AL;
7084 dsc->u.branch.link = 0;
7085 dsc->u.branch.exchange = 0;
7086 dsc->u.branch.dest = dsc->insn_addr + 4 + 2 * halfwords;
7088 dsc->cleanup = &cleanup_branch;
7094 cleanup_pop_pc_16bit_all (struct gdbarch *gdbarch, struct regcache *regs,
7095 arm_displaced_step_closure *dsc)
7098 int val = displaced_read_reg (regs, dsc, 7);
7099 displaced_write_reg (regs, dsc, ARM_PC_REGNUM, val, BX_WRITE_PC);
7102 val = displaced_read_reg (regs, dsc, 8);
7103 displaced_write_reg (regs, dsc, 7, val, CANNOT_WRITE_PC);
7106 displaced_write_reg (regs, dsc, 8, dsc->tmp[0], CANNOT_WRITE_PC);
7111 thumb_copy_pop_pc_16bit (struct gdbarch *gdbarch, uint16_t insn1,
7112 struct regcache *regs,
7113 arm_displaced_step_closure *dsc)
7115 dsc->u.block.regmask = insn1 & 0x00ff;
7117 /* Rewrite instruction: POP {rX, rY, ...,rZ, PC}
7120 (1) register list is full, that is, r0-r7 are used.
7121 Prepare: tmp[0] <- r8
7123 POP {r0, r1, ...., r6, r7}; remove PC from reglist
7124 MOV r8, r7; Move value of r7 to r8;
7125 POP {r7}; Store PC value into r7.
7127 Cleanup: PC <- r7, r7 <- r8, r8 <-tmp[0]
7129 (2) register list is not full, supposing there are N registers in
7130 register list (except PC, 0 <= N <= 7).
7131 Prepare: for each i, 0 - N, tmp[i] <- ri.
7133 POP {r0, r1, ...., rN};
7135 Cleanup: Set registers in original reglist from r0 - rN. Restore r0 - rN
7136 from tmp[] properly.
7138 if (debug_displaced)
7139 fprintf_unfiltered (gdb_stdlog,
7140 "displaced: copying thumb pop {%.8x, pc} insn %.4x\n",
7141 dsc->u.block.regmask, insn1);
7143 if (dsc->u.block.regmask == 0xff)
7145 dsc->tmp[0] = displaced_read_reg (regs, dsc, 8);
7147 dsc->modinsn[0] = (insn1 & 0xfeff); /* POP {r0,r1,...,r6, r7} */
7148 dsc->modinsn[1] = 0x46b8; /* MOV r8, r7 */
7149 dsc->modinsn[2] = 0xbc80; /* POP {r7} */
7152 dsc->cleanup = &cleanup_pop_pc_16bit_all;
7156 unsigned int num_in_list = bitcount (dsc->u.block.regmask);
7158 unsigned int new_regmask;
7160 for (i = 0; i < num_in_list + 1; i++)
7161 dsc->tmp[i] = displaced_read_reg (regs, dsc, i);
7163 new_regmask = (1 << (num_in_list + 1)) - 1;
7165 if (debug_displaced)
7166 fprintf_unfiltered (gdb_stdlog, _("displaced: POP "
7167 "{..., pc}: original reg list %.4x,"
7168 " modified list %.4x\n"),
7169 (int) dsc->u.block.regmask, new_regmask);
7171 dsc->u.block.regmask |= 0x8000;
7172 dsc->u.block.writeback = 0;
7173 dsc->u.block.cond = INST_AL;
7175 dsc->modinsn[0] = (insn1 & ~0x1ff) | (new_regmask & 0xff);
7177 dsc->cleanup = &cleanup_block_load_pc;
7184 thumb_process_displaced_16bit_insn (struct gdbarch *gdbarch, uint16_t insn1,
7185 struct regcache *regs,
7186 arm_displaced_step_closure *dsc)
7188 unsigned short op_bit_12_15 = bits (insn1, 12, 15);
7189 unsigned short op_bit_10_11 = bits (insn1, 10, 11);
7192 /* 16-bit thumb instructions. */
7193 switch (op_bit_12_15)
7195 /* Shift (imme), add, subtract, move and compare. */
7196 case 0: case 1: case 2: case 3:
7197 err = thumb_copy_unmodified_16bit (gdbarch, insn1,
7198 "shift/add/sub/mov/cmp",
7202 switch (op_bit_10_11)
7204 case 0: /* Data-processing */
7205 err = thumb_copy_unmodified_16bit (gdbarch, insn1,
7209 case 1: /* Special data instructions and branch and exchange. */
7211 unsigned short op = bits (insn1, 7, 9);
7212 if (op == 6 || op == 7) /* BX or BLX */
7213 err = thumb_copy_bx_blx_reg (gdbarch, insn1, regs, dsc);
7214 else if (bits (insn1, 6, 7) != 0) /* ADD/MOV/CMP high registers. */
7215 err = thumb_copy_alu_reg (gdbarch, insn1, regs, dsc);
7217 err = thumb_copy_unmodified_16bit (gdbarch, insn1, "special data",
7221 default: /* LDR (literal) */
7222 err = thumb_copy_16bit_ldr_literal (gdbarch, insn1, regs, dsc);
7225 case 5: case 6: case 7: case 8: case 9: /* Load/Store single data item */
7226 err = thumb_copy_unmodified_16bit (gdbarch, insn1, "ldr/str", dsc);
7229 if (op_bit_10_11 < 2) /* Generate PC-relative address */
7230 err = thumb_decode_pc_relative_16bit (gdbarch, insn1, regs, dsc);
7231 else /* Generate SP-relative address */
7232 err = thumb_copy_unmodified_16bit (gdbarch, insn1, "sp-relative", dsc);
7234 case 11: /* Misc 16-bit instructions */
7236 switch (bits (insn1, 8, 11))
7238 case 1: case 3: case 9: case 11: /* CBNZ, CBZ */
7239 err = thumb_copy_cbnz_cbz (gdbarch, insn1, regs, dsc);
7241 case 12: case 13: /* POP */
7242 if (bit (insn1, 8)) /* PC is in register list. */
7243 err = thumb_copy_pop_pc_16bit (gdbarch, insn1, regs, dsc);
7245 err = thumb_copy_unmodified_16bit (gdbarch, insn1, "pop", dsc);
7247 case 15: /* If-Then, and hints */
7248 if (bits (insn1, 0, 3))
7249 /* If-Then makes up to four following instructions conditional.
7250 IT instruction itself is not conditional, so handle it as a
7251 common unmodified instruction. */
7252 err = thumb_copy_unmodified_16bit (gdbarch, insn1, "If-Then",
7255 err = thumb_copy_unmodified_16bit (gdbarch, insn1, "hints", dsc);
7258 err = thumb_copy_unmodified_16bit (gdbarch, insn1, "misc", dsc);
7263 if (op_bit_10_11 < 2) /* Store multiple registers */
7264 err = thumb_copy_unmodified_16bit (gdbarch, insn1, "stm", dsc);
7265 else /* Load multiple registers */
7266 err = thumb_copy_unmodified_16bit (gdbarch, insn1, "ldm", dsc);
7268 case 13: /* Conditional branch and supervisor call */
7269 if (bits (insn1, 9, 11) != 7) /* conditional branch */
7270 err = thumb_copy_b (gdbarch, insn1, dsc);
7272 err = thumb_copy_svc (gdbarch, insn1, regs, dsc);
7274 case 14: /* Unconditional branch */
7275 err = thumb_copy_b (gdbarch, insn1, dsc);
7282 internal_error (__FILE__, __LINE__,
7283 _("thumb_process_displaced_16bit_insn: Instruction decode error"));
7287 decode_thumb_32bit_ld_mem_hints (struct gdbarch *gdbarch,
7288 uint16_t insn1, uint16_t insn2,
7289 struct regcache *regs,
7290 arm_displaced_step_closure *dsc)
7292 int rt = bits (insn2, 12, 15);
7293 int rn = bits (insn1, 0, 3);
7294 int op1 = bits (insn1, 7, 8);
7296 switch (bits (insn1, 5, 6))
7298 case 0: /* Load byte and memory hints */
7299 if (rt == 0xf) /* PLD/PLI */
7302 /* PLD literal or Encoding T3 of PLI(immediate, literal). */
7303 return thumb2_copy_preload (gdbarch, insn1, insn2, regs, dsc);
7305 return thumb_copy_unmodified_32bit (gdbarch, insn1, insn2,
7310 if (rn == 0xf) /* LDRB/LDRSB (literal) */
7311 return thumb2_copy_load_literal (gdbarch, insn1, insn2, regs, dsc,
7314 return thumb_copy_unmodified_32bit (gdbarch, insn1, insn2,
7315 "ldrb{reg, immediate}/ldrbt",
7320 case 1: /* Load halfword and memory hints. */
7321 if (rt == 0xf) /* PLD{W} and Unalloc memory hint. */
7322 return thumb_copy_unmodified_32bit (gdbarch, insn1, insn2,
7323 "pld/unalloc memhint", dsc);
7327 return thumb2_copy_load_literal (gdbarch, insn1, insn2, regs, dsc,
7330 return thumb_copy_unmodified_32bit (gdbarch, insn1, insn2,
7334 case 2: /* Load word */
7336 int insn2_bit_8_11 = bits (insn2, 8, 11);
7339 return thumb2_copy_load_literal (gdbarch, insn1, insn2, regs, dsc, 4);
7340 else if (op1 == 0x1) /* Encoding T3 */
7341 return thumb2_copy_load_reg_imm (gdbarch, insn1, insn2, regs, dsc,
7343 else /* op1 == 0x0 */
7345 if (insn2_bit_8_11 == 0xc || (insn2_bit_8_11 & 0x9) == 0x9)
7346 /* LDR (immediate) */
7347 return thumb2_copy_load_reg_imm (gdbarch, insn1, insn2, regs,
7348 dsc, bit (insn2, 8), 1);
7349 else if (insn2_bit_8_11 == 0xe) /* LDRT */
7350 return thumb_copy_unmodified_32bit (gdbarch, insn1, insn2,
7353 /* LDR (register) */
7354 return thumb2_copy_load_reg_imm (gdbarch, insn1, insn2, regs,
7360 return thumb_32bit_copy_undef (gdbarch, insn1, insn2, dsc);
7367 thumb_process_displaced_32bit_insn (struct gdbarch *gdbarch, uint16_t insn1,
7368 uint16_t insn2, struct regcache *regs,
7369 arm_displaced_step_closure *dsc)
7372 unsigned short op = bit (insn2, 15);
7373 unsigned int op1 = bits (insn1, 11, 12);
7379 switch (bits (insn1, 9, 10))
7384 /* Load/store {dual, execlusive}, table branch. */
7385 if (bits (insn1, 7, 8) == 1 && bits (insn1, 4, 5) == 1
7386 && bits (insn2, 5, 7) == 0)
7387 err = thumb2_copy_table_branch (gdbarch, insn1, insn2, regs,
7390 /* PC is not allowed to use in load/store {dual, exclusive}
7392 err = thumb_copy_unmodified_32bit (gdbarch, insn1, insn2,
7393 "load/store dual/ex", dsc);
7395 else /* load/store multiple */
7397 switch (bits (insn1, 7, 8))
7399 case 0: case 3: /* SRS, RFE */
7400 err = thumb_copy_unmodified_32bit (gdbarch, insn1, insn2,
7403 case 1: case 2: /* LDM/STM/PUSH/POP */
7404 err = thumb2_copy_block_xfer (gdbarch, insn1, insn2, regs, dsc);
7411 /* Data-processing (shift register). */
7412 err = thumb2_decode_dp_shift_reg (gdbarch, insn1, insn2, regs,
7415 default: /* Coprocessor instructions. */
7416 err = thumb2_decode_svc_copro (gdbarch, insn1, insn2, regs, dsc);
7421 case 2: /* op1 = 2 */
7422 if (op) /* Branch and misc control. */
7424 if (bit (insn2, 14) /* BLX/BL */
7425 || bit (insn2, 12) /* Unconditional branch */
7426 || (bits (insn1, 7, 9) != 0x7)) /* Conditional branch */
7427 err = thumb2_copy_b_bl_blx (gdbarch, insn1, insn2, regs, dsc);
7429 err = thumb_copy_unmodified_32bit (gdbarch, insn1, insn2,
7434 if (bit (insn1, 9)) /* Data processing (plain binary imm). */
7436 int dp_op = bits (insn1, 4, 8);
7437 int rn = bits (insn1, 0, 3);
7438 if ((dp_op == 0 || dp_op == 0xa) && rn == 0xf)
7439 err = thumb_copy_pc_relative_32bit (gdbarch, insn1, insn2,
7442 err = thumb_copy_unmodified_32bit (gdbarch, insn1, insn2,
7445 else /* Data processing (modified immeidate) */
7446 err = thumb_copy_unmodified_32bit (gdbarch, insn1, insn2,
7450 case 3: /* op1 = 3 */
7451 switch (bits (insn1, 9, 10))
7455 err = decode_thumb_32bit_ld_mem_hints (gdbarch, insn1, insn2,
7457 else /* NEON Load/Store and Store single data item */
7458 err = thumb_copy_unmodified_32bit (gdbarch, insn1, insn2,
7459 "neon elt/struct load/store",
7462 case 1: /* op1 = 3, bits (9, 10) == 1 */
7463 switch (bits (insn1, 7, 8))
7465 case 0: case 1: /* Data processing (register) */
7466 err = thumb_copy_unmodified_32bit (gdbarch, insn1, insn2,
7469 case 2: /* Multiply and absolute difference */
7470 err = thumb_copy_unmodified_32bit (gdbarch, insn1, insn2,
7471 "mul/mua/diff", dsc);
7473 case 3: /* Long multiply and divide */
7474 err = thumb_copy_unmodified_32bit (gdbarch, insn1, insn2,
7479 default: /* Coprocessor instructions */
7480 err = thumb2_decode_svc_copro (gdbarch, insn1, insn2, regs, dsc);
7489 internal_error (__FILE__, __LINE__,
7490 _("thumb_process_displaced_32bit_insn: Instruction decode error"));
7495 thumb_process_displaced_insn (struct gdbarch *gdbarch, CORE_ADDR from,
7496 struct regcache *regs,
7497 arm_displaced_step_closure *dsc)
7499 enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
7501 = read_memory_unsigned_integer (from, 2, byte_order_for_code);
7503 if (debug_displaced)
7504 fprintf_unfiltered (gdb_stdlog, "displaced: process thumb insn %.4x "
7505 "at %.8lx\n", insn1, (unsigned long) from);
7508 dsc->insn_size = thumb_insn_size (insn1);
7509 if (thumb_insn_size (insn1) == 4)
7512 = read_memory_unsigned_integer (from + 2, 2, byte_order_for_code);
7513 thumb_process_displaced_32bit_insn (gdbarch, insn1, insn2, regs, dsc);
7516 thumb_process_displaced_16bit_insn (gdbarch, insn1, regs, dsc);
7520 arm_process_displaced_insn (struct gdbarch *gdbarch, CORE_ADDR from,
7521 CORE_ADDR to, struct regcache *regs,
7522 arm_displaced_step_closure *dsc)
7525 enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
7528 /* Most displaced instructions use a 1-instruction scratch space, so set this
7529 here and override below if/when necessary. */
7531 dsc->insn_addr = from;
7532 dsc->scratch_base = to;
7533 dsc->cleanup = NULL;
7534 dsc->wrote_to_pc = 0;
7536 if (!displaced_in_arm_mode (regs))
7537 return thumb_process_displaced_insn (gdbarch, from, regs, dsc);
7541 insn = read_memory_unsigned_integer (from, 4, byte_order_for_code);
7542 if (debug_displaced)
7543 fprintf_unfiltered (gdb_stdlog, "displaced: stepping insn %.8lx "
7544 "at %.8lx\n", (unsigned long) insn,
7545 (unsigned long) from);
7547 if ((insn & 0xf0000000) == 0xf0000000)
7548 err = arm_decode_unconditional (gdbarch, insn, regs, dsc);
7549 else switch (((insn & 0x10) >> 4) | ((insn & 0xe000000) >> 24))
7551 case 0x0: case 0x1: case 0x2: case 0x3:
7552 err = arm_decode_dp_misc (gdbarch, insn, regs, dsc);
7555 case 0x4: case 0x5: case 0x6:
7556 err = arm_decode_ld_st_word_ubyte (gdbarch, insn, regs, dsc);
7560 err = arm_decode_media (gdbarch, insn, dsc);
7563 case 0x8: case 0x9: case 0xa: case 0xb:
7564 err = arm_decode_b_bl_ldmstm (gdbarch, insn, regs, dsc);
7567 case 0xc: case 0xd: case 0xe: case 0xf:
7568 err = arm_decode_svc_copro (gdbarch, insn, regs, dsc);
7573 internal_error (__FILE__, __LINE__,
7574 _("arm_process_displaced_insn: Instruction decode error"));
7577 /* Actually set up the scratch space for a displaced instruction. */
7580 arm_displaced_init_closure (struct gdbarch *gdbarch, CORE_ADDR from,
7581 CORE_ADDR to, arm_displaced_step_closure *dsc)
7583 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
7584 unsigned int i, len, offset;
7585 enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
7586 int size = dsc->is_thumb? 2 : 4;
7587 const gdb_byte *bkp_insn;
7590 /* Poke modified instruction(s). */
7591 for (i = 0; i < dsc->numinsns; i++)
7593 if (debug_displaced)
7595 fprintf_unfiltered (gdb_stdlog, "displaced: writing insn ");
7597 fprintf_unfiltered (gdb_stdlog, "%.8lx",
7600 fprintf_unfiltered (gdb_stdlog, "%.4x",
7601 (unsigned short)dsc->modinsn[i]);
7603 fprintf_unfiltered (gdb_stdlog, " at %.8lx\n",
7604 (unsigned long) to + offset);
7607 write_memory_unsigned_integer (to + offset, size,
7608 byte_order_for_code,
7613 /* Choose the correct breakpoint instruction. */
7616 bkp_insn = tdep->thumb_breakpoint;
7617 len = tdep->thumb_breakpoint_size;
7621 bkp_insn = tdep->arm_breakpoint;
7622 len = tdep->arm_breakpoint_size;
7625 /* Put breakpoint afterwards. */
7626 write_memory (to + offset, bkp_insn, len);
7628 if (debug_displaced)
7629 fprintf_unfiltered (gdb_stdlog, "displaced: copy %s->%s: ",
7630 paddress (gdbarch, from), paddress (gdbarch, to));
7633 /* Entry point for cleaning things up after a displaced instruction has been
7637 arm_displaced_step_fixup (struct gdbarch *gdbarch,
7638 struct displaced_step_closure *dsc_,
7639 CORE_ADDR from, CORE_ADDR to,
7640 struct regcache *regs)
7642 arm_displaced_step_closure *dsc = (arm_displaced_step_closure *) dsc_;
7645 dsc->cleanup (gdbarch, regs, dsc);
7647 if (!dsc->wrote_to_pc)
7648 regcache_cooked_write_unsigned (regs, ARM_PC_REGNUM,
7649 dsc->insn_addr + dsc->insn_size);
7653 #include "bfd-in2.h"
7654 #include "libcoff.h"
7657 gdb_print_insn_arm (bfd_vma memaddr, disassemble_info *info)
7659 gdb_disassembler *di
7660 = static_cast<gdb_disassembler *>(info->application_data);
7661 struct gdbarch *gdbarch = di->arch ();
7663 if (arm_pc_is_thumb (gdbarch, memaddr))
7665 static asymbol *asym;
7666 static combined_entry_type ce;
7667 static struct coff_symbol_struct csym;
7668 static struct bfd fake_bfd;
7669 static bfd_target fake_target;
7671 if (csym.native == NULL)
7673 /* Create a fake symbol vector containing a Thumb symbol.
7674 This is solely so that the code in print_insn_little_arm()
7675 and print_insn_big_arm() in opcodes/arm-dis.c will detect
7676 the presence of a Thumb symbol and switch to decoding
7677 Thumb instructions. */
7679 fake_target.flavour = bfd_target_coff_flavour;
7680 fake_bfd.xvec = &fake_target;
7681 ce.u.syment.n_sclass = C_THUMBEXTFUNC;
7683 csym.symbol.the_bfd = &fake_bfd;
7684 csym.symbol.name = "fake";
7685 asym = (asymbol *) & csym;
7688 memaddr = UNMAKE_THUMB_ADDR (memaddr);
7689 info->symbols = &asym;
7692 info->symbols = NULL;
7694 /* GDB is able to get bfd_mach from the exe_bfd, info->mach is
7695 accurate, so mark USER_SPECIFIED_MACHINE_TYPE bit. Otherwise,
7696 opcodes/arm-dis.c:print_insn reset info->mach, and it will trigger
7697 the assert on the mismatch of info->mach and bfd_get_mach (exec_bfd)
7698 in default_print_insn. */
7699 if (exec_bfd != NULL)
7700 info->flags |= USER_SPECIFIED_MACHINE_TYPE;
7702 return default_print_insn (memaddr, info);
7705 /* The following define instruction sequences that will cause ARM
7706 cpu's to take an undefined instruction trap. These are used to
7707 signal a breakpoint to GDB.
7709 The newer ARMv4T cpu's are capable of operating in ARM or Thumb
7710 modes. A different instruction is required for each mode. The ARM
7711 cpu's can also be big or little endian. Thus four different
7712 instructions are needed to support all cases.
7714 Note: ARMv4 defines several new instructions that will take the
7715 undefined instruction trap. ARM7TDMI is nominally ARMv4T, but does
7716 not in fact add the new instructions. The new undefined
7717 instructions in ARMv4 are all instructions that had no defined
7718 behaviour in earlier chips. There is no guarantee that they will
7719 raise an exception, but may be treated as NOP's. In practice, it
7720 may only safe to rely on instructions matching:
7722 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
7723 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
7724 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
7726 Even this may only true if the condition predicate is true. The
7727 following use a condition predicate of ALWAYS so it is always TRUE.
7729 There are other ways of forcing a breakpoint. GNU/Linux, RISC iX,
7730 and NetBSD all use a software interrupt rather than an undefined
7731 instruction to force a trap. This can be handled by by the
7732 abi-specific code during establishment of the gdbarch vector. */
7734 #define ARM_LE_BREAKPOINT {0xFE,0xDE,0xFF,0xE7}
7735 #define ARM_BE_BREAKPOINT {0xE7,0xFF,0xDE,0xFE}
7736 #define THUMB_LE_BREAKPOINT {0xbe,0xbe}
7737 #define THUMB_BE_BREAKPOINT {0xbe,0xbe}
7739 static const gdb_byte arm_default_arm_le_breakpoint[] = ARM_LE_BREAKPOINT;
7740 static const gdb_byte arm_default_arm_be_breakpoint[] = ARM_BE_BREAKPOINT;
7741 static const gdb_byte arm_default_thumb_le_breakpoint[] = THUMB_LE_BREAKPOINT;
7742 static const gdb_byte arm_default_thumb_be_breakpoint[] = THUMB_BE_BREAKPOINT;
7744 /* Implement the breakpoint_kind_from_pc gdbarch method. */
7747 arm_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
7749 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
7750 enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
7752 if (arm_pc_is_thumb (gdbarch, *pcptr))
7754 *pcptr = UNMAKE_THUMB_ADDR (*pcptr);
7756 /* If we have a separate 32-bit breakpoint instruction for Thumb-2,
7757 check whether we are replacing a 32-bit instruction. */
7758 if (tdep->thumb2_breakpoint != NULL)
7762 if (target_read_memory (*pcptr, buf, 2) == 0)
7764 unsigned short inst1;
7766 inst1 = extract_unsigned_integer (buf, 2, byte_order_for_code);
7767 if (thumb_insn_size (inst1) == 4)
7768 return ARM_BP_KIND_THUMB2;
7772 return ARM_BP_KIND_THUMB;
7775 return ARM_BP_KIND_ARM;
7779 /* Implement the sw_breakpoint_from_kind gdbarch method. */
7781 static const gdb_byte *
7782 arm_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
7784 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
7788 case ARM_BP_KIND_ARM:
7789 *size = tdep->arm_breakpoint_size;
7790 return tdep->arm_breakpoint;
7791 case ARM_BP_KIND_THUMB:
7792 *size = tdep->thumb_breakpoint_size;
7793 return tdep->thumb_breakpoint;
7794 case ARM_BP_KIND_THUMB2:
7795 *size = tdep->thumb2_breakpoint_size;
7796 return tdep->thumb2_breakpoint;
7798 gdb_assert_not_reached ("unexpected arm breakpoint kind");
7802 /* Implement the breakpoint_kind_from_current_state gdbarch method. */
7805 arm_breakpoint_kind_from_current_state (struct gdbarch *gdbarch,
7806 struct regcache *regcache,
7811 /* Check the memory pointed by PC is readable. */
7812 if (target_read_memory (regcache_read_pc (regcache), buf, 4) == 0)
7814 struct arm_get_next_pcs next_pcs_ctx;
7816 arm_get_next_pcs_ctor (&next_pcs_ctx,
7817 &arm_get_next_pcs_ops,
7818 gdbarch_byte_order (gdbarch),
7819 gdbarch_byte_order_for_code (gdbarch),
7823 std::vector<CORE_ADDR> next_pcs = arm_get_next_pcs (&next_pcs_ctx);
7825 /* If MEMADDR is the next instruction of current pc, do the
7826 software single step computation, and get the thumb mode by
7827 the destination address. */
7828 for (CORE_ADDR pc : next_pcs)
7830 if (UNMAKE_THUMB_ADDR (pc) == *pcptr)
7832 if (IS_THUMB_ADDR (pc))
7834 *pcptr = MAKE_THUMB_ADDR (*pcptr);
7835 return arm_breakpoint_kind_from_pc (gdbarch, pcptr);
7838 return ARM_BP_KIND_ARM;
7843 return arm_breakpoint_kind_from_pc (gdbarch, pcptr);
7846 /* Extract from an array REGBUF containing the (raw) register state a
7847 function return value of type TYPE, and copy that, in virtual
7848 format, into VALBUF. */
7851 arm_extract_return_value (struct type *type, struct regcache *regs,
7854 struct gdbarch *gdbarch = regs->arch ();
7855 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
7857 if (TYPE_CODE_FLT == TYPE_CODE (type))
7859 switch (gdbarch_tdep (gdbarch)->fp_model)
7863 /* The value is in register F0 in internal format. We need to
7864 extract the raw value and then convert it to the desired
7866 bfd_byte tmpbuf[FP_REGISTER_SIZE];
7868 regs->cooked_read (ARM_F0_REGNUM, tmpbuf);
7869 target_float_convert (tmpbuf, arm_ext_type (gdbarch),
7874 case ARM_FLOAT_SOFT_FPA:
7875 case ARM_FLOAT_SOFT_VFP:
7876 /* ARM_FLOAT_VFP can arise if this is a variadic function so
7877 not using the VFP ABI code. */
7879 regs->cooked_read (ARM_A1_REGNUM, valbuf);
7880 if (TYPE_LENGTH (type) > 4)
7881 regs->cooked_read (ARM_A1_REGNUM + 1, valbuf + INT_REGISTER_SIZE);
7885 internal_error (__FILE__, __LINE__,
7886 _("arm_extract_return_value: "
7887 "Floating point model not supported"));
7891 else if (TYPE_CODE (type) == TYPE_CODE_INT
7892 || TYPE_CODE (type) == TYPE_CODE_CHAR
7893 || TYPE_CODE (type) == TYPE_CODE_BOOL
7894 || TYPE_CODE (type) == TYPE_CODE_PTR
7895 || TYPE_IS_REFERENCE (type)
7896 || TYPE_CODE (type) == TYPE_CODE_ENUM)
7898 /* If the type is a plain integer, then the access is
7899 straight-forward. Otherwise we have to play around a bit
7901 int len = TYPE_LENGTH (type);
7902 int regno = ARM_A1_REGNUM;
7907 /* By using store_unsigned_integer we avoid having to do
7908 anything special for small big-endian values. */
7909 regcache_cooked_read_unsigned (regs, regno++, &tmp);
7910 store_unsigned_integer (valbuf,
7911 (len > INT_REGISTER_SIZE
7912 ? INT_REGISTER_SIZE : len),
7914 len -= INT_REGISTER_SIZE;
7915 valbuf += INT_REGISTER_SIZE;
7920 /* For a structure or union the behaviour is as if the value had
7921 been stored to word-aligned memory and then loaded into
7922 registers with 32-bit load instruction(s). */
7923 int len = TYPE_LENGTH (type);
7924 int regno = ARM_A1_REGNUM;
7925 bfd_byte tmpbuf[INT_REGISTER_SIZE];
7929 regs->cooked_read (regno++, tmpbuf);
7930 memcpy (valbuf, tmpbuf,
7931 len > INT_REGISTER_SIZE ? INT_REGISTER_SIZE : len);
7932 len -= INT_REGISTER_SIZE;
7933 valbuf += INT_REGISTER_SIZE;
7939 /* Will a function return an aggregate type in memory or in a
7940 register? Return 0 if an aggregate type can be returned in a
7941 register, 1 if it must be returned in memory. */
7944 arm_return_in_memory (struct gdbarch *gdbarch, struct type *type)
7946 enum type_code code;
7948 type = check_typedef (type);
7950 /* Simple, non-aggregate types (ie not including vectors and
7951 complex) are always returned in a register (or registers). */
7952 code = TYPE_CODE (type);
7953 if (TYPE_CODE_STRUCT != code && TYPE_CODE_UNION != code
7954 && TYPE_CODE_ARRAY != code && TYPE_CODE_COMPLEX != code)
7957 if (TYPE_CODE_ARRAY == code && TYPE_VECTOR (type))
7959 /* Vector values should be returned using ARM registers if they
7960 are not over 16 bytes. */
7961 return (TYPE_LENGTH (type) > 16);
7964 if (gdbarch_tdep (gdbarch)->arm_abi != ARM_ABI_APCS)
7966 /* The AAPCS says all aggregates not larger than a word are returned
7968 if (TYPE_LENGTH (type) <= INT_REGISTER_SIZE)
7977 /* All aggregate types that won't fit in a register must be returned
7979 if (TYPE_LENGTH (type) > INT_REGISTER_SIZE)
7982 /* In the ARM ABI, "integer" like aggregate types are returned in
7983 registers. For an aggregate type to be integer like, its size
7984 must be less than or equal to INT_REGISTER_SIZE and the
7985 offset of each addressable subfield must be zero. Note that bit
7986 fields are not addressable, and all addressable subfields of
7987 unions always start at offset zero.
7989 This function is based on the behaviour of GCC 2.95.1.
7990 See: gcc/arm.c: arm_return_in_memory() for details.
7992 Note: All versions of GCC before GCC 2.95.2 do not set up the
7993 parameters correctly for a function returning the following
7994 structure: struct { float f;}; This should be returned in memory,
7995 not a register. Richard Earnshaw sent me a patch, but I do not
7996 know of any way to detect if a function like the above has been
7997 compiled with the correct calling convention. */
7999 /* Assume all other aggregate types can be returned in a register.
8000 Run a check for structures, unions and arrays. */
8003 if ((TYPE_CODE_STRUCT == code) || (TYPE_CODE_UNION == code))
8006 /* Need to check if this struct/union is "integer" like. For
8007 this to be true, its size must be less than or equal to
8008 INT_REGISTER_SIZE and the offset of each addressable
8009 subfield must be zero. Note that bit fields are not
8010 addressable, and unions always start at offset zero. If any
8011 of the subfields is a floating point type, the struct/union
8012 cannot be an integer type. */
8014 /* For each field in the object, check:
8015 1) Is it FP? --> yes, nRc = 1;
8016 2) Is it addressable (bitpos != 0) and
8017 not packed (bitsize == 0)?
8021 for (i = 0; i < TYPE_NFIELDS (type); i++)
8023 enum type_code field_type_code;
8026 = TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type,
8029 /* Is it a floating point type field? */
8030 if (field_type_code == TYPE_CODE_FLT)
8036 /* If bitpos != 0, then we have to care about it. */
8037 if (TYPE_FIELD_BITPOS (type, i) != 0)
8039 /* Bitfields are not addressable. If the field bitsize is
8040 zero, then the field is not packed. Hence it cannot be
8041 a bitfield or any other packed type. */
8042 if (TYPE_FIELD_BITSIZE (type, i) == 0)
8055 /* Write into appropriate registers a function return value of type
8056 TYPE, given in virtual format. */
8059 arm_store_return_value (struct type *type, struct regcache *regs,
8060 const gdb_byte *valbuf)
8062 struct gdbarch *gdbarch = regs->arch ();
8063 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
8065 if (TYPE_CODE (type) == TYPE_CODE_FLT)
8067 gdb_byte buf[FP_REGISTER_SIZE];
8069 switch (gdbarch_tdep (gdbarch)->fp_model)
8073 target_float_convert (valbuf, type, buf, arm_ext_type (gdbarch));
8074 regs->cooked_write (ARM_F0_REGNUM, buf);
8077 case ARM_FLOAT_SOFT_FPA:
8078 case ARM_FLOAT_SOFT_VFP:
8079 /* ARM_FLOAT_VFP can arise if this is a variadic function so
8080 not using the VFP ABI code. */
8082 regs->cooked_write (ARM_A1_REGNUM, valbuf);
8083 if (TYPE_LENGTH (type) > 4)
8084 regs->cooked_write (ARM_A1_REGNUM + 1, valbuf + INT_REGISTER_SIZE);
8088 internal_error (__FILE__, __LINE__,
8089 _("arm_store_return_value: Floating "
8090 "point model not supported"));
8094 else if (TYPE_CODE (type) == TYPE_CODE_INT
8095 || TYPE_CODE (type) == TYPE_CODE_CHAR
8096 || TYPE_CODE (type) == TYPE_CODE_BOOL
8097 || TYPE_CODE (type) == TYPE_CODE_PTR
8098 || TYPE_IS_REFERENCE (type)
8099 || TYPE_CODE (type) == TYPE_CODE_ENUM)
8101 if (TYPE_LENGTH (type) <= 4)
8103 /* Values of one word or less are zero/sign-extended and
8105 bfd_byte tmpbuf[INT_REGISTER_SIZE];
8106 LONGEST val = unpack_long (type, valbuf);
8108 store_signed_integer (tmpbuf, INT_REGISTER_SIZE, byte_order, val);
8109 regs->cooked_write (ARM_A1_REGNUM, tmpbuf);
8113 /* Integral values greater than one word are stored in consecutive
8114 registers starting with r0. This will always be a multiple of
8115 the regiser size. */
8116 int len = TYPE_LENGTH (type);
8117 int regno = ARM_A1_REGNUM;
8121 regs->cooked_write (regno++, valbuf);
8122 len -= INT_REGISTER_SIZE;
8123 valbuf += INT_REGISTER_SIZE;
8129 /* For a structure or union the behaviour is as if the value had
8130 been stored to word-aligned memory and then loaded into
8131 registers with 32-bit load instruction(s). */
8132 int len = TYPE_LENGTH (type);
8133 int regno = ARM_A1_REGNUM;
8134 bfd_byte tmpbuf[INT_REGISTER_SIZE];
8138 memcpy (tmpbuf, valbuf,
8139 len > INT_REGISTER_SIZE ? INT_REGISTER_SIZE : len);
8140 regs->cooked_write (regno++, tmpbuf);
8141 len -= INT_REGISTER_SIZE;
8142 valbuf += INT_REGISTER_SIZE;
8148 /* Handle function return values. */
8150 static enum return_value_convention
8151 arm_return_value (struct gdbarch *gdbarch, struct value *function,
8152 struct type *valtype, struct regcache *regcache,
8153 gdb_byte *readbuf, const gdb_byte *writebuf)
8155 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
8156 struct type *func_type = function ? value_type (function) : NULL;
8157 enum arm_vfp_cprc_base_type vfp_base_type;
8160 if (arm_vfp_abi_for_function (gdbarch, func_type)
8161 && arm_vfp_call_candidate (valtype, &vfp_base_type, &vfp_base_count))
8163 int reg_char = arm_vfp_cprc_reg_char (vfp_base_type);
8164 int unit_length = arm_vfp_cprc_unit_length (vfp_base_type);
8166 for (i = 0; i < vfp_base_count; i++)
8168 if (reg_char == 'q')
8171 arm_neon_quad_write (gdbarch, regcache, i,
8172 writebuf + i * unit_length);
8175 arm_neon_quad_read (gdbarch, regcache, i,
8176 readbuf + i * unit_length);
8183 xsnprintf (name_buf, sizeof (name_buf), "%c%d", reg_char, i);
8184 regnum = user_reg_map_name_to_regnum (gdbarch, name_buf,
8187 regcache->cooked_write (regnum, writebuf + i * unit_length);
8189 regcache->cooked_read (regnum, readbuf + i * unit_length);
8192 return RETURN_VALUE_REGISTER_CONVENTION;
8195 if (TYPE_CODE (valtype) == TYPE_CODE_STRUCT
8196 || TYPE_CODE (valtype) == TYPE_CODE_UNION
8197 || TYPE_CODE (valtype) == TYPE_CODE_ARRAY)
8199 if (tdep->struct_return == pcc_struct_return
8200 || arm_return_in_memory (gdbarch, valtype))
8201 return RETURN_VALUE_STRUCT_CONVENTION;
8203 else if (TYPE_CODE (valtype) == TYPE_CODE_COMPLEX)
8205 if (arm_return_in_memory (gdbarch, valtype))
8206 return RETURN_VALUE_STRUCT_CONVENTION;
8210 arm_store_return_value (valtype, regcache, writebuf);
8213 arm_extract_return_value (valtype, regcache, readbuf);
8215 return RETURN_VALUE_REGISTER_CONVENTION;
8220 arm_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
8222 struct gdbarch *gdbarch = get_frame_arch (frame);
8223 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
8224 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
8226 gdb_byte buf[INT_REGISTER_SIZE];
8228 jb_addr = get_frame_register_unsigned (frame, ARM_A1_REGNUM);
8230 if (target_read_memory (jb_addr + tdep->jb_pc * tdep->jb_elt_size, buf,
8234 *pc = extract_unsigned_integer (buf, INT_REGISTER_SIZE, byte_order);
8238 /* Recognize GCC and GNU ld's trampolines. If we are in a trampoline,
8239 return the target PC. Otherwise return 0. */
8242 arm_skip_stub (struct frame_info *frame, CORE_ADDR pc)
8246 CORE_ADDR start_addr;
8248 /* Find the starting address and name of the function containing the PC. */
8249 if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0)
8251 /* Trampoline 'bx reg' doesn't belong to any functions. Do the
8253 start_addr = arm_skip_bx_reg (frame, pc);
8254 if (start_addr != 0)
8260 /* If PC is in a Thumb call or return stub, return the address of the
8261 target PC, which is in a register. The thunk functions are called
8262 _call_via_xx, where x is the register name. The possible names
8263 are r0-r9, sl, fp, ip, sp, and lr. ARM RealView has similar
8264 functions, named __ARM_call_via_r[0-7]. */
8265 if (startswith (name, "_call_via_")
8266 || startswith (name, "__ARM_call_via_"))
8268 /* Use the name suffix to determine which register contains the
8270 static const char *table[15] =
8271 {"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
8272 "r8", "r9", "sl", "fp", "ip", "sp", "lr"
8275 int offset = strlen (name) - 2;
8277 for (regno = 0; regno <= 14; regno++)
8278 if (strcmp (&name[offset], table[regno]) == 0)
8279 return get_frame_register_unsigned (frame, regno);
8282 /* GNU ld generates __foo_from_arm or __foo_from_thumb for
8283 non-interworking calls to foo. We could decode the stubs
8284 to find the target but it's easier to use the symbol table. */
8285 namelen = strlen (name);
8286 if (name[0] == '_' && name[1] == '_'
8287 && ((namelen > 2 + strlen ("_from_thumb")
8288 && startswith (name + namelen - strlen ("_from_thumb"), "_from_thumb"))
8289 || (namelen > 2 + strlen ("_from_arm")
8290 && startswith (name + namelen - strlen ("_from_arm"), "_from_arm"))))
8293 int target_len = namelen - 2;
8294 struct bound_minimal_symbol minsym;
8295 struct objfile *objfile;
8296 struct obj_section *sec;
8298 if (name[namelen - 1] == 'b')
8299 target_len -= strlen ("_from_thumb");
8301 target_len -= strlen ("_from_arm");
8303 target_name = (char *) alloca (target_len + 1);
8304 memcpy (target_name, name + 2, target_len);
8305 target_name[target_len] = '\0';
8307 sec = find_pc_section (pc);
8308 objfile = (sec == NULL) ? NULL : sec->objfile;
8309 minsym = lookup_minimal_symbol (target_name, NULL, objfile);
8310 if (minsym.minsym != NULL)
8311 return BMSYMBOL_VALUE_ADDRESS (minsym);
8316 return 0; /* not a stub */
8320 set_arm_command (const char *args, int from_tty)
8322 printf_unfiltered (_("\
8323 \"set arm\" must be followed by an apporpriate subcommand.\n"));
8324 help_list (setarmcmdlist, "set arm ", all_commands, gdb_stdout);
8328 show_arm_command (const char *args, int from_tty)
8330 cmd_show_list (showarmcmdlist, from_tty, "");
8334 arm_update_current_architecture (void)
8336 struct gdbarch_info info;
8338 /* If the current architecture is not ARM, we have nothing to do. */
8339 if (gdbarch_bfd_arch_info (target_gdbarch ())->arch != bfd_arch_arm)
8342 /* Update the architecture. */
8343 gdbarch_info_init (&info);
8345 if (!gdbarch_update_p (info))
8346 internal_error (__FILE__, __LINE__, _("could not update architecture"));
8350 set_fp_model_sfunc (const char *args, int from_tty,
8351 struct cmd_list_element *c)
8355 for (fp_model = ARM_FLOAT_AUTO; fp_model != ARM_FLOAT_LAST; fp_model++)
8356 if (strcmp (current_fp_model, fp_model_strings[fp_model]) == 0)
8358 arm_fp_model = (enum arm_float_model) fp_model;
8362 if (fp_model == ARM_FLOAT_LAST)
8363 internal_error (__FILE__, __LINE__, _("Invalid fp model accepted: %s."),
8366 arm_update_current_architecture ();
8370 show_fp_model (struct ui_file *file, int from_tty,
8371 struct cmd_list_element *c, const char *value)
8373 struct gdbarch_tdep *tdep = gdbarch_tdep (target_gdbarch ());
8375 if (arm_fp_model == ARM_FLOAT_AUTO
8376 && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
8377 fprintf_filtered (file, _("\
8378 The current ARM floating point model is \"auto\" (currently \"%s\").\n"),
8379 fp_model_strings[tdep->fp_model]);
8381 fprintf_filtered (file, _("\
8382 The current ARM floating point model is \"%s\".\n"),
8383 fp_model_strings[arm_fp_model]);
8387 arm_set_abi (const char *args, int from_tty,
8388 struct cmd_list_element *c)
8392 for (arm_abi = ARM_ABI_AUTO; arm_abi != ARM_ABI_LAST; arm_abi++)
8393 if (strcmp (arm_abi_string, arm_abi_strings[arm_abi]) == 0)
8395 arm_abi_global = (enum arm_abi_kind) arm_abi;
8399 if (arm_abi == ARM_ABI_LAST)
8400 internal_error (__FILE__, __LINE__, _("Invalid ABI accepted: %s."),
8403 arm_update_current_architecture ();
8407 arm_show_abi (struct ui_file *file, int from_tty,
8408 struct cmd_list_element *c, const char *value)
8410 struct gdbarch_tdep *tdep = gdbarch_tdep (target_gdbarch ());
8412 if (arm_abi_global == ARM_ABI_AUTO
8413 && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
8414 fprintf_filtered (file, _("\
8415 The current ARM ABI is \"auto\" (currently \"%s\").\n"),
8416 arm_abi_strings[tdep->arm_abi]);
8418 fprintf_filtered (file, _("The current ARM ABI is \"%s\".\n"),
8423 arm_show_fallback_mode (struct ui_file *file, int from_tty,
8424 struct cmd_list_element *c, const char *value)
8426 fprintf_filtered (file,
8427 _("The current execution mode assumed "
8428 "(when symbols are unavailable) is \"%s\".\n"),
8429 arm_fallback_mode_string);
8433 arm_show_force_mode (struct ui_file *file, int from_tty,
8434 struct cmd_list_element *c, const char *value)
8436 fprintf_filtered (file,
8437 _("The current execution mode assumed "
8438 "(even when symbols are available) is \"%s\".\n"),
8439 arm_force_mode_string);
8442 /* If the user changes the register disassembly style used for info
8443 register and other commands, we have to also switch the style used
8444 in opcodes for disassembly output. This function is run in the "set
8445 arm disassembly" command, and does that. */
8448 set_disassembly_style_sfunc (const char *args, int from_tty,
8449 struct cmd_list_element *c)
8451 /* Convert the short style name into the long style name (eg, reg-names-*)
8452 before calling the generic set_disassembler_options() function. */
8453 std::string long_name = std::string ("reg-names-") + disassembly_style;
8454 set_disassembler_options (&long_name[0]);
8458 show_disassembly_style_sfunc (struct ui_file *file, int from_tty,
8459 struct cmd_list_element *c, const char *value)
8461 struct gdbarch *gdbarch = get_current_arch ();
8462 char *options = get_disassembler_options (gdbarch);
8463 const char *style = "";
8467 FOR_EACH_DISASSEMBLER_OPTION (opt, options)
8468 if (CONST_STRNEQ (opt, "reg-names-"))
8470 style = &opt[strlen ("reg-names-")];
8471 len = strcspn (style, ",");
8474 fprintf_unfiltered (file, "The disassembly style is \"%.*s\".\n", len, style);
8477 /* Return the ARM register name corresponding to register I. */
8479 arm_register_name (struct gdbarch *gdbarch, int i)
8481 const int num_regs = gdbarch_num_regs (gdbarch);
8483 if (gdbarch_tdep (gdbarch)->have_vfp_pseudos
8484 && i >= num_regs && i < num_regs + 32)
8486 static const char *const vfp_pseudo_names[] = {
8487 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
8488 "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15",
8489 "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23",
8490 "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31",
8493 return vfp_pseudo_names[i - num_regs];
8496 if (gdbarch_tdep (gdbarch)->have_neon_pseudos
8497 && i >= num_regs + 32 && i < num_regs + 32 + 16)
8499 static const char *const neon_pseudo_names[] = {
8500 "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7",
8501 "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15",
8504 return neon_pseudo_names[i - num_regs - 32];
8507 if (i >= ARRAY_SIZE (arm_register_names))
8508 /* These registers are only supported on targets which supply
8509 an XML description. */
8512 return arm_register_names[i];
8515 /* Test whether the coff symbol specific value corresponds to a Thumb
8519 coff_sym_is_thumb (int val)
8521 return (val == C_THUMBEXT
8522 || val == C_THUMBSTAT
8523 || val == C_THUMBEXTFUNC
8524 || val == C_THUMBSTATFUNC
8525 || val == C_THUMBLABEL);
8528 /* arm_coff_make_msymbol_special()
8529 arm_elf_make_msymbol_special()
8531 These functions test whether the COFF or ELF symbol corresponds to
8532 an address in thumb code, and set a "special" bit in a minimal
8533 symbol to indicate that it does. */
8536 arm_elf_make_msymbol_special(asymbol *sym, struct minimal_symbol *msym)
8538 elf_symbol_type *elfsym = (elf_symbol_type *) sym;
8540 if (ARM_GET_SYM_BRANCH_TYPE (elfsym->internal_elf_sym.st_target_internal)
8541 == ST_BRANCH_TO_THUMB)
8542 MSYMBOL_SET_SPECIAL (msym);
8546 arm_coff_make_msymbol_special(int val, struct minimal_symbol *msym)
8548 if (coff_sym_is_thumb (val))
8549 MSYMBOL_SET_SPECIAL (msym);
8553 arm_objfile_data_free (struct objfile *objfile, void *arg)
8555 struct arm_per_objfile *data = (struct arm_per_objfile *) arg;
8558 for (i = 0; i < objfile->obfd->section_count; i++)
8559 VEC_free (arm_mapping_symbol_s, data->section_maps[i]);
8563 arm_record_special_symbol (struct gdbarch *gdbarch, struct objfile *objfile,
8566 const char *name = bfd_asymbol_name (sym);
8567 struct arm_per_objfile *data;
8568 VEC(arm_mapping_symbol_s) **map_p;
8569 struct arm_mapping_symbol new_map_sym;
8571 gdb_assert (name[0] == '$');
8572 if (name[1] != 'a' && name[1] != 't' && name[1] != 'd')
8575 data = (struct arm_per_objfile *) objfile_data (objfile,
8576 arm_objfile_data_key);
8579 data = OBSTACK_ZALLOC (&objfile->objfile_obstack,
8580 struct arm_per_objfile);
8581 set_objfile_data (objfile, arm_objfile_data_key, data);
8582 data->section_maps = OBSTACK_CALLOC (&objfile->objfile_obstack,
8583 objfile->obfd->section_count,
8584 VEC(arm_mapping_symbol_s) *);
8586 map_p = &data->section_maps[bfd_get_section (sym)->index];
8588 new_map_sym.value = sym->value;
8589 new_map_sym.type = name[1];
8591 /* Assume that most mapping symbols appear in order of increasing
8592 value. If they were randomly distributed, it would be faster to
8593 always push here and then sort at first use. */
8594 if (!VEC_empty (arm_mapping_symbol_s, *map_p))
8596 struct arm_mapping_symbol *prev_map_sym;
8598 prev_map_sym = VEC_last (arm_mapping_symbol_s, *map_p);
8599 if (prev_map_sym->value >= sym->value)
8602 idx = VEC_lower_bound (arm_mapping_symbol_s, *map_p, &new_map_sym,
8603 arm_compare_mapping_symbols);
8604 VEC_safe_insert (arm_mapping_symbol_s, *map_p, idx, &new_map_sym);
8609 VEC_safe_push (arm_mapping_symbol_s, *map_p, &new_map_sym);
8613 arm_write_pc (struct regcache *regcache, CORE_ADDR pc)
8615 struct gdbarch *gdbarch = regcache->arch ();
8616 regcache_cooked_write_unsigned (regcache, ARM_PC_REGNUM, pc);
8618 /* If necessary, set the T bit. */
8621 ULONGEST val, t_bit;
8622 regcache_cooked_read_unsigned (regcache, ARM_PS_REGNUM, &val);
8623 t_bit = arm_psr_thumb_bit (gdbarch);
8624 if (arm_pc_is_thumb (gdbarch, pc))
8625 regcache_cooked_write_unsigned (regcache, ARM_PS_REGNUM,
8628 regcache_cooked_write_unsigned (regcache, ARM_PS_REGNUM,
8633 /* Read the contents of a NEON quad register, by reading from two
8634 double registers. This is used to implement the quad pseudo
8635 registers, and for argument passing in case the quad registers are
8636 missing; vectors are passed in quad registers when using the VFP
8637 ABI, even if a NEON unit is not present. REGNUM is the index of
8638 the quad register, in [0, 15]. */
8640 static enum register_status
8641 arm_neon_quad_read (struct gdbarch *gdbarch, readable_regcache *regcache,
8642 int regnum, gdb_byte *buf)
8645 gdb_byte reg_buf[8];
8646 int offset, double_regnum;
8647 enum register_status status;
8649 xsnprintf (name_buf, sizeof (name_buf), "d%d", regnum << 1);
8650 double_regnum = user_reg_map_name_to_regnum (gdbarch, name_buf,
8653 /* d0 is always the least significant half of q0. */
8654 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
8659 status = regcache->raw_read (double_regnum, reg_buf);
8660 if (status != REG_VALID)
8662 memcpy (buf + offset, reg_buf, 8);
8664 offset = 8 - offset;
8665 status = regcache->raw_read (double_regnum + 1, reg_buf);
8666 if (status != REG_VALID)
8668 memcpy (buf + offset, reg_buf, 8);
8673 static enum register_status
8674 arm_pseudo_read (struct gdbarch *gdbarch, readable_regcache *regcache,
8675 int regnum, gdb_byte *buf)
8677 const int num_regs = gdbarch_num_regs (gdbarch);
8679 gdb_byte reg_buf[8];
8680 int offset, double_regnum;
8682 gdb_assert (regnum >= num_regs);
8685 if (gdbarch_tdep (gdbarch)->have_neon_pseudos && regnum >= 32 && regnum < 48)
8686 /* Quad-precision register. */
8687 return arm_neon_quad_read (gdbarch, regcache, regnum - 32, buf);
8690 enum register_status status;
8692 /* Single-precision register. */
8693 gdb_assert (regnum < 32);
8695 /* s0 is always the least significant half of d0. */
8696 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
8697 offset = (regnum & 1) ? 0 : 4;
8699 offset = (regnum & 1) ? 4 : 0;
8701 xsnprintf (name_buf, sizeof (name_buf), "d%d", regnum >> 1);
8702 double_regnum = user_reg_map_name_to_regnum (gdbarch, name_buf,
8705 status = regcache->raw_read (double_regnum, reg_buf);
8706 if (status == REG_VALID)
8707 memcpy (buf, reg_buf + offset, 4);
8712 /* Store the contents of BUF to a NEON quad register, by writing to
8713 two double registers. This is used to implement the quad pseudo
8714 registers, and for argument passing in case the quad registers are
8715 missing; vectors are passed in quad registers when using the VFP
8716 ABI, even if a NEON unit is not present. REGNUM is the index
8717 of the quad register, in [0, 15]. */
8720 arm_neon_quad_write (struct gdbarch *gdbarch, struct regcache *regcache,
8721 int regnum, const gdb_byte *buf)
8724 int offset, double_regnum;
8726 xsnprintf (name_buf, sizeof (name_buf), "d%d", regnum << 1);
8727 double_regnum = user_reg_map_name_to_regnum (gdbarch, name_buf,
8730 /* d0 is always the least significant half of q0. */
8731 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
8736 regcache->raw_write (double_regnum, buf + offset);
8737 offset = 8 - offset;
8738 regcache->raw_write (double_regnum + 1, buf + offset);
8742 arm_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
8743 int regnum, const gdb_byte *buf)
8745 const int num_regs = gdbarch_num_regs (gdbarch);
8747 gdb_byte reg_buf[8];
8748 int offset, double_regnum;
8750 gdb_assert (regnum >= num_regs);
8753 if (gdbarch_tdep (gdbarch)->have_neon_pseudos && regnum >= 32 && regnum < 48)
8754 /* Quad-precision register. */
8755 arm_neon_quad_write (gdbarch, regcache, regnum - 32, buf);
8758 /* Single-precision register. */
8759 gdb_assert (regnum < 32);
8761 /* s0 is always the least significant half of d0. */
8762 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
8763 offset = (regnum & 1) ? 0 : 4;
8765 offset = (regnum & 1) ? 4 : 0;
8767 xsnprintf (name_buf, sizeof (name_buf), "d%d", regnum >> 1);
8768 double_regnum = user_reg_map_name_to_regnum (gdbarch, name_buf,
8771 regcache->raw_read (double_regnum, reg_buf);
8772 memcpy (reg_buf + offset, buf, 4);
8773 regcache->raw_write (double_regnum, reg_buf);
8777 static struct value *
8778 value_of_arm_user_reg (struct frame_info *frame, const void *baton)
8780 const int *reg_p = (const int *) baton;
8781 return value_of_register (*reg_p, frame);
8784 static enum gdb_osabi
8785 arm_elf_osabi_sniffer (bfd *abfd)
8787 unsigned int elfosabi;
8788 enum gdb_osabi osabi = GDB_OSABI_UNKNOWN;
8790 elfosabi = elf_elfheader (abfd)->e_ident[EI_OSABI];
8792 if (elfosabi == ELFOSABI_ARM)
8793 /* GNU tools use this value. Check note sections in this case,
8795 bfd_map_over_sections (abfd,
8796 generic_elf_osabi_sniff_abi_tag_sections,
8799 /* Anything else will be handled by the generic ELF sniffer. */
8804 arm_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
8805 struct reggroup *group)
8807 /* FPS register's type is INT, but belongs to float_reggroup. Beside
8808 this, FPS register belongs to save_regroup, restore_reggroup, and
8809 all_reggroup, of course. */
8810 if (regnum == ARM_FPS_REGNUM)
8811 return (group == float_reggroup
8812 || group == save_reggroup
8813 || group == restore_reggroup
8814 || group == all_reggroup);
8816 return default_register_reggroup_p (gdbarch, regnum, group);
8820 /* For backward-compatibility we allow two 'g' packet lengths with
8821 the remote protocol depending on whether FPA registers are
8822 supplied. M-profile targets do not have FPA registers, but some
8823 stubs already exist in the wild which use a 'g' packet which
8824 supplies them albeit with dummy values. The packet format which
8825 includes FPA registers should be considered deprecated for
8826 M-profile targets. */
8829 arm_register_g_packet_guesses (struct gdbarch *gdbarch)
8831 if (gdbarch_tdep (gdbarch)->is_m)
8833 /* If we know from the executable this is an M-profile target,
8834 cater for remote targets whose register set layout is the
8835 same as the FPA layout. */
8836 register_remote_g_packet_guess (gdbarch,
8837 /* r0-r12,sp,lr,pc; f0-f7; fps,xpsr */
8838 (16 * INT_REGISTER_SIZE)
8839 + (8 * FP_REGISTER_SIZE)
8840 + (2 * INT_REGISTER_SIZE),
8841 tdesc_arm_with_m_fpa_layout);
8843 /* The regular M-profile layout. */
8844 register_remote_g_packet_guess (gdbarch,
8845 /* r0-r12,sp,lr,pc; xpsr */
8846 (16 * INT_REGISTER_SIZE)
8847 + INT_REGISTER_SIZE,
8850 /* M-profile plus M4F VFP. */
8851 register_remote_g_packet_guess (gdbarch,
8852 /* r0-r12,sp,lr,pc; d0-d15; fpscr,xpsr */
8853 (16 * INT_REGISTER_SIZE)
8854 + (16 * VFP_REGISTER_SIZE)
8855 + (2 * INT_REGISTER_SIZE),
8856 tdesc_arm_with_m_vfp_d16);
8859 /* Otherwise we don't have a useful guess. */
8862 /* Implement the code_of_frame_writable gdbarch method. */
8865 arm_code_of_frame_writable (struct gdbarch *gdbarch, struct frame_info *frame)
8867 if (gdbarch_tdep (gdbarch)->is_m
8868 && get_frame_type (frame) == SIGTRAMP_FRAME)
8870 /* M-profile exception frames return to some magic PCs, where
8871 isn't writable at all. */
8879 /* Initialize the current architecture based on INFO. If possible,
8880 re-use an architecture from ARCHES, which is a list of
8881 architectures already created during this debugging session.
8883 Called e.g. at program startup, when reading a core file, and when
8884 reading a binary file. */
8886 static struct gdbarch *
8887 arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
8889 struct gdbarch_tdep *tdep;
8890 struct gdbarch *gdbarch;
8891 struct gdbarch_list *best_arch;
8892 enum arm_abi_kind arm_abi = arm_abi_global;
8893 enum arm_float_model fp_model = arm_fp_model;
8894 struct tdesc_arch_data *tdesc_data = NULL;
8896 int vfp_register_count = 0, have_vfp_pseudos = 0, have_neon_pseudos = 0;
8897 int have_wmmx_registers = 0;
8899 int have_fpa_registers = 1;
8900 const struct target_desc *tdesc = info.target_desc;
8902 /* If we have an object to base this architecture on, try to determine
8905 if (arm_abi == ARM_ABI_AUTO && info.abfd != NULL)
8907 int ei_osabi, e_flags;
8909 switch (bfd_get_flavour (info.abfd))
8911 case bfd_target_coff_flavour:
8912 /* Assume it's an old APCS-style ABI. */
8914 arm_abi = ARM_ABI_APCS;
8917 case bfd_target_elf_flavour:
8918 ei_osabi = elf_elfheader (info.abfd)->e_ident[EI_OSABI];
8919 e_flags = elf_elfheader (info.abfd)->e_flags;
8921 if (ei_osabi == ELFOSABI_ARM)
8923 /* GNU tools used to use this value, but do not for EABI
8924 objects. There's nowhere to tag an EABI version
8925 anyway, so assume APCS. */
8926 arm_abi = ARM_ABI_APCS;
8928 else if (ei_osabi == ELFOSABI_NONE || ei_osabi == ELFOSABI_GNU)
8930 int eabi_ver = EF_ARM_EABI_VERSION (e_flags);
8934 case EF_ARM_EABI_UNKNOWN:
8935 /* Assume GNU tools. */
8936 arm_abi = ARM_ABI_APCS;
8939 case EF_ARM_EABI_VER4:
8940 case EF_ARM_EABI_VER5:
8941 arm_abi = ARM_ABI_AAPCS;
8942 /* EABI binaries default to VFP float ordering.
8943 They may also contain build attributes that can
8944 be used to identify if the VFP argument-passing
8946 if (fp_model == ARM_FLOAT_AUTO)
8949 switch (bfd_elf_get_obj_attr_int (info.abfd,
8953 case AEABI_VFP_args_base:
8954 /* "The user intended FP parameter/result
8955 passing to conform to AAPCS, base
8957 fp_model = ARM_FLOAT_SOFT_VFP;
8959 case AEABI_VFP_args_vfp:
8960 /* "The user intended FP parameter/result
8961 passing to conform to AAPCS, VFP
8963 fp_model = ARM_FLOAT_VFP;
8965 case AEABI_VFP_args_toolchain:
8966 /* "The user intended FP parameter/result
8967 passing to conform to tool chain-specific
8968 conventions" - we don't know any such
8969 conventions, so leave it as "auto". */
8971 case AEABI_VFP_args_compatible:
8972 /* "Code is compatible with both the base
8973 and VFP variants; the user did not permit
8974 non-variadic functions to pass FP
8975 parameters/results" - leave it as
8979 /* Attribute value not mentioned in the
8980 November 2012 ABI, so leave it as
8985 fp_model = ARM_FLOAT_SOFT_VFP;
8991 /* Leave it as "auto". */
8992 warning (_("unknown ARM EABI version 0x%x"), eabi_ver);
8997 /* Detect M-profile programs. This only works if the
8998 executable file includes build attributes; GCC does
8999 copy them to the executable, but e.g. RealView does
9002 = bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_PROC,
9005 = bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_PROC,
9006 Tag_CPU_arch_profile);
9008 /* GCC specifies the profile for v6-M; RealView only
9009 specifies the profile for architectures starting with
9010 V7 (as opposed to architectures with a tag
9011 numerically greater than TAG_CPU_ARCH_V7). */
9012 if (!tdesc_has_registers (tdesc)
9013 && (attr_arch == TAG_CPU_ARCH_V6_M
9014 || attr_arch == TAG_CPU_ARCH_V6S_M
9015 || attr_profile == 'M'))
9020 if (fp_model == ARM_FLOAT_AUTO)
9022 switch (e_flags & (EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT))
9025 /* Leave it as "auto". Strictly speaking this case
9026 means FPA, but almost nobody uses that now, and
9027 many toolchains fail to set the appropriate bits
9028 for the floating-point model they use. */
9030 case EF_ARM_SOFT_FLOAT:
9031 fp_model = ARM_FLOAT_SOFT_FPA;
9033 case EF_ARM_VFP_FLOAT:
9034 fp_model = ARM_FLOAT_VFP;
9036 case EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT:
9037 fp_model = ARM_FLOAT_SOFT_VFP;
9042 if (e_flags & EF_ARM_BE8)
9043 info.byte_order_for_code = BFD_ENDIAN_LITTLE;
9048 /* Leave it as "auto". */
9053 /* Check any target description for validity. */
9054 if (tdesc_has_registers (tdesc))
9056 /* For most registers we require GDB's default names; but also allow
9057 the numeric names for sp / lr / pc, as a convenience. */
9058 static const char *const arm_sp_names[] = { "r13", "sp", NULL };
9059 static const char *const arm_lr_names[] = { "r14", "lr", NULL };
9060 static const char *const arm_pc_names[] = { "r15", "pc", NULL };
9062 const struct tdesc_feature *feature;
9065 feature = tdesc_find_feature (tdesc,
9066 "org.gnu.gdb.arm.core");
9067 if (feature == NULL)
9069 feature = tdesc_find_feature (tdesc,
9070 "org.gnu.gdb.arm.m-profile");
9071 if (feature == NULL)
9077 tdesc_data = tdesc_data_alloc ();
9080 for (i = 0; i < ARM_SP_REGNUM; i++)
9081 valid_p &= tdesc_numbered_register (feature, tdesc_data, i,
9082 arm_register_names[i]);
9083 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
9086 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
9089 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
9093 valid_p &= tdesc_numbered_register (feature, tdesc_data,
9094 ARM_PS_REGNUM, "xpsr");
9096 valid_p &= tdesc_numbered_register (feature, tdesc_data,
9097 ARM_PS_REGNUM, "cpsr");
9101 tdesc_data_cleanup (tdesc_data);
9105 feature = tdesc_find_feature (tdesc,
9106 "org.gnu.gdb.arm.fpa");
9107 if (feature != NULL)
9110 for (i = ARM_F0_REGNUM; i <= ARM_FPS_REGNUM; i++)
9111 valid_p &= tdesc_numbered_register (feature, tdesc_data, i,
9112 arm_register_names[i]);
9115 tdesc_data_cleanup (tdesc_data);
9120 have_fpa_registers = 0;
9122 feature = tdesc_find_feature (tdesc,
9123 "org.gnu.gdb.xscale.iwmmxt");
9124 if (feature != NULL)
9126 static const char *const iwmmxt_names[] = {
9127 "wR0", "wR1", "wR2", "wR3", "wR4", "wR5", "wR6", "wR7",
9128 "wR8", "wR9", "wR10", "wR11", "wR12", "wR13", "wR14", "wR15",
9129 "wCID", "wCon", "wCSSF", "wCASF", "", "", "", "",
9130 "wCGR0", "wCGR1", "wCGR2", "wCGR3", "", "", "", "",
9134 for (i = ARM_WR0_REGNUM; i <= ARM_WR15_REGNUM; i++)
9136 &= tdesc_numbered_register (feature, tdesc_data, i,
9137 iwmmxt_names[i - ARM_WR0_REGNUM]);
9139 /* Check for the control registers, but do not fail if they
9141 for (i = ARM_WC0_REGNUM; i <= ARM_WCASF_REGNUM; i++)
9142 tdesc_numbered_register (feature, tdesc_data, i,
9143 iwmmxt_names[i - ARM_WR0_REGNUM]);
9145 for (i = ARM_WCGR0_REGNUM; i <= ARM_WCGR3_REGNUM; i++)
9147 &= tdesc_numbered_register (feature, tdesc_data, i,
9148 iwmmxt_names[i - ARM_WR0_REGNUM]);
9152 tdesc_data_cleanup (tdesc_data);
9156 have_wmmx_registers = 1;
9159 /* If we have a VFP unit, check whether the single precision registers
9160 are present. If not, then we will synthesize them as pseudo
9162 feature = tdesc_find_feature (tdesc,
9163 "org.gnu.gdb.arm.vfp");
9164 if (feature != NULL)
9166 static const char *const vfp_double_names[] = {
9167 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
9168 "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15",
9169 "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23",
9170 "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31",
9173 /* Require the double precision registers. There must be either
9176 for (i = 0; i < 32; i++)
9178 valid_p &= tdesc_numbered_register (feature, tdesc_data,
9180 vfp_double_names[i]);
9184 if (!valid_p && i == 16)
9187 /* Also require FPSCR. */
9188 valid_p &= tdesc_numbered_register (feature, tdesc_data,
9189 ARM_FPSCR_REGNUM, "fpscr");
9192 tdesc_data_cleanup (tdesc_data);
9196 if (tdesc_unnumbered_register (feature, "s0") == 0)
9197 have_vfp_pseudos = 1;
9199 vfp_register_count = i;
9201 /* If we have VFP, also check for NEON. The architecture allows
9202 NEON without VFP (integer vector operations only), but GDB
9203 does not support that. */
9204 feature = tdesc_find_feature (tdesc,
9205 "org.gnu.gdb.arm.neon");
9206 if (feature != NULL)
9208 /* NEON requires 32 double-precision registers. */
9211 tdesc_data_cleanup (tdesc_data);
9215 /* If there are quad registers defined by the stub, use
9216 their type; otherwise (normally) provide them with
9217 the default type. */
9218 if (tdesc_unnumbered_register (feature, "q0") == 0)
9219 have_neon_pseudos = 1;
9226 /* If there is already a candidate, use it. */
9227 for (best_arch = gdbarch_list_lookup_by_info (arches, &info);
9229 best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
9231 if (arm_abi != ARM_ABI_AUTO
9232 && arm_abi != gdbarch_tdep (best_arch->gdbarch)->arm_abi)
9235 if (fp_model != ARM_FLOAT_AUTO
9236 && fp_model != gdbarch_tdep (best_arch->gdbarch)->fp_model)
9239 /* There are various other properties in tdep that we do not
9240 need to check here: those derived from a target description,
9241 since gdbarches with a different target description are
9242 automatically disqualified. */
9244 /* Do check is_m, though, since it might come from the binary. */
9245 if (is_m != gdbarch_tdep (best_arch->gdbarch)->is_m)
9248 /* Found a match. */
9252 if (best_arch != NULL)
9254 if (tdesc_data != NULL)
9255 tdesc_data_cleanup (tdesc_data);
9256 return best_arch->gdbarch;
9259 tdep = XCNEW (struct gdbarch_tdep);
9260 gdbarch = gdbarch_alloc (&info, tdep);
9262 /* Record additional information about the architecture we are defining.
9263 These are gdbarch discriminators, like the OSABI. */
9264 tdep->arm_abi = arm_abi;
9265 tdep->fp_model = fp_model;
9267 tdep->have_fpa_registers = have_fpa_registers;
9268 tdep->have_wmmx_registers = have_wmmx_registers;
9269 gdb_assert (vfp_register_count == 0
9270 || vfp_register_count == 16
9271 || vfp_register_count == 32);
9272 tdep->vfp_register_count = vfp_register_count;
9273 tdep->have_vfp_pseudos = have_vfp_pseudos;
9274 tdep->have_neon_pseudos = have_neon_pseudos;
9275 tdep->have_neon = have_neon;
9277 arm_register_g_packet_guesses (gdbarch);
9280 switch (info.byte_order_for_code)
9282 case BFD_ENDIAN_BIG:
9283 tdep->arm_breakpoint = arm_default_arm_be_breakpoint;
9284 tdep->arm_breakpoint_size = sizeof (arm_default_arm_be_breakpoint);
9285 tdep->thumb_breakpoint = arm_default_thumb_be_breakpoint;
9286 tdep->thumb_breakpoint_size = sizeof (arm_default_thumb_be_breakpoint);
9290 case BFD_ENDIAN_LITTLE:
9291 tdep->arm_breakpoint = arm_default_arm_le_breakpoint;
9292 tdep->arm_breakpoint_size = sizeof (arm_default_arm_le_breakpoint);
9293 tdep->thumb_breakpoint = arm_default_thumb_le_breakpoint;
9294 tdep->thumb_breakpoint_size = sizeof (arm_default_thumb_le_breakpoint);
9299 internal_error (__FILE__, __LINE__,
9300 _("arm_gdbarch_init: bad byte order for float format"));
9303 /* On ARM targets char defaults to unsigned. */
9304 set_gdbarch_char_signed (gdbarch, 0);
9306 /* wchar_t is unsigned under the AAPCS. */
9307 if (tdep->arm_abi == ARM_ABI_AAPCS)
9308 set_gdbarch_wchar_signed (gdbarch, 0);
9310 set_gdbarch_wchar_signed (gdbarch, 1);
9312 /* Note: for displaced stepping, this includes the breakpoint, and one word
9313 of additional scratch space. This setting isn't used for anything beside
9314 displaced stepping at present. */
9315 set_gdbarch_max_insn_length (gdbarch, 4 * DISPLACED_MODIFIED_INSNS);
9317 /* This should be low enough for everything. */
9318 tdep->lowest_pc = 0x20;
9319 tdep->jb_pc = -1; /* Longjump support not enabled by default. */
9321 /* The default, for both APCS and AAPCS, is to return small
9322 structures in registers. */
9323 tdep->struct_return = reg_struct_return;
9325 set_gdbarch_push_dummy_call (gdbarch, arm_push_dummy_call);
9326 set_gdbarch_frame_align (gdbarch, arm_frame_align);
9329 set_gdbarch_code_of_frame_writable (gdbarch, arm_code_of_frame_writable);
9331 set_gdbarch_write_pc (gdbarch, arm_write_pc);
9333 frame_base_set_default (gdbarch, &arm_normal_base);
9335 /* Address manipulation. */
9336 set_gdbarch_addr_bits_remove (gdbarch, arm_addr_bits_remove);
9338 /* Advance PC across function entry code. */
9339 set_gdbarch_skip_prologue (gdbarch, arm_skip_prologue);
9341 /* Detect whether PC is at a point where the stack has been destroyed. */
9342 set_gdbarch_stack_frame_destroyed_p (gdbarch, arm_stack_frame_destroyed_p);
9344 /* Skip trampolines. */
9345 set_gdbarch_skip_trampoline_code (gdbarch, arm_skip_stub);
9347 /* The stack grows downward. */
9348 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
9350 /* Breakpoint manipulation. */
9351 set_gdbarch_breakpoint_kind_from_pc (gdbarch, arm_breakpoint_kind_from_pc);
9352 set_gdbarch_sw_breakpoint_from_kind (gdbarch, arm_sw_breakpoint_from_kind);
9353 set_gdbarch_breakpoint_kind_from_current_state (gdbarch,
9354 arm_breakpoint_kind_from_current_state);
9356 /* Information about registers, etc. */
9357 set_gdbarch_sp_regnum (gdbarch, ARM_SP_REGNUM);
9358 set_gdbarch_pc_regnum (gdbarch, ARM_PC_REGNUM);
9359 set_gdbarch_num_regs (gdbarch, ARM_NUM_REGS);
9360 set_gdbarch_register_type (gdbarch, arm_register_type);
9361 set_gdbarch_register_reggroup_p (gdbarch, arm_register_reggroup_p);
9363 /* This "info float" is FPA-specific. Use the generic version if we
9365 if (gdbarch_tdep (gdbarch)->have_fpa_registers)
9366 set_gdbarch_print_float_info (gdbarch, arm_print_float_info);
9368 /* Internal <-> external register number maps. */
9369 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, arm_dwarf_reg_to_regnum);
9370 set_gdbarch_register_sim_regno (gdbarch, arm_register_sim_regno);
9372 set_gdbarch_register_name (gdbarch, arm_register_name);
9374 /* Returning results. */
9375 set_gdbarch_return_value (gdbarch, arm_return_value);
9378 set_gdbarch_print_insn (gdbarch, gdb_print_insn_arm);
9380 /* Minsymbol frobbing. */
9381 set_gdbarch_elf_make_msymbol_special (gdbarch, arm_elf_make_msymbol_special);
9382 set_gdbarch_coff_make_msymbol_special (gdbarch,
9383 arm_coff_make_msymbol_special);
9384 set_gdbarch_record_special_symbol (gdbarch, arm_record_special_symbol);
9386 /* Thumb-2 IT block support. */
9387 set_gdbarch_adjust_breakpoint_address (gdbarch,
9388 arm_adjust_breakpoint_address);
9390 /* Virtual tables. */
9391 set_gdbarch_vbit_in_delta (gdbarch, 1);
9393 /* Hook in the ABI-specific overrides, if they have been registered. */
9394 gdbarch_init_osabi (info, gdbarch);
9396 dwarf2_frame_set_init_reg (gdbarch, arm_dwarf2_frame_init_reg);
9398 /* Add some default predicates. */
9400 frame_unwind_append_unwinder (gdbarch, &arm_m_exception_unwind);
9401 frame_unwind_append_unwinder (gdbarch, &arm_stub_unwind);
9402 dwarf2_append_unwinders (gdbarch);
9403 frame_unwind_append_unwinder (gdbarch, &arm_exidx_unwind);
9404 frame_unwind_append_unwinder (gdbarch, &arm_epilogue_frame_unwind);
9405 frame_unwind_append_unwinder (gdbarch, &arm_prologue_unwind);
9407 /* Now we have tuned the configuration, set a few final things,
9408 based on what the OS ABI has told us. */
9410 /* If the ABI is not otherwise marked, assume the old GNU APCS. EABI
9411 binaries are always marked. */
9412 if (tdep->arm_abi == ARM_ABI_AUTO)
9413 tdep->arm_abi = ARM_ABI_APCS;
9415 /* Watchpoints are not steppable. */
9416 set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
9418 /* We used to default to FPA for generic ARM, but almost nobody
9419 uses that now, and we now provide a way for the user to force
9420 the model. So default to the most useful variant. */
9421 if (tdep->fp_model == ARM_FLOAT_AUTO)
9422 tdep->fp_model = ARM_FLOAT_SOFT_FPA;
9424 if (tdep->jb_pc >= 0)
9425 set_gdbarch_get_longjmp_target (gdbarch, arm_get_longjmp_target);
9427 /* Floating point sizes and format. */
9428 set_gdbarch_float_format (gdbarch, floatformats_ieee_single);
9429 if (tdep->fp_model == ARM_FLOAT_SOFT_FPA || tdep->fp_model == ARM_FLOAT_FPA)
9431 set_gdbarch_double_format
9432 (gdbarch, floatformats_ieee_double_littlebyte_bigword);
9433 set_gdbarch_long_double_format
9434 (gdbarch, floatformats_ieee_double_littlebyte_bigword);
9438 set_gdbarch_double_format (gdbarch, floatformats_ieee_double);
9439 set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double);
9442 if (have_vfp_pseudos)
9444 /* NOTE: These are the only pseudo registers used by
9445 the ARM target at the moment. If more are added, a
9446 little more care in numbering will be needed. */
9448 int num_pseudos = 32;
9449 if (have_neon_pseudos)
9451 set_gdbarch_num_pseudo_regs (gdbarch, num_pseudos);
9452 set_gdbarch_pseudo_register_read (gdbarch, arm_pseudo_read);
9453 set_gdbarch_pseudo_register_write (gdbarch, arm_pseudo_write);
9458 set_tdesc_pseudo_register_name (gdbarch, arm_register_name);
9460 tdesc_use_registers (gdbarch, tdesc, tdesc_data);
9462 /* Override tdesc_register_type to adjust the types of VFP
9463 registers for NEON. */
9464 set_gdbarch_register_type (gdbarch, arm_register_type);
9467 /* Add standard register aliases. We add aliases even for those
9468 nanes which are used by the current architecture - it's simpler,
9469 and does no harm, since nothing ever lists user registers. */
9470 for (i = 0; i < ARRAY_SIZE (arm_register_aliases); i++)
9471 user_reg_add (gdbarch, arm_register_aliases[i].name,
9472 value_of_arm_user_reg, &arm_register_aliases[i].regnum);
9474 set_gdbarch_disassembler_options (gdbarch, &arm_disassembler_options);
9475 set_gdbarch_valid_disassembler_options (gdbarch, disassembler_options_arm ());
9481 arm_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
9483 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
9488 fprintf_unfiltered (file, _("arm_dump_tdep: Lowest pc = 0x%lx"),
9489 (unsigned long) tdep->lowest_pc);
9495 static void arm_record_test (void);
9500 _initialize_arm_tdep (void)
9504 char regdesc[1024], *rdptr = regdesc;
9505 size_t rest = sizeof (regdesc);
9507 gdbarch_register (bfd_arch_arm, arm_gdbarch_init, arm_dump_tdep);
9509 arm_objfile_data_key
9510 = register_objfile_data_with_cleanup (NULL, arm_objfile_data_free);
9512 /* Add ourselves to objfile event chain. */
9513 gdb::observers::new_objfile.attach (arm_exidx_new_objfile);
9515 = register_objfile_data_with_cleanup (NULL, arm_exidx_data_free);
9517 /* Register an ELF OS ABI sniffer for ARM binaries. */
9518 gdbarch_register_osabi_sniffer (bfd_arch_arm,
9519 bfd_target_elf_flavour,
9520 arm_elf_osabi_sniffer);
9522 /* Initialize the standard target descriptions. */
9523 initialize_tdesc_arm_with_m ();
9524 initialize_tdesc_arm_with_m_fpa_layout ();
9525 initialize_tdesc_arm_with_m_vfp_d16 ();
9526 initialize_tdesc_arm_with_iwmmxt ();
9527 initialize_tdesc_arm_with_vfpv2 ();
9528 initialize_tdesc_arm_with_vfpv3 ();
9529 initialize_tdesc_arm_with_neon ();
9531 /* Add root prefix command for all "set arm"/"show arm" commands. */
9532 add_prefix_cmd ("arm", no_class, set_arm_command,
9533 _("Various ARM-specific commands."),
9534 &setarmcmdlist, "set arm ", 0, &setlist);
9536 add_prefix_cmd ("arm", no_class, show_arm_command,
9537 _("Various ARM-specific commands."),
9538 &showarmcmdlist, "show arm ", 0, &showlist);
9541 arm_disassembler_options = xstrdup ("reg-names-std");
9542 const disasm_options_t *disasm_options
9543 = &disassembler_options_arm ()->options;
9544 int num_disassembly_styles = 0;
9545 for (i = 0; disasm_options->name[i] != NULL; i++)
9546 if (CONST_STRNEQ (disasm_options->name[i], "reg-names-"))
9547 num_disassembly_styles++;
9549 /* Initialize the array that will be passed to add_setshow_enum_cmd(). */
9550 valid_disassembly_styles = XNEWVEC (const char *,
9551 num_disassembly_styles + 1);
9552 for (i = j = 0; disasm_options->name[i] != NULL; i++)
9553 if (CONST_STRNEQ (disasm_options->name[i], "reg-names-"))
9555 size_t offset = strlen ("reg-names-");
9556 const char *style = disasm_options->name[i];
9557 valid_disassembly_styles[j++] = &style[offset];
9558 length = snprintf (rdptr, rest, "%s - %s\n", &style[offset],
9559 disasm_options->description[i]);
9563 /* Mark the end of valid options. */
9564 valid_disassembly_styles[num_disassembly_styles] = NULL;
9566 /* Create the help text. */
9567 std::string helptext = string_printf ("%s%s%s",
9568 _("The valid values are:\n"),
9570 _("The default is \"std\"."));
9572 add_setshow_enum_cmd("disassembler", no_class,
9573 valid_disassembly_styles, &disassembly_style,
9574 _("Set the disassembly style."),
9575 _("Show the disassembly style."),
9577 set_disassembly_style_sfunc,
9578 show_disassembly_style_sfunc,
9579 &setarmcmdlist, &showarmcmdlist);
9581 add_setshow_boolean_cmd ("apcs32", no_class, &arm_apcs_32,
9582 _("Set usage of ARM 32-bit mode."),
9583 _("Show usage of ARM 32-bit mode."),
9584 _("When off, a 26-bit PC will be used."),
9586 NULL, /* FIXME: i18n: Usage of ARM 32-bit
9588 &setarmcmdlist, &showarmcmdlist);
9590 /* Add a command to allow the user to force the FPU model. */
9591 add_setshow_enum_cmd ("fpu", no_class, fp_model_strings, ¤t_fp_model,
9592 _("Set the floating point type."),
9593 _("Show the floating point type."),
9594 _("auto - Determine the FP typefrom the OS-ABI.\n\
9595 softfpa - Software FP, mixed-endian doubles on little-endian ARMs.\n\
9596 fpa - FPA co-processor (GCC compiled).\n\
9597 softvfp - Software FP with pure-endian doubles.\n\
9598 vfp - VFP co-processor."),
9599 set_fp_model_sfunc, show_fp_model,
9600 &setarmcmdlist, &showarmcmdlist);
9602 /* Add a command to allow the user to force the ABI. */
9603 add_setshow_enum_cmd ("abi", class_support, arm_abi_strings, &arm_abi_string,
9606 NULL, arm_set_abi, arm_show_abi,
9607 &setarmcmdlist, &showarmcmdlist);
9609 /* Add two commands to allow the user to force the assumed
9611 add_setshow_enum_cmd ("fallback-mode", class_support,
9612 arm_mode_strings, &arm_fallback_mode_string,
9613 _("Set the mode assumed when symbols are unavailable."),
9614 _("Show the mode assumed when symbols are unavailable."),
9615 NULL, NULL, arm_show_fallback_mode,
9616 &setarmcmdlist, &showarmcmdlist);
9617 add_setshow_enum_cmd ("force-mode", class_support,
9618 arm_mode_strings, &arm_force_mode_string,
9619 _("Set the mode assumed even when symbols are available."),
9620 _("Show the mode assumed even when symbols are available."),
9621 NULL, NULL, arm_show_force_mode,
9622 &setarmcmdlist, &showarmcmdlist);
9624 /* Debugging flag. */
9625 add_setshow_boolean_cmd ("arm", class_maintenance, &arm_debug,
9626 _("Set ARM debugging."),
9627 _("Show ARM debugging."),
9628 _("When on, arm-specific debugging is enabled."),
9630 NULL, /* FIXME: i18n: "ARM debugging is %s. */
9631 &setdebuglist, &showdebuglist);
9634 selftests::register_test ("arm-record", selftests::arm_record_test);
9639 /* ARM-reversible process record data structures. */
9641 #define ARM_INSN_SIZE_BYTES 4
9642 #define THUMB_INSN_SIZE_BYTES 2
9643 #define THUMB2_INSN_SIZE_BYTES 4
9646 /* Position of the bit within a 32-bit ARM instruction
9647 that defines whether the instruction is a load or store. */
9648 #define INSN_S_L_BIT_NUM 20
9650 #define REG_ALLOC(REGS, LENGTH, RECORD_BUF) \
9653 unsigned int reg_len = LENGTH; \
9656 REGS = XNEWVEC (uint32_t, reg_len); \
9657 memcpy(®S[0], &RECORD_BUF[0], sizeof(uint32_t)*LENGTH); \
9662 #define MEM_ALLOC(MEMS, LENGTH, RECORD_BUF) \
9665 unsigned int mem_len = LENGTH; \
9668 MEMS = XNEWVEC (struct arm_mem_r, mem_len); \
9669 memcpy(&MEMS->len, &RECORD_BUF[0], \
9670 sizeof(struct arm_mem_r) * LENGTH); \
9675 /* Checks whether insn is already recorded or yet to be decoded. (boolean expression). */
9676 #define INSN_RECORDED(ARM_RECORD) \
9677 (0 != (ARM_RECORD)->reg_rec_count || 0 != (ARM_RECORD)->mem_rec_count)
9679 /* ARM memory record structure. */
9682 uint32_t len; /* Record length. */
9683 uint32_t addr; /* Memory address. */
9686 /* ARM instruction record contains opcode of current insn
9687 and execution state (before entry to decode_insn()),
9688 contains list of to-be-modified registers and
9689 memory blocks (on return from decode_insn()). */
9691 typedef struct insn_decode_record_t
9693 struct gdbarch *gdbarch;
9694 struct regcache *regcache;
9695 CORE_ADDR this_addr; /* Address of the insn being decoded. */
9696 uint32_t arm_insn; /* Should accommodate thumb. */
9697 uint32_t cond; /* Condition code. */
9698 uint32_t opcode; /* Insn opcode. */
9699 uint32_t decode; /* Insn decode bits. */
9700 uint32_t mem_rec_count; /* No of mem records. */
9701 uint32_t reg_rec_count; /* No of reg records. */
9702 uint32_t *arm_regs; /* Registers to be saved for this record. */
9703 struct arm_mem_r *arm_mems; /* Memory to be saved for this record. */
9704 } insn_decode_record;
9707 /* Checks ARM SBZ and SBO mandatory fields. */
9710 sbo_sbz (uint32_t insn, uint32_t bit_num, uint32_t len, uint32_t sbo)
9712 uint32_t ones = bits (insn, bit_num - 1, (bit_num -1) + (len - 1));
9731 enum arm_record_result
9733 ARM_RECORD_SUCCESS = 0,
9734 ARM_RECORD_FAILURE = 1
9741 } arm_record_strx_t;
9752 arm_record_strx (insn_decode_record *arm_insn_r, uint32_t *record_buf,
9753 uint32_t *record_buf_mem, arm_record_strx_t str_type)
9756 struct regcache *reg_cache = arm_insn_r->regcache;
9757 ULONGEST u_regval[2]= {0};
9759 uint32_t reg_src1 = 0, reg_src2 = 0;
9760 uint32_t immed_high = 0, immed_low = 0,offset_8 = 0, tgt_mem_addr = 0;
9762 arm_insn_r->opcode = bits (arm_insn_r->arm_insn, 21, 24);
9763 arm_insn_r->decode = bits (arm_insn_r->arm_insn, 4, 7);
9765 if (14 == arm_insn_r->opcode || 10 == arm_insn_r->opcode)
9767 /* 1) Handle misc store, immediate offset. */
9768 immed_low = bits (arm_insn_r->arm_insn, 0, 3);
9769 immed_high = bits (arm_insn_r->arm_insn, 8, 11);
9770 reg_src1 = bits (arm_insn_r->arm_insn, 16, 19);
9771 regcache_raw_read_unsigned (reg_cache, reg_src1,
9773 if (ARM_PC_REGNUM == reg_src1)
9775 /* If R15 was used as Rn, hence current PC+8. */
9776 u_regval[0] = u_regval[0] + 8;
9778 offset_8 = (immed_high << 4) | immed_low;
9779 /* Calculate target store address. */
9780 if (14 == arm_insn_r->opcode)
9782 tgt_mem_addr = u_regval[0] + offset_8;
9786 tgt_mem_addr = u_regval[0] - offset_8;
9788 if (ARM_RECORD_STRH == str_type)
9790 record_buf_mem[0] = 2;
9791 record_buf_mem[1] = tgt_mem_addr;
9792 arm_insn_r->mem_rec_count = 1;
9794 else if (ARM_RECORD_STRD == str_type)
9796 record_buf_mem[0] = 4;
9797 record_buf_mem[1] = tgt_mem_addr;
9798 record_buf_mem[2] = 4;
9799 record_buf_mem[3] = tgt_mem_addr + 4;
9800 arm_insn_r->mem_rec_count = 2;
9803 else if (12 == arm_insn_r->opcode || 8 == arm_insn_r->opcode)
9805 /* 2) Store, register offset. */
9807 reg_src1 = bits (arm_insn_r->arm_insn, 0, 3);
9809 reg_src2 = bits (arm_insn_r->arm_insn, 16, 19);
9810 regcache_raw_read_unsigned (reg_cache, reg_src1, &u_regval[0]);
9811 regcache_raw_read_unsigned (reg_cache, reg_src2, &u_regval[1]);
9814 /* If R15 was used as Rn, hence current PC+8. */
9815 u_regval[0] = u_regval[0] + 8;
9817 /* Calculate target store address, Rn +/- Rm, register offset. */
9818 if (12 == arm_insn_r->opcode)
9820 tgt_mem_addr = u_regval[0] + u_regval[1];
9824 tgt_mem_addr = u_regval[1] - u_regval[0];
9826 if (ARM_RECORD_STRH == str_type)
9828 record_buf_mem[0] = 2;
9829 record_buf_mem[1] = tgt_mem_addr;
9830 arm_insn_r->mem_rec_count = 1;
9832 else if (ARM_RECORD_STRD == str_type)
9834 record_buf_mem[0] = 4;
9835 record_buf_mem[1] = tgt_mem_addr;
9836 record_buf_mem[2] = 4;
9837 record_buf_mem[3] = tgt_mem_addr + 4;
9838 arm_insn_r->mem_rec_count = 2;
9841 else if (11 == arm_insn_r->opcode || 15 == arm_insn_r->opcode
9842 || 2 == arm_insn_r->opcode || 6 == arm_insn_r->opcode)
9844 /* 3) Store, immediate pre-indexed. */
9845 /* 5) Store, immediate post-indexed. */
9846 immed_low = bits (arm_insn_r->arm_insn, 0, 3);
9847 immed_high = bits (arm_insn_r->arm_insn, 8, 11);
9848 offset_8 = (immed_high << 4) | immed_low;
9849 reg_src1 = bits (arm_insn_r->arm_insn, 16, 19);
9850 regcache_raw_read_unsigned (reg_cache, reg_src1, &u_regval[0]);
9851 /* Calculate target store address, Rn +/- Rm, register offset. */
9852 if (15 == arm_insn_r->opcode || 6 == arm_insn_r->opcode)
9854 tgt_mem_addr = u_regval[0] + offset_8;
9858 tgt_mem_addr = u_regval[0] - offset_8;
9860 if (ARM_RECORD_STRH == str_type)
9862 record_buf_mem[0] = 2;
9863 record_buf_mem[1] = tgt_mem_addr;
9864 arm_insn_r->mem_rec_count = 1;
9866 else if (ARM_RECORD_STRD == str_type)
9868 record_buf_mem[0] = 4;
9869 record_buf_mem[1] = tgt_mem_addr;
9870 record_buf_mem[2] = 4;
9871 record_buf_mem[3] = tgt_mem_addr + 4;
9872 arm_insn_r->mem_rec_count = 2;
9874 /* Record Rn also as it changes. */
9875 *(record_buf) = bits (arm_insn_r->arm_insn, 16, 19);
9876 arm_insn_r->reg_rec_count = 1;
9878 else if (9 == arm_insn_r->opcode || 13 == arm_insn_r->opcode
9879 || 0 == arm_insn_r->opcode || 4 == arm_insn_r->opcode)
9881 /* 4) Store, register pre-indexed. */
9882 /* 6) Store, register post -indexed. */
9883 reg_src1 = bits (arm_insn_r->arm_insn, 0, 3);
9884 reg_src2 = bits (arm_insn_r->arm_insn, 16, 19);
9885 regcache_raw_read_unsigned (reg_cache, reg_src1, &u_regval[0]);
9886 regcache_raw_read_unsigned (reg_cache, reg_src2, &u_regval[1]);
9887 /* Calculate target store address, Rn +/- Rm, register offset. */
9888 if (13 == arm_insn_r->opcode || 4 == arm_insn_r->opcode)
9890 tgt_mem_addr = u_regval[0] + u_regval[1];
9894 tgt_mem_addr = u_regval[1] - u_regval[0];
9896 if (ARM_RECORD_STRH == str_type)
9898 record_buf_mem[0] = 2;
9899 record_buf_mem[1] = tgt_mem_addr;
9900 arm_insn_r->mem_rec_count = 1;
9902 else if (ARM_RECORD_STRD == str_type)
9904 record_buf_mem[0] = 4;
9905 record_buf_mem[1] = tgt_mem_addr;
9906 record_buf_mem[2] = 4;
9907 record_buf_mem[3] = tgt_mem_addr + 4;
9908 arm_insn_r->mem_rec_count = 2;
9910 /* Record Rn also as it changes. */
9911 *(record_buf) = bits (arm_insn_r->arm_insn, 16, 19);
9912 arm_insn_r->reg_rec_count = 1;
9917 /* Handling ARM extension space insns. */
9920 arm_record_extension_space (insn_decode_record *arm_insn_r)
9922 int ret = 0; /* Return value: -1:record failure ; 0:success */
9923 uint32_t opcode1 = 0, opcode2 = 0, insn_op1 = 0;
9924 uint32_t record_buf[8], record_buf_mem[8];
9925 uint32_t reg_src1 = 0;
9926 struct regcache *reg_cache = arm_insn_r->regcache;
9927 ULONGEST u_regval = 0;
9929 gdb_assert (!INSN_RECORDED(arm_insn_r));
9930 /* Handle unconditional insn extension space. */
9932 opcode1 = bits (arm_insn_r->arm_insn, 20, 27);
9933 opcode2 = bits (arm_insn_r->arm_insn, 4, 7);
9934 if (arm_insn_r->cond)
9936 /* PLD has no affect on architectural state, it just affects
9938 if (5 == ((opcode1 & 0xE0) >> 5))
9941 record_buf[0] = ARM_PS_REGNUM;
9942 record_buf[1] = ARM_LR_REGNUM;
9943 arm_insn_r->reg_rec_count = 2;
9945 /* STC2, LDC2, MCR2, MRC2, CDP2: <TBD>, co-processor insn. */
9949 opcode1 = bits (arm_insn_r->arm_insn, 25, 27);
9950 if (3 == opcode1 && bit (arm_insn_r->arm_insn, 4))
9953 /* Undefined instruction on ARM V5; need to handle if later
9954 versions define it. */
9957 opcode1 = bits (arm_insn_r->arm_insn, 24, 27);
9958 opcode2 = bits (arm_insn_r->arm_insn, 4, 7);
9959 insn_op1 = bits (arm_insn_r->arm_insn, 20, 23);
9961 /* Handle arithmetic insn extension space. */
9962 if (!opcode1 && 9 == opcode2 && 1 != arm_insn_r->cond
9963 && !INSN_RECORDED(arm_insn_r))
9965 /* Handle MLA(S) and MUL(S). */
9966 if (in_inclusive_range (insn_op1, 0U, 3U))
9968 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
9969 record_buf[1] = ARM_PS_REGNUM;
9970 arm_insn_r->reg_rec_count = 2;
9972 else if (in_inclusive_range (insn_op1, 4U, 15U))
9974 /* Handle SMLAL(S), SMULL(S), UMLAL(S), UMULL(S). */
9975 record_buf[0] = bits (arm_insn_r->arm_insn, 16, 19);
9976 record_buf[1] = bits (arm_insn_r->arm_insn, 12, 15);
9977 record_buf[2] = ARM_PS_REGNUM;
9978 arm_insn_r->reg_rec_count = 3;
9982 opcode1 = bits (arm_insn_r->arm_insn, 26, 27);
9983 opcode2 = bits (arm_insn_r->arm_insn, 23, 24);
9984 insn_op1 = bits (arm_insn_r->arm_insn, 21, 22);
9986 /* Handle control insn extension space. */
9988 if (!opcode1 && 2 == opcode2 && !bit (arm_insn_r->arm_insn, 20)
9989 && 1 != arm_insn_r->cond && !INSN_RECORDED(arm_insn_r))
9991 if (!bit (arm_insn_r->arm_insn,25))
9993 if (!bits (arm_insn_r->arm_insn, 4, 7))
9995 if ((0 == insn_op1) || (2 == insn_op1))
9998 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
9999 arm_insn_r->reg_rec_count = 1;
10001 else if (1 == insn_op1)
10003 /* CSPR is going to be changed. */
10004 record_buf[0] = ARM_PS_REGNUM;
10005 arm_insn_r->reg_rec_count = 1;
10007 else if (3 == insn_op1)
10009 /* SPSR is going to be changed. */
10010 /* We need to get SPSR value, which is yet to be done. */
10014 else if (1 == bits (arm_insn_r->arm_insn, 4, 7))
10019 record_buf[0] = ARM_PS_REGNUM;
10020 arm_insn_r->reg_rec_count = 1;
10022 else if (3 == insn_op1)
10025 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
10026 arm_insn_r->reg_rec_count = 1;
10029 else if (3 == bits (arm_insn_r->arm_insn, 4, 7))
10032 record_buf[0] = ARM_PS_REGNUM;
10033 record_buf[1] = ARM_LR_REGNUM;
10034 arm_insn_r->reg_rec_count = 2;
10036 else if (5 == bits (arm_insn_r->arm_insn, 4, 7))
10038 /* QADD, QSUB, QDADD, QDSUB */
10039 record_buf[0] = ARM_PS_REGNUM;
10040 record_buf[1] = bits (arm_insn_r->arm_insn, 12, 15);
10041 arm_insn_r->reg_rec_count = 2;
10043 else if (7 == bits (arm_insn_r->arm_insn, 4, 7))
10046 record_buf[0] = ARM_PS_REGNUM;
10047 record_buf[1] = ARM_LR_REGNUM;
10048 arm_insn_r->reg_rec_count = 2;
10050 /* Save SPSR also;how? */
10053 else if(8 == bits (arm_insn_r->arm_insn, 4, 7)
10054 || 10 == bits (arm_insn_r->arm_insn, 4, 7)
10055 || 12 == bits (arm_insn_r->arm_insn, 4, 7)
10056 || 14 == bits (arm_insn_r->arm_insn, 4, 7)
10059 if (0 == insn_op1 || 1 == insn_op1)
10061 /* SMLA<x><y>, SMLAW<y>, SMULW<y>. */
10062 /* We dont do optimization for SMULW<y> where we
10064 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
10065 record_buf[1] = ARM_PS_REGNUM;
10066 arm_insn_r->reg_rec_count = 2;
10068 else if (2 == insn_op1)
10071 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
10072 record_buf[1] = bits (arm_insn_r->arm_insn, 16, 19);
10073 arm_insn_r->reg_rec_count = 2;
10075 else if (3 == insn_op1)
10078 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
10079 arm_insn_r->reg_rec_count = 1;
10085 /* MSR : immediate form. */
10088 /* CSPR is going to be changed. */
10089 record_buf[0] = ARM_PS_REGNUM;
10090 arm_insn_r->reg_rec_count = 1;
10092 else if (3 == insn_op1)
10094 /* SPSR is going to be changed. */
10095 /* we need to get SPSR value, which is yet to be done */
10101 opcode1 = bits (arm_insn_r->arm_insn, 25, 27);
10102 opcode2 = bits (arm_insn_r->arm_insn, 20, 24);
10103 insn_op1 = bits (arm_insn_r->arm_insn, 5, 6);
10105 /* Handle load/store insn extension space. */
10107 if (!opcode1 && bit (arm_insn_r->arm_insn, 7)
10108 && bit (arm_insn_r->arm_insn, 4) && 1 != arm_insn_r->cond
10109 && !INSN_RECORDED(arm_insn_r))
10114 /* These insn, changes register and memory as well. */
10115 /* SWP or SWPB insn. */
10116 /* Get memory address given by Rn. */
10117 reg_src1 = bits (arm_insn_r->arm_insn, 16, 19);
10118 regcache_raw_read_unsigned (reg_cache, reg_src1, &u_regval);
10119 /* SWP insn ?, swaps word. */
10120 if (8 == arm_insn_r->opcode)
10122 record_buf_mem[0] = 4;
10126 /* SWPB insn, swaps only byte. */
10127 record_buf_mem[0] = 1;
10129 record_buf_mem[1] = u_regval;
10130 arm_insn_r->mem_rec_count = 1;
10131 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
10132 arm_insn_r->reg_rec_count = 1;
10134 else if (1 == insn_op1 && !bit (arm_insn_r->arm_insn, 20))
10137 arm_record_strx(arm_insn_r, &record_buf[0], &record_buf_mem[0],
10140 else if (2 == insn_op1 && !bit (arm_insn_r->arm_insn, 20))
10143 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
10144 record_buf[1] = record_buf[0] + 1;
10145 arm_insn_r->reg_rec_count = 2;
10147 else if (3 == insn_op1 && !bit (arm_insn_r->arm_insn, 20))
10150 arm_record_strx(arm_insn_r, &record_buf[0], &record_buf_mem[0],
10153 else if (bit (arm_insn_r->arm_insn, 20) && insn_op1 <= 3)
10155 /* LDRH, LDRSB, LDRSH. */
10156 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
10157 arm_insn_r->reg_rec_count = 1;
10162 opcode1 = bits (arm_insn_r->arm_insn, 23, 27);
10163 if (24 == opcode1 && bit (arm_insn_r->arm_insn, 21)
10164 && !INSN_RECORDED(arm_insn_r))
10167 /* Handle coprocessor insn extension space. */
10170 /* To be done for ARMv5 and later; as of now we return -1. */
10174 REG_ALLOC (arm_insn_r->arm_regs, arm_insn_r->reg_rec_count, record_buf);
10175 MEM_ALLOC (arm_insn_r->arm_mems, arm_insn_r->mem_rec_count, record_buf_mem);
10180 /* Handling opcode 000 insns. */
10183 arm_record_data_proc_misc_ld_str (insn_decode_record *arm_insn_r)
10185 struct regcache *reg_cache = arm_insn_r->regcache;
10186 uint32_t record_buf[8], record_buf_mem[8];
10187 ULONGEST u_regval[2] = {0};
10189 uint32_t reg_src1 = 0;
10190 uint32_t opcode1 = 0;
10192 arm_insn_r->opcode = bits (arm_insn_r->arm_insn, 21, 24);
10193 arm_insn_r->decode = bits (arm_insn_r->arm_insn, 4, 7);
10194 opcode1 = bits (arm_insn_r->arm_insn, 20, 24);
10196 if (!((opcode1 & 0x19) == 0x10))
10198 /* Data-processing (register) and Data-processing (register-shifted
10200 /* Out of 11 shifter operands mode, all the insn modifies destination
10201 register, which is specified by 13-16 decode. */
10202 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
10203 record_buf[1] = ARM_PS_REGNUM;
10204 arm_insn_r->reg_rec_count = 2;
10206 else if ((arm_insn_r->decode < 8) && ((opcode1 & 0x19) == 0x10))
10208 /* Miscellaneous instructions */
10210 if (3 == arm_insn_r->decode && 0x12 == opcode1
10211 && sbo_sbz (arm_insn_r->arm_insn, 9, 12, 1))
10213 /* Handle BLX, branch and link/exchange. */
10214 if (9 == arm_insn_r->opcode)
10216 /* Branch is chosen by setting T bit of CSPR, bitp[0] of Rm,
10217 and R14 stores the return address. */
10218 record_buf[0] = ARM_PS_REGNUM;
10219 record_buf[1] = ARM_LR_REGNUM;
10220 arm_insn_r->reg_rec_count = 2;
10223 else if (7 == arm_insn_r->decode && 0x12 == opcode1)
10225 /* Handle enhanced software breakpoint insn, BKPT. */
10226 /* CPSR is changed to be executed in ARM state, disabling normal
10227 interrupts, entering abort mode. */
10228 /* According to high vector configuration PC is set. */
10229 /* user hit breakpoint and type reverse, in
10230 that case, we need to go back with previous CPSR and
10231 Program Counter. */
10232 record_buf[0] = ARM_PS_REGNUM;
10233 record_buf[1] = ARM_LR_REGNUM;
10234 arm_insn_r->reg_rec_count = 2;
10236 /* Save SPSR also; how? */
10239 else if (1 == arm_insn_r->decode && 0x12 == opcode1
10240 && sbo_sbz (arm_insn_r->arm_insn, 9, 12, 1))
10242 /* Handle BX, branch and link/exchange. */
10243 /* Branch is chosen by setting T bit of CSPR, bitp[0] of Rm. */
10244 record_buf[0] = ARM_PS_REGNUM;
10245 arm_insn_r->reg_rec_count = 1;
10247 else if (1 == arm_insn_r->decode && 0x16 == opcode1
10248 && sbo_sbz (arm_insn_r->arm_insn, 9, 4, 1)
10249 && sbo_sbz (arm_insn_r->arm_insn, 17, 4, 1))
10251 /* Count leading zeros: CLZ. */
10252 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
10253 arm_insn_r->reg_rec_count = 1;
10255 else if (!bit (arm_insn_r->arm_insn, INSN_S_L_BIT_NUM)
10256 && (8 == arm_insn_r->opcode || 10 == arm_insn_r->opcode)
10257 && sbo_sbz (arm_insn_r->arm_insn, 17, 4, 1)
10258 && sbo_sbz (arm_insn_r->arm_insn, 1, 12, 0))
10260 /* Handle MRS insn. */
10261 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
10262 arm_insn_r->reg_rec_count = 1;
10265 else if (9 == arm_insn_r->decode && opcode1 < 0x10)
10267 /* Multiply and multiply-accumulate */
10269 /* Handle multiply instructions. */
10270 /* MLA, MUL, SMLAL, SMULL, UMLAL, UMULL. */
10271 if (0 == arm_insn_r->opcode || 1 == arm_insn_r->opcode)
10273 /* Handle MLA and MUL. */
10274 record_buf[0] = bits (arm_insn_r->arm_insn, 16, 19);
10275 record_buf[1] = ARM_PS_REGNUM;
10276 arm_insn_r->reg_rec_count = 2;
10278 else if (4 <= arm_insn_r->opcode && 7 >= arm_insn_r->opcode)
10280 /* Handle SMLAL, SMULL, UMLAL, UMULL. */
10281 record_buf[0] = bits (arm_insn_r->arm_insn, 16, 19);
10282 record_buf[1] = bits (arm_insn_r->arm_insn, 12, 15);
10283 record_buf[2] = ARM_PS_REGNUM;
10284 arm_insn_r->reg_rec_count = 3;
10287 else if (9 == arm_insn_r->decode && opcode1 > 0x10)
10289 /* Synchronization primitives */
10291 /* Handling SWP, SWPB. */
10292 /* These insn, changes register and memory as well. */
10293 /* SWP or SWPB insn. */
10295 reg_src1 = bits (arm_insn_r->arm_insn, 16, 19);
10296 regcache_raw_read_unsigned (reg_cache, reg_src1, &u_regval[0]);
10297 /* SWP insn ?, swaps word. */
10298 if (8 == arm_insn_r->opcode)
10300 record_buf_mem[0] = 4;
10304 /* SWPB insn, swaps only byte. */
10305 record_buf_mem[0] = 1;
10307 record_buf_mem[1] = u_regval[0];
10308 arm_insn_r->mem_rec_count = 1;
10309 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
10310 arm_insn_r->reg_rec_count = 1;
10312 else if (11 == arm_insn_r->decode || 13 == arm_insn_r->decode
10313 || 15 == arm_insn_r->decode)
10315 if ((opcode1 & 0x12) == 2)
10317 /* Extra load/store (unprivileged) */
10322 /* Extra load/store */
10323 switch (bits (arm_insn_r->arm_insn, 5, 6))
10326 if ((opcode1 & 0x05) == 0x0 || (opcode1 & 0x05) == 0x4)
10328 /* STRH (register), STRH (immediate) */
10329 arm_record_strx (arm_insn_r, &record_buf[0],
10330 &record_buf_mem[0], ARM_RECORD_STRH);
10332 else if ((opcode1 & 0x05) == 0x1)
10334 /* LDRH (register) */
10335 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
10336 arm_insn_r->reg_rec_count = 1;
10338 if (bit (arm_insn_r->arm_insn, 21))
10340 /* Write back to Rn. */
10341 record_buf[arm_insn_r->reg_rec_count++]
10342 = bits (arm_insn_r->arm_insn, 16, 19);
10345 else if ((opcode1 & 0x05) == 0x5)
10347 /* LDRH (immediate), LDRH (literal) */
10348 int rn = bits (arm_insn_r->arm_insn, 16, 19);
10350 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
10351 arm_insn_r->reg_rec_count = 1;
10355 /*LDRH (immediate) */
10356 if (bit (arm_insn_r->arm_insn, 21))
10358 /* Write back to Rn. */
10359 record_buf[arm_insn_r->reg_rec_count++] = rn;
10367 if ((opcode1 & 0x05) == 0x0)
10369 /* LDRD (register) */
10370 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
10371 record_buf[1] = record_buf[0] + 1;
10372 arm_insn_r->reg_rec_count = 2;
10374 if (bit (arm_insn_r->arm_insn, 21))
10376 /* Write back to Rn. */
10377 record_buf[arm_insn_r->reg_rec_count++]
10378 = bits (arm_insn_r->arm_insn, 16, 19);
10381 else if ((opcode1 & 0x05) == 0x1)
10383 /* LDRSB (register) */
10384 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
10385 arm_insn_r->reg_rec_count = 1;
10387 if (bit (arm_insn_r->arm_insn, 21))
10389 /* Write back to Rn. */
10390 record_buf[arm_insn_r->reg_rec_count++]
10391 = bits (arm_insn_r->arm_insn, 16, 19);
10394 else if ((opcode1 & 0x05) == 0x4 || (opcode1 & 0x05) == 0x5)
10396 /* LDRD (immediate), LDRD (literal), LDRSB (immediate),
10398 int rn = bits (arm_insn_r->arm_insn, 16, 19);
10400 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
10401 arm_insn_r->reg_rec_count = 1;
10405 /*LDRD (immediate), LDRSB (immediate) */
10406 if (bit (arm_insn_r->arm_insn, 21))
10408 /* Write back to Rn. */
10409 record_buf[arm_insn_r->reg_rec_count++] = rn;
10417 if ((opcode1 & 0x05) == 0x0)
10419 /* STRD (register) */
10420 arm_record_strx (arm_insn_r, &record_buf[0],
10421 &record_buf_mem[0], ARM_RECORD_STRD);
10423 else if ((opcode1 & 0x05) == 0x1)
10425 /* LDRSH (register) */
10426 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
10427 arm_insn_r->reg_rec_count = 1;
10429 if (bit (arm_insn_r->arm_insn, 21))
10431 /* Write back to Rn. */
10432 record_buf[arm_insn_r->reg_rec_count++]
10433 = bits (arm_insn_r->arm_insn, 16, 19);
10436 else if ((opcode1 & 0x05) == 0x4)
10438 /* STRD (immediate) */
10439 arm_record_strx (arm_insn_r, &record_buf[0],
10440 &record_buf_mem[0], ARM_RECORD_STRD);
10442 else if ((opcode1 & 0x05) == 0x5)
10444 /* LDRSH (immediate), LDRSH (literal) */
10445 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
10446 arm_insn_r->reg_rec_count = 1;
10448 if (bit (arm_insn_r->arm_insn, 21))
10450 /* Write back to Rn. */
10451 record_buf[arm_insn_r->reg_rec_count++]
10452 = bits (arm_insn_r->arm_insn, 16, 19);
10468 REG_ALLOC (arm_insn_r->arm_regs, arm_insn_r->reg_rec_count, record_buf);
10469 MEM_ALLOC (arm_insn_r->arm_mems, arm_insn_r->mem_rec_count, record_buf_mem);
10473 /* Handling opcode 001 insns. */
10476 arm_record_data_proc_imm (insn_decode_record *arm_insn_r)
10478 uint32_t record_buf[8], record_buf_mem[8];
10480 arm_insn_r->opcode = bits (arm_insn_r->arm_insn, 21, 24);
10481 arm_insn_r->decode = bits (arm_insn_r->arm_insn, 4, 7);
10483 if ((9 == arm_insn_r->opcode || 11 == arm_insn_r->opcode)
10484 && 2 == bits (arm_insn_r->arm_insn, 20, 21)
10485 && sbo_sbz (arm_insn_r->arm_insn, 13, 4, 1)
10488 /* Handle MSR insn. */
10489 if (9 == arm_insn_r->opcode)
10491 /* CSPR is going to be changed. */
10492 record_buf[0] = ARM_PS_REGNUM;
10493 arm_insn_r->reg_rec_count = 1;
10497 /* SPSR is going to be changed. */
10500 else if (arm_insn_r->opcode <= 15)
10502 /* Normal data processing insns. */
10503 /* Out of 11 shifter operands mode, all the insn modifies destination
10504 register, which is specified by 13-16 decode. */
10505 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
10506 record_buf[1] = ARM_PS_REGNUM;
10507 arm_insn_r->reg_rec_count = 2;
10514 REG_ALLOC (arm_insn_r->arm_regs, arm_insn_r->reg_rec_count, record_buf);
10515 MEM_ALLOC (arm_insn_r->arm_mems, arm_insn_r->mem_rec_count, record_buf_mem);
10520 arm_record_media (insn_decode_record *arm_insn_r)
10522 uint32_t record_buf[8];
10524 switch (bits (arm_insn_r->arm_insn, 22, 24))
10527 /* Parallel addition and subtraction, signed */
10529 /* Parallel addition and subtraction, unsigned */
10532 /* Packing, unpacking, saturation and reversal */
10534 int rd = bits (arm_insn_r->arm_insn, 12, 15);
10536 record_buf[arm_insn_r->reg_rec_count++] = rd;
10542 /* Signed multiplies */
10544 int rd = bits (arm_insn_r->arm_insn, 16, 19);
10545 unsigned int op1 = bits (arm_insn_r->arm_insn, 20, 22);
10547 record_buf[arm_insn_r->reg_rec_count++] = rd;
10549 record_buf[arm_insn_r->reg_rec_count++] = ARM_PS_REGNUM;
10550 else if (op1 == 0x4)
10551 record_buf[arm_insn_r->reg_rec_count++]
10552 = bits (arm_insn_r->arm_insn, 12, 15);
10558 if (bit (arm_insn_r->arm_insn, 21)
10559 && bits (arm_insn_r->arm_insn, 5, 6) == 0x2)
10562 record_buf[arm_insn_r->reg_rec_count++]
10563 = bits (arm_insn_r->arm_insn, 12, 15);
10565 else if (bits (arm_insn_r->arm_insn, 20, 21) == 0x0
10566 && bits (arm_insn_r->arm_insn, 5, 7) == 0x0)
10568 /* USAD8 and USADA8 */
10569 record_buf[arm_insn_r->reg_rec_count++]
10570 = bits (arm_insn_r->arm_insn, 16, 19);
10577 if (bits (arm_insn_r->arm_insn, 20, 21) == 0x3
10578 && bits (arm_insn_r->arm_insn, 5, 7) == 0x7)
10580 /* Permanently UNDEFINED */
10585 /* BFC, BFI and UBFX */
10586 record_buf[arm_insn_r->reg_rec_count++]
10587 = bits (arm_insn_r->arm_insn, 12, 15);
10596 REG_ALLOC (arm_insn_r->arm_regs, arm_insn_r->reg_rec_count, record_buf);
10601 /* Handle ARM mode instructions with opcode 010. */
10604 arm_record_ld_st_imm_offset (insn_decode_record *arm_insn_r)
10606 struct regcache *reg_cache = arm_insn_r->regcache;
10608 uint32_t reg_base , reg_dest;
10609 uint32_t offset_12, tgt_mem_addr;
10610 uint32_t record_buf[8], record_buf_mem[8];
10611 unsigned char wback;
10614 /* Calculate wback. */
10615 wback = (bit (arm_insn_r->arm_insn, 24) == 0)
10616 || (bit (arm_insn_r->arm_insn, 21) == 1);
10618 arm_insn_r->reg_rec_count = 0;
10619 reg_base = bits (arm_insn_r->arm_insn, 16, 19);
10621 if (bit (arm_insn_r->arm_insn, INSN_S_L_BIT_NUM))
10623 /* LDR (immediate), LDR (literal), LDRB (immediate), LDRB (literal), LDRBT
10626 reg_dest = bits (arm_insn_r->arm_insn, 12, 15);
10627 record_buf[arm_insn_r->reg_rec_count++] = reg_dest;
10629 /* The LDR instruction is capable of doing branching. If MOV LR, PC
10630 preceeds a LDR instruction having R15 as reg_base, it
10631 emulates a branch and link instruction, and hence we need to save
10632 CPSR and PC as well. */
10633 if (ARM_PC_REGNUM == reg_dest)
10634 record_buf[arm_insn_r->reg_rec_count++] = ARM_PS_REGNUM;
10636 /* If wback is true, also save the base register, which is going to be
10639 record_buf[arm_insn_r->reg_rec_count++] = reg_base;
10643 /* STR (immediate), STRB (immediate), STRBT and STRT. */
10645 offset_12 = bits (arm_insn_r->arm_insn, 0, 11);
10646 regcache_raw_read_unsigned (reg_cache, reg_base, &u_regval);
10648 /* Handle bit U. */
10649 if (bit (arm_insn_r->arm_insn, 23))
10651 /* U == 1: Add the offset. */
10652 tgt_mem_addr = (uint32_t) u_regval + offset_12;
10656 /* U == 0: subtract the offset. */
10657 tgt_mem_addr = (uint32_t) u_regval - offset_12;
10660 /* Bit 22 tells us whether the store instruction writes 1 byte or 4
10662 if (bit (arm_insn_r->arm_insn, 22))
10664 /* STRB and STRBT: 1 byte. */
10665 record_buf_mem[0] = 1;
10669 /* STR and STRT: 4 bytes. */
10670 record_buf_mem[0] = 4;
10673 /* Handle bit P. */
10674 if (bit (arm_insn_r->arm_insn, 24))
10675 record_buf_mem[1] = tgt_mem_addr;
10677 record_buf_mem[1] = (uint32_t) u_regval;
10679 arm_insn_r->mem_rec_count = 1;
10681 /* If wback is true, also save the base register, which is going to be
10684 record_buf[arm_insn_r->reg_rec_count++] = reg_base;
10687 REG_ALLOC (arm_insn_r->arm_regs, arm_insn_r->reg_rec_count, record_buf);
10688 MEM_ALLOC (arm_insn_r->arm_mems, arm_insn_r->mem_rec_count, record_buf_mem);
10692 /* Handling opcode 011 insns. */
10695 arm_record_ld_st_reg_offset (insn_decode_record *arm_insn_r)
10697 struct regcache *reg_cache = arm_insn_r->regcache;
10699 uint32_t shift_imm = 0;
10700 uint32_t reg_src1 = 0, reg_src2 = 0, reg_dest = 0;
10701 uint32_t offset_12 = 0, tgt_mem_addr = 0;
10702 uint32_t record_buf[8], record_buf_mem[8];
10705 ULONGEST u_regval[2];
10707 if (bit (arm_insn_r->arm_insn, 4))
10708 return arm_record_media (arm_insn_r);
10710 arm_insn_r->opcode = bits (arm_insn_r->arm_insn, 21, 24);
10711 arm_insn_r->decode = bits (arm_insn_r->arm_insn, 4, 7);
10713 /* Handle enhanced store insns and LDRD DSP insn,
10714 order begins according to addressing modes for store insns
10718 if (bit (arm_insn_r->arm_insn, INSN_S_L_BIT_NUM))
10720 reg_dest = bits (arm_insn_r->arm_insn, 12, 15);
10721 /* LDR insn has a capability to do branching, if
10722 MOV LR, PC is precedded by LDR insn having Rn as R15
10723 in that case, it emulates branch and link insn, and hence we
10724 need to save CSPR and PC as well. */
10725 if (15 != reg_dest)
10727 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
10728 arm_insn_r->reg_rec_count = 1;
10732 record_buf[0] = reg_dest;
10733 record_buf[1] = ARM_PS_REGNUM;
10734 arm_insn_r->reg_rec_count = 2;
10739 if (! bits (arm_insn_r->arm_insn, 4, 11))
10741 /* Store insn, register offset and register pre-indexed,
10742 register post-indexed. */
10744 reg_src1 = bits (arm_insn_r->arm_insn, 0, 3);
10746 reg_src2 = bits (arm_insn_r->arm_insn, 16, 19);
10747 regcache_raw_read_unsigned (reg_cache, reg_src1
10749 regcache_raw_read_unsigned (reg_cache, reg_src2
10751 if (15 == reg_src2)
10753 /* If R15 was used as Rn, hence current PC+8. */
10754 /* Pre-indexed mode doesnt reach here ; illegal insn. */
10755 u_regval[0] = u_regval[0] + 8;
10757 /* Calculate target store address, Rn +/- Rm, register offset. */
10759 if (bit (arm_insn_r->arm_insn, 23))
10761 tgt_mem_addr = u_regval[0] + u_regval[1];
10765 tgt_mem_addr = u_regval[1] - u_regval[0];
10768 switch (arm_insn_r->opcode)
10782 record_buf_mem[0] = 4;
10797 record_buf_mem[0] = 1;
10801 gdb_assert_not_reached ("no decoding pattern found");
10804 record_buf_mem[1] = tgt_mem_addr;
10805 arm_insn_r->mem_rec_count = 1;
10807 if (9 == arm_insn_r->opcode || 11 == arm_insn_r->opcode
10808 || 13 == arm_insn_r->opcode || 15 == arm_insn_r->opcode
10809 || 0 == arm_insn_r->opcode || 2 == arm_insn_r->opcode
10810 || 4 == arm_insn_r->opcode || 6 == arm_insn_r->opcode
10811 || 1 == arm_insn_r->opcode || 3 == arm_insn_r->opcode
10812 || 5 == arm_insn_r->opcode || 7 == arm_insn_r->opcode
10815 /* Rn is going to be changed in pre-indexed mode and
10816 post-indexed mode as well. */
10817 record_buf[0] = reg_src2;
10818 arm_insn_r->reg_rec_count = 1;
10823 /* Store insn, scaled register offset; scaled pre-indexed. */
10824 offset_12 = bits (arm_insn_r->arm_insn, 5, 6);
10826 reg_src1 = bits (arm_insn_r->arm_insn, 0, 3);
10828 reg_src2 = bits (arm_insn_r->arm_insn, 16, 19);
10829 /* Get shift_imm. */
10830 shift_imm = bits (arm_insn_r->arm_insn, 7, 11);
10831 regcache_raw_read_unsigned (reg_cache, reg_src1, &u_regval[0]);
10832 regcache_raw_read_signed (reg_cache, reg_src1, &s_word);
10833 regcache_raw_read_unsigned (reg_cache, reg_src2, &u_regval[1]);
10834 /* Offset_12 used as shift. */
10838 /* Offset_12 used as index. */
10839 offset_12 = u_regval[0] << shift_imm;
10843 offset_12 = (!shift_imm)?0:u_regval[0] >> shift_imm;
10849 if (bit (u_regval[0], 31))
10851 offset_12 = 0xFFFFFFFF;
10860 /* This is arithmetic shift. */
10861 offset_12 = s_word >> shift_imm;
10868 regcache_raw_read_unsigned (reg_cache, ARM_PS_REGNUM,
10870 /* Get C flag value and shift it by 31. */
10871 offset_12 = (((bit (u_regval[1], 29)) << 31) \
10872 | (u_regval[0]) >> 1);
10876 offset_12 = (u_regval[0] >> shift_imm) \
10878 (sizeof(uint32_t) - shift_imm));
10883 gdb_assert_not_reached ("no decoding pattern found");
10887 regcache_raw_read_unsigned (reg_cache, reg_src2, &u_regval[1]);
10889 if (bit (arm_insn_r->arm_insn, 23))
10891 tgt_mem_addr = u_regval[1] + offset_12;
10895 tgt_mem_addr = u_regval[1] - offset_12;
10898 switch (arm_insn_r->opcode)
10912 record_buf_mem[0] = 4;
10927 record_buf_mem[0] = 1;
10931 gdb_assert_not_reached ("no decoding pattern found");
10934 record_buf_mem[1] = tgt_mem_addr;
10935 arm_insn_r->mem_rec_count = 1;
10937 if (9 == arm_insn_r->opcode || 11 == arm_insn_r->opcode
10938 || 13 == arm_insn_r->opcode || 15 == arm_insn_r->opcode
10939 || 0 == arm_insn_r->opcode || 2 == arm_insn_r->opcode
10940 || 4 == arm_insn_r->opcode || 6 == arm_insn_r->opcode
10941 || 1 == arm_insn_r->opcode || 3 == arm_insn_r->opcode
10942 || 5 == arm_insn_r->opcode || 7 == arm_insn_r->opcode
10945 /* Rn is going to be changed in register scaled pre-indexed
10946 mode,and scaled post indexed mode. */
10947 record_buf[0] = reg_src2;
10948 arm_insn_r->reg_rec_count = 1;
10953 REG_ALLOC (arm_insn_r->arm_regs, arm_insn_r->reg_rec_count, record_buf);
10954 MEM_ALLOC (arm_insn_r->arm_mems, arm_insn_r->mem_rec_count, record_buf_mem);
10958 /* Handle ARM mode instructions with opcode 100. */
10961 arm_record_ld_st_multiple (insn_decode_record *arm_insn_r)
10963 struct regcache *reg_cache = arm_insn_r->regcache;
10964 uint32_t register_count = 0, register_bits;
10965 uint32_t reg_base, addr_mode;
10966 uint32_t record_buf[24], record_buf_mem[48];
10970 /* Fetch the list of registers. */
10971 register_bits = bits (arm_insn_r->arm_insn, 0, 15);
10972 arm_insn_r->reg_rec_count = 0;
10974 /* Fetch the base register that contains the address we are loading data
10976 reg_base = bits (arm_insn_r->arm_insn, 16, 19);
10978 /* Calculate wback. */
10979 wback = (bit (arm_insn_r->arm_insn, 21) == 1);
10981 if (bit (arm_insn_r->arm_insn, INSN_S_L_BIT_NUM))
10983 /* LDM/LDMIA/LDMFD, LDMDA/LDMFA, LDMDB and LDMIB. */
10985 /* Find out which registers are going to be loaded from memory. */
10986 while (register_bits)
10988 if (register_bits & 0x00000001)
10989 record_buf[arm_insn_r->reg_rec_count++] = register_count;
10990 register_bits = register_bits >> 1;
10995 /* If wback is true, also save the base register, which is going to be
10998 record_buf[arm_insn_r->reg_rec_count++] = reg_base;
11000 /* Save the CPSR register. */
11001 record_buf[arm_insn_r->reg_rec_count++] = ARM_PS_REGNUM;
11005 /* STM (STMIA, STMEA), STMDA (STMED), STMDB (STMFD) and STMIB (STMFA). */
11007 addr_mode = bits (arm_insn_r->arm_insn, 23, 24);
11009 regcache_raw_read_unsigned (reg_cache, reg_base, &u_regval);
11011 /* Find out how many registers are going to be stored to memory. */
11012 while (register_bits)
11014 if (register_bits & 0x00000001)
11016 register_bits = register_bits >> 1;
11021 /* STMDA (STMED): Decrement after. */
11023 record_buf_mem[1] = (uint32_t) u_regval
11024 - register_count * INT_REGISTER_SIZE + 4;
11026 /* STM (STMIA, STMEA): Increment after. */
11028 record_buf_mem[1] = (uint32_t) u_regval;
11030 /* STMDB (STMFD): Decrement before. */
11032 record_buf_mem[1] = (uint32_t) u_regval
11033 - register_count * INT_REGISTER_SIZE;
11035 /* STMIB (STMFA): Increment before. */
11037 record_buf_mem[1] = (uint32_t) u_regval + INT_REGISTER_SIZE;
11040 gdb_assert_not_reached ("no decoding pattern found");
11044 record_buf_mem[0] = register_count * INT_REGISTER_SIZE;
11045 arm_insn_r->mem_rec_count = 1;
11047 /* If wback is true, also save the base register, which is going to be
11050 record_buf[arm_insn_r->reg_rec_count++] = reg_base;
11053 REG_ALLOC (arm_insn_r->arm_regs, arm_insn_r->reg_rec_count, record_buf);
11054 MEM_ALLOC (arm_insn_r->arm_mems, arm_insn_r->mem_rec_count, record_buf_mem);
11058 /* Handling opcode 101 insns. */
11061 arm_record_b_bl (insn_decode_record *arm_insn_r)
11063 uint32_t record_buf[8];
11065 /* Handle B, BL, BLX(1) insns. */
11066 /* B simply branches so we do nothing here. */
11067 /* Note: BLX(1) doesnt fall here but instead it falls into
11068 extension space. */
11069 if (bit (arm_insn_r->arm_insn, 24))
11071 record_buf[0] = ARM_LR_REGNUM;
11072 arm_insn_r->reg_rec_count = 1;
11075 REG_ALLOC (arm_insn_r->arm_regs, arm_insn_r->reg_rec_count, record_buf);
11081 arm_record_unsupported_insn (insn_decode_record *arm_insn_r)
11083 printf_unfiltered (_("Process record does not support instruction "
11084 "0x%0x at address %s.\n"),arm_insn_r->arm_insn,
11085 paddress (arm_insn_r->gdbarch, arm_insn_r->this_addr));
11090 /* Record handler for vector data transfer instructions. */
11093 arm_record_vdata_transfer_insn (insn_decode_record *arm_insn_r)
11095 uint32_t bits_a, bit_c, bit_l, reg_t, reg_v;
11096 uint32_t record_buf[4];
11098 reg_t = bits (arm_insn_r->arm_insn, 12, 15);
11099 reg_v = bits (arm_insn_r->arm_insn, 21, 23);
11100 bits_a = bits (arm_insn_r->arm_insn, 21, 23);
11101 bit_l = bit (arm_insn_r->arm_insn, 20);
11102 bit_c = bit (arm_insn_r->arm_insn, 8);
11104 /* Handle VMOV instruction. */
11105 if (bit_l && bit_c)
11107 record_buf[0] = reg_t;
11108 arm_insn_r->reg_rec_count = 1;
11110 else if (bit_l && !bit_c)
11112 /* Handle VMOV instruction. */
11113 if (bits_a == 0x00)
11115 record_buf[0] = reg_t;
11116 arm_insn_r->reg_rec_count = 1;
11118 /* Handle VMRS instruction. */
11119 else if (bits_a == 0x07)
11122 reg_t = ARM_PS_REGNUM;
11124 record_buf[0] = reg_t;
11125 arm_insn_r->reg_rec_count = 1;
11128 else if (!bit_l && !bit_c)
11130 /* Handle VMOV instruction. */
11131 if (bits_a == 0x00)
11133 record_buf[0] = ARM_D0_REGNUM + reg_v;
11135 arm_insn_r->reg_rec_count = 1;
11137 /* Handle VMSR instruction. */
11138 else if (bits_a == 0x07)
11140 record_buf[0] = ARM_FPSCR_REGNUM;
11141 arm_insn_r->reg_rec_count = 1;
11144 else if (!bit_l && bit_c)
11146 /* Handle VMOV instruction. */
11147 if (!(bits_a & 0x04))
11149 record_buf[0] = (reg_v | (bit (arm_insn_r->arm_insn, 7) << 4))
11151 arm_insn_r->reg_rec_count = 1;
11153 /* Handle VDUP instruction. */
11156 if (bit (arm_insn_r->arm_insn, 21))
11158 reg_v = reg_v | (bit (arm_insn_r->arm_insn, 7) << 4);
11159 record_buf[0] = reg_v + ARM_D0_REGNUM;
11160 record_buf[1] = reg_v + ARM_D0_REGNUM + 1;
11161 arm_insn_r->reg_rec_count = 2;
11165 reg_v = reg_v | (bit (arm_insn_r->arm_insn, 7) << 4);
11166 record_buf[0] = reg_v + ARM_D0_REGNUM;
11167 arm_insn_r->reg_rec_count = 1;
11172 REG_ALLOC (arm_insn_r->arm_regs, arm_insn_r->reg_rec_count, record_buf);
11176 /* Record handler for extension register load/store instructions. */
11179 arm_record_exreg_ld_st_insn (insn_decode_record *arm_insn_r)
11181 uint32_t opcode, single_reg;
11182 uint8_t op_vldm_vstm;
11183 uint32_t record_buf[8], record_buf_mem[128];
11184 ULONGEST u_regval = 0;
11186 struct regcache *reg_cache = arm_insn_r->regcache;
11188 opcode = bits (arm_insn_r->arm_insn, 20, 24);
11189 single_reg = !bit (arm_insn_r->arm_insn, 8);
11190 op_vldm_vstm = opcode & 0x1b;
11192 /* Handle VMOV instructions. */
11193 if ((opcode & 0x1e) == 0x04)
11195 if (bit (arm_insn_r->arm_insn, 20)) /* to_arm_registers bit 20? */
11197 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
11198 record_buf[1] = bits (arm_insn_r->arm_insn, 16, 19);
11199 arm_insn_r->reg_rec_count = 2;
11203 uint8_t reg_m = bits (arm_insn_r->arm_insn, 0, 3);
11204 uint8_t bit_m = bit (arm_insn_r->arm_insn, 5);
11208 /* The first S register number m is REG_M:M (M is bit 5),
11209 the corresponding D register number is REG_M:M / 2, which
11211 record_buf[arm_insn_r->reg_rec_count++] = ARM_D0_REGNUM + reg_m;
11212 /* The second S register number is REG_M:M + 1, the
11213 corresponding D register number is (REG_M:M + 1) / 2.
11214 IOW, if bit M is 1, the first and second S registers
11215 are mapped to different D registers, otherwise, they are
11216 in the same D register. */
11219 record_buf[arm_insn_r->reg_rec_count++]
11220 = ARM_D0_REGNUM + reg_m + 1;
11225 record_buf[0] = ((bit_m << 4) + reg_m + ARM_D0_REGNUM);
11226 arm_insn_r->reg_rec_count = 1;
11230 /* Handle VSTM and VPUSH instructions. */
11231 else if (op_vldm_vstm == 0x08 || op_vldm_vstm == 0x0a
11232 || op_vldm_vstm == 0x12)
11234 uint32_t start_address, reg_rn, imm_off32, imm_off8, memory_count;
11235 uint32_t memory_index = 0;
11237 reg_rn = bits (arm_insn_r->arm_insn, 16, 19);
11238 regcache_raw_read_unsigned (reg_cache, reg_rn, &u_regval);
11239 imm_off8 = bits (arm_insn_r->arm_insn, 0, 7);
11240 imm_off32 = imm_off8 << 2;
11241 memory_count = imm_off8;
11243 if (bit (arm_insn_r->arm_insn, 23))
11244 start_address = u_regval;
11246 start_address = u_regval - imm_off32;
11248 if (bit (arm_insn_r->arm_insn, 21))
11250 record_buf[0] = reg_rn;
11251 arm_insn_r->reg_rec_count = 1;
11254 while (memory_count > 0)
11258 record_buf_mem[memory_index] = 4;
11259 record_buf_mem[memory_index + 1] = start_address;
11260 start_address = start_address + 4;
11261 memory_index = memory_index + 2;
11265 record_buf_mem[memory_index] = 4;
11266 record_buf_mem[memory_index + 1] = start_address;
11267 record_buf_mem[memory_index + 2] = 4;
11268 record_buf_mem[memory_index + 3] = start_address + 4;
11269 start_address = start_address + 8;
11270 memory_index = memory_index + 4;
11274 arm_insn_r->mem_rec_count = (memory_index >> 1);
11276 /* Handle VLDM instructions. */
11277 else if (op_vldm_vstm == 0x09 || op_vldm_vstm == 0x0b
11278 || op_vldm_vstm == 0x13)
11280 uint32_t reg_count, reg_vd;
11281 uint32_t reg_index = 0;
11282 uint32_t bit_d = bit (arm_insn_r->arm_insn, 22);
11284 reg_vd = bits (arm_insn_r->arm_insn, 12, 15);
11285 reg_count = bits (arm_insn_r->arm_insn, 0, 7);
11287 /* REG_VD is the first D register number. If the instruction
11288 loads memory to S registers (SINGLE_REG is TRUE), the register
11289 number is (REG_VD << 1 | bit D), so the corresponding D
11290 register number is (REG_VD << 1 | bit D) / 2 = REG_VD. */
11292 reg_vd = reg_vd | (bit_d << 4);
11294 if (bit (arm_insn_r->arm_insn, 21) /* write back */)
11295 record_buf[reg_index++] = bits (arm_insn_r->arm_insn, 16, 19);
11297 /* If the instruction loads memory to D register, REG_COUNT should
11298 be divided by 2, according to the ARM Architecture Reference
11299 Manual. If the instruction loads memory to S register, divide by
11300 2 as well because two S registers are mapped to D register. */
11301 reg_count = reg_count / 2;
11302 if (single_reg && bit_d)
11304 /* Increase the register count if S register list starts from
11305 an odd number (bit d is one). */
11309 while (reg_count > 0)
11311 record_buf[reg_index++] = ARM_D0_REGNUM + reg_vd + reg_count - 1;
11314 arm_insn_r->reg_rec_count = reg_index;
11316 /* VSTR Vector store register. */
11317 else if ((opcode & 0x13) == 0x10)
11319 uint32_t start_address, reg_rn, imm_off32, imm_off8;
11320 uint32_t memory_index = 0;
11322 reg_rn = bits (arm_insn_r->arm_insn, 16, 19);
11323 regcache_raw_read_unsigned (reg_cache, reg_rn, &u_regval);
11324 imm_off8 = bits (arm_insn_r->arm_insn, 0, 7);
11325 imm_off32 = imm_off8 << 2;
11327 if (bit (arm_insn_r->arm_insn, 23))
11328 start_address = u_regval + imm_off32;
11330 start_address = u_regval - imm_off32;
11334 record_buf_mem[memory_index] = 4;
11335 record_buf_mem[memory_index + 1] = start_address;
11336 arm_insn_r->mem_rec_count = 1;
11340 record_buf_mem[memory_index] = 4;
11341 record_buf_mem[memory_index + 1] = start_address;
11342 record_buf_mem[memory_index + 2] = 4;
11343 record_buf_mem[memory_index + 3] = start_address + 4;
11344 arm_insn_r->mem_rec_count = 2;
11347 /* VLDR Vector load register. */
11348 else if ((opcode & 0x13) == 0x11)
11350 uint32_t reg_vd = bits (arm_insn_r->arm_insn, 12, 15);
11354 reg_vd = reg_vd | (bit (arm_insn_r->arm_insn, 22) << 4);
11355 record_buf[0] = ARM_D0_REGNUM + reg_vd;
11359 reg_vd = (reg_vd << 1) | bit (arm_insn_r->arm_insn, 22);
11360 /* Record register D rather than pseudo register S. */
11361 record_buf[0] = ARM_D0_REGNUM + reg_vd / 2;
11363 arm_insn_r->reg_rec_count = 1;
11366 REG_ALLOC (arm_insn_r->arm_regs, arm_insn_r->reg_rec_count, record_buf);
11367 MEM_ALLOC (arm_insn_r->arm_mems, arm_insn_r->mem_rec_count, record_buf_mem);
11371 /* Record handler for arm/thumb mode VFP data processing instructions. */
11374 arm_record_vfp_data_proc_insn (insn_decode_record *arm_insn_r)
11376 uint32_t opc1, opc2, opc3, dp_op_sz, bit_d, reg_vd;
11377 uint32_t record_buf[4];
11378 enum insn_types {INSN_T0, INSN_T1, INSN_T2, INSN_T3, INSN_INV};
11379 enum insn_types curr_insn_type = INSN_INV;
11381 reg_vd = bits (arm_insn_r->arm_insn, 12, 15);
11382 opc1 = bits (arm_insn_r->arm_insn, 20, 23);
11383 opc2 = bits (arm_insn_r->arm_insn, 16, 19);
11384 opc3 = bits (arm_insn_r->arm_insn, 6, 7);
11385 dp_op_sz = bit (arm_insn_r->arm_insn, 8);
11386 bit_d = bit (arm_insn_r->arm_insn, 22);
11387 /* Mask off the "D" bit. */
11388 opc1 = opc1 & ~0x04;
11390 /* Handle VMLA, VMLS. */
11393 if (bit (arm_insn_r->arm_insn, 10))
11395 if (bit (arm_insn_r->arm_insn, 6))
11396 curr_insn_type = INSN_T0;
11398 curr_insn_type = INSN_T1;
11403 curr_insn_type = INSN_T1;
11405 curr_insn_type = INSN_T2;
11408 /* Handle VNMLA, VNMLS, VNMUL. */
11409 else if (opc1 == 0x01)
11412 curr_insn_type = INSN_T1;
11414 curr_insn_type = INSN_T2;
11417 else if (opc1 == 0x02 && !(opc3 & 0x01))
11419 if (bit (arm_insn_r->arm_insn, 10))
11421 if (bit (arm_insn_r->arm_insn, 6))
11422 curr_insn_type = INSN_T0;
11424 curr_insn_type = INSN_T1;
11429 curr_insn_type = INSN_T1;
11431 curr_insn_type = INSN_T2;
11434 /* Handle VADD, VSUB. */
11435 else if (opc1 == 0x03)
11437 if (!bit (arm_insn_r->arm_insn, 9))
11439 if (bit (arm_insn_r->arm_insn, 6))
11440 curr_insn_type = INSN_T0;
11442 curr_insn_type = INSN_T1;
11447 curr_insn_type = INSN_T1;
11449 curr_insn_type = INSN_T2;
11453 else if (opc1 == 0x08)
11456 curr_insn_type = INSN_T1;
11458 curr_insn_type = INSN_T2;
11460 /* Handle all other vfp data processing instructions. */
11461 else if (opc1 == 0x0b)
11464 if (!(opc3 & 0x01) || (opc2 == 0x00 && opc3 == 0x01))
11466 if (bit (arm_insn_r->arm_insn, 4))
11468 if (bit (arm_insn_r->arm_insn, 6))
11469 curr_insn_type = INSN_T0;
11471 curr_insn_type = INSN_T1;
11476 curr_insn_type = INSN_T1;
11478 curr_insn_type = INSN_T2;
11481 /* Handle VNEG and VABS. */
11482 else if ((opc2 == 0x01 && opc3 == 0x01)
11483 || (opc2 == 0x00 && opc3 == 0x03))
11485 if (!bit (arm_insn_r->arm_insn, 11))
11487 if (bit (arm_insn_r->arm_insn, 6))
11488 curr_insn_type = INSN_T0;
11490 curr_insn_type = INSN_T1;
11495 curr_insn_type = INSN_T1;
11497 curr_insn_type = INSN_T2;
11500 /* Handle VSQRT. */
11501 else if (opc2 == 0x01 && opc3 == 0x03)
11504 curr_insn_type = INSN_T1;
11506 curr_insn_type = INSN_T2;
11509 else if (opc2 == 0x07 && opc3 == 0x03)
11512 curr_insn_type = INSN_T1;
11514 curr_insn_type = INSN_T2;
11516 else if (opc3 & 0x01)
11519 if ((opc2 == 0x08) || (opc2 & 0x0e) == 0x0c)
11521 if (!bit (arm_insn_r->arm_insn, 18))
11522 curr_insn_type = INSN_T2;
11526 curr_insn_type = INSN_T1;
11528 curr_insn_type = INSN_T2;
11532 else if ((opc2 & 0x0e) == 0x0a || (opc2 & 0x0e) == 0x0e)
11535 curr_insn_type = INSN_T1;
11537 curr_insn_type = INSN_T2;
11539 /* Handle VCVTB, VCVTT. */
11540 else if ((opc2 & 0x0e) == 0x02)
11541 curr_insn_type = INSN_T2;
11542 /* Handle VCMP, VCMPE. */
11543 else if ((opc2 & 0x0e) == 0x04)
11544 curr_insn_type = INSN_T3;
11548 switch (curr_insn_type)
11551 reg_vd = reg_vd | (bit_d << 4);
11552 record_buf[0] = reg_vd + ARM_D0_REGNUM;
11553 record_buf[1] = reg_vd + ARM_D0_REGNUM + 1;
11554 arm_insn_r->reg_rec_count = 2;
11558 reg_vd = reg_vd | (bit_d << 4);
11559 record_buf[0] = reg_vd + ARM_D0_REGNUM;
11560 arm_insn_r->reg_rec_count = 1;
11564 reg_vd = (reg_vd << 1) | bit_d;
11565 record_buf[0] = reg_vd + ARM_D0_REGNUM;
11566 arm_insn_r->reg_rec_count = 1;
11570 record_buf[0] = ARM_FPSCR_REGNUM;
11571 arm_insn_r->reg_rec_count = 1;
11575 gdb_assert_not_reached ("no decoding pattern found");
11579 REG_ALLOC (arm_insn_r->arm_regs, arm_insn_r->reg_rec_count, record_buf);
11583 /* Handling opcode 110 insns. */
11586 arm_record_asimd_vfp_coproc (insn_decode_record *arm_insn_r)
11588 uint32_t op1, op1_ebit, coproc;
11590 coproc = bits (arm_insn_r->arm_insn, 8, 11);
11591 op1 = bits (arm_insn_r->arm_insn, 20, 25);
11592 op1_ebit = bit (arm_insn_r->arm_insn, 20);
11594 if ((coproc & 0x0e) == 0x0a)
11596 /* Handle extension register ld/st instructions. */
11598 return arm_record_exreg_ld_st_insn (arm_insn_r);
11600 /* 64-bit transfers between arm core and extension registers. */
11601 if ((op1 & 0x3e) == 0x04)
11602 return arm_record_exreg_ld_st_insn (arm_insn_r);
11606 /* Handle coprocessor ld/st instructions. */
11611 return arm_record_unsupported_insn (arm_insn_r);
11614 return arm_record_unsupported_insn (arm_insn_r);
11617 /* Move to coprocessor from two arm core registers. */
11619 return arm_record_unsupported_insn (arm_insn_r);
11621 /* Move to two arm core registers from coprocessor. */
11626 reg_t[0] = bits (arm_insn_r->arm_insn, 12, 15);
11627 reg_t[1] = bits (arm_insn_r->arm_insn, 16, 19);
11628 arm_insn_r->reg_rec_count = 2;
11630 REG_ALLOC (arm_insn_r->arm_regs, arm_insn_r->reg_rec_count, reg_t);
11634 return arm_record_unsupported_insn (arm_insn_r);
11637 /* Handling opcode 111 insns. */
11640 arm_record_coproc_data_proc (insn_decode_record *arm_insn_r)
11642 uint32_t op, op1_ebit, coproc, bits_24_25;
11643 struct gdbarch_tdep *tdep = gdbarch_tdep (arm_insn_r->gdbarch);
11644 struct regcache *reg_cache = arm_insn_r->regcache;
11646 arm_insn_r->opcode = bits (arm_insn_r->arm_insn, 24, 27);
11647 coproc = bits (arm_insn_r->arm_insn, 8, 11);
11648 op1_ebit = bit (arm_insn_r->arm_insn, 20);
11649 op = bit (arm_insn_r->arm_insn, 4);
11650 bits_24_25 = bits (arm_insn_r->arm_insn, 24, 25);
11652 /* Handle arm SWI/SVC system call instructions. */
11653 if (bits_24_25 == 0x3)
11655 if (tdep->arm_syscall_record != NULL)
11657 ULONGEST svc_operand, svc_number;
11659 svc_operand = (0x00ffffff & arm_insn_r->arm_insn);
11661 if (svc_operand) /* OABI. */
11662 svc_number = svc_operand - 0x900000;
11664 regcache_raw_read_unsigned (reg_cache, 7, &svc_number);
11666 return tdep->arm_syscall_record (reg_cache, svc_number);
11670 printf_unfiltered (_("no syscall record support\n"));
11674 else if (bits_24_25 == 0x02)
11678 if ((coproc & 0x0e) == 0x0a)
11680 /* 8, 16, and 32-bit transfer */
11681 return arm_record_vdata_transfer_insn (arm_insn_r);
11688 uint32_t record_buf[1];
11690 record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15);
11691 if (record_buf[0] == 15)
11692 record_buf[0] = ARM_PS_REGNUM;
11694 arm_insn_r->reg_rec_count = 1;
11695 REG_ALLOC (arm_insn_r->arm_regs, arm_insn_r->reg_rec_count,
11708 if ((coproc & 0x0e) == 0x0a)
11710 /* VFP data-processing instructions. */
11711 return arm_record_vfp_data_proc_insn (arm_insn_r);
11722 unsigned int op1 = bits (arm_insn_r->arm_insn, 20, 25);
11726 if ((coproc & 0x0e) != 0x0a)
11732 else if (op1 == 4 || op1 == 5)
11734 if ((coproc & 0x0e) == 0x0a)
11736 /* 64-bit transfers between ARM core and extension */
11745 else if (op1 == 0 || op1 == 1)
11752 if ((coproc & 0x0e) == 0x0a)
11754 /* Extension register load/store */
11758 /* STC, STC2, LDC, LDC2 */
11767 /* Handling opcode 000 insns. */
11770 thumb_record_shift_add_sub (insn_decode_record *thumb_insn_r)
11772 uint32_t record_buf[8];
11773 uint32_t reg_src1 = 0;
11775 reg_src1 = bits (thumb_insn_r->arm_insn, 0, 2);
11777 record_buf[0] = ARM_PS_REGNUM;
11778 record_buf[1] = reg_src1;
11779 thumb_insn_r->reg_rec_count = 2;
11781 REG_ALLOC (thumb_insn_r->arm_regs, thumb_insn_r->reg_rec_count, record_buf);
11787 /* Handling opcode 001 insns. */
11790 thumb_record_add_sub_cmp_mov (insn_decode_record *thumb_insn_r)
11792 uint32_t record_buf[8];
11793 uint32_t reg_src1 = 0;
11795 reg_src1 = bits (thumb_insn_r->arm_insn, 8, 10);
11797 record_buf[0] = ARM_PS_REGNUM;
11798 record_buf[1] = reg_src1;
11799 thumb_insn_r->reg_rec_count = 2;
11801 REG_ALLOC (thumb_insn_r->arm_regs, thumb_insn_r->reg_rec_count, record_buf);
11806 /* Handling opcode 010 insns. */
11809 thumb_record_ld_st_reg_offset (insn_decode_record *thumb_insn_r)
11811 struct regcache *reg_cache = thumb_insn_r->regcache;
11812 uint32_t record_buf[8], record_buf_mem[8];
11814 uint32_t reg_src1 = 0, reg_src2 = 0;
11815 uint32_t opcode1 = 0, opcode2 = 0, opcode3 = 0;
11817 ULONGEST u_regval[2] = {0};
11819 opcode1 = bits (thumb_insn_r->arm_insn, 10, 12);
11821 if (bit (thumb_insn_r->arm_insn, 12))
11823 /* Handle load/store register offset. */
11824 uint32_t opB = bits (thumb_insn_r->arm_insn, 9, 11);
11826 if (in_inclusive_range (opB, 4U, 7U))
11828 /* LDR(2), LDRB(2) , LDRH(2), LDRSB, LDRSH. */
11829 reg_src1 = bits (thumb_insn_r->arm_insn,0, 2);
11830 record_buf[0] = reg_src1;
11831 thumb_insn_r->reg_rec_count = 1;
11833 else if (in_inclusive_range (opB, 0U, 2U))
11835 /* STR(2), STRB(2), STRH(2) . */
11836 reg_src1 = bits (thumb_insn_r->arm_insn, 3, 5);
11837 reg_src2 = bits (thumb_insn_r->arm_insn, 6, 8);
11838 regcache_raw_read_unsigned (reg_cache, reg_src1, &u_regval[0]);
11839 regcache_raw_read_unsigned (reg_cache, reg_src2, &u_regval[1]);
11841 record_buf_mem[0] = 4; /* STR (2). */
11843 record_buf_mem[0] = 1; /* STRB (2). */
11845 record_buf_mem[0] = 2; /* STRH (2). */
11846 record_buf_mem[1] = u_regval[0] + u_regval[1];
11847 thumb_insn_r->mem_rec_count = 1;
11850 else if (bit (thumb_insn_r->arm_insn, 11))
11852 /* Handle load from literal pool. */
11854 reg_src1 = bits (thumb_insn_r->arm_insn, 8, 10);
11855 record_buf[0] = reg_src1;
11856 thumb_insn_r->reg_rec_count = 1;
11860 /* Special data instructions and branch and exchange */
11861 opcode2 = bits (thumb_insn_r->arm_insn, 8, 9);
11862 opcode3 = bits (thumb_insn_r->arm_insn, 0, 2);
11863 if ((3 == opcode2) && (!opcode3))
11865 /* Branch with exchange. */
11866 record_buf[0] = ARM_PS_REGNUM;
11867 thumb_insn_r->reg_rec_count = 1;
11871 /* Format 8; special data processing insns. */
11872 record_buf[0] = ARM_PS_REGNUM;
11873 record_buf[1] = (bit (thumb_insn_r->arm_insn, 7) << 3
11874 | bits (thumb_insn_r->arm_insn, 0, 2));
11875 thumb_insn_r->reg_rec_count = 2;
11880 /* Format 5; data processing insns. */
11881 reg_src1 = bits (thumb_insn_r->arm_insn, 0, 2);
11882 if (bit (thumb_insn_r->arm_insn, 7))
11884 reg_src1 = reg_src1 + 8;
11886 record_buf[0] = ARM_PS_REGNUM;
11887 record_buf[1] = reg_src1;
11888 thumb_insn_r->reg_rec_count = 2;
11891 REG_ALLOC (thumb_insn_r->arm_regs, thumb_insn_r->reg_rec_count, record_buf);
11892 MEM_ALLOC (thumb_insn_r->arm_mems, thumb_insn_r->mem_rec_count,
11898 /* Handling opcode 001 insns. */
11901 thumb_record_ld_st_imm_offset (insn_decode_record *thumb_insn_r)
11903 struct regcache *reg_cache = thumb_insn_r->regcache;
11904 uint32_t record_buf[8], record_buf_mem[8];
11906 uint32_t reg_src1 = 0;
11907 uint32_t opcode = 0, immed_5 = 0;
11909 ULONGEST u_regval = 0;
11911 opcode = bits (thumb_insn_r->arm_insn, 11, 12);
11916 reg_src1 = bits (thumb_insn_r->arm_insn, 0, 2);
11917 record_buf[0] = reg_src1;
11918 thumb_insn_r->reg_rec_count = 1;
11923 reg_src1 = bits (thumb_insn_r->arm_insn, 3, 5);
11924 immed_5 = bits (thumb_insn_r->arm_insn, 6, 10);
11925 regcache_raw_read_unsigned (reg_cache, reg_src1, &u_regval);
11926 record_buf_mem[0] = 4;
11927 record_buf_mem[1] = u_regval + (immed_5 * 4);
11928 thumb_insn_r->mem_rec_count = 1;
11931 REG_ALLOC (thumb_insn_r->arm_regs, thumb_insn_r->reg_rec_count, record_buf);
11932 MEM_ALLOC (thumb_insn_r->arm_mems, thumb_insn_r->mem_rec_count,
11938 /* Handling opcode 100 insns. */
11941 thumb_record_ld_st_stack (insn_decode_record *thumb_insn_r)
11943 struct regcache *reg_cache = thumb_insn_r->regcache;
11944 uint32_t record_buf[8], record_buf_mem[8];
11946 uint32_t reg_src1 = 0;
11947 uint32_t opcode = 0, immed_8 = 0, immed_5 = 0;
11949 ULONGEST u_regval = 0;
11951 opcode = bits (thumb_insn_r->arm_insn, 11, 12);
11956 reg_src1 = bits (thumb_insn_r->arm_insn, 8, 10);
11957 record_buf[0] = reg_src1;
11958 thumb_insn_r->reg_rec_count = 1;
11960 else if (1 == opcode)
11963 reg_src1 = bits (thumb_insn_r->arm_insn, 0, 2);
11964 record_buf[0] = reg_src1;
11965 thumb_insn_r->reg_rec_count = 1;
11967 else if (2 == opcode)
11970 immed_8 = bits (thumb_insn_r->arm_insn, 0, 7);
11971 regcache_raw_read_unsigned (reg_cache, ARM_SP_REGNUM, &u_regval);
11972 record_buf_mem[0] = 4;
11973 record_buf_mem[1] = u_regval + (immed_8 * 4);
11974 thumb_insn_r->mem_rec_count = 1;
11976 else if (0 == opcode)
11979 immed_5 = bits (thumb_insn_r->arm_insn, 6, 10);
11980 reg_src1 = bits (thumb_insn_r->arm_insn, 3, 5);
11981 regcache_raw_read_unsigned (reg_cache, reg_src1, &u_regval);
11982 record_buf_mem[0] = 2;
11983 record_buf_mem[1] = u_regval + (immed_5 * 2);
11984 thumb_insn_r->mem_rec_count = 1;
11987 REG_ALLOC (thumb_insn_r->arm_regs, thumb_insn_r->reg_rec_count, record_buf);
11988 MEM_ALLOC (thumb_insn_r->arm_mems, thumb_insn_r->mem_rec_count,
11994 /* Handling opcode 101 insns. */
11997 thumb_record_misc (insn_decode_record *thumb_insn_r)
11999 struct regcache *reg_cache = thumb_insn_r->regcache;
12001 uint32_t opcode = 0;
12002 uint32_t register_bits = 0, register_count = 0;
12003 uint32_t index = 0, start_address = 0;
12004 uint32_t record_buf[24], record_buf_mem[48];
12007 ULONGEST u_regval = 0;
12009 opcode = bits (thumb_insn_r->arm_insn, 11, 12);
12011 if (opcode == 0 || opcode == 1)
12013 /* ADR and ADD (SP plus immediate) */
12015 reg_src1 = bits (thumb_insn_r->arm_insn, 8, 10);
12016 record_buf[0] = reg_src1;
12017 thumb_insn_r->reg_rec_count = 1;
12021 /* Miscellaneous 16-bit instructions */
12022 uint32_t opcode2 = bits (thumb_insn_r->arm_insn, 8, 11);
12027 /* SETEND and CPS */
12030 /* ADD/SUB (SP plus immediate) */
12031 reg_src1 = bits (thumb_insn_r->arm_insn, 8, 10);
12032 record_buf[0] = ARM_SP_REGNUM;
12033 thumb_insn_r->reg_rec_count = 1;
12035 case 1: /* fall through */
12036 case 3: /* fall through */
12037 case 9: /* fall through */
12042 /* SXTH, SXTB, UXTH, UXTB */
12043 record_buf[0] = bits (thumb_insn_r->arm_insn, 0, 2);
12044 thumb_insn_r->reg_rec_count = 1;
12046 case 4: /* fall through */
12049 register_bits = bits (thumb_insn_r->arm_insn, 0, 7);
12050 regcache_raw_read_unsigned (reg_cache, ARM_SP_REGNUM, &u_regval);
12051 while (register_bits)
12053 if (register_bits & 0x00000001)
12055 register_bits = register_bits >> 1;
12057 start_address = u_regval - \
12058 (4 * (bit (thumb_insn_r->arm_insn, 8) + register_count));
12059 thumb_insn_r->mem_rec_count = register_count;
12060 while (register_count)
12062 record_buf_mem[(register_count * 2) - 1] = start_address;
12063 record_buf_mem[(register_count * 2) - 2] = 4;
12064 start_address = start_address + 4;
12067 record_buf[0] = ARM_SP_REGNUM;
12068 thumb_insn_r->reg_rec_count = 1;
12071 /* REV, REV16, REVSH */
12072 record_buf[0] = bits (thumb_insn_r->arm_insn, 0, 2);
12073 thumb_insn_r->reg_rec_count = 1;
12075 case 12: /* fall through */
12078 register_bits = bits (thumb_insn_r->arm_insn, 0, 7);
12079 while (register_bits)
12081 if (register_bits & 0x00000001)
12082 record_buf[index++] = register_count;
12083 register_bits = register_bits >> 1;
12086 record_buf[index++] = ARM_PS_REGNUM;
12087 record_buf[index++] = ARM_SP_REGNUM;
12088 thumb_insn_r->reg_rec_count = index;
12092 /* Handle enhanced software breakpoint insn, BKPT. */
12093 /* CPSR is changed to be executed in ARM state, disabling normal
12094 interrupts, entering abort mode. */
12095 /* According to high vector configuration PC is set. */
12096 /* User hits breakpoint and type reverse, in that case, we need to go back with
12097 previous CPSR and Program Counter. */
12098 record_buf[0] = ARM_PS_REGNUM;
12099 record_buf[1] = ARM_LR_REGNUM;
12100 thumb_insn_r->reg_rec_count = 2;
12101 /* We need to save SPSR value, which is not yet done. */
12102 printf_unfiltered (_("Process record does not support instruction "
12103 "0x%0x at address %s.\n"),
12104 thumb_insn_r->arm_insn,
12105 paddress (thumb_insn_r->gdbarch,
12106 thumb_insn_r->this_addr));
12110 /* If-Then, and hints */
12117 REG_ALLOC (thumb_insn_r->arm_regs, thumb_insn_r->reg_rec_count, record_buf);
12118 MEM_ALLOC (thumb_insn_r->arm_mems, thumb_insn_r->mem_rec_count,
12124 /* Handling opcode 110 insns. */
12127 thumb_record_ldm_stm_swi (insn_decode_record *thumb_insn_r)
12129 struct gdbarch_tdep *tdep = gdbarch_tdep (thumb_insn_r->gdbarch);
12130 struct regcache *reg_cache = thumb_insn_r->regcache;
12132 uint32_t ret = 0; /* function return value: -1:record failure ; 0:success */
12133 uint32_t reg_src1 = 0;
12134 uint32_t opcode1 = 0, opcode2 = 0, register_bits = 0, register_count = 0;
12135 uint32_t index = 0, start_address = 0;
12136 uint32_t record_buf[24], record_buf_mem[48];
12138 ULONGEST u_regval = 0;
12140 opcode1 = bits (thumb_insn_r->arm_insn, 8, 12);
12141 opcode2 = bits (thumb_insn_r->arm_insn, 11, 12);
12147 register_bits = bits (thumb_insn_r->arm_insn, 0, 7);
12149 reg_src1 = bits (thumb_insn_r->arm_insn, 8, 10);
12150 while (register_bits)
12152 if (register_bits & 0x00000001)
12153 record_buf[index++] = register_count;
12154 register_bits = register_bits >> 1;
12157 record_buf[index++] = reg_src1;
12158 thumb_insn_r->reg_rec_count = index;
12160 else if (0 == opcode2)
12162 /* It handles both STMIA. */
12163 register_bits = bits (thumb_insn_r->arm_insn, 0, 7);
12165 reg_src1 = bits (thumb_insn_r->arm_insn, 8, 10);
12166 regcache_raw_read_unsigned (reg_cache, reg_src1, &u_regval);
12167 while (register_bits)
12169 if (register_bits & 0x00000001)
12171 register_bits = register_bits >> 1;
12173 start_address = u_regval;
12174 thumb_insn_r->mem_rec_count = register_count;
12175 while (register_count)
12177 record_buf_mem[(register_count * 2) - 1] = start_address;
12178 record_buf_mem[(register_count * 2) - 2] = 4;
12179 start_address = start_address + 4;
12183 else if (0x1F == opcode1)
12185 /* Handle arm syscall insn. */
12186 if (tdep->arm_syscall_record != NULL)
12188 regcache_raw_read_unsigned (reg_cache, 7, &u_regval);
12189 ret = tdep->arm_syscall_record (reg_cache, u_regval);
12193 printf_unfiltered (_("no syscall record support\n"));
12198 /* B (1), conditional branch is automatically taken care in process_record,
12199 as PC is saved there. */
12201 REG_ALLOC (thumb_insn_r->arm_regs, thumb_insn_r->reg_rec_count, record_buf);
12202 MEM_ALLOC (thumb_insn_r->arm_mems, thumb_insn_r->mem_rec_count,
12208 /* Handling opcode 111 insns. */
12211 thumb_record_branch (insn_decode_record *thumb_insn_r)
12213 uint32_t record_buf[8];
12214 uint32_t bits_h = 0;
12216 bits_h = bits (thumb_insn_r->arm_insn, 11, 12);
12218 if (2 == bits_h || 3 == bits_h)
12221 record_buf[0] = ARM_LR_REGNUM;
12222 thumb_insn_r->reg_rec_count = 1;
12224 else if (1 == bits_h)
12227 record_buf[0] = ARM_PS_REGNUM;
12228 record_buf[1] = ARM_LR_REGNUM;
12229 thumb_insn_r->reg_rec_count = 2;
12232 /* B(2) is automatically taken care in process_record, as PC is
12235 REG_ALLOC (thumb_insn_r->arm_regs, thumb_insn_r->reg_rec_count, record_buf);
12240 /* Handler for thumb2 load/store multiple instructions. */
12243 thumb2_record_ld_st_multiple (insn_decode_record *thumb2_insn_r)
12245 struct regcache *reg_cache = thumb2_insn_r->regcache;
12247 uint32_t reg_rn, op;
12248 uint32_t register_bits = 0, register_count = 0;
12249 uint32_t index = 0, start_address = 0;
12250 uint32_t record_buf[24], record_buf_mem[48];
12252 ULONGEST u_regval = 0;
12254 reg_rn = bits (thumb2_insn_r->arm_insn, 16, 19);
12255 op = bits (thumb2_insn_r->arm_insn, 23, 24);
12257 if (0 == op || 3 == op)
12259 if (bit (thumb2_insn_r->arm_insn, INSN_S_L_BIT_NUM))
12261 /* Handle RFE instruction. */
12262 record_buf[0] = ARM_PS_REGNUM;
12263 thumb2_insn_r->reg_rec_count = 1;
12267 /* Handle SRS instruction after reading banked SP. */
12268 return arm_record_unsupported_insn (thumb2_insn_r);
12271 else if (1 == op || 2 == op)
12273 if (bit (thumb2_insn_r->arm_insn, INSN_S_L_BIT_NUM))
12275 /* Handle LDM/LDMIA/LDMFD and LDMDB/LDMEA instructions. */
12276 register_bits = bits (thumb2_insn_r->arm_insn, 0, 15);
12277 while (register_bits)
12279 if (register_bits & 0x00000001)
12280 record_buf[index++] = register_count;
12283 register_bits = register_bits >> 1;
12285 record_buf[index++] = reg_rn;
12286 record_buf[index++] = ARM_PS_REGNUM;
12287 thumb2_insn_r->reg_rec_count = index;
12291 /* Handle STM/STMIA/STMEA and STMDB/STMFD. */
12292 register_bits = bits (thumb2_insn_r->arm_insn, 0, 15);
12293 regcache_raw_read_unsigned (reg_cache, reg_rn, &u_regval);
12294 while (register_bits)
12296 if (register_bits & 0x00000001)
12299 register_bits = register_bits >> 1;
12304 /* Start address calculation for LDMDB/LDMEA. */
12305 start_address = u_regval;
12309 /* Start address calculation for LDMDB/LDMEA. */
12310 start_address = u_regval - register_count * 4;
12313 thumb2_insn_r->mem_rec_count = register_count;
12314 while (register_count)
12316 record_buf_mem[register_count * 2 - 1] = start_address;
12317 record_buf_mem[register_count * 2 - 2] = 4;
12318 start_address = start_address + 4;
12321 record_buf[0] = reg_rn;
12322 record_buf[1] = ARM_PS_REGNUM;
12323 thumb2_insn_r->reg_rec_count = 2;
12327 MEM_ALLOC (thumb2_insn_r->arm_mems, thumb2_insn_r->mem_rec_count,
12329 REG_ALLOC (thumb2_insn_r->arm_regs, thumb2_insn_r->reg_rec_count,
12331 return ARM_RECORD_SUCCESS;
12334 /* Handler for thumb2 load/store (dual/exclusive) and table branch
12338 thumb2_record_ld_st_dual_ex_tbb (insn_decode_record *thumb2_insn_r)
12340 struct regcache *reg_cache = thumb2_insn_r->regcache;
12342 uint32_t reg_rd, reg_rn, offset_imm;
12343 uint32_t reg_dest1, reg_dest2;
12344 uint32_t address, offset_addr;
12345 uint32_t record_buf[8], record_buf_mem[8];
12346 uint32_t op1, op2, op3;
12348 ULONGEST u_regval[2];
12350 op1 = bits (thumb2_insn_r->arm_insn, 23, 24);
12351 op2 = bits (thumb2_insn_r->arm_insn, 20, 21);
12352 op3 = bits (thumb2_insn_r->arm_insn, 4, 7);
12354 if (bit (thumb2_insn_r->arm_insn, INSN_S_L_BIT_NUM))
12356 if(!(1 == op1 && 1 == op2 && (0 == op3 || 1 == op3)))
12358 reg_dest1 = bits (thumb2_insn_r->arm_insn, 12, 15);
12359 record_buf[0] = reg_dest1;
12360 record_buf[1] = ARM_PS_REGNUM;
12361 thumb2_insn_r->reg_rec_count = 2;
12364 if (3 == op2 || (op1 & 2) || (1 == op1 && 1 == op2 && 7 == op3))
12366 reg_dest2 = bits (thumb2_insn_r->arm_insn, 8, 11);
12367 record_buf[2] = reg_dest2;
12368 thumb2_insn_r->reg_rec_count = 3;
12373 reg_rn = bits (thumb2_insn_r->arm_insn, 16, 19);
12374 regcache_raw_read_unsigned (reg_cache, reg_rn, &u_regval[0]);
12376 if (0 == op1 && 0 == op2)
12378 /* Handle STREX. */
12379 offset_imm = bits (thumb2_insn_r->arm_insn, 0, 7);
12380 address = u_regval[0] + (offset_imm * 4);
12381 record_buf_mem[0] = 4;
12382 record_buf_mem[1] = address;
12383 thumb2_insn_r->mem_rec_count = 1;
12384 reg_rd = bits (thumb2_insn_r->arm_insn, 0, 3);
12385 record_buf[0] = reg_rd;
12386 thumb2_insn_r->reg_rec_count = 1;
12388 else if (1 == op1 && 0 == op2)
12390 reg_rd = bits (thumb2_insn_r->arm_insn, 0, 3);
12391 record_buf[0] = reg_rd;
12392 thumb2_insn_r->reg_rec_count = 1;
12393 address = u_regval[0];
12394 record_buf_mem[1] = address;
12398 /* Handle STREXB. */
12399 record_buf_mem[0] = 1;
12400 thumb2_insn_r->mem_rec_count = 1;
12404 /* Handle STREXH. */
12405 record_buf_mem[0] = 2 ;
12406 thumb2_insn_r->mem_rec_count = 1;
12410 /* Handle STREXD. */
12411 address = u_regval[0];
12412 record_buf_mem[0] = 4;
12413 record_buf_mem[2] = 4;
12414 record_buf_mem[3] = address + 4;
12415 thumb2_insn_r->mem_rec_count = 2;
12420 offset_imm = bits (thumb2_insn_r->arm_insn, 0, 7);
12422 if (bit (thumb2_insn_r->arm_insn, 24))
12424 if (bit (thumb2_insn_r->arm_insn, 23))
12425 offset_addr = u_regval[0] + (offset_imm * 4);
12427 offset_addr = u_regval[0] - (offset_imm * 4);
12429 address = offset_addr;
12432 address = u_regval[0];
12434 record_buf_mem[0] = 4;
12435 record_buf_mem[1] = address;
12436 record_buf_mem[2] = 4;
12437 record_buf_mem[3] = address + 4;
12438 thumb2_insn_r->mem_rec_count = 2;
12439 record_buf[0] = reg_rn;
12440 thumb2_insn_r->reg_rec_count = 1;
12444 REG_ALLOC (thumb2_insn_r->arm_regs, thumb2_insn_r->reg_rec_count,
12446 MEM_ALLOC (thumb2_insn_r->arm_mems, thumb2_insn_r->mem_rec_count,
12448 return ARM_RECORD_SUCCESS;
12451 /* Handler for thumb2 data processing (shift register and modified immediate)
12455 thumb2_record_data_proc_sreg_mimm (insn_decode_record *thumb2_insn_r)
12457 uint32_t reg_rd, op;
12458 uint32_t record_buf[8];
12460 op = bits (thumb2_insn_r->arm_insn, 21, 24);
12461 reg_rd = bits (thumb2_insn_r->arm_insn, 8, 11);
12463 if ((0 == op || 4 == op || 8 == op || 13 == op) && 15 == reg_rd)
12465 record_buf[0] = ARM_PS_REGNUM;
12466 thumb2_insn_r->reg_rec_count = 1;
12470 record_buf[0] = reg_rd;
12471 record_buf[1] = ARM_PS_REGNUM;
12472 thumb2_insn_r->reg_rec_count = 2;
12475 REG_ALLOC (thumb2_insn_r->arm_regs, thumb2_insn_r->reg_rec_count,
12477 return ARM_RECORD_SUCCESS;
12480 /* Generic handler for thumb2 instructions which effect destination and PS
12484 thumb2_record_ps_dest_generic (insn_decode_record *thumb2_insn_r)
12487 uint32_t record_buf[8];
12489 reg_rd = bits (thumb2_insn_r->arm_insn, 8, 11);
12491 record_buf[0] = reg_rd;
12492 record_buf[1] = ARM_PS_REGNUM;
12493 thumb2_insn_r->reg_rec_count = 2;
12495 REG_ALLOC (thumb2_insn_r->arm_regs, thumb2_insn_r->reg_rec_count,
12497 return ARM_RECORD_SUCCESS;
12500 /* Handler for thumb2 branch and miscellaneous control instructions. */
12503 thumb2_record_branch_misc_cntrl (insn_decode_record *thumb2_insn_r)
12505 uint32_t op, op1, op2;
12506 uint32_t record_buf[8];
12508 op = bits (thumb2_insn_r->arm_insn, 20, 26);
12509 op1 = bits (thumb2_insn_r->arm_insn, 12, 14);
12510 op2 = bits (thumb2_insn_r->arm_insn, 8, 11);
12512 /* Handle MSR insn. */
12513 if (!(op1 & 0x2) && 0x38 == op)
12517 /* CPSR is going to be changed. */
12518 record_buf[0] = ARM_PS_REGNUM;
12519 thumb2_insn_r->reg_rec_count = 1;
12523 arm_record_unsupported_insn(thumb2_insn_r);
12527 else if (4 == (op1 & 0x5) || 5 == (op1 & 0x5))
12530 record_buf[0] = ARM_PS_REGNUM;
12531 record_buf[1] = ARM_LR_REGNUM;
12532 thumb2_insn_r->reg_rec_count = 2;
12535 REG_ALLOC (thumb2_insn_r->arm_regs, thumb2_insn_r->reg_rec_count,
12537 return ARM_RECORD_SUCCESS;
12540 /* Handler for thumb2 store single data item instructions. */
12543 thumb2_record_str_single_data (insn_decode_record *thumb2_insn_r)
12545 struct regcache *reg_cache = thumb2_insn_r->regcache;
12547 uint32_t reg_rn, reg_rm, offset_imm, shift_imm;
12548 uint32_t address, offset_addr;
12549 uint32_t record_buf[8], record_buf_mem[8];
12552 ULONGEST u_regval[2];
12554 op1 = bits (thumb2_insn_r->arm_insn, 21, 23);
12555 op2 = bits (thumb2_insn_r->arm_insn, 6, 11);
12556 reg_rn = bits (thumb2_insn_r->arm_insn, 16, 19);
12557 regcache_raw_read_unsigned (reg_cache, reg_rn, &u_regval[0]);
12559 if (bit (thumb2_insn_r->arm_insn, 23))
12562 offset_imm = bits (thumb2_insn_r->arm_insn, 0, 11);
12563 offset_addr = u_regval[0] + offset_imm;
12564 address = offset_addr;
12569 if ((0 == op1 || 1 == op1 || 2 == op1) && !(op2 & 0x20))
12571 /* Handle STRB (register). */
12572 reg_rm = bits (thumb2_insn_r->arm_insn, 0, 3);
12573 regcache_raw_read_unsigned (reg_cache, reg_rm, &u_regval[1]);
12574 shift_imm = bits (thumb2_insn_r->arm_insn, 4, 5);
12575 offset_addr = u_regval[1] << shift_imm;
12576 address = u_regval[0] + offset_addr;
12580 offset_imm = bits (thumb2_insn_r->arm_insn, 0, 7);
12581 if (bit (thumb2_insn_r->arm_insn, 10))
12583 if (bit (thumb2_insn_r->arm_insn, 9))
12584 offset_addr = u_regval[0] + offset_imm;
12586 offset_addr = u_regval[0] - offset_imm;
12588 address = offset_addr;
12591 address = u_regval[0];
12597 /* Store byte instructions. */
12600 record_buf_mem[0] = 1;
12602 /* Store half word instructions. */
12605 record_buf_mem[0] = 2;
12607 /* Store word instructions. */
12610 record_buf_mem[0] = 4;
12614 gdb_assert_not_reached ("no decoding pattern found");
12618 record_buf_mem[1] = address;
12619 thumb2_insn_r->mem_rec_count = 1;
12620 record_buf[0] = reg_rn;
12621 thumb2_insn_r->reg_rec_count = 1;
12623 REG_ALLOC (thumb2_insn_r->arm_regs, thumb2_insn_r->reg_rec_count,
12625 MEM_ALLOC (thumb2_insn_r->arm_mems, thumb2_insn_r->mem_rec_count,
12627 return ARM_RECORD_SUCCESS;
12630 /* Handler for thumb2 load memory hints instructions. */
12633 thumb2_record_ld_mem_hints (insn_decode_record *thumb2_insn_r)
12635 uint32_t record_buf[8];
12636 uint32_t reg_rt, reg_rn;
12638 reg_rt = bits (thumb2_insn_r->arm_insn, 12, 15);
12639 reg_rn = bits (thumb2_insn_r->arm_insn, 16, 19);
12641 if (ARM_PC_REGNUM != reg_rt)
12643 record_buf[0] = reg_rt;
12644 record_buf[1] = reg_rn;
12645 record_buf[2] = ARM_PS_REGNUM;
12646 thumb2_insn_r->reg_rec_count = 3;
12648 REG_ALLOC (thumb2_insn_r->arm_regs, thumb2_insn_r->reg_rec_count,
12650 return ARM_RECORD_SUCCESS;
12653 return ARM_RECORD_FAILURE;
12656 /* Handler for thumb2 load word instructions. */
12659 thumb2_record_ld_word (insn_decode_record *thumb2_insn_r)
12661 uint32_t record_buf[8];
12663 record_buf[0] = bits (thumb2_insn_r->arm_insn, 12, 15);
12664 record_buf[1] = ARM_PS_REGNUM;
12665 thumb2_insn_r->reg_rec_count = 2;
12667 REG_ALLOC (thumb2_insn_r->arm_regs, thumb2_insn_r->reg_rec_count,
12669 return ARM_RECORD_SUCCESS;
12672 /* Handler for thumb2 long multiply, long multiply accumulate, and
12673 divide instructions. */
12676 thumb2_record_lmul_lmla_div (insn_decode_record *thumb2_insn_r)
12678 uint32_t opcode1 = 0, opcode2 = 0;
12679 uint32_t record_buf[8];
12681 opcode1 = bits (thumb2_insn_r->arm_insn, 20, 22);
12682 opcode2 = bits (thumb2_insn_r->arm_insn, 4, 7);
12684 if (0 == opcode1 || 2 == opcode1 || (opcode1 >= 4 && opcode1 <= 6))
12686 /* Handle SMULL, UMULL, SMULAL. */
12687 /* Handle SMLAL(S), SMULL(S), UMLAL(S), UMULL(S). */
12688 record_buf[0] = bits (thumb2_insn_r->arm_insn, 16, 19);
12689 record_buf[1] = bits (thumb2_insn_r->arm_insn, 12, 15);
12690 record_buf[2] = ARM_PS_REGNUM;
12691 thumb2_insn_r->reg_rec_count = 3;
12693 else if (1 == opcode1 || 3 == opcode2)
12695 /* Handle SDIV and UDIV. */
12696 record_buf[0] = bits (thumb2_insn_r->arm_insn, 16, 19);
12697 record_buf[1] = bits (thumb2_insn_r->arm_insn, 12, 15);
12698 record_buf[2] = ARM_PS_REGNUM;
12699 thumb2_insn_r->reg_rec_count = 3;
12702 return ARM_RECORD_FAILURE;
12704 REG_ALLOC (thumb2_insn_r->arm_regs, thumb2_insn_r->reg_rec_count,
12706 return ARM_RECORD_SUCCESS;
12709 /* Record handler for thumb32 coprocessor instructions. */
12712 thumb2_record_coproc_insn (insn_decode_record *thumb2_insn_r)
12714 if (bit (thumb2_insn_r->arm_insn, 25))
12715 return arm_record_coproc_data_proc (thumb2_insn_r);
12717 return arm_record_asimd_vfp_coproc (thumb2_insn_r);
12720 /* Record handler for advance SIMD structure load/store instructions. */
12723 thumb2_record_asimd_struct_ld_st (insn_decode_record *thumb2_insn_r)
12725 struct regcache *reg_cache = thumb2_insn_r->regcache;
12726 uint32_t l_bit, a_bit, b_bits;
12727 uint32_t record_buf[128], record_buf_mem[128];
12728 uint32_t reg_rn, reg_vd, address, f_elem;
12729 uint32_t index_r = 0, index_e = 0, bf_regs = 0, index_m = 0, loop_t = 0;
12732 l_bit = bit (thumb2_insn_r->arm_insn, 21);
12733 a_bit = bit (thumb2_insn_r->arm_insn, 23);
12734 b_bits = bits (thumb2_insn_r->arm_insn, 8, 11);
12735 reg_rn = bits (thumb2_insn_r->arm_insn, 16, 19);
12736 reg_vd = bits (thumb2_insn_r->arm_insn, 12, 15);
12737 reg_vd = (bit (thumb2_insn_r->arm_insn, 22) << 4) | reg_vd;
12738 f_ebytes = (1 << bits (thumb2_insn_r->arm_insn, 6, 7));
12739 f_elem = 8 / f_ebytes;
12743 ULONGEST u_regval = 0;
12744 regcache_raw_read_unsigned (reg_cache, reg_rn, &u_regval);
12745 address = u_regval;
12750 if (b_bits == 0x02 || b_bits == 0x0a || (b_bits & 0x0e) == 0x06)
12752 if (b_bits == 0x07)
12754 else if (b_bits == 0x0a)
12756 else if (b_bits == 0x06)
12758 else if (b_bits == 0x02)
12763 for (index_r = 0; index_r < bf_regs; index_r++)
12765 for (index_e = 0; index_e < f_elem; index_e++)
12767 record_buf_mem[index_m++] = f_ebytes;
12768 record_buf_mem[index_m++] = address;
12769 address = address + f_ebytes;
12770 thumb2_insn_r->mem_rec_count += 1;
12775 else if (b_bits == 0x03 || (b_bits & 0x0e) == 0x08)
12777 if (b_bits == 0x09 || b_bits == 0x08)
12779 else if (b_bits == 0x03)
12784 for (index_r = 0; index_r < bf_regs; index_r++)
12785 for (index_e = 0; index_e < f_elem; index_e++)
12787 for (loop_t = 0; loop_t < 2; loop_t++)
12789 record_buf_mem[index_m++] = f_ebytes;
12790 record_buf_mem[index_m++] = address + (loop_t * f_ebytes);
12791 thumb2_insn_r->mem_rec_count += 1;
12793 address = address + (2 * f_ebytes);
12797 else if ((b_bits & 0x0e) == 0x04)
12799 for (index_e = 0; index_e < f_elem; index_e++)
12801 for (loop_t = 0; loop_t < 3; loop_t++)
12803 record_buf_mem[index_m++] = f_ebytes;
12804 record_buf_mem[index_m++] = address + (loop_t * f_ebytes);
12805 thumb2_insn_r->mem_rec_count += 1;
12807 address = address + (3 * f_ebytes);
12811 else if (!(b_bits & 0x0e))
12813 for (index_e = 0; index_e < f_elem; index_e++)
12815 for (loop_t = 0; loop_t < 4; loop_t++)
12817 record_buf_mem[index_m++] = f_ebytes;
12818 record_buf_mem[index_m++] = address + (loop_t * f_ebytes);
12819 thumb2_insn_r->mem_rec_count += 1;
12821 address = address + (4 * f_ebytes);
12827 uint8_t bft_size = bits (thumb2_insn_r->arm_insn, 10, 11);
12829 if (bft_size == 0x00)
12831 else if (bft_size == 0x01)
12833 else if (bft_size == 0x02)
12839 if (!(b_bits & 0x0b) || b_bits == 0x08)
12840 thumb2_insn_r->mem_rec_count = 1;
12842 else if ((b_bits & 0x0b) == 0x01 || b_bits == 0x09)
12843 thumb2_insn_r->mem_rec_count = 2;
12845 else if ((b_bits & 0x0b) == 0x02 || b_bits == 0x0a)
12846 thumb2_insn_r->mem_rec_count = 3;
12848 else if ((b_bits & 0x0b) == 0x03 || b_bits == 0x0b)
12849 thumb2_insn_r->mem_rec_count = 4;
12851 for (index_m = 0; index_m < thumb2_insn_r->mem_rec_count; index_m++)
12853 record_buf_mem[index_m] = f_ebytes;
12854 record_buf_mem[index_m] = address + (index_m * f_ebytes);
12863 if (b_bits == 0x02 || b_bits == 0x0a || (b_bits & 0x0e) == 0x06)
12864 thumb2_insn_r->reg_rec_count = 1;
12866 else if (b_bits == 0x03 || (b_bits & 0x0e) == 0x08)
12867 thumb2_insn_r->reg_rec_count = 2;
12869 else if ((b_bits & 0x0e) == 0x04)
12870 thumb2_insn_r->reg_rec_count = 3;
12872 else if (!(b_bits & 0x0e))
12873 thumb2_insn_r->reg_rec_count = 4;
12878 if (!(b_bits & 0x0b) || b_bits == 0x08 || b_bits == 0x0c)
12879 thumb2_insn_r->reg_rec_count = 1;
12881 else if ((b_bits & 0x0b) == 0x01 || b_bits == 0x09 || b_bits == 0x0d)
12882 thumb2_insn_r->reg_rec_count = 2;
12884 else if ((b_bits & 0x0b) == 0x02 || b_bits == 0x0a || b_bits == 0x0e)
12885 thumb2_insn_r->reg_rec_count = 3;
12887 else if ((b_bits & 0x0b) == 0x03 || b_bits == 0x0b || b_bits == 0x0f)
12888 thumb2_insn_r->reg_rec_count = 4;
12890 for (index_r = 0; index_r < thumb2_insn_r->reg_rec_count; index_r++)
12891 record_buf[index_r] = reg_vd + ARM_D0_REGNUM + index_r;
12895 if (bits (thumb2_insn_r->arm_insn, 0, 3) != 15)
12897 record_buf[index_r] = reg_rn;
12898 thumb2_insn_r->reg_rec_count += 1;
12901 REG_ALLOC (thumb2_insn_r->arm_regs, thumb2_insn_r->reg_rec_count,
12903 MEM_ALLOC (thumb2_insn_r->arm_mems, thumb2_insn_r->mem_rec_count,
12908 /* Decodes thumb2 instruction type and invokes its record handler. */
12910 static unsigned int
12911 thumb2_record_decode_insn_handler (insn_decode_record *thumb2_insn_r)
12913 uint32_t op, op1, op2;
12915 op = bit (thumb2_insn_r->arm_insn, 15);
12916 op1 = bits (thumb2_insn_r->arm_insn, 27, 28);
12917 op2 = bits (thumb2_insn_r->arm_insn, 20, 26);
12921 if (!(op2 & 0x64 ))
12923 /* Load/store multiple instruction. */
12924 return thumb2_record_ld_st_multiple (thumb2_insn_r);
12926 else if ((op2 & 0x64) == 0x4)
12928 /* Load/store (dual/exclusive) and table branch instruction. */
12929 return thumb2_record_ld_st_dual_ex_tbb (thumb2_insn_r);
12931 else if ((op2 & 0x60) == 0x20)
12933 /* Data-processing (shifted register). */
12934 return thumb2_record_data_proc_sreg_mimm (thumb2_insn_r);
12936 else if (op2 & 0x40)
12938 /* Co-processor instructions. */
12939 return thumb2_record_coproc_insn (thumb2_insn_r);
12942 else if (op1 == 0x02)
12946 /* Branches and miscellaneous control instructions. */
12947 return thumb2_record_branch_misc_cntrl (thumb2_insn_r);
12949 else if (op2 & 0x20)
12951 /* Data-processing (plain binary immediate) instruction. */
12952 return thumb2_record_ps_dest_generic (thumb2_insn_r);
12956 /* Data-processing (modified immediate). */
12957 return thumb2_record_data_proc_sreg_mimm (thumb2_insn_r);
12960 else if (op1 == 0x03)
12962 if (!(op2 & 0x71 ))
12964 /* Store single data item. */
12965 return thumb2_record_str_single_data (thumb2_insn_r);
12967 else if (!((op2 & 0x71) ^ 0x10))
12969 /* Advanced SIMD or structure load/store instructions. */
12970 return thumb2_record_asimd_struct_ld_st (thumb2_insn_r);
12972 else if (!((op2 & 0x67) ^ 0x01))
12974 /* Load byte, memory hints instruction. */
12975 return thumb2_record_ld_mem_hints (thumb2_insn_r);
12977 else if (!((op2 & 0x67) ^ 0x03))
12979 /* Load halfword, memory hints instruction. */
12980 return thumb2_record_ld_mem_hints (thumb2_insn_r);
12982 else if (!((op2 & 0x67) ^ 0x05))
12984 /* Load word instruction. */
12985 return thumb2_record_ld_word (thumb2_insn_r);
12987 else if (!((op2 & 0x70) ^ 0x20))
12989 /* Data-processing (register) instruction. */
12990 return thumb2_record_ps_dest_generic (thumb2_insn_r);
12992 else if (!((op2 & 0x78) ^ 0x30))
12994 /* Multiply, multiply accumulate, abs diff instruction. */
12995 return thumb2_record_ps_dest_generic (thumb2_insn_r);
12997 else if (!((op2 & 0x78) ^ 0x38))
12999 /* Long multiply, long multiply accumulate, and divide. */
13000 return thumb2_record_lmul_lmla_div (thumb2_insn_r);
13002 else if (op2 & 0x40)
13004 /* Co-processor instructions. */
13005 return thumb2_record_coproc_insn (thumb2_insn_r);
13013 /* Abstract memory reader. */
13015 class abstract_memory_reader
13018 /* Read LEN bytes of target memory at address MEMADDR, placing the
13019 results in GDB's memory at BUF. Return true on success. */
13021 virtual bool read (CORE_ADDR memaddr, gdb_byte *buf, const size_t len) = 0;
13024 /* Instruction reader from real target. */
13026 class instruction_reader : public abstract_memory_reader
13029 bool read (CORE_ADDR memaddr, gdb_byte *buf, const size_t len) override
13031 if (target_read_memory (memaddr, buf, len))
13040 /* Extracts arm/thumb/thumb2 insn depending on the size, and returns 0 on success
13041 and positive val on fauilure. */
13044 extract_arm_insn (abstract_memory_reader& reader,
13045 insn_decode_record *insn_record, uint32_t insn_size)
13047 gdb_byte buf[insn_size];
13049 memset (&buf[0], 0, insn_size);
13051 if (!reader.read (insn_record->this_addr, buf, insn_size))
13053 insn_record->arm_insn = (uint32_t) extract_unsigned_integer (&buf[0],
13055 gdbarch_byte_order_for_code (insn_record->gdbarch));
13059 typedef int (*sti_arm_hdl_fp_t) (insn_decode_record*);
13061 /* Decode arm/thumb insn depending on condition cods and opcodes; and
13065 decode_insn (abstract_memory_reader &reader, insn_decode_record *arm_record,
13066 record_type_t record_type, uint32_t insn_size)
13069 /* (Starting from numerical 0); bits 25, 26, 27 decodes type of arm
13071 static const sti_arm_hdl_fp_t arm_handle_insn[8] =
13073 arm_record_data_proc_misc_ld_str, /* 000. */
13074 arm_record_data_proc_imm, /* 001. */
13075 arm_record_ld_st_imm_offset, /* 010. */
13076 arm_record_ld_st_reg_offset, /* 011. */
13077 arm_record_ld_st_multiple, /* 100. */
13078 arm_record_b_bl, /* 101. */
13079 arm_record_asimd_vfp_coproc, /* 110. */
13080 arm_record_coproc_data_proc /* 111. */
13083 /* (Starting from numerical 0); bits 13,14,15 decodes type of thumb
13085 static const sti_arm_hdl_fp_t thumb_handle_insn[8] =
13087 thumb_record_shift_add_sub, /* 000. */
13088 thumb_record_add_sub_cmp_mov, /* 001. */
13089 thumb_record_ld_st_reg_offset, /* 010. */
13090 thumb_record_ld_st_imm_offset, /* 011. */
13091 thumb_record_ld_st_stack, /* 100. */
13092 thumb_record_misc, /* 101. */
13093 thumb_record_ldm_stm_swi, /* 110. */
13094 thumb_record_branch /* 111. */
13097 uint32_t ret = 0; /* return value: negative:failure 0:success. */
13098 uint32_t insn_id = 0;
13100 if (extract_arm_insn (reader, arm_record, insn_size))
13104 printf_unfiltered (_("Process record: error reading memory at "
13105 "addr %s len = %d.\n"),
13106 paddress (arm_record->gdbarch,
13107 arm_record->this_addr), insn_size);
13111 else if (ARM_RECORD == record_type)
13113 arm_record->cond = bits (arm_record->arm_insn, 28, 31);
13114 insn_id = bits (arm_record->arm_insn, 25, 27);
13116 if (arm_record->cond == 0xf)
13117 ret = arm_record_extension_space (arm_record);
13120 /* If this insn has fallen into extension space
13121 then we need not decode it anymore. */
13122 ret = arm_handle_insn[insn_id] (arm_record);
13124 if (ret != ARM_RECORD_SUCCESS)
13126 arm_record_unsupported_insn (arm_record);
13130 else if (THUMB_RECORD == record_type)
13132 /* As thumb does not have condition codes, we set negative. */
13133 arm_record->cond = -1;
13134 insn_id = bits (arm_record->arm_insn, 13, 15);
13135 ret = thumb_handle_insn[insn_id] (arm_record);
13136 if (ret != ARM_RECORD_SUCCESS)
13138 arm_record_unsupported_insn (arm_record);
13142 else if (THUMB2_RECORD == record_type)
13144 /* As thumb does not have condition codes, we set negative. */
13145 arm_record->cond = -1;
13147 /* Swap first half of 32bit thumb instruction with second half. */
13148 arm_record->arm_insn
13149 = (arm_record->arm_insn >> 16) | (arm_record->arm_insn << 16);
13151 ret = thumb2_record_decode_insn_handler (arm_record);
13153 if (ret != ARM_RECORD_SUCCESS)
13155 arm_record_unsupported_insn (arm_record);
13161 /* Throw assertion. */
13162 gdb_assert_not_reached ("not a valid instruction, could not decode");
13169 namespace selftests {
13171 /* Provide both 16-bit and 32-bit thumb instructions. */
13173 class instruction_reader_thumb : public abstract_memory_reader
13176 template<size_t SIZE>
13177 instruction_reader_thumb (enum bfd_endian endian,
13178 const uint16_t (&insns)[SIZE])
13179 : m_endian (endian), m_insns (insns), m_insns_size (SIZE)
13182 bool read (CORE_ADDR memaddr, gdb_byte *buf, const size_t len) override
13184 SELF_CHECK (len == 4 || len == 2);
13185 SELF_CHECK (memaddr % 2 == 0);
13186 SELF_CHECK ((memaddr / 2) < m_insns_size);
13188 store_unsigned_integer (buf, 2, m_endian, m_insns[memaddr / 2]);
13191 store_unsigned_integer (&buf[2], 2, m_endian,
13192 m_insns[memaddr / 2 + 1]);
13198 enum bfd_endian m_endian;
13199 const uint16_t *m_insns;
13200 size_t m_insns_size;
13204 arm_record_test (void)
13206 struct gdbarch_info info;
13207 gdbarch_info_init (&info);
13208 info.bfd_arch_info = bfd_scan_arch ("arm");
13210 struct gdbarch *gdbarch = gdbarch_find_by_info (info);
13212 SELF_CHECK (gdbarch != NULL);
13214 /* 16-bit Thumb instructions. */
13216 insn_decode_record arm_record;
13218 memset (&arm_record, 0, sizeof (insn_decode_record));
13219 arm_record.gdbarch = gdbarch;
13221 static const uint16_t insns[] = {
13222 /* db b2 uxtb r3, r3 */
13224 /* cd 58 ldr r5, [r1, r3] */
13228 enum bfd_endian endian = gdbarch_byte_order_for_code (arm_record.gdbarch);
13229 instruction_reader_thumb reader (endian, insns);
13230 int ret = decode_insn (reader, &arm_record, THUMB_RECORD,
13231 THUMB_INSN_SIZE_BYTES);
13233 SELF_CHECK (ret == 0);
13234 SELF_CHECK (arm_record.mem_rec_count == 0);
13235 SELF_CHECK (arm_record.reg_rec_count == 1);
13236 SELF_CHECK (arm_record.arm_regs[0] == 3);
13238 arm_record.this_addr += 2;
13239 ret = decode_insn (reader, &arm_record, THUMB_RECORD,
13240 THUMB_INSN_SIZE_BYTES);
13242 SELF_CHECK (ret == 0);
13243 SELF_CHECK (arm_record.mem_rec_count == 0);
13244 SELF_CHECK (arm_record.reg_rec_count == 1);
13245 SELF_CHECK (arm_record.arm_regs[0] == 5);
13248 /* 32-bit Thumb-2 instructions. */
13250 insn_decode_record arm_record;
13252 memset (&arm_record, 0, sizeof (insn_decode_record));
13253 arm_record.gdbarch = gdbarch;
13255 static const uint16_t insns[] = {
13256 /* 1d ee 70 7f mrc 15, 0, r7, cr13, cr0, {3} */
13260 enum bfd_endian endian = gdbarch_byte_order_for_code (arm_record.gdbarch);
13261 instruction_reader_thumb reader (endian, insns);
13262 int ret = decode_insn (reader, &arm_record, THUMB2_RECORD,
13263 THUMB2_INSN_SIZE_BYTES);
13265 SELF_CHECK (ret == 0);
13266 SELF_CHECK (arm_record.mem_rec_count == 0);
13267 SELF_CHECK (arm_record.reg_rec_count == 1);
13268 SELF_CHECK (arm_record.arm_regs[0] == 7);
13271 } // namespace selftests
13272 #endif /* GDB_SELF_TEST */
13274 /* Cleans up local record registers and memory allocations. */
13277 deallocate_reg_mem (insn_decode_record *record)
13279 xfree (record->arm_regs);
13280 xfree (record->arm_mems);
13284 /* Parse the current instruction and record the values of the registers and
13285 memory that will be changed in current instruction to record_arch_list".
13286 Return -1 if something is wrong. */
13289 arm_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
13290 CORE_ADDR insn_addr)
13293 uint32_t no_of_rec = 0;
13294 uint32_t ret = 0; /* return value: -1:record failure ; 0:success */
13295 ULONGEST t_bit = 0, insn_id = 0;
13297 ULONGEST u_regval = 0;
13299 insn_decode_record arm_record;
13301 memset (&arm_record, 0, sizeof (insn_decode_record));
13302 arm_record.regcache = regcache;
13303 arm_record.this_addr = insn_addr;
13304 arm_record.gdbarch = gdbarch;
13307 if (record_debug > 1)
13309 fprintf_unfiltered (gdb_stdlog, "Process record: arm_process_record "
13311 paddress (gdbarch, arm_record.this_addr));
13314 instruction_reader reader;
13315 if (extract_arm_insn (reader, &arm_record, 2))
13319 printf_unfiltered (_("Process record: error reading memory at "
13320 "addr %s len = %d.\n"),
13321 paddress (arm_record.gdbarch,
13322 arm_record.this_addr), 2);
13327 /* Check the insn, whether it is thumb or arm one. */
13329 t_bit = arm_psr_thumb_bit (arm_record.gdbarch);
13330 regcache_raw_read_unsigned (arm_record.regcache, ARM_PS_REGNUM, &u_regval);
13333 if (!(u_regval & t_bit))
13335 /* We are decoding arm insn. */
13336 ret = decode_insn (reader, &arm_record, ARM_RECORD, ARM_INSN_SIZE_BYTES);
13340 insn_id = bits (arm_record.arm_insn, 11, 15);
13341 /* is it thumb2 insn? */
13342 if ((0x1D == insn_id) || (0x1E == insn_id) || (0x1F == insn_id))
13344 ret = decode_insn (reader, &arm_record, THUMB2_RECORD,
13345 THUMB2_INSN_SIZE_BYTES);
13349 /* We are decoding thumb insn. */
13350 ret = decode_insn (reader, &arm_record, THUMB_RECORD,
13351 THUMB_INSN_SIZE_BYTES);
13357 /* Record registers. */
13358 record_full_arch_list_add_reg (arm_record.regcache, ARM_PC_REGNUM);
13359 if (arm_record.arm_regs)
13361 for (no_of_rec = 0; no_of_rec < arm_record.reg_rec_count; no_of_rec++)
13363 if (record_full_arch_list_add_reg
13364 (arm_record.regcache , arm_record.arm_regs[no_of_rec]))
13368 /* Record memories. */
13369 if (arm_record.arm_mems)
13371 for (no_of_rec = 0; no_of_rec < arm_record.mem_rec_count; no_of_rec++)
13373 if (record_full_arch_list_add_mem
13374 ((CORE_ADDR)arm_record.arm_mems[no_of_rec].addr,
13375 arm_record.arm_mems[no_of_rec].len))
13380 if (record_full_arch_list_add_end ())
13385 deallocate_reg_mem (&arm_record);