arm-tdep.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /* Common target dependent code for GDB on ARM systems.
  2. Copyright (C) 2002-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 ARM_TDEP_H
  15. #define ARM_TDEP_H
  16. /* Forward declarations. */
  17. struct regset;
  18. struct address_space;
  19. struct get_next_pcs;
  20. struct arm_get_next_pcs;
  21. struct gdb_get_next_pcs;
  22. /* Set to true if the 32-bit mode is in use. */
  23. extern bool arm_apcs_32;
  24. #include "gdbarch.h"
  25. #include "arch/arm.h"
  26. #include "infrun.h"
  27. #include <vector>
  28. /* Number of machine registers. The only define actually required
  29. is gdbarch_num_regs. The other definitions are used for documentation
  30. purposes and code readability. */
  31. /* For 26 bit ARM code, a fake copy of the PC is placed in register 25 (PS)
  32. (and called PS for processor status) so the status bits can be cleared
  33. from the PC (register 15). For 32 bit ARM code, a copy of CPSR is placed
  34. in PS. */
  35. #define NUM_FREGS 8 /* Number of floating point registers. */
  36. #define NUM_SREGS 2 /* Number of status registers. */
  37. #define NUM_GREGS 16 /* Number of general purpose registers. */
  38. /* Type of floating-point code in use by inferior. There are really 3 models
  39. that are traditionally supported (plus the endianness issue), but gcc can
  40. only generate 2 of those. The third is APCS_FLOAT, where arguments to
  41. functions are passed in floating-point registers.
  42. In addition to the traditional models, VFP adds two more.
  43. If you update this enum, don't forget to update fp_model_strings in
  44. arm-tdep.c. */
  45. enum arm_float_model
  46. {
  47. ARM_FLOAT_AUTO, /* Automatic detection. Do not set in tdep. */
  48. ARM_FLOAT_SOFT_FPA, /* Traditional soft-float (mixed-endian on LE ARM). */
  49. ARM_FLOAT_FPA, /* FPA co-processor. GCC calling convention. */
  50. ARM_FLOAT_SOFT_VFP, /* Soft-float with pure-endian doubles. */
  51. ARM_FLOAT_VFP, /* Full VFP calling convention. */
  52. ARM_FLOAT_LAST /* Keep at end. */
  53. };
  54. /* ABI used by the inferior. */
  55. enum arm_abi_kind
  56. {
  57. ARM_ABI_AUTO,
  58. ARM_ABI_APCS,
  59. ARM_ABI_AAPCS,
  60. ARM_ABI_LAST
  61. };
  62. /* Convention for returning structures. */
  63. enum struct_return
  64. {
  65. pcc_struct_return, /* Return "short" structures in memory. */
  66. reg_struct_return /* Return "short" structures in registers. */
  67. };
  68. /* Target-dependent structure in gdbarch. */
  69. struct arm_gdbarch_tdep : gdbarch_tdep
  70. {
  71. /* The ABI for this architecture. It should never be set to
  72. ARM_ABI_AUTO. */
  73. enum arm_abi_kind arm_abi {};
  74. enum arm_float_model fp_model {}; /* Floating point calling conventions. */
  75. bool have_fpa_registers = false; /* Does the target report the FPA registers? */
  76. bool have_wmmx_registers = false; /* Does the target report the WMMX registers? */
  77. /* The number of VFP registers reported by the target. It is zero
  78. if VFP registers are not supported. */
  79. int vfp_register_count = 0;
  80. bool have_s_pseudos = false; /* Are we synthesizing the single precision
  81. VFP registers? */
  82. int s_pseudo_base = 0; /* Register number for the first S pseudo
  83. register. */
  84. int s_pseudo_count = 0; /* Number of S pseudo registers. */
  85. bool have_q_pseudos = false; /* Are we synthesizing the quad precision
  86. Q (NEON or MVE) registers? Requires
  87. have_s_pseudos. */
  88. int q_pseudo_base = 0; /* Register number for the first quad
  89. precision pseudo register. */
  90. int q_pseudo_count = 0; /* Number of quad precision pseudo
  91. registers. */
  92. bool have_neon = false; /* Do we have a NEON unit? */
  93. bool have_mve = false; /* Do we have a MVE extension? */
  94. int mve_vpr_regnum = 0; /* MVE VPR register number. */
  95. int mve_pseudo_base = 0; /* Number of the first MVE pseudo register. */
  96. int mve_pseudo_count = 0; /* Total number of MVE pseudo registers. */
  97. bool have_pacbti = false; /* True if we have the ARMv8.1-m PACBTI
  98. extensions. */
  99. int pacbti_pseudo_base = 0; /* Number of the first PACBTI pseudo
  100. register. */
  101. int pacbti_pseudo_count = 0; /* Total number of PACBTI pseudo registers. */
  102. bool is_m = false; /* Does the target follow the "M" profile. */
  103. CORE_ADDR lowest_pc = 0; /* Lowest address at which instructions
  104. will appear. */
  105. const gdb_byte *arm_breakpoint = nullptr; /* Breakpoint pattern for an ARM insn. */
  106. int arm_breakpoint_size = 0; /* And its size. */
  107. const gdb_byte *thumb_breakpoint = nullptr; /* Breakpoint pattern for a Thumb insn. */
  108. int thumb_breakpoint_size = 0; /* And its size. */
  109. /* If the Thumb breakpoint is an undefined instruction (which is
  110. affected by IT blocks) rather than a BKPT instruction (which is
  111. not), then we need a 32-bit Thumb breakpoint to preserve the
  112. instruction count in IT blocks. */
  113. const gdb_byte *thumb2_breakpoint = nullptr;
  114. int thumb2_breakpoint_size = 0;
  115. int jb_pc = 0; /* Offset to PC value in jump buffer.
  116. If this is negative, longjmp support
  117. will be disabled. */
  118. size_t jb_elt_size = 0; /* And the size of each entry in the buf. */
  119. /* Convention for returning structures. */
  120. enum struct_return struct_return {};
  121. /* ISA-specific data types. */
  122. struct type *arm_ext_type = nullptr;
  123. struct type *neon_double_type = nullptr;
  124. struct type *neon_quad_type = nullptr;
  125. /* syscall record. */
  126. int (*arm_syscall_record) (struct regcache *regcache,
  127. unsigned long svc_number) = nullptr;
  128. };
  129. /* Structures used for displaced stepping. */
  130. /* The maximum number of temporaries available for displaced instructions. */
  131. #define DISPLACED_TEMPS 16
  132. /* The maximum number of modified instructions generated for one single-stepped
  133. instruction, including the breakpoint (usually at the end of the instruction
  134. sequence) and any scratch words, etc. */
  135. #define ARM_DISPLACED_MODIFIED_INSNS 8
  136. struct arm_displaced_step_copy_insn_closure
  137. : public displaced_step_copy_insn_closure
  138. {
  139. ULONGEST tmp[DISPLACED_TEMPS];
  140. int rd;
  141. int wrote_to_pc;
  142. union
  143. {
  144. struct
  145. {
  146. int xfersize;
  147. int rn; /* Writeback register. */
  148. unsigned int immed : 1; /* Offset is immediate. */
  149. unsigned int writeback : 1; /* Perform base-register writeback. */
  150. unsigned int restore_r4 : 1; /* Used r4 as scratch. */
  151. } ldst;
  152. struct
  153. {
  154. unsigned long dest;
  155. unsigned int link : 1;
  156. unsigned int exchange : 1;
  157. unsigned int cond : 4;
  158. } branch;
  159. struct
  160. {
  161. unsigned int regmask;
  162. int rn;
  163. CORE_ADDR xfer_addr;
  164. unsigned int load : 1;
  165. unsigned int user : 1;
  166. unsigned int increment : 1;
  167. unsigned int before : 1;
  168. unsigned int writeback : 1;
  169. unsigned int cond : 4;
  170. } block;
  171. struct
  172. {
  173. unsigned int immed : 1;
  174. } preload;
  175. struct
  176. {
  177. /* If non-NULL, override generic SVC handling (e.g. for a particular
  178. OS). */
  179. int (*copy_svc_os) (struct gdbarch *gdbarch, struct regcache *regs,
  180. arm_displaced_step_copy_insn_closure *dsc);
  181. } svc;
  182. } u;
  183. /* The size of original instruction, 2 or 4. */
  184. unsigned int insn_size;
  185. /* True if the original insn (and thus all replacement insns) are Thumb
  186. instead of ARM. */
  187. unsigned int is_thumb;
  188. /* The slots in the array is used in this way below,
  189. - ARM instruction occupies one slot,
  190. - Thumb 16 bit instruction occupies one slot,
  191. - Thumb 32-bit instruction occupies *two* slots, one part for each. */
  192. unsigned long modinsn[ARM_DISPLACED_MODIFIED_INSNS];
  193. int numinsns;
  194. CORE_ADDR insn_addr;
  195. CORE_ADDR scratch_base;
  196. void (*cleanup) (struct gdbarch *, struct regcache *,
  197. arm_displaced_step_copy_insn_closure *);
  198. };
  199. /* Values for the WRITE_PC argument to displaced_write_reg. If the register
  200. write may write to the PC, specifies the way the CPSR T bit, etc. is
  201. modified by the instruction. */
  202. enum pc_write_style
  203. {
  204. BRANCH_WRITE_PC,
  205. BX_WRITE_PC,
  206. LOAD_WRITE_PC,
  207. ALU_WRITE_PC,
  208. CANNOT_WRITE_PC
  209. };
  210. extern void
  211. arm_process_displaced_insn (struct gdbarch *gdbarch, CORE_ADDR from,
  212. CORE_ADDR to, struct regcache *regs,
  213. arm_displaced_step_copy_insn_closure *dsc);
  214. extern void
  215. arm_displaced_init_closure (struct gdbarch *gdbarch, CORE_ADDR from,
  216. CORE_ADDR to,
  217. arm_displaced_step_copy_insn_closure *dsc);
  218. extern ULONGEST
  219. displaced_read_reg (regcache *regs, arm_displaced_step_copy_insn_closure *dsc,
  220. int regno);
  221. extern void
  222. displaced_write_reg (struct regcache *regs,
  223. arm_displaced_step_copy_insn_closure *dsc, int regno,
  224. ULONGEST val, enum pc_write_style write_pc);
  225. CORE_ADDR arm_skip_stub (struct frame_info *, CORE_ADDR);
  226. ULONGEST arm_get_next_pcs_read_memory_unsigned_integer (CORE_ADDR memaddr,
  227. int len,
  228. int byte_order);
  229. CORE_ADDR arm_get_next_pcs_addr_bits_remove (struct arm_get_next_pcs *self,
  230. CORE_ADDR val);
  231. int arm_get_next_pcs_is_thumb (struct arm_get_next_pcs *self);
  232. std::vector<CORE_ADDR> arm_software_single_step (struct regcache *);
  233. int arm_is_thumb (struct regcache *regcache);
  234. int arm_frame_is_thumb (struct frame_info *frame);
  235. extern void arm_displaced_step_fixup (struct gdbarch *,
  236. displaced_step_copy_insn_closure *,
  237. CORE_ADDR, CORE_ADDR, struct regcache *);
  238. /* Return the bit mask in ARM_PS_REGNUM that indicates Thumb mode. */
  239. extern int arm_psr_thumb_bit (struct gdbarch *);
  240. /* Is the instruction at the given memory address a Thumb or ARM
  241. instruction? */
  242. extern int arm_pc_is_thumb (struct gdbarch *, CORE_ADDR);
  243. extern int arm_process_record (struct gdbarch *gdbarch,
  244. struct regcache *regcache, CORE_ADDR addr);
  245. /* Functions exported from arm-bsd-tdep.h. */
  246. /* Return the appropriate register set for the core section identified
  247. by SECT_NAME and SECT_SIZE. */
  248. extern void
  249. armbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
  250. iterate_over_regset_sections_cb *cb,
  251. void *cb_data,
  252. const struct regcache *regcache);
  253. /* Get the correct Arm target description with given FP hardware type. */
  254. const target_desc *arm_read_description (arm_fp_type fp_type);
  255. /* Get the correct Arm M-Profile target description with given hardware
  256. type. */
  257. const target_desc *arm_read_mprofile_description (arm_m_profile_type m_type);
  258. #endif /* arm-tdep.h */