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 | |
| 19 | #include "object.h" |
| 20 | |
| 21 | namespace art { |
| 22 | namespace arm { |
| 23 | |
| 24 | ArmContext::ArmContext() { |
Ian Rogers | 67375ac | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 25 | #ifndef NDEBUG |
Ian Rogers | ad42e13 | 2011-09-17 20:23:33 -0700 | [diff] [blame] | 26 | // Initialize registers with easy to spot debug values |
Elliott Hughes | 362f9bc | 2011-10-17 18:56:41 -0700 | [diff] [blame] | 27 | for (int i = 0; i < 16; i++) { |
Elliott Hughes | 9c750f9 | 2012-04-05 12:07:59 -0700 | [diff] [blame] | 28 | gprs_[i] = kBadGprBase + i; |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 29 | } |
Elliott Hughes | 362f9bc | 2011-10-17 18:56:41 -0700 | [diff] [blame] | 30 | for (int i = 0; i < 32; i++) { |
Elliott Hughes | 9c750f9 | 2012-04-05 12:07:59 -0700 | [diff] [blame] | 31 | fprs_[i] = kBadFprBase + i; |
Ian Rogers | 15fdb8c | 2011-09-25 15:45:07 -0700 | [diff] [blame] | 32 | } |
Ian Rogers | 67375ac | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 33 | #endif |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 36 | void ArmContext::FillCalleeSaves(const StackVisitor& fr) { |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 37 | Method* method = fr.GetMethod(); |
| 38 | uint32_t core_spills = method->GetCoreSpillMask(); |
Ian Rogers | 15fdb8c | 2011-09-25 15:45:07 -0700 | [diff] [blame] | 39 | uint32_t fp_core_spills = method->GetFpSpillMask(); |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 40 | size_t spill_count = __builtin_popcount(core_spills); |
Ian Rogers | 15fdb8c | 2011-09-25 15:45:07 -0700 | [diff] [blame] | 41 | size_t fp_spill_count = __builtin_popcount(fp_core_spills); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 42 | size_t frame_size = method->GetFrameSizeInBytes(); |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 43 | if (spill_count > 0) { |
| 44 | // Lowest number spill is furthest away, walk registers and fill into context |
| 45 | int j = 1; |
Elliott Hughes | 362f9bc | 2011-10-17 18:56:41 -0700 | [diff] [blame] | 46 | for (int i = 0; i < 16; i++) { |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 47 | if (((core_spills >> i) & 1) != 0) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 48 | gprs_[i] = fr.LoadCalleeSave(spill_count - j, frame_size); |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 49 | j++; |
| 50 | } |
| 51 | } |
| 52 | } |
Ian Rogers | 15fdb8c | 2011-09-25 15:45:07 -0700 | [diff] [blame] | 53 | if (fp_spill_count > 0) { |
| 54 | // Lowest number spill is furthest away, walk registers and fill into context |
| 55 | int j = 1; |
Elliott Hughes | 362f9bc | 2011-10-17 18:56:41 -0700 | [diff] [blame] | 56 | for (int i = 0; i < 32; i++) { |
Ian Rogers | 15fdb8c | 2011-09-25 15:45:07 -0700 | [diff] [blame] | 57 | if (((fp_core_spills >> i) & 1) != 0) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 58 | fprs_[i] = fr.LoadCalleeSave(spill_count + fp_spill_count - j, frame_size); |
Ian Rogers | 15fdb8c | 2011-09-25 15:45:07 -0700 | [diff] [blame] | 59 | j++; |
| 60 | } |
| 61 | } |
| 62 | } |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Elliott Hughes | 9c750f9 | 2012-04-05 12:07:59 -0700 | [diff] [blame] | 65 | void ArmContext::SmashCallerSaves() { |
| 66 | gprs_[0] = 0; // This needs to be 0 because we want a null/zero return value. |
| 67 | gprs_[1] = kBadGprBase + 1; |
| 68 | gprs_[2] = kBadGprBase + 2; |
| 69 | gprs_[3] = kBadGprBase + 3; |
| 70 | gprs_[IP] = kBadGprBase + IP; |
| 71 | gprs_[LR] = kBadGprBase + LR; |
| 72 | } |
| 73 | |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 74 | extern "C" void art_do_long_jump(uint32_t*, uint32_t*); |
| 75 | |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 76 | void ArmContext::DoLongJump() { |
Brian Carlstrom | 6f495f2 | 2011-10-10 15:05:03 -0700 | [diff] [blame] | 77 | art_do_long_jump(&gprs_[0], &fprs_[S0]); |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | } // namespace arm |
| 81 | } // namespace art |