blob: ad2889135aa9cf271609262625d16702455c1bf8 [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"
Ian Rogers8e26b312013-03-18 18:48:21 -070020#include "mirror/object-inl.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010021#include "quick/quick_method_frame_info.h"
Brian Carlstrom4a4552d2013-02-10 20:41:26 -080022#include "stack.h"
jeffhao7fbee072012-08-24 17:56:54 -070023
24namespace art {
25namespace mips {
26
Mathieu Chartier67022432012-11-29 18:04:50 -080027static const uint32_t gZero = 0;
28
29void MipsContext::Reset() {
30 for (size_t i = 0; i < kNumberOfCoreRegisters; i++) {
31 gprs_[i] = NULL;
32 }
33 for (size_t i = 0; i < kNumberOfFRegisters; i++) {
34 fprs_[i] = NULL;
35 }
36 gprs_[SP] = &sp_;
37 gprs_[RA] = &ra_;
jeffhao7fbee072012-08-24 17:56:54 -070038 // Initialize registers with easy to spot debug values.
Mathieu Chartier67022432012-11-29 18:04:50 -080039 sp_ = MipsContext::kBadGprBase + SP;
40 ra_ = MipsContext::kBadGprBase + RA;
jeffhao7fbee072012-08-24 17:56:54 -070041}
42
43void MipsContext::FillCalleeSaves(const StackVisitor& fr) {
Brian Carlstromea46f952013-07-30 01:26:50 -070044 mirror::ArtMethod* method = fr.GetMethod();
Vladimir Marko7624d252014-05-02 14:40:15 +010045 const QuickMethodFrameInfo frame_info = method->GetQuickFrameInfo();
46 size_t spill_count = POPCOUNT(frame_info.CoreSpillMask());
47 size_t fp_spill_count = POPCOUNT(frame_info.FpSpillMask());
jeffhao7fbee072012-08-24 17:56:54 -070048 if (spill_count > 0) {
Mathieu Chartier67022432012-11-29 18:04:50 -080049 // Lowest number spill is farthest away, walk registers and fill into context.
jeffhao7fbee072012-08-24 17:56:54 -070050 int j = 1;
Mathieu Chartier67022432012-11-29 18:04:50 -080051 for (size_t i = 0; i < kNumberOfCoreRegisters; i++) {
Vladimir Marko7624d252014-05-02 14:40:15 +010052 if (((frame_info.CoreSpillMask() >> i) & 1) != 0) {
53 gprs_[i] = fr.CalleeSaveAddress(spill_count - j, frame_info.FrameSizeInBytes());
jeffhao7fbee072012-08-24 17:56:54 -070054 j++;
55 }
56 }
57 }
58 if (fp_spill_count > 0) {
Mathieu Chartier67022432012-11-29 18:04:50 -080059 // Lowest number spill is farthest away, walk registers and fill into context.
jeffhao7fbee072012-08-24 17:56:54 -070060 int j = 1;
Mathieu Chartier67022432012-11-29 18:04:50 -080061 for (size_t i = 0; i < kNumberOfFRegisters; i++) {
Vladimir Marko7624d252014-05-02 14:40:15 +010062 if (((frame_info.FpSpillMask() >> i) & 1) != 0) {
63 fprs_[i] = fr.CalleeSaveAddress(spill_count + fp_spill_count - j,
64 frame_info.FrameSizeInBytes());
jeffhao7fbee072012-08-24 17:56:54 -070065 j++;
66 }
67 }
68 }
69}
70
Mathieu Chartier67022432012-11-29 18:04:50 -080071void MipsContext::SetGPR(uint32_t reg, uintptr_t value) {
Brian Carlstrom8b1ce162013-03-31 00:17:54 -070072 CHECK_LT(reg, static_cast<uint32_t>(kNumberOfCoreRegisters));
Brian Carlstrom7934ac22013-07-26 10:54:15 -070073 CHECK_NE(gprs_[reg], &gZero); // Can't overwrite this static value since they are never reset.
Mathieu Chartier67022432012-11-29 18:04:50 -080074 CHECK(gprs_[reg] != NULL);
75 *gprs_[reg] = value;
76}
77
jeffhao7fbee072012-08-24 17:56:54 -070078void MipsContext::SmashCallerSaves() {
Mathieu Chartier67022432012-11-29 18:04:50 -080079 // This needs to be 0 because we want a null/zero return value.
80 gprs_[V0] = const_cast<uint32_t*>(&gZero);
81 gprs_[V1] = const_cast<uint32_t*>(&gZero);
82 gprs_[A1] = NULL;
83 gprs_[A2] = NULL;
84 gprs_[A3] = NULL;
jeffhao7fbee072012-08-24 17:56:54 -070085}
86
Logan Chien8dbb7082013-01-25 20:31:17 +080087extern "C" void art_quick_do_long_jump(uint32_t*, uint32_t*);
jeffhao7fbee072012-08-24 17:56:54 -070088
89void MipsContext::DoLongJump() {
Mathieu Chartier67022432012-11-29 18:04:50 -080090 uintptr_t gprs[kNumberOfCoreRegisters];
91 uint32_t fprs[kNumberOfFRegisters];
92 for (size_t i = 0; i < kNumberOfCoreRegisters; ++i) {
93 gprs[i] = gprs_[i] != NULL ? *gprs_[i] : MipsContext::kBadGprBase + i;
94 }
95 for (size_t i = 0; i < kNumberOfFRegisters; ++i) {
96 fprs[i] = fprs_[i] != NULL ? *fprs_[i] : MipsContext::kBadGprBase + i;
97 }
Logan Chien8dbb7082013-01-25 20:31:17 +080098 art_quick_do_long_jump(gprs, fprs);
jeffhao7fbee072012-08-24 17:56:54 -070099}
100
101} // namespace mips
102} // namespace art