blob: 32d657d820dbccab2333c31e1b836887dc74c9df [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 Rogers57b86d42012-03-27 16:05:41 -070017#include "asm_support.h"
18
19#if defined(__APPLE__)
Elliott Hughes787ec202012-03-29 17:14:15 -070020 // Mac OS' as(1) doesn't let you name macro parameters.
21 #define MACRO0(macro_name) .macro macro_name
22 #define MACRO1(macro_name, macro_arg1) .macro macro_name
23 #define MACRO2(macro_name, macro_arg1, macro_args2) .macro macro_name
Ian Rogersd36c52e2012-04-09 16:29:25 -070024 #define MACRO3(macro_name, macro_arg1, macro_args2, macro_args3) .macro macro_name
Elliott Hughes787ec202012-03-29 17:14:15 -070025 #define END_MACRO .endmacro
26
27 // Mac OS' as(1) uses $0, $1, and so on for macro arguments, and function names
28 // are mangled with an extra underscore prefix. The use of $x for arguments
29 // mean that literals need to be represented with $$x in macros.
Elliott Hughes20a7a072012-04-04 12:54:00 -070030 #define SYMBOL(name) _ ## name
Elliott Hughesadc078a2012-04-04 11:39:05 -070031 #define VAR(name,index) SYMBOL($index)
Ian Rogersaeeada42013-02-13 11:28:34 -080032 #define REG_VAR(name,index) %$index
Elliott Hughes754caaa2012-04-10 10:57:36 -070033 #define CALL_MACRO(name,index) $index
Elliott Hughesea944212012-04-05 13:11:53 -070034 #define LITERAL(value) $value
35 #define MACRO_LITERAL(value) $$value
Elliott Hughes787ec202012-03-29 17:14:15 -070036#else
37 // Regular gas(1) lets you name macro parameters.
38 #define MACRO0(macro_name) .macro macro_name
39 #define MACRO1(macro_name, macro_arg1) .macro macro_name macro_arg1
40 #define MACRO2(macro_name, macro_arg1, macro_arg2) .macro macro_name macro_arg1, macro_arg2
Ian Rogersd36c52e2012-04-09 16:29:25 -070041 #define MACRO3(macro_name, macro_arg1, macro_arg2, macro_arg3) .macro macro_name macro_arg1, macro_arg2, macro_arg3
Elliott Hughes787ec202012-03-29 17:14:15 -070042 #define END_MACRO .endm
43
44 // Regular gas(1) uses \argument_name for macro arguments.
45 // We need to turn on alternate macro syntax so we can use & instead or the preprocessor
46 // will screw us by inserting a space between the \ and the name. Even in this mode there's
Ian Rogersaeeada42013-02-13 11:28:34 -080047 // no special meaning to $, so literals are still just $x. The use of altmacro means % is a
48 // special character meaning care needs to be taken when passing registers as macro arguments.
Elliott Hughes787ec202012-03-29 17:14:15 -070049 .altmacro
Elliott Hughesadc078a2012-04-04 11:39:05 -070050 #define SYMBOL(name) name
Elliott Hughes787ec202012-03-29 17:14:15 -070051 #define VAR(name,index) name&
Ian Rogersaeeada42013-02-13 11:28:34 -080052 #define REG_VAR(name,index) %name
Elliott Hughes754caaa2012-04-10 10:57:36 -070053 #define CALL_MACRO(name,index) name&
Elliott Hughes787ec202012-03-29 17:14:15 -070054 #define LITERAL(value) $value
Elliott Hughesea944212012-04-05 13:11:53 -070055 #define MACRO_LITERAL(value) $value
Ian Rogers57b86d42012-03-27 16:05:41 -070056#endif
57
Ian Rogers57b86d42012-03-27 16:05:41 -070058 /* Cache alignment for function entry */
Elliott Hughes787ec202012-03-29 17:14:15 -070059MACRO0(ALIGN_FUNCTION_ENTRY)
Ian Rogers57b86d42012-03-27 16:05:41 -070060 .balign 16
Elliott Hughes787ec202012-03-29 17:14:15 -070061END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070062
Ian Rogersaeeada42013-02-13 11:28:34 -080063MACRO1(DEFINE_FUNCTION, c_name)
64 .type VAR(c_name, 0), @function
Elliott Hughes5e284222012-04-04 13:38:03 -070065 .globl VAR(c_name, 0)
66 ALIGN_FUNCTION_ENTRY
67VAR(c_name, 0):
Ian Rogersaeeada42013-02-13 11:28:34 -080068 .cfi_startproc
69END_MACRO
70
71MACRO1(END_FUNCTION, c_name)
72 .cfi_endproc
73 .size \c_name, .-\c_name
74END_MACRO
75
76MACRO1(PUSH, reg)
77 pushl REG_VAR(reg, 0)
78 .cfi_adjust_cfa_offset 4
79 .cfi_rel_offset REG_VAR(reg, 0), 0
80END_MACRO
81
82MACRO1(POP, reg)
83 popl REG_VAR(reg,0)
84 .cfi_adjust_cfa_offset -4
85 .cfi_restore REG_VAR(reg,0)
Elliott Hughes5e284222012-04-04 13:38:03 -070086END_MACRO
87
Ian Rogers57b86d42012-03-27 16:05:41 -070088 /*
89 * Macro that sets up the callee save frame to conform with
Ian Rogers7caad772012-03-30 01:07:54 -070090 * Runtime::CreateCalleeSaveMethod(kSaveAll)
Ian Rogers57b86d42012-03-27 16:05:41 -070091 */
Elliott Hughes787ec202012-03-29 17:14:15 -070092MACRO0(SETUP_SAVE_ALL_CALLEE_SAVE_FRAME)
Ian Rogersaeeada42013-02-13 11:28:34 -080093 PUSH edi // Save callee saves (ebx is saved/restored by the upcall)
94 PUSH esi
95 PUSH ebp
Elliott Hughesea944212012-04-05 13:11:53 -070096 subl MACRO_LITERAL(16), %esp // Grow stack by 4 words, bottom word will hold Method*
Ian Rogersaeeada42013-02-13 11:28:34 -080097 .cfi_adjust_cfa_offset 16
Elliott Hughes787ec202012-03-29 17:14:15 -070098END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070099
Ian Rogers7caad772012-03-30 01:07:54 -0700100 /*
101 * Macro that sets up the callee save frame to conform with
102 * Runtime::CreateCalleeSaveMethod(kRefsOnly)
103 */
104MACRO0(SETUP_REF_ONLY_CALLEE_SAVE_FRAME)
Ian Rogersaeeada42013-02-13 11:28:34 -0800105 PUSH edi // Save callee saves (ebx is saved/restored by the upcall)
106 PUSH esi
107 PUSH ebp
Elliott Hughesea944212012-04-05 13:11:53 -0700108 subl MACRO_LITERAL(16), %esp // Grow stack by 4 words, bottom word will hold Method*
Ian Rogersaeeada42013-02-13 11:28:34 -0800109 .cfi_adjust_cfa_offset 16
Ian Rogers7caad772012-03-30 01:07:54 -0700110END_MACRO
111
112MACRO0(RESTORE_REF_ONLY_CALLEE_SAVE_FRAME)
Elliott Hughesea944212012-04-05 13:11:53 -0700113 addl MACRO_LITERAL(28), %esp // Unwind stack up to return address
Ian Rogersaeeada42013-02-13 11:28:34 -0800114 .cfi_adjust_cfa_offset -28
Elliott Hughes787ec202012-03-29 17:14:15 -0700115END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700116
117 /*
118 * Macro that sets up the callee save frame to conform with
Ian Rogers7caad772012-03-30 01:07:54 -0700119 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs)
Ian Rogers57b86d42012-03-27 16:05:41 -0700120 */
jeffhao9dbb23e2012-05-18 17:03:57 -0700121MACRO0(SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME)
Ian Rogersaeeada42013-02-13 11:28:34 -0800122 PUSH edi // Save callee saves
123 PUSH esi
124 PUSH ebp
125 PUSH ebx // Save args
126 PUSH edx
127 PUSH ecx
128 PUSH eax // Align stack, eax will be clobbered by Method*
Elliott Hughes787ec202012-03-29 17:14:15 -0700129END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700130
jeffhao9dbb23e2012-05-18 17:03:57 -0700131MACRO0(RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME)
Elliott Hughesea944212012-04-05 13:11:53 -0700132 addl MACRO_LITERAL(4), %esp // Remove padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800133 .cfi_adjust_cfa_offset -4
134 POP ecx // Restore args except eax
135 POP edx
136 POP ebx
137 POP ebp // Restore callee saves
138 POP esi
139 POP edi
Elliott Hughes787ec202012-03-29 17:14:15 -0700140END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700141
142 /*
143 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
144 * exception is Thread::Current()->exception_.
145 */
Elliott Hughes787ec202012-03-29 17:14:15 -0700146MACRO0(DELIVER_PENDING_EXCEPTION)
Ian Rogers57b86d42012-03-27 16:05:41 -0700147 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save callee saves for throw
148 mov %esp, %ecx
149 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700150 subl MACRO_LITERAL(8), %esp // Alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800151 .cfi_adjust_cfa_offset 8
152 PUSH ecx // pass SP
Ian Rogers57b86d42012-03-27 16:05:41 -0700153 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800154 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700155 call SYMBOL(artDeliverPendingExceptionFromCode) // artDeliverPendingExceptionFromCode(Thread*, SP)
156 int3 // unreached
Elliott Hughes787ec202012-03-29 17:14:15 -0700157END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700158
Elliott Hughes787ec202012-03-29 17:14:15 -0700159MACRO2(NO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Ian Rogersaeeada42013-02-13 11:28:34 -0800160 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700161 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
162 mov %esp, %ecx
163 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700164 subl MACRO_LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800165 .cfi_adjust_cfa_offset 8
166 PUSH ecx // pass SP
Ian Rogers55bd45f2012-04-04 17:31:20 -0700167 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800168 .cfi_adjust_cfa_offset 4
Elliott Hughes787ec202012-03-29 17:14:15 -0700169 call VAR(cxx_name, 1) // cxx_name(Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700170 int3 // unreached
Ian Rogersaeeada42013-02-13 11:28:34 -0800171 END_FUNCTION VAR(c_name, 0)
Elliott Hughes787ec202012-03-29 17:14:15 -0700172END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700173
Elliott Hughes787ec202012-03-29 17:14:15 -0700174MACRO2(ONE_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Ian Rogersaeeada42013-02-13 11:28:34 -0800175 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700176 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
177 mov %esp, %ecx
178 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800179 PUSH eax // alignment padding
180 PUSH ecx // pass SP
Ian Rogers57b86d42012-03-27 16:05:41 -0700181 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800182 .cfi_adjust_cfa_offset 4
183 PUSH eax // pass arg1
Elliott Hughes787ec202012-03-29 17:14:15 -0700184 call VAR(cxx_name, 1) // cxx_name(arg1, Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700185 int3 // unreached
Ian Rogersaeeada42013-02-13 11:28:34 -0800186 END_FUNCTION VAR(c_name, 0)
Elliott Hughes787ec202012-03-29 17:14:15 -0700187END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700188
Elliott Hughes787ec202012-03-29 17:14:15 -0700189MACRO2(TWO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Ian Rogersaeeada42013-02-13 11:28:34 -0800190 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700191 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
192 mov %esp, %edx
193 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800194 PUSH edx // pass SP
Ian Rogers57b86d42012-03-27 16:05:41 -0700195 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800196 .cfi_adjust_cfa_offset 4
197 PUSH ecx // pass arg2
198 PUSH eax // pass arg1
Ian Rogers7caad772012-03-30 01:07:54 -0700199 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700200 int3 // unreached
Ian Rogersaeeada42013-02-13 11:28:34 -0800201 END_FUNCTION VAR(c_name, 0)
Elliott Hughes787ec202012-03-29 17:14:15 -0700202END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700203
204 /*
205 * Called by managed code to create and deliver a NullPointerException.
206 */
Logan Chien8dbb7082013-01-25 20:31:17 +0800207NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception_from_code, artThrowNullPointerExceptionFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700208
209 /*
210 * Called by managed code to create and deliver an ArithmeticException.
211 */
Logan Chien8dbb7082013-01-25 20:31:17 +0800212NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero_from_code, artThrowDivZeroFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700213
214 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700215 * Called by managed code to create and deliver a StackOverflowError.
216 */
Logan Chien8dbb7082013-01-25 20:31:17 +0800217NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow_from_code, artThrowStackOverflowFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700218
219 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700220 * Called by managed code, saves callee saves and then calls artThrowException
221 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
222 */
Logan Chien8dbb7082013-01-25 20:31:17 +0800223ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception_from_code, artDeliverExceptionFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700224
225 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700226 * Called by managed code to create and deliver a NoSuchMethodError.
227 */
Logan Chien8dbb7082013-01-25 20:31:17 +0800228ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method_from_code, artThrowNoSuchMethodFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700229
230 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700231 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
232 * index, arg2 holds limit.
233 */
Logan Chien8dbb7082013-01-25 20:31:17 +0800234TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds_from_code, artThrowArrayBoundsFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700235
236 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700237 * All generated callsites for interface invokes and invocation slow paths will load arguments
238 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
239 * the method_idx. This wrapper will save arg1-arg3, load the caller's Method*, align the
240 * stack and call the appropriate C helper.
241 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
242 *
243 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
244 * of the target Method* in r0 and method->code_ in r1.
245 *
246 * If unsuccessful, the helper will return NULL/NULL. There will bea pending exception in the
247 * thread and we branch to another stub to deliver it.
248 *
249 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
250 * pointing back to the original caller.
251 */
Elliott Hughes787ec202012-03-29 17:14:15 -0700252MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name)
Ian Rogersaeeada42013-02-13 11:28:34 -0800253 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700254 // Set up the callee save frame to conform with Runtime::CreateCalleeSaveMethod(kRefsAndArgs)
255 // return address
Ian Rogersaeeada42013-02-13 11:28:34 -0800256 PUSH edi
257 PUSH esi
258 PUSH ebp
259 PUSH ebx
260 PUSH edx
261 PUSH ecx
262 PUSH eax // <-- callee save Method* to go here
Ian Rogers7caad772012-03-30 01:07:54 -0700263 movl %esp, %edx // remember SP
264 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700265 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800266 .cfi_adjust_cfa_offset 12
267 PUSH edx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700268 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800269 .cfi_adjust_cfa_offset 4
Ian Rogers7caad772012-03-30 01:07:54 -0700270 pushl 32(%edx) // pass caller Method*
Ian Rogersaeeada42013-02-13 11:28:34 -0800271 .cfi_adjust_cfa_offset 4
272 PUSH ecx // pass arg2
273 PUSH eax // pass arg1
Ian Rogers7caad772012-03-30 01:07:54 -0700274 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, arg3, Thread*, SP)
275 movl %edx, %edi // save code pointer in EDI
Elliott Hughesea944212012-04-05 13:11:53 -0700276 addl MACRO_LITERAL(36), %esp // Pop arguments skip eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800277 .cfi_adjust_cfa_offset -36
278 POP ecx // Restore args
279 POP edx
280 POP ebx
281 POP ebp // Restore callee saves.
282 POP esi
Ian Rogers7caad772012-03-30 01:07:54 -0700283 // Swap EDI callee save with code pointer.
284 xchgl %edi, (%esp)
285 testl %eax, %eax // Branch forward if exception pending.
286 jz 1f
287 // Tail call to intended method.
288 ret
2891:
jeffhao20b5c6c2012-05-21 14:15:18 -0700290 addl MACRO_LITERAL(4), %esp // Pop code pointer off stack
Ian Rogers5793fea2013-02-14 13:33:34 -0800291 .cfi_adjust_cfa_offset -4
Ian Rogers7caad772012-03-30 01:07:54 -0700292 DELIVER_PENDING_EXCEPTION
Ian Rogersaeeada42013-02-13 11:28:34 -0800293 END_FUNCTION VAR(c_name, 0)
Elliott Hughes787ec202012-03-29 17:14:15 -0700294END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700295
Logan Chien8dbb7082013-01-25 20:31:17 +0800296INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline, artInvokeInterfaceTrampoline
297INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700298
Logan Chien8dbb7082013-01-25 20:31:17 +0800299INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
300INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
301INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
302INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700303
Jeff Hao5d917302013-02-27 17:57:33 -0800304 /*
305 * Invocation stub.
306 * On entry:
307 * [sp] = return address
308 * [sp + 4] = method pointer
309 * [sp + 8] = argument array or NULL for no argument methods
310 * [sp + 12] = size of argument array in bytes
311 * [sp + 16] = (managed) thread pointer
312 * [sp + 20] = JValue* result for non-floating point returns
313 * [sp + 24] = JValue* result for floating point returns
314 */
315DEFINE_FUNCTION art_quick_invoke_stub
316 PUSH ebp // save ebp
317 PUSH ebx // save ebx
318 mov %esp, %ebp // copy value of stack pointer into base pointer
319 .cfi_def_cfa_register ebp
320 mov 20(%ebp), %ebx // get arg array size
321 addl LITERAL(28), %ebx // reserve space for return addr, method*, ebx, and ebp in frame
322 andl LITERAL(0xFFFFFFF8), %ebx // align frame size to 16 bytes
323 subl LITERAL(12), %ebx // remove space for return address, ebx, and ebp
324 subl %ebx, %esp // reserve stack space for argument array
325 lea 4(%esp), %eax // use stack pointer + method ptr as dest for memcpy
326 pushl 20(%ebp) // push size of region to memcpy
327 pushl 16(%ebp) // push arg array as source of memcpy
328 pushl %eax // push stack pointer as destination of memcpy
329 call SYMBOL(memcpy) // (void*, const void*, size_t)
330 addl LITERAL(12), %esp // pop arguments to memcpy
331 movl LITERAL(0), (%esp) // store NULL for method*
332 mov 12(%ebp), %eax // move method pointer into eax
333 mov 4(%esp), %ecx // copy arg1 into ecx
334 mov 8(%esp), %edx // copy arg2 into edx
335 mov 12(%esp), %ebx // copy arg3 into ebx
336 call METHOD_CODE_OFFSET(%eax) // call the method
337 mov %ebp, %esp // restore stack pointer
338 POP ebx // pop ebx
339 POP ebp // pop ebp
340 mov 20(%esp), %ecx // get result pointer
341 mov %eax, (%ecx) // store the result
342 mov %edx, 4(%ecx) // store the other half of the result
343 mov 24(%esp), %ecx // get floating point result pointer
344 movsd %xmm0, (%ecx) // store the floating point result
345 ret
346END_FUNCTION art_quick_invoke_stub
347
Ian Rogersd36c52e2012-04-09 16:29:25 -0700348MACRO3(NO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800349 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700350 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
351 mov %esp, %edx // remember SP
352 // Outgoing argument set up
353 subl MACRO_LITERAL(8), %esp // push padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800354 .cfi_adjust_cfa_offset 8
355 PUSH edx // pass SP
Ian Rogersd36c52e2012-04-09 16:29:25 -0700356 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800357 .cfi_adjust_cfa_offset 4
Ian Rogersd36c52e2012-04-09 16:29:25 -0700358 call VAR(cxx_name, 1) // cxx_name(Thread*, SP)
359 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800360 .cfi_adjust_cfa_offset -16
Ian Rogersd36c52e2012-04-09 16:29:25 -0700361 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700362 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800363 END_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700364END_MACRO
365
366MACRO3(ONE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800367 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700368 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
369 mov %esp, %edx // remember SP
370 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800371 PUSH eax // push padding
372 PUSH edx // pass SP
Ian Rogersd36c52e2012-04-09 16:29:25 -0700373 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800374 .cfi_adjust_cfa_offset 4
375 PUSH eax // pass arg1
Ian Rogersd36c52e2012-04-09 16:29:25 -0700376 call VAR(cxx_name, 1) // cxx_name(arg1, Thread*, SP)
377 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800378 .cfi_adjust_cfa_offset -16
Ian Rogersd36c52e2012-04-09 16:29:25 -0700379 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700380 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800381 END_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700382END_MACRO
383
384MACRO3(TWO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800385 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700386 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
387 mov %esp, %edx // remember SP
388 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800389 PUSH edx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700390 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800391 .cfi_adjust_cfa_offset 4
392 PUSH ecx // pass arg2
393 PUSH eax // pass arg1
Ian Rogersd36c52e2012-04-09 16:29:25 -0700394 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, Thread*, SP)
Elliott Hughesea944212012-04-05 13:11:53 -0700395 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800396 .cfi_adjust_cfa_offset -16
Ian Rogers7caad772012-03-30 01:07:54 -0700397 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700398 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800399 END_FUNCTION VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700400END_MACRO
401
Ian Rogersd36c52e2012-04-09 16:29:25 -0700402MACRO3(THREE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800403 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700404 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
405 mov %esp, %ebx // remember SP
406 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700407 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800408 .cfi_adjust_cfa_offset 12
409 PUSH ebx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700410 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800411 .cfi_adjust_cfa_offset 4
412 PUSH edx // pass arg3
413 PUSH ecx // pass arg2
414 PUSH eax // pass arg1
Ian Rogersd36c52e2012-04-09 16:29:25 -0700415 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, arg3, Thread*, SP)
Elliott Hughesea944212012-04-05 13:11:53 -0700416 addl MACRO_LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800417 .cfi_adjust_cfa_offset -32
Ian Rogers7caad772012-03-30 01:07:54 -0700418 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700419 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800420 END_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700421END_MACRO
422
423MACRO0(RETURN_IF_EAX_NOT_ZERO)
Ian Rogers7caad772012-03-30 01:07:54 -0700424 testl %eax, %eax // eax == 0 ?
Ian Rogersd36c52e2012-04-09 16:29:25 -0700425 jz 1f // if eax == 0 goto 1
426 ret // return
4271: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700428 DELIVER_PENDING_EXCEPTION
429END_MACRO
430
Ian Rogersd36c52e2012-04-09 16:29:25 -0700431MACRO0(RETURN_IF_EAX_ZERO)
432 testl %eax, %eax // eax == 0 ?
433 jnz 1f // if eax != 0 goto 1
434 ret // return
4351: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700436 DELIVER_PENDING_EXCEPTION
Ian Rogersd36c52e2012-04-09 16:29:25 -0700437END_MACRO
Ian Rogers7caad772012-03-30 01:07:54 -0700438
jeffhaod66a8752012-05-22 15:30:16 -0700439MACRO0(RETURN_OR_DELIVER_PENDING_EXCEPTION)
440 mov %fs:THREAD_EXCEPTION_OFFSET, %ebx // get exception field
441 testl %ebx, %ebx // ebx == 0 ?
442 jnz 1f // if ebx != 0 goto 1
443 ret // return
4441: // deliver exception on current thread
445 DELIVER_PENDING_EXCEPTION
446END_MACRO
447
Logan Chien8dbb7082013-01-25 20:31:17 +0800448TWO_ARG_DOWNCALL art_quick_alloc_object_from_code, artAllocObjectFromCode, RETURN_IF_EAX_NOT_ZERO
449TWO_ARG_DOWNCALL art_quick_alloc_object_from_code_with_access_check, artAllocObjectFromCodeWithAccessCheck, RETURN_IF_EAX_NOT_ZERO
450THREE_ARG_DOWNCALL art_quick_alloc_array_from_code, artAllocArrayFromCode, RETURN_IF_EAX_NOT_ZERO
451THREE_ARG_DOWNCALL art_quick_alloc_array_from_code_with_access_check, artAllocArrayFromCodeWithAccessCheck, RETURN_IF_EAX_NOT_ZERO
452THREE_ARG_DOWNCALL art_quick_check_and_alloc_array_from_code, artCheckAndAllocArrayFromCode, RETURN_IF_EAX_NOT_ZERO
453THREE_ARG_DOWNCALL art_quick_check_and_alloc_array_from_code_with_access_check, artCheckAndAllocArrayFromCodeWithAccessCheck, RETURN_IF_EAX_NOT_ZERO
Ian Rogersd36c52e2012-04-09 16:29:25 -0700454
Logan Chien8dbb7082013-01-25 20:31:17 +0800455TWO_ARG_DOWNCALL art_quick_resolve_string_from_code, artResolveStringFromCode, RETURN_IF_EAX_NOT_ZERO
456TWO_ARG_DOWNCALL art_quick_initialize_static_storage_from_code, artInitializeStaticStorageFromCode, RETURN_IF_EAX_NOT_ZERO
457TWO_ARG_DOWNCALL art_quick_initialize_type_from_code, artInitializeTypeFromCode, RETURN_IF_EAX_NOT_ZERO
458TWO_ARG_DOWNCALL art_quick_initialize_type_and_verify_access_from_code, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_EAX_NOT_ZERO
Ian Rogersd36c52e2012-04-09 16:29:25 -0700459
jeffhao7e4fcb82013-01-10 18:11:08 -0800460 /*
461 * On entry, eax and ecx must be preserved, edx is dex PC
462 */
Logan Chien8dbb7082013-01-25 20:31:17 +0800463DEFINE_FUNCTION art_quick_update_debugger
jeffhao7e4fcb82013-01-10 18:11:08 -0800464 mov %eax, %ebx // stash away eax so that it's saved as if it were an argument
jeffhao162fd332013-01-08 16:21:01 -0800465 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
jeffhao7e4fcb82013-01-10 18:11:08 -0800466 subl LITERAL(4), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800467 .cfi_adjust_cfa_offset 4
468 PUSH esp // pass arg2 (sp)
jeffhao162fd332013-01-08 16:21:01 -0800469 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800470 .cfi_adjust_cfa_offset 4
471 PUSH edx // pass arg0 (dex pc)
jeffhao162fd332013-01-08 16:21:01 -0800472 call SYMBOL(artUpdateDebuggerFromCode) // artUpdateDebuggerFromCode(int32_t, Thread*, Method**)
jeffhao7e4fcb82013-01-10 18:11:08 -0800473 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800474 .cfi_adjust_cfa_offset -16
jeffhao162fd332013-01-08 16:21:01 -0800475 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
jeffhao7e4fcb82013-01-10 18:11:08 -0800476 mov %ebx, %eax // restore original eax
jeffhao162fd332013-01-08 16:21:01 -0800477 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800478END_FUNCTION art_quick_update_debugger
jeffhao162fd332013-01-08 16:21:01 -0800479
Logan Chien8dbb7082013-01-25 20:31:17 +0800480ONE_ARG_DOWNCALL art_quick_lock_object_from_code, artLockObjectFromCode, ret
481ONE_ARG_DOWNCALL art_quick_unlock_object_from_code, artUnlockObjectFromCode, RETURN_IF_EAX_ZERO
Ian Rogersd36c52e2012-04-09 16:29:25 -0700482
Logan Chien8dbb7082013-01-25 20:31:17 +0800483TWO_ARG_DOWNCALL art_quick_handle_fill_data_from_code, artHandleFillArrayDataFromCode, RETURN_IF_EAX_ZERO
Ian Rogers7caad772012-03-30 01:07:54 -0700484
Logan Chien8dbb7082013-01-25 20:31:17 +0800485DEFINE_FUNCTION art_quick_is_assignable_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800486 PUSH eax // alignment padding
487 PUSH ecx // pass arg2
488 PUSH eax // pass arg1
Elliott Hughesadc078a2012-04-04 11:39:05 -0700489 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b, Thread*, SP)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700490 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800491 .cfi_adjust_cfa_offset -12
Ian Rogers7caad772012-03-30 01:07:54 -0700492 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800493END_FUNCTION art_quick_is_assignable_from_code
Ian Rogers7caad772012-03-30 01:07:54 -0700494
Logan Chien8dbb7082013-01-25 20:31:17 +0800495DEFINE_FUNCTION art_quick_memcpy
Ian Rogersaeeada42013-02-13 11:28:34 -0800496 PUSH edx // pass arg3
497 PUSH ecx // pass arg2
498 PUSH eax // pass arg1
Elliott Hughesadc078a2012-04-04 11:39:05 -0700499 call SYMBOL(memcpy) // (void*, const void*, size_t)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700500 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800501 .cfi_adjust_cfa_offset -12
Ian Rogers7caad772012-03-30 01:07:54 -0700502 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800503END_FUNCTION art_quick_memcpy
Ian Rogers7caad772012-03-30 01:07:54 -0700504
Logan Chien8dbb7082013-01-25 20:31:17 +0800505TWO_ARG_DOWNCALL art_quick_check_cast_from_code, artCheckCastFromCode, RETURN_IF_EAX_ZERO
506TWO_ARG_DOWNCALL art_quick_can_put_array_element_from_code, artCanPutArrayElementFromCode, RETURN_IF_EAX_ZERO
Ian Rogersd36c52e2012-04-09 16:29:25 -0700507
Logan Chien8dbb7082013-01-25 20:31:17 +0800508NO_ARG_DOWNCALL art_quick_test_suspend, artTestSuspendFromCode, ret
Ian Rogers7caad772012-03-30 01:07:54 -0700509
Logan Chien8dbb7082013-01-25 20:31:17 +0800510DEFINE_FUNCTION art_quick_fmod_from_code
jeffhao1395b1e2012-06-13 18:05:13 -0700511 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800512 .cfi_adjust_cfa_offset 12
513 PUSH ebx // pass arg4 b.hi
514 PUSH edx // pass arg3 b.lo
515 PUSH ecx // pass arg2 a.hi
516 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700517 call SYMBOL(fmod) // (jdouble a, jdouble b)
518 fstpl (%esp) // pop return value off fp stack
519 movsd (%esp), %xmm0 // place into %xmm0
520 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800521 .cfi_adjust_cfa_offset -28
jeffhao292188d2012-05-17 15:45:04 -0700522 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800523END_FUNCTION art_quick_fmod_from_code
jeffhao292188d2012-05-17 15:45:04 -0700524
Logan Chien8dbb7082013-01-25 20:31:17 +0800525DEFINE_FUNCTION art_quick_fmodf_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800526 PUSH eax // alignment padding
527 PUSH ecx // pass arg2 b
528 PUSH eax // pass arg1 a
jeffhao1395b1e2012-06-13 18:05:13 -0700529 call SYMBOL(fmodf) // (jfloat a, jfloat b)
Ian Rogers1b09b092012-08-20 15:35:52 -0700530 fstps (%esp) // pop return value off fp stack
jeffhao1395b1e2012-06-13 18:05:13 -0700531 movss (%esp), %xmm0 // place into %xmm0
532 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800533 .cfi_adjust_cfa_offset -12
jeffhao292188d2012-05-17 15:45:04 -0700534 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800535END_FUNCTION art_quick_fmodf_from_code
jeffhao292188d2012-05-17 15:45:04 -0700536
Logan Chien8dbb7082013-01-25 20:31:17 +0800537DEFINE_FUNCTION art_quick_l2d_from_code
Ian Rogers5793fea2013-02-14 13:33:34 -0800538 PUSH ecx // push arg2 a.hi
539 PUSH eax // push arg1 a.lo
540 fildll (%esp) // load as integer and push into st0
541 fstpl (%esp) // pop value off fp stack as double
jeffhao41005dd2012-05-09 17:58:52 -0700542 movsd (%esp), %xmm0 // place into %xmm0
Ian Rogers5793fea2013-02-14 13:33:34 -0800543 addl LITERAL(8), %esp // pop arguments
544 .cfi_adjust_cfa_offset -8
jeffhao41005dd2012-05-09 17:58:52 -0700545 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800546END_FUNCTION art_quick_l2d_from_code
jeffhao41005dd2012-05-09 17:58:52 -0700547
Logan Chien8dbb7082013-01-25 20:31:17 +0800548DEFINE_FUNCTION art_quick_l2f_from_code
Ian Rogers5793fea2013-02-14 13:33:34 -0800549 PUSH ecx // push arg2 a.hi
550 PUSH eax // push arg1 a.lo
551 fildll (%esp) // load as integer and push into st0
552 fstps (%esp) // pop value off fp stack as a single
jeffhao41005dd2012-05-09 17:58:52 -0700553 movss (%esp), %xmm0 // place into %xmm0
Ian Rogers5793fea2013-02-14 13:33:34 -0800554 addl LITERAL(8), %esp // pop argument
555 .cfi_adjust_cfa_offset -8
jeffhao41005dd2012-05-09 17:58:52 -0700556 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800557END_FUNCTION art_quick_l2f_from_code
jeffhao41005dd2012-05-09 17:58:52 -0700558
Logan Chien8dbb7082013-01-25 20:31:17 +0800559DEFINE_FUNCTION art_quick_d2l_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800560 PUSH eax // alignment padding
561 PUSH ecx // pass arg2 a.hi
562 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700563 call SYMBOL(art_d2l) // (jdouble a)
jeffhao41005dd2012-05-09 17:58:52 -0700564 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800565 .cfi_adjust_cfa_offset -12
jeffhao41005dd2012-05-09 17:58:52 -0700566 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800567END_FUNCTION art_quick_d2l_from_code
jeffhao41005dd2012-05-09 17:58:52 -0700568
Logan Chien8dbb7082013-01-25 20:31:17 +0800569DEFINE_FUNCTION art_quick_f2l_from_code
jeffhao41005dd2012-05-09 17:58:52 -0700570 subl LITERAL(8), %esp // alignment padding
Ian Rogers5793fea2013-02-14 13:33:34 -0800571 .cfi_adjust_cfa_offset 8
Ian Rogersaeeada42013-02-13 11:28:34 -0800572 PUSH eax // pass arg1 a
jeffhao1395b1e2012-06-13 18:05:13 -0700573 call SYMBOL(art_f2l) // (jfloat a)
jeffhao41005dd2012-05-09 17:58:52 -0700574 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800575 .cfi_adjust_cfa_offset -12
jeffhao41005dd2012-05-09 17:58:52 -0700576 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800577END_FUNCTION art_quick_f2l_from_code
jeffhao41005dd2012-05-09 17:58:52 -0700578
Logan Chien8dbb7082013-01-25 20:31:17 +0800579DEFINE_FUNCTION art_quick_idivmod_from_code
jeffhao174651d2012-04-19 15:27:22 -0700580 cmpl LITERAL(0x80000000), %eax
581 je check_arg2 // special case
582args_ok:
Ian Rogers7caad772012-03-30 01:07:54 -0700583 cdq // edx:eax = sign extend eax
584 idiv %ecx // (edx,eax) = (edx:eax % ecx, edx:eax / ecx)
Ian Rogers7caad772012-03-30 01:07:54 -0700585 ret
jeffhao174651d2012-04-19 15:27:22 -0700586check_arg2:
587 cmpl LITERAL(-1), %ecx
588 jne args_ok
589 xorl %edx, %edx
590 ret // eax already holds min int
Ian Rogersaeeada42013-02-13 11:28:34 -0800591END_FUNCTION art_quick_idivmod_from_code
Ian Rogers7caad772012-03-30 01:07:54 -0700592
Logan Chien8dbb7082013-01-25 20:31:17 +0800593DEFINE_FUNCTION art_quick_ldiv_from_code
Ian Rogers141d6222012-04-05 12:23:06 -0700594 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800595 .cfi_adjust_cfa_offset 12
596 PUSH ebx // pass arg4 b.hi
597 PUSH edx // pass arg3 b.lo
598 PUSH ecx // pass arg2 a.hi
599 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700600 call SYMBOL(artLdivFromCode) // (jlong a, jlong b)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700601 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800602 .cfi_adjust_cfa_offset -28
Ian Rogers55bd45f2012-04-04 17:31:20 -0700603 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800604END_FUNCTION art_quick_ldiv_from_code
Ian Rogers55bd45f2012-04-04 17:31:20 -0700605
Logan Chien8dbb7082013-01-25 20:31:17 +0800606DEFINE_FUNCTION art_quick_ldivmod_from_code
Ian Rogers141d6222012-04-05 12:23:06 -0700607 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800608 .cfi_adjust_cfa_offset 12
609 PUSH ebx // pass arg4 b.hi
610 PUSH edx // pass arg3 b.lo
611 PUSH ecx // pass arg2 a.hi
612 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700613 call SYMBOL(artLdivmodFromCode) // (jlong a, jlong b)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700614 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800615 .cfi_adjust_cfa_offset -28
Ian Rogers55bd45f2012-04-04 17:31:20 -0700616 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800617END_FUNCTION art_quick_ldivmod_from_code
Ian Rogers55bd45f2012-04-04 17:31:20 -0700618
Logan Chien8dbb7082013-01-25 20:31:17 +0800619DEFINE_FUNCTION art_quick_lmul_from_code
Ian Rogers5793fea2013-02-14 13:33:34 -0800620 imul %eax, %ebx // ebx = a.lo(eax) * b.hi(ebx)
621 imul %edx, %ecx // ecx = b.lo(edx) * a.hi(ecx)
622 mul %edx // edx:eax = a.lo(eax) * b.lo(edx)
623 add %ebx, %ecx
624 add %ecx, %edx // edx += (a.lo * b.hi) + (b.lo * a.hi)
jeffhao644d5312012-05-03 19:04:49 -0700625 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800626END_FUNCTION art_quick_lmul_from_code
jeffhao644d5312012-05-03 19:04:49 -0700627
Logan Chien8dbb7082013-01-25 20:31:17 +0800628DEFINE_FUNCTION art_quick_lshl_from_code
jeffhao644d5312012-05-03 19:04:49 -0700629 // ecx:eax << edx
Ian Rogers141d6222012-04-05 12:23:06 -0700630 xchg %edx, %ecx
631 shld %cl,%eax,%edx
632 shl %cl,%eax
633 test LITERAL(32), %cl
634 jz 1f
635 mov %eax, %edx
636 xor %eax, %eax
6371:
638 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800639END_FUNCTION art_quick_lshl_from_code
Ian Rogers141d6222012-04-05 12:23:06 -0700640
Logan Chien8dbb7082013-01-25 20:31:17 +0800641DEFINE_FUNCTION art_quick_lshr_from_code
jeffhao644d5312012-05-03 19:04:49 -0700642 // ecx:eax >> edx
Ian Rogers141d6222012-04-05 12:23:06 -0700643 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -0700644 shrd %cl,%edx,%eax
645 sar %cl,%edx
Ian Rogers141d6222012-04-05 12:23:06 -0700646 test LITERAL(32),%cl
647 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -0700648 mov %edx, %eax
649 sar LITERAL(31), %edx
Ian Rogers141d6222012-04-05 12:23:06 -07006501:
651 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800652END_FUNCTION art_quick_lshr_from_code
Ian Rogers141d6222012-04-05 12:23:06 -0700653
Logan Chien8dbb7082013-01-25 20:31:17 +0800654DEFINE_FUNCTION art_quick_lushr_from_code
jeffhao644d5312012-05-03 19:04:49 -0700655 // ecx:eax >>> edx
Ian Rogers141d6222012-04-05 12:23:06 -0700656 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -0700657 shrd %cl,%edx,%eax
658 shr %cl,%edx
659 test LITERAL(32),%cl
Ian Rogers141d6222012-04-05 12:23:06 -0700660 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -0700661 mov %edx, %eax
662 xor %edx, %edx
Ian Rogers141d6222012-04-05 12:23:06 -07006631:
664 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800665END_FUNCTION art_quick_lushr_from_code
Ian Rogers141d6222012-04-05 12:23:06 -0700666
Logan Chien8dbb7082013-01-25 20:31:17 +0800667DEFINE_FUNCTION art_quick_set32_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700668 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
669 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700670 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800671 .cfi_adjust_cfa_offset 8
672 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700673 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800674 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700675 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800676 PUSH ebx // pass referrer
677 PUSH edx // pass new_val
678 PUSH ecx // pass object
679 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700680 call SYMBOL(artSet32InstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700681 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800682 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700683 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
684 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800685END_FUNCTION art_quick_set32_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700686
Logan Chien8dbb7082013-01-25 20:31:17 +0800687DEFINE_FUNCTION art_quick_set64_instance_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800688 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao1ff4cd72012-05-21 11:17:48 -0700689 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800690 .cfi_adjust_cfa_offset 8
691 PUSH esp // pass SP-8
jeffhao1ff4cd72012-05-21 11:17:48 -0700692 addl LITERAL(8), (%esp) // fix SP on stack by adding 8
jeffhao9dbb23e2012-05-18 17:03:57 -0700693 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800694 .cfi_adjust_cfa_offset 4
695 PUSH ebx // pass high half of new_val
696 PUSH edx // pass low half of new_val
697 PUSH ecx // pass object
698 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700699 call SYMBOL(artSet64InstanceFromCode) // (field_idx, Object*, new_val, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700700 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800701 .cfi_adjust_cfa_offset -32
702 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700703 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800704END_FUNCTION art_quick_set64_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700705
Logan Chien8dbb7082013-01-25 20:31:17 +0800706DEFINE_FUNCTION art_quick_set_obj_instance_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800707 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700708 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700709 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800710 .cfi_adjust_cfa_offset 8
711 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700712 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800713 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700714 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800715 PUSH ebx // pass referrer
716 PUSH edx // pass new_val
717 PUSH ecx // pass object
718 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700719 call SYMBOL(artSetObjInstanceFromCode) // (field_idx, Object*, 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 Rogersaeeada42013-02-13 11:28:34 -0800724END_FUNCTION art_quick_set_obj_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700725
Logan Chien8dbb7082013-01-25 20:31:17 +0800726DEFINE_FUNCTION art_quick_get32_instance_from_code
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
729 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700730 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800731 .cfi_adjust_cfa_offset 12
732 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700733 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800734 .cfi_adjust_cfa_offset 4
735 PUSH edx // pass referrer
736 PUSH ecx // pass object
737 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700738 call SYMBOL(artGet32InstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700739 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800740 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700741 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700742 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800743END_FUNCTION art_quick_get32_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700744
Logan Chien8dbb7082013-01-25 20:31:17 +0800745DEFINE_FUNCTION art_quick_get64_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700746 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
747 mov %esp, %ebx // remember SP
748 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700749 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800750 .cfi_adjust_cfa_offset 12
751 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700752 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800753 .cfi_adjust_cfa_offset 4
754 PUSH edx // pass referrer
755 PUSH ecx // pass object
756 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700757 call SYMBOL(artGet64InstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700758 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800759 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700760 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700761 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800762END_FUNCTION art_quick_get64_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700763
Logan Chien8dbb7082013-01-25 20:31:17 +0800764DEFINE_FUNCTION art_quick_get_obj_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700765 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
766 mov %esp, %ebx // remember SP
767 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700768 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800769 .cfi_adjust_cfa_offset 12
770 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700771 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800772 .cfi_adjust_cfa_offset 4
773 PUSH edx // pass referrer
774 PUSH ecx // pass object
775 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700776 call SYMBOL(artGetObjInstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700777 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800778 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700779 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700780 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800781END_FUNCTION art_quick_get_obj_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700782
Logan Chien8dbb7082013-01-25 20:31:17 +0800783DEFINE_FUNCTION art_quick_set32_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700784 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
785 mov %esp, %ebx // remember SP
786 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700787 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800788 .cfi_adjust_cfa_offset 12
789 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700790 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800791 .cfi_adjust_cfa_offset 4
792 PUSH edx // pass referrer
793 PUSH ecx // pass new_val
794 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700795 call SYMBOL(artSet32StaticFromCode) // (field_idx, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700796 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800797 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700798 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
799 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800800END_FUNCTION art_quick_set32_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700801
Logan Chien8dbb7082013-01-25 20:31:17 +0800802DEFINE_FUNCTION art_quick_set64_static_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800803 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700804 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700805 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800806 .cfi_adjust_cfa_offset 8
807 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700808 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800809 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700810 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800811 PUSH edx // pass high half of new_val
812 PUSH ecx // pass low half of new_val
813 PUSH ebx // pass referrer
814 PUSH eax // pass field_idx
815 call SYMBOL(artSet64StaticFromCode) // (field_idx, referrer, new_val, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700816 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800817 .cfi_adjust_cfa_offset -32
818 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700819 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800820END_FUNCTION art_quick_set64_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700821
Logan Chien8dbb7082013-01-25 20:31:17 +0800822DEFINE_FUNCTION art_quick_set_obj_static_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800823 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700824 mov %esp, %ebx // remember SP
825 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700826 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800827 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700828 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800829 .cfi_adjust_cfa_offset 4
830 PUSH edx // pass referrer
831 PUSH ecx // pass new_val
832 PUSH eax // pass field_idx
833 call SYMBOL(artSetObjStaticFromCode) // (field_idx, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700834 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800835 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700836 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800837END_FUNCTION art_quick_set_obj_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700838
Logan Chien8dbb7082013-01-25 20:31:17 +0800839DEFINE_FUNCTION art_quick_get32_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700840 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
841 mov %esp, %edx // remember SP
842 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800843 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700844 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800845 .cfi_adjust_cfa_offset 4
846 PUSH ecx // pass referrer
847 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700848 call SYMBOL(artGet32StaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700849 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800850 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -0700851 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700852 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800853END_FUNCTION art_quick_get32_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700854
Logan Chien8dbb7082013-01-25 20:31:17 +0800855DEFINE_FUNCTION art_quick_get64_static_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800856 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700857 mov %esp, %edx // remember SP
858 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800859 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700860 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800861 .cfi_adjust_cfa_offset 4
862 PUSH ecx // pass referrer
863 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700864 call SYMBOL(artGet64StaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700865 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800866 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -0700867 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700868 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800869END_FUNCTION art_quick_get64_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700870
Logan Chien8dbb7082013-01-25 20:31:17 +0800871DEFINE_FUNCTION art_quick_get_obj_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700872 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
873 mov %esp, %edx // remember SP
874 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800875 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700876 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800877 .cfi_adjust_cfa_offset 4
878 PUSH ecx // pass referrer
879 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700880 call SYMBOL(artGetObjStaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700881 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800882 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -0700883 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700884 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800885END_FUNCTION art_quick_get_obj_static_from_code
jeffhaod66a8752012-05-22 15:30:16 -0700886
Logan Chien8dbb7082013-01-25 20:31:17 +0800887DEFINE_FUNCTION art_quick_proxy_invoke_handler
Ian Rogers7db619b2013-01-16 18:35:48 -0800888 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save frame and Method*
Ian Rogersaeeada42013-02-13 11:28:34 -0800889 PUSH esp // pass SP
jeffhaod66a8752012-05-22 15:30:16 -0700890 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800891 .cfi_adjust_cfa_offset 4
892 PUSH ecx // pass receiver
893 PUSH eax // pass proxy method
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800894 call SYMBOL(artProxyInvokeHandler) // (proxy method, receiver, Thread*, SP)
895 movd %eax, %xmm0 // place return value also into floating point return value
896 movd %edx, %xmm1
897 punpckldq %xmm1, %xmm0
jeffhaod66a8752012-05-22 15:30:16 -0700898 addl LITERAL(44), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800899 .cfi_adjust_cfa_offset -44
jeffhaod66a8752012-05-22 15:30:16 -0700900 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800901END_FUNCTION art_quick_proxy_invoke_handler
jeffhao9dbb23e2012-05-18 17:03:57 -0700902
Logan Chien8dbb7082013-01-25 20:31:17 +0800903DEFINE_FUNCTION art_quick_interpreter_entry
Ian Rogers7db619b2013-01-16 18:35:48 -0800904 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save frame and Method*
Ian Rogersaeeada42013-02-13 11:28:34 -0800905 mov %esp, %edx // remember SP
906 PUSH eax // alignment padding
907 PUSH edx // pass SP
Ian Rogers7db619b2013-01-16 18:35:48 -0800908 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800909 .cfi_adjust_cfa_offset 4
910 PUSH eax // pass method
Ian Rogers7db619b2013-01-16 18:35:48 -0800911 call SYMBOL(artInterpreterEntry) // (method, Thread*, SP)
912 movd %eax, %xmm0 // place return value also into floating point return value
913 movd %edx, %xmm1
914 punpckldq %xmm1, %xmm0
915 addl LITERAL(44), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800916 .cfi_adjust_cfa_offset -44
Ian Rogers7db619b2013-01-16 18:35:48 -0800917 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800918END_FUNCTION art_quick_interpreter_entry
Ian Rogers7db619b2013-01-16 18:35:48 -0800919
jeffhao7e4fcb82013-01-10 18:11:08 -0800920 /*
921 * Routine that intercepts method calls and returns.
922 */
Logan Chien8dbb7082013-01-25 20:31:17 +0800923DEFINE_FUNCTION art_quick_instrumentation_entry_from_code
jeffhao7e4fcb82013-01-10 18:11:08 -0800924 xchgl %eax, (%esp) // place LR in eax, save eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800925 PUSH ecx // save ecx
926 PUSH edx // save edx
927 PUSH ebx // save ebx
jeffhao7e4fcb82013-01-10 18:11:08 -0800928 lea 16(%esp), %edx // remember bottom of caller's frame
Ian Rogersaeeada42013-02-13 11:28:34 -0800929 PUSH eax // pass LR
930 PUSH edx // pass SP
jeffhao7e4fcb82013-01-10 18:11:08 -0800931 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800932 .cfi_adjust_cfa_offset 4
jeffhao7e4fcb82013-01-10 18:11:08 -0800933 pushl 24(%esp) // pass Method*
Ian Rogersaeeada42013-02-13 11:28:34 -0800934 .cfi_adjust_cfa_offset 4
jeffhao7e4fcb82013-01-10 18:11:08 -0800935 call SYMBOL(artInstrumentationMethodEntryFromCode) // (Method*, Thread*, SP, LR)
936 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800937 POP ebx // restore ebx
938 POP edx // restore edx
jeffhao7e4fcb82013-01-10 18:11:08 -0800939 movl (%esp), %ecx // restore ecx (without popping)
940 movl %eax, (%esp) // place method's code pointer on stack
941 movl 4(%esp), %eax // restore eax (without popping)
Logan Chien8dbb7082013-01-25 20:31:17 +0800942 movl LITERAL(SYMBOL(art_quick_instrumentation_exit_from_code)), 4(%esp)
jeffhao7e4fcb82013-01-10 18:11:08 -0800943 // place instrumentation exit as return pc
944 ret // call method (and pop)
Ian Rogersaeeada42013-02-13 11:28:34 -0800945END_FUNCTION art_quick_instrumentation_entry_from_code
Logan Chien8dbb7082013-01-25 20:31:17 +0800946DEFINE_FUNCTION art_quick_instrumentation_exit_from_code
jeffhao7e4fcb82013-01-10 18:11:08 -0800947 mov %esp, %ecx // remember bottom of caller's frame
Ian Rogersaeeada42013-02-13 11:28:34 -0800948 PUSH edx // save return value
949 PUSH eax // save other half of return value
950 PUSH ecx // pass SP
jeffhao7e4fcb82013-01-10 18:11:08 -0800951 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current
Ian Rogersaeeada42013-02-13 11:28:34 -0800952 .cfi_adjust_cfa_offset 4
jeffhao7e4fcb82013-01-10 18:11:08 -0800953 call SYMBOL(artInstrumentationMethodExitFromCode) // (Thread*, SP)
954 mov %eax, %ecx // move returned link register
955 // TODO: Set link register for deopt
Ian Rogers5793fea2013-02-14 13:33:34 -0800956 addl LITERAL(8), %esp // pop arguments
957 .cfi_adjust_cfa_offset -8
Ian Rogersaeeada42013-02-13 11:28:34 -0800958 POP eax // restore return value
959 POP edx // restore other half of return value
jeffhao7e4fcb82013-01-10 18:11:08 -0800960 jmp *%ecx // return
Ian Rogersaeeada42013-02-13 11:28:34 -0800961END_FUNCTION art_quick_instrumentation_exit_from_code
jeffhao162fd332013-01-08 16:21:01 -0800962
jeffhao7e4fcb82013-01-10 18:11:08 -0800963 /*
964 * The thread's enter interpreter flag is set and so we should transition to the interpreter
965 * rather than allow execution to continue in the frame below. There may be live results in
966 * registers depending on how complete the operation is when we safepoint - for example, a
967 * set operation may have completed while a get operation needs writing back into the vregs.
968 */
Logan Chien8dbb7082013-01-25 20:31:17 +0800969DEFINE_FUNCTION art_quick_deoptimize
jeffhao7e4fcb82013-01-10 18:11:08 -0800970 SETUP_REF_ONLY_CALLEE_SAVE_FRAME
Ian Rogersaeeada42013-02-13 11:28:34 -0800971 PUSH esp // pass SP
jeffhao7e4fcb82013-01-10 18:11:08 -0800972 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800973 .cfi_adjust_cfa_offset 4
974 PUSH edx // push half of return value
975 PUSH eax // push other half of return value
jeffhao7e4fcb82013-01-10 18:11:08 -0800976 call SYMBOL(artDeoptimize) // artDeoptimize(return value, Thread*, SP)
977 // Returns caller method's frame size.
978 addl LITERAL(16), %esp // pop arguments
979 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
980 testl %eax, %eax // Was the caller an upcall?
981 jz 1f // Return if caller was upcall.
982 lea (%esp, %eax), %edx // edx == bottom of caller's frame.
983 mov %edx, %esp // Remove frame.
984 SETUP_REF_ONLY_CALLEE_SAVE_FRAME
985 call SYMBOL(artEnterInterpreterFromDeoptimize) // Enter interpreter, callee-save ends stack fragment.
986 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
9871:
988 ret // Return to caller.
Ian Rogersaeeada42013-02-13 11:28:34 -0800989END_FUNCTION art_quick_deoptimize
jeffhao162fd332013-01-08 16:21:01 -0800990
jeffhao86e46712012-08-08 17:30:59 -0700991 /*
992 * String's indexOf.
993 *
994 * On entry:
995 * eax: string object (known non-null)
996 * ecx: char to match (known <= 0xFFFF)
997 * edx: Starting offset in string data
998 */
Logan Chien8dbb7082013-01-25 20:31:17 +0800999DEFINE_FUNCTION art_quick_indexof
Ian Rogersaeeada42013-02-13 11:28:34 -08001000 PUSH edi // push callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001001 mov STRING_COUNT_OFFSET(%eax), %ebx
1002 mov STRING_VALUE_OFFSET(%eax), %edi
1003 mov STRING_OFFSET_OFFSET(%eax), %eax
1004 testl %edx, %edx // check if start < 0
1005 jl clamp_min
1006clamp_done:
1007 cmpl %ebx, %edx // check if start >= count
1008 jge not_found
1009 lea STRING_DATA_OFFSET(%edi, %eax, 2), %edi // build a pointer to the start of string data
1010 mov %edi, %eax // save a copy in eax to later compute result
1011 lea (%edi, %edx, 2), %edi // build pointer to start of data to compare
1012 subl %edx, %ebx // compute iteration count
1013 /*
1014 * At this point we have:
1015 * eax: original start of string data
1016 * ecx: char to compare
1017 * ebx: length to compare
1018 * edi: start of data to test
1019 */
1020 mov %eax, %edx
1021 mov %ecx, %eax // put char to match in %eax
1022 mov %ebx, %ecx // put length to compare in %ecx
1023 repne scasw // find %ax, starting at [%edi], up to length %ecx
1024 jne not_found
1025 subl %edx, %edi
1026 sar LITERAL(1), %edi
1027 decl %edi // index = ((curr_ptr - orig_ptr) / 2) - 1
1028 mov %edi, %eax
Ian Rogersaeeada42013-02-13 11:28:34 -08001029 POP edi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001030 ret
1031 .balign 16
1032not_found:
1033 mov LITERAL(-1), %eax // return -1 (not found)
Ian Rogersaeeada42013-02-13 11:28:34 -08001034 POP edi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001035 ret
1036clamp_min:
1037 xor %edx, %edx // clamp start to 0
1038 jmp clamp_done
Ian Rogersaeeada42013-02-13 11:28:34 -08001039END_FUNCTION art_quick_indexof
jeffhao86e46712012-08-08 17:30:59 -07001040
1041 /*
1042 * String's compareTo.
1043 *
1044 * On entry:
1045 * eax: this string object (known non-null)
1046 * ecx: comp string object (known non-null)
1047 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001048DEFINE_FUNCTION art_quick_string_compareto
Ian Rogersaeeada42013-02-13 11:28:34 -08001049 PUSH esi // push callee save reg
1050 PUSH edi // push callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001051 mov STRING_COUNT_OFFSET(%eax), %edx
1052 mov STRING_COUNT_OFFSET(%ecx), %ebx
1053 mov STRING_VALUE_OFFSET(%eax), %esi
1054 mov STRING_VALUE_OFFSET(%ecx), %edi
1055 mov STRING_OFFSET_OFFSET(%eax), %eax
1056 mov STRING_OFFSET_OFFSET(%ecx), %ecx
1057 /* Build pointers to the start of string data */
1058 lea STRING_DATA_OFFSET(%esi, %eax, 2), %esi
1059 lea STRING_DATA_OFFSET(%edi, %ecx, 2), %edi
1060 /* Calculate min length and count diff */
1061 mov %edx, %ecx
1062 mov %edx, %eax
1063 subl %ebx, %eax
1064 cmovg %ebx, %ecx
1065 /*
1066 * At this point we have:
1067 * eax: value to return if first part of strings are equal
1068 * ecx: minimum among the lengths of the two strings
1069 * esi: pointer to this string data
1070 * edi: pointer to comp string data
1071 */
1072 repe cmpsw // find nonmatching chars in [%esi] and [%edi], up to length %ecx
1073 jne not_equal
Ian Rogersaeeada42013-02-13 11:28:34 -08001074 POP edi // pop callee save reg
1075 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001076 ret
1077 .balign 16
1078not_equal:
Ian Rogers1b09b092012-08-20 15:35:52 -07001079 movzwl -2(%esi), %eax // get last compared char from this string
1080 movzwl -2(%edi), %ecx // get last compared char from comp string
jeffhao86e46712012-08-08 17:30:59 -07001081 subl %ecx, %eax // return the difference
Ian Rogersaeeada42013-02-13 11:28:34 -08001082 POP edi // pop callee save reg
1083 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001084 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001085END_FUNCTION art_quick_string_compareto
jeffhao86e46712012-08-08 17:30:59 -07001086
Elliott Hughes787ec202012-03-29 17:14:15 -07001087MACRO1(UNIMPLEMENTED,name)
1088 .globl VAR(name, 0)
1089 ALIGN_FUNCTION_ENTRY
1090VAR(name, 0):
Ian Rogers57b86d42012-03-27 16:05:41 -07001091 int3
Elliott Hughes787ec202012-03-29 17:14:15 -07001092END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -07001093
Elliott Hughes787ec202012-03-29 17:14:15 -07001094 // TODO: implement these!
Logan Chien8dbb7082013-01-25 20:31:17 +08001095UNIMPLEMENTED art_quick_memcmp16