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