xref: /llvm-project/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.h (revision 6f59f302e4358b4dc869bc298c2b9c06aa716b60)
1 //===-- NativeRegisterContextLinux_ppc64le.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 // This implementation is related to the OpenPOWER ABI for Power Architecture
10 // 64-bit ELF V2 ABI
11 
12 #if defined(__powerpc64__)
13 
14 #ifndef lldb_NativeRegisterContextLinux_ppc64le_h
15 #define lldb_NativeRegisterContextLinux_ppc64le_h
16 
17 #include "Plugins/Process/Linux/NativeRegisterContextLinux.h"
18 #include "Plugins/Process/Utility/lldb-ppc64le-register-enums.h"
19 
20 #define DECLARE_REGISTER_INFOS_PPC64LE_STRUCT
21 #include "Plugins/Process/Utility/RegisterInfos_ppc64le.h"
22 #undef DECLARE_REGISTER_INFOS_PPC64LE_STRUCT
23 
24 namespace lldb_private {
25 namespace process_linux {
26 
27 class NativeProcessLinux;
28 
29 class NativeRegisterContextLinux_ppc64le : public NativeRegisterContextLinux {
30 public:
31   NativeRegisterContextLinux_ppc64le(const ArchSpec &target_arch,
32                                      NativeThreadProtocol &native_thread);
33 
34   uint32_t GetRegisterSetCount() const override;
35 
36   uint32_t GetUserRegisterCount() const override;
37 
38   const RegisterSet *GetRegisterSet(uint32_t set_index) const override;
39 
40   Status ReadRegister(const RegisterInfo *reg_info,
41                       RegisterValue &reg_value) override;
42 
43   Status WriteRegister(const RegisterInfo *reg_info,
44                        const RegisterValue &reg_value) override;
45 
46   Status ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override;
47 
48   Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override;
49 
50   // Hardware watchpoint management functions
51 
52   uint32_t NumSupportedHardwareWatchpoints() override;
53 
54   uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
55                                  uint32_t watch_flags) override;
56 
57   bool ClearHardwareWatchpoint(uint32_t hw_index) override;
58 
59   Status GetWatchpointHitIndex(uint32_t &wp_index,
60                                lldb::addr_t trap_addr) override;
61 
62   lldb::addr_t GetWatchpointHitAddress(uint32_t wp_index) override;
63 
64   lldb::addr_t GetWatchpointAddress(uint32_t wp_index) override;
65 
66   uint32_t GetWatchpointSize(uint32_t wp_index);
67 
68   bool WatchpointIsEnabled(uint32_t wp_index);
69 
70 protected:
71   bool IsVMX(unsigned reg);
72 
73   bool IsVSX(unsigned reg);
74 
75   Status ReadVMX();
76 
77   Status WriteVMX();
78 
79   Status ReadVSX();
80 
81   Status WriteVSX();
82 
GetGPRBuffer()83   void *GetGPRBuffer() override { return &m_gpr_ppc64le; }
84 
GetFPRBuffer()85   void *GetFPRBuffer() override { return &m_fpr_ppc64le; }
86 
GetFPRSize()87   size_t GetFPRSize() override { return sizeof(m_fpr_ppc64le); }
88 
89 private:
90   GPR m_gpr_ppc64le; // 64-bit general purpose registers.
91   FPR m_fpr_ppc64le; // floating-point registers including extended register.
92   VMX m_vmx_ppc64le; // VMX registers.
93   VSX m_vsx_ppc64le; // Last lower bytes from first VSX registers.
94 
95   bool IsGPR(unsigned reg) const;
96 
97   bool IsFPR(unsigned reg) const;
98 
99   bool IsVMX(unsigned reg) const;
100 
101   bool IsVSX(unsigned reg) const;
102 
103   uint32_t CalculateFprOffset(const RegisterInfo *reg_info) const;
104 
105   uint32_t CalculateVmxOffset(const RegisterInfo *reg_info) const;
106 
107   uint32_t CalculateVsxOffset(const RegisterInfo *reg_info) const;
108 
109   Status ReadHardwareDebugInfo();
110 
111   Status WriteHardwareDebugRegs();
112 
113   // Debug register info for hardware watchpoints management.
114   struct DREG {
115     lldb::addr_t address;   // Breakpoint/watchpoint address value.
116     lldb::addr_t hit_addr;  // Address at which last watchpoint trigger
117                             // exception occurred.
118     lldb::addr_t real_addr; // Address value that should cause target to stop.
119     uint32_t control;       // Breakpoint/watchpoint control value.
120     uint32_t refcount;      // Serves as enable/disable and reference counter.
121     long slot;              // Saves the value returned from PTRACE_SETHWDEBUG.
122     int mode;               // Defines if watchpoint is read/write/access.
123   };
124 
125   std::array<DREG, 16> m_hwp_regs;
126 
127   // 16 is just a maximum value, query hardware for actual watchpoint count
128   uint32_t m_max_hwp_supported = 16;
129   uint32_t m_max_hbp_supported = 16;
130   bool m_refresh_hwdebug_info = true;
131 };
132 
133 } // namespace process_linux
134 } // namespace lldb_private
135 
136 #endif // #ifndef lldb_NativeRegisterContextLinux_ppc64le_h
137 
138 #endif // defined(__powerpc64__)
139