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::DataBufferSP &data_sp) override;
47 
48   Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override;
49 
50   //------------------------------------------------------------------
51   // Hardware watchpoint management functions
52   //------------------------------------------------------------------
53 
54   uint32_t NumSupportedHardwareWatchpoints() override;
55 
56   uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
57                                  uint32_t watch_flags) override;
58 
59   bool ClearHardwareWatchpoint(uint32_t hw_index) override;
60 
61   Status GetWatchpointHitIndex(uint32_t &wp_index,
62                                lldb::addr_t trap_addr) override;
63 
64   lldb::addr_t GetWatchpointHitAddress(uint32_t wp_index) override;
65 
66   lldb::addr_t GetWatchpointAddress(uint32_t wp_index) override;
67 
68   uint32_t GetWatchpointSize(uint32_t wp_index);
69 
70   bool WatchpointIsEnabled(uint32_t wp_index);
71 
72 protected:
73   Status DoReadGPR(void *buf, size_t buf_size) override;
74 
75   Status DoWriteGPR(void *buf, size_t buf_size) override;
76 
77   Status DoReadFPR(void *buf, size_t buf_size) override;
78 
79   Status DoWriteFPR(void *buf, size_t buf_size) override;
80 
81   bool IsVMX(unsigned reg);
82 
83   bool IsVSX(unsigned reg);
84 
85   Status ReadVMX();
86 
87   Status WriteVMX();
88 
89   Status ReadVSX();
90 
91   Status WriteVSX();
92 
93   void *GetGPRBuffer() override { return &m_gpr_ppc64le; }
94 
95   void *GetFPRBuffer() override { return &m_fpr_ppc64le; }
96 
97   size_t GetFPRSize() override { return sizeof(m_fpr_ppc64le); }
98 
99 private:
100   GPR m_gpr_ppc64le; // 64-bit general purpose registers.
101   FPR m_fpr_ppc64le; // floating-point registers including extended register.
102   VMX m_vmx_ppc64le; // VMX registers.
103   VSX m_vsx_ppc64le; // Last lower bytes from first VSX registers.
104 
105   bool IsGPR(unsigned reg) const;
106 
107   bool IsFPR(unsigned reg) const;
108 
109   bool IsVMX(unsigned reg) const;
110 
111   bool IsVSX(unsigned reg) const;
112 
113   uint32_t CalculateFprOffset(const RegisterInfo *reg_info) const;
114 
115   uint32_t CalculateVmxOffset(const RegisterInfo *reg_info) const;
116 
117   uint32_t CalculateVsxOffset(const RegisterInfo *reg_info) const;
118 
119   Status ReadHardwareDebugInfo();
120 
121   Status WriteHardwareDebugRegs();
122 
123   // Debug register info for hardware watchpoints management.
124   struct DREG {
125     lldb::addr_t address;   // Breakpoint/watchpoint address value.
126     lldb::addr_t hit_addr;  // Address at which last watchpoint trigger
127                             // exception occurred.
128     lldb::addr_t real_addr; // Address value that should cause target to stop.
129     uint32_t control;       // Breakpoint/watchpoint control value.
130     uint32_t refcount;      // Serves as enable/disable and reference counter.
131     long slot;              // Saves the value returned from PTRACE_SETHWDEBUG.
132     int mode;               // Defines if watchpoint is read/write/access.
133   };
134 
135   std::array<DREG, 4> m_hwp_regs;
136 
137   // 16 is just a maximum value, query hardware for actual watchpoint count
138   uint32_t m_max_hwp_supported = 16;
139   uint32_t m_max_hbp_supported = 16;
140   bool m_refresh_hwdebug_info = true;
141 };
142 
143 } // namespace process_linux
144 } // namespace lldb_private
145 
146 #endif // #ifndef lldb_NativeRegisterContextLinux_ppc64le_h
147 
148 #endif // defined(__powerpc64__)
149