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 14 #include "Plugins/Process/Linux/NativeRegisterContextLinux.h" 15 #include "Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h" 16 17 #include <asm/ptrace.h> 18 19 namespace lldb_private { 20 namespace process_linux { 21 22 class NativeProcessLinux; 23 24 class NativeRegisterContextLinux_arm64 : public NativeRegisterContextLinux { 25 public: 26 NativeRegisterContextLinux_arm64(const ArchSpec &target_arch, 27 NativeThreadProtocol &native_thread); 28 29 uint32_t GetRegisterSetCount() const override; 30 31 uint32_t GetUserRegisterCount() const override; 32 33 const RegisterSet *GetRegisterSet(uint32_t set_index) const override; 34 35 Status ReadRegister(const RegisterInfo *reg_info, 36 RegisterValue ®_value) override; 37 38 Status WriteRegister(const RegisterInfo *reg_info, 39 const RegisterValue ®_value) override; 40 41 Status ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override; 42 43 Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override; 44 45 void InvalidateAllRegisters() override; 46 47 std::vector<uint32_t> 48 GetExpeditedRegisters(ExpeditedRegs expType) const override; 49 50 // Hardware breakpoints/watchpoint management functions 51 52 uint32_t NumSupportedHardwareBreakpoints() override; 53 54 uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size) override; 55 56 bool ClearHardwareBreakpoint(uint32_t hw_idx) override; 57 58 Status ClearAllHardwareBreakpoints() override; 59 60 Status GetHardwareBreakHitIndex(uint32_t &bp_index, 61 lldb::addr_t trap_addr) override; 62 63 uint32_t NumSupportedHardwareWatchpoints() override; 64 65 uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size, 66 uint32_t watch_flags) override; 67 68 bool ClearHardwareWatchpoint(uint32_t hw_index) override; 69 70 Status ClearAllHardwareWatchpoints() override; 71 72 Status GetWatchpointHitIndex(uint32_t &wp_index, 73 lldb::addr_t trap_addr) override; 74 75 lldb::addr_t GetWatchpointHitAddress(uint32_t wp_index) override; 76 77 lldb::addr_t GetWatchpointAddress(uint32_t wp_index) override; 78 79 uint32_t GetWatchpointSize(uint32_t wp_index); 80 81 bool WatchpointIsEnabled(uint32_t wp_index); 82 83 // Debug register type select 84 enum DREGType { eDREGTypeWATCH = 0, eDREGTypeBREAK }; 85 86 protected: 87 88 Status ReadGPR() override; 89 90 Status WriteGPR() override; 91 92 Status ReadFPR() override; 93 94 Status WriteFPR() override; 95 96 void *GetGPRBuffer() override { return &m_gpr_arm64; } 97 98 void *GetFPRBuffer() override { return &m_fpr; } 99 100 size_t GetFPRSize() override { return sizeof(m_fpr); } 101 102 private: 103 bool m_gpr_is_valid; 104 bool m_fpu_is_valid; 105 bool m_sve_buffer_is_valid; 106 107 bool m_sve_header_is_valid; 108 109 RegisterInfoPOSIX_arm64::GPR m_gpr_arm64; // 64-bit general purpose registers. 110 111 RegisterInfoPOSIX_arm64::FPU 112 m_fpr; // floating-point registers including extended register sets. 113 114 SVEState m_sve_state; 115 struct user_sve_header m_sve_header; 116 std::vector<uint8_t> m_sve_ptrace_payload; 117 118 // Debug register info for hardware breakpoints and watchpoints management. 119 struct DREG { 120 lldb::addr_t address; // Breakpoint/watchpoint address value. 121 lldb::addr_t hit_addr; // Address at which last watchpoint trigger exception 122 // occurred. 123 lldb::addr_t real_addr; // Address value that should cause target to stop. 124 uint32_t control; // Breakpoint/watchpoint control value. 125 uint32_t refcount; // Serves as enable/disable and reference counter. 126 }; 127 128 struct DREG m_hbr_regs[16]; // Arm native linux hardware breakpoints 129 struct DREG m_hwp_regs[16]; // Arm native linux hardware watchpoints 130 131 uint32_t m_max_hwp_supported; 132 uint32_t m_max_hbp_supported; 133 bool m_refresh_hwdebug_info; 134 135 bool IsGPR(unsigned reg) const; 136 137 bool IsFPR(unsigned reg) const; 138 139 Status ReadAllSVE(); 140 141 Status WriteAllSVE(); 142 143 Status ReadSVEHeader(); 144 145 Status WriteSVEHeader(); 146 147 bool IsSVE(unsigned reg) const; 148 149 uint64_t GetSVERegVG() { return m_sve_header.vl / 8; } 150 151 void SetSVERegVG(uint64_t vg) { m_sve_header.vl = vg * 8; } 152 153 void *GetSVEHeader() { return &m_sve_header; } 154 155 void *GetSVEBuffer(); 156 157 size_t GetSVEHeaderSize() { return sizeof(m_sve_header); } 158 159 size_t GetSVEBufferSize() { return m_sve_ptrace_payload.size(); } 160 161 Status ReadHardwareDebugInfo(); 162 163 Status WriteHardwareDebugRegs(int hwbType); 164 165 uint32_t CalculateFprOffset(const RegisterInfo *reg_info) const; 166 167 RegisterInfoPOSIX_arm64 &GetRegisterInfo() const; 168 169 void ConfigureRegisterContext(); 170 171 uint32_t CalculateSVEOffset(const RegisterInfo *reg_info) const; 172 }; 173 174 } // namespace process_linux 175 } // namespace lldb_private 176 177 #endif // #ifndef lldb_NativeRegisterContextLinux_arm64_h 178 179 #endif // defined (__arm64__) || defined (__aarch64__) 180