blob: dc13c635e77dbaa62532e41fae9829e7122b9b2d [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 }
jeffhao7fbee072012-08-24 17:56:54 -070033#endif
34}
35
36void MipsContext::FillCalleeSaves(const StackVisitor& fr) {
Mathieu Chartier66f19252012-09-18 08:57:04 -070037 AbstractMethod* method = fr.GetMethod();
jeffhao7fbee072012-08-24 17:56:54 -070038 uint32_t core_spills = method->GetCoreSpillMask();
39 uint32_t fp_core_spills = method->GetFpSpillMask();
40 size_t spill_count = __builtin_popcount(core_spills);
41 size_t fp_spill_count = __builtin_popcount(fp_core_spills);
42 size_t frame_size = method->GetFrameSizeInBytes();
43 if (spill_count > 0) {
44 // Lowest number spill is furthest away, walk registers and fill into context.
45 int j = 1;
46 for (int i = 0; i < 32; i++) {
47 if (((core_spills >> i) & 1) != 0) {
48 gprs_[i] = fr.LoadCalleeSave(spill_count - j, frame_size);
49 j++;
50 }
51 }
52 }
53 if (fp_spill_count > 0) {
54 // Lowest number spill is furthest away, walk registers and fill into context.
55 int j = 1;
56 for (int i = 0; i < 32; i++) {
57 if (((fp_core_spills >> i) & 1) != 0) {
jeffhao07030602012-09-26 14:33:14 -070058 fprs_[i] = fr.LoadCalleeSave(spill_count + fp_spill_count - j, frame_size);
jeffhao7fbee072012-08-24 17:56:54 -070059 j++;
60 }
61 }
62 }
63}
64
65void MipsContext::SmashCallerSaves() {
66 gprs_[V0] = 0; // This needs to be 0 because we want a null/zero return value.
67 gprs_[V1] = 0; // This needs to be 0 because we want a null/zero return value.
68 gprs_[A1] = kBadGprBase + A1;
69 gprs_[A2] = kBadGprBase + A2;
70 gprs_[A3] = kBadGprBase + A3;
jeffhao7fbee072012-08-24 17:56:54 -070071}
72
73extern "C" void art_do_long_jump(uint32_t*, uint32_t*);
74
75void MipsContext::DoLongJump() {
76 art_do_long_jump(&gprs_[ZERO], &fprs_[F0]);
77}
78
79} // namespace mips
80} // namespace art