411d7d6a185f7a6670e9e13f73192b002fbe614f
[deliverable/binutils-gdb.git] / gdb / arm-tdep.c
1 /* Common target dependent code for GDB on ARM systems.
2 Copyright 1988, 1989, 1991, 1992, 1993, 1995, 1996, 1998, 1999, 2000,
3 2001, 2002, 2003 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 #include <ctype.h> /* XXX for isupper () */
23
24 #include "defs.h"
25 #include "frame.h"
26 #include "inferior.h"
27 #include "gdbcmd.h"
28 #include "gdbcore.h"
29 #include "symfile.h"
30 #include "gdb_string.h"
31 #include "dis-asm.h" /* For register styles. */
32 #include "regcache.h"
33 #include "doublest.h"
34 #include "value.h"
35 #include "arch-utils.h"
36 #include "osabi.h"
37
38 #include "arm-tdep.h"
39 #include "gdb/sim-arm.h"
40
41 #include "elf-bfd.h"
42 #include "coff/internal.h"
43 #include "elf/arm.h"
44
45 #include "gdb_assert.h"
46
47 static int arm_debug;
48
49 /* Each OS has a different mechanism for accessing the various
50 registers stored in the sigcontext structure.
51
52 SIGCONTEXT_REGISTER_ADDRESS should be defined to the name (or
53 function pointer) which may be used to determine the addresses
54 of the various saved registers in the sigcontext structure.
55
56 For the ARM target, there are three parameters to this function.
57 The first is the pc value of the frame under consideration, the
58 second the stack pointer of this frame, and the last is the
59 register number to fetch.
60
61 If the tm.h file does not define this macro, then it's assumed that
62 no mechanism is needed and we define SIGCONTEXT_REGISTER_ADDRESS to
63 be 0.
64
65 When it comes time to multi-arching this code, see the identically
66 named machinery in ia64-tdep.c for an example of how it could be
67 done. It should not be necessary to modify the code below where
68 this macro is used. */
69
70 #ifdef SIGCONTEXT_REGISTER_ADDRESS
71 #ifndef SIGCONTEXT_REGISTER_ADDRESS_P
72 #define SIGCONTEXT_REGISTER_ADDRESS_P() 1
73 #endif
74 #else
75 #define SIGCONTEXT_REGISTER_ADDRESS(SP,PC,REG) 0
76 #define SIGCONTEXT_REGISTER_ADDRESS_P() 0
77 #endif
78
79 /* Macros for setting and testing a bit in a minimal symbol that marks
80 it as Thumb function. The MSB of the minimal symbol's "info" field
81 is used for this purpose. This field is already being used to store
82 the symbol size, so the assumption is that the symbol size cannot
83 exceed 2^31.
84
85 MSYMBOL_SET_SPECIAL Actually sets the "special" bit.
86 MSYMBOL_IS_SPECIAL Tests the "special" bit in a minimal symbol.
87 MSYMBOL_SIZE Returns the size of the minimal symbol,
88 i.e. the "info" field with the "special" bit
89 masked out. */
90
91 #define MSYMBOL_SET_SPECIAL(msym) \
92 MSYMBOL_INFO (msym) = (char *) (((long) MSYMBOL_INFO (msym)) \
93 | 0x80000000)
94
95 #define MSYMBOL_IS_SPECIAL(msym) \
96 (((long) MSYMBOL_INFO (msym) & 0x80000000) != 0)
97
98 #define MSYMBOL_SIZE(msym) \
99 ((long) MSYMBOL_INFO (msym) & 0x7fffffff)
100
101 /* The list of available "set arm ..." and "show arm ..." commands. */
102 static struct cmd_list_element *setarmcmdlist = NULL;
103 static struct cmd_list_element *showarmcmdlist = NULL;
104
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. */
107 static const char *fp_model_strings[] =
108 {
109 "auto",
110 "softfpa",
111 "fpa",
112 "softvfp",
113 "vfp"
114 };
115
116 /* A variable that can be configured by the user. */
117 static enum arm_float_model arm_fp_model = ARM_FLOAT_AUTO;
118 static const char *current_fp_model = "auto";
119
120 /* Number of different reg name sets (options). */
121 static int num_disassembly_options;
122
123 /* We have more registers than the disassembler as gdb can print the value
124 of special registers as well.
125 The general register names are overwritten by whatever is being used by
126 the disassembler at the moment. We also adjust the case of cpsr and fps. */
127
128 /* Initial value: Register names used in ARM's ISA documentation. */
129 static char * arm_register_name_strings[] =
130 {"r0", "r1", "r2", "r3", /* 0 1 2 3 */
131 "r4", "r5", "r6", "r7", /* 4 5 6 7 */
132 "r8", "r9", "r10", "r11", /* 8 9 10 11 */
133 "r12", "sp", "lr", "pc", /* 12 13 14 15 */
134 "f0", "f1", "f2", "f3", /* 16 17 18 19 */
135 "f4", "f5", "f6", "f7", /* 20 21 22 23 */
136 "fps", "cpsr" }; /* 24 25 */
137 static char **arm_register_names = arm_register_name_strings;
138
139 /* Valid register name styles. */
140 static const char **valid_disassembly_styles;
141
142 /* Disassembly style to use. Default to "std" register names. */
143 static const char *disassembly_style;
144 /* Index to that option in the opcodes table. */
145 static int current_option;
146
147 /* This is used to keep the bfd arch_info in sync with the disassembly
148 style. */
149 static void set_disassembly_style_sfunc(char *, int,
150 struct cmd_list_element *);
151 static void set_disassembly_style (void);
152
153 static void convert_from_extended (const struct floatformat *, const void *,
154 void *);
155 static void convert_to_extended (const struct floatformat *, void *,
156 const void *);
157
158 /* Define other aspects of the stack frame. We keep the offsets of
159 all saved registers, 'cause we need 'em a lot! We also keep the
160 current size of the stack frame, and the offset of the frame
161 pointer from the stack pointer (for frameless functions, and when
162 we're still in the prologue of a function with a frame). */
163
164 #define arm_get_cache(fi) ((struct arm_prologue_cache *) get_frame_extra_info (fi))
165
166 struct arm_prologue_cache
167 {
168 CORE_ADDR unwound_sp, unwound_pc;
169 int framesize;
170 int frameoffset;
171 int framereg;
172 CORE_ADDR saved_regs[1];
173 };
174
175 /* Addresses for calling Thumb functions have the bit 0 set.
176 Here are some macros to test, set, or clear bit 0 of addresses. */
177 #define IS_THUMB_ADDR(addr) ((addr) & 1)
178 #define MAKE_THUMB_ADDR(addr) ((addr) | 1)
179 #define UNMAKE_THUMB_ADDR(addr) ((addr) & ~1)
180
181 static int
182 arm_frame_chain_valid (CORE_ADDR chain, struct frame_info *thisframe)
183 {
184 return (DEPRECATED_FRAME_SAVED_PC (thisframe) >= LOWEST_PC);
185 }
186
187 /* Set to true if the 32-bit mode is in use. */
188
189 int arm_apcs_32 = 1;
190
191 /* Flag set by arm_fix_call_dummy that tells whether the target
192 function is a Thumb function. This flag is checked by
193 arm_push_arguments. FIXME: Change the PUSH_ARGUMENTS macro (and
194 its use in valops.c) to pass the function address as an additional
195 parameter. */
196
197 static int target_is_thumb;
198
199 /* Flag set by arm_fix_call_dummy that tells whether the calling
200 function is a Thumb function. This flag is checked by
201 arm_pc_is_thumb and arm_call_dummy_breakpoint_offset. */
202
203 static int caller_is_thumb;
204
205 /* Determine if the program counter specified in MEMADDR is in a Thumb
206 function. */
207
208 int
209 arm_pc_is_thumb (CORE_ADDR memaddr)
210 {
211 struct minimal_symbol *sym;
212
213 /* If bit 0 of the address is set, assume this is a Thumb address. */
214 if (IS_THUMB_ADDR (memaddr))
215 return 1;
216
217 /* Thumb functions have a "special" bit set in minimal symbols. */
218 sym = lookup_minimal_symbol_by_pc (memaddr);
219 if (sym)
220 {
221 return (MSYMBOL_IS_SPECIAL (sym));
222 }
223 else
224 {
225 return 0;
226 }
227 }
228
229 /* Determine if the program counter specified in MEMADDR is in a call
230 dummy being called from a Thumb function. */
231
232 int
233 arm_pc_is_thumb_dummy (CORE_ADDR memaddr)
234 {
235 CORE_ADDR sp = read_sp ();
236
237 /* FIXME: Until we switch for the new call dummy macros, this heuristic
238 is the best we can do. We are trying to determine if the pc is on
239 the stack, which (hopefully) will only happen in a call dummy.
240 We hope the current stack pointer is not so far alway from the dummy
241 frame location (true if we have not pushed large data structures or
242 gone too many levels deep) and that our 1024 is not enough to consider
243 code regions as part of the stack (true for most practical purposes). */
244 if (DEPRECATED_PC_IN_CALL_DUMMY (memaddr, sp, sp + 1024))
245 return caller_is_thumb;
246 else
247 return 0;
248 }
249
250 /* Remove useless bits from addresses in a running program. */
251 static CORE_ADDR
252 arm_addr_bits_remove (CORE_ADDR val)
253 {
254 if (arm_apcs_32)
255 return (val & (arm_pc_is_thumb (val) ? 0xfffffffe : 0xfffffffc));
256 else
257 return (val & 0x03fffffc);
258 }
259
260 /* When reading symbols, we need to zap the low bit of the address,
261 which may be set to 1 for Thumb functions. */
262 static CORE_ADDR
263 arm_smash_text_address (CORE_ADDR val)
264 {
265 return val & ~1;
266 }
267
268 /* Immediately after a function call, return the saved pc. Can't
269 always go through the frames for this because on some machines the
270 new frame is not set up until the new function executes some
271 instructions. */
272
273 static CORE_ADDR
274 arm_saved_pc_after_call (struct frame_info *frame)
275 {
276 return ADDR_BITS_REMOVE (read_register (ARM_LR_REGNUM));
277 }
278
279 /* Determine whether the function invocation represented by FI has a
280 frame on the stack associated with it. If it does return zero,
281 otherwise return 1. */
282
283 static int
284 arm_frameless_function_invocation (struct frame_info *fi)
285 {
286 CORE_ADDR func_start, after_prologue;
287 int frameless;
288
289 /* Sometimes we have functions that do a little setup (like saving the
290 vN registers with the stmdb instruction, but DO NOT set up a frame.
291 The symbol table will report this as a prologue. However, it is
292 important not to try to parse these partial frames as frames, or we
293 will get really confused.
294
295 So I will demand 3 instructions between the start & end of the
296 prologue before I call it a real prologue, i.e. at least
297 mov ip, sp,
298 stmdb sp!, {}
299 sub sp, ip, #4. */
300
301 func_start = (get_frame_func (fi) + FUNCTION_START_OFFSET);
302 after_prologue = SKIP_PROLOGUE (func_start);
303
304 /* There are some frameless functions whose first two instructions
305 follow the standard APCS form, in which case after_prologue will
306 be func_start + 8. */
307
308 frameless = (after_prologue < func_start + 12);
309 return frameless;
310 }
311
312 /* A typical Thumb prologue looks like this:
313 push {r7, lr}
314 add sp, sp, #-28
315 add r7, sp, #12
316 Sometimes the latter instruction may be replaced by:
317 mov r7, sp
318
319 or like this:
320 push {r7, lr}
321 mov r7, sp
322 sub sp, #12
323
324 or, on tpcs, like this:
325 sub sp,#16
326 push {r7, lr}
327 (many instructions)
328 mov r7, sp
329 sub sp, #12
330
331 There is always one instruction of three classes:
332 1 - push
333 2 - setting of r7
334 3 - adjusting of sp
335
336 When we have found at least one of each class we are done with the prolog.
337 Note that the "sub sp, #NN" before the push does not count.
338 */
339
340 static CORE_ADDR
341 thumb_skip_prologue (CORE_ADDR pc, CORE_ADDR func_end)
342 {
343 CORE_ADDR current_pc;
344 /* findmask:
345 bit 0 - push { rlist }
346 bit 1 - mov r7, sp OR add r7, sp, #imm (setting of r7)
347 bit 2 - sub sp, #simm OR add sp, #simm (adjusting of sp)
348 */
349 int findmask = 0;
350
351 for (current_pc = pc;
352 current_pc + 2 < func_end && current_pc < pc + 40;
353 current_pc += 2)
354 {
355 unsigned short insn = read_memory_unsigned_integer (current_pc, 2);
356
357 if ((insn & 0xfe00) == 0xb400) /* push { rlist } */
358 {
359 findmask |= 1; /* push found */
360 }
361 else if ((insn & 0xff00) == 0xb000) /* add sp, #simm OR
362 sub sp, #simm */
363 {
364 if ((findmask & 1) == 0) /* before push ? */
365 continue;
366 else
367 findmask |= 4; /* add/sub sp found */
368 }
369 else if ((insn & 0xff00) == 0xaf00) /* add r7, sp, #imm */
370 {
371 findmask |= 2; /* setting of r7 found */
372 }
373 else if (insn == 0x466f) /* mov r7, sp */
374 {
375 findmask |= 2; /* setting of r7 found */
376 }
377 else if (findmask == (4+2+1))
378 {
379 /* We have found one of each type of prologue instruction */
380 break;
381 }
382 else
383 /* Something in the prolog that we don't care about or some
384 instruction from outside the prolog scheduled here for
385 optimization. */
386 continue;
387 }
388
389 return current_pc;
390 }
391
392 /* Advance the PC across any function entry prologue instructions to
393 reach some "real" code.
394
395 The APCS (ARM Procedure Call Standard) defines the following
396 prologue:
397
398 mov ip, sp
399 [stmfd sp!, {a1,a2,a3,a4}]
400 stmfd sp!, {...,fp,ip,lr,pc}
401 [stfe f7, [sp, #-12]!]
402 [stfe f6, [sp, #-12]!]
403 [stfe f5, [sp, #-12]!]
404 [stfe f4, [sp, #-12]!]
405 sub fp, ip, #nn @@ nn == 20 or 4 depending on second insn */
406
407 static CORE_ADDR
408 arm_skip_prologue (CORE_ADDR pc)
409 {
410 unsigned long inst;
411 CORE_ADDR skip_pc;
412 CORE_ADDR func_addr, func_end = 0;
413 char *func_name;
414 struct symtab_and_line sal;
415
416 /* If we're in a dummy frame, don't even try to skip the prologue. */
417 if (DEPRECATED_PC_IN_CALL_DUMMY (pc, 0, 0))
418 return pc;
419
420 /* See what the symbol table says. */
421
422 if (find_pc_partial_function (pc, &func_name, &func_addr, &func_end))
423 {
424 struct symbol *sym;
425
426 /* Found a function. */
427 sym = lookup_symbol (func_name, NULL, VAR_DOMAIN, NULL, NULL);
428 if (sym && SYMBOL_LANGUAGE (sym) != language_asm)
429 {
430 /* Don't use this trick for assembly source files. */
431 sal = find_pc_line (func_addr, 0);
432 if ((sal.line != 0) && (sal.end < func_end))
433 return sal.end;
434 }
435 }
436
437 /* Check if this is Thumb code. */
438 if (arm_pc_is_thumb (pc))
439 return thumb_skip_prologue (pc, func_end);
440
441 /* Can't find the prologue end in the symbol table, try it the hard way
442 by disassembling the instructions. */
443
444 /* Like arm_scan_prologue, stop no later than pc + 64. */
445 if (func_end == 0 || func_end > pc + 64)
446 func_end = pc + 64;
447
448 for (skip_pc = pc; skip_pc < func_end; skip_pc += 4)
449 {
450 inst = read_memory_integer (skip_pc, 4);
451
452 /* "mov ip, sp" is no longer a required part of the prologue. */
453 if (inst == 0xe1a0c00d) /* mov ip, sp */
454 continue;
455
456 /* Some prologues begin with "str lr, [sp, #-4]!". */
457 if (inst == 0xe52de004) /* str lr, [sp, #-4]! */
458 continue;
459
460 if ((inst & 0xfffffff0) == 0xe92d0000) /* stmfd sp!,{a1,a2,a3,a4} */
461 continue;
462
463 if ((inst & 0xfffff800) == 0xe92dd800) /* stmfd sp!,{fp,ip,lr,pc} */
464 continue;
465
466 /* Any insns after this point may float into the code, if it makes
467 for better instruction scheduling, so we skip them only if we
468 find them, but still consider the function to be frame-ful. */
469
470 /* We may have either one sfmfd instruction here, or several stfe
471 insns, depending on the version of floating point code we
472 support. */
473 if ((inst & 0xffbf0fff) == 0xec2d0200) /* sfmfd fn, <cnt>, [sp]! */
474 continue;
475
476 if ((inst & 0xffff8fff) == 0xed6d0103) /* stfe fn, [sp, #-12]! */
477 continue;
478
479 if ((inst & 0xfffff000) == 0xe24cb000) /* sub fp, ip, #nn */
480 continue;
481
482 if ((inst & 0xfffff000) == 0xe24dd000) /* sub sp, sp, #nn */
483 continue;
484
485 if ((inst & 0xffffc000) == 0xe54b0000 || /* strb r(0123),[r11,#-nn] */
486 (inst & 0xffffc0f0) == 0xe14b00b0 || /* strh r(0123),[r11,#-nn] */
487 (inst & 0xffffc000) == 0xe50b0000) /* str r(0123),[r11,#-nn] */
488 continue;
489
490 if ((inst & 0xffffc000) == 0xe5cd0000 || /* strb r(0123),[sp,#nn] */
491 (inst & 0xffffc0f0) == 0xe1cd00b0 || /* strh r(0123),[sp,#nn] */
492 (inst & 0xffffc000) == 0xe58d0000) /* str r(0123),[sp,#nn] */
493 continue;
494
495 /* Un-recognized instruction; stop scanning. */
496 break;
497 }
498
499 return skip_pc; /* End of prologue */
500 }
501
502 /* *INDENT-OFF* */
503 /* Function: thumb_scan_prologue (helper function for arm_scan_prologue)
504 This function decodes a Thumb function prologue to determine:
505 1) the size of the stack frame
506 2) which registers are saved on it
507 3) the offsets of saved regs
508 4) the offset from the stack pointer to the frame pointer
509 This information is stored in the "extra" fields of the frame_info.
510
511 A typical Thumb function prologue would create this stack frame
512 (offsets relative to FP)
513 old SP -> 24 stack parameters
514 20 LR
515 16 R7
516 R7 -> 0 local variables (16 bytes)
517 SP -> -12 additional stack space (12 bytes)
518 The frame size would thus be 36 bytes, and the frame offset would be
519 12 bytes. The frame register is R7.
520
521 The comments for thumb_skip_prolog() describe the algorithm we use
522 to detect the end of the prolog. */
523 /* *INDENT-ON* */
524
525 static void
526 thumb_scan_prologue (struct arm_prologue_cache *cache)
527 {
528 CORE_ADDR prologue_start;
529 CORE_ADDR prologue_end;
530 CORE_ADDR current_pc;
531 /* Which register has been copied to register n? */
532 int saved_reg[16];
533 /* findmask:
534 bit 0 - push { rlist }
535 bit 1 - mov r7, sp OR add r7, sp, #imm (setting of r7)
536 bit 2 - sub sp, #simm OR add sp, #simm (adjusting of sp)
537 */
538 int findmask = 0;
539 int i;
540
541 /* Don't try to scan dummy frames. */
542 if (DEPRECATED_PC_IN_CALL_DUMMY (cache->unwound_pc, 0, 0))
543 return;
544
545 if (find_pc_partial_function (cache->unwound_pc, NULL, &prologue_start, &prologue_end))
546 {
547 struct symtab_and_line sal = find_pc_line (prologue_start, 0);
548
549 if (sal.line == 0) /* no line info, use current PC */
550 prologue_end = cache->unwound_pc;
551 else if (sal.end < prologue_end) /* next line begins after fn end */
552 prologue_end = sal.end; /* (probably means no prologue) */
553 }
554 else
555 /* We're in the boondocks: allow for
556 16 pushes, an add, and "mv fp,sp". */
557 prologue_end = prologue_start + 40;
558
559 prologue_end = min (prologue_end, cache->unwound_pc);
560
561 /* Initialize the saved register map. When register H is copied to
562 register L, we will put H in saved_reg[L]. */
563 for (i = 0; i < 16; i++)
564 saved_reg[i] = i;
565
566 /* Search the prologue looking for instructions that set up the
567 frame pointer, adjust the stack pointer, and save registers.
568 Do this until all basic prolog instructions are found. */
569
570 cache->framesize = 0;
571 for (current_pc = prologue_start;
572 (current_pc < prologue_end) && ((findmask & 7) != 7);
573 current_pc += 2)
574 {
575 unsigned short insn;
576 int regno;
577 int offset;
578
579 insn = read_memory_unsigned_integer (current_pc, 2);
580
581 if ((insn & 0xfe00) == 0xb400) /* push { rlist } */
582 {
583 int mask;
584 findmask |= 1; /* push found */
585 /* Bits 0-7 contain a mask for registers R0-R7. Bit 8 says
586 whether to save LR (R14). */
587 mask = (insn & 0xff) | ((insn & 0x100) << 6);
588
589 /* Calculate offsets of saved R0-R7 and LR. */
590 for (regno = ARM_LR_REGNUM; regno >= 0; regno--)
591 if (mask & (1 << regno))
592 {
593 cache->framesize += 4;
594 cache->saved_regs[saved_reg[regno]] = -cache->framesize;
595 /* Reset saved register map. */
596 saved_reg[regno] = regno;
597 }
598 }
599 else if ((insn & 0xff00) == 0xb000) /* add sp, #simm OR
600 sub sp, #simm */
601 {
602 if ((findmask & 1) == 0) /* before push? */
603 continue;
604 else
605 findmask |= 4; /* add/sub sp found */
606
607 offset = (insn & 0x7f) << 2; /* get scaled offset */
608 if (insn & 0x80) /* is it signed? (==subtracting) */
609 {
610 cache->frameoffset += offset;
611 offset = -offset;
612 }
613 cache->framesize -= offset;
614 }
615 else if ((insn & 0xff00) == 0xaf00) /* add r7, sp, #imm */
616 {
617 findmask |= 2; /* setting of r7 found */
618 cache->framereg = THUMB_FP_REGNUM;
619 /* get scaled offset */
620 cache->frameoffset = (insn & 0xff) << 2;
621 }
622 else if (insn == 0x466f) /* mov r7, sp */
623 {
624 findmask |= 2; /* setting of r7 found */
625 cache->framereg = THUMB_FP_REGNUM;
626 cache->frameoffset = 0;
627 saved_reg[THUMB_FP_REGNUM] = ARM_SP_REGNUM;
628 }
629 else if ((insn & 0xffc0) == 0x4640) /* mov r0-r7, r8-r15 */
630 {
631 int lo_reg = insn & 7; /* dest. register (r0-r7) */
632 int hi_reg = ((insn >> 3) & 7) + 8; /* source register (r8-15) */
633 saved_reg[lo_reg] = hi_reg; /* remember hi reg was saved */
634 }
635 else
636 /* Something in the prolog that we don't care about or some
637 instruction from outside the prolog scheduled here for
638 optimization. */
639 continue;
640 }
641 }
642
643 /* This function decodes an ARM function prologue to determine:
644 1) the size of the stack frame
645 2) which registers are saved on it
646 3) the offsets of saved regs
647 4) the offset from the stack pointer to the frame pointer
648 This information is stored in the "extra" fields of the frame_info.
649
650 There are two basic forms for the ARM prologue. The fixed argument
651 function call will look like:
652
653 mov ip, sp
654 stmfd sp!, {fp, ip, lr, pc}
655 sub fp, ip, #4
656 [sub sp, sp, #4]
657
658 Which would create this stack frame (offsets relative to FP):
659 IP -> 4 (caller's stack)
660 FP -> 0 PC (points to address of stmfd instruction + 8 in callee)
661 -4 LR (return address in caller)
662 -8 IP (copy of caller's SP)
663 -12 FP (caller's FP)
664 SP -> -28 Local variables
665
666 The frame size would thus be 32 bytes, and the frame offset would be
667 28 bytes. The stmfd call can also save any of the vN registers it
668 plans to use, which increases the frame size accordingly.
669
670 Note: The stored PC is 8 off of the STMFD instruction that stored it
671 because the ARM Store instructions always store PC + 8 when you read
672 the PC register.
673
674 A variable argument function call will look like:
675
676 mov ip, sp
677 stmfd sp!, {a1, a2, a3, a4}
678 stmfd sp!, {fp, ip, lr, pc}
679 sub fp, ip, #20
680
681 Which would create this stack frame (offsets relative to FP):
682 IP -> 20 (caller's stack)
683 16 A4
684 12 A3
685 8 A2
686 4 A1
687 FP -> 0 PC (points to address of stmfd instruction + 8 in callee)
688 -4 LR (return address in caller)
689 -8 IP (copy of caller's SP)
690 -12 FP (caller's FP)
691 SP -> -28 Local variables
692
693 The frame size would thus be 48 bytes, and the frame offset would be
694 28 bytes.
695
696 There is another potential complication, which is that the optimizer
697 will try to separate the store of fp in the "stmfd" instruction from
698 the "sub fp, ip, #NN" instruction. Almost anything can be there, so
699 we just key on the stmfd, and then scan for the "sub fp, ip, #NN"...
700
701 Also, note, the original version of the ARM toolchain claimed that there
702 should be an
703
704 instruction at the end of the prologue. I have never seen GCC produce
705 this, and the ARM docs don't mention it. We still test for it below in
706 case it happens...
707
708 */
709
710 static void
711 arm_scan_prologue (struct arm_prologue_cache *cache)
712 {
713 int regno, sp_offset, fp_offset;
714 LONGEST return_value;
715 CORE_ADDR prologue_start, prologue_end, current_pc;
716
717 /* Assume there is no frame until proven otherwise. */
718 cache->framereg = ARM_SP_REGNUM;
719 cache->framesize = 0;
720 cache->frameoffset = 0;
721
722 /* Check for Thumb prologue. */
723 if (arm_pc_is_thumb (cache->unwound_pc))
724 {
725 thumb_scan_prologue (cache);
726 return;
727 }
728
729 /* Find the function prologue. If we can't find the function in
730 the symbol table, peek in the stack frame to find the PC. */
731 if (find_pc_partial_function (cache->unwound_pc, NULL, &prologue_start, &prologue_end))
732 {
733 /* One way to find the end of the prologue (which works well
734 for unoptimized code) is to do the following:
735
736 struct symtab_and_line sal = find_pc_line (prologue_start, 0);
737
738 if (sal.line == 0)
739 prologue_end = cache->unwound_pc;
740 else if (sal.end < prologue_end)
741 prologue_end = sal.end;
742
743 This mechanism is very accurate so long as the optimizer
744 doesn't move any instructions from the function body into the
745 prologue. If this happens, sal.end will be the last
746 instruction in the first hunk of prologue code just before
747 the first instruction that the scheduler has moved from
748 the body to the prologue.
749
750 In order to make sure that we scan all of the prologue
751 instructions, we use a slightly less accurate mechanism which
752 may scan more than necessary. To help compensate for this
753 lack of accuracy, the prologue scanning loop below contains
754 several clauses which'll cause the loop to terminate early if
755 an implausible prologue instruction is encountered.
756
757 The expression
758
759 prologue_start + 64
760
761 is a suitable endpoint since it accounts for the largest
762 possible prologue plus up to five instructions inserted by
763 the scheduler. */
764
765 if (prologue_end > prologue_start + 64)
766 {
767 prologue_end = prologue_start + 64; /* See above. */
768 }
769 }
770 else
771 {
772 /* Get address of the stmfd in the prologue of the callee;
773 the saved PC is the address of the stmfd + 8. */
774 if (!safe_read_memory_integer (cache->unwound_sp, 4, &return_value))
775 return;
776 else
777 {
778 prologue_start = ADDR_BITS_REMOVE (return_value) - 8;
779 prologue_end = prologue_start + 64; /* See above. */
780 }
781 }
782
783 /* Now search the prologue looking for instructions that set up the
784 frame pointer, adjust the stack pointer, and save registers.
785
786 Be careful, however, and if it doesn't look like a prologue,
787 don't try to scan it. If, for instance, a frameless function
788 begins with stmfd sp!, then we will tell ourselves there is
789 a frame, which will confuse stack traceback, as well as "finish"
790 and other operations that rely on a knowledge of the stack
791 traceback.
792
793 In the APCS, the prologue should start with "mov ip, sp" so
794 if we don't see this as the first insn, we will stop.
795
796 [Note: This doesn't seem to be true any longer, so it's now an
797 optional part of the prologue. - Kevin Buettner, 2001-11-20]
798
799 [Note further: The "mov ip,sp" only seems to be missing in
800 frameless functions at optimization level "-O2" or above,
801 in which case it is often (but not always) replaced by
802 "str lr, [sp, #-4]!". - Michael Snyder, 2002-04-23] */
803
804 sp_offset = fp_offset = 0;
805
806 for (current_pc = prologue_start;
807 current_pc < prologue_end;
808 current_pc += 4)
809 {
810 unsigned int insn = read_memory_unsigned_integer (current_pc, 4);
811
812 if (insn == 0xe1a0c00d) /* mov ip, sp */
813 {
814 continue;
815 }
816 else if (insn == 0xe52de004) /* str lr, [sp, #-4]! */
817 {
818 /* Function is frameless: extra_info defaults OK? */
819 continue;
820 }
821 else if ((insn & 0xffff0000) == 0xe92d0000)
822 /* stmfd sp!, {..., fp, ip, lr, pc}
823 or
824 stmfd sp!, {a1, a2, a3, a4} */
825 {
826 int mask = insn & 0xffff;
827
828 /* Calculate offsets of saved registers. */
829 for (regno = ARM_PC_REGNUM; regno >= 0; regno--)
830 if (mask & (1 << regno))
831 {
832 sp_offset -= 4;
833 cache->saved_regs[regno] = sp_offset;
834 }
835 }
836 else if ((insn & 0xffffc000) == 0xe54b0000 || /* strb rx,[r11,#-n] */
837 (insn & 0xffffc0f0) == 0xe14b00b0 || /* strh rx,[r11,#-n] */
838 (insn & 0xffffc000) == 0xe50b0000) /* str rx,[r11,#-n] */
839 {
840 /* No need to add this to saved_regs -- it's just an arg reg. */
841 continue;
842 }
843 else if ((insn & 0xffffc000) == 0xe5cd0000 || /* strb rx,[sp,#n] */
844 (insn & 0xffffc0f0) == 0xe1cd00b0 || /* strh rx,[sp,#n] */
845 (insn & 0xffffc000) == 0xe58d0000) /* str rx,[sp,#n] */
846 {
847 /* No need to add this to saved_regs -- it's just an arg reg. */
848 continue;
849 }
850 else if ((insn & 0xfffff000) == 0xe24cb000) /* sub fp, ip #n */
851 {
852 unsigned imm = insn & 0xff; /* immediate value */
853 unsigned rot = (insn & 0xf00) >> 7; /* rotate amount */
854 imm = (imm >> rot) | (imm << (32 - rot));
855 fp_offset = -imm;
856 cache->framereg = ARM_FP_REGNUM;
857 }
858 else if ((insn & 0xfffff000) == 0xe24dd000) /* sub sp, sp #n */
859 {
860 unsigned imm = insn & 0xff; /* immediate value */
861 unsigned rot = (insn & 0xf00) >> 7; /* rotate amount */
862 imm = (imm >> rot) | (imm << (32 - rot));
863 sp_offset -= imm;
864 }
865 else if ((insn & 0xffff7fff) == 0xed6d0103) /* stfe f?, [sp, -#c]! */
866 {
867 sp_offset -= 12;
868 regno = ARM_F0_REGNUM + ((insn >> 12) & 0x07);
869 cache->saved_regs[regno] = sp_offset;
870 }
871 else if ((insn & 0xffbf0fff) == 0xec2d0200) /* sfmfd f0, 4, [sp!] */
872 {
873 int n_saved_fp_regs;
874 unsigned int fp_start_reg, fp_bound_reg;
875
876 if ((insn & 0x800) == 0x800) /* N0 is set */
877 {
878 if ((insn & 0x40000) == 0x40000) /* N1 is set */
879 n_saved_fp_regs = 3;
880 else
881 n_saved_fp_regs = 1;
882 }
883 else
884 {
885 if ((insn & 0x40000) == 0x40000) /* N1 is set */
886 n_saved_fp_regs = 2;
887 else
888 n_saved_fp_regs = 4;
889 }
890
891 fp_start_reg = ARM_F0_REGNUM + ((insn >> 12) & 0x7);
892 fp_bound_reg = fp_start_reg + n_saved_fp_regs;
893 for (; fp_start_reg < fp_bound_reg; fp_start_reg++)
894 {
895 sp_offset -= 12;
896 cache->saved_regs[fp_start_reg++] = sp_offset;
897 }
898 }
899 else if ((insn & 0xf0000000) != 0xe0000000)
900 break; /* Condition not true, exit early */
901 else if ((insn & 0xfe200000) == 0xe8200000) /* ldm? */
902 break; /* Don't scan past a block load */
903 else
904 /* The optimizer might shove anything into the prologue,
905 so we just skip what we don't recognize. */
906 continue;
907 }
908
909 /* The frame size is just the negative of the offset (from the
910 original SP) of the last thing thing we pushed on the stack.
911 The frame offset is [new FP] - [new SP]. */
912 cache->framesize = -sp_offset;
913 if (cache->framereg == ARM_FP_REGNUM)
914 cache->frameoffset = fp_offset - sp_offset;
915 else
916 cache->frameoffset = 0;
917 }
918
919 /* Find REGNUM on the stack. Otherwise, it's in an active register.
920 One thing we might want to do here is to check REGNUM against the
921 clobber mask, and somehow flag it as invalid if it isn't saved on
922 the stack somewhere. This would provide a graceful failure mode
923 when trying to get the value of caller-saves registers for an inner
924 frame. */
925
926 static CORE_ADDR
927 arm_find_callers_reg (struct frame_info *fi, int regnum)
928 {
929 /* NOTE: cagney/2002-05-03: This function really shouldn't be
930 needed. Instead the (still being written) register unwind
931 function could be called directly. */
932 for (; fi; fi = get_next_frame (fi))
933 {
934 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi), 0, 0))
935 {
936 return deprecated_read_register_dummy (get_frame_pc (fi),
937 get_frame_base (fi), regnum);
938 }
939 else if (get_frame_saved_regs (fi)[regnum] != 0)
940 {
941 /* NOTE: cagney/2002-05-03: This would normally need to
942 handle ARM_SP_REGNUM as a special case as, according to
943 the frame.h comments, saved_regs[SP_REGNUM] contains the
944 SP value not its address. It appears that the ARM isn't
945 doing this though. */
946 return read_memory_integer (get_frame_saved_regs (fi)[regnum],
947 REGISTER_RAW_SIZE (regnum));
948 }
949 }
950 return read_register (regnum);
951 }
952 /* Function: frame_chain Given a GDB frame, determine the address of
953 the calling function's frame. This will be used to create a new
954 GDB frame struct, and then DEPRECATED_INIT_EXTRA_FRAME_INFO and
955 DEPRECATED_INIT_FRAME_PC will be called for the new frame. For
956 ARM, we save the frame size when we initialize the frame_info. */
957
958 CORE_ADDR
959 arm_minimal_frame_chain (struct frame_info *next_frame, struct arm_prologue_cache *cache)
960 {
961 CORE_ADDR caller_pc;
962 int framereg = arm_get_cache (next_frame)->framereg;
963
964 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (next_frame), 0, 0))
965 return get_frame_base (next_frame);
966
967 if (get_frame_pc (next_frame) < LOWEST_PC)
968 return 0;
969
970 caller_pc = cache->unwound_pc;
971
972 /* If the caller is Thumb and the caller is ARM, or vice versa,
973 the frame register of the caller is different from ours.
974 So we must scan the prologue of the caller to determine its
975 frame register number. */
976 /* XXX Fixme, we should try to do this without creating a temporary
977 cache! */
978 /* NOTE drow/2003-06-26: I'm quite suspicious of this code... what is it
979 really doing? I have the feeling that it's trying to handle the case
980 where my framereg is ARM_FP_REGNUM, and my (Thumb) caller's framereg is
981 THUMB_FP_REGNUM, and switching between the two. But the unwinder should
982 be taking care of that. */
983 if (arm_pc_is_thumb (caller_pc) != arm_pc_is_thumb (get_frame_pc (next_frame)))
984 {
985 struct arm_prologue_cache *cache
986 = xcalloc (1, sizeof (struct arm_prologue_cache)
987 + (NUM_REGS + NUM_PSEUDO_REGS - 1) * sizeof (CORE_ADDR));
988 struct cleanup *old_chain = make_cleanup (xfree, cache);
989
990 /* Now, scan the prologue and obtain the frame register. */
991 cache->unwound_pc = caller_pc;
992 arm_scan_prologue (cache);
993 framereg = cache->framereg;
994
995 /* Deallocate the storage associated with the temporary frame
996 created above. */
997 do_cleanups (old_chain);
998 }
999
1000 /* If the caller used a frame register, return its value.
1001 Otherwise, return the caller's stack pointer. */
1002 if (framereg == ARM_FP_REGNUM || framereg == THUMB_FP_REGNUM)
1003 return arm_find_callers_reg (next_frame, framereg);
1004 else
1005 /* FIXME drow/2003-06-26: The next frame is an opaque thing at this point,
1006 we should only be using frame methods on it. What if it's a dummy
1007 frame, calling a frameless function (framereg == ARM_SP_REGNUM)? Test
1008 it. */
1009 return get_frame_base (next_frame) + arm_get_cache (next_frame)->framesize;
1010 }
1011
1012 /* This function actually figures out the frame address for a given pc
1013 and sp. This is tricky because we sometimes don't use an explicit
1014 frame pointer, and the previous stack pointer isn't necessarily
1015 recorded on the stack. The only reliable way to get this info is
1016 to examine the prologue. */
1017
1018 static void
1019 arm_minimal_frame_info (struct frame_info *next_frame,
1020 struct arm_prologue_cache *cache)
1021 {
1022 int reg;
1023 CORE_ADDR sp;
1024
1025 memset (cache->saved_regs, '\000', sizeof (CORE_ADDR) * (NUM_REGS + NUM_PSEUDO_REGS));
1026
1027 /* Compute stack pointer for this frame. We use this value for both
1028 the sigtramp and call dummy cases. */
1029
1030 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (next_frame), 0, 0))
1031 /* For generic dummy frames, pull the value direct from the frame.
1032 Having an unwind function to do this would be nice. */
1033 sp = deprecated_read_register_dummy (get_frame_pc (next_frame),
1034 get_frame_base (next_frame),
1035 ARM_SP_REGNUM);
1036 else if (arm_get_cache (next_frame))
1037 sp = (get_frame_base (next_frame)
1038 - arm_get_cache (next_frame)->frameoffset
1039 + arm_get_cache (next_frame)->framesize);
1040 else
1041 sp = read_sp (); /* FIXME remove case */
1042
1043 /* Determine whether or not we're in a sigtramp frame.
1044 Unfortunately, it isn't sufficient to test (get_frame_type (fi)
1045 == SIGTRAMP_FRAME) because this value is sometimes set after
1046 invoking DEPRECATED_INIT_EXTRA_FRAME_INFO. So we test *both*
1047 (get_frame_type (fi) == SIGTRAMP_FRAME) and PC_IN_SIGTRAMP to
1048 determine if we need to use the sigcontext addresses for the
1049 saved registers.
1050
1051 Note: If an ARM PC_IN_SIGTRAMP method ever needs to compare
1052 against the name of the function, the code below will have to be
1053 changed to first fetch the name of the function and then pass
1054 this name to PC_IN_SIGTRAMP. */
1055
1056 /* FIXME: cagney/2002-11-18: This problem will go away once
1057 frame.c:get_prev_frame() is modified to set the frame's type
1058 before calling functions like this. */
1059
1060 /* NOTE drow/2003-06-26: This will move to a predicate for a different unwinder shortly. */
1061
1062 if (SIGCONTEXT_REGISTER_ADDRESS_P ()
1063 && PC_IN_SIGTRAMP (cache->unwound_pc, (char *)0))
1064 {
1065 for (reg = 0; reg < NUM_REGS; reg++)
1066 cache->saved_regs[reg] = SIGCONTEXT_REGISTER_ADDRESS (sp, cache->unwound_pc, reg);
1067
1068 /* FIXME: What about thumb mode? */
1069 cache->framereg = ARM_SP_REGNUM;
1070 cache->unwound_sp = read_memory_integer (cache->saved_regs[cache->framereg], REGISTER_RAW_SIZE (cache->framereg));
1071 cache->framesize = 0;
1072 cache->frameoffset = 0;
1073 }
1074 else
1075 {
1076 /* At this point, the unwound sp is just the result of frame_chain.
1077 Then it gets changed below. */
1078
1079 arm_scan_prologue (cache);
1080
1081 if (!next_frame)
1082 /* This is the innermost frame? */
1083 cache->unwound_sp = read_register (cache->framereg);
1084 else if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (next_frame), 0, 0))
1085 /* Next inner most frame is a dummy, just grab its frame.
1086 Dummy frames always have the same FP as their caller. */
1087 cache->unwound_sp = get_frame_base (next_frame);
1088 else if (cache->framereg == ARM_FP_REGNUM
1089 || cache->framereg == THUMB_FP_REGNUM)
1090 {
1091 /* not the innermost frame */
1092 /* If we have an FP, the callee saved it. */
1093 if (get_frame_saved_regs (next_frame) /**/ && get_frame_saved_regs (next_frame)[cache->framereg] != 0)
1094 cache->unwound_sp = read_memory_integer (get_frame_saved_regs (next_frame)[cache->framereg], 4);
1095 else if (frame_relative_level (next_frame) == 0
1096 && FRAMELESS_FUNCTION_INVOCATION (next_frame))
1097 /* If we were called by a frameless fn. then our frame is
1098 still in the frame pointer register on the board... */
1099 cache->unwound_sp = deprecated_read_fp ();
1100 }
1101
1102 /* Calculate actual addresses of saved registers using offsets
1103 determined by arm_scan_prologue. */
1104 for (reg = 0; reg < NUM_REGS; reg++)
1105 if (cache->saved_regs[reg] != 0)
1106 cache->saved_regs[reg] = (cache->saved_regs[reg]
1107 + cache->unwound_sp
1108 + cache->framesize
1109 - cache->frameoffset);
1110 }
1111 }
1112
1113 static struct arm_prologue_cache *
1114 arm_make_prologue_cache (struct frame_info *next_frame)
1115 {
1116 struct arm_prologue_cache *cache;
1117
1118 cache = frame_obstack_zalloc (sizeof (struct arm_prologue_cache)
1119 + sizeof (CORE_ADDR) * (NUM_REGS + NUM_PSEUDO_REGS - 1));
1120
1121 cache->unwound_pc = frame_pc_unwind (next_frame);
1122 if (frame_relative_level (next_frame) < 0)
1123 cache->unwound_sp = deprecated_read_fp ();
1124 else
1125 cache->unwound_sp = arm_minimal_frame_chain (next_frame, cache);
1126 arm_minimal_frame_info (next_frame, cache);
1127
1128 return cache;
1129 }
1130
1131 static CORE_ADDR
1132 arm_frame_chain (struct frame_info *next_frame)
1133 {
1134 struct arm_prologue_cache *cache;
1135
1136 cache = arm_make_prologue_cache (next_frame);
1137 return cache->unwound_sp;
1138 }
1139
1140 static void
1141 arm_init_extra_frame_info (int fromleaf, struct frame_info *fi)
1142 {
1143 struct arm_prologue_cache *cache;
1144
1145 cache = arm_make_prologue_cache (deprecated_get_next_frame_hack (fi));
1146
1147 if (get_frame_saved_regs (fi) == NULL)
1148 frame_saved_regs_zalloc (fi);
1149
1150 frame_extra_info_zalloc (fi, (sizeof (struct arm_prologue_cache)
1151 + ((NUM_REGS + NUM_PSEUDO_REGS - 1)
1152 * sizeof (CORE_ADDR))));
1153
1154 memcpy (get_frame_extra_info (fi), cache, (sizeof (struct arm_prologue_cache)
1155 + ((NUM_REGS + NUM_PSEUDO_REGS - 1)
1156 * sizeof (CORE_ADDR))));
1157 memcpy (get_frame_saved_regs (fi), cache->saved_regs,
1158 (NUM_REGS + NUM_PSEUDO_REGS - 1) * sizeof (CORE_ADDR));
1159 }
1160
1161 /* Find the caller of this frame. We do this by seeing if ARM_LR_REGNUM
1162 is saved in the stack anywhere, otherwise we get it from the
1163 registers.
1164
1165 The old definition of this function was a macro:
1166 #define FRAME_SAVED_PC(FRAME) \
1167 ADDR_BITS_REMOVE (read_memory_integer ((FRAME)->frame - 4, 4)) */
1168
1169 static CORE_ADDR
1170 arm_frame_saved_pc (struct frame_info *fi)
1171 {
1172 /* If a dummy frame, pull the PC out of the frame's register buffer. */
1173 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi), 0, 0))
1174 return deprecated_read_register_dummy (get_frame_pc (fi),
1175 get_frame_base (fi), ARM_PC_REGNUM);
1176
1177 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi),
1178 (get_frame_base (fi)
1179 - arm_get_cache (fi)->frameoffset),
1180 get_frame_base (fi)))
1181 {
1182 return read_memory_integer (get_frame_saved_regs (fi)[ARM_PC_REGNUM],
1183 REGISTER_RAW_SIZE (ARM_PC_REGNUM));
1184 }
1185 else
1186 {
1187 CORE_ADDR pc = arm_find_callers_reg (fi, ARM_LR_REGNUM);
1188 return IS_THUMB_ADDR (pc) ? UNMAKE_THUMB_ADDR (pc) : pc;
1189 }
1190 }
1191
1192 /* Return the frame address. On ARM, it is R11; on Thumb it is R7.
1193 Examine the Program Status Register to decide which state we're in. */
1194
1195 static CORE_ADDR
1196 arm_read_fp (void)
1197 {
1198 if (read_register (ARM_PS_REGNUM) & 0x20) /* Bit 5 is Thumb state bit */
1199 return read_register (THUMB_FP_REGNUM); /* R7 if Thumb */
1200 else
1201 return read_register (ARM_FP_REGNUM); /* R11 if ARM */
1202 }
1203
1204 /* Store into a struct frame_saved_regs the addresses of the saved
1205 registers of frame described by FRAME_INFO. This includes special
1206 registers such as PC and FP saved in special ways in the stack
1207 frame. SP is even more special: the address we return for it IS
1208 the sp for the next frame. */
1209
1210 static void
1211 arm_frame_init_saved_regs (struct frame_info *fip)
1212 {
1213
1214 if (get_frame_saved_regs (fip))
1215 return;
1216
1217 arm_init_extra_frame_info (0, fip);
1218 }
1219
1220 /* Set the return address for a generic dummy frame. ARM uses the
1221 entry point. */
1222
1223 static CORE_ADDR
1224 arm_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
1225 {
1226 write_register (ARM_LR_REGNUM, CALL_DUMMY_ADDRESS ());
1227 return sp;
1228 }
1229
1230 /* Push an empty stack frame, to record the current PC, etc. */
1231
1232 static void
1233 arm_push_dummy_frame (void)
1234 {
1235 CORE_ADDR old_sp = read_register (ARM_SP_REGNUM);
1236 CORE_ADDR sp = old_sp;
1237 CORE_ADDR fp, prologue_start;
1238 int regnum;
1239
1240 /* Push the two dummy prologue instructions in reverse order,
1241 so that they'll be in the correct low-to-high order in memory. */
1242 /* sub fp, ip, #4 */
1243 sp = push_word (sp, 0xe24cb004);
1244 /* stmdb sp!, {r0-r10, fp, ip, lr, pc} */
1245 prologue_start = sp = push_word (sp, 0xe92ddfff);
1246
1247 /* Push a pointer to the dummy prologue + 12, because when stm
1248 instruction stores the PC, it stores the address of the stm
1249 instruction itself plus 12. */
1250 fp = sp = push_word (sp, prologue_start + 12);
1251
1252 /* Push the processor status. */
1253 sp = push_word (sp, read_register (ARM_PS_REGNUM));
1254
1255 /* Push all 16 registers starting with r15. */
1256 for (regnum = ARM_PC_REGNUM; regnum >= 0; regnum--)
1257 sp = push_word (sp, read_register (regnum));
1258
1259 /* Update fp (for both Thumb and ARM) and sp. */
1260 write_register (ARM_FP_REGNUM, fp);
1261 write_register (THUMB_FP_REGNUM, fp);
1262 write_register (ARM_SP_REGNUM, sp);
1263 }
1264
1265 /* DEPRECATED_CALL_DUMMY_WORDS:
1266 This sequence of words is the instructions
1267
1268 mov lr,pc
1269 mov pc,r4
1270 illegal
1271
1272 Note this is 12 bytes. */
1273
1274 static LONGEST arm_call_dummy_words[] =
1275 {
1276 0xe1a0e00f, 0xe1a0f004, 0xe7ffdefe
1277 };
1278
1279 /* Adjust the call_dummy_breakpoint_offset for the bp_call_dummy
1280 breakpoint to the proper address in the call dummy, so that
1281 `finish' after a stop in a call dummy works.
1282
1283 FIXME rearnsha 2002-02018: Tweeking current_gdbarch is not an
1284 optimal solution, but the call to arm_fix_call_dummy is immediately
1285 followed by a call to call_function_by_hand, which is the only
1286 function where call_dummy_breakpoint_offset is actually used. */
1287
1288
1289 static void
1290 arm_set_call_dummy_breakpoint_offset (void)
1291 {
1292 if (caller_is_thumb)
1293 set_gdbarch_deprecated_call_dummy_breakpoint_offset (current_gdbarch, 4);
1294 else
1295 set_gdbarch_deprecated_call_dummy_breakpoint_offset (current_gdbarch, 8);
1296 }
1297
1298 /* Fix up the call dummy, based on whether the processor is currently
1299 in Thumb or ARM mode, and whether the target function is Thumb or
1300 ARM. There are three different situations requiring three
1301 different dummies:
1302
1303 * ARM calling ARM: uses the call dummy in tm-arm.h, which has already
1304 been copied into the dummy parameter to this function.
1305 * ARM calling Thumb: uses the call dummy in tm-arm.h, but with the
1306 "mov pc,r4" instruction patched to be a "bx r4" instead.
1307 * Thumb calling anything: uses the Thumb dummy defined below, which
1308 works for calling both ARM and Thumb functions.
1309
1310 All three call dummies expect to receive the target function
1311 address in R4, with the low bit set if it's a Thumb function. */
1312
1313 static void
1314 arm_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
1315 struct value **args, struct type *type, int gcc_p)
1316 {
1317 static short thumb_dummy[4] =
1318 {
1319 0xf000, 0xf801, /* bl label */
1320 0xdf18, /* swi 24 */
1321 0x4720, /* label: bx r4 */
1322 };
1323 static unsigned long arm_bx_r4 = 0xe12fff14; /* bx r4 instruction */
1324
1325 /* Set flag indicating whether the current PC is in a Thumb function. */
1326 caller_is_thumb = arm_pc_is_thumb (read_pc ());
1327 arm_set_call_dummy_breakpoint_offset ();
1328
1329 /* If the target function is Thumb, set the low bit of the function
1330 address. And if the CPU is currently in ARM mode, patch the
1331 second instruction of call dummy to use a BX instruction to
1332 switch to Thumb mode. */
1333 target_is_thumb = arm_pc_is_thumb (fun);
1334 if (target_is_thumb)
1335 {
1336 fun |= 1;
1337 if (!caller_is_thumb)
1338 store_unsigned_integer (dummy + 4, sizeof (arm_bx_r4), arm_bx_r4);
1339 }
1340
1341 /* If the CPU is currently in Thumb mode, use the Thumb call dummy
1342 instead of the ARM one that's already been copied. This will
1343 work for both Thumb and ARM target functions. */
1344 if (caller_is_thumb)
1345 {
1346 int i;
1347 char *p = dummy;
1348 int len = sizeof (thumb_dummy) / sizeof (thumb_dummy[0]);
1349
1350 for (i = 0; i < len; i++)
1351 {
1352 store_unsigned_integer (p, sizeof (thumb_dummy[0]), thumb_dummy[i]);
1353 p += sizeof (thumb_dummy[0]);
1354 }
1355 }
1356
1357 /* Put the target address in r4; the call dummy will copy this to
1358 the PC. */
1359 write_register (4, fun);
1360 }
1361
1362 /* Pop the current frame. So long as the frame info has been
1363 initialized properly (see arm_init_extra_frame_info), this code
1364 works for dummy frames as well as regular frames. I.e, there's no
1365 need to have a special case for dummy frames. */
1366 static void
1367 arm_pop_frame (void)
1368 {
1369 int regnum;
1370 struct frame_info *frame = get_current_frame ();
1371 CORE_ADDR old_SP = (get_frame_base (frame)
1372 - arm_get_cache (frame)->frameoffset
1373 + arm_get_cache (frame)->framesize);
1374
1375 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame),
1376 get_frame_base (frame),
1377 get_frame_base (frame)))
1378 {
1379 generic_pop_dummy_frame ();
1380 flush_cached_frames ();
1381 return;
1382 }
1383
1384 for (regnum = 0; regnum < NUM_REGS; regnum++)
1385 if (get_frame_saved_regs (frame)[regnum] != 0)
1386 write_register (regnum,
1387 read_memory_integer (get_frame_saved_regs (frame)[regnum],
1388 REGISTER_RAW_SIZE (regnum)));
1389
1390 write_register (ARM_PC_REGNUM, DEPRECATED_FRAME_SAVED_PC (frame));
1391 write_register (ARM_SP_REGNUM, old_SP);
1392
1393 flush_cached_frames ();
1394 }
1395
1396 /* When arguments must be pushed onto the stack, they go on in reverse
1397 order. The code below implements a FILO (stack) to do this. */
1398
1399 struct stack_item
1400 {
1401 int len;
1402 struct stack_item *prev;
1403 void *data;
1404 };
1405
1406 static struct stack_item *
1407 push_stack_item (struct stack_item *prev, void *contents, int len)
1408 {
1409 struct stack_item *si;
1410 si = xmalloc (sizeof (struct stack_item));
1411 si->data = xmalloc (len);
1412 si->len = len;
1413 si->prev = prev;
1414 memcpy (si->data, contents, len);
1415 return si;
1416 }
1417
1418 static struct stack_item *
1419 pop_stack_item (struct stack_item *si)
1420 {
1421 struct stack_item *dead = si;
1422 si = si->prev;
1423 xfree (dead->data);
1424 xfree (dead);
1425 return si;
1426 }
1427
1428 /* We currently only support passing parameters in integer registers. This
1429 conforms with GCC's default model. Several other variants exist and
1430 we should probably support some of them based on the selected ABI. */
1431
1432 static CORE_ADDR
1433 arm_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
1434 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
1435 struct value **args, CORE_ADDR sp, int struct_return,
1436 CORE_ADDR struct_addr)
1437 {
1438 int argnum;
1439 int argreg;
1440 int nstack;
1441 struct stack_item *si = NULL;
1442
1443 /* Set the return address. For the ARM, the return breakpoint is
1444 always at BP_ADDR. */
1445 /* XXX Fix for Thumb. */
1446 regcache_cooked_write_unsigned (regcache, ARM_LR_REGNUM, bp_addr);
1447
1448 /* Walk through the list of args and determine how large a temporary
1449 stack is required. Need to take care here as structs may be
1450 passed on the stack, and we have to to push them. */
1451 nstack = 0;
1452
1453 argreg = ARM_A1_REGNUM;
1454 nstack = 0;
1455
1456 /* Some platforms require a double-word aligned stack. Make sure sp
1457 is correctly aligned before we start. We always do this even if
1458 it isn't really needed -- it can never hurt things. */
1459 sp &= ~(CORE_ADDR)(2 * DEPRECATED_REGISTER_SIZE - 1);
1460
1461 /* The struct_return pointer occupies the first parameter
1462 passing register. */
1463 if (struct_return)
1464 {
1465 if (arm_debug)
1466 fprintf_unfiltered (gdb_stdlog, "struct return in %s = 0x%s\n",
1467 REGISTER_NAME (argreg), paddr (struct_addr));
1468 regcache_cooked_write_unsigned (regcache, argreg, struct_addr);
1469 argreg++;
1470 }
1471
1472 for (argnum = 0; argnum < nargs; argnum++)
1473 {
1474 int len;
1475 struct type *arg_type;
1476 struct type *target_type;
1477 enum type_code typecode;
1478 char *val;
1479
1480 arg_type = check_typedef (VALUE_TYPE (args[argnum]));
1481 len = TYPE_LENGTH (arg_type);
1482 target_type = TYPE_TARGET_TYPE (arg_type);
1483 typecode = TYPE_CODE (arg_type);
1484 val = VALUE_CONTENTS (args[argnum]);
1485
1486 /* If the argument is a pointer to a function, and it is a
1487 Thumb function, create a LOCAL copy of the value and set
1488 the THUMB bit in it. */
1489 if (TYPE_CODE_PTR == typecode
1490 && target_type != NULL
1491 && TYPE_CODE_FUNC == TYPE_CODE (target_type))
1492 {
1493 CORE_ADDR regval = extract_unsigned_integer (val, len);
1494 if (arm_pc_is_thumb (regval))
1495 {
1496 val = alloca (len);
1497 store_unsigned_integer (val, len, MAKE_THUMB_ADDR (regval));
1498 }
1499 }
1500
1501 /* Copy the argument to general registers or the stack in
1502 register-sized pieces. Large arguments are split between
1503 registers and stack. */
1504 while (len > 0)
1505 {
1506 int partial_len = len < DEPRECATED_REGISTER_SIZE ? len : DEPRECATED_REGISTER_SIZE;
1507
1508 if (argreg <= ARM_LAST_ARG_REGNUM)
1509 {
1510 /* The argument is being passed in a general purpose
1511 register. */
1512 CORE_ADDR regval = extract_unsigned_integer (val, partial_len);
1513 if (arm_debug)
1514 fprintf_unfiltered (gdb_stdlog, "arg %d in %s = 0x%s\n",
1515 argnum, REGISTER_NAME (argreg),
1516 phex (regval, DEPRECATED_REGISTER_SIZE));
1517 regcache_cooked_write_unsigned (regcache, argreg, regval);
1518 argreg++;
1519 }
1520 else
1521 {
1522 /* Push the arguments onto the stack. */
1523 if (arm_debug)
1524 fprintf_unfiltered (gdb_stdlog, "arg %d @ sp + %d\n",
1525 argnum, nstack);
1526 si = push_stack_item (si, val, DEPRECATED_REGISTER_SIZE);
1527 nstack += DEPRECATED_REGISTER_SIZE;
1528 }
1529
1530 len -= partial_len;
1531 val += partial_len;
1532 }
1533 }
1534 /* If we have an odd number of words to push, then decrement the stack
1535 by one word now, so first stack argument will be dword aligned. */
1536 if (nstack & 4)
1537 sp -= 4;
1538
1539 while (si)
1540 {
1541 sp -= si->len;
1542 write_memory (sp, si->data, si->len);
1543 si = pop_stack_item (si);
1544 }
1545
1546 /* Finally, update teh SP register. */
1547 regcache_cooked_write_unsigned (regcache, ARM_SP_REGNUM, sp);
1548
1549 return sp;
1550 }
1551
1552 static void
1553 print_fpu_flags (int flags)
1554 {
1555 if (flags & (1 << 0))
1556 fputs ("IVO ", stdout);
1557 if (flags & (1 << 1))
1558 fputs ("DVZ ", stdout);
1559 if (flags & (1 << 2))
1560 fputs ("OFL ", stdout);
1561 if (flags & (1 << 3))
1562 fputs ("UFL ", stdout);
1563 if (flags & (1 << 4))
1564 fputs ("INX ", stdout);
1565 putchar ('\n');
1566 }
1567
1568 /* Print interesting information about the floating point processor
1569 (if present) or emulator. */
1570 static void
1571 arm_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
1572 struct frame_info *frame, const char *args)
1573 {
1574 register unsigned long status = read_register (ARM_FPS_REGNUM);
1575 int type;
1576
1577 type = (status >> 24) & 127;
1578 printf ("%s FPU type %d\n",
1579 (status & (1 << 31)) ? "Hardware" : "Software",
1580 type);
1581 fputs ("mask: ", stdout);
1582 print_fpu_flags (status >> 16);
1583 fputs ("flags: ", stdout);
1584 print_fpu_flags (status);
1585 }
1586
1587 /* Return the GDB type object for the "standard" data type of data in
1588 register N. */
1589
1590 static struct type *
1591 arm_register_type (int regnum)
1592 {
1593 if (regnum >= ARM_F0_REGNUM && regnum < ARM_F0_REGNUM + NUM_FREGS)
1594 {
1595 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
1596 return builtin_type_arm_ext_big;
1597 else
1598 return builtin_type_arm_ext_littlebyte_bigword;
1599 }
1600 else
1601 return builtin_type_int32;
1602 }
1603
1604 /* Index within `registers' of the first byte of the space for
1605 register N. */
1606
1607 static int
1608 arm_register_byte (int regnum)
1609 {
1610 if (regnum < ARM_F0_REGNUM)
1611 return regnum * INT_REGISTER_RAW_SIZE;
1612 else if (regnum < ARM_PS_REGNUM)
1613 return (NUM_GREGS * INT_REGISTER_RAW_SIZE
1614 + (regnum - ARM_F0_REGNUM) * FP_REGISTER_RAW_SIZE);
1615 else
1616 return (NUM_GREGS * INT_REGISTER_RAW_SIZE
1617 + NUM_FREGS * FP_REGISTER_RAW_SIZE
1618 + (regnum - ARM_FPS_REGNUM) * STATUS_REGISTER_SIZE);
1619 }
1620
1621 /* Number of bytes of storage in the actual machine representation for
1622 register N. All registers are 4 bytes, except fp0 - fp7, which are
1623 12 bytes in length. */
1624
1625 static int
1626 arm_register_raw_size (int regnum)
1627 {
1628 if (regnum < ARM_F0_REGNUM)
1629 return INT_REGISTER_RAW_SIZE;
1630 else if (regnum < ARM_FPS_REGNUM)
1631 return FP_REGISTER_RAW_SIZE;
1632 else
1633 return STATUS_REGISTER_SIZE;
1634 }
1635
1636 /* Number of bytes of storage in a program's representation
1637 for register N. */
1638 static int
1639 arm_register_virtual_size (int regnum)
1640 {
1641 if (regnum < ARM_F0_REGNUM)
1642 return INT_REGISTER_VIRTUAL_SIZE;
1643 else if (regnum < ARM_FPS_REGNUM)
1644 return FP_REGISTER_VIRTUAL_SIZE;
1645 else
1646 return STATUS_REGISTER_SIZE;
1647 }
1648
1649 /* Map GDB internal REGNUM onto the Arm simulator register numbers. */
1650 static int
1651 arm_register_sim_regno (int regnum)
1652 {
1653 int reg = regnum;
1654 gdb_assert (reg >= 0 && reg < NUM_REGS);
1655
1656 if (reg < NUM_GREGS)
1657 return SIM_ARM_R0_REGNUM + reg;
1658 reg -= NUM_GREGS;
1659
1660 if (reg < NUM_FREGS)
1661 return SIM_ARM_FP0_REGNUM + reg;
1662 reg -= NUM_FREGS;
1663
1664 if (reg < NUM_SREGS)
1665 return SIM_ARM_FPS_REGNUM + reg;
1666 reg -= NUM_SREGS;
1667
1668 internal_error (__FILE__, __LINE__, "Bad REGNUM %d", regnum);
1669 }
1670
1671 /* NOTE: cagney/2001-08-20: Both convert_from_extended() and
1672 convert_to_extended() use floatformat_arm_ext_littlebyte_bigword.
1673 It is thought that this is is the floating-point register format on
1674 little-endian systems. */
1675
1676 static void
1677 convert_from_extended (const struct floatformat *fmt, const void *ptr,
1678 void *dbl)
1679 {
1680 DOUBLEST d;
1681 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
1682 floatformat_to_doublest (&floatformat_arm_ext_big, ptr, &d);
1683 else
1684 floatformat_to_doublest (&floatformat_arm_ext_littlebyte_bigword,
1685 ptr, &d);
1686 floatformat_from_doublest (fmt, &d, dbl);
1687 }
1688
1689 static void
1690 convert_to_extended (const struct floatformat *fmt, void *dbl, const void *ptr)
1691 {
1692 DOUBLEST d;
1693 floatformat_to_doublest (fmt, ptr, &d);
1694 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
1695 floatformat_from_doublest (&floatformat_arm_ext_big, &d, dbl);
1696 else
1697 floatformat_from_doublest (&floatformat_arm_ext_littlebyte_bigword,
1698 &d, dbl);
1699 }
1700
1701 static int
1702 condition_true (unsigned long cond, unsigned long status_reg)
1703 {
1704 if (cond == INST_AL || cond == INST_NV)
1705 return 1;
1706
1707 switch (cond)
1708 {
1709 case INST_EQ:
1710 return ((status_reg & FLAG_Z) != 0);
1711 case INST_NE:
1712 return ((status_reg & FLAG_Z) == 0);
1713 case INST_CS:
1714 return ((status_reg & FLAG_C) != 0);
1715 case INST_CC:
1716 return ((status_reg & FLAG_C) == 0);
1717 case INST_MI:
1718 return ((status_reg & FLAG_N) != 0);
1719 case INST_PL:
1720 return ((status_reg & FLAG_N) == 0);
1721 case INST_VS:
1722 return ((status_reg & FLAG_V) != 0);
1723 case INST_VC:
1724 return ((status_reg & FLAG_V) == 0);
1725 case INST_HI:
1726 return ((status_reg & (FLAG_C | FLAG_Z)) == FLAG_C);
1727 case INST_LS:
1728 return ((status_reg & (FLAG_C | FLAG_Z)) != FLAG_C);
1729 case INST_GE:
1730 return (((status_reg & FLAG_N) == 0) == ((status_reg & FLAG_V) == 0));
1731 case INST_LT:
1732 return (((status_reg & FLAG_N) == 0) != ((status_reg & FLAG_V) == 0));
1733 case INST_GT:
1734 return (((status_reg & FLAG_Z) == 0) &&
1735 (((status_reg & FLAG_N) == 0) == ((status_reg & FLAG_V) == 0)));
1736 case INST_LE:
1737 return (((status_reg & FLAG_Z) != 0) ||
1738 (((status_reg & FLAG_N) == 0) != ((status_reg & FLAG_V) == 0)));
1739 }
1740 return 1;
1741 }
1742
1743 /* Support routines for single stepping. Calculate the next PC value. */
1744 #define submask(x) ((1L << ((x) + 1)) - 1)
1745 #define bit(obj,st) (((obj) >> (st)) & 1)
1746 #define bits(obj,st,fn) (((obj) >> (st)) & submask ((fn) - (st)))
1747 #define sbits(obj,st,fn) \
1748 ((long) (bits(obj,st,fn) | ((long) bit(obj,fn) * ~ submask (fn - st))))
1749 #define BranchDest(addr,instr) \
1750 ((CORE_ADDR) (((long) (addr)) + 8 + (sbits (instr, 0, 23) << 2)))
1751 #define ARM_PC_32 1
1752
1753 static unsigned long
1754 shifted_reg_val (unsigned long inst, int carry, unsigned long pc_val,
1755 unsigned long status_reg)
1756 {
1757 unsigned long res, shift;
1758 int rm = bits (inst, 0, 3);
1759 unsigned long shifttype = bits (inst, 5, 6);
1760
1761 if (bit (inst, 4))
1762 {
1763 int rs = bits (inst, 8, 11);
1764 shift = (rs == 15 ? pc_val + 8 : read_register (rs)) & 0xFF;
1765 }
1766 else
1767 shift = bits (inst, 7, 11);
1768
1769 res = (rm == 15
1770 ? ((pc_val | (ARM_PC_32 ? 0 : status_reg))
1771 + (bit (inst, 4) ? 12 : 8))
1772 : read_register (rm));
1773
1774 switch (shifttype)
1775 {
1776 case 0: /* LSL */
1777 res = shift >= 32 ? 0 : res << shift;
1778 break;
1779
1780 case 1: /* LSR */
1781 res = shift >= 32 ? 0 : res >> shift;
1782 break;
1783
1784 case 2: /* ASR */
1785 if (shift >= 32)
1786 shift = 31;
1787 res = ((res & 0x80000000L)
1788 ? ~((~res) >> shift) : res >> shift);
1789 break;
1790
1791 case 3: /* ROR/RRX */
1792 shift &= 31;
1793 if (shift == 0)
1794 res = (res >> 1) | (carry ? 0x80000000L : 0);
1795 else
1796 res = (res >> shift) | (res << (32 - shift));
1797 break;
1798 }
1799
1800 return res & 0xffffffff;
1801 }
1802
1803 /* Return number of 1-bits in VAL. */
1804
1805 static int
1806 bitcount (unsigned long val)
1807 {
1808 int nbits;
1809 for (nbits = 0; val != 0; nbits++)
1810 val &= val - 1; /* delete rightmost 1-bit in val */
1811 return nbits;
1812 }
1813
1814 CORE_ADDR
1815 thumb_get_next_pc (CORE_ADDR pc)
1816 {
1817 unsigned long pc_val = ((unsigned long) pc) + 4; /* PC after prefetch */
1818 unsigned short inst1 = read_memory_integer (pc, 2);
1819 CORE_ADDR nextpc = pc + 2; /* default is next instruction */
1820 unsigned long offset;
1821
1822 if ((inst1 & 0xff00) == 0xbd00) /* pop {rlist, pc} */
1823 {
1824 CORE_ADDR sp;
1825
1826 /* Fetch the saved PC from the stack. It's stored above
1827 all of the other registers. */
1828 offset = bitcount (bits (inst1, 0, 7)) * DEPRECATED_REGISTER_SIZE;
1829 sp = read_register (ARM_SP_REGNUM);
1830 nextpc = (CORE_ADDR) read_memory_integer (sp + offset, 4);
1831 nextpc = ADDR_BITS_REMOVE (nextpc);
1832 if (nextpc == pc)
1833 error ("Infinite loop detected");
1834 }
1835 else if ((inst1 & 0xf000) == 0xd000) /* conditional branch */
1836 {
1837 unsigned long status = read_register (ARM_PS_REGNUM);
1838 unsigned long cond = bits (inst1, 8, 11);
1839 if (cond != 0x0f && condition_true (cond, status)) /* 0x0f = SWI */
1840 nextpc = pc_val + (sbits (inst1, 0, 7) << 1);
1841 }
1842 else if ((inst1 & 0xf800) == 0xe000) /* unconditional branch */
1843 {
1844 nextpc = pc_val + (sbits (inst1, 0, 10) << 1);
1845 }
1846 else if ((inst1 & 0xf800) == 0xf000) /* long branch with link */
1847 {
1848 unsigned short inst2 = read_memory_integer (pc + 2, 2);
1849 offset = (sbits (inst1, 0, 10) << 12) + (bits (inst2, 0, 10) << 1);
1850 nextpc = pc_val + offset;
1851 }
1852
1853 return nextpc;
1854 }
1855
1856 CORE_ADDR
1857 arm_get_next_pc (CORE_ADDR pc)
1858 {
1859 unsigned long pc_val;
1860 unsigned long this_instr;
1861 unsigned long status;
1862 CORE_ADDR nextpc;
1863
1864 if (arm_pc_is_thumb (pc))
1865 return thumb_get_next_pc (pc);
1866
1867 pc_val = (unsigned long) pc;
1868 this_instr = read_memory_integer (pc, 4);
1869 status = read_register (ARM_PS_REGNUM);
1870 nextpc = (CORE_ADDR) (pc_val + 4); /* Default case */
1871
1872 if (condition_true (bits (this_instr, 28, 31), status))
1873 {
1874 switch (bits (this_instr, 24, 27))
1875 {
1876 case 0x0:
1877 case 0x1: /* data processing */
1878 case 0x2:
1879 case 0x3:
1880 {
1881 unsigned long operand1, operand2, result = 0;
1882 unsigned long rn;
1883 int c;
1884
1885 if (bits (this_instr, 12, 15) != 15)
1886 break;
1887
1888 if (bits (this_instr, 22, 25) == 0
1889 && bits (this_instr, 4, 7) == 9) /* multiply */
1890 error ("Illegal update to pc in instruction");
1891
1892 /* Multiply into PC */
1893 c = (status & FLAG_C) ? 1 : 0;
1894 rn = bits (this_instr, 16, 19);
1895 operand1 = (rn == 15) ? pc_val + 8 : read_register (rn);
1896
1897 if (bit (this_instr, 25))
1898 {
1899 unsigned long immval = bits (this_instr, 0, 7);
1900 unsigned long rotate = 2 * bits (this_instr, 8, 11);
1901 operand2 = ((immval >> rotate) | (immval << (32 - rotate)))
1902 & 0xffffffff;
1903 }
1904 else /* operand 2 is a shifted register */
1905 operand2 = shifted_reg_val (this_instr, c, pc_val, status);
1906
1907 switch (bits (this_instr, 21, 24))
1908 {
1909 case 0x0: /*and */
1910 result = operand1 & operand2;
1911 break;
1912
1913 case 0x1: /*eor */
1914 result = operand1 ^ operand2;
1915 break;
1916
1917 case 0x2: /*sub */
1918 result = operand1 - operand2;
1919 break;
1920
1921 case 0x3: /*rsb */
1922 result = operand2 - operand1;
1923 break;
1924
1925 case 0x4: /*add */
1926 result = operand1 + operand2;
1927 break;
1928
1929 case 0x5: /*adc */
1930 result = operand1 + operand2 + c;
1931 break;
1932
1933 case 0x6: /*sbc */
1934 result = operand1 - operand2 + c;
1935 break;
1936
1937 case 0x7: /*rsc */
1938 result = operand2 - operand1 + c;
1939 break;
1940
1941 case 0x8:
1942 case 0x9:
1943 case 0xa:
1944 case 0xb: /* tst, teq, cmp, cmn */
1945 result = (unsigned long) nextpc;
1946 break;
1947
1948 case 0xc: /*orr */
1949 result = operand1 | operand2;
1950 break;
1951
1952 case 0xd: /*mov */
1953 /* Always step into a function. */
1954 result = operand2;
1955 break;
1956
1957 case 0xe: /*bic */
1958 result = operand1 & ~operand2;
1959 break;
1960
1961 case 0xf: /*mvn */
1962 result = ~operand2;
1963 break;
1964 }
1965 nextpc = (CORE_ADDR) ADDR_BITS_REMOVE (result);
1966
1967 if (nextpc == pc)
1968 error ("Infinite loop detected");
1969 break;
1970 }
1971
1972 case 0x4:
1973 case 0x5: /* data transfer */
1974 case 0x6:
1975 case 0x7:
1976 if (bit (this_instr, 20))
1977 {
1978 /* load */
1979 if (bits (this_instr, 12, 15) == 15)
1980 {
1981 /* rd == pc */
1982 unsigned long rn;
1983 unsigned long base;
1984
1985 if (bit (this_instr, 22))
1986 error ("Illegal update to pc in instruction");
1987
1988 /* byte write to PC */
1989 rn = bits (this_instr, 16, 19);
1990 base = (rn == 15) ? pc_val + 8 : read_register (rn);
1991 if (bit (this_instr, 24))
1992 {
1993 /* pre-indexed */
1994 int c = (status & FLAG_C) ? 1 : 0;
1995 unsigned long offset =
1996 (bit (this_instr, 25)
1997 ? shifted_reg_val (this_instr, c, pc_val, status)
1998 : bits (this_instr, 0, 11));
1999
2000 if (bit (this_instr, 23))
2001 base += offset;
2002 else
2003 base -= offset;
2004 }
2005 nextpc = (CORE_ADDR) read_memory_integer ((CORE_ADDR) base,
2006 4);
2007
2008 nextpc = ADDR_BITS_REMOVE (nextpc);
2009
2010 if (nextpc == pc)
2011 error ("Infinite loop detected");
2012 }
2013 }
2014 break;
2015
2016 case 0x8:
2017 case 0x9: /* block transfer */
2018 if (bit (this_instr, 20))
2019 {
2020 /* LDM */
2021 if (bit (this_instr, 15))
2022 {
2023 /* loading pc */
2024 int offset = 0;
2025
2026 if (bit (this_instr, 23))
2027 {
2028 /* up */
2029 unsigned long reglist = bits (this_instr, 0, 14);
2030 offset = bitcount (reglist) * 4;
2031 if (bit (this_instr, 24)) /* pre */
2032 offset += 4;
2033 }
2034 else if (bit (this_instr, 24))
2035 offset = -4;
2036
2037 {
2038 unsigned long rn_val =
2039 read_register (bits (this_instr, 16, 19));
2040 nextpc =
2041 (CORE_ADDR) read_memory_integer ((CORE_ADDR) (rn_val
2042 + offset),
2043 4);
2044 }
2045 nextpc = ADDR_BITS_REMOVE (nextpc);
2046 if (nextpc == pc)
2047 error ("Infinite loop detected");
2048 }
2049 }
2050 break;
2051
2052 case 0xb: /* branch & link */
2053 case 0xa: /* branch */
2054 {
2055 nextpc = BranchDest (pc, this_instr);
2056
2057 nextpc = ADDR_BITS_REMOVE (nextpc);
2058 if (nextpc == pc)
2059 error ("Infinite loop detected");
2060 break;
2061 }
2062
2063 case 0xc:
2064 case 0xd:
2065 case 0xe: /* coproc ops */
2066 case 0xf: /* SWI */
2067 break;
2068
2069 default:
2070 fprintf_filtered (gdb_stderr, "Bad bit-field extraction\n");
2071 return (pc);
2072 }
2073 }
2074
2075 return nextpc;
2076 }
2077
2078 /* single_step() is called just before we want to resume the inferior,
2079 if we want to single-step it but there is no hardware or kernel
2080 single-step support. We find the target of the coming instruction
2081 and breakpoint it.
2082
2083 single_step() is also called just after the inferior stops. If we
2084 had set up a simulated single-step, we undo our damage. */
2085
2086 static void
2087 arm_software_single_step (enum target_signal sig, int insert_bpt)
2088 {
2089 static int next_pc; /* State between setting and unsetting. */
2090 static char break_mem[BREAKPOINT_MAX]; /* Temporary storage for mem@bpt */
2091
2092 if (insert_bpt)
2093 {
2094 next_pc = arm_get_next_pc (read_register (ARM_PC_REGNUM));
2095 target_insert_breakpoint (next_pc, break_mem);
2096 }
2097 else
2098 target_remove_breakpoint (next_pc, break_mem);
2099 }
2100
2101 #include "bfd-in2.h"
2102 #include "libcoff.h"
2103
2104 static int
2105 gdb_print_insn_arm (bfd_vma memaddr, disassemble_info *info)
2106 {
2107 if (arm_pc_is_thumb (memaddr))
2108 {
2109 static asymbol *asym;
2110 static combined_entry_type ce;
2111 static struct coff_symbol_struct csym;
2112 static struct bfd fake_bfd;
2113 static bfd_target fake_target;
2114
2115 if (csym.native == NULL)
2116 {
2117 /* Create a fake symbol vector containing a Thumb symbol.
2118 This is solely so that the code in print_insn_little_arm()
2119 and print_insn_big_arm() in opcodes/arm-dis.c will detect
2120 the presence of a Thumb symbol and switch to decoding
2121 Thumb instructions. */
2122
2123 fake_target.flavour = bfd_target_coff_flavour;
2124 fake_bfd.xvec = &fake_target;
2125 ce.u.syment.n_sclass = C_THUMBEXTFUNC;
2126 csym.native = &ce;
2127 csym.symbol.the_bfd = &fake_bfd;
2128 csym.symbol.name = "fake";
2129 asym = (asymbol *) & csym;
2130 }
2131
2132 memaddr = UNMAKE_THUMB_ADDR (memaddr);
2133 info->symbols = &asym;
2134 }
2135 else
2136 info->symbols = NULL;
2137
2138 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
2139 return print_insn_big_arm (memaddr, info);
2140 else
2141 return print_insn_little_arm (memaddr, info);
2142 }
2143
2144 /* The following define instruction sequences that will cause ARM
2145 cpu's to take an undefined instruction trap. These are used to
2146 signal a breakpoint to GDB.
2147
2148 The newer ARMv4T cpu's are capable of operating in ARM or Thumb
2149 modes. A different instruction is required for each mode. The ARM
2150 cpu's can also be big or little endian. Thus four different
2151 instructions are needed to support all cases.
2152
2153 Note: ARMv4 defines several new instructions that will take the
2154 undefined instruction trap. ARM7TDMI is nominally ARMv4T, but does
2155 not in fact add the new instructions. The new undefined
2156 instructions in ARMv4 are all instructions that had no defined
2157 behaviour in earlier chips. There is no guarantee that they will
2158 raise an exception, but may be treated as NOP's. In practice, it
2159 may only safe to rely on instructions matching:
2160
2161 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
2162 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
2163 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
2164
2165 Even this may only true if the condition predicate is true. The
2166 following use a condition predicate of ALWAYS so it is always TRUE.
2167
2168 There are other ways of forcing a breakpoint. GNU/Linux, RISC iX,
2169 and NetBSD all use a software interrupt rather than an undefined
2170 instruction to force a trap. This can be handled by by the
2171 abi-specific code during establishment of the gdbarch vector. */
2172
2173
2174 /* NOTE rearnsha 2002-02-18: for now we allow a non-multi-arch gdb to
2175 override these definitions. */
2176 #ifndef ARM_LE_BREAKPOINT
2177 #define ARM_LE_BREAKPOINT {0xFE,0xDE,0xFF,0xE7}
2178 #endif
2179 #ifndef ARM_BE_BREAKPOINT
2180 #define ARM_BE_BREAKPOINT {0xE7,0xFF,0xDE,0xFE}
2181 #endif
2182 #ifndef THUMB_LE_BREAKPOINT
2183 #define THUMB_LE_BREAKPOINT {0xfe,0xdf}
2184 #endif
2185 #ifndef THUMB_BE_BREAKPOINT
2186 #define THUMB_BE_BREAKPOINT {0xdf,0xfe}
2187 #endif
2188
2189 static const char arm_default_arm_le_breakpoint[] = ARM_LE_BREAKPOINT;
2190 static const char arm_default_arm_be_breakpoint[] = ARM_BE_BREAKPOINT;
2191 static const char arm_default_thumb_le_breakpoint[] = THUMB_LE_BREAKPOINT;
2192 static const char arm_default_thumb_be_breakpoint[] = THUMB_BE_BREAKPOINT;
2193
2194 /* Determine the type and size of breakpoint to insert at PCPTR. Uses
2195 the program counter value to determine whether a 16-bit or 32-bit
2196 breakpoint should be used. It returns a pointer to a string of
2197 bytes that encode a breakpoint instruction, stores the length of
2198 the string to *lenptr, and adjusts the program counter (if
2199 necessary) to point to the actual memory location where the
2200 breakpoint should be inserted. */
2201
2202 /* XXX ??? from old tm-arm.h: if we're using RDP, then we're inserting
2203 breakpoints and storing their handles instread of what was in
2204 memory. It is nice that this is the same size as a handle -
2205 otherwise remote-rdp will have to change. */
2206
2207 static const unsigned char *
2208 arm_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
2209 {
2210 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2211
2212 if (arm_pc_is_thumb (*pcptr) || arm_pc_is_thumb_dummy (*pcptr))
2213 {
2214 *pcptr = UNMAKE_THUMB_ADDR (*pcptr);
2215 *lenptr = tdep->thumb_breakpoint_size;
2216 return tdep->thumb_breakpoint;
2217 }
2218 else
2219 {
2220 *lenptr = tdep->arm_breakpoint_size;
2221 return tdep->arm_breakpoint;
2222 }
2223 }
2224
2225 /* Extract from an array REGBUF containing the (raw) register state a
2226 function return value of type TYPE, and copy that, in virtual
2227 format, into VALBUF. */
2228
2229 static void
2230 arm_extract_return_value (struct type *type,
2231 struct regcache *regs,
2232 void *dst)
2233 {
2234 bfd_byte *valbuf = dst;
2235
2236 if (TYPE_CODE_FLT == TYPE_CODE (type))
2237 {
2238 switch (arm_get_fp_model (current_gdbarch))
2239 {
2240 case ARM_FLOAT_FPA:
2241 {
2242 /* The value is in register F0 in internal format. We need to
2243 extract the raw value and then convert it to the desired
2244 internal type. */
2245 bfd_byte tmpbuf[FP_REGISTER_RAW_SIZE];
2246
2247 regcache_cooked_read (regs, ARM_F0_REGNUM, tmpbuf);
2248 convert_from_extended (floatformat_from_type (type), tmpbuf,
2249 valbuf);
2250 }
2251 break;
2252
2253 case ARM_FLOAT_SOFT_FPA:
2254 case ARM_FLOAT_SOFT_VFP:
2255 regcache_cooked_read (regs, ARM_A1_REGNUM, valbuf);
2256 if (TYPE_LENGTH (type) > 4)
2257 regcache_cooked_read (regs, ARM_A1_REGNUM + 1,
2258 valbuf + INT_REGISTER_RAW_SIZE);
2259 break;
2260
2261 default:
2262 internal_error
2263 (__FILE__, __LINE__,
2264 "arm_extract_return_value: Floating point model not supported");
2265 break;
2266 }
2267 }
2268 else if (TYPE_CODE (type) == TYPE_CODE_INT
2269 || TYPE_CODE (type) == TYPE_CODE_CHAR
2270 || TYPE_CODE (type) == TYPE_CODE_BOOL
2271 || TYPE_CODE (type) == TYPE_CODE_PTR
2272 || TYPE_CODE (type) == TYPE_CODE_REF
2273 || TYPE_CODE (type) == TYPE_CODE_ENUM)
2274 {
2275 /* If the the type is a plain integer, then the access is
2276 straight-forward. Otherwise we have to play around a bit more. */
2277 int len = TYPE_LENGTH (type);
2278 int regno = ARM_A1_REGNUM;
2279 ULONGEST tmp;
2280
2281 while (len > 0)
2282 {
2283 /* By using store_unsigned_integer we avoid having to do
2284 anything special for small big-endian values. */
2285 regcache_cooked_read_unsigned (regs, regno++, &tmp);
2286 store_unsigned_integer (valbuf,
2287 (len > INT_REGISTER_RAW_SIZE
2288 ? INT_REGISTER_RAW_SIZE : len),
2289 tmp);
2290 len -= INT_REGISTER_RAW_SIZE;
2291 valbuf += INT_REGISTER_RAW_SIZE;
2292 }
2293 }
2294 else
2295 {
2296 /* For a structure or union the behaviour is as if the value had
2297 been stored to word-aligned memory and then loaded into
2298 registers with 32-bit load instruction(s). */
2299 int len = TYPE_LENGTH (type);
2300 int regno = ARM_A1_REGNUM;
2301 bfd_byte tmpbuf[INT_REGISTER_RAW_SIZE];
2302
2303 while (len > 0)
2304 {
2305 regcache_cooked_read (regs, regno++, tmpbuf);
2306 memcpy (valbuf, tmpbuf,
2307 len > INT_REGISTER_RAW_SIZE ? INT_REGISTER_RAW_SIZE : len);
2308 len -= INT_REGISTER_RAW_SIZE;
2309 valbuf += INT_REGISTER_RAW_SIZE;
2310 }
2311 }
2312 }
2313
2314 /* Extract from an array REGBUF containing the (raw) register state
2315 the address in which a function should return its structure value. */
2316
2317 static CORE_ADDR
2318 arm_extract_struct_value_address (struct regcache *regcache)
2319 {
2320 ULONGEST ret;
2321
2322 regcache_cooked_read_unsigned (regcache, ARM_A1_REGNUM, &ret);
2323 return ret;
2324 }
2325
2326 /* Will a function return an aggregate type in memory or in a
2327 register? Return 0 if an aggregate type can be returned in a
2328 register, 1 if it must be returned in memory. */
2329
2330 static int
2331 arm_use_struct_convention (int gcc_p, struct type *type)
2332 {
2333 int nRc;
2334 register enum type_code code;
2335
2336 /* In the ARM ABI, "integer" like aggregate types are returned in
2337 registers. For an aggregate type to be integer like, its size
2338 must be less than or equal to DEPRECATED_REGISTER_SIZE and the
2339 offset of each addressable subfield must be zero. Note that bit
2340 fields are not addressable, and all addressable subfields of
2341 unions always start at offset zero.
2342
2343 This function is based on the behaviour of GCC 2.95.1.
2344 See: gcc/arm.c: arm_return_in_memory() for details.
2345
2346 Note: All versions of GCC before GCC 2.95.2 do not set up the
2347 parameters correctly for a function returning the following
2348 structure: struct { float f;}; This should be returned in memory,
2349 not a register. Richard Earnshaw sent me a patch, but I do not
2350 know of any way to detect if a function like the above has been
2351 compiled with the correct calling convention. */
2352
2353 /* All aggregate types that won't fit in a register must be returned
2354 in memory. */
2355 if (TYPE_LENGTH (type) > DEPRECATED_REGISTER_SIZE)
2356 {
2357 return 1;
2358 }
2359
2360 /* The only aggregate types that can be returned in a register are
2361 structs and unions. Arrays must be returned in memory. */
2362 code = TYPE_CODE (type);
2363 if ((TYPE_CODE_STRUCT != code) && (TYPE_CODE_UNION != code))
2364 {
2365 return 1;
2366 }
2367
2368 /* Assume all other aggregate types can be returned in a register.
2369 Run a check for structures, unions and arrays. */
2370 nRc = 0;
2371
2372 if ((TYPE_CODE_STRUCT == code) || (TYPE_CODE_UNION == code))
2373 {
2374 int i;
2375 /* Need to check if this struct/union is "integer" like. For
2376 this to be true, its size must be less than or equal to
2377 DEPRECATED_REGISTER_SIZE and the offset of each addressable
2378 subfield must be zero. Note that bit fields are not
2379 addressable, and unions always start at offset zero. If any
2380 of the subfields is a floating point type, the struct/union
2381 cannot be an integer type. */
2382
2383 /* For each field in the object, check:
2384 1) Is it FP? --> yes, nRc = 1;
2385 2) Is it addressable (bitpos != 0) and
2386 not packed (bitsize == 0)?
2387 --> yes, nRc = 1
2388 */
2389
2390 for (i = 0; i < TYPE_NFIELDS (type); i++)
2391 {
2392 enum type_code field_type_code;
2393 field_type_code = TYPE_CODE (TYPE_FIELD_TYPE (type, i));
2394
2395 /* Is it a floating point type field? */
2396 if (field_type_code == TYPE_CODE_FLT)
2397 {
2398 nRc = 1;
2399 break;
2400 }
2401
2402 /* If bitpos != 0, then we have to care about it. */
2403 if (TYPE_FIELD_BITPOS (type, i) != 0)
2404 {
2405 /* Bitfields are not addressable. If the field bitsize is
2406 zero, then the field is not packed. Hence it cannot be
2407 a bitfield or any other packed type. */
2408 if (TYPE_FIELD_BITSIZE (type, i) == 0)
2409 {
2410 nRc = 1;
2411 break;
2412 }
2413 }
2414 }
2415 }
2416
2417 return nRc;
2418 }
2419
2420 /* Write into appropriate registers a function return value of type
2421 TYPE, given in virtual format. */
2422
2423 static void
2424 arm_store_return_value (struct type *type, struct regcache *regs,
2425 const void *src)
2426 {
2427 const bfd_byte *valbuf = src;
2428
2429 if (TYPE_CODE (type) == TYPE_CODE_FLT)
2430 {
2431 char buf[ARM_MAX_REGISTER_RAW_SIZE];
2432
2433 switch (arm_get_fp_model (current_gdbarch))
2434 {
2435 case ARM_FLOAT_FPA:
2436
2437 convert_to_extended (floatformat_from_type (type), buf, valbuf);
2438 regcache_cooked_write (regs, ARM_F0_REGNUM, buf);
2439 break;
2440
2441 case ARM_FLOAT_SOFT_FPA:
2442 case ARM_FLOAT_SOFT_VFP:
2443 regcache_cooked_write (regs, ARM_A1_REGNUM, valbuf);
2444 if (TYPE_LENGTH (type) > 4)
2445 regcache_cooked_write (regs, ARM_A1_REGNUM + 1,
2446 valbuf + INT_REGISTER_RAW_SIZE);
2447 break;
2448
2449 default:
2450 internal_error
2451 (__FILE__, __LINE__,
2452 "arm_store_return_value: Floating point model not supported");
2453 break;
2454 }
2455 }
2456 else if (TYPE_CODE (type) == TYPE_CODE_INT
2457 || TYPE_CODE (type) == TYPE_CODE_CHAR
2458 || TYPE_CODE (type) == TYPE_CODE_BOOL
2459 || TYPE_CODE (type) == TYPE_CODE_PTR
2460 || TYPE_CODE (type) == TYPE_CODE_REF
2461 || TYPE_CODE (type) == TYPE_CODE_ENUM)
2462 {
2463 if (TYPE_LENGTH (type) <= 4)
2464 {
2465 /* Values of one word or less are zero/sign-extended and
2466 returned in r0. */
2467 bfd_byte tmpbuf[INT_REGISTER_RAW_SIZE];
2468 LONGEST val = unpack_long (type, valbuf);
2469
2470 store_signed_integer (tmpbuf, INT_REGISTER_RAW_SIZE, val);
2471 regcache_cooked_write (regs, ARM_A1_REGNUM, tmpbuf);
2472 }
2473 else
2474 {
2475 /* Integral values greater than one word are stored in consecutive
2476 registers starting with r0. This will always be a multiple of
2477 the regiser size. */
2478 int len = TYPE_LENGTH (type);
2479 int regno = ARM_A1_REGNUM;
2480
2481 while (len > 0)
2482 {
2483 regcache_cooked_write (regs, regno++, valbuf);
2484 len -= INT_REGISTER_RAW_SIZE;
2485 valbuf += INT_REGISTER_RAW_SIZE;
2486 }
2487 }
2488 }
2489 else
2490 {
2491 /* For a structure or union the behaviour is as if the value had
2492 been stored to word-aligned memory and then loaded into
2493 registers with 32-bit load instruction(s). */
2494 int len = TYPE_LENGTH (type);
2495 int regno = ARM_A1_REGNUM;
2496 bfd_byte tmpbuf[INT_REGISTER_RAW_SIZE];
2497
2498 while (len > 0)
2499 {
2500 memcpy (tmpbuf, valbuf,
2501 len > INT_REGISTER_RAW_SIZE ? INT_REGISTER_RAW_SIZE : len);
2502 regcache_cooked_write (regs, regno++, tmpbuf);
2503 len -= INT_REGISTER_RAW_SIZE;
2504 valbuf += INT_REGISTER_RAW_SIZE;
2505 }
2506 }
2507 }
2508
2509 static int
2510 arm_get_longjmp_target (CORE_ADDR *pc)
2511 {
2512 CORE_ADDR jb_addr;
2513 char buf[INT_REGISTER_RAW_SIZE];
2514 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2515
2516 jb_addr = read_register (ARM_A1_REGNUM);
2517
2518 if (target_read_memory (jb_addr + tdep->jb_pc * tdep->jb_elt_size, buf,
2519 INT_REGISTER_RAW_SIZE))
2520 return 0;
2521
2522 *pc = extract_unsigned_integer (buf, INT_REGISTER_RAW_SIZE);
2523 return 1;
2524 }
2525
2526 /* Return non-zero if the PC is inside a thumb call thunk. */
2527
2528 int
2529 arm_in_call_stub (CORE_ADDR pc, char *name)
2530 {
2531 CORE_ADDR start_addr;
2532
2533 /* Find the starting address of the function containing the PC. If
2534 the caller didn't give us a name, look it up at the same time. */
2535 if (0 == find_pc_partial_function (pc, name ? NULL : &name,
2536 &start_addr, NULL))
2537 return 0;
2538
2539 return strncmp (name, "_call_via_r", 11) == 0;
2540 }
2541
2542 /* If PC is in a Thumb call or return stub, return the address of the
2543 target PC, which is in a register. The thunk functions are called
2544 _called_via_xx, where x is the register name. The possible names
2545 are r0-r9, sl, fp, ip, sp, and lr. */
2546
2547 CORE_ADDR
2548 arm_skip_stub (CORE_ADDR pc)
2549 {
2550 char *name;
2551 CORE_ADDR start_addr;
2552
2553 /* Find the starting address and name of the function containing the PC. */
2554 if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0)
2555 return 0;
2556
2557 /* Call thunks always start with "_call_via_". */
2558 if (strncmp (name, "_call_via_", 10) == 0)
2559 {
2560 /* Use the name suffix to determine which register contains the
2561 target PC. */
2562 static char *table[15] =
2563 {"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2564 "r8", "r9", "sl", "fp", "ip", "sp", "lr"
2565 };
2566 int regno;
2567
2568 for (regno = 0; regno <= 14; regno++)
2569 if (strcmp (&name[10], table[regno]) == 0)
2570 return read_register (regno);
2571 }
2572
2573 return 0; /* not a stub */
2574 }
2575
2576 static void
2577 set_arm_command (char *args, int from_tty)
2578 {
2579 printf_unfiltered ("\"set arm\" must be followed by an apporpriate subcommand.\n");
2580 help_list (setarmcmdlist, "set arm ", all_commands, gdb_stdout);
2581 }
2582
2583 static void
2584 show_arm_command (char *args, int from_tty)
2585 {
2586 cmd_show_list (showarmcmdlist, from_tty, "");
2587 }
2588
2589 enum arm_float_model
2590 arm_get_fp_model (struct gdbarch *gdbarch)
2591 {
2592 if (arm_fp_model == ARM_FLOAT_AUTO)
2593 return gdbarch_tdep (gdbarch)->fp_model;
2594
2595 return arm_fp_model;
2596 }
2597
2598 static void
2599 arm_set_fp (struct gdbarch *gdbarch)
2600 {
2601 enum arm_float_model fp_model = arm_get_fp_model (gdbarch);
2602
2603 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE
2604 && (fp_model == ARM_FLOAT_SOFT_FPA || fp_model == ARM_FLOAT_FPA))
2605 {
2606 set_gdbarch_double_format (gdbarch,
2607 &floatformat_ieee_double_littlebyte_bigword);
2608 set_gdbarch_long_double_format
2609 (gdbarch, &floatformat_ieee_double_littlebyte_bigword);
2610 }
2611 else
2612 {
2613 set_gdbarch_double_format (gdbarch, &floatformat_ieee_double_little);
2614 set_gdbarch_long_double_format (gdbarch,
2615 &floatformat_ieee_double_little);
2616 }
2617 }
2618
2619 static void
2620 set_fp_model_sfunc (char *args, int from_tty,
2621 struct cmd_list_element *c)
2622 {
2623 enum arm_float_model fp_model;
2624
2625 for (fp_model = ARM_FLOAT_AUTO; fp_model != ARM_FLOAT_LAST; fp_model++)
2626 if (strcmp (current_fp_model, fp_model_strings[fp_model]) == 0)
2627 {
2628 arm_fp_model = fp_model;
2629 break;
2630 }
2631
2632 if (fp_model == ARM_FLOAT_LAST)
2633 internal_error (__FILE__, __LINE__, "Invalid fp model accepted: %s.",
2634 current_fp_model);
2635
2636 if (gdbarch_bfd_arch_info (current_gdbarch)->arch == bfd_arch_arm)
2637 arm_set_fp (current_gdbarch);
2638 }
2639
2640 static void
2641 show_fp_model (char *args, int from_tty,
2642 struct cmd_list_element *c)
2643 {
2644 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2645
2646 if (arm_fp_model == ARM_FLOAT_AUTO
2647 && gdbarch_bfd_arch_info (current_gdbarch)->arch == bfd_arch_arm)
2648 printf_filtered (" - the default for the current ABI is \"%s\".\n",
2649 fp_model_strings[tdep->fp_model]);
2650 }
2651
2652 /* If the user changes the register disassembly style used for info
2653 register and other commands, we have to also switch the style used
2654 in opcodes for disassembly output. This function is run in the "set
2655 arm disassembly" command, and does that. */
2656
2657 static void
2658 set_disassembly_style_sfunc (char *args, int from_tty,
2659 struct cmd_list_element *c)
2660 {
2661 set_disassembly_style ();
2662 }
2663 \f
2664 /* Return the ARM register name corresponding to register I. */
2665 static const char *
2666 arm_register_name (int i)
2667 {
2668 return arm_register_names[i];
2669 }
2670
2671 static void
2672 set_disassembly_style (void)
2673 {
2674 const char *setname, *setdesc, **regnames;
2675 int numregs, j;
2676
2677 /* Find the style that the user wants in the opcodes table. */
2678 int current = 0;
2679 numregs = get_arm_regnames (current, &setname, &setdesc, &regnames);
2680 while ((disassembly_style != setname)
2681 && (current < num_disassembly_options))
2682 get_arm_regnames (++current, &setname, &setdesc, &regnames);
2683 current_option = current;
2684
2685 /* Fill our copy. */
2686 for (j = 0; j < numregs; j++)
2687 arm_register_names[j] = (char *) regnames[j];
2688
2689 /* Adjust case. */
2690 if (isupper (*regnames[ARM_PC_REGNUM]))
2691 {
2692 arm_register_names[ARM_FPS_REGNUM] = "FPS";
2693 arm_register_names[ARM_PS_REGNUM] = "CPSR";
2694 }
2695 else
2696 {
2697 arm_register_names[ARM_FPS_REGNUM] = "fps";
2698 arm_register_names[ARM_PS_REGNUM] = "cpsr";
2699 }
2700
2701 /* Synchronize the disassembler. */
2702 set_arm_regname_option (current);
2703 }
2704
2705 /* arm_othernames implements the "othernames" command. This is deprecated
2706 by the "set arm disassembly" command. */
2707
2708 static void
2709 arm_othernames (char *names, int n)
2710 {
2711 /* Circle through the various flavors. */
2712 current_option = (current_option + 1) % num_disassembly_options;
2713
2714 disassembly_style = valid_disassembly_styles[current_option];
2715 set_disassembly_style ();
2716 }
2717
2718 /* Test whether the coff symbol specific value corresponds to a Thumb
2719 function. */
2720
2721 static int
2722 coff_sym_is_thumb (int val)
2723 {
2724 return (val == C_THUMBEXT ||
2725 val == C_THUMBSTAT ||
2726 val == C_THUMBEXTFUNC ||
2727 val == C_THUMBSTATFUNC ||
2728 val == C_THUMBLABEL);
2729 }
2730
2731 /* arm_coff_make_msymbol_special()
2732 arm_elf_make_msymbol_special()
2733
2734 These functions test whether the COFF or ELF symbol corresponds to
2735 an address in thumb code, and set a "special" bit in a minimal
2736 symbol to indicate that it does. */
2737
2738 static void
2739 arm_elf_make_msymbol_special(asymbol *sym, struct minimal_symbol *msym)
2740 {
2741 /* Thumb symbols are of type STT_LOPROC, (synonymous with
2742 STT_ARM_TFUNC). */
2743 if (ELF_ST_TYPE (((elf_symbol_type *)sym)->internal_elf_sym.st_info)
2744 == STT_LOPROC)
2745 MSYMBOL_SET_SPECIAL (msym);
2746 }
2747
2748 static void
2749 arm_coff_make_msymbol_special(int val, struct minimal_symbol *msym)
2750 {
2751 if (coff_sym_is_thumb (val))
2752 MSYMBOL_SET_SPECIAL (msym);
2753 }
2754
2755 \f
2756 static enum gdb_osabi
2757 arm_elf_osabi_sniffer (bfd *abfd)
2758 {
2759 unsigned int elfosabi, eflags;
2760 enum gdb_osabi osabi = GDB_OSABI_UNKNOWN;
2761
2762 elfosabi = elf_elfheader (abfd)->e_ident[EI_OSABI];
2763
2764 switch (elfosabi)
2765 {
2766 case ELFOSABI_NONE:
2767 /* When elfosabi is ELFOSABI_NONE (0), then the ELF structures in the
2768 file are conforming to the base specification for that machine
2769 (there are no OS-specific extensions). In order to determine the
2770 real OS in use we must look for OS notes that have been added. */
2771 bfd_map_over_sections (abfd,
2772 generic_elf_osabi_sniff_abi_tag_sections,
2773 &osabi);
2774 if (osabi == GDB_OSABI_UNKNOWN)
2775 {
2776 /* Existing ARM tools don't set this field, so look at the EI_FLAGS
2777 field for more information. */
2778 eflags = EF_ARM_EABI_VERSION(elf_elfheader(abfd)->e_flags);
2779 switch (eflags)
2780 {
2781 case EF_ARM_EABI_VER1:
2782 osabi = GDB_OSABI_ARM_EABI_V1;
2783 break;
2784
2785 case EF_ARM_EABI_VER2:
2786 osabi = GDB_OSABI_ARM_EABI_V2;
2787 break;
2788
2789 case EF_ARM_EABI_UNKNOWN:
2790 /* Assume GNU tools. */
2791 osabi = GDB_OSABI_ARM_APCS;
2792 break;
2793
2794 default:
2795 internal_error (__FILE__, __LINE__,
2796 "arm_elf_osabi_sniffer: Unknown ARM EABI "
2797 "version 0x%x", eflags);
2798 }
2799 }
2800 break;
2801
2802 case ELFOSABI_ARM:
2803 /* GNU tools use this value. Check note sections in this case,
2804 as well. */
2805 bfd_map_over_sections (abfd,
2806 generic_elf_osabi_sniff_abi_tag_sections,
2807 &osabi);
2808 if (osabi == GDB_OSABI_UNKNOWN)
2809 {
2810 /* Assume APCS ABI. */
2811 osabi = GDB_OSABI_ARM_APCS;
2812 }
2813 break;
2814
2815 case ELFOSABI_FREEBSD:
2816 osabi = GDB_OSABI_FREEBSD_ELF;
2817 break;
2818
2819 case ELFOSABI_NETBSD:
2820 osabi = GDB_OSABI_NETBSD_ELF;
2821 break;
2822
2823 case ELFOSABI_LINUX:
2824 osabi = GDB_OSABI_LINUX;
2825 break;
2826 }
2827
2828 return osabi;
2829 }
2830
2831 \f
2832 /* Initialize the current architecture based on INFO. If possible,
2833 re-use an architecture from ARCHES, which is a list of
2834 architectures already created during this debugging session.
2835
2836 Called e.g. at program startup, when reading a core file, and when
2837 reading a binary file. */
2838
2839 static struct gdbarch *
2840 arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
2841 {
2842 struct gdbarch_tdep *tdep;
2843 struct gdbarch *gdbarch;
2844
2845 /* Try to deterimine the ABI of the object we are loading. */
2846
2847 if (info.abfd != NULL && info.osabi == GDB_OSABI_UNKNOWN)
2848 {
2849 switch (bfd_get_flavour (info.abfd))
2850 {
2851 case bfd_target_aout_flavour:
2852 /* Assume it's an old APCS-style ABI. */
2853 info.osabi = GDB_OSABI_ARM_APCS;
2854 break;
2855
2856 case bfd_target_coff_flavour:
2857 /* Assume it's an old APCS-style ABI. */
2858 /* XXX WinCE? */
2859 info.osabi = GDB_OSABI_ARM_APCS;
2860 break;
2861
2862 default:
2863 /* Leave it as "unknown". */
2864 break;
2865 }
2866 }
2867
2868 /* If there is already a candidate, use it. */
2869 arches = gdbarch_list_lookup_by_info (arches, &info);
2870 if (arches != NULL)
2871 return arches->gdbarch;
2872
2873 tdep = xmalloc (sizeof (struct gdbarch_tdep));
2874 gdbarch = gdbarch_alloc (&info, tdep);
2875
2876 /* NOTE: cagney/2002-12-06: This can be deleted when this arch is
2877 ready to unwind the PC first (see frame.c:get_prev_frame()). */
2878 set_gdbarch_deprecated_init_frame_pc (gdbarch, init_frame_pc_default);
2879
2880 /* We used to default to FPA for generic ARM, but almost nobody uses that
2881 now, and we now provide a way for the user to force the model. So
2882 default to the most useful variant. */
2883 tdep->fp_model = ARM_FLOAT_SOFT_FPA;
2884
2885 /* Breakpoints. */
2886 switch (info.byte_order)
2887 {
2888 case BFD_ENDIAN_BIG:
2889 tdep->arm_breakpoint = arm_default_arm_be_breakpoint;
2890 tdep->arm_breakpoint_size = sizeof (arm_default_arm_be_breakpoint);
2891 tdep->thumb_breakpoint = arm_default_thumb_be_breakpoint;
2892 tdep->thumb_breakpoint_size = sizeof (arm_default_thumb_be_breakpoint);
2893
2894 break;
2895
2896 case BFD_ENDIAN_LITTLE:
2897 tdep->arm_breakpoint = arm_default_arm_le_breakpoint;
2898 tdep->arm_breakpoint_size = sizeof (arm_default_arm_le_breakpoint);
2899 tdep->thumb_breakpoint = arm_default_thumb_le_breakpoint;
2900 tdep->thumb_breakpoint_size = sizeof (arm_default_thumb_le_breakpoint);
2901
2902 break;
2903
2904 default:
2905 internal_error (__FILE__, __LINE__,
2906 "arm_gdbarch_init: bad byte order for float format");
2907 }
2908
2909 /* On ARM targets char defaults to unsigned. */
2910 set_gdbarch_char_signed (gdbarch, 0);
2911
2912 /* This should be low enough for everything. */
2913 tdep->lowest_pc = 0x20;
2914 tdep->jb_pc = -1; /* Longjump support not enabled by default. */
2915
2916 set_gdbarch_deprecated_call_dummy_words (gdbarch, arm_call_dummy_words);
2917 set_gdbarch_deprecated_sizeof_call_dummy_words (gdbarch, 0);
2918
2919 set_gdbarch_push_dummy_call (gdbarch, arm_push_dummy_call);
2920
2921 /* Frame handling. */
2922 set_gdbarch_deprecated_frame_chain_valid (gdbarch, arm_frame_chain_valid);
2923 set_gdbarch_deprecated_init_extra_frame_info (gdbarch, arm_init_extra_frame_info);
2924 set_gdbarch_deprecated_target_read_fp (gdbarch, arm_read_fp);
2925 set_gdbarch_deprecated_frame_chain (gdbarch, arm_frame_chain);
2926 set_gdbarch_frameless_function_invocation
2927 (gdbarch, arm_frameless_function_invocation);
2928 set_gdbarch_deprecated_frame_saved_pc (gdbarch, arm_frame_saved_pc);
2929 set_gdbarch_frame_args_skip (gdbarch, 0);
2930 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, arm_frame_init_saved_regs);
2931 set_gdbarch_deprecated_pop_frame (gdbarch, arm_pop_frame);
2932
2933 /* Address manipulation. */
2934 set_gdbarch_smash_text_address (gdbarch, arm_smash_text_address);
2935 set_gdbarch_addr_bits_remove (gdbarch, arm_addr_bits_remove);
2936
2937 /* Offset from address of function to start of its code. */
2938 set_gdbarch_function_start_offset (gdbarch, 0);
2939
2940 /* Advance PC across function entry code. */
2941 set_gdbarch_skip_prologue (gdbarch, arm_skip_prologue);
2942
2943 /* Get the PC when a frame might not be available. */
2944 set_gdbarch_deprecated_saved_pc_after_call (gdbarch, arm_saved_pc_after_call);
2945
2946 /* The stack grows downward. */
2947 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
2948
2949 /* Breakpoint manipulation. */
2950 set_gdbarch_breakpoint_from_pc (gdbarch, arm_breakpoint_from_pc);
2951 set_gdbarch_decr_pc_after_break (gdbarch, 0);
2952
2953 /* Information about registers, etc. */
2954 set_gdbarch_print_float_info (gdbarch, arm_print_float_info);
2955 set_gdbarch_deprecated_fp_regnum (gdbarch, ARM_FP_REGNUM); /* ??? */
2956 set_gdbarch_sp_regnum (gdbarch, ARM_SP_REGNUM);
2957 set_gdbarch_pc_regnum (gdbarch, ARM_PC_REGNUM);
2958 set_gdbarch_deprecated_register_byte (gdbarch, arm_register_byte);
2959 set_gdbarch_deprecated_register_bytes (gdbarch,
2960 (NUM_GREGS * INT_REGISTER_RAW_SIZE
2961 + NUM_FREGS * FP_REGISTER_RAW_SIZE
2962 + NUM_SREGS * STATUS_REGISTER_SIZE));
2963 set_gdbarch_num_regs (gdbarch, NUM_GREGS + NUM_FREGS + NUM_SREGS);
2964 set_gdbarch_deprecated_register_raw_size (gdbarch, arm_register_raw_size);
2965 set_gdbarch_deprecated_register_virtual_size (gdbarch, arm_register_virtual_size);
2966 set_gdbarch_deprecated_max_register_raw_size (gdbarch, FP_REGISTER_RAW_SIZE);
2967 set_gdbarch_deprecated_max_register_virtual_size (gdbarch, FP_REGISTER_VIRTUAL_SIZE);
2968 set_gdbarch_deprecated_register_virtual_type (gdbarch, arm_register_type);
2969
2970 /* Internal <-> external register number maps. */
2971 set_gdbarch_register_sim_regno (gdbarch, arm_register_sim_regno);
2972
2973 /* Integer registers are 4 bytes. */
2974 set_gdbarch_deprecated_register_size (gdbarch, 4);
2975 set_gdbarch_register_name (gdbarch, arm_register_name);
2976
2977 /* Returning results. */
2978 set_gdbarch_extract_return_value (gdbarch, arm_extract_return_value);
2979 set_gdbarch_store_return_value (gdbarch, arm_store_return_value);
2980 set_gdbarch_use_struct_convention (gdbarch, arm_use_struct_convention);
2981 set_gdbarch_extract_struct_value_address (gdbarch,
2982 arm_extract_struct_value_address);
2983
2984 /* Single stepping. */
2985 /* XXX For an RDI target we should ask the target if it can single-step. */
2986 set_gdbarch_software_single_step (gdbarch, arm_software_single_step);
2987
2988 /* Disassembly. */
2989 set_gdbarch_print_insn (gdbarch, gdb_print_insn_arm);
2990
2991 /* Minsymbol frobbing. */
2992 set_gdbarch_elf_make_msymbol_special (gdbarch, arm_elf_make_msymbol_special);
2993 set_gdbarch_coff_make_msymbol_special (gdbarch,
2994 arm_coff_make_msymbol_special);
2995
2996 /* Hook in the ABI-specific overrides, if they have been registered. */
2997 gdbarch_init_osabi (info, gdbarch);
2998
2999 /* Now we have tuned the configuration, set a few final things,
3000 based on what the OS ABI has told us. */
3001
3002 if (tdep->jb_pc >= 0)
3003 set_gdbarch_get_longjmp_target (gdbarch, arm_get_longjmp_target);
3004
3005 /* Floating point sizes and format. */
3006 switch (info.byte_order)
3007 {
3008 case BFD_ENDIAN_BIG:
3009 set_gdbarch_float_format (gdbarch, &floatformat_ieee_single_big);
3010 set_gdbarch_double_format (gdbarch, &floatformat_ieee_double_big);
3011 set_gdbarch_long_double_format (gdbarch, &floatformat_ieee_double_big);
3012
3013 break;
3014
3015 case BFD_ENDIAN_LITTLE:
3016 set_gdbarch_float_format (gdbarch, &floatformat_ieee_single_little);
3017 arm_set_fp (gdbarch);
3018 break;
3019
3020 default:
3021 internal_error (__FILE__, __LINE__,
3022 "arm_gdbarch_init: bad byte order for float format");
3023 }
3024
3025 return gdbarch;
3026 }
3027
3028 static void
3029 arm_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
3030 {
3031 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3032
3033 if (tdep == NULL)
3034 return;
3035
3036 fprintf_unfiltered (file, "arm_dump_tdep: Lowest pc = 0x%lx",
3037 (unsigned long) tdep->lowest_pc);
3038 }
3039
3040 static void
3041 arm_init_abi_eabi_v1 (struct gdbarch_info info,
3042 struct gdbarch *gdbarch)
3043 {
3044 /* Place-holder. */
3045 }
3046
3047 static void
3048 arm_init_abi_eabi_v2 (struct gdbarch_info info,
3049 struct gdbarch *gdbarch)
3050 {
3051 /* Place-holder. */
3052 }
3053
3054 static void
3055 arm_init_abi_apcs (struct gdbarch_info info,
3056 struct gdbarch *gdbarch)
3057 {
3058 /* Place-holder. */
3059 }
3060
3061 extern initialize_file_ftype _initialize_arm_tdep; /* -Wmissing-prototypes */
3062
3063 void
3064 _initialize_arm_tdep (void)
3065 {
3066 struct ui_file *stb;
3067 long length;
3068 struct cmd_list_element *new_set, *new_show;
3069 const char *setname;
3070 const char *setdesc;
3071 const char **regnames;
3072 int numregs, i, j;
3073 static char *helptext;
3074
3075 gdbarch_register (bfd_arch_arm, arm_gdbarch_init, arm_dump_tdep);
3076
3077 /* Register an ELF OS ABI sniffer for ARM binaries. */
3078 gdbarch_register_osabi_sniffer (bfd_arch_arm,
3079 bfd_target_elf_flavour,
3080 arm_elf_osabi_sniffer);
3081
3082 /* Register some ABI variants for embedded systems. */
3083 gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_ARM_EABI_V1,
3084 arm_init_abi_eabi_v1);
3085 gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_ARM_EABI_V2,
3086 arm_init_abi_eabi_v2);
3087 gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_ARM_APCS,
3088 arm_init_abi_apcs);
3089
3090 /* Get the number of possible sets of register names defined in opcodes. */
3091 num_disassembly_options = get_arm_regname_num_options ();
3092
3093 /* Add root prefix command for all "set arm"/"show arm" commands. */
3094 add_prefix_cmd ("arm", no_class, set_arm_command,
3095 "Various ARM-specific commands.",
3096 &setarmcmdlist, "set arm ", 0, &setlist);
3097
3098 add_prefix_cmd ("arm", no_class, show_arm_command,
3099 "Various ARM-specific commands.",
3100 &showarmcmdlist, "show arm ", 0, &showlist);
3101
3102 /* Sync the opcode insn printer with our register viewer. */
3103 parse_arm_disassembler_option ("reg-names-std");
3104
3105 /* Begin creating the help text. */
3106 stb = mem_fileopen ();
3107 fprintf_unfiltered (stb, "Set the disassembly style.\n"
3108 "The valid values are:\n");
3109
3110 /* Initialize the array that will be passed to add_set_enum_cmd(). */
3111 valid_disassembly_styles
3112 = xmalloc ((num_disassembly_options + 1) * sizeof (char *));
3113 for (i = 0; i < num_disassembly_options; i++)
3114 {
3115 numregs = get_arm_regnames (i, &setname, &setdesc, &regnames);
3116 valid_disassembly_styles[i] = setname;
3117 fprintf_unfiltered (stb, "%s - %s\n", setname,
3118 setdesc);
3119 /* Copy the default names (if found) and synchronize disassembler. */
3120 if (!strcmp (setname, "std"))
3121 {
3122 disassembly_style = setname;
3123 current_option = i;
3124 for (j = 0; j < numregs; j++)
3125 arm_register_names[j] = (char *) regnames[j];
3126 set_arm_regname_option (i);
3127 }
3128 }
3129 /* Mark the end of valid options. */
3130 valid_disassembly_styles[num_disassembly_options] = NULL;
3131
3132 /* Finish the creation of the help text. */
3133 fprintf_unfiltered (stb, "The default is \"std\".");
3134 helptext = ui_file_xstrdup (stb, &length);
3135 ui_file_delete (stb);
3136
3137 /* Add the deprecated disassembly-flavor command. */
3138 new_set = add_set_enum_cmd ("disassembly-flavor", no_class,
3139 valid_disassembly_styles,
3140 &disassembly_style,
3141 helptext,
3142 &setlist);
3143 set_cmd_sfunc (new_set, set_disassembly_style_sfunc);
3144 deprecate_cmd (new_set, "set arm disassembly");
3145 deprecate_cmd (add_show_from_set (new_set, &showlist),
3146 "show arm disassembly");
3147
3148 /* And now add the new interface. */
3149 new_set = add_set_enum_cmd ("disassembler", no_class,
3150 valid_disassembly_styles, &disassembly_style,
3151 helptext, &setarmcmdlist);
3152
3153 set_cmd_sfunc (new_set, set_disassembly_style_sfunc);
3154 add_show_from_set (new_set, &showarmcmdlist);
3155
3156 add_setshow_cmd_full ("apcs32", no_class,
3157 var_boolean, (char *) &arm_apcs_32,
3158 "Set usage of ARM 32-bit mode.",
3159 "Show usage of ARM 32-bit mode.",
3160 NULL, NULL,
3161 &setlist, &showlist, &new_set, &new_show);
3162 deprecate_cmd (new_set, "set arm apcs32");
3163 deprecate_cmd (new_show, "show arm apcs32");
3164
3165 add_setshow_boolean_cmd ("apcs32", no_class, &arm_apcs_32,
3166 "Set usage of ARM 32-bit mode. "
3167 "When off, a 26-bit PC will be used.",
3168 "Show usage of ARM 32-bit mode. "
3169 "When off, a 26-bit PC will be used.",
3170 NULL, NULL,
3171 &setarmcmdlist, &showarmcmdlist);
3172
3173 /* Add a command to allow the user to force the FPU model. */
3174 new_set = add_set_enum_cmd
3175 ("fpu", no_class, fp_model_strings, &current_fp_model,
3176 "Set the floating point type.\n"
3177 "auto - Determine the FP typefrom the OS-ABI.\n"
3178 "softfpa - Software FP, mixed-endian doubles on little-endian ARMs.\n"
3179 "fpa - FPA co-processor (GCC compiled).\n"
3180 "softvfp - Software FP with pure-endian doubles.\n"
3181 "vfp - VFP co-processor.",
3182 &setarmcmdlist);
3183 set_cmd_sfunc (new_set, set_fp_model_sfunc);
3184 set_cmd_sfunc (add_show_from_set (new_set, &showarmcmdlist), show_fp_model);
3185
3186 /* Add the deprecated "othernames" command. */
3187 deprecate_cmd (add_com ("othernames", class_obscure, arm_othernames,
3188 "Switch to the next set of register names."),
3189 "set arm disassembly");
3190
3191 /* Debugging flag. */
3192 add_setshow_boolean_cmd ("arm", class_maintenance, &arm_debug,
3193 "Set ARM debugging. "
3194 "When on, arm-specific debugging is enabled.",
3195 "Show ARM debugging. "
3196 "When on, arm-specific debugging is enabled.",
3197 NULL, NULL,
3198 &setdebuglist, &showdebuglist);
3199 }
This page took 0.118516 seconds and 4 git commands to generate.