Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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_mips64.h" |
| 18 | |
| 19 | #include "mirror/art_method-inl.h" |
| 20 | #include "quick/quick_method_frame_info.h" |
| 21 | #include "util.h" |
| 22 | |
| 23 | namespace art { |
| 24 | namespace mips64 { |
| 25 | |
| 26 | static constexpr uintptr_t gZero = 0; |
| 27 | |
| 28 | void Mips64Context::Reset() { |
| 29 | for (size_t i = 0; i < kNumberOfGpuRegisters; i++) { |
| 30 | gprs_[i] = nullptr; |
| 31 | } |
| 32 | for (size_t i = 0; i < kNumberOfFpuRegisters; i++) { |
| 33 | fprs_[i] = nullptr; |
| 34 | } |
| 35 | gprs_[SP] = &sp_; |
| 36 | gprs_[RA] = &ra_; |
| 37 | // Initialize registers with easy to spot debug values. |
| 38 | sp_ = Mips64Context::kBadGprBase + SP; |
| 39 | ra_ = Mips64Context::kBadGprBase + RA; |
| 40 | } |
| 41 | |
| 42 | void Mips64Context::FillCalleeSaves(const StackVisitor& fr) { |
| 43 | mirror::ArtMethod* method = fr.GetMethod(); |
| 44 | const QuickMethodFrameInfo frame_info = method->GetQuickFrameInfo(); |
| 45 | size_t spill_count = POPCOUNT(frame_info.CoreSpillMask()); |
| 46 | size_t fp_spill_count = POPCOUNT(frame_info.FpSpillMask()); |
| 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 < kNumberOfGpuRegisters; i++) { |
| 51 | if (((frame_info.CoreSpillMask() >> i) & 1) != 0) { |
| 52 | gprs_[i] = fr.CalleeSaveAddress(spill_count - j, frame_info.FrameSizeInBytes()); |
| 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 < kNumberOfFpuRegisters; i++) { |
| 61 | if (((frame_info.FpSpillMask() >> i) & 1) != 0) { |
| 62 | fprs_[i] = fr.CalleeSaveAddress(spill_count + fp_spill_count - j, |
| 63 | frame_info.FrameSizeInBytes()); |
| 64 | j++; |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 70 | void Mips64Context::SetGPR(uint32_t reg, uintptr_t value) { |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 71 | CHECK_LT(reg, static_cast<uint32_t>(kNumberOfGpuRegisters)); |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 72 | DCHECK(IsAccessibleGPR(reg)); |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 73 | CHECK_NE(gprs_[reg], &gZero); // Can't overwrite this static value since they are never reset. |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 74 | *gprs_[reg] = value; |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 75 | } |
| 76 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 77 | void Mips64Context::SetFPR(uint32_t reg, uintptr_t value) { |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 78 | CHECK_LT(reg, static_cast<uint32_t>(kNumberOfFpuRegisters)); |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 79 | DCHECK(IsAccessibleFPR(reg)); |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 80 | CHECK_NE(fprs_[reg], &gZero); // Can't overwrite this static value since they are never reset. |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 81 | *fprs_[reg] = value; |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | void Mips64Context::SmashCallerSaves() { |
| 85 | // This needs to be 0 because we want a null/zero return value. |
| 86 | gprs_[V0] = const_cast<uintptr_t*>(&gZero); |
| 87 | gprs_[V1] = const_cast<uintptr_t*>(&gZero); |
| 88 | gprs_[A1] = nullptr; |
| 89 | gprs_[A0] = nullptr; |
| 90 | gprs_[A2] = nullptr; |
| 91 | gprs_[A3] = nullptr; |
| 92 | gprs_[A4] = nullptr; |
| 93 | gprs_[A5] = nullptr; |
| 94 | gprs_[A6] = nullptr; |
| 95 | gprs_[A7] = nullptr; |
| 96 | |
| 97 | // f0-f23 are caller-saved; f24-f31 are callee-saved. |
| 98 | fprs_[F0] = nullptr; |
| 99 | fprs_[F1] = nullptr; |
| 100 | fprs_[F2] = nullptr; |
| 101 | fprs_[F3] = nullptr; |
| 102 | fprs_[F4] = nullptr; |
| 103 | fprs_[F5] = nullptr; |
| 104 | fprs_[F6] = nullptr; |
| 105 | fprs_[F7] = nullptr; |
| 106 | fprs_[F8] = nullptr; |
| 107 | fprs_[F9] = nullptr; |
| 108 | fprs_[F10] = nullptr; |
| 109 | fprs_[F11] = nullptr; |
| 110 | fprs_[F12] = nullptr; |
| 111 | fprs_[F13] = nullptr; |
| 112 | fprs_[F14] = nullptr; |
| 113 | fprs_[F15] = nullptr; |
| 114 | fprs_[F16] = nullptr; |
| 115 | fprs_[F17] = nullptr; |
| 116 | fprs_[F18] = nullptr; |
| 117 | fprs_[F19] = nullptr; |
| 118 | fprs_[F20] = nullptr; |
| 119 | fprs_[F21] = nullptr; |
| 120 | fprs_[F22] = nullptr; |
| 121 | fprs_[F23] = nullptr; |
| 122 | } |
| 123 | |
Andreas Gampe | 794ad76 | 2015-02-23 08:12:24 -0800 | [diff] [blame] | 124 | extern "C" NO_RETURN void art_quick_do_long_jump(uintptr_t*, uintptr_t*); |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 125 | |
| 126 | void Mips64Context::DoLongJump() { |
| 127 | uintptr_t gprs[kNumberOfGpuRegisters]; |
| 128 | uintptr_t fprs[kNumberOfFpuRegisters]; |
| 129 | for (size_t i = 0; i < kNumberOfGpuRegisters; ++i) { |
| 130 | gprs[i] = gprs_[i] != nullptr ? *gprs_[i] : Mips64Context::kBadGprBase + i; |
| 131 | } |
| 132 | for (size_t i = 0; i < kNumberOfFpuRegisters; ++i) { |
| 133 | fprs[i] = fprs_[i] != nullptr ? *fprs_[i] : Mips64Context::kBadFprBase + i; |
| 134 | } |
| 135 | art_quick_do_long_jump(gprs, fprs); |
| 136 | } |
| 137 | |
| 138 | } // namespace mips64 |
| 139 | } // namespace art |