blob: 375a03acee4394c7126ebedeee420eee96155be2 [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
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"
jeffhao7fbee072012-08-24 17:56:54 -070021
22namespace art {
23namespace mips {
24
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020025static constexpr uint32_t gZero = 0;
Mathieu Chartier67022432012-11-29 18:04:50 -080026
27void MipsContext::Reset() {
Vladimir Marko80afd022015-05-19 18:08:00 +010028 std::fill_n(gprs_, arraysize(gprs_), nullptr);
29 std::fill_n(fprs_, arraysize(fprs_), nullptr);
Mathieu Chartier67022432012-11-29 18:04:50 -080030 gprs_[SP] = &sp_;
Goran Jakovljevic75969962015-10-27 12:29:07 +010031 gprs_[T9] = &t9_;
Andreas Gampe639bdd12015-06-03 11:22:45 -070032 gprs_[A0] = &arg0_;
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;
Goran Jakovljevic75969962015-10-27 12:29:07 +010035 t9_ = MipsContext::kBadGprBase + T9;
Andreas Gampe639bdd12015-06-03 11:22:45 -070036 arg0_ = 0;
jeffhao7fbee072012-08-24 17:56:54 -070037}
38
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010039void MipsContext::FillCalleeSaves(uint8_t* frame, const QuickMethodFrameInfo& frame_info) {
Vladimir Marko80afd022015-05-19 18:08:00 +010040 int spill_pos = 0;
41
42 // Core registers come first, from the highest down to the lowest.
43 for (uint32_t core_reg : HighToLowBits(frame_info.CoreSpillMask())) {
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010044 gprs_[core_reg] = CalleeSaveAddress(frame, spill_pos, frame_info.FrameSizeInBytes());
Vladimir Marko80afd022015-05-19 18:08:00 +010045 ++spill_pos;
jeffhao7fbee072012-08-24 17:56:54 -070046 }
Vladimir Marko80afd022015-05-19 18:08:00 +010047 DCHECK_EQ(spill_pos, POPCOUNT(frame_info.CoreSpillMask()));
48
49 // FP registers come second, from the highest down to the lowest.
50 for (uint32_t fp_reg : HighToLowBits(frame_info.FpSpillMask())) {
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010051 fprs_[fp_reg] = CalleeSaveAddress(frame, spill_pos, frame_info.FrameSizeInBytes());
Vladimir Marko80afd022015-05-19 18:08:00 +010052 ++spill_pos;
jeffhao7fbee072012-08-24 17:56:54 -070053 }
Vladimir Marko80afd022015-05-19 18:08:00 +010054 DCHECK_EQ(spill_pos, POPCOUNT(frame_info.CoreSpillMask()) + POPCOUNT(frame_info.FpSpillMask()));
jeffhao7fbee072012-08-24 17:56:54 -070055}
56
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010057void MipsContext::SetGPR(uint32_t reg, uintptr_t value) {
Brian Carlstrom8b1ce162013-03-31 00:17:54 -070058 CHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters));
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010059 DCHECK(IsAccessibleGPR(reg));
Brian Carlstrom7934ac22013-07-26 10:54:15 -070060 CHECK_NE(gprs_[reg], &gZero); // Can't overwrite this static value since they are never reset.
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010061 *gprs_[reg] = value;
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020062}
63
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010064void MipsContext::SetFPR(uint32_t reg, uintptr_t value) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020065 CHECK_LT(reg, static_cast<uint32_t>(kNumberOfFRegisters));
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010066 DCHECK(IsAccessibleFPR(reg));
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020067 CHECK_NE(fprs_[reg], &gZero); // Can't overwrite this static value since they are never reset.
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010068 *fprs_[reg] = value;
Mathieu Chartier67022432012-11-29 18:04:50 -080069}
70
jeffhao7fbee072012-08-24 17:56:54 -070071void MipsContext::SmashCallerSaves() {
Mathieu Chartier67022432012-11-29 18:04:50 -080072 // This needs to be 0 because we want a null/zero return value.
73 gprs_[V0] = const_cast<uint32_t*>(&gZero);
74 gprs_[V1] = const_cast<uint32_t*>(&gZero);
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020075 gprs_[A1] = nullptr;
76 gprs_[A2] = nullptr;
77 gprs_[A3] = nullptr;
Goran Jakovljevicff734982015-08-24 12:58:55 +000078
79 fprs_[F12] = nullptr;
80 fprs_[F13] = nullptr;
81 fprs_[F14] = nullptr;
82 fprs_[F15] = nullptr;
jeffhao7fbee072012-08-24 17:56:54 -070083}
84
Andreas Gampe794ad762015-02-23 08:12:24 -080085extern "C" NO_RETURN void art_quick_do_long_jump(uint32_t*, uint32_t*);
jeffhao7fbee072012-08-24 17:56:54 -070086
87void MipsContext::DoLongJump() {
Mathieu Chartier67022432012-11-29 18:04:50 -080088 uintptr_t gprs[kNumberOfCoreRegisters];
89 uint32_t fprs[kNumberOfFRegisters];
90 for (size_t i = 0; i < kNumberOfCoreRegisters; ++i) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020091 gprs[i] = gprs_[i] != nullptr ? *gprs_[i] : MipsContext::kBadGprBase + i;
Mathieu Chartier67022432012-11-29 18:04:50 -080092 }
93 for (size_t i = 0; i < kNumberOfFRegisters; ++i) {
Vladimir Marko5b09ea02015-05-27 14:07:08 +010094 fprs[i] = fprs_[i] != nullptr ? *fprs_[i] : MipsContext::kBadFprBase + i;
Mathieu Chartier67022432012-11-29 18:04:50 -080095 }
Logan Chien8dbb7082013-01-25 20:31:17 +080096 art_quick_do_long_jump(gprs, fprs);
jeffhao7fbee072012-08-24 17:56:54 -070097}
98
99} // namespace mips
100} // namespace art