blob: 6a337b303804b3e473deec6bb8449dbf501fffd0 [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
Mathieu Chartier67022432012-11-29 18:04:50 -080028static const uint32_t gZero = 0;
29
30void ArmContext::Reset() {
31 for (size_t i = 0; i < kNumberOfCoreRegisters; i++) {
32 gprs_[i] = NULL;
Ian Rogersbdb03912011-09-14 00:55:44 -070033 }
Mathieu Chartier67022432012-11-29 18:04:50 -080034 for (size_t i = 0; i < kNumberOfSRegisters; i++) {
35 fprs_[i] = NULL;
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
Mathieu Chartier67022432012-11-29 18:04:50 -080072void 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.
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070075 DCHECK(gprs_[reg] != NULL);
Mathieu Chartier67022432012-11-29 18:04:50 -080076 *gprs_[reg] = value;
77}
78
Elliott Hughes9c750f92012-04-05 12:07:59 -070079void ArmContext::SmashCallerSaves() {
Mathieu Chartier67022432012-11-29 18:04:50 -080080 // This needs to be 0 because we want a null/zero return value.
81 gprs_[R0] = const_cast<uint32_t*>(&gZero);
82 gprs_[R1] = const_cast<uint32_t*>(&gZero);
83 gprs_[R2] = NULL;
84 gprs_[R3] = NULL;
Elliott Hughes9c750f92012-04-05 12:07:59 -070085}
86
Logan Chien8dbb7082013-01-25 20:31:17 +080087extern "C" void art_quick_do_long_jump(uint32_t*, uint32_t*);
Ian Rogers57b86d42012-03-27 16:05:41 -070088
Ian Rogersbdb03912011-09-14 00:55:44 -070089void ArmContext::DoLongJump() {
Mathieu Chartier67022432012-11-29 18:04:50 -080090 uintptr_t gprs[16];
91 uint32_t fprs[32];
92 for (size_t i = 0; i < kNumberOfCoreRegisters; ++i) {
93 gprs[i] = gprs_[i] != NULL ? *gprs_[i] : ArmContext::kBadGprBase + i;
94 }
95 for (size_t i = 0; i < kNumberOfSRegisters; ++i) {
96 fprs[i] = fprs_[i] != NULL ? *fprs_[i] : ArmContext::kBadGprBase + i;
97 }
98 DCHECK_EQ(reinterpret_cast<uintptr_t>(Thread::Current()), gprs[TR]);
Logan Chien8dbb7082013-01-25 20:31:17 +080099 art_quick_do_long_jump(gprs, fprs);
Ian Rogersbdb03912011-09-14 00:55:44 -0700100}
101
102} // namespace arm
103} // namespace art