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 "arch/context.h" 21 #include "base/logging.h" 22 #include "registers_x86.h" 23 24 namespace art { 25 namespace x86 { 26 27 class X86Context : public Context { 28 public: X86Context()29 X86Context() { 30 Reset(); 31 } ~X86Context()32 virtual ~X86Context() {} 33 34 void Reset() OVERRIDE; 35 36 void FillCalleeSaves(const StackVisitor& fr) OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 37 SetSP(uintptr_t new_sp)38 void SetSP(uintptr_t new_sp) OVERRIDE { 39 bool success = SetGPR(ESP, new_sp); 40 CHECK(success) << "Failed to set ESP register"; 41 } 42 SetPC(uintptr_t new_pc)43 void SetPC(uintptr_t new_pc) OVERRIDE { 44 eip_ = new_pc; 45 } 46 GetGPRAddress(uint32_t reg)47 uintptr_t* GetGPRAddress(uint32_t reg) OVERRIDE { 48 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCpuRegisters)); 49 return gprs_[reg]; 50 } 51 GetGPR(uint32_t reg,uintptr_t * val)52 bool GetGPR(uint32_t reg, uintptr_t* val) OVERRIDE { 53 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCpuRegisters)); 54 if (gprs_[reg] == nullptr) { 55 return false; 56 } else { 57 DCHECK(val != nullptr); 58 *val = *gprs_[reg]; 59 return true; 60 } 61 } 62 63 bool SetGPR(uint32_t reg, uintptr_t value) OVERRIDE; 64 GetFPR(uint32_t reg,uintptr_t * val)65 bool GetFPR(uint32_t reg, uintptr_t* val) OVERRIDE { 66 LOG(FATAL) << "Floating-point registers are all caller save in X86"; 67 return false; 68 } 69 SetFPR(uint32_t reg,uintptr_t value)70 bool SetFPR(uint32_t reg, uintptr_t value) OVERRIDE { 71 LOG(FATAL) << "Floating-point registers are all caller save in X86"; 72 return false; 73 } 74 75 void SmashCallerSaves() OVERRIDE; 76 void DoLongJump() OVERRIDE; 77 78 private: 79 // Pointers to register locations, floating point registers are all caller save. Values are 80 // initialized to NULL or the special registers below. 81 uintptr_t* gprs_[kNumberOfCpuRegisters]; 82 // Hold values for esp and eip if they are not located within a stack frame. EIP is somewhat 83 // special in that it cannot be encoded normally as a register operand to an instruction (except 84 // in 64bit addressing modes). 85 uintptr_t esp_, eip_; 86 }; 87 } // namespace x86 88 } // namespace art 89 90 #endif // ART_RUNTIME_ARCH_X86_CONTEXT_X86_H_ 91