xref: /aosp_15_r20/art/runtime/arch/x86/native_entrypoints_x86.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_x86.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: ESP+4: The context pointer for ExecuteSwitchImpl.
34*795d594fSAndroid Build Coastguard Worker//  Argument 1: ESP+8: Pointer to the templated ExecuteSwitchImpl to call.
35*795d594fSAndroid Build Coastguard Worker//  Argument 2: ESP+12: The value of DEX PC (memory address of the methods bytecode).
36*795d594fSAndroid Build Coastguard WorkerDEFINE_FUNCTION ExecuteSwitchImplAsm
37*795d594fSAndroid Build Coastguard Worker    PUSH ebx                 // Spill EBX; Increments ESP, so arg0 is at ESP+8 now.
38*795d594fSAndroid Build Coastguard Worker    mov 12(%esp), %eax       // EAX = C++ templated interpreter function
39*795d594fSAndroid Build Coastguard Worker    mov 16(%esp), %ebx       // EBX = DEX PC (callee save register)
40*795d594fSAndroid Build Coastguard Worker    mov 8(%esp), %ecx        // ECX = Context argument for the function
41*795d594fSAndroid Build Coastguard Worker    CFI_DEFINE_DEX_PC_WITH_OFFSET(0 /* EAX */, 3 /* EBX */, 0)
42*795d594fSAndroid Build Coastguard Worker
43*795d594fSAndroid Build Coastguard Worker    sub LITERAL(4), %esp     // Alignment padding
44*795d594fSAndroid Build Coastguard Worker    CFI_ADJUST_CFA_OFFSET(4)
45*795d594fSAndroid Build Coastguard Worker    push %ecx                // Push argument
46*795d594fSAndroid Build Coastguard Worker    CFI_ADJUST_CFA_OFFSET(4)
47*795d594fSAndroid Build Coastguard Worker    call *%eax               // Call the wrapped function
48*795d594fSAndroid Build Coastguard Worker    addl LITERAL(8), %esp
49*795d594fSAndroid Build Coastguard Worker    CFI_ADJUST_CFA_OFFSET(-8)
50*795d594fSAndroid Build Coastguard Worker
51*795d594fSAndroid Build Coastguard Worker    POP ebx                  // Restore EBX
52*795d594fSAndroid Build Coastguard Worker    ret
53*795d594fSAndroid Build Coastguard WorkerEND_FUNCTION ExecuteSwitchImplAsm
54*795d594fSAndroid Build Coastguard Worker
55*795d594fSAndroid Build Coastguard Worker    /*
56*795d594fSAndroid Build Coastguard Worker     * Jni dlsym lookup stub.
57*795d594fSAndroid Build Coastguard Worker     */
58*795d594fSAndroid Build Coastguard WorkerDEFINE_FUNCTION art_jni_dlsym_lookup_stub
59*795d594fSAndroid Build Coastguard Worker    INCREASE_FRAME 8              // Align stack.
60*795d594fSAndroid Build Coastguard Worker    pushl %fs:THREAD_SELF_OFFSET  // Pass Thread::Current().
61*795d594fSAndroid Build Coastguard Worker    CFI_ADJUST_CFA_OFFSET(4)
62*795d594fSAndroid Build Coastguard Worker    // Call artFindNativeMethod() for normal native and artFindNativeMethodRunnable()
63*795d594fSAndroid Build Coastguard Worker    // for @FastNative or @CriticalNative.
64*795d594fSAndroid Build Coastguard Worker    movl (%esp), %eax                                // Thread* self
65*795d594fSAndroid Build Coastguard Worker    movl THREAD_TOP_QUICK_FRAME_OFFSET(%eax), %eax   // uintptr_t tagged_quick_frame
66*795d594fSAndroid Build Coastguard Worker    andl LITERAL(TAGGED_JNI_SP_MASK_TOGGLED32), %eax // ArtMethod** sp
67*795d594fSAndroid Build Coastguard Worker    movl (%eax), %eax                                // ArtMethod* method
68*795d594fSAndroid Build Coastguard Worker    testl LITERAL(ACCESS_FLAGS_METHOD_IS_FAST_NATIVE | ACCESS_FLAGS_METHOD_IS_CRITICAL_NATIVE), \
69*795d594fSAndroid Build Coastguard Worker          ART_METHOD_ACCESS_FLAGS_OFFSET(%eax)
70*795d594fSAndroid Build Coastguard Worker    jne .Llookup_stub_fast_or_critical_native
71*795d594fSAndroid Build Coastguard Worker    call SYMBOL(artFindNativeMethod)  // (Thread*)
72*795d594fSAndroid Build Coastguard Worker    jmp .Llookup_stub_continue
73*795d594fSAndroid Build Coastguard Worker.Llookup_stub_fast_or_critical_native:
74*795d594fSAndroid Build Coastguard Worker    call SYMBOL(artFindNativeMethodRunnable)  // (Thread*)
75*795d594fSAndroid Build Coastguard Worker.Llookup_stub_continue:
76*795d594fSAndroid Build Coastguard Worker    DECREASE_FRAME 12             // Remove argument & padding.
77*795d594fSAndroid Build Coastguard Worker    testl %eax, %eax              // Check if returned method code is null.
78*795d594fSAndroid Build Coastguard Worker    jz .Lno_native_code_found     // If null, jump to return to handle.
79*795d594fSAndroid Build Coastguard Worker    jmp *%eax                     // Otherwise, tail call to intended method.
80*795d594fSAndroid Build Coastguard Worker.Lno_native_code_found:
81*795d594fSAndroid Build Coastguard Worker    ret
82*795d594fSAndroid Build Coastguard WorkerEND_FUNCTION art_jni_dlsym_lookup_stub
83