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 | |
| 17 | #include "context_mips.h" |
| 18 | |
| 19 | #include "object.h" |
| 20 | |
| 21 | namespace art { |
| 22 | namespace mips { |
| 23 | |
| 24 | MipsContext::MipsContext() { |
| 25 | #ifndef NDEBUG |
| 26 | // Initialize registers with easy to spot debug values. |
| 27 | for (int i = 0; i < 32; i++) { |
| 28 | gprs_[i] = kBadGprBase + i; |
| 29 | } |
| 30 | for (int i = 0; i < 32; i++) { |
| 31 | fprs_[i] = kBadGprBase + i; |
| 32 | } |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 33 | #endif |
| 34 | } |
| 35 | |
| 36 | void MipsContext::FillCalleeSaves(const StackVisitor& fr) { |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 37 | AbstractMethod* method = fr.GetMethod(); |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 38 | uint32_t core_spills = method->GetCoreSpillMask(); |
| 39 | uint32_t fp_core_spills = method->GetFpSpillMask(); |
| 40 | size_t spill_count = __builtin_popcount(core_spills); |
| 41 | size_t fp_spill_count = __builtin_popcount(fp_core_spills); |
| 42 | size_t frame_size = method->GetFrameSizeInBytes(); |
| 43 | if (spill_count > 0) { |
| 44 | // Lowest number spill is furthest away, walk registers and fill into context. |
| 45 | int j = 1; |
| 46 | for (int i = 0; i < 32; i++) { |
| 47 | if (((core_spills >> i) & 1) != 0) { |
| 48 | gprs_[i] = fr.LoadCalleeSave(spill_count - j, frame_size); |
| 49 | j++; |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | if (fp_spill_count > 0) { |
| 54 | // Lowest number spill is furthest away, walk registers and fill into context. |
| 55 | int j = 1; |
| 56 | for (int i = 0; i < 32; i++) { |
| 57 | if (((fp_core_spills >> i) & 1) != 0) { |
jeffhao | 0703060 | 2012-09-26 14:33:14 -0700 | [diff] [blame] | 58 | fprs_[i] = fr.LoadCalleeSave(spill_count + fp_spill_count - j, frame_size); |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 59 | j++; |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | void MipsContext::SmashCallerSaves() { |
| 66 | gprs_[V0] = 0; // This needs to be 0 because we want a null/zero return value. |
| 67 | gprs_[V1] = 0; // This needs to be 0 because we want a null/zero return value. |
| 68 | gprs_[A1] = kBadGprBase + A1; |
| 69 | gprs_[A2] = kBadGprBase + A2; |
| 70 | gprs_[A3] = kBadGprBase + A3; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | extern "C" void art_do_long_jump(uint32_t*, uint32_t*); |
| 74 | |
| 75 | void MipsContext::DoLongJump() { |
| 76 | art_do_long_jump(&gprs_[ZERO], &fprs_[F0]); |
| 77 | } |
| 78 | |
| 79 | } // namespace mips |
| 80 | } // namespace art |