jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 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 | |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_ARCH_MIPS_CONTEXT_MIPS_H_ |
| 18 | #define ART_RUNTIME_ARCH_MIPS_CONTEXT_MIPS_H_ |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 19 | |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 20 | #include "arch/context.h" |
| 21 | #include "base/logging.h" |
| 22 | #include "registers_mips.h" |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 23 | |
| 24 | namespace art { |
| 25 | namespace mips { |
| 26 | |
| 27 | class MipsContext : public Context { |
| 28 | public: |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 29 | MipsContext() { |
| 30 | Reset(); |
| 31 | } |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 32 | virtual ~MipsContext() {} |
| 33 | |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame^] | 34 | void Reset() OVERRIDE; |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 35 | |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame^] | 36 | void FillCalleeSaves(const StackVisitor& fr) OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 37 | |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame^] | 38 | void SetSP(uintptr_t new_sp) OVERRIDE { |
| 39 | bool success = SetGPR(SP, new_sp); |
| 40 | CHECK(success) << "Failed to set SP register"; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame^] | 43 | void SetPC(uintptr_t new_pc) OVERRIDE { |
| 44 | bool success = SetGPR(RA, new_pc); |
| 45 | CHECK(success) << "Failed to set RA register"; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame^] | 48 | uintptr_t* GetGPRAddress(uint32_t reg) OVERRIDE { |
Mathieu Chartier | 815873e | 2014-02-13 18:02:13 -0800 | [diff] [blame] | 49 | DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters)); |
| 50 | return gprs_[reg]; |
| 51 | } |
| 52 | |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame^] | 53 | bool GetGPR(uint32_t reg, uintptr_t* val) OVERRIDE { |
Brian Carlstrom | 8b1ce16 | 2013-03-31 00:17:54 -0700 | [diff] [blame] | 54 | CHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters)); |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame^] | 55 | if (gprs_[reg] == nullptr) { |
| 56 | return false; |
| 57 | } else { |
| 58 | DCHECK(val != nullptr); |
| 59 | *val = *gprs_[reg]; |
| 60 | return true; |
| 61 | } |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame^] | 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; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 81 | |
| 82 | private: |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 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_; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 88 | }; |
| 89 | } // namespace mips |
| 90 | } // namespace art |
| 91 | |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 92 | #endif // ART_RUNTIME_ARCH_MIPS_CONTEXT_MIPS_H_ |