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 - pointsize). 33 (1 << art::arm64::LR); 34 // Callee saved registers 35 static constexpr uint32_t kArm64CalleeSaveRefSpills = 36 (1 << art::arm64::X19) | (1 << art::arm64::X20) | (1 << art::arm64::X21) | 37 (1 << art::arm64::X22) | (1 << art::arm64::X23) | (1 << art::arm64::X24) | 38 (1 << art::arm64::X25) | (1 << art::arm64::X26) | (1 << art::arm64::X27) | 39 (1 << art::arm64::X28) | (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 // Thread register. 47 (1 << art::arm64::X18); 48 49 static constexpr uint32_t kArm64CalleeSaveFpAlwaysSpills = 0; 50 static constexpr uint32_t kArm64CalleeSaveFpRefSpills = 0; 51 static constexpr uint32_t kArm64CalleeSaveFpArgSpills = 52 (1 << art::arm64::D0) | (1 << art::arm64::D1) | (1 << art::arm64::D2) | 53 (1 << art::arm64::D3) | (1 << art::arm64::D4) | (1 << art::arm64::D5) | 54 (1 << art::arm64::D6) | (1 << art::arm64::D7); 55 static constexpr uint32_t kArm64CalleeSaveFpAllSpills = 56 (1 << art::arm64::D8) | (1 << art::arm64::D9) | (1 << art::arm64::D10) | 57 (1 << art::arm64::D11) | (1 << art::arm64::D12) | (1 << art::arm64::D13) | 58 (1 << art::arm64::D14) | (1 << art::arm64::D15); 59 Arm64CalleeSaveCoreSpills(Runtime::CalleeSaveType type)60constexpr uint32_t Arm64CalleeSaveCoreSpills(Runtime::CalleeSaveType type) { 61 return kArm64CalleeSaveAlwaysSpills | kArm64CalleeSaveRefSpills | 62 (type == Runtime::kRefsAndArgs ? kArm64CalleeSaveArgSpills : 0) | 63 (type == Runtime::kSaveAll ? kArm64CalleeSaveAllSpills : 0); 64 } 65 Arm64CalleeSaveFpSpills(Runtime::CalleeSaveType type)66constexpr uint32_t Arm64CalleeSaveFpSpills(Runtime::CalleeSaveType type) { 67 return kArm64CalleeSaveFpAlwaysSpills | kArm64CalleeSaveFpRefSpills | 68 (type == Runtime::kRefsAndArgs ? kArm64CalleeSaveFpArgSpills: 0) | 69 (type == Runtime::kSaveAll ? kArm64CalleeSaveFpAllSpills : 0); 70 } 71 Arm64CalleeSaveFrameSize(Runtime::CalleeSaveType type)72constexpr uint32_t Arm64CalleeSaveFrameSize(Runtime::CalleeSaveType type) { 73 return RoundUp((POPCOUNT(Arm64CalleeSaveCoreSpills(type)) /* gprs */ + 74 POPCOUNT(Arm64CalleeSaveFpSpills(type)) /* fprs */ + 75 1 /* Method* */) * kArm64PointerSize, kStackAlignment); 76 } 77 Arm64CalleeSaveMethodFrameInfo(Runtime::CalleeSaveType type)78constexpr QuickMethodFrameInfo Arm64CalleeSaveMethodFrameInfo(Runtime::CalleeSaveType type) { 79 return QuickMethodFrameInfo(Arm64CalleeSaveFrameSize(type), 80 Arm64CalleeSaveCoreSpills(type), 81 Arm64CalleeSaveFpSpills(type)); 82 } 83 Arm64CalleeSaveFpr1Offset(Runtime::CalleeSaveType type)84constexpr size_t Arm64CalleeSaveFpr1Offset(Runtime::CalleeSaveType type) { 85 return Arm64CalleeSaveFrameSize(type) - 86 (POPCOUNT(Arm64CalleeSaveCoreSpills(type)) + 87 POPCOUNT(Arm64CalleeSaveFpSpills(type))) * kArm64PointerSize; 88 } 89 Arm64CalleeSaveGpr1Offset(Runtime::CalleeSaveType type)90constexpr size_t Arm64CalleeSaveGpr1Offset(Runtime::CalleeSaveType type) { 91 return Arm64CalleeSaveFrameSize(type) - 92 POPCOUNT(Arm64CalleeSaveCoreSpills(type)) * kArm64PointerSize; 93 } 94 Arm64CalleeSaveLrOffset(Runtime::CalleeSaveType type)95constexpr size_t Arm64CalleeSaveLrOffset(Runtime::CalleeSaveType type) { 96 return Arm64CalleeSaveFrameSize(type) - 97 POPCOUNT(Arm64CalleeSaveCoreSpills(type) & (-(1 << LR))) * kArm64PointerSize; 98 } 99 100 } // namespace arm64 101 } // namespace art 102 103 #endif // ART_RUNTIME_ARCH_ARM64_QUICK_METHOD_FRAME_INFO_ARM64_H_ 104