1 /*
2  * Copyright (C) 2011 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_COMPILER_JNI_QUICK_X86_CALLING_CONVENTION_X86_H_
18 #define ART_COMPILER_JNI_QUICK_X86_CALLING_CONVENTION_X86_H_
19 
20 #include "base/enums.h"
21 #include "jni/quick/calling_convention.h"
22 
23 namespace art {
24 namespace x86 {
25 
26 constexpr size_t kFramePointerSize = static_cast<size_t>(PointerSize::k32);
27 
28 class X86ManagedRuntimeCallingConvention FINAL : public ManagedRuntimeCallingConvention {
29  public:
X86ManagedRuntimeCallingConvention(bool is_static,bool is_synchronized,const char * shorty)30   X86ManagedRuntimeCallingConvention(bool is_static, bool is_synchronized, const char* shorty)
31       : ManagedRuntimeCallingConvention(is_static,
32                                         is_synchronized,
33                                         shorty,
34                                         PointerSize::k32),
35         gpr_arg_count_(0) {}
~X86ManagedRuntimeCallingConvention()36   ~X86ManagedRuntimeCallingConvention() OVERRIDE {}
37   // Calling convention
38   ManagedRegister ReturnRegister() OVERRIDE;
39   ManagedRegister InterproceduralScratchRegister() OVERRIDE;
40   // Managed runtime calling convention
41   ManagedRegister MethodRegister() OVERRIDE;
42   bool IsCurrentParamInRegister() OVERRIDE;
43   bool IsCurrentParamOnStack() OVERRIDE;
44   ManagedRegister CurrentParamRegister() OVERRIDE;
45   FrameOffset CurrentParamStackOffset() OVERRIDE;
46   const ManagedRegisterEntrySpills& EntrySpills() OVERRIDE;
47 
48  private:
49   int gpr_arg_count_;
50   ManagedRegister CurrentParamHighLongRegister();
51   ManagedRegisterEntrySpills entry_spills_;
52   DISALLOW_COPY_AND_ASSIGN(X86ManagedRuntimeCallingConvention);
53 };
54 
55 // Implements the x86 cdecl calling convention.
56 class X86JniCallingConvention FINAL : public JniCallingConvention {
57  public:
58   X86JniCallingConvention(bool is_static,
59                           bool is_synchronized,
60                           bool is_critical_native,
61                           const char* shorty);
~X86JniCallingConvention()62   ~X86JniCallingConvention() OVERRIDE {}
63   // Calling convention
64   ManagedRegister ReturnRegister() OVERRIDE;
65   ManagedRegister IntReturnRegister() OVERRIDE;
66   ManagedRegister InterproceduralScratchRegister() OVERRIDE;
67   // JNI calling convention
68   size_t FrameSize() OVERRIDE;
69   size_t OutArgSize() OVERRIDE;
70   ArrayRef<const ManagedRegister> CalleeSaveRegisters() const OVERRIDE;
71   ManagedRegister ReturnScratchRegister() const OVERRIDE;
72   uint32_t CoreSpillMask() const OVERRIDE;
73   uint32_t FpSpillMask() const OVERRIDE;
74   bool IsCurrentParamInRegister() OVERRIDE;
75   bool IsCurrentParamOnStack() OVERRIDE;
76   ManagedRegister CurrentParamRegister() OVERRIDE;
77   FrameOffset CurrentParamStackOffset() OVERRIDE;
78 
79   // x86 needs to extend small return types.
RequiresSmallResultTypeExtension()80   bool RequiresSmallResultTypeExtension() const OVERRIDE {
81     return true;
82   }
83 
84  protected:
85   size_t NumberOfOutgoingStackArgs() OVERRIDE;
86 
87  private:
88   DISALLOW_COPY_AND_ASSIGN(X86JniCallingConvention);
89 };
90 
91 }  // namespace x86
92 }  // namespace art
93 
94 #endif  // ART_COMPILER_JNI_QUICK_X86_CALLING_CONVENTION_X86_H_
95