LLDB  mainline
LinuxPTraceDefines_arm64sve.h
Go to the documentation of this file.
1 //===-- LinuxPTraceDefines_arm64sve.h ------------------------- -*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_LINUXPTRACEDEFINES_ARM64SVE_H
10 #define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_LINUXPTRACEDEFINES_ARM64SVE_H
11 
12 #include <cstdint>
13 
14 namespace lldb_private {
15 namespace sve {
16 
17 /*
18  * The SVE architecture leaves space for future expansion of the
19  * vector length beyond its initial architectural limit of 2048 bits
20  * (16 quadwords).
21  *
22  * See <Linux kernel source tree>/Documentation/arm64/sve.rst for a description
23  * of the vl/vq terminology.
24  */
25 
26 const uint16_t vq_bytes = 16; /* number of bytes per quadword */
27 
28 const uint16_t vq_min = 1;
29 const uint16_t vq_max = 512;
30 
33 
36 
38  return (vl % vq_bytes == 0 && vl >= vl_min && vl <= vl_max);
39 }
40 
41 inline uint16_t vq_from_vl(uint16_t vl) { return vl / vq_bytes; }
42 inline uint16_t vl_from_vq(uint16_t vq) { return vq * vq_bytes; }
43 
44 /* A new signal frame record sve_context encodes the SVE Registers on signal
45  * delivery. sve_context struct definition may be included in asm/sigcontext.h.
46  * We define sve_context_size which will be used by LLDB sve helper functions.
47  * More information on sve_context can be found in Linux kernel source tree at
48  * Documentation/arm64/sve.rst.
49  */
50 
52 
53 /*
54  * If the SVE registers are currently live for the thread at signal delivery,
55  * sve_context.head.size >=
56  * SigContextSize(vq_from_vl(sve_context.vl))
57  * and the register data may be accessed using the Sig*() functions.
58  *
59  * If sve_context.head.size <
60  * SigContextSize(vq_from_vl(sve_context.vl)),
61  * the SVE registers were not live for the thread and no register data
62  * is included: in this case, the Sig*() functions should not be
63  * used except for this check.
64  *
65  * The same convention applies when returning from a signal: a caller
66  * will need to remove or resize the sve_context block if it wants to
67  * make the SVE registers live when they were previously non-live or
68  * vice-versa. This may require the caller to allocate fresh
69  * memory and/or move other context blocks in the signal frame.
70  *
71  * Changing the vector length during signal return is not permitted:
72  * sve_context.vl must equal the thread's current vector length when
73  * doing a sigreturn.
74  *
75  *
76  * Note: for all these functions, the "vq" argument denotes the SVE
77  * vector length in quadwords (i.e., units of 128 bits).
78  *
79  * The correct way to obtain vq is to use vq_from_vl(vl). The
80  * result is valid if and only if vl_valid(vl) is true. This is
81  * guaranteed for a struct sve_context written by the kernel.
82  *
83  *
84  * Additional functions describe the contents and layout of the payload.
85  * For each, Sig*Offset(args) is the start offset relative to
86  * the start of struct sve_context, and Sig*Size(args) is the
87  * size in bytes:
88  *
89  * x type description
90  * - ---- -----------
91  * REGS the entire SVE context
92  *
93  * ZREGS __uint128_t[num_of_zregs][vq] all Z-registers
94  * ZREG __uint128_t[vq] individual Z-register Zn
95  *
96  * PREGS uint16_t[num_of_pregs][vq] all P-registers
97  * PREG uint16_t[vq] individual P-register Pn
98  *
99  * FFR uint16_t[vq] first-fault status register
100  *
101  * Additional data might be appended in the future.
102  */
103 
104 inline uint16_t SigZRegSize(uint16_t vq) { return vq * vq_bytes; }
105 inline uint16_t SigPRegSize(uint16_t vq) { return vq * vq_bytes / 8; }
106 inline uint16_t SigFFRSize(uint16_t vq) { return SigPRegSize(vq); }
107 
109  return (sve_context_size + vq_bytes - 1) / vq_bytes * vq_bytes;
110 }
111 
112 inline uint32_t SigZRegsOffset() { return SigRegsOffset(); }
113 
115  return SigRegsOffset() + SigZRegSize(vq) * n;
116 }
117 
119  return SigZRegOffset(vq, num_of_zregs) - SigRegsOffset();
120 }
121 
123  return SigRegsOffset() + SigZRegsSize(vq);
124 }
125 
127  return SigPRegsOffset(vq) + SigPRegSize(vq) * n;
128 }
129 
131  return SigPRegOffset(vq, num_of_pregs) - SigPRegsOffset(vq);
132 }
133 
135  return SigPRegsOffset(vq) + SigpRegsSize(vq);
136 }
137 
139  return SigFFROffset(vq) + SigFFRSize(vq) - SigRegsOffset();
140 }
141 
143  return SigRegsOffset() + SigRegsSize(vq);
144 }
145 
147  uint32_t size; /* total meaningful regset content in bytes */
148  uint32_t max_size; /* maxmium possible size for this thread */
149  uint16_t vl; /* current vector length */
150  uint16_t max_vl; /* maximum possible vector length */
153 };
154 
155 /* Definitions for user_sve_header.flags: */
156 const uint16_t ptrace_regs_mask = 1 << 0;
159 
160 /*
161  * The remainder of the SVE state follows struct user_sve_header. The
162  * total size of the SVE state (including header) depends on the
163  * metadata in the header: PTraceSize(vq, flags) gives the total size
164  * of the state in bytes, including the header.
165  *
166  * Refer to <asm/sigcontext.h> for details of how to pass the correct
167  * "vq" argument to these macros.
168  */
169 
170 /* Offset from the start of struct user_sve_header to the register data */
172  return (sizeof(struct user_sve_header) + vq_bytes - 1) / vq_bytes * vq_bytes;
173 }
174 
175 /*
176  * The register data content and layout depends on the value of the
177  * flags field.
178  */
179 
180 /*
181  * (flags & ptrace_regs_mask) == ptrace_regs_fpsimd case:
182  *
183  * The payload starts at offset PTraceFPSIMDOffset, and is of type
184  * struct user_fpsimd_state. Additional data might be appended in the
185  * future: use PTraceFPSIMDSize(vq, flags) to compute the total size.
186  * PTraceFPSIMDSize(vq, flags) will never be less than
187  * sizeof(struct user_fpsimd_state).
188  */
189 
191 
192 /* Return size of struct user_fpsimd_state from asm/ptrace.h */
193 inline uint32_t PTraceFPSIMDSize(uint16_t vq, uint16_t flags) { return 528; }
194 
195 /*
196  * (flags & ptrace_regs_mask) == ptrace_regs_sve case:
197  *
198  * The payload starts at offset PTraceSVEOffset, and is of size
199  * PTraceSVESize(vq, flags).
200  *
201  * Additional functions describe the contents and layout of the payload.
202  * For each, PTrace*X*Offset(args) is the start offset relative to
203  * the start of struct user_sve_header, and PTrace*X*Size(args) is
204  * the size in bytes:
205  *
206  * x type description
207  * - ---- -----------
208  * ZREGS \
209  * ZREG |
210  * PREGS | refer to <asm/sigcontext.h>
211  * PREG |
212  * FFR /
213  *
214  * FPSR uint32_t FPSR
215  * FPCR uint32_t FPCR
216  *
217  * Additional data might be appended in the future.
218  */
219 
220 inline uint32_t PTraceZRegSize(uint16_t vq) { return SigZRegSize(vq); }
221 
222 inline uint32_t PTracePRegSize(uint16_t vq) { return SigPRegSize(vq); }
223 
224 inline uint32_t PTraceFFRSize(uint16_t vq) { return SigFFRSize(vq); }
225 
226 const uint32_t fpsr_size = sizeof(uint32_t);
227 const uint32_t fpcr_size = sizeof(uint32_t);
228 
229 inline uint32_t SigToPTrace(uint32_t offset) {
230  return offset - SigRegsOffset() + PTraceRegsOffset();
231 }
232 
234 
236  return SigToPTrace(SigZRegsOffset());
237 }
238 
240  return SigToPTrace(SigZRegOffset(vq, n));
241 }
242 
245 }
246 
248  return SigToPTrace(SigPRegsOffset(vq));
249 }
250 
252  return SigToPTrace(SigPRegOffset(vq, n));
253 }
254 
257 }
258 
260  return SigToPTrace(SigFFROffset(vq));
261 }
262 
264  return (PTraceFFROffset(vq) + PTraceFFRSize(vq) + (vq_bytes - 1)) / vq_bytes *
265  vq_bytes;
266 }
267 
269  return PTraceFPSROffset(vq) + fpsr_size;
270 }
271 
272 /*
273  * Any future extension appended after FPCR must be aligned to the next
274  * 128-bit boundary.
275  */
276 
278  return (PTraceFPCROffset(vq) + fpcr_size - ptrace_sve_offset + vq_bytes - 1) /
279  vq_bytes * vq_bytes;
280 }
281 
283  return (flags & ptrace_regs_mask) == ptrace_regs_sve
284  ? ptrace_sve_offset + PTraceSVESize(vq, flags)
285  : ptrace_fpsimd_offset + PTraceFPSIMDSize(vq, flags);
286 }
287 
288 } // namespace SVE
289 } // namespace lldb_private
290 
291 #endif // LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_LINUXPTRACEDEFINES_ARM64SVE_H
lldb_private::sve::SVESigContextSize
uint32_t SVESigContextSize(uint16_t vq)
Definition: LinuxPTraceDefines_arm64sve.h:142
lldb_private::sve::PTracePRegsOffset
uint32_t PTracePRegsOffset(uint16_t vq)
Definition: LinuxPTraceDefines_arm64sve.h:247
lldb_private::sve::ptrace_fpsimd_offset
const uint32_t ptrace_fpsimd_offset
Definition: LinuxPTraceDefines_arm64sve.h:190
lldb_private::sve::PTraceZRegSize
uint32_t PTraceZRegSize(uint16_t vq)
Definition: LinuxPTraceDefines_arm64sve.h:220
lldb_private::sve::PTraceFFROffset
uint32_t PTraceFFROffset(uint16_t vq)
Definition: LinuxPTraceDefines_arm64sve.h:259
lldb_private::sve::user_sve_header
Definition: LinuxPTraceDefines_arm64sve.h:146
lldb_private::sve::SigFFROffset
uint32_t SigFFROffset(uint16_t vq)
Definition: LinuxPTraceDefines_arm64sve.h:134
lldb_private::sve::user_sve_header::max_size
uint32_t max_size
Definition: LinuxPTraceDefines_arm64sve.h:148
lldb_private::sve::SigpRegsSize
uint32_t SigpRegsSize(uint16_t vq)
Definition: LinuxPTraceDefines_arm64sve.h:130
lldb_private::sve::SigZRegsOffset
uint32_t SigZRegsOffset()
Definition: LinuxPTraceDefines_arm64sve.h:112
lldb_private::sve::PTraceFPSROffset
uint32_t PTraceFPSROffset(uint16_t vq)
Definition: LinuxPTraceDefines_arm64sve.h:263
lldb_private::sve::vl_valid
uint16_t vl_valid(uint16_t vl)
Definition: LinuxPTraceDefines_arm64sve.h:37
lldb_private::sve::ptrace_regs_fpsimd
const uint16_t ptrace_regs_fpsimd
Definition: LinuxPTraceDefines_arm64sve.h:157
lldb_private::sve::PTracePRegSize
uint32_t PTracePRegSize(uint16_t vq)
Definition: LinuxPTraceDefines_arm64sve.h:222
lldb_private::sve::SigZRegsSize
uint32_t SigZRegsSize(uint16_t vq)
Definition: LinuxPTraceDefines_arm64sve.h:118
lldb_private::sve::ptrace_regs_mask
const uint16_t ptrace_regs_mask
Definition: LinuxPTraceDefines_arm64sve.h:156
lldb_private::sve::PTraceZRegsOffset
uint32_t PTraceZRegsOffset(uint16_t vq)
Definition: LinuxPTraceDefines_arm64sve.h:235
lldb_private::sve::user_sve_header::vl
uint16_t vl
Definition: LinuxPTraceDefines_arm64sve.h:149
lldb_private::sve::vq_from_vl
uint16_t vq_from_vl(uint16_t vl)
Definition: LinuxPTraceDefines_arm64sve.h:41
lldb_private::sve::PTracePRegOffset
uint32_t PTracePRegOffset(uint16_t vq, uint16_t n)
Definition: LinuxPTraceDefines_arm64sve.h:251
lldb_private::sve::PTraceSize
uint32_t PTraceSize(uint16_t vq, uint16_t flags)
Definition: LinuxPTraceDefines_arm64sve.h:282
lldb_private::sve::vq_max
const uint16_t vq_max
Definition: LinuxPTraceDefines_arm64sve.h:29
lldb_private::sve::PTraceFPSIMDSize
uint32_t PTraceFPSIMDSize(uint16_t vq, uint16_t flags)
Definition: LinuxPTraceDefines_arm64sve.h:193
lldb_private::sve::sve_context_size
const uint16_t sve_context_size
Definition: LinuxPTraceDefines_arm64sve.h:51
lldb_private::sve::user_sve_header::reserved
uint16_t reserved
Definition: LinuxPTraceDefines_arm64sve.h:152
lldb_private::sve::SigRegsOffset
uint32_t SigRegsOffset()
Definition: LinuxPTraceDefines_arm64sve.h:108
lldb_private::sve::SigPRegSize
uint16_t SigPRegSize(uint16_t vq)
Definition: LinuxPTraceDefines_arm64sve.h:105
lldb_private::sve::SigPRegsOffset
uint32_t SigPRegsOffset(uint16_t vq)
Definition: LinuxPTraceDefines_arm64sve.h:122
lldb_private::sve::SigPRegOffset
uint32_t SigPRegOffset(uint16_t vq, uint16_t n)
Definition: LinuxPTraceDefines_arm64sve.h:126
lldb_private::sve::user_sve_header::flags
uint16_t flags
Definition: LinuxPTraceDefines_arm64sve.h:151
lldb_private::sve::vl_max
const uint16_t vl_max
Definition: LinuxPTraceDefines_arm64sve.h:32
lldb_private::sve::user_sve_header::size
uint32_t size
Definition: LinuxPTraceDefines_arm64sve.h:147
lldb_private::sve::PTraceFPCROffset
uint32_t PTraceFPCROffset(uint16_t vq)
Definition: LinuxPTraceDefines_arm64sve.h:268
lldb_private::sve::vq_min
const uint16_t vq_min
Definition: LinuxPTraceDefines_arm64sve.h:28
lldb_private::sve::ptrace_sve_offset
const uint32_t ptrace_sve_offset
Definition: LinuxPTraceDefines_arm64sve.h:233
uint32_t
lldb_private::sve::vl_min
const uint16_t vl_min
Definition: LinuxPTraceDefines_arm64sve.h:31
lldb_private::sve::PTraceFFRSize
uint32_t PTraceFFRSize(uint16_t vq)
Definition: LinuxPTraceDefines_arm64sve.h:224
uint16_t
lldb_private::sve::fpsr_size
const uint32_t fpsr_size
Definition: LinuxPTraceDefines_arm64sve.h:226
lldb_private::sve::SigToPTrace
uint32_t SigToPTrace(uint32_t offset)
Definition: LinuxPTraceDefines_arm64sve.h:229
lldb_private::sve::PTraceSVESize
uint32_t PTraceSVESize(uint16_t vq, uint16_t flags)
Definition: LinuxPTraceDefines_arm64sve.h:277
lldb_private::sve::SigZRegSize
uint16_t SigZRegSize(uint16_t vq)
Definition: LinuxPTraceDefines_arm64sve.h:104
lldb_private::sve::ptrace_regs_sve
const uint16_t ptrace_regs_sve
Definition: LinuxPTraceDefines_arm64sve.h:158
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::sve::num_of_zregs
const uint16_t num_of_zregs
Definition: LinuxPTraceDefines_arm64sve.h:34
lldb_private::sve::PTraceRegsOffset
uint16_t PTraceRegsOffset()
Definition: LinuxPTraceDefines_arm64sve.h:171
lldb_private::sve::PTraceZRegsSize
uint32_t PTraceZRegsSize(uint16_t vq)
Definition: LinuxPTraceDefines_arm64sve.h:243
lldb_private::sve::vq_bytes
const uint16_t vq_bytes
Definition: LinuxPTraceDefines_arm64sve.h:26
lldb_private::sve::PTraceZRegOffset
uint32_t PTraceZRegOffset(uint16_t vq, uint16_t n)
Definition: LinuxPTraceDefines_arm64sve.h:239
lldb_private::sve::SigRegsSize
uint32_t SigRegsSize(uint16_t vq)
Definition: LinuxPTraceDefines_arm64sve.h:138
lldb_private::sve::SigFFRSize
uint16_t SigFFRSize(uint16_t vq)
Definition: LinuxPTraceDefines_arm64sve.h:106
lldb_private::sve::SigZRegOffset
uint32_t SigZRegOffset(uint16_t vq, uint16_t n)
Definition: LinuxPTraceDefines_arm64sve.h:114
lldb_private::sve::user_sve_header::max_vl
uint16_t max_vl
Definition: LinuxPTraceDefines_arm64sve.h:150
lldb_private::sve::vl_from_vq
uint16_t vl_from_vq(uint16_t vq)
Definition: LinuxPTraceDefines_arm64sve.h:42
lldb_private::sve::fpcr_size
const uint32_t fpcr_size
Definition: LinuxPTraceDefines_arm64sve.h:227
lldb_private::sve::PTracePRegsSize
uint32_t PTracePRegsSize(uint16_t vq)
Definition: LinuxPTraceDefines_arm64sve.h:255
lldb_private::sve::num_of_pregs
const uint16_t num_of_pregs
Definition: LinuxPTraceDefines_arm64sve.h:35