1/*
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
17#ifndef ART_RUNTIME_ARCH_MIPS_CONTEXT_MIPS_H_
18#define ART_RUNTIME_ARCH_MIPS_CONTEXT_MIPS_H_
19
20#include "arch/context.h"
21#include "base/logging.h"
22#include "registers_mips.h"
23
24namespace art {
25namespace mips {
26
27class MipsContext : public Context {
28 public:
29  MipsContext() {
30    Reset();
31  }
32  virtual ~MipsContext() {}
33
34  void Reset() OVERRIDE;
35
36  void FillCalleeSaves(const StackVisitor& fr) OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
37
38  void SetSP(uintptr_t new_sp) OVERRIDE {
39    bool success = SetGPR(SP, new_sp);
40    CHECK(success) << "Failed to set SP register";
41  }
42
43  void SetPC(uintptr_t new_pc) OVERRIDE {
44    bool success = SetGPR(RA, new_pc);
45    CHECK(success) << "Failed to set RA register";
46  }
47
48  uintptr_t* GetGPRAddress(uint32_t reg) OVERRIDE {
49    DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters));
50    return gprs_[reg];
51  }
52
53  bool GetGPR(uint32_t reg, uintptr_t* val) OVERRIDE {
54    CHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters));
55    if (gprs_[reg] == nullptr) {
56      return false;
57    } else {
58      DCHECK(val != nullptr);
59      *val = *gprs_[reg];
60      return true;
61    }
62  }
63
64  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;
81
82 private:
83  // 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_;
88};
89}  // namespace mips
90}  // namespace art
91
92#endif  // ART_RUNTIME_ARCH_MIPS_CONTEXT_MIPS_H_
93