blob: 6be73d1aa160a314d40e186d7168d4e3dee71df6 [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
Ian Rogers57b86d42012-03-27 16:05:41 -070019 /*
20 * Macro that sets up the callee save frame to conform with
Ian Rogers7caad772012-03-30 01:07:54 -070021 * Runtime::CreateCalleeSaveMethod(kSaveAll)
Ian Rogers57b86d42012-03-27 16:05:41 -070022 */
Elliott Hughes787ec202012-03-29 17:14:15 -070023MACRO0(SETUP_SAVE_ALL_CALLEE_SAVE_FRAME)
Ian Rogersaeeada42013-02-13 11:28:34 -080024 PUSH edi // Save callee saves (ebx is saved/restored by the upcall)
25 PUSH esi
26 PUSH ebp
Elliott Hughesea944212012-04-05 13:11:53 -070027 subl MACRO_LITERAL(16), %esp // Grow stack by 4 words, bottom word will hold Method*
Ian Rogersaeeada42013-02-13 11:28:34 -080028 .cfi_adjust_cfa_offset 16
Elliott Hughes787ec202012-03-29 17:14:15 -070029END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070030
Ian Rogers7caad772012-03-30 01:07:54 -070031 /*
32 * Macro that sets up the callee save frame to conform with
33 * Runtime::CreateCalleeSaveMethod(kRefsOnly)
34 */
35MACRO0(SETUP_REF_ONLY_CALLEE_SAVE_FRAME)
Ian Rogersaeeada42013-02-13 11:28:34 -080036 PUSH edi // Save callee saves (ebx is saved/restored by the upcall)
37 PUSH esi
38 PUSH ebp
Elliott Hughesea944212012-04-05 13:11:53 -070039 subl MACRO_LITERAL(16), %esp // Grow stack by 4 words, bottom word will hold Method*
Ian Rogersaeeada42013-02-13 11:28:34 -080040 .cfi_adjust_cfa_offset 16
Ian Rogers7caad772012-03-30 01:07:54 -070041END_MACRO
42
43MACRO0(RESTORE_REF_ONLY_CALLEE_SAVE_FRAME)
Elliott Hughesea944212012-04-05 13:11:53 -070044 addl MACRO_LITERAL(28), %esp // Unwind stack up to return address
Ian Rogersaeeada42013-02-13 11:28:34 -080045 .cfi_adjust_cfa_offset -28
Elliott Hughes787ec202012-03-29 17:14:15 -070046END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070047
48 /*
49 * Macro that sets up the callee save frame to conform with
Ian Rogers7caad772012-03-30 01:07:54 -070050 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs)
Ian Rogers57b86d42012-03-27 16:05:41 -070051 */
jeffhao9dbb23e2012-05-18 17:03:57 -070052MACRO0(SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME)
Ian Rogersaeeada42013-02-13 11:28:34 -080053 PUSH edi // Save callee saves
54 PUSH esi
55 PUSH ebp
56 PUSH ebx // Save args
57 PUSH edx
58 PUSH ecx
59 PUSH eax // Align stack, eax will be clobbered by Method*
Elliott Hughes787ec202012-03-29 17:14:15 -070060END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070061
jeffhao9dbb23e2012-05-18 17:03:57 -070062MACRO0(RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME)
Elliott Hughesea944212012-04-05 13:11:53 -070063 addl MACRO_LITERAL(4), %esp // Remove padding
Ian Rogersaeeada42013-02-13 11:28:34 -080064 .cfi_adjust_cfa_offset -4
65 POP ecx // Restore args except eax
66 POP edx
67 POP ebx
68 POP ebp // Restore callee saves
69 POP esi
70 POP edi
Elliott Hughes787ec202012-03-29 17:14:15 -070071END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070072
73 /*
74 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
75 * exception is Thread::Current()->exception_.
76 */
Elliott Hughes787ec202012-03-29 17:14:15 -070077MACRO0(DELIVER_PENDING_EXCEPTION)
Ian Rogers57b86d42012-03-27 16:05:41 -070078 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save callee saves for throw
79 mov %esp, %ecx
80 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -070081 subl MACRO_LITERAL(8), %esp // Alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -080082 .cfi_adjust_cfa_offset 8
83 PUSH ecx // pass SP
Ian Rogers57b86d42012-03-27 16:05:41 -070084 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -080085 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -070086 call SYMBOL(artDeliverPendingExceptionFromCode) // artDeliverPendingExceptionFromCode(Thread*, SP)
87 int3 // unreached
Elliott Hughes787ec202012-03-29 17:14:15 -070088END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070089
Elliott Hughes787ec202012-03-29 17:14:15 -070090MACRO2(NO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Ian Rogersaeeada42013-02-13 11:28:34 -080091 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -070092 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
93 mov %esp, %ecx
94 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -070095 subl MACRO_LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -080096 .cfi_adjust_cfa_offset 8
97 PUSH ecx // pass SP
Ian Rogers55bd45f2012-04-04 17:31:20 -070098 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -080099 .cfi_adjust_cfa_offset 4
Elliott Hughes787ec202012-03-29 17:14:15 -0700100 call VAR(cxx_name, 1) // cxx_name(Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700101 int3 // unreached
Ian Rogersaeeada42013-02-13 11:28:34 -0800102 END_FUNCTION VAR(c_name, 0)
Elliott Hughes787ec202012-03-29 17:14:15 -0700103END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700104
Elliott Hughes787ec202012-03-29 17:14:15 -0700105MACRO2(ONE_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Ian Rogersaeeada42013-02-13 11:28:34 -0800106 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700107 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
108 mov %esp, %ecx
109 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800110 PUSH eax // alignment padding
111 PUSH ecx // pass SP
Ian Rogers57b86d42012-03-27 16:05:41 -0700112 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800113 .cfi_adjust_cfa_offset 4
114 PUSH eax // pass arg1
Elliott Hughes787ec202012-03-29 17:14:15 -0700115 call VAR(cxx_name, 1) // cxx_name(arg1, Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700116 int3 // unreached
Ian Rogersaeeada42013-02-13 11:28:34 -0800117 END_FUNCTION VAR(c_name, 0)
Elliott Hughes787ec202012-03-29 17:14:15 -0700118END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700119
Elliott Hughes787ec202012-03-29 17:14:15 -0700120MACRO2(TWO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Ian Rogersaeeada42013-02-13 11:28:34 -0800121 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700122 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
123 mov %esp, %edx
124 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800125 PUSH edx // pass SP
Ian Rogers57b86d42012-03-27 16:05:41 -0700126 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800127 .cfi_adjust_cfa_offset 4
128 PUSH ecx // pass arg2
129 PUSH eax // pass arg1
Ian Rogers7caad772012-03-30 01:07:54 -0700130 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700131 int3 // unreached
Ian Rogersaeeada42013-02-13 11:28:34 -0800132 END_FUNCTION VAR(c_name, 0)
Elliott Hughes787ec202012-03-29 17:14:15 -0700133END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700134
135 /*
136 * Called by managed code to create and deliver a NullPointerException.
137 */
Ian Rogers468532e2013-08-05 10:56:33 -0700138NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700139
140 /*
141 * Called by managed code to create and deliver an ArithmeticException.
142 */
Ian Rogers468532e2013-08-05 10:56:33 -0700143NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700144
145 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700146 * Called by managed code to create and deliver a StackOverflowError.
147 */
Ian Rogers468532e2013-08-05 10:56:33 -0700148NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700149
150 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700151 * Called by managed code, saves callee saves and then calls artThrowException
152 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
153 */
Ian Rogers468532e2013-08-05 10:56:33 -0700154ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700155
156 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700157 * Called by managed code to create and deliver a NoSuchMethodError.
158 */
Ian Rogers468532e2013-08-05 10:56:33 -0700159ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700160
161 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700162 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
163 * index, arg2 holds limit.
164 */
Ian Rogers468532e2013-08-05 10:56:33 -0700165TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700166
167 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700168 * All generated callsites for interface invokes and invocation slow paths will load arguments
169 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
170 * the method_idx. This wrapper will save arg1-arg3, load the caller's Method*, align the
171 * stack and call the appropriate C helper.
172 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
173 *
174 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
175 * of the target Method* in r0 and method->code_ in r1.
176 *
177 * If unsuccessful, the helper will return NULL/NULL. There will bea pending exception in the
178 * thread and we branch to another stub to deliver it.
179 *
180 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
181 * pointing back to the original caller.
182 */
Elliott Hughes787ec202012-03-29 17:14:15 -0700183MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name)
Ian Rogersaeeada42013-02-13 11:28:34 -0800184 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700185 // Set up the callee save frame to conform with Runtime::CreateCalleeSaveMethod(kRefsAndArgs)
186 // return address
Ian Rogersaeeada42013-02-13 11:28:34 -0800187 PUSH edi
188 PUSH esi
189 PUSH ebp
190 PUSH ebx
191 PUSH edx
192 PUSH ecx
193 PUSH eax // <-- callee save Method* to go here
Ian Rogers7caad772012-03-30 01:07:54 -0700194 movl %esp, %edx // remember SP
195 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700196 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800197 .cfi_adjust_cfa_offset 12
198 PUSH edx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700199 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800200 .cfi_adjust_cfa_offset 4
Ian Rogers7caad772012-03-30 01:07:54 -0700201 pushl 32(%edx) // pass caller Method*
Ian Rogersaeeada42013-02-13 11:28:34 -0800202 .cfi_adjust_cfa_offset 4
203 PUSH ecx // pass arg2
204 PUSH eax // pass arg1
Ian Rogers7caad772012-03-30 01:07:54 -0700205 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, arg3, Thread*, SP)
206 movl %edx, %edi // save code pointer in EDI
Elliott Hughesea944212012-04-05 13:11:53 -0700207 addl MACRO_LITERAL(36), %esp // Pop arguments skip eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800208 .cfi_adjust_cfa_offset -36
209 POP ecx // Restore args
210 POP edx
211 POP ebx
212 POP ebp // Restore callee saves.
213 POP esi
Ian Rogers7caad772012-03-30 01:07:54 -0700214 // Swap EDI callee save with code pointer.
215 xchgl %edi, (%esp)
216 testl %eax, %eax // Branch forward if exception pending.
217 jz 1f
218 // Tail call to intended method.
219 ret
2201:
jeffhao20b5c6c2012-05-21 14:15:18 -0700221 addl MACRO_LITERAL(4), %esp // Pop code pointer off stack
Ian Rogers5793fea2013-02-14 13:33:34 -0800222 .cfi_adjust_cfa_offset -4
Ian Rogers7caad772012-03-30 01:07:54 -0700223 DELIVER_PENDING_EXCEPTION
Ian Rogersaeeada42013-02-13 11:28:34 -0800224 END_FUNCTION VAR(c_name, 0)
Elliott Hughes787ec202012-03-29 17:14:15 -0700225END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700226
Logan Chien8dbb7082013-01-25 20:31:17 +0800227INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline, artInvokeInterfaceTrampoline
228INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700229
Logan Chien8dbb7082013-01-25 20:31:17 +0800230INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
231INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
232INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
233INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700234
Jeff Hao5d917302013-02-27 17:57:33 -0800235 /*
Jeff Hao6474d192013-03-26 14:08:09 -0700236 * Quick invocation stub.
237 * On entry:
238 * [sp] = return address
239 * [sp + 4] = method pointer
240 * [sp + 8] = argument array or NULL for no argument methods
241 * [sp + 12] = size of argument array in bytes
242 * [sp + 16] = (managed) thread pointer
243 * [sp + 20] = JValue* result
244 * [sp + 24] = result type char
Jeff Hao5d917302013-02-27 17:57:33 -0800245 */
246DEFINE_FUNCTION art_quick_invoke_stub
247 PUSH ebp // save ebp
248 PUSH ebx // save ebx
249 mov %esp, %ebp // copy value of stack pointer into base pointer
250 .cfi_def_cfa_register ebp
251 mov 20(%ebp), %ebx // get arg array size
252 addl LITERAL(28), %ebx // reserve space for return addr, method*, ebx, and ebp in frame
Jeff Hao6474d192013-03-26 14:08:09 -0700253 andl LITERAL(0xFFFFFFF0), %ebx // align frame size to 16 bytes
Jeff Hao5d917302013-02-27 17:57:33 -0800254 subl LITERAL(12), %ebx // remove space for return address, ebx, and ebp
255 subl %ebx, %esp // reserve stack space for argument array
256 lea 4(%esp), %eax // use stack pointer + method ptr as dest for memcpy
257 pushl 20(%ebp) // push size of region to memcpy
258 pushl 16(%ebp) // push arg array as source of memcpy
259 pushl %eax // push stack pointer as destination of memcpy
260 call SYMBOL(memcpy) // (void*, const void*, size_t)
261 addl LITERAL(12), %esp // pop arguments to memcpy
262 movl LITERAL(0), (%esp) // store NULL for method*
263 mov 12(%ebp), %eax // move method pointer into eax
264 mov 4(%esp), %ecx // copy arg1 into ecx
265 mov 8(%esp), %edx // copy arg2 into edx
266 mov 12(%esp), %ebx // copy arg3 into ebx
Ian Rogers225ade22013-03-18 17:45:44 -0700267 call *METHOD_CODE_OFFSET(%eax) // call the method
Jeff Hao5d917302013-02-27 17:57:33 -0800268 mov %ebp, %esp // restore stack pointer
269 POP ebx // pop ebx
270 POP ebp // pop ebp
271 mov 20(%esp), %ecx // get result pointer
Jeff Hao6474d192013-03-26 14:08:09 -0700272 cmpl LITERAL(68), 24(%esp) // test if result type char == 'D'
273 je return_double_quick
274 cmpl LITERAL(70), 24(%esp) // test if result type char == 'F'
275 je return_float_quick
Jeff Hao5d917302013-02-27 17:57:33 -0800276 mov %eax, (%ecx) // store the result
277 mov %edx, 4(%ecx) // store the other half of the result
Jeff Hao6474d192013-03-26 14:08:09 -0700278 ret
279return_double_quick:
280return_float_quick:
Jeff Hao5d917302013-02-27 17:57:33 -0800281 movsd %xmm0, (%ecx) // store the floating point result
282 ret
283END_FUNCTION art_quick_invoke_stub
284
Ian Rogersd36c52e2012-04-09 16:29:25 -0700285MACRO3(NO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800286 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700287 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
288 mov %esp, %edx // remember SP
289 // Outgoing argument set up
290 subl MACRO_LITERAL(8), %esp // push padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800291 .cfi_adjust_cfa_offset 8
292 PUSH edx // pass SP
Ian Rogersd36c52e2012-04-09 16:29:25 -0700293 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800294 .cfi_adjust_cfa_offset 4
Ian Rogersd36c52e2012-04-09 16:29:25 -0700295 call VAR(cxx_name, 1) // cxx_name(Thread*, SP)
296 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800297 .cfi_adjust_cfa_offset -16
Ian Rogersd36c52e2012-04-09 16:29:25 -0700298 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700299 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800300 END_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700301END_MACRO
302
303MACRO3(ONE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800304 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700305 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
306 mov %esp, %edx // remember SP
307 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800308 PUSH eax // push padding
309 PUSH edx // pass SP
Ian Rogersd36c52e2012-04-09 16:29:25 -0700310 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800311 .cfi_adjust_cfa_offset 4
312 PUSH eax // pass arg1
Ian Rogersd36c52e2012-04-09 16:29:25 -0700313 call VAR(cxx_name, 1) // cxx_name(arg1, Thread*, SP)
314 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800315 .cfi_adjust_cfa_offset -16
Ian Rogersd36c52e2012-04-09 16:29:25 -0700316 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700317 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800318 END_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700319END_MACRO
320
321MACRO3(TWO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800322 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700323 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
324 mov %esp, %edx // remember SP
325 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800326 PUSH edx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700327 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800328 .cfi_adjust_cfa_offset 4
329 PUSH ecx // pass arg2
330 PUSH eax // pass arg1
Ian Rogersd36c52e2012-04-09 16:29:25 -0700331 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, Thread*, SP)
Elliott Hughesea944212012-04-05 13:11:53 -0700332 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800333 .cfi_adjust_cfa_offset -16
Ian Rogers7caad772012-03-30 01:07:54 -0700334 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700335 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800336 END_FUNCTION VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700337END_MACRO
338
Ian Rogersd36c52e2012-04-09 16:29:25 -0700339MACRO3(THREE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800340 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700341 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
342 mov %esp, %ebx // remember SP
343 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700344 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800345 .cfi_adjust_cfa_offset 12
346 PUSH ebx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700347 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800348 .cfi_adjust_cfa_offset 4
349 PUSH edx // pass arg3
350 PUSH ecx // pass arg2
351 PUSH eax // pass arg1
Ian Rogersd36c52e2012-04-09 16:29:25 -0700352 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, arg3, Thread*, SP)
Elliott Hughesea944212012-04-05 13:11:53 -0700353 addl MACRO_LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800354 .cfi_adjust_cfa_offset -32
Ian Rogers7caad772012-03-30 01:07:54 -0700355 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700356 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800357 END_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700358END_MACRO
359
360MACRO0(RETURN_IF_EAX_NOT_ZERO)
Ian Rogers7caad772012-03-30 01:07:54 -0700361 testl %eax, %eax // eax == 0 ?
Ian Rogersd36c52e2012-04-09 16:29:25 -0700362 jz 1f // if eax == 0 goto 1
363 ret // return
3641: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700365 DELIVER_PENDING_EXCEPTION
366END_MACRO
367
Ian Rogersd36c52e2012-04-09 16:29:25 -0700368MACRO0(RETURN_IF_EAX_ZERO)
369 testl %eax, %eax // eax == 0 ?
370 jnz 1f // if eax != 0 goto 1
371 ret // return
3721: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700373 DELIVER_PENDING_EXCEPTION
Ian Rogersd36c52e2012-04-09 16:29:25 -0700374END_MACRO
Ian Rogers7caad772012-03-30 01:07:54 -0700375
jeffhaod66a8752012-05-22 15:30:16 -0700376MACRO0(RETURN_OR_DELIVER_PENDING_EXCEPTION)
377 mov %fs:THREAD_EXCEPTION_OFFSET, %ebx // get exception field
378 testl %ebx, %ebx // ebx == 0 ?
379 jnz 1f // if ebx != 0 goto 1
380 ret // return
3811: // deliver exception on current thread
382 DELIVER_PENDING_EXCEPTION
383END_MACRO
384
Ian Rogers468532e2013-08-05 10:56:33 -0700385TWO_ARG_DOWNCALL art_quick_alloc_object, artAllocObjectFromCode, RETURN_IF_EAX_NOT_ZERO
386TWO_ARG_DOWNCALL art_quick_alloc_object_with_access_check, artAllocObjectFromCodeWithAccessCheck, RETURN_IF_EAX_NOT_ZERO
387THREE_ARG_DOWNCALL art_quick_alloc_array, artAllocArrayFromCode, RETURN_IF_EAX_NOT_ZERO
388THREE_ARG_DOWNCALL art_quick_alloc_array_with_access_check, artAllocArrayFromCodeWithAccessCheck, RETURN_IF_EAX_NOT_ZERO
389THREE_ARG_DOWNCALL art_quick_check_and_alloc_array, artCheckAndAllocArrayFromCode, RETURN_IF_EAX_NOT_ZERO
390THREE_ARG_DOWNCALL art_quick_check_and_alloc_array_with_access_check, artCheckAndAllocArrayFromCodeWithAccessCheck, RETURN_IF_EAX_NOT_ZERO
Ian Rogersd36c52e2012-04-09 16:29:25 -0700391
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700392TWO_ARG_DOWNCALL art_quick_alloc_object_instrumented, artAllocObjectFromCodeInstrumented, RETURN_IF_EAX_NOT_ZERO
393TWO_ARG_DOWNCALL art_quick_alloc_object_with_access_check_instrumented, artAllocObjectFromCodeWithAccessCheckInstrumented, RETURN_IF_EAX_NOT_ZERO
394THREE_ARG_DOWNCALL art_quick_alloc_array_instrumented, artAllocArrayFromCodeInstrumented, RETURN_IF_EAX_NOT_ZERO
395THREE_ARG_DOWNCALL art_quick_alloc_array_with_access_check_instrumented, artAllocArrayFromCodeWithAccessCheckInstrumented, RETURN_IF_EAX_NOT_ZERO
396THREE_ARG_DOWNCALL art_quick_check_and_alloc_array_instrumented, artCheckAndAllocArrayFromCodeInstrumented, RETURN_IF_EAX_NOT_ZERO
397THREE_ARG_DOWNCALL art_quick_check_and_alloc_array_with_access_check_instrumented, artCheckAndAllocArrayFromCodeWithAccessCheckInstrumented, RETURN_IF_EAX_NOT_ZERO
398
Ian Rogers468532e2013-08-05 10:56:33 -0700399TWO_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_EAX_NOT_ZERO
400TWO_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_EAX_NOT_ZERO
401TWO_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_EAX_NOT_ZERO
402TWO_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_EAX_NOT_ZERO
Ian Rogersd36c52e2012-04-09 16:29:25 -0700403
Ian Rogers468532e2013-08-05 10:56:33 -0700404TWO_ARG_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_EAX_ZERO
Ian Rogers7caad772012-03-30 01:07:54 -0700405
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700406DEFINE_FUNCTION art_quick_lock_object
407 testl %eax, %eax // null check object/eax
408 jz slow_lock
409retry_lock:
410 movl LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
411 movl %fs:THREAD_ID_OFFSET, %edx // edx := thread id
412 test %ecx, %ecx
413 jb slow_lock // lock word contains a monitor
414 jnz already_thin // lock word contains a thin lock
415 // unlocked case - %edx holds thread id with count of 0
416 movl %eax, %ecx // remember object in case of retry
417 xor %eax, %eax // eax == 0 for comparison with lock word in cmpxchg
418 lock cmpxchg %edx, LOCK_WORD_OFFSET(%ecx)
419 jnz cmpxchg_fail // cmpxchg failed retry
420 ret
421cmpxchg_fail:
422 movl %ecx, %eax // restore eax
423 jmp retry_lock
424already_thin:
425 cmpw %ax, %dx // do we hold the lock already?
426 jne slow_lock
427 addl LITERAL(65536), %eax // increment recursion count
428 jb slow_lock // count overflowed so go slow
429 movl %eax, LOCK_WORD_OFFSET(%ecx) // update lockword, cmpxchg not necessary as we hold lock
430 ret
431slow_lock:
432 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
433 mov %esp, %edx // remember SP
434 // Outgoing argument set up
435 PUSH eax // push padding
436 PUSH edx // pass SP
437 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
438 .cfi_adjust_cfa_offset 4
439 PUSH eax // pass object
440 call artLockObjectFromCode // artLockObjectFromCode(object, Thread*, SP)
441 addl MACRO_LITERAL(16), %esp // pop arguments
442 .cfi_adjust_cfa_offset -16
443 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
444 RETURN_IF_EAX_ZERO
445END_FUNCTION art_quick_lock_object
446
447DEFINE_FUNCTION art_quick_unlock_object
448 testl %eax, %eax // null check object/eax
449 jz slow_unlock
450 movl LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
451 movl %fs:THREAD_ID_OFFSET, %edx // edx := thread id
452 test %ecx, %ecx
453 jb slow_unlock // lock word contains a monitor
454 cmpw %cx, %dx // does the thread id match?
455 jne slow_unlock
456 cmpl LITERAL(65536), %ecx
457 jae recursive_thin_unlock
458 movl LITERAL(0), LOCK_WORD_OFFSET(%eax)
459 ret
460recursive_thin_unlock:
461 subl LITERAL(65536), %ecx
462 mov %ecx, LOCK_WORD_OFFSET(%eax)
463 ret
464slow_unlock:
465 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
466 mov %esp, %edx // remember SP
467 // Outgoing argument set up
468 PUSH eax // push padding
469 PUSH edx // pass SP
470 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
471 .cfi_adjust_cfa_offset 4
472 PUSH eax // pass object
473 call artUnlockObjectFromCode // artUnlockObjectFromCode(object, Thread*, SP)
474 addl MACRO_LITERAL(16), %esp // pop arguments
475 .cfi_adjust_cfa_offset -16
476 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
477 RETURN_IF_EAX_ZERO
478END_FUNCTION art_quick_unlock_object
479
Ian Rogers468532e2013-08-05 10:56:33 -0700480DEFINE_FUNCTION art_quick_is_assignable
Ian Rogersaeeada42013-02-13 11:28:34 -0800481 PUSH eax // alignment padding
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700482 PUSH ecx // pass arg2
Ian Rogersaeeada42013-02-13 11:28:34 -0800483 PUSH eax // pass arg1
Elliott Hughesadc078a2012-04-04 11:39:05 -0700484 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b, Thread*, SP)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700485 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800486 .cfi_adjust_cfa_offset -12
Ian Rogers7caad772012-03-30 01:07:54 -0700487 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700488END_FUNCTION art_quick_is_assignable
Ian Rogers7caad772012-03-30 01:07:54 -0700489
Logan Chien8dbb7082013-01-25 20:31:17 +0800490DEFINE_FUNCTION art_quick_memcpy
Ian Rogersaeeada42013-02-13 11:28:34 -0800491 PUSH edx // pass arg3
492 PUSH ecx // pass arg2
493 PUSH eax // pass arg1
Elliott Hughesadc078a2012-04-04 11:39:05 -0700494 call SYMBOL(memcpy) // (void*, const void*, size_t)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700495 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800496 .cfi_adjust_cfa_offset -12
Ian Rogers7caad772012-03-30 01:07:54 -0700497 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800498END_FUNCTION art_quick_memcpy
Ian Rogers7caad772012-03-30 01:07:54 -0700499
Ian Rogers468532e2013-08-05 10:56:33 -0700500TWO_ARG_DOWNCALL art_quick_check_cast, artCheckCastFromCode, RETURN_IF_EAX_ZERO
501TWO_ARG_DOWNCALL art_quick_can_put_array_element, artCanPutArrayElementFromCode, RETURN_IF_EAX_ZERO
Ian Rogersd36c52e2012-04-09 16:29:25 -0700502
Logan Chien8dbb7082013-01-25 20:31:17 +0800503NO_ARG_DOWNCALL art_quick_test_suspend, artTestSuspendFromCode, ret
Ian Rogers7caad772012-03-30 01:07:54 -0700504
Ian Rogers468532e2013-08-05 10:56:33 -0700505DEFINE_FUNCTION art_quick_fmod
jeffhao1395b1e2012-06-13 18:05:13 -0700506 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800507 .cfi_adjust_cfa_offset 12
508 PUSH ebx // pass arg4 b.hi
509 PUSH edx // pass arg3 b.lo
510 PUSH ecx // pass arg2 a.hi
511 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700512 call SYMBOL(fmod) // (jdouble a, jdouble b)
513 fstpl (%esp) // pop return value off fp stack
514 movsd (%esp), %xmm0 // place into %xmm0
515 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800516 .cfi_adjust_cfa_offset -28
jeffhao292188d2012-05-17 15:45:04 -0700517 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700518END_FUNCTION art_quick_fmod
jeffhao292188d2012-05-17 15:45:04 -0700519
Ian Rogers468532e2013-08-05 10:56:33 -0700520DEFINE_FUNCTION art_quick_fmodf
Ian Rogersaeeada42013-02-13 11:28:34 -0800521 PUSH eax // alignment padding
522 PUSH ecx // pass arg2 b
523 PUSH eax // pass arg1 a
jeffhao1395b1e2012-06-13 18:05:13 -0700524 call SYMBOL(fmodf) // (jfloat a, jfloat b)
Ian Rogers1b09b092012-08-20 15:35:52 -0700525 fstps (%esp) // pop return value off fp stack
jeffhao1395b1e2012-06-13 18:05:13 -0700526 movss (%esp), %xmm0 // place into %xmm0
527 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800528 .cfi_adjust_cfa_offset -12
jeffhao292188d2012-05-17 15:45:04 -0700529 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700530END_FUNCTION art_quick_fmodf
jeffhao292188d2012-05-17 15:45:04 -0700531
Ian Rogers468532e2013-08-05 10:56:33 -0700532DEFINE_FUNCTION art_quick_l2d
Ian Rogers5793fea2013-02-14 13:33:34 -0800533 PUSH ecx // push arg2 a.hi
534 PUSH eax // push arg1 a.lo
535 fildll (%esp) // load as integer and push into st0
536 fstpl (%esp) // pop value off fp stack as double
jeffhao41005dd2012-05-09 17:58:52 -0700537 movsd (%esp), %xmm0 // place into %xmm0
Ian Rogers5793fea2013-02-14 13:33:34 -0800538 addl LITERAL(8), %esp // pop arguments
539 .cfi_adjust_cfa_offset -8
jeffhao41005dd2012-05-09 17:58:52 -0700540 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700541END_FUNCTION art_quick_l2d
jeffhao41005dd2012-05-09 17:58:52 -0700542
Ian Rogers468532e2013-08-05 10:56:33 -0700543DEFINE_FUNCTION art_quick_l2f
Ian Rogers5793fea2013-02-14 13:33:34 -0800544 PUSH ecx // push arg2 a.hi
545 PUSH eax // push arg1 a.lo
546 fildll (%esp) // load as integer and push into st0
547 fstps (%esp) // pop value off fp stack as a single
jeffhao41005dd2012-05-09 17:58:52 -0700548 movss (%esp), %xmm0 // place into %xmm0
Ian Rogers5793fea2013-02-14 13:33:34 -0800549 addl LITERAL(8), %esp // pop argument
550 .cfi_adjust_cfa_offset -8
jeffhao41005dd2012-05-09 17:58:52 -0700551 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700552END_FUNCTION art_quick_l2f
jeffhao41005dd2012-05-09 17:58:52 -0700553
Ian Rogers468532e2013-08-05 10:56:33 -0700554DEFINE_FUNCTION art_quick_d2l
Ian Rogersaeeada42013-02-13 11:28:34 -0800555 PUSH eax // alignment padding
556 PUSH ecx // pass arg2 a.hi
557 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700558 call SYMBOL(art_d2l) // (jdouble a)
jeffhao41005dd2012-05-09 17:58:52 -0700559 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800560 .cfi_adjust_cfa_offset -12
jeffhao41005dd2012-05-09 17:58:52 -0700561 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700562END_FUNCTION art_quick_d2l
jeffhao41005dd2012-05-09 17:58:52 -0700563
Ian Rogers468532e2013-08-05 10:56:33 -0700564DEFINE_FUNCTION art_quick_f2l
jeffhao41005dd2012-05-09 17:58:52 -0700565 subl LITERAL(8), %esp // alignment padding
Ian Rogers5793fea2013-02-14 13:33:34 -0800566 .cfi_adjust_cfa_offset 8
Ian Rogersaeeada42013-02-13 11:28:34 -0800567 PUSH eax // pass arg1 a
jeffhao1395b1e2012-06-13 18:05:13 -0700568 call SYMBOL(art_f2l) // (jfloat a)
jeffhao41005dd2012-05-09 17:58:52 -0700569 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800570 .cfi_adjust_cfa_offset -12
jeffhao41005dd2012-05-09 17:58:52 -0700571 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700572END_FUNCTION art_quick_f2l
jeffhao41005dd2012-05-09 17:58:52 -0700573
Ian Rogers468532e2013-08-05 10:56:33 -0700574DEFINE_FUNCTION art_quick_idivmod
jeffhao174651d2012-04-19 15:27:22 -0700575 cmpl LITERAL(0x80000000), %eax
576 je check_arg2 // special case
577args_ok:
Ian Rogers7caad772012-03-30 01:07:54 -0700578 cdq // edx:eax = sign extend eax
579 idiv %ecx // (edx,eax) = (edx:eax % ecx, edx:eax / ecx)
Ian Rogers7caad772012-03-30 01:07:54 -0700580 ret
jeffhao174651d2012-04-19 15:27:22 -0700581check_arg2:
582 cmpl LITERAL(-1), %ecx
583 jne args_ok
584 xorl %edx, %edx
585 ret // eax already holds min int
Ian Rogers468532e2013-08-05 10:56:33 -0700586END_FUNCTION art_quick_idivmod
Ian Rogers7caad772012-03-30 01:07:54 -0700587
Ian Rogers468532e2013-08-05 10:56:33 -0700588DEFINE_FUNCTION art_quick_ldiv
Ian Rogers141d6222012-04-05 12:23:06 -0700589 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800590 .cfi_adjust_cfa_offset 12
591 PUSH ebx // pass arg4 b.hi
592 PUSH edx // pass arg3 b.lo
593 PUSH ecx // pass arg2 a.hi
594 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700595 call SYMBOL(artLdivFromCode) // (jlong a, jlong b)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700596 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800597 .cfi_adjust_cfa_offset -28
Ian Rogers55bd45f2012-04-04 17:31:20 -0700598 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700599END_FUNCTION art_quick_ldiv
Ian Rogers55bd45f2012-04-04 17:31:20 -0700600
Ian Rogers468532e2013-08-05 10:56:33 -0700601DEFINE_FUNCTION art_quick_ldivmod
Ian Rogers141d6222012-04-05 12:23:06 -0700602 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800603 .cfi_adjust_cfa_offset 12
604 PUSH ebx // pass arg4 b.hi
605 PUSH edx // pass arg3 b.lo
606 PUSH ecx // pass arg2 a.hi
607 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700608 call SYMBOL(artLdivmodFromCode) // (jlong a, jlong b)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700609 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800610 .cfi_adjust_cfa_offset -28
Ian Rogers55bd45f2012-04-04 17:31:20 -0700611 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700612END_FUNCTION art_quick_ldivmod
Ian Rogers55bd45f2012-04-04 17:31:20 -0700613
Ian Rogers468532e2013-08-05 10:56:33 -0700614DEFINE_FUNCTION art_quick_lmul
Ian Rogers5793fea2013-02-14 13:33:34 -0800615 imul %eax, %ebx // ebx = a.lo(eax) * b.hi(ebx)
616 imul %edx, %ecx // ecx = b.lo(edx) * a.hi(ecx)
617 mul %edx // edx:eax = a.lo(eax) * b.lo(edx)
618 add %ebx, %ecx
619 add %ecx, %edx // edx += (a.lo * b.hi) + (b.lo * a.hi)
jeffhao644d5312012-05-03 19:04:49 -0700620 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700621END_FUNCTION art_quick_lmul
jeffhao644d5312012-05-03 19:04:49 -0700622
Ian Rogers468532e2013-08-05 10:56:33 -0700623DEFINE_FUNCTION art_quick_lshl
jeffhao644d5312012-05-03 19:04:49 -0700624 // ecx:eax << edx
Ian Rogers141d6222012-04-05 12:23:06 -0700625 xchg %edx, %ecx
626 shld %cl,%eax,%edx
627 shl %cl,%eax
628 test LITERAL(32), %cl
629 jz 1f
630 mov %eax, %edx
631 xor %eax, %eax
6321:
633 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700634END_FUNCTION art_quick_lshl
Ian Rogers141d6222012-04-05 12:23:06 -0700635
Ian Rogers468532e2013-08-05 10:56:33 -0700636DEFINE_FUNCTION art_quick_lshr
jeffhao644d5312012-05-03 19:04:49 -0700637 // ecx:eax >> edx
Ian Rogers141d6222012-04-05 12:23:06 -0700638 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -0700639 shrd %cl,%edx,%eax
640 sar %cl,%edx
Ian Rogers141d6222012-04-05 12:23:06 -0700641 test LITERAL(32),%cl
642 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -0700643 mov %edx, %eax
644 sar LITERAL(31), %edx
Ian Rogers141d6222012-04-05 12:23:06 -07006451:
646 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700647END_FUNCTION art_quick_lshr
Ian Rogers141d6222012-04-05 12:23:06 -0700648
Ian Rogers468532e2013-08-05 10:56:33 -0700649DEFINE_FUNCTION art_quick_lushr
jeffhao644d5312012-05-03 19:04:49 -0700650 // ecx:eax >>> edx
Ian Rogers141d6222012-04-05 12:23:06 -0700651 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -0700652 shrd %cl,%edx,%eax
653 shr %cl,%edx
654 test LITERAL(32),%cl
Ian Rogers141d6222012-04-05 12:23:06 -0700655 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -0700656 mov %edx, %eax
657 xor %edx, %edx
Ian Rogers141d6222012-04-05 12:23:06 -07006581:
659 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700660END_FUNCTION art_quick_lushr
Ian Rogers141d6222012-04-05 12:23:06 -0700661
Ian Rogers468532e2013-08-05 10:56:33 -0700662DEFINE_FUNCTION art_quick_set32_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700663 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
664 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700665 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800666 .cfi_adjust_cfa_offset 8
667 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700668 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800669 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700670 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800671 PUSH ebx // pass referrer
672 PUSH edx // pass new_val
673 PUSH ecx // pass object
674 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700675 call SYMBOL(artSet32InstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700676 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800677 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700678 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
679 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700680END_FUNCTION art_quick_set32_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700681
Ian Rogers468532e2013-08-05 10:56:33 -0700682DEFINE_FUNCTION art_quick_set64_instance
Ian Rogersaeeada42013-02-13 11:28:34 -0800683 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao1ff4cd72012-05-21 11:17:48 -0700684 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800685 .cfi_adjust_cfa_offset 8
686 PUSH esp // pass SP-8
jeffhao1ff4cd72012-05-21 11:17:48 -0700687 addl LITERAL(8), (%esp) // fix SP on stack by adding 8
jeffhao9dbb23e2012-05-18 17:03:57 -0700688 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800689 .cfi_adjust_cfa_offset 4
690 PUSH ebx // pass high half of new_val
691 PUSH edx // pass low half of new_val
692 PUSH ecx // pass object
693 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700694 call SYMBOL(artSet64InstanceFromCode) // (field_idx, Object*, new_val, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700695 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800696 .cfi_adjust_cfa_offset -32
697 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700698 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700699END_FUNCTION art_quick_set64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700700
Ian Rogers468532e2013-08-05 10:56:33 -0700701DEFINE_FUNCTION art_quick_set_obj_instance
Ian Rogersaeeada42013-02-13 11:28:34 -0800702 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700703 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700704 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800705 .cfi_adjust_cfa_offset 8
706 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700707 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800708 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700709 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800710 PUSH ebx // pass referrer
711 PUSH edx // pass new_val
712 PUSH ecx // pass object
713 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700714 call SYMBOL(artSetObjInstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700715 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800716 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700717 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
718 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700719END_FUNCTION art_quick_set_obj_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700720
Ian Rogers468532e2013-08-05 10:56:33 -0700721DEFINE_FUNCTION art_quick_get32_instance
Ian Rogersaeeada42013-02-13 11:28:34 -0800722 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700723 mov %esp, %ebx // remember SP
724 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700725 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800726 .cfi_adjust_cfa_offset 12
727 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700728 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800729 .cfi_adjust_cfa_offset 4
730 PUSH edx // pass referrer
731 PUSH ecx // pass object
732 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700733 call SYMBOL(artGet32InstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700734 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800735 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700736 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700737 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700738END_FUNCTION art_quick_get32_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700739
Ian Rogers468532e2013-08-05 10:56:33 -0700740DEFINE_FUNCTION art_quick_get64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700741 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
742 mov %esp, %ebx // remember SP
743 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700744 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800745 .cfi_adjust_cfa_offset 12
746 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700747 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800748 .cfi_adjust_cfa_offset 4
749 PUSH edx // pass referrer
750 PUSH ecx // pass object
751 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700752 call SYMBOL(artGet64InstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700753 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800754 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700755 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700756 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700757END_FUNCTION art_quick_get64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700758
Ian Rogers468532e2013-08-05 10:56:33 -0700759DEFINE_FUNCTION art_quick_get_obj_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700760 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
761 mov %esp, %ebx // remember SP
762 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700763 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800764 .cfi_adjust_cfa_offset 12
765 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700766 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800767 .cfi_adjust_cfa_offset 4
768 PUSH edx // pass referrer
769 PUSH ecx // pass object
770 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700771 call SYMBOL(artGetObjInstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700772 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800773 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700774 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700775 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700776END_FUNCTION art_quick_get_obj_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700777
Ian Rogers468532e2013-08-05 10:56:33 -0700778DEFINE_FUNCTION art_quick_set32_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700779 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
780 mov %esp, %ebx // remember SP
781 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700782 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800783 .cfi_adjust_cfa_offset 12
784 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700785 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800786 .cfi_adjust_cfa_offset 4
787 PUSH edx // pass referrer
788 PUSH ecx // pass new_val
789 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700790 call SYMBOL(artSet32StaticFromCode) // (field_idx, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700791 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800792 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700793 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
794 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700795END_FUNCTION art_quick_set32_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700796
Ian Rogers468532e2013-08-05 10:56:33 -0700797DEFINE_FUNCTION art_quick_set64_static
Ian Rogersaeeada42013-02-13 11:28:34 -0800798 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700799 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700800 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800801 .cfi_adjust_cfa_offset 8
802 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700803 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800804 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700805 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800806 PUSH edx // pass high half of new_val
807 PUSH ecx // pass low half of new_val
808 PUSH ebx // pass referrer
809 PUSH eax // pass field_idx
810 call SYMBOL(artSet64StaticFromCode) // (field_idx, referrer, new_val, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700811 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800812 .cfi_adjust_cfa_offset -32
813 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700814 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700815END_FUNCTION art_quick_set64_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700816
Ian Rogers468532e2013-08-05 10:56:33 -0700817DEFINE_FUNCTION art_quick_set_obj_static
Ian Rogersaeeada42013-02-13 11:28:34 -0800818 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700819 mov %esp, %ebx // remember SP
820 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700821 subl LITERAL(12), %esp // alignment padding
Ian Rogers62d6c772013-02-27 08:32:07 -0800822 .cfi_adjust_cfa_offset 12
Ian Rogersaeeada42013-02-13 11:28:34 -0800823 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700824 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800825 .cfi_adjust_cfa_offset 4
826 PUSH edx // pass referrer
827 PUSH ecx // pass new_val
828 PUSH eax // pass field_idx
829 call SYMBOL(artSetObjStaticFromCode) // (field_idx, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700830 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800831 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700832 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700833END_FUNCTION art_quick_set_obj_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700834
Ian Rogers468532e2013-08-05 10:56:33 -0700835DEFINE_FUNCTION art_quick_get32_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700836 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
837 mov %esp, %edx // remember SP
838 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800839 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700840 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800841 .cfi_adjust_cfa_offset 4
842 PUSH ecx // pass referrer
843 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700844 call SYMBOL(artGet32StaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700845 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800846 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -0700847 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700848 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700849END_FUNCTION art_quick_get32_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700850
Ian Rogers468532e2013-08-05 10:56:33 -0700851DEFINE_FUNCTION art_quick_get64_static
Ian Rogersaeeada42013-02-13 11:28:34 -0800852 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700853 mov %esp, %edx // remember SP
854 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800855 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700856 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800857 .cfi_adjust_cfa_offset 4
858 PUSH ecx // pass referrer
859 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700860 call SYMBOL(artGet64StaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700861 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800862 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -0700863 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700864 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700865END_FUNCTION art_quick_get64_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700866
Ian Rogers468532e2013-08-05 10:56:33 -0700867DEFINE_FUNCTION art_quick_get_obj_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700868 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
869 mov %esp, %edx // remember SP
870 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800871 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700872 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800873 .cfi_adjust_cfa_offset 4
874 PUSH ecx // pass referrer
875 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700876 call SYMBOL(artGetObjStaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700877 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800878 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -0700879 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700880 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700881END_FUNCTION art_quick_get_obj_static
jeffhaod66a8752012-05-22 15:30:16 -0700882
Logan Chien8dbb7082013-01-25 20:31:17 +0800883DEFINE_FUNCTION art_quick_proxy_invoke_handler
Ian Rogers7db619b2013-01-16 18:35:48 -0800884 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save frame and Method*
Ian Rogersaeeada42013-02-13 11:28:34 -0800885 PUSH esp // pass SP
jeffhaod66a8752012-05-22 15:30:16 -0700886 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800887 .cfi_adjust_cfa_offset 4
888 PUSH ecx // pass receiver
889 PUSH eax // pass proxy method
Jeff Hao5fa60c32013-04-04 17:57:01 -0700890 call SYMBOL(artQuickProxyInvokeHandler) // (proxy method, receiver, Thread*, SP)
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800891 movd %eax, %xmm0 // place return value also into floating point return value
892 movd %edx, %xmm1
893 punpckldq %xmm1, %xmm0
jeffhaod66a8752012-05-22 15:30:16 -0700894 addl LITERAL(44), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800895 .cfi_adjust_cfa_offset -44
jeffhaod66a8752012-05-22 15:30:16 -0700896 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800897END_FUNCTION art_quick_proxy_invoke_handler
jeffhao9dbb23e2012-05-18 17:03:57 -0700898
Ian Rogers468532e2013-08-05 10:56:33 -0700899DEFINE_FUNCTION art_quick_resolution_trampoline
900 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
901 PUSH esp // pass SP
902 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
903 .cfi_adjust_cfa_offset 4
904 PUSH ecx // pass receiver
905 PUSH eax // pass method
906 call SYMBOL(artQuickResolutionTrampoline) // (Method* called, receiver, Thread*, SP)
907 movl %eax, %edi // remember code pointer in EDI
908 addl LITERAL(16), %esp // pop arguments
909 test %eax, %eax // if code pointer is NULL goto deliver pending exception
910 jz 1f
911 POP eax // called method
912 POP ecx // restore args
913 POP edx
914 POP ebx
915 POP ebp // restore callee saves except EDI
916 POP esi
917 xchgl 0(%esp),%edi // restore EDI and place code pointer as only value on stack
918 ret // tail call into method
9191:
920 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
921 DELIVER_PENDING_EXCEPTION
922END_FUNCTION art_quick_resolution_trampoline
923
924DEFINE_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers62d6c772013-02-27 08:32:07 -0800925 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save frame
Ian Rogersaeeada42013-02-13 11:28:34 -0800926 mov %esp, %edx // remember SP
927 PUSH eax // alignment padding
928 PUSH edx // pass SP
Ian Rogers7db619b2013-01-16 18:35:48 -0800929 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800930 .cfi_adjust_cfa_offset 4
931 PUSH eax // pass method
Ian Rogers468532e2013-08-05 10:56:33 -0700932 call SYMBOL(artQuickToInterpreterBridge) // (method, Thread*, SP)
Ian Rogers7db619b2013-01-16 18:35:48 -0800933 movd %eax, %xmm0 // place return value also into floating point return value
934 movd %edx, %xmm1
935 punpckldq %xmm1, %xmm0
936 addl LITERAL(44), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800937 .cfi_adjust_cfa_offset -44
Ian Rogers7db619b2013-01-16 18:35:48 -0800938 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700939END_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -0800940
jeffhao7e4fcb82013-01-10 18:11:08 -0800941 /*
942 * Routine that intercepts method calls and returns.
943 */
Ian Rogers468532e2013-08-05 10:56:33 -0700944DEFINE_FUNCTION art_quick_instrumentation_entry
Ian Rogers62d6c772013-02-27 08:32:07 -0800945 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
946 movl %esp, %edx // Save SP.
947 PUSH eax // Save eax which will be clobbered by the callee-save method.
948 subl LITERAL(8), %esp // Align stack.
949 .cfi_adjust_cfa_offset 8
950 pushl 40(%esp) // Pass LR.
Ian Rogersaeeada42013-02-13 11:28:34 -0800951 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -0800952 PUSH edx // Pass SP.
953 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Ian Rogersaeeada42013-02-13 11:28:34 -0800954 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -0800955 PUSH ecx // Pass receiver.
956 PUSH eax // Pass Method*.
957 call SYMBOL(artInstrumentationMethodEntryFromCode) // (Method*, Object*, Thread*, SP, LR)
958 addl LITERAL(28), %esp // Pop arguments upto saved Method*.
959 movl 28(%esp), %edi // Restore edi.
960 movl %eax, 28(%esp) // Place code* over edi, just under return pc.
Ian Rogers468532e2013-08-05 10:56:33 -0700961 movl LITERAL(SYMBOL(art_quick_instrumentation_exit)), 32(%esp)
Ian Rogers62d6c772013-02-27 08:32:07 -0800962 // Place instrumentation exit as return pc.
963 movl (%esp), %eax // Restore eax.
964 movl 8(%esp), %ecx // Restore ecx.
965 movl 12(%esp), %edx // Restore edx.
966 movl 16(%esp), %ebx // Restore ebx.
967 movl 20(%esp), %ebp // Restore ebp.
968 movl 24(%esp), %esi // Restore esi.
969 addl LITERAL(28), %esp // Wind stack back upto code*.
970 ret // Call method (and pop).
Ian Rogers468532e2013-08-05 10:56:33 -0700971END_FUNCTION art_quick_instrumentation_entry
Ian Rogers62d6c772013-02-27 08:32:07 -0800972
Ian Rogers468532e2013-08-05 10:56:33 -0700973DEFINE_FUNCTION art_quick_instrumentation_exit
Ian Rogers62d6c772013-02-27 08:32:07 -0800974 pushl LITERAL(0) // Push a fake return PC as there will be none on the stack.
975 SETUP_REF_ONLY_CALLEE_SAVE_FRAME
976 mov %esp, %ecx // Remember SP
977 subl LITERAL(8), %esp // Save float return value.
978 .cfi_adjust_cfa_offset 8
979 movd %xmm0, (%esp)
980 PUSH edx // Save gpr return value.
981 PUSH eax
982 subl LITERAL(8), %esp // Align stack
983 movd %xmm0, (%esp)
984 subl LITERAL(8), %esp // Pass float return value.
985 .cfi_adjust_cfa_offset 8
986 movd %xmm0, (%esp)
987 PUSH edx // Pass gpr return value.
988 PUSH eax
989 PUSH ecx // Pass SP.
990 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current.
Ian Rogersaeeada42013-02-13 11:28:34 -0800991 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -0800992 call SYMBOL(artInstrumentationMethodExitFromCode) // (Thread*, SP, gpr_result, fpr_result)
993 mov %eax, %ecx // Move returned link register.
994 addl LITERAL(32), %esp // Pop arguments.
995 .cfi_adjust_cfa_offset -32
996 movl %edx, %ebx // Move returned link register for deopt
997 // (ebx is pretending to be our LR).
998 POP eax // Restore gpr return value.
999 POP edx
1000 movd (%esp), %xmm0 // Restore fpr return value.
1001 addl LITERAL(8), %esp
Ian Rogers5793fea2013-02-14 13:33:34 -08001002 .cfi_adjust_cfa_offset -8
Ian Rogers62d6c772013-02-27 08:32:07 -08001003 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
1004 addl LITERAL(4), %esp // Remove fake return pc.
1005 jmp *%ecx // Return.
Ian Rogers468532e2013-08-05 10:56:33 -07001006END_FUNCTION art_quick_instrumentation_exit
jeffhao162fd332013-01-08 16:21:01 -08001007
jeffhao7e4fcb82013-01-10 18:11:08 -08001008 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001009 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1010 * will long jump to the upcall with a special exception of -1.
jeffhao7e4fcb82013-01-10 18:11:08 -08001011 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001012DEFINE_FUNCTION art_quick_deoptimize
Ian Rogers62d6c772013-02-27 08:32:07 -08001013 pushl %ebx // Fake that we were called.
Jeff Haoc1fcdf12013-04-11 13:34:01 -07001014 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
Ian Rogers62d6c772013-02-27 08:32:07 -08001015 mov %esp, %ecx // Remember SP.
1016 subl LITERAL(8), %esp // Align stack.
1017 .cfi_adjust_cfa_offset 8
1018 PUSH ecx // Pass SP.
1019 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Ian Rogersaeeada42013-02-13 11:28:34 -08001020 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -08001021 call SYMBOL(artDeoptimize) // artDeoptimize(Thread*, SP)
1022 int3 // Unreachable.
Ian Rogersaeeada42013-02-13 11:28:34 -08001023END_FUNCTION art_quick_deoptimize
jeffhao162fd332013-01-08 16:21:01 -08001024
jeffhao86e46712012-08-08 17:30:59 -07001025 /*
1026 * String's indexOf.
1027 *
1028 * On entry:
1029 * eax: string object (known non-null)
1030 * ecx: char to match (known <= 0xFFFF)
1031 * edx: Starting offset in string data
1032 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001033DEFINE_FUNCTION art_quick_indexof
Ian Rogersaeeada42013-02-13 11:28:34 -08001034 PUSH edi // push callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001035 mov STRING_COUNT_OFFSET(%eax), %ebx
1036 mov STRING_VALUE_OFFSET(%eax), %edi
1037 mov STRING_OFFSET_OFFSET(%eax), %eax
1038 testl %edx, %edx // check if start < 0
1039 jl clamp_min
1040clamp_done:
1041 cmpl %ebx, %edx // check if start >= count
1042 jge not_found
1043 lea STRING_DATA_OFFSET(%edi, %eax, 2), %edi // build a pointer to the start of string data
1044 mov %edi, %eax // save a copy in eax to later compute result
1045 lea (%edi, %edx, 2), %edi // build pointer to start of data to compare
1046 subl %edx, %ebx // compute iteration count
1047 /*
1048 * At this point we have:
1049 * eax: original start of string data
1050 * ecx: char to compare
1051 * ebx: length to compare
1052 * edi: start of data to test
1053 */
1054 mov %eax, %edx
1055 mov %ecx, %eax // put char to match in %eax
1056 mov %ebx, %ecx // put length to compare in %ecx
1057 repne scasw // find %ax, starting at [%edi], up to length %ecx
1058 jne not_found
1059 subl %edx, %edi
1060 sar LITERAL(1), %edi
1061 decl %edi // index = ((curr_ptr - orig_ptr) / 2) - 1
1062 mov %edi, %eax
Ian Rogersaeeada42013-02-13 11:28:34 -08001063 POP edi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001064 ret
1065 .balign 16
1066not_found:
1067 mov LITERAL(-1), %eax // return -1 (not found)
Ian Rogersaeeada42013-02-13 11:28:34 -08001068 POP edi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001069 ret
1070clamp_min:
1071 xor %edx, %edx // clamp start to 0
1072 jmp clamp_done
Ian Rogersaeeada42013-02-13 11:28:34 -08001073END_FUNCTION art_quick_indexof
jeffhao86e46712012-08-08 17:30:59 -07001074
1075 /*
1076 * String's compareTo.
1077 *
1078 * On entry:
1079 * eax: this string object (known non-null)
1080 * ecx: comp string object (known non-null)
1081 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001082DEFINE_FUNCTION art_quick_string_compareto
Ian Rogersaeeada42013-02-13 11:28:34 -08001083 PUSH esi // push callee save reg
1084 PUSH edi // push callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001085 mov STRING_COUNT_OFFSET(%eax), %edx
1086 mov STRING_COUNT_OFFSET(%ecx), %ebx
1087 mov STRING_VALUE_OFFSET(%eax), %esi
1088 mov STRING_VALUE_OFFSET(%ecx), %edi
1089 mov STRING_OFFSET_OFFSET(%eax), %eax
1090 mov STRING_OFFSET_OFFSET(%ecx), %ecx
1091 /* Build pointers to the start of string data */
1092 lea STRING_DATA_OFFSET(%esi, %eax, 2), %esi
1093 lea STRING_DATA_OFFSET(%edi, %ecx, 2), %edi
1094 /* Calculate min length and count diff */
1095 mov %edx, %ecx
1096 mov %edx, %eax
1097 subl %ebx, %eax
1098 cmovg %ebx, %ecx
1099 /*
1100 * At this point we have:
1101 * eax: value to return if first part of strings are equal
1102 * ecx: minimum among the lengths of the two strings
1103 * esi: pointer to this string data
1104 * edi: pointer to comp string data
1105 */
1106 repe cmpsw // find nonmatching chars in [%esi] and [%edi], up to length %ecx
1107 jne not_equal
Ian Rogersaeeada42013-02-13 11:28:34 -08001108 POP edi // pop callee save reg
1109 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001110 ret
1111 .balign 16
1112not_equal:
Ian Rogers1b09b092012-08-20 15:35:52 -07001113 movzwl -2(%esi), %eax // get last compared char from this string
1114 movzwl -2(%edi), %ecx // get last compared char from comp string
jeffhao86e46712012-08-08 17:30:59 -07001115 subl %ecx, %eax // return the difference
Ian Rogersaeeada42013-02-13 11:28:34 -08001116 POP edi // pop callee save reg
1117 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001118 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001119END_FUNCTION art_quick_string_compareto
jeffhao86e46712012-08-08 17:30:59 -07001120
Elliott Hughes787ec202012-03-29 17:14:15 -07001121 // TODO: implement these!
Logan Chien8dbb7082013-01-25 20:31:17 +08001122UNIMPLEMENTED art_quick_memcmp16