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 #include <string.h>
18
19 #include "atomic.h"
20 #include "entrypoints/jni/jni_entrypoints.h"
21 #include "entrypoints/quick/quick_alloc_entrypoints.h"
22 #include "entrypoints/quick/quick_default_externs.h"
23 #include "entrypoints/quick/quick_default_init_entrypoints.h"
24 #include "entrypoints/quick/quick_entrypoints.h"
25 #include "entrypoints/entrypoint_utils.h"
26 #include "entrypoints/math_entrypoints.h"
27 #include "entrypoints/runtime_asm_entrypoints.h"
28 #include "interpreter/interpreter.h"
29
30 namespace art {
31
32 // Cast entrypoints.
33 extern "C" size_t artInstanceOfFromCode(mirror::Object* obj, mirror::Class* ref_class);
34
35 // Read barrier entrypoints.
36 // art_quick_read_barrier_mark_regXX uses a non-standard calling
37 // convention: it expects its input in register XX+1 and returns its
38 // result in that same register, and saves and restores all
39 // caller-save registers.
40 extern "C" mirror::Object* art_quick_read_barrier_mark_reg01(mirror::Object*);
41 extern "C" mirror::Object* art_quick_read_barrier_mark_reg02(mirror::Object*);
42 extern "C" mirror::Object* art_quick_read_barrier_mark_reg03(mirror::Object*);
43 extern "C" mirror::Object* art_quick_read_barrier_mark_reg04(mirror::Object*);
44 extern "C" mirror::Object* art_quick_read_barrier_mark_reg05(mirror::Object*);
45 extern "C" mirror::Object* art_quick_read_barrier_mark_reg06(mirror::Object*);
46 extern "C" mirror::Object* art_quick_read_barrier_mark_reg07(mirror::Object*);
47 extern "C" mirror::Object* art_quick_read_barrier_mark_reg08(mirror::Object*);
48 extern "C" mirror::Object* art_quick_read_barrier_mark_reg09(mirror::Object*);
49 extern "C" mirror::Object* art_quick_read_barrier_mark_reg10(mirror::Object*);
50 extern "C" mirror::Object* art_quick_read_barrier_mark_reg11(mirror::Object*);
51 extern "C" mirror::Object* art_quick_read_barrier_mark_reg12(mirror::Object*);
52 extern "C" mirror::Object* art_quick_read_barrier_mark_reg13(mirror::Object*);
53 extern "C" mirror::Object* art_quick_read_barrier_mark_reg17(mirror::Object*);
54 extern "C" mirror::Object* art_quick_read_barrier_mark_reg18(mirror::Object*);
55 extern "C" mirror::Object* art_quick_read_barrier_mark_reg19(mirror::Object*);
56 extern "C" mirror::Object* art_quick_read_barrier_mark_reg20(mirror::Object*);
57 extern "C" mirror::Object* art_quick_read_barrier_mark_reg21(mirror::Object*);
58 extern "C" mirror::Object* art_quick_read_barrier_mark_reg22(mirror::Object*);
59 extern "C" mirror::Object* art_quick_read_barrier_mark_reg29(mirror::Object*);
60
61 // Math entrypoints.
62 extern int32_t CmpgDouble(double a, double b);
63 extern int32_t CmplDouble(double a, double b);
64 extern int32_t CmpgFloat(float a, float b);
65 extern int32_t CmplFloat(float a, float b);
66 extern "C" int64_t artLmul(int64_t a, int64_t b);
67 extern "C" int64_t artLdiv(int64_t a, int64_t b);
68 extern "C" int64_t artLmod(int64_t a, int64_t b);
69
70 // Math conversions.
71 extern "C" int32_t __fixsfsi(float op1); // FLOAT_TO_INT
72 extern "C" int32_t __fixdfsi(double op1); // DOUBLE_TO_INT
73 extern "C" float __floatdisf(int64_t op1); // LONG_TO_FLOAT
74 extern "C" double __floatdidf(int64_t op1); // LONG_TO_DOUBLE
75 extern "C" int64_t __fixsfdi(float op1); // FLOAT_TO_LONG
76 extern "C" int64_t __fixdfdi(double op1); // DOUBLE_TO_LONG
77
78 // Single-precision FP arithmetics.
79 extern "C" float fmodf(float a, float b); // REM_FLOAT[_2ADDR]
80
81 // Double-precision FP arithmetics.
82 extern "C" double fmod(double a, double b); // REM_DOUBLE[_2ADDR]
83
84 // Long long arithmetics - REM_LONG[_2ADDR] and DIV_LONG[_2ADDR]
85 extern "C" int64_t __divdi3(int64_t, int64_t);
86 extern "C" int64_t __moddi3(int64_t, int64_t);
87
88 // No read barrier entrypoints for marking registers.
UpdateReadBarrierEntrypoints(QuickEntryPoints * qpoints,bool is_marking)89 void UpdateReadBarrierEntrypoints(QuickEntryPoints* qpoints, bool is_marking) {
90 qpoints->pReadBarrierMarkReg01 = is_marking ? art_quick_read_barrier_mark_reg01 : nullptr;
91 qpoints->pReadBarrierMarkReg02 = is_marking ? art_quick_read_barrier_mark_reg02 : nullptr;
92 qpoints->pReadBarrierMarkReg03 = is_marking ? art_quick_read_barrier_mark_reg03 : nullptr;
93 qpoints->pReadBarrierMarkReg04 = is_marking ? art_quick_read_barrier_mark_reg04 : nullptr;
94 qpoints->pReadBarrierMarkReg05 = is_marking ? art_quick_read_barrier_mark_reg05 : nullptr;
95 qpoints->pReadBarrierMarkReg06 = is_marking ? art_quick_read_barrier_mark_reg06 : nullptr;
96 qpoints->pReadBarrierMarkReg07 = is_marking ? art_quick_read_barrier_mark_reg07 : nullptr;
97 qpoints->pReadBarrierMarkReg08 = is_marking ? art_quick_read_barrier_mark_reg08 : nullptr;
98 qpoints->pReadBarrierMarkReg09 = is_marking ? art_quick_read_barrier_mark_reg09 : nullptr;
99 qpoints->pReadBarrierMarkReg10 = is_marking ? art_quick_read_barrier_mark_reg10 : nullptr;
100 qpoints->pReadBarrierMarkReg11 = is_marking ? art_quick_read_barrier_mark_reg11 : nullptr;
101 qpoints->pReadBarrierMarkReg12 = is_marking ? art_quick_read_barrier_mark_reg12 : nullptr;
102 qpoints->pReadBarrierMarkReg13 = is_marking ? art_quick_read_barrier_mark_reg13 : nullptr;
103 qpoints->pReadBarrierMarkReg17 = is_marking ? art_quick_read_barrier_mark_reg17 : nullptr;
104 qpoints->pReadBarrierMarkReg18 = is_marking ? art_quick_read_barrier_mark_reg18 : nullptr;
105 qpoints->pReadBarrierMarkReg19 = is_marking ? art_quick_read_barrier_mark_reg19 : nullptr;
106 qpoints->pReadBarrierMarkReg20 = is_marking ? art_quick_read_barrier_mark_reg20 : nullptr;
107 qpoints->pReadBarrierMarkReg21 = is_marking ? art_quick_read_barrier_mark_reg21 : nullptr;
108 qpoints->pReadBarrierMarkReg22 = is_marking ? art_quick_read_barrier_mark_reg22 : nullptr;
109 qpoints->pReadBarrierMarkReg29 = is_marking ? art_quick_read_barrier_mark_reg29 : nullptr;
110 }
111
InitEntryPoints(JniEntryPoints * jpoints,QuickEntryPoints * qpoints)112 void InitEntryPoints(JniEntryPoints* jpoints, QuickEntryPoints* qpoints) {
113 DefaultInitEntryPoints(jpoints, qpoints);
114
115 // Cast
116 qpoints->pInstanceofNonTrivial = artInstanceOfFromCode;
117 qpoints->pCheckInstanceOf = art_quick_check_instance_of;
118
119 // Math
120 qpoints->pCmpgDouble = CmpgDouble;
121 qpoints->pCmpgFloat = CmpgFloat;
122 qpoints->pCmplDouble = CmplDouble;
123 qpoints->pCmplFloat = CmplFloat;
124 qpoints->pFmod = fmod;
125 qpoints->pL2d = art_l2d;
126 qpoints->pFmodf = fmodf;
127 qpoints->pL2f = art_l2f;
128 qpoints->pD2iz = art_d2i;
129 qpoints->pF2iz = art_f2i;
130 qpoints->pIdivmod = nullptr;
131 qpoints->pD2l = art_d2l;
132 qpoints->pF2l = art_f2l;
133 qpoints->pLdiv = artLdiv;
134 qpoints->pLmod = artLmod;
135 qpoints->pLmul = artLmul;
136 qpoints->pShlLong = nullptr;
137 qpoints->pShrLong = nullptr;
138 qpoints->pUshrLong = nullptr;
139
140 // More math.
141 qpoints->pCos = cos;
142 qpoints->pSin = sin;
143 qpoints->pAcos = acos;
144 qpoints->pAsin = asin;
145 qpoints->pAtan = atan;
146 qpoints->pAtan2 = atan2;
147 qpoints->pCbrt = cbrt;
148 qpoints->pCosh = cosh;
149 qpoints->pExp = exp;
150 qpoints->pExpm1 = expm1;
151 qpoints->pHypot = hypot;
152 qpoints->pLog = log;
153 qpoints->pLog10 = log10;
154 qpoints->pNextAfter = nextafter;
155 qpoints->pSinh = sinh;
156 qpoints->pTan = tan;
157 qpoints->pTanh = tanh;
158
159 // Intrinsics
160 qpoints->pIndexOf = art_quick_indexof;
161 qpoints->pStringCompareTo = art_quick_string_compareto;
162 qpoints->pMemcpy = memcpy;
163
164 // TODO - use lld/scd instructions for Mips64
165 // Atomic 64-bit load/store
166 qpoints->pA64Load = QuasiAtomic::Read64;
167 qpoints->pA64Store = QuasiAtomic::Write64;
168
169 // Read barrier.
170 qpoints->pReadBarrierJni = ReadBarrierJni;
171 UpdateReadBarrierEntrypoints(qpoints, /*is_marking*/ false);
172 // Cannot use the following registers to pass arguments:
173 // 0(ZERO), 1(AT), 15(T3), 16(S0), 17(S1), 24(T8), 25(T9), 26(K0), 27(K1), 28(GP), 29(SP), 31(RA).
174 // Note that there are 30 entry points only: 00 for register 1(AT), ..., 29 for register 30(S8).
175 qpoints->pReadBarrierMarkReg00 = nullptr;
176 qpoints->pReadBarrierMarkReg14 = nullptr;
177 qpoints->pReadBarrierMarkReg15 = nullptr;
178 qpoints->pReadBarrierMarkReg16 = nullptr;
179 qpoints->pReadBarrierMarkReg23 = nullptr;
180 qpoints->pReadBarrierMarkReg24 = nullptr;
181 qpoints->pReadBarrierMarkReg25 = nullptr;
182 qpoints->pReadBarrierMarkReg26 = nullptr;
183 qpoints->pReadBarrierMarkReg27 = nullptr;
184 qpoints->pReadBarrierMarkReg28 = nullptr;
185 qpoints->pReadBarrierSlow = artReadBarrierSlow;
186 qpoints->pReadBarrierForRootSlow = artReadBarrierForRootSlow;
187 };
188
189 } // namespace art
190