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