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_X86_64_CALLEE_SAVE_FRAME_X86_64_H_ 18 #define ART_RUNTIME_ARCH_X86_64_CALLEE_SAVE_FRAME_X86_64_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_x86_64.h" 27 #include "runtime_globals.h" 28 29 namespace art HIDDEN { 30 namespace x86_64 { 31 32 static constexpr uint32_t kX86_64CalleeSaveAlwaysSpills = 33 (1 << art::x86_64::kNumberOfCpuRegisters); // Fake return address callee save. 34 static constexpr uint32_t kX86_64CalleeSaveRefSpills = 35 (1 << art::x86_64::RBX) | (1 << art::x86_64::RBP) | (1 << art::x86_64::R12) | 36 (1 << art::x86_64::R13) | (1 << art::x86_64::R14) | (1 << art::x86_64::R15); 37 static constexpr uint32_t kX86_64CalleeSaveArgSpills = 38 (1 << art::x86_64::RSI) | (1 << art::x86_64::RDX) | (1 << art::x86_64::RCX) | 39 (1 << art::x86_64::R8) | (1 << art::x86_64::R9); 40 static constexpr uint32_t kX86_64CalleeSaveEverythingSpills = 41 (1 << art::x86_64::RAX) | (1 << art::x86_64::RCX) | (1 << art::x86_64::RDX) | 42 (1 << art::x86_64::RSI) | (1 << art::x86_64::RDI) | (1 << art::x86_64::R8) | 43 (1 << art::x86_64::R9) | (1 << art::x86_64::R10) | (1 << art::x86_64::R11); 44 45 static constexpr uint32_t kX86_64CalleeSaveFpArgSpills = 46 (1 << art::x86_64::XMM0) | (1 << art::x86_64::XMM1) | (1 << art::x86_64::XMM2) | 47 (1 << art::x86_64::XMM3) | (1 << art::x86_64::XMM4) | (1 << art::x86_64::XMM5) | 48 (1 << art::x86_64::XMM6) | (1 << art::x86_64::XMM7); 49 static constexpr uint32_t kX86_64CalleeSaveFpSpills = 50 (1 << art::x86_64::XMM12) | (1 << art::x86_64::XMM13) | 51 (1 << art::x86_64::XMM14) | (1 << art::x86_64::XMM15); 52 static constexpr uint32_t kX86_64CalleeSaveFpEverythingSpills = 53 (1 << art::x86_64::XMM0) | (1 << art::x86_64::XMM1) | 54 (1 << art::x86_64::XMM2) | (1 << art::x86_64::XMM3) | 55 (1 << art::x86_64::XMM4) | (1 << art::x86_64::XMM5) | 56 (1 << art::x86_64::XMM6) | (1 << art::x86_64::XMM7) | 57 (1 << art::x86_64::XMM8) | (1 << art::x86_64::XMM9) | 58 (1 << art::x86_64::XMM10) | (1 << art::x86_64::XMM11); 59 60 class X86_64CalleeSaveFrame { 61 public: GetCoreSpills(CalleeSaveType type)62 static constexpr uint32_t GetCoreSpills(CalleeSaveType type) { 63 type = GetCanonicalCalleeSaveType(type); 64 return kX86_64CalleeSaveAlwaysSpills | kX86_64CalleeSaveRefSpills | 65 (type == CalleeSaveType::kSaveRefsAndArgs ? kX86_64CalleeSaveArgSpills : 0) | 66 (type == CalleeSaveType::kSaveEverything ? kX86_64CalleeSaveEverythingSpills : 0); 67 } 68 GetFpSpills(CalleeSaveType type)69 static constexpr uint32_t GetFpSpills(CalleeSaveType type) { 70 type = GetCanonicalCalleeSaveType(type); 71 return kX86_64CalleeSaveFpSpills | 72 (type == CalleeSaveType::kSaveRefsAndArgs ? kX86_64CalleeSaveFpArgSpills : 0) | 73 (type == CalleeSaveType::kSaveEverything ? kX86_64CalleeSaveFpEverythingSpills : 0); 74 } 75 GetFrameSize(CalleeSaveType type)76 static constexpr uint32_t GetFrameSize(CalleeSaveType type) { 77 type = GetCanonicalCalleeSaveType(type); 78 return RoundUp((POPCOUNT(GetCoreSpills(type)) /* gprs */ + 79 POPCOUNT(GetFpSpills(type)) /* fprs */ + 80 1 /* Method* */) * static_cast<size_t>(kX86_64PointerSize), kStackAlignment); 81 } 82 GetMethodFrameInfo(CalleeSaveType type)83 static constexpr QuickMethodFrameInfo GetMethodFrameInfo(CalleeSaveType type) { 84 type = GetCanonicalCalleeSaveType(type); 85 return QuickMethodFrameInfo(GetFrameSize(type), GetCoreSpills(type), GetFpSpills(type)); 86 } 87 GetFpr1Offset(CalleeSaveType type)88 static constexpr size_t GetFpr1Offset(CalleeSaveType type) { 89 type = GetCanonicalCalleeSaveType(type); 90 return GetFrameSize(type) - 91 (POPCOUNT(GetCoreSpills(type)) + 92 POPCOUNT(GetFpSpills(type))) * static_cast<size_t>(kX86_64PointerSize); 93 } 94 GetGpr1Offset(CalleeSaveType type)95 static constexpr size_t GetGpr1Offset(CalleeSaveType type) { 96 type = GetCanonicalCalleeSaveType(type); 97 return GetFrameSize(type) - 98 POPCOUNT(GetCoreSpills(type)) * static_cast<size_t>(kX86_64PointerSize); 99 } 100 GetReturnPcOffset(CalleeSaveType type)101 static constexpr size_t GetReturnPcOffset(CalleeSaveType type) { 102 type = GetCanonicalCalleeSaveType(type); 103 return GetFrameSize(type) - static_cast<size_t>(kX86_64PointerSize); 104 } 105 }; 106 107 } // namespace x86_64 108 } // namespace art 109 110 #endif // ART_RUNTIME_ARCH_X86_64_CALLEE_SAVE_FRAME_X86_64_H_ 111