* gdbtypes.h (builtin_type_true_char): Remove.
[deliverable/binutils-gdb.git] / gdb / arm-tdep.c
CommitLineData
ed9a39eb 1/* Common target dependent code for GDB on ARM systems.
0fd88904 2
6aba47ca 3 Copyright (C) 1988, 1989, 1991, 1992, 1993, 1995, 1996, 1998, 1999, 2000,
0fb0cc75 4 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
9b254dd1 5 Free Software Foundation, Inc.
c906108c 6
c5aa993b 7 This file is part of GDB.
c906108c 8
c5aa993b
JM
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
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
c5aa993b 12 (at your option) any later version.
c906108c 13
c5aa993b
JM
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.
c906108c 18
c5aa993b 19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c 21
34e8f22d
RE
22#include <ctype.h> /* XXX for isupper () */
23
c906108c
SS
24#include "defs.h"
25#include "frame.h"
26#include "inferior.h"
27#include "gdbcmd.h"
28#include "gdbcore.h"
c906108c 29#include "gdb_string.h"
afd7eef0 30#include "dis-asm.h" /* For register styles. */
4e052eda 31#include "regcache.h"
d16aafd8 32#include "doublest.h"
fd0407d6 33#include "value.h"
34e8f22d 34#include "arch-utils.h"
4be87837 35#include "osabi.h"
eb5492fa
DJ
36#include "frame-unwind.h"
37#include "frame-base.h"
38#include "trad-frame.h"
842e1f1e
DJ
39#include "objfiles.h"
40#include "dwarf2-frame.h"
e4c16157 41#include "gdbtypes.h"
29d73ae4 42#include "prologue-value.h"
123dc839
DJ
43#include "target-descriptions.h"
44#include "user-regs.h"
34e8f22d
RE
45
46#include "arm-tdep.h"
26216b98 47#include "gdb/sim-arm.h"
34e8f22d 48
082fc60d
RE
49#include "elf-bfd.h"
50#include "coff/internal.h"
97e03143 51#include "elf/arm.h"
c906108c 52
26216b98 53#include "gdb_assert.h"
60c5725c 54#include "vec.h"
26216b98 55
6529d2dd
AC
56static int arm_debug;
57
082fc60d
RE
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
f594e5e9 60 is used for this purpose.
082fc60d
RE
61
62 MSYMBOL_SET_SPECIAL Actually sets the "special" bit.
f594e5e9 63 MSYMBOL_IS_SPECIAL Tests the "special" bit in a minimal symbol. */
082fc60d
RE
64
65#define MSYMBOL_SET_SPECIAL(msym) \
b887350f 66 MSYMBOL_TARGET_FLAG_1 (msym) = 1
082fc60d
RE
67
68#define MSYMBOL_IS_SPECIAL(msym) \
b887350f 69 MSYMBOL_TARGET_FLAG_1 (msym)
082fc60d 70
9d4fde75
SS
71/* Macros for swapping shorts and ints. In the unlikely case that anybody else needs these,
72 move to a general header. (A better solution might be to define memory read routines that
73 know whether they are reading code or data.) */
74
75#define SWAP_SHORT(x) \
76 ((((x) & 0xff00) >> 8) | (((x) & 0x00ff) << 8));
77
78#define SWAP_INT(x) \
79 ( ((x & 0xff000000) >> 24) \
80 | ((x & 0x00ff0000) >> 8) \
81 | ((x & 0x0000ff00) << 8) \
82 | ((x & 0x000000ff) << 24))
83
60c5725c
DJ
84/* Per-objfile data used for mapping symbols. */
85static const struct objfile_data *arm_objfile_data_key;
86
87struct arm_mapping_symbol
88{
89 bfd_vma value;
90 char type;
91};
92typedef struct arm_mapping_symbol arm_mapping_symbol_s;
93DEF_VEC_O(arm_mapping_symbol_s);
94
95struct arm_per_objfile
96{
97 VEC(arm_mapping_symbol_s) **section_maps;
98};
99
afd7eef0
RE
100/* The list of available "set arm ..." and "show arm ..." commands. */
101static struct cmd_list_element *setarmcmdlist = NULL;
102static struct cmd_list_element *showarmcmdlist = NULL;
103
fd50bc42
RE
104/* The type of floating-point to use. Keep this in sync with enum
105 arm_float_model, and the help string in _initialize_arm_tdep. */
106static const char *fp_model_strings[] =
107{
108 "auto",
109 "softfpa",
110 "fpa",
111 "softvfp",
28e97307
DJ
112 "vfp",
113 NULL
fd50bc42
RE
114};
115
116/* A variable that can be configured by the user. */
117static enum arm_float_model arm_fp_model = ARM_FLOAT_AUTO;
118static const char *current_fp_model = "auto";
119
28e97307
DJ
120/* The ABI to use. Keep this in sync with arm_abi_kind. */
121static const char *arm_abi_strings[] =
122{
123 "auto",
124 "APCS",
125 "AAPCS",
126 NULL
127};
128
129/* A variable that can be configured by the user. */
130static enum arm_abi_kind arm_abi_global = ARM_ABI_AUTO;
131static const char *arm_abi_string = "auto";
132
0428b8f5
DJ
133/* The execution mode to assume. */
134static const char *arm_mode_strings[] =
135 {
136 "auto",
137 "arm",
138 "thumb"
139 };
140
141static const char *arm_fallback_mode_string = "auto";
142static const char *arm_force_mode_string = "auto";
143
94c30b78 144/* Number of different reg name sets (options). */
afd7eef0 145static int num_disassembly_options;
bc90b915 146
123dc839
DJ
147/* The standard register names, and all the valid aliases for them. */
148static const struct
149{
150 const char *name;
151 int regnum;
152} arm_register_aliases[] = {
153 /* Basic register numbers. */
154 { "r0", 0 },
155 { "r1", 1 },
156 { "r2", 2 },
157 { "r3", 3 },
158 { "r4", 4 },
159 { "r5", 5 },
160 { "r6", 6 },
161 { "r7", 7 },
162 { "r8", 8 },
163 { "r9", 9 },
164 { "r10", 10 },
165 { "r11", 11 },
166 { "r12", 12 },
167 { "r13", 13 },
168 { "r14", 14 },
169 { "r15", 15 },
170 /* Synonyms (argument and variable registers). */
171 { "a1", 0 },
172 { "a2", 1 },
173 { "a3", 2 },
174 { "a4", 3 },
175 { "v1", 4 },
176 { "v2", 5 },
177 { "v3", 6 },
178 { "v4", 7 },
179 { "v5", 8 },
180 { "v6", 9 },
181 { "v7", 10 },
182 { "v8", 11 },
183 /* Other platform-specific names for r9. */
184 { "sb", 9 },
185 { "tr", 9 },
186 /* Special names. */
187 { "ip", 12 },
188 { "sp", 13 },
189 { "lr", 14 },
190 { "pc", 15 },
191 /* Names used by GCC (not listed in the ARM EABI). */
192 { "sl", 10 },
193 { "fp", 11 },
194 /* A special name from the older ATPCS. */
195 { "wr", 7 },
196};
bc90b915 197
123dc839 198static const char *const arm_register_names[] =
da59e081
JM
199{"r0", "r1", "r2", "r3", /* 0 1 2 3 */
200 "r4", "r5", "r6", "r7", /* 4 5 6 7 */
201 "r8", "r9", "r10", "r11", /* 8 9 10 11 */
202 "r12", "sp", "lr", "pc", /* 12 13 14 15 */
203 "f0", "f1", "f2", "f3", /* 16 17 18 19 */
204 "f4", "f5", "f6", "f7", /* 20 21 22 23 */
94c30b78 205 "fps", "cpsr" }; /* 24 25 */
ed9a39eb 206
afd7eef0
RE
207/* Valid register name styles. */
208static const char **valid_disassembly_styles;
ed9a39eb 209
afd7eef0
RE
210/* Disassembly style to use. Default to "std" register names. */
211static const char *disassembly_style;
96baa820 212
ed9a39eb 213/* This is used to keep the bfd arch_info in sync with the disassembly
afd7eef0
RE
214 style. */
215static void set_disassembly_style_sfunc(char *, int,
ed9a39eb 216 struct cmd_list_element *);
afd7eef0 217static void set_disassembly_style (void);
ed9a39eb 218
b508a996 219static void convert_from_extended (const struct floatformat *, const void *,
be8626e0 220 void *, int);
b508a996 221static void convert_to_extended (const struct floatformat *, void *,
be8626e0 222 const void *, int);
ed9a39eb 223
9b8d791a 224struct arm_prologue_cache
c3b4394c 225{
eb5492fa
DJ
226 /* The stack pointer at the time this frame was created; i.e. the
227 caller's stack pointer when this function was called. It is used
228 to identify this frame. */
229 CORE_ADDR prev_sp;
230
4be43953
DJ
231 /* The frame base for this frame is just prev_sp - frame size.
232 FRAMESIZE is the distance from the frame pointer to the
233 initial stack pointer. */
eb5492fa 234
c3b4394c 235 int framesize;
eb5492fa
DJ
236
237 /* The register used to hold the frame pointer for this frame. */
c3b4394c 238 int framereg;
eb5492fa
DJ
239
240 /* Saved register offsets. */
241 struct trad_frame_saved_reg *saved_regs;
c3b4394c 242};
ed9a39eb 243
bc90b915
FN
244/* Addresses for calling Thumb functions have the bit 0 set.
245 Here are some macros to test, set, or clear bit 0 of addresses. */
246#define IS_THUMB_ADDR(addr) ((addr) & 1)
247#define MAKE_THUMB_ADDR(addr) ((addr) | 1)
248#define UNMAKE_THUMB_ADDR(addr) ((addr) & ~1)
249
94c30b78 250/* Set to true if the 32-bit mode is in use. */
c906108c
SS
251
252int arm_apcs_32 = 1;
253
b39cc962
DJ
254/* Determine if FRAME is executing in Thumb mode. */
255
256static int
257arm_frame_is_thumb (struct frame_info *frame)
258{
259 CORE_ADDR cpsr;
260
261 /* Every ARM frame unwinder can unwind the T bit of the CPSR, either
262 directly (from a signal frame or dummy frame) or by interpreting
263 the saved LR (from a prologue or DWARF frame). So consult it and
264 trust the unwinders. */
265 cpsr = get_frame_register_unsigned (frame, ARM_PS_REGNUM);
266
267 return (cpsr & CPSR_T) != 0;
268}
269
60c5725c
DJ
270/* Callback for VEC_lower_bound. */
271
272static inline int
273arm_compare_mapping_symbols (const struct arm_mapping_symbol *lhs,
274 const struct arm_mapping_symbol *rhs)
275{
276 return lhs->value < rhs->value;
277}
278
ed9a39eb 279/* Determine if the program counter specified in MEMADDR is in a Thumb
b39cc962
DJ
280 function. This function should be called for addresses unrelated to
281 any executing frame; otherwise, prefer arm_frame_is_thumb. */
c906108c 282
ad527d2e 283static int
2a451106 284arm_pc_is_thumb (CORE_ADDR memaddr)
c906108c 285{
60c5725c 286 struct obj_section *sec;
c5aa993b 287 struct minimal_symbol *sym;
c906108c 288
ed9a39eb 289 /* If bit 0 of the address is set, assume this is a Thumb address. */
c906108c
SS
290 if (IS_THUMB_ADDR (memaddr))
291 return 1;
292
0428b8f5
DJ
293 /* If the user wants to override the symbol table, let him. */
294 if (strcmp (arm_force_mode_string, "arm") == 0)
295 return 0;
296 if (strcmp (arm_force_mode_string, "thumb") == 0)
297 return 1;
298
60c5725c
DJ
299 /* If there are mapping symbols, consult them. */
300 sec = find_pc_section (memaddr);
301 if (sec != NULL)
302 {
303 struct arm_per_objfile *data;
304 VEC(arm_mapping_symbol_s) *map;
aded6f54
PA
305 struct arm_mapping_symbol map_key = { memaddr - obj_section_addr (sec),
306 0 };
60c5725c
DJ
307 unsigned int idx;
308
309 data = objfile_data (sec->objfile, arm_objfile_data_key);
310 if (data != NULL)
311 {
312 map = data->section_maps[sec->the_bfd_section->index];
313 if (!VEC_empty (arm_mapping_symbol_s, map))
314 {
315 struct arm_mapping_symbol *map_sym;
316
317 idx = VEC_lower_bound (arm_mapping_symbol_s, map, &map_key,
318 arm_compare_mapping_symbols);
319
320 /* VEC_lower_bound finds the earliest ordered insertion
321 point. If the following symbol starts at this exact
322 address, we use that; otherwise, the preceding
323 mapping symbol covers this address. */
324 if (idx < VEC_length (arm_mapping_symbol_s, map))
325 {
326 map_sym = VEC_index (arm_mapping_symbol_s, map, idx);
327 if (map_sym->value == map_key.value)
328 return map_sym->type == 't';
329 }
330
331 if (idx > 0)
332 {
333 map_sym = VEC_index (arm_mapping_symbol_s, map, idx - 1);
334 return map_sym->type == 't';
335 }
336 }
337 }
338 }
339
ed9a39eb 340 /* Thumb functions have a "special" bit set in minimal symbols. */
c906108c
SS
341 sym = lookup_minimal_symbol_by_pc (memaddr);
342 if (sym)
0428b8f5
DJ
343 return (MSYMBOL_IS_SPECIAL (sym));
344
345 /* If the user wants to override the fallback mode, let them. */
346 if (strcmp (arm_fallback_mode_string, "arm") == 0)
347 return 0;
348 if (strcmp (arm_fallback_mode_string, "thumb") == 0)
349 return 1;
350
351 /* If we couldn't find any symbol, but we're talking to a running
352 target, then trust the current value of $cpsr. This lets
353 "display/i $pc" always show the correct mode (though if there is
354 a symbol table we will not reach here, so it still may not be
355 displayed in the mode it will be executed). */
356 if (target_has_registers)
357 return arm_frame_is_thumb (get_current_frame ());
358
359 /* Otherwise we're out of luck; we assume ARM. */
360 return 0;
c906108c
SS
361}
362
181c1381 363/* Remove useless bits from addresses in a running program. */
34e8f22d 364static CORE_ADDR
24568a2c 365arm_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR val)
c906108c 366{
a3a2ee65 367 if (arm_apcs_32)
dd6be234 368 return UNMAKE_THUMB_ADDR (val);
c906108c 369 else
a3a2ee65 370 return (val & 0x03fffffc);
c906108c
SS
371}
372
181c1381
RE
373/* When reading symbols, we need to zap the low bit of the address,
374 which may be set to 1 for Thumb functions. */
34e8f22d 375static CORE_ADDR
24568a2c 376arm_smash_text_address (struct gdbarch *gdbarch, CORE_ADDR val)
181c1381
RE
377{
378 return val & ~1;
379}
380
29d73ae4
DJ
381/* Analyze a Thumb prologue, looking for a recognizable stack frame
382 and frame pointer. Scan until we encounter a store that could
383 clobber the stack frame unexpectedly, or an unknown instruction. */
c906108c
SS
384
385static CORE_ADDR
29d73ae4
DJ
386thumb_analyze_prologue (struct gdbarch *gdbarch,
387 CORE_ADDR start, CORE_ADDR limit,
388 struct arm_prologue_cache *cache)
c906108c 389{
29d73ae4
DJ
390 int i;
391 pv_t regs[16];
392 struct pv_area *stack;
393 struct cleanup *back_to;
394 CORE_ADDR offset;
da3c6d4a 395
29d73ae4
DJ
396 for (i = 0; i < 16; i++)
397 regs[i] = pv_register (i, 0);
55f960e1 398 stack = make_pv_area (ARM_SP_REGNUM, gdbarch_addr_bit (gdbarch));
29d73ae4
DJ
399 back_to = make_cleanup_free_pv_area (stack);
400
29d73ae4 401 while (start < limit)
c906108c 402 {
29d73ae4
DJ
403 unsigned short insn;
404
405 insn = read_memory_unsigned_integer (start, 2);
c906108c 406
9d4fde75
SS
407 if (gdbarch_byte_order_for_code (gdbarch) != gdbarch_byte_order (gdbarch))
408 insn = SWAP_SHORT (insn);
409
94c30b78 410 if ((insn & 0xfe00) == 0xb400) /* push { rlist } */
da59e081 411 {
29d73ae4
DJ
412 int regno;
413 int mask;
4be43953
DJ
414
415 if (pv_area_store_would_trash (stack, regs[ARM_SP_REGNUM]))
416 break;
29d73ae4
DJ
417
418 /* Bits 0-7 contain a mask for registers R0-R7. Bit 8 says
419 whether to save LR (R14). */
420 mask = (insn & 0xff) | ((insn & 0x100) << 6);
421
422 /* Calculate offsets of saved R0-R7 and LR. */
423 for (regno = ARM_LR_REGNUM; regno >= 0; regno--)
424 if (mask & (1 << regno))
425 {
29d73ae4
DJ
426 regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM],
427 -4);
428 pv_area_store (stack, regs[ARM_SP_REGNUM], 4, regs[regno]);
429 }
da59e081 430 }
da3c6d4a
MS
431 else if ((insn & 0xff00) == 0xb000) /* add sp, #simm OR
432 sub sp, #simm */
da59e081 433 {
29d73ae4
DJ
434 offset = (insn & 0x7f) << 2; /* get scaled offset */
435 if (insn & 0x80) /* Check for SUB. */
436 regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM],
437 -offset);
da59e081 438 else
29d73ae4
DJ
439 regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM],
440 offset);
da59e081
JM
441 }
442 else if ((insn & 0xff00) == 0xaf00) /* add r7, sp, #imm */
29d73ae4
DJ
443 regs[THUMB_FP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM],
444 (insn & 0xff) << 2);
445 else if ((insn & 0xff00) == 0x4600) /* mov hi, lo or mov lo, hi */
da59e081 446 {
29d73ae4
DJ
447 int dst_reg = (insn & 0x7) + ((insn & 0x80) >> 4);
448 int src_reg = (insn & 0x78) >> 3;
449 regs[dst_reg] = regs[src_reg];
da59e081 450 }
29d73ae4 451 else if ((insn & 0xf800) == 0x9000) /* str rd, [sp, #off] */
da59e081 452 {
29d73ae4
DJ
453 /* Handle stores to the stack. Normally pushes are used,
454 but with GCC -mtpcs-frame, there may be other stores
455 in the prologue to create the frame. */
456 int regno = (insn >> 8) & 0x7;
457 pv_t addr;
458
459 offset = (insn & 0xff) << 2;
460 addr = pv_add_constant (regs[ARM_SP_REGNUM], offset);
461
462 if (pv_area_store_would_trash (stack, addr))
463 break;
464
465 pv_area_store (stack, addr, 4, regs[regno]);
da59e081 466 }
29d73ae4 467 else
3d74b771 468 {
29d73ae4
DJ
469 /* We don't know what this instruction is. We're finished
470 scanning. NOTE: Recognizing more safe-to-ignore
471 instructions here will improve support for optimized
472 code. */
da3c6d4a 473 break;
3d74b771 474 }
29d73ae4
DJ
475
476 start += 2;
c906108c
SS
477 }
478
29d73ae4
DJ
479 if (cache == NULL)
480 {
481 do_cleanups (back_to);
482 return start;
483 }
484
29d73ae4
DJ
485 if (pv_is_register (regs[ARM_FP_REGNUM], ARM_SP_REGNUM))
486 {
487 /* Frame pointer is fp. Frame size is constant. */
488 cache->framereg = ARM_FP_REGNUM;
489 cache->framesize = -regs[ARM_FP_REGNUM].k;
490 }
491 else if (pv_is_register (regs[THUMB_FP_REGNUM], ARM_SP_REGNUM))
492 {
493 /* Frame pointer is r7. Frame size is constant. */
494 cache->framereg = THUMB_FP_REGNUM;
495 cache->framesize = -regs[THUMB_FP_REGNUM].k;
496 }
497 else if (pv_is_register (regs[ARM_SP_REGNUM], ARM_SP_REGNUM))
498 {
499 /* Try the stack pointer... this is a bit desperate. */
500 cache->framereg = ARM_SP_REGNUM;
501 cache->framesize = -regs[ARM_SP_REGNUM].k;
502 }
503 else
504 {
505 /* We're just out of luck. We don't know where the frame is. */
506 cache->framereg = -1;
507 cache->framesize = 0;
508 }
509
510 for (i = 0; i < 16; i++)
511 if (pv_area_find_reg (stack, gdbarch, i, &offset))
512 cache->saved_regs[i].addr = offset;
513
514 do_cleanups (back_to);
515 return start;
c906108c
SS
516}
517
da3c6d4a
MS
518/* Advance the PC across any function entry prologue instructions to
519 reach some "real" code.
34e8f22d
RE
520
521 The APCS (ARM Procedure Call Standard) defines the following
ed9a39eb 522 prologue:
c906108c 523
c5aa993b
JM
524 mov ip, sp
525 [stmfd sp!, {a1,a2,a3,a4}]
526 stmfd sp!, {...,fp,ip,lr,pc}
ed9a39eb
JM
527 [stfe f7, [sp, #-12]!]
528 [stfe f6, [sp, #-12]!]
529 [stfe f5, [sp, #-12]!]
530 [stfe f4, [sp, #-12]!]
531 sub fp, ip, #nn @@ nn == 20 or 4 depending on second insn */
c906108c 532
34e8f22d 533static CORE_ADDR
6093d2eb 534arm_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
c906108c
SS
535{
536 unsigned long inst;
537 CORE_ADDR skip_pc;
a89fea3c 538 CORE_ADDR func_addr, limit_pc;
c906108c
SS
539 struct symtab_and_line sal;
540
848cfffb 541 /* If we're in a dummy frame, don't even try to skip the prologue. */
d80b854b 542 if (deprecated_pc_in_call_dummy (gdbarch, pc))
848cfffb
AC
543 return pc;
544
a89fea3c
JL
545 /* See if we can determine the end of the prologue via the symbol table.
546 If so, then return either PC, or the PC after the prologue, whichever
547 is greater. */
548 if (find_pc_partial_function (pc, NULL, &func_addr, NULL))
c906108c 549 {
d80b854b
UW
550 CORE_ADDR post_prologue_pc
551 = skip_prologue_using_sal (gdbarch, func_addr);
a89fea3c
JL
552 if (post_prologue_pc != 0)
553 return max (pc, post_prologue_pc);
c906108c
SS
554 }
555
a89fea3c
JL
556 /* Can't determine prologue from the symbol table, need to examine
557 instructions. */
c906108c 558
a89fea3c
JL
559 /* Find an upper limit on the function prologue using the debug
560 information. If the debug information could not be used to provide
561 that bound, then use an arbitrary large number as the upper bound. */
b8d5e71d 562 /* Like arm_scan_prologue, stop no later than pc + 64. */
d80b854b 563 limit_pc = skip_prologue_using_sal (gdbarch, pc);
a89fea3c
JL
564 if (limit_pc == 0)
565 limit_pc = pc + 64; /* Magic. */
566
c906108c 567
29d73ae4
DJ
568 /* Check if this is Thumb code. */
569 if (arm_pc_is_thumb (pc))
a89fea3c 570 return thumb_analyze_prologue (gdbarch, pc, limit_pc, NULL);
29d73ae4 571
a89fea3c 572 for (skip_pc = pc; skip_pc < limit_pc; skip_pc += 4)
f43845b3 573 {
1c5bada0 574 inst = read_memory_unsigned_integer (skip_pc, 4);
f43845b3 575
9d4fde75
SS
576 if (gdbarch_byte_order_for_code (gdbarch) != gdbarch_byte_order (gdbarch))
577 inst = SWAP_INT (inst);
578
b8d5e71d
MS
579 /* "mov ip, sp" is no longer a required part of the prologue. */
580 if (inst == 0xe1a0c00d) /* mov ip, sp */
581 continue;
c906108c 582
28cd8767
JG
583 if ((inst & 0xfffff000) == 0xe28dc000) /* add ip, sp #n */
584 continue;
585
586 if ((inst & 0xfffff000) == 0xe24dc000) /* sub ip, sp #n */
587 continue;
588
b8d5e71d
MS
589 /* Some prologues begin with "str lr, [sp, #-4]!". */
590 if (inst == 0xe52de004) /* str lr, [sp, #-4]! */
591 continue;
c906108c 592
b8d5e71d
MS
593 if ((inst & 0xfffffff0) == 0xe92d0000) /* stmfd sp!,{a1,a2,a3,a4} */
594 continue;
c906108c 595
b8d5e71d
MS
596 if ((inst & 0xfffff800) == 0xe92dd800) /* stmfd sp!,{fp,ip,lr,pc} */
597 continue;
11d3b27d 598
b8d5e71d
MS
599 /* Any insns after this point may float into the code, if it makes
600 for better instruction scheduling, so we skip them only if we
601 find them, but still consider the function to be frame-ful. */
f43845b3 602
b8d5e71d
MS
603 /* We may have either one sfmfd instruction here, or several stfe
604 insns, depending on the version of floating point code we
605 support. */
606 if ((inst & 0xffbf0fff) == 0xec2d0200) /* sfmfd fn, <cnt>, [sp]! */
607 continue;
608
609 if ((inst & 0xffff8fff) == 0xed6d0103) /* stfe fn, [sp, #-12]! */
610 continue;
611
612 if ((inst & 0xfffff000) == 0xe24cb000) /* sub fp, ip, #nn */
613 continue;
614
615 if ((inst & 0xfffff000) == 0xe24dd000) /* sub sp, sp, #nn */
616 continue;
617
618 if ((inst & 0xffffc000) == 0xe54b0000 || /* strb r(0123),[r11,#-nn] */
619 (inst & 0xffffc0f0) == 0xe14b00b0 || /* strh r(0123),[r11,#-nn] */
620 (inst & 0xffffc000) == 0xe50b0000) /* str r(0123),[r11,#-nn] */
621 continue;
622
623 if ((inst & 0xffffc000) == 0xe5cd0000 || /* strb r(0123),[sp,#nn] */
624 (inst & 0xffffc0f0) == 0xe1cd00b0 || /* strh r(0123),[sp,#nn] */
625 (inst & 0xffffc000) == 0xe58d0000) /* str r(0123),[sp,#nn] */
626 continue;
627
628 /* Un-recognized instruction; stop scanning. */
629 break;
f43845b3 630 }
c906108c 631
b8d5e71d 632 return skip_pc; /* End of prologue */
c906108c 633}
94c30b78 634
c5aa993b 635/* *INDENT-OFF* */
c906108c
SS
636/* Function: thumb_scan_prologue (helper function for arm_scan_prologue)
637 This function decodes a Thumb function prologue to determine:
638 1) the size of the stack frame
639 2) which registers are saved on it
640 3) the offsets of saved regs
641 4) the offset from the stack pointer to the frame pointer
c906108c 642
da59e081
JM
643 A typical Thumb function prologue would create this stack frame
644 (offsets relative to FP)
c906108c
SS
645 old SP -> 24 stack parameters
646 20 LR
647 16 R7
648 R7 -> 0 local variables (16 bytes)
649 SP -> -12 additional stack space (12 bytes)
650 The frame size would thus be 36 bytes, and the frame offset would be
da59e081
JM
651 12 bytes. The frame register is R7.
652
da3c6d4a
MS
653 The comments for thumb_skip_prolog() describe the algorithm we use
654 to detect the end of the prolog. */
c5aa993b
JM
655/* *INDENT-ON* */
656
c906108c 657static void
be8626e0 658thumb_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR prev_pc,
b39cc962 659 CORE_ADDR block_addr, struct arm_prologue_cache *cache)
c906108c
SS
660{
661 CORE_ADDR prologue_start;
662 CORE_ADDR prologue_end;
663 CORE_ADDR current_pc;
c906108c 664
b39cc962
DJ
665 if (find_pc_partial_function (block_addr, NULL, &prologue_start,
666 &prologue_end))
c906108c
SS
667 {
668 struct symtab_and_line sal = find_pc_line (prologue_start, 0);
669
94c30b78 670 if (sal.line == 0) /* no line info, use current PC */
eb5492fa 671 prologue_end = prev_pc;
c906108c 672 else if (sal.end < prologue_end) /* next line begins after fn end */
94c30b78 673 prologue_end = sal.end; /* (probably means no prologue) */
c906108c
SS
674 }
675 else
f7060f85
DJ
676 /* We're in the boondocks: we have no idea where the start of the
677 function is. */
678 return;
c906108c 679
eb5492fa 680 prologue_end = min (prologue_end, prev_pc);
c906108c 681
be8626e0 682 thumb_analyze_prologue (gdbarch, prologue_start, prologue_end, cache);
c906108c
SS
683}
684
ed9a39eb 685/* This function decodes an ARM function prologue to determine:
c5aa993b
JM
686 1) the size of the stack frame
687 2) which registers are saved on it
688 3) the offsets of saved regs
689 4) the offset from the stack pointer to the frame pointer
c906108c
SS
690 This information is stored in the "extra" fields of the frame_info.
691
96baa820
JM
692 There are two basic forms for the ARM prologue. The fixed argument
693 function call will look like:
ed9a39eb
JM
694
695 mov ip, sp
696 stmfd sp!, {fp, ip, lr, pc}
697 sub fp, ip, #4
698 [sub sp, sp, #4]
96baa820 699
c906108c 700 Which would create this stack frame (offsets relative to FP):
ed9a39eb
JM
701 IP -> 4 (caller's stack)
702 FP -> 0 PC (points to address of stmfd instruction + 8 in callee)
703 -4 LR (return address in caller)
704 -8 IP (copy of caller's SP)
705 -12 FP (caller's FP)
706 SP -> -28 Local variables
707
c906108c 708 The frame size would thus be 32 bytes, and the frame offset would be
96baa820
JM
709 28 bytes. The stmfd call can also save any of the vN registers it
710 plans to use, which increases the frame size accordingly.
711
712 Note: The stored PC is 8 off of the STMFD instruction that stored it
713 because the ARM Store instructions always store PC + 8 when you read
714 the PC register.
ed9a39eb 715
96baa820
JM
716 A variable argument function call will look like:
717
ed9a39eb
JM
718 mov ip, sp
719 stmfd sp!, {a1, a2, a3, a4}
720 stmfd sp!, {fp, ip, lr, pc}
721 sub fp, ip, #20
722
96baa820 723 Which would create this stack frame (offsets relative to FP):
ed9a39eb
JM
724 IP -> 20 (caller's stack)
725 16 A4
726 12 A3
727 8 A2
728 4 A1
729 FP -> 0 PC (points to address of stmfd instruction + 8 in callee)
730 -4 LR (return address in caller)
731 -8 IP (copy of caller's SP)
732 -12 FP (caller's FP)
733 SP -> -28 Local variables
96baa820
JM
734
735 The frame size would thus be 48 bytes, and the frame offset would be
736 28 bytes.
737
738 There is another potential complication, which is that the optimizer
739 will try to separate the store of fp in the "stmfd" instruction from
740 the "sub fp, ip, #NN" instruction. Almost anything can be there, so
741 we just key on the stmfd, and then scan for the "sub fp, ip, #NN"...
742
743 Also, note, the original version of the ARM toolchain claimed that there
744 should be an
745
746 instruction at the end of the prologue. I have never seen GCC produce
747 this, and the ARM docs don't mention it. We still test for it below in
748 case it happens...
ed9a39eb
JM
749
750 */
c906108c
SS
751
752static void
a262aec2 753arm_scan_prologue (struct frame_info *this_frame,
2af46ca0 754 struct arm_prologue_cache *cache)
c906108c 755{
a262aec2 756 struct gdbarch *gdbarch = get_frame_arch (this_frame);
4be43953 757 int regno;
c906108c 758 CORE_ADDR prologue_start, prologue_end, current_pc;
a262aec2 759 CORE_ADDR prev_pc = get_frame_pc (this_frame);
b39cc962 760 CORE_ADDR block_addr = get_frame_address_in_block (this_frame);
4be43953
DJ
761 pv_t regs[ARM_FPS_REGNUM];
762 struct pv_area *stack;
763 struct cleanup *back_to;
764 CORE_ADDR offset;
c906108c 765
c906108c 766 /* Assume there is no frame until proven otherwise. */
9b8d791a
DJ
767 cache->framereg = ARM_SP_REGNUM;
768 cache->framesize = 0;
c906108c
SS
769
770 /* Check for Thumb prologue. */
b39cc962 771 if (arm_frame_is_thumb (this_frame))
c906108c 772 {
b39cc962 773 thumb_scan_prologue (gdbarch, prev_pc, block_addr, cache);
c906108c
SS
774 return;
775 }
776
777 /* Find the function prologue. If we can't find the function in
778 the symbol table, peek in the stack frame to find the PC. */
b39cc962
DJ
779 if (find_pc_partial_function (block_addr, NULL, &prologue_start,
780 &prologue_end))
c906108c 781 {
2a451106
KB
782 /* One way to find the end of the prologue (which works well
783 for unoptimized code) is to do the following:
784
785 struct symtab_and_line sal = find_pc_line (prologue_start, 0);
786
787 if (sal.line == 0)
eb5492fa 788 prologue_end = prev_pc;
2a451106
KB
789 else if (sal.end < prologue_end)
790 prologue_end = sal.end;
791
792 This mechanism is very accurate so long as the optimizer
793 doesn't move any instructions from the function body into the
794 prologue. If this happens, sal.end will be the last
795 instruction in the first hunk of prologue code just before
796 the first instruction that the scheduler has moved from
797 the body to the prologue.
798
799 In order to make sure that we scan all of the prologue
800 instructions, we use a slightly less accurate mechanism which
801 may scan more than necessary. To help compensate for this
802 lack of accuracy, the prologue scanning loop below contains
803 several clauses which'll cause the loop to terminate early if
804 an implausible prologue instruction is encountered.
805
806 The expression
807
808 prologue_start + 64
809
810 is a suitable endpoint since it accounts for the largest
811 possible prologue plus up to five instructions inserted by
94c30b78 812 the scheduler. */
2a451106
KB
813
814 if (prologue_end > prologue_start + 64)
815 {
94c30b78 816 prologue_end = prologue_start + 64; /* See above. */
2a451106 817 }
c906108c
SS
818 }
819 else
820 {
eb5492fa
DJ
821 /* We have no symbol information. Our only option is to assume this
822 function has a standard stack frame and the normal frame register.
823 Then, we can find the value of our frame pointer on entrance to
824 the callee (or at the present moment if this is the innermost frame).
825 The value stored there should be the address of the stmfd + 8. */
826 CORE_ADDR frame_loc;
827 LONGEST return_value;
828
a262aec2 829 frame_loc = get_frame_register_unsigned (this_frame, ARM_FP_REGNUM);
eb5492fa 830 if (!safe_read_memory_integer (frame_loc, 4, &return_value))
16a0f3e7
EZ
831 return;
832 else
833 {
bf6ae464 834 prologue_start = gdbarch_addr_bits_remove
2af46ca0 835 (gdbarch, return_value) - 8;
94c30b78 836 prologue_end = prologue_start + 64; /* See above. */
16a0f3e7 837 }
c906108c
SS
838 }
839
eb5492fa
DJ
840 if (prev_pc < prologue_end)
841 prologue_end = prev_pc;
842
c906108c 843 /* Now search the prologue looking for instructions that set up the
96baa820 844 frame pointer, adjust the stack pointer, and save registers.
ed9a39eb 845
96baa820
JM
846 Be careful, however, and if it doesn't look like a prologue,
847 don't try to scan it. If, for instance, a frameless function
848 begins with stmfd sp!, then we will tell ourselves there is
b8d5e71d 849 a frame, which will confuse stack traceback, as well as "finish"
96baa820
JM
850 and other operations that rely on a knowledge of the stack
851 traceback.
852
853 In the APCS, the prologue should start with "mov ip, sp" so
f43845b3 854 if we don't see this as the first insn, we will stop.
c906108c 855
f43845b3
MS
856 [Note: This doesn't seem to be true any longer, so it's now an
857 optional part of the prologue. - Kevin Buettner, 2001-11-20]
c906108c 858
f43845b3
MS
859 [Note further: The "mov ip,sp" only seems to be missing in
860 frameless functions at optimization level "-O2" or above,
861 in which case it is often (but not always) replaced by
b8d5e71d 862 "str lr, [sp, #-4]!". - Michael Snyder, 2002-04-23] */
d4473757 863
4be43953
DJ
864 for (regno = 0; regno < ARM_FPS_REGNUM; regno++)
865 regs[regno] = pv_register (regno, 0);
55f960e1 866 stack = make_pv_area (ARM_SP_REGNUM, gdbarch_addr_bit (gdbarch));
4be43953
DJ
867 back_to = make_cleanup_free_pv_area (stack);
868
94c30b78
MS
869 for (current_pc = prologue_start;
870 current_pc < prologue_end;
f43845b3 871 current_pc += 4)
96baa820 872 {
d4473757
KB
873 unsigned int insn = read_memory_unsigned_integer (current_pc, 4);
874
9d4fde75
SS
875 if (gdbarch_byte_order_for_code (gdbarch) != gdbarch_byte_order (gdbarch))
876 insn = SWAP_INT (insn);
877
94c30b78 878 if (insn == 0xe1a0c00d) /* mov ip, sp */
f43845b3 879 {
4be43953 880 regs[ARM_IP_REGNUM] = regs[ARM_SP_REGNUM];
28cd8767
JG
881 continue;
882 }
883 else if ((insn & 0xfffff000) == 0xe28dc000) /* add ip, sp #n */
884 {
885 unsigned imm = insn & 0xff; /* immediate value */
886 unsigned rot = (insn & 0xf00) >> 7; /* rotate amount */
887 imm = (imm >> rot) | (imm << (32 - rot));
4be43953 888 regs[ARM_IP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM], imm);
28cd8767
JG
889 continue;
890 }
891 else if ((insn & 0xfffff000) == 0xe24dc000) /* sub ip, sp #n */
892 {
893 unsigned imm = insn & 0xff; /* immediate value */
894 unsigned rot = (insn & 0xf00) >> 7; /* rotate amount */
895 imm = (imm >> rot) | (imm << (32 - rot));
4be43953 896 regs[ARM_IP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM], -imm);
f43845b3
MS
897 continue;
898 }
94c30b78 899 else if (insn == 0xe52de004) /* str lr, [sp, #-4]! */
f43845b3 900 {
4be43953
DJ
901 if (pv_area_store_would_trash (stack, regs[ARM_SP_REGNUM]))
902 break;
903 regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM], -4);
904 pv_area_store (stack, regs[ARM_SP_REGNUM], 4, regs[ARM_LR_REGNUM]);
f43845b3
MS
905 continue;
906 }
907 else if ((insn & 0xffff0000) == 0xe92d0000)
d4473757
KB
908 /* stmfd sp!, {..., fp, ip, lr, pc}
909 or
910 stmfd sp!, {a1, a2, a3, a4} */
c906108c 911 {
d4473757 912 int mask = insn & 0xffff;
ed9a39eb 913
4be43953
DJ
914 if (pv_area_store_would_trash (stack, regs[ARM_SP_REGNUM]))
915 break;
916
94c30b78 917 /* Calculate offsets of saved registers. */
34e8f22d 918 for (regno = ARM_PC_REGNUM; regno >= 0; regno--)
d4473757
KB
919 if (mask & (1 << regno))
920 {
4be43953
DJ
921 regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM], -4);
922 pv_area_store (stack, regs[ARM_SP_REGNUM], 4, regs[regno]);
d4473757
KB
923 }
924 }
b8d5e71d
MS
925 else if ((insn & 0xffffc000) == 0xe54b0000 || /* strb rx,[r11,#-n] */
926 (insn & 0xffffc0f0) == 0xe14b00b0 || /* strh rx,[r11,#-n] */
927 (insn & 0xffffc000) == 0xe50b0000) /* str rx,[r11,#-n] */
928 {
929 /* No need to add this to saved_regs -- it's just an arg reg. */
930 continue;
931 }
932 else if ((insn & 0xffffc000) == 0xe5cd0000 || /* strb rx,[sp,#n] */
933 (insn & 0xffffc0f0) == 0xe1cd00b0 || /* strh rx,[sp,#n] */
934 (insn & 0xffffc000) == 0xe58d0000) /* str rx,[sp,#n] */
f43845b3
MS
935 {
936 /* No need to add this to saved_regs -- it's just an arg reg. */
937 continue;
938 }
d4473757
KB
939 else if ((insn & 0xfffff000) == 0xe24cb000) /* sub fp, ip #n */
940 {
94c30b78
MS
941 unsigned imm = insn & 0xff; /* immediate value */
942 unsigned rot = (insn & 0xf00) >> 7; /* rotate amount */
d4473757 943 imm = (imm >> rot) | (imm << (32 - rot));
4be43953 944 regs[ARM_FP_REGNUM] = pv_add_constant (regs[ARM_IP_REGNUM], -imm);
d4473757
KB
945 }
946 else if ((insn & 0xfffff000) == 0xe24dd000) /* sub sp, sp #n */
947 {
94c30b78
MS
948 unsigned imm = insn & 0xff; /* immediate value */
949 unsigned rot = (insn & 0xf00) >> 7; /* rotate amount */
d4473757 950 imm = (imm >> rot) | (imm << (32 - rot));
4be43953 951 regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM], -imm);
d4473757 952 }
ff6f572f 953 else if ((insn & 0xffff7fff) == 0xed6d0103 /* stfe f?, [sp, -#c]! */
2af46ca0 954 && gdbarch_tdep (gdbarch)->have_fpa_registers)
d4473757 955 {
4be43953
DJ
956 if (pv_area_store_would_trash (stack, regs[ARM_SP_REGNUM]))
957 break;
958
959 regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM], -12);
34e8f22d 960 regno = ARM_F0_REGNUM + ((insn >> 12) & 0x07);
4be43953 961 pv_area_store (stack, regs[ARM_SP_REGNUM], 12, regs[regno]);
d4473757 962 }
ff6f572f 963 else if ((insn & 0xffbf0fff) == 0xec2d0200 /* sfmfd f0, 4, [sp!] */
2af46ca0 964 && gdbarch_tdep (gdbarch)->have_fpa_registers)
d4473757
KB
965 {
966 int n_saved_fp_regs;
967 unsigned int fp_start_reg, fp_bound_reg;
968
4be43953
DJ
969 if (pv_area_store_would_trash (stack, regs[ARM_SP_REGNUM]))
970 break;
971
94c30b78 972 if ((insn & 0x800) == 0x800) /* N0 is set */
96baa820 973 {
d4473757
KB
974 if ((insn & 0x40000) == 0x40000) /* N1 is set */
975 n_saved_fp_regs = 3;
976 else
977 n_saved_fp_regs = 1;
96baa820 978 }
d4473757 979 else
96baa820 980 {
d4473757
KB
981 if ((insn & 0x40000) == 0x40000) /* N1 is set */
982 n_saved_fp_regs = 2;
983 else
984 n_saved_fp_regs = 4;
96baa820 985 }
d4473757 986
34e8f22d 987 fp_start_reg = ARM_F0_REGNUM + ((insn >> 12) & 0x7);
d4473757
KB
988 fp_bound_reg = fp_start_reg + n_saved_fp_regs;
989 for (; fp_start_reg < fp_bound_reg; fp_start_reg++)
96baa820 990 {
4be43953
DJ
991 regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM], -12);
992 pv_area_store (stack, regs[ARM_SP_REGNUM], 12,
993 regs[fp_start_reg++]);
96baa820 994 }
c906108c 995 }
d4473757 996 else if ((insn & 0xf0000000) != 0xe0000000)
94c30b78 997 break; /* Condition not true, exit early */
b8d5e71d 998 else if ((insn & 0xfe200000) == 0xe8200000) /* ldm? */
94c30b78 999 break; /* Don't scan past a block load */
d4473757
KB
1000 else
1001 /* The optimizer might shove anything into the prologue,
94c30b78 1002 so we just skip what we don't recognize. */
d4473757 1003 continue;
c906108c
SS
1004 }
1005
4be43953
DJ
1006 /* The frame size is just the distance from the frame register
1007 to the original stack pointer. */
1008 if (pv_is_register (regs[ARM_FP_REGNUM], ARM_SP_REGNUM))
1009 {
1010 /* Frame pointer is fp. */
1011 cache->framereg = ARM_FP_REGNUM;
1012 cache->framesize = -regs[ARM_FP_REGNUM].k;
1013 }
1014 else if (pv_is_register (regs[ARM_SP_REGNUM], ARM_SP_REGNUM))
1015 {
1016 /* Try the stack pointer... this is a bit desperate. */
1017 cache->framereg = ARM_SP_REGNUM;
1018 cache->framesize = -regs[ARM_SP_REGNUM].k;
1019 }
d4473757 1020 else
4be43953
DJ
1021 {
1022 /* We're just out of luck. We don't know where the frame is. */
1023 cache->framereg = -1;
1024 cache->framesize = 0;
1025 }
1026
1027 for (regno = 0; regno < ARM_FPS_REGNUM; regno++)
1028 if (pv_area_find_reg (stack, gdbarch, regno, &offset))
1029 cache->saved_regs[regno].addr = offset;
1030
1031 do_cleanups (back_to);
c906108c
SS
1032}
1033
eb5492fa 1034static struct arm_prologue_cache *
a262aec2 1035arm_make_prologue_cache (struct frame_info *this_frame)
c906108c 1036{
eb5492fa
DJ
1037 int reg;
1038 struct arm_prologue_cache *cache;
1039 CORE_ADDR unwound_fp;
c5aa993b 1040
35d5d4ee 1041 cache = FRAME_OBSTACK_ZALLOC (struct arm_prologue_cache);
a262aec2 1042 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
c906108c 1043
a262aec2 1044 arm_scan_prologue (this_frame, cache);
848cfffb 1045
a262aec2 1046 unwound_fp = get_frame_register_unsigned (this_frame, cache->framereg);
eb5492fa
DJ
1047 if (unwound_fp == 0)
1048 return cache;
c906108c 1049
4be43953 1050 cache->prev_sp = unwound_fp + cache->framesize;
c906108c 1051
eb5492fa
DJ
1052 /* Calculate actual addresses of saved registers using offsets
1053 determined by arm_scan_prologue. */
a262aec2 1054 for (reg = 0; reg < gdbarch_num_regs (get_frame_arch (this_frame)); reg++)
e28a332c 1055 if (trad_frame_addr_p (cache->saved_regs, reg))
eb5492fa
DJ
1056 cache->saved_regs[reg].addr += cache->prev_sp;
1057
1058 return cache;
c906108c
SS
1059}
1060
eb5492fa
DJ
1061/* Our frame ID for a normal frame is the current function's starting PC
1062 and the caller's SP when we were called. */
c906108c 1063
148754e5 1064static void
a262aec2 1065arm_prologue_this_id (struct frame_info *this_frame,
eb5492fa
DJ
1066 void **this_cache,
1067 struct frame_id *this_id)
c906108c 1068{
eb5492fa
DJ
1069 struct arm_prologue_cache *cache;
1070 struct frame_id id;
2c404490 1071 CORE_ADDR pc, func;
f079148d 1072
eb5492fa 1073 if (*this_cache == NULL)
a262aec2 1074 *this_cache = arm_make_prologue_cache (this_frame);
eb5492fa 1075 cache = *this_cache;
2a451106 1076
2c404490
DJ
1077 /* This is meant to halt the backtrace at "_start". */
1078 pc = get_frame_pc (this_frame);
1079 if (pc <= gdbarch_tdep (get_frame_arch (this_frame))->lowest_pc)
eb5492fa 1080 return;
5a203e44 1081
eb5492fa
DJ
1082 /* If we've hit a wall, stop. */
1083 if (cache->prev_sp == 0)
1084 return;
24de872b 1085
2c404490 1086 func = get_frame_func (this_frame);
eb5492fa 1087 id = frame_id_build (cache->prev_sp, func);
eb5492fa 1088 *this_id = id;
c906108c
SS
1089}
1090
a262aec2
DJ
1091static struct value *
1092arm_prologue_prev_register (struct frame_info *this_frame,
eb5492fa 1093 void **this_cache,
a262aec2 1094 int prev_regnum)
24de872b 1095{
24568a2c 1096 struct gdbarch *gdbarch = get_frame_arch (this_frame);
24de872b
DJ
1097 struct arm_prologue_cache *cache;
1098
eb5492fa 1099 if (*this_cache == NULL)
a262aec2 1100 *this_cache = arm_make_prologue_cache (this_frame);
eb5492fa 1101 cache = *this_cache;
24de872b 1102
eb5492fa 1103 /* If we are asked to unwind the PC, then we need to return the LR
b39cc962
DJ
1104 instead. The prologue may save PC, but it will point into this
1105 frame's prologue, not the next frame's resume location. Also
1106 strip the saved T bit. A valid LR may have the low bit set, but
1107 a valid PC never does. */
eb5492fa 1108 if (prev_regnum == ARM_PC_REGNUM)
b39cc962
DJ
1109 {
1110 CORE_ADDR lr;
1111
1112 lr = frame_unwind_register_unsigned (this_frame, ARM_LR_REGNUM);
1113 return frame_unwind_got_constant (this_frame, prev_regnum,
24568a2c 1114 arm_addr_bits_remove (gdbarch, lr));
b39cc962 1115 }
24de872b 1116
eb5492fa 1117 /* SP is generally not saved to the stack, but this frame is
a262aec2 1118 identified by the next frame's stack pointer at the time of the call.
eb5492fa
DJ
1119 The value was already reconstructed into PREV_SP. */
1120 if (prev_regnum == ARM_SP_REGNUM)
a262aec2 1121 return frame_unwind_got_constant (this_frame, prev_regnum, cache->prev_sp);
eb5492fa 1122
b39cc962
DJ
1123 /* The CPSR may have been changed by the call instruction and by the
1124 called function. The only bit we can reconstruct is the T bit,
1125 by checking the low bit of LR as of the call. This is a reliable
1126 indicator of Thumb-ness except for some ARM v4T pre-interworking
1127 Thumb code, which could get away with a clear low bit as long as
1128 the called function did not use bx. Guess that all other
1129 bits are unchanged; the condition flags are presumably lost,
1130 but the processor status is likely valid. */
1131 if (prev_regnum == ARM_PS_REGNUM)
1132 {
1133 CORE_ADDR lr, cpsr;
1134
1135 cpsr = get_frame_register_unsigned (this_frame, prev_regnum);
1136 lr = frame_unwind_register_unsigned (this_frame, ARM_LR_REGNUM);
1137 if (IS_THUMB_ADDR (lr))
1138 cpsr |= CPSR_T;
1139 else
1140 cpsr &= ~CPSR_T;
1141 return frame_unwind_got_constant (this_frame, prev_regnum, cpsr);
1142 }
1143
a262aec2
DJ
1144 return trad_frame_get_prev_register (this_frame, cache->saved_regs,
1145 prev_regnum);
eb5492fa
DJ
1146}
1147
1148struct frame_unwind arm_prologue_unwind = {
1149 NORMAL_FRAME,
1150 arm_prologue_this_id,
a262aec2
DJ
1151 arm_prologue_prev_register,
1152 NULL,
1153 default_frame_sniffer
eb5492fa
DJ
1154};
1155
909cf6ea 1156static struct arm_prologue_cache *
a262aec2 1157arm_make_stub_cache (struct frame_info *this_frame)
909cf6ea
DJ
1158{
1159 int reg;
1160 struct arm_prologue_cache *cache;
1161 CORE_ADDR unwound_fp;
1162
35d5d4ee 1163 cache = FRAME_OBSTACK_ZALLOC (struct arm_prologue_cache);
a262aec2 1164 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
909cf6ea 1165
a262aec2 1166 cache->prev_sp = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM);
909cf6ea
DJ
1167
1168 return cache;
1169}
1170
1171/* Our frame ID for a stub frame is the current SP and LR. */
1172
1173static void
a262aec2 1174arm_stub_this_id (struct frame_info *this_frame,
909cf6ea
DJ
1175 void **this_cache,
1176 struct frame_id *this_id)
1177{
1178 struct arm_prologue_cache *cache;
1179
1180 if (*this_cache == NULL)
a262aec2 1181 *this_cache = arm_make_stub_cache (this_frame);
909cf6ea
DJ
1182 cache = *this_cache;
1183
a262aec2 1184 *this_id = frame_id_build (cache->prev_sp, get_frame_pc (this_frame));
909cf6ea
DJ
1185}
1186
a262aec2
DJ
1187static int
1188arm_stub_unwind_sniffer (const struct frame_unwind *self,
1189 struct frame_info *this_frame,
1190 void **this_prologue_cache)
909cf6ea 1191{
93d42b30 1192 CORE_ADDR addr_in_block;
909cf6ea
DJ
1193 char dummy[4];
1194
a262aec2 1195 addr_in_block = get_frame_address_in_block (this_frame);
93d42b30 1196 if (in_plt_section (addr_in_block, NULL)
a262aec2
DJ
1197 || target_read_memory (get_frame_pc (this_frame), dummy, 4) != 0)
1198 return 1;
909cf6ea 1199
a262aec2 1200 return 0;
909cf6ea
DJ
1201}
1202
a262aec2
DJ
1203struct frame_unwind arm_stub_unwind = {
1204 NORMAL_FRAME,
1205 arm_stub_this_id,
1206 arm_prologue_prev_register,
1207 NULL,
1208 arm_stub_unwind_sniffer
1209};
1210
24de872b 1211static CORE_ADDR
a262aec2 1212arm_normal_frame_base (struct frame_info *this_frame, void **this_cache)
24de872b
DJ
1213{
1214 struct arm_prologue_cache *cache;
1215
eb5492fa 1216 if (*this_cache == NULL)
a262aec2 1217 *this_cache = arm_make_prologue_cache (this_frame);
eb5492fa
DJ
1218 cache = *this_cache;
1219
4be43953 1220 return cache->prev_sp - cache->framesize;
24de872b
DJ
1221}
1222
eb5492fa
DJ
1223struct frame_base arm_normal_base = {
1224 &arm_prologue_unwind,
1225 arm_normal_frame_base,
1226 arm_normal_frame_base,
1227 arm_normal_frame_base
1228};
1229
a262aec2 1230/* Assuming THIS_FRAME is a dummy, return the frame ID of that
eb5492fa
DJ
1231 dummy frame. The frame ID's base needs to match the TOS value
1232 saved by save_dummy_frame_tos() and returned from
1233 arm_push_dummy_call, and the PC needs to match the dummy frame's
1234 breakpoint. */
c906108c 1235
eb5492fa 1236static struct frame_id
a262aec2 1237arm_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
c906108c 1238{
a262aec2
DJ
1239 return frame_id_build (get_frame_register_unsigned (this_frame, ARM_SP_REGNUM),
1240 get_frame_pc (this_frame));
eb5492fa 1241}
c3b4394c 1242
eb5492fa
DJ
1243/* Given THIS_FRAME, find the previous frame's resume PC (which will
1244 be used to construct the previous frame's ID, after looking up the
1245 containing function). */
c3b4394c 1246
eb5492fa
DJ
1247static CORE_ADDR
1248arm_unwind_pc (struct gdbarch *gdbarch, struct frame_info *this_frame)
1249{
1250 CORE_ADDR pc;
1251 pc = frame_unwind_register_unsigned (this_frame, ARM_PC_REGNUM);
24568a2c 1252 return arm_addr_bits_remove (gdbarch, pc);
eb5492fa
DJ
1253}
1254
1255static CORE_ADDR
1256arm_unwind_sp (struct gdbarch *gdbarch, struct frame_info *this_frame)
1257{
1258 return frame_unwind_register_unsigned (this_frame, ARM_SP_REGNUM);
c906108c
SS
1259}
1260
b39cc962
DJ
1261static struct value *
1262arm_dwarf2_prev_register (struct frame_info *this_frame, void **this_cache,
1263 int regnum)
1264{
24568a2c 1265 struct gdbarch * gdbarch = get_frame_arch (this_frame);
b39cc962
DJ
1266 CORE_ADDR lr, cpsr;
1267
1268 switch (regnum)
1269 {
1270 case ARM_PC_REGNUM:
1271 /* The PC is normally copied from the return column, which
1272 describes saves of LR. However, that version may have an
1273 extra bit set to indicate Thumb state. The bit is not
1274 part of the PC. */
1275 lr = frame_unwind_register_unsigned (this_frame, ARM_LR_REGNUM);
1276 return frame_unwind_got_constant (this_frame, regnum,
24568a2c 1277 arm_addr_bits_remove (gdbarch, lr));
b39cc962
DJ
1278
1279 case ARM_PS_REGNUM:
1280 /* Reconstruct the T bit; see arm_prologue_prev_register for details. */
ca38c58e 1281 cpsr = get_frame_register_unsigned (this_frame, regnum);
b39cc962
DJ
1282 lr = frame_unwind_register_unsigned (this_frame, ARM_LR_REGNUM);
1283 if (IS_THUMB_ADDR (lr))
1284 cpsr |= CPSR_T;
1285 else
1286 cpsr &= ~CPSR_T;
ca38c58e 1287 return frame_unwind_got_constant (this_frame, regnum, cpsr);
b39cc962
DJ
1288
1289 default:
1290 internal_error (__FILE__, __LINE__,
1291 _("Unexpected register %d"), regnum);
1292 }
1293}
1294
1295static void
1296arm_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
1297 struct dwarf2_frame_state_reg *reg,
1298 struct frame_info *this_frame)
1299{
1300 switch (regnum)
1301 {
1302 case ARM_PC_REGNUM:
1303 case ARM_PS_REGNUM:
1304 reg->how = DWARF2_FRAME_REG_FN;
1305 reg->loc.fn = arm_dwarf2_prev_register;
1306 break;
1307 case ARM_SP_REGNUM:
1308 reg->how = DWARF2_FRAME_REG_CFA;
1309 break;
1310 }
1311}
1312
2dd604e7
RE
1313/* When arguments must be pushed onto the stack, they go on in reverse
1314 order. The code below implements a FILO (stack) to do this. */
1315
1316struct stack_item
1317{
1318 int len;
1319 struct stack_item *prev;
1320 void *data;
1321};
1322
1323static struct stack_item *
1324push_stack_item (struct stack_item *prev, void *contents, int len)
1325{
1326 struct stack_item *si;
1327 si = xmalloc (sizeof (struct stack_item));
226c7fbc 1328 si->data = xmalloc (len);
2dd604e7
RE
1329 si->len = len;
1330 si->prev = prev;
1331 memcpy (si->data, contents, len);
1332 return si;
1333}
1334
1335static struct stack_item *
1336pop_stack_item (struct stack_item *si)
1337{
1338 struct stack_item *dead = si;
1339 si = si->prev;
1340 xfree (dead->data);
1341 xfree (dead);
1342 return si;
1343}
1344
2af48f68
PB
1345
1346/* Return the alignment (in bytes) of the given type. */
1347
1348static int
1349arm_type_align (struct type *t)
1350{
1351 int n;
1352 int align;
1353 int falign;
1354
1355 t = check_typedef (t);
1356 switch (TYPE_CODE (t))
1357 {
1358 default:
1359 /* Should never happen. */
1360 internal_error (__FILE__, __LINE__, _("unknown type alignment"));
1361 return 4;
1362
1363 case TYPE_CODE_PTR:
1364 case TYPE_CODE_ENUM:
1365 case TYPE_CODE_INT:
1366 case TYPE_CODE_FLT:
1367 case TYPE_CODE_SET:
1368 case TYPE_CODE_RANGE:
1369 case TYPE_CODE_BITSTRING:
1370 case TYPE_CODE_REF:
1371 case TYPE_CODE_CHAR:
1372 case TYPE_CODE_BOOL:
1373 return TYPE_LENGTH (t);
1374
1375 case TYPE_CODE_ARRAY:
1376 case TYPE_CODE_COMPLEX:
1377 /* TODO: What about vector types? */
1378 return arm_type_align (TYPE_TARGET_TYPE (t));
1379
1380 case TYPE_CODE_STRUCT:
1381 case TYPE_CODE_UNION:
1382 align = 1;
1383 for (n = 0; n < TYPE_NFIELDS (t); n++)
1384 {
1385 falign = arm_type_align (TYPE_FIELD_TYPE (t, n));
1386 if (falign > align)
1387 align = falign;
1388 }
1389 return align;
1390 }
1391}
1392
2dd604e7
RE
1393/* We currently only support passing parameters in integer registers. This
1394 conforms with GCC's default model. Several other variants exist and
1395 we should probably support some of them based on the selected ABI. */
1396
1397static CORE_ADDR
7d9b040b 1398arm_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
6a65450a
AC
1399 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
1400 struct value **args, CORE_ADDR sp, int struct_return,
1401 CORE_ADDR struct_addr)
2dd604e7
RE
1402{
1403 int argnum;
1404 int argreg;
1405 int nstack;
1406 struct stack_item *si = NULL;
1407
6a65450a
AC
1408 /* Set the return address. For the ARM, the return breakpoint is
1409 always at BP_ADDR. */
2dd604e7 1410 /* XXX Fix for Thumb. */
6a65450a 1411 regcache_cooked_write_unsigned (regcache, ARM_LR_REGNUM, bp_addr);
2dd604e7
RE
1412
1413 /* Walk through the list of args and determine how large a temporary
1414 stack is required. Need to take care here as structs may be
1415 passed on the stack, and we have to to push them. */
1416 nstack = 0;
1417
1418 argreg = ARM_A1_REGNUM;
1419 nstack = 0;
1420
2dd604e7
RE
1421 /* The struct_return pointer occupies the first parameter
1422 passing register. */
1423 if (struct_return)
1424 {
1425 if (arm_debug)
1426 fprintf_unfiltered (gdb_stdlog, "struct return in %s = 0x%s\n",
2af46ca0 1427 gdbarch_register_name (gdbarch, argreg),
c9f4d572 1428 paddr (struct_addr));
2dd604e7
RE
1429 regcache_cooked_write_unsigned (regcache, argreg, struct_addr);
1430 argreg++;
1431 }
1432
1433 for (argnum = 0; argnum < nargs; argnum++)
1434 {
1435 int len;
1436 struct type *arg_type;
1437 struct type *target_type;
1438 enum type_code typecode;
0fd88904 1439 bfd_byte *val;
2af48f68 1440 int align;
2dd604e7 1441
df407dfe 1442 arg_type = check_typedef (value_type (args[argnum]));
2dd604e7
RE
1443 len = TYPE_LENGTH (arg_type);
1444 target_type = TYPE_TARGET_TYPE (arg_type);
1445 typecode = TYPE_CODE (arg_type);
0fd88904 1446 val = value_contents_writeable (args[argnum]);
2dd604e7 1447
2af48f68
PB
1448 align = arm_type_align (arg_type);
1449 /* Round alignment up to a whole number of words. */
1450 align = (align + INT_REGISTER_SIZE - 1) & ~(INT_REGISTER_SIZE - 1);
1451 /* Different ABIs have different maximum alignments. */
1452 if (gdbarch_tdep (gdbarch)->arm_abi == ARM_ABI_APCS)
1453 {
1454 /* The APCS ABI only requires word alignment. */
1455 align = INT_REGISTER_SIZE;
1456 }
1457 else
1458 {
1459 /* The AAPCS requires at most doubleword alignment. */
1460 if (align > INT_REGISTER_SIZE * 2)
1461 align = INT_REGISTER_SIZE * 2;
1462 }
1463
1464 /* Push stack padding for dowubleword alignment. */
1465 if (nstack & (align - 1))
1466 {
1467 si = push_stack_item (si, val, INT_REGISTER_SIZE);
1468 nstack += INT_REGISTER_SIZE;
1469 }
1470
1471 /* Doubleword aligned quantities must go in even register pairs. */
1472 if (argreg <= ARM_LAST_ARG_REGNUM
1473 && align > INT_REGISTER_SIZE
1474 && argreg & 1)
1475 argreg++;
1476
2dd604e7
RE
1477 /* If the argument is a pointer to a function, and it is a
1478 Thumb function, create a LOCAL copy of the value and set
1479 the THUMB bit in it. */
1480 if (TYPE_CODE_PTR == typecode
1481 && target_type != NULL
1482 && TYPE_CODE_FUNC == TYPE_CODE (target_type))
1483 {
7c0b4a20 1484 CORE_ADDR regval = extract_unsigned_integer (val, len);
2dd604e7
RE
1485 if (arm_pc_is_thumb (regval))
1486 {
1487 val = alloca (len);
fbd9dcd3 1488 store_unsigned_integer (val, len, MAKE_THUMB_ADDR (regval));
2dd604e7
RE
1489 }
1490 }
1491
1492 /* Copy the argument to general registers or the stack in
1493 register-sized pieces. Large arguments are split between
1494 registers and stack. */
1495 while (len > 0)
1496 {
f0c9063c 1497 int partial_len = len < INT_REGISTER_SIZE ? len : INT_REGISTER_SIZE;
2dd604e7
RE
1498
1499 if (argreg <= ARM_LAST_ARG_REGNUM)
1500 {
1501 /* The argument is being passed in a general purpose
1502 register. */
7c0b4a20 1503 CORE_ADDR regval = extract_unsigned_integer (val, partial_len);
2af46ca0 1504 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
8bf8793c 1505 regval <<= (INT_REGISTER_SIZE - partial_len) * 8;
2dd604e7
RE
1506 if (arm_debug)
1507 fprintf_unfiltered (gdb_stdlog, "arg %d in %s = 0x%s\n",
c9f4d572
UW
1508 argnum,
1509 gdbarch_register_name
2af46ca0 1510 (gdbarch, argreg),
f0c9063c 1511 phex (regval, INT_REGISTER_SIZE));
2dd604e7
RE
1512 regcache_cooked_write_unsigned (regcache, argreg, regval);
1513 argreg++;
1514 }
1515 else
1516 {
1517 /* Push the arguments onto the stack. */
1518 if (arm_debug)
1519 fprintf_unfiltered (gdb_stdlog, "arg %d @ sp + %d\n",
1520 argnum, nstack);
f0c9063c
UW
1521 si = push_stack_item (si, val, INT_REGISTER_SIZE);
1522 nstack += INT_REGISTER_SIZE;
2dd604e7
RE
1523 }
1524
1525 len -= partial_len;
1526 val += partial_len;
1527 }
1528 }
1529 /* If we have an odd number of words to push, then decrement the stack
1530 by one word now, so first stack argument will be dword aligned. */
1531 if (nstack & 4)
1532 sp -= 4;
1533
1534 while (si)
1535 {
1536 sp -= si->len;
1537 write_memory (sp, si->data, si->len);
1538 si = pop_stack_item (si);
1539 }
1540
1541 /* Finally, update teh SP register. */
1542 regcache_cooked_write_unsigned (regcache, ARM_SP_REGNUM, sp);
1543
1544 return sp;
1545}
1546
f53f0d0b
PB
1547
1548/* Always align the frame to an 8-byte boundary. This is required on
1549 some platforms and harmless on the rest. */
1550
1551static CORE_ADDR
1552arm_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
1553{
1554 /* Align the stack to eight bytes. */
1555 return sp & ~ (CORE_ADDR) 7;
1556}
1557
c906108c 1558static void
ed9a39eb 1559print_fpu_flags (int flags)
c906108c 1560{
c5aa993b
JM
1561 if (flags & (1 << 0))
1562 fputs ("IVO ", stdout);
1563 if (flags & (1 << 1))
1564 fputs ("DVZ ", stdout);
1565 if (flags & (1 << 2))
1566 fputs ("OFL ", stdout);
1567 if (flags & (1 << 3))
1568 fputs ("UFL ", stdout);
1569 if (flags & (1 << 4))
1570 fputs ("INX ", stdout);
1571 putchar ('\n');
c906108c
SS
1572}
1573
5e74b15c
RE
1574/* Print interesting information about the floating point processor
1575 (if present) or emulator. */
34e8f22d 1576static void
d855c300 1577arm_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
23e3a7ac 1578 struct frame_info *frame, const char *args)
c906108c 1579{
9c9acae0 1580 unsigned long status = get_frame_register_unsigned (frame, ARM_FPS_REGNUM);
c5aa993b
JM
1581 int type;
1582
1583 type = (status >> 24) & 127;
edefbb7c
AC
1584 if (status & (1 << 31))
1585 printf (_("Hardware FPU type %d\n"), type);
1586 else
1587 printf (_("Software FPU type %d\n"), type);
1588 /* i18n: [floating point unit] mask */
1589 fputs (_("mask: "), stdout);
c5aa993b 1590 print_fpu_flags (status >> 16);
edefbb7c
AC
1591 /* i18n: [floating point unit] flags */
1592 fputs (_("flags: "), stdout);
c5aa993b 1593 print_fpu_flags (status);
c906108c
SS
1594}
1595
34e8f22d
RE
1596/* Return the GDB type object for the "standard" data type of data in
1597 register N. */
1598
1599static struct type *
7a5ea0d4 1600arm_register_type (struct gdbarch *gdbarch, int regnum)
032758dc 1601{
34e8f22d 1602 if (regnum >= ARM_F0_REGNUM && regnum < ARM_F0_REGNUM + NUM_FREGS)
8da61cc4 1603 return builtin_type_arm_ext;
e4c16157 1604 else if (regnum == ARM_SP_REGNUM)
0dfff4cb 1605 return builtin_type (gdbarch)->builtin_data_ptr;
e4c16157 1606 else if (regnum == ARM_PC_REGNUM)
0dfff4cb 1607 return builtin_type (gdbarch)->builtin_func_ptr;
ff6f572f
DJ
1608 else if (regnum >= ARRAY_SIZE (arm_register_names))
1609 /* These registers are only supported on targets which supply
1610 an XML description. */
1611 return builtin_type_int0;
032758dc 1612 else
e4c16157 1613 return builtin_type_uint32;
032758dc
AC
1614}
1615
ff6f572f
DJ
1616/* Map a DWARF register REGNUM onto the appropriate GDB register
1617 number. */
1618
1619static int
d3f73121 1620arm_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
ff6f572f
DJ
1621{
1622 /* Core integer regs. */
1623 if (reg >= 0 && reg <= 15)
1624 return reg;
1625
1626 /* Legacy FPA encoding. These were once used in a way which
1627 overlapped with VFP register numbering, so their use is
1628 discouraged, but GDB doesn't support the ARM toolchain
1629 which used them for VFP. */
1630 if (reg >= 16 && reg <= 23)
1631 return ARM_F0_REGNUM + reg - 16;
1632
1633 /* New assignments for the FPA registers. */
1634 if (reg >= 96 && reg <= 103)
1635 return ARM_F0_REGNUM + reg - 96;
1636
1637 /* WMMX register assignments. */
1638 if (reg >= 104 && reg <= 111)
1639 return ARM_WCGR0_REGNUM + reg - 104;
1640
1641 if (reg >= 112 && reg <= 127)
1642 return ARM_WR0_REGNUM + reg - 112;
1643
1644 if (reg >= 192 && reg <= 199)
1645 return ARM_WC0_REGNUM + reg - 192;
1646
1647 return -1;
1648}
1649
26216b98
AC
1650/* Map GDB internal REGNUM onto the Arm simulator register numbers. */
1651static int
e7faf938 1652arm_register_sim_regno (struct gdbarch *gdbarch, int regnum)
26216b98
AC
1653{
1654 int reg = regnum;
e7faf938 1655 gdb_assert (reg >= 0 && reg < gdbarch_num_regs (gdbarch));
26216b98 1656
ff6f572f
DJ
1657 if (regnum >= ARM_WR0_REGNUM && regnum <= ARM_WR15_REGNUM)
1658 return regnum - ARM_WR0_REGNUM + SIM_ARM_IWMMXT_COP0R0_REGNUM;
1659
1660 if (regnum >= ARM_WC0_REGNUM && regnum <= ARM_WC7_REGNUM)
1661 return regnum - ARM_WC0_REGNUM + SIM_ARM_IWMMXT_COP1R0_REGNUM;
1662
1663 if (regnum >= ARM_WCGR0_REGNUM && regnum <= ARM_WCGR7_REGNUM)
1664 return regnum - ARM_WCGR0_REGNUM + SIM_ARM_IWMMXT_COP1R8_REGNUM;
1665
26216b98
AC
1666 if (reg < NUM_GREGS)
1667 return SIM_ARM_R0_REGNUM + reg;
1668 reg -= NUM_GREGS;
1669
1670 if (reg < NUM_FREGS)
1671 return SIM_ARM_FP0_REGNUM + reg;
1672 reg -= NUM_FREGS;
1673
1674 if (reg < NUM_SREGS)
1675 return SIM_ARM_FPS_REGNUM + reg;
1676 reg -= NUM_SREGS;
1677
edefbb7c 1678 internal_error (__FILE__, __LINE__, _("Bad REGNUM %d"), regnum);
26216b98 1679}
34e8f22d 1680
a37b3cc0
AC
1681/* NOTE: cagney/2001-08-20: Both convert_from_extended() and
1682 convert_to_extended() use floatformat_arm_ext_littlebyte_bigword.
1683 It is thought that this is is the floating-point register format on
1684 little-endian systems. */
c906108c 1685
ed9a39eb 1686static void
b508a996 1687convert_from_extended (const struct floatformat *fmt, const void *ptr,
be8626e0 1688 void *dbl, int endianess)
c906108c 1689{
a37b3cc0 1690 DOUBLEST d;
be8626e0
MD
1691
1692 if (endianess == BFD_ENDIAN_BIG)
a37b3cc0
AC
1693 floatformat_to_doublest (&floatformat_arm_ext_big, ptr, &d);
1694 else
1695 floatformat_to_doublest (&floatformat_arm_ext_littlebyte_bigword,
1696 ptr, &d);
b508a996 1697 floatformat_from_doublest (fmt, &d, dbl);
c906108c
SS
1698}
1699
34e8f22d 1700static void
be8626e0
MD
1701convert_to_extended (const struct floatformat *fmt, void *dbl, const void *ptr,
1702 int endianess)
c906108c 1703{
a37b3cc0 1704 DOUBLEST d;
be8626e0 1705
b508a996 1706 floatformat_to_doublest (fmt, ptr, &d);
be8626e0 1707 if (endianess == BFD_ENDIAN_BIG)
a37b3cc0
AC
1708 floatformat_from_doublest (&floatformat_arm_ext_big, &d, dbl);
1709 else
1710 floatformat_from_doublest (&floatformat_arm_ext_littlebyte_bigword,
1711 &d, dbl);
c906108c 1712}
ed9a39eb 1713
c906108c 1714static int
ed9a39eb 1715condition_true (unsigned long cond, unsigned long status_reg)
c906108c
SS
1716{
1717 if (cond == INST_AL || cond == INST_NV)
1718 return 1;
1719
1720 switch (cond)
1721 {
1722 case INST_EQ:
1723 return ((status_reg & FLAG_Z) != 0);
1724 case INST_NE:
1725 return ((status_reg & FLAG_Z) == 0);
1726 case INST_CS:
1727 return ((status_reg & FLAG_C) != 0);
1728 case INST_CC:
1729 return ((status_reg & FLAG_C) == 0);
1730 case INST_MI:
1731 return ((status_reg & FLAG_N) != 0);
1732 case INST_PL:
1733 return ((status_reg & FLAG_N) == 0);
1734 case INST_VS:
1735 return ((status_reg & FLAG_V) != 0);
1736 case INST_VC:
1737 return ((status_reg & FLAG_V) == 0);
1738 case INST_HI:
1739 return ((status_reg & (FLAG_C | FLAG_Z)) == FLAG_C);
1740 case INST_LS:
1741 return ((status_reg & (FLAG_C | FLAG_Z)) != FLAG_C);
1742 case INST_GE:
1743 return (((status_reg & FLAG_N) == 0) == ((status_reg & FLAG_V) == 0));
1744 case INST_LT:
1745 return (((status_reg & FLAG_N) == 0) != ((status_reg & FLAG_V) == 0));
1746 case INST_GT:
1747 return (((status_reg & FLAG_Z) == 0) &&
ed9a39eb 1748 (((status_reg & FLAG_N) == 0) == ((status_reg & FLAG_V) == 0)));
c906108c
SS
1749 case INST_LE:
1750 return (((status_reg & FLAG_Z) != 0) ||
ed9a39eb 1751 (((status_reg & FLAG_N) == 0) != ((status_reg & FLAG_V) == 0)));
c906108c
SS
1752 }
1753 return 1;
1754}
1755
9512d7fd 1756/* Support routines for single stepping. Calculate the next PC value. */
c906108c
SS
1757#define submask(x) ((1L << ((x) + 1)) - 1)
1758#define bit(obj,st) (((obj) >> (st)) & 1)
1759#define bits(obj,st,fn) (((obj) >> (st)) & submask ((fn) - (st)))
1760#define sbits(obj,st,fn) \
1761 ((long) (bits(obj,st,fn) | ((long) bit(obj,fn) * ~ submask (fn - st))))
1762#define BranchDest(addr,instr) \
1763 ((CORE_ADDR) (((long) (addr)) + 8 + (sbits (instr, 0, 23) << 2)))
1764#define ARM_PC_32 1
1765
1766static unsigned long
0b1b3e42
UW
1767shifted_reg_val (struct frame_info *frame, unsigned long inst, int carry,
1768 unsigned long pc_val, unsigned long status_reg)
c906108c
SS
1769{
1770 unsigned long res, shift;
1771 int rm = bits (inst, 0, 3);
1772 unsigned long shifttype = bits (inst, 5, 6);
c5aa993b
JM
1773
1774 if (bit (inst, 4))
c906108c
SS
1775 {
1776 int rs = bits (inst, 8, 11);
0b1b3e42
UW
1777 shift = (rs == 15 ? pc_val + 8
1778 : get_frame_register_unsigned (frame, rs)) & 0xFF;
c906108c
SS
1779 }
1780 else
1781 shift = bits (inst, 7, 11);
c5aa993b
JM
1782
1783 res = (rm == 15
c906108c 1784 ? ((pc_val | (ARM_PC_32 ? 0 : status_reg))
c5aa993b 1785 + (bit (inst, 4) ? 12 : 8))
0b1b3e42 1786 : get_frame_register_unsigned (frame, rm));
c906108c
SS
1787
1788 switch (shifttype)
1789 {
c5aa993b 1790 case 0: /* LSL */
c906108c
SS
1791 res = shift >= 32 ? 0 : res << shift;
1792 break;
c5aa993b
JM
1793
1794 case 1: /* LSR */
c906108c
SS
1795 res = shift >= 32 ? 0 : res >> shift;
1796 break;
1797
c5aa993b
JM
1798 case 2: /* ASR */
1799 if (shift >= 32)
1800 shift = 31;
c906108c
SS
1801 res = ((res & 0x80000000L)
1802 ? ~((~res) >> shift) : res >> shift);
1803 break;
1804
c5aa993b 1805 case 3: /* ROR/RRX */
c906108c
SS
1806 shift &= 31;
1807 if (shift == 0)
1808 res = (res >> 1) | (carry ? 0x80000000L : 0);
1809 else
c5aa993b 1810 res = (res >> shift) | (res << (32 - shift));
c906108c
SS
1811 break;
1812 }
1813
1814 return res & 0xffffffff;
1815}
1816
c906108c
SS
1817/* Return number of 1-bits in VAL. */
1818
1819static int
ed9a39eb 1820bitcount (unsigned long val)
c906108c
SS
1821{
1822 int nbits;
1823 for (nbits = 0; val != 0; nbits++)
c5aa993b 1824 val &= val - 1; /* delete rightmost 1-bit in val */
c906108c
SS
1825 return nbits;
1826}
1827
ad527d2e 1828static CORE_ADDR
0b1b3e42 1829thumb_get_next_pc (struct frame_info *frame, CORE_ADDR pc)
c906108c 1830{
2af46ca0 1831 struct gdbarch *gdbarch = get_frame_arch (frame);
c5aa993b 1832 unsigned long pc_val = ((unsigned long) pc) + 4; /* PC after prefetch */
1c5bada0 1833 unsigned short inst1 = read_memory_unsigned_integer (pc, 2);
94c30b78 1834 CORE_ADDR nextpc = pc + 2; /* default is next instruction */
c906108c
SS
1835 unsigned long offset;
1836
9d4fde75
SS
1837 if (gdbarch_byte_order_for_code (gdbarch) != gdbarch_byte_order (gdbarch))
1838 inst1 = SWAP_SHORT (inst1);
1839
c906108c
SS
1840 if ((inst1 & 0xff00) == 0xbd00) /* pop {rlist, pc} */
1841 {
1842 CORE_ADDR sp;
1843
1844 /* Fetch the saved PC from the stack. It's stored above
1845 all of the other registers. */
f0c9063c 1846 offset = bitcount (bits (inst1, 0, 7)) * INT_REGISTER_SIZE;
0b1b3e42 1847 sp = get_frame_register_unsigned (frame, ARM_SP_REGNUM);
1c5bada0 1848 nextpc = (CORE_ADDR) read_memory_unsigned_integer (sp + offset, 4);
2af46ca0 1849 nextpc = gdbarch_addr_bits_remove (gdbarch, nextpc);
c906108c 1850 if (nextpc == pc)
edefbb7c 1851 error (_("Infinite loop detected"));
c906108c
SS
1852 }
1853 else if ((inst1 & 0xf000) == 0xd000) /* conditional branch */
1854 {
0b1b3e42 1855 unsigned long status = get_frame_register_unsigned (frame, ARM_PS_REGNUM);
c5aa993b 1856 unsigned long cond = bits (inst1, 8, 11);
94c30b78 1857 if (cond != 0x0f && condition_true (cond, status)) /* 0x0f = SWI */
c906108c
SS
1858 nextpc = pc_val + (sbits (inst1, 0, 7) << 1);
1859 }
1860 else if ((inst1 & 0xf800) == 0xe000) /* unconditional branch */
1861 {
1862 nextpc = pc_val + (sbits (inst1, 0, 10) << 1);
1863 }
aa17d93e 1864 else if ((inst1 & 0xf800) == 0xf000) /* long branch with link, and blx */
c906108c 1865 {
1c5bada0 1866 unsigned short inst2 = read_memory_unsigned_integer (pc + 2, 2);
9d4fde75
SS
1867 if (gdbarch_byte_order_for_code (gdbarch) != gdbarch_byte_order (gdbarch))
1868 inst2 = SWAP_SHORT (inst2);
c5aa993b 1869 offset = (sbits (inst1, 0, 10) << 12) + (bits (inst2, 0, 10) << 1);
c906108c 1870 nextpc = pc_val + offset;
aa17d93e
DJ
1871 /* For BLX make sure to clear the low bits. */
1872 if (bits (inst2, 11, 12) == 1)
1873 nextpc = nextpc & 0xfffffffc;
c906108c 1874 }
aa17d93e 1875 else if ((inst1 & 0xff00) == 0x4700) /* bx REG, blx REG */
9498281f
DJ
1876 {
1877 if (bits (inst1, 3, 6) == 0x0f)
1878 nextpc = pc_val;
1879 else
0b1b3e42 1880 nextpc = get_frame_register_unsigned (frame, bits (inst1, 3, 6));
9498281f 1881
2af46ca0 1882 nextpc = gdbarch_addr_bits_remove (gdbarch, nextpc);
9498281f 1883 if (nextpc == pc)
edefbb7c 1884 error (_("Infinite loop detected"));
9498281f 1885 }
c906108c
SS
1886
1887 return nextpc;
1888}
1889
daddc3c1 1890CORE_ADDR
0b1b3e42 1891arm_get_next_pc (struct frame_info *frame, CORE_ADDR pc)
c906108c 1892{
2af46ca0 1893 struct gdbarch *gdbarch = get_frame_arch (frame);
c906108c
SS
1894 unsigned long pc_val;
1895 unsigned long this_instr;
1896 unsigned long status;
1897 CORE_ADDR nextpc;
1898
b39cc962 1899 if (arm_frame_is_thumb (frame))
0b1b3e42 1900 return thumb_get_next_pc (frame, pc);
c906108c
SS
1901
1902 pc_val = (unsigned long) pc;
1c5bada0 1903 this_instr = read_memory_unsigned_integer (pc, 4);
9d4fde75
SS
1904
1905 if (gdbarch_byte_order_for_code (gdbarch) != gdbarch_byte_order (gdbarch))
1906 this_instr = SWAP_INT (this_instr);
1907
0b1b3e42 1908 status = get_frame_register_unsigned (frame, ARM_PS_REGNUM);
c5aa993b 1909 nextpc = (CORE_ADDR) (pc_val + 4); /* Default case */
c906108c 1910
daddc3c1
DJ
1911 if (bits (this_instr, 28, 31) == INST_NV)
1912 switch (bits (this_instr, 24, 27))
1913 {
1914 case 0xa:
1915 case 0xb:
1916 {
1917 /* Branch with Link and change to Thumb. */
1918 nextpc = BranchDest (pc, this_instr);
1919 nextpc |= bit (this_instr, 24) << 1;
1920
e1e01acd 1921 nextpc = gdbarch_addr_bits_remove (gdbarch, nextpc);
daddc3c1
DJ
1922 if (nextpc == pc)
1923 error (_("Infinite loop detected"));
1924 break;
1925 }
1926 case 0xc:
1927 case 0xd:
1928 case 0xe:
1929 /* Coprocessor register transfer. */
1930 if (bits (this_instr, 12, 15) == 15)
1931 error (_("Invalid update to pc in instruction"));
1932 break;
1933 }
1934 else if (condition_true (bits (this_instr, 28, 31), status))
c906108c
SS
1935 {
1936 switch (bits (this_instr, 24, 27))
1937 {
c5aa993b 1938 case 0x0:
94c30b78 1939 case 0x1: /* data processing */
c5aa993b
JM
1940 case 0x2:
1941 case 0x3:
c906108c
SS
1942 {
1943 unsigned long operand1, operand2, result = 0;
1944 unsigned long rn;
1945 int c;
c5aa993b 1946
c906108c
SS
1947 if (bits (this_instr, 12, 15) != 15)
1948 break;
1949
1950 if (bits (this_instr, 22, 25) == 0
c5aa993b 1951 && bits (this_instr, 4, 7) == 9) /* multiply */
edefbb7c 1952 error (_("Invalid update to pc in instruction"));
c906108c 1953
9498281f 1954 /* BX <reg>, BLX <reg> */
e150acc7
PB
1955 if (bits (this_instr, 4, 27) == 0x12fff1
1956 || bits (this_instr, 4, 27) == 0x12fff3)
9498281f
DJ
1957 {
1958 rn = bits (this_instr, 0, 3);
0b1b3e42
UW
1959 result = (rn == 15) ? pc_val + 8
1960 : get_frame_register_unsigned (frame, rn);
bf6ae464 1961 nextpc = (CORE_ADDR) gdbarch_addr_bits_remove
2af46ca0 1962 (gdbarch, result);
9498281f
DJ
1963
1964 if (nextpc == pc)
edefbb7c 1965 error (_("Infinite loop detected"));
9498281f
DJ
1966
1967 return nextpc;
1968 }
1969
c906108c
SS
1970 /* Multiply into PC */
1971 c = (status & FLAG_C) ? 1 : 0;
1972 rn = bits (this_instr, 16, 19);
0b1b3e42
UW
1973 operand1 = (rn == 15) ? pc_val + 8
1974 : get_frame_register_unsigned (frame, rn);
c5aa993b 1975
c906108c
SS
1976 if (bit (this_instr, 25))
1977 {
1978 unsigned long immval = bits (this_instr, 0, 7);
1979 unsigned long rotate = 2 * bits (this_instr, 8, 11);
c5aa993b
JM
1980 operand2 = ((immval >> rotate) | (immval << (32 - rotate)))
1981 & 0xffffffff;
c906108c 1982 }
c5aa993b 1983 else /* operand 2 is a shifted register */
0b1b3e42 1984 operand2 = shifted_reg_val (frame, this_instr, c, pc_val, status);
c5aa993b 1985
c906108c
SS
1986 switch (bits (this_instr, 21, 24))
1987 {
c5aa993b 1988 case 0x0: /*and */
c906108c
SS
1989 result = operand1 & operand2;
1990 break;
1991
c5aa993b 1992 case 0x1: /*eor */
c906108c
SS
1993 result = operand1 ^ operand2;
1994 break;
1995
c5aa993b 1996 case 0x2: /*sub */
c906108c
SS
1997 result = operand1 - operand2;
1998 break;
1999
c5aa993b 2000 case 0x3: /*rsb */
c906108c
SS
2001 result = operand2 - operand1;
2002 break;
2003
c5aa993b 2004 case 0x4: /*add */
c906108c
SS
2005 result = operand1 + operand2;
2006 break;
2007
c5aa993b 2008 case 0x5: /*adc */
c906108c
SS
2009 result = operand1 + operand2 + c;
2010 break;
2011
c5aa993b 2012 case 0x6: /*sbc */
c906108c
SS
2013 result = operand1 - operand2 + c;
2014 break;
2015
c5aa993b 2016 case 0x7: /*rsc */
c906108c
SS
2017 result = operand2 - operand1 + c;
2018 break;
2019
c5aa993b
JM
2020 case 0x8:
2021 case 0x9:
2022 case 0xa:
2023 case 0xb: /* tst, teq, cmp, cmn */
c906108c
SS
2024 result = (unsigned long) nextpc;
2025 break;
2026
c5aa993b 2027 case 0xc: /*orr */
c906108c
SS
2028 result = operand1 | operand2;
2029 break;
2030
c5aa993b 2031 case 0xd: /*mov */
c906108c
SS
2032 /* Always step into a function. */
2033 result = operand2;
c5aa993b 2034 break;
c906108c 2035
c5aa993b 2036 case 0xe: /*bic */
c906108c
SS
2037 result = operand1 & ~operand2;
2038 break;
2039
c5aa993b 2040 case 0xf: /*mvn */
c906108c
SS
2041 result = ~operand2;
2042 break;
2043 }
bf6ae464 2044 nextpc = (CORE_ADDR) gdbarch_addr_bits_remove
2af46ca0 2045 (gdbarch, result);
c906108c
SS
2046
2047 if (nextpc == pc)
edefbb7c 2048 error (_("Infinite loop detected"));
c906108c
SS
2049 break;
2050 }
c5aa993b
JM
2051
2052 case 0x4:
2053 case 0x5: /* data transfer */
2054 case 0x6:
2055 case 0x7:
c906108c
SS
2056 if (bit (this_instr, 20))
2057 {
2058 /* load */
2059 if (bits (this_instr, 12, 15) == 15)
2060 {
2061 /* rd == pc */
c5aa993b 2062 unsigned long rn;
c906108c 2063 unsigned long base;
c5aa993b 2064
c906108c 2065 if (bit (this_instr, 22))
edefbb7c 2066 error (_("Invalid update to pc in instruction"));
c906108c
SS
2067
2068 /* byte write to PC */
2069 rn = bits (this_instr, 16, 19);
0b1b3e42
UW
2070 base = (rn == 15) ? pc_val + 8
2071 : get_frame_register_unsigned (frame, rn);
c906108c
SS
2072 if (bit (this_instr, 24))
2073 {
2074 /* pre-indexed */
2075 int c = (status & FLAG_C) ? 1 : 0;
2076 unsigned long offset =
c5aa993b 2077 (bit (this_instr, 25)
0b1b3e42 2078 ? shifted_reg_val (frame, this_instr, c, pc_val, status)
c5aa993b 2079 : bits (this_instr, 0, 11));
c906108c
SS
2080
2081 if (bit (this_instr, 23))
2082 base += offset;
2083 else
2084 base -= offset;
2085 }
c5aa993b 2086 nextpc = (CORE_ADDR) read_memory_integer ((CORE_ADDR) base,
c906108c 2087 4);
c5aa993b 2088
2af46ca0 2089 nextpc = gdbarch_addr_bits_remove (gdbarch, nextpc);
c906108c
SS
2090
2091 if (nextpc == pc)
edefbb7c 2092 error (_("Infinite loop detected"));
c906108c
SS
2093 }
2094 }
2095 break;
c5aa993b
JM
2096
2097 case 0x8:
2098 case 0x9: /* block transfer */
c906108c
SS
2099 if (bit (this_instr, 20))
2100 {
2101 /* LDM */
2102 if (bit (this_instr, 15))
2103 {
2104 /* loading pc */
2105 int offset = 0;
2106
2107 if (bit (this_instr, 23))
2108 {
2109 /* up */
2110 unsigned long reglist = bits (this_instr, 0, 14);
2111 offset = bitcount (reglist) * 4;
c5aa993b 2112 if (bit (this_instr, 24)) /* pre */
c906108c
SS
2113 offset += 4;
2114 }
2115 else if (bit (this_instr, 24))
2116 offset = -4;
c5aa993b 2117
c906108c 2118 {
c5aa993b 2119 unsigned long rn_val =
0b1b3e42
UW
2120 get_frame_register_unsigned (frame,
2121 bits (this_instr, 16, 19));
c906108c
SS
2122 nextpc =
2123 (CORE_ADDR) read_memory_integer ((CORE_ADDR) (rn_val
c5aa993b 2124 + offset),
c906108c
SS
2125 4);
2126 }
bf6ae464 2127 nextpc = gdbarch_addr_bits_remove
2af46ca0 2128 (gdbarch, nextpc);
c906108c 2129 if (nextpc == pc)
edefbb7c 2130 error (_("Infinite loop detected"));
c906108c
SS
2131 }
2132 }
2133 break;
c5aa993b
JM
2134
2135 case 0xb: /* branch & link */
2136 case 0xa: /* branch */
c906108c
SS
2137 {
2138 nextpc = BranchDest (pc, this_instr);
2139
2af46ca0 2140 nextpc = gdbarch_addr_bits_remove (gdbarch, nextpc);
c906108c 2141 if (nextpc == pc)
edefbb7c 2142 error (_("Infinite loop detected"));
c906108c
SS
2143 break;
2144 }
c5aa993b
JM
2145
2146 case 0xc:
2147 case 0xd:
2148 case 0xe: /* coproc ops */
2149 case 0xf: /* SWI */
c906108c
SS
2150 break;
2151
2152 default:
edefbb7c 2153 fprintf_filtered (gdb_stderr, _("Bad bit-field extraction\n"));
c906108c
SS
2154 return (pc);
2155 }
2156 }
2157
2158 return nextpc;
2159}
2160
9512d7fd
FN
2161/* single_step() is called just before we want to resume the inferior,
2162 if we want to single-step it but there is no hardware or kernel
2163 single-step support. We find the target of the coming instruction
e0cd558a 2164 and breakpoint it. */
9512d7fd 2165
190dce09 2166int
0b1b3e42 2167arm_software_single_step (struct frame_info *frame)
9512d7fd 2168{
8181d85f
DJ
2169 /* NOTE: This may insert the wrong breakpoint instruction when
2170 single-stepping over a mode-changing instruction, if the
2171 CPSR heuristics are used. */
9512d7fd 2172
0b1b3e42 2173 CORE_ADDR next_pc = arm_get_next_pc (frame, get_frame_pc (frame));
e0cd558a 2174 insert_single_step_breakpoint (next_pc);
e6590a1b
UW
2175
2176 return 1;
9512d7fd 2177}
9512d7fd 2178
c906108c
SS
2179#include "bfd-in2.h"
2180#include "libcoff.h"
2181
2182static int
ed9a39eb 2183gdb_print_insn_arm (bfd_vma memaddr, disassemble_info *info)
c906108c
SS
2184{
2185 if (arm_pc_is_thumb (memaddr))
2186 {
c5aa993b
JM
2187 static asymbol *asym;
2188 static combined_entry_type ce;
2189 static struct coff_symbol_struct csym;
27cddce2 2190 static struct bfd fake_bfd;
c5aa993b 2191 static bfd_target fake_target;
c906108c
SS
2192
2193 if (csym.native == NULL)
2194 {
da3c6d4a
MS
2195 /* Create a fake symbol vector containing a Thumb symbol.
2196 This is solely so that the code in print_insn_little_arm()
2197 and print_insn_big_arm() in opcodes/arm-dis.c will detect
2198 the presence of a Thumb symbol and switch to decoding
2199 Thumb instructions. */
c5aa993b
JM
2200
2201 fake_target.flavour = bfd_target_coff_flavour;
2202 fake_bfd.xvec = &fake_target;
c906108c 2203 ce.u.syment.n_sclass = C_THUMBEXTFUNC;
c5aa993b
JM
2204 csym.native = &ce;
2205 csym.symbol.the_bfd = &fake_bfd;
2206 csym.symbol.name = "fake";
2207 asym = (asymbol *) & csym;
c906108c 2208 }
c5aa993b 2209
c906108c 2210 memaddr = UNMAKE_THUMB_ADDR (memaddr);
c5aa993b 2211 info->symbols = &asym;
c906108c
SS
2212 }
2213 else
2214 info->symbols = NULL;
c5aa993b 2215
40887e1a 2216 if (info->endian == BFD_ENDIAN_BIG)
c906108c
SS
2217 return print_insn_big_arm (memaddr, info);
2218 else
2219 return print_insn_little_arm (memaddr, info);
2220}
2221
66e810cd
RE
2222/* The following define instruction sequences that will cause ARM
2223 cpu's to take an undefined instruction trap. These are used to
2224 signal a breakpoint to GDB.
2225
2226 The newer ARMv4T cpu's are capable of operating in ARM or Thumb
2227 modes. A different instruction is required for each mode. The ARM
2228 cpu's can also be big or little endian. Thus four different
2229 instructions are needed to support all cases.
2230
2231 Note: ARMv4 defines several new instructions that will take the
2232 undefined instruction trap. ARM7TDMI is nominally ARMv4T, but does
2233 not in fact add the new instructions. The new undefined
2234 instructions in ARMv4 are all instructions that had no defined
2235 behaviour in earlier chips. There is no guarantee that they will
2236 raise an exception, but may be treated as NOP's. In practice, it
2237 may only safe to rely on instructions matching:
2238
2239 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
2240 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
2241 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
2242
2243 Even this may only true if the condition predicate is true. The
2244 following use a condition predicate of ALWAYS so it is always TRUE.
2245
2246 There are other ways of forcing a breakpoint. GNU/Linux, RISC iX,
2247 and NetBSD all use a software interrupt rather than an undefined
2248 instruction to force a trap. This can be handled by by the
2249 abi-specific code during establishment of the gdbarch vector. */
2250
66e810cd 2251#define ARM_LE_BREAKPOINT {0xFE,0xDE,0xFF,0xE7}
66e810cd 2252#define ARM_BE_BREAKPOINT {0xE7,0xFF,0xDE,0xFE}
190dce09
UW
2253#define THUMB_LE_BREAKPOINT {0xbe,0xbe}
2254#define THUMB_BE_BREAKPOINT {0xbe,0xbe}
66e810cd
RE
2255
2256static const char arm_default_arm_le_breakpoint[] = ARM_LE_BREAKPOINT;
2257static const char arm_default_arm_be_breakpoint[] = ARM_BE_BREAKPOINT;
2258static const char arm_default_thumb_le_breakpoint[] = THUMB_LE_BREAKPOINT;
2259static const char arm_default_thumb_be_breakpoint[] = THUMB_BE_BREAKPOINT;
2260
34e8f22d
RE
2261/* Determine the type and size of breakpoint to insert at PCPTR. Uses
2262 the program counter value to determine whether a 16-bit or 32-bit
ed9a39eb
JM
2263 breakpoint should be used. It returns a pointer to a string of
2264 bytes that encode a breakpoint instruction, stores the length of
2265 the string to *lenptr, and adjusts the program counter (if
2266 necessary) to point to the actual memory location where the
c906108c
SS
2267 breakpoint should be inserted. */
2268
ab89facf 2269static const unsigned char *
67d57894 2270arm_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
c906108c 2271{
67d57894 2272 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
66e810cd 2273
4bf7064c 2274 if (arm_pc_is_thumb (*pcptr))
c906108c 2275 {
66e810cd
RE
2276 *pcptr = UNMAKE_THUMB_ADDR (*pcptr);
2277 *lenptr = tdep->thumb_breakpoint_size;
2278 return tdep->thumb_breakpoint;
c906108c
SS
2279 }
2280 else
2281 {
66e810cd
RE
2282 *lenptr = tdep->arm_breakpoint_size;
2283 return tdep->arm_breakpoint;
c906108c
SS
2284 }
2285}
ed9a39eb
JM
2286
2287/* Extract from an array REGBUF containing the (raw) register state a
2288 function return value of type TYPE, and copy that, in virtual
2289 format, into VALBUF. */
2290
34e8f22d 2291static void
5238cf52
MK
2292arm_extract_return_value (struct type *type, struct regcache *regs,
2293 gdb_byte *valbuf)
ed9a39eb 2294{
be8626e0
MD
2295 struct gdbarch *gdbarch = get_regcache_arch (regs);
2296
ed9a39eb 2297 if (TYPE_CODE_FLT == TYPE_CODE (type))
08216dd7 2298 {
be8626e0 2299 switch (gdbarch_tdep (gdbarch)->fp_model)
08216dd7
RE
2300 {
2301 case ARM_FLOAT_FPA:
b508a996
RE
2302 {
2303 /* The value is in register F0 in internal format. We need to
2304 extract the raw value and then convert it to the desired
2305 internal type. */
7a5ea0d4 2306 bfd_byte tmpbuf[FP_REGISTER_SIZE];
b508a996
RE
2307
2308 regcache_cooked_read (regs, ARM_F0_REGNUM, tmpbuf);
2309 convert_from_extended (floatformat_from_type (type), tmpbuf,
be8626e0 2310 valbuf, gdbarch_byte_order (gdbarch));
b508a996 2311 }
08216dd7
RE
2312 break;
2313
fd50bc42 2314 case ARM_FLOAT_SOFT_FPA:
08216dd7 2315 case ARM_FLOAT_SOFT_VFP:
b508a996
RE
2316 regcache_cooked_read (regs, ARM_A1_REGNUM, valbuf);
2317 if (TYPE_LENGTH (type) > 4)
2318 regcache_cooked_read (regs, ARM_A1_REGNUM + 1,
7a5ea0d4 2319 valbuf + INT_REGISTER_SIZE);
08216dd7
RE
2320 break;
2321
2322 default:
2323 internal_error
2324 (__FILE__, __LINE__,
edefbb7c 2325 _("arm_extract_return_value: Floating point model not supported"));
08216dd7
RE
2326 break;
2327 }
2328 }
b508a996
RE
2329 else if (TYPE_CODE (type) == TYPE_CODE_INT
2330 || TYPE_CODE (type) == TYPE_CODE_CHAR
2331 || TYPE_CODE (type) == TYPE_CODE_BOOL
2332 || TYPE_CODE (type) == TYPE_CODE_PTR
2333 || TYPE_CODE (type) == TYPE_CODE_REF
2334 || TYPE_CODE (type) == TYPE_CODE_ENUM)
2335 {
2336 /* If the the type is a plain integer, then the access is
2337 straight-forward. Otherwise we have to play around a bit more. */
2338 int len = TYPE_LENGTH (type);
2339 int regno = ARM_A1_REGNUM;
2340 ULONGEST tmp;
2341
2342 while (len > 0)
2343 {
2344 /* By using store_unsigned_integer we avoid having to do
2345 anything special for small big-endian values. */
2346 regcache_cooked_read_unsigned (regs, regno++, &tmp);
2347 store_unsigned_integer (valbuf,
7a5ea0d4
DJ
2348 (len > INT_REGISTER_SIZE
2349 ? INT_REGISTER_SIZE : len),
b508a996 2350 tmp);
7a5ea0d4
DJ
2351 len -= INT_REGISTER_SIZE;
2352 valbuf += INT_REGISTER_SIZE;
b508a996
RE
2353 }
2354 }
ed9a39eb 2355 else
b508a996
RE
2356 {
2357 /* For a structure or union the behaviour is as if the value had
2358 been stored to word-aligned memory and then loaded into
2359 registers with 32-bit load instruction(s). */
2360 int len = TYPE_LENGTH (type);
2361 int regno = ARM_A1_REGNUM;
7a5ea0d4 2362 bfd_byte tmpbuf[INT_REGISTER_SIZE];
b508a996
RE
2363
2364 while (len > 0)
2365 {
2366 regcache_cooked_read (regs, regno++, tmpbuf);
2367 memcpy (valbuf, tmpbuf,
7a5ea0d4
DJ
2368 len > INT_REGISTER_SIZE ? INT_REGISTER_SIZE : len);
2369 len -= INT_REGISTER_SIZE;
2370 valbuf += INT_REGISTER_SIZE;
b508a996
RE
2371 }
2372 }
34e8f22d
RE
2373}
2374
67255d04
RE
2375
2376/* Will a function return an aggregate type in memory or in a
2377 register? Return 0 if an aggregate type can be returned in a
2378 register, 1 if it must be returned in memory. */
2379
2380static int
2af48f68 2381arm_return_in_memory (struct gdbarch *gdbarch, struct type *type)
67255d04
RE
2382{
2383 int nRc;
52f0bd74 2384 enum type_code code;
67255d04 2385
44e1a9eb
DJ
2386 CHECK_TYPEDEF (type);
2387
67255d04
RE
2388 /* In the ARM ABI, "integer" like aggregate types are returned in
2389 registers. For an aggregate type to be integer like, its size
f0c9063c 2390 must be less than or equal to INT_REGISTER_SIZE and the
b1e29e33
AC
2391 offset of each addressable subfield must be zero. Note that bit
2392 fields are not addressable, and all addressable subfields of
2393 unions always start at offset zero.
67255d04
RE
2394
2395 This function is based on the behaviour of GCC 2.95.1.
2396 See: gcc/arm.c: arm_return_in_memory() for details.
2397
2398 Note: All versions of GCC before GCC 2.95.2 do not set up the
2399 parameters correctly for a function returning the following
2400 structure: struct { float f;}; This should be returned in memory,
2401 not a register. Richard Earnshaw sent me a patch, but I do not
2402 know of any way to detect if a function like the above has been
2403 compiled with the correct calling convention. */
2404
2405 /* All aggregate types that won't fit in a register must be returned
2406 in memory. */
f0c9063c 2407 if (TYPE_LENGTH (type) > INT_REGISTER_SIZE)
67255d04
RE
2408 {
2409 return 1;
2410 }
2411
2af48f68
PB
2412 /* The AAPCS says all aggregates not larger than a word are returned
2413 in a register. */
2414 if (gdbarch_tdep (gdbarch)->arm_abi != ARM_ABI_APCS)
2415 return 0;
2416
67255d04
RE
2417 /* The only aggregate types that can be returned in a register are
2418 structs and unions. Arrays must be returned in memory. */
2419 code = TYPE_CODE (type);
2420 if ((TYPE_CODE_STRUCT != code) && (TYPE_CODE_UNION != code))
2421 {
2422 return 1;
2423 }
2424
2425 /* Assume all other aggregate types can be returned in a register.
2426 Run a check for structures, unions and arrays. */
2427 nRc = 0;
2428
2429 if ((TYPE_CODE_STRUCT == code) || (TYPE_CODE_UNION == code))
2430 {
2431 int i;
2432 /* Need to check if this struct/union is "integer" like. For
2433 this to be true, its size must be less than or equal to
f0c9063c 2434 INT_REGISTER_SIZE and the offset of each addressable
b1e29e33
AC
2435 subfield must be zero. Note that bit fields are not
2436 addressable, and unions always start at offset zero. If any
2437 of the subfields is a floating point type, the struct/union
2438 cannot be an integer type. */
67255d04
RE
2439
2440 /* For each field in the object, check:
2441 1) Is it FP? --> yes, nRc = 1;
2442 2) Is it addressable (bitpos != 0) and
2443 not packed (bitsize == 0)?
2444 --> yes, nRc = 1
2445 */
2446
2447 for (i = 0; i < TYPE_NFIELDS (type); i++)
2448 {
2449 enum type_code field_type_code;
44e1a9eb 2450 field_type_code = TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type, i)));
67255d04
RE
2451
2452 /* Is it a floating point type field? */
2453 if (field_type_code == TYPE_CODE_FLT)
2454 {
2455 nRc = 1;
2456 break;
2457 }
2458
2459 /* If bitpos != 0, then we have to care about it. */
2460 if (TYPE_FIELD_BITPOS (type, i) != 0)
2461 {
2462 /* Bitfields are not addressable. If the field bitsize is
2463 zero, then the field is not packed. Hence it cannot be
2464 a bitfield or any other packed type. */
2465 if (TYPE_FIELD_BITSIZE (type, i) == 0)
2466 {
2467 nRc = 1;
2468 break;
2469 }
2470 }
2471 }
2472 }
2473
2474 return nRc;
2475}
2476
34e8f22d
RE
2477/* Write into appropriate registers a function return value of type
2478 TYPE, given in virtual format. */
2479
2480static void
b508a996 2481arm_store_return_value (struct type *type, struct regcache *regs,
5238cf52 2482 const gdb_byte *valbuf)
34e8f22d 2483{
be8626e0
MD
2484 struct gdbarch *gdbarch = get_regcache_arch (regs);
2485
34e8f22d
RE
2486 if (TYPE_CODE (type) == TYPE_CODE_FLT)
2487 {
7a5ea0d4 2488 char buf[MAX_REGISTER_SIZE];
34e8f22d 2489
be8626e0 2490 switch (gdbarch_tdep (gdbarch)->fp_model)
08216dd7
RE
2491 {
2492 case ARM_FLOAT_FPA:
2493
be8626e0
MD
2494 convert_to_extended (floatformat_from_type (type), buf, valbuf,
2495 gdbarch_byte_order (gdbarch));
b508a996 2496 regcache_cooked_write (regs, ARM_F0_REGNUM, buf);
08216dd7
RE
2497 break;
2498
fd50bc42 2499 case ARM_FLOAT_SOFT_FPA:
08216dd7 2500 case ARM_FLOAT_SOFT_VFP:
b508a996
RE
2501 regcache_cooked_write (regs, ARM_A1_REGNUM, valbuf);
2502 if (TYPE_LENGTH (type) > 4)
2503 regcache_cooked_write (regs, ARM_A1_REGNUM + 1,
7a5ea0d4 2504 valbuf + INT_REGISTER_SIZE);
08216dd7
RE
2505 break;
2506
2507 default:
2508 internal_error
2509 (__FILE__, __LINE__,
edefbb7c 2510 _("arm_store_return_value: Floating point model not supported"));
08216dd7
RE
2511 break;
2512 }
34e8f22d 2513 }
b508a996
RE
2514 else if (TYPE_CODE (type) == TYPE_CODE_INT
2515 || TYPE_CODE (type) == TYPE_CODE_CHAR
2516 || TYPE_CODE (type) == TYPE_CODE_BOOL
2517 || TYPE_CODE (type) == TYPE_CODE_PTR
2518 || TYPE_CODE (type) == TYPE_CODE_REF
2519 || TYPE_CODE (type) == TYPE_CODE_ENUM)
2520 {
2521 if (TYPE_LENGTH (type) <= 4)
2522 {
2523 /* Values of one word or less are zero/sign-extended and
2524 returned in r0. */
7a5ea0d4 2525 bfd_byte tmpbuf[INT_REGISTER_SIZE];
b508a996
RE
2526 LONGEST val = unpack_long (type, valbuf);
2527
7a5ea0d4 2528 store_signed_integer (tmpbuf, INT_REGISTER_SIZE, val);
b508a996
RE
2529 regcache_cooked_write (regs, ARM_A1_REGNUM, tmpbuf);
2530 }
2531 else
2532 {
2533 /* Integral values greater than one word are stored in consecutive
2534 registers starting with r0. This will always be a multiple of
2535 the regiser size. */
2536 int len = TYPE_LENGTH (type);
2537 int regno = ARM_A1_REGNUM;
2538
2539 while (len > 0)
2540 {
2541 regcache_cooked_write (regs, regno++, valbuf);
7a5ea0d4
DJ
2542 len -= INT_REGISTER_SIZE;
2543 valbuf += INT_REGISTER_SIZE;
b508a996
RE
2544 }
2545 }
2546 }
34e8f22d 2547 else
b508a996
RE
2548 {
2549 /* For a structure or union the behaviour is as if the value had
2550 been stored to word-aligned memory and then loaded into
2551 registers with 32-bit load instruction(s). */
2552 int len = TYPE_LENGTH (type);
2553 int regno = ARM_A1_REGNUM;
7a5ea0d4 2554 bfd_byte tmpbuf[INT_REGISTER_SIZE];
b508a996
RE
2555
2556 while (len > 0)
2557 {
2558 memcpy (tmpbuf, valbuf,
7a5ea0d4 2559 len > INT_REGISTER_SIZE ? INT_REGISTER_SIZE : len);
b508a996 2560 regcache_cooked_write (regs, regno++, tmpbuf);
7a5ea0d4
DJ
2561 len -= INT_REGISTER_SIZE;
2562 valbuf += INT_REGISTER_SIZE;
b508a996
RE
2563 }
2564 }
34e8f22d
RE
2565}
2566
2af48f68
PB
2567
2568/* Handle function return values. */
2569
2570static enum return_value_convention
c055b101
CV
2571arm_return_value (struct gdbarch *gdbarch, struct type *func_type,
2572 struct type *valtype, struct regcache *regcache,
2573 gdb_byte *readbuf, const gdb_byte *writebuf)
2af48f68 2574{
7c00367c
MK
2575 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2576
2af48f68
PB
2577 if (TYPE_CODE (valtype) == TYPE_CODE_STRUCT
2578 || TYPE_CODE (valtype) == TYPE_CODE_UNION
2579 || TYPE_CODE (valtype) == TYPE_CODE_ARRAY)
2580 {
7c00367c
MK
2581 if (tdep->struct_return == pcc_struct_return
2582 || arm_return_in_memory (gdbarch, valtype))
2af48f68
PB
2583 return RETURN_VALUE_STRUCT_CONVENTION;
2584 }
2585
2586 if (writebuf)
2587 arm_store_return_value (valtype, regcache, writebuf);
2588
2589 if (readbuf)
2590 arm_extract_return_value (valtype, regcache, readbuf);
2591
2592 return RETURN_VALUE_REGISTER_CONVENTION;
2593}
2594
2595
9df628e0 2596static int
60ade65d 2597arm_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
9df628e0
RE
2598{
2599 CORE_ADDR jb_addr;
7a5ea0d4 2600 char buf[INT_REGISTER_SIZE];
60ade65d 2601 struct gdbarch_tdep *tdep = gdbarch_tdep (get_frame_arch (frame));
9df628e0 2602
60ade65d 2603 jb_addr = get_frame_register_unsigned (frame, ARM_A1_REGNUM);
9df628e0
RE
2604
2605 if (target_read_memory (jb_addr + tdep->jb_pc * tdep->jb_elt_size, buf,
7a5ea0d4 2606 INT_REGISTER_SIZE))
9df628e0
RE
2607 return 0;
2608
7a5ea0d4 2609 *pc = extract_unsigned_integer (buf, INT_REGISTER_SIZE);
9df628e0
RE
2610 return 1;
2611}
2612
faa95490
DJ
2613/* Recognize GCC and GNU ld's trampolines. If we are in a trampoline,
2614 return the target PC. Otherwise return 0. */
c906108c
SS
2615
2616CORE_ADDR
52f729a7 2617arm_skip_stub (struct frame_info *frame, CORE_ADDR pc)
c906108c 2618{
c5aa993b 2619 char *name;
faa95490 2620 int namelen;
c906108c
SS
2621 CORE_ADDR start_addr;
2622
2623 /* Find the starting address and name of the function containing the PC. */
2624 if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0)
2625 return 0;
2626
faa95490
DJ
2627 /* If PC is in a Thumb call or return stub, return the address of the
2628 target PC, which is in a register. The thunk functions are called
2629 _call_via_xx, where x is the register name. The possible names
2630 are r0-r9, sl, fp, ip, sp, and lr. */
c906108c
SS
2631 if (strncmp (name, "_call_via_", 10) == 0)
2632 {
ed9a39eb
JM
2633 /* Use the name suffix to determine which register contains the
2634 target PC. */
c5aa993b
JM
2635 static char *table[15] =
2636 {"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2637 "r8", "r9", "sl", "fp", "ip", "sp", "lr"
2638 };
c906108c 2639 int regno;
faa95490 2640 int offset = strlen (name) - 2;
c906108c
SS
2641
2642 for (regno = 0; regno <= 14; regno++)
faa95490 2643 if (strcmp (&name[offset], table[regno]) == 0)
52f729a7 2644 return get_frame_register_unsigned (frame, regno);
c906108c 2645 }
ed9a39eb 2646
faa95490
DJ
2647 /* GNU ld generates __foo_from_arm or __foo_from_thumb for
2648 non-interworking calls to foo. We could decode the stubs
2649 to find the target but it's easier to use the symbol table. */
2650 namelen = strlen (name);
2651 if (name[0] == '_' && name[1] == '_'
2652 && ((namelen > 2 + strlen ("_from_thumb")
2653 && strncmp (name + namelen - strlen ("_from_thumb"), "_from_thumb",
2654 strlen ("_from_thumb")) == 0)
2655 || (namelen > 2 + strlen ("_from_arm")
2656 && strncmp (name + namelen - strlen ("_from_arm"), "_from_arm",
2657 strlen ("_from_arm")) == 0)))
2658 {
2659 char *target_name;
2660 int target_len = namelen - 2;
2661 struct minimal_symbol *minsym;
2662 struct objfile *objfile;
2663 struct obj_section *sec;
2664
2665 if (name[namelen - 1] == 'b')
2666 target_len -= strlen ("_from_thumb");
2667 else
2668 target_len -= strlen ("_from_arm");
2669
2670 target_name = alloca (target_len + 1);
2671 memcpy (target_name, name + 2, target_len);
2672 target_name[target_len] = '\0';
2673
2674 sec = find_pc_section (pc);
2675 objfile = (sec == NULL) ? NULL : sec->objfile;
2676 minsym = lookup_minimal_symbol (target_name, NULL, objfile);
2677 if (minsym != NULL)
2678 return SYMBOL_VALUE_ADDRESS (minsym);
2679 else
2680 return 0;
2681 }
2682
c5aa993b 2683 return 0; /* not a stub */
c906108c
SS
2684}
2685
afd7eef0
RE
2686static void
2687set_arm_command (char *args, int from_tty)
2688{
edefbb7c
AC
2689 printf_unfiltered (_("\
2690\"set arm\" must be followed by an apporpriate subcommand.\n"));
afd7eef0
RE
2691 help_list (setarmcmdlist, "set arm ", all_commands, gdb_stdout);
2692}
2693
2694static void
2695show_arm_command (char *args, int from_tty)
2696{
26304000 2697 cmd_show_list (showarmcmdlist, from_tty, "");
afd7eef0
RE
2698}
2699
28e97307
DJ
2700static void
2701arm_update_current_architecture (void)
fd50bc42 2702{
28e97307 2703 struct gdbarch_info info;
fd50bc42 2704
28e97307 2705 /* If the current architecture is not ARM, we have nothing to do. */
1cf3db46 2706 if (gdbarch_bfd_arch_info (target_gdbarch)->arch != bfd_arch_arm)
28e97307 2707 return;
fd50bc42 2708
28e97307
DJ
2709 /* Update the architecture. */
2710 gdbarch_info_init (&info);
fd50bc42 2711
28e97307
DJ
2712 if (!gdbarch_update_p (info))
2713 internal_error (__FILE__, __LINE__, "could not update architecture");
fd50bc42
RE
2714}
2715
2716static void
2717set_fp_model_sfunc (char *args, int from_tty,
2718 struct cmd_list_element *c)
2719{
2720 enum arm_float_model fp_model;
2721
2722 for (fp_model = ARM_FLOAT_AUTO; fp_model != ARM_FLOAT_LAST; fp_model++)
2723 if (strcmp (current_fp_model, fp_model_strings[fp_model]) == 0)
2724 {
2725 arm_fp_model = fp_model;
2726 break;
2727 }
2728
2729 if (fp_model == ARM_FLOAT_LAST)
edefbb7c 2730 internal_error (__FILE__, __LINE__, _("Invalid fp model accepted: %s."),
fd50bc42
RE
2731 current_fp_model);
2732
28e97307 2733 arm_update_current_architecture ();
fd50bc42
RE
2734}
2735
2736static void
08546159
AC
2737show_fp_model (struct ui_file *file, int from_tty,
2738 struct cmd_list_element *c, const char *value)
fd50bc42 2739{
1cf3db46 2740 struct gdbarch_tdep *tdep = gdbarch_tdep (target_gdbarch);
fd50bc42 2741
28e97307 2742 if (arm_fp_model == ARM_FLOAT_AUTO
1cf3db46 2743 && gdbarch_bfd_arch_info (target_gdbarch)->arch == bfd_arch_arm)
28e97307
DJ
2744 fprintf_filtered (file, _("\
2745The current ARM floating point model is \"auto\" (currently \"%s\").\n"),
2746 fp_model_strings[tdep->fp_model]);
2747 else
2748 fprintf_filtered (file, _("\
2749The current ARM floating point model is \"%s\".\n"),
2750 fp_model_strings[arm_fp_model]);
2751}
2752
2753static void
2754arm_set_abi (char *args, int from_tty,
2755 struct cmd_list_element *c)
2756{
2757 enum arm_abi_kind arm_abi;
2758
2759 for (arm_abi = ARM_ABI_AUTO; arm_abi != ARM_ABI_LAST; arm_abi++)
2760 if (strcmp (arm_abi_string, arm_abi_strings[arm_abi]) == 0)
2761 {
2762 arm_abi_global = arm_abi;
2763 break;
2764 }
2765
2766 if (arm_abi == ARM_ABI_LAST)
2767 internal_error (__FILE__, __LINE__, _("Invalid ABI accepted: %s."),
2768 arm_abi_string);
2769
2770 arm_update_current_architecture ();
2771}
2772
2773static void
2774arm_show_abi (struct ui_file *file, int from_tty,
2775 struct cmd_list_element *c, const char *value)
2776{
1cf3db46 2777 struct gdbarch_tdep *tdep = gdbarch_tdep (target_gdbarch);
28e97307
DJ
2778
2779 if (arm_abi_global == ARM_ABI_AUTO
1cf3db46 2780 && gdbarch_bfd_arch_info (target_gdbarch)->arch == bfd_arch_arm)
28e97307
DJ
2781 fprintf_filtered (file, _("\
2782The current ARM ABI is \"auto\" (currently \"%s\").\n"),
2783 arm_abi_strings[tdep->arm_abi]);
2784 else
2785 fprintf_filtered (file, _("The current ARM ABI is \"%s\".\n"),
2786 arm_abi_string);
fd50bc42
RE
2787}
2788
0428b8f5
DJ
2789static void
2790arm_show_fallback_mode (struct ui_file *file, int from_tty,
2791 struct cmd_list_element *c, const char *value)
2792{
1cf3db46 2793 struct gdbarch_tdep *tdep = gdbarch_tdep (target_gdbarch);
0428b8f5
DJ
2794
2795 fprintf_filtered (file, _("\
2796The current execution mode assumed (when symbols are unavailable) is \"%s\".\n"),
2797 arm_fallback_mode_string);
2798}
2799
2800static void
2801arm_show_force_mode (struct ui_file *file, int from_tty,
2802 struct cmd_list_element *c, const char *value)
2803{
1cf3db46 2804 struct gdbarch_tdep *tdep = gdbarch_tdep (target_gdbarch);
0428b8f5
DJ
2805
2806 fprintf_filtered (file, _("\
2807The current execution mode assumed (even when symbols are available) is \"%s\".\n"),
2808 arm_force_mode_string);
2809}
2810
afd7eef0
RE
2811/* If the user changes the register disassembly style used for info
2812 register and other commands, we have to also switch the style used
2813 in opcodes for disassembly output. This function is run in the "set
2814 arm disassembly" command, and does that. */
bc90b915
FN
2815
2816static void
afd7eef0 2817set_disassembly_style_sfunc (char *args, int from_tty,
bc90b915
FN
2818 struct cmd_list_element *c)
2819{
afd7eef0 2820 set_disassembly_style ();
bc90b915
FN
2821}
2822\f
966fbf70 2823/* Return the ARM register name corresponding to register I. */
a208b0cb 2824static const char *
d93859e2 2825arm_register_name (struct gdbarch *gdbarch, int i)
966fbf70 2826{
ff6f572f
DJ
2827 if (i >= ARRAY_SIZE (arm_register_names))
2828 /* These registers are only supported on targets which supply
2829 an XML description. */
2830 return "";
2831
966fbf70
RE
2832 return arm_register_names[i];
2833}
2834
bc90b915 2835static void
afd7eef0 2836set_disassembly_style (void)
bc90b915 2837{
123dc839 2838 int current;
bc90b915 2839
123dc839
DJ
2840 /* Find the style that the user wants. */
2841 for (current = 0; current < num_disassembly_options; current++)
2842 if (disassembly_style == valid_disassembly_styles[current])
2843 break;
2844 gdb_assert (current < num_disassembly_options);
bc90b915 2845
94c30b78 2846 /* Synchronize the disassembler. */
bc90b915
FN
2847 set_arm_regname_option (current);
2848}
2849
082fc60d
RE
2850/* Test whether the coff symbol specific value corresponds to a Thumb
2851 function. */
2852
2853static int
2854coff_sym_is_thumb (int val)
2855{
2856 return (val == C_THUMBEXT ||
2857 val == C_THUMBSTAT ||
2858 val == C_THUMBEXTFUNC ||
2859 val == C_THUMBSTATFUNC ||
2860 val == C_THUMBLABEL);
2861}
2862
2863/* arm_coff_make_msymbol_special()
2864 arm_elf_make_msymbol_special()
2865
2866 These functions test whether the COFF or ELF symbol corresponds to
2867 an address in thumb code, and set a "special" bit in a minimal
2868 symbol to indicate that it does. */
2869
34e8f22d 2870static void
082fc60d
RE
2871arm_elf_make_msymbol_special(asymbol *sym, struct minimal_symbol *msym)
2872{
2873 /* Thumb symbols are of type STT_LOPROC, (synonymous with
2874 STT_ARM_TFUNC). */
2875 if (ELF_ST_TYPE (((elf_symbol_type *)sym)->internal_elf_sym.st_info)
2876 == STT_LOPROC)
2877 MSYMBOL_SET_SPECIAL (msym);
2878}
2879
34e8f22d 2880static void
082fc60d
RE
2881arm_coff_make_msymbol_special(int val, struct minimal_symbol *msym)
2882{
2883 if (coff_sym_is_thumb (val))
2884 MSYMBOL_SET_SPECIAL (msym);
2885}
2886
60c5725c
DJ
2887static void
2888arm_objfile_data_cleanup (struct objfile *objfile, void *arg)
2889{
2890 struct arm_per_objfile *data = arg;
2891 unsigned int i;
2892
2893 for (i = 0; i < objfile->obfd->section_count; i++)
2894 VEC_free (arm_mapping_symbol_s, data->section_maps[i]);
2895}
2896
2897static void
2898arm_record_special_symbol (struct gdbarch *gdbarch, struct objfile *objfile,
2899 asymbol *sym)
2900{
2901 const char *name = bfd_asymbol_name (sym);
2902 struct arm_per_objfile *data;
2903 VEC(arm_mapping_symbol_s) **map_p;
2904 struct arm_mapping_symbol new_map_sym;
2905
2906 gdb_assert (name[0] == '$');
2907 if (name[1] != 'a' && name[1] != 't' && name[1] != 'd')
2908 return;
2909
2910 data = objfile_data (objfile, arm_objfile_data_key);
2911 if (data == NULL)
2912 {
2913 data = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2914 struct arm_per_objfile);
2915 set_objfile_data (objfile, arm_objfile_data_key, data);
2916 data->section_maps = OBSTACK_CALLOC (&objfile->objfile_obstack,
2917 objfile->obfd->section_count,
2918 VEC(arm_mapping_symbol_s) *);
2919 }
2920 map_p = &data->section_maps[bfd_get_section (sym)->index];
2921
2922 new_map_sym.value = sym->value;
2923 new_map_sym.type = name[1];
2924
2925 /* Assume that most mapping symbols appear in order of increasing
2926 value. If they were randomly distributed, it would be faster to
2927 always push here and then sort at first use. */
2928 if (!VEC_empty (arm_mapping_symbol_s, *map_p))
2929 {
2930 struct arm_mapping_symbol *prev_map_sym;
2931
2932 prev_map_sym = VEC_last (arm_mapping_symbol_s, *map_p);
2933 if (prev_map_sym->value >= sym->value)
2934 {
2935 unsigned int idx;
2936 idx = VEC_lower_bound (arm_mapping_symbol_s, *map_p, &new_map_sym,
2937 arm_compare_mapping_symbols);
2938 VEC_safe_insert (arm_mapping_symbol_s, *map_p, idx, &new_map_sym);
2939 return;
2940 }
2941 }
2942
2943 VEC_safe_push (arm_mapping_symbol_s, *map_p, &new_map_sym);
2944}
2945
756fe439 2946static void
61a1198a 2947arm_write_pc (struct regcache *regcache, CORE_ADDR pc)
756fe439 2948{
61a1198a 2949 regcache_cooked_write_unsigned (regcache, ARM_PC_REGNUM, pc);
756fe439
DJ
2950
2951 /* If necessary, set the T bit. */
2952 if (arm_apcs_32)
2953 {
61a1198a
UW
2954 ULONGEST val;
2955 regcache_cooked_read_unsigned (regcache, ARM_PS_REGNUM, &val);
756fe439 2956 if (arm_pc_is_thumb (pc))
b39cc962 2957 regcache_cooked_write_unsigned (regcache, ARM_PS_REGNUM, val | CPSR_T);
756fe439 2958 else
61a1198a 2959 regcache_cooked_write_unsigned (regcache, ARM_PS_REGNUM,
b39cc962 2960 val & ~(ULONGEST) CPSR_T);
756fe439
DJ
2961 }
2962}
123dc839
DJ
2963
2964static struct value *
2965value_of_arm_user_reg (struct frame_info *frame, const void *baton)
2966{
2967 const int *reg_p = baton;
2968 return value_of_register (*reg_p, frame);
2969}
97e03143 2970\f
70f80edf
JT
2971static enum gdb_osabi
2972arm_elf_osabi_sniffer (bfd *abfd)
97e03143 2973{
2af48f68 2974 unsigned int elfosabi;
70f80edf 2975 enum gdb_osabi osabi = GDB_OSABI_UNKNOWN;
97e03143 2976
70f80edf 2977 elfosabi = elf_elfheader (abfd)->e_ident[EI_OSABI];
97e03143 2978
28e97307
DJ
2979 if (elfosabi == ELFOSABI_ARM)
2980 /* GNU tools use this value. Check note sections in this case,
2981 as well. */
2982 bfd_map_over_sections (abfd,
2983 generic_elf_osabi_sniff_abi_tag_sections,
2984 &osabi);
97e03143 2985
28e97307 2986 /* Anything else will be handled by the generic ELF sniffer. */
70f80edf 2987 return osabi;
97e03143
RE
2988}
2989
70f80edf 2990\f
da3c6d4a
MS
2991/* Initialize the current architecture based on INFO. If possible,
2992 re-use an architecture from ARCHES, which is a list of
2993 architectures already created during this debugging session.
97e03143 2994
da3c6d4a
MS
2995 Called e.g. at program startup, when reading a core file, and when
2996 reading a binary file. */
97e03143 2997
39bbf761
RE
2998static struct gdbarch *
2999arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
3000{
97e03143 3001 struct gdbarch_tdep *tdep;
39bbf761 3002 struct gdbarch *gdbarch;
28e97307
DJ
3003 struct gdbarch_list *best_arch;
3004 enum arm_abi_kind arm_abi = arm_abi_global;
3005 enum arm_float_model fp_model = arm_fp_model;
123dc839
DJ
3006 struct tdesc_arch_data *tdesc_data = NULL;
3007 int i;
ff6f572f 3008 int have_fpa_registers = 1;
123dc839
DJ
3009
3010 /* Check any target description for validity. */
3011 if (tdesc_has_registers (info.target_desc))
3012 {
3013 /* For most registers we require GDB's default names; but also allow
3014 the numeric names for sp / lr / pc, as a convenience. */
3015 static const char *const arm_sp_names[] = { "r13", "sp", NULL };
3016 static const char *const arm_lr_names[] = { "r14", "lr", NULL };
3017 static const char *const arm_pc_names[] = { "r15", "pc", NULL };
3018
3019 const struct tdesc_feature *feature;
3020 int i, valid_p;
3021
3022 feature = tdesc_find_feature (info.target_desc,
3023 "org.gnu.gdb.arm.core");
3024 if (feature == NULL)
3025 return NULL;
3026
3027 tdesc_data = tdesc_data_alloc ();
3028
3029 valid_p = 1;
3030 for (i = 0; i < ARM_SP_REGNUM; i++)
3031 valid_p &= tdesc_numbered_register (feature, tdesc_data, i,
3032 arm_register_names[i]);
3033 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
3034 ARM_SP_REGNUM,
3035 arm_sp_names);
3036 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
3037 ARM_LR_REGNUM,
3038 arm_lr_names);
3039 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
3040 ARM_PC_REGNUM,
3041 arm_pc_names);
3042 valid_p &= tdesc_numbered_register (feature, tdesc_data,
3043 ARM_PS_REGNUM, "cpsr");
3044
3045 if (!valid_p)
3046 {
3047 tdesc_data_cleanup (tdesc_data);
3048 return NULL;
3049 }
3050
3051 feature = tdesc_find_feature (info.target_desc,
3052 "org.gnu.gdb.arm.fpa");
3053 if (feature != NULL)
3054 {
3055 valid_p = 1;
3056 for (i = ARM_F0_REGNUM; i <= ARM_FPS_REGNUM; i++)
3057 valid_p &= tdesc_numbered_register (feature, tdesc_data, i,
3058 arm_register_names[i]);
3059 if (!valid_p)
3060 {
3061 tdesc_data_cleanup (tdesc_data);
3062 return NULL;
3063 }
3064 }
ff6f572f
DJ
3065 else
3066 have_fpa_registers = 0;
3067
3068 feature = tdesc_find_feature (info.target_desc,
3069 "org.gnu.gdb.xscale.iwmmxt");
3070 if (feature != NULL)
3071 {
3072 static const char *const iwmmxt_names[] = {
3073 "wR0", "wR1", "wR2", "wR3", "wR4", "wR5", "wR6", "wR7",
3074 "wR8", "wR9", "wR10", "wR11", "wR12", "wR13", "wR14", "wR15",
3075 "wCID", "wCon", "wCSSF", "wCASF", "", "", "", "",
3076 "wCGR0", "wCGR1", "wCGR2", "wCGR3", "", "", "", "",
3077 };
3078
3079 valid_p = 1;
3080 for (i = ARM_WR0_REGNUM; i <= ARM_WR15_REGNUM; i++)
3081 valid_p
3082 &= tdesc_numbered_register (feature, tdesc_data, i,
3083 iwmmxt_names[i - ARM_WR0_REGNUM]);
3084
3085 /* Check for the control registers, but do not fail if they
3086 are missing. */
3087 for (i = ARM_WC0_REGNUM; i <= ARM_WCASF_REGNUM; i++)
3088 tdesc_numbered_register (feature, tdesc_data, i,
3089 iwmmxt_names[i - ARM_WR0_REGNUM]);
3090
3091 for (i = ARM_WCGR0_REGNUM; i <= ARM_WCGR3_REGNUM; i++)
3092 valid_p
3093 &= tdesc_numbered_register (feature, tdesc_data, i,
3094 iwmmxt_names[i - ARM_WR0_REGNUM]);
3095
3096 if (!valid_p)
3097 {
3098 tdesc_data_cleanup (tdesc_data);
3099 return NULL;
3100 }
3101 }
123dc839 3102 }
39bbf761 3103
28e97307
DJ
3104 /* If we have an object to base this architecture on, try to determine
3105 its ABI. */
39bbf761 3106
28e97307 3107 if (arm_abi == ARM_ABI_AUTO && info.abfd != NULL)
97e03143 3108 {
6b26d61a 3109 int ei_osabi, e_flags;
28e97307 3110
4be87837 3111 switch (bfd_get_flavour (info.abfd))
97e03143 3112 {
4be87837
DJ
3113 case bfd_target_aout_flavour:
3114 /* Assume it's an old APCS-style ABI. */
28e97307 3115 arm_abi = ARM_ABI_APCS;
4be87837 3116 break;
97e03143 3117
4be87837
DJ
3118 case bfd_target_coff_flavour:
3119 /* Assume it's an old APCS-style ABI. */
3120 /* XXX WinCE? */
28e97307
DJ
3121 arm_abi = ARM_ABI_APCS;
3122 break;
3123
3124 case bfd_target_elf_flavour:
3125 ei_osabi = elf_elfheader (info.abfd)->e_ident[EI_OSABI];
6b26d61a
MK
3126 e_flags = elf_elfheader (info.abfd)->e_flags;
3127
28e97307
DJ
3128 if (ei_osabi == ELFOSABI_ARM)
3129 {
3130 /* GNU tools used to use this value, but do not for EABI
6b26d61a
MK
3131 objects. There's nowhere to tag an EABI version
3132 anyway, so assume APCS. */
28e97307
DJ
3133 arm_abi = ARM_ABI_APCS;
3134 }
3135 else if (ei_osabi == ELFOSABI_NONE)
3136 {
6b26d61a 3137 int eabi_ver = EF_ARM_EABI_VERSION (e_flags);
28e97307
DJ
3138
3139 switch (eabi_ver)
3140 {
3141 case EF_ARM_EABI_UNKNOWN:
3142 /* Assume GNU tools. */
3143 arm_abi = ARM_ABI_APCS;
3144 break;
3145
3146 case EF_ARM_EABI_VER4:
625b5003 3147 case EF_ARM_EABI_VER5:
28e97307 3148 arm_abi = ARM_ABI_AAPCS;
2af48f68
PB
3149 /* EABI binaries default to VFP float ordering. */
3150 if (fp_model == ARM_FLOAT_AUTO)
3151 fp_model = ARM_FLOAT_SOFT_VFP;
28e97307
DJ
3152 break;
3153
3154 default:
6b26d61a 3155 /* Leave it as "auto". */
28e97307 3156 warning (_("unknown ARM EABI version 0x%x"), eabi_ver);
6b26d61a
MK
3157 break;
3158 }
3159 }
3160
3161 if (fp_model == ARM_FLOAT_AUTO)
3162 {
3163 int e_flags = elf_elfheader (info.abfd)->e_flags;
3164
3165 switch (e_flags & (EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT))
3166 {
3167 case 0:
3168 /* Leave it as "auto". Strictly speaking this case
3169 means FPA, but almost nobody uses that now, and
3170 many toolchains fail to set the appropriate bits
3171 for the floating-point model they use. */
3172 break;
3173 case EF_ARM_SOFT_FLOAT:
3174 fp_model = ARM_FLOAT_SOFT_FPA;
3175 break;
3176 case EF_ARM_VFP_FLOAT:
3177 fp_model = ARM_FLOAT_VFP;
3178 break;
3179 case EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT:
3180 fp_model = ARM_FLOAT_SOFT_VFP;
28e97307
DJ
3181 break;
3182 }
3183 }
9d4fde75
SS
3184
3185 if (e_flags & EF_ARM_BE8)
3186 info.byte_order_for_code = BFD_ENDIAN_LITTLE;
3187
4be87837 3188 break;
97e03143 3189
4be87837 3190 default:
28e97307 3191 /* Leave it as "auto". */
50ceaba5 3192 break;
97e03143
RE
3193 }
3194 }
3195
28e97307
DJ
3196 /* If there is already a candidate, use it. */
3197 for (best_arch = gdbarch_list_lookup_by_info (arches, &info);
3198 best_arch != NULL;
3199 best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
3200 {
b8926edc
DJ
3201 if (arm_abi != ARM_ABI_AUTO
3202 && arm_abi != gdbarch_tdep (best_arch->gdbarch)->arm_abi)
28e97307
DJ
3203 continue;
3204
b8926edc
DJ
3205 if (fp_model != ARM_FLOAT_AUTO
3206 && fp_model != gdbarch_tdep (best_arch->gdbarch)->fp_model)
28e97307
DJ
3207 continue;
3208
3209 /* Found a match. */
3210 break;
3211 }
97e03143 3212
28e97307 3213 if (best_arch != NULL)
123dc839
DJ
3214 {
3215 if (tdesc_data != NULL)
3216 tdesc_data_cleanup (tdesc_data);
3217 return best_arch->gdbarch;
3218 }
28e97307
DJ
3219
3220 tdep = xcalloc (1, sizeof (struct gdbarch_tdep));
97e03143
RE
3221 gdbarch = gdbarch_alloc (&info, tdep);
3222
28e97307
DJ
3223 /* Record additional information about the architecture we are defining.
3224 These are gdbarch discriminators, like the OSABI. */
3225 tdep->arm_abi = arm_abi;
3226 tdep->fp_model = fp_model;
ff6f572f 3227 tdep->have_fpa_registers = have_fpa_registers;
08216dd7
RE
3228
3229 /* Breakpoints. */
9d4fde75 3230 switch (info.byte_order_for_code)
67255d04
RE
3231 {
3232 case BFD_ENDIAN_BIG:
66e810cd
RE
3233 tdep->arm_breakpoint = arm_default_arm_be_breakpoint;
3234 tdep->arm_breakpoint_size = sizeof (arm_default_arm_be_breakpoint);
3235 tdep->thumb_breakpoint = arm_default_thumb_be_breakpoint;
3236 tdep->thumb_breakpoint_size = sizeof (arm_default_thumb_be_breakpoint);
3237
67255d04
RE
3238 break;
3239
3240 case BFD_ENDIAN_LITTLE:
66e810cd
RE
3241 tdep->arm_breakpoint = arm_default_arm_le_breakpoint;
3242 tdep->arm_breakpoint_size = sizeof (arm_default_arm_le_breakpoint);
3243 tdep->thumb_breakpoint = arm_default_thumb_le_breakpoint;
3244 tdep->thumb_breakpoint_size = sizeof (arm_default_thumb_le_breakpoint);
3245
67255d04
RE
3246 break;
3247
3248 default:
3249 internal_error (__FILE__, __LINE__,
edefbb7c 3250 _("arm_gdbarch_init: bad byte order for float format"));
67255d04
RE
3251 }
3252
d7b486e7
RE
3253 /* On ARM targets char defaults to unsigned. */
3254 set_gdbarch_char_signed (gdbarch, 0);
3255
9df628e0 3256 /* This should be low enough for everything. */
97e03143 3257 tdep->lowest_pc = 0x20;
94c30b78 3258 tdep->jb_pc = -1; /* Longjump support not enabled by default. */
97e03143 3259
7c00367c
MK
3260 /* The default, for both APCS and AAPCS, is to return small
3261 structures in registers. */
3262 tdep->struct_return = reg_struct_return;
3263
2dd604e7 3264 set_gdbarch_push_dummy_call (gdbarch, arm_push_dummy_call);
f53f0d0b 3265 set_gdbarch_frame_align (gdbarch, arm_frame_align);
39bbf761 3266
756fe439
DJ
3267 set_gdbarch_write_pc (gdbarch, arm_write_pc);
3268
148754e5 3269 /* Frame handling. */
a262aec2 3270 set_gdbarch_dummy_id (gdbarch, arm_dummy_id);
eb5492fa
DJ
3271 set_gdbarch_unwind_pc (gdbarch, arm_unwind_pc);
3272 set_gdbarch_unwind_sp (gdbarch, arm_unwind_sp);
3273
eb5492fa 3274 frame_base_set_default (gdbarch, &arm_normal_base);
148754e5 3275
34e8f22d
RE
3276 /* Address manipulation. */
3277 set_gdbarch_smash_text_address (gdbarch, arm_smash_text_address);
3278 set_gdbarch_addr_bits_remove (gdbarch, arm_addr_bits_remove);
3279
34e8f22d
RE
3280 /* Advance PC across function entry code. */
3281 set_gdbarch_skip_prologue (gdbarch, arm_skip_prologue);
3282
190dce09
UW
3283 /* Skip trampolines. */
3284 set_gdbarch_skip_trampoline_code (gdbarch, arm_skip_stub);
3285
34e8f22d
RE
3286 /* The stack grows downward. */
3287 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
3288
3289 /* Breakpoint manipulation. */
3290 set_gdbarch_breakpoint_from_pc (gdbarch, arm_breakpoint_from_pc);
34e8f22d
RE
3291
3292 /* Information about registers, etc. */
0ba6dca9 3293 set_gdbarch_deprecated_fp_regnum (gdbarch, ARM_FP_REGNUM); /* ??? */
34e8f22d
RE
3294 set_gdbarch_sp_regnum (gdbarch, ARM_SP_REGNUM);
3295 set_gdbarch_pc_regnum (gdbarch, ARM_PC_REGNUM);
ff6f572f 3296 set_gdbarch_num_regs (gdbarch, ARM_NUM_REGS);
7a5ea0d4 3297 set_gdbarch_register_type (gdbarch, arm_register_type);
34e8f22d 3298
ff6f572f
DJ
3299 /* This "info float" is FPA-specific. Use the generic version if we
3300 do not have FPA. */
3301 if (gdbarch_tdep (gdbarch)->have_fpa_registers)
3302 set_gdbarch_print_float_info (gdbarch, arm_print_float_info);
3303
26216b98 3304 /* Internal <-> external register number maps. */
ff6f572f 3305 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, arm_dwarf_reg_to_regnum);
26216b98
AC
3306 set_gdbarch_register_sim_regno (gdbarch, arm_register_sim_regno);
3307
34e8f22d
RE
3308 set_gdbarch_register_name (gdbarch, arm_register_name);
3309
3310 /* Returning results. */
2af48f68 3311 set_gdbarch_return_value (gdbarch, arm_return_value);
34e8f22d 3312
03d48a7d
RE
3313 /* Disassembly. */
3314 set_gdbarch_print_insn (gdbarch, gdb_print_insn_arm);
3315
34e8f22d
RE
3316 /* Minsymbol frobbing. */
3317 set_gdbarch_elf_make_msymbol_special (gdbarch, arm_elf_make_msymbol_special);
3318 set_gdbarch_coff_make_msymbol_special (gdbarch,
3319 arm_coff_make_msymbol_special);
60c5725c 3320 set_gdbarch_record_special_symbol (gdbarch, arm_record_special_symbol);
34e8f22d 3321
0d5de010
DJ
3322 /* Virtual tables. */
3323 set_gdbarch_vbit_in_delta (gdbarch, 1);
3324
97e03143 3325 /* Hook in the ABI-specific overrides, if they have been registered. */
4be87837 3326 gdbarch_init_osabi (info, gdbarch);
97e03143 3327
b39cc962
DJ
3328 dwarf2_frame_set_init_reg (gdbarch, arm_dwarf2_frame_init_reg);
3329
eb5492fa 3330 /* Add some default predicates. */
a262aec2
DJ
3331 frame_unwind_append_unwinder (gdbarch, &arm_stub_unwind);
3332 dwarf2_append_unwinders (gdbarch);
3333 frame_unwind_append_unwinder (gdbarch, &arm_prologue_unwind);
eb5492fa 3334
97e03143
RE
3335 /* Now we have tuned the configuration, set a few final things,
3336 based on what the OS ABI has told us. */
3337
b8926edc
DJ
3338 /* If the ABI is not otherwise marked, assume the old GNU APCS. EABI
3339 binaries are always marked. */
3340 if (tdep->arm_abi == ARM_ABI_AUTO)
3341 tdep->arm_abi = ARM_ABI_APCS;
3342
3343 /* We used to default to FPA for generic ARM, but almost nobody
3344 uses that now, and we now provide a way for the user to force
3345 the model. So default to the most useful variant. */
3346 if (tdep->fp_model == ARM_FLOAT_AUTO)
3347 tdep->fp_model = ARM_FLOAT_SOFT_FPA;
3348
9df628e0
RE
3349 if (tdep->jb_pc >= 0)
3350 set_gdbarch_get_longjmp_target (gdbarch, arm_get_longjmp_target);
3351
08216dd7 3352 /* Floating point sizes and format. */
8da61cc4 3353 set_gdbarch_float_format (gdbarch, floatformats_ieee_single);
b8926edc 3354 if (tdep->fp_model == ARM_FLOAT_SOFT_FPA || tdep->fp_model == ARM_FLOAT_FPA)
08216dd7 3355 {
8da61cc4
DJ
3356 set_gdbarch_double_format
3357 (gdbarch, floatformats_ieee_double_littlebyte_bigword);
3358 set_gdbarch_long_double_format
3359 (gdbarch, floatformats_ieee_double_littlebyte_bigword);
3360 }
3361 else
3362 {
3363 set_gdbarch_double_format (gdbarch, floatformats_ieee_double);
3364 set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double);
08216dd7
RE
3365 }
3366
123dc839 3367 if (tdesc_data)
7cc46491 3368 tdesc_use_registers (gdbarch, info.target_desc, tdesc_data);
123dc839
DJ
3369
3370 /* Add standard register aliases. We add aliases even for those
3371 nanes which are used by the current architecture - it's simpler,
3372 and does no harm, since nothing ever lists user registers. */
3373 for (i = 0; i < ARRAY_SIZE (arm_register_aliases); i++)
3374 user_reg_add (gdbarch, arm_register_aliases[i].name,
3375 value_of_arm_user_reg, &arm_register_aliases[i].regnum);
3376
39bbf761
RE
3377 return gdbarch;
3378}
3379
97e03143 3380static void
2af46ca0 3381arm_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
97e03143 3382{
2af46ca0 3383 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
97e03143
RE
3384
3385 if (tdep == NULL)
3386 return;
3387
edefbb7c 3388 fprintf_unfiltered (file, _("arm_dump_tdep: Lowest pc = 0x%lx"),
97e03143
RE
3389 (unsigned long) tdep->lowest_pc);
3390}
3391
a78f21af
AC
3392extern initialize_file_ftype _initialize_arm_tdep; /* -Wmissing-prototypes */
3393
c906108c 3394void
ed9a39eb 3395_initialize_arm_tdep (void)
c906108c 3396{
bc90b915
FN
3397 struct ui_file *stb;
3398 long length;
26304000 3399 struct cmd_list_element *new_set, *new_show;
53904c9e
AC
3400 const char *setname;
3401 const char *setdesc;
4bd7b427 3402 const char *const *regnames;
bc90b915
FN
3403 int numregs, i, j;
3404 static char *helptext;
edefbb7c
AC
3405 char regdesc[1024], *rdptr = regdesc;
3406 size_t rest = sizeof (regdesc);
085dd6e6 3407
42cf1509 3408 gdbarch_register (bfd_arch_arm, arm_gdbarch_init, arm_dump_tdep);
97e03143 3409
60c5725c
DJ
3410 arm_objfile_data_key
3411 = register_objfile_data_with_cleanup (arm_objfile_data_cleanup);
3412
70f80edf
JT
3413 /* Register an ELF OS ABI sniffer for ARM binaries. */
3414 gdbarch_register_osabi_sniffer (bfd_arch_arm,
3415 bfd_target_elf_flavour,
3416 arm_elf_osabi_sniffer);
3417
94c30b78 3418 /* Get the number of possible sets of register names defined in opcodes. */
afd7eef0
RE
3419 num_disassembly_options = get_arm_regname_num_options ();
3420
3421 /* Add root prefix command for all "set arm"/"show arm" commands. */
3422 add_prefix_cmd ("arm", no_class, set_arm_command,
edefbb7c 3423 _("Various ARM-specific commands."),
afd7eef0
RE
3424 &setarmcmdlist, "set arm ", 0, &setlist);
3425
3426 add_prefix_cmd ("arm", no_class, show_arm_command,
edefbb7c 3427 _("Various ARM-specific commands."),
afd7eef0 3428 &showarmcmdlist, "show arm ", 0, &showlist);
bc90b915 3429
94c30b78 3430 /* Sync the opcode insn printer with our register viewer. */
bc90b915 3431 parse_arm_disassembler_option ("reg-names-std");
c5aa993b 3432
eefe576e
AC
3433 /* Initialize the array that will be passed to
3434 add_setshow_enum_cmd(). */
afd7eef0
RE
3435 valid_disassembly_styles
3436 = xmalloc ((num_disassembly_options + 1) * sizeof (char *));
3437 for (i = 0; i < num_disassembly_options; i++)
bc90b915
FN
3438 {
3439 numregs = get_arm_regnames (i, &setname, &setdesc, &regnames);
afd7eef0 3440 valid_disassembly_styles[i] = setname;
edefbb7c
AC
3441 length = snprintf (rdptr, rest, "%s - %s\n", setname, setdesc);
3442 rdptr += length;
3443 rest -= length;
123dc839
DJ
3444 /* When we find the default names, tell the disassembler to use
3445 them. */
bc90b915
FN
3446 if (!strcmp (setname, "std"))
3447 {
afd7eef0 3448 disassembly_style = setname;
bc90b915
FN
3449 set_arm_regname_option (i);
3450 }
3451 }
94c30b78 3452 /* Mark the end of valid options. */
afd7eef0 3453 valid_disassembly_styles[num_disassembly_options] = NULL;
c906108c 3454
edefbb7c
AC
3455 /* Create the help text. */
3456 stb = mem_fileopen ();
3457 fprintf_unfiltered (stb, "%s%s%s",
3458 _("The valid values are:\n"),
3459 regdesc,
3460 _("The default is \"std\"."));
bc90b915
FN
3461 helptext = ui_file_xstrdup (stb, &length);
3462 ui_file_delete (stb);
ed9a39eb 3463
edefbb7c
AC
3464 add_setshow_enum_cmd("disassembler", no_class,
3465 valid_disassembly_styles, &disassembly_style,
3466 _("Set the disassembly style."),
3467 _("Show the disassembly style."),
3468 helptext,
2c5b56ce 3469 set_disassembly_style_sfunc,
7915a72c 3470 NULL, /* FIXME: i18n: The disassembly style is \"%s\". */
7376b4c2 3471 &setarmcmdlist, &showarmcmdlist);
edefbb7c
AC
3472
3473 add_setshow_boolean_cmd ("apcs32", no_class, &arm_apcs_32,
3474 _("Set usage of ARM 32-bit mode."),
3475 _("Show usage of ARM 32-bit mode."),
3476 _("When off, a 26-bit PC will be used."),
2c5b56ce 3477 NULL,
7915a72c 3478 NULL, /* FIXME: i18n: Usage of ARM 32-bit mode is %s. */
26304000 3479 &setarmcmdlist, &showarmcmdlist);
c906108c 3480
fd50bc42 3481 /* Add a command to allow the user to force the FPU model. */
edefbb7c
AC
3482 add_setshow_enum_cmd ("fpu", no_class, fp_model_strings, &current_fp_model,
3483 _("Set the floating point type."),
3484 _("Show the floating point type."),
3485 _("auto - Determine the FP typefrom the OS-ABI.\n\
3486softfpa - Software FP, mixed-endian doubles on little-endian ARMs.\n\
3487fpa - FPA co-processor (GCC compiled).\n\
3488softvfp - Software FP with pure-endian doubles.\n\
3489vfp - VFP co-processor."),
edefbb7c 3490 set_fp_model_sfunc, show_fp_model,
7376b4c2 3491 &setarmcmdlist, &showarmcmdlist);
fd50bc42 3492
28e97307
DJ
3493 /* Add a command to allow the user to force the ABI. */
3494 add_setshow_enum_cmd ("abi", class_support, arm_abi_strings, &arm_abi_string,
3495 _("Set the ABI."),
3496 _("Show the ABI."),
3497 NULL, arm_set_abi, arm_show_abi,
3498 &setarmcmdlist, &showarmcmdlist);
3499
0428b8f5
DJ
3500 /* Add two commands to allow the user to force the assumed
3501 execution mode. */
3502 add_setshow_enum_cmd ("fallback-mode", class_support,
3503 arm_mode_strings, &arm_fallback_mode_string,
3504 _("Set the mode assumed when symbols are unavailable."),
3505 _("Show the mode assumed when symbols are unavailable."),
3506 NULL, NULL, arm_show_fallback_mode,
3507 &setarmcmdlist, &showarmcmdlist);
3508 add_setshow_enum_cmd ("force-mode", class_support,
3509 arm_mode_strings, &arm_force_mode_string,
3510 _("Set the mode assumed even when symbols are available."),
3511 _("Show the mode assumed even when symbols are available."),
3512 NULL, NULL, arm_show_force_mode,
3513 &setarmcmdlist, &showarmcmdlist);
3514
6529d2dd 3515 /* Debugging flag. */
edefbb7c
AC
3516 add_setshow_boolean_cmd ("arm", class_maintenance, &arm_debug,
3517 _("Set ARM debugging."),
3518 _("Show ARM debugging."),
3519 _("When on, arm-specific debugging is enabled."),
2c5b56ce 3520 NULL,
7915a72c 3521 NULL, /* FIXME: i18n: "ARM debugging is %s. */
26304000 3522 &setdebuglist, &showdebuglist);
c906108c 3523}
This page took 0.823584 seconds and 4 git commands to generate.