1 /* 2 * Copyright (C) 2014 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 #ifndef ART_RUNTIME_ARCH_MIPS64_CALLEE_SAVE_FRAME_MIPS64_H_ 18 #define ART_RUNTIME_ARCH_MIPS64_CALLEE_SAVE_FRAME_MIPS64_H_ 19 20 #include "arch/instruction_set.h" 21 #include "base/bit_utils.h" 22 #include "base/callee_save_type.h" 23 #include "base/enums.h" 24 #include "quick/quick_method_frame_info.h" 25 #include "registers_mips64.h" 26 #include "runtime_globals.h" 27 28 namespace art { 29 namespace mips64 { 30 31 static constexpr uint32_t kMips64CalleeSaveAlwaysSpills = 32 (1 << art::mips64::RA); 33 static constexpr uint32_t kMips64CalleeSaveRefSpills = 34 (1 << art::mips64::S2) | (1 << art::mips64::S3) | (1 << art::mips64::S4) | 35 (1 << art::mips64::S5) | (1 << art::mips64::S6) | (1 << art::mips64::S7) | 36 (1 << art::mips64::GP) | (1 << art::mips64::S8); 37 static constexpr uint32_t kMips64CalleeSaveArgSpills = 38 (1 << art::mips64::A1) | (1 << art::mips64::A2) | (1 << art::mips64::A3) | 39 (1 << art::mips64::A4) | (1 << art::mips64::A5) | (1 << art::mips64::A6) | 40 (1 << art::mips64::A7); 41 static constexpr uint32_t kMips64CalleeSaveAllSpills = 42 (1 << art::mips64::S0) | (1 << art::mips64::S1); 43 static constexpr uint32_t kMips64CalleeSaveEverythingSpills = 44 (1 << art::mips64::AT) | (1 << art::mips64::V0) | (1 << art::mips64::V1) | 45 (1 << art::mips64::A0) | (1 << art::mips64::A1) | (1 << art::mips64::A2) | 46 (1 << art::mips64::A3) | (1 << art::mips64::A4) | (1 << art::mips64::A5) | 47 (1 << art::mips64::A6) | (1 << art::mips64::A7) | (1 << art::mips64::T0) | 48 (1 << art::mips64::T1) | (1 << art::mips64::T2) | (1 << art::mips64::T3) | 49 (1 << art::mips64::S0) | (1 << art::mips64::S1) | (1 << art::mips64::T8) | 50 (1 << art::mips64::T9); 51 52 static constexpr uint32_t kMips64CalleeSaveFpRefSpills = 0; 53 static constexpr uint32_t kMips64CalleeSaveFpArgSpills = 54 (1 << art::mips64::F12) | (1 << art::mips64::F13) | (1 << art::mips64::F14) | 55 (1 << art::mips64::F15) | (1 << art::mips64::F16) | (1 << art::mips64::F17) | 56 (1 << art::mips64::F18) | (1 << art::mips64::F19); 57 // F12 should not be necessary to spill, as A0 is always in use. 58 static constexpr uint32_t kMips64CalleeSaveFpAllSpills = 59 (1 << art::mips64::F24) | (1 << art::mips64::F25) | (1 << art::mips64::F26) | 60 (1 << art::mips64::F27) | (1 << art::mips64::F28) | (1 << art::mips64::F29) | 61 (1 << art::mips64::F30) | (1 << art::mips64::F31); 62 static constexpr uint32_t kMips64CalleeSaveFpEverythingSpills = 63 (1 << art::mips64::F0) | (1 << art::mips64::F1) | (1 << art::mips64::F2) | 64 (1 << art::mips64::F3) | (1 << art::mips64::F4) | (1 << art::mips64::F5) | 65 (1 << art::mips64::F6) | (1 << art::mips64::F7) | (1 << art::mips64::F8) | 66 (1 << art::mips64::F9) | (1 << art::mips64::F10) | (1 << art::mips64::F11) | 67 (1 << art::mips64::F12) | (1 << art::mips64::F13) | (1 << art::mips64::F14) | 68 (1 << art::mips64::F15) | (1 << art::mips64::F16) | (1 << art::mips64::F17) | 69 (1 << art::mips64::F18) | (1 << art::mips64::F19) | (1 << art::mips64::F20) | 70 (1 << art::mips64::F21) | (1 << art::mips64::F22) | (1 << art::mips64::F23) | 71 (1 << art::mips64::F24) | (1 << art::mips64::F25) | (1 << art::mips64::F26) | 72 (1 << art::mips64::F27) | (1 << art::mips64::F28) | (1 << art::mips64::F29) | 73 (1 << art::mips64::F30) | (1 << art::mips64::F31); 74 75 class Mips64CalleeSaveFrame { 76 public: GetCoreSpills(CalleeSaveType type)77 static constexpr uint32_t GetCoreSpills(CalleeSaveType type) { 78 type = GetCanonicalCalleeSaveType(type); 79 return kMips64CalleeSaveAlwaysSpills | kMips64CalleeSaveRefSpills | 80 (type == CalleeSaveType::kSaveRefsAndArgs ? kMips64CalleeSaveArgSpills : 0) | 81 (type == CalleeSaveType::kSaveAllCalleeSaves ? kMips64CalleeSaveAllSpills : 0) | 82 (type == CalleeSaveType::kSaveEverything ? kMips64CalleeSaveEverythingSpills : 0); 83 } 84 GetFpSpills(CalleeSaveType type)85 static constexpr uint32_t GetFpSpills(CalleeSaveType type) { 86 type = GetCanonicalCalleeSaveType(type); 87 return kMips64CalleeSaveFpRefSpills | 88 (type == CalleeSaveType::kSaveRefsAndArgs ? kMips64CalleeSaveFpArgSpills : 0) | 89 (type == CalleeSaveType::kSaveAllCalleeSaves ? kMips64CalleeSaveFpAllSpills : 0) | 90 (type == CalleeSaveType::kSaveEverything ? kMips64CalleeSaveFpEverythingSpills : 0); 91 } 92 GetFrameSize(CalleeSaveType type)93 static constexpr uint32_t GetFrameSize(CalleeSaveType type) { 94 type = GetCanonicalCalleeSaveType(type); 95 return RoundUp((POPCOUNT(GetCoreSpills(type)) /* gprs */ + 96 POPCOUNT(GetFpSpills(type)) /* fprs */ + 97 + 1 /* Method* */) * static_cast<size_t>(kMips64PointerSize), kStackAlignment); 98 } 99 GetMethodFrameInfo(CalleeSaveType type)100 static constexpr QuickMethodFrameInfo GetMethodFrameInfo(CalleeSaveType type) { 101 type = GetCanonicalCalleeSaveType(type); 102 return QuickMethodFrameInfo(GetFrameSize(type), GetCoreSpills(type), GetFpSpills(type)); 103 } 104 GetFpr1Offset(CalleeSaveType type)105 static constexpr size_t GetFpr1Offset(CalleeSaveType type) { 106 type = GetCanonicalCalleeSaveType(type); 107 return GetFrameSize(type) - 108 (POPCOUNT(GetCoreSpills(type)) + 109 POPCOUNT(GetFpSpills(type))) * static_cast<size_t>(kMips64PointerSize); 110 } 111 GetGpr1Offset(CalleeSaveType type)112 static constexpr size_t GetGpr1Offset(CalleeSaveType type) { 113 type = GetCanonicalCalleeSaveType(type); 114 return GetFrameSize(type) - 115 POPCOUNT(GetCoreSpills(type)) * static_cast<size_t>(kMips64PointerSize); 116 } 117 GetReturnPcOffset(CalleeSaveType type)118 static constexpr size_t GetReturnPcOffset(CalleeSaveType type) { 119 type = GetCanonicalCalleeSaveType(type); 120 return GetFrameSize(type) - static_cast<size_t>(kMips64PointerSize); 121 } 122 }; 123 124 } // namespace mips64 125 } // namespace art 126 127 #endif // ART_RUNTIME_ARCH_MIPS64_CALLEE_SAVE_FRAME_MIPS64_H_ 128