Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [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 <stdint.h> |
| 18 | |
| 19 | #include "context_arm64.h" |
| 20 | |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 21 | #include "mirror/art_method-inl.h" |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 22 | #include "mirror/object-inl.h" |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 23 | #include "quick/quick_method_frame_info.h" |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 24 | #include "stack.h" |
| 25 | #include "thread.h" |
| 26 | |
| 27 | |
| 28 | namespace art { |
| 29 | namespace arm64 { |
| 30 | |
| 31 | static const uint64_t gZero = 0; |
| 32 | |
| 33 | void Arm64Context::Reset() { |
| 34 | for (size_t i = 0; i < kNumberOfCoreRegisters; i++) { |
| 35 | gprs_[i] = NULL; |
| 36 | } |
| 37 | for (size_t i = 0; i < kNumberOfDRegisters; i++) { |
| 38 | fprs_[i] = NULL; |
| 39 | } |
| 40 | gprs_[SP] = &sp_; |
| 41 | gprs_[LR] = &pc_; |
| 42 | // Initialize registers with easy to spot debug values. |
| 43 | sp_ = Arm64Context::kBadGprBase + SP; |
| 44 | pc_ = Arm64Context::kBadGprBase + LR; |
| 45 | } |
| 46 | |
| 47 | void Arm64Context::FillCalleeSaves(const StackVisitor& fr) { |
| 48 | mirror::ArtMethod* method = fr.GetMethod(); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 49 | const QuickMethodFrameInfo frame_info = method->GetQuickFrameInfo(); |
| 50 | size_t spill_count = POPCOUNT(frame_info.CoreSpillMask()); |
| 51 | size_t fp_spill_count = POPCOUNT(frame_info.FpSpillMask()); |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 52 | if (spill_count > 0) { |
| 53 | // Lowest number spill is farthest away, walk registers and fill into context. |
| 54 | int j = 1; |
| 55 | for (size_t i = 0; i < kNumberOfCoreRegisters; i++) { |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 56 | if (((frame_info.CoreSpillMask() >> i) & 1) != 0) { |
| 57 | gprs_[i] = fr.CalleeSaveAddress(spill_count - j, frame_info.FrameSizeInBytes()); |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 58 | j++; |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | if (fp_spill_count > 0) { |
| 64 | // Lowest number spill is farthest away, walk registers and fill into context. |
| 65 | int j = 1; |
| 66 | for (size_t i = 0; i < kNumberOfDRegisters; i++) { |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 67 | if (((frame_info.FpSpillMask() >> i) & 1) != 0) { |
| 68 | fprs_[i] = fr.CalleeSaveAddress(spill_count + fp_spill_count - j, |
| 69 | frame_info.FrameSizeInBytes()); |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 70 | j++; |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | void Arm64Context::SetGPR(uint32_t reg, uintptr_t value) { |
| 77 | DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters)); |
| 78 | DCHECK_NE(gprs_[reg], &gZero); // Can't overwrite this static value since they are never reset. |
| 79 | DCHECK(gprs_[reg] != NULL); |
| 80 | *gprs_[reg] = value; |
| 81 | } |
| 82 | |
| 83 | void Arm64Context::SmashCallerSaves() { |
| 84 | // This needs to be 0 because we want a null/zero return value. |
| 85 | gprs_[X0] = const_cast<uint64_t*>(&gZero); |
| 86 | gprs_[X1] = NULL; |
| 87 | gprs_[X2] = NULL; |
| 88 | gprs_[X3] = NULL; |
| 89 | gprs_[X4] = NULL; |
| 90 | gprs_[X5] = NULL; |
| 91 | gprs_[X6] = NULL; |
| 92 | gprs_[X7] = NULL; |
| 93 | gprs_[X8] = NULL; |
| 94 | gprs_[X9] = NULL; |
| 95 | gprs_[X10] = NULL; |
| 96 | gprs_[X11] = NULL; |
| 97 | gprs_[X12] = NULL; |
| 98 | gprs_[X13] = NULL; |
| 99 | gprs_[X14] = NULL; |
| 100 | gprs_[X15] = NULL; |
| 101 | |
Andreas Gampe | 6cf8010 | 2014-05-19 11:32:41 -0700 | [diff] [blame^] | 102 | // d0-d7, d16-d31 are caller-saved; d8-d15 are callee-saved. |
| 103 | |
| 104 | fprs_[D0] = NULL; |
| 105 | fprs_[D1] = NULL; |
| 106 | fprs_[D2] = NULL; |
| 107 | fprs_[D3] = NULL; |
| 108 | fprs_[D4] = NULL; |
| 109 | fprs_[D5] = NULL; |
| 110 | fprs_[D6] = NULL; |
| 111 | fprs_[D7] = NULL; |
| 112 | |
| 113 | fprs_[D16] = NULL; |
| 114 | fprs_[D17] = NULL; |
| 115 | fprs_[D18] = NULL; |
| 116 | fprs_[D19] = NULL; |
| 117 | fprs_[D20] = NULL; |
| 118 | fprs_[D21] = NULL; |
| 119 | fprs_[D22] = NULL; |
| 120 | fprs_[D23] = NULL; |
| 121 | fprs_[D24] = NULL; |
| 122 | fprs_[D25] = NULL; |
| 123 | fprs_[D26] = NULL; |
| 124 | fprs_[D27] = NULL; |
| 125 | fprs_[D28] = NULL; |
| 126 | fprs_[D29] = NULL; |
| 127 | fprs_[D30] = NULL; |
| 128 | fprs_[D31] = NULL; |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | extern "C" void art_quick_do_long_jump(uint64_t*, uint64_t*); |
| 132 | |
| 133 | void Arm64Context::DoLongJump() { |
| 134 | uint64_t gprs[32]; |
| 135 | uint64_t fprs[32]; |
| 136 | |
Andreas Gampe | a376328 | 2014-04-09 10:25:11 -0700 | [diff] [blame] | 137 | // Do not use kNumberOfCoreRegisters, as this is with the distinction of SP and XZR |
| 138 | for (size_t i = 0; i < 32; ++i) { |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 139 | gprs[i] = gprs_[i] != NULL ? *gprs_[i] : Arm64Context::kBadGprBase + i; |
| 140 | } |
| 141 | for (size_t i = 0; i < kNumberOfDRegisters; ++i) { |
| 142 | fprs[i] = fprs_[i] != NULL ? *fprs_[i] : Arm64Context::kBadGprBase + i; |
| 143 | } |
| 144 | DCHECK_EQ(reinterpret_cast<uintptr_t>(Thread::Current()), gprs[TR]); |
| 145 | art_quick_do_long_jump(gprs, fprs); |
| 146 | } |
| 147 | |
| 148 | } // namespace arm64 |
| 149 | } // namespace art |