blob: bfb3fc65d40d19a55cece41d13e264c84ed96f9f [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
Brian Carlstrom4a4552d2013-02-10 20:41:26 -080019#include "mirror/abstract_method.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080020#include "mirror/object.h"
Brian Carlstrom4a4552d2013-02-10 20:41:26 -080021#include "stack.h"
jeffhao7fbee072012-08-24 17:56:54 -070022
23namespace art {
24namespace mips {
25
Mathieu Chartier67022432012-11-29 18:04:50 -080026static const uint32_t gZero = 0;
27
28void MipsContext::Reset() {
29 for (size_t i = 0; i < kNumberOfCoreRegisters; i++) {
30 gprs_[i] = NULL;
31 }
32 for (size_t i = 0; i < kNumberOfFRegisters; i++) {
33 fprs_[i] = NULL;
34 }
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 Carlstrom4a4552d2013-02-10 20:41:26 -080043 mirror::AbstractMethod* method = fr.GetMethod();
jeffhao7fbee072012-08-24 17:56:54 -070044 uint32_t core_spills = method->GetCoreSpillMask();
45 uint32_t fp_core_spills = method->GetFpSpillMask();
46 size_t spill_count = __builtin_popcount(core_spills);
47 size_t fp_spill_count = __builtin_popcount(fp_core_spills);
48 size_t frame_size = method->GetFrameSizeInBytes();
49 if (spill_count > 0) {
Mathieu Chartier67022432012-11-29 18:04:50 -080050 // Lowest number spill is farthest away, walk registers and fill into context.
jeffhao7fbee072012-08-24 17:56:54 -070051 int j = 1;
Mathieu Chartier67022432012-11-29 18:04:50 -080052 for (size_t i = 0; i < kNumberOfCoreRegisters; i++) {
jeffhao7fbee072012-08-24 17:56:54 -070053 if (((core_spills >> i) & 1) != 0) {
Mathieu Chartier67022432012-11-29 18:04:50 -080054 gprs_[i] = fr.CalleeSaveAddress(spill_count - j, frame_size);
jeffhao7fbee072012-08-24 17:56:54 -070055 j++;
56 }
57 }
58 }
59 if (fp_spill_count > 0) {
Mathieu Chartier67022432012-11-29 18:04:50 -080060 // Lowest number spill is farthest away, walk registers and fill into context.
jeffhao7fbee072012-08-24 17:56:54 -070061 int j = 1;
Mathieu Chartier67022432012-11-29 18:04:50 -080062 for (size_t i = 0; i < kNumberOfFRegisters; i++) {
jeffhao7fbee072012-08-24 17:56:54 -070063 if (((fp_core_spills >> i) & 1) != 0) {
Mathieu Chartier67022432012-11-29 18:04:50 -080064 fprs_[i] = fr.CalleeSaveAddress(spill_count + fp_spill_count - j, frame_size);
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) {
72 CHECK_LT(reg, kNumberOfCoreRegisters);
73 CHECK_NE(gprs_[reg], &gZero); // Can't overwrite this static value since they are never reset.
74 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