1 /* Common target dependent code for GDB on ARM systems.
3 Copyright (C) 1988, 1989, 1991, 1992, 1993, 1995, 1996, 1998, 1999, 2000,
4 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
5 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include <ctype.h> /* XXX for isupper () */
29 #include "gdb_string.h"
30 #include "dis-asm.h" /* For register styles. */
34 #include "arch-utils.h"
36 #include "frame-unwind.h"
37 #include "frame-base.h"
38 #include "trad-frame.h"
40 #include "dwarf2-frame.h"
42 #include "prologue-value.h"
43 #include "target-descriptions.h"
44 #include "user-regs.h"
47 #include "gdb/sim-arm.h"
50 #include "coff/internal.h"
53 #include "gdb_assert.h"
58 /* Macros for setting and testing a bit in a minimal symbol that marks
59 it as Thumb function. The MSB of the minimal symbol's "info" field
60 is used for this purpose.
62 MSYMBOL_SET_SPECIAL Actually sets the "special" bit.
63 MSYMBOL_IS_SPECIAL Tests the "special" bit in a minimal symbol. */
65 #define MSYMBOL_SET_SPECIAL(msym) \
66 MSYMBOL_TARGET_FLAG_1 (msym) = 1
68 #define MSYMBOL_IS_SPECIAL(msym) \
69 MSYMBOL_TARGET_FLAG_1 (msym)
71 /* Per-objfile data used for mapping symbols. */
72 static const struct objfile_data *arm_objfile_data_key;
74 struct arm_mapping_symbol
79 typedef struct arm_mapping_symbol arm_mapping_symbol_s;
80 DEF_VEC_O(arm_mapping_symbol_s);
82 struct arm_per_objfile
84 VEC(arm_mapping_symbol_s) **section_maps;
87 /* The list of available "set arm ..." and "show arm ..." commands. */
88 static struct cmd_list_element *setarmcmdlist = NULL;
89 static struct cmd_list_element *showarmcmdlist = NULL;
91 /* The type of floating-point to use. Keep this in sync with enum
92 arm_float_model, and the help string in _initialize_arm_tdep. */
93 static const char *fp_model_strings[] =
103 /* A variable that can be configured by the user. */
104 static enum arm_float_model arm_fp_model = ARM_FLOAT_AUTO;
105 static const char *current_fp_model = "auto";
107 /* The ABI to use. Keep this in sync with arm_abi_kind. */
108 static const char *arm_abi_strings[] =
116 /* A variable that can be configured by the user. */
117 static enum arm_abi_kind arm_abi_global = ARM_ABI_AUTO;
118 static const char *arm_abi_string = "auto";
120 /* The execution mode to assume. */
121 static const char *arm_mode_strings[] =
128 static const char *arm_fallback_mode_string = "auto";
129 static const char *arm_force_mode_string = "auto";
131 /* Number of different reg name sets (options). */
132 static int num_disassembly_options;
134 /* The standard register names, and all the valid aliases for them. */
139 } arm_register_aliases[] = {
140 /* Basic register numbers. */
157 /* Synonyms (argument and variable registers). */
170 /* Other platform-specific names for r9. */
178 /* Names used by GCC (not listed in the ARM EABI). */
181 /* A special name from the older ATPCS. */
185 static const char *const arm_register_names[] =
186 {"r0", "r1", "r2", "r3", /* 0 1 2 3 */
187 "r4", "r5", "r6", "r7", /* 4 5 6 7 */
188 "r8", "r9", "r10", "r11", /* 8 9 10 11 */
189 "r12", "sp", "lr", "pc", /* 12 13 14 15 */
190 "f0", "f1", "f2", "f3", /* 16 17 18 19 */
191 "f4", "f5", "f6", "f7", /* 20 21 22 23 */
192 "fps", "cpsr" }; /* 24 25 */
194 /* Valid register name styles. */
195 static const char **valid_disassembly_styles;
197 /* Disassembly style to use. Default to "std" register names. */
198 static const char *disassembly_style;
200 /* This is used to keep the bfd arch_info in sync with the disassembly
202 static void set_disassembly_style_sfunc(char *, int,
203 struct cmd_list_element *);
204 static void set_disassembly_style (void);
206 static void convert_from_extended (const struct floatformat *, const void *,
208 static void convert_to_extended (const struct floatformat *, void *,
211 static void arm_neon_quad_read (struct gdbarch *gdbarch,
212 struct regcache *regcache,
213 int regnum, gdb_byte *buf);
214 static void arm_neon_quad_write (struct gdbarch *gdbarch,
215 struct regcache *regcache,
216 int regnum, const gdb_byte *buf);
218 struct arm_prologue_cache
220 /* The stack pointer at the time this frame was created; i.e. the
221 caller's stack pointer when this function was called. It is used
222 to identify this frame. */
225 /* The frame base for this frame is just prev_sp - frame size.
226 FRAMESIZE is the distance from the frame pointer to the
227 initial stack pointer. */
231 /* The register used to hold the frame pointer for this frame. */
234 /* Saved register offsets. */
235 struct trad_frame_saved_reg *saved_regs;
238 /* Addresses for calling Thumb functions have the bit 0 set.
239 Here are some macros to test, set, or clear bit 0 of addresses. */
240 #define IS_THUMB_ADDR(addr) ((addr) & 1)
241 #define MAKE_THUMB_ADDR(addr) ((addr) | 1)
242 #define UNMAKE_THUMB_ADDR(addr) ((addr) & ~1)
244 /* Set to true if the 32-bit mode is in use. */
248 /* Determine if FRAME is executing in Thumb mode. */
251 arm_frame_is_thumb (struct frame_info *frame)
255 /* Every ARM frame unwinder can unwind the T bit of the CPSR, either
256 directly (from a signal frame or dummy frame) or by interpreting
257 the saved LR (from a prologue or DWARF frame). So consult it and
258 trust the unwinders. */
259 cpsr = get_frame_register_unsigned (frame, ARM_PS_REGNUM);
261 return (cpsr & CPSR_T) != 0;
264 /* Callback for VEC_lower_bound. */
267 arm_compare_mapping_symbols (const struct arm_mapping_symbol *lhs,
268 const struct arm_mapping_symbol *rhs)
270 return lhs->value < rhs->value;
273 /* Determine if the program counter specified in MEMADDR is in a Thumb
274 function. This function should be called for addresses unrelated to
275 any executing frame; otherwise, prefer arm_frame_is_thumb. */
278 arm_pc_is_thumb (CORE_ADDR memaddr)
280 struct obj_section *sec;
281 struct minimal_symbol *sym;
283 /* If bit 0 of the address is set, assume this is a Thumb address. */
284 if (IS_THUMB_ADDR (memaddr))
287 /* If the user wants to override the symbol table, let him. */
288 if (strcmp (arm_force_mode_string, "arm") == 0)
290 if (strcmp (arm_force_mode_string, "thumb") == 0)
293 /* If there are mapping symbols, consult them. */
294 sec = find_pc_section (memaddr);
297 struct arm_per_objfile *data;
298 VEC(arm_mapping_symbol_s) *map;
299 struct arm_mapping_symbol map_key = { memaddr - obj_section_addr (sec),
303 data = objfile_data (sec->objfile, arm_objfile_data_key);
306 map = data->section_maps[sec->the_bfd_section->index];
307 if (!VEC_empty (arm_mapping_symbol_s, map))
309 struct arm_mapping_symbol *map_sym;
311 idx = VEC_lower_bound (arm_mapping_symbol_s, map, &map_key,
312 arm_compare_mapping_symbols);
314 /* VEC_lower_bound finds the earliest ordered insertion
315 point. If the following symbol starts at this exact
316 address, we use that; otherwise, the preceding
317 mapping symbol covers this address. */
318 if (idx < VEC_length (arm_mapping_symbol_s, map))
320 map_sym = VEC_index (arm_mapping_symbol_s, map, idx);
321 if (map_sym->value == map_key.value)
322 return map_sym->type == 't';
327 map_sym = VEC_index (arm_mapping_symbol_s, map, idx - 1);
328 return map_sym->type == 't';
334 /* Thumb functions have a "special" bit set in minimal symbols. */
335 sym = lookup_minimal_symbol_by_pc (memaddr);
337 return (MSYMBOL_IS_SPECIAL (sym));
339 /* If the user wants to override the fallback mode, let them. */
340 if (strcmp (arm_fallback_mode_string, "arm") == 0)
342 if (strcmp (arm_fallback_mode_string, "thumb") == 0)
345 /* If we couldn't find any symbol, but we're talking to a running
346 target, then trust the current value of $cpsr. This lets
347 "display/i $pc" always show the correct mode (though if there is
348 a symbol table we will not reach here, so it still may not be
349 displayed in the mode it will be executed). */
350 if (target_has_registers)
351 return arm_frame_is_thumb (get_current_frame ());
353 /* Otherwise we're out of luck; we assume ARM. */
357 /* Remove useless bits from addresses in a running program. */
359 arm_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR val)
362 return UNMAKE_THUMB_ADDR (val);
364 return (val & 0x03fffffc);
367 /* When reading symbols, we need to zap the low bit of the address,
368 which may be set to 1 for Thumb functions. */
370 arm_smash_text_address (struct gdbarch *gdbarch, CORE_ADDR val)
375 /* Analyze a Thumb prologue, looking for a recognizable stack frame
376 and frame pointer. Scan until we encounter a store that could
377 clobber the stack frame unexpectedly, or an unknown instruction. */
380 thumb_analyze_prologue (struct gdbarch *gdbarch,
381 CORE_ADDR start, CORE_ADDR limit,
382 struct arm_prologue_cache *cache)
384 enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
387 struct pv_area *stack;
388 struct cleanup *back_to;
391 for (i = 0; i < 16; i++)
392 regs[i] = pv_register (i, 0);
393 stack = make_pv_area (ARM_SP_REGNUM, gdbarch_addr_bit (gdbarch));
394 back_to = make_cleanup_free_pv_area (stack);
396 while (start < limit)
400 insn = read_memory_unsigned_integer (start, 2, byte_order_for_code);
402 if ((insn & 0xfe00) == 0xb400) /* push { rlist } */
407 if (pv_area_store_would_trash (stack, regs[ARM_SP_REGNUM]))
410 /* Bits 0-7 contain a mask for registers R0-R7. Bit 8 says
411 whether to save LR (R14). */
412 mask = (insn & 0xff) | ((insn & 0x100) << 6);
414 /* Calculate offsets of saved R0-R7 and LR. */
415 for (regno = ARM_LR_REGNUM; regno >= 0; regno--)
416 if (mask & (1 << regno))
418 regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM],
420 pv_area_store (stack, regs[ARM_SP_REGNUM], 4, regs[regno]);
423 else if ((insn & 0xff00) == 0xb000) /* add sp, #simm OR
426 offset = (insn & 0x7f) << 2; /* get scaled offset */
427 if (insn & 0x80) /* Check for SUB. */
428 regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM],
431 regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM],
434 else if ((insn & 0xff00) == 0xaf00) /* add r7, sp, #imm */
435 regs[THUMB_FP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM],
437 else if ((insn & 0xff00) == 0x4600) /* mov hi, lo or mov lo, hi */
439 int dst_reg = (insn & 0x7) + ((insn & 0x80) >> 4);
440 int src_reg = (insn & 0x78) >> 3;
441 regs[dst_reg] = regs[src_reg];
443 else if ((insn & 0xf800) == 0x9000) /* str rd, [sp, #off] */
445 /* Handle stores to the stack. Normally pushes are used,
446 but with GCC -mtpcs-frame, there may be other stores
447 in the prologue to create the frame. */
448 int regno = (insn >> 8) & 0x7;
451 offset = (insn & 0xff) << 2;
452 addr = pv_add_constant (regs[ARM_SP_REGNUM], offset);
454 if (pv_area_store_would_trash (stack, addr))
457 pv_area_store (stack, addr, 4, regs[regno]);
461 /* We don't know what this instruction is. We're finished
462 scanning. NOTE: Recognizing more safe-to-ignore
463 instructions here will improve support for optimized
473 do_cleanups (back_to);
477 if (pv_is_register (regs[ARM_FP_REGNUM], ARM_SP_REGNUM))
479 /* Frame pointer is fp. Frame size is constant. */
480 cache->framereg = ARM_FP_REGNUM;
481 cache->framesize = -regs[ARM_FP_REGNUM].k;
483 else if (pv_is_register (regs[THUMB_FP_REGNUM], ARM_SP_REGNUM))
485 /* Frame pointer is r7. Frame size is constant. */
486 cache->framereg = THUMB_FP_REGNUM;
487 cache->framesize = -regs[THUMB_FP_REGNUM].k;
489 else if (pv_is_register (regs[ARM_SP_REGNUM], ARM_SP_REGNUM))
491 /* Try the stack pointer... this is a bit desperate. */
492 cache->framereg = ARM_SP_REGNUM;
493 cache->framesize = -regs[ARM_SP_REGNUM].k;
497 /* We're just out of luck. We don't know where the frame is. */
498 cache->framereg = -1;
499 cache->framesize = 0;
502 for (i = 0; i < 16; i++)
503 if (pv_area_find_reg (stack, gdbarch, i, &offset))
504 cache->saved_regs[i].addr = offset;
506 do_cleanups (back_to);
510 /* Advance the PC across any function entry prologue instructions to
511 reach some "real" code.
513 The APCS (ARM Procedure Call Standard) defines the following
517 [stmfd sp!, {a1,a2,a3,a4}]
518 stmfd sp!, {...,fp,ip,lr,pc}
519 [stfe f7, [sp, #-12]!]
520 [stfe f6, [sp, #-12]!]
521 [stfe f5, [sp, #-12]!]
522 [stfe f4, [sp, #-12]!]
523 sub fp, ip, #nn @@ nn == 20 or 4 depending on second insn */
526 arm_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
528 enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
531 CORE_ADDR func_addr, limit_pc;
532 struct symtab_and_line sal;
534 /* If we're in a dummy frame, don't even try to skip the prologue. */
535 if (deprecated_pc_in_call_dummy (gdbarch, pc))
538 /* See if we can determine the end of the prologue via the symbol table.
539 If so, then return either PC, or the PC after the prologue, whichever
541 if (find_pc_partial_function (pc, NULL, &func_addr, NULL))
543 CORE_ADDR post_prologue_pc
544 = skip_prologue_using_sal (gdbarch, func_addr);
545 if (post_prologue_pc != 0)
546 return max (pc, post_prologue_pc);
549 /* Can't determine prologue from the symbol table, need to examine
552 /* Find an upper limit on the function prologue using the debug
553 information. If the debug information could not be used to provide
554 that bound, then use an arbitrary large number as the upper bound. */
555 /* Like arm_scan_prologue, stop no later than pc + 64. */
556 limit_pc = skip_prologue_using_sal (gdbarch, pc);
558 limit_pc = pc + 64; /* Magic. */
561 /* Check if this is Thumb code. */
562 if (arm_pc_is_thumb (pc))
563 return thumb_analyze_prologue (gdbarch, pc, limit_pc, NULL);
565 for (skip_pc = pc; skip_pc < limit_pc; skip_pc += 4)
567 inst = read_memory_unsigned_integer (skip_pc, 4, byte_order_for_code);
569 /* "mov ip, sp" is no longer a required part of the prologue. */
570 if (inst == 0xe1a0c00d) /* mov ip, sp */
573 if ((inst & 0xfffff000) == 0xe28dc000) /* add ip, sp #n */
576 if ((inst & 0xfffff000) == 0xe24dc000) /* sub ip, sp #n */
579 /* Some prologues begin with "str lr, [sp, #-4]!". */
580 if (inst == 0xe52de004) /* str lr, [sp, #-4]! */
583 if ((inst & 0xfffffff0) == 0xe92d0000) /* stmfd sp!,{a1,a2,a3,a4} */
586 if ((inst & 0xfffff800) == 0xe92dd800) /* stmfd sp!,{fp,ip,lr,pc} */
589 /* Any insns after this point may float into the code, if it makes
590 for better instruction scheduling, so we skip them only if we
591 find them, but still consider the function to be frame-ful. */
593 /* We may have either one sfmfd instruction here, or several stfe
594 insns, depending on the version of floating point code we
596 if ((inst & 0xffbf0fff) == 0xec2d0200) /* sfmfd fn, <cnt>, [sp]! */
599 if ((inst & 0xffff8fff) == 0xed6d0103) /* stfe fn, [sp, #-12]! */
602 if ((inst & 0xfffff000) == 0xe24cb000) /* sub fp, ip, #nn */
605 if ((inst & 0xfffff000) == 0xe24dd000) /* sub sp, sp, #nn */
608 if ((inst & 0xffffc000) == 0xe54b0000 || /* strb r(0123),[r11,#-nn] */
609 (inst & 0xffffc0f0) == 0xe14b00b0 || /* strh r(0123),[r11,#-nn] */
610 (inst & 0xffffc000) == 0xe50b0000) /* str r(0123),[r11,#-nn] */
613 if ((inst & 0xffffc000) == 0xe5cd0000 || /* strb r(0123),[sp,#nn] */
614 (inst & 0xffffc0f0) == 0xe1cd00b0 || /* strh r(0123),[sp,#nn] */
615 (inst & 0xffffc000) == 0xe58d0000) /* str r(0123),[sp,#nn] */
618 /* Un-recognized instruction; stop scanning. */
622 return skip_pc; /* End of prologue */
626 /* Function: thumb_scan_prologue (helper function for arm_scan_prologue)
627 This function decodes a Thumb function prologue to determine:
628 1) the size of the stack frame
629 2) which registers are saved on it
630 3) the offsets of saved regs
631 4) the offset from the stack pointer to the frame pointer
633 A typical Thumb function prologue would create this stack frame
634 (offsets relative to FP)
635 old SP -> 24 stack parameters
638 R7 -> 0 local variables (16 bytes)
639 SP -> -12 additional stack space (12 bytes)
640 The frame size would thus be 36 bytes, and the frame offset would be
641 12 bytes. The frame register is R7.
643 The comments for thumb_skip_prolog() describe the algorithm we use
644 to detect the end of the prolog. */
648 thumb_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR prev_pc,
649 CORE_ADDR block_addr, struct arm_prologue_cache *cache)
651 CORE_ADDR prologue_start;
652 CORE_ADDR prologue_end;
653 CORE_ADDR current_pc;
655 if (find_pc_partial_function (block_addr, NULL, &prologue_start,
658 struct symtab_and_line sal = find_pc_line (prologue_start, 0);
660 if (sal.line == 0) /* no line info, use current PC */
661 prologue_end = prev_pc;
662 else if (sal.end < prologue_end) /* next line begins after fn end */
663 prologue_end = sal.end; /* (probably means no prologue) */
666 /* We're in the boondocks: we have no idea where the start of the
670 prologue_end = min (prologue_end, prev_pc);
672 thumb_analyze_prologue (gdbarch, prologue_start, prologue_end, cache);
675 /* This function decodes an ARM function prologue to determine:
676 1) the size of the stack frame
677 2) which registers are saved on it
678 3) the offsets of saved regs
679 4) the offset from the stack pointer to the frame pointer
680 This information is stored in the "extra" fields of the frame_info.
682 There are two basic forms for the ARM prologue. The fixed argument
683 function call will look like:
686 stmfd sp!, {fp, ip, lr, pc}
690 Which would create this stack frame (offsets relative to FP):
691 IP -> 4 (caller's stack)
692 FP -> 0 PC (points to address of stmfd instruction + 8 in callee)
693 -4 LR (return address in caller)
694 -8 IP (copy of caller's SP)
696 SP -> -28 Local variables
698 The frame size would thus be 32 bytes, and the frame offset would be
699 28 bytes. The stmfd call can also save any of the vN registers it
700 plans to use, which increases the frame size accordingly.
702 Note: The stored PC is 8 off of the STMFD instruction that stored it
703 because the ARM Store instructions always store PC + 8 when you read
706 A variable argument function call will look like:
709 stmfd sp!, {a1, a2, a3, a4}
710 stmfd sp!, {fp, ip, lr, pc}
713 Which would create this stack frame (offsets relative to FP):
714 IP -> 20 (caller's stack)
719 FP -> 0 PC (points to address of stmfd instruction + 8 in callee)
720 -4 LR (return address in caller)
721 -8 IP (copy of caller's SP)
723 SP -> -28 Local variables
725 The frame size would thus be 48 bytes, and the frame offset would be
728 There is another potential complication, which is that the optimizer
729 will try to separate the store of fp in the "stmfd" instruction from
730 the "sub fp, ip, #NN" instruction. Almost anything can be there, so
731 we just key on the stmfd, and then scan for the "sub fp, ip, #NN"...
733 Also, note, the original version of the ARM toolchain claimed that there
736 instruction at the end of the prologue. I have never seen GCC produce
737 this, and the ARM docs don't mention it. We still test for it below in
743 arm_scan_prologue (struct frame_info *this_frame,
744 struct arm_prologue_cache *cache)
746 struct gdbarch *gdbarch = get_frame_arch (this_frame);
747 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
748 enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
750 CORE_ADDR prologue_start, prologue_end, current_pc;
751 CORE_ADDR prev_pc = get_frame_pc (this_frame);
752 CORE_ADDR block_addr = get_frame_address_in_block (this_frame);
753 pv_t regs[ARM_FPS_REGNUM];
754 struct pv_area *stack;
755 struct cleanup *back_to;
758 /* Assume there is no frame until proven otherwise. */
759 cache->framereg = ARM_SP_REGNUM;
760 cache->framesize = 0;
762 /* Check for Thumb prologue. */
763 if (arm_frame_is_thumb (this_frame))
765 thumb_scan_prologue (gdbarch, prev_pc, block_addr, cache);
769 /* Find the function prologue. If we can't find the function in
770 the symbol table, peek in the stack frame to find the PC. */
771 if (find_pc_partial_function (block_addr, NULL, &prologue_start,
774 /* One way to find the end of the prologue (which works well
775 for unoptimized code) is to do the following:
777 struct symtab_and_line sal = find_pc_line (prologue_start, 0);
780 prologue_end = prev_pc;
781 else if (sal.end < prologue_end)
782 prologue_end = sal.end;
784 This mechanism is very accurate so long as the optimizer
785 doesn't move any instructions from the function body into the
786 prologue. If this happens, sal.end will be the last
787 instruction in the first hunk of prologue code just before
788 the first instruction that the scheduler has moved from
789 the body to the prologue.
791 In order to make sure that we scan all of the prologue
792 instructions, we use a slightly less accurate mechanism which
793 may scan more than necessary. To help compensate for this
794 lack of accuracy, the prologue scanning loop below contains
795 several clauses which'll cause the loop to terminate early if
796 an implausible prologue instruction is encountered.
802 is a suitable endpoint since it accounts for the largest
803 possible prologue plus up to five instructions inserted by
806 if (prologue_end > prologue_start + 64)
808 prologue_end = prologue_start + 64; /* See above. */
813 /* We have no symbol information. Our only option is to assume this
814 function has a standard stack frame and the normal frame register.
815 Then, we can find the value of our frame pointer on entrance to
816 the callee (or at the present moment if this is the innermost frame).
817 The value stored there should be the address of the stmfd + 8. */
819 LONGEST return_value;
821 frame_loc = get_frame_register_unsigned (this_frame, ARM_FP_REGNUM);
822 if (!safe_read_memory_integer (frame_loc, 4, byte_order, &return_value))
826 prologue_start = gdbarch_addr_bits_remove
827 (gdbarch, return_value) - 8;
828 prologue_end = prologue_start + 64; /* See above. */
832 if (prev_pc < prologue_end)
833 prologue_end = prev_pc;
835 /* Now search the prologue looking for instructions that set up the
836 frame pointer, adjust the stack pointer, and save registers.
838 Be careful, however, and if it doesn't look like a prologue,
839 don't try to scan it. If, for instance, a frameless function
840 begins with stmfd sp!, then we will tell ourselves there is
841 a frame, which will confuse stack traceback, as well as "finish"
842 and other operations that rely on a knowledge of the stack
845 In the APCS, the prologue should start with "mov ip, sp" so
846 if we don't see this as the first insn, we will stop.
848 [Note: This doesn't seem to be true any longer, so it's now an
849 optional part of the prologue. - Kevin Buettner, 2001-11-20]
851 [Note further: The "mov ip,sp" only seems to be missing in
852 frameless functions at optimization level "-O2" or above,
853 in which case it is often (but not always) replaced by
854 "str lr, [sp, #-4]!". - Michael Snyder, 2002-04-23] */
856 for (regno = 0; regno < ARM_FPS_REGNUM; regno++)
857 regs[regno] = pv_register (regno, 0);
858 stack = make_pv_area (ARM_SP_REGNUM, gdbarch_addr_bit (gdbarch));
859 back_to = make_cleanup_free_pv_area (stack);
861 for (current_pc = prologue_start;
862 current_pc < prologue_end;
866 = read_memory_unsigned_integer (current_pc, 4, byte_order_for_code);
868 if (insn == 0xe1a0c00d) /* mov ip, sp */
870 regs[ARM_IP_REGNUM] = regs[ARM_SP_REGNUM];
873 else if ((insn & 0xfffff000) == 0xe28dc000) /* add ip, sp #n */
875 unsigned imm = insn & 0xff; /* immediate value */
876 unsigned rot = (insn & 0xf00) >> 7; /* rotate amount */
877 imm = (imm >> rot) | (imm << (32 - rot));
878 regs[ARM_IP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM], imm);
881 else if ((insn & 0xfffff000) == 0xe24dc000) /* sub ip, sp #n */
883 unsigned imm = insn & 0xff; /* immediate value */
884 unsigned rot = (insn & 0xf00) >> 7; /* rotate amount */
885 imm = (imm >> rot) | (imm << (32 - rot));
886 regs[ARM_IP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM], -imm);
889 else if (insn == 0xe52de004) /* str lr, [sp, #-4]! */
891 if (pv_area_store_would_trash (stack, regs[ARM_SP_REGNUM]))
893 regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM], -4);
894 pv_area_store (stack, regs[ARM_SP_REGNUM], 4, regs[ARM_LR_REGNUM]);
897 else if ((insn & 0xffff0000) == 0xe92d0000)
898 /* stmfd sp!, {..., fp, ip, lr, pc}
900 stmfd sp!, {a1, a2, a3, a4} */
902 int mask = insn & 0xffff;
904 if (pv_area_store_would_trash (stack, regs[ARM_SP_REGNUM]))
907 /* Calculate offsets of saved registers. */
908 for (regno = ARM_PC_REGNUM; regno >= 0; regno--)
909 if (mask & (1 << regno))
911 regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM], -4);
912 pv_area_store (stack, regs[ARM_SP_REGNUM], 4, regs[regno]);
915 else if ((insn & 0xffffc000) == 0xe54b0000 || /* strb rx,[r11,#-n] */
916 (insn & 0xffffc0f0) == 0xe14b00b0 || /* strh rx,[r11,#-n] */
917 (insn & 0xffffc000) == 0xe50b0000) /* str rx,[r11,#-n] */
919 /* No need to add this to saved_regs -- it's just an arg reg. */
922 else if ((insn & 0xffffc000) == 0xe5cd0000 || /* strb rx,[sp,#n] */
923 (insn & 0xffffc0f0) == 0xe1cd00b0 || /* strh rx,[sp,#n] */
924 (insn & 0xffffc000) == 0xe58d0000) /* str rx,[sp,#n] */
926 /* No need to add this to saved_regs -- it's just an arg reg. */
929 else if ((insn & 0xfffff000) == 0xe24cb000) /* sub fp, ip #n */
931 unsigned imm = insn & 0xff; /* immediate value */
932 unsigned rot = (insn & 0xf00) >> 7; /* rotate amount */
933 imm = (imm >> rot) | (imm << (32 - rot));
934 regs[ARM_FP_REGNUM] = pv_add_constant (regs[ARM_IP_REGNUM], -imm);
936 else if ((insn & 0xfffff000) == 0xe24dd000) /* sub sp, sp #n */
938 unsigned imm = insn & 0xff; /* immediate value */
939 unsigned rot = (insn & 0xf00) >> 7; /* rotate amount */
940 imm = (imm >> rot) | (imm << (32 - rot));
941 regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM], -imm);
943 else if ((insn & 0xffff7fff) == 0xed6d0103 /* stfe f?, [sp, -#c]! */
944 && gdbarch_tdep (gdbarch)->have_fpa_registers)
946 if (pv_area_store_would_trash (stack, regs[ARM_SP_REGNUM]))
949 regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM], -12);
950 regno = ARM_F0_REGNUM + ((insn >> 12) & 0x07);
951 pv_area_store (stack, regs[ARM_SP_REGNUM], 12, regs[regno]);
953 else if ((insn & 0xffbf0fff) == 0xec2d0200 /* sfmfd f0, 4, [sp!] */
954 && gdbarch_tdep (gdbarch)->have_fpa_registers)
957 unsigned int fp_start_reg, fp_bound_reg;
959 if (pv_area_store_would_trash (stack, regs[ARM_SP_REGNUM]))
962 if ((insn & 0x800) == 0x800) /* N0 is set */
964 if ((insn & 0x40000) == 0x40000) /* N1 is set */
971 if ((insn & 0x40000) == 0x40000) /* N1 is set */
977 fp_start_reg = ARM_F0_REGNUM + ((insn >> 12) & 0x7);
978 fp_bound_reg = fp_start_reg + n_saved_fp_regs;
979 for (; fp_start_reg < fp_bound_reg; fp_start_reg++)
981 regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM], -12);
982 pv_area_store (stack, regs[ARM_SP_REGNUM], 12,
983 regs[fp_start_reg++]);
986 else if ((insn & 0xf0000000) != 0xe0000000)
987 break; /* Condition not true, exit early */
988 else if ((insn & 0xfe200000) == 0xe8200000) /* ldm? */
989 break; /* Don't scan past a block load */
991 /* The optimizer might shove anything into the prologue,
992 so we just skip what we don't recognize. */
996 /* The frame size is just the distance from the frame register
997 to the original stack pointer. */
998 if (pv_is_register (regs[ARM_FP_REGNUM], ARM_SP_REGNUM))
1000 /* Frame pointer is fp. */
1001 cache->framereg = ARM_FP_REGNUM;
1002 cache->framesize = -regs[ARM_FP_REGNUM].k;
1004 else if (pv_is_register (regs[ARM_SP_REGNUM], ARM_SP_REGNUM))
1006 /* Try the stack pointer... this is a bit desperate. */
1007 cache->framereg = ARM_SP_REGNUM;
1008 cache->framesize = -regs[ARM_SP_REGNUM].k;
1012 /* We're just out of luck. We don't know where the frame is. */
1013 cache->framereg = -1;
1014 cache->framesize = 0;
1017 for (regno = 0; regno < ARM_FPS_REGNUM; regno++)
1018 if (pv_area_find_reg (stack, gdbarch, regno, &offset))
1019 cache->saved_regs[regno].addr = offset;
1021 do_cleanups (back_to);
1024 static struct arm_prologue_cache *
1025 arm_make_prologue_cache (struct frame_info *this_frame)
1028 struct arm_prologue_cache *cache;
1029 CORE_ADDR unwound_fp;
1031 cache = FRAME_OBSTACK_ZALLOC (struct arm_prologue_cache);
1032 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
1034 arm_scan_prologue (this_frame, cache);
1036 unwound_fp = get_frame_register_unsigned (this_frame, cache->framereg);
1037 if (unwound_fp == 0)
1040 cache->prev_sp = unwound_fp + cache->framesize;
1042 /* Calculate actual addresses of saved registers using offsets
1043 determined by arm_scan_prologue. */
1044 for (reg = 0; reg < gdbarch_num_regs (get_frame_arch (this_frame)); reg++)
1045 if (trad_frame_addr_p (cache->saved_regs, reg))
1046 cache->saved_regs[reg].addr += cache->prev_sp;
1051 /* Our frame ID for a normal frame is the current function's starting PC
1052 and the caller's SP when we were called. */
1055 arm_prologue_this_id (struct frame_info *this_frame,
1057 struct frame_id *this_id)
1059 struct arm_prologue_cache *cache;
1063 if (*this_cache == NULL)
1064 *this_cache = arm_make_prologue_cache (this_frame);
1065 cache = *this_cache;
1067 /* This is meant to halt the backtrace at "_start". */
1068 pc = get_frame_pc (this_frame);
1069 if (pc <= gdbarch_tdep (get_frame_arch (this_frame))->lowest_pc)
1072 /* If we've hit a wall, stop. */
1073 if (cache->prev_sp == 0)
1076 func = get_frame_func (this_frame);
1077 id = frame_id_build (cache->prev_sp, func);
1081 static struct value *
1082 arm_prologue_prev_register (struct frame_info *this_frame,
1086 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1087 struct arm_prologue_cache *cache;
1089 if (*this_cache == NULL)
1090 *this_cache = arm_make_prologue_cache (this_frame);
1091 cache = *this_cache;
1093 /* If we are asked to unwind the PC, then we need to return the LR
1094 instead. The prologue may save PC, but it will point into this
1095 frame's prologue, not the next frame's resume location. Also
1096 strip the saved T bit. A valid LR may have the low bit set, but
1097 a valid PC never does. */
1098 if (prev_regnum == ARM_PC_REGNUM)
1102 lr = frame_unwind_register_unsigned (this_frame, ARM_LR_REGNUM);
1103 return frame_unwind_got_constant (this_frame, prev_regnum,
1104 arm_addr_bits_remove (gdbarch, lr));
1107 /* SP is generally not saved to the stack, but this frame is
1108 identified by the next frame's stack pointer at the time of the call.
1109 The value was already reconstructed into PREV_SP. */
1110 if (prev_regnum == ARM_SP_REGNUM)
1111 return frame_unwind_got_constant (this_frame, prev_regnum, cache->prev_sp);
1113 /* The CPSR may have been changed by the call instruction and by the
1114 called function. The only bit we can reconstruct is the T bit,
1115 by checking the low bit of LR as of the call. This is a reliable
1116 indicator of Thumb-ness except for some ARM v4T pre-interworking
1117 Thumb code, which could get away with a clear low bit as long as
1118 the called function did not use bx. Guess that all other
1119 bits are unchanged; the condition flags are presumably lost,
1120 but the processor status is likely valid. */
1121 if (prev_regnum == ARM_PS_REGNUM)
1125 cpsr = get_frame_register_unsigned (this_frame, prev_regnum);
1126 lr = frame_unwind_register_unsigned (this_frame, ARM_LR_REGNUM);
1127 if (IS_THUMB_ADDR (lr))
1131 return frame_unwind_got_constant (this_frame, prev_regnum, cpsr);
1134 return trad_frame_get_prev_register (this_frame, cache->saved_regs,
1138 struct frame_unwind arm_prologue_unwind = {
1140 arm_prologue_this_id,
1141 arm_prologue_prev_register,
1143 default_frame_sniffer
1146 static struct arm_prologue_cache *
1147 arm_make_stub_cache (struct frame_info *this_frame)
1150 struct arm_prologue_cache *cache;
1151 CORE_ADDR unwound_fp;
1153 cache = FRAME_OBSTACK_ZALLOC (struct arm_prologue_cache);
1154 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
1156 cache->prev_sp = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM);
1161 /* Our frame ID for a stub frame is the current SP and LR. */
1164 arm_stub_this_id (struct frame_info *this_frame,
1166 struct frame_id *this_id)
1168 struct arm_prologue_cache *cache;
1170 if (*this_cache == NULL)
1171 *this_cache = arm_make_stub_cache (this_frame);
1172 cache = *this_cache;
1174 *this_id = frame_id_build (cache->prev_sp, get_frame_pc (this_frame));
1178 arm_stub_unwind_sniffer (const struct frame_unwind *self,
1179 struct frame_info *this_frame,
1180 void **this_prologue_cache)
1182 CORE_ADDR addr_in_block;
1185 addr_in_block = get_frame_address_in_block (this_frame);
1186 if (in_plt_section (addr_in_block, NULL)
1187 || target_read_memory (get_frame_pc (this_frame), dummy, 4) != 0)
1193 struct frame_unwind arm_stub_unwind = {
1196 arm_prologue_prev_register,
1198 arm_stub_unwind_sniffer
1202 arm_normal_frame_base (struct frame_info *this_frame, void **this_cache)
1204 struct arm_prologue_cache *cache;
1206 if (*this_cache == NULL)
1207 *this_cache = arm_make_prologue_cache (this_frame);
1208 cache = *this_cache;
1210 return cache->prev_sp - cache->framesize;
1213 struct frame_base arm_normal_base = {
1214 &arm_prologue_unwind,
1215 arm_normal_frame_base,
1216 arm_normal_frame_base,
1217 arm_normal_frame_base
1220 /* Assuming THIS_FRAME is a dummy, return the frame ID of that
1221 dummy frame. The frame ID's base needs to match the TOS value
1222 saved by save_dummy_frame_tos() and returned from
1223 arm_push_dummy_call, and the PC needs to match the dummy frame's
1226 static struct frame_id
1227 arm_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
1229 return frame_id_build (get_frame_register_unsigned (this_frame, ARM_SP_REGNUM),
1230 get_frame_pc (this_frame));
1233 /* Given THIS_FRAME, find the previous frame's resume PC (which will
1234 be used to construct the previous frame's ID, after looking up the
1235 containing function). */
1238 arm_unwind_pc (struct gdbarch *gdbarch, struct frame_info *this_frame)
1241 pc = frame_unwind_register_unsigned (this_frame, ARM_PC_REGNUM);
1242 return arm_addr_bits_remove (gdbarch, pc);
1246 arm_unwind_sp (struct gdbarch *gdbarch, struct frame_info *this_frame)
1248 return frame_unwind_register_unsigned (this_frame, ARM_SP_REGNUM);
1251 static struct value *
1252 arm_dwarf2_prev_register (struct frame_info *this_frame, void **this_cache,
1255 struct gdbarch * gdbarch = get_frame_arch (this_frame);
1261 /* The PC is normally copied from the return column, which
1262 describes saves of LR. However, that version may have an
1263 extra bit set to indicate Thumb state. The bit is not
1265 lr = frame_unwind_register_unsigned (this_frame, ARM_LR_REGNUM);
1266 return frame_unwind_got_constant (this_frame, regnum,
1267 arm_addr_bits_remove (gdbarch, lr));
1270 /* Reconstruct the T bit; see arm_prologue_prev_register for details. */
1271 cpsr = get_frame_register_unsigned (this_frame, regnum);
1272 lr = frame_unwind_register_unsigned (this_frame, ARM_LR_REGNUM);
1273 if (IS_THUMB_ADDR (lr))
1277 return frame_unwind_got_constant (this_frame, regnum, cpsr);
1280 internal_error (__FILE__, __LINE__,
1281 _("Unexpected register %d"), regnum);
1286 arm_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
1287 struct dwarf2_frame_state_reg *reg,
1288 struct frame_info *this_frame)
1294 reg->how = DWARF2_FRAME_REG_FN;
1295 reg->loc.fn = arm_dwarf2_prev_register;
1298 reg->how = DWARF2_FRAME_REG_CFA;
1303 /* When arguments must be pushed onto the stack, they go on in reverse
1304 order. The code below implements a FILO (stack) to do this. */
1309 struct stack_item *prev;
1313 static struct stack_item *
1314 push_stack_item (struct stack_item *prev, void *contents, int len)
1316 struct stack_item *si;
1317 si = xmalloc (sizeof (struct stack_item));
1318 si->data = xmalloc (len);
1321 memcpy (si->data, contents, len);
1325 static struct stack_item *
1326 pop_stack_item (struct stack_item *si)
1328 struct stack_item *dead = si;
1336 /* Return the alignment (in bytes) of the given type. */
1339 arm_type_align (struct type *t)
1345 t = check_typedef (t);
1346 switch (TYPE_CODE (t))
1349 /* Should never happen. */
1350 internal_error (__FILE__, __LINE__, _("unknown type alignment"));
1354 case TYPE_CODE_ENUM:
1358 case TYPE_CODE_RANGE:
1359 case TYPE_CODE_BITSTRING:
1361 case TYPE_CODE_CHAR:
1362 case TYPE_CODE_BOOL:
1363 return TYPE_LENGTH (t);
1365 case TYPE_CODE_ARRAY:
1366 case TYPE_CODE_COMPLEX:
1367 /* TODO: What about vector types? */
1368 return arm_type_align (TYPE_TARGET_TYPE (t));
1370 case TYPE_CODE_STRUCT:
1371 case TYPE_CODE_UNION:
1373 for (n = 0; n < TYPE_NFIELDS (t); n++)
1375 falign = arm_type_align (TYPE_FIELD_TYPE (t, n));
1383 /* Possible base types for a candidate for passing and returning in
1386 enum arm_vfp_cprc_base_type
1395 /* The length of one element of base type B. */
1398 arm_vfp_cprc_unit_length (enum arm_vfp_cprc_base_type b)
1402 case VFP_CPRC_SINGLE:
1404 case VFP_CPRC_DOUBLE:
1406 case VFP_CPRC_VEC64:
1408 case VFP_CPRC_VEC128:
1411 internal_error (__FILE__, __LINE__, _("Invalid VFP CPRC type: %d."),
1416 /* The character ('s', 'd' or 'q') for the type of VFP register used
1417 for passing base type B. */
1420 arm_vfp_cprc_reg_char (enum arm_vfp_cprc_base_type b)
1424 case VFP_CPRC_SINGLE:
1426 case VFP_CPRC_DOUBLE:
1428 case VFP_CPRC_VEC64:
1430 case VFP_CPRC_VEC128:
1433 internal_error (__FILE__, __LINE__, _("Invalid VFP CPRC type: %d."),
1438 /* Determine whether T may be part of a candidate for passing and
1439 returning in VFP registers, ignoring the limit on the total number
1440 of components. If *BASE_TYPE is VFP_CPRC_UNKNOWN, set it to the
1441 classification of the first valid component found; if it is not
1442 VFP_CPRC_UNKNOWN, all components must have the same classification
1443 as *BASE_TYPE. If it is found that T contains a type not permitted
1444 for passing and returning in VFP registers, a type differently
1445 classified from *BASE_TYPE, or two types differently classified
1446 from each other, return -1, otherwise return the total number of
1447 base-type elements found (possibly 0 in an empty structure or
1448 array). Vectors and complex types are not currently supported,
1449 matching the generic AAPCS support. */
1452 arm_vfp_cprc_sub_candidate (struct type *t,
1453 enum arm_vfp_cprc_base_type *base_type)
1455 t = check_typedef (t);
1456 switch (TYPE_CODE (t))
1459 switch (TYPE_LENGTH (t))
1462 if (*base_type == VFP_CPRC_UNKNOWN)
1463 *base_type = VFP_CPRC_SINGLE;
1464 else if (*base_type != VFP_CPRC_SINGLE)
1469 if (*base_type == VFP_CPRC_UNKNOWN)
1470 *base_type = VFP_CPRC_DOUBLE;
1471 else if (*base_type != VFP_CPRC_DOUBLE)
1480 case TYPE_CODE_ARRAY:
1484 count = arm_vfp_cprc_sub_candidate (TYPE_TARGET_TYPE (t), base_type);
1487 if (TYPE_LENGTH (t) == 0)
1489 gdb_assert (count == 0);
1492 else if (count == 0)
1494 unitlen = arm_vfp_cprc_unit_length (*base_type);
1495 gdb_assert ((TYPE_LENGTH (t) % unitlen) == 0);
1496 return TYPE_LENGTH (t) / unitlen;
1500 case TYPE_CODE_STRUCT:
1505 for (i = 0; i < TYPE_NFIELDS (t); i++)
1507 int sub_count = arm_vfp_cprc_sub_candidate (TYPE_FIELD_TYPE (t, i),
1509 if (sub_count == -1)
1513 if (TYPE_LENGTH (t) == 0)
1515 gdb_assert (count == 0);
1518 else if (count == 0)
1520 unitlen = arm_vfp_cprc_unit_length (*base_type);
1521 if (TYPE_LENGTH (t) != unitlen * count)
1526 case TYPE_CODE_UNION:
1531 for (i = 0; i < TYPE_NFIELDS (t); i++)
1533 int sub_count = arm_vfp_cprc_sub_candidate (TYPE_FIELD_TYPE (t, i),
1535 if (sub_count == -1)
1537 count = (count > sub_count ? count : sub_count);
1539 if (TYPE_LENGTH (t) == 0)
1541 gdb_assert (count == 0);
1544 else if (count == 0)
1546 unitlen = arm_vfp_cprc_unit_length (*base_type);
1547 if (TYPE_LENGTH (t) != unitlen * count)
1559 /* Determine whether T is a VFP co-processor register candidate (CPRC)
1560 if passed to or returned from a non-variadic function with the VFP
1561 ABI in effect. Return 1 if it is, 0 otherwise. If it is, set
1562 *BASE_TYPE to the base type for T and *COUNT to the number of
1563 elements of that base type before returning. */
1566 arm_vfp_call_candidate (struct type *t, enum arm_vfp_cprc_base_type *base_type,
1569 enum arm_vfp_cprc_base_type b = VFP_CPRC_UNKNOWN;
1570 int c = arm_vfp_cprc_sub_candidate (t, &b);
1571 if (c <= 0 || c > 4)
1578 /* Return 1 if the VFP ABI should be used for passing arguments to and
1579 returning values from a function of type FUNC_TYPE, 0
1583 arm_vfp_abi_for_function (struct gdbarch *gdbarch, struct type *func_type)
1585 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1586 /* Variadic functions always use the base ABI. Assume that functions
1587 without debug info are not variadic. */
1588 if (func_type && TYPE_VARARGS (check_typedef (func_type)))
1590 /* The VFP ABI is only supported as a variant of AAPCS. */
1591 if (tdep->arm_abi != ARM_ABI_AAPCS)
1593 return gdbarch_tdep (gdbarch)->fp_model == ARM_FLOAT_VFP;
1596 /* We currently only support passing parameters in integer registers, which
1597 conforms with GCC's default model, and VFP argument passing following
1598 the VFP variant of AAPCS. Several other variants exist and
1599 we should probably support some of them based on the selected ABI. */
1602 arm_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
1603 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
1604 struct value **args, CORE_ADDR sp, int struct_return,
1605 CORE_ADDR struct_addr)
1607 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1611 struct stack_item *si = NULL;
1614 unsigned vfp_regs_free = (1 << 16) - 1;
1616 /* Determine the type of this function and whether the VFP ABI
1618 ftype = check_typedef (value_type (function));
1619 if (TYPE_CODE (ftype) == TYPE_CODE_PTR)
1620 ftype = check_typedef (TYPE_TARGET_TYPE (ftype));
1621 use_vfp_abi = arm_vfp_abi_for_function (gdbarch, ftype);
1623 /* Set the return address. For the ARM, the return breakpoint is
1624 always at BP_ADDR. */
1625 /* XXX Fix for Thumb. */
1626 regcache_cooked_write_unsigned (regcache, ARM_LR_REGNUM, bp_addr);
1628 /* Walk through the list of args and determine how large a temporary
1629 stack is required. Need to take care here as structs may be
1630 passed on the stack, and we have to to push them. */
1633 argreg = ARM_A1_REGNUM;
1636 /* The struct_return pointer occupies the first parameter
1637 passing register. */
1641 fprintf_unfiltered (gdb_stdlog, "struct return in %s = %s\n",
1642 gdbarch_register_name (gdbarch, argreg),
1643 paddress (gdbarch, struct_addr));
1644 regcache_cooked_write_unsigned (regcache, argreg, struct_addr);
1648 for (argnum = 0; argnum < nargs; argnum++)
1651 struct type *arg_type;
1652 struct type *target_type;
1653 enum type_code typecode;
1656 enum arm_vfp_cprc_base_type vfp_base_type;
1658 int may_use_core_reg = 1;
1660 arg_type = check_typedef (value_type (args[argnum]));
1661 len = TYPE_LENGTH (arg_type);
1662 target_type = TYPE_TARGET_TYPE (arg_type);
1663 typecode = TYPE_CODE (arg_type);
1664 val = value_contents_writeable (args[argnum]);
1666 align = arm_type_align (arg_type);
1667 /* Round alignment up to a whole number of words. */
1668 align = (align + INT_REGISTER_SIZE - 1) & ~(INT_REGISTER_SIZE - 1);
1669 /* Different ABIs have different maximum alignments. */
1670 if (gdbarch_tdep (gdbarch)->arm_abi == ARM_ABI_APCS)
1672 /* The APCS ABI only requires word alignment. */
1673 align = INT_REGISTER_SIZE;
1677 /* The AAPCS requires at most doubleword alignment. */
1678 if (align > INT_REGISTER_SIZE * 2)
1679 align = INT_REGISTER_SIZE * 2;
1683 && arm_vfp_call_candidate (arg_type, &vfp_base_type,
1691 /* Because this is a CPRC it cannot go in a core register or
1692 cause a core register to be skipped for alignment.
1693 Either it goes in VFP registers and the rest of this loop
1694 iteration is skipped for this argument, or it goes on the
1695 stack (and the stack alignment code is correct for this
1697 may_use_core_reg = 0;
1699 unit_length = arm_vfp_cprc_unit_length (vfp_base_type);
1700 shift = unit_length / 4;
1701 mask = (1 << (shift * vfp_base_count)) - 1;
1702 for (regno = 0; regno < 16; regno += shift)
1703 if (((vfp_regs_free >> regno) & mask) == mask)
1712 vfp_regs_free &= ~(mask << regno);
1713 reg_scaled = regno / shift;
1714 reg_char = arm_vfp_cprc_reg_char (vfp_base_type);
1715 for (i = 0; i < vfp_base_count; i++)
1719 if (reg_char == 'q')
1720 arm_neon_quad_write (gdbarch, regcache, reg_scaled + i,
1721 val + i * unit_length);
1724 sprintf (name_buf, "%c%d", reg_char, reg_scaled + i);
1725 regnum = user_reg_map_name_to_regnum (gdbarch, name_buf,
1727 regcache_cooked_write (regcache, regnum,
1728 val + i * unit_length);
1735 /* This CPRC could not go in VFP registers, so all VFP
1736 registers are now marked as used. */
1741 /* Push stack padding for dowubleword alignment. */
1742 if (nstack & (align - 1))
1744 si = push_stack_item (si, val, INT_REGISTER_SIZE);
1745 nstack += INT_REGISTER_SIZE;
1748 /* Doubleword aligned quantities must go in even register pairs. */
1749 if (may_use_core_reg
1750 && argreg <= ARM_LAST_ARG_REGNUM
1751 && align > INT_REGISTER_SIZE
1755 /* If the argument is a pointer to a function, and it is a
1756 Thumb function, create a LOCAL copy of the value and set
1757 the THUMB bit in it. */
1758 if (TYPE_CODE_PTR == typecode
1759 && target_type != NULL
1760 && TYPE_CODE_FUNC == TYPE_CODE (target_type))
1762 CORE_ADDR regval = extract_unsigned_integer (val, len, byte_order);
1763 if (arm_pc_is_thumb (regval))
1766 store_unsigned_integer (val, len, byte_order,
1767 MAKE_THUMB_ADDR (regval));
1771 /* Copy the argument to general registers or the stack in
1772 register-sized pieces. Large arguments are split between
1773 registers and stack. */
1776 int partial_len = len < INT_REGISTER_SIZE ? len : INT_REGISTER_SIZE;
1778 if (may_use_core_reg && argreg <= ARM_LAST_ARG_REGNUM)
1780 /* The argument is being passed in a general purpose
1783 = extract_unsigned_integer (val, partial_len, byte_order);
1784 if (byte_order == BFD_ENDIAN_BIG)
1785 regval <<= (INT_REGISTER_SIZE - partial_len) * 8;
1787 fprintf_unfiltered (gdb_stdlog, "arg %d in %s = 0x%s\n",
1789 gdbarch_register_name
1791 phex (regval, INT_REGISTER_SIZE));
1792 regcache_cooked_write_unsigned (regcache, argreg, regval);
1797 /* Push the arguments onto the stack. */
1799 fprintf_unfiltered (gdb_stdlog, "arg %d @ sp + %d\n",
1801 si = push_stack_item (si, val, INT_REGISTER_SIZE);
1802 nstack += INT_REGISTER_SIZE;
1809 /* If we have an odd number of words to push, then decrement the stack
1810 by one word now, so first stack argument will be dword aligned. */
1817 write_memory (sp, si->data, si->len);
1818 si = pop_stack_item (si);
1821 /* Finally, update teh SP register. */
1822 regcache_cooked_write_unsigned (regcache, ARM_SP_REGNUM, sp);
1828 /* Always align the frame to an 8-byte boundary. This is required on
1829 some platforms and harmless on the rest. */
1832 arm_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
1834 /* Align the stack to eight bytes. */
1835 return sp & ~ (CORE_ADDR) 7;
1839 print_fpu_flags (int flags)
1841 if (flags & (1 << 0))
1842 fputs ("IVO ", stdout);
1843 if (flags & (1 << 1))
1844 fputs ("DVZ ", stdout);
1845 if (flags & (1 << 2))
1846 fputs ("OFL ", stdout);
1847 if (flags & (1 << 3))
1848 fputs ("UFL ", stdout);
1849 if (flags & (1 << 4))
1850 fputs ("INX ", stdout);
1854 /* Print interesting information about the floating point processor
1855 (if present) or emulator. */
1857 arm_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
1858 struct frame_info *frame, const char *args)
1860 unsigned long status = get_frame_register_unsigned (frame, ARM_FPS_REGNUM);
1863 type = (status >> 24) & 127;
1864 if (status & (1 << 31))
1865 printf (_("Hardware FPU type %d\n"), type);
1867 printf (_("Software FPU type %d\n"), type);
1868 /* i18n: [floating point unit] mask */
1869 fputs (_("mask: "), stdout);
1870 print_fpu_flags (status >> 16);
1871 /* i18n: [floating point unit] flags */
1872 fputs (_("flags: "), stdout);
1873 print_fpu_flags (status);
1876 /* Construct the ARM extended floating point type. */
1877 static struct type *
1878 arm_ext_type (struct gdbarch *gdbarch)
1880 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1882 if (!tdep->arm_ext_type)
1884 = arch_float_type (gdbarch, -1, "builtin_type_arm_ext",
1885 floatformats_arm_ext);
1887 return tdep->arm_ext_type;
1890 static struct type *
1891 arm_neon_double_type (struct gdbarch *gdbarch)
1893 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1895 if (tdep->neon_double_type == NULL)
1897 struct type *t, *elem;
1899 t = arch_composite_type (gdbarch, "__gdb_builtin_type_neon_d",
1901 elem = builtin_type (gdbarch)->builtin_uint8;
1902 append_composite_type_field (t, "u8", init_vector_type (elem, 8));
1903 elem = builtin_type (gdbarch)->builtin_uint16;
1904 append_composite_type_field (t, "u16", init_vector_type (elem, 4));
1905 elem = builtin_type (gdbarch)->builtin_uint32;
1906 append_composite_type_field (t, "u32", init_vector_type (elem, 2));
1907 elem = builtin_type (gdbarch)->builtin_uint64;
1908 append_composite_type_field (t, "u64", elem);
1909 elem = builtin_type (gdbarch)->builtin_float;
1910 append_composite_type_field (t, "f32", init_vector_type (elem, 2));
1911 elem = builtin_type (gdbarch)->builtin_double;
1912 append_composite_type_field (t, "f64", elem);
1914 TYPE_VECTOR (t) = 1;
1915 TYPE_NAME (t) = "neon_d";
1916 tdep->neon_double_type = t;
1919 return tdep->neon_double_type;
1922 /* FIXME: The vector types are not correctly ordered on big-endian
1923 targets. Just as s0 is the low bits of d0, d0[0] is also the low
1924 bits of d0 - regardless of what unit size is being held in d0. So
1925 the offset of the first uint8 in d0 is 7, but the offset of the
1926 first float is 4. This code works as-is for little-endian
1929 static struct type *
1930 arm_neon_quad_type (struct gdbarch *gdbarch)
1932 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1934 if (tdep->neon_quad_type == NULL)
1936 struct type *t, *elem;
1938 t = arch_composite_type (gdbarch, "__gdb_builtin_type_neon_q",
1940 elem = builtin_type (gdbarch)->builtin_uint8;
1941 append_composite_type_field (t, "u8", init_vector_type (elem, 16));
1942 elem = builtin_type (gdbarch)->builtin_uint16;
1943 append_composite_type_field (t, "u16", init_vector_type (elem, 8));
1944 elem = builtin_type (gdbarch)->builtin_uint32;
1945 append_composite_type_field (t, "u32", init_vector_type (elem, 4));
1946 elem = builtin_type (gdbarch)->builtin_uint64;
1947 append_composite_type_field (t, "u64", init_vector_type (elem, 2));
1948 elem = builtin_type (gdbarch)->builtin_float;
1949 append_composite_type_field (t, "f32", init_vector_type (elem, 4));
1950 elem = builtin_type (gdbarch)->builtin_double;
1951 append_composite_type_field (t, "f64", init_vector_type (elem, 2));
1953 TYPE_VECTOR (t) = 1;
1954 TYPE_NAME (t) = "neon_q";
1955 tdep->neon_quad_type = t;
1958 return tdep->neon_quad_type;
1961 /* Return the GDB type object for the "standard" data type of data in
1964 static struct type *
1965 arm_register_type (struct gdbarch *gdbarch, int regnum)
1967 int num_regs = gdbarch_num_regs (gdbarch);
1969 if (gdbarch_tdep (gdbarch)->have_vfp_pseudos
1970 && regnum >= num_regs && regnum < num_regs + 32)
1971 return builtin_type (gdbarch)->builtin_float;
1973 if (gdbarch_tdep (gdbarch)->have_neon_pseudos
1974 && regnum >= num_regs + 32 && regnum < num_regs + 32 + 16)
1975 return arm_neon_quad_type (gdbarch);
1977 /* If the target description has register information, we are only
1978 in this function so that we can override the types of
1979 double-precision registers for NEON. */
1980 if (tdesc_has_registers (gdbarch_target_desc (gdbarch)))
1982 struct type *t = tdesc_register_type (gdbarch, regnum);
1984 if (regnum >= ARM_D0_REGNUM && regnum < ARM_D0_REGNUM + 32
1985 && TYPE_CODE (t) == TYPE_CODE_FLT
1986 && gdbarch_tdep (gdbarch)->have_neon)
1987 return arm_neon_double_type (gdbarch);
1992 if (regnum >= ARM_F0_REGNUM && regnum < ARM_F0_REGNUM + NUM_FREGS)
1994 if (!gdbarch_tdep (gdbarch)->have_fpa_registers)
1995 return builtin_type (gdbarch)->builtin_void;
1997 return arm_ext_type (gdbarch);
1999 else if (regnum == ARM_SP_REGNUM)
2000 return builtin_type (gdbarch)->builtin_data_ptr;
2001 else if (regnum == ARM_PC_REGNUM)
2002 return builtin_type (gdbarch)->builtin_func_ptr;
2003 else if (regnum >= ARRAY_SIZE (arm_register_names))
2004 /* These registers are only supported on targets which supply
2005 an XML description. */
2006 return builtin_type (gdbarch)->builtin_int0;
2008 return builtin_type (gdbarch)->builtin_uint32;
2011 /* Map a DWARF register REGNUM onto the appropriate GDB register
2015 arm_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
2017 /* Core integer regs. */
2018 if (reg >= 0 && reg <= 15)
2021 /* Legacy FPA encoding. These were once used in a way which
2022 overlapped with VFP register numbering, so their use is
2023 discouraged, but GDB doesn't support the ARM toolchain
2024 which used them for VFP. */
2025 if (reg >= 16 && reg <= 23)
2026 return ARM_F0_REGNUM + reg - 16;
2028 /* New assignments for the FPA registers. */
2029 if (reg >= 96 && reg <= 103)
2030 return ARM_F0_REGNUM + reg - 96;
2032 /* WMMX register assignments. */
2033 if (reg >= 104 && reg <= 111)
2034 return ARM_WCGR0_REGNUM + reg - 104;
2036 if (reg >= 112 && reg <= 127)
2037 return ARM_WR0_REGNUM + reg - 112;
2039 if (reg >= 192 && reg <= 199)
2040 return ARM_WC0_REGNUM + reg - 192;
2042 /* VFP v2 registers. A double precision value is actually
2043 in d1 rather than s2, but the ABI only defines numbering
2044 for the single precision registers. This will "just work"
2045 in GDB for little endian targets (we'll read eight bytes,
2046 starting in s0 and then progressing to s1), but will be
2047 reversed on big endian targets with VFP. This won't
2048 be a problem for the new Neon quad registers; you're supposed
2049 to use DW_OP_piece for those. */
2050 if (reg >= 64 && reg <= 95)
2054 sprintf (name_buf, "s%d", reg - 64);
2055 return user_reg_map_name_to_regnum (gdbarch, name_buf,
2059 /* VFP v3 / Neon registers. This range is also used for VFP v2
2060 registers, except that it now describes d0 instead of s0. */
2061 if (reg >= 256 && reg <= 287)
2065 sprintf (name_buf, "d%d", reg - 256);
2066 return user_reg_map_name_to_regnum (gdbarch, name_buf,
2073 /* Map GDB internal REGNUM onto the Arm simulator register numbers. */
2075 arm_register_sim_regno (struct gdbarch *gdbarch, int regnum)
2078 gdb_assert (reg >= 0 && reg < gdbarch_num_regs (gdbarch));
2080 if (regnum >= ARM_WR0_REGNUM && regnum <= ARM_WR15_REGNUM)
2081 return regnum - ARM_WR0_REGNUM + SIM_ARM_IWMMXT_COP0R0_REGNUM;
2083 if (regnum >= ARM_WC0_REGNUM && regnum <= ARM_WC7_REGNUM)
2084 return regnum - ARM_WC0_REGNUM + SIM_ARM_IWMMXT_COP1R0_REGNUM;
2086 if (regnum >= ARM_WCGR0_REGNUM && regnum <= ARM_WCGR7_REGNUM)
2087 return regnum - ARM_WCGR0_REGNUM + SIM_ARM_IWMMXT_COP1R8_REGNUM;
2089 if (reg < NUM_GREGS)
2090 return SIM_ARM_R0_REGNUM + reg;
2093 if (reg < NUM_FREGS)
2094 return SIM_ARM_FP0_REGNUM + reg;
2097 if (reg < NUM_SREGS)
2098 return SIM_ARM_FPS_REGNUM + reg;
2101 internal_error (__FILE__, __LINE__, _("Bad REGNUM %d"), regnum);
2104 /* NOTE: cagney/2001-08-20: Both convert_from_extended() and
2105 convert_to_extended() use floatformat_arm_ext_littlebyte_bigword.
2106 It is thought that this is is the floating-point register format on
2107 little-endian systems. */
2110 convert_from_extended (const struct floatformat *fmt, const void *ptr,
2111 void *dbl, int endianess)
2115 if (endianess == BFD_ENDIAN_BIG)
2116 floatformat_to_doublest (&floatformat_arm_ext_big, ptr, &d);
2118 floatformat_to_doublest (&floatformat_arm_ext_littlebyte_bigword,
2120 floatformat_from_doublest (fmt, &d, dbl);
2124 convert_to_extended (const struct floatformat *fmt, void *dbl, const void *ptr,
2129 floatformat_to_doublest (fmt, ptr, &d);
2130 if (endianess == BFD_ENDIAN_BIG)
2131 floatformat_from_doublest (&floatformat_arm_ext_big, &d, dbl);
2133 floatformat_from_doublest (&floatformat_arm_ext_littlebyte_bigword,
2138 condition_true (unsigned long cond, unsigned long status_reg)
2140 if (cond == INST_AL || cond == INST_NV)
2146 return ((status_reg & FLAG_Z) != 0);
2148 return ((status_reg & FLAG_Z) == 0);
2150 return ((status_reg & FLAG_C) != 0);
2152 return ((status_reg & FLAG_C) == 0);
2154 return ((status_reg & FLAG_N) != 0);
2156 return ((status_reg & FLAG_N) == 0);
2158 return ((status_reg & FLAG_V) != 0);
2160 return ((status_reg & FLAG_V) == 0);
2162 return ((status_reg & (FLAG_C | FLAG_Z)) == FLAG_C);
2164 return ((status_reg & (FLAG_C | FLAG_Z)) != FLAG_C);
2166 return (((status_reg & FLAG_N) == 0) == ((status_reg & FLAG_V) == 0));
2168 return (((status_reg & FLAG_N) == 0) != ((status_reg & FLAG_V) == 0));
2170 return (((status_reg & FLAG_Z) == 0) &&
2171 (((status_reg & FLAG_N) == 0) == ((status_reg & FLAG_V) == 0)));
2173 return (((status_reg & FLAG_Z) != 0) ||
2174 (((status_reg & FLAG_N) == 0) != ((status_reg & FLAG_V) == 0)));
2179 /* Support routines for single stepping. Calculate the next PC value. */
2180 #define submask(x) ((1L << ((x) + 1)) - 1)
2181 #define bit(obj,st) (((obj) >> (st)) & 1)
2182 #define bits(obj,st,fn) (((obj) >> (st)) & submask ((fn) - (st)))
2183 #define sbits(obj,st,fn) \
2184 ((long) (bits(obj,st,fn) | ((long) bit(obj,fn) * ~ submask (fn - st))))
2185 #define BranchDest(addr,instr) \
2186 ((CORE_ADDR) (((long) (addr)) + 8 + (sbits (instr, 0, 23) << 2)))
2189 static unsigned long
2190 shifted_reg_val (struct frame_info *frame, unsigned long inst, int carry,
2191 unsigned long pc_val, unsigned long status_reg)
2193 unsigned long res, shift;
2194 int rm = bits (inst, 0, 3);
2195 unsigned long shifttype = bits (inst, 5, 6);
2199 int rs = bits (inst, 8, 11);
2200 shift = (rs == 15 ? pc_val + 8
2201 : get_frame_register_unsigned (frame, rs)) & 0xFF;
2204 shift = bits (inst, 7, 11);
2207 ? ((pc_val | (ARM_PC_32 ? 0 : status_reg))
2208 + (bit (inst, 4) ? 12 : 8))
2209 : get_frame_register_unsigned (frame, rm));
2214 res = shift >= 32 ? 0 : res << shift;
2218 res = shift >= 32 ? 0 : res >> shift;
2224 res = ((res & 0x80000000L)
2225 ? ~((~res) >> shift) : res >> shift);
2228 case 3: /* ROR/RRX */
2231 res = (res >> 1) | (carry ? 0x80000000L : 0);
2233 res = (res >> shift) | (res << (32 - shift));
2237 return res & 0xffffffff;
2240 /* Return number of 1-bits in VAL. */
2243 bitcount (unsigned long val)
2246 for (nbits = 0; val != 0; nbits++)
2247 val &= val - 1; /* delete rightmost 1-bit in val */
2252 thumb_get_next_pc (struct frame_info *frame, CORE_ADDR pc)
2254 struct gdbarch *gdbarch = get_frame_arch (frame);
2255 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2256 enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
2257 unsigned long pc_val = ((unsigned long) pc) + 4; /* PC after prefetch */
2258 unsigned short inst1;
2259 CORE_ADDR nextpc = pc + 2; /* default is next instruction */
2260 unsigned long offset;
2262 inst1 = read_memory_unsigned_integer (pc, 2, byte_order_for_code);
2264 if ((inst1 & 0xff00) == 0xbd00) /* pop {rlist, pc} */
2268 /* Fetch the saved PC from the stack. It's stored above
2269 all of the other registers. */
2270 offset = bitcount (bits (inst1, 0, 7)) * INT_REGISTER_SIZE;
2271 sp = get_frame_register_unsigned (frame, ARM_SP_REGNUM);
2272 nextpc = read_memory_unsigned_integer (sp + offset, 4, byte_order);
2273 nextpc = gdbarch_addr_bits_remove (gdbarch, nextpc);
2275 error (_("Infinite loop detected"));
2277 else if ((inst1 & 0xf000) == 0xd000) /* conditional branch */
2279 unsigned long status = get_frame_register_unsigned (frame, ARM_PS_REGNUM);
2280 unsigned long cond = bits (inst1, 8, 11);
2281 if (cond != 0x0f && condition_true (cond, status)) /* 0x0f = SWI */
2282 nextpc = pc_val + (sbits (inst1, 0, 7) << 1);
2284 else if ((inst1 & 0xf800) == 0xe000) /* unconditional branch */
2286 nextpc = pc_val + (sbits (inst1, 0, 10) << 1);
2288 else if ((inst1 & 0xf800) == 0xf000) /* long branch with link, and blx */
2290 unsigned short inst2;
2291 inst2 = read_memory_unsigned_integer (pc + 2, 2, byte_order_for_code);
2292 offset = (sbits (inst1, 0, 10) << 12) + (bits (inst2, 0, 10) << 1);
2293 nextpc = pc_val + offset;
2294 /* For BLX make sure to clear the low bits. */
2295 if (bits (inst2, 11, 12) == 1)
2296 nextpc = nextpc & 0xfffffffc;
2298 else if ((inst1 & 0xff00) == 0x4700) /* bx REG, blx REG */
2300 if (bits (inst1, 3, 6) == 0x0f)
2303 nextpc = get_frame_register_unsigned (frame, bits (inst1, 3, 6));
2305 nextpc = gdbarch_addr_bits_remove (gdbarch, nextpc);
2307 error (_("Infinite loop detected"));
2314 arm_get_next_pc (struct frame_info *frame, CORE_ADDR pc)
2316 struct gdbarch *gdbarch = get_frame_arch (frame);
2317 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2318 enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
2319 unsigned long pc_val;
2320 unsigned long this_instr;
2321 unsigned long status;
2324 if (arm_frame_is_thumb (frame))
2325 return thumb_get_next_pc (frame, pc);
2327 pc_val = (unsigned long) pc;
2328 this_instr = read_memory_unsigned_integer (pc, 4, byte_order_for_code);
2330 status = get_frame_register_unsigned (frame, ARM_PS_REGNUM);
2331 nextpc = (CORE_ADDR) (pc_val + 4); /* Default case */
2333 if (bits (this_instr, 28, 31) == INST_NV)
2334 switch (bits (this_instr, 24, 27))
2339 /* Branch with Link and change to Thumb. */
2340 nextpc = BranchDest (pc, this_instr);
2341 nextpc |= bit (this_instr, 24) << 1;
2343 nextpc = gdbarch_addr_bits_remove (gdbarch, nextpc);
2345 error (_("Infinite loop detected"));
2351 /* Coprocessor register transfer. */
2352 if (bits (this_instr, 12, 15) == 15)
2353 error (_("Invalid update to pc in instruction"));
2356 else if (condition_true (bits (this_instr, 28, 31), status))
2358 switch (bits (this_instr, 24, 27))
2361 case 0x1: /* data processing */
2365 unsigned long operand1, operand2, result = 0;
2369 if (bits (this_instr, 12, 15) != 15)
2372 if (bits (this_instr, 22, 25) == 0
2373 && bits (this_instr, 4, 7) == 9) /* multiply */
2374 error (_("Invalid update to pc in instruction"));
2376 /* BX <reg>, BLX <reg> */
2377 if (bits (this_instr, 4, 27) == 0x12fff1
2378 || bits (this_instr, 4, 27) == 0x12fff3)
2380 rn = bits (this_instr, 0, 3);
2381 result = (rn == 15) ? pc_val + 8
2382 : get_frame_register_unsigned (frame, rn);
2383 nextpc = (CORE_ADDR) gdbarch_addr_bits_remove
2387 error (_("Infinite loop detected"));
2392 /* Multiply into PC */
2393 c = (status & FLAG_C) ? 1 : 0;
2394 rn = bits (this_instr, 16, 19);
2395 operand1 = (rn == 15) ? pc_val + 8
2396 : get_frame_register_unsigned (frame, rn);
2398 if (bit (this_instr, 25))
2400 unsigned long immval = bits (this_instr, 0, 7);
2401 unsigned long rotate = 2 * bits (this_instr, 8, 11);
2402 operand2 = ((immval >> rotate) | (immval << (32 - rotate)))
2405 else /* operand 2 is a shifted register */
2406 operand2 = shifted_reg_val (frame, this_instr, c, pc_val, status);
2408 switch (bits (this_instr, 21, 24))
2411 result = operand1 & operand2;
2415 result = operand1 ^ operand2;
2419 result = operand1 - operand2;
2423 result = operand2 - operand1;
2427 result = operand1 + operand2;
2431 result = operand1 + operand2 + c;
2435 result = operand1 - operand2 + c;
2439 result = operand2 - operand1 + c;
2445 case 0xb: /* tst, teq, cmp, cmn */
2446 result = (unsigned long) nextpc;
2450 result = operand1 | operand2;
2454 /* Always step into a function. */
2459 result = operand1 & ~operand2;
2466 nextpc = (CORE_ADDR) gdbarch_addr_bits_remove
2470 error (_("Infinite loop detected"));
2475 case 0x5: /* data transfer */
2478 if (bit (this_instr, 20))
2481 if (bits (this_instr, 12, 15) == 15)
2487 if (bit (this_instr, 22))
2488 error (_("Invalid update to pc in instruction"));
2490 /* byte write to PC */
2491 rn = bits (this_instr, 16, 19);
2492 base = (rn == 15) ? pc_val + 8
2493 : get_frame_register_unsigned (frame, rn);
2494 if (bit (this_instr, 24))
2497 int c = (status & FLAG_C) ? 1 : 0;
2498 unsigned long offset =
2499 (bit (this_instr, 25)
2500 ? shifted_reg_val (frame, this_instr, c, pc_val, status)
2501 : bits (this_instr, 0, 11));
2503 if (bit (this_instr, 23))
2508 nextpc = (CORE_ADDR) read_memory_integer ((CORE_ADDR) base,
2511 nextpc = gdbarch_addr_bits_remove (gdbarch, nextpc);
2514 error (_("Infinite loop detected"));
2520 case 0x9: /* block transfer */
2521 if (bit (this_instr, 20))
2524 if (bit (this_instr, 15))
2529 if (bit (this_instr, 23))
2532 unsigned long reglist = bits (this_instr, 0, 14);
2533 offset = bitcount (reglist) * 4;
2534 if (bit (this_instr, 24)) /* pre */
2537 else if (bit (this_instr, 24))
2541 unsigned long rn_val =
2542 get_frame_register_unsigned (frame,
2543 bits (this_instr, 16, 19));
2545 (CORE_ADDR) read_memory_integer ((CORE_ADDR) (rn_val
2549 nextpc = gdbarch_addr_bits_remove
2552 error (_("Infinite loop detected"));
2557 case 0xb: /* branch & link */
2558 case 0xa: /* branch */
2560 nextpc = BranchDest (pc, this_instr);
2562 nextpc = gdbarch_addr_bits_remove (gdbarch, nextpc);
2564 error (_("Infinite loop detected"));
2570 case 0xe: /* coproc ops */
2575 fprintf_filtered (gdb_stderr, _("Bad bit-field extraction\n"));
2583 /* single_step() is called just before we want to resume the inferior,
2584 if we want to single-step it but there is no hardware or kernel
2585 single-step support. We find the target of the coming instruction
2586 and breakpoint it. */
2589 arm_software_single_step (struct frame_info *frame)
2591 struct gdbarch *gdbarch = get_frame_arch (frame);
2593 /* NOTE: This may insert the wrong breakpoint instruction when
2594 single-stepping over a mode-changing instruction, if the
2595 CPSR heuristics are used. */
2597 CORE_ADDR next_pc = arm_get_next_pc (frame, get_frame_pc (frame));
2598 insert_single_step_breakpoint (gdbarch, next_pc);
2603 #include "bfd-in2.h"
2604 #include "libcoff.h"
2607 gdb_print_insn_arm (bfd_vma memaddr, disassemble_info *info)
2609 if (arm_pc_is_thumb (memaddr))
2611 static asymbol *asym;
2612 static combined_entry_type ce;
2613 static struct coff_symbol_struct csym;
2614 static struct bfd fake_bfd;
2615 static bfd_target fake_target;
2617 if (csym.native == NULL)
2619 /* Create a fake symbol vector containing a Thumb symbol.
2620 This is solely so that the code in print_insn_little_arm()
2621 and print_insn_big_arm() in opcodes/arm-dis.c will detect
2622 the presence of a Thumb symbol and switch to decoding
2623 Thumb instructions. */
2625 fake_target.flavour = bfd_target_coff_flavour;
2626 fake_bfd.xvec = &fake_target;
2627 ce.u.syment.n_sclass = C_THUMBEXTFUNC;
2629 csym.symbol.the_bfd = &fake_bfd;
2630 csym.symbol.name = "fake";
2631 asym = (asymbol *) & csym;
2634 memaddr = UNMAKE_THUMB_ADDR (memaddr);
2635 info->symbols = &asym;
2638 info->symbols = NULL;
2640 if (info->endian == BFD_ENDIAN_BIG)
2641 return print_insn_big_arm (memaddr, info);
2643 return print_insn_little_arm (memaddr, info);
2646 /* The following define instruction sequences that will cause ARM
2647 cpu's to take an undefined instruction trap. These are used to
2648 signal a breakpoint to GDB.
2650 The newer ARMv4T cpu's are capable of operating in ARM or Thumb
2651 modes. A different instruction is required for each mode. The ARM
2652 cpu's can also be big or little endian. Thus four different
2653 instructions are needed to support all cases.
2655 Note: ARMv4 defines several new instructions that will take the
2656 undefined instruction trap. ARM7TDMI is nominally ARMv4T, but does
2657 not in fact add the new instructions. The new undefined
2658 instructions in ARMv4 are all instructions that had no defined
2659 behaviour in earlier chips. There is no guarantee that they will
2660 raise an exception, but may be treated as NOP's. In practice, it
2661 may only safe to rely on instructions matching:
2663 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
2664 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
2665 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
2667 Even this may only true if the condition predicate is true. The
2668 following use a condition predicate of ALWAYS so it is always TRUE.
2670 There are other ways of forcing a breakpoint. GNU/Linux, RISC iX,
2671 and NetBSD all use a software interrupt rather than an undefined
2672 instruction to force a trap. This can be handled by by the
2673 abi-specific code during establishment of the gdbarch vector. */
2675 #define ARM_LE_BREAKPOINT {0xFE,0xDE,0xFF,0xE7}
2676 #define ARM_BE_BREAKPOINT {0xE7,0xFF,0xDE,0xFE}
2677 #define THUMB_LE_BREAKPOINT {0xbe,0xbe}
2678 #define THUMB_BE_BREAKPOINT {0xbe,0xbe}
2680 static const char arm_default_arm_le_breakpoint[] = ARM_LE_BREAKPOINT;
2681 static const char arm_default_arm_be_breakpoint[] = ARM_BE_BREAKPOINT;
2682 static const char arm_default_thumb_le_breakpoint[] = THUMB_LE_BREAKPOINT;
2683 static const char arm_default_thumb_be_breakpoint[] = THUMB_BE_BREAKPOINT;
2685 /* Determine the type and size of breakpoint to insert at PCPTR. Uses
2686 the program counter value to determine whether a 16-bit or 32-bit
2687 breakpoint should be used. It returns a pointer to a string of
2688 bytes that encode a breakpoint instruction, stores the length of
2689 the string to *lenptr, and adjusts the program counter (if
2690 necessary) to point to the actual memory location where the
2691 breakpoint should be inserted. */
2693 static const unsigned char *
2694 arm_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
2696 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2698 if (arm_pc_is_thumb (*pcptr))
2700 *pcptr = UNMAKE_THUMB_ADDR (*pcptr);
2701 *lenptr = tdep->thumb_breakpoint_size;
2702 return tdep->thumb_breakpoint;
2706 *lenptr = tdep->arm_breakpoint_size;
2707 return tdep->arm_breakpoint;
2711 /* Extract from an array REGBUF containing the (raw) register state a
2712 function return value of type TYPE, and copy that, in virtual
2713 format, into VALBUF. */
2716 arm_extract_return_value (struct type *type, struct regcache *regs,
2719 struct gdbarch *gdbarch = get_regcache_arch (regs);
2720 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2722 if (TYPE_CODE_FLT == TYPE_CODE (type))
2724 switch (gdbarch_tdep (gdbarch)->fp_model)
2728 /* The value is in register F0 in internal format. We need to
2729 extract the raw value and then convert it to the desired
2731 bfd_byte tmpbuf[FP_REGISTER_SIZE];
2733 regcache_cooked_read (regs, ARM_F0_REGNUM, tmpbuf);
2734 convert_from_extended (floatformat_from_type (type), tmpbuf,
2735 valbuf, gdbarch_byte_order (gdbarch));
2739 case ARM_FLOAT_SOFT_FPA:
2740 case ARM_FLOAT_SOFT_VFP:
2741 /* ARM_FLOAT_VFP can arise if this is a variadic function so
2742 not using the VFP ABI code. */
2744 regcache_cooked_read (regs, ARM_A1_REGNUM, valbuf);
2745 if (TYPE_LENGTH (type) > 4)
2746 regcache_cooked_read (regs, ARM_A1_REGNUM + 1,
2747 valbuf + INT_REGISTER_SIZE);
2752 (__FILE__, __LINE__,
2753 _("arm_extract_return_value: Floating point model not supported"));
2757 else if (TYPE_CODE (type) == TYPE_CODE_INT
2758 || TYPE_CODE (type) == TYPE_CODE_CHAR
2759 || TYPE_CODE (type) == TYPE_CODE_BOOL
2760 || TYPE_CODE (type) == TYPE_CODE_PTR
2761 || TYPE_CODE (type) == TYPE_CODE_REF
2762 || TYPE_CODE (type) == TYPE_CODE_ENUM)
2764 /* If the the type is a plain integer, then the access is
2765 straight-forward. Otherwise we have to play around a bit more. */
2766 int len = TYPE_LENGTH (type);
2767 int regno = ARM_A1_REGNUM;
2772 /* By using store_unsigned_integer we avoid having to do
2773 anything special for small big-endian values. */
2774 regcache_cooked_read_unsigned (regs, regno++, &tmp);
2775 store_unsigned_integer (valbuf,
2776 (len > INT_REGISTER_SIZE
2777 ? INT_REGISTER_SIZE : len),
2779 len -= INT_REGISTER_SIZE;
2780 valbuf += INT_REGISTER_SIZE;
2785 /* For a structure or union the behaviour is as if the value had
2786 been stored to word-aligned memory and then loaded into
2787 registers with 32-bit load instruction(s). */
2788 int len = TYPE_LENGTH (type);
2789 int regno = ARM_A1_REGNUM;
2790 bfd_byte tmpbuf[INT_REGISTER_SIZE];
2794 regcache_cooked_read (regs, regno++, tmpbuf);
2795 memcpy (valbuf, tmpbuf,
2796 len > INT_REGISTER_SIZE ? INT_REGISTER_SIZE : len);
2797 len -= INT_REGISTER_SIZE;
2798 valbuf += INT_REGISTER_SIZE;
2804 /* Will a function return an aggregate type in memory or in a
2805 register? Return 0 if an aggregate type can be returned in a
2806 register, 1 if it must be returned in memory. */
2809 arm_return_in_memory (struct gdbarch *gdbarch, struct type *type)
2812 enum type_code code;
2814 CHECK_TYPEDEF (type);
2816 /* In the ARM ABI, "integer" like aggregate types are returned in
2817 registers. For an aggregate type to be integer like, its size
2818 must be less than or equal to INT_REGISTER_SIZE and the
2819 offset of each addressable subfield must be zero. Note that bit
2820 fields are not addressable, and all addressable subfields of
2821 unions always start at offset zero.
2823 This function is based on the behaviour of GCC 2.95.1.
2824 See: gcc/arm.c: arm_return_in_memory() for details.
2826 Note: All versions of GCC before GCC 2.95.2 do not set up the
2827 parameters correctly for a function returning the following
2828 structure: struct { float f;}; This should be returned in memory,
2829 not a register. Richard Earnshaw sent me a patch, but I do not
2830 know of any way to detect if a function like the above has been
2831 compiled with the correct calling convention. */
2833 /* All aggregate types that won't fit in a register must be returned
2835 if (TYPE_LENGTH (type) > INT_REGISTER_SIZE)
2840 /* The AAPCS says all aggregates not larger than a word are returned
2842 if (gdbarch_tdep (gdbarch)->arm_abi != ARM_ABI_APCS)
2845 /* The only aggregate types that can be returned in a register are
2846 structs and unions. Arrays must be returned in memory. */
2847 code = TYPE_CODE (type);
2848 if ((TYPE_CODE_STRUCT != code) && (TYPE_CODE_UNION != code))
2853 /* Assume all other aggregate types can be returned in a register.
2854 Run a check for structures, unions and arrays. */
2857 if ((TYPE_CODE_STRUCT == code) || (TYPE_CODE_UNION == code))
2860 /* Need to check if this struct/union is "integer" like. For
2861 this to be true, its size must be less than or equal to
2862 INT_REGISTER_SIZE and the offset of each addressable
2863 subfield must be zero. Note that bit fields are not
2864 addressable, and unions always start at offset zero. If any
2865 of the subfields is a floating point type, the struct/union
2866 cannot be an integer type. */
2868 /* For each field in the object, check:
2869 1) Is it FP? --> yes, nRc = 1;
2870 2) Is it addressable (bitpos != 0) and
2871 not packed (bitsize == 0)?
2875 for (i = 0; i < TYPE_NFIELDS (type); i++)
2877 enum type_code field_type_code;
2878 field_type_code = TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type, i)));
2880 /* Is it a floating point type field? */
2881 if (field_type_code == TYPE_CODE_FLT)
2887 /* If bitpos != 0, then we have to care about it. */
2888 if (TYPE_FIELD_BITPOS (type, i) != 0)
2890 /* Bitfields are not addressable. If the field bitsize is
2891 zero, then the field is not packed. Hence it cannot be
2892 a bitfield or any other packed type. */
2893 if (TYPE_FIELD_BITSIZE (type, i) == 0)
2905 /* Write into appropriate registers a function return value of type
2906 TYPE, given in virtual format. */
2909 arm_store_return_value (struct type *type, struct regcache *regs,
2910 const gdb_byte *valbuf)
2912 struct gdbarch *gdbarch = get_regcache_arch (regs);
2913 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2915 if (TYPE_CODE (type) == TYPE_CODE_FLT)
2917 char buf[MAX_REGISTER_SIZE];
2919 switch (gdbarch_tdep (gdbarch)->fp_model)
2923 convert_to_extended (floatformat_from_type (type), buf, valbuf,
2924 gdbarch_byte_order (gdbarch));
2925 regcache_cooked_write (regs, ARM_F0_REGNUM, buf);
2928 case ARM_FLOAT_SOFT_FPA:
2929 case ARM_FLOAT_SOFT_VFP:
2930 /* ARM_FLOAT_VFP can arise if this is a variadic function so
2931 not using the VFP ABI code. */
2933 regcache_cooked_write (regs, ARM_A1_REGNUM, valbuf);
2934 if (TYPE_LENGTH (type) > 4)
2935 regcache_cooked_write (regs, ARM_A1_REGNUM + 1,
2936 valbuf + INT_REGISTER_SIZE);
2941 (__FILE__, __LINE__,
2942 _("arm_store_return_value: Floating point model not supported"));
2946 else if (TYPE_CODE (type) == TYPE_CODE_INT
2947 || TYPE_CODE (type) == TYPE_CODE_CHAR
2948 || TYPE_CODE (type) == TYPE_CODE_BOOL
2949 || TYPE_CODE (type) == TYPE_CODE_PTR
2950 || TYPE_CODE (type) == TYPE_CODE_REF
2951 || TYPE_CODE (type) == TYPE_CODE_ENUM)
2953 if (TYPE_LENGTH (type) <= 4)
2955 /* Values of one word or less are zero/sign-extended and
2957 bfd_byte tmpbuf[INT_REGISTER_SIZE];
2958 LONGEST val = unpack_long (type, valbuf);
2960 store_signed_integer (tmpbuf, INT_REGISTER_SIZE, byte_order, val);
2961 regcache_cooked_write (regs, ARM_A1_REGNUM, tmpbuf);
2965 /* Integral values greater than one word are stored in consecutive
2966 registers starting with r0. This will always be a multiple of
2967 the regiser size. */
2968 int len = TYPE_LENGTH (type);
2969 int regno = ARM_A1_REGNUM;
2973 regcache_cooked_write (regs, regno++, valbuf);
2974 len -= INT_REGISTER_SIZE;
2975 valbuf += INT_REGISTER_SIZE;
2981 /* For a structure or union the behaviour is as if the value had
2982 been stored to word-aligned memory and then loaded into
2983 registers with 32-bit load instruction(s). */
2984 int len = TYPE_LENGTH (type);
2985 int regno = ARM_A1_REGNUM;
2986 bfd_byte tmpbuf[INT_REGISTER_SIZE];
2990 memcpy (tmpbuf, valbuf,
2991 len > INT_REGISTER_SIZE ? INT_REGISTER_SIZE : len);
2992 regcache_cooked_write (regs, regno++, tmpbuf);
2993 len -= INT_REGISTER_SIZE;
2994 valbuf += INT_REGISTER_SIZE;
3000 /* Handle function return values. */
3002 static enum return_value_convention
3003 arm_return_value (struct gdbarch *gdbarch, struct type *func_type,
3004 struct type *valtype, struct regcache *regcache,
3005 gdb_byte *readbuf, const gdb_byte *writebuf)
3007 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3008 enum arm_vfp_cprc_base_type vfp_base_type;
3011 if (arm_vfp_abi_for_function (gdbarch, func_type)
3012 && arm_vfp_call_candidate (valtype, &vfp_base_type, &vfp_base_count))
3014 int reg_char = arm_vfp_cprc_reg_char (vfp_base_type);
3015 int unit_length = arm_vfp_cprc_unit_length (vfp_base_type);
3017 for (i = 0; i < vfp_base_count; i++)
3019 if (reg_char == 'q')
3022 arm_neon_quad_write (gdbarch, regcache, i,
3023 writebuf + i * unit_length);
3026 arm_neon_quad_read (gdbarch, regcache, i,
3027 readbuf + i * unit_length);
3034 sprintf (name_buf, "%c%d", reg_char, i);
3035 regnum = user_reg_map_name_to_regnum (gdbarch, name_buf,
3038 regcache_cooked_write (regcache, regnum,
3039 writebuf + i * unit_length);
3041 regcache_cooked_read (regcache, regnum,
3042 readbuf + i * unit_length);
3045 return RETURN_VALUE_REGISTER_CONVENTION;
3048 if (TYPE_CODE (valtype) == TYPE_CODE_STRUCT
3049 || TYPE_CODE (valtype) == TYPE_CODE_UNION
3050 || TYPE_CODE (valtype) == TYPE_CODE_ARRAY)
3052 if (tdep->struct_return == pcc_struct_return
3053 || arm_return_in_memory (gdbarch, valtype))
3054 return RETURN_VALUE_STRUCT_CONVENTION;
3058 arm_store_return_value (valtype, regcache, writebuf);
3061 arm_extract_return_value (valtype, regcache, readbuf);
3063 return RETURN_VALUE_REGISTER_CONVENTION;
3068 arm_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
3070 struct gdbarch *gdbarch = get_frame_arch (frame);
3071 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3072 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
3074 char buf[INT_REGISTER_SIZE];
3076 jb_addr = get_frame_register_unsigned (frame, ARM_A1_REGNUM);
3078 if (target_read_memory (jb_addr + tdep->jb_pc * tdep->jb_elt_size, buf,
3082 *pc = extract_unsigned_integer (buf, INT_REGISTER_SIZE, byte_order);
3086 /* Recognize GCC and GNU ld's trampolines. If we are in a trampoline,
3087 return the target PC. Otherwise return 0. */
3090 arm_skip_stub (struct frame_info *frame, CORE_ADDR pc)
3094 CORE_ADDR start_addr;
3096 /* Find the starting address and name of the function containing the PC. */
3097 if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0)
3100 /* If PC is in a Thumb call or return stub, return the address of the
3101 target PC, which is in a register. The thunk functions are called
3102 _call_via_xx, where x is the register name. The possible names
3103 are r0-r9, sl, fp, ip, sp, and lr. */
3104 if (strncmp (name, "_call_via_", 10) == 0)
3106 /* Use the name suffix to determine which register contains the
3108 static char *table[15] =
3109 {"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
3110 "r8", "r9", "sl", "fp", "ip", "sp", "lr"
3113 int offset = strlen (name) - 2;
3115 for (regno = 0; regno <= 14; regno++)
3116 if (strcmp (&name[offset], table[regno]) == 0)
3117 return get_frame_register_unsigned (frame, regno);
3120 /* GNU ld generates __foo_from_arm or __foo_from_thumb for
3121 non-interworking calls to foo. We could decode the stubs
3122 to find the target but it's easier to use the symbol table. */
3123 namelen = strlen (name);
3124 if (name[0] == '_' && name[1] == '_'
3125 && ((namelen > 2 + strlen ("_from_thumb")
3126 && strncmp (name + namelen - strlen ("_from_thumb"), "_from_thumb",
3127 strlen ("_from_thumb")) == 0)
3128 || (namelen > 2 + strlen ("_from_arm")
3129 && strncmp (name + namelen - strlen ("_from_arm"), "_from_arm",
3130 strlen ("_from_arm")) == 0)))
3133 int target_len = namelen - 2;
3134 struct minimal_symbol *minsym;
3135 struct objfile *objfile;
3136 struct obj_section *sec;
3138 if (name[namelen - 1] == 'b')
3139 target_len -= strlen ("_from_thumb");
3141 target_len -= strlen ("_from_arm");
3143 target_name = alloca (target_len + 1);
3144 memcpy (target_name, name + 2, target_len);
3145 target_name[target_len] = '\0';
3147 sec = find_pc_section (pc);
3148 objfile = (sec == NULL) ? NULL : sec->objfile;
3149 minsym = lookup_minimal_symbol (target_name, NULL, objfile);
3151 return SYMBOL_VALUE_ADDRESS (minsym);
3156 return 0; /* not a stub */
3160 set_arm_command (char *args, int from_tty)
3162 printf_unfiltered (_("\
3163 \"set arm\" must be followed by an apporpriate subcommand.\n"));
3164 help_list (setarmcmdlist, "set arm ", all_commands, gdb_stdout);
3168 show_arm_command (char *args, int from_tty)
3170 cmd_show_list (showarmcmdlist, from_tty, "");
3174 arm_update_current_architecture (void)
3176 struct gdbarch_info info;
3178 /* If the current architecture is not ARM, we have nothing to do. */
3179 if (gdbarch_bfd_arch_info (target_gdbarch)->arch != bfd_arch_arm)
3182 /* Update the architecture. */
3183 gdbarch_info_init (&info);
3185 if (!gdbarch_update_p (info))
3186 internal_error (__FILE__, __LINE__, "could not update architecture");
3190 set_fp_model_sfunc (char *args, int from_tty,
3191 struct cmd_list_element *c)
3193 enum arm_float_model fp_model;
3195 for (fp_model = ARM_FLOAT_AUTO; fp_model != ARM_FLOAT_LAST; fp_model++)
3196 if (strcmp (current_fp_model, fp_model_strings[fp_model]) == 0)
3198 arm_fp_model = fp_model;
3202 if (fp_model == ARM_FLOAT_LAST)
3203 internal_error (__FILE__, __LINE__, _("Invalid fp model accepted: %s."),
3206 arm_update_current_architecture ();
3210 show_fp_model (struct ui_file *file, int from_tty,
3211 struct cmd_list_element *c, const char *value)
3213 struct gdbarch_tdep *tdep = gdbarch_tdep (target_gdbarch);
3215 if (arm_fp_model == ARM_FLOAT_AUTO
3216 && gdbarch_bfd_arch_info (target_gdbarch)->arch == bfd_arch_arm)
3217 fprintf_filtered (file, _("\
3218 The current ARM floating point model is \"auto\" (currently \"%s\").\n"),
3219 fp_model_strings[tdep->fp_model]);
3221 fprintf_filtered (file, _("\
3222 The current ARM floating point model is \"%s\".\n"),
3223 fp_model_strings[arm_fp_model]);
3227 arm_set_abi (char *args, int from_tty,
3228 struct cmd_list_element *c)
3230 enum arm_abi_kind arm_abi;
3232 for (arm_abi = ARM_ABI_AUTO; arm_abi != ARM_ABI_LAST; arm_abi++)
3233 if (strcmp (arm_abi_string, arm_abi_strings[arm_abi]) == 0)
3235 arm_abi_global = arm_abi;
3239 if (arm_abi == ARM_ABI_LAST)
3240 internal_error (__FILE__, __LINE__, _("Invalid ABI accepted: %s."),
3243 arm_update_current_architecture ();
3247 arm_show_abi (struct ui_file *file, int from_tty,
3248 struct cmd_list_element *c, const char *value)
3250 struct gdbarch_tdep *tdep = gdbarch_tdep (target_gdbarch);
3252 if (arm_abi_global == ARM_ABI_AUTO
3253 && gdbarch_bfd_arch_info (target_gdbarch)->arch == bfd_arch_arm)
3254 fprintf_filtered (file, _("\
3255 The current ARM ABI is \"auto\" (currently \"%s\").\n"),
3256 arm_abi_strings[tdep->arm_abi]);
3258 fprintf_filtered (file, _("The current ARM ABI is \"%s\".\n"),
3263 arm_show_fallback_mode (struct ui_file *file, int from_tty,
3264 struct cmd_list_element *c, const char *value)
3266 struct gdbarch_tdep *tdep = gdbarch_tdep (target_gdbarch);
3268 fprintf_filtered (file, _("\
3269 The current execution mode assumed (when symbols are unavailable) is \"%s\".\n"),
3270 arm_fallback_mode_string);
3274 arm_show_force_mode (struct ui_file *file, int from_tty,
3275 struct cmd_list_element *c, const char *value)
3277 struct gdbarch_tdep *tdep = gdbarch_tdep (target_gdbarch);
3279 fprintf_filtered (file, _("\
3280 The current execution mode assumed (even when symbols are available) is \"%s\".\n"),
3281 arm_force_mode_string);
3284 /* If the user changes the register disassembly style used for info
3285 register and other commands, we have to also switch the style used
3286 in opcodes for disassembly output. This function is run in the "set
3287 arm disassembly" command, and does that. */
3290 set_disassembly_style_sfunc (char *args, int from_tty,
3291 struct cmd_list_element *c)
3293 set_disassembly_style ();
3296 /* Return the ARM register name corresponding to register I. */
3298 arm_register_name (struct gdbarch *gdbarch, int i)
3300 const int num_regs = gdbarch_num_regs (gdbarch);
3302 if (gdbarch_tdep (gdbarch)->have_vfp_pseudos
3303 && i >= num_regs && i < num_regs + 32)
3305 static const char *const vfp_pseudo_names[] = {
3306 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
3307 "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15",
3308 "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23",
3309 "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31",
3312 return vfp_pseudo_names[i - num_regs];
3315 if (gdbarch_tdep (gdbarch)->have_neon_pseudos
3316 && i >= num_regs + 32 && i < num_regs + 32 + 16)
3318 static const char *const neon_pseudo_names[] = {
3319 "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7",
3320 "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15",
3323 return neon_pseudo_names[i - num_regs - 32];
3326 if (i >= ARRAY_SIZE (arm_register_names))
3327 /* These registers are only supported on targets which supply
3328 an XML description. */
3331 return arm_register_names[i];
3335 set_disassembly_style (void)
3339 /* Find the style that the user wants. */
3340 for (current = 0; current < num_disassembly_options; current++)
3341 if (disassembly_style == valid_disassembly_styles[current])
3343 gdb_assert (current < num_disassembly_options);
3345 /* Synchronize the disassembler. */
3346 set_arm_regname_option (current);
3349 /* Test whether the coff symbol specific value corresponds to a Thumb
3353 coff_sym_is_thumb (int val)
3355 return (val == C_THUMBEXT ||
3356 val == C_THUMBSTAT ||
3357 val == C_THUMBEXTFUNC ||
3358 val == C_THUMBSTATFUNC ||
3359 val == C_THUMBLABEL);
3362 /* arm_coff_make_msymbol_special()
3363 arm_elf_make_msymbol_special()
3365 These functions test whether the COFF or ELF symbol corresponds to
3366 an address in thumb code, and set a "special" bit in a minimal
3367 symbol to indicate that it does. */
3370 arm_elf_make_msymbol_special(asymbol *sym, struct minimal_symbol *msym)
3372 /* Thumb symbols are of type STT_LOPROC, (synonymous with
3374 if (ELF_ST_TYPE (((elf_symbol_type *)sym)->internal_elf_sym.st_info)
3376 MSYMBOL_SET_SPECIAL (msym);
3380 arm_coff_make_msymbol_special(int val, struct minimal_symbol *msym)
3382 if (coff_sym_is_thumb (val))
3383 MSYMBOL_SET_SPECIAL (msym);
3387 arm_objfile_data_cleanup (struct objfile *objfile, void *arg)
3389 struct arm_per_objfile *data = arg;
3392 for (i = 0; i < objfile->obfd->section_count; i++)
3393 VEC_free (arm_mapping_symbol_s, data->section_maps[i]);
3397 arm_record_special_symbol (struct gdbarch *gdbarch, struct objfile *objfile,
3400 const char *name = bfd_asymbol_name (sym);
3401 struct arm_per_objfile *data;
3402 VEC(arm_mapping_symbol_s) **map_p;
3403 struct arm_mapping_symbol new_map_sym;
3405 gdb_assert (name[0] == '$');
3406 if (name[1] != 'a' && name[1] != 't' && name[1] != 'd')
3409 data = objfile_data (objfile, arm_objfile_data_key);
3412 data = OBSTACK_ZALLOC (&objfile->objfile_obstack,
3413 struct arm_per_objfile);
3414 set_objfile_data (objfile, arm_objfile_data_key, data);
3415 data->section_maps = OBSTACK_CALLOC (&objfile->objfile_obstack,
3416 objfile->obfd->section_count,
3417 VEC(arm_mapping_symbol_s) *);
3419 map_p = &data->section_maps[bfd_get_section (sym)->index];
3421 new_map_sym.value = sym->value;
3422 new_map_sym.type = name[1];
3424 /* Assume that most mapping symbols appear in order of increasing
3425 value. If they were randomly distributed, it would be faster to
3426 always push here and then sort at first use. */
3427 if (!VEC_empty (arm_mapping_symbol_s, *map_p))
3429 struct arm_mapping_symbol *prev_map_sym;
3431 prev_map_sym = VEC_last (arm_mapping_symbol_s, *map_p);
3432 if (prev_map_sym->value >= sym->value)
3435 idx = VEC_lower_bound (arm_mapping_symbol_s, *map_p, &new_map_sym,
3436 arm_compare_mapping_symbols);
3437 VEC_safe_insert (arm_mapping_symbol_s, *map_p, idx, &new_map_sym);
3442 VEC_safe_push (arm_mapping_symbol_s, *map_p, &new_map_sym);
3446 arm_write_pc (struct regcache *regcache, CORE_ADDR pc)
3448 regcache_cooked_write_unsigned (regcache, ARM_PC_REGNUM, pc);
3450 /* If necessary, set the T bit. */
3454 regcache_cooked_read_unsigned (regcache, ARM_PS_REGNUM, &val);
3455 if (arm_pc_is_thumb (pc))
3456 regcache_cooked_write_unsigned (regcache, ARM_PS_REGNUM, val | CPSR_T);
3458 regcache_cooked_write_unsigned (regcache, ARM_PS_REGNUM,
3459 val & ~(ULONGEST) CPSR_T);
3463 /* Read the contents of a NEON quad register, by reading from two
3464 double registers. This is used to implement the quad pseudo
3465 registers, and for argument passing in case the quad registers are
3466 missing; vectors are passed in quad registers when using the VFP
3467 ABI, even if a NEON unit is not present. REGNUM is the index of
3468 the quad register, in [0, 15]. */
3471 arm_neon_quad_read (struct gdbarch *gdbarch, struct regcache *regcache,
3472 int regnum, gdb_byte *buf)
3475 gdb_byte reg_buf[8];
3476 int offset, double_regnum;
3478 sprintf (name_buf, "d%d", regnum << 1);
3479 double_regnum = user_reg_map_name_to_regnum (gdbarch, name_buf,
3482 /* d0 is always the least significant half of q0. */
3483 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
3488 regcache_raw_read (regcache, double_regnum, reg_buf);
3489 memcpy (buf + offset, reg_buf, 8);
3491 offset = 8 - offset;
3492 regcache_raw_read (regcache, double_regnum + 1, reg_buf);
3493 memcpy (buf + offset, reg_buf, 8);
3497 arm_pseudo_read (struct gdbarch *gdbarch, struct regcache *regcache,
3498 int regnum, gdb_byte *buf)
3500 const int num_regs = gdbarch_num_regs (gdbarch);
3502 gdb_byte reg_buf[8];
3503 int offset, double_regnum;
3505 gdb_assert (regnum >= num_regs);
3508 if (gdbarch_tdep (gdbarch)->have_neon_pseudos && regnum >= 32 && regnum < 48)
3509 /* Quad-precision register. */
3510 arm_neon_quad_read (gdbarch, regcache, regnum - 32, buf);
3513 /* Single-precision register. */
3514 gdb_assert (regnum < 32);
3516 /* s0 is always the least significant half of d0. */
3517 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
3518 offset = (regnum & 1) ? 0 : 4;
3520 offset = (regnum & 1) ? 4 : 0;
3522 sprintf (name_buf, "d%d", regnum >> 1);
3523 double_regnum = user_reg_map_name_to_regnum (gdbarch, name_buf,
3526 regcache_raw_read (regcache, double_regnum, reg_buf);
3527 memcpy (buf, reg_buf + offset, 4);
3531 /* Store the contents of BUF to a NEON quad register, by writing to
3532 two double registers. This is used to implement the quad pseudo
3533 registers, and for argument passing in case the quad registers are
3534 missing; vectors are passed in quad registers when using the VFP
3535 ABI, even if a NEON unit is not present. REGNUM is the index
3536 of the quad register, in [0, 15]. */
3539 arm_neon_quad_write (struct gdbarch *gdbarch, struct regcache *regcache,
3540 int regnum, const gdb_byte *buf)
3543 gdb_byte reg_buf[8];
3544 int offset, double_regnum;
3546 sprintf (name_buf, "d%d", regnum << 1);
3547 double_regnum = user_reg_map_name_to_regnum (gdbarch, name_buf,
3550 /* d0 is always the least significant half of q0. */
3551 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
3556 regcache_raw_write (regcache, double_regnum, buf + offset);
3557 offset = 8 - offset;
3558 regcache_raw_write (regcache, double_regnum + 1, buf + offset);
3562 arm_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
3563 int regnum, const gdb_byte *buf)
3565 const int num_regs = gdbarch_num_regs (gdbarch);
3567 gdb_byte reg_buf[8];
3568 int offset, double_regnum;
3570 gdb_assert (regnum >= num_regs);
3573 if (gdbarch_tdep (gdbarch)->have_neon_pseudos && regnum >= 32 && regnum < 48)
3574 /* Quad-precision register. */
3575 arm_neon_quad_write (gdbarch, regcache, regnum - 32, buf);
3578 /* Single-precision register. */
3579 gdb_assert (regnum < 32);
3581 /* s0 is always the least significant half of d0. */
3582 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
3583 offset = (regnum & 1) ? 0 : 4;
3585 offset = (regnum & 1) ? 4 : 0;
3587 sprintf (name_buf, "d%d", regnum >> 1);
3588 double_regnum = user_reg_map_name_to_regnum (gdbarch, name_buf,
3591 regcache_raw_read (regcache, double_regnum, reg_buf);
3592 memcpy (reg_buf + offset, buf, 4);
3593 regcache_raw_write (regcache, double_regnum, reg_buf);
3597 static struct value *
3598 value_of_arm_user_reg (struct frame_info *frame, const void *baton)
3600 const int *reg_p = baton;
3601 return value_of_register (*reg_p, frame);
3604 static enum gdb_osabi
3605 arm_elf_osabi_sniffer (bfd *abfd)
3607 unsigned int elfosabi;
3608 enum gdb_osabi osabi = GDB_OSABI_UNKNOWN;
3610 elfosabi = elf_elfheader (abfd)->e_ident[EI_OSABI];
3612 if (elfosabi == ELFOSABI_ARM)
3613 /* GNU tools use this value. Check note sections in this case,
3615 bfd_map_over_sections (abfd,
3616 generic_elf_osabi_sniff_abi_tag_sections,
3619 /* Anything else will be handled by the generic ELF sniffer. */
3624 /* Initialize the current architecture based on INFO. If possible,
3625 re-use an architecture from ARCHES, which is a list of
3626 architectures already created during this debugging session.
3628 Called e.g. at program startup, when reading a core file, and when
3629 reading a binary file. */
3631 static struct gdbarch *
3632 arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
3634 struct gdbarch_tdep *tdep;
3635 struct gdbarch *gdbarch;
3636 struct gdbarch_list *best_arch;
3637 enum arm_abi_kind arm_abi = arm_abi_global;
3638 enum arm_float_model fp_model = arm_fp_model;
3639 struct tdesc_arch_data *tdesc_data = NULL;
3641 int have_vfp_registers = 0, have_vfp_pseudos = 0, have_neon_pseudos = 0;
3643 int have_fpa_registers = 1;
3645 /* Check any target description for validity. */
3646 if (tdesc_has_registers (info.target_desc))
3648 /* For most registers we require GDB's default names; but also allow
3649 the numeric names for sp / lr / pc, as a convenience. */
3650 static const char *const arm_sp_names[] = { "r13", "sp", NULL };
3651 static const char *const arm_lr_names[] = { "r14", "lr", NULL };
3652 static const char *const arm_pc_names[] = { "r15", "pc", NULL };
3654 const struct tdesc_feature *feature;
3657 feature = tdesc_find_feature (info.target_desc,
3658 "org.gnu.gdb.arm.core");
3659 if (feature == NULL)
3662 tdesc_data = tdesc_data_alloc ();
3665 for (i = 0; i < ARM_SP_REGNUM; i++)
3666 valid_p &= tdesc_numbered_register (feature, tdesc_data, i,
3667 arm_register_names[i]);
3668 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
3671 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
3674 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
3677 valid_p &= tdesc_numbered_register (feature, tdesc_data,
3678 ARM_PS_REGNUM, "cpsr");
3682 tdesc_data_cleanup (tdesc_data);
3686 feature = tdesc_find_feature (info.target_desc,
3687 "org.gnu.gdb.arm.fpa");
3688 if (feature != NULL)
3691 for (i = ARM_F0_REGNUM; i <= ARM_FPS_REGNUM; i++)
3692 valid_p &= tdesc_numbered_register (feature, tdesc_data, i,
3693 arm_register_names[i]);
3696 tdesc_data_cleanup (tdesc_data);
3701 have_fpa_registers = 0;
3703 feature = tdesc_find_feature (info.target_desc,
3704 "org.gnu.gdb.xscale.iwmmxt");
3705 if (feature != NULL)
3707 static const char *const iwmmxt_names[] = {
3708 "wR0", "wR1", "wR2", "wR3", "wR4", "wR5", "wR6", "wR7",
3709 "wR8", "wR9", "wR10", "wR11", "wR12", "wR13", "wR14", "wR15",
3710 "wCID", "wCon", "wCSSF", "wCASF", "", "", "", "",
3711 "wCGR0", "wCGR1", "wCGR2", "wCGR3", "", "", "", "",
3715 for (i = ARM_WR0_REGNUM; i <= ARM_WR15_REGNUM; i++)
3717 &= tdesc_numbered_register (feature, tdesc_data, i,
3718 iwmmxt_names[i - ARM_WR0_REGNUM]);
3720 /* Check for the control registers, but do not fail if they
3722 for (i = ARM_WC0_REGNUM; i <= ARM_WCASF_REGNUM; i++)
3723 tdesc_numbered_register (feature, tdesc_data, i,
3724 iwmmxt_names[i - ARM_WR0_REGNUM]);
3726 for (i = ARM_WCGR0_REGNUM; i <= ARM_WCGR3_REGNUM; i++)
3728 &= tdesc_numbered_register (feature, tdesc_data, i,
3729 iwmmxt_names[i - ARM_WR0_REGNUM]);
3733 tdesc_data_cleanup (tdesc_data);
3738 /* If we have a VFP unit, check whether the single precision registers
3739 are present. If not, then we will synthesize them as pseudo
3741 feature = tdesc_find_feature (info.target_desc,
3742 "org.gnu.gdb.arm.vfp");
3743 if (feature != NULL)
3745 static const char *const vfp_double_names[] = {
3746 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
3747 "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15",
3748 "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23",
3749 "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31",
3752 /* Require the double precision registers. There must be either
3755 for (i = 0; i < 32; i++)
3757 valid_p &= tdesc_numbered_register (feature, tdesc_data,
3759 vfp_double_names[i]);
3764 if (!valid_p && i != 16)
3766 tdesc_data_cleanup (tdesc_data);
3770 if (tdesc_unnumbered_register (feature, "s0") == 0)
3771 have_vfp_pseudos = 1;
3773 have_vfp_registers = 1;
3775 /* If we have VFP, also check for NEON. The architecture allows
3776 NEON without VFP (integer vector operations only), but GDB
3777 does not support that. */
3778 feature = tdesc_find_feature (info.target_desc,
3779 "org.gnu.gdb.arm.neon");
3780 if (feature != NULL)
3782 /* NEON requires 32 double-precision registers. */
3785 tdesc_data_cleanup (tdesc_data);
3789 /* If there are quad registers defined by the stub, use
3790 their type; otherwise (normally) provide them with
3791 the default type. */
3792 if (tdesc_unnumbered_register (feature, "q0") == 0)
3793 have_neon_pseudos = 1;
3800 /* If we have an object to base this architecture on, try to determine
3803 if (arm_abi == ARM_ABI_AUTO && info.abfd != NULL)
3805 int ei_osabi, e_flags;
3807 switch (bfd_get_flavour (info.abfd))
3809 case bfd_target_aout_flavour:
3810 /* Assume it's an old APCS-style ABI. */
3811 arm_abi = ARM_ABI_APCS;
3814 case bfd_target_coff_flavour:
3815 /* Assume it's an old APCS-style ABI. */
3817 arm_abi = ARM_ABI_APCS;
3820 case bfd_target_elf_flavour:
3821 ei_osabi = elf_elfheader (info.abfd)->e_ident[EI_OSABI];
3822 e_flags = elf_elfheader (info.abfd)->e_flags;
3824 if (ei_osabi == ELFOSABI_ARM)
3826 /* GNU tools used to use this value, but do not for EABI
3827 objects. There's nowhere to tag an EABI version
3828 anyway, so assume APCS. */
3829 arm_abi = ARM_ABI_APCS;
3831 else if (ei_osabi == ELFOSABI_NONE)
3833 int eabi_ver = EF_ARM_EABI_VERSION (e_flags);
3837 case EF_ARM_EABI_UNKNOWN:
3838 /* Assume GNU tools. */
3839 arm_abi = ARM_ABI_APCS;
3842 case EF_ARM_EABI_VER4:
3843 case EF_ARM_EABI_VER5:
3844 arm_abi = ARM_ABI_AAPCS;
3845 /* EABI binaries default to VFP float ordering.
3846 They may also contain build attributes that can
3847 be used to identify if the VFP argument-passing
3849 if (fp_model == ARM_FLOAT_AUTO)
3852 switch (bfd_elf_get_obj_attr_int (info.abfd,
3857 /* "The user intended FP parameter/result
3858 passing to conform to AAPCS, base
3860 fp_model = ARM_FLOAT_SOFT_VFP;
3863 /* "The user intended FP parameter/result
3864 passing to conform to AAPCS, VFP
3866 fp_model = ARM_FLOAT_VFP;
3869 /* "The user intended FP parameter/result
3870 passing to conform to tool chain-specific
3871 conventions" - we don't know any such
3872 conventions, so leave it as "auto". */
3875 /* Attribute value not mentioned in the
3876 October 2008 ABI, so leave it as
3881 fp_model = ARM_FLOAT_SOFT_VFP;
3887 /* Leave it as "auto". */
3888 warning (_("unknown ARM EABI version 0x%x"), eabi_ver);
3893 if (fp_model == ARM_FLOAT_AUTO)
3895 int e_flags = elf_elfheader (info.abfd)->e_flags;
3897 switch (e_flags & (EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT))
3900 /* Leave it as "auto". Strictly speaking this case
3901 means FPA, but almost nobody uses that now, and
3902 many toolchains fail to set the appropriate bits
3903 for the floating-point model they use. */
3905 case EF_ARM_SOFT_FLOAT:
3906 fp_model = ARM_FLOAT_SOFT_FPA;
3908 case EF_ARM_VFP_FLOAT:
3909 fp_model = ARM_FLOAT_VFP;
3911 case EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT:
3912 fp_model = ARM_FLOAT_SOFT_VFP;
3917 if (e_flags & EF_ARM_BE8)
3918 info.byte_order_for_code = BFD_ENDIAN_LITTLE;
3923 /* Leave it as "auto". */
3928 /* If there is already a candidate, use it. */
3929 for (best_arch = gdbarch_list_lookup_by_info (arches, &info);
3931 best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
3933 if (arm_abi != ARM_ABI_AUTO
3934 && arm_abi != gdbarch_tdep (best_arch->gdbarch)->arm_abi)
3937 if (fp_model != ARM_FLOAT_AUTO
3938 && fp_model != gdbarch_tdep (best_arch->gdbarch)->fp_model)
3941 /* There are various other properties in tdep that we do not
3942 need to check here: those derived from a target description,
3943 since gdbarches with a different target description are
3944 automatically disqualified. */
3946 /* Found a match. */
3950 if (best_arch != NULL)
3952 if (tdesc_data != NULL)
3953 tdesc_data_cleanup (tdesc_data);
3954 return best_arch->gdbarch;
3957 tdep = xcalloc (1, sizeof (struct gdbarch_tdep));
3958 gdbarch = gdbarch_alloc (&info, tdep);
3960 /* Record additional information about the architecture we are defining.
3961 These are gdbarch discriminators, like the OSABI. */
3962 tdep->arm_abi = arm_abi;
3963 tdep->fp_model = fp_model;
3964 tdep->have_fpa_registers = have_fpa_registers;
3965 tdep->have_vfp_registers = have_vfp_registers;
3966 tdep->have_vfp_pseudos = have_vfp_pseudos;
3967 tdep->have_neon_pseudos = have_neon_pseudos;
3968 tdep->have_neon = have_neon;
3971 switch (info.byte_order_for_code)
3973 case BFD_ENDIAN_BIG:
3974 tdep->arm_breakpoint = arm_default_arm_be_breakpoint;
3975 tdep->arm_breakpoint_size = sizeof (arm_default_arm_be_breakpoint);
3976 tdep->thumb_breakpoint = arm_default_thumb_be_breakpoint;
3977 tdep->thumb_breakpoint_size = sizeof (arm_default_thumb_be_breakpoint);
3981 case BFD_ENDIAN_LITTLE:
3982 tdep->arm_breakpoint = arm_default_arm_le_breakpoint;
3983 tdep->arm_breakpoint_size = sizeof (arm_default_arm_le_breakpoint);
3984 tdep->thumb_breakpoint = arm_default_thumb_le_breakpoint;
3985 tdep->thumb_breakpoint_size = sizeof (arm_default_thumb_le_breakpoint);
3990 internal_error (__FILE__, __LINE__,
3991 _("arm_gdbarch_init: bad byte order for float format"));
3994 /* On ARM targets char defaults to unsigned. */
3995 set_gdbarch_char_signed (gdbarch, 0);
3997 /* This should be low enough for everything. */
3998 tdep->lowest_pc = 0x20;
3999 tdep->jb_pc = -1; /* Longjump support not enabled by default. */
4001 /* The default, for both APCS and AAPCS, is to return small
4002 structures in registers. */
4003 tdep->struct_return = reg_struct_return;
4005 set_gdbarch_push_dummy_call (gdbarch, arm_push_dummy_call);
4006 set_gdbarch_frame_align (gdbarch, arm_frame_align);
4008 set_gdbarch_write_pc (gdbarch, arm_write_pc);
4010 /* Frame handling. */
4011 set_gdbarch_dummy_id (gdbarch, arm_dummy_id);
4012 set_gdbarch_unwind_pc (gdbarch, arm_unwind_pc);
4013 set_gdbarch_unwind_sp (gdbarch, arm_unwind_sp);
4015 frame_base_set_default (gdbarch, &arm_normal_base);
4017 /* Address manipulation. */
4018 set_gdbarch_smash_text_address (gdbarch, arm_smash_text_address);
4019 set_gdbarch_addr_bits_remove (gdbarch, arm_addr_bits_remove);
4021 /* Advance PC across function entry code. */
4022 set_gdbarch_skip_prologue (gdbarch, arm_skip_prologue);
4024 /* Skip trampolines. */
4025 set_gdbarch_skip_trampoline_code (gdbarch, arm_skip_stub);
4027 /* The stack grows downward. */
4028 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
4030 /* Breakpoint manipulation. */
4031 set_gdbarch_breakpoint_from_pc (gdbarch, arm_breakpoint_from_pc);
4033 /* Information about registers, etc. */
4034 set_gdbarch_deprecated_fp_regnum (gdbarch, ARM_FP_REGNUM); /* ??? */
4035 set_gdbarch_sp_regnum (gdbarch, ARM_SP_REGNUM);
4036 set_gdbarch_pc_regnum (gdbarch, ARM_PC_REGNUM);
4037 set_gdbarch_num_regs (gdbarch, ARM_NUM_REGS);
4038 set_gdbarch_register_type (gdbarch, arm_register_type);
4040 /* This "info float" is FPA-specific. Use the generic version if we
4042 if (gdbarch_tdep (gdbarch)->have_fpa_registers)
4043 set_gdbarch_print_float_info (gdbarch, arm_print_float_info);
4045 /* Internal <-> external register number maps. */
4046 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, arm_dwarf_reg_to_regnum);
4047 set_gdbarch_register_sim_regno (gdbarch, arm_register_sim_regno);
4049 set_gdbarch_register_name (gdbarch, arm_register_name);
4051 /* Returning results. */
4052 set_gdbarch_return_value (gdbarch, arm_return_value);
4055 set_gdbarch_print_insn (gdbarch, gdb_print_insn_arm);
4057 /* Minsymbol frobbing. */
4058 set_gdbarch_elf_make_msymbol_special (gdbarch, arm_elf_make_msymbol_special);
4059 set_gdbarch_coff_make_msymbol_special (gdbarch,
4060 arm_coff_make_msymbol_special);
4061 set_gdbarch_record_special_symbol (gdbarch, arm_record_special_symbol);
4063 /* Virtual tables. */
4064 set_gdbarch_vbit_in_delta (gdbarch, 1);
4066 /* Hook in the ABI-specific overrides, if they have been registered. */
4067 gdbarch_init_osabi (info, gdbarch);
4069 dwarf2_frame_set_init_reg (gdbarch, arm_dwarf2_frame_init_reg);
4071 /* Add some default predicates. */
4072 frame_unwind_append_unwinder (gdbarch, &arm_stub_unwind);
4073 dwarf2_append_unwinders (gdbarch);
4074 frame_unwind_append_unwinder (gdbarch, &arm_prologue_unwind);
4076 /* Now we have tuned the configuration, set a few final things,
4077 based on what the OS ABI has told us. */
4079 /* If the ABI is not otherwise marked, assume the old GNU APCS. EABI
4080 binaries are always marked. */
4081 if (tdep->arm_abi == ARM_ABI_AUTO)
4082 tdep->arm_abi = ARM_ABI_APCS;
4084 /* We used to default to FPA for generic ARM, but almost nobody
4085 uses that now, and we now provide a way for the user to force
4086 the model. So default to the most useful variant. */
4087 if (tdep->fp_model == ARM_FLOAT_AUTO)
4088 tdep->fp_model = ARM_FLOAT_SOFT_FPA;
4090 if (tdep->jb_pc >= 0)
4091 set_gdbarch_get_longjmp_target (gdbarch, arm_get_longjmp_target);
4093 /* Floating point sizes and format. */
4094 set_gdbarch_float_format (gdbarch, floatformats_ieee_single);
4095 if (tdep->fp_model == ARM_FLOAT_SOFT_FPA || tdep->fp_model == ARM_FLOAT_FPA)
4097 set_gdbarch_double_format
4098 (gdbarch, floatformats_ieee_double_littlebyte_bigword);
4099 set_gdbarch_long_double_format
4100 (gdbarch, floatformats_ieee_double_littlebyte_bigword);
4104 set_gdbarch_double_format (gdbarch, floatformats_ieee_double);
4105 set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double);
4108 if (have_vfp_pseudos)
4110 /* NOTE: These are the only pseudo registers used by
4111 the ARM target at the moment. If more are added, a
4112 little more care in numbering will be needed. */
4114 int num_pseudos = 32;
4115 if (have_neon_pseudos)
4117 set_gdbarch_num_pseudo_regs (gdbarch, num_pseudos);
4118 set_gdbarch_pseudo_register_read (gdbarch, arm_pseudo_read);
4119 set_gdbarch_pseudo_register_write (gdbarch, arm_pseudo_write);
4124 set_tdesc_pseudo_register_name (gdbarch, arm_register_name);
4126 tdesc_use_registers (gdbarch, info.target_desc, tdesc_data);
4128 /* Override tdesc_register_type to adjust the types of VFP
4129 registers for NEON. */
4130 set_gdbarch_register_type (gdbarch, arm_register_type);
4133 /* Add standard register aliases. We add aliases even for those
4134 nanes which are used by the current architecture - it's simpler,
4135 and does no harm, since nothing ever lists user registers. */
4136 for (i = 0; i < ARRAY_SIZE (arm_register_aliases); i++)
4137 user_reg_add (gdbarch, arm_register_aliases[i].name,
4138 value_of_arm_user_reg, &arm_register_aliases[i].regnum);
4144 arm_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
4146 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
4151 fprintf_unfiltered (file, _("arm_dump_tdep: Lowest pc = 0x%lx"),
4152 (unsigned long) tdep->lowest_pc);
4155 extern initialize_file_ftype _initialize_arm_tdep; /* -Wmissing-prototypes */
4158 _initialize_arm_tdep (void)
4160 struct ui_file *stb;
4162 struct cmd_list_element *new_set, *new_show;
4163 const char *setname;
4164 const char *setdesc;
4165 const char *const *regnames;
4167 static char *helptext;
4168 char regdesc[1024], *rdptr = regdesc;
4169 size_t rest = sizeof (regdesc);
4171 gdbarch_register (bfd_arch_arm, arm_gdbarch_init, arm_dump_tdep);
4173 arm_objfile_data_key
4174 = register_objfile_data_with_cleanup (arm_objfile_data_cleanup);
4176 /* Register an ELF OS ABI sniffer for ARM binaries. */
4177 gdbarch_register_osabi_sniffer (bfd_arch_arm,
4178 bfd_target_elf_flavour,
4179 arm_elf_osabi_sniffer);
4181 /* Get the number of possible sets of register names defined in opcodes. */
4182 num_disassembly_options = get_arm_regname_num_options ();
4184 /* Add root prefix command for all "set arm"/"show arm" commands. */
4185 add_prefix_cmd ("arm", no_class, set_arm_command,
4186 _("Various ARM-specific commands."),
4187 &setarmcmdlist, "set arm ", 0, &setlist);
4189 add_prefix_cmd ("arm", no_class, show_arm_command,
4190 _("Various ARM-specific commands."),
4191 &showarmcmdlist, "show arm ", 0, &showlist);
4193 /* Sync the opcode insn printer with our register viewer. */
4194 parse_arm_disassembler_option ("reg-names-std");
4196 /* Initialize the array that will be passed to
4197 add_setshow_enum_cmd(). */
4198 valid_disassembly_styles
4199 = xmalloc ((num_disassembly_options + 1) * sizeof (char *));
4200 for (i = 0; i < num_disassembly_options; i++)
4202 numregs = get_arm_regnames (i, &setname, &setdesc, ®names);
4203 valid_disassembly_styles[i] = setname;
4204 length = snprintf (rdptr, rest, "%s - %s\n", setname, setdesc);
4207 /* When we find the default names, tell the disassembler to use
4209 if (!strcmp (setname, "std"))
4211 disassembly_style = setname;
4212 set_arm_regname_option (i);
4215 /* Mark the end of valid options. */
4216 valid_disassembly_styles[num_disassembly_options] = NULL;
4218 /* Create the help text. */
4219 stb = mem_fileopen ();
4220 fprintf_unfiltered (stb, "%s%s%s",
4221 _("The valid values are:\n"),
4223 _("The default is \"std\"."));
4224 helptext = ui_file_xstrdup (stb, &length);
4225 ui_file_delete (stb);
4227 add_setshow_enum_cmd("disassembler", no_class,
4228 valid_disassembly_styles, &disassembly_style,
4229 _("Set the disassembly style."),
4230 _("Show the disassembly style."),
4232 set_disassembly_style_sfunc,
4233 NULL, /* FIXME: i18n: The disassembly style is \"%s\". */
4234 &setarmcmdlist, &showarmcmdlist);
4236 add_setshow_boolean_cmd ("apcs32", no_class, &arm_apcs_32,
4237 _("Set usage of ARM 32-bit mode."),
4238 _("Show usage of ARM 32-bit mode."),
4239 _("When off, a 26-bit PC will be used."),
4241 NULL, /* FIXME: i18n: Usage of ARM 32-bit mode is %s. */
4242 &setarmcmdlist, &showarmcmdlist);
4244 /* Add a command to allow the user to force the FPU model. */
4245 add_setshow_enum_cmd ("fpu", no_class, fp_model_strings, ¤t_fp_model,
4246 _("Set the floating point type."),
4247 _("Show the floating point type."),
4248 _("auto - Determine the FP typefrom the OS-ABI.\n\
4249 softfpa - Software FP, mixed-endian doubles on little-endian ARMs.\n\
4250 fpa - FPA co-processor (GCC compiled).\n\
4251 softvfp - Software FP with pure-endian doubles.\n\
4252 vfp - VFP co-processor."),
4253 set_fp_model_sfunc, show_fp_model,
4254 &setarmcmdlist, &showarmcmdlist);
4256 /* Add a command to allow the user to force the ABI. */
4257 add_setshow_enum_cmd ("abi", class_support, arm_abi_strings, &arm_abi_string,
4260 NULL, arm_set_abi, arm_show_abi,
4261 &setarmcmdlist, &showarmcmdlist);
4263 /* Add two commands to allow the user to force the assumed
4265 add_setshow_enum_cmd ("fallback-mode", class_support,
4266 arm_mode_strings, &arm_fallback_mode_string,
4267 _("Set the mode assumed when symbols are unavailable."),
4268 _("Show the mode assumed when symbols are unavailable."),
4269 NULL, NULL, arm_show_fallback_mode,
4270 &setarmcmdlist, &showarmcmdlist);
4271 add_setshow_enum_cmd ("force-mode", class_support,
4272 arm_mode_strings, &arm_force_mode_string,
4273 _("Set the mode assumed even when symbols are available."),
4274 _("Show the mode assumed even when symbols are available."),
4275 NULL, NULL, arm_show_force_mode,
4276 &setarmcmdlist, &showarmcmdlist);
4278 /* Debugging flag. */
4279 add_setshow_boolean_cmd ("arm", class_maintenance, &arm_debug,
4280 _("Set ARM debugging."),
4281 _("Show ARM debugging."),
4282 _("When on, arm-specific debugging is enabled."),
4284 NULL, /* FIXME: i18n: "ARM debugging is %s. */
4285 &setdebuglist, &showdebuglist);