Home | History | Annotate | Download | only in x86_64
      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_64_CONTEXT_X86_64_H_
     18 #define ART_RUNTIME_ARCH_X86_64_CONTEXT_X86_64_H_
     19 
     20 #include <android-base/logging.h>
     21 
     22 #include "arch/context.h"
     23 #include "base/macros.h"
     24 #include "registers_x86_64.h"
     25 
     26 namespace art {
     27 namespace x86_64 {
     28 
     29 class X86_64Context final : public Context {
     30  public:
     31   X86_64Context() {
     32     Reset();
     33   }
     34   virtual ~X86_64Context() {}
     35 
     36   void Reset() override;
     37 
     38   void FillCalleeSaves(uint8_t* frame, const QuickMethodFrameInfo& fr) override;
     39 
     40   void SetSP(uintptr_t new_sp) override {
     41     SetGPR(RSP, new_sp);
     42   }
     43 
     44   void SetPC(uintptr_t new_pc) override {
     45     rip_ = new_pc;
     46   }
     47 
     48   void SetArg0(uintptr_t new_arg0_value) override {
     49     SetGPR(RDI, new_arg0_value);
     50   }
     51 
     52   bool IsAccessibleGPR(uint32_t reg) override {
     53     DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCpuRegisters));
     54     return gprs_[reg] != nullptr;
     55   }
     56 
     57   uintptr_t* GetGPRAddress(uint32_t reg) override {
     58     DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCpuRegisters));
     59     return gprs_[reg];
     60   }
     61 
     62   uintptr_t GetGPR(uint32_t reg) override {
     63     DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCpuRegisters));
     64     DCHECK(IsAccessibleGPR(reg));
     65     return *gprs_[reg];
     66   }
     67 
     68   void SetGPR(uint32_t reg, uintptr_t value) override;
     69 
     70   bool IsAccessibleFPR(uint32_t reg) override {
     71     DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfFloatRegisters));
     72     return fprs_[reg] != nullptr;
     73   }
     74 
     75   uintptr_t GetFPR(uint32_t reg) override {
     76     DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfFloatRegisters));
     77     DCHECK(IsAccessibleFPR(reg));
     78     return *fprs_[reg];
     79   }
     80 
     81   void SetFPR(uint32_t reg, uintptr_t value) override;
     82 
     83   void SmashCallerSaves() override;
     84   NO_RETURN void DoLongJump() override;
     85 
     86  private:
     87   // Pointers to register locations. Values are initialized to null or the special registers below.
     88   uintptr_t* gprs_[kNumberOfCpuRegisters];
     89   uint64_t* fprs_[kNumberOfFloatRegisters];
     90   // Hold values for rsp, rip and arg0 if they are not located within a stack frame. RIP is somewhat
     91   // special in that it cannot be encoded normally as a register operand to an instruction (except
     92   // in 64bit addressing modes).
     93   uintptr_t rsp_, rip_, arg0_;
     94 };
     95 }  // namespace x86_64
     96 }  // namespace art
     97 
     98 #endif  // ART_RUNTIME_ARCH_X86_64_CONTEXT_X86_64_H_
     99