Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [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 | */ |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 16 | |
| 17 | #include "context_arm.h" |
| 18 | |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 19 | #include "mirror/art_method-inl.h" |
Ian Rogers | 04d7aa9 | 2013-03-16 14:29:17 -0700 | [diff] [blame] | 20 | #include "mirror/object-inl.h" |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 21 | #include "quick/quick_method_frame_info.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 22 | #include "stack.h" |
| 23 | #include "thread.h" |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 24 | |
| 25 | namespace art { |
| 26 | namespace arm { |
| 27 | |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame^] | 28 | static constexpr uint32_t gZero = 0; |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 29 | |
| 30 | void ArmContext::Reset() { |
| 31 | for (size_t i = 0; i < kNumberOfCoreRegisters; i++) { |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame^] | 32 | gprs_[i] = nullptr; |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 33 | } |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 34 | for (size_t i = 0; i < kNumberOfSRegisters; i++) { |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame^] | 35 | fprs_[i] = nullptr; |
Ian Rogers | 15fdb8c | 2011-09-25 15:45:07 -0700 | [diff] [blame] | 36 | } |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 37 | gprs_[SP] = &sp_; |
| 38 | gprs_[PC] = &pc_; |
| 39 | // Initialize registers with easy to spot debug values. |
| 40 | sp_ = ArmContext::kBadGprBase + SP; |
| 41 | pc_ = ArmContext::kBadGprBase + PC; |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 44 | void ArmContext::FillCalleeSaves(const StackVisitor& fr) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 45 | mirror::ArtMethod* method = fr.GetMethod(); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 46 | const QuickMethodFrameInfo frame_info = method->GetQuickFrameInfo(); |
| 47 | size_t spill_count = POPCOUNT(frame_info.CoreSpillMask()); |
| 48 | size_t fp_spill_count = POPCOUNT(frame_info.FpSpillMask()); |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 49 | if (spill_count > 0) { |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 50 | // Lowest number spill is farthest away, walk registers and fill into context |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 51 | int j = 1; |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 52 | for (size_t i = 0; i < kNumberOfCoreRegisters; i++) { |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 53 | if (((frame_info.CoreSpillMask() >> i) & 1) != 0) { |
| 54 | gprs_[i] = fr.CalleeSaveAddress(spill_count - j, frame_info.FrameSizeInBytes()); |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 55 | j++; |
| 56 | } |
| 57 | } |
| 58 | } |
Ian Rogers | 15fdb8c | 2011-09-25 15:45:07 -0700 | [diff] [blame] | 59 | if (fp_spill_count > 0) { |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 60 | // Lowest number spill is farthest away, walk registers and fill into context |
Ian Rogers | 15fdb8c | 2011-09-25 15:45:07 -0700 | [diff] [blame] | 61 | int j = 1; |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 62 | for (size_t i = 0; i < kNumberOfSRegisters; i++) { |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 63 | if (((frame_info.FpSpillMask() >> i) & 1) != 0) { |
| 64 | fprs_[i] = fr.CalleeSaveAddress(spill_count + fp_spill_count - j, |
| 65 | frame_info.FrameSizeInBytes()); |
Ian Rogers | 15fdb8c | 2011-09-25 15:45:07 -0700 | [diff] [blame] | 66 | j++; |
| 67 | } |
| 68 | } |
| 69 | } |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame^] | 72 | bool ArmContext::SetGPR(uint32_t reg, uintptr_t value) { |
Brian Carlstrom | d74e41b | 2013-03-24 23:47:01 -0700 | [diff] [blame] | 73 | DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters)); |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 74 | DCHECK_NE(gprs_[reg], &gZero); // Can't overwrite this static value since they are never reset. |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame^] | 75 | if (gprs_[reg] != nullptr) { |
| 76 | *gprs_[reg] = value; |
| 77 | return true; |
| 78 | } else { |
| 79 | return false; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | bool ArmContext::SetFPR(uint32_t reg, uintptr_t value) { |
| 84 | DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfSRegisters)); |
| 85 | DCHECK_NE(fprs_[reg], &gZero); // Can't overwrite this static value since they are never reset. |
| 86 | if (fprs_[reg] != nullptr) { |
| 87 | *fprs_[reg] = value; |
| 88 | return true; |
| 89 | } else { |
| 90 | return false; |
| 91 | } |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 92 | } |
| 93 | |
Elliott Hughes | 9c750f9 | 2012-04-05 12:07:59 -0700 | [diff] [blame] | 94 | void ArmContext::SmashCallerSaves() { |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 95 | // This needs to be 0 because we want a null/zero return value. |
| 96 | gprs_[R0] = const_cast<uint32_t*>(&gZero); |
| 97 | gprs_[R1] = const_cast<uint32_t*>(&gZero); |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame^] | 98 | gprs_[R2] = nullptr; |
| 99 | gprs_[R3] = nullptr; |
Elliott Hughes | 9c750f9 | 2012-04-05 12:07:59 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Logan Chien | 8dbb708 | 2013-01-25 20:31:17 +0800 | [diff] [blame] | 102 | extern "C" void art_quick_do_long_jump(uint32_t*, uint32_t*); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 103 | |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 104 | void ArmContext::DoLongJump() { |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame^] | 105 | uintptr_t gprs[kNumberOfCoreRegisters]; |
| 106 | uint32_t fprs[kNumberOfSRegisters]; |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 107 | for (size_t i = 0; i < kNumberOfCoreRegisters; ++i) { |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame^] | 108 | gprs[i] = gprs_[i] != nullptr ? *gprs_[i] : ArmContext::kBadGprBase + i; |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 109 | } |
| 110 | for (size_t i = 0; i < kNumberOfSRegisters; ++i) { |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame^] | 111 | fprs[i] = fprs_[i] != nullptr ? *fprs_[i] : ArmContext::kBadFprBase + i; |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 112 | } |
| 113 | DCHECK_EQ(reinterpret_cast<uintptr_t>(Thread::Current()), gprs[TR]); |
Logan Chien | 8dbb708 | 2013-01-25 20:31:17 +0800 | [diff] [blame] | 114 | art_quick_do_long_jump(gprs, fprs); |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | } // namespace arm |
| 118 | } // namespace art |