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