1 /* 2 * Copyright (C) 2012 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 #include <string.h> 19 20 #include "arch/arm/asm_support_arm.h" 21 #include "base/bit_utils.h" 22 #include "entrypoints/jni/jni_entrypoints.h" 23 #include "entrypoints/quick/quick_alloc_entrypoints.h" 24 #include "entrypoints/quick/quick_default_externs.h" 25 #include "entrypoints/quick/quick_default_init_entrypoints.h" 26 #include "entrypoints/quick/quick_entrypoints.h" 27 #include "entrypoints/entrypoint_utils.h" 28 #include "entrypoints/math_entrypoints.h" 29 #include "entrypoints/runtime_asm_entrypoints.h" 30 #include "interpreter/interpreter.h" 31 32 namespace art { 33 34 // Cast entrypoints. 35 extern "C" size_t artInstanceOfFromCode(mirror::Object* obj, mirror::Class* ref_class); 36 37 // Read barrier entrypoints. 38 // art_quick_read_barrier_mark_regX uses an non-standard calling 39 // convention: it expects its input in register X and returns its 40 // result in that same register, and saves and restores all 41 // caller-save registers. 42 extern "C" mirror::Object* art_quick_read_barrier_mark_reg00(mirror::Object*); 43 extern "C" mirror::Object* art_quick_read_barrier_mark_reg01(mirror::Object*); 44 extern "C" mirror::Object* art_quick_read_barrier_mark_reg02(mirror::Object*); 45 extern "C" mirror::Object* art_quick_read_barrier_mark_reg03(mirror::Object*); 46 extern "C" mirror::Object* art_quick_read_barrier_mark_reg04(mirror::Object*); 47 extern "C" mirror::Object* art_quick_read_barrier_mark_reg05(mirror::Object*); 48 extern "C" mirror::Object* art_quick_read_barrier_mark_reg06(mirror::Object*); 49 extern "C" mirror::Object* art_quick_read_barrier_mark_reg07(mirror::Object*); 50 extern "C" mirror::Object* art_quick_read_barrier_mark_reg08(mirror::Object*); 51 extern "C" mirror::Object* art_quick_read_barrier_mark_reg09(mirror::Object*); 52 extern "C" mirror::Object* art_quick_read_barrier_mark_reg10(mirror::Object*); 53 extern "C" mirror::Object* art_quick_read_barrier_mark_reg11(mirror::Object*); 54 extern "C" mirror::Object* art_quick_read_barrier_mark_reg12(mirror::Object*); 55 56 extern "C" mirror::Object* art_quick_read_barrier_mark_introspection(mirror::Object*); 57 extern "C" mirror::Object* art_quick_read_barrier_mark_introspection_narrow(mirror::Object*); 58 extern "C" mirror::Object* art_quick_read_barrier_mark_introspection_arrays(mirror::Object*); 59 extern "C" mirror::Object* art_quick_read_barrier_mark_introspection_gc_roots_wide(mirror::Object*); 60 extern "C" mirror::Object* art_quick_read_barrier_mark_introspection_gc_roots_narrow( 61 mirror::Object*); 62 63 // Used by soft float. 64 // Single-precision FP arithmetics. 65 extern "C" float fmodf(float a, float b); // REM_FLOAT[_2ADDR] 66 // Double-precision FP arithmetics. 67 extern "C" double fmod(double a, double b); // REM_DOUBLE[_2ADDR] 68 69 // Used by hard float. 70 extern "C" float art_quick_fmodf(float a, float b); // REM_FLOAT[_2ADDR] 71 extern "C" double art_quick_fmod(double a, double b); // REM_DOUBLE[_2ADDR] 72 73 // Integer arithmetics. 74 extern "C" int __aeabi_idivmod(int32_t, int32_t); // [DIV|REM]_INT[_2ADDR|_LIT8|_LIT16] 75 76 // Long long arithmetics - REM_LONG[_2ADDR] and DIV_LONG[_2ADDR] 77 extern "C" int64_t __aeabi_ldivmod(int64_t, int64_t); 78 79 void UpdateReadBarrierEntrypoints(QuickEntryPoints* qpoints, bool is_active) { 80 qpoints->pReadBarrierMarkReg00 = is_active ? art_quick_read_barrier_mark_reg00 : nullptr; 81 qpoints->pReadBarrierMarkReg01 = is_active ? art_quick_read_barrier_mark_reg01 : nullptr; 82 qpoints->pReadBarrierMarkReg02 = is_active ? art_quick_read_barrier_mark_reg02 : nullptr; 83 qpoints->pReadBarrierMarkReg03 = is_active ? art_quick_read_barrier_mark_reg03 : nullptr; 84 qpoints->pReadBarrierMarkReg04 = is_active ? art_quick_read_barrier_mark_reg04 : nullptr; 85 qpoints->pReadBarrierMarkReg05 = is_active ? art_quick_read_barrier_mark_reg05 : nullptr; 86 qpoints->pReadBarrierMarkReg06 = is_active ? art_quick_read_barrier_mark_reg06 : nullptr; 87 qpoints->pReadBarrierMarkReg07 = is_active ? art_quick_read_barrier_mark_reg07 : nullptr; 88 qpoints->pReadBarrierMarkReg08 = is_active ? art_quick_read_barrier_mark_reg08 : nullptr; 89 qpoints->pReadBarrierMarkReg09 = is_active ? art_quick_read_barrier_mark_reg09 : nullptr; 90 qpoints->pReadBarrierMarkReg10 = is_active ? art_quick_read_barrier_mark_reg10 : nullptr; 91 qpoints->pReadBarrierMarkReg11 = is_active ? art_quick_read_barrier_mark_reg11 : nullptr; 92 93 // For the alignment check, strip the Thumb mode bit. 94 DCHECK_ALIGNED(reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection) - 1u, 256u); 95 // Check the field narrow entrypoint offset from the introspection entrypoint. 96 intptr_t narrow_diff = 97 reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection_narrow) - 98 reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection); 99 DCHECK_EQ(BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_ENTRYPOINT_OFFSET, narrow_diff); 100 // Check array switch cases offsets from the introspection entrypoint. 101 intptr_t array_diff = 102 reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection_arrays) - 103 reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection); 104 DCHECK_EQ(BAKER_MARK_INTROSPECTION_ARRAY_SWITCH_OFFSET, array_diff); 105 // Check the GC root entrypoint offsets from the introspection entrypoint. 106 intptr_t gc_roots_wide_diff = 107 reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection_gc_roots_wide) - 108 reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection); 109 DCHECK_EQ(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_ENTRYPOINT_OFFSET, gc_roots_wide_diff); 110 intptr_t gc_roots_narrow_diff = 111 reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection_gc_roots_narrow) - 112 reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection); 113 DCHECK_EQ(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_ENTRYPOINT_OFFSET, gc_roots_narrow_diff); 114 // The register 12, i.e. IP, is reserved, so there is no art_quick_read_barrier_mark_reg12. 115 // We're using the entry to hold a pointer to the introspection entrypoint instead. 116 qpoints->pReadBarrierMarkReg12 = is_active ? art_quick_read_barrier_mark_introspection : nullptr; 117 } 118 119 void InitEntryPoints(JniEntryPoints* jpoints, QuickEntryPoints* qpoints) { 120 DefaultInitEntryPoints(jpoints, qpoints); 121 122 // Cast 123 qpoints->pInstanceofNonTrivial = artInstanceOfFromCode; 124 qpoints->pCheckInstanceOf = art_quick_check_instance_of; 125 126 // Math 127 qpoints->pIdivmod = __aeabi_idivmod; 128 qpoints->pLdiv = __aeabi_ldivmod; 129 qpoints->pLmod = __aeabi_ldivmod; // result returned in r2:r3 130 qpoints->pLmul = art_quick_mul_long; 131 qpoints->pShlLong = art_quick_shl_long; 132 qpoints->pShrLong = art_quick_shr_long; 133 qpoints->pUshrLong = art_quick_ushr_long; 134 if (kArm32QuickCodeUseSoftFloat) { 135 qpoints->pFmod = fmod; 136 qpoints->pFmodf = fmodf; 137 qpoints->pD2l = art_d2l; 138 qpoints->pF2l = art_f2l; 139 qpoints->pL2f = art_l2f; 140 } else { 141 qpoints->pFmod = art_quick_fmod; 142 qpoints->pFmodf = art_quick_fmodf; 143 qpoints->pD2l = art_quick_d2l; 144 qpoints->pF2l = art_quick_f2l; 145 qpoints->pL2f = art_quick_l2f; 146 } 147 148 // More math. 149 qpoints->pCos = cos; 150 qpoints->pSin = sin; 151 qpoints->pAcos = acos; 152 qpoints->pAsin = asin; 153 qpoints->pAtan = atan; 154 qpoints->pAtan2 = atan2; 155 qpoints->pCbrt = cbrt; 156 qpoints->pCosh = cosh; 157 qpoints->pExp = exp; 158 qpoints->pExpm1 = expm1; 159 qpoints->pHypot = hypot; 160 qpoints->pLog = log; 161 qpoints->pLog10 = log10; 162 qpoints->pNextAfter = nextafter; 163 qpoints->pSinh = sinh; 164 qpoints->pTan = tan; 165 qpoints->pTanh = tanh; 166 167 // Intrinsics 168 qpoints->pIndexOf = art_quick_indexof; 169 // The ARM StringCompareTo intrinsic does not call the runtime. 170 qpoints->pStringCompareTo = nullptr; 171 qpoints->pMemcpy = memcpy; 172 173 // Read barrier. 174 qpoints->pReadBarrierJni = ReadBarrierJni; 175 UpdateReadBarrierEntrypoints(qpoints, /*is_active*/ false); 176 qpoints->pReadBarrierMarkReg12 = nullptr; // Cannot use register 12 (IP) to pass arguments. 177 qpoints->pReadBarrierMarkReg13 = nullptr; // Cannot use register 13 (SP) to pass arguments. 178 qpoints->pReadBarrierMarkReg14 = nullptr; // Cannot use register 14 (LR) to pass arguments. 179 qpoints->pReadBarrierMarkReg15 = nullptr; // Cannot use register 15 (PC) to pass arguments. 180 // ARM has only 16 core registers. 181 qpoints->pReadBarrierMarkReg16 = nullptr; 182 qpoints->pReadBarrierMarkReg17 = nullptr; 183 qpoints->pReadBarrierMarkReg18 = nullptr; 184 qpoints->pReadBarrierMarkReg19 = nullptr; 185 qpoints->pReadBarrierMarkReg20 = nullptr; 186 qpoints->pReadBarrierMarkReg21 = nullptr; 187 qpoints->pReadBarrierMarkReg22 = nullptr; 188 qpoints->pReadBarrierMarkReg23 = nullptr; 189 qpoints->pReadBarrierMarkReg24 = nullptr; 190 qpoints->pReadBarrierMarkReg25 = nullptr; 191 qpoints->pReadBarrierMarkReg26 = nullptr; 192 qpoints->pReadBarrierMarkReg27 = nullptr; 193 qpoints->pReadBarrierMarkReg28 = nullptr; 194 qpoints->pReadBarrierMarkReg29 = nullptr; 195 qpoints->pReadBarrierSlow = artReadBarrierSlow; 196 qpoints->pReadBarrierForRootSlow = artReadBarrierForRootSlow; 197 } 198 199 } // namespace art 200