blob: d808c9e0dc7e44a4cd25ae043d1eff9aab896ae0 [file] [log] [blame]
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001/*
2 * Copyright (C) 2014 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 */
16
17#include "context_mips64.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"
Andreas Gampe1a5c4062015-01-15 12:10:47 -080021#include "quick/quick_method_frame_info.h"
Andreas Gampe1a5c4062015-01-15 12:10:47 -080022
23namespace art {
24namespace mips64 {
25
26static constexpr uintptr_t gZero = 0;
27
28void Mips64Context::Reset() {
Vladimir Marko80afd022015-05-19 18:08:00 +010029 std::fill_n(gprs_, arraysize(gprs_), nullptr);
30 std::fill_n(fprs_, arraysize(fprs_), nullptr);
Andreas Gampe1a5c4062015-01-15 12:10:47 -080031 gprs_[SP] = &sp_;
Andreas Gampedbf056d2015-09-25 08:24:13 -070032 gprs_[T9] = &t9_;
Andreas Gampe639bdd12015-06-03 11:22:45 -070033 gprs_[A0] = &arg0_;
Andreas Gampe1a5c4062015-01-15 12:10:47 -080034 // Initialize registers with easy to spot debug values.
35 sp_ = Mips64Context::kBadGprBase + SP;
Andreas Gampedbf056d2015-09-25 08:24:13 -070036 t9_ = Mips64Context::kBadGprBase + T9;
Andreas Gampe639bdd12015-06-03 11:22:45 -070037 arg0_ = 0;
Andreas Gampe1a5c4062015-01-15 12:10:47 -080038}
39
40void Mips64Context::FillCalleeSaves(const StackVisitor& fr) {
Vladimir Marko245c11a2015-10-13 15:28:24 +010041 ArtCode code = fr.GetCurrentCode();
Nicolas Geoffray6bc43742015-10-12 18:11:10 +010042 const QuickMethodFrameInfo frame_info = code.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 for (uint32_t core_reg : HighToLowBits(frame_info.CoreSpillMask())) {
47 gprs_[core_reg] = fr.CalleeSaveAddress(spill_pos, frame_info.FrameSizeInBytes());
48 ++spill_pos;
Andreas Gampe1a5c4062015-01-15 12:10:47 -080049 }
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())) {
54 fprs_[fp_reg] = fr.CalleeSaveAddress(spill_pos, frame_info.FrameSizeInBytes());
55 ++spill_pos;
Andreas Gampe1a5c4062015-01-15 12:10:47 -080056 }
Vladimir Marko80afd022015-05-19 18:08:00 +010057 DCHECK_EQ(spill_pos, POPCOUNT(frame_info.CoreSpillMask()) + POPCOUNT(frame_info.FpSpillMask()));
Andreas Gampe1a5c4062015-01-15 12:10:47 -080058}
59
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010060void Mips64Context::SetGPR(uint32_t reg, uintptr_t value) {
Andreas Gampe1a5c4062015-01-15 12:10:47 -080061 CHECK_LT(reg, static_cast<uint32_t>(kNumberOfGpuRegisters));
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010062 DCHECK(IsAccessibleGPR(reg));
Andreas Gampe1a5c4062015-01-15 12:10:47 -080063 CHECK_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;
Andreas Gampe1a5c4062015-01-15 12:10:47 -080065}
66
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010067void Mips64Context::SetFPR(uint32_t reg, uintptr_t value) {
Andreas Gampe1a5c4062015-01-15 12:10:47 -080068 CHECK_LT(reg, static_cast<uint32_t>(kNumberOfFpuRegisters));
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010069 DCHECK(IsAccessibleFPR(reg));
Andreas Gampe1a5c4062015-01-15 12:10:47 -080070 CHECK_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;
Andreas Gampe1a5c4062015-01-15 12:10:47 -080072}
73
74void Mips64Context::SmashCallerSaves() {
75 // This needs to be 0 because we want a null/zero return value.
76 gprs_[V0] = const_cast<uintptr_t*>(&gZero);
77 gprs_[V1] = const_cast<uintptr_t*>(&gZero);
78 gprs_[A1] = nullptr;
79 gprs_[A0] = nullptr;
80 gprs_[A2] = nullptr;
81 gprs_[A3] = nullptr;
82 gprs_[A4] = nullptr;
83 gprs_[A5] = nullptr;
84 gprs_[A6] = nullptr;
85 gprs_[A7] = nullptr;
86
87 // f0-f23 are caller-saved; f24-f31 are callee-saved.
88 fprs_[F0] = nullptr;
89 fprs_[F1] = nullptr;
90 fprs_[F2] = nullptr;
91 fprs_[F3] = nullptr;
92 fprs_[F4] = nullptr;
93 fprs_[F5] = nullptr;
94 fprs_[F6] = nullptr;
95 fprs_[F7] = nullptr;
96 fprs_[F8] = nullptr;
97 fprs_[F9] = nullptr;
98 fprs_[F10] = nullptr;
99 fprs_[F11] = nullptr;
100 fprs_[F12] = nullptr;
101 fprs_[F13] = nullptr;
102 fprs_[F14] = nullptr;
103 fprs_[F15] = nullptr;
104 fprs_[F16] = nullptr;
105 fprs_[F17] = nullptr;
106 fprs_[F18] = nullptr;
107 fprs_[F19] = nullptr;
108 fprs_[F20] = nullptr;
109 fprs_[F21] = nullptr;
110 fprs_[F22] = nullptr;
111 fprs_[F23] = nullptr;
112}
113
Andreas Gampe794ad762015-02-23 08:12:24 -0800114extern "C" NO_RETURN void art_quick_do_long_jump(uintptr_t*, uintptr_t*);
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800115
116void Mips64Context::DoLongJump() {
117 uintptr_t gprs[kNumberOfGpuRegisters];
118 uintptr_t fprs[kNumberOfFpuRegisters];
119 for (size_t i = 0; i < kNumberOfGpuRegisters; ++i) {
120 gprs[i] = gprs_[i] != nullptr ? *gprs_[i] : Mips64Context::kBadGprBase + i;
121 }
122 for (size_t i = 0; i < kNumberOfFpuRegisters; ++i) {
123 fprs[i] = fprs_[i] != nullptr ? *fprs_[i] : Mips64Context::kBadFprBase + i;
124 }
125 art_quick_do_long_jump(gprs, fprs);
126}
127
128} // namespace mips64
129} // namespace art