quick_entrypoints_x86.S revision a0b530dd5e76662156b40c8a84ebb446b6332598
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 "asm_support_x86.S"
18
19// For x86, the CFA is esp+4, the address above the pushed return address on the stack.
20
21    /*
22     * Macro that sets up the callee save frame to conform with
23     * Runtime::CreateCalleeSaveMethod(kSaveAll)
24     */
25MACRO0(SETUP_SAVE_ALL_CALLEE_SAVE_FRAME)
26    PUSH edi  // Save callee saves (ebx is saved/restored by the upcall)
27    PUSH esi
28    PUSH ebp
29    subl  MACRO_LITERAL(16), %esp  // Grow stack by 4 words, bottom word will hold Method*
30    CFI_ADJUST_CFA_OFFSET(16)
31    // Ugly compile-time check, but we only have the preprocessor.
32    // Last +4: implicit return address pushed on stack when caller made call.
33#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVE != 3*4 + 16 + 4)
34#error "SAVE_ALL_CALLEE_SAVE_FRAME(X86) size not as expected."
35#endif
36END_MACRO
37
38    /*
39     * Macro that sets up the callee save frame to conform with
40     * Runtime::CreateCalleeSaveMethod(kRefsOnly)
41     */
42MACRO0(SETUP_REF_ONLY_CALLEE_SAVE_FRAME)
43    PUSH edi  // Save callee saves (ebx is saved/restored by the upcall)
44    PUSH esi
45    PUSH ebp
46    subl  MACRO_LITERAL(16), %esp  // Grow stack by 4 words, bottom word will hold Method*
47    CFI_ADJUST_CFA_OFFSET(16)
48
49    // Ugly compile-time check, but we only have the preprocessor.
50    // Last +4: implicit return address pushed on stack when caller made call.
51#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 3*4 + 16 + 4)
52#error "REFS_ONLY_CALLEE_SAVE_FRAME(X86) size not as expected."
53#endif
54END_MACRO
55
56MACRO0(RESTORE_REF_ONLY_CALLEE_SAVE_FRAME)
57    addl MACRO_LITERAL(16), %esp  // Unwind stack up to saved values
58    CFI_ADJUST_CFA_OFFSET(-16)
59    POP ebp  // Restore callee saves (ebx is saved/restored by the upcall)
60    POP esi
61    POP edi
62END_MACRO
63
64    /*
65     * Macro that sets up the callee save frame to conform with
66     * Runtime::CreateCalleeSaveMethod(kRefsAndArgs)
67     */
68MACRO0(SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME)
69    PUSH edi  // Save callee saves
70    PUSH esi
71    PUSH ebp
72    PUSH ebx  // Save args
73    PUSH edx
74    PUSH ecx
75    PUSH eax   // Align stack, eax will be clobbered by Method*
76
77    // Ugly compile-time check, but we only have the preprocessor.
78    // Last +4: implicit return address pushed on stack when caller made call.
79#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 7*4 + 4)
80#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(X86) size not as expected."
81#endif
82END_MACRO
83
84MACRO0(RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME)
85    addl MACRO_LITERAL(4), %esp  // Remove padding
86    CFI_ADJUST_CFA_OFFSET(-4)
87    POP ecx  // Restore args except eax
88    POP edx
89    POP ebx
90    POP ebp  // Restore callee saves
91    POP esi
92    POP edi
93END_MACRO
94
95    /*
96     * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
97     * exception is Thread::Current()->exception_.
98     */
99MACRO0(DELIVER_PENDING_EXCEPTION)
100    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME         // save callee saves for throw
101    mov %esp, %ecx
102    // Outgoing argument set up
103    subl  MACRO_LITERAL(8), %esp             // Alignment padding
104    CFI_ADJUST_CFA_OFFSET(8)
105    PUSH ecx                                 // pass SP
106    pushl %fs:THREAD_SELF_OFFSET             // pass Thread::Current()
107    CFI_ADJUST_CFA_OFFSET(4)
108    SETUP_GOT_NOSAVE                         // clobbers ebx (harmless here)
109    call PLT_SYMBOL(artDeliverPendingExceptionFromCode)  // artDeliverPendingExceptionFromCode(Thread*, SP)
110    int3                                     // unreached
111END_MACRO
112
113MACRO2(NO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
114    DEFINE_FUNCTION RAW_VAR(c_name, 0)
115    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME  // save all registers as basis for long jump context
116    mov %esp, %ecx
117    // Outgoing argument set up
118    subl  MACRO_LITERAL(8), %esp  // alignment padding
119    CFI_ADJUST_CFA_OFFSET(8)
120    PUSH ecx                      // pass SP
121    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
122    CFI_ADJUST_CFA_OFFSET(4)
123    SETUP_GOT_NOSAVE              // clobbers ebx (harmless here)
124    call PLT_VAR(cxx_name, 1)     // cxx_name(Thread*, SP)
125    int3                          // unreached
126    END_FUNCTION RAW_VAR(c_name, 0)
127END_MACRO
128
129MACRO2(ONE_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
130    DEFINE_FUNCTION RAW_VAR(c_name, 0)
131    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME  // save all registers as basis for long jump context
132    mov %esp, %ecx
133    // Outgoing argument set up
134    PUSH eax                      // alignment padding
135    PUSH ecx                      // pass SP
136    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
137    CFI_ADJUST_CFA_OFFSET(4)
138    PUSH eax                      // pass arg1
139    SETUP_GOT_NOSAVE              // clobbers ebx (harmless here)
140    call PLT_VAR(cxx_name, 1)     // cxx_name(arg1, Thread*, SP)
141    int3                          // unreached
142    END_FUNCTION RAW_VAR(c_name, 0)
143END_MACRO
144
145MACRO2(TWO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
146    DEFINE_FUNCTION RAW_VAR(c_name, 0)
147    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME  // save all registers as basis for long jump context
148    mov %esp, %edx
149    // Outgoing argument set up
150    PUSH edx                      // pass SP
151    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
152    CFI_ADJUST_CFA_OFFSET(4)
153    PUSH ecx                      // pass arg2
154    PUSH eax                      // pass arg1
155    SETUP_GOT_NOSAVE              // clobbers ebx (harmless here)
156    call PLT_VAR(cxx_name, 1)     // cxx_name(arg1, arg2, Thread*, SP)
157    int3                          // unreached
158    END_FUNCTION RAW_VAR(c_name, 0)
159END_MACRO
160
161    /*
162     * Called by managed code to create and deliver a NullPointerException.
163     */
164    ASM_HIDDEN art_quick_throw_null_pointer_exception
165NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
166
167    /*
168     * Called by managed code to create and deliver an ArithmeticException.
169     */
170NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
171
172    /*
173     * Called by managed code to create and deliver a StackOverflowError.
174     */
175NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
176
177// On entry to this function, EAX contains the ESP value for the overflow region.
178DEFINE_FUNCTION art_quick_throw_stack_overflow_from_signal
179    // Here, the ESP is above the protected region.  We need to create a
180    // callee save frame and then move ESP down to the overflow region.
181    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME  // save all registers as basis for long jump context
182    mov %esp, %ecx                // get current stack pointer
183    mov %eax, %esp                // move ESP to the overflow region.
184    PUSH ecx                      // pass SP
185    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
186    CFI_ADJUST_CFA_OFFSET(4)
187    SETUP_GOT_NOSAVE              // clobbers ebx (harmless here)
188    call PLT_SYMBOL(artThrowStackOverflowFromCode)    // artThrowStackOverflowFromCode(Thread*, SP)
189    int3                          // unreached
190END_FUNCTION art_quick_throw_stack_overflow_from_signal
191
192    /*
193     * Called by managed code, saves callee saves and then calls artThrowException
194     * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
195     */
196ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
197
198    /*
199     * Called by managed code to create and deliver a NoSuchMethodError.
200     */
201ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
202
203    /*
204     * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
205     * index, arg2 holds limit.
206     */
207    ASM_HIDDEN art_quick_throw_array_bounds
208TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
209
210    /*
211     * All generated callsites for interface invokes and invocation slow paths will load arguments
212     * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
213     * the method_idx.  This wrapper will save arg1-arg3, load the caller's Method*, align the
214     * stack and call the appropriate C helper.
215     * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
216     *
217     * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
218     * of the target Method* in r0 and method->code_ in r1.
219     *
220     * If unsuccessful, the helper will return NULL/NULL. There will bea pending exception in the
221     * thread and we branch to another stub to deliver it.
222     *
223     * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
224     * pointing back to the original caller.
225     */
226MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name)
227    DEFINE_FUNCTION RAW_VAR(c_name, 0)
228    // Set up the callee save frame to conform with Runtime::CreateCalleeSaveMethod(kRefsAndArgs)
229    // return address
230    PUSH edi
231    PUSH esi
232    PUSH ebp
233    PUSH ebx  // Save args
234    PUSH edx
235    PUSH ecx
236    PUSH eax    // <-- callee save Method* to go here
237    movl %esp, %edx  // remember SP
238    // Outgoing argument set up
239    SETUP_GOT_NOSAVE
240    subl MACRO_LITERAL(12), %esp  // alignment padding
241    CFI_ADJUST_CFA_OFFSET(12)
242    PUSH edx                      // pass SP
243    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
244    CFI_ADJUST_CFA_OFFSET(4)
245    pushl 32(%edx)                // pass caller Method*
246    CFI_ADJUST_CFA_OFFSET(4)
247    PUSH ecx                      // pass arg2
248    PUSH eax                      // pass arg1
249    call PLT_VAR(cxx_name, 1)     // cxx_name(arg1, arg2, arg3, Thread*, SP)
250    movl %edx, %edi               // save code pointer in EDI
251    addl MACRO_LITERAL(36), %esp  // Pop arguments skip eax
252    CFI_ADJUST_CFA_OFFSET(-36)
253    POP ecx  // Restore args except eax
254    POP edx
255    POP ebx
256    POP ebp  // Restore callee saves
257    POP esi
258    // Swap EDI callee save with code pointer.
259    xchgl %edi, (%esp)
260    testl %eax, %eax              // Branch forward if exception pending.
261    jz    1f
262    // Tail call to intended method.
263    ret
2641:
265    addl MACRO_LITERAL(4), %esp   // Pop code pointer off stack
266    CFI_ADJUST_CFA_OFFSET(-4)
267    DELIVER_PENDING_EXCEPTION
268    END_FUNCTION RAW_VAR(c_name, 0)
269END_MACRO
270
271    ASM_HIDDEN art_quick_invoke_interface_trampoline
272INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline, artInvokeInterfaceTrampoline
273INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
274
275INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
276INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
277INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
278INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
279
280    /*
281     * Quick invocation stub.
282     * On entry:
283     *   [sp] = return address
284     *   [sp + 4] = method pointer
285     *   [sp + 8] = argument array or NULL for no argument methods
286     *   [sp + 12] = size of argument array in bytes
287     *   [sp + 16] = (managed) thread pointer
288     *   [sp + 20] = JValue* result
289     *   [sp + 24] = shorty
290     */
291DEFINE_FUNCTION art_quick_invoke_stub
292    PUSH ebp                      // save ebp
293    PUSH ebx                      // save ebx
294    mov %esp, %ebp                // copy value of stack pointer into base pointer
295    CFI_DEF_CFA_REGISTER(ebp)
296    mov 20(%ebp), %ebx            // get arg array size
297    addl LITERAL(28), %ebx        // reserve space for return addr, method*, ebx, and ebp in frame
298    andl LITERAL(0xFFFFFFF0), %ebx    // align frame size to 16 bytes
299    subl LITERAL(12), %ebx        // remove space for return address, ebx, and ebp
300    subl %ebx, %esp               // reserve stack space for argument array
301    SETUP_GOT_NOSAVE              // clobbers ebx (harmless here)
302    lea  4(%esp), %eax            // use stack pointer + method ptr as dest for memcpy
303    pushl 20(%ebp)                // push size of region to memcpy
304    pushl 16(%ebp)                // push arg array as source of memcpy
305    pushl %eax                    // push stack pointer as destination of memcpy
306    call PLT_SYMBOL(memcpy)       // (void*, const void*, size_t)
307    addl LITERAL(12), %esp        // pop arguments to memcpy
308    movl LITERAL(0), (%esp)       // store NULL for method*
309    mov 12(%ebp), %eax            // move method pointer into eax
310    mov 4(%esp), %ecx             // copy arg1 into ecx
311    mov 8(%esp), %edx             // copy arg2 into edx
312    mov 12(%esp), %ebx            // copy arg3 into ebx
313    call *METHOD_QUICK_CODE_OFFSET(%eax) // call the method
314    mov %ebp, %esp                // restore stack pointer
315    CFI_DEF_CFA_REGISTER(esp)
316    POP ebx                       // pop ebx
317    POP ebp                       // pop ebp
318    mov 20(%esp), %ecx            // get result pointer
319    mov %eax, (%ecx)              // store the result assuming its a long, int or Object*
320    mov %edx, 4(%ecx)             // store the other half of the result
321    mov 24(%esp), %edx            // get the shorty
322    cmpb LITERAL(68), (%edx)      // test if result type char == 'D'
323    je .Lreturn_double_quick
324    cmpb LITERAL(70), (%edx)      // test if result type char == 'F'
325    je .Lreturn_float_quick
326    ret
327.Lreturn_double_quick:
328    movsd %xmm0, (%ecx)           // store the floating point result
329    ret
330.Lreturn_float_quick:
331    movss %xmm0, (%ecx)           // store the floating point result
332    ret
333END_FUNCTION art_quick_invoke_stub
334
335MACRO3(NO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
336    DEFINE_FUNCTION RAW_VAR(c_name, 0)
337    SETUP_REF_ONLY_CALLEE_SAVE_FRAME  // save ref containing registers for GC
338    mov %esp, %edx                // remember SP
339    SETUP_GOT_NOSAVE              // clobbers ebx (harmless here)
340    // Outgoing argument set up
341    subl MACRO_LITERAL(8), %esp   // push padding
342    CFI_ADJUST_CFA_OFFSET(8)
343    PUSH edx                      // pass SP
344    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
345    CFI_ADJUST_CFA_OFFSET(4)
346    call PLT_VAR(cxx_name, 1)     // cxx_name(Thread*, SP)
347    addl MACRO_LITERAL(16), %esp  // pop arguments
348    CFI_ADJUST_CFA_OFFSET(-16)
349    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME  // restore frame up to return address
350    CALL_MACRO(return_macro, 2)   // return or deliver exception
351    END_FUNCTION RAW_VAR(c_name, 0)
352END_MACRO
353
354MACRO3(ONE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
355    DEFINE_FUNCTION RAW_VAR(c_name, 0)
356    SETUP_REF_ONLY_CALLEE_SAVE_FRAME  // save ref containing registers for GC
357    mov %esp, %edx                // remember SP
358    SETUP_GOT_NOSAVE              // clobbers EBX
359    // Outgoing argument set up
360    PUSH eax                      // push padding
361    PUSH edx                      // pass SP
362    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
363    CFI_ADJUST_CFA_OFFSET(4)
364    PUSH eax                      // pass arg1
365    call PLT_VAR(cxx_name, 1)     // cxx_name(arg1, Thread*, SP)
366    addl MACRO_LITERAL(16), %esp  // pop arguments
367    CFI_ADJUST_CFA_OFFSET(-16)
368    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME  // restore frame up to return address
369    CALL_MACRO(return_macro, 2)   // return or deliver exception
370    END_FUNCTION RAW_VAR(c_name, 0)
371END_MACRO
372
373MACRO3(TWO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
374    DEFINE_FUNCTION RAW_VAR(c_name, 0)
375    SETUP_REF_ONLY_CALLEE_SAVE_FRAME  // save ref containing registers for GC
376    mov %esp, %edx                // remember SP
377    SETUP_GOT_NOSAVE              // clobbers EBX
378    // Outgoing argument set up
379    PUSH edx                      // pass SP
380    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
381    CFI_ADJUST_CFA_OFFSET(4)
382    PUSH ecx                      // pass arg2
383    PUSH eax                      // pass arg1
384    call PLT_VAR(cxx_name, 1)     // cxx_name(arg1, arg2, Thread*, SP)
385    addl MACRO_LITERAL(16), %esp  // pop arguments
386    CFI_ADJUST_CFA_OFFSET(-16)
387    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME  // restore frame up to return address
388    CALL_MACRO(return_macro, 2)   // return or deliver exception
389    END_FUNCTION RAW_VAR(c_name, 0)
390END_MACRO
391
392MACRO3(THREE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
393    DEFINE_FUNCTION RAW_VAR(c_name, 0)
394    SETUP_REF_ONLY_CALLEE_SAVE_FRAME  // save ref containing registers for GC
395    mov %esp, %ebx                // remember SP
396    // Outgoing argument set up
397    subl MACRO_LITERAL(12), %esp  // alignment padding
398    CFI_ADJUST_CFA_OFFSET(12)
399    PUSH ebx                      // pass SP
400    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
401    CFI_ADJUST_CFA_OFFSET(4)
402    PUSH edx                      // pass arg3
403    PUSH ecx                      // pass arg2
404    PUSH eax                      // pass arg1
405    SETUP_GOT_NOSAVE              // clobbers EBX
406    call PLT_VAR(cxx_name, 1)     // cxx_name(arg1, arg2, arg3, Thread*, SP)
407    addl MACRO_LITERAL(32), %esp  // pop arguments
408    CFI_ADJUST_CFA_OFFSET(-32)
409    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME  // restore frame up to return address
410    CALL_MACRO(return_macro, 2)   // return or deliver exception
411    END_FUNCTION RAW_VAR(c_name, 0)
412END_MACRO
413
414MACRO0(RETURN_IF_RESULT_IS_NON_ZERO)
415    testl %eax, %eax               // eax == 0 ?
416    jz  1f                         // if eax == 0 goto 1
417    ret                            // return
4181:                                 // deliver exception on current thread
419    DELIVER_PENDING_EXCEPTION
420END_MACRO
421
422MACRO0(RETURN_IF_EAX_ZERO)
423    testl %eax, %eax               // eax == 0 ?
424    jnz  1f                        // if eax != 0 goto 1
425    ret                            // return
4261:                                 // deliver exception on current thread
427    DELIVER_PENDING_EXCEPTION
428END_MACRO
429
430MACRO0(RETURN_OR_DELIVER_PENDING_EXCEPTION)
431    mov %fs:THREAD_EXCEPTION_OFFSET, %ebx // get exception field
432    testl %ebx, %ebx               // ebx == 0 ?
433    jnz 1f                         // if ebx != 0 goto 1
434    ret                            // return
4351:                                 // deliver exception on current thread
436    DELIVER_PENDING_EXCEPTION
437END_MACRO
438
439// Generate the allocation entrypoints for each allocator.
440// TODO: use arch/quick_alloc_entrypoints.S. Currently we don't as we need to use concatenation
441// macros to work around differences between OS/X's as and binutils as (OS/X lacks named arguments
442// to macros and the VAR macro won't concatenate arguments properly), this also breaks having
443// multi-line macros that use each other (hence using 1 macro per newline below).
444#define GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(c_suffix, cxx_suffix) \
445  TWO_ARG_DOWNCALL art_quick_alloc_object ## c_suffix, artAllocObjectFromCode ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO
446#define GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(c_suffix, cxx_suffix) \
447  TWO_ARG_DOWNCALL art_quick_alloc_object_resolved ## c_suffix, artAllocObjectFromCodeResolved ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO
448#define GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(c_suffix, cxx_suffix) \
449  TWO_ARG_DOWNCALL art_quick_alloc_object_initialized ## c_suffix, artAllocObjectFromCodeInitialized ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO
450#define GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(c_suffix, cxx_suffix) \
451  TWO_ARG_DOWNCALL art_quick_alloc_object_with_access_check ## c_suffix, artAllocObjectFromCodeWithAccessCheck ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO
452#define GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(c_suffix, cxx_suffix) \
453  THREE_ARG_DOWNCALL art_quick_alloc_array ## c_suffix, artAllocArrayFromCode ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO
454#define GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(c_suffix, cxx_suffix) \
455  THREE_ARG_DOWNCALL art_quick_alloc_array_resolved ## c_suffix, artAllocArrayFromCodeResolved ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO
456#define GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(c_suffix, cxx_suffix) \
457  THREE_ARG_DOWNCALL art_quick_alloc_array_with_access_check ## c_suffix, artAllocArrayFromCodeWithAccessCheck ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO
458#define GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(c_suffix, cxx_suffix) \
459  THREE_ARG_DOWNCALL art_quick_check_and_alloc_array ## c_suffix, artCheckAndAllocArrayFromCode ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO
460#define GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(c_suffix, cxx_suffix) \
461  THREE_ARG_DOWNCALL art_quick_check_and_alloc_array_with_access_check ## c_suffix, artCheckAndAllocArrayFromCodeWithAccessCheck ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO
462
463GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_dlmalloc, DlMalloc)
464GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_dlmalloc, DlMalloc)
465GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_dlmalloc, DlMalloc)
466GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_dlmalloc, DlMalloc)
467GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_dlmalloc, DlMalloc)
468GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_dlmalloc, DlMalloc)
469GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_dlmalloc, DlMalloc)
470GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_dlmalloc, DlMalloc)
471GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_dlmalloc, DlMalloc)
472
473GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_dlmalloc_instrumented, DlMallocInstrumented)
474GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_dlmalloc_instrumented, DlMallocInstrumented)
475GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_dlmalloc_instrumented, DlMallocInstrumented)
476GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_dlmalloc_instrumented, DlMallocInstrumented)
477GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_dlmalloc_instrumented, DlMallocInstrumented)
478GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_dlmalloc_instrumented, DlMallocInstrumented)
479GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_dlmalloc_instrumented, DlMallocInstrumented)
480GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_dlmalloc_instrumented, DlMallocInstrumented)
481GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_dlmalloc_instrumented, DlMallocInstrumented)
482
483GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc)
484GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_rosalloc, RosAlloc)
485GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_rosalloc, RosAlloc)
486GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_rosalloc, RosAlloc)
487GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_rosalloc, RosAlloc)
488GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_rosalloc, RosAlloc)
489GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_rosalloc, RosAlloc)
490GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_rosalloc, RosAlloc)
491GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_rosalloc, RosAlloc)
492
493GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc_instrumented, RosAllocInstrumented)
494GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_rosalloc_instrumented, RosAllocInstrumented)
495GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_rosalloc_instrumented, RosAllocInstrumented)
496GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_rosalloc_instrumented, RosAllocInstrumented)
497GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_rosalloc_instrumented, RosAllocInstrumented)
498GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_rosalloc_instrumented, RosAllocInstrumented)
499GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_rosalloc_instrumented, RosAllocInstrumented)
500GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_rosalloc_instrumented, RosAllocInstrumented)
501GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_rosalloc_instrumented, RosAllocInstrumented)
502
503GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_bump_pointer, BumpPointer)
504GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_bump_pointer, BumpPointer)
505GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_bump_pointer, BumpPointer)
506GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_bump_pointer, BumpPointer)
507GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_bump_pointer, BumpPointer)
508GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_bump_pointer, BumpPointer)
509GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_bump_pointer, BumpPointer)
510GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_bump_pointer, BumpPointer)
511GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_bump_pointer, BumpPointer)
512
513GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_bump_pointer_instrumented, BumpPointerInstrumented)
514GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_bump_pointer_instrumented, BumpPointerInstrumented)
515GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_bump_pointer_instrumented, BumpPointerInstrumented)
516GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_bump_pointer_instrumented, BumpPointerInstrumented)
517GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_bump_pointer_instrumented, BumpPointerInstrumented)
518GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_bump_pointer_instrumented, BumpPointerInstrumented)
519GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_bump_pointer_instrumented, BumpPointerInstrumented)
520GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_bump_pointer_instrumented, BumpPointerInstrumented)
521GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_bump_pointer_instrumented, BumpPointerInstrumented)
522
523GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB)
524GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_tlab, TLAB)
525GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_tlab, TLAB)
526GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_tlab, TLAB)
527GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_tlab, TLAB)
528GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_tlab, TLAB)
529GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_tlab, TLAB)
530GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_tlab, TLAB)
531GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_tlab, TLAB)
532
533GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab_instrumented, TLABInstrumented)
534GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_tlab_instrumented, TLABInstrumented)
535GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_tlab_instrumented, TLABInstrumented)
536GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_tlab_instrumented, TLABInstrumented)
537GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_tlab_instrumented, TLABInstrumented)
538GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_tlab_instrumented, TLABInstrumented)
539GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_tlab_instrumented, TLABInstrumented)
540GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_tlab_instrumented, TLABInstrumented)
541GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_tlab_instrumented, TLABInstrumented)
542
543TWO_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO
544TWO_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO
545TWO_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO
546TWO_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO
547
548TWO_ARG_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_EAX_ZERO
549
550DEFINE_FUNCTION art_quick_lock_object
551    testl %eax, %eax                      // null check object/eax
552    jz   .Lslow_lock
553.Lretry_lock:
554    movl LOCK_WORD_OFFSET(%eax), %ecx     // ecx := lock word
555    test LITERAL(0xC0000000), %ecx        // test the 2 high bits.
556    jne  .Lslow_lock                      // slow path if either of the two high bits are set.
557    movl %fs:THREAD_ID_OFFSET, %edx       // edx := thread id
558    test %ecx, %ecx
559    jnz  .Lalready_thin                   // lock word contains a thin lock
560    // unlocked case - %edx holds thread id with count of 0
561    movl %eax, %ecx                       // remember object in case of retry
562    xor  %eax, %eax                       // eax == 0 for comparison with lock word in cmpxchg
563    lock cmpxchg  %edx, LOCK_WORD_OFFSET(%ecx)
564    jnz  .Lcmpxchg_fail                   // cmpxchg failed retry
565    ret
566.Lcmpxchg_fail:
567    movl  %ecx, %eax                       // restore eax
568    jmp  .Lretry_lock
569.Lalready_thin:
570    cmpw %cx, %dx                         // do we hold the lock already?
571    jne  .Lslow_lock
572    addl LITERAL(65536), %ecx             // increment recursion count
573    test LITERAL(0xC0000000), %ecx        // overflowed if either of top two bits are set
574    jne  .Lslow_lock                      // count overflowed so go slow
575    movl %ecx, LOCK_WORD_OFFSET(%eax)     // update lockword, cmpxchg not necessary as we hold lock
576    ret
577.Lslow_lock:
578    SETUP_REF_ONLY_CALLEE_SAVE_FRAME  // save ref containing registers for GC
579    mov %esp, %edx                // remember SP
580    SETUP_GOT_NOSAVE              // clobbers EBX
581    // Outgoing argument set up
582    PUSH eax                      // push padding
583    PUSH edx                      // pass SP
584    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
585    CFI_ADJUST_CFA_OFFSET(4)
586    PUSH eax                      // pass object
587    call PLT_SYMBOL(artLockObjectFromCode)  // artLockObjectFromCode(object, Thread*, SP)
588    addl LITERAL(16), %esp  // pop arguments
589    CFI_ADJUST_CFA_OFFSET(-16)
590    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME  // restore frame up to return address
591    RETURN_IF_EAX_ZERO
592END_FUNCTION art_quick_lock_object
593
594DEFINE_FUNCTION art_quick_unlock_object
595    testl %eax, %eax                      // null check object/eax
596    jz   .Lslow_unlock
597    movl LOCK_WORD_OFFSET(%eax), %ecx     // ecx := lock word
598    movl %fs:THREAD_ID_OFFSET, %edx       // edx := thread id
599    test LITERAL(0xC0000000), %ecx
600    jnz  .Lslow_unlock                    // lock word contains a monitor
601    cmpw %cx, %dx                         // does the thread id match?
602    jne  .Lslow_unlock
603    cmpl LITERAL(65536), %ecx
604    jae  .Lrecursive_thin_unlock
605    movl LITERAL(0), LOCK_WORD_OFFSET(%eax)
606    ret
607.Lrecursive_thin_unlock:
608    subl LITERAL(65536), %ecx
609    mov  %ecx, LOCK_WORD_OFFSET(%eax)
610    ret
611.Lslow_unlock:
612    SETUP_REF_ONLY_CALLEE_SAVE_FRAME  // save ref containing registers for GC
613    mov %esp, %edx                // remember SP
614    SETUP_GOT_NOSAVE              // clobbers EBX
615    // Outgoing argument set up
616    PUSH eax                      // push padding
617    PUSH edx                      // pass SP
618    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
619    CFI_ADJUST_CFA_OFFSET(4)
620    PUSH eax                      // pass object
621    call PLT_SYMBOL(artUnlockObjectFromCode)  // artUnlockObjectFromCode(object, Thread*, SP)
622    addl LITERAL(16), %esp  // pop arguments
623    CFI_ADJUST_CFA_OFFSET(-16)
624    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME  // restore frame up to return address
625    RETURN_IF_EAX_ZERO
626END_FUNCTION art_quick_unlock_object
627
628DEFINE_FUNCTION art_quick_is_assignable
629    SETUP_GOT_NOSAVE             // clobbers EBX
630    PUSH eax                     // alignment padding
631    PUSH ecx                     // pass arg2 - obj->klass
632    PUSH eax                     // pass arg1 - checked class
633    call PLT_SYMBOL(artIsAssignableFromCode)  // (Class* klass, Class* ref_klass)
634    addl LITERAL(12), %esp        // pop arguments
635    CFI_ADJUST_CFA_OFFSET(-12)
636    ret
637END_FUNCTION art_quick_is_assignable
638
639DEFINE_FUNCTION art_quick_check_cast
640    SETUP_GOT_NOSAVE             // clobbers EBX
641    PUSH eax                     // alignment padding
642    PUSH ecx                     // pass arg2 - obj->klass
643    PUSH eax                     // pass arg1 - checked class
644    call PLT_SYMBOL(artIsAssignableFromCode)  // (Class* klass, Class* ref_klass)
645    testl %eax, %eax
646    jz 1f                         // jump forward if not assignable
647    addl LITERAL(12), %esp        // pop arguments
648    CFI_ADJUST_CFA_OFFSET(-12)
649    ret
6501:
651    POP eax                       // pop arguments
652    POP ecx
653    addl LITERAL(4), %esp
654    CFI_ADJUST_CFA_OFFSET(-12)
655    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME  // save all registers as basis for long jump context
656    mov %esp, %edx
657    // Outgoing argument set up
658    PUSH edx                      // pass SP
659    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
660    CFI_ADJUST_CFA_OFFSET(4)
661    PUSH ecx                      // pass arg2
662    PUSH eax                      // pass arg1
663    call PLT_SYMBOL(artThrowClassCastException) // (Class* a, Class* b, Thread*, SP)
664    int3                          // unreached
665END_FUNCTION art_quick_check_cast
666
667    /*
668     * Entry from managed code for array put operations of objects where the value being stored
669     * needs to be checked for compatibility.
670     * eax = array, ecx = index, edx = value
671     */
672DEFINE_FUNCTION art_quick_aput_obj_with_null_and_bound_check
673    testl %eax, %eax
674    jnz SYMBOL(art_quick_aput_obj_with_bound_check)
675    jmp SYMBOL(art_quick_throw_null_pointer_exception)
676END_FUNCTION art_quick_aput_obj_with_null_and_bound_check
677
678    ASM_HIDDEN art_quick_aput_obj_with_bound_check
679DEFINE_FUNCTION art_quick_aput_obj_with_bound_check
680    movl ARRAY_LENGTH_OFFSET(%eax), %ebx
681    cmpl %ebx, %ecx
682    jb SYMBOL(art_quick_aput_obj)
683    mov %ecx, %eax
684    mov %ebx, %ecx
685    jmp SYMBOL(art_quick_throw_array_bounds)
686END_FUNCTION art_quick_aput_obj_with_bound_check
687
688    ASM_HIDDEN art_quick_aput_obj
689DEFINE_FUNCTION art_quick_aput_obj
690    test %edx, %edx              // store of null
691    jz .Ldo_aput_null
692    movl CLASS_OFFSET(%eax), %ebx
693    movl CLASS_COMPONENT_TYPE_OFFSET(%ebx), %ebx
694    cmpl CLASS_OFFSET(%edx), %ebx // value's type == array's component type - trivial assignability
695    jne .Lcheck_assignability
696.Ldo_aput:
697    movl %edx, OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
698    movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
699    shrl LITERAL(7), %eax
700    movb %dl, (%edx, %eax)
701    ret
702.Ldo_aput_null:
703    movl %edx, OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
704    ret
705.Lcheck_assignability:
706    PUSH eax                     // save arguments
707    PUSH ecx
708    PUSH edx
709    subl LITERAL(8), %esp        // alignment padding
710    CFI_ADJUST_CFA_OFFSET(8)
711    pushl CLASS_OFFSET(%edx)     // pass arg2 - type of the value to be stored
712    CFI_ADJUST_CFA_OFFSET(4)
713    PUSH ebx                     // pass arg1 - component type of the array
714    SETUP_GOT_NOSAVE             // clobbers EBX
715    call PLT_SYMBOL(artIsAssignableFromCode)  // (Class* a, Class* b)
716    addl LITERAL(16), %esp       // pop arguments
717    CFI_ADJUST_CFA_OFFSET(-16)
718    testl %eax, %eax
719    jz   .Lthrow_array_store_exception
720    POP  edx
721    POP  ecx
722    POP  eax
723    movl %edx, OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)  // do the aput
724    movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
725    shrl LITERAL(7), %eax
726    movb %dl, (%edx, %eax)
727    ret
728.Lthrow_array_store_exception:
729    POP  edx
730    POP  ecx
731    POP  eax
732    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME  // save all registers as basis for long jump context
733    mov %esp, %ecx
734    // Outgoing argument set up
735    PUSH ecx                      // pass SP
736    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
737    CFI_ADJUST_CFA_OFFSET(4)
738    PUSH edx                      // pass arg2 - value
739    PUSH eax                      // pass arg1 - array
740    call PLT_SYMBOL(artThrowArrayStoreException) // (array, value, Thread*, SP)
741    int3                          // unreached
742END_FUNCTION art_quick_aput_obj
743
744DEFINE_FUNCTION art_quick_memcpy
745    SETUP_GOT_NOSAVE              // clobbers EBX
746    PUSH edx                      // pass arg3
747    PUSH ecx                      // pass arg2
748    PUSH eax                      // pass arg1
749    call PLT_SYMBOL(memcpy)       // (void*, const void*, size_t)
750    addl LITERAL(12), %esp        // pop arguments
751    CFI_ADJUST_CFA_OFFSET(-12)
752    ret
753END_FUNCTION art_quick_memcpy
754
755NO_ARG_DOWNCALL art_quick_test_suspend, artTestSuspendFromCode, ret
756
757DEFINE_FUNCTION art_quick_d2l
758    PUSH eax                      // alignment padding
759    PUSH ecx                      // pass arg2 a.hi
760    PUSH eax                      // pass arg1 a.lo
761    SETUP_GOT_NOSAVE              // clobbers EBX
762    call PLT_SYMBOL(art_d2l)      // (jdouble a)
763    addl LITERAL(12), %esp        // pop arguments
764    CFI_ADJUST_CFA_OFFSET(-12)
765    ret
766END_FUNCTION art_quick_d2l
767
768DEFINE_FUNCTION art_quick_f2l
769    subl LITERAL(8), %esp         // alignment padding
770    CFI_ADJUST_CFA_OFFSET(8)
771    SETUP_GOT_NOSAVE              // clobbers EBX
772    PUSH eax                      // pass arg1 a
773    call PLT_SYMBOL(art_f2l)      // (jfloat a)
774    addl LITERAL(12), %esp        // pop arguments
775    CFI_ADJUST_CFA_OFFSET(-12)
776    ret
777END_FUNCTION art_quick_f2l
778
779DEFINE_FUNCTION art_quick_ldiv
780    subl LITERAL(12), %esp       // alignment padding
781    CFI_ADJUST_CFA_OFFSET(12)
782    PUSH ebx                     // pass arg4 b.hi
783    PUSH edx                     // pass arg3 b.lo
784    PUSH ecx                     // pass arg2 a.hi
785    PUSH eax                     // pass arg1 a.lo
786    SETUP_GOT_NOSAVE             // clobbers EBX
787    call PLT_SYMBOL(artLdiv)     // (jlong a, jlong b)
788    addl LITERAL(28), %esp       // pop arguments
789    CFI_ADJUST_CFA_OFFSET(-28)
790    ret
791END_FUNCTION art_quick_ldiv
792
793DEFINE_FUNCTION art_quick_lmod
794    subl LITERAL(12), %esp       // alignment padding
795    CFI_ADJUST_CFA_OFFSET(12)
796    PUSH ebx                     // pass arg4 b.hi
797    PUSH edx                     // pass arg3 b.lo
798    PUSH ecx                     // pass arg2 a.hi
799    PUSH eax                     // pass arg1 a.lo
800    SETUP_GOT_NOSAVE             // clobbers EBX
801    call PLT_SYMBOL(artLmod)     // (jlong a, jlong b)
802    addl LITERAL(28), %esp       // pop arguments
803    CFI_ADJUST_CFA_OFFSET(-28)
804    ret
805END_FUNCTION art_quick_lmod
806
807DEFINE_FUNCTION art_quick_lmul
808    imul %eax, %ebx              // ebx = a.lo(eax) * b.hi(ebx)
809    imul %edx, %ecx              // ecx = b.lo(edx) * a.hi(ecx)
810    mul  %edx                    // edx:eax = a.lo(eax) * b.lo(edx)
811    add  %ebx, %ecx
812    add  %ecx, %edx              // edx += (a.lo * b.hi) + (b.lo * a.hi)
813    ret
814END_FUNCTION art_quick_lmul
815
816DEFINE_FUNCTION art_quick_lshl
817    // ecx:eax << edx
818    xchg %edx, %ecx
819    shld %cl,%eax,%edx
820    shl  %cl,%eax
821    test LITERAL(32), %cl
822    jz  1f
823    mov %eax, %edx
824    xor %eax, %eax
8251:
826    ret
827END_FUNCTION art_quick_lshl
828
829DEFINE_FUNCTION art_quick_lshr
830    // ecx:eax >> edx
831    xchg %edx, %ecx
832    shrd %cl,%edx,%eax
833    sar  %cl,%edx
834    test LITERAL(32),%cl
835    jz  1f
836    mov %edx, %eax
837    sar LITERAL(31), %edx
8381:
839    ret
840END_FUNCTION art_quick_lshr
841
842DEFINE_FUNCTION art_quick_lushr
843    // ecx:eax >>> edx
844    xchg %edx, %ecx
845    shrd %cl,%edx,%eax
846    shr  %cl,%edx
847    test LITERAL(32),%cl
848    jz  1f
849    mov %edx, %eax
850    xor %edx, %edx
8511:
852    ret
853END_FUNCTION art_quick_lushr
854
855DEFINE_FUNCTION art_quick_set32_instance
856    SETUP_REF_ONLY_CALLEE_SAVE_FRAME       // save ref containing registers for GC
857    mov %esp, %ebx                // remember SP
858    subl LITERAL(8), %esp         // alignment padding
859    CFI_ADJUST_CFA_OFFSET(8)
860    PUSH ebx                      // pass SP
861    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
862    CFI_ADJUST_CFA_OFFSET(4)
863    mov 32(%ebx), %ebx            // get referrer
864    PUSH ebx                      // pass referrer
865    PUSH edx                      // pass new_val
866    PUSH ecx                      // pass object
867    PUSH eax                      // pass field_idx
868    SETUP_GOT_NOSAVE              // clobbers EBX
869    call PLT_SYMBOL(artSet32InstanceFromCode)  // (field_idx, Object*, new_val, referrer, Thread*, SP)
870    addl LITERAL(32), %esp        // pop arguments
871    CFI_ADJUST_CFA_OFFSET(-32)
872    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME     // restore frame up to return address
873    RETURN_IF_EAX_ZERO            // return or deliver exception
874END_FUNCTION art_quick_set32_instance
875
876DEFINE_FUNCTION art_quick_set64_instance
877    SETUP_REF_ONLY_CALLEE_SAVE_FRAME  // save ref containing registers for GC
878    subl LITERAL(8), %esp         // alignment padding
879    CFI_ADJUST_CFA_OFFSET(8)
880    PUSH esp                      // pass SP-8
881    addl LITERAL(8), (%esp)       // fix SP on stack by adding 8
882    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
883    CFI_ADJUST_CFA_OFFSET(4)
884    PUSH ebx                      // pass high half of new_val
885    PUSH edx                      // pass low half of new_val
886    PUSH ecx                      // pass object
887    PUSH eax                      // pass field_idx
888    SETUP_GOT_NOSAVE              // clobbers EBX
889    call PLT_SYMBOL(artSet64InstanceFromCode)  // (field_idx, Object*, new_val, Thread*, SP)
890    addl LITERAL(32), %esp        // pop arguments
891    CFI_ADJUST_CFA_OFFSET(-32)
892    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME  // restore frame up to return address
893    RETURN_IF_EAX_ZERO            // return or deliver exception
894END_FUNCTION art_quick_set64_instance
895
896DEFINE_FUNCTION art_quick_set_obj_instance
897    SETUP_REF_ONLY_CALLEE_SAVE_FRAME  // save ref containing registers for GC
898    mov %esp, %ebx                // remember SP
899    subl LITERAL(8), %esp         // alignment padding
900    CFI_ADJUST_CFA_OFFSET(8)
901    PUSH ebx                      // pass SP
902    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
903    CFI_ADJUST_CFA_OFFSET(4)
904    mov 32(%ebx), %ebx            // get referrer
905    PUSH ebx                      // pass referrer
906    PUSH edx                      // pass new_val
907    PUSH ecx                      // pass object
908    PUSH eax                      // pass field_idx
909    SETUP_GOT_NOSAVE              // clobbers EBX
910    call PLT_SYMBOL(artSetObjInstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*, SP)
911    addl LITERAL(32), %esp        // pop arguments
912    CFI_ADJUST_CFA_OFFSET(-32)
913    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME     // restore frame up to return address
914    RETURN_IF_EAX_ZERO            // return or deliver exception
915END_FUNCTION art_quick_set_obj_instance
916
917DEFINE_FUNCTION art_quick_get32_instance
918    SETUP_REF_ONLY_CALLEE_SAVE_FRAME  // save ref containing registers for GC
919    mov %esp, %ebx                // remember SP
920    mov 32(%esp), %edx            // get referrer
921    subl LITERAL(12), %esp        // alignment padding
922    CFI_ADJUST_CFA_OFFSET(12)
923    PUSH ebx                      // pass SP
924    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
925    CFI_ADJUST_CFA_OFFSET(4)
926    PUSH edx                      // pass referrer
927    PUSH ecx                      // pass object
928    PUSH eax                      // pass field_idx
929    SETUP_GOT_NOSAVE              // clobbers EBX
930    call PLT_SYMBOL(artGet32InstanceFromCode)  // (field_idx, Object*, referrer, Thread*, SP)
931    addl LITERAL(32), %esp        // pop arguments
932    CFI_ADJUST_CFA_OFFSET(-32)
933    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME     // restore frame up to return address
934    RETURN_OR_DELIVER_PENDING_EXCEPTION    // return or deliver exception
935END_FUNCTION art_quick_get32_instance
936
937DEFINE_FUNCTION art_quick_get64_instance
938    SETUP_REF_ONLY_CALLEE_SAVE_FRAME       // save ref containing registers for GC
939    mov %esp, %ebx                // remember SP
940    mov 32(%esp), %edx            // get referrer
941    subl LITERAL(12), %esp        // alignment padding
942    CFI_ADJUST_CFA_OFFSET(12)
943    PUSH ebx                      // pass SP
944    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
945    CFI_ADJUST_CFA_OFFSET(4)
946    PUSH edx                      // pass referrer
947    PUSH ecx                      // pass object
948    PUSH eax                      // pass field_idx
949    SETUP_GOT_NOSAVE              // clobbers EBX
950    call PLT_SYMBOL(artGet64InstanceFromCode)  // (field_idx, Object*, referrer, Thread*, SP)
951    addl LITERAL(32), %esp        // pop arguments
952    CFI_ADJUST_CFA_OFFSET(-32)
953    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME     // restore frame up to return address
954    RETURN_OR_DELIVER_PENDING_EXCEPTION    // return or deliver exception
955END_FUNCTION art_quick_get64_instance
956
957DEFINE_FUNCTION art_quick_get_obj_instance
958    SETUP_REF_ONLY_CALLEE_SAVE_FRAME       // save ref containing registers for GC
959    mov %esp, %ebx                // remember SP
960    mov 32(%esp), %edx            // get referrer
961    subl LITERAL(12), %esp        // alignment padding
962    CFI_ADJUST_CFA_OFFSET(12)
963    PUSH ebx                      // pass SP
964    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
965    CFI_ADJUST_CFA_OFFSET(4)
966    PUSH edx                      // pass referrer
967    PUSH ecx                      // pass object
968    PUSH eax                      // pass field_idx
969    SETUP_GOT_NOSAVE              // clobbers EBX
970    call PLT_SYMBOL(artGetObjInstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
971    addl LITERAL(32), %esp        // pop arguments
972    CFI_ADJUST_CFA_OFFSET(-32)
973    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME     // restore frame up to return address
974    RETURN_OR_DELIVER_PENDING_EXCEPTION    // return or deliver exception
975END_FUNCTION art_quick_get_obj_instance
976
977DEFINE_FUNCTION art_quick_set32_static
978    SETUP_REF_ONLY_CALLEE_SAVE_FRAME       // save ref containing registers for GC
979    mov %esp, %ebx                // remember SP
980    mov 32(%esp), %edx            // get referrer
981    subl LITERAL(12), %esp        // alignment padding
982    CFI_ADJUST_CFA_OFFSET(12)
983    PUSH ebx                      // pass SP
984    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
985    CFI_ADJUST_CFA_OFFSET(4)
986    PUSH edx                      // pass referrer
987    PUSH ecx                      // pass new_val
988    PUSH eax                      // pass field_idx
989    SETUP_GOT_NOSAVE              // clobbers EBX
990    call PLT_SYMBOL(artSet32StaticFromCode)  // (field_idx, new_val, referrer, Thread*, SP)
991    addl LITERAL(32), %esp        // pop arguments
992    CFI_ADJUST_CFA_OFFSET(-32)
993    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME     // restore frame up to return address
994    RETURN_IF_EAX_ZERO            // return or deliver exception
995END_FUNCTION art_quick_set32_static
996
997DEFINE_FUNCTION art_quick_set64_static
998    SETUP_REF_ONLY_CALLEE_SAVE_FRAME  // save ref containing registers for GC
999    mov %esp, %ebx                // remember SP
1000    subl LITERAL(8), %esp         // alignment padding
1001    CFI_ADJUST_CFA_OFFSET(8)
1002    PUSH ebx                      // pass SP
1003    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
1004    CFI_ADJUST_CFA_OFFSET(4)
1005    mov 32(%ebx), %ebx            // get referrer
1006    PUSH edx                      // pass high half of new_val
1007    PUSH ecx                      // pass low half of new_val
1008    PUSH ebx                      // pass referrer
1009    PUSH eax                      // pass field_idx
1010    SETUP_GOT_NOSAVE              // clobbers EBX
1011    call PLT_SYMBOL(artSet64StaticFromCode)  // (field_idx, referrer, new_val, Thread*, SP)
1012    addl LITERAL(32), %esp        // pop arguments
1013    CFI_ADJUST_CFA_OFFSET(-32)
1014    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME  // restore frame up to return address
1015    RETURN_IF_EAX_ZERO            // return or deliver exception
1016END_FUNCTION art_quick_set64_static
1017
1018DEFINE_FUNCTION art_quick_set_obj_static
1019    SETUP_REF_ONLY_CALLEE_SAVE_FRAME  // save ref containing registers for GC
1020    mov %esp, %ebx                // remember SP
1021    mov 32(%esp), %edx            // get referrer
1022    subl LITERAL(12), %esp        // alignment padding
1023    CFI_ADJUST_CFA_OFFSET(12)
1024    PUSH ebx                      // pass SP
1025    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
1026    CFI_ADJUST_CFA_OFFSET(4)
1027    PUSH edx                      // pass referrer
1028    PUSH ecx                      // pass new_val
1029    PUSH eax                      // pass field_idx
1030    SETUP_GOT_NOSAVE              // clobbers EBX
1031    call PLT_SYMBOL(artSetObjStaticFromCode)  // (field_idx, new_val, referrer, Thread*, SP)
1032    addl LITERAL(32), %esp        // pop arguments
1033    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME  // restore frame up to return address
1034    RETURN_IF_EAX_ZERO            // return or deliver exception
1035END_FUNCTION art_quick_set_obj_static
1036
1037DEFINE_FUNCTION art_quick_get32_static
1038    SETUP_REF_ONLY_CALLEE_SAVE_FRAME       // save ref containing registers for GC
1039    mov %esp, %edx                // remember SP
1040    mov 32(%esp), %ecx            // get referrer
1041    PUSH edx                      // pass SP
1042    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
1043    CFI_ADJUST_CFA_OFFSET(4)
1044    PUSH ecx                      // pass referrer
1045    PUSH eax                      // pass field_idx
1046    SETUP_GOT_NOSAVE              // clobbers EBX
1047    call PLT_SYMBOL(artGet32StaticFromCode)    // (field_idx, referrer, Thread*, SP)
1048    addl LITERAL(16), %esp        // pop arguments
1049    CFI_ADJUST_CFA_OFFSET(-16)
1050    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME     // restore frame up to return address
1051    RETURN_OR_DELIVER_PENDING_EXCEPTION    // return or deliver exception
1052END_FUNCTION art_quick_get32_static
1053
1054DEFINE_FUNCTION art_quick_get64_static
1055    SETUP_REF_ONLY_CALLEE_SAVE_FRAME  // save ref containing registers for GC
1056    mov %esp, %edx                // remember SP
1057    mov 32(%esp), %ecx            // get referrer
1058    PUSH edx                      // pass SP
1059    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
1060    CFI_ADJUST_CFA_OFFSET(4)
1061    PUSH ecx                      // pass referrer
1062    PUSH eax                      // pass field_idx
1063    SETUP_GOT_NOSAVE              // clobbers EBX
1064    call PLT_SYMBOL(artGet64StaticFromCode)    // (field_idx, referrer, Thread*, SP)
1065    addl LITERAL(16), %esp        // pop arguments
1066    CFI_ADJUST_CFA_OFFSET(-16)
1067    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME     // restore frame up to return address
1068    RETURN_OR_DELIVER_PENDING_EXCEPTION    // return or deliver exception
1069END_FUNCTION art_quick_get64_static
1070
1071DEFINE_FUNCTION art_quick_get_obj_static
1072    SETUP_REF_ONLY_CALLEE_SAVE_FRAME       // save ref containing registers for GC
1073    mov %esp, %edx                // remember SP
1074    mov 32(%esp), %ecx            // get referrer
1075    PUSH edx                      // pass SP
1076    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
1077    CFI_ADJUST_CFA_OFFSET(4)
1078    PUSH ecx                      // pass referrer
1079    PUSH eax                      // pass field_idx
1080    SETUP_GOT_NOSAVE              // clobbers EBX
1081    call PLT_SYMBOL(artGetObjStaticFromCode)   // (field_idx, referrer, Thread*, SP)
1082    addl LITERAL(16), %esp        // pop arguments
1083    CFI_ADJUST_CFA_OFFSET(-16)
1084    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME     // restore frame up to return address
1085    RETURN_OR_DELIVER_PENDING_EXCEPTION    // return or deliver exception
1086END_FUNCTION art_quick_get_obj_static
1087
1088DEFINE_FUNCTION art_quick_proxy_invoke_handler
1089    SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME   // save frame and Method*
1090    PUSH esp                      // pass SP
1091    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
1092    CFI_ADJUST_CFA_OFFSET(4)
1093    PUSH ecx                      // pass receiver
1094    PUSH eax                      // pass proxy method
1095    SETUP_GOT_NOSAVE              // clobbers EBX
1096    call PLT_SYMBOL(artQuickProxyInvokeHandler) // (proxy method, receiver, Thread*, SP)
1097    movd %eax, %xmm0              // place return value also into floating point return value
1098    movd %edx, %xmm1
1099    punpckldq %xmm1, %xmm0
1100    addl LITERAL(44), %esp        // pop arguments
1101    CFI_ADJUST_CFA_OFFSET(-44)
1102    RETURN_OR_DELIVER_PENDING_EXCEPTION    // return or deliver exception
1103END_FUNCTION art_quick_proxy_invoke_handler
1104
1105    /*
1106     * Called to resolve an imt conflict. xmm0 is a hidden argument that holds the target method's
1107     * dex method index.
1108     */
1109DEFINE_FUNCTION art_quick_imt_conflict_trampoline
1110    PUSH ecx
1111    movl 8(%esp), %eax            // load caller Method*
1112    movl METHOD_DEX_CACHE_METHODS_OFFSET(%eax), %eax  // load dex_cache_resolved_methods
1113    movd %xmm0, %ecx              // get target method index stored in xmm0
1114    movl OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4), %eax  // load the target method
1115    POP ecx
1116    jmp SYMBOL(art_quick_invoke_interface_trampoline)
1117END_FUNCTION art_quick_imt_conflict_trampoline
1118
1119DEFINE_FUNCTION art_quick_resolution_trampoline
1120    SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
1121    movl %esp, %edi
1122    PUSH EDI                      // pass SP. do not just PUSH ESP; that messes up unwinding
1123    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
1124    CFI_ADJUST_CFA_OFFSET(4)
1125    PUSH ecx                      // pass receiver
1126    PUSH eax                      // pass method
1127    SETUP_GOT_NOSAVE              // clobbers EBX
1128    call PLT_SYMBOL(artQuickResolutionTrampoline) // (Method* called, receiver, Thread*, SP)
1129    movl %eax, %edi               // remember code pointer in EDI
1130    addl LITERAL(16), %esp        // pop arguments
1131    test %eax, %eax               // if code pointer is NULL goto deliver pending exception
1132    jz 1f
1133    POP eax                       // called method
1134    POP ecx                       // restore args
1135    POP edx
1136    POP ebx
1137    POP ebp                       // restore callee saves except EDI
1138    POP esi
1139    xchgl 0(%esp),%edi            // restore EDI and place code pointer as only value on stack
1140    ret                           // tail call into method
11411:
1142    RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
1143    DELIVER_PENDING_EXCEPTION
1144END_FUNCTION art_quick_resolution_trampoline
1145
1146DEFINE_FUNCTION art_quick_generic_jni_trampoline
1147    SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
1148    // This also stores the native ArtMethod reference at the bottom of the stack.
1149
1150    movl %esp, %ebp                 // save SP at callee-save frame
1151    CFI_DEF_CFA_REGISTER(ebp)
1152    subl LITERAL(5120), %esp
1153    // prepare for artQuickGenericJniTrampoline call
1154    // (Thread*,  SP)
1155    //  (esp)    4(esp)   <= C calling convention
1156    //  fs:...    ebp     <= where they are
1157    // Also: PLT, so need GOT in ebx.
1158
1159    subl LITERAL(8), %esp         // Padding for 16B alignment.
1160    pushl %ebp                    // Pass SP (to ArtMethod).
1161    pushl %fs:THREAD_SELF_OFFSET  // Pass Thread::Current().
1162    SETUP_GOT_NOSAVE              // Clobbers ebx.
1163    call PLT_SYMBOL(artQuickGenericJniTrampoline)  // (Thread*, sp)
1164
1165    // The C call will have registered the complete save-frame on success.
1166    // The result of the call is:
1167    // eax: pointer to native code, 0 on error.
1168    // edx: pointer to the bottom of the used area of the alloca, can restore stack till there.
1169
1170    // Check for error = 0.
1171    test %eax, %eax
1172    jz .Lentry_error
1173
1174    // Release part of the alloca.
1175    movl %edx, %esp
1176
1177    // On x86 there are no registers passed, so nothing to pop here.
1178
1179    // Native call.
1180    call *%eax
1181
1182    // result sign extension is handled in C code
1183    // prepare for artQuickGenericJniEndTrampoline call
1184    // (Thread*, result, result_f)
1185    //  (esp)    4(esp)  12(esp)    <= C calling convention
1186    //  fs:...  eax:edx   xmm0      <= where they are
1187
1188    subl LITERAL(20), %esp         // Padding & pass float result.
1189    movsd %xmm0, (%esp)
1190    pushl %edx                    // Pass int result.
1191    pushl %eax
1192    pushl %fs:THREAD_SELF_OFFSET  // Pass Thread::Current().
1193    call PLT_SYMBOL(artQuickGenericJniEndTrampoline)
1194
1195    // Tear down the alloca.
1196    movl %ebp, %esp
1197    CFI_DEF_CFA_REGISTER(esp)
1198
1199    // Pending exceptions possible.
1200    mov %fs:THREAD_EXCEPTION_OFFSET, %ebx
1201    testl %ebx, %ebx
1202    jnz .Lexception_in_native
1203
1204    // Tear down the callee-save frame.
1205    addl LITERAL(4), %esp     // Remove padding
1206    CFI_ADJUST_CFA_OFFSET(-4)
1207    POP ecx
1208    addl LITERAL(4), %esp     // Avoid edx, as it may be part of the result.
1209    CFI_ADJUST_CFA_OFFSET(-4)
1210    POP ebx
1211    POP ebp  // Restore callee saves
1212    POP esi
1213    POP edi
1214    // store into fpr, for when it's a fpr return...
1215    movd %eax, %xmm0
1216    movd %edx, %xmm1
1217    punpckldq %xmm1, %xmm0
1218    ret
1219.Lentry_error:
1220    movl %ebp, %esp
1221    CFI_DEF_CFA_REGISTER(esp)
1222.Lexception_in_native:
1223    RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
1224    DELIVER_PENDING_EXCEPTION
1225END_FUNCTION art_quick_generic_jni_trampoline
1226
1227DEFINE_FUNCTION art_quick_to_interpreter_bridge
1228    SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME   // save frame
1229    mov %esp, %edx                // remember SP
1230    PUSH eax                      // alignment padding
1231    PUSH edx                      // pass SP
1232    pushl %fs:THREAD_SELF_OFFSET  // pass Thread::Current()
1233    CFI_ADJUST_CFA_OFFSET(4)
1234    PUSH eax                      // pass  method
1235    SETUP_GOT_NOSAVE              // clobbers EBX
1236    call PLT_SYMBOL(artQuickToInterpreterBridge)  // (method, Thread*, SP)
1237    movd %eax, %xmm0              // place return value also into floating point return value
1238    movd %edx, %xmm1
1239    punpckldq %xmm1, %xmm0
1240    addl LITERAL(16), %esp        // pop arguments
1241    CFI_ADJUST_CFA_OFFSET(-16)
1242    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
1243    RETURN_OR_DELIVER_PENDING_EXCEPTION    // return or deliver exception
1244END_FUNCTION art_quick_to_interpreter_bridge
1245
1246    /*
1247     * Routine that intercepts method calls and returns.
1248     */
1249DEFINE_FUNCTION art_quick_instrumentation_entry
1250    SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
1251    movl  %esp, %edx              // Save SP.
1252    PUSH eax                      // Save eax which will be clobbered by the callee-save method.
1253    subl LITERAL(8), %esp         // Align stack.
1254    CFI_ADJUST_CFA_OFFSET(8)
1255    pushl 40(%esp)                // Pass LR.
1256    CFI_ADJUST_CFA_OFFSET(4)
1257    PUSH edx                      // Pass SP.
1258    pushl %fs:THREAD_SELF_OFFSET  // Pass Thread::Current().
1259    CFI_ADJUST_CFA_OFFSET(4)
1260    PUSH ecx                      // Pass receiver.
1261    PUSH eax                      // Pass Method*.
1262    SETUP_GOT_NOSAVE              // clobbers EBX
1263    call PLT_SYMBOL(artInstrumentationMethodEntryFromCode) // (Method*, Object*, Thread*, SP, LR)
1264    addl LITERAL(28), %esp        // Pop arguments upto saved Method*.
1265    movl 28(%esp), %edi           // Restore edi.
1266    movl %eax, 28(%esp)           // Place code* over edi, just under return pc.
1267    movl SYMBOL(art_quick_instrumentation_exit)@GOT(%ebx), %ebx
1268    movl %ebx, 32(%esp)
1269                                  // Place instrumentation exit as return pc.
1270    movl (%esp), %eax             // Restore eax.
1271    movl 8(%esp), %ecx            // Restore ecx.
1272    movl 12(%esp), %edx           // Restore edx.
1273    movl 16(%esp), %ebx           // Restore ebx.
1274    movl 20(%esp), %ebp           // Restore ebp.
1275    movl 24(%esp), %esi           // Restore esi.
1276    addl LITERAL(28), %esp        // Wind stack back upto code*.
1277    ret                           // Call method (and pop).
1278END_FUNCTION art_quick_instrumentation_entry
1279
1280DEFINE_FUNCTION art_quick_instrumentation_exit
1281    pushl LITERAL(0)              // Push a fake return PC as there will be none on the stack.
1282    SETUP_REF_ONLY_CALLEE_SAVE_FRAME
1283    mov  %esp, %ecx               // Remember SP
1284    subl LITERAL(8), %esp         // Save float return value.
1285    CFI_ADJUST_CFA_OFFSET(8)
1286    movq %xmm0, (%esp)
1287    PUSH edx                      // Save gpr return value.
1288    PUSH eax
1289    subl LITERAL(16), %esp        // Align stack
1290    CFI_ADJUST_CFA_OFFSET(16)
1291    movq %xmm0, (%esp)            // Pass float return value.
1292    PUSH edx                      // Pass gpr return value.
1293    PUSH eax
1294    PUSH ecx                      // Pass SP.
1295    pushl %fs:THREAD_SELF_OFFSET  // Pass Thread::Current.
1296    CFI_ADJUST_CFA_OFFSET(4)
1297    SETUP_GOT_NOSAVE              // clobbers EBX
1298    call PLT_SYMBOL(artInstrumentationMethodExitFromCode)  // (Thread*, SP, gpr_result, fpr_result)
1299    mov   %eax, %ecx              // Move returned link register.
1300    addl LITERAL(32), %esp        // Pop arguments.
1301    CFI_ADJUST_CFA_OFFSET(-32)
1302    movl %edx, %ebx               // Move returned link register for deopt
1303                                  // (ebx is pretending to be our LR).
1304    POP eax                       // Restore gpr return value.
1305    POP edx
1306    movq (%esp), %xmm0            // Restore fpr return value.
1307    addl LITERAL(8), %esp
1308    CFI_ADJUST_CFA_OFFSET(-8)
1309    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
1310    addl LITERAL(4), %esp         // Remove fake return pc.
1311    jmp   *%ecx                   // Return.
1312END_FUNCTION art_quick_instrumentation_exit
1313
1314    /*
1315     * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1316     * will long jump to the upcall with a special exception of -1.
1317     */
1318DEFINE_FUNCTION art_quick_deoptimize
1319    pushl %ebx                    // Fake that we were called.
1320    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1321    mov  %esp, %ecx               // Remember SP.
1322    subl LITERAL(8), %esp         // Align stack.
1323    CFI_ADJUST_CFA_OFFSET(8)
1324    PUSH ecx                      // Pass SP.
1325    pushl %fs:THREAD_SELF_OFFSET  // Pass Thread::Current().
1326    CFI_ADJUST_CFA_OFFSET(4)
1327    SETUP_GOT_NOSAVE              // clobbers EBX
1328    call PLT_SYMBOL(artDeoptimize)  // artDeoptimize(Thread*, SP)
1329    int3                          // Unreachable.
1330END_FUNCTION art_quick_deoptimize
1331
1332    /*
1333     * String's compareTo.
1334     *
1335     * On entry:
1336     *    eax:   this string object (known non-null)
1337     *    ecx:   comp string object (known non-null)
1338     */
1339DEFINE_FUNCTION art_quick_string_compareto
1340    PUSH esi                    // push callee save reg
1341    PUSH edi                    // push callee save reg
1342    mov STRING_COUNT_OFFSET(%eax), %edx
1343    mov STRING_COUNT_OFFSET(%ecx), %ebx
1344    mov STRING_VALUE_OFFSET(%eax), %esi
1345    mov STRING_VALUE_OFFSET(%ecx), %edi
1346    mov STRING_OFFSET_OFFSET(%eax), %eax
1347    mov STRING_OFFSET_OFFSET(%ecx), %ecx
1348    /* Build pointers to the start of string data */
1349    lea  STRING_DATA_OFFSET(%esi, %eax, 2), %esi
1350    lea  STRING_DATA_OFFSET(%edi, %ecx, 2), %edi
1351    /* Calculate min length and count diff */
1352    mov   %edx, %ecx
1353    mov   %edx, %eax
1354    subl  %ebx, %eax
1355    cmovg %ebx, %ecx
1356    /*
1357     * At this point we have:
1358     *   eax: value to return if first part of strings are equal
1359     *   ecx: minimum among the lengths of the two strings
1360     *   esi: pointer to this string data
1361     *   edi: pointer to comp string data
1362     */
1363    jecxz .Lkeep_length
1364    repe cmpsw                    // find nonmatching chars in [%esi] and [%edi], up to length %ecx
1365    jne .Lnot_equal
1366.Lkeep_length:
1367    POP edi                       // pop callee save reg
1368    POP esi                       // pop callee save reg
1369    ret
1370    .balign 16
1371.Lnot_equal:
1372    movzwl  -2(%esi), %eax        // get last compared char from this string
1373    movzwl  -2(%edi), %ecx        // get last compared char from comp string
1374    subl  %ecx, %eax              // return the difference
1375    POP edi                       // pop callee save reg
1376    POP esi                       // pop callee save reg
1377    ret
1378END_FUNCTION art_quick_string_compareto
1379
1380    // TODO: implement these!
1381UNIMPLEMENTED art_quick_memcmp16
1382