blob: 5bd23d0def491efefc60cc096a7af79c36422cd0 [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 Hertz96ba8dc2015-01-22 18:57:14 +010070void ArmContext::SetGPR(uint32_t reg, uintptr_t value) {
Brian Carlstromd74e41b2013-03-24 23:47:01 -070071 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters));
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010072 DCHECK(IsAccessibleGPR(reg));
Brian Carlstrom7934ac22013-07-26 10:54:15 -070073 DCHECK_NE(gprs_[reg], &gZero); // Can't overwrite this static value since they are never reset.
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010074 *gprs_[reg] = value;
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020075}
76
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010077void ArmContext::SetFPR(uint32_t reg, uintptr_t value) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020078 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfSRegisters));
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010079 DCHECK(IsAccessibleFPR(reg));
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020080 DCHECK_NE(fprs_[reg], &gZero); // Can't overwrite this static value since they are never reset.
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010081 *fprs_[reg] = value;
Mathieu Chartier67022432012-11-29 18:04:50 -080082}
83
Elliott Hughes9c750f92012-04-05 12:07:59 -070084void ArmContext::SmashCallerSaves() {
Mathieu Chartier67022432012-11-29 18:04:50 -080085 // This needs to be 0 because we want a null/zero return value.
86 gprs_[R0] = const_cast<uint32_t*>(&gZero);
87 gprs_[R1] = const_cast<uint32_t*>(&gZero);
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020088 gprs_[R2] = nullptr;
89 gprs_[R3] = nullptr;
Zheng Xu5667fdb2014-10-23 18:29:55 +080090
91 fprs_[S0] = nullptr;
92 fprs_[S1] = nullptr;
93 fprs_[S2] = nullptr;
94 fprs_[S3] = nullptr;
95 fprs_[S4] = nullptr;
96 fprs_[S5] = nullptr;
97 fprs_[S6] = nullptr;
98 fprs_[S7] = nullptr;
99 fprs_[S8] = nullptr;
100 fprs_[S9] = nullptr;
101 fprs_[S10] = nullptr;
102 fprs_[S11] = nullptr;
103 fprs_[S12] = nullptr;
104 fprs_[S13] = nullptr;
105 fprs_[S14] = nullptr;
106 fprs_[S15] = nullptr;
Elliott Hughes9c750f92012-04-05 12:07:59 -0700107}
108
Andreas Gampe794ad762015-02-23 08:12:24 -0800109extern "C" NO_RETURN void art_quick_do_long_jump(uint32_t*, uint32_t*);
Ian Rogers57b86d42012-03-27 16:05:41 -0700110
Ian Rogersbdb03912011-09-14 00:55:44 -0700111void ArmContext::DoLongJump() {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +0200112 uintptr_t gprs[kNumberOfCoreRegisters];
113 uint32_t fprs[kNumberOfSRegisters];
Mathieu Chartier67022432012-11-29 18:04:50 -0800114 for (size_t i = 0; i < kNumberOfCoreRegisters; ++i) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +0200115 gprs[i] = gprs_[i] != nullptr ? *gprs_[i] : ArmContext::kBadGprBase + i;
Mathieu Chartier67022432012-11-29 18:04:50 -0800116 }
117 for (size_t i = 0; i < kNumberOfSRegisters; ++i) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +0200118 fprs[i] = fprs_[i] != nullptr ? *fprs_[i] : ArmContext::kBadFprBase + i;
Mathieu Chartier67022432012-11-29 18:04:50 -0800119 }
120 DCHECK_EQ(reinterpret_cast<uintptr_t>(Thread::Current()), gprs[TR]);
Logan Chien8dbb7082013-01-25 20:31:17 +0800121 art_quick_do_long_jump(gprs, fprs);
Ian Rogersbdb03912011-09-14 00:55:44 -0700122}
123
124} // namespace arm
125} // namespace art