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