blob: 5bd4b3d02efbd74c138237fec3537b830f477ade [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
19#include "object.h"
20
21namespace art {
22namespace arm {
23
Mathieu Chartier67022432012-11-29 18:04:50 -080024static const uint32_t gZero = 0;
25
26void ArmContext::Reset() {
27 for (size_t i = 0; i < kNumberOfCoreRegisters; i++) {
28 gprs_[i] = NULL;
Ian Rogersbdb03912011-09-14 00:55:44 -070029 }
Mathieu Chartier67022432012-11-29 18:04:50 -080030 for (size_t i = 0; i < kNumberOfSRegisters; i++) {
31 fprs_[i] = NULL;
Ian Rogers15fdb8c2011-09-25 15:45:07 -070032 }
Mathieu Chartier67022432012-11-29 18:04:50 -080033 gprs_[SP] = &sp_;
34 gprs_[PC] = &pc_;
35 // Initialize registers with easy to spot debug values.
36 sp_ = ArmContext::kBadGprBase + SP;
37 pc_ = ArmContext::kBadGprBase + PC;
Ian Rogersbdb03912011-09-14 00:55:44 -070038}
39
Ian Rogers0399dde2012-06-06 17:09:28 -070040void ArmContext::FillCalleeSaves(const StackVisitor& fr) {
Mathieu Chartier66f19252012-09-18 08:57:04 -070041 AbstractMethod* method = fr.GetMethod();
Ian Rogersbdb03912011-09-14 00:55:44 -070042 uint32_t core_spills = method->GetCoreSpillMask();
Ian Rogers15fdb8c2011-09-25 15:45:07 -070043 uint32_t fp_core_spills = method->GetFpSpillMask();
Ian Rogersbdb03912011-09-14 00:55:44 -070044 size_t spill_count = __builtin_popcount(core_spills);
Ian Rogers15fdb8c2011-09-25 15:45:07 -070045 size_t fp_spill_count = __builtin_popcount(fp_core_spills);
Ian Rogers0399dde2012-06-06 17:09:28 -070046 size_t frame_size = method->GetFrameSizeInBytes();
Ian Rogersbdb03912011-09-14 00:55:44 -070047 if (spill_count > 0) {
Mathieu Chartier67022432012-11-29 18:04:50 -080048 // Lowest number spill is farthest away, walk registers and fill into context
Ian Rogersbdb03912011-09-14 00:55:44 -070049 int j = 1;
Mathieu Chartier67022432012-11-29 18:04:50 -080050 for (size_t i = 0; i < kNumberOfCoreRegisters; i++) {
Ian Rogersbdb03912011-09-14 00:55:44 -070051 if (((core_spills >> i) & 1) != 0) {
Mathieu Chartier67022432012-11-29 18:04:50 -080052 gprs_[i] = fr.CalleeSaveAddress(spill_count - j, frame_size);
Ian Rogersbdb03912011-09-14 00:55:44 -070053 j++;
54 }
55 }
56 }
Ian Rogers15fdb8c2011-09-25 15:45:07 -070057 if (fp_spill_count > 0) {
Mathieu Chartier67022432012-11-29 18:04:50 -080058 // Lowest number spill is farthest away, walk registers and fill into context
Ian Rogers15fdb8c2011-09-25 15:45:07 -070059 int j = 1;
Mathieu Chartier67022432012-11-29 18:04:50 -080060 for (size_t i = 0; i < kNumberOfSRegisters; i++) {
Ian Rogers15fdb8c2011-09-25 15:45:07 -070061 if (((fp_core_spills >> i) & 1) != 0) {
Mathieu Chartier67022432012-11-29 18:04:50 -080062 fprs_[i] = fr.CalleeSaveAddress(spill_count + fp_spill_count - j, frame_size);
Ian Rogers15fdb8c2011-09-25 15:45:07 -070063 j++;
64 }
65 }
66 }
Ian Rogersbdb03912011-09-14 00:55:44 -070067}
68
Mathieu Chartier67022432012-11-29 18:04:50 -080069void ArmContext::SetGPR(uint32_t reg, uintptr_t value) {
70 CHECK_LT(reg, kNumberOfCoreRegisters);
71 CHECK_NE(gprs_[reg], &gZero); // Can't overwrite this static value since they are never reset.
72 CHECK(gprs_[reg] != NULL);
73 *gprs_[reg] = value;
74}
75
Elliott Hughes9c750f92012-04-05 12:07:59 -070076void ArmContext::SmashCallerSaves() {
Mathieu Chartier67022432012-11-29 18:04:50 -080077 // This needs to be 0 because we want a null/zero return value.
78 gprs_[R0] = const_cast<uint32_t*>(&gZero);
79 gprs_[R1] = const_cast<uint32_t*>(&gZero);
80 gprs_[R2] = NULL;
81 gprs_[R3] = NULL;
Elliott Hughes9c750f92012-04-05 12:07:59 -070082}
83
Ian Rogers57b86d42012-03-27 16:05:41 -070084extern "C" void art_do_long_jump(uint32_t*, uint32_t*);
85
Ian Rogersbdb03912011-09-14 00:55:44 -070086void ArmContext::DoLongJump() {
Mathieu Chartier67022432012-11-29 18:04:50 -080087 uintptr_t gprs[16];
88 uint32_t fprs[32];
89 for (size_t i = 0; i < kNumberOfCoreRegisters; ++i) {
90 gprs[i] = gprs_[i] != NULL ? *gprs_[i] : ArmContext::kBadGprBase + i;
91 }
92 for (size_t i = 0; i < kNumberOfSRegisters; ++i) {
93 fprs[i] = fprs_[i] != NULL ? *fprs_[i] : ArmContext::kBadGprBase + i;
94 }
95 DCHECK_EQ(reinterpret_cast<uintptr_t>(Thread::Current()), gprs[TR]);
96 art_do_long_jump(gprs, fprs);
Ian Rogersbdb03912011-09-14 00:55:44 -070097}
98
99} // namespace arm
100} // namespace art