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 #include  <math.h>
18 
19 #include "entrypoints/quick/quick_default_init_entrypoints.h"
20 #include "entrypoints/quick/quick_entrypoints.h"
21 
22 namespace art HIDDEN {
23 
24 // Cast entrypoints.
25 extern "C" size_t artInstanceOfFromCode(mirror::Object* obj, mirror::Class* ref_class);
26 
27 // Read barrier entrypoints.
28 // art_quick_read_barrier_mark_regX uses an non-standard calling convention: it
29 // expects its input in register X and returns its result in that same register,
30 // and saves and restores all other registers.
31 // No read barrier for X0 (Zero), X1 (RA), X2 (SP), X3 (GP) and X4 (TP).
32 extern "C" mirror::Object* art_quick_read_barrier_mark_reg05(mirror::Object*);  // t0/x5
33 extern "C" mirror::Object* art_quick_read_barrier_mark_reg06(mirror::Object*);  // t1/x6
34 extern "C" mirror::Object* art_quick_read_barrier_mark_reg07(mirror::Object*);  // t2/x7
35 extern "C" mirror::Object* art_quick_read_barrier_mark_reg08(mirror::Object*);  // t3/x8
36 // No read barrier for X9 (S1/xSELF).
37 extern "C" mirror::Object* art_quick_read_barrier_mark_reg10(mirror::Object*);  // a0/x10
38 extern "C" mirror::Object* art_quick_read_barrier_mark_reg11(mirror::Object*);  // a1/x11
39 extern "C" mirror::Object* art_quick_read_barrier_mark_reg12(mirror::Object*);  // a2/x12
40 extern "C" mirror::Object* art_quick_read_barrier_mark_reg13(mirror::Object*);  // a3/x13
41 extern "C" mirror::Object* art_quick_read_barrier_mark_reg14(mirror::Object*);  // a4/x14
42 extern "C" mirror::Object* art_quick_read_barrier_mark_reg15(mirror::Object*);  // a5/x15
43 extern "C" mirror::Object* art_quick_read_barrier_mark_reg16(mirror::Object*);  // a6/x16
44 extern "C" mirror::Object* art_quick_read_barrier_mark_reg17(mirror::Object*);  // a7/x17
45 extern "C" mirror::Object* art_quick_read_barrier_mark_reg18(mirror::Object*);  // s2/x18
46 extern "C" mirror::Object* art_quick_read_barrier_mark_reg19(mirror::Object*);  // s3/x19
47 extern "C" mirror::Object* art_quick_read_barrier_mark_reg20(mirror::Object*);  // s4/x20
48 extern "C" mirror::Object* art_quick_read_barrier_mark_reg21(mirror::Object*);  // s5/x21
49 extern "C" mirror::Object* art_quick_read_barrier_mark_reg22(mirror::Object*);  // s6/x22
50 extern "C" mirror::Object* art_quick_read_barrier_mark_reg23(mirror::Object*);  // s7/x23
51 extern "C" mirror::Object* art_quick_read_barrier_mark_reg24(mirror::Object*);  // s8/x24
52 extern "C" mirror::Object* art_quick_read_barrier_mark_reg25(mirror::Object*);  // s9/x25
53 extern "C" mirror::Object* art_quick_read_barrier_mark_reg26(mirror::Object*);  // s10/x26
54 extern "C" mirror::Object* art_quick_read_barrier_mark_reg27(mirror::Object*);  // s11/x27
55 extern "C" mirror::Object* art_quick_read_barrier_mark_reg28(mirror::Object*);  // t3/x28
56 extern "C" mirror::Object* art_quick_read_barrier_mark_reg29(mirror::Object*);  // t4/x29
57 extern "C" mirror::Object* art_quick_read_barrier_mark_reg30(mirror::Object*);  // t5/x30
58 extern "C" mirror::Object* art_quick_read_barrier_mark_reg31(mirror::Object*);  // t6/x31
59 
UpdateReadBarrierEntrypoints(QuickEntryPoints * qpoints,bool is_active)60 void UpdateReadBarrierEntrypoints(QuickEntryPoints* qpoints, bool is_active) {
61   // No read barrier for X0 (Zero), X1 (RA), X2 (SP), X3 (GP) and X4 (TP).
62   qpoints->SetReadBarrierMarkReg05(is_active ? art_quick_read_barrier_mark_reg05 : nullptr);
63   qpoints->SetReadBarrierMarkReg06(is_active ? art_quick_read_barrier_mark_reg06 : nullptr);
64   qpoints->SetReadBarrierMarkReg07(is_active ? art_quick_read_barrier_mark_reg07 : nullptr);
65   qpoints->SetReadBarrierMarkReg08(is_active ? art_quick_read_barrier_mark_reg08 : nullptr);
66   // No read barrier for X9 (S1/xSELF).
67   qpoints->SetReadBarrierMarkReg10(is_active ? art_quick_read_barrier_mark_reg10 : nullptr);
68   qpoints->SetReadBarrierMarkReg11(is_active ? art_quick_read_barrier_mark_reg11 : nullptr);
69   qpoints->SetReadBarrierMarkReg12(is_active ? art_quick_read_barrier_mark_reg12 : nullptr);
70   qpoints->SetReadBarrierMarkReg13(is_active ? art_quick_read_barrier_mark_reg13 : nullptr);
71   qpoints->SetReadBarrierMarkReg14(is_active ? art_quick_read_barrier_mark_reg14 : nullptr);
72   qpoints->SetReadBarrierMarkReg15(is_active ? art_quick_read_barrier_mark_reg15 : nullptr);
73   qpoints->SetReadBarrierMarkReg16(is_active ? art_quick_read_barrier_mark_reg16 : nullptr);
74   qpoints->SetReadBarrierMarkReg17(is_active ? art_quick_read_barrier_mark_reg17 : nullptr);
75   qpoints->SetReadBarrierMarkReg18(is_active ? art_quick_read_barrier_mark_reg18 : nullptr);
76   qpoints->SetReadBarrierMarkReg19(is_active ? art_quick_read_barrier_mark_reg19 : nullptr);
77   qpoints->SetReadBarrierMarkReg20(is_active ? art_quick_read_barrier_mark_reg20 : nullptr);
78   qpoints->SetReadBarrierMarkReg21(is_active ? art_quick_read_barrier_mark_reg21 : nullptr);
79   qpoints->SetReadBarrierMarkReg22(is_active ? art_quick_read_barrier_mark_reg22 : nullptr);
80   qpoints->SetReadBarrierMarkReg23(is_active ? art_quick_read_barrier_mark_reg23 : nullptr);
81   qpoints->SetReadBarrierMarkReg24(is_active ? art_quick_read_barrier_mark_reg24 : nullptr);
82   qpoints->SetReadBarrierMarkReg25(is_active ? art_quick_read_barrier_mark_reg25 : nullptr);
83   qpoints->SetReadBarrierMarkReg26(is_active ? art_quick_read_barrier_mark_reg26 : nullptr);
84   qpoints->SetReadBarrierMarkReg27(is_active ? art_quick_read_barrier_mark_reg27 : nullptr);
85   qpoints->SetReadBarrierMarkReg28(is_active ? art_quick_read_barrier_mark_reg28 : nullptr);
86   qpoints->SetReadBarrierMarkReg29(is_active ? art_quick_read_barrier_mark_reg29 : nullptr);
87   // Note: Entrypoints for registers X30 (T5) and T31 (T6) are stored in entries
88   // for X0 (Zero) and X1 (RA) because these are not valid registers for marking
89   // and we currently have slots only up to register 29.
90   qpoints->SetReadBarrierMarkReg00(is_active ? art_quick_read_barrier_mark_reg30 : nullptr);
91   qpoints->SetReadBarrierMarkReg01(is_active ? art_quick_read_barrier_mark_reg31 : nullptr);
92 }
93 
InitEntryPoints(JniEntryPoints * jpoints,QuickEntryPoints * qpoints,bool monitor_jni_entry_exit)94 void InitEntryPoints(JniEntryPoints* jpoints,
95                      QuickEntryPoints* qpoints,
96                      bool monitor_jni_entry_exit) {
97   DefaultInitEntryPoints(jpoints, qpoints, monitor_jni_entry_exit);
98 
99   // Cast
100   qpoints->SetInstanceofNonTrivial(artInstanceOfFromCode);
101   qpoints->SetCheckInstanceOf(art_quick_check_instance_of);
102 
103   // Math
104   // TODO(riscv64): null entrypoints not needed for riscv64 - using generated code.
105   qpoints->SetCmpgDouble(nullptr);
106   qpoints->SetCmpgFloat(nullptr);
107   qpoints->SetCmplDouble(nullptr);
108   qpoints->SetCmplFloat(nullptr);
109   qpoints->SetFmod(fmod);
110   qpoints->SetL2d(nullptr);
111   qpoints->SetFmodf(fmodf);
112   qpoints->SetL2f(nullptr);
113   qpoints->SetD2iz(nullptr);
114   qpoints->SetF2iz(nullptr);
115   qpoints->SetIdivmod(nullptr);
116   qpoints->SetD2l(nullptr);
117   qpoints->SetF2l(nullptr);
118   qpoints->SetLdiv(nullptr);
119   qpoints->SetLmod(nullptr);
120   qpoints->SetLmul(nullptr);
121   qpoints->SetShlLong(nullptr);
122   qpoints->SetShrLong(nullptr);
123   qpoints->SetUshrLong(nullptr);
124 
125   // More math.
126   qpoints->SetCos(cos);
127   qpoints->SetSin(sin);
128   qpoints->SetAcos(acos);
129   qpoints->SetAsin(asin);
130   qpoints->SetAtan(atan);
131   qpoints->SetAtan2(atan2);
132   qpoints->SetPow(pow);
133   qpoints->SetCbrt(cbrt);
134   qpoints->SetCosh(cosh);
135   qpoints->SetExp(exp);
136   qpoints->SetExpm1(expm1);
137   qpoints->SetHypot(hypot);
138   qpoints->SetLog(log);
139   qpoints->SetLog10(log10);
140   qpoints->SetNextAfter(nextafter);
141   qpoints->SetSinh(sinh);
142   qpoints->SetTan(tan);
143   qpoints->SetTanh(tanh);
144 
145   // Intrinsics
146   qpoints->SetIndexOf(art_quick_indexof);
147   // TODO(riscv64): More intrinsics.
148 
149   // Read barrier.
150   UpdateReadBarrierEntrypoints(qpoints, /*is_active=*/ false);
151   qpoints->SetReadBarrierSlow(artReadBarrierSlow);
152   qpoints->SetReadBarrierForRootSlow(artReadBarrierForRootSlow);
153 }
154 
155 }  // namespace art
156