1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ART_RUNTIME_ARCH_X86_CONTEXT_X86_H_ 18 #define ART_RUNTIME_ARCH_X86_CONTEXT_X86_H_ 19 20 #include <android-base/logging.h> 21 22 #include "arch/context.h" 23 #include "base/macros.h" 24 #include "registers_x86.h" 25 26 namespace art { 27 namespace x86 { 28 29 class X86Context final : public Context { 30 public: X86Context()31 X86Context() { 32 Reset(); 33 } ~X86Context()34 virtual ~X86Context() {} 35 36 void Reset() override; 37 38 void FillCalleeSaves(uint8_t* frame, const QuickMethodFrameInfo& fr) override; 39 SetSP(uintptr_t new_sp)40 void SetSP(uintptr_t new_sp) override { 41 SetGPR(ESP, new_sp); 42 } 43 SetPC(uintptr_t new_pc)44 void SetPC(uintptr_t new_pc) override { 45 eip_ = new_pc; 46 } 47 SetNterpDexPC(uintptr_t dex_pc_ptr)48 void SetNterpDexPC(uintptr_t dex_pc_ptr) override { 49 SetGPR(ESI, dex_pc_ptr); 50 } 51 SetArg0(uintptr_t new_arg0_value)52 void SetArg0(uintptr_t new_arg0_value) override { 53 SetGPR(EAX, new_arg0_value); 54 } 55 IsAccessibleGPR(uint32_t reg)56 bool IsAccessibleGPR(uint32_t reg) override { 57 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCpuRegisters)); 58 return gprs_[reg] != nullptr; 59 } 60 GetGPRAddress(uint32_t reg)61 uintptr_t* GetGPRAddress(uint32_t reg) override { 62 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCpuRegisters)); 63 return gprs_[reg]; 64 } 65 GetGPR(uint32_t reg)66 uintptr_t GetGPR(uint32_t reg) override { 67 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCpuRegisters)); 68 DCHECK(IsAccessibleGPR(reg)); 69 return *gprs_[reg]; 70 } 71 72 void SetGPR(uint32_t reg, uintptr_t value) override; 73 IsAccessibleFPR(uint32_t reg)74 bool IsAccessibleFPR(uint32_t reg) override { 75 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfFloatRegisters)); 76 return fprs_[reg] != nullptr; 77 } 78 GetFPR(uint32_t reg)79 uintptr_t GetFPR(uint32_t reg) override { 80 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfFloatRegisters)); 81 DCHECK(IsAccessibleFPR(reg)); 82 return *fprs_[reg]; 83 } 84 85 void SetFPR(uint32_t reg, uintptr_t value) override; 86 87 void SmashCallerSaves() override; 88 NO_RETURN void DoLongJump() override; 89 90 private: 91 // Pretend XMM registers are made of uin32_t pieces, because they are manipulated 92 // in uint32_t chunks. 93 enum { 94 XMM0_0 = 0, XMM0_1, 95 XMM1_0, XMM1_1, 96 XMM2_0, XMM2_1, 97 XMM3_0, XMM3_1, 98 XMM4_0, XMM4_1, 99 XMM5_0, XMM5_1, 100 XMM6_0, XMM6_1, 101 XMM7_0, XMM7_1, 102 kNumberOfFloatRegisters}; 103 104 // Pointers to register locations. Values are initialized to null or the special registers below. 105 uintptr_t* gprs_[kNumberOfCpuRegisters]; 106 uint32_t* fprs_[kNumberOfFloatRegisters]; 107 // Hold values for esp, eip and arg0 if they are not located within a stack frame. EIP is somewhat 108 // special in that it cannot be encoded normally as a register operand to an instruction (except 109 // in 64bit addressing modes). 110 uintptr_t esp_, eip_, arg0_; 111 }; 112 } // namespace x86 113 } // namespace art 114 115 #endif // ART_RUNTIME_ARCH_X86_CONTEXT_X86_H_ 116