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