1 //===-- NativeRegisterContextLinux_arm.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 #if defined(__arm__) // arm register context only needed on arm devices
11 
12 #ifndef lldb_NativeRegisterContextLinux_arm_h
13 #define lldb_NativeRegisterContextLinux_arm_h
14 
15 #include "Plugins/Process/Linux/NativeRegisterContextLinux.h"
16 #include "Plugins/Process/Utility/lldb-arm-register-enums.h"
17 
18 namespace lldb_private {
19 namespace process_linux {
20 
21     class NativeProcessLinux;
22 
23     class NativeRegisterContextLinux_arm : public NativeRegisterContextLinux
24     {
25     public:
26         NativeRegisterContextLinux_arm (const ArchSpec& target_arch,
27                                         NativeThreadProtocol &native_thread,
28                                         uint32_t concrete_frame_idx);
29 
30         uint32_t
31         GetRegisterSetCount () const override;
32 
33         const RegisterSet *
34         GetRegisterSet (uint32_t set_index) const override;
35 
36         uint32_t
37         GetUserRegisterCount() const override;
38 
39         Error
40         ReadRegister (const RegisterInfo *reg_info, RegisterValue &reg_value) override;
41 
42         Error
43         WriteRegister (const RegisterInfo *reg_info, const RegisterValue &reg_value) override;
44 
45         Error
46         ReadAllRegisterValues (lldb::DataBufferSP &data_sp) override;
47 
48         Error
49         WriteAllRegisterValues (const lldb::DataBufferSP &data_sp) override;
50 
51         //------------------------------------------------------------------
52         // Hardware breakpoints/watchpoint mangement functions
53         //------------------------------------------------------------------
54 
55         uint32_t
56         SetHardwareBreakpoint (lldb::addr_t addr, size_t size) override;
57 
58         bool
59         ClearHardwareBreakpoint (uint32_t hw_idx) override;
60 
61         uint32_t
62         NumSupportedHardwareWatchpoints () override;
63 
64         uint32_t
65         SetHardwareWatchpoint (lldb::addr_t addr, size_t size, uint32_t watch_flags) override;
66 
67         bool
68         ClearHardwareWatchpoint (uint32_t hw_index) override;
69 
70         Error
71         ClearAllHardwareWatchpoints () override;
72 
73         Error
74         GetWatchpointHitIndex(uint32_t &wp_index, lldb::addr_t trap_addr) override;
75 
76         lldb::addr_t
77         GetWatchpointAddress (uint32_t wp_index) override;
78 
79         uint32_t
80         GetWatchpointSize(uint32_t wp_index);
81 
82         bool
83         WatchpointIsEnabled(uint32_t wp_index);
84 
85         // Debug register type select
86         enum DREGType
87         {
88             eDREGTypeWATCH = 0,
89             eDREGTypeBREAK
90         };
91 
92     protected:
93         void*
94         GetGPRBuffer() override { return &m_gpr_arm; }
95 
96         void*
97         GetFPRBuffer() override { return &m_fpr; }
98 
99         size_t
100         GetFPRSize() override { return sizeof(m_fpr); }
101 
102     private:
103         struct RegInfo
104         {
105             uint32_t num_registers;
106             uint32_t num_gpr_registers;
107             uint32_t num_fpr_registers;
108 
109             uint32_t last_gpr;
110             uint32_t first_fpr;
111             uint32_t last_fpr;
112 
113             uint32_t first_fpr_v;
114             uint32_t last_fpr_v;
115 
116             uint32_t gpr_flags;
117         };
118 
119         struct QReg
120         {
121             uint8_t bytes[16];
122         };
123 
124         struct FPU
125         {
126             union {
127                 uint32_t s[32];
128                 uint64_t d[32];
129                 QReg     q[16];  // the 128-bit NEON registers
130                 } floats;
131             uint32_t fpscr;
132         };
133 
134         uint32_t m_gpr_arm[k_num_gpr_registers_arm];
135         RegInfo  m_reg_info;
136         FPU m_fpr;
137 
138         // Debug register info for hardware breakpoints and watchpoints management.
139         struct DREG
140         {
141             lldb::addr_t address;  // Breakpoint/watchpoint address value.
142             uint32_t control;  // Breakpoint/watchpoint control value.
143             uint32_t refcount;  // Serves as enable/disable and refernce counter.
144         };
145 
146         struct DREG m_hbr_regs[16];  // Arm native linux hardware breakpoints
147         struct DREG m_hwp_regs[16];  // Arm native linux hardware watchpoints
148 
149         uint32_t m_max_hwp_supported;
150         uint32_t m_max_hbp_supported;
151         bool m_refresh_hwdebug_info;
152 
153         bool
154         IsGPR(unsigned reg) const;
155 
156         bool
157         IsFPR(unsigned reg) const;
158 
159         Error
160         ReadHardwareDebugInfo();
161 
162         Error
163         WriteHardwareDebugRegs(int hwbType, int hwb_index);
164 
165         uint32_t
166         CalculateFprOffset(const RegisterInfo* reg_info) const;
167     };
168 
169 } // namespace process_linux
170 } // namespace lldb_private
171 
172 #endif // #ifndef lldb_NativeRegisterContextLinux_arm_h
173 
174 #endif // defined(__arm__)
175