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