blob: ded90854c635bf3fa11d6d87d2c5de416612a9f3 [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
19#include "object.h"
20
21namespace art {
22namespace mips {
23
24MipsContext::MipsContext() {
25#ifndef NDEBUG
26 // Initialize registers with easy to spot debug values.
27 for (int i = 0; i < 32; i++) {
28 gprs_[i] = kBadGprBase + i;
29 }
30 for (int i = 0; i < 32; i++) {
31 fprs_[i] = kBadGprBase + i;
32 }
33 pc_ = 0xEBAD601F;
34#endif
35}
36
37void MipsContext::FillCalleeSaves(const StackVisitor& fr) {
38 Method* method = fr.GetMethod();
39 uint32_t core_spills = method->GetCoreSpillMask();
40 uint32_t fp_core_spills = method->GetFpSpillMask();
41 size_t spill_count = __builtin_popcount(core_spills);
42 size_t fp_spill_count = __builtin_popcount(fp_core_spills);
43 size_t frame_size = method->GetFrameSizeInBytes();
44 if (spill_count > 0) {
45 // Lowest number spill is furthest away, walk registers and fill into context.
46 int j = 1;
47 for (int i = 0; i < 32; i++) {
48 if (((core_spills >> i) & 1) != 0) {
49 gprs_[i] = fr.LoadCalleeSave(spill_count - j, frame_size);
50 j++;
51 }
52 }
53 }
54 if (fp_spill_count > 0) {
55 // Lowest number spill is furthest away, walk registers and fill into context.
56 int j = 1;
57 for (int i = 0; i < 32; i++) {
58 if (((fp_core_spills >> i) & 1) != 0) {
59 fprs_[i] = fr.LoadCalleeSave(spill_count +fp_spill_count - j, frame_size);
60 j++;
61 }
62 }
63 }
64}
65
66void MipsContext::SmashCallerSaves() {
67 gprs_[V0] = 0; // This needs to be 0 because we want a null/zero return value.
68 gprs_[V1] = 0; // This needs to be 0 because we want a null/zero return value.
69 gprs_[A1] = kBadGprBase + A1;
70 gprs_[A2] = kBadGprBase + A2;
71 gprs_[A3] = kBadGprBase + A3;
72 gprs_[RA] = kBadGprBase + RA;
73}
74
75extern "C" void art_do_long_jump(uint32_t*, uint32_t*);
76
77void MipsContext::DoLongJump() {
78 art_do_long_jump(&gprs_[ZERO], &fprs_[F0]);
79}
80
81} // namespace mips
82} // namespace art