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_ARM_CALLEE_SAVE_FRAME_ARM_H_ 18 #define ART_RUNTIME_ARCH_ARM_CALLEE_SAVE_FRAME_ARM_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_arm.h" 26 #include "runtime_globals.h" 27 28 namespace art { 29 namespace arm { 30 31 static constexpr uint32_t kArmCalleeSaveAlwaysSpills = 32 (1 << art::arm::LR); 33 static constexpr uint32_t kArmCalleeSaveRefSpills = 34 (1 << art::arm::R5) | (1 << art::arm::R6) | (1 << art::arm::R7) | (1 << art::arm::R8) | 35 (1 << art::arm::R10) | (1 << art::arm::R11); 36 static constexpr uint32_t kArmCalleeSaveArgSpills = 37 (1 << art::arm::R1) | (1 << art::arm::R2) | (1 << art::arm::R3); 38 static constexpr uint32_t kArmCalleeSaveAllSpills = 39 (1 << art::arm::R4) | (1 << art::arm::R9); 40 static constexpr uint32_t kArmCalleeSaveEverythingSpills = 41 (1 << art::arm::R0) | (1 << art::arm::R1) | (1 << art::arm::R2) | (1 << art::arm::R3) | 42 (1 << art::arm::R4) | (1 << art::arm::R9) | (1 << art::arm::R12); 43 44 static constexpr uint32_t kArmCalleeSaveFpAlwaysSpills = 0; 45 static constexpr uint32_t kArmCalleeSaveFpRefSpills = 0; 46 static constexpr uint32_t kArmCalleeSaveFpArgSpills = 47 (1 << art::arm::S0) | (1 << art::arm::S1) | (1 << art::arm::S2) | (1 << art::arm::S3) | 48 (1 << art::arm::S4) | (1 << art::arm::S5) | (1 << art::arm::S6) | (1 << art::arm::S7) | 49 (1 << art::arm::S8) | (1 << art::arm::S9) | (1 << art::arm::S10) | (1 << art::arm::S11) | 50 (1 << art::arm::S12) | (1 << art::arm::S13) | (1 << art::arm::S14) | (1 << art::arm::S15); 51 static constexpr uint32_t kArmCalleeSaveFpAllSpills = 52 (1 << art::arm::S16) | (1 << art::arm::S17) | (1 << art::arm::S18) | (1 << art::arm::S19) | 53 (1 << art::arm::S20) | (1 << art::arm::S21) | (1 << art::arm::S22) | (1 << art::arm::S23) | 54 (1 << art::arm::S24) | (1 << art::arm::S25) | (1 << art::arm::S26) | (1 << art::arm::S27) | 55 (1 << art::arm::S28) | (1 << art::arm::S29) | (1 << art::arm::S30) | (1 << art::arm::S31); 56 static constexpr uint32_t kArmCalleeSaveFpEverythingSpills = 57 kArmCalleeSaveFpArgSpills | kArmCalleeSaveFpAllSpills; 58 59 class ArmCalleeSaveFrame { 60 public: GetCoreSpills(CalleeSaveType type)61 static constexpr uint32_t GetCoreSpills(CalleeSaveType type) { 62 type = GetCanonicalCalleeSaveType(type); 63 return kArmCalleeSaveAlwaysSpills | kArmCalleeSaveRefSpills | 64 (type == CalleeSaveType::kSaveRefsAndArgs ? kArmCalleeSaveArgSpills : 0) | 65 (type == CalleeSaveType::kSaveAllCalleeSaves ? kArmCalleeSaveAllSpills : 0) | 66 (type == CalleeSaveType::kSaveEverything ? kArmCalleeSaveEverythingSpills : 0); 67 } 68 GetFpSpills(CalleeSaveType type)69 static constexpr uint32_t GetFpSpills(CalleeSaveType type) { 70 type = GetCanonicalCalleeSaveType(type); 71 return kArmCalleeSaveFpAlwaysSpills | kArmCalleeSaveFpRefSpills | 72 (type == CalleeSaveType::kSaveRefsAndArgs ? kArmCalleeSaveFpArgSpills : 0) | 73 (type == CalleeSaveType::kSaveAllCalleeSaves ? kArmCalleeSaveFpAllSpills : 0) | 74 (type == CalleeSaveType::kSaveEverything ? kArmCalleeSaveFpEverythingSpills : 0); 75 } 76 GetFrameSize(CalleeSaveType type)77 static constexpr uint32_t GetFrameSize(CalleeSaveType type) { 78 type = GetCanonicalCalleeSaveType(type); 79 return RoundUp((POPCOUNT(GetCoreSpills(type)) /* gprs */ + 80 POPCOUNT(GetFpSpills(type)) /* fprs */ + 81 1 /* Method* */) * static_cast<size_t>(kArmPointerSize), kStackAlignment); 82 } 83 GetMethodFrameInfo(CalleeSaveType type)84 static constexpr QuickMethodFrameInfo GetMethodFrameInfo(CalleeSaveType type) { 85 type = GetCanonicalCalleeSaveType(type); 86 return QuickMethodFrameInfo(GetFrameSize(type), GetCoreSpills(type), GetFpSpills(type)); 87 } 88 GetFpr1Offset(CalleeSaveType type)89 static constexpr size_t GetFpr1Offset(CalleeSaveType type) { 90 type = GetCanonicalCalleeSaveType(type); 91 return GetFrameSize(type) - 92 (POPCOUNT(GetCoreSpills(type)) + 93 POPCOUNT(GetFpSpills(type))) * static_cast<size_t>(kArmPointerSize); 94 } 95 GetGpr1Offset(CalleeSaveType type)96 static constexpr size_t GetGpr1Offset(CalleeSaveType type) { 97 type = GetCanonicalCalleeSaveType(type); 98 return GetFrameSize(type) - 99 POPCOUNT(GetCoreSpills(type)) * static_cast<size_t>(kArmPointerSize); 100 } 101 GetReturnPcOffset(CalleeSaveType type)102 static constexpr size_t GetReturnPcOffset(CalleeSaveType type) { 103 type = GetCanonicalCalleeSaveType(type); 104 return GetFrameSize(type) - static_cast<size_t>(kArmPointerSize); 105 } 106 }; 107 108 } // namespace arm 109 } // namespace art 110 111 #endif // ART_RUNTIME_ARCH_ARM_CALLEE_SAVE_FRAME_ARM_H_ 112