blob: bc2bf68993ac2fc7ff1a41523dff888b223f4ef9 [file] [log] [blame]
jeffhao7fbee072012-08-24 17:56:54 -07001/*
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 */
16
17#include "context_mips.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"
jeffhao7fbee072012-08-24 17:56:54 -070022
23namespace art {
24namespace mips {
25
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020026static constexpr uint32_t gZero = 0;
Mathieu Chartier67022432012-11-29 18:04:50 -080027
28void MipsContext::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_[RA] = &ra_;
jeffhao7fbee072012-08-24 17:56:54 -070033 // Initialize registers with easy to spot debug values.
Mathieu Chartier67022432012-11-29 18:04:50 -080034 sp_ = MipsContext::kBadGprBase + SP;
35 ra_ = MipsContext::kBadGprBase + RA;
jeffhao7fbee072012-08-24 17:56:54 -070036}
37
38void MipsContext::FillCalleeSaves(const StackVisitor& fr) {
Mathieu Chartiere401d142015-04-22 13:56:20 -070039 ArtMethod* method = fr.GetMethod();
Vladimir Marko7624d252014-05-02 14:40:15 +010040 const QuickMethodFrameInfo frame_info = method->GetQuickFrameInfo();
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 for (uint32_t core_reg : HighToLowBits(frame_info.CoreSpillMask())) {
45 gprs_[core_reg] = fr.CalleeSaveAddress(spill_pos, frame_info.FrameSizeInBytes());
46 ++spill_pos;
jeffhao7fbee072012-08-24 17:56:54 -070047 }
Vladimir Marko80afd022015-05-19 18:08:00 +010048 DCHECK_EQ(spill_pos, POPCOUNT(frame_info.CoreSpillMask()));
49
50 // FP registers come second, from the highest down to the lowest.
51 for (uint32_t fp_reg : HighToLowBits(frame_info.FpSpillMask())) {
52 fprs_[fp_reg] = fr.CalleeSaveAddress(spill_pos, frame_info.FrameSizeInBytes());
53 ++spill_pos;
jeffhao7fbee072012-08-24 17:56:54 -070054 }
Vladimir Marko80afd022015-05-19 18:08:00 +010055 DCHECK_EQ(spill_pos, POPCOUNT(frame_info.CoreSpillMask()) + POPCOUNT(frame_info.FpSpillMask()));
jeffhao7fbee072012-08-24 17:56:54 -070056}
57
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010058void MipsContext::SetGPR(uint32_t reg, uintptr_t value) {
Brian Carlstrom8b1ce162013-03-31 00:17:54 -070059 CHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters));
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010060 DCHECK(IsAccessibleGPR(reg));
Brian Carlstrom7934ac22013-07-26 10:54:15 -070061 CHECK_NE(gprs_[reg], &gZero); // Can't overwrite this static value since they are never reset.
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010062 *gprs_[reg] = value;
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020063}
64
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010065void MipsContext::SetFPR(uint32_t reg, uintptr_t value) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020066 CHECK_LT(reg, static_cast<uint32_t>(kNumberOfFRegisters));
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010067 DCHECK(IsAccessibleFPR(reg));
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020068 CHECK_NE(fprs_[reg], &gZero); // Can't overwrite this static value since they are never reset.
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010069 *fprs_[reg] = value;
Mathieu Chartier67022432012-11-29 18:04:50 -080070}
71
jeffhao7fbee072012-08-24 17:56:54 -070072void MipsContext::SmashCallerSaves() {
Mathieu Chartier67022432012-11-29 18:04:50 -080073 // This needs to be 0 because we want a null/zero return value.
74 gprs_[V0] = const_cast<uint32_t*>(&gZero);
75 gprs_[V1] = const_cast<uint32_t*>(&gZero);
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020076 gprs_[A1] = nullptr;
77 gprs_[A2] = nullptr;
78 gprs_[A3] = nullptr;
Goran Jakovljevicff734982015-08-24 12:58:55 +000079
80 fprs_[F12] = nullptr;
81 fprs_[F13] = nullptr;
82 fprs_[F14] = nullptr;
83 fprs_[F15] = nullptr;
jeffhao7fbee072012-08-24 17:56:54 -070084}
85
Andreas Gampe794ad762015-02-23 08:12:24 -080086extern "C" NO_RETURN void art_quick_do_long_jump(uint32_t*, uint32_t*);
jeffhao7fbee072012-08-24 17:56:54 -070087
88void MipsContext::DoLongJump() {
Mathieu Chartier67022432012-11-29 18:04:50 -080089 uintptr_t gprs[kNumberOfCoreRegisters];
90 uint32_t fprs[kNumberOfFRegisters];
91 for (size_t i = 0; i < kNumberOfCoreRegisters; ++i) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020092 gprs[i] = gprs_[i] != nullptr ? *gprs_[i] : MipsContext::kBadGprBase + i;
Mathieu Chartier67022432012-11-29 18:04:50 -080093 }
94 for (size_t i = 0; i < kNumberOfFRegisters; ++i) {
Vladimir Marko5b09ea02015-05-27 14:07:08 +010095 fprs[i] = fprs_[i] != nullptr ? *fprs_[i] : MipsContext::kBadFprBase + i;
Mathieu Chartier67022432012-11-29 18:04:50 -080096 }
Logan Chien8dbb7082013-01-25 20:31:17 +080097 art_quick_do_long_jump(gprs, fprs);
jeffhao7fbee072012-08-24 17:56:54 -070098}
99
100} // namespace mips
101} // namespace art