1*795d594fSAndroid Build Coastguard Worker/* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2024 The Android Open Source Project 3*795d594fSAndroid Build Coastguard Worker * 4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*795d594fSAndroid Build Coastguard Worker * 8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*795d594fSAndroid Build Coastguard Worker * 10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*795d594fSAndroid Build Coastguard Worker * limitations under the License. 15*795d594fSAndroid Build Coastguard Worker */ 16*795d594fSAndroid Build Coastguard Worker 17*795d594fSAndroid Build Coastguard Worker#include "asm_support_arm64.S" 18*795d594fSAndroid Build Coastguard Worker#include "interpreter/cfi_asm_support.h" 19*795d594fSAndroid Build Coastguard Worker 20*795d594fSAndroid Build Coastguard Worker/* 21*795d594fSAndroid Build Coastguard Worker * This file contains all native entrypoints that are called using the native ABI and do not 22*795d594fSAndroid Build Coastguard Worker * transition to the quick ABI. For example: the switch interpreter (using the native ABI) directly 23*795d594fSAndroid Build Coastguard Worker * calls ExecuteSwitchImplAsm and this code will always return back to the switch interpreter, 24*795d594fSAndroid Build Coastguard Worker * again using the native ABI. Because of this behaviour ExecuteSwitchImplAsm should be included in 25*795d594fSAndroid Build Coastguard Worker * this file. This is done so these native entrypoints can be compiled independently to quick 26*795d594fSAndroid Build Coastguard Worker * entrypoints for cases when the kRuntimeISA and kRuntimeQuickCodeISA do not match. 27*795d594fSAndroid Build Coastguard Worker * 28*795d594fSAndroid Build Coastguard Worker * See comment on StackType (thread.h) for definitions and examples of quick ABI/code and 29*795d594fSAndroid Build Coastguard Worker * native ABI/code. 30*795d594fSAndroid Build Coastguard Worker */ 31*795d594fSAndroid Build Coastguard Worker 32*795d594fSAndroid Build Coastguard Worker// Wrap ExecuteSwitchImpl in assembly method which specifies DEX PC for unwinding. 33*795d594fSAndroid Build Coastguard Worker// Argument 0: x0: The context pointer for ExecuteSwitchImpl. 34*795d594fSAndroid Build Coastguard Worker// Argument 1: x1: Pointer to the templated ExecuteSwitchImpl to call. 35*795d594fSAndroid Build Coastguard Worker// Argument 2: x2: The value of DEX PC (memory address of the methods bytecode). 36*795d594fSAndroid Build Coastguard WorkerENTRY ExecuteSwitchImplAsm 37*795d594fSAndroid Build Coastguard Worker SAVE_TWO_REGS_INCREASE_FRAME x19, xLR, 16 38*795d594fSAndroid Build Coastguard Worker mov x19, x2 // x19 = DEX PC 39*795d594fSAndroid Build Coastguard Worker CFI_DEFINE_DEX_PC_WITH_OFFSET(0 /* x0 */, 19 /* x19 */, 0) 40*795d594fSAndroid Build Coastguard Worker blr x1 // Call the wrapped method. 41*795d594fSAndroid Build Coastguard Worker RESTORE_TWO_REGS_DECREASE_FRAME x19, xLR, 16 42*795d594fSAndroid Build Coastguard Worker ret 43*795d594fSAndroid Build Coastguard WorkerEND ExecuteSwitchImplAsm 44*795d594fSAndroid Build Coastguard Worker 45*795d594fSAndroid Build Coastguard Worker /* 46*795d594fSAndroid Build Coastguard Worker * Jni dlsym lookup stub. 47*795d594fSAndroid Build Coastguard Worker */ 48*795d594fSAndroid Build Coastguard Worker .extern artFindNativeMethod 49*795d594fSAndroid Build Coastguard Worker .extern artFindNativeMethodRunnable 50*795d594fSAndroid Build Coastguard WorkerENTRY art_jni_dlsym_lookup_stub 51*795d594fSAndroid Build Coastguard Worker // spill regs. 52*795d594fSAndroid Build Coastguard Worker SAVE_ALL_ARGS_INCREASE_FRAME 2 * 8 53*795d594fSAndroid Build Coastguard Worker stp x29, x30, [sp, ALL_ARGS_SIZE] 54*795d594fSAndroid Build Coastguard Worker .cfi_rel_offset x29, ALL_ARGS_SIZE 55*795d594fSAndroid Build Coastguard Worker .cfi_rel_offset x30, ALL_ARGS_SIZE + 8 56*795d594fSAndroid Build Coastguard Worker add x29, sp, ALL_ARGS_SIZE 57*795d594fSAndroid Build Coastguard Worker 58*795d594fSAndroid Build Coastguard Worker mov x0, xSELF // pass Thread::Current() 59*795d594fSAndroid Build Coastguard Worker // Call artFindNativeMethod() for normal native and artFindNativeMethodRunnable() 60*795d594fSAndroid Build Coastguard Worker // for @FastNative or @CriticalNative. 61*795d594fSAndroid Build Coastguard Worker ldr xIP0, [x0, #THREAD_TOP_QUICK_FRAME_OFFSET] // uintptr_t tagged_quick_frame 62*795d594fSAndroid Build Coastguard Worker bic xIP0, xIP0, #TAGGED_JNI_SP_MASK // ArtMethod** sp 63*795d594fSAndroid Build Coastguard Worker ldr xIP0, [xIP0] // ArtMethod* method 64*795d594fSAndroid Build Coastguard Worker ldr xIP0, [xIP0, #ART_METHOD_ACCESS_FLAGS_OFFSET] // uint32_t access_flags 65*795d594fSAndroid Build Coastguard Worker mov xIP1, #(ACCESS_FLAGS_METHOD_IS_FAST_NATIVE | ACCESS_FLAGS_METHOD_IS_CRITICAL_NATIVE) 66*795d594fSAndroid Build Coastguard Worker tst xIP0, xIP1 67*795d594fSAndroid Build Coastguard Worker b.ne .Llookup_stub_fast_or_critical_native 68*795d594fSAndroid Build Coastguard Worker bl artFindNativeMethod 69*795d594fSAndroid Build Coastguard Worker b .Llookup_stub_continue 70*795d594fSAndroid Build Coastguard Worker .Llookup_stub_fast_or_critical_native: 71*795d594fSAndroid Build Coastguard Worker bl artFindNativeMethodRunnable 72*795d594fSAndroid Build Coastguard Worker.Llookup_stub_continue: 73*795d594fSAndroid Build Coastguard Worker mov x17, x0 // store result in scratch reg. 74*795d594fSAndroid Build Coastguard Worker 75*795d594fSAndroid Build Coastguard Worker // load spill regs. 76*795d594fSAndroid Build Coastguard Worker ldp x29, x30, [sp, #ALL_ARGS_SIZE] 77*795d594fSAndroid Build Coastguard Worker .cfi_restore x29 78*795d594fSAndroid Build Coastguard Worker .cfi_restore x30 79*795d594fSAndroid Build Coastguard Worker RESTORE_ALL_ARGS_DECREASE_FRAME 2 * 8 80*795d594fSAndroid Build Coastguard Worker 81*795d594fSAndroid Build Coastguard Worker cbz x17, 1f // is method code null ? 82*795d594fSAndroid Build Coastguard Worker br x17 // if non-null, tail call to method's code. 83*795d594fSAndroid Build Coastguard Worker 84*795d594fSAndroid Build Coastguard Worker1: 85*795d594fSAndroid Build Coastguard Worker ret // restore regs and return to caller to handle exception. 86*795d594fSAndroid Build Coastguard WorkerEND art_jni_dlsym_lookup_stub 87