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 | |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 19 | #include "base/bit_utils.h" |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 20 | #include "quick/quick_method_frame_info.h" |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 21 | |
| 22 | namespace art { |
| 23 | namespace mips64 { |
| 24 | |
| 25 | static constexpr uintptr_t gZero = 0; |
| 26 | |
| 27 | void Mips64Context::Reset() { |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 28 | std::fill_n(gprs_, arraysize(gprs_), nullptr); |
| 29 | std::fill_n(fprs_, arraysize(fprs_), nullptr); |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 30 | gprs_[SP] = &sp_; |
Andreas Gampe | dbf056d | 2015-09-25 08:24:13 -0700 | [diff] [blame] | 31 | gprs_[T9] = &t9_; |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 32 | gprs_[A0] = &arg0_; |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 33 | // Initialize registers with easy to spot debug values. |
| 34 | sp_ = Mips64Context::kBadGprBase + SP; |
Andreas Gampe | dbf056d | 2015-09-25 08:24:13 -0700 | [diff] [blame] | 35 | t9_ = Mips64Context::kBadGprBase + T9; |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 36 | arg0_ = 0; |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 37 | } |
| 38 | |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame^] | 39 | void Mips64Context::FillCalleeSaves(uint8_t* frame, const QuickMethodFrameInfo& frame_info) { |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 40 | int spill_pos = 0; |
| 41 | |
| 42 | // Core registers come first, from the highest down to the lowest. |
| 43 | for (uint32_t core_reg : HighToLowBits(frame_info.CoreSpillMask())) { |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame^] | 44 | gprs_[core_reg] = CalleeSaveAddress(frame, spill_pos, frame_info.FrameSizeInBytes()); |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 45 | ++spill_pos; |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 46 | } |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 47 | DCHECK_EQ(spill_pos, POPCOUNT(frame_info.CoreSpillMask())); |
| 48 | |
| 49 | // FP registers come second, from the highest down to the lowest. |
| 50 | for (uint32_t fp_reg : HighToLowBits(frame_info.FpSpillMask())) { |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame^] | 51 | fprs_[fp_reg] = CalleeSaveAddress(frame, spill_pos, frame_info.FrameSizeInBytes()); |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 52 | ++spill_pos; |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 53 | } |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 54 | DCHECK_EQ(spill_pos, POPCOUNT(frame_info.CoreSpillMask()) + POPCOUNT(frame_info.FpSpillMask())); |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 55 | } |
| 56 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 57 | void Mips64Context::SetGPR(uint32_t reg, uintptr_t value) { |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 58 | CHECK_LT(reg, static_cast<uint32_t>(kNumberOfGpuRegisters)); |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 59 | DCHECK(IsAccessibleGPR(reg)); |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 60 | 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] | 61 | *gprs_[reg] = value; |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 64 | void Mips64Context::SetFPR(uint32_t reg, uintptr_t value) { |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 65 | CHECK_LT(reg, static_cast<uint32_t>(kNumberOfFpuRegisters)); |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 66 | DCHECK(IsAccessibleFPR(reg)); |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 67 | 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] | 68 | *fprs_[reg] = value; |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | void Mips64Context::SmashCallerSaves() { |
| 72 | // This needs to be 0 because we want a null/zero return value. |
| 73 | gprs_[V0] = const_cast<uintptr_t*>(&gZero); |
| 74 | gprs_[V1] = const_cast<uintptr_t*>(&gZero); |
| 75 | gprs_[A1] = nullptr; |
| 76 | gprs_[A0] = nullptr; |
| 77 | gprs_[A2] = nullptr; |
| 78 | gprs_[A3] = nullptr; |
| 79 | gprs_[A4] = nullptr; |
| 80 | gprs_[A5] = nullptr; |
| 81 | gprs_[A6] = nullptr; |
| 82 | gprs_[A7] = nullptr; |
| 83 | |
| 84 | // f0-f23 are caller-saved; f24-f31 are callee-saved. |
| 85 | fprs_[F0] = nullptr; |
| 86 | fprs_[F1] = nullptr; |
| 87 | fprs_[F2] = nullptr; |
| 88 | fprs_[F3] = nullptr; |
| 89 | fprs_[F4] = nullptr; |
| 90 | fprs_[F5] = nullptr; |
| 91 | fprs_[F6] = nullptr; |
| 92 | fprs_[F7] = nullptr; |
| 93 | fprs_[F8] = nullptr; |
| 94 | fprs_[F9] = nullptr; |
| 95 | fprs_[F10] = nullptr; |
| 96 | fprs_[F11] = nullptr; |
| 97 | fprs_[F12] = nullptr; |
| 98 | fprs_[F13] = nullptr; |
| 99 | fprs_[F14] = nullptr; |
| 100 | fprs_[F15] = nullptr; |
| 101 | fprs_[F16] = nullptr; |
| 102 | fprs_[F17] = nullptr; |
| 103 | fprs_[F18] = nullptr; |
| 104 | fprs_[F19] = nullptr; |
| 105 | fprs_[F20] = nullptr; |
| 106 | fprs_[F21] = nullptr; |
| 107 | fprs_[F22] = nullptr; |
| 108 | fprs_[F23] = nullptr; |
| 109 | } |
| 110 | |
Andreas Gampe | 794ad76 | 2015-02-23 08:12:24 -0800 | [diff] [blame] | 111 | 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] | 112 | |
| 113 | void Mips64Context::DoLongJump() { |
| 114 | uintptr_t gprs[kNumberOfGpuRegisters]; |
| 115 | uintptr_t fprs[kNumberOfFpuRegisters]; |
| 116 | for (size_t i = 0; i < kNumberOfGpuRegisters; ++i) { |
| 117 | gprs[i] = gprs_[i] != nullptr ? *gprs_[i] : Mips64Context::kBadGprBase + i; |
| 118 | } |
| 119 | for (size_t i = 0; i < kNumberOfFpuRegisters; ++i) { |
| 120 | fprs[i] = fprs_[i] != nullptr ? *fprs_[i] : Mips64Context::kBadFprBase + i; |
| 121 | } |
| 122 | art_quick_do_long_jump(gprs, fprs); |
| 123 | } |
| 124 | |
| 125 | } // namespace mips64 |
| 126 | } // namespace art |