1 //===-- RegisterContextDarwin_arm64.h -----------------------------*- C++
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTDARWIN_ARM64_H
11 #define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTDARWIN_ARM64_H
13 #include "lldb/Target/RegisterContext.h"
14 #include "lldb/lldb-private.h"
16 // Break only in privileged or user mode
17 #define S_RSVD ((uint32_t)(0u << 1))
18 #define S_PRIV ((uint32_t)(1u << 1))
19 #define S_USER ((uint32_t)(2u << 1))
20 #define S_PRIV_USER ((S_PRIV) | (S_USER))
22 #define WCR_ENABLE ((uint32_t)(1u))
24 // Watchpoint load/store
25 #define WCR_LOAD ((uint32_t)(1u << 3))
26 #define WCR_STORE ((uint32_t)(1u << 4))
28 class RegisterContextDarwin_arm64
: public lldb_private::RegisterContext
{
30 RegisterContextDarwin_arm64(lldb_private::Thread
&thread
,
31 uint32_t concrete_frame_idx
);
33 ~RegisterContextDarwin_arm64() override
;
35 void InvalidateAllRegisters() override
;
37 size_t GetRegisterCount() override
;
39 const lldb_private::RegisterInfo
*GetRegisterInfoAtIndex(size_t reg
) override
;
41 size_t GetRegisterSetCount() override
;
43 const lldb_private::RegisterSet
*GetRegisterSet(size_t set
) override
;
45 bool ReadRegister(const lldb_private::RegisterInfo
*reg_info
,
46 lldb_private::RegisterValue
®_value
) override
;
48 bool WriteRegister(const lldb_private::RegisterInfo
*reg_info
,
49 const lldb_private::RegisterValue
®_value
) override
;
51 bool ReadAllRegisterValues(lldb::WritableDataBufferSP
&data_sp
) override
;
53 bool WriteAllRegisterValues(const lldb::DataBufferSP
&data_sp
) override
;
55 uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind
,
56 uint32_t num
) override
;
58 uint32_t NumSupportedHardwareWatchpoints() override
;
60 uint32_t SetHardwareWatchpoint(lldb::addr_t addr
, size_t size
, bool read
,
63 bool ClearHardwareWatchpoint(uint32_t hw_index
) override
;
65 // mirrors <mach/arm/thread_status.h> arm_thread_state64_t
67 uint64_t x
[29]; // x0-x28
72 uint32_t cpsr
; // cpsr
76 alignas(16) char bytes
[16];
79 // mirrors <mach/arm/thread_status.h> arm_neon_state64_t
86 // mirrors <mach/arm/thread_status.h> arm_exception_state64_t
88 uint64_t far
; // Virtual Fault Address
89 uint32_t esr
; // Exception syndrome
90 uint32_t exception
; // number of arm exception token
93 // mirrors <mach/arm/thread_status.h> arm_debug_state64_t
102 static void LogDBGRegisters(lldb_private::Log
*log
, const DBG
&dbg
);
106 GPRRegSet
= 6, // ARM_THREAD_STATE64
107 FPURegSet
= 17, // ARM_NEON_STATE64
108 EXCRegSet
= 7, // ARM_EXCEPTION_STATE64
109 DBGRegSet
= 15 // ARM_DEBUG_STATE64
113 GPRWordCount
= sizeof(GPR
) / sizeof(uint32_t), // ARM_THREAD_STATE64_COUNT
114 FPUWordCount
= sizeof(FPU
) / sizeof(uint32_t), // ARM_NEON_STATE64_COUNT
116 sizeof(EXC
) / sizeof(uint32_t), // ARM_EXCEPTION_STATE64_COUNT
117 DBGWordCount
= sizeof(DBG
) / sizeof(uint32_t) // ARM_DEBUG_STATE64_COUNT
120 enum { Read
= 0, Write
= 1, kNumErrors
= 2 };
126 int gpr_errs
[2]; // Read/Write errors
127 int fpu_errs
[2]; // Read/Write errors
128 int exc_errs
[2]; // Read/Write errors
129 int dbg_errs
[2]; // Read/Write errors
131 void InvalidateAllRegisterStates() {
132 SetError(GPRRegSet
, Read
, -1);
133 SetError(FPURegSet
, Read
, -1);
134 SetError(EXCRegSet
, Read
, -1);
137 int GetError(int flavor
, uint32_t err_idx
) const {
138 if (err_idx
< kNumErrors
) {
140 // When getting all errors, just OR all values together to see if
141 // we got any kind of error.
143 return gpr_errs
[err_idx
];
145 return fpu_errs
[err_idx
];
147 return exc_errs
[err_idx
];
149 return dbg_errs
[err_idx
];
157 bool SetError(int flavor
, uint32_t err_idx
, int err
) {
158 if (err_idx
< kNumErrors
) {
161 gpr_errs
[err_idx
] = err
;
165 fpu_errs
[err_idx
] = err
;
169 exc_errs
[err_idx
] = err
;
173 exc_errs
[err_idx
] = err
;
183 bool RegisterSetIsCached(int set
) const { return GetError(set
, Read
) == 0; }
185 int ReadGPR(bool force
);
187 int ReadFPU(bool force
);
189 int ReadEXC(bool force
);
191 int ReadDBG(bool force
);
201 // Subclasses override these to do the actual reading.
202 virtual int DoReadGPR(lldb::tid_t tid
, int flavor
, GPR
&gpr
) { return -1; }
204 virtual int DoReadFPU(lldb::tid_t tid
, int flavor
, FPU
&fpu
) = 0;
206 virtual int DoReadEXC(lldb::tid_t tid
, int flavor
, EXC
&exc
) = 0;
208 virtual int DoReadDBG(lldb::tid_t tid
, int flavor
, DBG
&dbg
) = 0;
210 virtual int DoWriteGPR(lldb::tid_t tid
, int flavor
, const GPR
&gpr
) = 0;
212 virtual int DoWriteFPU(lldb::tid_t tid
, int flavor
, const FPU
&fpu
) = 0;
214 virtual int DoWriteEXC(lldb::tid_t tid
, int flavor
, const EXC
&exc
) = 0;
216 virtual int DoWriteDBG(lldb::tid_t tid
, int flavor
, const DBG
&dbg
) = 0;
218 int ReadRegisterSet(uint32_t set
, bool force
);
220 int WriteRegisterSet(uint32_t set
);
222 static uint32_t GetRegisterNumber(uint32_t reg_kind
, uint32_t reg_num
);
224 static int GetSetForNativeRegNum(int reg_num
);
226 static size_t GetRegisterInfosCount();
228 static const lldb_private::RegisterInfo
*GetRegisterInfos();
231 #endif // LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTDARWIN_ARM64_H