blob: 102e1269b5ca2906a0b476e5e75d2c48b8a40a00 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 Rogersbdb03912011-09-14 00:55:44 -070016
17#include "context_arm.h"
18
Brian Carlstromea46f952013-07-30 01:26:50 -070019#include "mirror/art_method.h"
Ian Rogers04d7aa92013-03-16 14:29:17 -070020#include "mirror/object-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080021#include "stack.h"
22#include "thread.h"
Ian Rogersbdb03912011-09-14 00:55:44 -070023
24namespace art {
25namespace arm {
26
Mathieu Chartier67022432012-11-29 18:04:50 -080027static const uint32_t gZero = 0;
28
29void ArmContext::Reset() {
30 for (size_t i = 0; i < kNumberOfCoreRegisters; i++) {
31 gprs_[i] = NULL;
Ian Rogersbdb03912011-09-14 00:55:44 -070032 }
Mathieu Chartier67022432012-11-29 18:04:50 -080033 for (size_t i = 0; i < kNumberOfSRegisters; i++) {
34 fprs_[i] = NULL;
Ian Rogers15fdb8c2011-09-25 15:45:07 -070035 }
Mathieu Chartier67022432012-11-29 18:04:50 -080036 gprs_[SP] = &sp_;
37 gprs_[PC] = &pc_;
38 // Initialize registers with easy to spot debug values.
39 sp_ = ArmContext::kBadGprBase + SP;
40 pc_ = ArmContext::kBadGprBase + PC;
Ian Rogersbdb03912011-09-14 00:55:44 -070041}
42
Ian Rogers0399dde2012-06-06 17:09:28 -070043void ArmContext::FillCalleeSaves(const StackVisitor& fr) {
Brian Carlstromea46f952013-07-30 01:26:50 -070044 mirror::ArtMethod* method = fr.GetMethod();
Ian Rogersbdb03912011-09-14 00:55:44 -070045 uint32_t core_spills = method->GetCoreSpillMask();
Ian Rogers15fdb8c2011-09-25 15:45:07 -070046 uint32_t fp_core_spills = method->GetFpSpillMask();
Ian Rogersbdb03912011-09-14 00:55:44 -070047 size_t spill_count = __builtin_popcount(core_spills);
Ian Rogers15fdb8c2011-09-25 15:45:07 -070048 size_t fp_spill_count = __builtin_popcount(fp_core_spills);
Ian Rogers0399dde2012-06-06 17:09:28 -070049 size_t frame_size = method->GetFrameSizeInBytes();
Ian Rogersbdb03912011-09-14 00:55:44 -070050 if (spill_count > 0) {
Mathieu Chartier67022432012-11-29 18:04:50 -080051 // Lowest number spill is farthest away, walk registers and fill into context
Ian Rogersbdb03912011-09-14 00:55:44 -070052 int j = 1;
Mathieu Chartier67022432012-11-29 18:04:50 -080053 for (size_t i = 0; i < kNumberOfCoreRegisters; i++) {
Ian Rogersbdb03912011-09-14 00:55:44 -070054 if (((core_spills >> i) & 1) != 0) {
Mathieu Chartier67022432012-11-29 18:04:50 -080055 gprs_[i] = fr.CalleeSaveAddress(spill_count - j, frame_size);
Ian Rogersbdb03912011-09-14 00:55:44 -070056 j++;
57 }
58 }
59 }
Ian Rogers15fdb8c2011-09-25 15:45:07 -070060 if (fp_spill_count > 0) {
Mathieu Chartier67022432012-11-29 18:04:50 -080061 // Lowest number spill is farthest away, walk registers and fill into context
Ian Rogers15fdb8c2011-09-25 15:45:07 -070062 int j = 1;
Mathieu Chartier67022432012-11-29 18:04:50 -080063 for (size_t i = 0; i < kNumberOfSRegisters; i++) {
Ian Rogers15fdb8c2011-09-25 15:45:07 -070064 if (((fp_core_spills >> i) & 1) != 0) {
Mathieu Chartier67022432012-11-29 18:04:50 -080065 fprs_[i] = fr.CalleeSaveAddress(spill_count + fp_spill_count - j, frame_size);
Ian Rogers15fdb8c2011-09-25 15:45:07 -070066 j++;
67 }
68 }
69 }
Ian Rogersbdb03912011-09-14 00:55:44 -070070}
71
Mathieu Chartier67022432012-11-29 18:04:50 -080072void ArmContext::SetGPR(uint32_t reg, uintptr_t value) {
Brian Carlstromd74e41b2013-03-24 23:47:01 -070073 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters));
Brian Carlstrom7934ac22013-07-26 10:54:15 -070074 DCHECK_NE(gprs_[reg], &gZero); // Can't overwrite this static value since they are never reset.
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070075 DCHECK(gprs_[reg] != NULL);
Mathieu Chartier67022432012-11-29 18:04:50 -080076 *gprs_[reg] = value;
77}
78
Elliott Hughes9c750f92012-04-05 12:07:59 -070079void ArmContext::SmashCallerSaves() {
Mathieu Chartier67022432012-11-29 18:04:50 -080080 // This needs to be 0 because we want a null/zero return value.
81 gprs_[R0] = const_cast<uint32_t*>(&gZero);
82 gprs_[R1] = const_cast<uint32_t*>(&gZero);
83 gprs_[R2] = NULL;
84 gprs_[R3] = NULL;
Elliott Hughes9c750f92012-04-05 12:07:59 -070085}
86
Logan Chien8dbb7082013-01-25 20:31:17 +080087extern "C" void art_quick_do_long_jump(uint32_t*, uint32_t*);
Ian Rogers57b86d42012-03-27 16:05:41 -070088
Ian Rogersbdb03912011-09-14 00:55:44 -070089void ArmContext::DoLongJump() {
Mathieu Chartier67022432012-11-29 18:04:50 -080090 uintptr_t gprs[16];
91 uint32_t fprs[32];
92 for (size_t i = 0; i < kNumberOfCoreRegisters; ++i) {
93 gprs[i] = gprs_[i] != NULL ? *gprs_[i] : ArmContext::kBadGprBase + i;
94 }
95 for (size_t i = 0; i < kNumberOfSRegisters; ++i) {
96 fprs[i] = fprs_[i] != NULL ? *fprs_[i] : ArmContext::kBadGprBase + i;
97 }
98 DCHECK_EQ(reinterpret_cast<uintptr_t>(Thread::Current()), gprs[TR]);
Logan Chien8dbb7082013-01-25 20:31:17 +080099 art_quick_do_long_jump(gprs, fprs);
Ian Rogersbdb03912011-09-14 00:55:44 -0700100}
101
102} // namespace arm
103} // namespace art