//===-- DNBArchImplI386.h ---------------------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // Created by Greg Clayton on 6/25/07. // //===----------------------------------------------------------------------===// #ifndef __DNBArchImplI386_h__ #define __DNBArchImplI386_h__ #if defined (__i386__) || defined (__x86_64__) #include "DNBArch.h" #include "../HasAVX.h" #include "MachRegisterStatesI386.h" class MachThread; class DNBArchImplI386 : public DNBArchProtocol { public: DNBArchImplI386(MachThread *thread) : m_thread(thread), m_state(), m_2pc_dbg_checkpoint(), m_2pc_trans_state(Trans_Done) { } virtual ~DNBArchImplI386() { } static void Initialize(); virtual bool GetRegisterValue(int set, int reg, DNBRegisterValue *value); virtual bool SetRegisterValue(int set, int reg, const DNBRegisterValue *value); virtual nub_size_t GetRegisterContext (void *buf, nub_size_t buf_len); virtual nub_size_t SetRegisterContext (const void *buf, nub_size_t buf_len); virtual kern_return_t GetRegisterState (int set, bool force); virtual kern_return_t SetRegisterState (int set); virtual bool RegisterSetStateIsValid (int set) const; virtual uint64_t GetPC(uint64_t failValue); // Get program counter virtual kern_return_t SetPC(uint64_t value); virtual uint64_t GetSP(uint64_t failValue); // Get stack pointer virtual void ThreadWillResume(); virtual bool ThreadDidStop(); virtual bool NotifyException(MachException::Data& exc); virtual uint32_t NumSupportedHardwareWatchpoints(); virtual uint32_t EnableHardwareWatchpoint (nub_addr_t addr, nub_size_t size, bool read, bool write, bool also_set_on_task); virtual bool DisableHardwareWatchpoint (uint32_t hw_break_index, bool also_set_on_task); virtual uint32_t GetHardwareWatchpointHit(nub_addr_t &addr); protected: kern_return_t EnableHardwareSingleStep (bool enable); typedef __i386_thread_state_t GPR; typedef __i386_float_state_t FPU; typedef __i386_exception_state_t EXC; typedef __i386_avx_state_t AVX; typedef __i386_debug_state_t DBG; static const DNBRegisterInfo g_gpr_registers[]; static const DNBRegisterInfo g_fpu_registers_no_avx[]; static const DNBRegisterInfo g_fpu_registers_avx[]; static const DNBRegisterInfo g_exc_registers[]; static const DNBRegisterSetInfo g_reg_sets_no_avx[]; static const DNBRegisterSetInfo g_reg_sets_avx[]; static const size_t k_num_gpr_registers; static const size_t k_num_fpu_registers_no_avx; static const size_t k_num_fpu_registers_avx; static const size_t k_num_exc_registers; static const size_t k_num_all_registers_no_avx; static const size_t k_num_all_registers_avx; static const size_t k_num_register_sets; typedef enum RegisterSetTag { e_regSetALL = REGISTER_SET_ALL, e_regSetGPR, e_regSetFPU, e_regSetEXC, e_regSetDBG, kNumRegisterSets } RegisterSet; typedef enum RegisterSetWordSizeTag { e_regSetWordSizeGPR = sizeof(GPR) / sizeof(int), e_regSetWordSizeFPU = sizeof(FPU) / sizeof(int), e_regSetWordSizeEXC = sizeof(EXC) / sizeof(int), e_regSetWordSizeAVX = sizeof(AVX) / sizeof(int), e_regSetWordSizeDBG = sizeof(DBG) / sizeof(int) } RegisterSetWordSize; enum { Read = 0, Write = 1, kNumErrors = 2 }; struct Context { GPR gpr; union { FPU no_avx; AVX avx; } fpu; EXC exc; DBG dbg; }; struct State { Context context; kern_return_t gpr_errs[2]; // Read/Write errors kern_return_t fpu_errs[2]; // Read/Write errors kern_return_t exc_errs[2]; // Read/Write errors kern_return_t dbg_errs[2]; // Read/Write errors State() { uint32_t i; for (i=0; i