]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.h
Upgrade to OpenSSH 6.9p1.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / Process / Utility / RegisterContextDarwin_arm64.h
1 //===-- RegisterContextDarwin_arm64.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 #ifndef liblldb_RegisterContextDarwin_arm64_h_
11 #define liblldb_RegisterContextDarwin_arm64_h_
12
13 // C Includes
14 // C++ Includes
15 // Other libraries and framework includes
16 // Project includes
17 #include "lldb/lldb-private.h"
18 #include "lldb/Target/RegisterContext.h"
19
20 // Break only in privileged or user mode
21 #define S_RSVD                  ((uint32_t)(0u << 1))
22 #define S_PRIV                  ((uint32_t)(1u << 1))
23 #define S_USER                  ((uint32_t)(2u << 1))
24 #define S_PRIV_USER             ((S_PRIV) | (S_USER))
25
26 #define WCR_ENABLE              ((uint32_t)(1u))
27
28 // Watchpoint load/store
29 #define WCR_LOAD                ((uint32_t)(1u << 3))
30 #define WCR_STORE               ((uint32_t)(1u << 4))
31
32 class RegisterContextDarwin_arm64 : public lldb_private::RegisterContext
33 {
34 public:
35
36     RegisterContextDarwin_arm64(lldb_private::Thread &thread, uint32_t concrete_frame_idx);
37
38     virtual
39     ~RegisterContextDarwin_arm64();
40
41     virtual void
42     InvalidateAllRegisters ();
43
44     virtual size_t
45     GetRegisterCount ();
46
47     virtual const lldb_private::RegisterInfo *
48     GetRegisterInfoAtIndex (size_t reg);
49
50     virtual size_t
51     GetRegisterSetCount ();
52
53     virtual const lldb_private::RegisterSet *
54     GetRegisterSet (size_t set);
55
56     virtual bool
57     ReadRegister (const lldb_private::RegisterInfo *reg_info, 
58                   lldb_private::RegisterValue &reg_value);
59     
60     virtual bool
61     WriteRegister (const lldb_private::RegisterInfo *reg_info,
62                    const lldb_private::RegisterValue &reg_value);
63     
64     virtual bool
65     ReadAllRegisterValues (lldb::DataBufferSP &data_sp);
66
67     virtual bool
68     WriteAllRegisterValues (const lldb::DataBufferSP &data_sp);
69
70     virtual uint32_t
71     ConvertRegisterKindToRegisterNumber (lldb::RegisterKind kind, uint32_t num);
72
73     virtual uint32_t
74     NumSupportedHardwareWatchpoints ();
75
76     virtual uint32_t
77     SetHardwareWatchpoint (lldb::addr_t addr, size_t size, bool read, bool write);
78
79     virtual bool
80     ClearHardwareWatchpoint (uint32_t hw_index);
81
82     // mirrors <mach/arm/thread_status.h> arm_thread_state64_t
83     struct GPR
84     {
85         uint64_t    x[29];  // x0-x28
86         uint64_t    fp;     // x29
87         uint64_t    lr;     // x30
88         uint64_t    sp;     // x31
89         uint64_t    pc;     // pc
90         uint32_t    cpsr;   // cpsr
91     };
92
93
94     struct VReg
95     {
96         uint8_t bytes[16];
97     };
98
99     // mirrors <mach/arm/thread_status.h> arm_neon_state64_t
100     struct FPU
101     {
102         VReg        v[32];
103         uint32_t    fpsr;
104         uint32_t    fpcr;
105     };
106
107     // mirrors <mach/arm/thread_status.h> arm_exception_state64_t
108     struct EXC
109     {
110         uint64_t    far;       // Virtual Fault Address
111         uint32_t    esr;       // Exception syndrome
112         uint32_t    exception; // number of arm exception token
113     };
114
115     // mirrors <mach/arm/thread_status.h> arm_debug_state64_t
116     struct DBG
117     {
118         uint64_t bvr[16];
119         uint64_t bcr[16];
120         uint64_t wvr[16];
121         uint64_t wcr[16];
122         uint64_t mdscr_el1;
123     };
124
125     static void
126     LogDBGRegisters (lldb_private::Log *log, const DBG& dbg);
127
128 protected:
129
130     enum
131     {
132         GPRRegSet = 6,  // ARM_THREAD_STATE64
133         FPURegSet = 17, // ARM_NEON_STATE64
134         EXCRegSet = 7,  // ARM_EXCEPTION_STATE64
135         DBGRegSet = 15  // ARM_DEBUG_STATE64
136     };
137
138     enum
139     {
140         GPRWordCount = sizeof(GPR)/sizeof(uint32_t),  // ARM_THREAD_STATE64_COUNT
141         FPUWordCount = sizeof(FPU)/sizeof(uint32_t),  // ARM_NEON_STATE64_COUNT
142         EXCWordCount = sizeof(EXC)/sizeof(uint32_t),  // ARM_EXCEPTION_STATE64_COUNT
143         DBGWordCount = sizeof(DBG)/sizeof(uint32_t)   // ARM_DEBUG_STATE64_COUNT
144     };
145
146     enum
147     {
148         Read = 0,
149         Write = 1,
150         kNumErrors = 2
151     };
152
153     GPR gpr;
154     FPU fpu;
155     EXC exc;
156     DBG dbg;
157     int gpr_errs[2]; // Read/Write errors
158     int fpu_errs[2]; // Read/Write errors
159     int exc_errs[2]; // Read/Write errors
160     int dbg_errs[2]; // Read/Write errors
161
162     void
163     InvalidateAllRegisterStates()
164     {
165         SetError (GPRRegSet, Read, -1);
166         SetError (FPURegSet, Read, -1);
167         SetError (EXCRegSet, Read, -1);
168     }
169
170     int
171     GetError (int flavor, uint32_t err_idx) const
172     {
173         if (err_idx < kNumErrors)
174         {
175             switch (flavor)
176             {
177             // When getting all errors, just OR all values together to see if
178             // we got any kind of error.
179             case GPRRegSet:    return gpr_errs[err_idx];
180             case FPURegSet:    return fpu_errs[err_idx];
181             case EXCRegSet:    return exc_errs[err_idx];
182             case DBGRegSet:    return dbg_errs[err_idx];
183             default: break;
184             }
185         }
186         return -1;
187     }
188
189     bool
190     SetError (int flavor, uint32_t err_idx, int err)
191     {
192         if (err_idx < kNumErrors)
193         {
194             switch (flavor)
195             {
196             case GPRRegSet:
197                 gpr_errs[err_idx] = err;
198                 return true;
199
200             case FPURegSet:
201                 fpu_errs[err_idx] = err;
202                 return true;
203
204             case EXCRegSet:
205                 exc_errs[err_idx] = err;
206                 return true;
207
208             case DBGRegSet:
209                 exc_errs[err_idx] = err;
210                 return true;
211
212             default: break;
213             }
214         }
215         return false;
216     }
217
218     bool
219     RegisterSetIsCached (int set) const
220     {
221         return GetError(set, Read) == 0;
222     }
223
224     int
225     ReadGPR (bool force);
226
227     int
228     ReadFPU (bool force);
229
230     int
231     ReadEXC (bool force);
232
233     int
234     ReadDBG (bool force);
235
236     int
237     WriteGPR ();
238
239     int
240     WriteFPU ();
241
242     int
243     WriteEXC ();
244
245     int
246     WriteDBG ();
247
248     
249     // Subclasses override these to do the actual reading.
250     virtual int
251     DoReadGPR (lldb::tid_t tid, int flavor, GPR &gpr)
252     {
253         return -1;
254     }
255     
256     virtual int
257     DoReadFPU (lldb::tid_t tid, int flavor, FPU &fpu) = 0;
258     
259     virtual int
260     DoReadEXC (lldb::tid_t tid, int flavor, EXC &exc) = 0;
261
262     virtual int
263     DoReadDBG (lldb::tid_t tid, int flavor, DBG &dbg) = 0;
264
265     virtual int
266     DoWriteGPR (lldb::tid_t tid, int flavor, const GPR &gpr) = 0;
267     
268     virtual int
269     DoWriteFPU (lldb::tid_t tid, int flavor, const FPU &fpu) = 0;
270     
271     virtual int
272     DoWriteEXC (lldb::tid_t tid, int flavor, const EXC &exc) = 0;
273
274     virtual int
275     DoWriteDBG (lldb::tid_t tid, int flavor, const DBG &dbg) = 0;
276
277     int
278     ReadRegisterSet (uint32_t set, bool force);
279
280     int
281     WriteRegisterSet (uint32_t set);
282
283     static uint32_t
284     GetRegisterNumber (uint32_t reg_kind, uint32_t reg_num);
285
286     static int
287     GetSetForNativeRegNum (int reg_num);
288
289     static size_t
290     GetRegisterInfosCount ();
291
292     static const lldb_private::RegisterInfo *
293     GetRegisterInfos ();
294 };
295
296 #endif  // liblldb_RegisterContextDarwin_arm64_h_