blob: 3b525be122c33668ad68f1367479a7f81fd59785 [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 Marko7624d252014-05-02 14:40:15 +010019#include "mirror/art_method-inl.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010020#include "quick/quick_method_frame_info.h"
Andreas Gampeb6886112014-11-03 08:47:01 -080021#include "utils.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() {
29 for (size_t i = 0; i < kNumberOfCoreRegisters; i++) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020030 gprs_[i] = nullptr;
Mathieu Chartier67022432012-11-29 18:04:50 -080031 }
32 for (size_t i = 0; i < kNumberOfFRegisters; i++) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020033 fprs_[i] = nullptr;
Mathieu Chartier67022432012-11-29 18:04:50 -080034 }
35 gprs_[SP] = &sp_;
36 gprs_[RA] = &ra_;
jeffhao7fbee072012-08-24 17:56:54 -070037 // Initialize registers with easy to spot debug values.
Mathieu Chartier67022432012-11-29 18:04:50 -080038 sp_ = MipsContext::kBadGprBase + SP;
39 ra_ = MipsContext::kBadGprBase + RA;
jeffhao7fbee072012-08-24 17:56:54 -070040}
41
42void MipsContext::FillCalleeSaves(const StackVisitor& fr) {
Brian Carlstromea46f952013-07-30 01:26:50 -070043 mirror::ArtMethod* method = fr.GetMethod();
Vladimir Marko7624d252014-05-02 14:40:15 +010044 const QuickMethodFrameInfo frame_info = method->GetQuickFrameInfo();
45 size_t spill_count = POPCOUNT(frame_info.CoreSpillMask());
46 size_t fp_spill_count = POPCOUNT(frame_info.FpSpillMask());
jeffhao7fbee072012-08-24 17:56:54 -070047 if (spill_count > 0) {
Mathieu Chartier67022432012-11-29 18:04:50 -080048 // Lowest number spill is farthest away, walk registers and fill into context.
jeffhao7fbee072012-08-24 17:56:54 -070049 int j = 1;
Mathieu Chartier67022432012-11-29 18:04:50 -080050 for (size_t i = 0; i < kNumberOfCoreRegisters; i++) {
Vladimir Marko7624d252014-05-02 14:40:15 +010051 if (((frame_info.CoreSpillMask() >> i) & 1) != 0) {
52 gprs_[i] = fr.CalleeSaveAddress(spill_count - j, frame_info.FrameSizeInBytes());
jeffhao7fbee072012-08-24 17:56:54 -070053 j++;
54 }
55 }
56 }
57 if (fp_spill_count > 0) {
Mathieu Chartier67022432012-11-29 18:04:50 -080058 // Lowest number spill is farthest away, walk registers and fill into context.
jeffhao7fbee072012-08-24 17:56:54 -070059 int j = 1;
Mathieu Chartier67022432012-11-29 18:04:50 -080060 for (size_t i = 0; i < kNumberOfFRegisters; i++) {
Vladimir Marko7624d252014-05-02 14:40:15 +010061 if (((frame_info.FpSpillMask() >> i) & 1) != 0) {
62 fprs_[i] = fr.CalleeSaveAddress(spill_count + fp_spill_count - j,
63 frame_info.FrameSizeInBytes());
jeffhao7fbee072012-08-24 17:56:54 -070064 j++;
65 }
66 }
67 }
68}
69
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010070void MipsContext::SetGPR(uint32_t reg, uintptr_t value) {
Brian Carlstrom8b1ce162013-03-31 00:17:54 -070071 CHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters));
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010072 DCHECK(IsAccessibleGPR(reg));
Brian Carlstrom7934ac22013-07-26 10:54:15 -070073 CHECK_NE(gprs_[reg], &gZero); // Can't overwrite this static value since they are never reset.
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010074 *gprs_[reg] = value;
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020075}
76
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010077void MipsContext::SetFPR(uint32_t reg, uintptr_t value) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020078 CHECK_LT(reg, static_cast<uint32_t>(kNumberOfFRegisters));
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010079 DCHECK(IsAccessibleFPR(reg));
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020080 CHECK_NE(fprs_[reg], &gZero); // Can't overwrite this static value since they are never reset.
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010081 *fprs_[reg] = value;
Mathieu Chartier67022432012-11-29 18:04:50 -080082}
83
jeffhao7fbee072012-08-24 17:56:54 -070084void MipsContext::SmashCallerSaves() {
Mathieu Chartier67022432012-11-29 18:04:50 -080085 // This needs to be 0 because we want a null/zero return value.
86 gprs_[V0] = const_cast<uint32_t*>(&gZero);
87 gprs_[V1] = const_cast<uint32_t*>(&gZero);
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020088 gprs_[A1] = nullptr;
89 gprs_[A2] = nullptr;
90 gprs_[A3] = nullptr;
jeffhao7fbee072012-08-24 17:56:54 -070091}
92
Andreas Gampe794ad762015-02-23 08:12:24 -080093extern "C" NO_RETURN void art_quick_do_long_jump(uint32_t*, uint32_t*);
jeffhao7fbee072012-08-24 17:56:54 -070094
95void MipsContext::DoLongJump() {
Mathieu Chartier67022432012-11-29 18:04:50 -080096 uintptr_t gprs[kNumberOfCoreRegisters];
97 uint32_t fprs[kNumberOfFRegisters];
98 for (size_t i = 0; i < kNumberOfCoreRegisters; ++i) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020099 gprs[i] = gprs_[i] != nullptr ? *gprs_[i] : MipsContext::kBadGprBase + i;
Mathieu Chartier67022432012-11-29 18:04:50 -0800100 }
101 for (size_t i = 0; i < kNumberOfFRegisters; ++i) {
Sebastien Hertz0bcb2902014-06-17 15:52:45 +0200102 fprs[i] = fprs_[i] != nullptr ? *fprs_[i] : MipsContext::kBadGprBase + i;
Mathieu Chartier67022432012-11-29 18:04:50 -0800103 }
Logan Chien8dbb7082013-01-25 20:31:17 +0800104 art_quick_do_long_jump(gprs, fprs);
jeffhao7fbee072012-08-24 17:56:54 -0700105}
106
107} // namespace mips
108} // namespace art