• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTPOSIX_X86_H
10 #define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_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 RegisterContextPOSIX_x86 : public lldb_private::RegisterContext {
19 public:
20   RegisterContextPOSIX_x86(lldb_private::Thread &thread,
21                            uint32_t concrete_frame_idx,
22                            lldb_private::RegisterInfoInterface *register_info);
23 
24   ~RegisterContextPOSIX_x86() override;
25 
26   void Invalidate();
27 
28   void InvalidateAllRegisters() override;
29 
30   size_t GetRegisterCount() override;
31 
32   virtual size_t GetGPRSize();
33 
34   virtual size_t GetFXSAVEOffset();
35 
36   virtual unsigned GetRegisterSize(unsigned reg);
37 
38   virtual unsigned GetRegisterOffset(unsigned reg);
39 
40   const lldb_private::RegisterInfo *GetRegisterInfoAtIndex(size_t reg) override;
41 
42   size_t GetRegisterSetCount() override;
43 
44   const lldb_private::RegisterSet *GetRegisterSet(size_t set) override;
45 
46   const char *GetRegisterName(unsigned reg);
47 
48   // Note: prefer kernel definitions over user-land
49   enum FPRType {
50     eNotValid = 0,
51     eFSAVE, // TODO
52     eFXSAVE,
53     eSOFT, // TODO
54     eXSAVE
55   };
56 
57   static uint32_t g_contained_eax[];
58   static uint32_t g_contained_ebx[];
59   static uint32_t g_contained_ecx[];
60   static uint32_t g_contained_edx[];
61   static uint32_t g_contained_edi[];
62   static uint32_t g_contained_esi[];
63   static uint32_t g_contained_ebp[];
64   static uint32_t g_contained_esp[];
65 
66   static uint32_t g_invalidate_eax[];
67   static uint32_t g_invalidate_ebx[];
68   static uint32_t g_invalidate_ecx[];
69   static uint32_t g_invalidate_edx[];
70   static uint32_t g_invalidate_edi[];
71   static uint32_t g_invalidate_esi[];
72   static uint32_t g_invalidate_ebp[];
73   static uint32_t g_invalidate_esp[];
74 
75   static uint32_t g_contained_rax[];
76   static uint32_t g_contained_rbx[];
77   static uint32_t g_contained_rcx[];
78   static uint32_t g_contained_rdx[];
79   static uint32_t g_contained_rdi[];
80   static uint32_t g_contained_rsi[];
81   static uint32_t g_contained_rbp[];
82   static uint32_t g_contained_rsp[];
83   static uint32_t g_contained_r8[];
84   static uint32_t g_contained_r9[];
85   static uint32_t g_contained_r10[];
86   static uint32_t g_contained_r11[];
87   static uint32_t g_contained_r12[];
88   static uint32_t g_contained_r13[];
89   static uint32_t g_contained_r14[];
90   static uint32_t g_contained_r15[];
91 
92   static uint32_t g_invalidate_rax[];
93   static uint32_t g_invalidate_rbx[];
94   static uint32_t g_invalidate_rcx[];
95   static uint32_t g_invalidate_rdx[];
96   static uint32_t g_invalidate_rdi[];
97   static uint32_t g_invalidate_rsi[];
98   static uint32_t g_invalidate_rbp[];
99   static uint32_t g_invalidate_rsp[];
100   static uint32_t g_invalidate_r8[];
101   static uint32_t g_invalidate_r9[];
102   static uint32_t g_invalidate_r10[];
103   static uint32_t g_invalidate_r11[];
104   static uint32_t g_invalidate_r12[];
105   static uint32_t g_invalidate_r13[];
106   static uint32_t g_invalidate_r14[];
107   static uint32_t g_invalidate_r15[];
108 
109   static uint32_t g_contained_fip[];
110   static uint32_t g_contained_fdp[];
111 
112   static uint32_t g_invalidate_fip[];
113   static uint32_t g_invalidate_fdp[];
114 
115   static uint32_t g_contained_st0_32[];
116   static uint32_t g_contained_st1_32[];
117   static uint32_t g_contained_st2_32[];
118   static uint32_t g_contained_st3_32[];
119   static uint32_t g_contained_st4_32[];
120   static uint32_t g_contained_st5_32[];
121   static uint32_t g_contained_st6_32[];
122   static uint32_t g_contained_st7_32[];
123 
124   static uint32_t g_invalidate_st0_32[];
125   static uint32_t g_invalidate_st1_32[];
126   static uint32_t g_invalidate_st2_32[];
127   static uint32_t g_invalidate_st3_32[];
128   static uint32_t g_invalidate_st4_32[];
129   static uint32_t g_invalidate_st5_32[];
130   static uint32_t g_invalidate_st6_32[];
131   static uint32_t g_invalidate_st7_32[];
132 
133   static uint32_t g_contained_st0_64[];
134   static uint32_t g_contained_st1_64[];
135   static uint32_t g_contained_st2_64[];
136   static uint32_t g_contained_st3_64[];
137   static uint32_t g_contained_st4_64[];
138   static uint32_t g_contained_st5_64[];
139   static uint32_t g_contained_st6_64[];
140   static uint32_t g_contained_st7_64[];
141 
142   static uint32_t g_invalidate_st0_64[];
143   static uint32_t g_invalidate_st1_64[];
144   static uint32_t g_invalidate_st2_64[];
145   static uint32_t g_invalidate_st3_64[];
146   static uint32_t g_invalidate_st4_64[];
147   static uint32_t g_invalidate_st5_64[];
148   static uint32_t g_invalidate_st6_64[];
149   static uint32_t g_invalidate_st7_64[];
150 
151 protected:
152   struct RegInfo {
153     uint32_t num_registers;
154     uint32_t num_gpr_registers;
155     uint32_t num_fpr_registers;
156     uint32_t num_avx_registers;
157 
158     uint32_t last_gpr;
159     uint32_t first_fpr;
160     uint32_t last_fpr;
161 
162     uint32_t first_st;
163     uint32_t last_st;
164     uint32_t first_mm;
165     uint32_t last_mm;
166     uint32_t first_xmm;
167     uint32_t last_xmm;
168     uint32_t first_ymm;
169     uint32_t last_ymm;
170 
171     uint32_t first_dr;
172     uint32_t gpr_flags;
173   };
174 
175   uint64_t m_gpr_x86_64[lldb_private::k_num_gpr_registers_x86_64]; // 64-bit
176                                                                    // general
177                                                                    // purpose
178                                                                    // registers.
179   RegInfo m_reg_info;
180   FPRType
181       m_fpr_type; // determines the type of data stored by union FPR, if any.
182   lldb_private::FPR m_fpr;     // floating-point registers including extended
183                                // register sets.
184   lldb_private::YMM m_ymm_set; // copy of ymmh and xmm register halves.
185   std::unique_ptr<lldb_private::RegisterInfoInterface>
186       m_register_info_up; // Register Info Interface (FreeBSD or Linux)
187 
188   // Determines if an extended register set is supported on the processor
189   // running the inferior process.
190   virtual bool IsRegisterSetAvailable(size_t set_index);
191 
192   virtual const lldb_private::RegisterInfo *GetRegisterInfo();
193 
194   bool IsGPR(unsigned reg);
195 
196   bool IsFPR(unsigned reg);
197 
198   bool IsAVX(unsigned reg);
199 
200   bool CopyXSTATEtoYMM(uint32_t reg, lldb::ByteOrder byte_order);
201   bool CopyYMMtoXSTATE(uint32_t reg, lldb::ByteOrder byte_order);
202   bool IsFPR(unsigned reg, FPRType fpr_type);
203   FPRType GetFPRType();
204 
205   virtual bool ReadGPR() = 0;
206   virtual bool ReadFPR() = 0;
207   virtual bool WriteGPR() = 0;
208   virtual bool WriteFPR() = 0;
209 };
210 
211 #endif // LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTPOSIX_X86_H
212