blob: 9e8d282a87c8de0ad11a0ddcf8d3e8f7bd655efa [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"
Vladimir Marko7624d252014-05-02 14:40:15 +010020#include "quick/quick_method_frame_info.h"
Andreas Gampeb6886112014-11-03 08:47:01 -080021#include "utils.h"
Ian Rogersbdb03912011-09-14 00:55:44 -070022
23namespace art {
24namespace arm {
25
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020026static constexpr uint32_t gZero = 0;
Mathieu Chartier67022432012-11-29 18:04:50 -080027
28void ArmContext::Reset() {
29 for (size_t i = 0; i < kNumberOfCoreRegisters; i++) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020030 gprs_[i] = nullptr;
Ian Rogersbdb03912011-09-14 00:55:44 -070031 }
Mathieu Chartier67022432012-11-29 18:04:50 -080032 for (size_t i = 0; i < kNumberOfSRegisters; i++) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020033 fprs_[i] = nullptr;
Ian Rogers15fdb8c2011-09-25 15:45:07 -070034 }
Mathieu Chartier67022432012-11-29 18:04:50 -080035 gprs_[SP] = &sp_;
36 gprs_[PC] = &pc_;
37 // Initialize registers with easy to spot debug values.
38 sp_ = ArmContext::kBadGprBase + SP;
39 pc_ = ArmContext::kBadGprBase + PC;
Ian Rogersbdb03912011-09-14 00:55:44 -070040}
41
Ian Rogers0399dde2012-06-06 17:09:28 -070042void ArmContext::FillCalleeSaves(const StackVisitor& fr) {
Brian Carlstromea46f952013-07-30 01:26:50 -070043 mirror::ArtMethod* method = fr.GetMethod();
Vladimir Marko7624d252014-05-02 14:40:15 +010044 const QuickMethodFrameInfo frame_info = method->GetQuickFrameInfo();
45 size_t spill_count = POPCOUNT(frame_info.CoreSpillMask());
46 size_t fp_spill_count = POPCOUNT(frame_info.FpSpillMask());
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++) {
Vladimir Marko7624d252014-05-02 14:40:15 +010051 if (((frame_info.CoreSpillMask() >> i) & 1) != 0) {
52 gprs_[i] = fr.CalleeSaveAddress(spill_count - j, frame_info.FrameSizeInBytes());
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++) {
Vladimir Marko7624d252014-05-02 14:40:15 +010061 if (((frame_info.FpSpillMask() >> i) & 1) != 0) {
62 fprs_[i] = fr.CalleeSaveAddress(spill_count + fp_spill_count - j,
63 frame_info.FrameSizeInBytes());
Ian Rogers15fdb8c2011-09-25 15:45:07 -070064 j++;
65 }
66 }
67 }
Ian Rogersbdb03912011-09-14 00:55:44 -070068}
69
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020070bool ArmContext::SetGPR(uint32_t reg, uintptr_t value) {
Brian Carlstromd74e41b2013-03-24 23:47:01 -070071 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters));
Brian Carlstrom7934ac22013-07-26 10:54:15 -070072 DCHECK_NE(gprs_[reg], &gZero); // Can't overwrite this static value since they are never reset.
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020073 if (gprs_[reg] != nullptr) {
74 *gprs_[reg] = value;
75 return true;
76 } else {
77 return false;
78 }
79}
80
81bool ArmContext::SetFPR(uint32_t reg, uintptr_t value) {
82 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfSRegisters));
83 DCHECK_NE(fprs_[reg], &gZero); // Can't overwrite this static value since they are never reset.
84 if (fprs_[reg] != nullptr) {
85 *fprs_[reg] = value;
86 return true;
87 } else {
88 return false;
89 }
Mathieu Chartier67022432012-11-29 18:04:50 -080090}
91
Elliott Hughes9c750f92012-04-05 12:07:59 -070092void ArmContext::SmashCallerSaves() {
Mathieu Chartier67022432012-11-29 18:04:50 -080093 // This needs to be 0 because we want a null/zero return value.
94 gprs_[R0] = const_cast<uint32_t*>(&gZero);
95 gprs_[R1] = const_cast<uint32_t*>(&gZero);
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020096 gprs_[R2] = nullptr;
97 gprs_[R3] = nullptr;
Zheng Xu5667fdb2014-10-23 18:29:55 +080098
99 fprs_[S0] = nullptr;
100 fprs_[S1] = nullptr;
101 fprs_[S2] = nullptr;
102 fprs_[S3] = nullptr;
103 fprs_[S4] = nullptr;
104 fprs_[S5] = nullptr;
105 fprs_[S6] = nullptr;
106 fprs_[S7] = nullptr;
107 fprs_[S8] = nullptr;
108 fprs_[S9] = nullptr;
109 fprs_[S10] = nullptr;
110 fprs_[S11] = nullptr;
111 fprs_[S12] = nullptr;
112 fprs_[S13] = nullptr;
113 fprs_[S14] = nullptr;
114 fprs_[S15] = nullptr;
Elliott Hughes9c750f92012-04-05 12:07:59 -0700115}
116
Logan Chien8dbb7082013-01-25 20:31:17 +0800117extern "C" void art_quick_do_long_jump(uint32_t*, uint32_t*);
Ian Rogers57b86d42012-03-27 16:05:41 -0700118
Ian Rogersbdb03912011-09-14 00:55:44 -0700119void ArmContext::DoLongJump() {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +0200120 uintptr_t gprs[kNumberOfCoreRegisters];
121 uint32_t fprs[kNumberOfSRegisters];
Mathieu Chartier67022432012-11-29 18:04:50 -0800122 for (size_t i = 0; i < kNumberOfCoreRegisters; ++i) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +0200123 gprs[i] = gprs_[i] != nullptr ? *gprs_[i] : ArmContext::kBadGprBase + i;
Mathieu Chartier67022432012-11-29 18:04:50 -0800124 }
125 for (size_t i = 0; i < kNumberOfSRegisters; ++i) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +0200126 fprs[i] = fprs_[i] != nullptr ? *fprs_[i] : ArmContext::kBadFprBase + i;
Mathieu Chartier67022432012-11-29 18:04:50 -0800127 }
128 DCHECK_EQ(reinterpret_cast<uintptr_t>(Thread::Current()), gprs[TR]);
Logan Chien8dbb7082013-01-25 20:31:17 +0800129 art_quick_do_long_jump(gprs, fprs);
Ian Rogersbdb03912011-09-14 00:55:44 -0700130}
131
132} // namespace arm
133} // namespace art