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