LLDB mainline
NativeRegisterContextLinux_arm64.h
Go to the documentation of this file.
1//===-- NativeRegisterContextLinux_arm64.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#if defined(__arm64__) || defined(__aarch64__)
10
11#ifndef lldb_NativeRegisterContextLinux_arm64_h
12#define lldb_NativeRegisterContextLinux_arm64_h
13
18
19#include "llvm/ADT/BitmaskEnum.h"
20
21#include <asm/ptrace.h>
22
23namespace lldb_private {
24namespace process_linux {
25
27
28class NativeRegisterContextLinux_arm64
30 public NativeRegisterContextDBReg_arm64 {
31public:
32 NativeRegisterContextLinux_arm64(
33 const ArchSpec &target_arch, NativeThreadProtocol &native_thread,
34 std::unique_ptr<RegisterInfoPOSIX_arm64> register_info_up);
35
36 uint32_t GetRegisterSetCount() const override;
37
38 uint32_t GetUserRegisterCount() const override;
39
40 const RegisterSet *GetRegisterSet(uint32_t set_index) const override;
41
42 Status ReadRegister(const RegisterInfo *reg_info,
43 RegisterValue &reg_value) override;
44
45 Status WriteRegister(const RegisterInfo *reg_info,
46 const RegisterValue &reg_value) override;
47
48 Status ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override;
49
50 Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override;
51
52 void InvalidateAllRegisters() override;
53
54 std::vector<uint32_t>
55 GetExpeditedRegisters(ExpeditedRegs expType) const override;
56
57 bool RegisterOffsetIsDynamic() const override { return true; }
58
59 llvm::Expected<MemoryTaggingDetails>
60 GetMemoryTaggingDetails(int32_t type) override;
61
62protected:
63 Status ReadGPR() override;
64
65 Status WriteGPR() override;
66
67 Status ReadFPR() override;
68
69 Status WriteFPR() override;
70
71 void *GetGPRBuffer() override { return &m_gpr_arm64; }
72
73 // GetGPRBufferSize returns sizeof arm64 GPR ptrace buffer, it is different
74 // from GetGPRSize which returns sizeof RegisterInfoPOSIX_arm64::GPR.
75 size_t GetGPRBufferSize() { return sizeof(m_gpr_arm64); }
76
77 void *GetFPRBuffer() override { return &m_fpr; }
78
79 size_t GetFPRSize() override { return sizeof(m_fpr); }
80
81 lldb::addr_t FixWatchpointHitAddress(lldb::addr_t hit_addr) override;
82
83private:
84 // Bit mask enum used to refer to the types of registers we support. Currently
85 // used for tracking cache validity and ReadAll/WriteAllRegister data. Will
86 // be used for much more in future.
87 enum class RegisterSetType : uint32_t {
88 // General purpose registers.
89 GPR = 1 << 0,
90 // When there is no SVE, or SVE in FPSIMD mode, or streaming only SVE that
91 // is in non-streaming mode.
92 FPR = 1 << 1,
93 // Used for SVE registers in streaming or non-streaming mode.
94 SVE = 1 << 2,
95 // Only the ptrace header for SVE.
96 SVE_HEADER = 1 << 3,
97 // Pointer authentication mask registers.
98 PAC = 1 << 4,
99 // Memory tagging control registers.
100 MTE = 1 << 5,
101 // Thread local storage registers.
102 TLS = 1 << 6,
103 // ZA only, because SVCR and SVG are pseudo registers.
104 ZA = 1 << 7,
105 // Only the ptrace header for ZA.
106 ZA_HEADER = 1 << 8,
107 // ZT only.
108 ZT = 1 << 9,
109 // Floating point mode control registers.
110 FPMR = 1 << 10,
111 // Guarded Control Stack registers.
112 GCS = 1 << 11,
113 // Permission Overlay registers.
114 POE = 1 << 12,
116 };
117
118 RegisterSetType m_validity = static_cast<RegisterSetType>(0);
119
120 // Returns the ptrace register set number for the given register set.
121 unsigned int GetPtraceSet(RegisterSetType set) const;
122
123 size_t GetSetSize(RegisterSetType set) const;
124
125 void *GetSetBuffer(RegisterSetType set);
126
127 void MakeValid(RegisterSetType set) { m_validity |= set; }
128
129 [[nodiscard]] bool IsValid(RegisterSetType set) const {
130 return any(m_validity & set);
131 }
132
133 /// Returns the mask of sets that would be invalidated if the given set was
134 /// invalidated. That is, the set itself and any sets that depend on it.
135 ///
136 /// If you need anything more complex such as only invalidating during certain
137 /// modes, put that logic in the function that calls Invalidate().
138 RegisterSetType GetInvalidationMask(const RegisterSetType set) const;
139
140 /// Invalidate our saved copies of the given register sets and any sets that
141 /// depend on those sets.
142 template <typename... Ts> void Invalidate(RegisterSetType first, Ts... rest) {
143 static_assert((std::is_same_v<Ts, RegisterSetType> && ...));
144 m_validity &=
145 ~(GetInvalidationMask(first) | ... | GetInvalidationMask(rest));
146 }
147
148 Status RestoreRegisters(void *buffer, const uint8_t **src, size_t len,
149 const RegisterSetType set,
150 std::function<Status()> writer);
151
152 size_t m_tls_size = 0;
153
154 /// 64-bit general purpose registers.
155 struct user_pt_regs m_gpr_arm64{};
156
157 /// Floating-point registers including extended register sets.
158 RegisterInfoPOSIX_arm64::FPU m_fpr{};
159
160 SVEState m_sve_state = SVEState::Unknown;
161 struct sve::user_sve_header m_sve_header{};
162 std::vector<uint8_t> m_sve_ptrace_payload;
163
164 sve::user_za_header m_za_header;
165 std::vector<uint8_t> m_za_ptrace_payload;
166
167 bool m_refresh_hwdebug_info = true;
168
169 struct user_pac_mask {
170 uint64_t data_mask = 0;
171 uint64_t insn_mask = 0;
172 } m_pac_mask;
173
174 uint64_t m_mte_ctrl_reg = 0;
175
176 struct sme_pseudo_regs {
177 uint64_t ctrl_reg = 0;
178 uint64_t svg_reg = 0;
179 } m_sme_pseudo_regs;
180
181 struct tls_regs {
182 uint64_t tpidr_reg = 0;
183 // Only valid when SME is present.
184 uint64_t tpidr2_reg = 0;
185 } m_tls_regs;
186
187 // SME2's ZT is a 512 bit register.
188 std::array<uint8_t, 64> m_zt_reg{};
189
190 uint64_t m_fpmr_reg = 0;
191
192 struct poe_regs {
193 uint64_t por_el0_reg = 0;
194 } m_poe_regs;
195
196 struct gcs_regs {
197 uint64_t features_enabled = 0;
198 uint64_t features_locked = 0;
199 uint64_t gcspr_e0 = 0;
200 } m_gcs_regs;
201
202 Status ReadAllSVE();
203
204 Status WriteAllSVE();
205
206 Status ReadSVEHeader();
207
208 Status WriteSVEHeader();
209
210 Status ReadPAuthMask();
211
212 Status ReadMTEControl();
213
214 Status WriteMTEControl();
215
216 Status ReadTLS();
217
218 Status WriteTLS();
219
220 Status ReadSMESVG();
221
222 Status ReadZAHeader();
223
224 Status ReadZA();
225
226 Status WriteZA();
227
228 Status ReadGCS();
229
230 Status WriteGCS();
231
232 // No WriteZAHeader because writing only the header will disable ZA.
233 // Instead use WriteZA and ensure you have the correct ZA buffer size set
234 // beforehand if you wish to disable it.
235
236 Status ReadZT();
237
238 Status WriteZT();
239
240 // SVCR is a pseudo register and we do not allow writes to it.
241 Status ReadSMEControl();
242
243 Status ReadFPMR();
244
245 Status WriteFPMR();
246
247 Status ReadPOE();
248
249 Status WritePOE();
250
251 uint64_t GetSVERegVG() { return m_sve_header.vl / 8; }
252
253 void SetSVERegVG(uint64_t vg) { m_sve_header.vl = vg * 8; }
254
255 void *GetSMEPseudoBuffer() { return &m_sme_pseudo_regs; }
256
257 size_t GetSMEPseudoBufferSize() { return sizeof(m_sme_pseudo_regs); }
258
259 llvm::Error ReadHardwareDebugInfo() override;
260
261 llvm::Error WriteHardwareDebugRegs(DREGType hwbType) override;
262
263 uint32_t CalculateFprOffset(const RegisterInfo *reg_info,
264 bool streaming_fpsimd) const;
265
266 RegisterInfoPOSIX_arm64 &GetRegisterInfo() const;
267
268 void ConfigureRegisterContext();
269
270 uint32_t CalculateSVEOffset(const RegisterInfo *reg_info) const;
271
272 Status CacheAllRegisters(uint32_t &cached_size);
273
274 uint8_t *AddRegisterSetType(uint8_t *dst, RegisterSetType register_set_type);
275
276 uint8_t *AddSavedRegisters(uint8_t *dst, RegisterSetType register_set_type,
277 void *src, size_t size);
278};
279
280} // namespace process_linux
281} // namespace lldb_private
282
283#endif // #ifndef lldb_NativeRegisterContextLinux_arm64_h
284
285#endif // defined (__arm64__) || defined (__aarch64__)
#define GPR(r16)
Definition ABIX86.cpp:145
struct _FPR FPR
Manages communication with the inferior (debugee) process.
Status WriteHardwareDebugRegs(int hwbType, ::pid_t tid, uint32_t max_supported, const std::array< NativeRegisterContextDBReg::DREG, 16 > &regs)
Status ReadHardwareDebugInfo(::pid_t tid, uint32_t &max_hwp_supported, uint32_t &max_hbp_supported)
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
uint64_t addr_t
Definition lldb-types.h:80