blob: 06b220391f2c5db92d56b354e5fb297eb8f5fa18 [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 -0700404ONE_ARG_DOWNCALL art_quick_lock_object, artLockObjectFromCode, ret
405ONE_ARG_DOWNCALL art_quick_unlock_object, artUnlockObjectFromCode, RETURN_IF_EAX_ZERO
Ian Rogersd36c52e2012-04-09 16:29:25 -0700406
Ian Rogers468532e2013-08-05 10:56:33 -0700407TWO_ARG_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_EAX_ZERO
Ian Rogers7caad772012-03-30 01:07:54 -0700408
Ian Rogers468532e2013-08-05 10:56:33 -0700409DEFINE_FUNCTION art_quick_is_assignable
Ian Rogersaeeada42013-02-13 11:28:34 -0800410 PUSH eax // alignment padding
411 PUSH ecx // pass arg2
412 PUSH eax // pass arg1
Elliott Hughesadc078a2012-04-04 11:39:05 -0700413 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b, Thread*, SP)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700414 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800415 .cfi_adjust_cfa_offset -12
Ian Rogers7caad772012-03-30 01:07:54 -0700416 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700417END_FUNCTION art_quick_is_assignable
Ian Rogers7caad772012-03-30 01:07:54 -0700418
Logan Chien8dbb7082013-01-25 20:31:17 +0800419DEFINE_FUNCTION art_quick_memcpy
Ian Rogersaeeada42013-02-13 11:28:34 -0800420 PUSH edx // pass arg3
421 PUSH ecx // pass arg2
422 PUSH eax // pass arg1
Elliott Hughesadc078a2012-04-04 11:39:05 -0700423 call SYMBOL(memcpy) // (void*, const void*, size_t)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700424 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800425 .cfi_adjust_cfa_offset -12
Ian Rogers7caad772012-03-30 01:07:54 -0700426 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800427END_FUNCTION art_quick_memcpy
Ian Rogers7caad772012-03-30 01:07:54 -0700428
Ian Rogers468532e2013-08-05 10:56:33 -0700429TWO_ARG_DOWNCALL art_quick_check_cast, artCheckCastFromCode, RETURN_IF_EAX_ZERO
430TWO_ARG_DOWNCALL art_quick_can_put_array_element, artCanPutArrayElementFromCode, RETURN_IF_EAX_ZERO
Ian Rogersd36c52e2012-04-09 16:29:25 -0700431
Logan Chien8dbb7082013-01-25 20:31:17 +0800432NO_ARG_DOWNCALL art_quick_test_suspend, artTestSuspendFromCode, ret
Ian Rogers7caad772012-03-30 01:07:54 -0700433
Ian Rogers468532e2013-08-05 10:56:33 -0700434DEFINE_FUNCTION art_quick_fmod
jeffhao1395b1e2012-06-13 18:05:13 -0700435 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800436 .cfi_adjust_cfa_offset 12
437 PUSH ebx // pass arg4 b.hi
438 PUSH edx // pass arg3 b.lo
439 PUSH ecx // pass arg2 a.hi
440 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700441 call SYMBOL(fmod) // (jdouble a, jdouble b)
442 fstpl (%esp) // pop return value off fp stack
443 movsd (%esp), %xmm0 // place into %xmm0
444 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800445 .cfi_adjust_cfa_offset -28
jeffhao292188d2012-05-17 15:45:04 -0700446 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700447END_FUNCTION art_quick_fmod
jeffhao292188d2012-05-17 15:45:04 -0700448
Ian Rogers468532e2013-08-05 10:56:33 -0700449DEFINE_FUNCTION art_quick_fmodf
Ian Rogersaeeada42013-02-13 11:28:34 -0800450 PUSH eax // alignment padding
451 PUSH ecx // pass arg2 b
452 PUSH eax // pass arg1 a
jeffhao1395b1e2012-06-13 18:05:13 -0700453 call SYMBOL(fmodf) // (jfloat a, jfloat b)
Ian Rogers1b09b092012-08-20 15:35:52 -0700454 fstps (%esp) // pop return value off fp stack
jeffhao1395b1e2012-06-13 18:05:13 -0700455 movss (%esp), %xmm0 // place into %xmm0
456 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800457 .cfi_adjust_cfa_offset -12
jeffhao292188d2012-05-17 15:45:04 -0700458 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700459END_FUNCTION art_quick_fmodf
jeffhao292188d2012-05-17 15:45:04 -0700460
Ian Rogers468532e2013-08-05 10:56:33 -0700461DEFINE_FUNCTION art_quick_l2d
Ian Rogers5793fea2013-02-14 13:33:34 -0800462 PUSH ecx // push arg2 a.hi
463 PUSH eax // push arg1 a.lo
464 fildll (%esp) // load as integer and push into st0
465 fstpl (%esp) // pop value off fp stack as double
jeffhao41005dd2012-05-09 17:58:52 -0700466 movsd (%esp), %xmm0 // place into %xmm0
Ian Rogers5793fea2013-02-14 13:33:34 -0800467 addl LITERAL(8), %esp // pop arguments
468 .cfi_adjust_cfa_offset -8
jeffhao41005dd2012-05-09 17:58:52 -0700469 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700470END_FUNCTION art_quick_l2d
jeffhao41005dd2012-05-09 17:58:52 -0700471
Ian Rogers468532e2013-08-05 10:56:33 -0700472DEFINE_FUNCTION art_quick_l2f
Ian Rogers5793fea2013-02-14 13:33:34 -0800473 PUSH ecx // push arg2 a.hi
474 PUSH eax // push arg1 a.lo
475 fildll (%esp) // load as integer and push into st0
476 fstps (%esp) // pop value off fp stack as a single
jeffhao41005dd2012-05-09 17:58:52 -0700477 movss (%esp), %xmm0 // place into %xmm0
Ian Rogers5793fea2013-02-14 13:33:34 -0800478 addl LITERAL(8), %esp // pop argument
479 .cfi_adjust_cfa_offset -8
jeffhao41005dd2012-05-09 17:58:52 -0700480 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700481END_FUNCTION art_quick_l2f
jeffhao41005dd2012-05-09 17:58:52 -0700482
Ian Rogers468532e2013-08-05 10:56:33 -0700483DEFINE_FUNCTION art_quick_d2l
Ian Rogersaeeada42013-02-13 11:28:34 -0800484 PUSH eax // alignment padding
485 PUSH ecx // pass arg2 a.hi
486 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700487 call SYMBOL(art_d2l) // (jdouble a)
jeffhao41005dd2012-05-09 17:58:52 -0700488 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800489 .cfi_adjust_cfa_offset -12
jeffhao41005dd2012-05-09 17:58:52 -0700490 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700491END_FUNCTION art_quick_d2l
jeffhao41005dd2012-05-09 17:58:52 -0700492
Ian Rogers468532e2013-08-05 10:56:33 -0700493DEFINE_FUNCTION art_quick_f2l
jeffhao41005dd2012-05-09 17:58:52 -0700494 subl LITERAL(8), %esp // alignment padding
Ian Rogers5793fea2013-02-14 13:33:34 -0800495 .cfi_adjust_cfa_offset 8
Ian Rogersaeeada42013-02-13 11:28:34 -0800496 PUSH eax // pass arg1 a
jeffhao1395b1e2012-06-13 18:05:13 -0700497 call SYMBOL(art_f2l) // (jfloat a)
jeffhao41005dd2012-05-09 17:58:52 -0700498 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800499 .cfi_adjust_cfa_offset -12
jeffhao41005dd2012-05-09 17:58:52 -0700500 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700501END_FUNCTION art_quick_f2l
jeffhao41005dd2012-05-09 17:58:52 -0700502
Ian Rogers468532e2013-08-05 10:56:33 -0700503DEFINE_FUNCTION art_quick_idivmod
jeffhao174651d2012-04-19 15:27:22 -0700504 cmpl LITERAL(0x80000000), %eax
505 je check_arg2 // special case
506args_ok:
Ian Rogers7caad772012-03-30 01:07:54 -0700507 cdq // edx:eax = sign extend eax
508 idiv %ecx // (edx,eax) = (edx:eax % ecx, edx:eax / ecx)
Ian Rogers7caad772012-03-30 01:07:54 -0700509 ret
jeffhao174651d2012-04-19 15:27:22 -0700510check_arg2:
511 cmpl LITERAL(-1), %ecx
512 jne args_ok
513 xorl %edx, %edx
514 ret // eax already holds min int
Ian Rogers468532e2013-08-05 10:56:33 -0700515END_FUNCTION art_quick_idivmod
Ian Rogers7caad772012-03-30 01:07:54 -0700516
Ian Rogers468532e2013-08-05 10:56:33 -0700517DEFINE_FUNCTION art_quick_ldiv
Ian Rogers141d6222012-04-05 12:23:06 -0700518 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800519 .cfi_adjust_cfa_offset 12
520 PUSH ebx // pass arg4 b.hi
521 PUSH edx // pass arg3 b.lo
522 PUSH ecx // pass arg2 a.hi
523 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700524 call SYMBOL(artLdivFromCode) // (jlong a, jlong b)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700525 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800526 .cfi_adjust_cfa_offset -28
Ian Rogers55bd45f2012-04-04 17:31:20 -0700527 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700528END_FUNCTION art_quick_ldiv
Ian Rogers55bd45f2012-04-04 17:31:20 -0700529
Ian Rogers468532e2013-08-05 10:56:33 -0700530DEFINE_FUNCTION art_quick_ldivmod
Ian Rogers141d6222012-04-05 12:23:06 -0700531 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800532 .cfi_adjust_cfa_offset 12
533 PUSH ebx // pass arg4 b.hi
534 PUSH edx // pass arg3 b.lo
535 PUSH ecx // pass arg2 a.hi
536 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700537 call SYMBOL(artLdivmodFromCode) // (jlong a, jlong b)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700538 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800539 .cfi_adjust_cfa_offset -28
Ian Rogers55bd45f2012-04-04 17:31:20 -0700540 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700541END_FUNCTION art_quick_ldivmod
Ian Rogers55bd45f2012-04-04 17:31:20 -0700542
Ian Rogers468532e2013-08-05 10:56:33 -0700543DEFINE_FUNCTION art_quick_lmul
Ian Rogers5793fea2013-02-14 13:33:34 -0800544 imul %eax, %ebx // ebx = a.lo(eax) * b.hi(ebx)
545 imul %edx, %ecx // ecx = b.lo(edx) * a.hi(ecx)
546 mul %edx // edx:eax = a.lo(eax) * b.lo(edx)
547 add %ebx, %ecx
548 add %ecx, %edx // edx += (a.lo * b.hi) + (b.lo * a.hi)
jeffhao644d5312012-05-03 19:04:49 -0700549 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700550END_FUNCTION art_quick_lmul
jeffhao644d5312012-05-03 19:04:49 -0700551
Ian Rogers468532e2013-08-05 10:56:33 -0700552DEFINE_FUNCTION art_quick_lshl
jeffhao644d5312012-05-03 19:04:49 -0700553 // ecx:eax << edx
Ian Rogers141d6222012-04-05 12:23:06 -0700554 xchg %edx, %ecx
555 shld %cl,%eax,%edx
556 shl %cl,%eax
557 test LITERAL(32), %cl
558 jz 1f
559 mov %eax, %edx
560 xor %eax, %eax
5611:
562 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700563END_FUNCTION art_quick_lshl
Ian Rogers141d6222012-04-05 12:23:06 -0700564
Ian Rogers468532e2013-08-05 10:56:33 -0700565DEFINE_FUNCTION art_quick_lshr
jeffhao644d5312012-05-03 19:04:49 -0700566 // ecx:eax >> edx
Ian Rogers141d6222012-04-05 12:23:06 -0700567 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -0700568 shrd %cl,%edx,%eax
569 sar %cl,%edx
Ian Rogers141d6222012-04-05 12:23:06 -0700570 test LITERAL(32),%cl
571 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -0700572 mov %edx, %eax
573 sar LITERAL(31), %edx
Ian Rogers141d6222012-04-05 12:23:06 -07005741:
575 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700576END_FUNCTION art_quick_lshr
Ian Rogers141d6222012-04-05 12:23:06 -0700577
Ian Rogers468532e2013-08-05 10:56:33 -0700578DEFINE_FUNCTION art_quick_lushr
jeffhao644d5312012-05-03 19:04:49 -0700579 // ecx:eax >>> edx
Ian Rogers141d6222012-04-05 12:23:06 -0700580 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -0700581 shrd %cl,%edx,%eax
582 shr %cl,%edx
583 test LITERAL(32),%cl
Ian Rogers141d6222012-04-05 12:23:06 -0700584 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -0700585 mov %edx, %eax
586 xor %edx, %edx
Ian Rogers141d6222012-04-05 12:23:06 -07005871:
588 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700589END_FUNCTION art_quick_lushr
Ian Rogers141d6222012-04-05 12:23:06 -0700590
Ian Rogers468532e2013-08-05 10:56:33 -0700591DEFINE_FUNCTION art_quick_set32_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700592 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
593 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700594 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800595 .cfi_adjust_cfa_offset 8
596 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700597 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800598 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700599 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800600 PUSH ebx // pass referrer
601 PUSH edx // pass new_val
602 PUSH ecx // pass object
603 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700604 call SYMBOL(artSet32InstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700605 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800606 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700607 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
608 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700609END_FUNCTION art_quick_set32_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700610
Ian Rogers468532e2013-08-05 10:56:33 -0700611DEFINE_FUNCTION art_quick_set64_instance
Ian Rogersaeeada42013-02-13 11:28:34 -0800612 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao1ff4cd72012-05-21 11:17:48 -0700613 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800614 .cfi_adjust_cfa_offset 8
615 PUSH esp // pass SP-8
jeffhao1ff4cd72012-05-21 11:17:48 -0700616 addl LITERAL(8), (%esp) // fix SP on stack by adding 8
jeffhao9dbb23e2012-05-18 17:03:57 -0700617 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800618 .cfi_adjust_cfa_offset 4
619 PUSH ebx // pass high half of new_val
620 PUSH edx // pass low half of new_val
621 PUSH ecx // pass object
622 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700623 call SYMBOL(artSet64InstanceFromCode) // (field_idx, Object*, new_val, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700624 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800625 .cfi_adjust_cfa_offset -32
626 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700627 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700628END_FUNCTION art_quick_set64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700629
Ian Rogers468532e2013-08-05 10:56:33 -0700630DEFINE_FUNCTION art_quick_set_obj_instance
Ian Rogersaeeada42013-02-13 11:28:34 -0800631 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700632 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700633 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800634 .cfi_adjust_cfa_offset 8
635 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700636 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800637 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700638 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800639 PUSH ebx // pass referrer
640 PUSH edx // pass new_val
641 PUSH ecx // pass object
642 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700643 call SYMBOL(artSetObjInstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700644 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800645 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700646 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
647 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700648END_FUNCTION art_quick_set_obj_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700649
Ian Rogers468532e2013-08-05 10:56:33 -0700650DEFINE_FUNCTION art_quick_get32_instance
Ian Rogersaeeada42013-02-13 11:28:34 -0800651 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700652 mov %esp, %ebx // remember SP
653 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700654 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800655 .cfi_adjust_cfa_offset 12
656 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700657 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800658 .cfi_adjust_cfa_offset 4
659 PUSH edx // pass referrer
660 PUSH ecx // pass object
661 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700662 call SYMBOL(artGet32InstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700663 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800664 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700665 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700666 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700667END_FUNCTION art_quick_get32_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700668
Ian Rogers468532e2013-08-05 10:56:33 -0700669DEFINE_FUNCTION art_quick_get64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700670 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
671 mov %esp, %ebx // remember SP
672 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700673 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800674 .cfi_adjust_cfa_offset 12
675 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700676 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800677 .cfi_adjust_cfa_offset 4
678 PUSH edx // pass referrer
679 PUSH ecx // pass object
680 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700681 call SYMBOL(artGet64InstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700682 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800683 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700684 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700685 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700686END_FUNCTION art_quick_get64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700687
Ian Rogers468532e2013-08-05 10:56:33 -0700688DEFINE_FUNCTION art_quick_get_obj_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700689 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
690 mov %esp, %ebx // remember SP
691 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700692 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800693 .cfi_adjust_cfa_offset 12
694 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700695 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800696 .cfi_adjust_cfa_offset 4
697 PUSH edx // pass referrer
698 PUSH ecx // pass object
699 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700700 call SYMBOL(artGetObjInstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700701 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800702 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700703 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700704 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700705END_FUNCTION art_quick_get_obj_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700706
Ian Rogers468532e2013-08-05 10:56:33 -0700707DEFINE_FUNCTION art_quick_set32_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700708 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
709 mov %esp, %ebx // remember SP
710 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700711 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800712 .cfi_adjust_cfa_offset 12
713 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700714 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800715 .cfi_adjust_cfa_offset 4
716 PUSH edx // pass referrer
717 PUSH ecx // pass new_val
718 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700719 call SYMBOL(artSet32StaticFromCode) // (field_idx, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700720 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800721 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700722 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
723 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700724END_FUNCTION art_quick_set32_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700725
Ian Rogers468532e2013-08-05 10:56:33 -0700726DEFINE_FUNCTION art_quick_set64_static
Ian Rogersaeeada42013-02-13 11:28:34 -0800727 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700728 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700729 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800730 .cfi_adjust_cfa_offset 8
731 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700732 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800733 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700734 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800735 PUSH edx // pass high half of new_val
736 PUSH ecx // pass low half of new_val
737 PUSH ebx // pass referrer
738 PUSH eax // pass field_idx
739 call SYMBOL(artSet64StaticFromCode) // (field_idx, referrer, new_val, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700740 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800741 .cfi_adjust_cfa_offset -32
742 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700743 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700744END_FUNCTION art_quick_set64_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700745
Ian Rogers468532e2013-08-05 10:56:33 -0700746DEFINE_FUNCTION art_quick_set_obj_static
Ian Rogersaeeada42013-02-13 11:28:34 -0800747 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700748 mov %esp, %ebx // remember SP
749 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700750 subl LITERAL(12), %esp // alignment padding
Ian Rogers62d6c772013-02-27 08:32:07 -0800751 .cfi_adjust_cfa_offset 12
Ian Rogersaeeada42013-02-13 11:28:34 -0800752 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700753 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800754 .cfi_adjust_cfa_offset 4
755 PUSH edx // pass referrer
756 PUSH ecx // pass new_val
757 PUSH eax // pass field_idx
758 call SYMBOL(artSetObjStaticFromCode) // (field_idx, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700759 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800760 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700761 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700762END_FUNCTION art_quick_set_obj_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700763
Ian Rogers468532e2013-08-05 10:56:33 -0700764DEFINE_FUNCTION art_quick_get32_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700765 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
766 mov %esp, %edx // remember SP
767 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800768 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700769 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800770 .cfi_adjust_cfa_offset 4
771 PUSH ecx // pass referrer
772 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700773 call SYMBOL(artGet32StaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700774 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800775 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -0700776 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700777 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700778END_FUNCTION art_quick_get32_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700779
Ian Rogers468532e2013-08-05 10:56:33 -0700780DEFINE_FUNCTION art_quick_get64_static
Ian Rogersaeeada42013-02-13 11:28:34 -0800781 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700782 mov %esp, %edx // remember SP
783 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800784 PUSH edx // 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 ecx // pass referrer
788 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700789 call SYMBOL(artGet64StaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700790 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800791 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -0700792 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700793 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700794END_FUNCTION art_quick_get64_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700795
Ian Rogers468532e2013-08-05 10:56:33 -0700796DEFINE_FUNCTION art_quick_get_obj_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700797 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
798 mov %esp, %edx // remember SP
799 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800800 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700801 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800802 .cfi_adjust_cfa_offset 4
803 PUSH ecx // pass referrer
804 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700805 call SYMBOL(artGetObjStaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700806 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800807 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -0700808 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700809 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700810END_FUNCTION art_quick_get_obj_static
jeffhaod66a8752012-05-22 15:30:16 -0700811
Logan Chien8dbb7082013-01-25 20:31:17 +0800812DEFINE_FUNCTION art_quick_proxy_invoke_handler
Ian Rogers7db619b2013-01-16 18:35:48 -0800813 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save frame and Method*
Ian Rogersaeeada42013-02-13 11:28:34 -0800814 PUSH esp // pass SP
jeffhaod66a8752012-05-22 15:30:16 -0700815 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800816 .cfi_adjust_cfa_offset 4
817 PUSH ecx // pass receiver
818 PUSH eax // pass proxy method
Jeff Hao5fa60c32013-04-04 17:57:01 -0700819 call SYMBOL(artQuickProxyInvokeHandler) // (proxy method, receiver, Thread*, SP)
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800820 movd %eax, %xmm0 // place return value also into floating point return value
821 movd %edx, %xmm1
822 punpckldq %xmm1, %xmm0
jeffhaod66a8752012-05-22 15:30:16 -0700823 addl LITERAL(44), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800824 .cfi_adjust_cfa_offset -44
jeffhaod66a8752012-05-22 15:30:16 -0700825 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800826END_FUNCTION art_quick_proxy_invoke_handler
jeffhao9dbb23e2012-05-18 17:03:57 -0700827
Ian Rogers468532e2013-08-05 10:56:33 -0700828DEFINE_FUNCTION art_quick_resolution_trampoline
829 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
830 PUSH esp // pass SP
831 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
832 .cfi_adjust_cfa_offset 4
833 PUSH ecx // pass receiver
834 PUSH eax // pass method
835 call SYMBOL(artQuickResolutionTrampoline) // (Method* called, receiver, Thread*, SP)
836 movl %eax, %edi // remember code pointer in EDI
837 addl LITERAL(16), %esp // pop arguments
838 test %eax, %eax // if code pointer is NULL goto deliver pending exception
839 jz 1f
840 POP eax // called method
841 POP ecx // restore args
842 POP edx
843 POP ebx
844 POP ebp // restore callee saves except EDI
845 POP esi
846 xchgl 0(%esp),%edi // restore EDI and place code pointer as only value on stack
847 ret // tail call into method
8481:
849 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
850 DELIVER_PENDING_EXCEPTION
851END_FUNCTION art_quick_resolution_trampoline
852
853DEFINE_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers62d6c772013-02-27 08:32:07 -0800854 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save frame
Ian Rogersaeeada42013-02-13 11:28:34 -0800855 mov %esp, %edx // remember SP
856 PUSH eax // alignment padding
857 PUSH edx // pass SP
Ian Rogers7db619b2013-01-16 18:35:48 -0800858 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800859 .cfi_adjust_cfa_offset 4
860 PUSH eax // pass method
Ian Rogers468532e2013-08-05 10:56:33 -0700861 call SYMBOL(artQuickToInterpreterBridge) // (method, Thread*, SP)
Ian Rogers7db619b2013-01-16 18:35:48 -0800862 movd %eax, %xmm0 // place return value also into floating point return value
863 movd %edx, %xmm1
864 punpckldq %xmm1, %xmm0
865 addl LITERAL(44), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800866 .cfi_adjust_cfa_offset -44
Ian Rogers7db619b2013-01-16 18:35:48 -0800867 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700868END_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -0800869
jeffhao7e4fcb82013-01-10 18:11:08 -0800870 /*
871 * Routine that intercepts method calls and returns.
872 */
Ian Rogers468532e2013-08-05 10:56:33 -0700873DEFINE_FUNCTION art_quick_instrumentation_entry
Ian Rogers62d6c772013-02-27 08:32:07 -0800874 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
875 movl %esp, %edx // Save SP.
876 PUSH eax // Save eax which will be clobbered by the callee-save method.
877 subl LITERAL(8), %esp // Align stack.
878 .cfi_adjust_cfa_offset 8
879 pushl 40(%esp) // Pass LR.
Ian Rogersaeeada42013-02-13 11:28:34 -0800880 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -0800881 PUSH edx // Pass SP.
882 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Ian Rogersaeeada42013-02-13 11:28:34 -0800883 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -0800884 PUSH ecx // Pass receiver.
885 PUSH eax // Pass Method*.
886 call SYMBOL(artInstrumentationMethodEntryFromCode) // (Method*, Object*, Thread*, SP, LR)
887 addl LITERAL(28), %esp // Pop arguments upto saved Method*.
888 movl 28(%esp), %edi // Restore edi.
889 movl %eax, 28(%esp) // Place code* over edi, just under return pc.
Ian Rogers468532e2013-08-05 10:56:33 -0700890 movl LITERAL(SYMBOL(art_quick_instrumentation_exit)), 32(%esp)
Ian Rogers62d6c772013-02-27 08:32:07 -0800891 // Place instrumentation exit as return pc.
892 movl (%esp), %eax // Restore eax.
893 movl 8(%esp), %ecx // Restore ecx.
894 movl 12(%esp), %edx // Restore edx.
895 movl 16(%esp), %ebx // Restore ebx.
896 movl 20(%esp), %ebp // Restore ebp.
897 movl 24(%esp), %esi // Restore esi.
898 addl LITERAL(28), %esp // Wind stack back upto code*.
899 ret // Call method (and pop).
Ian Rogers468532e2013-08-05 10:56:33 -0700900END_FUNCTION art_quick_instrumentation_entry
Ian Rogers62d6c772013-02-27 08:32:07 -0800901
Ian Rogers468532e2013-08-05 10:56:33 -0700902DEFINE_FUNCTION art_quick_instrumentation_exit
Ian Rogers62d6c772013-02-27 08:32:07 -0800903 pushl LITERAL(0) // Push a fake return PC as there will be none on the stack.
904 SETUP_REF_ONLY_CALLEE_SAVE_FRAME
905 mov %esp, %ecx // Remember SP
906 subl LITERAL(8), %esp // Save float return value.
907 .cfi_adjust_cfa_offset 8
908 movd %xmm0, (%esp)
909 PUSH edx // Save gpr return value.
910 PUSH eax
911 subl LITERAL(8), %esp // Align stack
912 movd %xmm0, (%esp)
913 subl LITERAL(8), %esp // Pass float return value.
914 .cfi_adjust_cfa_offset 8
915 movd %xmm0, (%esp)
916 PUSH edx // Pass gpr return value.
917 PUSH eax
918 PUSH ecx // Pass SP.
919 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current.
Ian Rogersaeeada42013-02-13 11:28:34 -0800920 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -0800921 call SYMBOL(artInstrumentationMethodExitFromCode) // (Thread*, SP, gpr_result, fpr_result)
922 mov %eax, %ecx // Move returned link register.
923 addl LITERAL(32), %esp // Pop arguments.
924 .cfi_adjust_cfa_offset -32
925 movl %edx, %ebx // Move returned link register for deopt
926 // (ebx is pretending to be our LR).
927 POP eax // Restore gpr return value.
928 POP edx
929 movd (%esp), %xmm0 // Restore fpr return value.
930 addl LITERAL(8), %esp
Ian Rogers5793fea2013-02-14 13:33:34 -0800931 .cfi_adjust_cfa_offset -8
Ian Rogers62d6c772013-02-27 08:32:07 -0800932 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
933 addl LITERAL(4), %esp // Remove fake return pc.
934 jmp *%ecx // Return.
Ian Rogers468532e2013-08-05 10:56:33 -0700935END_FUNCTION art_quick_instrumentation_exit
jeffhao162fd332013-01-08 16:21:01 -0800936
jeffhao7e4fcb82013-01-10 18:11:08 -0800937 /*
Ian Rogers62d6c772013-02-27 08:32:07 -0800938 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
939 * will long jump to the upcall with a special exception of -1.
jeffhao7e4fcb82013-01-10 18:11:08 -0800940 */
Logan Chien8dbb7082013-01-25 20:31:17 +0800941DEFINE_FUNCTION art_quick_deoptimize
Ian Rogers62d6c772013-02-27 08:32:07 -0800942 pushl %ebx // Fake that we were called.
Jeff Haoc1fcdf12013-04-11 13:34:01 -0700943 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
Ian Rogers62d6c772013-02-27 08:32:07 -0800944 mov %esp, %ecx // Remember SP.
945 subl LITERAL(8), %esp // Align stack.
946 .cfi_adjust_cfa_offset 8
947 PUSH ecx // Pass SP.
948 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Ian Rogersaeeada42013-02-13 11:28:34 -0800949 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -0800950 call SYMBOL(artDeoptimize) // artDeoptimize(Thread*, SP)
951 int3 // Unreachable.
Ian Rogersaeeada42013-02-13 11:28:34 -0800952END_FUNCTION art_quick_deoptimize
jeffhao162fd332013-01-08 16:21:01 -0800953
jeffhao86e46712012-08-08 17:30:59 -0700954 /*
955 * String's indexOf.
956 *
957 * On entry:
958 * eax: string object (known non-null)
959 * ecx: char to match (known <= 0xFFFF)
960 * edx: Starting offset in string data
961 */
Logan Chien8dbb7082013-01-25 20:31:17 +0800962DEFINE_FUNCTION art_quick_indexof
Ian Rogersaeeada42013-02-13 11:28:34 -0800963 PUSH edi // push callee save reg
jeffhao86e46712012-08-08 17:30:59 -0700964 mov STRING_COUNT_OFFSET(%eax), %ebx
965 mov STRING_VALUE_OFFSET(%eax), %edi
966 mov STRING_OFFSET_OFFSET(%eax), %eax
967 testl %edx, %edx // check if start < 0
968 jl clamp_min
969clamp_done:
970 cmpl %ebx, %edx // check if start >= count
971 jge not_found
972 lea STRING_DATA_OFFSET(%edi, %eax, 2), %edi // build a pointer to the start of string data
973 mov %edi, %eax // save a copy in eax to later compute result
974 lea (%edi, %edx, 2), %edi // build pointer to start of data to compare
975 subl %edx, %ebx // compute iteration count
976 /*
977 * At this point we have:
978 * eax: original start of string data
979 * ecx: char to compare
980 * ebx: length to compare
981 * edi: start of data to test
982 */
983 mov %eax, %edx
984 mov %ecx, %eax // put char to match in %eax
985 mov %ebx, %ecx // put length to compare in %ecx
986 repne scasw // find %ax, starting at [%edi], up to length %ecx
987 jne not_found
988 subl %edx, %edi
989 sar LITERAL(1), %edi
990 decl %edi // index = ((curr_ptr - orig_ptr) / 2) - 1
991 mov %edi, %eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800992 POP edi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -0700993 ret
994 .balign 16
995not_found:
996 mov LITERAL(-1), %eax // return -1 (not found)
Ian Rogersaeeada42013-02-13 11:28:34 -0800997 POP edi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -0700998 ret
999clamp_min:
1000 xor %edx, %edx // clamp start to 0
1001 jmp clamp_done
Ian Rogersaeeada42013-02-13 11:28:34 -08001002END_FUNCTION art_quick_indexof
jeffhao86e46712012-08-08 17:30:59 -07001003
1004 /*
1005 * String's compareTo.
1006 *
1007 * On entry:
1008 * eax: this string object (known non-null)
1009 * ecx: comp string object (known non-null)
1010 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001011DEFINE_FUNCTION art_quick_string_compareto
Ian Rogersaeeada42013-02-13 11:28:34 -08001012 PUSH esi // push callee save reg
1013 PUSH edi // push callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001014 mov STRING_COUNT_OFFSET(%eax), %edx
1015 mov STRING_COUNT_OFFSET(%ecx), %ebx
1016 mov STRING_VALUE_OFFSET(%eax), %esi
1017 mov STRING_VALUE_OFFSET(%ecx), %edi
1018 mov STRING_OFFSET_OFFSET(%eax), %eax
1019 mov STRING_OFFSET_OFFSET(%ecx), %ecx
1020 /* Build pointers to the start of string data */
1021 lea STRING_DATA_OFFSET(%esi, %eax, 2), %esi
1022 lea STRING_DATA_OFFSET(%edi, %ecx, 2), %edi
1023 /* Calculate min length and count diff */
1024 mov %edx, %ecx
1025 mov %edx, %eax
1026 subl %ebx, %eax
1027 cmovg %ebx, %ecx
1028 /*
1029 * At this point we have:
1030 * eax: value to return if first part of strings are equal
1031 * ecx: minimum among the lengths of the two strings
1032 * esi: pointer to this string data
1033 * edi: pointer to comp string data
1034 */
1035 repe cmpsw // find nonmatching chars in [%esi] and [%edi], up to length %ecx
1036 jne not_equal
Ian Rogersaeeada42013-02-13 11:28:34 -08001037 POP edi // pop callee save reg
1038 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001039 ret
1040 .balign 16
1041not_equal:
Ian Rogers1b09b092012-08-20 15:35:52 -07001042 movzwl -2(%esi), %eax // get last compared char from this string
1043 movzwl -2(%edi), %ecx // get last compared char from comp string
jeffhao86e46712012-08-08 17:30:59 -07001044 subl %ecx, %eax // return the difference
Ian Rogersaeeada42013-02-13 11:28:34 -08001045 POP edi // pop callee save reg
1046 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001047 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001048END_FUNCTION art_quick_string_compareto
jeffhao86e46712012-08-08 17:30:59 -07001049
Elliott Hughes787ec202012-03-29 17:14:15 -07001050 // TODO: implement these!
Logan Chien8dbb7082013-01-25 20:31:17 +08001051UNIMPLEMENTED art_quick_memcmp16