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