* externalize a function
[binutils-gdb.git] / gdb / arm-tdep.c
bloba4d16329402a3e4da6f78bab309cdbc8aa36f6d6
1 /* Common target dependent code for GDB on ARM systems.
2 Copyright 1988, 1989, 1991, 1992, 1993, 1995, 1996, 1998, 1999, 2000,
3 2001 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #include "defs.h"
23 #include "frame.h"
24 #include "inferior.h"
25 #include "gdbcmd.h"
26 #include "gdbcore.h"
27 #include "symfile.h"
28 #include "gdb_string.h"
29 #include "coff/internal.h" /* Internal format of COFF symbols in BFD */
30 #include "dis-asm.h" /* For register flavors. */
31 #include <ctype.h> /* for isupper () */
32 #include "regcache.h"
34 /* Each OS has a different mechanism for accessing the various
35 registers stored in the sigcontext structure.
37 SIGCONTEXT_REGISTER_ADDRESS should be defined to the name (or
38 function pointer) which may be used to determine the addresses
39 of the various saved registers in the sigcontext structure.
41 For the ARM target, there are three parameters to this function.
42 The first is the pc value of the frame under consideration, the
43 second the stack pointer of this frame, and the last is the
44 register number to fetch.
46 If the tm.h file does not define this macro, then it's assumed that
47 no mechanism is needed and we define SIGCONTEXT_REGISTER_ADDRESS to
48 be 0.
50 When it comes time to multi-arching this code, see the identically
51 named machinery in ia64-tdep.c for an example of how it could be
52 done. It should not be necessary to modify the code below where
53 this macro is used. */
55 #ifdef SIGCONTEXT_REGISTER_ADDRESS
56 #ifndef SIGCONTEXT_REGISTER_ADDRESS_P
57 #define SIGCONTEXT_REGISTER_ADDRESS_P() 1
58 #endif
59 #else
60 #define SIGCONTEXT_REGISTER_ADDRESS(SP,PC,REG) 0
61 #define SIGCONTEXT_REGISTER_ADDRESS_P() 0
62 #endif
64 extern void _initialize_arm_tdep (void);
66 /* Number of different reg name sets (options). */
67 static int num_flavor_options;
69 /* We have more registers than the disassembler as gdb can print the value
70 of special registers as well.
71 The general register names are overwritten by whatever is being used by
72 the disassembler at the moment. We also adjust the case of cpsr and fps. */
74 /* Initial value: Register names used in ARM's ISA documentation. */
75 static char * arm_register_name_strings[] =
76 {"r0", "r1", "r2", "r3", /* 0 1 2 3 */
77 "r4", "r5", "r6", "r7", /* 4 5 6 7 */
78 "r8", "r9", "r10", "r11", /* 8 9 10 11 */
79 "r12", "sp", "lr", "pc", /* 12 13 14 15 */
80 "f0", "f1", "f2", "f3", /* 16 17 18 19 */
81 "f4", "f5", "f6", "f7", /* 20 21 22 23 */
82 "fps", "cpsr" }; /* 24 25 */
83 char **arm_register_names = arm_register_name_strings;
85 /* Valid register name flavors. */
86 static const char **valid_flavors;
88 /* Disassembly flavor to use. Default to "std" register names. */
89 static const char *disassembly_flavor;
90 static int current_option; /* Index to that option in the opcodes table. */
92 /* This is used to keep the bfd arch_info in sync with the disassembly
93 flavor. */
94 static void set_disassembly_flavor_sfunc(char *, int,
95 struct cmd_list_element *);
96 static void set_disassembly_flavor (void);
98 static void convert_from_extended (void *ptr, void *dbl);
100 /* Define other aspects of the stack frame. We keep the offsets of
101 all saved registers, 'cause we need 'em a lot! We also keep the
102 current size of the stack frame, and the offset of the frame
103 pointer from the stack pointer (for frameless functions, and when
104 we're still in the prologue of a function with a frame) */
106 struct frame_extra_info
108 struct frame_saved_regs fsr;
109 int framesize;
110 int frameoffset;
111 int framereg;
114 /* Addresses for calling Thumb functions have the bit 0 set.
115 Here are some macros to test, set, or clear bit 0 of addresses. */
116 #define IS_THUMB_ADDR(addr) ((addr) & 1)
117 #define MAKE_THUMB_ADDR(addr) ((addr) | 1)
118 #define UNMAKE_THUMB_ADDR(addr) ((addr) & ~1)
120 #define SWAP_TARGET_AND_HOST(buffer,len) \
121 do \
123 if (TARGET_BYTE_ORDER != HOST_BYTE_ORDER) \
125 char tmp; \
126 char *p = (char *)(buffer); \
127 char *q = ((char *)(buffer)) + len - 1; \
128 for (; p < q; p++, q--) \
130 tmp = *q; \
131 *q = *p; \
132 *p = tmp; \
136 while (0)
138 /* Will a function return an aggregate type in memory or in a
139 register? Return 0 if an aggregate type can be returned in a
140 register, 1 if it must be returned in memory. */
143 arm_use_struct_convention (int gcc_p, struct type *type)
145 int nRc;
146 register enum type_code code;
148 /* In the ARM ABI, "integer" like aggregate types are returned in
149 registers. For an aggregate type to be integer like, its size
150 must be less than or equal to REGISTER_SIZE and the offset of
151 each addressable subfield must be zero. Note that bit fields are
152 not addressable, and all addressable subfields of unions always
153 start at offset zero.
155 This function is based on the behaviour of GCC 2.95.1.
156 See: gcc/arm.c: arm_return_in_memory() for details.
158 Note: All versions of GCC before GCC 2.95.2 do not set up the
159 parameters correctly for a function returning the following
160 structure: struct { float f;}; This should be returned in memory,
161 not a register. Richard Earnshaw sent me a patch, but I do not
162 know of any way to detect if a function like the above has been
163 compiled with the correct calling convention. */
165 /* All aggregate types that won't fit in a register must be returned
166 in memory. */
167 if (TYPE_LENGTH (type) > REGISTER_SIZE)
169 return 1;
172 /* The only aggregate types that can be returned in a register are
173 structs and unions. Arrays must be returned in memory. */
174 code = TYPE_CODE (type);
175 if ((TYPE_CODE_STRUCT != code) && (TYPE_CODE_UNION != code))
177 return 1;
180 /* Assume all other aggregate types can be returned in a register.
181 Run a check for structures, unions and arrays. */
182 nRc = 0;
184 if ((TYPE_CODE_STRUCT == code) || (TYPE_CODE_UNION == code))
186 int i;
187 /* Need to check if this struct/union is "integer" like. For
188 this to be true, its size must be less than or equal to
189 REGISTER_SIZE and the offset of each addressable subfield
190 must be zero. Note that bit fields are not addressable, and
191 unions always start at offset zero. If any of the subfields
192 is a floating point type, the struct/union cannot be an
193 integer type. */
195 /* For each field in the object, check:
196 1) Is it FP? --> yes, nRc = 1;
197 2) Is it addressable (bitpos != 0) and
198 not packed (bitsize == 0)?
199 --> yes, nRc = 1
202 for (i = 0; i < TYPE_NFIELDS (type); i++)
204 enum type_code field_type_code;
205 field_type_code = TYPE_CODE (TYPE_FIELD_TYPE (type, i));
207 /* Is it a floating point type field? */
208 if (field_type_code == TYPE_CODE_FLT)
210 nRc = 1;
211 break;
214 /* If bitpos != 0, then we have to care about it. */
215 if (TYPE_FIELD_BITPOS (type, i) != 0)
217 /* Bitfields are not addressable. If the field bitsize is
218 zero, then the field is not packed. Hence it cannot be
219 a bitfield or any other packed type. */
220 if (TYPE_FIELD_BITSIZE (type, i) == 0)
222 nRc = 1;
223 break;
229 return nRc;
233 arm_frame_chain_valid (CORE_ADDR chain, struct frame_info *thisframe)
235 return (chain != 0 && (FRAME_SAVED_PC (thisframe) >= LOWEST_PC));
238 /* Set to true if the 32-bit mode is in use. */
240 int arm_apcs_32 = 1;
242 /* Flag set by arm_fix_call_dummy that tells whether the target
243 function is a Thumb function. This flag is checked by
244 arm_push_arguments. FIXME: Change the PUSH_ARGUMENTS macro (and
245 its use in valops.c) to pass the function address as an additional
246 parameter. */
248 static int target_is_thumb;
250 /* Flag set by arm_fix_call_dummy that tells whether the calling
251 function is a Thumb function. This flag is checked by
252 arm_pc_is_thumb and arm_call_dummy_breakpoint_offset. */
254 static int caller_is_thumb;
256 /* Determine if the program counter specified in MEMADDR is in a Thumb
257 function. */
260 arm_pc_is_thumb (CORE_ADDR memaddr)
262 struct minimal_symbol *sym;
264 /* If bit 0 of the address is set, assume this is a Thumb address. */
265 if (IS_THUMB_ADDR (memaddr))
266 return 1;
268 /* Thumb functions have a "special" bit set in minimal symbols. */
269 sym = lookup_minimal_symbol_by_pc (memaddr);
270 if (sym)
272 return (MSYMBOL_IS_SPECIAL (sym));
274 else
276 return 0;
280 /* Determine if the program counter specified in MEMADDR is in a call
281 dummy being called from a Thumb function. */
284 arm_pc_is_thumb_dummy (CORE_ADDR memaddr)
286 CORE_ADDR sp = read_sp ();
288 /* FIXME: Until we switch for the new call dummy macros, this heuristic
289 is the best we can do. We are trying to determine if the pc is on
290 the stack, which (hopefully) will only happen in a call dummy.
291 We hope the current stack pointer is not so far alway from the dummy
292 frame location (true if we have not pushed large data structures or
293 gone too many levels deep) and that our 1024 is not enough to consider
294 code regions as part of the stack (true for most practical purposes) */
295 if (PC_IN_CALL_DUMMY (memaddr, sp, sp + 1024))
296 return caller_is_thumb;
297 else
298 return 0;
301 CORE_ADDR
302 arm_addr_bits_remove (CORE_ADDR val)
304 if (arm_pc_is_thumb (val))
305 return (val & (arm_apcs_32 ? 0xfffffffe : 0x03fffffe));
306 else
307 return (val & (arm_apcs_32 ? 0xfffffffc : 0x03fffffc));
310 CORE_ADDR
311 arm_saved_pc_after_call (struct frame_info *frame)
313 return ADDR_BITS_REMOVE (read_register (LR_REGNUM));
317 arm_frameless_function_invocation (struct frame_info *fi)
319 CORE_ADDR func_start, after_prologue;
320 int frameless;
322 func_start = (get_pc_function_start ((fi)->pc) + FUNCTION_START_OFFSET);
323 after_prologue = SKIP_PROLOGUE (func_start);
325 /* There are some frameless functions whose first two instructions
326 follow the standard APCS form, in which case after_prologue will
327 be func_start + 8. */
329 frameless = (after_prologue < func_start + 12);
330 return frameless;
333 /* A typical Thumb prologue looks like this:
334 push {r7, lr}
335 add sp, sp, #-28
336 add r7, sp, #12
337 Sometimes the latter instruction may be replaced by:
338 mov r7, sp
340 or like this:
341 push {r7, lr}
342 mov r7, sp
343 sub sp, #12
345 or, on tpcs, like this:
346 sub sp,#16
347 push {r7, lr}
348 (many instructions)
349 mov r7, sp
350 sub sp, #12
352 There is always one instruction of three classes:
353 1 - push
354 2 - setting of r7
355 3 - adjusting of sp
357 When we have found at least one of each class we are done with the prolog.
358 Note that the "sub sp, #NN" before the push does not count.
361 static CORE_ADDR
362 thumb_skip_prologue (CORE_ADDR pc, CORE_ADDR func_end)
364 CORE_ADDR current_pc;
365 int findmask = 0; /* findmask:
366 bit 0 - push { rlist }
367 bit 1 - mov r7, sp OR add r7, sp, #imm (setting of r7)
368 bit 2 - sub sp, #simm OR add sp, #simm (adjusting of sp)
371 for (current_pc = pc; current_pc + 2 < func_end && current_pc < pc + 40; current_pc += 2)
373 unsigned short insn = read_memory_unsigned_integer (current_pc, 2);
375 if ((insn & 0xfe00) == 0xb400) /* push { rlist } */
377 findmask |= 1; /* push found */
379 else if ((insn & 0xff00) == 0xb000) /* add sp, #simm OR sub sp, #simm */
381 if ((findmask & 1) == 0) /* before push ? */
382 continue;
383 else
384 findmask |= 4; /* add/sub sp found */
386 else if ((insn & 0xff00) == 0xaf00) /* add r7, sp, #imm */
388 findmask |= 2; /* setting of r7 found */
390 else if (insn == 0x466f) /* mov r7, sp */
392 findmask |= 2; /* setting of r7 found */
394 else
395 continue; /* something in the prolog that we don't care about or some
396 instruction from outside the prolog scheduled here for optimization */
399 return current_pc;
402 /* The APCS (ARM Procedure Call Standard) defines the following
403 prologue:
405 mov ip, sp
406 [stmfd sp!, {a1,a2,a3,a4}]
407 stmfd sp!, {...,fp,ip,lr,pc}
408 [stfe f7, [sp, #-12]!]
409 [stfe f6, [sp, #-12]!]
410 [stfe f5, [sp, #-12]!]
411 [stfe f4, [sp, #-12]!]
412 sub fp, ip, #nn @@ nn == 20 or 4 depending on second insn */
414 CORE_ADDR
415 arm_skip_prologue (CORE_ADDR pc)
417 unsigned long inst;
418 CORE_ADDR skip_pc;
419 CORE_ADDR func_addr, func_end;
420 struct symtab_and_line sal;
422 /* See what the symbol table says. */
424 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
426 sal = find_pc_line (func_addr, 0);
427 if ((sal.line != 0) && (sal.end < func_end))
428 return sal.end;
431 /* Check if this is Thumb code. */
432 if (arm_pc_is_thumb (pc))
433 return thumb_skip_prologue (pc, func_end);
435 /* Can't find the prologue end in the symbol table, try it the hard way
436 by disassembling the instructions. */
437 skip_pc = pc;
438 inst = read_memory_integer (skip_pc, 4);
439 if (inst != 0xe1a0c00d) /* mov ip, sp */
440 return pc;
442 skip_pc += 4;
443 inst = read_memory_integer (skip_pc, 4);
444 if ((inst & 0xfffffff0) == 0xe92d0000) /* stmfd sp!,{a1,a2,a3,a4} */
446 skip_pc += 4;
447 inst = read_memory_integer (skip_pc, 4);
450 if ((inst & 0xfffff800) != 0xe92dd800) /* stmfd sp!,{...,fp,ip,lr,pc} */
451 return pc;
453 skip_pc += 4;
454 inst = read_memory_integer (skip_pc, 4);
456 /* Any insns after this point may float into the code, if it makes
457 for better instruction scheduling, so we skip them only if we
458 find them, but still consdier the function to be frame-ful. */
460 /* We may have either one sfmfd instruction here, or several stfe
461 insns, depending on the version of floating point code we
462 support. */
463 if ((inst & 0xffbf0fff) == 0xec2d0200) /* sfmfd fn, <cnt>, [sp]! */
465 skip_pc += 4;
466 inst = read_memory_integer (skip_pc, 4);
468 else
470 while ((inst & 0xffff8fff) == 0xed6d0103) /* stfe fn, [sp, #-12]! */
472 skip_pc += 4;
473 inst = read_memory_integer (skip_pc, 4);
477 if ((inst & 0xfffff000) == 0xe24cb000) /* sub fp, ip, #nn */
478 skip_pc += 4;
480 return skip_pc;
482 /* *INDENT-OFF* */
483 /* Function: thumb_scan_prologue (helper function for arm_scan_prologue)
484 This function decodes a Thumb function prologue to determine:
485 1) the size of the stack frame
486 2) which registers are saved on it
487 3) the offsets of saved regs
488 4) the offset from the stack pointer to the frame pointer
489 This information is stored in the "extra" fields of the frame_info.
491 A typical Thumb function prologue would create this stack frame
492 (offsets relative to FP)
493 old SP -> 24 stack parameters
494 20 LR
495 16 R7
496 R7 -> 0 local variables (16 bytes)
497 SP -> -12 additional stack space (12 bytes)
498 The frame size would thus be 36 bytes, and the frame offset would be
499 12 bytes. The frame register is R7.
501 The comments for thumb_skip_prolog() describe the algorithm we use to detect
502 the end of the prolog */
503 /* *INDENT-ON* */
505 static void
506 thumb_scan_prologue (struct frame_info *fi)
508 CORE_ADDR prologue_start;
509 CORE_ADDR prologue_end;
510 CORE_ADDR current_pc;
511 int saved_reg[16]; /* which register has been copied to register n? */
512 int findmask = 0; /* findmask:
513 bit 0 - push { rlist }
514 bit 1 - mov r7, sp OR add r7, sp, #imm (setting of r7)
515 bit 2 - sub sp, #simm OR add sp, #simm (adjusting of sp)
517 int i;
519 if (find_pc_partial_function (fi->pc, NULL, &prologue_start, &prologue_end))
521 struct symtab_and_line sal = find_pc_line (prologue_start, 0);
523 if (sal.line == 0) /* no line info, use current PC */
524 prologue_end = fi->pc;
525 else if (sal.end < prologue_end) /* next line begins after fn end */
526 prologue_end = sal.end; /* (probably means no prologue) */
528 else
529 prologue_end = prologue_start + 40; /* We're in the boondocks: allow for */
530 /* 16 pushes, an add, and "mv fp,sp" */
532 prologue_end = min (prologue_end, fi->pc);
534 /* Initialize the saved register map. When register H is copied to
535 register L, we will put H in saved_reg[L]. */
536 for (i = 0; i < 16; i++)
537 saved_reg[i] = i;
539 /* Search the prologue looking for instructions that set up the
540 frame pointer, adjust the stack pointer, and save registers.
541 Do this until all basic prolog instructions are found. */
543 fi->framesize = 0;
544 for (current_pc = prologue_start;
545 (current_pc < prologue_end) && ((findmask & 7) != 7);
546 current_pc += 2)
548 unsigned short insn;
549 int regno;
550 int offset;
552 insn = read_memory_unsigned_integer (current_pc, 2);
554 if ((insn & 0xfe00) == 0xb400) /* push { rlist } */
556 int mask;
557 findmask |= 1; /* push found */
558 /* Bits 0-7 contain a mask for registers R0-R7. Bit 8 says
559 whether to save LR (R14). */
560 mask = (insn & 0xff) | ((insn & 0x100) << 6);
562 /* Calculate offsets of saved R0-R7 and LR. */
563 for (regno = LR_REGNUM; regno >= 0; regno--)
564 if (mask & (1 << regno))
566 fi->framesize += 4;
567 fi->fsr.regs[saved_reg[regno]] = -(fi->framesize);
568 saved_reg[regno] = regno; /* reset saved register map */
571 else if ((insn & 0xff00) == 0xb000) /* add sp, #simm OR sub sp, #simm */
573 if ((findmask & 1) == 0) /* before push ? */
574 continue;
575 else
576 findmask |= 4; /* add/sub sp found */
578 offset = (insn & 0x7f) << 2; /* get scaled offset */
579 if (insn & 0x80) /* is it signed? (==subtracting) */
581 fi->frameoffset += offset;
582 offset = -offset;
584 fi->framesize -= offset;
586 else if ((insn & 0xff00) == 0xaf00) /* add r7, sp, #imm */
588 findmask |= 2; /* setting of r7 found */
589 fi->framereg = THUMB_FP_REGNUM;
590 fi->frameoffset = (insn & 0xff) << 2; /* get scaled offset */
592 else if (insn == 0x466f) /* mov r7, sp */
594 findmask |= 2; /* setting of r7 found */
595 fi->framereg = THUMB_FP_REGNUM;
596 fi->frameoffset = 0;
597 saved_reg[THUMB_FP_REGNUM] = SP_REGNUM;
599 else if ((insn & 0xffc0) == 0x4640) /* mov r0-r7, r8-r15 */
601 int lo_reg = insn & 7; /* dest. register (r0-r7) */
602 int hi_reg = ((insn >> 3) & 7) + 8; /* source register (r8-15) */
603 saved_reg[lo_reg] = hi_reg; /* remember hi reg was saved */
605 else
606 continue; /* something in the prolog that we don't care about or some
607 instruction from outside the prolog scheduled here for optimization */
611 /* Check if prologue for this frame's PC has already been scanned. If
612 it has, copy the relevant information about that prologue and
613 return non-zero. Otherwise do not copy anything and return zero.
615 The information saved in the cache includes:
616 * the frame register number;
617 * the size of the stack frame;
618 * the offsets of saved regs (relative to the old SP); and
619 * the offset from the stack pointer to the frame pointer
621 The cache contains only one entry, since this is adequate for the
622 typical sequence of prologue scan requests we get. When performing
623 a backtrace, GDB will usually ask to scan the same function twice
624 in a row (once to get the frame chain, and once to fill in the
625 extra frame information). */
627 static struct frame_info prologue_cache;
629 static int
630 check_prologue_cache (struct frame_info *fi)
632 int i;
634 if (fi->pc == prologue_cache.pc)
636 fi->framereg = prologue_cache.framereg;
637 fi->framesize = prologue_cache.framesize;
638 fi->frameoffset = prologue_cache.frameoffset;
639 for (i = 0; i < NUM_REGS; i++)
640 fi->fsr.regs[i] = prologue_cache.fsr.regs[i];
641 return 1;
643 else
644 return 0;
648 /* Copy the prologue information from fi to the prologue cache. */
650 static void
651 save_prologue_cache (struct frame_info *fi)
653 int i;
655 prologue_cache.pc = fi->pc;
656 prologue_cache.framereg = fi->framereg;
657 prologue_cache.framesize = fi->framesize;
658 prologue_cache.frameoffset = fi->frameoffset;
660 for (i = 0; i < NUM_REGS; i++)
661 prologue_cache.fsr.regs[i] = fi->fsr.regs[i];
665 /* This function decodes an ARM function prologue to determine:
666 1) the size of the stack frame
667 2) which registers are saved on it
668 3) the offsets of saved regs
669 4) the offset from the stack pointer to the frame pointer
670 This information is stored in the "extra" fields of the frame_info.
672 There are two basic forms for the ARM prologue. The fixed argument
673 function call will look like:
675 mov ip, sp
676 stmfd sp!, {fp, ip, lr, pc}
677 sub fp, ip, #4
678 [sub sp, sp, #4]
680 Which would create this stack frame (offsets relative to FP):
681 IP -> 4 (caller's stack)
682 FP -> 0 PC (points to address of stmfd instruction + 8 in callee)
683 -4 LR (return address in caller)
684 -8 IP (copy of caller's SP)
685 -12 FP (caller's FP)
686 SP -> -28 Local variables
688 The frame size would thus be 32 bytes, and the frame offset would be
689 28 bytes. The stmfd call can also save any of the vN registers it
690 plans to use, which increases the frame size accordingly.
692 Note: The stored PC is 8 off of the STMFD instruction that stored it
693 because the ARM Store instructions always store PC + 8 when you read
694 the PC register.
696 A variable argument function call will look like:
698 mov ip, sp
699 stmfd sp!, {a1, a2, a3, a4}
700 stmfd sp!, {fp, ip, lr, pc}
701 sub fp, ip, #20
703 Which would create this stack frame (offsets relative to FP):
704 IP -> 20 (caller's stack)
705 16 A4
706 12 A3
707 8 A2
708 4 A1
709 FP -> 0 PC (points to address of stmfd instruction + 8 in callee)
710 -4 LR (return address in caller)
711 -8 IP (copy of caller's SP)
712 -12 FP (caller's FP)
713 SP -> -28 Local variables
715 The frame size would thus be 48 bytes, and the frame offset would be
716 28 bytes.
718 There is another potential complication, which is that the optimizer
719 will try to separate the store of fp in the "stmfd" instruction from
720 the "sub fp, ip, #NN" instruction. Almost anything can be there, so
721 we just key on the stmfd, and then scan for the "sub fp, ip, #NN"...
723 Also, note, the original version of the ARM toolchain claimed that there
724 should be an
726 instruction at the end of the prologue. I have never seen GCC produce
727 this, and the ARM docs don't mention it. We still test for it below in
728 case it happens...
732 static void
733 arm_scan_prologue (struct frame_info *fi)
735 int regno, sp_offset, fp_offset;
736 CORE_ADDR prologue_start, prologue_end, current_pc;
738 /* Check if this function is already in the cache of frame information. */
739 if (check_prologue_cache (fi))
740 return;
742 /* Assume there is no frame until proven otherwise. */
743 fi->framereg = SP_REGNUM;
744 fi->framesize = 0;
745 fi->frameoffset = 0;
747 /* Check for Thumb prologue. */
748 if (arm_pc_is_thumb (fi->pc))
750 thumb_scan_prologue (fi);
751 save_prologue_cache (fi);
752 return;
755 /* Find the function prologue. If we can't find the function in
756 the symbol table, peek in the stack frame to find the PC. */
757 if (find_pc_partial_function (fi->pc, NULL, &prologue_start, &prologue_end))
759 /* One way to find the end of the prologue (which works well
760 for unoptimized code) is to do the following:
762 struct symtab_and_line sal = find_pc_line (prologue_start, 0);
764 if (sal.line == 0)
765 prologue_end = fi->pc;
766 else if (sal.end < prologue_end)
767 prologue_end = sal.end;
769 This mechanism is very accurate so long as the optimizer
770 doesn't move any instructions from the function body into the
771 prologue. If this happens, sal.end will be the last
772 instruction in the first hunk of prologue code just before
773 the first instruction that the scheduler has moved from
774 the body to the prologue.
776 In order to make sure that we scan all of the prologue
777 instructions, we use a slightly less accurate mechanism which
778 may scan more than necessary. To help compensate for this
779 lack of accuracy, the prologue scanning loop below contains
780 several clauses which'll cause the loop to terminate early if
781 an implausible prologue instruction is encountered.
783 The expression
785 prologue_start + 64
787 is a suitable endpoint since it accounts for the largest
788 possible prologue plus up to five instructions inserted by
789 the scheduler. */
791 if (prologue_end > prologue_start + 64)
793 prologue_end = prologue_start + 64; /* See above. */
796 else
798 /* Get address of the stmfd in the prologue of the callee; the saved
799 PC is the address of the stmfd + 8. */
800 prologue_start = ADDR_BITS_REMOVE (read_memory_integer (fi->frame, 4))
801 - 8;
802 prologue_end = prologue_start + 64; /* See above. */
805 /* Now search the prologue looking for instructions that set up the
806 frame pointer, adjust the stack pointer, and save registers.
808 Be careful, however, and if it doesn't look like a prologue,
809 don't try to scan it. If, for instance, a frameless function
810 begins with stmfd sp!, then we will tell ourselves there is
811 a frame, which will confuse stack traceback, as well ad"finish"
812 and other operations that rely on a knowledge of the stack
813 traceback.
815 In the APCS, the prologue should start with "mov ip, sp" so
816 if we don't see this as the first insn, we will stop. */
818 sp_offset = fp_offset = 0;
820 if (read_memory_unsigned_integer (prologue_start, 4)
821 == 0xe1a0c00d) /* mov ip, sp */
823 for (current_pc = prologue_start + 4; current_pc < prologue_end;
824 current_pc += 4)
826 unsigned int insn = read_memory_unsigned_integer (current_pc, 4);
828 if ((insn & 0xffff0000) == 0xe92d0000)
829 /* stmfd sp!, {..., fp, ip, lr, pc}
831 stmfd sp!, {a1, a2, a3, a4} */
833 int mask = insn & 0xffff;
835 /* Calculate offsets of saved registers. */
836 for (regno = PC_REGNUM; regno >= 0; regno--)
837 if (mask & (1 << regno))
839 sp_offset -= 4;
840 fi->fsr.regs[regno] = sp_offset;
843 else if ((insn & 0xfffff000) == 0xe24cb000) /* sub fp, ip #n */
845 unsigned imm = insn & 0xff; /* immediate value */
846 unsigned rot = (insn & 0xf00) >> 7; /* rotate amount */
847 imm = (imm >> rot) | (imm << (32 - rot));
848 fp_offset = -imm;
849 fi->framereg = FP_REGNUM;
851 else if ((insn & 0xfffff000) == 0xe24dd000) /* sub sp, sp #n */
853 unsigned imm = insn & 0xff; /* immediate value */
854 unsigned rot = (insn & 0xf00) >> 7; /* rotate amount */
855 imm = (imm >> rot) | (imm << (32 - rot));
856 sp_offset -= imm;
858 else if ((insn & 0xffff7fff) == 0xed6d0103) /* stfe f?, [sp, -#c]! */
860 sp_offset -= 12;
861 regno = F0_REGNUM + ((insn >> 12) & 0x07);
862 fi->fsr.regs[regno] = sp_offset;
864 else if ((insn & 0xffbf0fff) == 0xec2d0200) /* sfmfd f0, 4, [sp!] */
866 int n_saved_fp_regs;
867 unsigned int fp_start_reg, fp_bound_reg;
869 if ((insn & 0x800) == 0x800) /* N0 is set */
871 if ((insn & 0x40000) == 0x40000) /* N1 is set */
872 n_saved_fp_regs = 3;
873 else
874 n_saved_fp_regs = 1;
876 else
878 if ((insn & 0x40000) == 0x40000) /* N1 is set */
879 n_saved_fp_regs = 2;
880 else
881 n_saved_fp_regs = 4;
884 fp_start_reg = F0_REGNUM + ((insn >> 12) & 0x7);
885 fp_bound_reg = fp_start_reg + n_saved_fp_regs;
886 for (; fp_start_reg < fp_bound_reg; fp_start_reg++)
888 sp_offset -= 12;
889 fi->fsr.regs[fp_start_reg++] = sp_offset;
892 else if ((insn & 0xf0000000) != 0xe0000000)
893 break; /* Condition not true, exit early */
894 else if ((insn & 0xfe200000) == 0xe8200000) /* ldm? */
895 break; /* Don't scan past a block load */
896 else
897 /* The optimizer might shove anything into the prologue,
898 so we just skip what we don't recognize. */
899 continue;
903 /* The frame size is just the negative of the offset (from the original SP)
904 of the last thing thing we pushed on the stack. The frame offset is
905 [new FP] - [new SP]. */
906 fi->framesize = -sp_offset;
907 fi->frameoffset = fp_offset - sp_offset;
909 save_prologue_cache (fi);
912 /* Find REGNUM on the stack. Otherwise, it's in an active register.
913 One thing we might want to do here is to check REGNUM against the
914 clobber mask, and somehow flag it as invalid if it isn't saved on
915 the stack somewhere. This would provide a graceful failure mode
916 when trying to get the value of caller-saves registers for an inner
917 frame. */
919 static CORE_ADDR
920 arm_find_callers_reg (struct frame_info *fi, int regnum)
922 for (; fi; fi = fi->next)
924 #if 0 /* FIXME: enable this code if we convert to new call dummy scheme. */
925 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
926 return generic_read_register_dummy (fi->pc, fi->frame, regnum);
927 else
928 #endif
929 if (fi->fsr.regs[regnum] != 0)
930 return read_memory_integer (fi->fsr.regs[regnum],
931 REGISTER_RAW_SIZE (regnum));
932 return read_register (regnum);
934 /* *INDENT-OFF* */
935 /* Function: frame_chain
936 Given a GDB frame, determine the address of the calling function's frame.
937 This will be used to create a new GDB frame struct, and then
938 INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame.
939 For ARM, we save the frame size when we initialize the frame_info.
941 The original definition of this function was a macro in tm-arm.h:
942 { In the case of the ARM, the frame's nominal address is the FP value,
943 and 12 bytes before comes the saved previous FP value as a 4-byte word. }
945 #define FRAME_CHAIN(thisframe) \
946 ((thisframe)->pc >= LOWEST_PC ? \
947 read_memory_integer ((thisframe)->frame - 12, 4) :\
950 /* *INDENT-ON* */
952 CORE_ADDR
953 arm_frame_chain (struct frame_info *fi)
955 #if 0 /* FIXME: enable this code if we convert to new call dummy scheme. */
956 CORE_ADDR fn_start, callers_pc, fp;
958 /* is this a dummy frame? */
959 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
960 return fi->frame; /* dummy frame same as caller's frame */
962 /* is caller-of-this a dummy frame? */
963 callers_pc = FRAME_SAVED_PC (fi); /* find out who called us: */
964 fp = arm_find_callers_reg (fi, FP_REGNUM);
965 if (PC_IN_CALL_DUMMY (callers_pc, fp, fp))
966 return fp; /* dummy frame's frame may bear no relation to ours */
968 if (find_pc_partial_function (fi->pc, 0, &fn_start, 0))
969 if (fn_start == entry_point_address ())
970 return 0; /* in _start fn, don't chain further */
971 #endif
972 CORE_ADDR caller_pc, fn_start;
973 struct frame_info caller_fi;
974 int framereg = fi->framereg;
976 if (fi->pc < LOWEST_PC)
977 return 0;
979 /* If the caller is the startup code, we're at the end of the chain. */
980 caller_pc = FRAME_SAVED_PC (fi);
981 if (find_pc_partial_function (caller_pc, 0, &fn_start, 0))
982 if (fn_start == entry_point_address ())
983 return 0;
985 /* If the caller is Thumb and the caller is ARM, or vice versa,
986 the frame register of the caller is different from ours.
987 So we must scan the prologue of the caller to determine its
988 frame register number. */
989 if (arm_pc_is_thumb (caller_pc) != arm_pc_is_thumb (fi->pc))
991 memset (&caller_fi, 0, sizeof (caller_fi));
992 caller_fi.pc = caller_pc;
993 arm_scan_prologue (&caller_fi);
994 framereg = caller_fi.framereg;
997 /* If the caller used a frame register, return its value.
998 Otherwise, return the caller's stack pointer. */
999 if (framereg == FP_REGNUM || framereg == THUMB_FP_REGNUM)
1000 return arm_find_callers_reg (fi, framereg);
1001 else
1002 return fi->frame + fi->framesize;
1005 /* This function actually figures out the frame address for a given pc
1006 and sp. This is tricky because we sometimes don't use an explicit
1007 frame pointer, and the previous stack pointer isn't necessarily
1008 recorded on the stack. The only reliable way to get this info is
1009 to examine the prologue. FROMLEAF is a little confusing, it means
1010 this is the next frame up the chain AFTER a frameless function. If
1011 this is true, then the frame value for this frame is still in the
1012 fp register. */
1014 void
1015 arm_init_extra_frame_info (int fromleaf, struct frame_info *fi)
1017 int reg;
1019 if (fi->next)
1020 fi->pc = FRAME_SAVED_PC (fi->next);
1022 memset (fi->fsr.regs, '\000', sizeof fi->fsr.regs);
1024 #if 0 /* FIXME: enable this code if we convert to new call dummy scheme. */
1025 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
1027 /* We need to setup fi->frame here because run_stack_dummy gets it wrong
1028 by assuming it's always FP. */
1029 fi->frame = generic_read_register_dummy (fi->pc, fi->frame, SP_REGNUM);
1030 fi->framesize = 0;
1031 fi->frameoffset = 0;
1032 return;
1034 else
1035 #endif
1037 /* Determine whether or not we're in a sigtramp frame.
1038 Unfortunately, it isn't sufficient to test
1039 fi->signal_handler_caller because this value is sometimes set
1040 after invoking INIT_EXTRA_FRAME_INFO. So we test *both*
1041 fi->signal_handler_caller and IN_SIGTRAMP to determine if we need
1042 to use the sigcontext addresses for the saved registers.
1044 Note: If an ARM IN_SIGTRAMP method ever needs to compare against
1045 the name of the function, the code below will have to be changed
1046 to first fetch the name of the function and then pass this name
1047 to IN_SIGTRAMP. */
1049 if (SIGCONTEXT_REGISTER_ADDRESS_P ()
1050 && (fi->signal_handler_caller || IN_SIGTRAMP (fi->pc, 0)))
1052 CORE_ADDR sp;
1054 if (!fi->next)
1055 sp = read_sp();
1056 else
1057 sp = fi->next->frame - fi->next->frameoffset + fi->next->framesize;
1059 for (reg = 0; reg < NUM_REGS; reg++)
1060 fi->fsr.regs[reg] = SIGCONTEXT_REGISTER_ADDRESS (sp, fi->pc, reg);
1062 /* FIXME: What about thumb mode? */
1063 fi->framereg = SP_REGNUM;
1064 fi->frame = read_memory_integer (fi->fsr.regs[fi->framereg], 4);
1065 fi->framesize = 0;
1066 fi->frameoffset = 0;
1069 else
1071 arm_scan_prologue (fi);
1073 if (!fi->next)
1074 /* this is the innermost frame? */
1075 fi->frame = read_register (fi->framereg);
1076 else if (fi->framereg == FP_REGNUM || fi->framereg == THUMB_FP_REGNUM)
1078 /* not the innermost frame */
1079 /* If we have an FP, the callee saved it. */
1080 if (fi->next->fsr.regs[fi->framereg] != 0)
1081 fi->frame =
1082 read_memory_integer (fi->next->fsr.regs[fi->framereg], 4);
1083 else if (fromleaf)
1084 /* If we were called by a frameless fn. then our frame is
1085 still in the frame pointer register on the board... */
1086 fi->frame = read_fp ();
1089 /* Calculate actual addresses of saved registers using offsets
1090 determined by arm_scan_prologue. */
1091 for (reg = 0; reg < NUM_REGS; reg++)
1092 if (fi->fsr.regs[reg] != 0)
1093 fi->fsr.regs[reg] += fi->frame + fi->framesize - fi->frameoffset;
1098 /* Find the caller of this frame. We do this by seeing if LR_REGNUM
1099 is saved in the stack anywhere, otherwise we get it from the
1100 registers.
1102 The old definition of this function was a macro:
1103 #define FRAME_SAVED_PC(FRAME) \
1104 ADDR_BITS_REMOVE (read_memory_integer ((FRAME)->frame - 4, 4)) */
1106 CORE_ADDR
1107 arm_frame_saved_pc (struct frame_info *fi)
1109 #if 0 /* FIXME: enable this code if we convert to new call dummy scheme. */
1110 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
1111 return generic_read_register_dummy (fi->pc, fi->frame, PC_REGNUM);
1112 else
1113 #endif
1115 CORE_ADDR pc = arm_find_callers_reg (fi, LR_REGNUM);
1116 return IS_THUMB_ADDR (pc) ? UNMAKE_THUMB_ADDR (pc) : pc;
1120 /* Return the frame address. On ARM, it is R11; on Thumb it is R7.
1121 Examine the Program Status Register to decide which state we're in. */
1123 CORE_ADDR
1124 arm_target_read_fp (void)
1126 if (read_register (PS_REGNUM) & 0x20) /* Bit 5 is Thumb state bit */
1127 return read_register (THUMB_FP_REGNUM); /* R7 if Thumb */
1128 else
1129 return read_register (FP_REGNUM); /* R11 if ARM */
1132 /* Calculate the frame offsets of the saved registers (ARM version). */
1134 void
1135 arm_frame_find_saved_regs (struct frame_info *fi,
1136 struct frame_saved_regs *regaddr)
1138 memcpy (regaddr, &fi->fsr, sizeof (struct frame_saved_regs));
1141 void
1142 arm_push_dummy_frame (void)
1144 CORE_ADDR old_sp = read_register (SP_REGNUM);
1145 CORE_ADDR sp = old_sp;
1146 CORE_ADDR fp, prologue_start;
1147 int regnum;
1149 /* Push the two dummy prologue instructions in reverse order,
1150 so that they'll be in the correct low-to-high order in memory. */
1151 /* sub fp, ip, #4 */
1152 sp = push_word (sp, 0xe24cb004);
1153 /* stmdb sp!, {r0-r10, fp, ip, lr, pc} */
1154 prologue_start = sp = push_word (sp, 0xe92ddfff);
1156 /* Push a pointer to the dummy prologue + 12, because when stm
1157 instruction stores the PC, it stores the address of the stm
1158 instruction itself plus 12. */
1159 fp = sp = push_word (sp, prologue_start + 12);
1160 sp = push_word (sp, read_register (PC_REGNUM)); /* FIXME: was PS_REGNUM */
1161 sp = push_word (sp, old_sp);
1162 sp = push_word (sp, read_register (FP_REGNUM));
1164 for (regnum = 10; regnum >= 0; regnum--)
1165 sp = push_word (sp, read_register (regnum));
1167 write_register (FP_REGNUM, fp);
1168 write_register (THUMB_FP_REGNUM, fp);
1169 write_register (SP_REGNUM, sp);
1172 /* Fix up the call dummy, based on whether the processor is currently
1173 in Thumb or ARM mode, and whether the target function is Thumb or
1174 ARM. There are three different situations requiring three
1175 different dummies:
1177 * ARM calling ARM: uses the call dummy in tm-arm.h, which has already
1178 been copied into the dummy parameter to this function.
1179 * ARM calling Thumb: uses the call dummy in tm-arm.h, but with the
1180 "mov pc,r4" instruction patched to be a "bx r4" instead.
1181 * Thumb calling anything: uses the Thumb dummy defined below, which
1182 works for calling both ARM and Thumb functions.
1184 All three call dummies expect to receive the target function
1185 address in R4, with the low bit set if it's a Thumb function. */
1187 void
1188 arm_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
1189 value_ptr *args, struct type *type, int gcc_p)
1191 static short thumb_dummy[4] =
1193 0xf000, 0xf801, /* bl label */
1194 0xdf18, /* swi 24 */
1195 0x4720, /* label: bx r4 */
1197 static unsigned long arm_bx_r4 = 0xe12fff14; /* bx r4 instruction */
1199 /* Set flag indicating whether the current PC is in a Thumb function. */
1200 caller_is_thumb = arm_pc_is_thumb (read_pc ());
1202 /* If the target function is Thumb, set the low bit of the function
1203 address. And if the CPU is currently in ARM mode, patch the
1204 second instruction of call dummy to use a BX instruction to
1205 switch to Thumb mode. */
1206 target_is_thumb = arm_pc_is_thumb (fun);
1207 if (target_is_thumb)
1209 fun |= 1;
1210 if (!caller_is_thumb)
1211 store_unsigned_integer (dummy + 4, sizeof (arm_bx_r4), arm_bx_r4);
1214 /* If the CPU is currently in Thumb mode, use the Thumb call dummy
1215 instead of the ARM one that's already been copied. This will
1216 work for both Thumb and ARM target functions. */
1217 if (caller_is_thumb)
1219 int i;
1220 char *p = dummy;
1221 int len = sizeof (thumb_dummy) / sizeof (thumb_dummy[0]);
1223 for (i = 0; i < len; i++)
1225 store_unsigned_integer (p, sizeof (thumb_dummy[0]), thumb_dummy[i]);
1226 p += sizeof (thumb_dummy[0]);
1230 /* Put the target address in r4; the call dummy will copy this to
1231 the PC. */
1232 write_register (4, fun);
1235 /* Return the offset in the call dummy of the instruction that needs
1236 to have a breakpoint placed on it. This is the offset of the 'swi
1237 24' instruction, which is no longer actually used, but simply acts
1238 as a place-holder now.
1240 This implements the CALL_DUMMY_BREAK_OFFSET macro. */
1243 arm_call_dummy_breakpoint_offset (void)
1245 if (caller_is_thumb)
1246 return 4;
1247 else
1248 return 8;
1251 /* Note: ScottB
1253 This function does not support passing parameters using the FPA
1254 variant of the APCS. It passes any floating point arguments in the
1255 general registers and/or on the stack. */
1257 CORE_ADDR
1258 arm_push_arguments (int nargs, value_ptr * args, CORE_ADDR sp,
1259 int struct_return, CORE_ADDR struct_addr)
1261 char *fp;
1262 int argnum, argreg, nstack_size;
1264 /* Walk through the list of args and determine how large a temporary
1265 stack is required. Need to take care here as structs may be
1266 passed on the stack, and we have to to push them. */
1267 nstack_size = -4 * REGISTER_SIZE; /* Some arguments go into A1-A4. */
1268 if (struct_return) /* The struct address goes in A1. */
1269 nstack_size += REGISTER_SIZE;
1271 /* Walk through the arguments and add their size to nstack_size. */
1272 for (argnum = 0; argnum < nargs; argnum++)
1274 int len;
1275 struct type *arg_type;
1277 arg_type = check_typedef (VALUE_TYPE (args[argnum]));
1278 len = TYPE_LENGTH (arg_type);
1280 /* ANSI C code passes float arguments as integers, K&R code
1281 passes float arguments as doubles. Correct for this here. */
1282 if (TYPE_CODE_FLT == TYPE_CODE (arg_type) && REGISTER_SIZE == len)
1283 nstack_size += FP_REGISTER_VIRTUAL_SIZE;
1284 else
1285 nstack_size += len;
1288 /* Allocate room on the stack, and initialize our stack frame
1289 pointer. */
1290 fp = NULL;
1291 if (nstack_size > 0)
1293 sp -= nstack_size;
1294 fp = (char *) sp;
1297 /* Initialize the integer argument register pointer. */
1298 argreg = A1_REGNUM;
1300 /* The struct_return pointer occupies the first parameter passing
1301 register. */
1302 if (struct_return)
1303 write_register (argreg++, struct_addr);
1305 /* Process arguments from left to right. Store as many as allowed
1306 in the parameter passing registers (A1-A4), and save the rest on
1307 the temporary stack. */
1308 for (argnum = 0; argnum < nargs; argnum++)
1310 int len;
1311 char *val;
1312 double dbl_arg;
1313 CORE_ADDR regval;
1314 enum type_code typecode;
1315 struct type *arg_type, *target_type;
1317 arg_type = check_typedef (VALUE_TYPE (args[argnum]));
1318 target_type = TYPE_TARGET_TYPE (arg_type);
1319 len = TYPE_LENGTH (arg_type);
1320 typecode = TYPE_CODE (arg_type);
1321 val = (char *) VALUE_CONTENTS (args[argnum]);
1323 /* ANSI C code passes float arguments as integers, K&R code
1324 passes float arguments as doubles. The .stabs record for
1325 for ANSI prototype floating point arguments records the
1326 type as FP_INTEGER, while a K&R style (no prototype)
1327 .stabs records the type as FP_FLOAT. In this latter case
1328 the compiler converts the float arguments to double before
1329 calling the function. */
1330 if (TYPE_CODE_FLT == typecode && REGISTER_SIZE == len)
1332 float f;
1333 double d;
1334 char * bufo = (char *) &d;
1335 char * bufd = (char *) &dbl_arg;
1337 len = sizeof (double);
1338 f = *(float *) val;
1339 SWAP_TARGET_AND_HOST (&f, sizeof (float)); /* adjust endianess */
1340 d = f;
1341 /* We must revert the longwords so they get loaded into the
1342 the right registers. */
1343 memcpy (bufd, bufo + len / 2, len / 2);
1344 SWAP_TARGET_AND_HOST (bufd, len / 2); /* adjust endianess */
1345 memcpy (bufd + len / 2, bufo, len / 2);
1346 SWAP_TARGET_AND_HOST (bufd + len / 2, len / 2); /* adjust endianess */
1347 val = (char *) &dbl_arg;
1349 #if 1
1350 /* I don't know why this code was disable. The only logical use
1351 for a function pointer is to call that function, so setting
1352 the mode bit is perfectly fine. FN */
1353 /* If the argument is a pointer to a function, and it is a Thumb
1354 function, set the low bit of the pointer. */
1355 if (TYPE_CODE_PTR == typecode
1356 && NULL != target_type
1357 && TYPE_CODE_FUNC == TYPE_CODE (target_type))
1359 CORE_ADDR regval = extract_address (val, len);
1360 if (arm_pc_is_thumb (regval))
1361 store_address (val, len, MAKE_THUMB_ADDR (regval));
1363 #endif
1364 /* Copy the argument to general registers or the stack in
1365 register-sized pieces. Large arguments are split between
1366 registers and stack. */
1367 while (len > 0)
1369 int partial_len = len < REGISTER_SIZE ? len : REGISTER_SIZE;
1371 if (argreg <= ARM_LAST_ARG_REGNUM)
1373 /* It's an argument being passed in a general register. */
1374 regval = extract_address (val, partial_len);
1375 write_register (argreg++, regval);
1377 else
1379 /* Push the arguments onto the stack. */
1380 write_memory ((CORE_ADDR) fp, val, REGISTER_SIZE);
1381 fp += REGISTER_SIZE;
1384 len -= partial_len;
1385 val += partial_len;
1389 /* Return adjusted stack pointer. */
1390 return sp;
1393 void
1394 arm_pop_frame (void)
1396 int regnum;
1397 struct frame_info *frame = get_current_frame ();
1399 if (!PC_IN_CALL_DUMMY(frame->pc, frame->frame, read_fp()))
1401 CORE_ADDR old_SP;
1403 old_SP = read_register (frame->framereg);
1404 for (regnum = 0; regnum < NUM_REGS; regnum++)
1405 if (frame->fsr.regs[regnum] != 0)
1406 write_register (regnum,
1407 read_memory_integer (frame->fsr.regs[regnum], 4));
1409 write_register (PC_REGNUM, FRAME_SAVED_PC (frame));
1410 write_register (SP_REGNUM, old_SP);
1412 else
1414 CORE_ADDR sp;
1416 sp = read_register (FP_REGNUM);
1417 sp -= sizeof(CORE_ADDR); /* we don't care about this first word */
1419 write_register (PC_REGNUM, read_memory_integer (sp, 4));
1420 sp -= sizeof(CORE_ADDR);
1421 write_register (SP_REGNUM, read_memory_integer (sp, 4));
1422 sp -= sizeof(CORE_ADDR);
1423 write_register (FP_REGNUM, read_memory_integer (sp, 4));
1424 sp -= sizeof(CORE_ADDR);
1426 for (regnum = 10; regnum >= 0; regnum--)
1428 write_register (regnum, read_memory_integer (sp, 4));
1429 sp -= sizeof(CORE_ADDR);
1433 flush_cached_frames ();
1436 static void
1437 print_fpu_flags (int flags)
1439 if (flags & (1 << 0))
1440 fputs ("IVO ", stdout);
1441 if (flags & (1 << 1))
1442 fputs ("DVZ ", stdout);
1443 if (flags & (1 << 2))
1444 fputs ("OFL ", stdout);
1445 if (flags & (1 << 3))
1446 fputs ("UFL ", stdout);
1447 if (flags & (1 << 4))
1448 fputs ("INX ", stdout);
1449 putchar ('\n');
1452 void
1453 arm_float_info (void)
1455 register unsigned long status = read_register (FPS_REGNUM);
1456 int type;
1458 type = (status >> 24) & 127;
1459 printf ("%s FPU type %d\n",
1460 (status & (1 << 31)) ? "Hardware" : "Software",
1461 type);
1462 fputs ("mask: ", stdout);
1463 print_fpu_flags (status >> 16);
1464 fputs ("flags: ", stdout);
1465 print_fpu_flags (status);
1468 #if 0
1469 /* FIXME: The generated assembler works but sucks. Instead of using
1470 r0, r1 it pushes them on the stack, then loads them into r3, r4 and
1471 uses those registers. I must be missing something. ScottB */
1473 void
1474 convert_from_extended (void *ptr, void *dbl)
1476 __asm__ ("
1477 ldfe f0,[%0]
1478 stfd f0,[%1] "
1479 : /* no output */
1480 : "r" (ptr), "r" (dbl));
1483 void
1484 convert_to_extended (void *dbl, void *ptr)
1486 __asm__ ("
1487 ldfd f0,[%0]
1488 stfe f0,[%1] "
1489 : /* no output */
1490 : "r" (dbl), "r" (ptr));
1492 #else
1493 static void
1494 convert_from_extended (void *ptr, void *dbl)
1496 *(double *) dbl = *(double *) ptr;
1499 void
1500 convert_to_extended (void *dbl, void *ptr)
1502 *(double *) ptr = *(double *) dbl;
1504 #endif
1506 /* Nonzero if register N requires conversion from raw format to
1507 virtual format. */
1510 arm_register_convertible (unsigned int regnum)
1512 return ((regnum - F0_REGNUM) < 8);
1515 /* Convert data from raw format for register REGNUM in buffer FROM to
1516 virtual format with type TYPE in buffer TO. */
1518 void
1519 arm_register_convert_to_virtual (unsigned int regnum, struct type *type,
1520 void *from, void *to)
1522 double val;
1524 convert_from_extended (from, &val);
1525 store_floating (to, TYPE_LENGTH (type), val);
1528 /* Convert data from virtual format with type TYPE in buffer FROM to
1529 raw format for register REGNUM in buffer TO. */
1531 void
1532 arm_register_convert_to_raw (unsigned int regnum, struct type *type,
1533 void *from, void *to)
1535 double val = extract_floating (from, TYPE_LENGTH (type));
1537 convert_to_extended (&val, to);
1540 static int
1541 condition_true (unsigned long cond, unsigned long status_reg)
1543 if (cond == INST_AL || cond == INST_NV)
1544 return 1;
1546 switch (cond)
1548 case INST_EQ:
1549 return ((status_reg & FLAG_Z) != 0);
1550 case INST_NE:
1551 return ((status_reg & FLAG_Z) == 0);
1552 case INST_CS:
1553 return ((status_reg & FLAG_C) != 0);
1554 case INST_CC:
1555 return ((status_reg & FLAG_C) == 0);
1556 case INST_MI:
1557 return ((status_reg & FLAG_N) != 0);
1558 case INST_PL:
1559 return ((status_reg & FLAG_N) == 0);
1560 case INST_VS:
1561 return ((status_reg & FLAG_V) != 0);
1562 case INST_VC:
1563 return ((status_reg & FLAG_V) == 0);
1564 case INST_HI:
1565 return ((status_reg & (FLAG_C | FLAG_Z)) == FLAG_C);
1566 case INST_LS:
1567 return ((status_reg & (FLAG_C | FLAG_Z)) != FLAG_C);
1568 case INST_GE:
1569 return (((status_reg & FLAG_N) == 0) == ((status_reg & FLAG_V) == 0));
1570 case INST_LT:
1571 return (((status_reg & FLAG_N) == 0) != ((status_reg & FLAG_V) == 0));
1572 case INST_GT:
1573 return (((status_reg & FLAG_Z) == 0) &&
1574 (((status_reg & FLAG_N) == 0) == ((status_reg & FLAG_V) == 0)));
1575 case INST_LE:
1576 return (((status_reg & FLAG_Z) != 0) ||
1577 (((status_reg & FLAG_N) == 0) != ((status_reg & FLAG_V) == 0)));
1579 return 1;
1582 #define submask(x) ((1L << ((x) + 1)) - 1)
1583 #define bit(obj,st) (((obj) >> (st)) & 1)
1584 #define bits(obj,st,fn) (((obj) >> (st)) & submask ((fn) - (st)))
1585 #define sbits(obj,st,fn) \
1586 ((long) (bits(obj,st,fn) | ((long) bit(obj,fn) * ~ submask (fn - st))))
1587 #define BranchDest(addr,instr) \
1588 ((CORE_ADDR) (((long) (addr)) + 8 + (sbits (instr, 0, 23) << 2)))
1589 #define ARM_PC_32 1
1591 static unsigned long
1592 shifted_reg_val (unsigned long inst, int carry, unsigned long pc_val,
1593 unsigned long status_reg)
1595 unsigned long res, shift;
1596 int rm = bits (inst, 0, 3);
1597 unsigned long shifttype = bits (inst, 5, 6);
1599 if (bit (inst, 4))
1601 int rs = bits (inst, 8, 11);
1602 shift = (rs == 15 ? pc_val + 8 : read_register (rs)) & 0xFF;
1604 else
1605 shift = bits (inst, 7, 11);
1607 res = (rm == 15
1608 ? ((pc_val | (ARM_PC_32 ? 0 : status_reg))
1609 + (bit (inst, 4) ? 12 : 8))
1610 : read_register (rm));
1612 switch (shifttype)
1614 case 0: /* LSL */
1615 res = shift >= 32 ? 0 : res << shift;
1616 break;
1618 case 1: /* LSR */
1619 res = shift >= 32 ? 0 : res >> shift;
1620 break;
1622 case 2: /* ASR */
1623 if (shift >= 32)
1624 shift = 31;
1625 res = ((res & 0x80000000L)
1626 ? ~((~res) >> shift) : res >> shift);
1627 break;
1629 case 3: /* ROR/RRX */
1630 shift &= 31;
1631 if (shift == 0)
1632 res = (res >> 1) | (carry ? 0x80000000L : 0);
1633 else
1634 res = (res >> shift) | (res << (32 - shift));
1635 break;
1638 return res & 0xffffffff;
1641 /* Return number of 1-bits in VAL. */
1643 static int
1644 bitcount (unsigned long val)
1646 int nbits;
1647 for (nbits = 0; val != 0; nbits++)
1648 val &= val - 1; /* delete rightmost 1-bit in val */
1649 return nbits;
1652 static CORE_ADDR
1653 thumb_get_next_pc (CORE_ADDR pc)
1655 unsigned long pc_val = ((unsigned long) pc) + 4; /* PC after prefetch */
1656 unsigned short inst1 = read_memory_integer (pc, 2);
1657 CORE_ADDR nextpc = pc + 2; /* default is next instruction */
1658 unsigned long offset;
1660 if ((inst1 & 0xff00) == 0xbd00) /* pop {rlist, pc} */
1662 CORE_ADDR sp;
1664 /* Fetch the saved PC from the stack. It's stored above
1665 all of the other registers. */
1666 offset = bitcount (bits (inst1, 0, 7)) * REGISTER_SIZE;
1667 sp = read_register (SP_REGNUM);
1668 nextpc = (CORE_ADDR) read_memory_integer (sp + offset, 4);
1669 nextpc = ADDR_BITS_REMOVE (nextpc);
1670 if (nextpc == pc)
1671 error ("Infinite loop detected");
1673 else if ((inst1 & 0xf000) == 0xd000) /* conditional branch */
1675 unsigned long status = read_register (PS_REGNUM);
1676 unsigned long cond = bits (inst1, 8, 11);
1677 if (cond != 0x0f && condition_true (cond, status)) /* 0x0f = SWI */
1678 nextpc = pc_val + (sbits (inst1, 0, 7) << 1);
1680 else if ((inst1 & 0xf800) == 0xe000) /* unconditional branch */
1682 nextpc = pc_val + (sbits (inst1, 0, 10) << 1);
1684 else if ((inst1 & 0xf800) == 0xf000) /* long branch with link */
1686 unsigned short inst2 = read_memory_integer (pc + 2, 2);
1687 offset = (sbits (inst1, 0, 10) << 12) + (bits (inst2, 0, 10) << 1);
1688 nextpc = pc_val + offset;
1691 return nextpc;
1694 CORE_ADDR
1695 arm_get_next_pc (CORE_ADDR pc)
1697 unsigned long pc_val;
1698 unsigned long this_instr;
1699 unsigned long status;
1700 CORE_ADDR nextpc;
1702 if (arm_pc_is_thumb (pc))
1703 return thumb_get_next_pc (pc);
1705 pc_val = (unsigned long) pc;
1706 this_instr = read_memory_integer (pc, 4);
1707 status = read_register (PS_REGNUM);
1708 nextpc = (CORE_ADDR) (pc_val + 4); /* Default case */
1710 if (condition_true (bits (this_instr, 28, 31), status))
1712 switch (bits (this_instr, 24, 27))
1714 case 0x0:
1715 case 0x1: /* data processing */
1716 case 0x2:
1717 case 0x3:
1719 unsigned long operand1, operand2, result = 0;
1720 unsigned long rn;
1721 int c;
1723 if (bits (this_instr, 12, 15) != 15)
1724 break;
1726 if (bits (this_instr, 22, 25) == 0
1727 && bits (this_instr, 4, 7) == 9) /* multiply */
1728 error ("Illegal update to pc in instruction");
1730 /* Multiply into PC */
1731 c = (status & FLAG_C) ? 1 : 0;
1732 rn = bits (this_instr, 16, 19);
1733 operand1 = (rn == 15) ? pc_val + 8 : read_register (rn);
1735 if (bit (this_instr, 25))
1737 unsigned long immval = bits (this_instr, 0, 7);
1738 unsigned long rotate = 2 * bits (this_instr, 8, 11);
1739 operand2 = ((immval >> rotate) | (immval << (32 - rotate)))
1740 & 0xffffffff;
1742 else /* operand 2 is a shifted register */
1743 operand2 = shifted_reg_val (this_instr, c, pc_val, status);
1745 switch (bits (this_instr, 21, 24))
1747 case 0x0: /*and */
1748 result = operand1 & operand2;
1749 break;
1751 case 0x1: /*eor */
1752 result = operand1 ^ operand2;
1753 break;
1755 case 0x2: /*sub */
1756 result = operand1 - operand2;
1757 break;
1759 case 0x3: /*rsb */
1760 result = operand2 - operand1;
1761 break;
1763 case 0x4: /*add */
1764 result = operand1 + operand2;
1765 break;
1767 case 0x5: /*adc */
1768 result = operand1 + operand2 + c;
1769 break;
1771 case 0x6: /*sbc */
1772 result = operand1 - operand2 + c;
1773 break;
1775 case 0x7: /*rsc */
1776 result = operand2 - operand1 + c;
1777 break;
1779 case 0x8:
1780 case 0x9:
1781 case 0xa:
1782 case 0xb: /* tst, teq, cmp, cmn */
1783 result = (unsigned long) nextpc;
1784 break;
1786 case 0xc: /*orr */
1787 result = operand1 | operand2;
1788 break;
1790 case 0xd: /*mov */
1791 /* Always step into a function. */
1792 result = operand2;
1793 break;
1795 case 0xe: /*bic */
1796 result = operand1 & ~operand2;
1797 break;
1799 case 0xf: /*mvn */
1800 result = ~operand2;
1801 break;
1803 nextpc = (CORE_ADDR) ADDR_BITS_REMOVE (result);
1805 if (nextpc == pc)
1806 error ("Infinite loop detected");
1807 break;
1810 case 0x4:
1811 case 0x5: /* data transfer */
1812 case 0x6:
1813 case 0x7:
1814 if (bit (this_instr, 20))
1816 /* load */
1817 if (bits (this_instr, 12, 15) == 15)
1819 /* rd == pc */
1820 unsigned long rn;
1821 unsigned long base;
1823 if (bit (this_instr, 22))
1824 error ("Illegal update to pc in instruction");
1826 /* byte write to PC */
1827 rn = bits (this_instr, 16, 19);
1828 base = (rn == 15) ? pc_val + 8 : read_register (rn);
1829 if (bit (this_instr, 24))
1831 /* pre-indexed */
1832 int c = (status & FLAG_C) ? 1 : 0;
1833 unsigned long offset =
1834 (bit (this_instr, 25)
1835 ? shifted_reg_val (this_instr, c, pc_val, status)
1836 : bits (this_instr, 0, 11));
1838 if (bit (this_instr, 23))
1839 base += offset;
1840 else
1841 base -= offset;
1843 nextpc = (CORE_ADDR) read_memory_integer ((CORE_ADDR) base,
1846 nextpc = ADDR_BITS_REMOVE (nextpc);
1848 if (nextpc == pc)
1849 error ("Infinite loop detected");
1852 break;
1854 case 0x8:
1855 case 0x9: /* block transfer */
1856 if (bit (this_instr, 20))
1858 /* LDM */
1859 if (bit (this_instr, 15))
1861 /* loading pc */
1862 int offset = 0;
1864 if (bit (this_instr, 23))
1866 /* up */
1867 unsigned long reglist = bits (this_instr, 0, 14);
1868 offset = bitcount (reglist) * 4;
1869 if (bit (this_instr, 24)) /* pre */
1870 offset += 4;
1872 else if (bit (this_instr, 24))
1873 offset = -4;
1876 unsigned long rn_val =
1877 read_register (bits (this_instr, 16, 19));
1878 nextpc =
1879 (CORE_ADDR) read_memory_integer ((CORE_ADDR) (rn_val
1880 + offset),
1883 nextpc = ADDR_BITS_REMOVE (nextpc);
1884 if (nextpc == pc)
1885 error ("Infinite loop detected");
1888 break;
1890 case 0xb: /* branch & link */
1891 case 0xa: /* branch */
1893 nextpc = BranchDest (pc, this_instr);
1895 nextpc = ADDR_BITS_REMOVE (nextpc);
1896 if (nextpc == pc)
1897 error ("Infinite loop detected");
1898 break;
1901 case 0xc:
1902 case 0xd:
1903 case 0xe: /* coproc ops */
1904 case 0xf: /* SWI */
1905 break;
1907 default:
1908 fprintf (stderr, "Bad bit-field extraction\n");
1909 return (pc);
1913 return nextpc;
1916 #include "bfd-in2.h"
1917 #include "libcoff.h"
1919 static int
1920 gdb_print_insn_arm (bfd_vma memaddr, disassemble_info *info)
1922 if (arm_pc_is_thumb (memaddr))
1924 static asymbol *asym;
1925 static combined_entry_type ce;
1926 static struct coff_symbol_struct csym;
1927 static struct _bfd fake_bfd;
1928 static bfd_target fake_target;
1930 if (csym.native == NULL)
1932 /* Create a fake symbol vector containing a Thumb symbol. This is
1933 solely so that the code in print_insn_little_arm() and
1934 print_insn_big_arm() in opcodes/arm-dis.c will detect the presence
1935 of a Thumb symbol and switch to decoding Thumb instructions. */
1937 fake_target.flavour = bfd_target_coff_flavour;
1938 fake_bfd.xvec = &fake_target;
1939 ce.u.syment.n_sclass = C_THUMBEXTFUNC;
1940 csym.native = &ce;
1941 csym.symbol.the_bfd = &fake_bfd;
1942 csym.symbol.name = "fake";
1943 asym = (asymbol *) & csym;
1946 memaddr = UNMAKE_THUMB_ADDR (memaddr);
1947 info->symbols = &asym;
1949 else
1950 info->symbols = NULL;
1952 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
1953 return print_insn_big_arm (memaddr, info);
1954 else
1955 return print_insn_little_arm (memaddr, info);
1958 /* This function implements the BREAKPOINT_FROM_PC macro. It uses the
1959 program counter value to determine whether a 16-bit or 32-bit
1960 breakpoint should be used. It returns a pointer to a string of
1961 bytes that encode a breakpoint instruction, stores the length of
1962 the string to *lenptr, and adjusts the program counter (if
1963 necessary) to point to the actual memory location where the
1964 breakpoint should be inserted. */
1966 unsigned char *
1967 arm_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
1969 if (arm_pc_is_thumb (*pcptr) || arm_pc_is_thumb_dummy (*pcptr))
1971 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
1973 static char thumb_breakpoint[] = THUMB_BE_BREAKPOINT;
1974 *pcptr = UNMAKE_THUMB_ADDR (*pcptr);
1975 *lenptr = sizeof (thumb_breakpoint);
1976 return thumb_breakpoint;
1978 else
1980 static char thumb_breakpoint[] = THUMB_LE_BREAKPOINT;
1981 *pcptr = UNMAKE_THUMB_ADDR (*pcptr);
1982 *lenptr = sizeof (thumb_breakpoint);
1983 return thumb_breakpoint;
1986 else
1988 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
1990 static char arm_breakpoint[] = ARM_BE_BREAKPOINT;
1991 *lenptr = sizeof (arm_breakpoint);
1992 return arm_breakpoint;
1994 else
1996 static char arm_breakpoint[] = ARM_LE_BREAKPOINT;
1997 *lenptr = sizeof (arm_breakpoint);
1998 return arm_breakpoint;
2003 /* Extract from an array REGBUF containing the (raw) register state a
2004 function return value of type TYPE, and copy that, in virtual
2005 format, into VALBUF. */
2007 void
2008 arm_extract_return_value (struct type *type,
2009 char regbuf[REGISTER_BYTES],
2010 char *valbuf)
2012 if (TYPE_CODE_FLT == TYPE_CODE (type))
2013 convert_from_extended (&regbuf[REGISTER_BYTE (F0_REGNUM)], valbuf);
2014 else
2015 memcpy (valbuf, &regbuf[REGISTER_BYTE (A1_REGNUM)], TYPE_LENGTH (type));
2018 /* Return non-zero if the PC is inside a thumb call thunk. */
2021 arm_in_call_stub (CORE_ADDR pc, char *name)
2023 CORE_ADDR start_addr;
2025 /* Find the starting address of the function containing the PC. If
2026 the caller didn't give us a name, look it up at the same time. */
2027 if (find_pc_partial_function (pc, name ? NULL : &name, &start_addr, NULL) == 0)
2028 return 0;
2030 return strncmp (name, "_call_via_r", 11) == 0;
2033 /* If PC is in a Thumb call or return stub, return the address of the
2034 target PC, which is in a register. The thunk functions are called
2035 _called_via_xx, where x is the register name. The possible names
2036 are r0-r9, sl, fp, ip, sp, and lr. */
2038 CORE_ADDR
2039 arm_skip_stub (CORE_ADDR pc)
2041 char *name;
2042 CORE_ADDR start_addr;
2044 /* Find the starting address and name of the function containing the PC. */
2045 if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0)
2046 return 0;
2048 /* Call thunks always start with "_call_via_". */
2049 if (strncmp (name, "_call_via_", 10) == 0)
2051 /* Use the name suffix to determine which register contains the
2052 target PC. */
2053 static char *table[15] =
2054 {"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2055 "r8", "r9", "sl", "fp", "ip", "sp", "lr"
2057 int regno;
2059 for (regno = 0; regno <= 14; regno++)
2060 if (strcmp (&name[10], table[regno]) == 0)
2061 return read_register (regno);
2064 return 0; /* not a stub */
2067 /* If the user changes the register disassembly flavor used for info register
2068 and other commands, we have to also switch the flavor used in opcodes
2069 for disassembly output.
2070 This function is run in the set disassembly_flavor command, and does that. */
2072 static void
2073 set_disassembly_flavor_sfunc (char *args, int from_tty,
2074 struct cmd_list_element *c)
2076 set_disassembly_flavor ();
2079 static void
2080 set_disassembly_flavor (void)
2082 const char *setname, *setdesc, **regnames;
2083 int numregs, j;
2085 /* Find the flavor that the user wants in the opcodes table. */
2086 int current = 0;
2087 numregs = get_arm_regnames (current, &setname, &setdesc, &regnames);
2088 while ((disassembly_flavor != setname)
2089 && (current < num_flavor_options))
2090 get_arm_regnames (++current, &setname, &setdesc, &regnames);
2091 current_option = current;
2093 /* Fill our copy. */
2094 for (j = 0; j < numregs; j++)
2095 arm_register_names[j] = (char *) regnames[j];
2097 /* Adjust case. */
2098 if (isupper (*regnames[PC_REGNUM]))
2100 arm_register_names[FPS_REGNUM] = "FPS";
2101 arm_register_names[PS_REGNUM] = "CPSR";
2103 else
2105 arm_register_names[FPS_REGNUM] = "fps";
2106 arm_register_names[PS_REGNUM] = "cpsr";
2109 /* Synchronize the disassembler. */
2110 set_arm_regname_option (current);
2113 /* arm_othernames implements the "othernames" command. This is kind
2114 of hacky, and I prefer the set-show disassembly-flavor which is
2115 also used for the x86 gdb. I will keep this around, however, in
2116 case anyone is actually using it. */
2118 static void
2119 arm_othernames (char *names, int n)
2121 /* Circle through the various flavors. */
2122 current_option = (current_option + 1) % num_flavor_options;
2124 disassembly_flavor = valid_flavors[current_option];
2125 set_disassembly_flavor ();
2128 void
2129 _initialize_arm_tdep (void)
2131 struct ui_file *stb;
2132 long length;
2133 struct cmd_list_element *new_cmd;
2134 const char *setname;
2135 const char *setdesc;
2136 const char **regnames;
2137 int numregs, i, j;
2138 static char *helptext;
2140 tm_print_insn = gdb_print_insn_arm;
2142 /* Get the number of possible sets of register names defined in opcodes. */
2143 num_flavor_options = get_arm_regname_num_options ();
2145 /* Sync the opcode insn printer with our register viewer: */
2146 parse_arm_disassembler_option ("reg-names-std");
2148 /* Begin creating the help text. */
2149 stb = mem_fileopen ();
2150 fprintf_unfiltered (stb, "Set the disassembly flavor.\n\
2151 The valid values are:\n");
2153 /* Initialize the array that will be passed to add_set_enum_cmd(). */
2154 valid_flavors = xmalloc ((num_flavor_options + 1) * sizeof (char *));
2155 for (i = 0; i < num_flavor_options; i++)
2157 numregs = get_arm_regnames (i, &setname, &setdesc, &regnames);
2158 valid_flavors[i] = setname;
2159 fprintf_unfiltered (stb, "%s - %s\n", setname,
2160 setdesc);
2161 /* Copy the default names (if found) and synchronize disassembler. */
2162 if (!strcmp (setname, "std"))
2164 disassembly_flavor = setname;
2165 current_option = i;
2166 for (j = 0; j < numregs; j++)
2167 arm_register_names[j] = (char *) regnames[j];
2168 set_arm_regname_option (i);
2171 /* Mark the end of valid options. */
2172 valid_flavors[num_flavor_options] = NULL;
2174 /* Finish the creation of the help text. */
2175 fprintf_unfiltered (stb, "The default is \"std\".");
2176 helptext = ui_file_xstrdup (stb, &length);
2177 ui_file_delete (stb);
2179 /* Add the disassembly-flavor command */
2180 new_cmd = add_set_enum_cmd ("disassembly-flavor", no_class,
2181 valid_flavors,
2182 &disassembly_flavor,
2183 helptext,
2184 &setlist);
2185 new_cmd->function.sfunc = set_disassembly_flavor_sfunc;
2186 add_show_from_set (new_cmd, &showlist);
2188 /* ??? Maybe this should be a boolean. */
2189 add_show_from_set (add_set_cmd ("apcs32", no_class,
2190 var_zinteger, (char *) &arm_apcs_32,
2191 "Set usage of ARM 32-bit mode.\n", &setlist),
2192 &showlist);
2194 /* Add the deprecated "othernames" command */
2196 add_com ("othernames", class_obscure, arm_othernames,
2197 "Switch to the next set of register names.");
2200 /* Test whether the coff symbol specific value corresponds to a Thumb
2201 function. */
2204 coff_sym_is_thumb (int val)
2206 return (val == C_THUMBEXT ||
2207 val == C_THUMBSTAT ||
2208 val == C_THUMBEXTFUNC ||
2209 val == C_THUMBSTATFUNC ||
2210 val == C_THUMBLABEL);