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