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 #include "context_mips.h" 18 19 #include "mirror/art_method-inl.h" 20 #include "mirror/object-inl.h" 21 #include "quick/quick_method_frame_info.h" 22 #include "stack.h" 23 24 namespace art { 25 namespace mips { 26 27 static constexpr uint32_t gZero = 0; 28 29 void MipsContext::Reset() { 30 for (size_t i = 0; i < kNumberOfCoreRegisters; i++) { 31 gprs_[i] = nullptr; 32 } 33 for (size_t i = 0; i < kNumberOfFRegisters; i++) { 34 fprs_[i] = nullptr; 35 } 36 gprs_[SP] = &sp_; 37 gprs_[RA] = &ra_; 38 // Initialize registers with easy to spot debug values. 39 sp_ = MipsContext::kBadGprBase + SP; 40 ra_ = MipsContext::kBadGprBase + RA; 41 } 42 43 void MipsContext::FillCalleeSaves(const StackVisitor& fr) { 44 mirror::ArtMethod* method = fr.GetMethod(); 45 const QuickMethodFrameInfo frame_info = method->GetQuickFrameInfo(); 46 size_t spill_count = POPCOUNT(frame_info.CoreSpillMask()); 47 size_t fp_spill_count = POPCOUNT(frame_info.FpSpillMask()); 48 if (spill_count > 0) { 49 // Lowest number spill is farthest away, walk registers and fill into context. 50 int j = 1; 51 for (size_t i = 0; i < kNumberOfCoreRegisters; i++) { 52 if (((frame_info.CoreSpillMask() >> i) & 1) != 0) { 53 gprs_[i] = fr.CalleeSaveAddress(spill_count - j, frame_info.FrameSizeInBytes()); 54 j++; 55 } 56 } 57 } 58 if (fp_spill_count > 0) { 59 // Lowest number spill is farthest away, walk registers and fill into context. 60 int j = 1; 61 for (size_t i = 0; i < kNumberOfFRegisters; i++) { 62 if (((frame_info.FpSpillMask() >> i) & 1) != 0) { 63 fprs_[i] = fr.CalleeSaveAddress(spill_count + fp_spill_count - j, 64 frame_info.FrameSizeInBytes()); 65 j++; 66 } 67 } 68 } 69 } 70 71 bool MipsContext::SetGPR(uint32_t reg, uintptr_t value) { 72 CHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters)); 73 CHECK_NE(gprs_[reg], &gZero); // Can't overwrite this static value since they are never reset. 74 if (gprs_[reg] != nullptr) { 75 *gprs_[reg] = value; 76 return true; 77 } else { 78 return false; 79 } 80 } 81 82 bool MipsContext::SetFPR(uint32_t reg, uintptr_t value) { 83 CHECK_LT(reg, static_cast<uint32_t>(kNumberOfFRegisters)); 84 CHECK_NE(fprs_[reg], &gZero); // Can't overwrite this static value since they are never reset. 85 if (fprs_[reg] != nullptr) { 86 *fprs_[reg] = value; 87 return true; 88 } else { 89 return false; 90 } 91 } 92 93 void MipsContext::SmashCallerSaves() { 94 // This needs to be 0 because we want a null/zero return value. 95 gprs_[V0] = const_cast<uint32_t*>(&gZero); 96 gprs_[V1] = const_cast<uint32_t*>(&gZero); 97 gprs_[A1] = nullptr; 98 gprs_[A2] = nullptr; 99 gprs_[A3] = nullptr; 100 } 101 102 extern "C" void art_quick_do_long_jump(uint32_t*, uint32_t*); 103 104 void MipsContext::DoLongJump() { 105 uintptr_t gprs[kNumberOfCoreRegisters]; 106 uint32_t fprs[kNumberOfFRegisters]; 107 for (size_t i = 0; i < kNumberOfCoreRegisters; ++i) { 108 gprs[i] = gprs_[i] != nullptr ? *gprs_[i] : MipsContext::kBadGprBase + i; 109 } 110 for (size_t i = 0; i < kNumberOfFRegisters; ++i) { 111 fprs[i] = fprs_[i] != nullptr ? *fprs_[i] : MipsContext::kBadGprBase + i; 112 } 113 art_quick_do_long_jump(gprs, fprs); 114 } 115 116 } // namespace mips 117 } // namespace art 118