• 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 <android-base/logging.h>
21 
22 #include "arch/context.h"
23 #include "base/macros.h"
24 #include "registers_arm64.h"
25 
26 namespace art {
27 namespace arm64 {
28 
29 class Arm64Context final : public Context {
30  public:
Arm64Context()31   Arm64Context() {
32     Reset();
33   }
34 
~Arm64Context()35   ~Arm64Context() {}
36 
37   void Reset() override;
38 
39   void FillCalleeSaves(uint8_t* frame, const QuickMethodFrameInfo& fr) override;
40 
SetSP(uintptr_t new_sp)41   void SetSP(uintptr_t new_sp) override {
42     SetGPR(SP, new_sp);
43   }
44 
SetPC(uintptr_t new_lr)45   void SetPC(uintptr_t new_lr) override {
46     SetGPR(kPC, new_lr);
47   }
48 
SetNterpDexPC(uintptr_t dex_pc_ptr)49   void SetNterpDexPC(uintptr_t dex_pc_ptr) override {
50     SetGPR(X22, dex_pc_ptr);
51   }
52 
SetArg0(uintptr_t new_arg0_value)53   void SetArg0(uintptr_t new_arg0_value) override {
54     SetGPR(X0, new_arg0_value);
55   }
56 
IsAccessibleGPR(uint32_t reg)57   bool IsAccessibleGPR(uint32_t reg) override {
58     DCHECK_LT(reg, arraysize(gprs_));
59     return gprs_[reg] != nullptr;
60   }
61 
GetGPRAddress(uint32_t reg)62   uintptr_t* GetGPRAddress(uint32_t reg) override {
63     DCHECK_LT(reg, arraysize(gprs_));
64     return gprs_[reg];
65   }
66 
GetGPR(uint32_t reg)67   uintptr_t GetGPR(uint32_t reg) override {
68     // Note: PC isn't an available GPR (outside of internals), so don't allow retrieving the value.
69     DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfXRegisters));
70     DCHECK(IsAccessibleGPR(reg));
71     return *gprs_[reg];
72   }
73 
74   void SetGPR(uint32_t reg, uintptr_t value) override;
75 
IsAccessibleFPR(uint32_t reg)76   bool IsAccessibleFPR(uint32_t reg) override {
77     DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfDRegisters));
78     return fprs_[reg] != nullptr;
79   }
80 
GetFPR(uint32_t reg)81   uintptr_t GetFPR(uint32_t reg) override {
82     DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfDRegisters));
83     DCHECK(IsAccessibleFPR(reg));
84     return *fprs_[reg];
85   }
86 
87   void SetFPR(uint32_t reg, uintptr_t value) override;
88 
89   void SmashCallerSaves() override;
90   NO_RETURN void DoLongJump() override;
91 
92   static constexpr size_t kPC = kNumberOfXRegisters;
93 
94  private:
95   // Pointers to register locations, initialized to null or the specific registers below. We need
96   // an additional one for the PC.
97   uintptr_t* gprs_[kNumberOfXRegisters + 1];
98   uint64_t * fprs_[kNumberOfDRegisters];
99   // Hold values for sp, pc and arg0 if they are not located within a stack frame.
100   uintptr_t sp_, pc_, arg0_;
101 };
102 
103 }  // namespace arm64
104 }  // namespace art
105 
106 #endif  // ART_RUNTIME_ARCH_ARM64_CONTEXT_ARM64_H_
107