context_mips.cc revision 6702243ea2332b566d8e8b871cc9db0906d835ad
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 "object.h" 20 21namespace art { 22namespace mips { 23 24static const uint32_t gZero = 0; 25 26void MipsContext::Reset() { 27 for (size_t i = 0; i < kNumberOfCoreRegisters; i++) { 28 gprs_[i] = NULL; 29 } 30 for (size_t i = 0; i < kNumberOfFRegisters; i++) { 31 fprs_[i] = NULL; 32 } 33 gprs_[SP] = &sp_; 34 gprs_[RA] = &ra_; 35 // Initialize registers with easy to spot debug values. 36 sp_ = MipsContext::kBadGprBase + SP; 37 ra_ = MipsContext::kBadGprBase + RA; 38} 39 40void MipsContext::FillCalleeSaves(const StackVisitor& fr) { 41 AbstractMethod* method = fr.GetMethod(); 42 uint32_t core_spills = method->GetCoreSpillMask(); 43 uint32_t fp_core_spills = method->GetFpSpillMask(); 44 size_t spill_count = __builtin_popcount(core_spills); 45 size_t fp_spill_count = __builtin_popcount(fp_core_spills); 46 size_t frame_size = method->GetFrameSizeInBytes(); 47 if (spill_count > 0) { 48 // Lowest number spill is farthest away, walk registers and fill into context. 49 int j = 1; 50 for (size_t i = 0; i < kNumberOfCoreRegisters; i++) { 51 if (((core_spills >> i) & 1) != 0) { 52 gprs_[i] = fr.CalleeSaveAddress(spill_count - j, frame_size); 53 j++; 54 } 55 } 56 } 57 if (fp_spill_count > 0) { 58 // Lowest number spill is farthest away, walk registers and fill into context. 59 int j = 1; 60 for (size_t i = 0; i < kNumberOfFRegisters; i++) { 61 if (((fp_core_spills >> i) & 1) != 0) { 62 fprs_[i] = fr.CalleeSaveAddress(spill_count + fp_spill_count - j, frame_size); 63 j++; 64 } 65 } 66 } 67} 68 69void MipsContext::SetGPR(uint32_t reg, uintptr_t value) { 70 CHECK_LT(reg, kNumberOfCoreRegisters); 71 CHECK_NE(gprs_[reg], &gZero); // Can't overwrite this static value since they are never reset. 72 CHECK(gprs_[reg] != NULL); 73 *gprs_[reg] = value; 74} 75 76void MipsContext::SmashCallerSaves() { 77 // This needs to be 0 because we want a null/zero return value. 78 gprs_[V0] = const_cast<uint32_t*>(&gZero); 79 gprs_[V1] = const_cast<uint32_t*>(&gZero); 80 gprs_[A1] = NULL; 81 gprs_[A2] = NULL; 82 gprs_[A3] = NULL; 83} 84 85extern "C" void art_do_long_jump(uint32_t*, uint32_t*); 86 87void MipsContext::DoLongJump() { 88 uintptr_t gprs[kNumberOfCoreRegisters]; 89 uint32_t fprs[kNumberOfFRegisters]; 90 for (size_t i = 0; i < kNumberOfCoreRegisters; ++i) { 91 gprs[i] = gprs_[i] != NULL ? *gprs_[i] : MipsContext::kBadGprBase + i; 92 } 93 for (size_t i = 0; i < kNumberOfFRegisters; ++i) { 94 fprs[i] = fprs_[i] != NULL ? *fprs_[i] : MipsContext::kBadGprBase + i; 95 } 96 art_do_long_jump(gprs, fprs); 97} 98 99} // namespace mips 100} // namespace art 101