blob: c6e704a9cd8d55f604f14bbc9e45196b298198f2 [file] [log] [blame]
Elliott Hughes0f3c5532012-03-30 14:51:51 -07001/*
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
Ian Rogers7655f292013-07-29 11:07:13 -070017#include "asm_support_x86.S"
Elliott Hughes5e284222012-04-04 13:38:03 -070018
Dave Allisonbbb32c22013-11-05 18:25:18 -080019// For x86, the CFA is esp+4, the address above the pushed return address on the stack.
20
Ian Rogers57b86d42012-03-27 16:05:41 -070021 /*
22 * Macro that sets up the callee save frame to conform with
Ian Rogers7caad772012-03-30 01:07:54 -070023 * Runtime::CreateCalleeSaveMethod(kSaveAll)
Ian Rogers57b86d42012-03-27 16:05:41 -070024 */
Elliott Hughes787ec202012-03-29 17:14:15 -070025MACRO0(SETUP_SAVE_ALL_CALLEE_SAVE_FRAME)
Ian Rogersaeeada42013-02-13 11:28:34 -080026 PUSH edi // Save callee saves (ebx is saved/restored by the upcall)
27 PUSH esi
28 PUSH ebp
Elliott Hughesea944212012-04-05 13:11:53 -070029 subl MACRO_LITERAL(16), %esp // Grow stack by 4 words, bottom word will hold Method*
Mark Mendell3f2d0312014-01-20 17:20:27 -080030 CFI_ADJUST_CFA_OFFSET(16)
Andreas Gampe5c1e4352014-04-21 19:28:24 -070031 // 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
Elliott Hughes787ec202012-03-29 17:14:15 -070036END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070037
Ian Rogers7caad772012-03-30 01:07:54 -070038 /*
39 * Macro that sets up the callee save frame to conform with
40 * Runtime::CreateCalleeSaveMethod(kRefsOnly)
41 */
42MACRO0(SETUP_REF_ONLY_CALLEE_SAVE_FRAME)
Ian Rogersaeeada42013-02-13 11:28:34 -080043 PUSH edi // Save callee saves (ebx is saved/restored by the upcall)
44 PUSH esi
45 PUSH ebp
Elliott Hughesea944212012-04-05 13:11:53 -070046 subl MACRO_LITERAL(16), %esp // Grow stack by 4 words, bottom word will hold Method*
Mark Mendell3f2d0312014-01-20 17:20:27 -080047 CFI_ADJUST_CFA_OFFSET(16)
Andreas Gampe5c1e4352014-04-21 19:28:24 -070048
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
Ian Rogers7caad772012-03-30 01:07:54 -070054END_MACRO
55
56MACRO0(RESTORE_REF_ONLY_CALLEE_SAVE_FRAME)
Ian Rogers47d00c02014-04-16 17:33:27 -070057 addl MACRO_LITERAL(16), %esp // Unwind stack up to saved values
Andreas Gampebf6b92a2014-03-05 16:11:04 -080058 CFI_ADJUST_CFA_OFFSET(-16)
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -070059 POP ebp // Restore callee saves (ebx is saved/restored by the upcall)
60 POP esi
61 POP edi
Elliott Hughes787ec202012-03-29 17:14:15 -070062END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070063
64 /*
65 * Macro that sets up the callee save frame to conform with
Ian Rogers7caad772012-03-30 01:07:54 -070066 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs)
Ian Rogers57b86d42012-03-27 16:05:41 -070067 */
jeffhao9dbb23e2012-05-18 17:03:57 -070068MACRO0(SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME)
Ian Rogersaeeada42013-02-13 11:28:34 -080069 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*
Andreas Gampe5c1e4352014-04-21 19:28:24 -070076
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
Elliott Hughes787ec202012-03-29 17:14:15 -070082END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070083
jeffhao9dbb23e2012-05-18 17:03:57 -070084MACRO0(RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME)
Elliott Hughesea944212012-04-05 13:11:53 -070085 addl MACRO_LITERAL(4), %esp // Remove padding
Mark Mendell3f2d0312014-01-20 17:20:27 -080086 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogersaeeada42013-02-13 11:28:34 -080087 POP ecx // Restore args except eax
88 POP edx
89 POP ebx
90 POP ebp // Restore callee saves
91 POP esi
92 POP edi
Elliott Hughes787ec202012-03-29 17:14:15 -070093END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070094
95 /*
96 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
97 * exception is Thread::Current()->exception_.
98 */
Elliott Hughes787ec202012-03-29 17:14:15 -070099MACRO0(DELIVER_PENDING_EXCEPTION)
Ian Rogers57b86d42012-03-27 16:05:41 -0700100 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save callee saves for throw
101 mov %esp, %ecx
102 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700103 subl MACRO_LITERAL(8), %esp // Alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -0800104 CFI_ADJUST_CFA_OFFSET(8)
Ian Rogersaeeada42013-02-13 11:28:34 -0800105 PUSH ecx // pass SP
Ian Rogers57b86d42012-03-27 16:05:41 -0700106 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800107 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe29b38412014-08-13 00:15:43 -0700108 call SYMBOL(artDeliverPendingExceptionFromCode) // artDeliverPendingExceptionFromCode(Thread*, SP)
jeffhao9dbb23e2012-05-18 17:03:57 -0700109 int3 // unreached
Elliott Hughes787ec202012-03-29 17:14:15 -0700110END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700111
Elliott Hughes787ec202012-03-29 17:14:15 -0700112MACRO2(NO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Ian Rogersc5f17732014-06-05 20:48:42 -0700113 DEFINE_FUNCTION RAW_VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700114 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
115 mov %esp, %ecx
116 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700117 subl MACRO_LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -0800118 CFI_ADJUST_CFA_OFFSET(8)
Ian Rogersaeeada42013-02-13 11:28:34 -0800119 PUSH ecx // pass SP
Ian Rogers55bd45f2012-04-04 17:31:20 -0700120 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800121 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe29b38412014-08-13 00:15:43 -0700122 call VAR(cxx_name, 1) // cxx_name(Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700123 int3 // unreached
Ian Rogersc5f17732014-06-05 20:48:42 -0700124 END_FUNCTION RAW_VAR(c_name, 0)
Elliott Hughes787ec202012-03-29 17:14:15 -0700125END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700126
Elliott Hughes787ec202012-03-29 17:14:15 -0700127MACRO2(ONE_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Ian Rogersc5f17732014-06-05 20:48:42 -0700128 DEFINE_FUNCTION RAW_VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700129 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
130 mov %esp, %ecx
131 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800132 PUSH eax // alignment padding
133 PUSH ecx // pass SP
Ian Rogers57b86d42012-03-27 16:05:41 -0700134 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800135 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -0800136 PUSH eax // pass arg1
Andreas Gampe29b38412014-08-13 00:15:43 -0700137 call VAR(cxx_name, 1) // cxx_name(arg1, Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700138 int3 // unreached
Ian Rogersc5f17732014-06-05 20:48:42 -0700139 END_FUNCTION RAW_VAR(c_name, 0)
Elliott Hughes787ec202012-03-29 17:14:15 -0700140END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700141
Elliott Hughes787ec202012-03-29 17:14:15 -0700142MACRO2(TWO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Ian Rogersc5f17732014-06-05 20:48:42 -0700143 DEFINE_FUNCTION RAW_VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700144 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
145 mov %esp, %edx
146 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800147 PUSH edx // pass SP
Ian Rogers57b86d42012-03-27 16:05:41 -0700148 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800149 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -0800150 PUSH ecx // pass arg2
151 PUSH eax // pass arg1
Andreas Gampe29b38412014-08-13 00:15:43 -0700152 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700153 int3 // unreached
Ian Rogersc5f17732014-06-05 20:48:42 -0700154 END_FUNCTION RAW_VAR(c_name, 0)
Elliott Hughes787ec202012-03-29 17:14:15 -0700155END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700156
157 /*
158 * Called by managed code to create and deliver a NullPointerException.
159 */
Ian Rogers468532e2013-08-05 10:56:33 -0700160NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700161
162 /*
163 * Called by managed code to create and deliver an ArithmeticException.
164 */
Ian Rogers468532e2013-08-05 10:56:33 -0700165NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700166
167 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700168 * Called by managed code to create and deliver a StackOverflowError.
169 */
Ian Rogers468532e2013-08-05 10:56:33 -0700170NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700171
172 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700173 * Called by managed code, saves callee saves and then calls artThrowException
174 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
175 */
Ian Rogers468532e2013-08-05 10:56:33 -0700176ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700177
178 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700179 * Called by managed code to create and deliver a NoSuchMethodError.
180 */
Ian Rogers468532e2013-08-05 10:56:33 -0700181ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700182
183 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700184 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
185 * index, arg2 holds limit.
186 */
Ian Rogers468532e2013-08-05 10:56:33 -0700187TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700188
189 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700190 * All generated callsites for interface invokes and invocation slow paths will load arguments
191 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
192 * the method_idx. This wrapper will save arg1-arg3, load the caller's Method*, align the
193 * stack and call the appropriate C helper.
194 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
195 *
196 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
197 * of the target Method* in r0 and method->code_ in r1.
198 *
199 * If unsuccessful, the helper will return NULL/NULL. There will bea pending exception in the
200 * thread and we branch to another stub to deliver it.
201 *
202 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
203 * pointing back to the original caller.
204 */
Elliott Hughes787ec202012-03-29 17:14:15 -0700205MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name)
Ian Rogersc5f17732014-06-05 20:48:42 -0700206 DEFINE_FUNCTION RAW_VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700207 // Set up the callee save frame to conform with Runtime::CreateCalleeSaveMethod(kRefsAndArgs)
208 // return address
Ian Rogersaeeada42013-02-13 11:28:34 -0800209 PUSH edi
210 PUSH esi
211 PUSH ebp
Dave Allisonbbb32c22013-11-05 18:25:18 -0800212 PUSH ebx // Save args
Ian Rogersaeeada42013-02-13 11:28:34 -0800213 PUSH edx
214 PUSH ecx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800215 PUSH eax // <-- callee save Method* to go here
Ian Rogers7caad772012-03-30 01:07:54 -0700216 movl %esp, %edx // remember SP
217 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700218 subl MACRO_LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -0800219 CFI_ADJUST_CFA_OFFSET(12)
Ian Rogersaeeada42013-02-13 11:28:34 -0800220 PUSH edx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700221 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800222 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers7caad772012-03-30 01:07:54 -0700223 pushl 32(%edx) // pass caller Method*
Mark Mendell3f2d0312014-01-20 17:20:27 -0800224 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -0800225 PUSH ecx // pass arg2
226 PUSH eax // pass arg1
Andreas Gampe29b38412014-08-13 00:15:43 -0700227 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, arg3, Thread*, SP)
Ian Rogers7caad772012-03-30 01:07:54 -0700228 movl %edx, %edi // save code pointer in EDI
Elliott Hughesea944212012-04-05 13:11:53 -0700229 addl MACRO_LITERAL(36), %esp // Pop arguments skip eax
Mark Mendell3f2d0312014-01-20 17:20:27 -0800230 CFI_ADJUST_CFA_OFFSET(-36)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800231 POP ecx // Restore args except eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800232 POP edx
233 POP ebx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800234 POP ebp // Restore callee saves
Ian Rogersaeeada42013-02-13 11:28:34 -0800235 POP esi
Ian Rogers7caad772012-03-30 01:07:54 -0700236 // Swap EDI callee save with code pointer.
237 xchgl %edi, (%esp)
238 testl %eax, %eax // Branch forward if exception pending.
239 jz 1f
240 // Tail call to intended method.
241 ret
2421:
jeffhao20b5c6c2012-05-21 14:15:18 -0700243 addl MACRO_LITERAL(4), %esp // Pop code pointer off stack
Mark Mendell3f2d0312014-01-20 17:20:27 -0800244 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers7caad772012-03-30 01:07:54 -0700245 DELIVER_PENDING_EXCEPTION
Ian Rogersc5f17732014-06-05 20:48:42 -0700246 END_FUNCTION RAW_VAR(c_name, 0)
Elliott Hughes787ec202012-03-29 17:14:15 -0700247END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700248
Logan Chien8dbb7082013-01-25 20:31:17 +0800249INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline, artInvokeInterfaceTrampoline
250INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700251
Logan Chien8dbb7082013-01-25 20:31:17 +0800252INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
253INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
254INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
255INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700256
Jeff Hao5d917302013-02-27 17:57:33 -0800257 /*
Jeff Hao6474d192013-03-26 14:08:09 -0700258 * Quick invocation stub.
259 * On entry:
260 * [sp] = return address
261 * [sp + 4] = method pointer
262 * [sp + 8] = argument array or NULL for no argument methods
263 * [sp + 12] = size of argument array in bytes
264 * [sp + 16] = (managed) thread pointer
265 * [sp + 20] = JValue* result
Ian Rogers0177e532014-02-11 16:30:46 -0800266 * [sp + 24] = shorty
Jeff Hao5d917302013-02-27 17:57:33 -0800267 */
268DEFINE_FUNCTION art_quick_invoke_stub
269 PUSH ebp // save ebp
270 PUSH ebx // save ebx
271 mov %esp, %ebp // copy value of stack pointer into base pointer
Mark Mendell3f2d0312014-01-20 17:20:27 -0800272 CFI_DEF_CFA_REGISTER(ebp)
Jeff Hao5d917302013-02-27 17:57:33 -0800273 mov 20(%ebp), %ebx // get arg array size
274 addl LITERAL(28), %ebx // reserve space for return addr, method*, ebx, and ebp in frame
Jeff Hao6474d192013-03-26 14:08:09 -0700275 andl LITERAL(0xFFFFFFF0), %ebx // align frame size to 16 bytes
Jeff Hao5d917302013-02-27 17:57:33 -0800276 subl LITERAL(12), %ebx // remove space for return address, ebx, and ebp
277 subl %ebx, %esp // reserve stack space for argument array
Mark Mendella9abe872014-01-10 05:52:01 -0800278 SETUP_GOT_NOSAVE // clobbers ebx (harmless here)
Jeff Hao5d917302013-02-27 17:57:33 -0800279 lea 4(%esp), %eax // use stack pointer + method ptr as dest for memcpy
280 pushl 20(%ebp) // push size of region to memcpy
281 pushl 16(%ebp) // push arg array as source of memcpy
282 pushl %eax // push stack pointer as destination of memcpy
Mark Mendell3f2d0312014-01-20 17:20:27 -0800283 call PLT_SYMBOL(memcpy) // (void*, const void*, size_t)
Jeff Hao5d917302013-02-27 17:57:33 -0800284 addl LITERAL(12), %esp // pop arguments to memcpy
285 movl LITERAL(0), (%esp) // store NULL for method*
286 mov 12(%ebp), %eax // move method pointer into eax
287 mov 4(%esp), %ecx // copy arg1 into ecx
288 mov 8(%esp), %edx // copy arg2 into edx
289 mov 12(%esp), %ebx // copy arg3 into ebx
Ian Rogersef7d42f2014-01-06 12:55:46 -0800290 call *METHOD_QUICK_CODE_OFFSET(%eax) // call the method
Jeff Hao5d917302013-02-27 17:57:33 -0800291 mov %ebp, %esp // restore stack pointer
Mark Mendell3f2d0312014-01-20 17:20:27 -0800292 CFI_DEF_CFA_REGISTER(esp)
Jeff Hao5d917302013-02-27 17:57:33 -0800293 POP ebx // pop ebx
294 POP ebp // pop ebp
295 mov 20(%esp), %ecx // get result pointer
Ian Rogers0177e532014-02-11 16:30:46 -0800296 mov %eax, (%ecx) // store the result assuming its a long, int or Object*
Jeff Hao5d917302013-02-27 17:57:33 -0800297 mov %edx, 4(%ecx) // store the other half of the result
Ian Rogers0177e532014-02-11 16:30:46 -0800298 mov 24(%esp), %edx // get the shorty
299 cmpb LITERAL(68), (%edx) // test if result type char == 'D'
Ian Rogers8016a122014-02-21 20:37:21 -0800300 je .Lreturn_double_quick
Ian Rogers0177e532014-02-11 16:30:46 -0800301 cmpb LITERAL(70), (%edx) // test if result type char == 'F'
Ian Rogers8016a122014-02-21 20:37:21 -0800302 je .Lreturn_float_quick
Jeff Hao6474d192013-03-26 14:08:09 -0700303 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800304.Lreturn_double_quick:
Jeff Hao5d917302013-02-27 17:57:33 -0800305 movsd %xmm0, (%ecx) // store the floating point result
306 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800307.Lreturn_float_quick:
Ian Rogers0177e532014-02-11 16:30:46 -0800308 movss %xmm0, (%ecx) // store the floating point result
309 ret
Jeff Hao5d917302013-02-27 17:57:33 -0800310END_FUNCTION art_quick_invoke_stub
311
Ian Rogersd36c52e2012-04-09 16:29:25 -0700312MACRO3(NO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersc5f17732014-06-05 20:48:42 -0700313 DEFINE_FUNCTION RAW_VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700314 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
315 mov %esp, %edx // remember SP
316 // Outgoing argument set up
317 subl MACRO_LITERAL(8), %esp // push padding
Mark Mendell3f2d0312014-01-20 17:20:27 -0800318 CFI_ADJUST_CFA_OFFSET(8)
Ian Rogersaeeada42013-02-13 11:28:34 -0800319 PUSH edx // pass SP
Ian Rogersd36c52e2012-04-09 16:29:25 -0700320 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800321 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe29b38412014-08-13 00:15:43 -0700322 call VAR(cxx_name, 1) // cxx_name(Thread*, SP)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700323 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800324 CFI_ADJUST_CFA_OFFSET(-16)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700325 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700326 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersc5f17732014-06-05 20:48:42 -0700327 END_FUNCTION RAW_VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700328END_MACRO
329
330MACRO3(ONE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersc5f17732014-06-05 20:48:42 -0700331 DEFINE_FUNCTION RAW_VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700332 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
333 mov %esp, %edx // remember SP
334 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800335 PUSH eax // push padding
336 PUSH edx // pass SP
Ian Rogersd36c52e2012-04-09 16:29:25 -0700337 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800338 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -0800339 PUSH eax // pass arg1
Andreas Gampe29b38412014-08-13 00:15:43 -0700340 call VAR(cxx_name, 1) // cxx_name(arg1, Thread*, SP)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700341 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800342 CFI_ADJUST_CFA_OFFSET(-16)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700343 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700344 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersc5f17732014-06-05 20:48:42 -0700345 END_FUNCTION RAW_VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700346END_MACRO
347
348MACRO3(TWO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersc5f17732014-06-05 20:48:42 -0700349 DEFINE_FUNCTION RAW_VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700350 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
351 mov %esp, %edx // remember SP
352 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800353 PUSH edx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700354 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800355 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -0800356 PUSH ecx // pass arg2
357 PUSH eax // pass arg1
Andreas Gampe29b38412014-08-13 00:15:43 -0700358 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, Thread*, SP)
Elliott Hughesea944212012-04-05 13:11:53 -0700359 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800360 CFI_ADJUST_CFA_OFFSET(-16)
Ian Rogers7caad772012-03-30 01:07:54 -0700361 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700362 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersc5f17732014-06-05 20:48:42 -0700363 END_FUNCTION RAW_VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700364END_MACRO
365
Ian Rogersd36c52e2012-04-09 16:29:25 -0700366MACRO3(THREE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersc5f17732014-06-05 20:48:42 -0700367 DEFINE_FUNCTION RAW_VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700368 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
369 mov %esp, %ebx // remember SP
370 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700371 subl MACRO_LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -0800372 CFI_ADJUST_CFA_OFFSET(12)
Ian Rogersaeeada42013-02-13 11:28:34 -0800373 PUSH ebx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700374 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800375 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -0800376 PUSH edx // pass arg3
377 PUSH ecx // pass arg2
378 PUSH eax // pass arg1
Andreas Gampe29b38412014-08-13 00:15:43 -0700379 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, arg3, Thread*, SP)
Elliott Hughesea944212012-04-05 13:11:53 -0700380 addl MACRO_LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800381 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers7caad772012-03-30 01:07:54 -0700382 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700383 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersc5f17732014-06-05 20:48:42 -0700384 END_FUNCTION RAW_VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700385END_MACRO
386
Mathieu Chartier590fee92013-09-13 13:46:47 -0700387MACRO0(RETURN_IF_RESULT_IS_NON_ZERO)
Ian Rogers7caad772012-03-30 01:07:54 -0700388 testl %eax, %eax // eax == 0 ?
Ian Rogersd36c52e2012-04-09 16:29:25 -0700389 jz 1f // if eax == 0 goto 1
390 ret // return
3911: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700392 DELIVER_PENDING_EXCEPTION
393END_MACRO
394
Ian Rogersd36c52e2012-04-09 16:29:25 -0700395MACRO0(RETURN_IF_EAX_ZERO)
396 testl %eax, %eax // eax == 0 ?
397 jnz 1f // if eax != 0 goto 1
398 ret // return
3991: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700400 DELIVER_PENDING_EXCEPTION
Ian Rogersd36c52e2012-04-09 16:29:25 -0700401END_MACRO
Ian Rogers7caad772012-03-30 01:07:54 -0700402
jeffhaod66a8752012-05-22 15:30:16 -0700403MACRO0(RETURN_OR_DELIVER_PENDING_EXCEPTION)
404 mov %fs:THREAD_EXCEPTION_OFFSET, %ebx // get exception field
405 testl %ebx, %ebx // ebx == 0 ?
406 jnz 1f // if ebx != 0 goto 1
407 ret // return
4081: // deliver exception on current thread
409 DELIVER_PENDING_EXCEPTION
410END_MACRO
411
Mathieu Chartier7410f292013-11-24 13:17:35 -0800412// Generate the allocation entrypoints for each allocator.
Mark Mendell3f2d0312014-01-20 17:20:27 -0800413// TODO: use arch/quick_alloc_entrypoints.S. Currently we don't as we need to use concatenation
414// macros to work around differences between OS/X's as and binutils as (OS/X lacks named arguments
415// to macros and the VAR macro won't concatenate arguments properly), this also breaks having
416// multi-line macros that use each other (hence using 1 macro per newline below).
417#define GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(c_suffix, cxx_suffix) \
418 TWO_ARG_DOWNCALL art_quick_alloc_object ## c_suffix, artAllocObjectFromCode ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800419#define GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(c_suffix, cxx_suffix) \
420 TWO_ARG_DOWNCALL art_quick_alloc_object_resolved ## c_suffix, artAllocObjectFromCodeResolved ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO
421#define GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(c_suffix, cxx_suffix) \
422 TWO_ARG_DOWNCALL art_quick_alloc_object_initialized ## c_suffix, artAllocObjectFromCodeInitialized ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO
Mark Mendell3f2d0312014-01-20 17:20:27 -0800423#define GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(c_suffix, cxx_suffix) \
424 TWO_ARG_DOWNCALL art_quick_alloc_object_with_access_check ## c_suffix, artAllocObjectFromCodeWithAccessCheck ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO
425#define GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(c_suffix, cxx_suffix) \
426 THREE_ARG_DOWNCALL art_quick_alloc_array ## c_suffix, artAllocArrayFromCode ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800427#define GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(c_suffix, cxx_suffix) \
428 THREE_ARG_DOWNCALL art_quick_alloc_array_resolved ## c_suffix, artAllocArrayFromCodeResolved ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO
Mark Mendell3f2d0312014-01-20 17:20:27 -0800429#define GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(c_suffix, cxx_suffix) \
430 THREE_ARG_DOWNCALL art_quick_alloc_array_with_access_check ## c_suffix, artAllocArrayFromCodeWithAccessCheck ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO
431#define GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(c_suffix, cxx_suffix) \
432 THREE_ARG_DOWNCALL art_quick_check_and_alloc_array ## c_suffix, artCheckAndAllocArrayFromCode ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO
433#define GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(c_suffix, cxx_suffix) \
434 THREE_ARG_DOWNCALL art_quick_check_and_alloc_array_with_access_check ## c_suffix, artCheckAndAllocArrayFromCodeWithAccessCheck ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO
435
436GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_dlmalloc, DlMalloc)
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800437GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_dlmalloc, DlMalloc)
438GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_dlmalloc, DlMalloc)
Mark Mendell3f2d0312014-01-20 17:20:27 -0800439GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_dlmalloc, DlMalloc)
440GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_dlmalloc, DlMalloc)
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800441GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_dlmalloc, DlMalloc)
Mark Mendell3f2d0312014-01-20 17:20:27 -0800442GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_dlmalloc, DlMalloc)
443GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_dlmalloc, DlMalloc)
444GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_dlmalloc, DlMalloc)
445
446GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_dlmalloc_instrumented, DlMallocInstrumented)
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800447GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_dlmalloc_instrumented, DlMallocInstrumented)
448GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_dlmalloc_instrumented, DlMallocInstrumented)
Mark Mendell3f2d0312014-01-20 17:20:27 -0800449GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_dlmalloc_instrumented, DlMallocInstrumented)
450GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_dlmalloc_instrumented, DlMallocInstrumented)
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800451GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_dlmalloc_instrumented, DlMallocInstrumented)
Mark Mendell3f2d0312014-01-20 17:20:27 -0800452GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_dlmalloc_instrumented, DlMallocInstrumented)
453GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_dlmalloc_instrumented, DlMallocInstrumented)
454GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_dlmalloc_instrumented, DlMallocInstrumented)
455
456GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc)
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800457GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_rosalloc, RosAlloc)
458GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_rosalloc, RosAlloc)
Mark Mendell3f2d0312014-01-20 17:20:27 -0800459GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_rosalloc, RosAlloc)
460GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_rosalloc, RosAlloc)
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800461GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_rosalloc, RosAlloc)
Mark Mendell3f2d0312014-01-20 17:20:27 -0800462GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_rosalloc, RosAlloc)
463GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_rosalloc, RosAlloc)
464GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_rosalloc, RosAlloc)
465
466GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc_instrumented, RosAllocInstrumented)
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800467GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_rosalloc_instrumented, RosAllocInstrumented)
468GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_rosalloc_instrumented, RosAllocInstrumented)
Mark Mendell3f2d0312014-01-20 17:20:27 -0800469GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_rosalloc_instrumented, RosAllocInstrumented)
470GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_rosalloc_instrumented, RosAllocInstrumented)
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800471GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_rosalloc_instrumented, RosAllocInstrumented)
Mark Mendell3f2d0312014-01-20 17:20:27 -0800472GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_rosalloc_instrumented, RosAllocInstrumented)
473GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_rosalloc_instrumented, RosAllocInstrumented)
474GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_rosalloc_instrumented, RosAllocInstrumented)
475
476GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_bump_pointer, BumpPointer)
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800477GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_bump_pointer, BumpPointer)
478GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_bump_pointer, BumpPointer)
Mark Mendell3f2d0312014-01-20 17:20:27 -0800479GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_bump_pointer, BumpPointer)
480GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_bump_pointer, BumpPointer)
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800481GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_bump_pointer, BumpPointer)
Mark Mendell3f2d0312014-01-20 17:20:27 -0800482GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_bump_pointer, BumpPointer)
483GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_bump_pointer, BumpPointer)
484GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_bump_pointer, BumpPointer)
485
486GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_bump_pointer_instrumented, BumpPointerInstrumented)
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800487GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_bump_pointer_instrumented, BumpPointerInstrumented)
488GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_bump_pointer_instrumented, BumpPointerInstrumented)
Mark Mendell3f2d0312014-01-20 17:20:27 -0800489GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_bump_pointer_instrumented, BumpPointerInstrumented)
490GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_bump_pointer_instrumented, BumpPointerInstrumented)
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800491GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_bump_pointer_instrumented, BumpPointerInstrumented)
Mark Mendell3f2d0312014-01-20 17:20:27 -0800492GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_bump_pointer_instrumented, BumpPointerInstrumented)
493GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_bump_pointer_instrumented, BumpPointerInstrumented)
494GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_bump_pointer_instrumented, BumpPointerInstrumented)
495
496GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB)
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800497GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_tlab, TLAB)
498GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_tlab, TLAB)
Mark Mendell3f2d0312014-01-20 17:20:27 -0800499GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_tlab, TLAB)
500GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_tlab, TLAB)
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800501GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_tlab, TLAB)
Mark Mendell3f2d0312014-01-20 17:20:27 -0800502GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_tlab, TLAB)
503GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_tlab, TLAB)
504GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_tlab, TLAB)
505
506GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab_instrumented, TLABInstrumented)
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800507GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_tlab_instrumented, TLABInstrumented)
508GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_tlab_instrumented, TLABInstrumented)
Mark Mendell3f2d0312014-01-20 17:20:27 -0800509GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_tlab_instrumented, TLABInstrumented)
510GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_tlab_instrumented, TLABInstrumented)
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800511GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_tlab_instrumented, TLABInstrumented)
Mark Mendell3f2d0312014-01-20 17:20:27 -0800512GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_tlab_instrumented, TLABInstrumented)
513GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_tlab_instrumented, TLABInstrumented)
514GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_tlab_instrumented, TLABInstrumented)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700515
Mathieu Chartier590fee92013-09-13 13:46:47 -0700516TWO_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO
517TWO_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO
518TWO_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO
519TWO_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO
Ian Rogersd36c52e2012-04-09 16:29:25 -0700520
Ian Rogers468532e2013-08-05 10:56:33 -0700521TWO_ARG_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_EAX_ZERO
Ian Rogers7caad772012-03-30 01:07:54 -0700522
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700523DEFINE_FUNCTION art_quick_lock_object
524 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -0800525 jz .Lslow_lock
526.Lretry_lock:
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700527 movl LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Mathieu Chartierad2541a2013-10-25 10:05:23 -0700528 test LITERAL(0xC0000000), %ecx // test the 2 high bits.
Ian Rogers8016a122014-02-21 20:37:21 -0800529 jne .Lslow_lock // slow path if either of the two high bits are set.
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700530 movl %fs:THREAD_ID_OFFSET, %edx // edx := thread id
531 test %ecx, %ecx
Ian Rogers8016a122014-02-21 20:37:21 -0800532 jnz .Lalready_thin // lock word contains a thin lock
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700533 // unlocked case - %edx holds thread id with count of 0
534 movl %eax, %ecx // remember object in case of retry
535 xor %eax, %eax // eax == 0 for comparison with lock word in cmpxchg
536 lock cmpxchg %edx, LOCK_WORD_OFFSET(%ecx)
Ian Rogers8016a122014-02-21 20:37:21 -0800537 jnz .Lcmpxchg_fail // cmpxchg failed retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700538 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800539.Lcmpxchg_fail:
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700540 movl %ecx, %eax // restore eax
Ian Rogers8016a122014-02-21 20:37:21 -0800541 jmp .Lretry_lock
542.Lalready_thin:
Serguei Katkov8ef84af2014-04-03 15:17:26 +0700543 cmpw %cx, %dx // do we hold the lock already?
Ian Rogers8016a122014-02-21 20:37:21 -0800544 jne .Lslow_lock
Serguei Katkov8ef84af2014-04-03 15:17:26 +0700545 addl LITERAL(65536), %ecx // increment recursion count
546 test LITERAL(0xC0000000), %ecx // overflowed if either of top two bits are set
Ian Rogers8016a122014-02-21 20:37:21 -0800547 jne .Lslow_lock // count overflowed so go slow
Serguei Katkov8ef84af2014-04-03 15:17:26 +0700548 movl %ecx, LOCK_WORD_OFFSET(%eax) // update lockword, cmpxchg not necessary as we hold lock
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700549 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800550.Lslow_lock:
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700551 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
552 mov %esp, %edx // remember SP
553 // Outgoing argument set up
554 PUSH eax // push padding
555 PUSH edx // pass SP
556 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800557 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700558 PUSH eax // pass object
Andreas Gampe29b38412014-08-13 00:15:43 -0700559 call SYMBOL(artLockObjectFromCode) // artLockObjectFromCode(object, Thread*, SP)
Mark Mendell3f2d0312014-01-20 17:20:27 -0800560 addl LITERAL(16), %esp // pop arguments
561 CFI_ADJUST_CFA_OFFSET(-16)
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700562 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
563 RETURN_IF_EAX_ZERO
564END_FUNCTION art_quick_lock_object
565
566DEFINE_FUNCTION art_quick_unlock_object
567 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -0800568 jz .Lslow_unlock
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700569 movl LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
570 movl %fs:THREAD_ID_OFFSET, %edx // edx := thread id
Serguei Katkove78d4e12014-04-07 10:14:08 +0700571 test LITERAL(0xC0000000), %ecx
572 jnz .Lslow_unlock // lock word contains a monitor
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700573 cmpw %cx, %dx // does the thread id match?
Ian Rogers8016a122014-02-21 20:37:21 -0800574 jne .Lslow_unlock
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700575 cmpl LITERAL(65536), %ecx
Ian Rogers8016a122014-02-21 20:37:21 -0800576 jae .Lrecursive_thin_unlock
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700577 movl LITERAL(0), LOCK_WORD_OFFSET(%eax)
578 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800579.Lrecursive_thin_unlock:
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700580 subl LITERAL(65536), %ecx
581 mov %ecx, LOCK_WORD_OFFSET(%eax)
582 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800583.Lslow_unlock:
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700584 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
585 mov %esp, %edx // remember SP
586 // Outgoing argument set up
587 PUSH eax // push padding
588 PUSH edx // pass SP
589 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800590 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700591 PUSH eax // pass object
Andreas Gampe29b38412014-08-13 00:15:43 -0700592 call SYMBOL(artUnlockObjectFromCode) // artUnlockObjectFromCode(object, Thread*, SP)
Mark Mendell3f2d0312014-01-20 17:20:27 -0800593 addl LITERAL(16), %esp // pop arguments
594 CFI_ADJUST_CFA_OFFSET(-16)
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700595 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
596 RETURN_IF_EAX_ZERO
597END_FUNCTION art_quick_unlock_object
598
Ian Rogers468532e2013-08-05 10:56:33 -0700599DEFINE_FUNCTION art_quick_is_assignable
Ian Rogersaeeada42013-02-13 11:28:34 -0800600 PUSH eax // alignment padding
Ian Rogersa9a82542013-10-04 11:17:26 -0700601 PUSH ecx // pass arg2 - obj->klass
602 PUSH eax // pass arg1 - checked class
Andreas Gampe29b38412014-08-13 00:15:43 -0700603 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700604 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800605 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogers7caad772012-03-30 01:07:54 -0700606 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700607END_FUNCTION art_quick_is_assignable
Ian Rogers7caad772012-03-30 01:07:54 -0700608
Ian Rogersa9a82542013-10-04 11:17:26 -0700609DEFINE_FUNCTION art_quick_check_cast
610 PUSH eax // alignment padding
611 PUSH ecx // pass arg2 - obj->klass
612 PUSH eax // pass arg1 - checked class
Andreas Gampe29b38412014-08-13 00:15:43 -0700613 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
Ian Rogersa9a82542013-10-04 11:17:26 -0700614 testl %eax, %eax
615 jz 1f // jump forward if not assignable
616 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800617 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogersa9a82542013-10-04 11:17:26 -0700618 ret
6191:
620 POP eax // pop arguments
621 POP ecx
622 addl LITERAL(4), %esp
Mark Mendell3f2d0312014-01-20 17:20:27 -0800623 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogersa9a82542013-10-04 11:17:26 -0700624 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
625 mov %esp, %edx
626 // Outgoing argument set up
627 PUSH edx // pass SP
628 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800629 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersa9a82542013-10-04 11:17:26 -0700630 PUSH ecx // pass arg2
631 PUSH eax // pass arg1
Andreas Gampe29b38412014-08-13 00:15:43 -0700632 call SYMBOL(artThrowClassCastException) // (Class* a, Class* b, Thread*, SP)
Ian Rogersa9a82542013-10-04 11:17:26 -0700633 int3 // unreached
634END_FUNCTION art_quick_check_cast
635
636 /*
637 * Entry from managed code for array put operations of objects where the value being stored
638 * needs to be checked for compatibility.
639 * eax = array, ecx = index, edx = value
640 */
641DEFINE_FUNCTION art_quick_aput_obj_with_null_and_bound_check
642 testl %eax, %eax
Dan Albert3bed41c2014-08-07 17:39:34 -0700643 jnz SYMBOL(art_quick_aput_obj_with_bound_check)
644 jmp SYMBOL(art_quick_throw_null_pointer_exception)
Ian Rogersa9a82542013-10-04 11:17:26 -0700645END_FUNCTION art_quick_aput_obj_with_null_and_bound_check
646
647DEFINE_FUNCTION art_quick_aput_obj_with_bound_check
648 movl ARRAY_LENGTH_OFFSET(%eax), %ebx
649 cmpl %ebx, %ecx
Dan Albert3bed41c2014-08-07 17:39:34 -0700650 jb SYMBOL(art_quick_aput_obj)
Ian Rogersa9a82542013-10-04 11:17:26 -0700651 mov %ecx, %eax
652 mov %ebx, %ecx
Dan Albert3bed41c2014-08-07 17:39:34 -0700653 jmp SYMBOL(art_quick_throw_array_bounds)
Ian Rogersa9a82542013-10-04 11:17:26 -0700654END_FUNCTION art_quick_aput_obj_with_bound_check
655
656DEFINE_FUNCTION art_quick_aput_obj
657 test %edx, %edx // store of null
Ian Rogers8016a122014-02-21 20:37:21 -0800658 jz .Ldo_aput_null
Ian Rogersa9a82542013-10-04 11:17:26 -0700659 movl CLASS_OFFSET(%eax), %ebx
660 movl CLASS_COMPONENT_TYPE_OFFSET(%ebx), %ebx
661 cmpl CLASS_OFFSET(%edx), %ebx // value's type == array's component type - trivial assignability
Ian Rogers8016a122014-02-21 20:37:21 -0800662 jne .Lcheck_assignability
663.Ldo_aput:
Ian Rogersa9a82542013-10-04 11:17:26 -0700664 movl %edx, OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
665 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
666 shrl LITERAL(7), %eax
667 movb %dl, (%edx, %eax)
668 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800669.Ldo_aput_null:
Ian Rogersa9a82542013-10-04 11:17:26 -0700670 movl %edx, OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
671 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800672.Lcheck_assignability:
Ian Rogersa9a82542013-10-04 11:17:26 -0700673 PUSH eax // save arguments
674 PUSH ecx
675 PUSH edx
676 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -0800677 CFI_ADJUST_CFA_OFFSET(8)
Ian Rogersa9a82542013-10-04 11:17:26 -0700678 pushl CLASS_OFFSET(%edx) // pass arg2 - type of the value to be stored
Mark Mendell3f2d0312014-01-20 17:20:27 -0800679 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersa9a82542013-10-04 11:17:26 -0700680 PUSH ebx // pass arg1 - component type of the array
Andreas Gampe29b38412014-08-13 00:15:43 -0700681 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b)
Ian Rogersa9a82542013-10-04 11:17:26 -0700682 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800683 CFI_ADJUST_CFA_OFFSET(-16)
Ian Rogersa9a82542013-10-04 11:17:26 -0700684 testl %eax, %eax
Ian Rogers8016a122014-02-21 20:37:21 -0800685 jz .Lthrow_array_store_exception
Ian Rogersa9a82542013-10-04 11:17:26 -0700686 POP edx
687 POP ecx
688 POP eax
689 movl %edx, OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4) // do the aput
690 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
691 shrl LITERAL(7), %eax
692 movb %dl, (%edx, %eax)
693 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800694.Lthrow_array_store_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -0700695 POP edx
696 POP ecx
697 POP eax
698 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
699 mov %esp, %ecx
700 // Outgoing argument set up
701 PUSH ecx // pass SP
702 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800703 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersa9a82542013-10-04 11:17:26 -0700704 PUSH edx // pass arg2 - value
705 PUSH eax // pass arg1 - array
Andreas Gampe29b38412014-08-13 00:15:43 -0700706 call SYMBOL(artThrowArrayStoreException) // (array, value, Thread*, SP)
Ian Rogersa9a82542013-10-04 11:17:26 -0700707 int3 // unreached
708END_FUNCTION art_quick_aput_obj
709
Logan Chien8dbb7082013-01-25 20:31:17 +0800710DEFINE_FUNCTION art_quick_memcpy
Mark Mendella9abe872014-01-10 05:52:01 -0800711 SETUP_GOT_NOSAVE // clobbers EBX
Ian Rogersaeeada42013-02-13 11:28:34 -0800712 PUSH edx // pass arg3
713 PUSH ecx // pass arg2
714 PUSH eax // pass arg1
Mark Mendell3f2d0312014-01-20 17:20:27 -0800715 call PLT_SYMBOL(memcpy) // (void*, const void*, size_t)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700716 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800717 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogers7caad772012-03-30 01:07:54 -0700718 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800719END_FUNCTION art_quick_memcpy
Ian Rogers7caad772012-03-30 01:07:54 -0700720
Logan Chien8dbb7082013-01-25 20:31:17 +0800721NO_ARG_DOWNCALL art_quick_test_suspend, artTestSuspendFromCode, ret
Ian Rogers7caad772012-03-30 01:07:54 -0700722
Ian Rogers468532e2013-08-05 10:56:33 -0700723DEFINE_FUNCTION art_quick_d2l
Ian Rogersaeeada42013-02-13 11:28:34 -0800724 PUSH eax // alignment padding
725 PUSH ecx // pass arg2 a.hi
726 PUSH eax // pass arg1 a.lo
Andreas Gampe29b38412014-08-13 00:15:43 -0700727 call SYMBOL(art_d2l) // (jdouble a)
jeffhao41005dd2012-05-09 17:58:52 -0700728 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800729 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -0700730 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700731END_FUNCTION art_quick_d2l
jeffhao41005dd2012-05-09 17:58:52 -0700732
Ian Rogers468532e2013-08-05 10:56:33 -0700733DEFINE_FUNCTION art_quick_f2l
jeffhao41005dd2012-05-09 17:58:52 -0700734 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -0800735 CFI_ADJUST_CFA_OFFSET(8)
Ian Rogersaeeada42013-02-13 11:28:34 -0800736 PUSH eax // pass arg1 a
Andreas Gampe29b38412014-08-13 00:15:43 -0700737 call SYMBOL(art_f2l) // (jfloat a)
jeffhao41005dd2012-05-09 17:58:52 -0700738 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800739 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -0700740 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700741END_FUNCTION art_quick_f2l
jeffhao41005dd2012-05-09 17:58:52 -0700742
Ian Rogers468532e2013-08-05 10:56:33 -0700743DEFINE_FUNCTION art_quick_ldiv
Ian Rogersa9a82542013-10-04 11:17:26 -0700744 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -0800745 CFI_ADJUST_CFA_OFFSET(12)
Ian Rogersaeeada42013-02-13 11:28:34 -0800746 PUSH ebx // pass arg4 b.hi
747 PUSH edx // pass arg3 b.lo
748 PUSH ecx // pass arg2 a.hi
Ian Rogersa9a82542013-10-04 11:17:26 -0700749 PUSH eax // pass arg1 a.lo
Andreas Gampe29b38412014-08-13 00:15:43 -0700750 call SYMBOL(artLdiv) // (jlong a, jlong b)
Ian Rogersa9a82542013-10-04 11:17:26 -0700751 addl LITERAL(28), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800752 CFI_ADJUST_CFA_OFFSET(-28)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700753 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700754END_FUNCTION art_quick_ldiv
Ian Rogers55bd45f2012-04-04 17:31:20 -0700755
Ian Rogersa9a82542013-10-04 11:17:26 -0700756DEFINE_FUNCTION art_quick_lmod
757 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -0800758 CFI_ADJUST_CFA_OFFSET(12)
Ian Rogersaeeada42013-02-13 11:28:34 -0800759 PUSH ebx // pass arg4 b.hi
760 PUSH edx // pass arg3 b.lo
761 PUSH ecx // pass arg2 a.hi
Ian Rogersa9a82542013-10-04 11:17:26 -0700762 PUSH eax // pass arg1 a.lo
Andreas Gampe29b38412014-08-13 00:15:43 -0700763 call SYMBOL(artLmod) // (jlong a, jlong b)
Ian Rogersa9a82542013-10-04 11:17:26 -0700764 addl LITERAL(28), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800765 CFI_ADJUST_CFA_OFFSET(-28)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700766 ret
Ian Rogersa9a82542013-10-04 11:17:26 -0700767END_FUNCTION art_quick_lmod
Ian Rogers55bd45f2012-04-04 17:31:20 -0700768
Ian Rogers468532e2013-08-05 10:56:33 -0700769DEFINE_FUNCTION art_quick_lmul
Ian Rogers5793fea2013-02-14 13:33:34 -0800770 imul %eax, %ebx // ebx = a.lo(eax) * b.hi(ebx)
771 imul %edx, %ecx // ecx = b.lo(edx) * a.hi(ecx)
772 mul %edx // edx:eax = a.lo(eax) * b.lo(edx)
773 add %ebx, %ecx
774 add %ecx, %edx // edx += (a.lo * b.hi) + (b.lo * a.hi)
jeffhao644d5312012-05-03 19:04:49 -0700775 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700776END_FUNCTION art_quick_lmul
jeffhao644d5312012-05-03 19:04:49 -0700777
Ian Rogers468532e2013-08-05 10:56:33 -0700778DEFINE_FUNCTION art_quick_lshl
jeffhao644d5312012-05-03 19:04:49 -0700779 // ecx:eax << edx
Ian Rogers141d6222012-04-05 12:23:06 -0700780 xchg %edx, %ecx
781 shld %cl,%eax,%edx
782 shl %cl,%eax
783 test LITERAL(32), %cl
784 jz 1f
785 mov %eax, %edx
786 xor %eax, %eax
7871:
788 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700789END_FUNCTION art_quick_lshl
Ian Rogers141d6222012-04-05 12:23:06 -0700790
Ian Rogers468532e2013-08-05 10:56:33 -0700791DEFINE_FUNCTION art_quick_lshr
jeffhao644d5312012-05-03 19:04:49 -0700792 // ecx:eax >> edx
Ian Rogers141d6222012-04-05 12:23:06 -0700793 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -0700794 shrd %cl,%edx,%eax
795 sar %cl,%edx
Ian Rogers141d6222012-04-05 12:23:06 -0700796 test LITERAL(32),%cl
797 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -0700798 mov %edx, %eax
799 sar LITERAL(31), %edx
Ian Rogers141d6222012-04-05 12:23:06 -07008001:
801 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700802END_FUNCTION art_quick_lshr
Ian Rogers141d6222012-04-05 12:23:06 -0700803
Ian Rogers468532e2013-08-05 10:56:33 -0700804DEFINE_FUNCTION art_quick_lushr
jeffhao644d5312012-05-03 19:04:49 -0700805 // ecx:eax >>> edx
Ian Rogers141d6222012-04-05 12:23:06 -0700806 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -0700807 shrd %cl,%edx,%eax
808 shr %cl,%edx
809 test LITERAL(32),%cl
Ian Rogers141d6222012-04-05 12:23:06 -0700810 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -0700811 mov %edx, %eax
812 xor %edx, %edx
Ian Rogers141d6222012-04-05 12:23:06 -07008131:
814 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700815END_FUNCTION art_quick_lushr
Ian Rogers141d6222012-04-05 12:23:06 -0700816
Ian Rogers468532e2013-08-05 10:56:33 -0700817DEFINE_FUNCTION art_quick_set32_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700818 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
819 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700820 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -0800821 CFI_ADJUST_CFA_OFFSET(8)
Ian Rogersaeeada42013-02-13 11:28:34 -0800822 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700823 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800824 CFI_ADJUST_CFA_OFFSET(4)
jeffhao9dbb23e2012-05-18 17:03:57 -0700825 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800826 PUSH ebx // pass referrer
827 PUSH edx // pass new_val
828 PUSH ecx // pass object
829 PUSH eax // pass field_idx
Andreas Gampe29b38412014-08-13 00:15:43 -0700830 call SYMBOL(artSet32InstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700831 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800832 CFI_ADJUST_CFA_OFFSET(-32)
jeffhao9dbb23e2012-05-18 17:03:57 -0700833 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
834 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700835END_FUNCTION art_quick_set32_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700836
Ian Rogers468532e2013-08-05 10:56:33 -0700837DEFINE_FUNCTION art_quick_set64_instance
Ian Rogersaeeada42013-02-13 11:28:34 -0800838 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao1ff4cd72012-05-21 11:17:48 -0700839 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -0800840 CFI_ADJUST_CFA_OFFSET(8)
Ian Rogersaeeada42013-02-13 11:28:34 -0800841 PUSH esp // pass SP-8
jeffhao1ff4cd72012-05-21 11:17:48 -0700842 addl LITERAL(8), (%esp) // fix SP on stack by adding 8
jeffhao9dbb23e2012-05-18 17:03:57 -0700843 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800844 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -0800845 PUSH ebx // pass high half of new_val
846 PUSH edx // pass low half of new_val
847 PUSH ecx // pass object
848 PUSH eax // pass field_idx
Andreas Gampe29b38412014-08-13 00:15:43 -0700849 call SYMBOL(artSet64InstanceFromCode) // (field_idx, Object*, new_val, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700850 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800851 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogersaeeada42013-02-13 11:28:34 -0800852 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700853 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700854END_FUNCTION art_quick_set64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700855
Ian Rogers468532e2013-08-05 10:56:33 -0700856DEFINE_FUNCTION art_quick_set_obj_instance
Ian Rogersaeeada42013-02-13 11:28:34 -0800857 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700858 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700859 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -0800860 CFI_ADJUST_CFA_OFFSET(8)
Ian Rogersaeeada42013-02-13 11:28:34 -0800861 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700862 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800863 CFI_ADJUST_CFA_OFFSET(4)
jeffhao9dbb23e2012-05-18 17:03:57 -0700864 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800865 PUSH ebx // pass referrer
866 PUSH edx // pass new_val
867 PUSH ecx // pass object
868 PUSH eax // pass field_idx
Andreas Gampe29b38412014-08-13 00:15:43 -0700869 call SYMBOL(artSetObjInstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700870 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800871 CFI_ADJUST_CFA_OFFSET(-32)
jeffhao9dbb23e2012-05-18 17:03:57 -0700872 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
873 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700874END_FUNCTION art_quick_set_obj_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700875
Ian Rogers468532e2013-08-05 10:56:33 -0700876DEFINE_FUNCTION art_quick_get32_instance
Ian Rogersaeeada42013-02-13 11:28:34 -0800877 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700878 mov %esp, %ebx // remember SP
879 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700880 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -0800881 CFI_ADJUST_CFA_OFFSET(12)
Ian Rogersaeeada42013-02-13 11:28:34 -0800882 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700883 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800884 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -0800885 PUSH edx // pass referrer
886 PUSH ecx // pass object
887 PUSH eax // pass field_idx
Andreas Gampe29b38412014-08-13 00:15:43 -0700888 call SYMBOL(artGet32InstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700889 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800890 CFI_ADJUST_CFA_OFFSET(-32)
jeffhao9dbb23e2012-05-18 17:03:57 -0700891 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700892 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700893END_FUNCTION art_quick_get32_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700894
Ian Rogers468532e2013-08-05 10:56:33 -0700895DEFINE_FUNCTION art_quick_get64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700896 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
897 mov %esp, %ebx // remember SP
898 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700899 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -0800900 CFI_ADJUST_CFA_OFFSET(12)
Ian Rogersaeeada42013-02-13 11:28:34 -0800901 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700902 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800903 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -0800904 PUSH edx // pass referrer
905 PUSH ecx // pass object
906 PUSH eax // pass field_idx
Andreas Gampe29b38412014-08-13 00:15:43 -0700907 call SYMBOL(artGet64InstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700908 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800909 CFI_ADJUST_CFA_OFFSET(-32)
jeffhao9dbb23e2012-05-18 17:03:57 -0700910 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700911 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700912END_FUNCTION art_quick_get64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700913
Ian Rogers468532e2013-08-05 10:56:33 -0700914DEFINE_FUNCTION art_quick_get_obj_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700915 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
916 mov %esp, %ebx // remember SP
917 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700918 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -0800919 CFI_ADJUST_CFA_OFFSET(12)
Ian Rogersaeeada42013-02-13 11:28:34 -0800920 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700921 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800922 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -0800923 PUSH edx // pass referrer
924 PUSH ecx // pass object
925 PUSH eax // pass field_idx
Andreas Gampe29b38412014-08-13 00:15:43 -0700926 call SYMBOL(artGetObjInstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700927 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800928 CFI_ADJUST_CFA_OFFSET(-32)
jeffhao9dbb23e2012-05-18 17:03:57 -0700929 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700930 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700931END_FUNCTION art_quick_get_obj_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700932
Ian Rogers468532e2013-08-05 10:56:33 -0700933DEFINE_FUNCTION art_quick_set32_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700934 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
935 mov %esp, %ebx // remember SP
936 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700937 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -0800938 CFI_ADJUST_CFA_OFFSET(12)
Ian Rogersaeeada42013-02-13 11:28:34 -0800939 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700940 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800941 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -0800942 PUSH edx // pass referrer
943 PUSH ecx // pass new_val
944 PUSH eax // pass field_idx
Andreas Gampe29b38412014-08-13 00:15:43 -0700945 call SYMBOL(artSet32StaticFromCode) // (field_idx, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700946 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800947 CFI_ADJUST_CFA_OFFSET(-32)
jeffhao9dbb23e2012-05-18 17:03:57 -0700948 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
949 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700950END_FUNCTION art_quick_set32_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700951
Ian Rogers468532e2013-08-05 10:56:33 -0700952DEFINE_FUNCTION art_quick_set64_static
Ian Rogersaeeada42013-02-13 11:28:34 -0800953 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700954 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700955 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -0800956 CFI_ADJUST_CFA_OFFSET(8)
Ian Rogersaeeada42013-02-13 11:28:34 -0800957 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700958 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800959 CFI_ADJUST_CFA_OFFSET(4)
jeffhao9dbb23e2012-05-18 17:03:57 -0700960 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800961 PUSH edx // pass high half of new_val
962 PUSH ecx // pass low half of new_val
963 PUSH ebx // pass referrer
964 PUSH eax // pass field_idx
Andreas Gampe29b38412014-08-13 00:15:43 -0700965 call SYMBOL(artSet64StaticFromCode) // (field_idx, referrer, new_val, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700966 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800967 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogersaeeada42013-02-13 11:28:34 -0800968 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700969 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700970END_FUNCTION art_quick_set64_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700971
Ian Rogers468532e2013-08-05 10:56:33 -0700972DEFINE_FUNCTION art_quick_set_obj_static
Ian Rogersaeeada42013-02-13 11:28:34 -0800973 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700974 mov %esp, %ebx // remember SP
975 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700976 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -0800977 CFI_ADJUST_CFA_OFFSET(12)
Ian Rogersaeeada42013-02-13 11:28:34 -0800978 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700979 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800980 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -0800981 PUSH edx // pass referrer
982 PUSH ecx // pass new_val
983 PUSH eax // pass field_idx
Andreas Gampe29b38412014-08-13 00:15:43 -0700984 call SYMBOL(artSetObjStaticFromCode) // (field_idx, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700985 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800986 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700987 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700988END_FUNCTION art_quick_set_obj_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700989
Ian Rogers468532e2013-08-05 10:56:33 -0700990DEFINE_FUNCTION art_quick_get32_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700991 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
992 mov %esp, %edx // remember SP
993 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800994 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700995 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800996 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -0800997 PUSH ecx // pass referrer
998 PUSH eax // pass field_idx
Andreas Gampe29b38412014-08-13 00:15:43 -0700999 call SYMBOL(artGet32StaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -07001000 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001001 CFI_ADJUST_CFA_OFFSET(-16)
jeffhao9dbb23e2012-05-18 17:03:57 -07001002 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -07001003 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001004END_FUNCTION art_quick_get32_static
jeffhao9dbb23e2012-05-18 17:03:57 -07001005
Ian Rogers468532e2013-08-05 10:56:33 -07001006DEFINE_FUNCTION art_quick_get64_static
Ian Rogersaeeada42013-02-13 11:28:34 -08001007 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -07001008 mov %esp, %edx // remember SP
1009 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -08001010 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -07001011 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001012 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001013 PUSH ecx // pass referrer
1014 PUSH eax // pass field_idx
Andreas Gampe29b38412014-08-13 00:15:43 -07001015 call SYMBOL(artGet64StaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -07001016 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001017 CFI_ADJUST_CFA_OFFSET(-16)
jeffhao9dbb23e2012-05-18 17:03:57 -07001018 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -07001019 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001020END_FUNCTION art_quick_get64_static
jeffhao9dbb23e2012-05-18 17:03:57 -07001021
Ian Rogers468532e2013-08-05 10:56:33 -07001022DEFINE_FUNCTION art_quick_get_obj_static
jeffhao9dbb23e2012-05-18 17:03:57 -07001023 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
Ian Rogersaeeada42013-02-13 11:28:34 -08001026 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -07001027 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001028 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001029 PUSH ecx // pass referrer
1030 PUSH eax // pass field_idx
Andreas Gampe29b38412014-08-13 00:15:43 -07001031 call SYMBOL(artGetObjStaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -07001032 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001033 CFI_ADJUST_CFA_OFFSET(-16)
jeffhao9dbb23e2012-05-18 17:03:57 -07001034 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -07001035 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001036END_FUNCTION art_quick_get_obj_static
jeffhaod66a8752012-05-22 15:30:16 -07001037
Logan Chien8dbb7082013-01-25 20:31:17 +08001038DEFINE_FUNCTION art_quick_proxy_invoke_handler
Ian Rogers7db619b2013-01-16 18:35:48 -08001039 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save frame and Method*
Ian Rogersaeeada42013-02-13 11:28:34 -08001040 PUSH esp // pass SP
jeffhaod66a8752012-05-22 15:30:16 -07001041 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001042 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001043 PUSH ecx // pass receiver
1044 PUSH eax // pass proxy method
Andreas Gampe29b38412014-08-13 00:15:43 -07001045 call SYMBOL(artQuickProxyInvokeHandler) // (proxy method, receiver, Thread*, SP)
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001046 movd %eax, %xmm0 // place return value also into floating point return value
1047 movd %edx, %xmm1
1048 punpckldq %xmm1, %xmm0
jeffhaod66a8752012-05-22 15:30:16 -07001049 addl LITERAL(44), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001050 CFI_ADJUST_CFA_OFFSET(-44)
jeffhaod66a8752012-05-22 15:30:16 -07001051 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -08001052END_FUNCTION art_quick_proxy_invoke_handler
jeffhao9dbb23e2012-05-18 17:03:57 -07001053
Jeff Hao88474b42013-10-23 16:24:40 -07001054 /*
1055 * Called to resolve an imt conflict. xmm0 is a hidden argument that holds the target method's
1056 * dex method index.
1057 */
1058DEFINE_FUNCTION art_quick_imt_conflict_trampoline
1059 PUSH ecx
1060 movl 8(%esp), %eax // load caller Method*
1061 movl METHOD_DEX_CACHE_METHODS_OFFSET(%eax), %eax // load dex_cache_resolved_methods
1062 movd %xmm0, %ecx // get target method index stored in xmm0
1063 movl OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4), %eax // load the target method
1064 POP ecx
Dan Albert3bed41c2014-08-07 17:39:34 -07001065 jmp SYMBOL(art_quick_invoke_interface_trampoline)
Jeff Hao88474b42013-10-23 16:24:40 -07001066END_FUNCTION art_quick_imt_conflict_trampoline
1067
Ian Rogers468532e2013-08-05 10:56:33 -07001068DEFINE_FUNCTION art_quick_resolution_trampoline
1069 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
Tong Shen35e1e6a2014-07-30 09:31:22 -07001070 movl %esp, %edi
1071 PUSH EDI // pass SP. do not just PUSH ESP; that messes up unwinding
Ian Rogers468532e2013-08-05 10:56:33 -07001072 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001073 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers468532e2013-08-05 10:56:33 -07001074 PUSH ecx // pass receiver
1075 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001076 call SYMBOL(artQuickResolutionTrampoline) // (Method* called, receiver, Thread*, SP)
Ian Rogers468532e2013-08-05 10:56:33 -07001077 movl %eax, %edi // remember code pointer in EDI
1078 addl LITERAL(16), %esp // pop arguments
1079 test %eax, %eax // if code pointer is NULL goto deliver pending exception
1080 jz 1f
1081 POP eax // called method
1082 POP ecx // restore args
1083 POP edx
1084 POP ebx
1085 POP ebp // restore callee saves except EDI
1086 POP esi
1087 xchgl 0(%esp),%edi // restore EDI and place code pointer as only value on stack
1088 ret // tail call into method
10891:
1090 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
1091 DELIVER_PENDING_EXCEPTION
1092END_FUNCTION art_quick_resolution_trampoline
1093
Andreas Gampe29b38412014-08-13 00:15:43 -07001094DEFINE_FUNCTION_NO_HIDE art_quick_generic_jni_trampoline
Andreas Gampe779f8c92014-06-09 18:29:38 -07001095 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
1096 // This also stores the native ArtMethod reference at the bottom of the stack.
1097
1098 movl %esp, %ebp // save SP at callee-save frame
Andreas Gampec200a4a2014-06-16 18:39:09 -07001099 CFI_DEF_CFA_REGISTER(ebp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001100 subl LITERAL(5120), %esp
1101 // prepare for artQuickGenericJniTrampoline call
1102 // (Thread*, SP)
1103 // (esp) 4(esp) <= C calling convention
1104 // fs:... ebp <= where they are
1105 // Also: PLT, so need GOT in ebx.
1106
1107 subl LITERAL(8), %esp // Padding for 16B alignment.
1108 pushl %ebp // Pass SP (to ArtMethod).
1109 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001110 call SYMBOL(artQuickGenericJniTrampoline) // (Thread*, sp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001111
Andreas Gampec200a4a2014-06-16 18:39:09 -07001112 // The C call will have registered the complete save-frame on success.
1113 // The result of the call is:
1114 // eax: pointer to native code, 0 on error.
1115 // edx: pointer to the bottom of the used area of the alloca, can restore stack till there.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001116
Andreas Gampec200a4a2014-06-16 18:39:09 -07001117 // Check for error = 0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001118 test %eax, %eax
Andreas Gampec200a4a2014-06-16 18:39:09 -07001119 jz .Lentry_error
Andreas Gampe779f8c92014-06-09 18:29:38 -07001120
Andreas Gampec200a4a2014-06-16 18:39:09 -07001121 // Release part of the alloca.
1122 movl %edx, %esp
Andreas Gampe779f8c92014-06-09 18:29:38 -07001123
1124 // On x86 there are no registers passed, so nothing to pop here.
1125
1126 // Native call.
1127 call *%eax
1128
Andreas Gampe779f8c92014-06-09 18:29:38 -07001129 // result sign extension is handled in C code
1130 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07001131 // (Thread*, result, result_f)
1132 // (esp) 4(esp) 12(esp) <= C calling convention
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001133 // fs:... eax:edx fp0 <= where they are
Andreas Gampe779f8c92014-06-09 18:29:38 -07001134
Andreas Gampec200a4a2014-06-16 18:39:09 -07001135 subl LITERAL(20), %esp // Padding & pass float result.
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001136 fstpl (%esp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001137 pushl %edx // Pass int result.
1138 pushl %eax
Andreas Gampe779f8c92014-06-09 18:29:38 -07001139 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001140 call SYMBOL(artQuickGenericJniEndTrampoline)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001141
1142 // Tear down the alloca.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001143 movl %ebp, %esp
Andreas Gampe779f8c92014-06-09 18:29:38 -07001144 CFI_DEF_CFA_REGISTER(esp)
1145
1146 // Pending exceptions possible.
1147 mov %fs:THREAD_EXCEPTION_OFFSET, %ebx
1148 testl %ebx, %ebx
1149 jnz .Lexception_in_native
1150
1151 // Tear down the callee-save frame.
Ian Rogerse3d55812014-06-11 13:00:44 -07001152 addl LITERAL(4), %esp // Remove padding
Andreas Gampe779f8c92014-06-09 18:29:38 -07001153 CFI_ADJUST_CFA_OFFSET(-4)
1154 POP ecx
Ian Rogerse3d55812014-06-11 13:00:44 -07001155 addl LITERAL(4), %esp // Avoid edx, as it may be part of the result.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001156 CFI_ADJUST_CFA_OFFSET(-4)
1157 POP ebx
1158 POP ebp // Restore callee saves
1159 POP esi
1160 POP edi
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001161 // Quick expects the return value to be in xmm0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001162 movd %eax, %xmm0
1163 movd %edx, %xmm1
1164 punpckldq %xmm1, %xmm0
1165 ret
1166.Lentry_error:
Andreas Gampec200a4a2014-06-16 18:39:09 -07001167 movl %ebp, %esp
Andreas Gampe779f8c92014-06-09 18:29:38 -07001168 CFI_DEF_CFA_REGISTER(esp)
1169.Lexception_in_native:
1170 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
1171 DELIVER_PENDING_EXCEPTION
Andreas Gampe2da88232014-02-27 12:26:20 -08001172END_FUNCTION art_quick_generic_jni_trampoline
1173
Andreas Gampe29b38412014-08-13 00:15:43 -07001174DEFINE_FUNCTION_NO_HIDE art_quick_to_interpreter_bridge
Ian Rogers62d6c772013-02-27 08:32:07 -08001175 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save frame
Ian Rogersaeeada42013-02-13 11:28:34 -08001176 mov %esp, %edx // remember SP
1177 PUSH eax // alignment padding
1178 PUSH edx // pass SP
Ian Rogers7db619b2013-01-16 18:35:48 -08001179 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001180 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001181 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001182 call SYMBOL(artQuickToInterpreterBridge) // (method, Thread*, SP)
Ian Rogers7db619b2013-01-16 18:35:48 -08001183 movd %eax, %xmm0 // place return value also into floating point return value
1184 movd %edx, %xmm1
1185 punpckldq %xmm1, %xmm0
Mathieu Chartier19841522013-10-22 11:29:00 -07001186 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001187 CFI_ADJUST_CFA_OFFSET(-16)
Mathieu Chartier19841522013-10-22 11:29:00 -07001188 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
Ian Rogers7db619b2013-01-16 18:35:48 -08001189 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001190END_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001191
jeffhao7e4fcb82013-01-10 18:11:08 -08001192 /*
1193 * Routine that intercepts method calls and returns.
1194 */
Ian Rogers468532e2013-08-05 10:56:33 -07001195DEFINE_FUNCTION art_quick_instrumentation_entry
Ian Rogers62d6c772013-02-27 08:32:07 -08001196 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
1197 movl %esp, %edx // Save SP.
1198 PUSH eax // Save eax which will be clobbered by the callee-save method.
1199 subl LITERAL(8), %esp // Align stack.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001200 CFI_ADJUST_CFA_OFFSET(8)
Ian Rogers62d6c772013-02-27 08:32:07 -08001201 pushl 40(%esp) // Pass LR.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001202 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001203 PUSH edx // Pass SP.
1204 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08001205 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001206 PUSH ecx // Pass receiver.
1207 PUSH eax // Pass Method*.
Andreas Gampe29b38412014-08-13 00:15:43 -07001208 call SYMBOL(artInstrumentationMethodEntryFromCode) // (Method*, Object*, Thread*, SP, LR)
Elliott Hughes7ac7e322014-06-27 17:20:59 -07001209 addl LITERAL(28), %esp // Pop arguments upto saved Method*.
Ian Rogers62d6c772013-02-27 08:32:07 -08001210 movl 28(%esp), %edi // Restore edi.
1211 movl %eax, 28(%esp) // Place code* over edi, just under return pc.
Elliott Hughes7ac7e322014-06-27 17:20:59 -07001212 movl SYMBOL(art_quick_instrumentation_exit)@GOT(%ebx), %ebx
1213 movl %ebx, 32(%esp)
Ian Rogers62d6c772013-02-27 08:32:07 -08001214 // Place instrumentation exit as return pc.
1215 movl (%esp), %eax // Restore eax.
1216 movl 8(%esp), %ecx // Restore ecx.
1217 movl 12(%esp), %edx // Restore edx.
1218 movl 16(%esp), %ebx // Restore ebx.
1219 movl 20(%esp), %ebp // Restore ebp.
1220 movl 24(%esp), %esi // Restore esi.
1221 addl LITERAL(28), %esp // Wind stack back upto code*.
1222 ret // Call method (and pop).
Ian Rogers468532e2013-08-05 10:56:33 -07001223END_FUNCTION art_quick_instrumentation_entry
Ian Rogers62d6c772013-02-27 08:32:07 -08001224
Ian Rogers468532e2013-08-05 10:56:33 -07001225DEFINE_FUNCTION art_quick_instrumentation_exit
Ian Rogers62d6c772013-02-27 08:32:07 -08001226 pushl LITERAL(0) // Push a fake return PC as there will be none on the stack.
1227 SETUP_REF_ONLY_CALLEE_SAVE_FRAME
1228 mov %esp, %ecx // Remember SP
1229 subl LITERAL(8), %esp // Save float return value.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001230 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampefea29012014-07-23 10:05:02 -07001231 movq %xmm0, (%esp)
Ian Rogers62d6c772013-02-27 08:32:07 -08001232 PUSH edx // Save gpr return value.
1233 PUSH eax
Jeff Haocf2e7b02014-07-22 18:38:42 -07001234 subl LITERAL(16), %esp // Align stack
1235 CFI_ADJUST_CFA_OFFSET(16)
Andreas Gampefea29012014-07-23 10:05:02 -07001236 movq %xmm0, (%esp) // Pass float return value.
Ian Rogers62d6c772013-02-27 08:32:07 -08001237 PUSH edx // Pass gpr return value.
1238 PUSH eax
1239 PUSH ecx // Pass SP.
1240 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001241 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe29b38412014-08-13 00:15:43 -07001242 call SYMBOL(artInstrumentationMethodExitFromCode) // (Thread*, SP, gpr_result, fpr_result)
Ian Rogers62d6c772013-02-27 08:32:07 -08001243 mov %eax, %ecx // Move returned link register.
1244 addl LITERAL(32), %esp // Pop arguments.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001245 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers62d6c772013-02-27 08:32:07 -08001246 movl %edx, %ebx // Move returned link register for deopt
1247 // (ebx is pretending to be our LR).
1248 POP eax // Restore gpr return value.
1249 POP edx
Andreas Gampefea29012014-07-23 10:05:02 -07001250 movq (%esp), %xmm0 // Restore fpr return value.
Ian Rogers62d6c772013-02-27 08:32:07 -08001251 addl LITERAL(8), %esp
Mark Mendell3f2d0312014-01-20 17:20:27 -08001252 CFI_ADJUST_CFA_OFFSET(-8)
Ian Rogers62d6c772013-02-27 08:32:07 -08001253 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
1254 addl LITERAL(4), %esp // Remove fake return pc.
1255 jmp *%ecx // Return.
Ian Rogers468532e2013-08-05 10:56:33 -07001256END_FUNCTION art_quick_instrumentation_exit
jeffhao162fd332013-01-08 16:21:01 -08001257
jeffhao7e4fcb82013-01-10 18:11:08 -08001258 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001259 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1260 * will long jump to the upcall with a special exception of -1.
jeffhao7e4fcb82013-01-10 18:11:08 -08001261 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001262DEFINE_FUNCTION art_quick_deoptimize
Ian Rogers62d6c772013-02-27 08:32:07 -08001263 pushl %ebx // Fake that we were called.
Jeff Haoc1fcdf12013-04-11 13:34:01 -07001264 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
Ian Rogers62d6c772013-02-27 08:32:07 -08001265 mov %esp, %ecx // Remember SP.
1266 subl LITERAL(8), %esp // Align stack.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001267 CFI_ADJUST_CFA_OFFSET(8)
Ian Rogers62d6c772013-02-27 08:32:07 -08001268 PUSH ecx // Pass SP.
1269 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08001270 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe29b38412014-08-13 00:15:43 -07001271 call SYMBOL(artDeoptimize) // artDeoptimize(Thread*, SP)
Ian Rogers62d6c772013-02-27 08:32:07 -08001272 int3 // Unreachable.
Ian Rogersaeeada42013-02-13 11:28:34 -08001273END_FUNCTION art_quick_deoptimize
jeffhao162fd332013-01-08 16:21:01 -08001274
jeffhao86e46712012-08-08 17:30:59 -07001275 /*
jeffhao86e46712012-08-08 17:30:59 -07001276 * String's compareTo.
1277 *
1278 * On entry:
1279 * eax: this string object (known non-null)
1280 * ecx: comp string object (known non-null)
1281 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001282DEFINE_FUNCTION art_quick_string_compareto
Ian Rogersaeeada42013-02-13 11:28:34 -08001283 PUSH esi // push callee save reg
1284 PUSH edi // push callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001285 mov STRING_COUNT_OFFSET(%eax), %edx
1286 mov STRING_COUNT_OFFSET(%ecx), %ebx
1287 mov STRING_VALUE_OFFSET(%eax), %esi
1288 mov STRING_VALUE_OFFSET(%ecx), %edi
1289 mov STRING_OFFSET_OFFSET(%eax), %eax
1290 mov STRING_OFFSET_OFFSET(%ecx), %ecx
1291 /* Build pointers to the start of string data */
1292 lea STRING_DATA_OFFSET(%esi, %eax, 2), %esi
1293 lea STRING_DATA_OFFSET(%edi, %ecx, 2), %edi
1294 /* Calculate min length and count diff */
1295 mov %edx, %ecx
1296 mov %edx, %eax
1297 subl %ebx, %eax
1298 cmovg %ebx, %ecx
1299 /*
1300 * At this point we have:
1301 * eax: value to return if first part of strings are equal
1302 * ecx: minimum among the lengths of the two strings
1303 * esi: pointer to this string data
1304 * edi: pointer to comp string data
1305 */
Alexei Zavjalov4554bfd2014-02-26 17:28:35 +07001306 jecxz .Lkeep_length
jeffhao86e46712012-08-08 17:30:59 -07001307 repe cmpsw // find nonmatching chars in [%esi] and [%edi], up to length %ecx
Ian Rogers8016a122014-02-21 20:37:21 -08001308 jne .Lnot_equal
Alexei Zavjalov4554bfd2014-02-26 17:28:35 +07001309.Lkeep_length:
Ian Rogersaeeada42013-02-13 11:28:34 -08001310 POP edi // pop callee save reg
1311 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001312 ret
1313 .balign 16
Ian Rogers8016a122014-02-21 20:37:21 -08001314.Lnot_equal:
Ian Rogers1b09b092012-08-20 15:35:52 -07001315 movzwl -2(%esi), %eax // get last compared char from this string
1316 movzwl -2(%edi), %ecx // get last compared char from comp string
jeffhao86e46712012-08-08 17:30:59 -07001317 subl %ecx, %eax // return the difference
Ian Rogersaeeada42013-02-13 11:28:34 -08001318 POP edi // pop callee save reg
1319 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001320 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001321END_FUNCTION art_quick_string_compareto
jeffhao86e46712012-08-08 17:30:59 -07001322
Elliott Hughes787ec202012-03-29 17:14:15 -07001323 // TODO: implement these!
Logan Chien8dbb7082013-01-25 20:31:17 +08001324UNIMPLEMENTED art_quick_memcmp16