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_MIPS_QUICK_METHOD_FRAME_INFO_MIPS_H_
18 #define ART_RUNTIME_ARCH_MIPS_QUICK_METHOD_FRAME_INFO_MIPS_H_
19 
20 #include "base/bit_utils.h"
21 #include "quick/quick_method_frame_info.h"
22 #include "registers_mips.h"
23 #include "runtime.h"  // for Runtime::CalleeSaveType.
24 
25 namespace art {
26 namespace mips {
27 
28 static constexpr uint32_t kMipsCalleeSaveRefSpills =
29     (1 << art::mips::S2) | (1 << art::mips::S3) | (1 << art::mips::S4) | (1 << art::mips::S5) |
30     (1 << art::mips::S6) | (1 << art::mips::S7) | (1 << art::mips::GP) | (1 << art::mips::FP);
31 static constexpr uint32_t kMipsCalleeSaveArgSpills =
32     (1 << art::mips::A1) | (1 << art::mips::A2) | (1 << art::mips::A3);
33 static constexpr uint32_t kMipsCalleeSaveAllSpills =
34     (1 << art::mips::S0) | (1 << art::mips::S1);
35 static constexpr uint32_t kMipsCalleeSaveAllFPSpills =
36     (1 << art::mips::F20) | (1 << art::mips::F21) | (1 << art::mips::F22) | (1 << art::mips::F23) |
37     (1 << art::mips::F24) | (1 << art::mips::F25) | (1 << art::mips::F26) | (1 << art::mips::F27) |
38     (1 << art::mips::F28) | (1 << art::mips::F29) | (1 << art::mips::F30) | (1 << art::mips::F31);
39 
MipsCalleeSaveCoreSpills(Runtime::CalleeSaveType type)40 constexpr uint32_t MipsCalleeSaveCoreSpills(Runtime::CalleeSaveType type) {
41   return kMipsCalleeSaveRefSpills |
42       (type == Runtime::kRefsAndArgs ? kMipsCalleeSaveArgSpills : 0) |
43       (type == Runtime::kSaveAll ? kMipsCalleeSaveAllSpills : 0) | (1 << art::mips::RA);
44 }
45 
MipsCalleeSaveFPSpills(Runtime::CalleeSaveType type)46 constexpr uint32_t MipsCalleeSaveFPSpills(Runtime::CalleeSaveType type) {
47   return type == Runtime::kSaveAll ? kMipsCalleeSaveAllFPSpills : 0;
48 }
49 
MipsCalleeSaveFrameSize(Runtime::CalleeSaveType type)50 constexpr uint32_t MipsCalleeSaveFrameSize(Runtime::CalleeSaveType type) {
51   return RoundUp((POPCOUNT(MipsCalleeSaveCoreSpills(type)) /* gprs */ +
52                   POPCOUNT(MipsCalleeSaveFPSpills(type))   /* fprs */ +
53                   1 /* Method* */) * kMipsPointerSize, kStackAlignment);
54 }
55 
MipsCalleeSaveMethodFrameInfo(Runtime::CalleeSaveType type)56 constexpr QuickMethodFrameInfo MipsCalleeSaveMethodFrameInfo(Runtime::CalleeSaveType type) {
57   return QuickMethodFrameInfo(MipsCalleeSaveFrameSize(type),
58                               MipsCalleeSaveCoreSpills(type),
59                               MipsCalleeSaveFPSpills(type));
60 }
61 
62 }  // namespace mips
63 }  // namespace art
64 
65 #endif  // ART_RUNTIME_ARCH_MIPS_QUICK_METHOD_FRAME_INFO_MIPS_H_
66