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_ARM64_QUICK_METHOD_FRAME_INFO_ARM64_H_ 18 #define ART_RUNTIME_ARCH_ARM64_QUICK_METHOD_FRAME_INFO_ARM64_H_ 19 20 #include "base/bit_utils.h" 21 #include "quick/quick_method_frame_info.h" 22 #include "registers_arm64.h" 23 #include "runtime.h" // for Runtime::CalleeSaveType. 24 25 namespace art { 26 namespace arm64 { 27 28 // Registers need to be restored but not preserved by aapcs64. 29 static constexpr uint32_t kArm64CalleeSaveAlwaysSpills = 30 // Note: ArtMethod::GetReturnPcOffsetInBytes() rely on the assumption that 31 // LR is always saved on the top of the frame for all targets. 32 // That is, lr = *(sp + framesize - pointer_size). 33 (1 << art::arm64::LR); 34 // Callee saved registers 35 static constexpr uint32_t kArm64CalleeSaveRefSpills = 36 (1 << art::arm64::X20) | (1 << art::arm64::X21) | (1 << art::arm64::X22) | 37 (1 << art::arm64::X23) | (1 << art::arm64::X24) | (1 << art::arm64::X25) | 38 (1 << art::arm64::X26) | (1 << art::arm64::X27) | (1 << art::arm64::X28) | 39 (1 << art::arm64::X29); 40 // X0 is the method pointer. Not saved. 41 static constexpr uint32_t kArm64CalleeSaveArgSpills = 42 (1 << art::arm64::X1) | (1 << art::arm64::X2) | (1 << art::arm64::X3) | 43 (1 << art::arm64::X4) | (1 << art::arm64::X5) | (1 << art::arm64::X6) | 44 (1 << art::arm64::X7); 45 static constexpr uint32_t kArm64CalleeSaveAllSpills = 46 (1 << art::arm64::X19); 47 static constexpr uint32_t kArm64CalleeSaveEverythingSpills = 48 (1 << art::arm64::X0) | (1 << art::arm64::X1) | (1 << art::arm64::X2) | 49 (1 << art::arm64::X3) | (1 << art::arm64::X4) | (1 << art::arm64::X5) | 50 (1 << art::arm64::X6) | (1 << art::arm64::X7) | (1 << art::arm64::X8) | 51 (1 << art::arm64::X9) | (1 << art::arm64::X10) | (1 << art::arm64::X11) | 52 (1 << art::arm64::X12) | (1 << art::arm64::X13) | (1 << art::arm64::X14) | 53 (1 << art::arm64::X15) | (1 << art::arm64::X16) | (1 << art::arm64::X17) | 54 (1 << art::arm64::X18) | (1 << art::arm64::X19); 55 56 static constexpr uint32_t kArm64CalleeSaveFpAlwaysSpills = 0; 57 static constexpr uint32_t kArm64CalleeSaveFpRefSpills = 0; 58 static constexpr uint32_t kArm64CalleeSaveFpArgSpills = 59 (1 << art::arm64::D0) | (1 << art::arm64::D1) | (1 << art::arm64::D2) | 60 (1 << art::arm64::D3) | (1 << art::arm64::D4) | (1 << art::arm64::D5) | 61 (1 << art::arm64::D6) | (1 << art::arm64::D7); 62 static constexpr uint32_t kArm64CalleeSaveFpAllSpills = 63 (1 << art::arm64::D8) | (1 << art::arm64::D9) | (1 << art::arm64::D10) | 64 (1 << art::arm64::D11) | (1 << art::arm64::D12) | (1 << art::arm64::D13) | 65 (1 << art::arm64::D14) | (1 << art::arm64::D15); 66 static constexpr uint32_t kArm64CalleeSaveFpEverythingSpills = 67 (1 << art::arm64::D0) | (1 << art::arm64::D1) | (1 << art::arm64::D2) | 68 (1 << art::arm64::D3) | (1 << art::arm64::D4) | (1 << art::arm64::D5) | 69 (1 << art::arm64::D6) | (1 << art::arm64::D7) | (1 << art::arm64::D8) | 70 (1 << art::arm64::D9) | (1 << art::arm64::D10) | (1 << art::arm64::D11) | 71 (1 << art::arm64::D12) | (1 << art::arm64::D13) | (1 << art::arm64::D14) | 72 (1 << art::arm64::D15) | (1 << art::arm64::D16) | (1 << art::arm64::D17) | 73 (1 << art::arm64::D18) | (1 << art::arm64::D19) | (1 << art::arm64::D20) | 74 (1 << art::arm64::D21) | (1 << art::arm64::D22) | (1 << art::arm64::D23) | 75 (1 << art::arm64::D24) | (1 << art::arm64::D25) | (1 << art::arm64::D26) | 76 (1 << art::arm64::D27) | (1 << art::arm64::D28) | (1 << art::arm64::D29) | 77 (1 << art::arm64::D30) | (1 << art::arm64::D31); 78 79 constexpr uint32_t Arm64CalleeSaveCoreSpills(Runtime::CalleeSaveType type) { 80 return kArm64CalleeSaveAlwaysSpills | kArm64CalleeSaveRefSpills | 81 (type == Runtime::kSaveRefsAndArgs ? kArm64CalleeSaveArgSpills : 0) | 82 (type == Runtime::kSaveAllCalleeSaves ? kArm64CalleeSaveAllSpills : 0) | 83 (type == Runtime::kSaveEverything ? kArm64CalleeSaveEverythingSpills : 0); 84 } 85 86 constexpr uint32_t Arm64CalleeSaveFpSpills(Runtime::CalleeSaveType type) { 87 return kArm64CalleeSaveFpAlwaysSpills | kArm64CalleeSaveFpRefSpills | 88 (type == Runtime::kSaveRefsAndArgs ? kArm64CalleeSaveFpArgSpills : 0) | 89 (type == Runtime::kSaveAllCalleeSaves ? kArm64CalleeSaveFpAllSpills : 0) | 90 (type == Runtime::kSaveEverything ? kArm64CalleeSaveFpEverythingSpills : 0); 91 } 92 93 constexpr uint32_t Arm64CalleeSaveFrameSize(Runtime::CalleeSaveType type) { 94 return RoundUp((POPCOUNT(Arm64CalleeSaveCoreSpills(type)) /* gprs */ + 95 POPCOUNT(Arm64CalleeSaveFpSpills(type)) /* fprs */ + 96 1 /* Method* */) * static_cast<size_t>(kArm64PointerSize), kStackAlignment); 97 } 98 99 constexpr QuickMethodFrameInfo Arm64CalleeSaveMethodFrameInfo(Runtime::CalleeSaveType type) { 100 return QuickMethodFrameInfo(Arm64CalleeSaveFrameSize(type), 101 Arm64CalleeSaveCoreSpills(type), 102 Arm64CalleeSaveFpSpills(type)); 103 } 104 105 constexpr size_t Arm64CalleeSaveFpr1Offset(Runtime::CalleeSaveType type) { 106 return Arm64CalleeSaveFrameSize(type) - 107 (POPCOUNT(Arm64CalleeSaveCoreSpills(type)) + 108 POPCOUNT(Arm64CalleeSaveFpSpills(type))) * static_cast<size_t>(kArm64PointerSize); 109 } 110 111 constexpr size_t Arm64CalleeSaveGpr1Offset(Runtime::CalleeSaveType type) { 112 return Arm64CalleeSaveFrameSize(type) - 113 POPCOUNT(Arm64CalleeSaveCoreSpills(type)) * static_cast<size_t>(kArm64PointerSize); 114 } 115 116 constexpr size_t Arm64CalleeSaveLrOffset(Runtime::CalleeSaveType type) { 117 return Arm64CalleeSaveFrameSize(type) - 118 POPCOUNT(Arm64CalleeSaveCoreSpills(type) & (-(1 << LR))) * 119 static_cast<size_t>(kArm64PointerSize); 120 } 121 122 } // namespace arm64 123 } // namespace art 124 125 #endif // ART_RUNTIME_ARCH_ARM64_QUICK_METHOD_FRAME_INFO_ARM64_H_ 126