blob: 7b6aac9d6cf943891a6d0ac39e7a85b7ced8484c [file] [log] [blame]
Stuart Monteithb95a5342014-03-12 13:32:32 +00001/*
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
24namespace art {
25namespace arm64 {
26
27class Arm64Context : public Context {
28 public:
29 Arm64Context() {
30 Reset();
31 }
32
33 ~Arm64Context() {}
34
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020035 void Reset() OVERRIDE;
Stuart Monteithb95a5342014-03-12 13:32:32 +000036
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020037 void FillCalleeSaves(const StackVisitor& fr) OVERRIDE;
Stuart Monteithb95a5342014-03-12 13:32:32 +000038
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020039 void SetSP(uintptr_t new_sp) OVERRIDE {
40 bool success = SetGPR(SP, new_sp);
41 CHECK(success) << "Failed to set SP register";
Stuart Monteithb95a5342014-03-12 13:32:32 +000042 }
43
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020044 void SetPC(uintptr_t new_lr) OVERRIDE {
45 bool success = SetGPR(LR, new_lr);
46 CHECK(success) << "Failed to set LR register";
Stuart Monteithb95a5342014-03-12 13:32:32 +000047 }
48
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020049 uintptr_t* GetGPRAddress(uint32_t reg) OVERRIDE {
Alexandre Rames37c92df2014-10-17 14:35:27 +010050 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfXRegisters));
Stuart Monteithb95a5342014-03-12 13:32:32 +000051 return gprs_[reg];
52 }
53
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020054 bool GetGPR(uint32_t reg, uintptr_t* val) OVERRIDE {
Alexandre Rames37c92df2014-10-17 14:35:27 +010055 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfXRegisters));
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020056 if (gprs_[reg] == nullptr) {
57 return false;
58 } else {
59 DCHECK(val != nullptr);
60 *val = *gprs_[reg];
61 return true;
62 }
Stuart Monteithb95a5342014-03-12 13:32:32 +000063 }
64
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020065 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>(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;
Stuart Monteithb95a5342014-03-12 13:32:32 +000082
83 private:
84 // Pointers to register locations, initialized to NULL or the specific registers below.
Alexandre Rames37c92df2014-10-17 14:35:27 +010085 uintptr_t* gprs_[kNumberOfXRegisters];
Stuart Monteithb95a5342014-03-12 13:32:32 +000086 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_