ppc-tdep.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. /* Target-dependent code for GDB, the GNU debugger.
  2. Copyright (C) 2000-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 PPC_TDEP_H
  15. #define PPC_TDEP_H
  16. #include "gdbarch.h"
  17. struct gdbarch;
  18. struct frame_info;
  19. struct value;
  20. struct regcache;
  21. struct type;
  22. /* From ppc-sysv-tdep.c ... */
  23. enum return_value_convention ppc_sysv_abi_return_value (struct gdbarch *gdbarch,
  24. struct value *function,
  25. struct type *valtype,
  26. struct regcache *regcache,
  27. gdb_byte *readbuf,
  28. const gdb_byte *writebuf);
  29. enum return_value_convention ppc_sysv_abi_broken_return_value (struct gdbarch *gdbarch,
  30. struct value *function,
  31. struct type *valtype,
  32. struct regcache *regcache,
  33. gdb_byte *readbuf,
  34. const gdb_byte *writebuf);
  35. CORE_ADDR ppc_sysv_abi_push_dummy_call
  36. (struct gdbarch *gdbarch, struct value *function, struct regcache *regcache,
  37. CORE_ADDR bp_addr, int nargs, struct value **args, CORE_ADDR sp,
  38. function_call_return_method return_method, CORE_ADDR struct_addr);
  39. CORE_ADDR ppc64_sysv_abi_push_dummy_call
  40. (struct gdbarch *gdbarch, struct value *function, struct regcache *regcache,
  41. CORE_ADDR bp_addr, int nargs, struct value **args, CORE_ADDR sp,
  42. function_call_return_method return_method, CORE_ADDR struct_addr);
  43. enum return_value_convention ppc64_sysv_abi_return_value (struct gdbarch *gdbarch,
  44. struct value *function,
  45. struct type *valtype,
  46. struct regcache *regcache,
  47. gdb_byte *readbuf,
  48. const gdb_byte *writebuf);
  49. /* From rs6000-tdep.c... */
  50. int altivec_register_p (struct gdbarch *gdbarch, int regno);
  51. int vsx_register_p (struct gdbarch *gdbarch, int regno);
  52. int spe_register_p (struct gdbarch *gdbarch, int regno);
  53. /* Return non-zero if the architecture described by GDBARCH has
  54. floating-point registers (f0 --- f31 and fpscr). */
  55. int ppc_floating_point_unit_p (struct gdbarch *gdbarch);
  56. /* Return non-zero if the architecture described by GDBARCH has
  57. Altivec registers (vr0 --- vr31, vrsave and vscr). */
  58. int ppc_altivec_support_p (struct gdbarch *gdbarch);
  59. /* Return non-zero if the architecture described by GDBARCH has
  60. VSX registers (vsr0 --- vsr63). */
  61. int vsx_support_p (struct gdbarch *gdbarch);
  62. std::vector<CORE_ADDR> ppc_deal_with_atomic_sequence
  63. (struct regcache *regcache);
  64. /* Register set description. */
  65. struct ppc_reg_offsets
  66. {
  67. /* General-purpose registers. */
  68. int r0_offset;
  69. int gpr_size; /* size for r0-31, pc, ps, lr, ctr. */
  70. int xr_size; /* size for cr, xer, mq. */
  71. int pc_offset;
  72. int ps_offset;
  73. int cr_offset;
  74. int lr_offset;
  75. int ctr_offset;
  76. int xer_offset;
  77. int mq_offset;
  78. /* Floating-point registers. */
  79. int f0_offset;
  80. int fpscr_offset;
  81. int fpscr_size;
  82. };
  83. extern void ppc_supply_reg (struct regcache *regcache, int regnum,
  84. const gdb_byte *regs, size_t offset, int regsize);
  85. extern void ppc_collect_reg (const struct regcache *regcache, int regnum,
  86. gdb_byte *regs, size_t offset, int regsize);
  87. /* Supply register REGNUM in the general-purpose register set REGSET
  88. from the buffer specified by GREGS and LEN to register cache
  89. REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
  90. extern void ppc_supply_gregset (const struct regset *regset,
  91. struct regcache *regcache,
  92. int regnum, const void *gregs, size_t len);
  93. /* Supply register REGNUM in the floating-point register set REGSET
  94. from the buffer specified by FPREGS and LEN to register cache
  95. REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
  96. extern void ppc_supply_fpregset (const struct regset *regset,
  97. struct regcache *regcache,
  98. int regnum, const void *fpregs, size_t len);
  99. /* Supply register REGNUM in the Altivec register set REGSET
  100. from the buffer specified by VRREGS and LEN to register cache
  101. REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
  102. extern void ppc_supply_vrregset (const struct regset *regset,
  103. struct regcache *regcache,
  104. int regnum, const void *vrregs, size_t len);
  105. /* Supply register REGNUM in the VSX register set REGSET
  106. from the buffer specified by VSXREGS and LEN to register cache
  107. REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
  108. extern void ppc_supply_vsxregset (const struct regset *regset,
  109. struct regcache *regcache,
  110. int regnum, const void *vsxregs, size_t len);
  111. /* Collect register REGNUM in the general-purpose register set
  112. REGSET, from register cache REGCACHE into the buffer specified by
  113. GREGS and LEN. If REGNUM is -1, do this for all registers in
  114. REGSET. */
  115. extern void ppc_collect_gregset (const struct regset *regset,
  116. const struct regcache *regcache,
  117. int regnum, void *gregs, size_t len);
  118. /* Collect register REGNUM in the floating-point register set
  119. REGSET, from register cache REGCACHE into the buffer specified by
  120. FPREGS and LEN. If REGNUM is -1, do this for all registers in
  121. REGSET. */
  122. extern void ppc_collect_fpregset (const struct regset *regset,
  123. const struct regcache *regcache,
  124. int regnum, void *fpregs, size_t len);
  125. /* Collect register REGNUM in the Altivec register set
  126. REGSET from register cache REGCACHE into the buffer specified by
  127. VRREGS and LEN. If REGNUM is -1, do this for all registers in
  128. REGSET. */
  129. extern void ppc_collect_vrregset (const struct regset *regset,
  130. const struct regcache *regcache,
  131. int regnum, void *vrregs, size_t len);
  132. /* Collect register REGNUM in the VSX register set
  133. REGSET from register cache REGCACHE into the buffer specified by
  134. VSXREGS and LEN. If REGNUM is -1, do this for all registers in
  135. REGSET. */
  136. extern void ppc_collect_vsxregset (const struct regset *regset,
  137. const struct regcache *regcache,
  138. int regnum, void *vsxregs, size_t len);
  139. /* Private data that this module attaches to struct gdbarch. */
  140. /* ELF ABI version used by the inferior. */
  141. enum powerpc_elf_abi
  142. {
  143. POWERPC_ELF_AUTO,
  144. POWERPC_ELF_V1,
  145. POWERPC_ELF_V2,
  146. POWERPC_ELF_LAST
  147. };
  148. /* Vector ABI used by the inferior. */
  149. enum powerpc_vector_abi
  150. {
  151. POWERPC_VEC_AUTO,
  152. POWERPC_VEC_GENERIC,
  153. POWERPC_VEC_ALTIVEC,
  154. POWERPC_VEC_SPE,
  155. POWERPC_VEC_LAST
  156. };
  157. /* long double ABI version used by the inferior. */
  158. enum powerpc_long_double_abi
  159. {
  160. POWERPC_LONG_DOUBLE_AUTO,
  161. POWERPC_LONG_DOUBLE_IBM128,
  162. POWERPC_LONG_DOUBLE_IEEE128,
  163. POWERPC_LONG_DOUBLE_LAST
  164. };
  165. struct ppc_gdbarch_tdep : gdbarch_tdep
  166. {
  167. int wordsize = 0; /* Size in bytes of fixed-point word. */
  168. int soft_float = 0; /* Avoid FP registers for arguments? */
  169. enum powerpc_elf_abi elf_abi {}; /* ELF ABI version. */
  170. /* Format to use for the "long double" data type. */
  171. enum powerpc_long_double_abi long_double_abi {};
  172. /* How to pass vector arguments. Never set to AUTO or LAST. */
  173. enum powerpc_vector_abi vector_abi {};
  174. int ppc_gp0_regnum = 0; /* GPR register 0 */
  175. int ppc_toc_regnum = 0; /* TOC register */
  176. int ppc_ps_regnum = 0; /* Processor (or machine) status (%msr) */
  177. int ppc_cr_regnum = 0; /* Condition register */
  178. int ppc_lr_regnum = 0; /* Link register */
  179. int ppc_ctr_regnum = 0; /* Count register */
  180. int ppc_xer_regnum = 0; /* Integer exception register */
  181. /* Not all PPC and RS6000 variants will have the registers
  182. represented below. A -1 is used to indicate that the register
  183. is not present in this variant. */
  184. /* Floating-point registers. */
  185. int ppc_fp0_regnum = 0; /* Floating-point register 0. */
  186. int ppc_fpscr_regnum = 0; /* fp status and condition register. */
  187. /* Multiplier-Quotient Register (older POWER architectures only). */
  188. int ppc_mq_regnum = 0;
  189. /* POWER7 VSX registers. */
  190. int ppc_vsr0_regnum = 0; /* First VSX register. */
  191. int ppc_vsr0_upper_regnum = 0; /* First right most dword vsx register. */
  192. int ppc_efpr0_regnum = 0; /* First Extended FP register. */
  193. /* Altivec registers. */
  194. int ppc_vr0_regnum = 0; /* First AltiVec register. */
  195. int ppc_vrsave_regnum = 0; /* Last AltiVec register. */
  196. /* Altivec pseudo-register vX aliases for the raw vrX
  197. registers. */
  198. int ppc_v0_alias_regnum = 0;
  199. /* SPE registers. */
  200. int ppc_ev0_upper_regnum = 0; /* First GPR upper half register. */
  201. int ppc_ev0_regnum = 0; /* First ev register. */
  202. int ppc_acc_regnum = 0; /* SPE 'acc' register. */
  203. int ppc_spefscr_regnum = 0; /* SPE 'spefscr' register. */
  204. /* Program Priority Register. */
  205. int ppc_ppr_regnum = 0;
  206. /* Data Stream Control Register. */
  207. int ppc_dscr_regnum = 0;
  208. /* Target Address Register. */
  209. int ppc_tar_regnum = 0;
  210. /* Decimal 128 registers. */
  211. int ppc_dl0_regnum = 0; /* First Decimal128 argument register pair. */
  212. int have_ebb = 0;
  213. /* PMU registers. */
  214. int ppc_mmcr0_regnum = 0;
  215. int ppc_mmcr2_regnum = 0;
  216. int ppc_siar_regnum = 0;
  217. int ppc_sdar_regnum = 0;
  218. int ppc_sier_regnum = 0;
  219. /* Hardware Transactional Memory registers. */
  220. int have_htm_spr = 0;
  221. int have_htm_core = 0;
  222. int have_htm_fpu = 0;
  223. int have_htm_altivec = 0;
  224. int have_htm_vsx = 0;
  225. int ppc_cppr_regnum = 0;
  226. int ppc_cdscr_regnum = 0;
  227. int ppc_ctar_regnum = 0;
  228. /* HTM pseudo registers. */
  229. int ppc_cdl0_regnum = 0;
  230. int ppc_cvsr0_regnum = 0;
  231. int ppc_cefpr0_regnum = 0;
  232. /* Offset to ABI specific location where link register is saved. */
  233. int lr_frame_offset = 0;
  234. /* An array of integers, such that sim_regno[I] is the simulator
  235. register number for GDB register number I, or -1 if the
  236. simulator does not implement that register. */
  237. int *sim_regno = nullptr;
  238. /* ISA-specific types. */
  239. struct type *ppc_builtin_type_vec64 = nullptr;
  240. struct type *ppc_builtin_type_vec128 = nullptr;
  241. int (*ppc_syscall_record) (struct regcache *regcache) = nullptr;
  242. };
  243. /* Constants for register set sizes. */
  244. enum
  245. {
  246. ppc_num_gprs = 32, /* 32 general-purpose registers. */
  247. ppc_num_fprs = 32, /* 32 floating-point registers. */
  248. ppc_num_srs = 16, /* 16 segment registers. */
  249. ppc_num_vrs = 32, /* 32 Altivec vector registers. */
  250. ppc_num_vshrs = 32, /* 32 doublewords (dword 1 of vs0~vs31). */
  251. ppc_num_vsrs = 64, /* 64 VSX vector registers. */
  252. ppc_num_efprs = 32 /* 32 Extended FP registers. */
  253. };
  254. /* Register number constants. These are GDB internal register
  255. numbers; they are not used for the simulator or remote targets.
  256. Extra SPRs (those other than MQ, CTR, LR, XER, SPEFSCR) are given
  257. numbers above PPC_NUM_REGS. So are segment registers and other
  258. target-defined registers. */
  259. enum {
  260. PPC_R0_REGNUM = 0,
  261. PPC_F0_REGNUM = 32,
  262. PPC_PC_REGNUM = 64,
  263. PPC_MSR_REGNUM = 65,
  264. PPC_CR_REGNUM = 66,
  265. PPC_LR_REGNUM = 67,
  266. PPC_CTR_REGNUM = 68,
  267. PPC_XER_REGNUM = 69,
  268. PPC_FPSCR_REGNUM = 70,
  269. PPC_MQ_REGNUM = 71,
  270. PPC_SPE_UPPER_GP0_REGNUM = 72,
  271. PPC_SPE_ACC_REGNUM = 104,
  272. PPC_SPE_FSCR_REGNUM = 105,
  273. PPC_VR0_REGNUM = 106,
  274. PPC_VSCR_REGNUM = 138,
  275. PPC_VRSAVE_REGNUM = 139,
  276. PPC_VSR0_UPPER_REGNUM = 140,
  277. PPC_VSR31_UPPER_REGNUM = 171,
  278. PPC_PPR_REGNUM = 172,
  279. PPC_DSCR_REGNUM = 173,
  280. PPC_TAR_REGNUM = 174,
  281. /* EBB registers. */
  282. PPC_BESCR_REGNUM = 175,
  283. PPC_EBBHR_REGNUM = 176,
  284. PPC_EBBRR_REGNUM = 177,
  285. /* PMU registers. */
  286. PPC_MMCR0_REGNUM = 178,
  287. PPC_MMCR2_REGNUM = 179,
  288. PPC_SIAR_REGNUM = 180,
  289. PPC_SDAR_REGNUM = 181,
  290. PPC_SIER_REGNUM = 182,
  291. /* Hardware transactional memory registers. */
  292. PPC_TFHAR_REGNUM = 183,
  293. PPC_TEXASR_REGNUM = 184,
  294. PPC_TFIAR_REGNUM = 185,
  295. PPC_CR0_REGNUM = 186,
  296. PPC_CCR_REGNUM = 218,
  297. PPC_CXER_REGNUM = 219,
  298. PPC_CLR_REGNUM = 220,
  299. PPC_CCTR_REGNUM = 221,
  300. PPC_CF0_REGNUM = 222,
  301. PPC_CFPSCR_REGNUM = 254,
  302. PPC_CVR0_REGNUM = 255,
  303. PPC_CVSCR_REGNUM = 287,
  304. PPC_CVRSAVE_REGNUM = 288,
  305. PPC_CVSR0_UPPER_REGNUM = 289,
  306. PPC_CPPR_REGNUM = 321,
  307. PPC_CDSCR_REGNUM = 322,
  308. PPC_CTAR_REGNUM = 323,
  309. PPC_NUM_REGS
  310. };
  311. /* Big enough to hold the size of the largest register in bytes. */
  312. #define PPC_MAX_REGISTER_SIZE 64
  313. #define PPC_IS_EBB_REGNUM(i) \
  314. ((i) >= PPC_BESCR_REGNUM && (i) <= PPC_EBBRR_REGNUM)
  315. #define PPC_IS_PMU_REGNUM(i) \
  316. ((i) >= PPC_MMCR0_REGNUM && (i) <= PPC_SIER_REGNUM)
  317. #define PPC_IS_TMSPR_REGNUM(i) \
  318. ((i) >= PPC_TFHAR_REGNUM && (i) <= PPC_TFIAR_REGNUM)
  319. #define PPC_IS_CKPTGP_REGNUM(i) \
  320. ((i) >= PPC_CR0_REGNUM && (i) <= PPC_CCTR_REGNUM)
  321. #define PPC_IS_CKPTFP_REGNUM(i) \
  322. ((i) >= PPC_CF0_REGNUM && (i) <= PPC_CFPSCR_REGNUM)
  323. #define PPC_IS_CKPTVMX_REGNUM(i) \
  324. ((i) >= PPC_CVR0_REGNUM && (i) <= PPC_CVRSAVE_REGNUM)
  325. #define PPC_IS_CKPTVSX_REGNUM(i) \
  326. ((i) >= PPC_CVSR0_UPPER_REGNUM && (i) < (PPC_CVSR0_UPPER_REGNUM + 32))
  327. /* An instruction to match. */
  328. struct ppc_insn_pattern
  329. {
  330. unsigned int mask; /* mask the insn with this... */
  331. unsigned int data; /* ...and see if it matches this. */
  332. int optional; /* If non-zero, this insn may be absent. */
  333. };
  334. extern int ppc_insns_match_pattern (struct frame_info *frame, CORE_ADDR pc,
  335. const struct ppc_insn_pattern *pattern,
  336. unsigned int *insns);
  337. extern CORE_ADDR ppc_insn_d_field (unsigned int insn);
  338. extern CORE_ADDR ppc_insn_ds_field (unsigned int insn);
  339. extern CORE_ADDR ppc_insn_prefix_dform (unsigned int insn1,
  340. unsigned int insn2);
  341. extern int ppc_process_record (struct gdbarch *gdbarch,
  342. struct regcache *regcache, CORE_ADDR addr);
  343. /* Instruction size. */
  344. #define PPC_INSN_SIZE 4
  345. /* Estimate for the maximum number of instructions in a function epilogue. */
  346. #define PPC_MAX_EPILOGUE_INSTRUCTIONS 52
  347. struct ppc_inferior_data
  348. {
  349. /* This is an optional in case we add more fields to ppc_inferior_data, we
  350. don't want it instantiated as soon as we get the ppc_inferior_data for an
  351. inferior. */
  352. gdb::optional<displaced_step_buffers> disp_step_buf;
  353. };
  354. extern ppc_inferior_data * get_ppc_per_inferior (inferior *inf);
  355. #endif /* ppc-tdep.h */