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