blob: d8a0b673c8b2803a74eee9e98ecc2bdd0e72aac1 [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 {
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010039 SetGPR(SP, new_sp);
jeffhao7fbee072012-08-24 17:56:54 -070040 }
41
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020042 void SetPC(uintptr_t new_pc) OVERRIDE {
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010043 SetGPR(RA, new_pc);
44 }
45
46 bool IsAccessibleGPR(uint32_t reg) OVERRIDE {
47 CHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters));
48 return gprs_[reg] != nullptr;
jeffhao7fbee072012-08-24 17:56:54 -070049 }
50
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020051 uintptr_t* GetGPRAddress(uint32_t reg) OVERRIDE {
Mathieu Chartier815873e2014-02-13 18:02:13 -080052 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters));
53 return gprs_[reg];
54 }
55
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010056 uintptr_t GetGPR(uint32_t reg) OVERRIDE {
Brian Carlstrom8b1ce162013-03-31 00:17:54 -070057 CHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters));
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010058 DCHECK(IsAccessibleGPR(reg));
59 return *gprs_[reg];
jeffhao7fbee072012-08-24 17:56:54 -070060 }
61
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010062 void SetGPR(uint32_t reg, uintptr_t value) OVERRIDE;
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020063
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010064 bool IsAccessibleFPR(uint32_t reg) OVERRIDE {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020065 CHECK_LT(reg, static_cast<uint32_t>(kNumberOfFRegisters));
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010066 return fprs_[reg] != nullptr;
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020067 }
68
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010069 uintptr_t GetFPR(uint32_t reg) OVERRIDE {
70 CHECK_LT(reg, static_cast<uint32_t>(kNumberOfFRegisters));
71 DCHECK(IsAccessibleFPR(reg));
72 return *fprs_[reg];
73 }
74
75 void SetFPR(uint32_t reg, uintptr_t value) OVERRIDE;
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020076
77 void SmashCallerSaves() OVERRIDE;
78 void DoLongJump() OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -070079
80 private:
Mathieu Chartier67022432012-11-29 18:04:50 -080081 // Pointers to registers in the stack, initialized to NULL except for the special cases below.
82 uintptr_t* gprs_[kNumberOfCoreRegisters];
83 uint32_t* fprs_[kNumberOfFRegisters];
84 // Hold values for sp and ra (return address) if they are not located within a stack frame.
85 uintptr_t sp_, ra_;
jeffhao7fbee072012-08-24 17:56:54 -070086};
87} // namespace mips
88} // namespace art
89
Ian Rogers166db042013-07-26 12:05:57 -070090#endif // ART_RUNTIME_ARCH_MIPS_CONTEXT_MIPS_H_