xref: /aosp_15_r20/art/runtime/arch/arm/native_entrypoints_arm.S (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
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_arm.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: r0: The context pointer for ExecuteSwitchImpl.
34*795d594fSAndroid Build Coastguard Worker//  Argument 1: r1: Pointer to the templated ExecuteSwitchImpl to call.
35*795d594fSAndroid Build Coastguard Worker//  Argument 2: r2: The value of DEX PC (memory address of the methods bytecode).
36*795d594fSAndroid Build Coastguard WorkerENTRY ExecuteSwitchImplAsm
37*795d594fSAndroid Build Coastguard Worker    push {r4, lr}                                 // 2 words of callee saves.
38*795d594fSAndroid Build Coastguard Worker    .cfi_adjust_cfa_offset 8
39*795d594fSAndroid Build Coastguard Worker    .cfi_rel_offset r4, 0
40*795d594fSAndroid Build Coastguard Worker    .cfi_rel_offset lr, 4
41*795d594fSAndroid Build Coastguard Worker    mov r4, r2                                    // r4 = DEX PC
42*795d594fSAndroid Build Coastguard Worker    CFI_DEFINE_DEX_PC_WITH_OFFSET(0 /* r0 */, 4 /* r4 */, 0)
43*795d594fSAndroid Build Coastguard Worker    blx r1                                        // Call the wrapped method.
44*795d594fSAndroid Build Coastguard Worker    pop {r4, pc}
45*795d594fSAndroid Build Coastguard WorkerEND ExecuteSwitchImplAsm
46*795d594fSAndroid Build Coastguard Worker
47*795d594fSAndroid Build Coastguard Worker    /*
48*795d594fSAndroid Build Coastguard Worker     * Jni dlsym lookup stub.
49*795d594fSAndroid Build Coastguard Worker     */
50*795d594fSAndroid Build Coastguard Worker    .extern artFindNativeMethod
51*795d594fSAndroid Build Coastguard Worker    .extern artFindNativeMethodRunnable
52*795d594fSAndroid Build Coastguard WorkerENTRY art_jni_dlsym_lookup_stub
53*795d594fSAndroid Build Coastguard Worker    push   {r0, r1, r2, r3, lr}           @ spill regs
54*795d594fSAndroid Build Coastguard Worker    .cfi_adjust_cfa_offset 20
55*795d594fSAndroid Build Coastguard Worker    .cfi_rel_offset lr, 16
56*795d594fSAndroid Build Coastguard Worker    sub    sp, #12                        @ pad stack pointer to align frame
57*795d594fSAndroid Build Coastguard Worker    .cfi_adjust_cfa_offset 12
58*795d594fSAndroid Build Coastguard Worker
59*795d594fSAndroid Build Coastguard Worker    mov    r0, rSELF                      @ pass Thread::Current()
60*795d594fSAndroid Build Coastguard Worker    // Call artFindNativeMethod() for normal native and artFindNativeMethodRunnable()
61*795d594fSAndroid Build Coastguard Worker    // for @FastNative or @CriticalNative.
62*795d594fSAndroid Build Coastguard Worker    ldr    ip, [r0, #THREAD_TOP_QUICK_FRAME_OFFSET]   // uintptr_t tagged_quick_frame
63*795d594fSAndroid Build Coastguard Worker    bic    ip, #TAGGED_JNI_SP_MASK                    // ArtMethod** sp
64*795d594fSAndroid Build Coastguard Worker    ldr    ip, [ip]                                   // ArtMethod* method
65*795d594fSAndroid Build Coastguard Worker    ldr    ip, [ip, #ART_METHOD_ACCESS_FLAGS_OFFSET]  // uint32_t access_flags
66*795d594fSAndroid Build Coastguard Worker    tst    ip, #(ACCESS_FLAGS_METHOD_IS_FAST_NATIVE | ACCESS_FLAGS_METHOD_IS_CRITICAL_NATIVE)
67*795d594fSAndroid Build Coastguard Worker    bne    .Llookup_stub_fast_or_critical_native
68*795d594fSAndroid Build Coastguard Worker    blx    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    blx    artFindNativeMethodRunnable
72*795d594fSAndroid Build Coastguard Worker.Llookup_stub_continue:
73*795d594fSAndroid Build Coastguard Worker    mov    r12, r0                        @ save result in r12
74*795d594fSAndroid Build Coastguard Worker
75*795d594fSAndroid Build Coastguard Worker    add    sp, #12                        @ restore stack pointer
76*795d594fSAndroid Build Coastguard Worker    .cfi_adjust_cfa_offset -12
77*795d594fSAndroid Build Coastguard Worker    CFI_REMEMBER_STATE
78*795d594fSAndroid Build Coastguard Worker    cbz    r0, 1f                         @ is method code null?
79*795d594fSAndroid Build Coastguard Worker    pop    {r0, r1, r2, r3, lr}           @ restore regs
80*795d594fSAndroid Build Coastguard Worker    .cfi_adjust_cfa_offset -20
81*795d594fSAndroid Build Coastguard Worker    .cfi_restore lr
82*795d594fSAndroid Build Coastguard Worker    bx     r12                            @ if non-null, tail call to method's code
83*795d594fSAndroid Build Coastguard Worker1:
84*795d594fSAndroid Build Coastguard Worker    CFI_RESTORE_STATE_AND_DEF_CFA sp, 20
85*795d594fSAndroid Build Coastguard Worker    pop    {r0, r1, r2, r3, pc}           @ restore regs and return to caller to handle exception
86*795d594fSAndroid Build Coastguard WorkerEND art_jni_dlsym_lookup_stub
87*795d594fSAndroid Build Coastguard Worker
88