arm.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /* Common target dependent code for GDB on ARM systems.
  2. Copyright (C) 1988-2022 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 ARCH_ARM_H
  15. #define ARCH_ARM_H
  16. #include "gdbsupport/tdesc.h"
  17. /* Prologue helper macros for ARMv8.1-m PACBTI. */
  18. #define IS_PAC(instruction) (instruction == 0xf3af801d)
  19. #define IS_PACBTI(instruction) (instruction == 0xf3af800d)
  20. #define IS_BTI(instruction) (instruction == 0xf3af800f)
  21. #define IS_PACG(instruction) ((instruction & 0xfff0f0f0) == 0xfb60f000)
  22. #define IS_AUT(instruction) (instruction == 0xf3af802d)
  23. #define IS_AUTG(instruction) ((instruction & 0xfff00ff0) == 0xfb500f00)
  24. /* DWARF register numbers according to the AADWARF32 document. */
  25. enum arm_dwarf_regnum {
  26. ARM_DWARF_RA_AUTH_CODE = 143
  27. };
  28. /* Register numbers of various important registers. */
  29. enum gdb_regnum {
  30. ARM_A1_REGNUM = 0, /* first integer-like argument */
  31. ARM_A4_REGNUM = 3, /* last integer-like argument */
  32. ARM_AP_REGNUM = 11,
  33. ARM_IP_REGNUM = 12,
  34. ARM_SP_REGNUM = 13, /* Contains address of top of stack */
  35. ARM_LR_REGNUM = 14, /* address to return to from a function call */
  36. ARM_PC_REGNUM = 15, /* Contains program counter */
  37. /* F0..F7 are the fp registers for the (obsolete) FPA architecture. */
  38. ARM_F0_REGNUM = 16, /* first floating point register */
  39. ARM_F3_REGNUM = 19, /* last floating point argument register */
  40. ARM_F7_REGNUM = 23, /* last floating point register */
  41. ARM_FPS_REGNUM = 24, /* floating point status register */
  42. ARM_PS_REGNUM = 25, /* Contains processor status */
  43. ARM_WR0_REGNUM, /* WMMX data registers. */
  44. ARM_WR15_REGNUM = ARM_WR0_REGNUM + 15,
  45. ARM_WC0_REGNUM, /* WMMX control registers. */
  46. ARM_WCSSF_REGNUM = ARM_WC0_REGNUM + 2,
  47. ARM_WCASF_REGNUM = ARM_WC0_REGNUM + 3,
  48. ARM_WC7_REGNUM = ARM_WC0_REGNUM + 7,
  49. ARM_WCGR0_REGNUM, /* WMMX general purpose registers. */
  50. ARM_WCGR3_REGNUM = ARM_WCGR0_REGNUM + 3,
  51. ARM_WCGR7_REGNUM = ARM_WCGR0_REGNUM + 7,
  52. ARM_D0_REGNUM, /* VFP double-precision registers. */
  53. ARM_D31_REGNUM = ARM_D0_REGNUM + 31,
  54. ARM_FPSCR_REGNUM,
  55. /* Other useful registers. */
  56. ARM_FP_REGNUM = 11, /* Frame register in ARM code, if used. */
  57. THUMB_FP_REGNUM = 7, /* Frame register in Thumb code, if used. */
  58. ARM_LAST_ARG_REGNUM = ARM_A4_REGNUM,
  59. ARM_LAST_FP_ARG_REGNUM = ARM_F3_REGNUM
  60. };
  61. /* Register count constants. */
  62. enum arm_register_counts {
  63. /* Number of Q registers for MVE. */
  64. ARM_MVE_NUM_Q_REGS = 8,
  65. /* Number of argument registers. */
  66. ARM_NUM_ARG_REGS = 4,
  67. /* Number of floating point argument registers. */
  68. ARM_NUM_FP_ARG_REGS = 4,
  69. /* Number of registers (old, defined as ARM_FPSCR_REGNUM + 1. */
  70. ARM_NUM_REGS = ARM_FPSCR_REGNUM + 1
  71. };
  72. /* Enum describing the different kinds of breakpoints. */
  73. enum arm_breakpoint_kinds
  74. {
  75. ARM_BP_KIND_THUMB = 2,
  76. ARM_BP_KIND_THUMB2 = 3,
  77. ARM_BP_KIND_ARM = 4,
  78. };
  79. /* Supported Arm FP hardware types. */
  80. enum arm_fp_type {
  81. ARM_FP_TYPE_NONE = 0,
  82. ARM_FP_TYPE_VFPV2,
  83. ARM_FP_TYPE_VFPV3,
  84. ARM_FP_TYPE_IWMMXT,
  85. ARM_FP_TYPE_INVALID
  86. };
  87. /* Supported M-profile Arm types. */
  88. enum arm_m_profile_type {
  89. ARM_M_TYPE_M_PROFILE,
  90. ARM_M_TYPE_VFP_D16,
  91. ARM_M_TYPE_WITH_FPA,
  92. ARM_M_TYPE_MVE,
  93. ARM_M_TYPE_INVALID
  94. };
  95. /* Instruction condition field values. */
  96. #define INST_EQ 0x0
  97. #define INST_NE 0x1
  98. #define INST_CS 0x2
  99. #define INST_CC 0x3
  100. #define INST_MI 0x4
  101. #define INST_PL 0x5
  102. #define INST_VS 0x6
  103. #define INST_VC 0x7
  104. #define INST_HI 0x8
  105. #define INST_LS 0x9
  106. #define INST_GE 0xa
  107. #define INST_LT 0xb
  108. #define INST_GT 0xc
  109. #define INST_LE 0xd
  110. #define INST_AL 0xe
  111. #define INST_NV 0xf
  112. #define FLAG_N 0x80000000
  113. #define FLAG_Z 0x40000000
  114. #define FLAG_C 0x20000000
  115. #define FLAG_V 0x10000000
  116. #define CPSR_T 0x20
  117. #define XPSR_T 0x01000000
  118. /* Size of registers. */
  119. #define ARM_INT_REGISTER_SIZE 4
  120. /* IEEE extended doubles are 80 bits. DWORD aligned they use 96 bits. */
  121. #define ARM_FP_REGISTER_SIZE 12
  122. #define ARM_VFP_REGISTER_SIZE 8
  123. #define IWMMXT_VEC_REGISTER_SIZE 8
  124. /* Size of register sets. */
  125. /* r0-r12,sp,lr,pc,cpsr. */
  126. #define ARM_CORE_REGS_SIZE (17 * ARM_INT_REGISTER_SIZE)
  127. /* f0-f8,fps. */
  128. #define ARM_FP_REGS_SIZE (8 * ARM_FP_REGISTER_SIZE + ARM_INT_REGISTER_SIZE)
  129. /* d0-d15,fpscr. */
  130. #define ARM_VFP2_REGS_SIZE (16 * ARM_VFP_REGISTER_SIZE + ARM_INT_REGISTER_SIZE)
  131. /* d0-d31,fpscr. */
  132. #define ARM_VFP3_REGS_SIZE (32 * ARM_VFP_REGISTER_SIZE + ARM_INT_REGISTER_SIZE)
  133. /* wR0-wR15,fpscr. */
  134. #define IWMMXT_REGS_SIZE (16 * IWMMXT_VEC_REGISTER_SIZE \
  135. + 6 * ARM_INT_REGISTER_SIZE)
  136. /* Addresses for calling Thumb functions have the bit 0 set.
  137. Here are some macros to test, set, or clear bit 0 of addresses. */
  138. #define IS_THUMB_ADDR(addr) ((addr) & 1)
  139. #define MAKE_THUMB_ADDR(addr) ((addr) | 1)
  140. #define UNMAKE_THUMB_ADDR(addr) ((addr) & ~1)
  141. /* Support routines for instruction parsing. */
  142. #define submask(x) ((1L << ((x) + 1)) - 1)
  143. #define bits(obj,st,fn) (((obj) >> (st)) & submask ((fn) - (st)))
  144. #define bit(obj,st) (((obj) >> (st)) & 1)
  145. #define sbits(obj,st,fn) \
  146. ((long) (bits(obj,st,fn) | ((long) bit(obj,fn) * ~ submask (fn - st))))
  147. #define BranchDest(addr,instr) \
  148. ((CORE_ADDR) (((unsigned long) (addr)) + 8 + (sbits (instr, 0, 23) << 2)))
  149. /* Forward declaration. */
  150. struct regcache;
  151. /* Return the size in bytes of the complete Thumb instruction whose
  152. first halfword is INST1. */
  153. int thumb_insn_size (unsigned short inst1);
  154. /* Returns true if the condition evaluates to true. */
  155. int condition_true (unsigned long cond, unsigned long status_reg);
  156. /* Return 1 if THIS_INSTR might change control flow, 0 otherwise. */
  157. int arm_instruction_changes_pc (uint32_t this_instr);
  158. /* Return 1 if the 16-bit Thumb instruction INST might change
  159. control flow, 0 otherwise. */
  160. int thumb_instruction_changes_pc (unsigned short inst);
  161. /* Return 1 if the 32-bit Thumb instruction in INST1 and INST2
  162. might change control flow, 0 otherwise. */
  163. int thumb2_instruction_changes_pc (unsigned short inst1, unsigned short inst2);
  164. /* Advance the state of the IT block and return that state. */
  165. int thumb_advance_itstate (unsigned int itstate);
  166. /* Decode shifted register value. */
  167. unsigned long shifted_reg_val (struct regcache *regcache,
  168. unsigned long inst,
  169. int carry,
  170. unsigned long pc_val,
  171. unsigned long status_reg);
  172. /* Create an Arm target description with the given FP hardware type. */
  173. target_desc *arm_create_target_description (arm_fp_type fp_type);
  174. /* Create an Arm M-profile target description with the given hardware type. */
  175. target_desc *arm_create_mprofile_target_description (arm_m_profile_type m_type);
  176. #endif /* ARCH_ARM_H */