blob: f2ee335d48fb4c3b2136de06ef4e4b6145936914 [file] [log] [blame]
jeffhao7fbee072012-08-24 17:56:54 -07001/*
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
Ian Rogers166db042013-07-26 12:05:57 -070017#ifndef ART_RUNTIME_ARCH_MIPS_CONTEXT_MIPS_H_
18#define ART_RUNTIME_ARCH_MIPS_CONTEXT_MIPS_H_
jeffhao7fbee072012-08-24 17:56:54 -070019
Ian Rogers166db042013-07-26 12:05:57 -070020#include "arch/context.h"
21#include "base/logging.h"
22#include "registers_mips.h"
jeffhao7fbee072012-08-24 17:56:54 -070023
24namespace art {
25namespace mips {
26
27class MipsContext : public Context {
28 public:
Mathieu Chartier67022432012-11-29 18:04:50 -080029 MipsContext() {
30 Reset();
31 }
jeffhao7fbee072012-08-24 17:56:54 -070032 virtual ~MipsContext() {}
33
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020034 void Reset() OVERRIDE;
Mathieu Chartier67022432012-11-29 18:04:50 -080035
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020036 void FillCalleeSaves(const StackVisitor& fr) OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
jeffhao7fbee072012-08-24 17:56:54 -070037
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020038 void SetSP(uintptr_t new_sp) OVERRIDE {
39 bool success = SetGPR(SP, new_sp);
40 CHECK(success) << "Failed to set SP register";
jeffhao7fbee072012-08-24 17:56:54 -070041 }
42
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020043 void SetPC(uintptr_t new_pc) OVERRIDE {
44 bool success = SetGPR(RA, new_pc);
45 CHECK(success) << "Failed to set RA register";
jeffhao7fbee072012-08-24 17:56:54 -070046 }
47
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020048 uintptr_t* GetGPRAddress(uint32_t reg) OVERRIDE {
Mathieu Chartier815873e2014-02-13 18:02:13 -080049 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters));
50 return gprs_[reg];
51 }
52
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020053 bool GetGPR(uint32_t reg, uintptr_t* val) OVERRIDE {
Brian Carlstrom8b1ce162013-03-31 00:17:54 -070054 CHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters));
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020055 if (gprs_[reg] == nullptr) {
56 return false;
57 } else {
58 DCHECK(val != nullptr);
59 *val = *gprs_[reg];
60 return true;
61 }
jeffhao7fbee072012-08-24 17:56:54 -070062 }
63
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020064 bool SetGPR(uint32_t reg, uintptr_t value) OVERRIDE;
65
66 bool GetFPR(uint32_t reg, uintptr_t* val) OVERRIDE {
67 CHECK_LT(reg, static_cast<uint32_t>(kNumberOfFRegisters));
68 if (fprs_[reg] == nullptr) {
69 return false;
70 } else {
71 DCHECK(val != nullptr);
72 *val = *fprs_[reg];
73 return true;
74 }
75 }
76
77 bool SetFPR(uint32_t reg, uintptr_t value) OVERRIDE;
78
79 void SmashCallerSaves() OVERRIDE;
80 void DoLongJump() OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -070081
82 private:
Mathieu Chartier67022432012-11-29 18:04:50 -080083 // Pointers to registers in the stack, initialized to NULL except for the special cases below.
84 uintptr_t* gprs_[kNumberOfCoreRegisters];
85 uint32_t* fprs_[kNumberOfFRegisters];
86 // Hold values for sp and ra (return address) if they are not located within a stack frame.
87 uintptr_t sp_, ra_;
jeffhao7fbee072012-08-24 17:56:54 -070088};
89} // namespace mips
90} // namespace art
91
Ian Rogers166db042013-07-26 12:05:57 -070092#endif // ART_RUNTIME_ARCH_MIPS_CONTEXT_MIPS_H_