blob: 96ffc9310f08c536891e03502b927b3e39c5d8f7 [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
Vladimir Marko7624d252014-05-02 14:40:15 +010019#include "mirror/art_method-inl.h"
Ian Rogers04d7aa92013-03-16 14:29:17 -070020#include "mirror/object-inl.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010021#include "quick/quick_method_frame_info.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080022#include "stack.h"
23#include "thread.h"
Ian Rogersbdb03912011-09-14 00:55:44 -070024
25namespace art {
26namespace arm {
27
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020028static constexpr uint32_t gZero = 0;
Mathieu Chartier67022432012-11-29 18:04:50 -080029
30void ArmContext::Reset() {
31 for (size_t i = 0; i < kNumberOfCoreRegisters; i++) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020032 gprs_[i] = nullptr;
Ian Rogersbdb03912011-09-14 00:55:44 -070033 }
Mathieu Chartier67022432012-11-29 18:04:50 -080034 for (size_t i = 0; i < kNumberOfSRegisters; i++) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020035 fprs_[i] = nullptr;
Ian Rogers15fdb8c2011-09-25 15:45:07 -070036 }
Mathieu Chartier67022432012-11-29 18:04:50 -080037 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 Rogersbdb03912011-09-14 00:55:44 -070042}
43
Ian Rogers0399dde2012-06-06 17:09:28 -070044void ArmContext::FillCalleeSaves(const StackVisitor& fr) {
Brian Carlstromea46f952013-07-30 01:26:50 -070045 mirror::ArtMethod* method = fr.GetMethod();
Vladimir Marko7624d252014-05-02 14:40:15 +010046 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 Rogersbdb03912011-09-14 00:55:44 -070049 if (spill_count > 0) {
Mathieu Chartier67022432012-11-29 18:04:50 -080050 // Lowest number spill is farthest away, walk registers and fill into context
Ian Rogersbdb03912011-09-14 00:55:44 -070051 int j = 1;
Mathieu Chartier67022432012-11-29 18:04:50 -080052 for (size_t i = 0; i < kNumberOfCoreRegisters; i++) {
Vladimir Marko7624d252014-05-02 14:40:15 +010053 if (((frame_info.CoreSpillMask() >> i) & 1) != 0) {
54 gprs_[i] = fr.CalleeSaveAddress(spill_count - j, frame_info.FrameSizeInBytes());
Ian Rogersbdb03912011-09-14 00:55:44 -070055 j++;
56 }
57 }
58 }
Ian Rogers15fdb8c2011-09-25 15:45:07 -070059 if (fp_spill_count > 0) {
Mathieu Chartier67022432012-11-29 18:04:50 -080060 // Lowest number spill is farthest away, walk registers and fill into context
Ian Rogers15fdb8c2011-09-25 15:45:07 -070061 int j = 1;
Mathieu Chartier67022432012-11-29 18:04:50 -080062 for (size_t i = 0; i < kNumberOfSRegisters; i++) {
Vladimir Marko7624d252014-05-02 14:40:15 +010063 if (((frame_info.FpSpillMask() >> i) & 1) != 0) {
64 fprs_[i] = fr.CalleeSaveAddress(spill_count + fp_spill_count - j,
65 frame_info.FrameSizeInBytes());
Ian Rogers15fdb8c2011-09-25 15:45:07 -070066 j++;
67 }
68 }
69 }
Ian Rogersbdb03912011-09-14 00:55:44 -070070}
71
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020072bool 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.
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020075 if (gprs_[reg] != nullptr) {
76 *gprs_[reg] = value;
77 return true;
78 } else {
79 return false;
80 }
81}
82
83bool 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 Chartier67022432012-11-29 18:04:50 -080092}
93
Elliott Hughes9c750f92012-04-05 12:07:59 -070094void ArmContext::SmashCallerSaves() {
Mathieu Chartier67022432012-11-29 18:04:50 -080095 // 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 Hertz0bcb2902014-06-17 15:52:45 +020098 gprs_[R2] = nullptr;
99 gprs_[R3] = nullptr;
Elliott Hughes9c750f92012-04-05 12:07:59 -0700100}
101
Logan Chien8dbb7082013-01-25 20:31:17 +0800102extern "C" void art_quick_do_long_jump(uint32_t*, uint32_t*);
Ian Rogers57b86d42012-03-27 16:05:41 -0700103
Ian Rogersbdb03912011-09-14 00:55:44 -0700104void ArmContext::DoLongJump() {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +0200105 uintptr_t gprs[kNumberOfCoreRegisters];
106 uint32_t fprs[kNumberOfSRegisters];
Mathieu Chartier67022432012-11-29 18:04:50 -0800107 for (size_t i = 0; i < kNumberOfCoreRegisters; ++i) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +0200108 gprs[i] = gprs_[i] != nullptr ? *gprs_[i] : ArmContext::kBadGprBase + i;
Mathieu Chartier67022432012-11-29 18:04:50 -0800109 }
110 for (size_t i = 0; i < kNumberOfSRegisters; ++i) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +0200111 fprs[i] = fprs_[i] != nullptr ? *fprs_[i] : ArmContext::kBadFprBase + i;
Mathieu Chartier67022432012-11-29 18:04:50 -0800112 }
113 DCHECK_EQ(reinterpret_cast<uintptr_t>(Thread::Current()), gprs[TR]);
Logan Chien8dbb7082013-01-25 20:31:17 +0800114 art_quick_do_long_jump(gprs, fprs);
Ian Rogersbdb03912011-09-14 00:55:44 -0700115}
116
117} // namespace arm
118} // namespace art