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