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 protected:
110   struct RegInfo {
111     uint32_t num_registers;
112     uint32_t num_gpr_registers;
113     uint32_t num_fpr_registers;
114     uint32_t num_avx_registers;
115 
116     uint32_t last_gpr;
117     uint32_t first_fpr;
118     uint32_t last_fpr;
119 
120     uint32_t first_st;
121     uint32_t last_st;
122     uint32_t first_mm;
123     uint32_t last_mm;
124     uint32_t first_xmm;
125     uint32_t last_xmm;
126     uint32_t first_ymm;
127     uint32_t last_ymm;
128 
129     uint32_t first_dr;
130     uint32_t gpr_flags;
131   };
132 
133   uint64_t m_gpr_x86_64[lldb_private::k_num_gpr_registers_x86_64]; // 64-bit
134                                                                    // general
135                                                                    // purpose
136                                                                    // registers.
137   RegInfo m_reg_info;
138   FPRType
139       m_fpr_type; // determines the type of data stored by union FPR, if any.
140   lldb_private::FPR m_fpr;     // floating-point registers including extended
141                                // register sets.
142   lldb_private::YMM m_ymm_set; // copy of ymmh and xmm register halves.
143   std::unique_ptr<lldb_private::RegisterInfoInterface>
144       m_register_info_up; // Register Info Interface (FreeBSD or Linux)
145 
146   // Determines if an extended register set is supported on the processor
147   // running the inferior process.
148   virtual bool IsRegisterSetAvailable(size_t set_index);
149 
150   virtual const lldb_private::RegisterInfo *GetRegisterInfo();
151 
152   bool IsGPR(unsigned reg);
153 
154   bool IsFPR(unsigned reg);
155 
156   bool IsAVX(unsigned reg);
157 
158   bool CopyXSTATEtoYMM(uint32_t reg, lldb::ByteOrder byte_order);
159   bool CopyYMMtoXSTATE(uint32_t reg, lldb::ByteOrder byte_order);
160   bool IsFPR(unsigned reg, FPRType fpr_type);
161   FPRType GetFPRType();
162 
163   virtual bool ReadGPR() = 0;
164   virtual bool ReadFPR() = 0;
165   virtual bool WriteGPR() = 0;
166   virtual bool WriteFPR() = 0;
167 };
168 
169 #endif // LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTPOSIX_X86_H
170