1 /*
2  * Copyright (C) 2023 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_RISCV64_CALLING_CONVENTION_RISCV64_H_
18 #define ART_COMPILER_JNI_QUICK_RISCV64_CALLING_CONVENTION_RISCV64_H_
19 
20 #include "base/macros.h"
21 #include "base/pointer_size.h"
22 #include "jni/quick/calling_convention.h"
23 
24 namespace art HIDDEN {
25 namespace riscv64 {
26 
27 class Riscv64ManagedRuntimeCallingConvention final : public ManagedRuntimeCallingConvention {
28  public:
Riscv64ManagedRuntimeCallingConvention(bool is_static,bool is_synchronized,std::string_view shorty)29   Riscv64ManagedRuntimeCallingConvention(
30       bool is_static, bool is_synchronized, std::string_view shorty)
31       : ManagedRuntimeCallingConvention(is_static,
32                                         is_synchronized,
33                                         shorty,
34                                         PointerSize::k64) {}
~Riscv64ManagedRuntimeCallingConvention()35   ~Riscv64ManagedRuntimeCallingConvention() override {}
36   // Calling convention
37   ManagedRegister ReturnRegister() const override;
38   // Managed runtime calling convention
39   ManagedRegister MethodRegister() override;
40   ManagedRegister ArgumentRegisterForMethodExitHook() override;
41   bool IsCurrentParamInRegister() override;
42   bool IsCurrentParamOnStack() override;
43   ManagedRegister CurrentParamRegister() override;
44   FrameOffset CurrentParamStackOffset() override;
45 
46  private:
47   DISALLOW_COPY_AND_ASSIGN(Riscv64ManagedRuntimeCallingConvention);
48 };
49 
50 class Riscv64JniCallingConvention final : public JniCallingConvention {
51  public:
52   Riscv64JniCallingConvention(bool is_static,
53                               bool is_synchronized,
54                               bool is_fast_native,
55                               bool is_critical_native,
56                               std::string_view shorty);
~Riscv64JniCallingConvention()57   ~Riscv64JniCallingConvention() override {}
58   // Calling convention
59   ManagedRegister ReturnRegister() const override;
60   ManagedRegister IntReturnRegister() const override;
61   // JNI calling convention
62   size_t FrameSize() const override;
63   size_t OutFrameSize() const override;
64   ArrayRef<const ManagedRegister> CalleeSaveRegisters() const override;
65   ArrayRef<const ManagedRegister> CalleeSaveScratchRegisters() const override;
66   ArrayRef<const ManagedRegister> ArgumentScratchRegisters() const override;
67   uint32_t CoreSpillMask() const override;
68   uint32_t FpSpillMask() const override;
69   size_t CurrentParamSize() const override;
70   bool IsCurrentParamInRegister() override;
71   bool IsCurrentParamOnStack() override;
72   ManagedRegister CurrentParamRegister() override;
73   FrameOffset CurrentParamStackOffset() override;
74   bool RequiresSmallResultTypeExtension() const override;
75 
76   // Locking argument register, used to pass the synchronization object for calls
77   // to `JniLockObject()` and `JniUnlockObject()`.
78   ManagedRegister LockingArgumentRegister() const override;
79 
80   // Hidden argument register, used to pass the method pointer for @CriticalNative call.
81   ManagedRegister HiddenArgumentRegister() const override;
82 
83   // Whether to use tail call (used only for @CriticalNative).
84   bool UseTailCall() const override;
85 
86  private:
87   DISALLOW_COPY_AND_ASSIGN(Riscv64JniCallingConvention);
88 };
89 
90 }  // namespace riscv64
91 }  // namespace art
92 
93 #endif  // ART_COMPILER_JNI_QUICK_RISCV64_CALLING_CONVENTION_RISCV64_H_
94