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