GDB (API)
/home/stan/gdb/src/gdb/arm-tdep.h
Go to the documentation of this file.
00001 /* Common target dependent code for GDB on ARM systems.
00002    Copyright (C) 2002-2013 Free Software Foundation, Inc.
00003 
00004    This file is part of GDB.
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 3 of the License, or
00009    (at your option) any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00018 
00019 #ifndef ARM_TDEP_H
00020 #define ARM_TDEP_H
00021 
00022 /* Forward declarations.  */
00023 struct gdbarch;
00024 struct regset;
00025 struct address_space;
00026 
00027 /* Register numbers of various important registers.  */
00028 
00029 enum gdb_regnum {
00030   ARM_A1_REGNUM = 0,            /* first integer-like argument */
00031   ARM_A4_REGNUM = 3,            /* last integer-like argument */
00032   ARM_AP_REGNUM = 11,
00033   ARM_IP_REGNUM = 12,
00034   ARM_SP_REGNUM = 13,           /* Contains address of top of stack */
00035   ARM_LR_REGNUM = 14,           /* address to return to from a function call */
00036   ARM_PC_REGNUM = 15,           /* Contains program counter */
00037   ARM_F0_REGNUM = 16,           /* first floating point register */
00038   ARM_F3_REGNUM = 19,           /* last floating point argument register */
00039   ARM_F7_REGNUM = 23,           /* last floating point register */
00040   ARM_FPS_REGNUM = 24,          /* floating point status register */
00041   ARM_PS_REGNUM = 25,           /* Contains processor status */
00042   ARM_WR0_REGNUM,               /* WMMX data registers.  */
00043   ARM_WR15_REGNUM = ARM_WR0_REGNUM + 15,
00044   ARM_WC0_REGNUM,               /* WMMX control registers.  */
00045   ARM_WCSSF_REGNUM = ARM_WC0_REGNUM + 2,
00046   ARM_WCASF_REGNUM = ARM_WC0_REGNUM + 3,
00047   ARM_WC7_REGNUM = ARM_WC0_REGNUM + 7,
00048   ARM_WCGR0_REGNUM,             /* WMMX general purpose registers.  */
00049   ARM_WCGR3_REGNUM = ARM_WCGR0_REGNUM + 3,
00050   ARM_WCGR7_REGNUM = ARM_WCGR0_REGNUM + 7,
00051   ARM_D0_REGNUM,                /* VFP double-precision registers.  */
00052   ARM_D31_REGNUM = ARM_D0_REGNUM + 31,
00053   ARM_FPSCR_REGNUM,
00054 
00055   ARM_NUM_REGS,
00056 
00057   /* Other useful registers.  */
00058   ARM_FP_REGNUM = 11,           /* Frame register in ARM code, if used.  */
00059   THUMB_FP_REGNUM = 7,          /* Frame register in Thumb code, if used.  */
00060   ARM_NUM_ARG_REGS = 4, 
00061   ARM_LAST_ARG_REGNUM = ARM_A4_REGNUM,
00062   ARM_NUM_FP_ARG_REGS = 4,
00063   ARM_LAST_FP_ARG_REGNUM = ARM_F3_REGNUM
00064 };
00065 
00066 /* Size of integer registers.  */
00067 #define INT_REGISTER_SIZE               4
00068 
00069 /* Say how long FP registers are.  Used for documentation purposes and
00070    code readability in this header.  IEEE extended doubles are 80
00071    bits.  DWORD aligned they use 96 bits.  */
00072 #define FP_REGISTER_SIZE        12
00073 
00074 /* Say how long VFP double precision registers are.  Used for documentation
00075    purposes and code readability.  These are fixed at 64 bits.  */
00076 #define VFP_REGISTER_SIZE       8
00077 
00078 /* Number of machine registers.  The only define actually required 
00079    is gdbarch_num_regs.  The other definitions are used for documentation
00080    purposes and code readability.  */
00081 /* For 26 bit ARM code, a fake copy of the PC is placed in register 25 (PS)
00082    (and called PS for processor status) so the status bits can be cleared
00083    from the PC (register 15).  For 32 bit ARM code, a copy of CPSR is placed
00084    in PS.  */
00085 #define NUM_FREGS       8       /* Number of floating point registers.  */
00086 #define NUM_SREGS       2       /* Number of status registers.  */
00087 #define NUM_GREGS       16      /* Number of general purpose registers.  */
00088 
00089 
00090 /* Instruction condition field values.  */
00091 #define INST_EQ         0x0
00092 #define INST_NE         0x1
00093 #define INST_CS         0x2
00094 #define INST_CC         0x3
00095 #define INST_MI         0x4
00096 #define INST_PL         0x5
00097 #define INST_VS         0x6
00098 #define INST_VC         0x7
00099 #define INST_HI         0x8
00100 #define INST_LS         0x9
00101 #define INST_GE         0xa
00102 #define INST_LT         0xb
00103 #define INST_GT         0xc
00104 #define INST_LE         0xd
00105 #define INST_AL         0xe
00106 #define INST_NV         0xf
00107 
00108 #define FLAG_N          0x80000000
00109 #define FLAG_Z          0x40000000
00110 #define FLAG_C          0x20000000
00111 #define FLAG_V          0x10000000
00112 
00113 #define CPSR_T          0x20
00114 
00115 #define XPSR_T          0x01000000
00116 
00117 /* Type of floating-point code in use by inferior.  There are really 3 models
00118    that are traditionally supported (plus the endianness issue), but gcc can
00119    only generate 2 of those.  The third is APCS_FLOAT, where arguments to
00120    functions are passed in floating-point registers.  
00121 
00122    In addition to the traditional models, VFP adds two more. 
00123 
00124    If you update this enum, don't forget to update fp_model_strings in 
00125    arm-tdep.c.  */
00126 
00127 enum arm_float_model
00128 {
00129   ARM_FLOAT_AUTO,       /* Automatic detection.  Do not set in tdep.  */
00130   ARM_FLOAT_SOFT_FPA,   /* Traditional soft-float (mixed-endian on LE ARM).  */
00131   ARM_FLOAT_FPA,        /* FPA co-processor.  GCC calling convention.  */
00132   ARM_FLOAT_SOFT_VFP,   /* Soft-float with pure-endian doubles.  */
00133   ARM_FLOAT_VFP,        /* Full VFP calling convention.  */
00134   ARM_FLOAT_LAST        /* Keep at end.  */
00135 };
00136 
00137 /* ABI used by the inferior.  */
00138 enum arm_abi_kind
00139 {
00140   ARM_ABI_AUTO,
00141   ARM_ABI_APCS,
00142   ARM_ABI_AAPCS,
00143   ARM_ABI_LAST
00144 };
00145 
00146 /* Convention for returning structures.  */
00147 
00148 enum struct_return
00149 {
00150   pcc_struct_return,            /* Return "short" structures in memory.  */
00151   reg_struct_return             /* Return "short" structures in registers.  */
00152 };
00153 
00154 /* Target-dependent structure in gdbarch.  */
00155 struct gdbarch_tdep
00156 {
00157   /* The ABI for this architecture.  It should never be set to
00158      ARM_ABI_AUTO.  */
00159   enum arm_abi_kind arm_abi;
00160 
00161   enum arm_float_model fp_model; /* Floating point calling conventions.  */
00162 
00163   int have_fpa_registers;       /* Does the target report the FPA registers?  */
00164   int have_vfp_registers;       /* Does the target report the VFP registers?  */
00165   int have_vfp_pseudos;         /* Are we synthesizing the single precision
00166                                    VFP registers?  */
00167   int have_neon_pseudos;        /* Are we synthesizing the quad precision
00168                                    NEON registers?  Requires
00169                                    have_vfp_pseudos.  */
00170   int have_neon;                /* Do we have a NEON unit?  */
00171 
00172   int is_m;                     /* Does the target follow the "M" profile.  */
00173   CORE_ADDR lowest_pc;          /* Lowest address at which instructions 
00174                                    will appear.  */
00175 
00176   const gdb_byte *arm_breakpoint;       /* Breakpoint pattern for an ARM insn.  */
00177   int arm_breakpoint_size;      /* And its size.  */
00178   const gdb_byte *thumb_breakpoint;     /* Breakpoint pattern for a Thumb insn.  */
00179   int thumb_breakpoint_size;    /* And its size.  */
00180 
00181   /* If the Thumb breakpoint is an undefined instruction (which is
00182      affected by IT blocks) rather than a BKPT instruction (which is
00183      not), then we need a 32-bit Thumb breakpoint to preserve the
00184      instruction count in IT blocks.  */
00185   const gdb_byte *thumb2_breakpoint;
00186   int thumb2_breakpoint_size;
00187 
00188   int jb_pc;                    /* Offset to PC value in jump buffer.
00189                                    If this is negative, longjmp support
00190                                    will be disabled.  */
00191   size_t jb_elt_size;           /* And the size of each entry in the buf.  */
00192 
00193   /* Convention for returning structures.  */
00194   enum struct_return struct_return;
00195 
00196   /* Cached core file helpers.  */
00197   struct regset *gregset, *fpregset, *vfpregset;
00198 
00199   /* ISA-specific data types.  */
00200   struct type *arm_ext_type;
00201   struct type *neon_double_type;
00202   struct type *neon_quad_type;
00203 
00204   /* Return the expected next PC if FRAME is stopped at a syscall
00205      instruction.  */
00206   CORE_ADDR (*syscall_next_pc) (struct frame_info *frame);
00207 
00208    /* Parse swi insn args, sycall record.  */
00209   int (*arm_swi_record) (struct regcache *regcache);
00210 };
00211 
00212 /* Structures used for displaced stepping.  */
00213 
00214 /* The maximum number of temporaries available for displaced instructions.  */
00215 #define DISPLACED_TEMPS                 16
00216 /* The maximum number of modified instructions generated for one single-stepped
00217    instruction, including the breakpoint (usually at the end of the instruction
00218    sequence) and any scratch words, etc.  */
00219 #define DISPLACED_MODIFIED_INSNS        8
00220 
00221 struct displaced_step_closure
00222 {
00223   ULONGEST tmp[DISPLACED_TEMPS];
00224   int rd;
00225   int wrote_to_pc;
00226   union
00227   {
00228     struct
00229     {
00230       int xfersize;
00231       int rn;                      /* Writeback register.  */
00232       unsigned int immed : 1;      /* Offset is immediate.  */
00233       unsigned int writeback : 1;  /* Perform base-register writeback.  */
00234       unsigned int restore_r4 : 1; /* Used r4 as scratch.  */
00235     } ldst;
00236 
00237     struct
00238     {
00239       unsigned long dest;
00240       unsigned int link : 1;
00241       unsigned int exchange : 1;
00242       unsigned int cond : 4;
00243     } branch;
00244 
00245     struct
00246     {
00247       unsigned int regmask;
00248       int rn;
00249       CORE_ADDR xfer_addr;
00250       unsigned int load : 1;
00251       unsigned int user : 1;
00252       unsigned int increment : 1;
00253       unsigned int before : 1;
00254       unsigned int writeback : 1;
00255       unsigned int cond : 4;
00256     } block;
00257 
00258     struct
00259     {
00260       unsigned int immed : 1;
00261     } preload;
00262 
00263     struct
00264     {
00265       /* If non-NULL, override generic SVC handling (e.g. for a particular
00266          OS).  */
00267       int (*copy_svc_os) (struct gdbarch *gdbarch, struct regcache *regs,
00268                           struct displaced_step_closure *dsc);
00269     } svc;
00270   } u;
00271 
00272   /* The size of original instruction, 2 or 4.  */
00273   unsigned int insn_size;
00274   /* True if the original insn (and thus all replacement insns) are Thumb
00275      instead of ARM.   */
00276   unsigned int is_thumb;
00277 
00278   /* The slots in the array is used in this way below,
00279      - ARM instruction occupies one slot,
00280      - Thumb 16 bit instruction occupies one slot,
00281      - Thumb 32-bit instruction occupies *two* slots, one part for each.  */
00282   unsigned long modinsn[DISPLACED_MODIFIED_INSNS];
00283   int numinsns;
00284   CORE_ADDR insn_addr;
00285   CORE_ADDR scratch_base;
00286   void (*cleanup) (struct gdbarch *, struct regcache *,
00287                    struct displaced_step_closure *);
00288 };
00289 
00290 /* Values for the WRITE_PC argument to displaced_write_reg.  If the register
00291    write may write to the PC, specifies the way the CPSR T bit, etc. is
00292    modified by the instruction.  */
00293 
00294 enum pc_write_style
00295 {
00296   BRANCH_WRITE_PC,
00297   BX_WRITE_PC,
00298   LOAD_WRITE_PC,
00299   ALU_WRITE_PC,
00300   CANNOT_WRITE_PC
00301 };
00302 
00303 extern void
00304   arm_process_displaced_insn (struct gdbarch *gdbarch, CORE_ADDR from,
00305                               CORE_ADDR to, struct regcache *regs,
00306                               struct displaced_step_closure *dsc);
00307 extern void
00308   arm_displaced_init_closure (struct gdbarch *gdbarch, CORE_ADDR from,
00309                               CORE_ADDR to, struct displaced_step_closure *dsc);
00310 extern ULONGEST
00311   displaced_read_reg (struct regcache *regs, struct displaced_step_closure *dsc,
00312                       int regno);
00313 extern void
00314   displaced_write_reg (struct regcache *regs,
00315                        struct displaced_step_closure *dsc, int regno,
00316                        ULONGEST val, enum pc_write_style write_pc);
00317 
00318 CORE_ADDR arm_skip_stub (struct frame_info *, CORE_ADDR);
00319 CORE_ADDR arm_get_next_pc (struct frame_info *, CORE_ADDR);
00320 void arm_insert_single_step_breakpoint (struct gdbarch *,
00321                                         struct address_space *, CORE_ADDR);
00322 int arm_deal_with_atomic_sequence (struct frame_info *);
00323 int arm_software_single_step (struct frame_info *);
00324 int arm_frame_is_thumb (struct frame_info *frame);
00325 
00326 extern struct displaced_step_closure *
00327   arm_displaced_step_copy_insn (struct gdbarch *, CORE_ADDR, CORE_ADDR,
00328                                 struct regcache *);
00329 extern void arm_displaced_step_fixup (struct gdbarch *,
00330                                       struct displaced_step_closure *,
00331                                       CORE_ADDR, CORE_ADDR, struct regcache *);
00332 
00333 /* Return the bit mask in ARM_PS_REGNUM that indicates Thumb mode.  */
00334 extern int arm_psr_thumb_bit (struct gdbarch *);
00335 
00336 /* Is the instruction at the given memory address a Thumb or ARM
00337    instruction?  */
00338 extern int arm_pc_is_thumb (struct gdbarch *, CORE_ADDR);
00339 
00340 extern int arm_process_record (struct gdbarch *gdbarch, 
00341                                struct regcache *regcache, CORE_ADDR addr);
00342 /* Functions exported from armbsd-tdep.h.  */
00343 
00344 /* Return the appropriate register set for the core section identified
00345    by SECT_NAME and SECT_SIZE.  */
00346 
00347 extern const struct regset *
00348   armbsd_regset_from_core_section (struct gdbarch *gdbarch,
00349                                    const char *sect_name, size_t sect_size);
00350 
00351 /* Target descriptions.  */
00352 extern struct target_desc *tdesc_arm_with_m;
00353 extern struct target_desc *tdesc_arm_with_iwmmxt;
00354 extern struct target_desc *tdesc_arm_with_vfpv2;
00355 extern struct target_desc *tdesc_arm_with_vfpv3;
00356 extern struct target_desc *tdesc_arm_with_neon;
00357 
00358 #endif /* arm-tdep.h */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines