ptrace_arm64.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /*
  3. * Based on arch/arm/include/asm/ptrace.h
  4. *
  5. * Copyright (C) 1996-2003 Russell King
  6. * Copyright (C) 2012 ARM Ltd.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef __ASM_PTRACE_H
  21. #define __ASM_PTRACE_H
  22. #include <linux/types.h>
  23. #include <asm/hwcap.h>
  24. #include <asm/sve_context.h>
  25. /*
  26. * PSR bits
  27. */
  28. #define PSR_MODE_EL0t 0x00000000
  29. #define PSR_MODE_EL1t 0x00000004
  30. #define PSR_MODE_EL1h 0x00000005
  31. #define PSR_MODE_EL2t 0x00000008
  32. #define PSR_MODE_EL2h 0x00000009
  33. #define PSR_MODE_EL3t 0x0000000c
  34. #define PSR_MODE_EL3h 0x0000000d
  35. #define PSR_MODE_MASK 0x0000000f
  36. /* AArch32 CPSR bits */
  37. #define PSR_MODE32_BIT 0x00000010
  38. /* AArch64 SPSR bits */
  39. #define PSR_F_BIT 0x00000040
  40. #define PSR_I_BIT 0x00000080
  41. #define PSR_A_BIT 0x00000100
  42. #define PSR_D_BIT 0x00000200
  43. #define PSR_BTYPE_MASK 0x00000c00
  44. #define PSR_SSBS_BIT 0x00001000
  45. #define PSR_PAN_BIT 0x00400000
  46. #define PSR_UAO_BIT 0x00800000
  47. #define PSR_DIT_BIT 0x01000000
  48. #define PSR_TCO_BIT 0x02000000
  49. #define PSR_V_BIT 0x10000000
  50. #define PSR_C_BIT 0x20000000
  51. #define PSR_Z_BIT 0x40000000
  52. #define PSR_N_BIT 0x80000000
  53. #define PSR_BTYPE_SHIFT 10
  54. /*
  55. * Groups of PSR bits
  56. */
  57. #define PSR_f 0xff000000 /* Flags */
  58. #define PSR_s 0x00ff0000 /* Status */
  59. #define PSR_x 0x0000ff00 /* Extension */
  60. #define PSR_c 0x000000ff /* Control */
  61. /* Convenience names for the values of PSTATE.BTYPE */
  62. #define PSR_BTYPE_NONE (0b00 << PSR_BTYPE_SHIFT)
  63. #define PSR_BTYPE_JC (0b01 << PSR_BTYPE_SHIFT)
  64. #define PSR_BTYPE_C (0b10 << PSR_BTYPE_SHIFT)
  65. #define PSR_BTYPE_J (0b11 << PSR_BTYPE_SHIFT)
  66. /* syscall emulation path in ptrace */
  67. #define PTRACE_SYSEMU 31
  68. #define PTRACE_SYSEMU_SINGLESTEP 32
  69. /* MTE allocation tag access */
  70. #define PTRACE_PEEKMTETAGS 33
  71. #define PTRACE_POKEMTETAGS 34
  72. #ifndef __ASSEMBLY__
  73. /*
  74. * User structures for general purpose, floating point and debug registers.
  75. */
  76. struct user_pt_regs {
  77. __u64 regs[31];
  78. __u64 sp;
  79. __u64 pc;
  80. __u64 pstate;
  81. };
  82. struct user_fpsimd_state {
  83. __uint128_t vregs[32];
  84. __u32 fpsr;
  85. __u32 fpcr;
  86. __u32 __reserved[2];
  87. };
  88. struct user_hwdebug_state {
  89. __u32 dbg_info;
  90. __u32 pad;
  91. struct {
  92. __u64 addr;
  93. __u32 ctrl;
  94. __u32 pad;
  95. } dbg_regs[16];
  96. };
  97. /* SVE/FP/SIMD state (NT_ARM_SVE & NT_ARM_SSVE) */
  98. struct user_sve_header {
  99. __u32 size; /* total meaningful regset content in bytes */
  100. __u32 max_size; /* maxmium possible size for this thread */
  101. __u16 vl; /* current vector length */
  102. __u16 max_vl; /* maximum possible vector length */
  103. __u16 flags;
  104. __u16 __reserved;
  105. };
  106. /* Definitions for user_sve_header.flags: */
  107. #define SVE_PT_REGS_MASK (1 << 0)
  108. #define SVE_PT_REGS_FPSIMD 0
  109. #define SVE_PT_REGS_SVE SVE_PT_REGS_MASK
  110. /*
  111. * Common SVE_PT_* flags:
  112. * These must be kept in sync with prctl interface in <linux/prctl.h>
  113. */
  114. #define SVE_PT_VL_INHERIT ((1 << 17) /* PR_SVE_VL_INHERIT */ >> 16)
  115. #define SVE_PT_VL_ONEXEC ((1 << 18) /* PR_SVE_SET_VL_ONEXEC */ >> 16)
  116. /*
  117. * The remainder of the SVE state follows struct user_sve_header. The
  118. * total size of the SVE state (including header) depends on the
  119. * metadata in the header: SVE_PT_SIZE(vq, flags) gives the total size
  120. * of the state in bytes, including the header.
  121. *
  122. * Refer to <asm/sigcontext.h> for details of how to pass the correct
  123. * "vq" argument to these macros.
  124. */
  125. /* Offset from the start of struct user_sve_header to the register data */
  126. #define SVE_PT_REGS_OFFSET \
  127. ((sizeof(struct user_sve_header) + (__SVE_VQ_BYTES - 1)) \
  128. / __SVE_VQ_BYTES * __SVE_VQ_BYTES)
  129. /*
  130. * The register data content and layout depends on the value of the
  131. * flags field.
  132. */
  133. /*
  134. * (flags & SVE_PT_REGS_MASK) == SVE_PT_REGS_FPSIMD case:
  135. *
  136. * The payload starts at offset SVE_PT_FPSIMD_OFFSET, and is of type
  137. * struct user_fpsimd_state. Additional data might be appended in the
  138. * future: use SVE_PT_FPSIMD_SIZE(vq, flags) to compute the total size.
  139. * SVE_PT_FPSIMD_SIZE(vq, flags) will never be less than
  140. * sizeof(struct user_fpsimd_state).
  141. */
  142. #define SVE_PT_FPSIMD_OFFSET SVE_PT_REGS_OFFSET
  143. #define SVE_PT_FPSIMD_SIZE(vq, flags) (sizeof(struct user_fpsimd_state))
  144. /*
  145. * (flags & SVE_PT_REGS_MASK) == SVE_PT_REGS_SVE case:
  146. *
  147. * The payload starts at offset SVE_PT_SVE_OFFSET, and is of size
  148. * SVE_PT_SVE_SIZE(vq, flags).
  149. *
  150. * Additional macros describe the contents and layout of the payload.
  151. * For each, SVE_PT_SVE_x_OFFSET(args) is the start offset relative to
  152. * the start of struct user_sve_header, and SVE_PT_SVE_x_SIZE(args) is
  153. * the size in bytes:
  154. *
  155. * x type description
  156. * - ---- -----------
  157. * ZREGS \
  158. * ZREG |
  159. * PREGS | refer to <asm/sigcontext.h>
  160. * PREG |
  161. * FFR /
  162. *
  163. * FPSR uint32_t FPSR
  164. * FPCR uint32_t FPCR
  165. *
  166. * Additional data might be appended in the future.
  167. *
  168. * The Z-, P- and FFR registers are represented in memory in an endianness-
  169. * invariant layout which differs from the layout used for the FPSIMD
  170. * V-registers on big-endian systems: see sigcontext.h for more explanation.
  171. */
  172. #define SVE_PT_SVE_ZREG_SIZE(vq) __SVE_ZREG_SIZE(vq)
  173. #define SVE_PT_SVE_PREG_SIZE(vq) __SVE_PREG_SIZE(vq)
  174. #define SVE_PT_SVE_FFR_SIZE(vq) __SVE_FFR_SIZE(vq)
  175. #define SVE_PT_SVE_FPSR_SIZE sizeof(__u32)
  176. #define SVE_PT_SVE_FPCR_SIZE sizeof(__u32)
  177. #define SVE_PT_SVE_OFFSET SVE_PT_REGS_OFFSET
  178. #define SVE_PT_SVE_ZREGS_OFFSET \
  179. (SVE_PT_REGS_OFFSET + __SVE_ZREGS_OFFSET)
  180. #define SVE_PT_SVE_ZREG_OFFSET(vq, n) \
  181. (SVE_PT_REGS_OFFSET + __SVE_ZREG_OFFSET(vq, n))
  182. #define SVE_PT_SVE_ZREGS_SIZE(vq) \
  183. (SVE_PT_SVE_ZREG_OFFSET(vq, __SVE_NUM_ZREGS) - SVE_PT_SVE_ZREGS_OFFSET)
  184. #define SVE_PT_SVE_PREGS_OFFSET(vq) \
  185. (SVE_PT_REGS_OFFSET + __SVE_PREGS_OFFSET(vq))
  186. #define SVE_PT_SVE_PREG_OFFSET(vq, n) \
  187. (SVE_PT_REGS_OFFSET + __SVE_PREG_OFFSET(vq, n))
  188. #define SVE_PT_SVE_PREGS_SIZE(vq) \
  189. (SVE_PT_SVE_PREG_OFFSET(vq, __SVE_NUM_PREGS) - \
  190. SVE_PT_SVE_PREGS_OFFSET(vq))
  191. /* For streaming mode SVE (SSVE) FFR must be read and written as zero */
  192. #define SVE_PT_SVE_FFR_OFFSET(vq) \
  193. (SVE_PT_REGS_OFFSET + __SVE_FFR_OFFSET(vq))
  194. #define SVE_PT_SVE_FPSR_OFFSET(vq) \
  195. ((SVE_PT_SVE_FFR_OFFSET(vq) + SVE_PT_SVE_FFR_SIZE(vq) + \
  196. (__SVE_VQ_BYTES - 1)) \
  197. / __SVE_VQ_BYTES * __SVE_VQ_BYTES)
  198. #define SVE_PT_SVE_FPCR_OFFSET(vq) \
  199. (SVE_PT_SVE_FPSR_OFFSET(vq) + SVE_PT_SVE_FPSR_SIZE)
  200. /*
  201. * Any future extension appended after FPCR must be aligned to the next
  202. * 128-bit boundary.
  203. */
  204. #define SVE_PT_SVE_SIZE(vq, flags) \
  205. ((SVE_PT_SVE_FPCR_OFFSET(vq) + SVE_PT_SVE_FPCR_SIZE \
  206. - SVE_PT_SVE_OFFSET + (__SVE_VQ_BYTES - 1)) \
  207. / __SVE_VQ_BYTES * __SVE_VQ_BYTES)
  208. #define SVE_PT_SIZE(vq, flags) \
  209. (((flags) & SVE_PT_REGS_MASK) == SVE_PT_REGS_SVE ? \
  210. SVE_PT_SVE_OFFSET + SVE_PT_SVE_SIZE(vq, flags) \
  211. : ((((flags) & SVE_PT_REGS_MASK) == SVE_PT_REGS_FPSIMD ? \
  212. SVE_PT_FPSIMD_OFFSET + SVE_PT_FPSIMD_SIZE(vq, flags) \
  213. : SVE_PT_REGS_OFFSET)))
  214. /* pointer authentication masks (NT_ARM_PAC_MASK) */
  215. struct user_pac_mask {
  216. __u64 data_mask;
  217. __u64 insn_mask;
  218. };
  219. /* pointer authentication keys (NT_ARM_PACA_KEYS, NT_ARM_PACG_KEYS) */
  220. struct user_pac_address_keys {
  221. __uint128_t apiakey;
  222. __uint128_t apibkey;
  223. __uint128_t apdakey;
  224. __uint128_t apdbkey;
  225. };
  226. struct user_pac_generic_keys {
  227. __uint128_t apgakey;
  228. };
  229. /* ZA state (NT_ARM_ZA) */
  230. struct user_za_header {
  231. __u32 size; /* total meaningful regset content in bytes */
  232. __u32 max_size; /* maxmium possible size for this thread */
  233. __u16 vl; /* current vector length */
  234. __u16 max_vl; /* maximum possible vector length */
  235. __u16 flags;
  236. __u16 __reserved;
  237. };
  238. /*
  239. * Common ZA_PT_* flags:
  240. * These must be kept in sync with prctl interface in <linux/prctl.h>
  241. */
  242. #define ZA_PT_VL_INHERIT ((1 << 17) /* PR_SME_VL_INHERIT */ >> 16)
  243. #define ZA_PT_VL_ONEXEC ((1 << 18) /* PR_SME_SET_VL_ONEXEC */ >> 16)
  244. /*
  245. * The remainder of the ZA state follows struct user_za_header. The
  246. * total size of the ZA state (including header) depends on the
  247. * metadata in the header: ZA_PT_SIZE(vq, flags) gives the total size
  248. * of the state in bytes, including the header.
  249. *
  250. * Refer to <asm/sigcontext.h> for details of how to pass the correct
  251. * "vq" argument to these macros.
  252. */
  253. /* Offset from the start of struct user_za_header to the register data */
  254. #define ZA_PT_ZA_OFFSET \
  255. ((sizeof(struct user_za_header) + (__SVE_VQ_BYTES - 1)) \
  256. / __SVE_VQ_BYTES * __SVE_VQ_BYTES)
  257. /*
  258. * The payload starts at offset ZA_PT_ZA_OFFSET, and is of size
  259. * ZA_PT_ZA_SIZE(vq, flags).
  260. *
  261. * The ZA array is stored as a sequence of horizontal vectors ZAV of SVL/8
  262. * bytes each, starting from vector 0.
  263. *
  264. * Additional data might be appended in the future.
  265. *
  266. * The ZA matrix is represented in memory in an endianness-invariant layout
  267. * which differs from the layout used for the FPSIMD V-registers on big-endian
  268. * systems: see sigcontext.h for more explanation.
  269. */
  270. #define ZA_PT_ZAV_OFFSET(vq, n) \
  271. (ZA_PT_ZA_OFFSET + ((vq * __SVE_VQ_BYTES) * n))
  272. #define ZA_PT_ZA_SIZE(vq) ((vq * __SVE_VQ_BYTES) * (vq * __SVE_VQ_BYTES))
  273. #define ZA_PT_SIZE(vq) \
  274. (ZA_PT_ZA_OFFSET + ZA_PT_ZA_SIZE(vq))
  275. #endif /* __ASSEMBLY__ */
  276. #endif /* __ASM_PTRACE_H */