gdb/arm-tdep.h - gdb

Data types defined

Macros defined

Source code

  1. /* Common target dependent code for GDB on ARM systems.
  2.    Copyright (C) 2002-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #ifndef ARM_TDEP_H
  15. #define ARM_TDEP_H

  16. /* Forward declarations.  */
  17. struct gdbarch;
  18. struct regset;
  19. struct address_space;

  20. /* Register numbers of various important registers.  */

  21. enum gdb_regnum {
  22.   ARM_A1_REGNUM = 0,                /* first integer-like argument */
  23.   ARM_A4_REGNUM = 3,                /* last integer-like argument */
  24.   ARM_AP_REGNUM = 11,
  25.   ARM_IP_REGNUM = 12,
  26.   ARM_SP_REGNUM = 13,                /* Contains address of top of stack */
  27.   ARM_LR_REGNUM = 14,                /* address to return to from a function call */
  28.   ARM_PC_REGNUM = 15,                /* Contains program counter */
  29.   ARM_F0_REGNUM = 16,                /* first floating point register */
  30.   ARM_F3_REGNUM = 19,                /* last floating point argument register */
  31.   ARM_F7_REGNUM = 23,                 /* last floating point register */
  32.   ARM_FPS_REGNUM = 24,                /* floating point status register */
  33.   ARM_PS_REGNUM = 25,                /* Contains processor status */
  34.   ARM_WR0_REGNUM,                /* WMMX data registers.  */
  35.   ARM_WR15_REGNUM = ARM_WR0_REGNUM + 15,
  36.   ARM_WC0_REGNUM,                /* WMMX control registers.  */
  37.   ARM_WCSSF_REGNUM = ARM_WC0_REGNUM + 2,
  38.   ARM_WCASF_REGNUM = ARM_WC0_REGNUM + 3,
  39.   ARM_WC7_REGNUM = ARM_WC0_REGNUM + 7,
  40.   ARM_WCGR0_REGNUM,                /* WMMX general purpose registers.  */
  41.   ARM_WCGR3_REGNUM = ARM_WCGR0_REGNUM + 3,
  42.   ARM_WCGR7_REGNUM = ARM_WCGR0_REGNUM + 7,
  43.   ARM_D0_REGNUM,                /* VFP double-precision registers.  */
  44.   ARM_D31_REGNUM = ARM_D0_REGNUM + 31,
  45.   ARM_FPSCR_REGNUM,

  46.   ARM_NUM_REGS,

  47.   /* Other useful registers.  */
  48.   ARM_FP_REGNUM = 11,                /* Frame register in ARM code, if used.  */
  49.   THUMB_FP_REGNUM = 7,                /* Frame register in Thumb code, if used.  */
  50.   ARM_NUM_ARG_REGS = 4,
  51.   ARM_LAST_ARG_REGNUM = ARM_A4_REGNUM,
  52.   ARM_NUM_FP_ARG_REGS = 4,
  53.   ARM_LAST_FP_ARG_REGNUM = ARM_F3_REGNUM
  54. };

  55. /* Size of integer registers.  */
  56. #define INT_REGISTER_SIZE                4

  57. /* Say how long FP registers are.  Used for documentation purposes and
  58.    code readability in this header.  IEEE extended doubles are 80
  59.    bits.  DWORD aligned they use 96 bits.  */
  60. #define FP_REGISTER_SIZE        12

  61. /* Say how long VFP double precision registers are.  Used for documentation
  62.    purposes and code readability.  These are fixed at 64 bits.  */
  63. #define VFP_REGISTER_SIZE        8

  64. /* Number of machine registers.  The only define actually required
  65.    is gdbarch_num_regs.  The other definitions are used for documentation
  66.    purposes and code readability.  */
  67. /* For 26 bit ARM code, a fake copy of the PC is placed in register 25 (PS)
  68.    (and called PS for processor status) so the status bits can be cleared
  69.    from the PC (register 15).  For 32 bit ARM code, a copy of CPSR is placed
  70.    in PS.  */
  71. #define NUM_FREGS        8        /* Number of floating point registers.  */
  72. #define NUM_SREGS        2        /* Number of status registers.  */
  73. #define NUM_GREGS        16        /* Number of general purpose registers.  */


  74. /* Instruction condition field values.  */
  75. #define INST_EQ                0x0
  76. #define INST_NE                0x1
  77. #define INST_CS                0x2
  78. #define INST_CC                0x3
  79. #define INST_MI                0x4
  80. #define INST_PL                0x5
  81. #define INST_VS                0x6
  82. #define INST_VC                0x7
  83. #define INST_HI                0x8
  84. #define INST_LS                0x9
  85. #define INST_GE                0xa
  86. #define INST_LT                0xb
  87. #define INST_GT                0xc
  88. #define INST_LE                0xd
  89. #define INST_AL                0xe
  90. #define INST_NV                0xf

  91. #define FLAG_N                0x80000000
  92. #define FLAG_Z                0x40000000
  93. #define FLAG_C                0x20000000
  94. #define FLAG_V                0x10000000

  95. #define CPSR_T                0x20

  96. #define XPSR_T                0x01000000

  97. /* Type of floating-point code in use by inferior.  There are really 3 models
  98.    that are traditionally supported (plus the endianness issue), but gcc can
  99.    only generate 2 of those.  The third is APCS_FLOAT, where arguments to
  100.    functions are passed in floating-point registers.

  101.    In addition to the traditional models, VFP adds two more.

  102.    If you update this enum, don't forget to update fp_model_strings in
  103.    arm-tdep.c.  */

  104. enum arm_float_model
  105. {
  106.   ARM_FLOAT_AUTO,        /* Automatic detection.  Do not set in tdep.  */
  107.   ARM_FLOAT_SOFT_FPA,        /* Traditional soft-float (mixed-endian on LE ARM).  */
  108.   ARM_FLOAT_FPA,        /* FPA co-processor.  GCC calling convention.  */
  109.   ARM_FLOAT_SOFT_VFP,        /* Soft-float with pure-endian doubles.  */
  110.   ARM_FLOAT_VFP,        /* Full VFP calling convention.  */
  111.   ARM_FLOAT_LAST        /* Keep at end.  */
  112. };

  113. /* ABI used by the inferior.  */
  114. enum arm_abi_kind
  115. {
  116.   ARM_ABI_AUTO,
  117.   ARM_ABI_APCS,
  118.   ARM_ABI_AAPCS,
  119.   ARM_ABI_LAST
  120. };

  121. /* Convention for returning structures.  */

  122. enum struct_return
  123. {
  124.   pcc_struct_return,                /* Return "short" structures in memory.  */
  125.   reg_struct_return                /* Return "short" structures in registers.  */
  126. };

  127. /* Target-dependent structure in gdbarch.  */
  128. struct gdbarch_tdep
  129. {
  130.   /* The ABI for this architecture.  It should never be set to
  131.      ARM_ABI_AUTO.  */
  132.   enum arm_abi_kind arm_abi;

  133.   enum arm_float_model fp_model; /* Floating point calling conventions.  */

  134.   int have_fpa_registers;        /* Does the target report the FPA registers?  */
  135.   int have_vfp_registers;        /* Does the target report the VFP registers?  */
  136.   int have_vfp_pseudos;                /* Are we synthesizing the single precision
  137.                                    VFP registers?  */
  138.   int have_neon_pseudos;        /* Are we synthesizing the quad precision
  139.                                    NEON registers?  Requires
  140.                                    have_vfp_pseudos.  */
  141.   int have_neon;                /* Do we have a NEON unit?  */

  142.   int is_m;                        /* Does the target follow the "M" profile.  */
  143.   CORE_ADDR lowest_pc;                /* Lowest address at which instructions
  144.                                    will appear.  */

  145.   const gdb_byte *arm_breakpoint;        /* Breakpoint pattern for an ARM insn.  */
  146.   int arm_breakpoint_size;        /* And its size.  */
  147.   const gdb_byte *thumb_breakpoint;        /* Breakpoint pattern for a Thumb insn.  */
  148.   int thumb_breakpoint_size;        /* And its size.  */

  149.   /* If the Thumb breakpoint is an undefined instruction (which is
  150.      affected by IT blocks) rather than a BKPT instruction (which is
  151.      not), then we need a 32-bit Thumb breakpoint to preserve the
  152.      instruction count in IT blocks.  */
  153.   const gdb_byte *thumb2_breakpoint;
  154.   int thumb2_breakpoint_size;

  155.   int jb_pc;                        /* Offset to PC value in jump buffer.
  156.                                    If this is negative, longjmp support
  157.                                    will be disabled.  */
  158.   size_t jb_elt_size;                /* And the size of each entry in the buf.  */

  159.   /* Convention for returning structures.  */
  160.   enum struct_return struct_return;

  161.   /* ISA-specific data types.  */
  162.   struct type *arm_ext_type;
  163.   struct type *neon_double_type;
  164.   struct type *neon_quad_type;

  165.   /* Return the expected next PC if FRAME is stopped at a syscall
  166.      instruction.  */
  167.   CORE_ADDR (*syscall_next_pc) (struct frame_info *frame);

  168.    /* syscall record.  */
  169.   int (*arm_syscall_record) (struct regcache *regcache, unsigned long svc_number);
  170. };

  171. /* Structures used for displaced stepping.  */

  172. /* The maximum number of temporaries available for displaced instructions.  */
  173. #define DISPLACED_TEMPS                        16
  174. /* The maximum number of modified instructions generated for one single-stepped
  175.    instruction, including the breakpoint (usually at the end of the instruction
  176.    sequence) and any scratch words, etc.  */
  177. #define DISPLACED_MODIFIED_INSNS        8

  178. struct displaced_step_closure
  179. {
  180.   ULONGEST tmp[DISPLACED_TEMPS];
  181.   int rd;
  182.   int wrote_to_pc;
  183.   union
  184.   {
  185.     struct
  186.     {
  187.       int xfersize;
  188.       int rn;                           /* Writeback register.  */
  189.       unsigned int immed : 1;      /* Offset is immediate.  */
  190.       unsigned int writeback : 1/* Perform base-register writeback.  */
  191.       unsigned int restore_r4 : 1; /* Used r4 as scratch.  */
  192.     } ldst;

  193.     struct
  194.     {
  195.       unsigned long dest;
  196.       unsigned int link : 1;
  197.       unsigned int exchange : 1;
  198.       unsigned int cond : 4;
  199.     } branch;

  200.     struct
  201.     {
  202.       unsigned int regmask;
  203.       int rn;
  204.       CORE_ADDR xfer_addr;
  205.       unsigned int load : 1;
  206.       unsigned int user : 1;
  207.       unsigned int increment : 1;
  208.       unsigned int before : 1;
  209.       unsigned int writeback : 1;
  210.       unsigned int cond : 4;
  211.     } block;

  212.     struct
  213.     {
  214.       unsigned int immed : 1;
  215.     } preload;

  216.     struct
  217.     {
  218.       /* If non-NULL, override generic SVC handling (e.g. for a particular
  219.          OS).  */
  220.       int (*copy_svc_os) (struct gdbarch *gdbarch, struct regcache *regs,
  221.                           struct displaced_step_closure *dsc);
  222.     } svc;
  223.   } u;

  224.   /* The size of original instruction, 2 or 4.  */
  225.   unsigned int insn_size;
  226.   /* True if the original insn (and thus all replacement insns) are Thumb
  227.      instead of ARM.   */
  228.   unsigned int is_thumb;

  229.   /* The slots in the array is used in this way below,
  230.      - ARM instruction occupies one slot,
  231.      - Thumb 16 bit instruction occupies one slot,
  232.      - Thumb 32-bit instruction occupies *two* slots, one part for each.  */
  233.   unsigned long modinsn[DISPLACED_MODIFIED_INSNS];
  234.   int numinsns;
  235.   CORE_ADDR insn_addr;
  236.   CORE_ADDR scratch_base;
  237.   void (*cleanup) (struct gdbarch *, struct regcache *,
  238.                    struct displaced_step_closure *);
  239. };

  240. /* Values for the WRITE_PC argument to displaced_write_reg.  If the register
  241.    write may write to the PC, specifies the way the CPSR T bit, etc. is
  242.    modified by the instruction.  */

  243. enum pc_write_style
  244. {
  245.   BRANCH_WRITE_PC,
  246.   BX_WRITE_PC,
  247.   LOAD_WRITE_PC,
  248.   ALU_WRITE_PC,
  249.   CANNOT_WRITE_PC
  250. };

  251. extern void
  252.   arm_process_displaced_insn (struct gdbarch *gdbarch, CORE_ADDR from,
  253.                               CORE_ADDR to, struct regcache *regs,
  254.                               struct displaced_step_closure *dsc);
  255. extern void
  256.   arm_displaced_init_closure (struct gdbarch *gdbarch, CORE_ADDR from,
  257.                               CORE_ADDR to, struct displaced_step_closure *dsc);
  258. extern ULONGEST
  259.   displaced_read_reg (struct regcache *regs, struct displaced_step_closure *dsc,
  260.                       int regno);
  261. extern void
  262.   displaced_write_reg (struct regcache *regs,
  263.                        struct displaced_step_closure *dsc, int regno,
  264.                        ULONGEST val, enum pc_write_style write_pc);

  265. CORE_ADDR arm_skip_stub (struct frame_info *, CORE_ADDR);
  266. CORE_ADDR arm_get_next_pc (struct frame_info *, CORE_ADDR);
  267. void arm_insert_single_step_breakpoint (struct gdbarch *,
  268.                                         struct address_space *, CORE_ADDR);
  269. int arm_deal_with_atomic_sequence (struct frame_info *);
  270. int arm_software_single_step (struct frame_info *);
  271. int arm_frame_is_thumb (struct frame_info *frame);

  272. extern struct displaced_step_closure *
  273.   arm_displaced_step_copy_insn (struct gdbarch *, CORE_ADDR, CORE_ADDR,
  274.                                 struct regcache *);
  275. extern void arm_displaced_step_fixup (struct gdbarch *,
  276.                                       struct displaced_step_closure *,
  277.                                       CORE_ADDR, CORE_ADDR, struct regcache *);

  278. /* Return the bit mask in ARM_PS_REGNUM that indicates Thumb mode.  */
  279. extern int arm_psr_thumb_bit (struct gdbarch *);

  280. /* Is the instruction at the given memory address a Thumb or ARM
  281.    instruction?  */
  282. extern int arm_pc_is_thumb (struct gdbarch *, CORE_ADDR);

  283. extern int arm_process_record (struct gdbarch *gdbarch,
  284.                                struct regcache *regcache, CORE_ADDR addr);
  285. /* Functions exported from armbsd-tdep.h.  */

  286. /* Return the appropriate register set for the core section identified
  287.    by SECT_NAME and SECT_SIZE.  */

  288. extern void
  289.   armbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
  290.                                        iterate_over_regset_sections_cb *cb,
  291.                                        void *cb_data,
  292.                                        const struct regcache *regcache);

  293. /* Target descriptions.  */
  294. extern struct target_desc *tdesc_arm_with_m;
  295. extern struct target_desc *tdesc_arm_with_iwmmxt;
  296. extern struct target_desc *tdesc_arm_with_vfpv2;
  297. extern struct target_desc *tdesc_arm_with_vfpv3;
  298. extern struct target_desc *tdesc_arm_with_neon;

  299. #endif /* arm-tdep.h */