• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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_ARM64_CONTEXT_ARM64_H_
18 #define ART_RUNTIME_ARCH_ARM64_CONTEXT_ARM64_H_
19 
20 #include "arch/context.h"
21 #include "base/logging.h"
22 #include "registers_arm64.h"
23 
24 namespace art {
25 namespace arm64 {
26 
27 class Arm64Context : public Context {
28  public:
Arm64Context()29   Arm64Context() {
30     Reset();
31   }
32 
~Arm64Context()33   ~Arm64Context() {}
34 
35   void Reset() OVERRIDE;
36 
37   void FillCalleeSaves(const StackVisitor& fr) OVERRIDE;
38 
SetSP(uintptr_t new_sp)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 
SetPC(uintptr_t new_lr)44   void SetPC(uintptr_t new_lr) OVERRIDE {
45     bool success = SetGPR(LR, new_lr);
46     CHECK(success) << "Failed to set LR register";
47   }
48 
GetGPRAddress(uint32_t reg)49   uintptr_t* GetGPRAddress(uint32_t reg) OVERRIDE {
50     DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters));
51     return gprs_[reg];
52   }
53 
GetGPR(uint32_t reg,uintptr_t * val)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 
GetFPR(uint32_t reg,uintptr_t * val)67   bool GetFPR(uint32_t reg, uintptr_t* val) OVERRIDE {
68     DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfDRegisters));
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   uint64_t * fprs_[kNumberOfDRegisters];
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 arm64
92 }  // namespace art
93 
94 #endif  // ART_RUNTIME_ARCH_ARM64_CONTEXT_ARM64_H_
95