blob: 8f6b1ff0a5a169e45cb2709c6b57fe66e5636b9f [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
Mathieu Chartiere401d142015-04-22 13:56:20 -070019#include "art_method-inl.h"
Vladimir Marko80afd022015-05-19 18:08:00 +010020#include "base/bit_utils.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010021#include "quick/quick_method_frame_info.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() {
Vladimir Marko80afd022015-05-19 18:08:00 +010029 std::fill_n(gprs_, arraysize(gprs_), nullptr);
30 std::fill_n(fprs_, arraysize(fprs_), nullptr);
Mathieu Chartier67022432012-11-29 18:04:50 -080031 gprs_[SP] = &sp_;
32 gprs_[PC] = &pc_;
Andreas Gampe639bdd12015-06-03 11:22:45 -070033 gprs_[R0] = &arg0_;
Mathieu Chartier67022432012-11-29 18:04:50 -080034 // Initialize registers with easy to spot debug values.
35 sp_ = ArmContext::kBadGprBase + SP;
36 pc_ = ArmContext::kBadGprBase + PC;
Andreas Gampe639bdd12015-06-03 11:22:45 -070037 arg0_ = 0;
Ian Rogersbdb03912011-09-14 00:55:44 -070038}
39
Ian Rogers0399dde2012-06-06 17:09:28 -070040void ArmContext::FillCalleeSaves(const StackVisitor& fr) {
Mathieu Chartiere401d142015-04-22 13:56:20 -070041 ArtMethod* method = fr.GetMethod();
Vladimir Marko7624d252014-05-02 14:40:15 +010042 const QuickMethodFrameInfo frame_info = method->GetQuickFrameInfo();
Vladimir Marko80afd022015-05-19 18:08:00 +010043 int spill_pos = 0;
44
45 // Core registers come first, from the highest down to the lowest.
46 uint32_t core_regs = frame_info.CoreSpillMask();
47 DCHECK_EQ(0u, core_regs & (static_cast<uint32_t>(-1) << kNumberOfCoreRegisters));
48 for (uint32_t core_reg : HighToLowBits(core_regs)) {
49 gprs_[core_reg] = fr.CalleeSaveAddress(spill_pos, frame_info.FrameSizeInBytes());
50 ++spill_pos;
Ian Rogersbdb03912011-09-14 00:55:44 -070051 }
Vladimir Marko80afd022015-05-19 18:08:00 +010052 DCHECK_EQ(spill_pos, POPCOUNT(frame_info.CoreSpillMask()));
53
54 // FP registers come second, from the highest down to the lowest.
55 for (uint32_t fp_reg : HighToLowBits(frame_info.FpSpillMask())) {
56 fprs_[fp_reg] = fr.CalleeSaveAddress(spill_pos, frame_info.FrameSizeInBytes());
57 ++spill_pos;
Ian Rogers15fdb8c2011-09-25 15:45:07 -070058 }
Vladimir Marko80afd022015-05-19 18:08:00 +010059 DCHECK_EQ(spill_pos, POPCOUNT(frame_info.CoreSpillMask()) + POPCOUNT(frame_info.FpSpillMask()));
Ian Rogersbdb03912011-09-14 00:55:44 -070060}
61
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010062void ArmContext::SetGPR(uint32_t reg, uintptr_t value) {
Brian Carlstromd74e41b2013-03-24 23:47:01 -070063 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters));
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010064 DCHECK(IsAccessibleGPR(reg));
Brian Carlstrom7934ac22013-07-26 10:54:15 -070065 DCHECK_NE(gprs_[reg], &gZero); // Can't overwrite this static value since they are never reset.
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010066 *gprs_[reg] = value;
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020067}
68
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010069void ArmContext::SetFPR(uint32_t reg, uintptr_t value) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020070 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfSRegisters));
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010071 DCHECK(IsAccessibleFPR(reg));
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020072 DCHECK_NE(fprs_[reg], &gZero); // Can't overwrite this static value since they are never reset.
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010073 *fprs_[reg] = value;
Mathieu Chartier67022432012-11-29 18:04:50 -080074}
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);
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020080 gprs_[R2] = nullptr;
81 gprs_[R3] = nullptr;
Zheng Xu5667fdb2014-10-23 18:29:55 +080082
83 fprs_[S0] = nullptr;
84 fprs_[S1] = nullptr;
85 fprs_[S2] = nullptr;
86 fprs_[S3] = nullptr;
87 fprs_[S4] = nullptr;
88 fprs_[S5] = nullptr;
89 fprs_[S6] = nullptr;
90 fprs_[S7] = nullptr;
91 fprs_[S8] = nullptr;
92 fprs_[S9] = nullptr;
93 fprs_[S10] = nullptr;
94 fprs_[S11] = nullptr;
95 fprs_[S12] = nullptr;
96 fprs_[S13] = nullptr;
97 fprs_[S14] = nullptr;
98 fprs_[S15] = nullptr;
Elliott Hughes9c750f92012-04-05 12:07:59 -070099}
100
Andreas Gampe794ad762015-02-23 08:12:24 -0800101extern "C" NO_RETURN void art_quick_do_long_jump(uint32_t*, uint32_t*);
Ian Rogers57b86d42012-03-27 16:05:41 -0700102
Ian Rogersbdb03912011-09-14 00:55:44 -0700103void ArmContext::DoLongJump() {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +0200104 uintptr_t gprs[kNumberOfCoreRegisters];
105 uint32_t fprs[kNumberOfSRegisters];
Mathieu Chartier67022432012-11-29 18:04:50 -0800106 for (size_t i = 0; i < kNumberOfCoreRegisters; ++i) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +0200107 gprs[i] = gprs_[i] != nullptr ? *gprs_[i] : ArmContext::kBadGprBase + i;
Mathieu Chartier67022432012-11-29 18:04:50 -0800108 }
109 for (size_t i = 0; i < kNumberOfSRegisters; ++i) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +0200110 fprs[i] = fprs_[i] != nullptr ? *fprs_[i] : ArmContext::kBadFprBase + i;
Mathieu Chartier67022432012-11-29 18:04:50 -0800111 }
112 DCHECK_EQ(reinterpret_cast<uintptr_t>(Thread::Current()), gprs[TR]);
Logan Chien8dbb7082013-01-25 20:31:17 +0800113 art_quick_do_long_jump(gprs, fprs);
Ian Rogersbdb03912011-09-14 00:55:44 -0700114}
115
116} // namespace arm
117} // namespace art