blob: 9cbec1e5bc8e6fcfd688340ea3effbbb79d78bab [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 Marko80afd022015-05-19 18:08:00 +010019#include "base/bit_utils.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010020#include "quick/quick_method_frame_info.h"
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010021#include "thread-inl.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
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010040void ArmContext::FillCalleeSaves(uint8_t* frame, const QuickMethodFrameInfo& frame_info) {
Vladimir Marko80afd022015-05-19 18:08:00 +010041 int spill_pos = 0;
42
43 // Core registers come first, from the highest down to the lowest.
44 uint32_t core_regs = frame_info.CoreSpillMask();
45 DCHECK_EQ(0u, core_regs & (static_cast<uint32_t>(-1) << kNumberOfCoreRegisters));
46 for (uint32_t core_reg : HighToLowBits(core_regs)) {
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010047 gprs_[core_reg] = CalleeSaveAddress(frame, spill_pos, frame_info.FrameSizeInBytes());
Vladimir Marko80afd022015-05-19 18:08:00 +010048 ++spill_pos;
Ian Rogersbdb03912011-09-14 00:55:44 -070049 }
Vladimir Marko80afd022015-05-19 18:08:00 +010050 DCHECK_EQ(spill_pos, POPCOUNT(frame_info.CoreSpillMask()));
51
52 // FP registers come second, from the highest down to the lowest.
53 for (uint32_t fp_reg : HighToLowBits(frame_info.FpSpillMask())) {
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010054 fprs_[fp_reg] = CalleeSaveAddress(frame, spill_pos, frame_info.FrameSizeInBytes());
Vladimir Marko80afd022015-05-19 18:08:00 +010055 ++spill_pos;
Ian Rogers15fdb8c2011-09-25 15:45:07 -070056 }
Vladimir Marko80afd022015-05-19 18:08:00 +010057 DCHECK_EQ(spill_pos, POPCOUNT(frame_info.CoreSpillMask()) + POPCOUNT(frame_info.FpSpillMask()));
Ian Rogersbdb03912011-09-14 00:55:44 -070058}
59
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010060void ArmContext::SetGPR(uint32_t reg, uintptr_t value) {
Brian Carlstromd74e41b2013-03-24 23:47:01 -070061 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters));
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010062 DCHECK(IsAccessibleGPR(reg));
Brian Carlstrom7934ac22013-07-26 10:54:15 -070063 DCHECK_NE(gprs_[reg], &gZero); // Can't overwrite this static value since they are never reset.
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010064 *gprs_[reg] = value;
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020065}
66
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010067void ArmContext::SetFPR(uint32_t reg, uintptr_t value) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020068 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfSRegisters));
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010069 DCHECK(IsAccessibleFPR(reg));
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020070 DCHECK_NE(fprs_[reg], &gZero); // Can't overwrite this static value since they are never reset.
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010071 *fprs_[reg] = value;
Mathieu Chartier67022432012-11-29 18:04:50 -080072}
73
Elliott Hughes9c750f92012-04-05 12:07:59 -070074void ArmContext::SmashCallerSaves() {
Mathieu Chartier67022432012-11-29 18:04:50 -080075 // This needs to be 0 because we want a null/zero return value.
76 gprs_[R0] = const_cast<uint32_t*>(&gZero);
77 gprs_[R1] = const_cast<uint32_t*>(&gZero);
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020078 gprs_[R2] = nullptr;
79 gprs_[R3] = nullptr;
Zheng Xu5667fdb2014-10-23 18:29:55 +080080
81 fprs_[S0] = nullptr;
82 fprs_[S1] = nullptr;
83 fprs_[S2] = nullptr;
84 fprs_[S3] = nullptr;
85 fprs_[S4] = nullptr;
86 fprs_[S5] = nullptr;
87 fprs_[S6] = nullptr;
88 fprs_[S7] = nullptr;
89 fprs_[S8] = nullptr;
90 fprs_[S9] = nullptr;
91 fprs_[S10] = nullptr;
92 fprs_[S11] = nullptr;
93 fprs_[S12] = nullptr;
94 fprs_[S13] = nullptr;
95 fprs_[S14] = nullptr;
96 fprs_[S15] = nullptr;
Elliott Hughes9c750f92012-04-05 12:07:59 -070097}
98
Andreas Gampe794ad762015-02-23 08:12:24 -080099extern "C" NO_RETURN void art_quick_do_long_jump(uint32_t*, uint32_t*);
Ian Rogers57b86d42012-03-27 16:05:41 -0700100
Ian Rogersbdb03912011-09-14 00:55:44 -0700101void ArmContext::DoLongJump() {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +0200102 uintptr_t gprs[kNumberOfCoreRegisters];
103 uint32_t fprs[kNumberOfSRegisters];
Mathieu Chartier67022432012-11-29 18:04:50 -0800104 for (size_t i = 0; i < kNumberOfCoreRegisters; ++i) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +0200105 gprs[i] = gprs_[i] != nullptr ? *gprs_[i] : ArmContext::kBadGprBase + i;
Mathieu Chartier67022432012-11-29 18:04:50 -0800106 }
107 for (size_t i = 0; i < kNumberOfSRegisters; ++i) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +0200108 fprs[i] = fprs_[i] != nullptr ? *fprs_[i] : ArmContext::kBadFprBase + i;
Mathieu Chartier67022432012-11-29 18:04:50 -0800109 }
110 DCHECK_EQ(reinterpret_cast<uintptr_t>(Thread::Current()), gprs[TR]);
Logan Chien8dbb7082013-01-25 20:31:17 +0800111 art_quick_do_long_jump(gprs, fprs);
Ian Rogersbdb03912011-09-14 00:55:44 -0700112}
113
114} // namespace arm
115} // namespace art