17fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao/*
27fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao * Copyright (C) 2011 The Android Open Source Project
37fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao *
47fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao * Licensed under the Apache License, Version 2.0 (the "License");
57fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao * you may not use this file except in compliance with the License.
67fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao * You may obtain a copy of the License at
77fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao *
87fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao *      http://www.apache.org/licenses/LICENSE-2.0
97fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao *
107fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao * Unless required by applicable law or agreed to in writing, software
117fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao * distributed under the License is distributed on an "AS IS" BASIS,
127fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao * See the License for the specific language governing permissions and
147fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao * limitations under the License.
157fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao */
167fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao
17166db04e259ca51838c311891598664deeed85adIan Rogers#ifndef ART_RUNTIME_ARCH_MIPS_CONTEXT_MIPS_H_
18166db04e259ca51838c311891598664deeed85adIan Rogers#define ART_RUNTIME_ARCH_MIPS_CONTEXT_MIPS_H_
197fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao
20166db04e259ca51838c311891598664deeed85adIan Rogers#include "arch/context.h"
21166db04e259ca51838c311891598664deeed85adIan Rogers#include "base/logging.h"
22794ad76e8d5b5b9132819d5b08a0570e27615644Andreas Gampe#include "base/macros.h"
23166db04e259ca51838c311891598664deeed85adIan Rogers#include "registers_mips.h"
247fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao
257fbee0731b14b5bf392a4254f5cd84685ab517dajeffhaonamespace art {
267fbee0731b14b5bf392a4254f5cd84685ab517dajeffhaonamespace mips {
277fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao
287fbee0731b14b5bf392a4254f5cd84685ab517dajeffhaoclass MipsContext : public Context {
297fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao public:
306702243ea2332b566d8e8b871cc9db0906d835adMathieu Chartier  MipsContext() {
316702243ea2332b566d8e8b871cc9db0906d835adMathieu Chartier    Reset();
326702243ea2332b566d8e8b871cc9db0906d835adMathieu Chartier  }
337fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao  virtual ~MipsContext() {}
347fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao
350bcb2902ec21393d71c94e63aa6733cb5311a0ccSebastien Hertz  void Reset() OVERRIDE;
366702243ea2332b566d8e8b871cc9db0906d835adMathieu Chartier
37524e7ea8cd17bad17bd9f3e0ccbb19ad0d4d9c02Nicolas Geoffray  void FillCalleeSaves(uint8_t* frame, const QuickMethodFrameInfo& fr) OVERRIDE;
387fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao
390bcb2902ec21393d71c94e63aa6733cb5311a0ccSebastien Hertz  void SetSP(uintptr_t new_sp) OVERRIDE {
4096ba8dc82e7bd859106af837623fe8b2e9e772c3Sebastien Hertz    SetGPR(SP, new_sp);
417fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao  }
427fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao
430bcb2902ec21393d71c94e63aa6733cb5311a0ccSebastien Hertz  void SetPC(uintptr_t new_pc) OVERRIDE {
4475969963213c39a029e01c3b9440fb388d793afbGoran Jakovljevic    SetGPR(T9, new_pc);
4596ba8dc82e7bd859106af837623fe8b2e9e772c3Sebastien Hertz  }
4696ba8dc82e7bd859106af837623fe8b2e9e772c3Sebastien Hertz
4796ba8dc82e7bd859106af837623fe8b2e9e772c3Sebastien Hertz  bool IsAccessibleGPR(uint32_t reg) OVERRIDE {
4896ba8dc82e7bd859106af837623fe8b2e9e772c3Sebastien Hertz    CHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters));
4996ba8dc82e7bd859106af837623fe8b2e9e772c3Sebastien Hertz    return gprs_[reg] != nullptr;
507fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao  }
517fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao
520bcb2902ec21393d71c94e63aa6733cb5311a0ccSebastien Hertz  uintptr_t* GetGPRAddress(uint32_t reg) OVERRIDE {
53815873ecc312b1d231acce71e1a16f42cdaf09f2Mathieu Chartier    DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters));
54815873ecc312b1d231acce71e1a16f42cdaf09f2Mathieu Chartier    return gprs_[reg];
55815873ecc312b1d231acce71e1a16f42cdaf09f2Mathieu Chartier  }
56815873ecc312b1d231acce71e1a16f42cdaf09f2Mathieu Chartier
5796ba8dc82e7bd859106af837623fe8b2e9e772c3Sebastien Hertz  uintptr_t GetGPR(uint32_t reg) OVERRIDE {
588b1ce16de070672f0ab1a30f40853513734ff128Brian Carlstrom    CHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters));
5996ba8dc82e7bd859106af837623fe8b2e9e772c3Sebastien Hertz    DCHECK(IsAccessibleGPR(reg));
6096ba8dc82e7bd859106af837623fe8b2e9e772c3Sebastien Hertz    return *gprs_[reg];
617fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao  }
627fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao
6396ba8dc82e7bd859106af837623fe8b2e9e772c3Sebastien Hertz  void SetGPR(uint32_t reg, uintptr_t value) OVERRIDE;
6496ba8dc82e7bd859106af837623fe8b2e9e772c3Sebastien Hertz
6596ba8dc82e7bd859106af837623fe8b2e9e772c3Sebastien Hertz  bool IsAccessibleFPR(uint32_t reg) OVERRIDE {
6696ba8dc82e7bd859106af837623fe8b2e9e772c3Sebastien Hertz    CHECK_LT(reg, static_cast<uint32_t>(kNumberOfFRegisters));
6796ba8dc82e7bd859106af837623fe8b2e9e772c3Sebastien Hertz    return fprs_[reg] != nullptr;
6896ba8dc82e7bd859106af837623fe8b2e9e772c3Sebastien Hertz  }
690bcb2902ec21393d71c94e63aa6733cb5311a0ccSebastien Hertz
7096ba8dc82e7bd859106af837623fe8b2e9e772c3Sebastien Hertz  uintptr_t GetFPR(uint32_t reg) OVERRIDE {
710bcb2902ec21393d71c94e63aa6733cb5311a0ccSebastien Hertz    CHECK_LT(reg, static_cast<uint32_t>(kNumberOfFRegisters));
7296ba8dc82e7bd859106af837623fe8b2e9e772c3Sebastien Hertz    DCHECK(IsAccessibleFPR(reg));
7396ba8dc82e7bd859106af837623fe8b2e9e772c3Sebastien Hertz    return *fprs_[reg];
740bcb2902ec21393d71c94e63aa6733cb5311a0ccSebastien Hertz  }
750bcb2902ec21393d71c94e63aa6733cb5311a0ccSebastien Hertz
7696ba8dc82e7bd859106af837623fe8b2e9e772c3Sebastien Hertz  void SetFPR(uint32_t reg, uintptr_t value) OVERRIDE;
770bcb2902ec21393d71c94e63aa6733cb5311a0ccSebastien Hertz
780bcb2902ec21393d71c94e63aa6733cb5311a0ccSebastien Hertz  void SmashCallerSaves() OVERRIDE;
79794ad76e8d5b5b9132819d5b08a0570e27615644Andreas Gampe  NO_RETURN void DoLongJump() OVERRIDE;
807fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao
81639bdd13993644a267f177f8f5936496bda65e2bAndreas Gampe  void SetArg0(uintptr_t new_arg0_value) OVERRIDE {
82639bdd13993644a267f177f8f5936496bda65e2bAndreas Gampe    SetGPR(A0, new_arg0_value);
83639bdd13993644a267f177f8f5936496bda65e2bAndreas Gampe  }
84639bdd13993644a267f177f8f5936496bda65e2bAndreas Gampe
857fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao private:
862cebb24bfc3247d3e9be138a3350106737455918Mathieu Chartier  // Pointers to registers in the stack, initialized to null except for the special cases below.
876702243ea2332b566d8e8b871cc9db0906d835adMathieu Chartier  uintptr_t* gprs_[kNumberOfCoreRegisters];
886702243ea2332b566d8e8b871cc9db0906d835adMathieu Chartier  uint32_t* fprs_[kNumberOfFRegisters];
8975969963213c39a029e01c3b9440fb388d793afbGoran Jakovljevic  // Hold values for sp and t9 if they are not located within a stack frame. We use t9 for the
9075969963213c39a029e01c3b9440fb388d793afbGoran Jakovljevic  // PC (as ra is required to be valid for single-frame deopt and must not be clobbered). We
9175969963213c39a029e01c3b9440fb388d793afbGoran Jakovljevic  // also need the first argument for single-frame deopt.
9275969963213c39a029e01c3b9440fb388d793afbGoran Jakovljevic  uintptr_t sp_, t9_, arg0_;
937fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao};
947fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao}  // namespace mips
957fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao}  // namespace art
967fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao
97166db04e259ca51838c311891598664deeed85adIan Rogers#endif  // ART_RUNTIME_ARCH_MIPS_CONTEXT_MIPS_H_
98