1 //===-- RegisterContextPOSIX_x86.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_RegisterContextPOSIX_x86_h_
11 #define liblldb_RegisterContextPOSIX_x86_h_
12 
13 // C Includes
14 // C++ Includes
15 // Other libraries and framework includes
16 // Project includes
17 #include "RegisterContext_x86.h"
18 #include "RegisterInfoInterface.h"
19 #include "lldb-x86-register-enums.h"
20 #include "lldb/Core/Log.h"
21 #include "lldb/Target/RegisterContext.h"
22 
23 class ProcessMonitor;
24 
25 class RegisterContextPOSIX_x86 : public lldb_private::RegisterContext {
26 public:
27   RegisterContextPOSIX_x86(lldb_private::Thread &thread,
28                            uint32_t concrete_frame_idx,
29                            lldb_private::RegisterInfoInterface *register_info);
30 
31   ~RegisterContextPOSIX_x86() override;
32 
33   void Invalidate();
34 
35   void InvalidateAllRegisters() override;
36 
37   size_t GetRegisterCount() override;
38 
39   virtual size_t GetGPRSize();
40 
41   virtual unsigned GetRegisterSize(unsigned reg);
42 
43   virtual unsigned GetRegisterOffset(unsigned reg);
44 
45   const lldb_private::RegisterInfo *GetRegisterInfoAtIndex(size_t reg) override;
46 
47   size_t GetRegisterSetCount() override;
48 
49   const lldb_private::RegisterSet *GetRegisterSet(size_t set) override;
50 
51   const char *GetRegisterName(unsigned reg);
52 
53   uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind,
54                                                uint32_t num) override;
55 
56   //---------------------------------------------------------------------------
57   // Note: prefer kernel definitions over user-land
58   //---------------------------------------------------------------------------
59   enum FPRType {
60     eNotValid = 0,
61     eFSAVE, // TODO
62     eFXSAVE,
63     eSOFT, // TODO
64     eXSAVE
65   };
66 
67   static uint32_t g_contained_eax[];
68   static uint32_t g_contained_ebx[];
69   static uint32_t g_contained_ecx[];
70   static uint32_t g_contained_edx[];
71   static uint32_t g_contained_edi[];
72   static uint32_t g_contained_esi[];
73   static uint32_t g_contained_ebp[];
74   static uint32_t g_contained_esp[];
75 
76   static uint32_t g_invalidate_eax[];
77   static uint32_t g_invalidate_ebx[];
78   static uint32_t g_invalidate_ecx[];
79   static uint32_t g_invalidate_edx[];
80   static uint32_t g_invalidate_edi[];
81   static uint32_t g_invalidate_esi[];
82   static uint32_t g_invalidate_ebp[];
83   static uint32_t g_invalidate_esp[];
84 
85   static uint32_t g_contained_rax[];
86   static uint32_t g_contained_rbx[];
87   static uint32_t g_contained_rcx[];
88   static uint32_t g_contained_rdx[];
89   static uint32_t g_contained_rdi[];
90   static uint32_t g_contained_rsi[];
91   static uint32_t g_contained_rbp[];
92   static uint32_t g_contained_rsp[];
93   static uint32_t g_contained_r8[];
94   static uint32_t g_contained_r9[];
95   static uint32_t g_contained_r10[];
96   static uint32_t g_contained_r11[];
97   static uint32_t g_contained_r12[];
98   static uint32_t g_contained_r13[];
99   static uint32_t g_contained_r14[];
100   static uint32_t g_contained_r15[];
101 
102   static uint32_t g_invalidate_rax[];
103   static uint32_t g_invalidate_rbx[];
104   static uint32_t g_invalidate_rcx[];
105   static uint32_t g_invalidate_rdx[];
106   static uint32_t g_invalidate_rdi[];
107   static uint32_t g_invalidate_rsi[];
108   static uint32_t g_invalidate_rbp[];
109   static uint32_t g_invalidate_rsp[];
110   static uint32_t g_invalidate_r8[];
111   static uint32_t g_invalidate_r9[];
112   static uint32_t g_invalidate_r10[];
113   static uint32_t g_invalidate_r11[];
114   static uint32_t g_invalidate_r12[];
115   static uint32_t g_invalidate_r13[];
116   static uint32_t g_invalidate_r14[];
117   static uint32_t g_invalidate_r15[];
118 
119 protected:
120   struct RegInfo {
121     uint32_t num_registers;
122     uint32_t num_gpr_registers;
123     uint32_t num_fpr_registers;
124     uint32_t num_avx_registers;
125 
126     uint32_t last_gpr;
127     uint32_t first_fpr;
128     uint32_t last_fpr;
129 
130     uint32_t first_st;
131     uint32_t last_st;
132     uint32_t first_mm;
133     uint32_t last_mm;
134     uint32_t first_xmm;
135     uint32_t last_xmm;
136     uint32_t first_ymm;
137     uint32_t last_ymm;
138 
139     uint32_t first_dr;
140     uint32_t gpr_flags;
141   };
142 
143   uint64_t m_gpr_x86_64[lldb_private::k_num_gpr_registers_x86_64]; // 64-bit
144                                                                    // general
145                                                                    // purpose
146                                                                    // registers.
147   RegInfo m_reg_info;
148   FPRType
149       m_fpr_type; // determines the type of data stored by union FPR, if any.
150   FPR m_fpr;      // floating-point registers including extended register sets.
151   IOVEC m_iovec;  // wrapper for xsave.
152   YMM m_ymm_set;  // copy of ymmh and xmm register halves.
153   std::unique_ptr<lldb_private::RegisterInfoInterface>
154       m_register_info_ap; // Register Info Interface (FreeBSD or Linux)
155 
156   // Determines if an extended register set is supported on the processor
157   // running the inferior process.
158   virtual bool IsRegisterSetAvailable(size_t set_index);
159 
160   virtual const lldb_private::RegisterInfo *GetRegisterInfo();
161 
162   bool IsGPR(unsigned reg);
163 
164   bool IsFPR(unsigned reg);
165 
166   bool IsAVX(unsigned reg);
167 
168   lldb::ByteOrder GetByteOrder();
169 
170   bool CopyXSTATEtoYMM(uint32_t reg, lldb::ByteOrder byte_order);
171   bool CopyYMMtoXSTATE(uint32_t reg, lldb::ByteOrder byte_order);
172   bool IsFPR(unsigned reg, FPRType fpr_type);
173   FPRType GetFPRType();
174 
175   virtual bool ReadGPR() = 0;
176   virtual bool ReadFPR() = 0;
177   virtual bool WriteGPR() = 0;
178   virtual bool WriteFPR() = 0;
179 };
180 
181 #endif // liblldb_RegisterContextPOSIX_x86_h_
182