blob: 9fce72f7802cce43aafe8112d8e3672a3b4cc64b [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 Rogersa9a82542013-10-04 11:17:26 -0700482 PUSH ecx // pass arg2 - obj->klass
483 PUSH eax // pass arg1 - checked class
484 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
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
Ian Rogersa9a82542013-10-04 11:17:26 -0700490DEFINE_FUNCTION art_quick_check_cast
491 PUSH eax // alignment padding
492 PUSH ecx // pass arg2 - obj->klass
493 PUSH eax // pass arg1 - checked class
494 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
495 testl %eax, %eax
496 jz 1f // jump forward if not assignable
497 addl LITERAL(12), %esp // pop arguments
498 .cfi_adjust_cfa_offset -12
499 ret
5001:
501 POP eax // pop arguments
502 POP ecx
503 addl LITERAL(4), %esp
504 .cfi_adjust_cfa_offset -12
505 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
506 mov %esp, %edx
507 // Outgoing argument set up
508 PUSH edx // pass SP
509 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
510 .cfi_adjust_cfa_offset 4
511 PUSH ecx // pass arg2
512 PUSH eax // pass arg1
513 call SYMBOL(artThrowClassCastException) // (Class* a, Class* b, Thread*, SP)
514 int3 // unreached
515END_FUNCTION art_quick_check_cast
516
517 /*
518 * Entry from managed code for array put operations of objects where the value being stored
519 * needs to be checked for compatibility.
520 * eax = array, ecx = index, edx = value
521 */
522DEFINE_FUNCTION art_quick_aput_obj_with_null_and_bound_check
523 testl %eax, %eax
524 jnz art_quick_aput_obj_with_bound_check
525 jmp art_quick_throw_null_pointer_exception
526END_FUNCTION art_quick_aput_obj_with_null_and_bound_check
527
528DEFINE_FUNCTION art_quick_aput_obj_with_bound_check
529 movl ARRAY_LENGTH_OFFSET(%eax), %ebx
530 cmpl %ebx, %ecx
531 jb art_quick_aput_obj
532 mov %ecx, %eax
533 mov %ebx, %ecx
534 jmp art_quick_throw_array_bounds
535END_FUNCTION art_quick_aput_obj_with_bound_check
536
537DEFINE_FUNCTION art_quick_aput_obj
538 test %edx, %edx // store of null
539 jz do_aput_null
540 movl CLASS_OFFSET(%eax), %ebx
541 movl CLASS_COMPONENT_TYPE_OFFSET(%ebx), %ebx
542 cmpl CLASS_OFFSET(%edx), %ebx // value's type == array's component type - trivial assignability
543 jne check_assignability
544do_aput:
545 movl %edx, OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
546 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
547 shrl LITERAL(7), %eax
548 movb %dl, (%edx, %eax)
549 ret
550do_aput_null:
551 movl %edx, OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
552 ret
553check_assignability:
554 PUSH eax // save arguments
555 PUSH ecx
556 PUSH edx
557 subl LITERAL(8), %esp // alignment padding
558 .cfi_adjust_cfa_offset 8
559 pushl CLASS_OFFSET(%edx) // pass arg2 - type of the value to be stored
560 .cfi_adjust_cfa_offset 4
561 PUSH ebx // pass arg1 - component type of the array
562 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b)
563 addl LITERAL(16), %esp // pop arguments
564 .cfi_adjust_cfa_offset -16
565 testl %eax, %eax
566 jz throw_array_store_exception
567 POP edx
568 POP ecx
569 POP eax
570 movl %edx, OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4) // do the aput
571 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
572 shrl LITERAL(7), %eax
573 movb %dl, (%edx, %eax)
574 ret
575throw_array_store_exception:
576 POP edx
577 POP ecx
578 POP eax
579 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
580 mov %esp, %ecx
581 // Outgoing argument set up
582 PUSH ecx // pass SP
583 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
584 .cfi_adjust_cfa_offset 4
585 PUSH edx // pass arg2 - value
586 PUSH eax // pass arg1 - array
587 call SYMBOL(artThrowArrayStoreException) // (array, value, Thread*, SP)
588 int3 // unreached
589END_FUNCTION art_quick_aput_obj
590
Logan Chien8dbb7082013-01-25 20:31:17 +0800591DEFINE_FUNCTION art_quick_memcpy
Ian Rogersaeeada42013-02-13 11:28:34 -0800592 PUSH edx // pass arg3
593 PUSH ecx // pass arg2
594 PUSH eax // pass arg1
Elliott Hughesadc078a2012-04-04 11:39:05 -0700595 call SYMBOL(memcpy) // (void*, const void*, size_t)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700596 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800597 .cfi_adjust_cfa_offset -12
Ian Rogers7caad772012-03-30 01:07:54 -0700598 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800599END_FUNCTION art_quick_memcpy
Ian Rogers7caad772012-03-30 01:07:54 -0700600
Logan Chien8dbb7082013-01-25 20:31:17 +0800601NO_ARG_DOWNCALL art_quick_test_suspend, artTestSuspendFromCode, ret
Ian Rogers7caad772012-03-30 01:07:54 -0700602
Ian Rogers468532e2013-08-05 10:56:33 -0700603DEFINE_FUNCTION art_quick_fmod
jeffhao1395b1e2012-06-13 18:05:13 -0700604 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800605 .cfi_adjust_cfa_offset 12
606 PUSH ebx // pass arg4 b.hi
607 PUSH edx // pass arg3 b.lo
608 PUSH ecx // pass arg2 a.hi
609 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700610 call SYMBOL(fmod) // (jdouble a, jdouble b)
611 fstpl (%esp) // pop return value off fp stack
612 movsd (%esp), %xmm0 // place into %xmm0
613 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800614 .cfi_adjust_cfa_offset -28
jeffhao292188d2012-05-17 15:45:04 -0700615 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700616END_FUNCTION art_quick_fmod
jeffhao292188d2012-05-17 15:45:04 -0700617
Ian Rogers468532e2013-08-05 10:56:33 -0700618DEFINE_FUNCTION art_quick_fmodf
Ian Rogersaeeada42013-02-13 11:28:34 -0800619 PUSH eax // alignment padding
620 PUSH ecx // pass arg2 b
621 PUSH eax // pass arg1 a
jeffhao1395b1e2012-06-13 18:05:13 -0700622 call SYMBOL(fmodf) // (jfloat a, jfloat b)
Ian Rogers1b09b092012-08-20 15:35:52 -0700623 fstps (%esp) // pop return value off fp stack
jeffhao1395b1e2012-06-13 18:05:13 -0700624 movss (%esp), %xmm0 // place into %xmm0
625 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800626 .cfi_adjust_cfa_offset -12
jeffhao292188d2012-05-17 15:45:04 -0700627 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700628END_FUNCTION art_quick_fmodf
jeffhao292188d2012-05-17 15:45:04 -0700629
Ian Rogers468532e2013-08-05 10:56:33 -0700630DEFINE_FUNCTION art_quick_l2d
Ian Rogers5793fea2013-02-14 13:33:34 -0800631 PUSH ecx // push arg2 a.hi
632 PUSH eax // push arg1 a.lo
633 fildll (%esp) // load as integer and push into st0
634 fstpl (%esp) // pop value off fp stack as double
jeffhao41005dd2012-05-09 17:58:52 -0700635 movsd (%esp), %xmm0 // place into %xmm0
Ian Rogers5793fea2013-02-14 13:33:34 -0800636 addl LITERAL(8), %esp // pop arguments
637 .cfi_adjust_cfa_offset -8
jeffhao41005dd2012-05-09 17:58:52 -0700638 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700639END_FUNCTION art_quick_l2d
jeffhao41005dd2012-05-09 17:58:52 -0700640
Ian Rogers468532e2013-08-05 10:56:33 -0700641DEFINE_FUNCTION art_quick_l2f
Ian Rogers5793fea2013-02-14 13:33:34 -0800642 PUSH ecx // push arg2 a.hi
643 PUSH eax // push arg1 a.lo
644 fildll (%esp) // load as integer and push into st0
645 fstps (%esp) // pop value off fp stack as a single
jeffhao41005dd2012-05-09 17:58:52 -0700646 movss (%esp), %xmm0 // place into %xmm0
Ian Rogers5793fea2013-02-14 13:33:34 -0800647 addl LITERAL(8), %esp // pop argument
648 .cfi_adjust_cfa_offset -8
jeffhao41005dd2012-05-09 17:58:52 -0700649 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700650END_FUNCTION art_quick_l2f
jeffhao41005dd2012-05-09 17:58:52 -0700651
Ian Rogers468532e2013-08-05 10:56:33 -0700652DEFINE_FUNCTION art_quick_d2l
Ian Rogersaeeada42013-02-13 11:28:34 -0800653 PUSH eax // alignment padding
654 PUSH ecx // pass arg2 a.hi
655 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700656 call SYMBOL(art_d2l) // (jdouble a)
jeffhao41005dd2012-05-09 17:58:52 -0700657 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800658 .cfi_adjust_cfa_offset -12
jeffhao41005dd2012-05-09 17:58:52 -0700659 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700660END_FUNCTION art_quick_d2l
jeffhao41005dd2012-05-09 17:58:52 -0700661
Ian Rogers468532e2013-08-05 10:56:33 -0700662DEFINE_FUNCTION art_quick_f2l
jeffhao41005dd2012-05-09 17:58:52 -0700663 subl LITERAL(8), %esp // alignment padding
Ian Rogers5793fea2013-02-14 13:33:34 -0800664 .cfi_adjust_cfa_offset 8
Ian Rogersaeeada42013-02-13 11:28:34 -0800665 PUSH eax // pass arg1 a
jeffhao1395b1e2012-06-13 18:05:13 -0700666 call SYMBOL(art_f2l) // (jfloat a)
jeffhao41005dd2012-05-09 17:58:52 -0700667 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800668 .cfi_adjust_cfa_offset -12
jeffhao41005dd2012-05-09 17:58:52 -0700669 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700670END_FUNCTION art_quick_f2l
jeffhao41005dd2012-05-09 17:58:52 -0700671
Ian Rogers468532e2013-08-05 10:56:33 -0700672DEFINE_FUNCTION art_quick_idivmod
jeffhao174651d2012-04-19 15:27:22 -0700673 cmpl LITERAL(0x80000000), %eax
674 je check_arg2 // special case
675args_ok:
Ian Rogers7caad772012-03-30 01:07:54 -0700676 cdq // edx:eax = sign extend eax
677 idiv %ecx // (edx,eax) = (edx:eax % ecx, edx:eax / ecx)
Ian Rogers7caad772012-03-30 01:07:54 -0700678 ret
jeffhao174651d2012-04-19 15:27:22 -0700679check_arg2:
680 cmpl LITERAL(-1), %ecx
681 jne args_ok
682 xorl %edx, %edx
683 ret // eax already holds min int
Ian Rogers468532e2013-08-05 10:56:33 -0700684END_FUNCTION art_quick_idivmod
Ian Rogers7caad772012-03-30 01:07:54 -0700685
Ian Rogers468532e2013-08-05 10:56:33 -0700686DEFINE_FUNCTION art_quick_ldiv
Ian Rogersa9a82542013-10-04 11:17:26 -0700687 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800688 .cfi_adjust_cfa_offset 12
689 PUSH ebx // pass arg4 b.hi
690 PUSH edx // pass arg3 b.lo
691 PUSH ecx // pass arg2 a.hi
Ian Rogersa9a82542013-10-04 11:17:26 -0700692 PUSH eax // pass arg1 a.lo
693 call SYMBOL(artLdiv) // (jlong a, jlong b)
694 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800695 .cfi_adjust_cfa_offset -28
Ian Rogers55bd45f2012-04-04 17:31:20 -0700696 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700697END_FUNCTION art_quick_ldiv
Ian Rogers55bd45f2012-04-04 17:31:20 -0700698
Ian Rogersa9a82542013-10-04 11:17:26 -0700699DEFINE_FUNCTION art_quick_lmod
700 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800701 .cfi_adjust_cfa_offset 12
702 PUSH ebx // pass arg4 b.hi
703 PUSH edx // pass arg3 b.lo
704 PUSH ecx // pass arg2 a.hi
Ian Rogersa9a82542013-10-04 11:17:26 -0700705 PUSH eax // pass arg1 a.lo
706 call SYMBOL(artLmod) // (jlong a, jlong b)
707 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800708 .cfi_adjust_cfa_offset -28
Ian Rogers55bd45f2012-04-04 17:31:20 -0700709 ret
Ian Rogersa9a82542013-10-04 11:17:26 -0700710END_FUNCTION art_quick_lmod
Ian Rogers55bd45f2012-04-04 17:31:20 -0700711
Ian Rogers468532e2013-08-05 10:56:33 -0700712DEFINE_FUNCTION art_quick_lmul
Ian Rogers5793fea2013-02-14 13:33:34 -0800713 imul %eax, %ebx // ebx = a.lo(eax) * b.hi(ebx)
714 imul %edx, %ecx // ecx = b.lo(edx) * a.hi(ecx)
715 mul %edx // edx:eax = a.lo(eax) * b.lo(edx)
716 add %ebx, %ecx
717 add %ecx, %edx // edx += (a.lo * b.hi) + (b.lo * a.hi)
jeffhao644d5312012-05-03 19:04:49 -0700718 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700719END_FUNCTION art_quick_lmul
jeffhao644d5312012-05-03 19:04:49 -0700720
Ian Rogers468532e2013-08-05 10:56:33 -0700721DEFINE_FUNCTION art_quick_lshl
jeffhao644d5312012-05-03 19:04:49 -0700722 // ecx:eax << edx
Ian Rogers141d6222012-04-05 12:23:06 -0700723 xchg %edx, %ecx
724 shld %cl,%eax,%edx
725 shl %cl,%eax
726 test LITERAL(32), %cl
727 jz 1f
728 mov %eax, %edx
729 xor %eax, %eax
7301:
731 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700732END_FUNCTION art_quick_lshl
Ian Rogers141d6222012-04-05 12:23:06 -0700733
Ian Rogers468532e2013-08-05 10:56:33 -0700734DEFINE_FUNCTION art_quick_lshr
jeffhao644d5312012-05-03 19:04:49 -0700735 // ecx:eax >> edx
Ian Rogers141d6222012-04-05 12:23:06 -0700736 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -0700737 shrd %cl,%edx,%eax
738 sar %cl,%edx
Ian Rogers141d6222012-04-05 12:23:06 -0700739 test LITERAL(32),%cl
740 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -0700741 mov %edx, %eax
742 sar LITERAL(31), %edx
Ian Rogers141d6222012-04-05 12:23:06 -07007431:
744 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700745END_FUNCTION art_quick_lshr
Ian Rogers141d6222012-04-05 12:23:06 -0700746
Ian Rogers468532e2013-08-05 10:56:33 -0700747DEFINE_FUNCTION art_quick_lushr
jeffhao644d5312012-05-03 19:04:49 -0700748 // ecx:eax >>> edx
Ian Rogers141d6222012-04-05 12:23:06 -0700749 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -0700750 shrd %cl,%edx,%eax
751 shr %cl,%edx
752 test LITERAL(32),%cl
Ian Rogers141d6222012-04-05 12:23:06 -0700753 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -0700754 mov %edx, %eax
755 xor %edx, %edx
Ian Rogers141d6222012-04-05 12:23:06 -07007561:
757 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700758END_FUNCTION art_quick_lushr
Ian Rogers141d6222012-04-05 12:23:06 -0700759
Ian Rogers468532e2013-08-05 10:56:33 -0700760DEFINE_FUNCTION art_quick_set32_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700761 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
762 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700763 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800764 .cfi_adjust_cfa_offset 8
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
jeffhao9dbb23e2012-05-18 17:03:57 -0700768 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800769 PUSH ebx // pass referrer
770 PUSH edx // pass new_val
771 PUSH ecx // pass object
772 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700773 call SYMBOL(artSet32InstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700774 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800775 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700776 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
777 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700778END_FUNCTION art_quick_set32_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700779
Ian Rogers468532e2013-08-05 10:56:33 -0700780DEFINE_FUNCTION art_quick_set64_instance
Ian Rogersaeeada42013-02-13 11:28:34 -0800781 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao1ff4cd72012-05-21 11:17:48 -0700782 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800783 .cfi_adjust_cfa_offset 8
784 PUSH esp // pass SP-8
jeffhao1ff4cd72012-05-21 11:17:48 -0700785 addl LITERAL(8), (%esp) // fix SP on stack by adding 8
jeffhao9dbb23e2012-05-18 17:03:57 -0700786 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800787 .cfi_adjust_cfa_offset 4
788 PUSH ebx // pass high half of new_val
789 PUSH edx // pass low half of new_val
790 PUSH ecx // pass object
791 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700792 call SYMBOL(artSet64InstanceFromCode) // (field_idx, Object*, new_val, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700793 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800794 .cfi_adjust_cfa_offset -32
795 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700796 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700797END_FUNCTION art_quick_set64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700798
Ian Rogers468532e2013-08-05 10:56:33 -0700799DEFINE_FUNCTION art_quick_set_obj_instance
Ian Rogersaeeada42013-02-13 11:28:34 -0800800 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700801 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700802 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800803 .cfi_adjust_cfa_offset 8
804 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700805 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800806 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700807 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800808 PUSH ebx // pass referrer
809 PUSH edx // pass new_val
810 PUSH ecx // pass object
811 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700812 call SYMBOL(artSetObjInstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700813 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800814 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700815 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
816 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700817END_FUNCTION art_quick_set_obj_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700818
Ian Rogers468532e2013-08-05 10:56:33 -0700819DEFINE_FUNCTION art_quick_get32_instance
Ian Rogersaeeada42013-02-13 11:28:34 -0800820 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700821 mov %esp, %ebx // remember SP
822 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700823 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800824 .cfi_adjust_cfa_offset 12
825 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700826 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800827 .cfi_adjust_cfa_offset 4
828 PUSH edx // pass referrer
829 PUSH ecx // pass object
830 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700831 call SYMBOL(artGet32InstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700832 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800833 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700834 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700835 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700836END_FUNCTION art_quick_get32_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700837
Ian Rogers468532e2013-08-05 10:56:33 -0700838DEFINE_FUNCTION art_quick_get64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700839 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
840 mov %esp, %ebx // remember SP
841 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700842 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800843 .cfi_adjust_cfa_offset 12
844 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700845 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800846 .cfi_adjust_cfa_offset 4
847 PUSH edx // pass referrer
848 PUSH ecx // pass object
849 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700850 call SYMBOL(artGet64InstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700851 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800852 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700853 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700854 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700855END_FUNCTION art_quick_get64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700856
Ian Rogers468532e2013-08-05 10:56:33 -0700857DEFINE_FUNCTION art_quick_get_obj_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700858 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
859 mov %esp, %ebx // remember SP
860 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700861 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800862 .cfi_adjust_cfa_offset 12
863 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700864 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800865 .cfi_adjust_cfa_offset 4
866 PUSH edx // pass referrer
867 PUSH ecx // pass object
868 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700869 call SYMBOL(artGetObjInstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700870 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800871 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700872 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700873 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700874END_FUNCTION art_quick_get_obj_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700875
Ian Rogers468532e2013-08-05 10:56:33 -0700876DEFINE_FUNCTION art_quick_set32_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700877 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
878 mov %esp, %ebx // remember SP
879 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700880 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800881 .cfi_adjust_cfa_offset 12
882 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700883 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800884 .cfi_adjust_cfa_offset 4
885 PUSH edx // pass referrer
886 PUSH ecx // pass new_val
887 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700888 call SYMBOL(artSet32StaticFromCode) // (field_idx, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700889 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800890 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700891 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
892 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700893END_FUNCTION art_quick_set32_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700894
Ian Rogers468532e2013-08-05 10:56:33 -0700895DEFINE_FUNCTION art_quick_set64_static
Ian Rogersaeeada42013-02-13 11:28:34 -0800896 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700897 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700898 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800899 .cfi_adjust_cfa_offset 8
900 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700901 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800902 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700903 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800904 PUSH edx // pass high half of new_val
905 PUSH ecx // pass low half of new_val
906 PUSH ebx // pass referrer
907 PUSH eax // pass field_idx
908 call SYMBOL(artSet64StaticFromCode) // (field_idx, referrer, new_val, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700909 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800910 .cfi_adjust_cfa_offset -32
911 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700912 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700913END_FUNCTION art_quick_set64_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700914
Ian Rogers468532e2013-08-05 10:56:33 -0700915DEFINE_FUNCTION art_quick_set_obj_static
Ian Rogersaeeada42013-02-13 11:28:34 -0800916 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700917 mov %esp, %ebx // remember SP
918 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700919 subl LITERAL(12), %esp // alignment padding
Ian Rogers62d6c772013-02-27 08:32:07 -0800920 .cfi_adjust_cfa_offset 12
Ian Rogersaeeada42013-02-13 11:28:34 -0800921 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700922 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800923 .cfi_adjust_cfa_offset 4
924 PUSH edx // pass referrer
925 PUSH ecx // pass new_val
926 PUSH eax // pass field_idx
927 call SYMBOL(artSetObjStaticFromCode) // (field_idx, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700928 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800929 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700930 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700931END_FUNCTION art_quick_set_obj_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700932
Ian Rogers468532e2013-08-05 10:56:33 -0700933DEFINE_FUNCTION art_quick_get32_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700934 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
935 mov %esp, %edx // remember SP
936 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800937 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700938 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800939 .cfi_adjust_cfa_offset 4
940 PUSH ecx // pass referrer
941 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700942 call SYMBOL(artGet32StaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700943 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800944 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -0700945 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700946 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700947END_FUNCTION art_quick_get32_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700948
Ian Rogers468532e2013-08-05 10:56:33 -0700949DEFINE_FUNCTION art_quick_get64_static
Ian Rogersaeeada42013-02-13 11:28:34 -0800950 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700951 mov %esp, %edx // remember SP
952 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800953 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700954 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800955 .cfi_adjust_cfa_offset 4
956 PUSH ecx // pass referrer
957 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700958 call SYMBOL(artGet64StaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700959 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800960 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -0700961 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700962 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700963END_FUNCTION art_quick_get64_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700964
Ian Rogers468532e2013-08-05 10:56:33 -0700965DEFINE_FUNCTION art_quick_get_obj_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700966 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
967 mov %esp, %edx // remember SP
968 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800969 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700970 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800971 .cfi_adjust_cfa_offset 4
972 PUSH ecx // pass referrer
973 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700974 call SYMBOL(artGetObjStaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700975 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800976 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -0700977 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700978 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700979END_FUNCTION art_quick_get_obj_static
jeffhaod66a8752012-05-22 15:30:16 -0700980
Logan Chien8dbb7082013-01-25 20:31:17 +0800981DEFINE_FUNCTION art_quick_proxy_invoke_handler
Ian Rogers7db619b2013-01-16 18:35:48 -0800982 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save frame and Method*
Ian Rogersaeeada42013-02-13 11:28:34 -0800983 PUSH esp // pass SP
jeffhaod66a8752012-05-22 15:30:16 -0700984 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800985 .cfi_adjust_cfa_offset 4
986 PUSH ecx // pass receiver
987 PUSH eax // pass proxy method
Jeff Hao5fa60c32013-04-04 17:57:01 -0700988 call SYMBOL(artQuickProxyInvokeHandler) // (proxy method, receiver, Thread*, SP)
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800989 movd %eax, %xmm0 // place return value also into floating point return value
990 movd %edx, %xmm1
991 punpckldq %xmm1, %xmm0
jeffhaod66a8752012-05-22 15:30:16 -0700992 addl LITERAL(44), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800993 .cfi_adjust_cfa_offset -44
jeffhaod66a8752012-05-22 15:30:16 -0700994 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800995END_FUNCTION art_quick_proxy_invoke_handler
jeffhao9dbb23e2012-05-18 17:03:57 -0700996
Ian Rogers468532e2013-08-05 10:56:33 -0700997DEFINE_FUNCTION art_quick_resolution_trampoline
998 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
999 PUSH esp // pass SP
1000 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1001 .cfi_adjust_cfa_offset 4
1002 PUSH ecx // pass receiver
1003 PUSH eax // pass method
1004 call SYMBOL(artQuickResolutionTrampoline) // (Method* called, receiver, Thread*, SP)
1005 movl %eax, %edi // remember code pointer in EDI
1006 addl LITERAL(16), %esp // pop arguments
1007 test %eax, %eax // if code pointer is NULL goto deliver pending exception
1008 jz 1f
1009 POP eax // called method
1010 POP ecx // restore args
1011 POP edx
1012 POP ebx
1013 POP ebp // restore callee saves except EDI
1014 POP esi
1015 xchgl 0(%esp),%edi // restore EDI and place code pointer as only value on stack
1016 ret // tail call into method
10171:
1018 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
1019 DELIVER_PENDING_EXCEPTION
1020END_FUNCTION art_quick_resolution_trampoline
1021
1022DEFINE_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers62d6c772013-02-27 08:32:07 -08001023 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save frame
Ian Rogersaeeada42013-02-13 11:28:34 -08001024 mov %esp, %edx // remember SP
1025 PUSH eax // alignment padding
1026 PUSH edx // pass SP
Ian Rogers7db619b2013-01-16 18:35:48 -08001027 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -08001028 .cfi_adjust_cfa_offset 4
1029 PUSH eax // pass method
Ian Rogers468532e2013-08-05 10:56:33 -07001030 call SYMBOL(artQuickToInterpreterBridge) // (method, Thread*, SP)
Ian Rogers7db619b2013-01-16 18:35:48 -08001031 movd %eax, %xmm0 // place return value also into floating point return value
1032 movd %edx, %xmm1
1033 punpckldq %xmm1, %xmm0
1034 addl LITERAL(44), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -08001035 .cfi_adjust_cfa_offset -44
Ian Rogers7db619b2013-01-16 18:35:48 -08001036 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001037END_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001038
jeffhao7e4fcb82013-01-10 18:11:08 -08001039 /*
1040 * Routine that intercepts method calls and returns.
1041 */
Ian Rogers468532e2013-08-05 10:56:33 -07001042DEFINE_FUNCTION art_quick_instrumentation_entry
Ian Rogers62d6c772013-02-27 08:32:07 -08001043 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
1044 movl %esp, %edx // Save SP.
1045 PUSH eax // Save eax which will be clobbered by the callee-save method.
1046 subl LITERAL(8), %esp // Align stack.
1047 .cfi_adjust_cfa_offset 8
1048 pushl 40(%esp) // Pass LR.
Ian Rogersaeeada42013-02-13 11:28:34 -08001049 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -08001050 PUSH edx // Pass SP.
1051 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Ian Rogersaeeada42013-02-13 11:28:34 -08001052 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -08001053 PUSH ecx // Pass receiver.
1054 PUSH eax // Pass Method*.
1055 call SYMBOL(artInstrumentationMethodEntryFromCode) // (Method*, Object*, Thread*, SP, LR)
1056 addl LITERAL(28), %esp // Pop arguments upto saved Method*.
1057 movl 28(%esp), %edi // Restore edi.
1058 movl %eax, 28(%esp) // Place code* over edi, just under return pc.
Ian Rogers468532e2013-08-05 10:56:33 -07001059 movl LITERAL(SYMBOL(art_quick_instrumentation_exit)), 32(%esp)
Ian Rogers62d6c772013-02-27 08:32:07 -08001060 // Place instrumentation exit as return pc.
1061 movl (%esp), %eax // Restore eax.
1062 movl 8(%esp), %ecx // Restore ecx.
1063 movl 12(%esp), %edx // Restore edx.
1064 movl 16(%esp), %ebx // Restore ebx.
1065 movl 20(%esp), %ebp // Restore ebp.
1066 movl 24(%esp), %esi // Restore esi.
1067 addl LITERAL(28), %esp // Wind stack back upto code*.
1068 ret // Call method (and pop).
Ian Rogers468532e2013-08-05 10:56:33 -07001069END_FUNCTION art_quick_instrumentation_entry
Ian Rogers62d6c772013-02-27 08:32:07 -08001070
Ian Rogers468532e2013-08-05 10:56:33 -07001071DEFINE_FUNCTION art_quick_instrumentation_exit
Ian Rogers62d6c772013-02-27 08:32:07 -08001072 pushl LITERAL(0) // Push a fake return PC as there will be none on the stack.
1073 SETUP_REF_ONLY_CALLEE_SAVE_FRAME
1074 mov %esp, %ecx // Remember SP
1075 subl LITERAL(8), %esp // Save float return value.
1076 .cfi_adjust_cfa_offset 8
1077 movd %xmm0, (%esp)
1078 PUSH edx // Save gpr return value.
1079 PUSH eax
1080 subl LITERAL(8), %esp // Align stack
1081 movd %xmm0, (%esp)
1082 subl LITERAL(8), %esp // Pass float return value.
1083 .cfi_adjust_cfa_offset 8
1084 movd %xmm0, (%esp)
1085 PUSH edx // Pass gpr return value.
1086 PUSH eax
1087 PUSH ecx // Pass SP.
1088 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current.
Ian Rogersaeeada42013-02-13 11:28:34 -08001089 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -08001090 call SYMBOL(artInstrumentationMethodExitFromCode) // (Thread*, SP, gpr_result, fpr_result)
1091 mov %eax, %ecx // Move returned link register.
1092 addl LITERAL(32), %esp // Pop arguments.
1093 .cfi_adjust_cfa_offset -32
1094 movl %edx, %ebx // Move returned link register for deopt
1095 // (ebx is pretending to be our LR).
1096 POP eax // Restore gpr return value.
1097 POP edx
1098 movd (%esp), %xmm0 // Restore fpr return value.
1099 addl LITERAL(8), %esp
Ian Rogers5793fea2013-02-14 13:33:34 -08001100 .cfi_adjust_cfa_offset -8
Ian Rogers62d6c772013-02-27 08:32:07 -08001101 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
1102 addl LITERAL(4), %esp // Remove fake return pc.
1103 jmp *%ecx // Return.
Ian Rogers468532e2013-08-05 10:56:33 -07001104END_FUNCTION art_quick_instrumentation_exit
jeffhao162fd332013-01-08 16:21:01 -08001105
jeffhao7e4fcb82013-01-10 18:11:08 -08001106 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001107 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1108 * will long jump to the upcall with a special exception of -1.
jeffhao7e4fcb82013-01-10 18:11:08 -08001109 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001110DEFINE_FUNCTION art_quick_deoptimize
Ian Rogers62d6c772013-02-27 08:32:07 -08001111 pushl %ebx // Fake that we were called.
Jeff Haoc1fcdf12013-04-11 13:34:01 -07001112 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
Ian Rogers62d6c772013-02-27 08:32:07 -08001113 mov %esp, %ecx // Remember SP.
1114 subl LITERAL(8), %esp // Align stack.
1115 .cfi_adjust_cfa_offset 8
1116 PUSH ecx // Pass SP.
1117 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Ian Rogersaeeada42013-02-13 11:28:34 -08001118 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -08001119 call SYMBOL(artDeoptimize) // artDeoptimize(Thread*, SP)
1120 int3 // Unreachable.
Ian Rogersaeeada42013-02-13 11:28:34 -08001121END_FUNCTION art_quick_deoptimize
jeffhao162fd332013-01-08 16:21:01 -08001122
jeffhao86e46712012-08-08 17:30:59 -07001123 /*
1124 * String's indexOf.
1125 *
1126 * On entry:
1127 * eax: string object (known non-null)
1128 * ecx: char to match (known <= 0xFFFF)
1129 * edx: Starting offset in string data
1130 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001131DEFINE_FUNCTION art_quick_indexof
Ian Rogersaeeada42013-02-13 11:28:34 -08001132 PUSH edi // push callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001133 mov STRING_COUNT_OFFSET(%eax), %ebx
1134 mov STRING_VALUE_OFFSET(%eax), %edi
1135 mov STRING_OFFSET_OFFSET(%eax), %eax
1136 testl %edx, %edx // check if start < 0
1137 jl clamp_min
1138clamp_done:
1139 cmpl %ebx, %edx // check if start >= count
1140 jge not_found
1141 lea STRING_DATA_OFFSET(%edi, %eax, 2), %edi // build a pointer to the start of string data
1142 mov %edi, %eax // save a copy in eax to later compute result
1143 lea (%edi, %edx, 2), %edi // build pointer to start of data to compare
1144 subl %edx, %ebx // compute iteration count
1145 /*
1146 * At this point we have:
1147 * eax: original start of string data
1148 * ecx: char to compare
1149 * ebx: length to compare
1150 * edi: start of data to test
1151 */
1152 mov %eax, %edx
1153 mov %ecx, %eax // put char to match in %eax
1154 mov %ebx, %ecx // put length to compare in %ecx
1155 repne scasw // find %ax, starting at [%edi], up to length %ecx
1156 jne not_found
1157 subl %edx, %edi
1158 sar LITERAL(1), %edi
1159 decl %edi // index = ((curr_ptr - orig_ptr) / 2) - 1
1160 mov %edi, %eax
Ian Rogersaeeada42013-02-13 11:28:34 -08001161 POP edi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001162 ret
1163 .balign 16
1164not_found:
1165 mov LITERAL(-1), %eax // return -1 (not found)
Ian Rogersaeeada42013-02-13 11:28:34 -08001166 POP edi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001167 ret
1168clamp_min:
1169 xor %edx, %edx // clamp start to 0
1170 jmp clamp_done
Ian Rogersaeeada42013-02-13 11:28:34 -08001171END_FUNCTION art_quick_indexof
jeffhao86e46712012-08-08 17:30:59 -07001172
1173 /*
1174 * String's compareTo.
1175 *
1176 * On entry:
1177 * eax: this string object (known non-null)
1178 * ecx: comp string object (known non-null)
1179 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001180DEFINE_FUNCTION art_quick_string_compareto
Ian Rogersaeeada42013-02-13 11:28:34 -08001181 PUSH esi // push callee save reg
1182 PUSH edi // push callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001183 mov STRING_COUNT_OFFSET(%eax), %edx
1184 mov STRING_COUNT_OFFSET(%ecx), %ebx
1185 mov STRING_VALUE_OFFSET(%eax), %esi
1186 mov STRING_VALUE_OFFSET(%ecx), %edi
1187 mov STRING_OFFSET_OFFSET(%eax), %eax
1188 mov STRING_OFFSET_OFFSET(%ecx), %ecx
1189 /* Build pointers to the start of string data */
1190 lea STRING_DATA_OFFSET(%esi, %eax, 2), %esi
1191 lea STRING_DATA_OFFSET(%edi, %ecx, 2), %edi
1192 /* Calculate min length and count diff */
1193 mov %edx, %ecx
1194 mov %edx, %eax
1195 subl %ebx, %eax
1196 cmovg %ebx, %ecx
1197 /*
1198 * At this point we have:
1199 * eax: value to return if first part of strings are equal
1200 * ecx: minimum among the lengths of the two strings
1201 * esi: pointer to this string data
1202 * edi: pointer to comp string data
1203 */
1204 repe cmpsw // find nonmatching chars in [%esi] and [%edi], up to length %ecx
1205 jne not_equal
Ian Rogersaeeada42013-02-13 11:28:34 -08001206 POP edi // pop callee save reg
1207 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001208 ret
1209 .balign 16
1210not_equal:
Ian Rogers1b09b092012-08-20 15:35:52 -07001211 movzwl -2(%esi), %eax // get last compared char from this string
1212 movzwl -2(%edi), %ecx // get last compared char from comp string
jeffhao86e46712012-08-08 17:30:59 -07001213 subl %ecx, %eax // return the difference
Ian Rogersaeeada42013-02-13 11:28:34 -08001214 POP edi // pop callee save reg
1215 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001216 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001217END_FUNCTION art_quick_string_compareto
jeffhao86e46712012-08-08 17:30:59 -07001218
Elliott Hughes787ec202012-03-29 17:14:15 -07001219 // TODO: implement these!
Logan Chien8dbb7082013-01-25 20:31:17 +08001220UNIMPLEMENTED art_quick_memcmp16