1/* 2 * Copyright (C) 2024 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 "asm_support_riscv64.S" 18#include "interpreter/cfi_asm_support.h" 19 20/* 21 * This file contains all native entrypoints that are called using the native ABI and do not 22 * transition to the quick ABI. For example: the switch interpreter (using the native ABI) directly 23 * calls ExecuteSwitchImplAsm and this code will always return back to the switch interpreter, 24 * again using the native ABI. Because of this behaviour ExecuteSwitchImplAsm should be included in 25 * this file. This is done so these native entrypoints can be compiled independently to quick 26 * entrypoints for cases when the kRuntimeISA and kRuntimeQuickCodeISA do not match. 27 * 28 * See comment on StackType (thread.h) for definitions and examples of quick ABI/code and 29 * native ABI/code. 30 */ 31 32// Wrap ExecuteSwitchImpl in assembly method which specifies DEX PC for unwinding. 33// Argument 0: a0: The context pointer for ExecuteSwitchImpl. 34// Argument 1: a1: Pointer to the templated ExecuteSwitchImpl to call. 35// Argument 2: a2: The value of DEX PC (memory address of the methods bytecode). 36ENTRY ExecuteSwitchImplAsm 37 INCREASE_FRAME 16 38 SAVE_GPR s1, 0 39 SAVE_GPR ra, 8 40 41 mv s1, a2 // s1 = DEX PC 42 CFI_DEFINE_DEX_PC_WITH_OFFSET(0 /* a0 */, 9 /* s1, a.k.a. x9 */, 0) 43 jalr a1 // Call the wrapped method. 44 45 RESTORE_GPR s1, 0 46 RESTORE_GPR ra, 8 47 DECREASE_FRAME 16 48 ret 49END ExecuteSwitchImplAsm 50 51// JNI dlsym lookup stub. 52.extern artFindNativeMethod 53.extern artFindNativeMethodRunnable 54ENTRY art_jni_dlsym_lookup_stub 55 SAVE_ALL_ARGS_INCREASE_FRAME 2*8 56 SAVE_GPR fp, (ALL_ARGS_SIZE + 0) 57 SAVE_GPR ra, (ALL_ARGS_SIZE + 8) 58 add fp, sp, ALL_ARGS_SIZE 59 60 // Call artFindNativeMethod for normal native. 61 // Call artFindNativeMethodRunnable for @FastNative or @CriticalNative. 62 // Both functions have a single argument: Thread::Current() in a0. 63 mv a0, xSELF 64 ld t0, THREAD_TOP_QUICK_FRAME_OFFSET(a0) // uintptr_t tagged_quick_frame 65 andi t0, t0, ~TAGGED_JNI_SP_MASK // ArtMethod** sp 66 ld t0, (t0) // ArtMethod* method 67 lw t0, ART_METHOD_ACCESS_FLAGS_OFFSET(t0) // uint32_t access_flags 68 li t1, (ACCESS_FLAGS_METHOD_IS_FAST_NATIVE | ACCESS_FLAGS_METHOD_IS_CRITICAL_NATIVE) 69 and t0, t0, t1 70 bnez t0, .Llookup_stub_fast_or_critical_native 71 call artFindNativeMethod 72 j .Llookup_stub_continue 73 74.Llookup_stub_fast_or_critical_native: 75 call artFindNativeMethodRunnable 76 77.Llookup_stub_continue: 78 mv t0, a0 // store result in a temp reg. 79 RESTORE_GPR fp, (ALL_ARGS_SIZE + 0) 80 RESTORE_GPR ra, (ALL_ARGS_SIZE + 8) 81 RESTORE_ALL_ARGS_DECREASE_FRAME 2*8 82 83 beqz t0, 1f // is method code null? 84 jr t0 // if non-null, tail call to method code. 851: 86 ret // restore regs and return to caller to handle exception. 87END art_jni_dlsym_lookup_stub 88