Home | History | Annotate | Download | only in arm
      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_ARM_CONTEXT_ARM_H_
     18 #define ART_RUNTIME_ARCH_ARM_CONTEXT_ARM_H_
     19 
     20 #include "arch/context.h"
     21 #include "base/logging.h"
     22 #include "registers_arm.h"
     23 
     24 namespace art {
     25 namespace arm {
     26 
     27 class ArmContext : public Context {
     28  public:
     29   ArmContext() {
     30     Reset();
     31   }
     32 
     33   virtual ~ArmContext() {}
     34 
     35   void Reset() OVERRIDE;
     36 
     37   void FillCalleeSaves(const StackVisitor& fr) OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
     38 
     39   void SetSP(uintptr_t new_sp) OVERRIDE {
     40     bool success = SetGPR(SP, new_sp);
     41     CHECK(success) << "Failed to set SP register";
     42   }
     43 
     44   void SetPC(uintptr_t new_pc) OVERRIDE {
     45     bool success = SetGPR(PC, new_pc);
     46     CHECK(success) << "Failed to set PC register";
     47   }
     48 
     49   uintptr_t* GetGPRAddress(uint32_t reg) OVERRIDE {
     50     DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters));
     51     return gprs_[reg];
     52   }
     53 
     54   bool GetGPR(uint32_t reg, uintptr_t* val) OVERRIDE {
     55     DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters));
     56     if (gprs_[reg] == nullptr) {
     57       return false;
     58     } else {
     59       DCHECK(val != nullptr);
     60       *val = *gprs_[reg];
     61       return true;
     62     }
     63   }
     64 
     65   bool SetGPR(uint32_t reg, uintptr_t value) OVERRIDE;
     66 
     67   bool GetFPR(uint32_t reg, uintptr_t* val) OVERRIDE {
     68     DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfSRegisters));
     69     if (fprs_[reg] == nullptr) {
     70       return false;
     71     } else {
     72       DCHECK(val != nullptr);
     73       *val = *fprs_[reg];
     74       return true;
     75     }
     76   }
     77 
     78   bool SetFPR(uint32_t reg, uintptr_t value) OVERRIDE;
     79 
     80   void SmashCallerSaves() OVERRIDE;
     81   void DoLongJump() OVERRIDE;
     82 
     83  private:
     84   // Pointers to register locations, initialized to NULL or the specific registers below.
     85   uintptr_t* gprs_[kNumberOfCoreRegisters];
     86   uint32_t* fprs_[kNumberOfSRegisters];
     87   // Hold values for sp and pc if they are not located within a stack frame.
     88   uintptr_t sp_, pc_;
     89 };
     90 
     91 }  // namespace arm
     92 }  // namespace art
     93 
     94 #endif  // ART_RUNTIME_ARCH_ARM_CONTEXT_ARM_H_
     95