blob: ee6db0c3f8a385ac4f1880d07fcc7e91a0e7e5a4 [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 /*
Jeff Hao6474d192013-03-26 14:08:09 -0700305 * Portable invocation stub.
Jeff Hao5d917302013-02-27 17:57:33 -0800306 * 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
Jeff Hao6474d192013-03-26 14:08:09 -0700312 * [sp + 20] = JValue* result
313 * [sp + 24] = result type char
314 */
315DEFINE_FUNCTION art_portable_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(0xFFFFFFF0), %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 mov 12(%ebp), %eax // move method pointer into eax
332 mov %eax, (%esp) // push method pointer onto stack
333 call *METHOD_CODE_OFFSET(%eax) // call the method
334 mov %ebp, %esp // restore stack pointer
335 POP ebx // pop ebx
336 POP ebp // pop ebp
337 mov 20(%esp), %ecx // get result pointer
338 cmpl LITERAL(68), 24(%esp) // test if result type char == 'D'
339 je return_double_portable
340 cmpl LITERAL(70), 24(%esp) // test if result type char == 'F'
341 je return_float_portable
342 mov %eax, (%ecx) // store the result
343 mov %edx, 4(%ecx) // store the other half of the result
344 ret
345return_double_portable:
346 fstpl (%ecx) // store the floating point result as double
347 ret
348return_float_portable:
349 fstps (%ecx) // store the floating point result as float
350 ret
351END_FUNCTION art_portable_invoke_stub
352
353 /*
354 * Quick invocation stub.
355 * On entry:
356 * [sp] = return address
357 * [sp + 4] = method pointer
358 * [sp + 8] = argument array or NULL for no argument methods
359 * [sp + 12] = size of argument array in bytes
360 * [sp + 16] = (managed) thread pointer
361 * [sp + 20] = JValue* result
362 * [sp + 24] = result type char
Jeff Hao5d917302013-02-27 17:57:33 -0800363 */
364DEFINE_FUNCTION art_quick_invoke_stub
365 PUSH ebp // save ebp
366 PUSH ebx // save ebx
367 mov %esp, %ebp // copy value of stack pointer into base pointer
368 .cfi_def_cfa_register ebp
369 mov 20(%ebp), %ebx // get arg array size
370 addl LITERAL(28), %ebx // reserve space for return addr, method*, ebx, and ebp in frame
Jeff Hao6474d192013-03-26 14:08:09 -0700371 andl LITERAL(0xFFFFFFF0), %ebx // align frame size to 16 bytes
Jeff Hao5d917302013-02-27 17:57:33 -0800372 subl LITERAL(12), %ebx // remove space for return address, ebx, and ebp
373 subl %ebx, %esp // reserve stack space for argument array
374 lea 4(%esp), %eax // use stack pointer + method ptr as dest for memcpy
375 pushl 20(%ebp) // push size of region to memcpy
376 pushl 16(%ebp) // push arg array as source of memcpy
377 pushl %eax // push stack pointer as destination of memcpy
378 call SYMBOL(memcpy) // (void*, const void*, size_t)
379 addl LITERAL(12), %esp // pop arguments to memcpy
380 movl LITERAL(0), (%esp) // store NULL for method*
381 mov 12(%ebp), %eax // move method pointer into eax
382 mov 4(%esp), %ecx // copy arg1 into ecx
383 mov 8(%esp), %edx // copy arg2 into edx
384 mov 12(%esp), %ebx // copy arg3 into ebx
Ian Rogers225ade22013-03-18 17:45:44 -0700385 call *METHOD_CODE_OFFSET(%eax) // call the method
Jeff Hao5d917302013-02-27 17:57:33 -0800386 mov %ebp, %esp // restore stack pointer
387 POP ebx // pop ebx
388 POP ebp // pop ebp
389 mov 20(%esp), %ecx // get result pointer
Jeff Hao6474d192013-03-26 14:08:09 -0700390 cmpl LITERAL(68), 24(%esp) // test if result type char == 'D'
391 je return_double_quick
392 cmpl LITERAL(70), 24(%esp) // test if result type char == 'F'
393 je return_float_quick
Jeff Hao5d917302013-02-27 17:57:33 -0800394 mov %eax, (%ecx) // store the result
395 mov %edx, 4(%ecx) // store the other half of the result
Jeff Hao6474d192013-03-26 14:08:09 -0700396 ret
397return_double_quick:
398return_float_quick:
Jeff Hao5d917302013-02-27 17:57:33 -0800399 movsd %xmm0, (%ecx) // store the floating point result
400 ret
401END_FUNCTION art_quick_invoke_stub
402
Ian Rogersd36c52e2012-04-09 16:29:25 -0700403MACRO3(NO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800404 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700405 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
406 mov %esp, %edx // remember SP
407 // Outgoing argument set up
408 subl MACRO_LITERAL(8), %esp // push padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800409 .cfi_adjust_cfa_offset 8
410 PUSH edx // pass SP
Ian Rogersd36c52e2012-04-09 16:29:25 -0700411 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800412 .cfi_adjust_cfa_offset 4
Ian Rogersd36c52e2012-04-09 16:29:25 -0700413 call VAR(cxx_name, 1) // cxx_name(Thread*, SP)
414 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800415 .cfi_adjust_cfa_offset -16
Ian Rogersd36c52e2012-04-09 16:29:25 -0700416 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700417 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800418 END_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700419END_MACRO
420
421MACRO3(ONE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800422 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700423 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
424 mov %esp, %edx // remember SP
425 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800426 PUSH eax // push padding
427 PUSH edx // pass SP
Ian Rogersd36c52e2012-04-09 16:29:25 -0700428 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800429 .cfi_adjust_cfa_offset 4
430 PUSH eax // pass arg1
Ian Rogersd36c52e2012-04-09 16:29:25 -0700431 call VAR(cxx_name, 1) // cxx_name(arg1, Thread*, SP)
432 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800433 .cfi_adjust_cfa_offset -16
Ian Rogersd36c52e2012-04-09 16:29:25 -0700434 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700435 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800436 END_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700437END_MACRO
438
439MACRO3(TWO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800440 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700441 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
442 mov %esp, %edx // remember SP
443 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800444 PUSH edx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700445 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800446 .cfi_adjust_cfa_offset 4
447 PUSH ecx // pass arg2
448 PUSH eax // pass arg1
Ian Rogersd36c52e2012-04-09 16:29:25 -0700449 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, Thread*, SP)
Elliott Hughesea944212012-04-05 13:11:53 -0700450 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800451 .cfi_adjust_cfa_offset -16
Ian Rogers7caad772012-03-30 01:07:54 -0700452 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700453 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800454 END_FUNCTION VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700455END_MACRO
456
Ian Rogersd36c52e2012-04-09 16:29:25 -0700457MACRO3(THREE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800458 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700459 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
460 mov %esp, %ebx // remember SP
461 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700462 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800463 .cfi_adjust_cfa_offset 12
464 PUSH ebx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700465 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800466 .cfi_adjust_cfa_offset 4
467 PUSH edx // pass arg3
468 PUSH ecx // pass arg2
469 PUSH eax // pass arg1
Ian Rogersd36c52e2012-04-09 16:29:25 -0700470 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, arg3, Thread*, SP)
Elliott Hughesea944212012-04-05 13:11:53 -0700471 addl MACRO_LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800472 .cfi_adjust_cfa_offset -32
Ian Rogers7caad772012-03-30 01:07:54 -0700473 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700474 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800475 END_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700476END_MACRO
477
478MACRO0(RETURN_IF_EAX_NOT_ZERO)
Ian Rogers7caad772012-03-30 01:07:54 -0700479 testl %eax, %eax // eax == 0 ?
Ian Rogersd36c52e2012-04-09 16:29:25 -0700480 jz 1f // if eax == 0 goto 1
481 ret // return
4821: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700483 DELIVER_PENDING_EXCEPTION
484END_MACRO
485
Ian Rogersd36c52e2012-04-09 16:29:25 -0700486MACRO0(RETURN_IF_EAX_ZERO)
487 testl %eax, %eax // eax == 0 ?
488 jnz 1f // if eax != 0 goto 1
489 ret // return
4901: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700491 DELIVER_PENDING_EXCEPTION
Ian Rogersd36c52e2012-04-09 16:29:25 -0700492END_MACRO
Ian Rogers7caad772012-03-30 01:07:54 -0700493
jeffhaod66a8752012-05-22 15:30:16 -0700494MACRO0(RETURN_OR_DELIVER_PENDING_EXCEPTION)
495 mov %fs:THREAD_EXCEPTION_OFFSET, %ebx // get exception field
496 testl %ebx, %ebx // ebx == 0 ?
497 jnz 1f // if ebx != 0 goto 1
498 ret // return
4991: // deliver exception on current thread
500 DELIVER_PENDING_EXCEPTION
501END_MACRO
502
Logan Chien8dbb7082013-01-25 20:31:17 +0800503TWO_ARG_DOWNCALL art_quick_alloc_object_from_code, artAllocObjectFromCode, RETURN_IF_EAX_NOT_ZERO
504TWO_ARG_DOWNCALL art_quick_alloc_object_from_code_with_access_check, artAllocObjectFromCodeWithAccessCheck, RETURN_IF_EAX_NOT_ZERO
505THREE_ARG_DOWNCALL art_quick_alloc_array_from_code, artAllocArrayFromCode, RETURN_IF_EAX_NOT_ZERO
506THREE_ARG_DOWNCALL art_quick_alloc_array_from_code_with_access_check, artAllocArrayFromCodeWithAccessCheck, RETURN_IF_EAX_NOT_ZERO
507THREE_ARG_DOWNCALL art_quick_check_and_alloc_array_from_code, artCheckAndAllocArrayFromCode, RETURN_IF_EAX_NOT_ZERO
508THREE_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 -0700509
Logan Chien8dbb7082013-01-25 20:31:17 +0800510TWO_ARG_DOWNCALL art_quick_resolve_string_from_code, artResolveStringFromCode, RETURN_IF_EAX_NOT_ZERO
511TWO_ARG_DOWNCALL art_quick_initialize_static_storage_from_code, artInitializeStaticStorageFromCode, RETURN_IF_EAX_NOT_ZERO
512TWO_ARG_DOWNCALL art_quick_initialize_type_from_code, artInitializeTypeFromCode, RETURN_IF_EAX_NOT_ZERO
513TWO_ARG_DOWNCALL art_quick_initialize_type_and_verify_access_from_code, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_EAX_NOT_ZERO
Ian Rogersd36c52e2012-04-09 16:29:25 -0700514
Logan Chien8dbb7082013-01-25 20:31:17 +0800515ONE_ARG_DOWNCALL art_quick_lock_object_from_code, artLockObjectFromCode, ret
516ONE_ARG_DOWNCALL art_quick_unlock_object_from_code, artUnlockObjectFromCode, RETURN_IF_EAX_ZERO
Ian Rogersd36c52e2012-04-09 16:29:25 -0700517
Logan Chien8dbb7082013-01-25 20:31:17 +0800518TWO_ARG_DOWNCALL art_quick_handle_fill_data_from_code, artHandleFillArrayDataFromCode, RETURN_IF_EAX_ZERO
Ian Rogers7caad772012-03-30 01:07:54 -0700519
Logan Chien8dbb7082013-01-25 20:31:17 +0800520DEFINE_FUNCTION art_quick_is_assignable_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800521 PUSH eax // alignment padding
522 PUSH ecx // pass arg2
523 PUSH eax // pass arg1
Elliott Hughesadc078a2012-04-04 11:39:05 -0700524 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b, Thread*, SP)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700525 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800526 .cfi_adjust_cfa_offset -12
Ian Rogers7caad772012-03-30 01:07:54 -0700527 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800528END_FUNCTION art_quick_is_assignable_from_code
Ian Rogers7caad772012-03-30 01:07:54 -0700529
Logan Chien8dbb7082013-01-25 20:31:17 +0800530DEFINE_FUNCTION art_quick_memcpy
Ian Rogersaeeada42013-02-13 11:28:34 -0800531 PUSH edx // pass arg3
532 PUSH ecx // pass arg2
533 PUSH eax // pass arg1
Elliott Hughesadc078a2012-04-04 11:39:05 -0700534 call SYMBOL(memcpy) // (void*, const void*, size_t)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700535 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800536 .cfi_adjust_cfa_offset -12
Ian Rogers7caad772012-03-30 01:07:54 -0700537 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800538END_FUNCTION art_quick_memcpy
Ian Rogers7caad772012-03-30 01:07:54 -0700539
Logan Chien8dbb7082013-01-25 20:31:17 +0800540TWO_ARG_DOWNCALL art_quick_check_cast_from_code, artCheckCastFromCode, RETURN_IF_EAX_ZERO
541TWO_ARG_DOWNCALL art_quick_can_put_array_element_from_code, artCanPutArrayElementFromCode, RETURN_IF_EAX_ZERO
Ian Rogersd36c52e2012-04-09 16:29:25 -0700542
Logan Chien8dbb7082013-01-25 20:31:17 +0800543NO_ARG_DOWNCALL art_quick_test_suspend, artTestSuspendFromCode, ret
Ian Rogers7caad772012-03-30 01:07:54 -0700544
Logan Chien8dbb7082013-01-25 20:31:17 +0800545DEFINE_FUNCTION art_quick_fmod_from_code
jeffhao1395b1e2012-06-13 18:05:13 -0700546 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800547 .cfi_adjust_cfa_offset 12
548 PUSH ebx // pass arg4 b.hi
549 PUSH edx // pass arg3 b.lo
550 PUSH ecx // pass arg2 a.hi
551 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700552 call SYMBOL(fmod) // (jdouble a, jdouble b)
553 fstpl (%esp) // pop return value off fp stack
554 movsd (%esp), %xmm0 // place into %xmm0
555 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800556 .cfi_adjust_cfa_offset -28
jeffhao292188d2012-05-17 15:45:04 -0700557 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800558END_FUNCTION art_quick_fmod_from_code
jeffhao292188d2012-05-17 15:45:04 -0700559
Logan Chien8dbb7082013-01-25 20:31:17 +0800560DEFINE_FUNCTION art_quick_fmodf_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800561 PUSH eax // alignment padding
562 PUSH ecx // pass arg2 b
563 PUSH eax // pass arg1 a
jeffhao1395b1e2012-06-13 18:05:13 -0700564 call SYMBOL(fmodf) // (jfloat a, jfloat b)
Ian Rogers1b09b092012-08-20 15:35:52 -0700565 fstps (%esp) // pop return value off fp stack
jeffhao1395b1e2012-06-13 18:05:13 -0700566 movss (%esp), %xmm0 // place into %xmm0
567 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800568 .cfi_adjust_cfa_offset -12
jeffhao292188d2012-05-17 15:45:04 -0700569 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800570END_FUNCTION art_quick_fmodf_from_code
jeffhao292188d2012-05-17 15:45:04 -0700571
Logan Chien8dbb7082013-01-25 20:31:17 +0800572DEFINE_FUNCTION art_quick_l2d_from_code
Ian Rogers5793fea2013-02-14 13:33:34 -0800573 PUSH ecx // push arg2 a.hi
574 PUSH eax // push arg1 a.lo
575 fildll (%esp) // load as integer and push into st0
576 fstpl (%esp) // pop value off fp stack as double
jeffhao41005dd2012-05-09 17:58:52 -0700577 movsd (%esp), %xmm0 // place into %xmm0
Ian Rogers5793fea2013-02-14 13:33:34 -0800578 addl LITERAL(8), %esp // pop arguments
579 .cfi_adjust_cfa_offset -8
jeffhao41005dd2012-05-09 17:58:52 -0700580 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800581END_FUNCTION art_quick_l2d_from_code
jeffhao41005dd2012-05-09 17:58:52 -0700582
Logan Chien8dbb7082013-01-25 20:31:17 +0800583DEFINE_FUNCTION art_quick_l2f_from_code
Ian Rogers5793fea2013-02-14 13:33:34 -0800584 PUSH ecx // push arg2 a.hi
585 PUSH eax // push arg1 a.lo
586 fildll (%esp) // load as integer and push into st0
587 fstps (%esp) // pop value off fp stack as a single
jeffhao41005dd2012-05-09 17:58:52 -0700588 movss (%esp), %xmm0 // place into %xmm0
Ian Rogers5793fea2013-02-14 13:33:34 -0800589 addl LITERAL(8), %esp // pop argument
590 .cfi_adjust_cfa_offset -8
jeffhao41005dd2012-05-09 17:58:52 -0700591 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800592END_FUNCTION art_quick_l2f_from_code
jeffhao41005dd2012-05-09 17:58:52 -0700593
Logan Chien8dbb7082013-01-25 20:31:17 +0800594DEFINE_FUNCTION art_quick_d2l_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800595 PUSH eax // alignment padding
596 PUSH ecx // pass arg2 a.hi
597 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700598 call SYMBOL(art_d2l) // (jdouble a)
jeffhao41005dd2012-05-09 17:58:52 -0700599 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800600 .cfi_adjust_cfa_offset -12
jeffhao41005dd2012-05-09 17:58:52 -0700601 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800602END_FUNCTION art_quick_d2l_from_code
jeffhao41005dd2012-05-09 17:58:52 -0700603
Logan Chien8dbb7082013-01-25 20:31:17 +0800604DEFINE_FUNCTION art_quick_f2l_from_code
jeffhao41005dd2012-05-09 17:58:52 -0700605 subl LITERAL(8), %esp // alignment padding
Ian Rogers5793fea2013-02-14 13:33:34 -0800606 .cfi_adjust_cfa_offset 8
Ian Rogersaeeada42013-02-13 11:28:34 -0800607 PUSH eax // pass arg1 a
jeffhao1395b1e2012-06-13 18:05:13 -0700608 call SYMBOL(art_f2l) // (jfloat a)
jeffhao41005dd2012-05-09 17:58:52 -0700609 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800610 .cfi_adjust_cfa_offset -12
jeffhao41005dd2012-05-09 17:58:52 -0700611 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800612END_FUNCTION art_quick_f2l_from_code
jeffhao41005dd2012-05-09 17:58:52 -0700613
Logan Chien8dbb7082013-01-25 20:31:17 +0800614DEFINE_FUNCTION art_quick_idivmod_from_code
jeffhao174651d2012-04-19 15:27:22 -0700615 cmpl LITERAL(0x80000000), %eax
616 je check_arg2 // special case
617args_ok:
Ian Rogers7caad772012-03-30 01:07:54 -0700618 cdq // edx:eax = sign extend eax
619 idiv %ecx // (edx,eax) = (edx:eax % ecx, edx:eax / ecx)
Ian Rogers7caad772012-03-30 01:07:54 -0700620 ret
jeffhao174651d2012-04-19 15:27:22 -0700621check_arg2:
622 cmpl LITERAL(-1), %ecx
623 jne args_ok
624 xorl %edx, %edx
625 ret // eax already holds min int
Ian Rogersaeeada42013-02-13 11:28:34 -0800626END_FUNCTION art_quick_idivmod_from_code
Ian Rogers7caad772012-03-30 01:07:54 -0700627
Logan Chien8dbb7082013-01-25 20:31:17 +0800628DEFINE_FUNCTION art_quick_ldiv_from_code
Ian Rogers141d6222012-04-05 12:23:06 -0700629 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800630 .cfi_adjust_cfa_offset 12
631 PUSH ebx // pass arg4 b.hi
632 PUSH edx // pass arg3 b.lo
633 PUSH ecx // pass arg2 a.hi
634 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700635 call SYMBOL(artLdivFromCode) // (jlong a, jlong b)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700636 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800637 .cfi_adjust_cfa_offset -28
Ian Rogers55bd45f2012-04-04 17:31:20 -0700638 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800639END_FUNCTION art_quick_ldiv_from_code
Ian Rogers55bd45f2012-04-04 17:31:20 -0700640
Logan Chien8dbb7082013-01-25 20:31:17 +0800641DEFINE_FUNCTION art_quick_ldivmod_from_code
Ian Rogers141d6222012-04-05 12:23:06 -0700642 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800643 .cfi_adjust_cfa_offset 12
644 PUSH ebx // pass arg4 b.hi
645 PUSH edx // pass arg3 b.lo
646 PUSH ecx // pass arg2 a.hi
647 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700648 call SYMBOL(artLdivmodFromCode) // (jlong a, jlong b)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700649 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800650 .cfi_adjust_cfa_offset -28
Ian Rogers55bd45f2012-04-04 17:31:20 -0700651 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800652END_FUNCTION art_quick_ldivmod_from_code
Ian Rogers55bd45f2012-04-04 17:31:20 -0700653
Logan Chien8dbb7082013-01-25 20:31:17 +0800654DEFINE_FUNCTION art_quick_lmul_from_code
Ian Rogers5793fea2013-02-14 13:33:34 -0800655 imul %eax, %ebx // ebx = a.lo(eax) * b.hi(ebx)
656 imul %edx, %ecx // ecx = b.lo(edx) * a.hi(ecx)
657 mul %edx // edx:eax = a.lo(eax) * b.lo(edx)
658 add %ebx, %ecx
659 add %ecx, %edx // edx += (a.lo * b.hi) + (b.lo * a.hi)
jeffhao644d5312012-05-03 19:04:49 -0700660 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800661END_FUNCTION art_quick_lmul_from_code
jeffhao644d5312012-05-03 19:04:49 -0700662
Logan Chien8dbb7082013-01-25 20:31:17 +0800663DEFINE_FUNCTION art_quick_lshl_from_code
jeffhao644d5312012-05-03 19:04:49 -0700664 // ecx:eax << edx
Ian Rogers141d6222012-04-05 12:23:06 -0700665 xchg %edx, %ecx
666 shld %cl,%eax,%edx
667 shl %cl,%eax
668 test LITERAL(32), %cl
669 jz 1f
670 mov %eax, %edx
671 xor %eax, %eax
6721:
673 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800674END_FUNCTION art_quick_lshl_from_code
Ian Rogers141d6222012-04-05 12:23:06 -0700675
Logan Chien8dbb7082013-01-25 20:31:17 +0800676DEFINE_FUNCTION art_quick_lshr_from_code
jeffhao644d5312012-05-03 19:04:49 -0700677 // ecx:eax >> edx
Ian Rogers141d6222012-04-05 12:23:06 -0700678 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -0700679 shrd %cl,%edx,%eax
680 sar %cl,%edx
Ian Rogers141d6222012-04-05 12:23:06 -0700681 test LITERAL(32),%cl
682 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -0700683 mov %edx, %eax
684 sar LITERAL(31), %edx
Ian Rogers141d6222012-04-05 12:23:06 -07006851:
686 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800687END_FUNCTION art_quick_lshr_from_code
Ian Rogers141d6222012-04-05 12:23:06 -0700688
Logan Chien8dbb7082013-01-25 20:31:17 +0800689DEFINE_FUNCTION art_quick_lushr_from_code
jeffhao644d5312012-05-03 19:04:49 -0700690 // ecx:eax >>> edx
Ian Rogers141d6222012-04-05 12:23:06 -0700691 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -0700692 shrd %cl,%edx,%eax
693 shr %cl,%edx
694 test LITERAL(32),%cl
Ian Rogers141d6222012-04-05 12:23:06 -0700695 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -0700696 mov %edx, %eax
697 xor %edx, %edx
Ian Rogers141d6222012-04-05 12:23:06 -07006981:
699 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800700END_FUNCTION art_quick_lushr_from_code
Ian Rogers141d6222012-04-05 12:23:06 -0700701
Logan Chien8dbb7082013-01-25 20:31:17 +0800702DEFINE_FUNCTION art_quick_set32_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700703 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
704 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700705 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800706 .cfi_adjust_cfa_offset 8
707 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700708 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800709 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700710 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800711 PUSH ebx // pass referrer
712 PUSH edx // pass new_val
713 PUSH ecx // pass object
714 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700715 call SYMBOL(artSet32InstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700716 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800717 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700718 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
719 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800720END_FUNCTION art_quick_set32_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700721
Logan Chien8dbb7082013-01-25 20:31:17 +0800722DEFINE_FUNCTION art_quick_set64_instance_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800723 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao1ff4cd72012-05-21 11:17:48 -0700724 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800725 .cfi_adjust_cfa_offset 8
726 PUSH esp // pass SP-8
jeffhao1ff4cd72012-05-21 11:17:48 -0700727 addl LITERAL(8), (%esp) // fix SP on stack by adding 8
jeffhao9dbb23e2012-05-18 17:03:57 -0700728 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800729 .cfi_adjust_cfa_offset 4
730 PUSH ebx // pass high half of new_val
731 PUSH edx // pass low half of new_val
732 PUSH ecx // pass object
733 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700734 call SYMBOL(artSet64InstanceFromCode) // (field_idx, Object*, new_val, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700735 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800736 .cfi_adjust_cfa_offset -32
737 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700738 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800739END_FUNCTION art_quick_set64_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700740
Logan Chien8dbb7082013-01-25 20:31:17 +0800741DEFINE_FUNCTION art_quick_set_obj_instance_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800742 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700743 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700744 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800745 .cfi_adjust_cfa_offset 8
746 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700747 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800748 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700749 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800750 PUSH ebx // pass referrer
751 PUSH edx // pass new_val
752 PUSH ecx // pass object
753 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700754 call SYMBOL(artSetObjInstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700755 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800756 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700757 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
758 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800759END_FUNCTION art_quick_set_obj_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700760
Logan Chien8dbb7082013-01-25 20:31:17 +0800761DEFINE_FUNCTION art_quick_get32_instance_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800762 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700763 mov %esp, %ebx // remember SP
764 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700765 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800766 .cfi_adjust_cfa_offset 12
767 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700768 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800769 .cfi_adjust_cfa_offset 4
770 PUSH edx // pass referrer
771 PUSH ecx // pass object
772 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700773 call SYMBOL(artGet32InstanceFromCode) // (field_idx, Object*, 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
jeffhaod66a8752012-05-22 15:30:16 -0700777 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800778END_FUNCTION art_quick_get32_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700779
Logan Chien8dbb7082013-01-25 20:31:17 +0800780DEFINE_FUNCTION art_quick_get64_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700781 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
782 mov %esp, %ebx // remember SP
783 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700784 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800785 .cfi_adjust_cfa_offset 12
786 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700787 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800788 .cfi_adjust_cfa_offset 4
789 PUSH edx // pass referrer
790 PUSH ecx // pass object
791 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700792 call SYMBOL(artGet64InstanceFromCode) // (field_idx, Object*, referrer, 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
jeffhao9dbb23e2012-05-18 17:03:57 -0700795 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700796 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800797END_FUNCTION art_quick_get64_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700798
Logan Chien8dbb7082013-01-25 20:31:17 +0800799DEFINE_FUNCTION art_quick_get_obj_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700800 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
801 mov %esp, %ebx // remember SP
802 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700803 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800804 .cfi_adjust_cfa_offset 12
805 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700806 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800807 .cfi_adjust_cfa_offset 4
808 PUSH edx // pass referrer
809 PUSH ecx // pass object
810 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700811 call SYMBOL(artGetObjInstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700812 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800813 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700814 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700815 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800816END_FUNCTION art_quick_get_obj_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700817
Logan Chien8dbb7082013-01-25 20:31:17 +0800818DEFINE_FUNCTION art_quick_set32_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700819 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
820 mov %esp, %ebx // remember SP
821 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700822 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800823 .cfi_adjust_cfa_offset 12
824 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700825 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800826 .cfi_adjust_cfa_offset 4
827 PUSH edx // pass referrer
828 PUSH ecx // pass new_val
829 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700830 call SYMBOL(artSet32StaticFromCode) // (field_idx, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700831 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800832 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700833 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
834 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800835END_FUNCTION art_quick_set32_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700836
Logan Chien8dbb7082013-01-25 20:31:17 +0800837DEFINE_FUNCTION art_quick_set64_static_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800838 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700839 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700840 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800841 .cfi_adjust_cfa_offset 8
842 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700843 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800844 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700845 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800846 PUSH edx // pass high half of new_val
847 PUSH ecx // pass low half of new_val
848 PUSH ebx // pass referrer
849 PUSH eax // pass field_idx
850 call SYMBOL(artSet64StaticFromCode) // (field_idx, referrer, new_val, 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
853 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700854 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800855END_FUNCTION art_quick_set64_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700856
Logan Chien8dbb7082013-01-25 20:31:17 +0800857DEFINE_FUNCTION art_quick_set_obj_static_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800858 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700859 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 Rogers62d6c772013-02-27 08:32:07 -0800862 .cfi_adjust_cfa_offset 12
Ian Rogersaeeada42013-02-13 11:28:34 -0800863 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 new_val
868 PUSH eax // pass field_idx
869 call SYMBOL(artSetObjStaticFromCode) // (field_idx, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700870 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800871 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700872 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800873END_FUNCTION art_quick_set_obj_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700874
Logan Chien8dbb7082013-01-25 20:31:17 +0800875DEFINE_FUNCTION art_quick_get32_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700876 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
877 mov %esp, %edx // remember SP
878 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800879 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700880 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800881 .cfi_adjust_cfa_offset 4
882 PUSH ecx // pass referrer
883 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700884 call SYMBOL(artGet32StaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700885 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800886 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -0700887 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700888 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800889END_FUNCTION art_quick_get32_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700890
Logan Chien8dbb7082013-01-25 20:31:17 +0800891DEFINE_FUNCTION art_quick_get64_static_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800892 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700893 mov %esp, %edx // remember SP
894 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800895 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700896 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800897 .cfi_adjust_cfa_offset 4
898 PUSH ecx // pass referrer
899 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700900 call SYMBOL(artGet64StaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700901 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800902 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -0700903 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700904 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800905END_FUNCTION art_quick_get64_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700906
Logan Chien8dbb7082013-01-25 20:31:17 +0800907DEFINE_FUNCTION art_quick_get_obj_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700908 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
909 mov %esp, %edx // remember SP
910 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800911 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700912 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800913 .cfi_adjust_cfa_offset 4
914 PUSH ecx // pass referrer
915 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700916 call SYMBOL(artGetObjStaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700917 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800918 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -0700919 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700920 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800921END_FUNCTION art_quick_get_obj_static_from_code
jeffhaod66a8752012-05-22 15:30:16 -0700922
Jeff Hao5fa60c32013-04-04 17:57:01 -0700923DEFINE_FUNCTION art_portable_proxy_invoke_handler
924 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save frame and Method*
925 PUSH esp // pass SP
926 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
927 .cfi_adjust_cfa_offset 4
928 PUSH ecx // pass receiver
929 PUSH eax // pass proxy method
930 call SYMBOL(artPortableProxyInvokeHandler) // (proxy method, receiver, Thread*, SP)
931 movd %eax, %xmm0 // place return value also into floating point return value
932 movd %edx, %xmm1
933 punpckldq %xmm1, %xmm0
934 addl LITERAL(44), %esp // pop arguments
935 .cfi_adjust_cfa_offset -44
936 ret
937END_FUNCTION art_portable_proxy_invoke_handler
938
Logan Chien8dbb7082013-01-25 20:31:17 +0800939DEFINE_FUNCTION art_quick_proxy_invoke_handler
Ian Rogers7db619b2013-01-16 18:35:48 -0800940 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save frame and Method*
Ian Rogersaeeada42013-02-13 11:28:34 -0800941 PUSH esp // pass SP
jeffhaod66a8752012-05-22 15:30:16 -0700942 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800943 .cfi_adjust_cfa_offset 4
944 PUSH ecx // pass receiver
945 PUSH eax // pass proxy method
Jeff Hao5fa60c32013-04-04 17:57:01 -0700946 call SYMBOL(artQuickProxyInvokeHandler) // (proxy method, receiver, Thread*, SP)
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800947 movd %eax, %xmm0 // place return value also into floating point return value
948 movd %edx, %xmm1
949 punpckldq %xmm1, %xmm0
jeffhaod66a8752012-05-22 15:30:16 -0700950 addl LITERAL(44), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800951 .cfi_adjust_cfa_offset -44
jeffhaod66a8752012-05-22 15:30:16 -0700952 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800953END_FUNCTION art_quick_proxy_invoke_handler
jeffhao9dbb23e2012-05-18 17:03:57 -0700954
Logan Chien8dbb7082013-01-25 20:31:17 +0800955DEFINE_FUNCTION art_quick_interpreter_entry
Ian Rogers62d6c772013-02-27 08:32:07 -0800956 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save frame
Ian Rogersaeeada42013-02-13 11:28:34 -0800957 mov %esp, %edx // remember SP
958 PUSH eax // alignment padding
959 PUSH edx // pass SP
Ian Rogers7db619b2013-01-16 18:35:48 -0800960 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800961 .cfi_adjust_cfa_offset 4
962 PUSH eax // pass method
Ian Rogers7db619b2013-01-16 18:35:48 -0800963 call SYMBOL(artInterpreterEntry) // (method, Thread*, SP)
964 movd %eax, %xmm0 // place return value also into floating point return value
965 movd %edx, %xmm1
966 punpckldq %xmm1, %xmm0
967 addl LITERAL(44), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800968 .cfi_adjust_cfa_offset -44
Ian Rogers7db619b2013-01-16 18:35:48 -0800969 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800970END_FUNCTION art_quick_interpreter_entry
Ian Rogers7db619b2013-01-16 18:35:48 -0800971
jeffhao7e4fcb82013-01-10 18:11:08 -0800972 /*
973 * Routine that intercepts method calls and returns.
974 */
Logan Chien8dbb7082013-01-25 20:31:17 +0800975DEFINE_FUNCTION art_quick_instrumentation_entry_from_code
Ian Rogers62d6c772013-02-27 08:32:07 -0800976 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
977 movl %esp, %edx // Save SP.
978 PUSH eax // Save eax which will be clobbered by the callee-save method.
979 subl LITERAL(8), %esp // Align stack.
980 .cfi_adjust_cfa_offset 8
981 pushl 40(%esp) // Pass LR.
Ian Rogersaeeada42013-02-13 11:28:34 -0800982 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -0800983 PUSH edx // Pass SP.
984 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Ian Rogersaeeada42013-02-13 11:28:34 -0800985 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -0800986 PUSH ecx // Pass receiver.
987 PUSH eax // Pass Method*.
988 call SYMBOL(artInstrumentationMethodEntryFromCode) // (Method*, Object*, Thread*, SP, LR)
989 addl LITERAL(28), %esp // Pop arguments upto saved Method*.
990 movl 28(%esp), %edi // Restore edi.
991 movl %eax, 28(%esp) // Place code* over edi, just under return pc.
992 movl LITERAL(SYMBOL(art_quick_instrumentation_exit_from_code)), 32(%esp)
993 // Place instrumentation exit as return pc.
994 movl (%esp), %eax // Restore eax.
995 movl 8(%esp), %ecx // Restore ecx.
996 movl 12(%esp), %edx // Restore edx.
997 movl 16(%esp), %ebx // Restore ebx.
998 movl 20(%esp), %ebp // Restore ebp.
999 movl 24(%esp), %esi // Restore esi.
1000 addl LITERAL(28), %esp // Wind stack back upto code*.
1001 ret // Call method (and pop).
Ian Rogersaeeada42013-02-13 11:28:34 -08001002END_FUNCTION art_quick_instrumentation_entry_from_code
Ian Rogers62d6c772013-02-27 08:32:07 -08001003
Logan Chien8dbb7082013-01-25 20:31:17 +08001004DEFINE_FUNCTION art_quick_instrumentation_exit_from_code
Ian Rogers62d6c772013-02-27 08:32:07 -08001005 pushl LITERAL(0) // Push a fake return PC as there will be none on the stack.
1006 SETUP_REF_ONLY_CALLEE_SAVE_FRAME
1007 mov %esp, %ecx // Remember SP
1008 subl LITERAL(8), %esp // Save float return value.
1009 .cfi_adjust_cfa_offset 8
1010 movd %xmm0, (%esp)
1011 PUSH edx // Save gpr return value.
1012 PUSH eax
1013 subl LITERAL(8), %esp // Align stack
1014 movd %xmm0, (%esp)
1015 subl LITERAL(8), %esp // Pass float return value.
1016 .cfi_adjust_cfa_offset 8
1017 movd %xmm0, (%esp)
1018 PUSH edx // Pass gpr return value.
1019 PUSH eax
1020 PUSH ecx // Pass SP.
1021 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current.
Ian Rogersaeeada42013-02-13 11:28:34 -08001022 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -08001023 call SYMBOL(artInstrumentationMethodExitFromCode) // (Thread*, SP, gpr_result, fpr_result)
1024 mov %eax, %ecx // Move returned link register.
1025 addl LITERAL(32), %esp // Pop arguments.
1026 .cfi_adjust_cfa_offset -32
1027 movl %edx, %ebx // Move returned link register for deopt
1028 // (ebx is pretending to be our LR).
1029 POP eax // Restore gpr return value.
1030 POP edx
1031 movd (%esp), %xmm0 // Restore fpr return value.
1032 addl LITERAL(8), %esp
Ian Rogers5793fea2013-02-14 13:33:34 -08001033 .cfi_adjust_cfa_offset -8
Ian Rogers62d6c772013-02-27 08:32:07 -08001034 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
1035 addl LITERAL(4), %esp // Remove fake return pc.
1036 jmp *%ecx // Return.
Ian Rogersaeeada42013-02-13 11:28:34 -08001037END_FUNCTION art_quick_instrumentation_exit_from_code
jeffhao162fd332013-01-08 16:21:01 -08001038
jeffhao7e4fcb82013-01-10 18:11:08 -08001039 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001040 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1041 * will long jump to the upcall with a special exception of -1.
jeffhao7e4fcb82013-01-10 18:11:08 -08001042 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001043DEFINE_FUNCTION art_quick_deoptimize
Ian Rogers62d6c772013-02-27 08:32:07 -08001044 pushl %ebx // Fake that we were called.
Jeff Haoc1fcdf12013-04-11 13:34:01 -07001045 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
Ian Rogers62d6c772013-02-27 08:32:07 -08001046 mov %esp, %ecx // Remember SP.
1047 subl LITERAL(8), %esp // Align stack.
1048 .cfi_adjust_cfa_offset 8
1049 PUSH ecx // Pass SP.
1050 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Ian Rogersaeeada42013-02-13 11:28:34 -08001051 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -08001052 call SYMBOL(artDeoptimize) // artDeoptimize(Thread*, SP)
1053 int3 // Unreachable.
Ian Rogersaeeada42013-02-13 11:28:34 -08001054END_FUNCTION art_quick_deoptimize
jeffhao162fd332013-01-08 16:21:01 -08001055
jeffhao86e46712012-08-08 17:30:59 -07001056 /*
Jeff Hao79fe5392013-04-24 18:41:58 -07001057 * Portable abstract method error stub. method* is at %esp + 4 on entry.
1058 */
1059DEFINE_FUNCTION art_portable_abstract_method_error_stub
1060 PUSH ebp
1061 movl %esp, %ebp // Remember SP.
1062 .cfi_def_cfa_register ebp
1063 subl LITERAL(12), %esp // Align stack.
1064 PUSH esp // Pass sp (not used).
1065 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
1066 pushl 8(%ebp) // Pass Method*.
1067 call SYMBOL(artThrowAbstractMethodErrorFromCode) // (Method*, Thread*, SP)
1068 leave // Restore the stack and %ebp.
1069 .cfi_def_cfa esp, 4
1070 .cfi_restore ebp
1071 ret // Return to caller to handle pending exception.
1072END_FUNCTION art_portable_abstract_method_error_stub
1073
1074 /*
1075 * Quick abstract method error stub. %eax contains method* on entry.
1076 */
1077DEFINE_FUNCTION art_quick_abstract_method_error_stub
1078 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1079 movl %esp, %ecx // Remember SP.
1080 PUSH eax // Align frame.
1081 PUSH ecx // Pass SP for Method*.
1082 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
1083 .cfi_adjust_cfa_offset 4
1084 PUSH eax // Pass Method*.
1085 call SYMBOL(artThrowAbstractMethodErrorFromCode) // (Method*, Thread*, SP)
1086 int3 // Unreachable.
1087END_FUNCTION art_quick_abstract_method_error_stub
1088
1089 /*
1090 * Portable resolution trampoline.
1091 */
1092DEFINE_FUNCTION art_jni_dlsym_lookup_stub
1093 subl LITERAL(8), %esp // align stack
1094 .cfi_adjust_cfa_offset 8
1095 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1096 .cfi_adjust_cfa_offset 4
1097 call SYMBOL(artFindNativeMethod) // (Thread*)
1098 addl LITERAL(12), %esp // restore the stack
1099 .cfi_adjust_cfa_offset -12
1100 cmpl LITERAL(0), %eax // check if returned method code is null
1101 je no_native_code_found // if null, jump to return to handle
1102 jmp *%eax // otherwise, tail call to intended method
1103no_native_code_found:
1104 ret
1105END_FUNCTION art_jni_dlsym_lookup_stub
1106
1107 /*
jeffhao86e46712012-08-08 17:30:59 -07001108 * String's indexOf.
1109 *
1110 * On entry:
1111 * eax: string object (known non-null)
1112 * ecx: char to match (known <= 0xFFFF)
1113 * edx: Starting offset in string data
1114 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001115DEFINE_FUNCTION art_quick_indexof
Ian Rogersaeeada42013-02-13 11:28:34 -08001116 PUSH edi // push callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001117 mov STRING_COUNT_OFFSET(%eax), %ebx
1118 mov STRING_VALUE_OFFSET(%eax), %edi
1119 mov STRING_OFFSET_OFFSET(%eax), %eax
1120 testl %edx, %edx // check if start < 0
1121 jl clamp_min
1122clamp_done:
1123 cmpl %ebx, %edx // check if start >= count
1124 jge not_found
1125 lea STRING_DATA_OFFSET(%edi, %eax, 2), %edi // build a pointer to the start of string data
1126 mov %edi, %eax // save a copy in eax to later compute result
1127 lea (%edi, %edx, 2), %edi // build pointer to start of data to compare
1128 subl %edx, %ebx // compute iteration count
1129 /*
1130 * At this point we have:
1131 * eax: original start of string data
1132 * ecx: char to compare
1133 * ebx: length to compare
1134 * edi: start of data to test
1135 */
1136 mov %eax, %edx
1137 mov %ecx, %eax // put char to match in %eax
1138 mov %ebx, %ecx // put length to compare in %ecx
1139 repne scasw // find %ax, starting at [%edi], up to length %ecx
1140 jne not_found
1141 subl %edx, %edi
1142 sar LITERAL(1), %edi
1143 decl %edi // index = ((curr_ptr - orig_ptr) / 2) - 1
1144 mov %edi, %eax
Ian Rogersaeeada42013-02-13 11:28:34 -08001145 POP edi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001146 ret
1147 .balign 16
1148not_found:
1149 mov LITERAL(-1), %eax // return -1 (not found)
Ian Rogersaeeada42013-02-13 11:28:34 -08001150 POP edi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001151 ret
1152clamp_min:
1153 xor %edx, %edx // clamp start to 0
1154 jmp clamp_done
Ian Rogersaeeada42013-02-13 11:28:34 -08001155END_FUNCTION art_quick_indexof
jeffhao86e46712012-08-08 17:30:59 -07001156
1157 /*
1158 * String's compareTo.
1159 *
1160 * On entry:
1161 * eax: this string object (known non-null)
1162 * ecx: comp string object (known non-null)
1163 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001164DEFINE_FUNCTION art_quick_string_compareto
Ian Rogersaeeada42013-02-13 11:28:34 -08001165 PUSH esi // push callee save reg
1166 PUSH edi // push callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001167 mov STRING_COUNT_OFFSET(%eax), %edx
1168 mov STRING_COUNT_OFFSET(%ecx), %ebx
1169 mov STRING_VALUE_OFFSET(%eax), %esi
1170 mov STRING_VALUE_OFFSET(%ecx), %edi
1171 mov STRING_OFFSET_OFFSET(%eax), %eax
1172 mov STRING_OFFSET_OFFSET(%ecx), %ecx
1173 /* Build pointers to the start of string data */
1174 lea STRING_DATA_OFFSET(%esi, %eax, 2), %esi
1175 lea STRING_DATA_OFFSET(%edi, %ecx, 2), %edi
1176 /* Calculate min length and count diff */
1177 mov %edx, %ecx
1178 mov %edx, %eax
1179 subl %ebx, %eax
1180 cmovg %ebx, %ecx
1181 /*
1182 * At this point we have:
1183 * eax: value to return if first part of strings are equal
1184 * ecx: minimum among the lengths of the two strings
1185 * esi: pointer to this string data
1186 * edi: pointer to comp string data
1187 */
1188 repe cmpsw // find nonmatching chars in [%esi] and [%edi], up to length %ecx
1189 jne not_equal
Ian Rogersaeeada42013-02-13 11:28:34 -08001190 POP edi // pop callee save reg
1191 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001192 ret
1193 .balign 16
1194not_equal:
Ian Rogers1b09b092012-08-20 15:35:52 -07001195 movzwl -2(%esi), %eax // get last compared char from this string
1196 movzwl -2(%edi), %ecx // get last compared char from comp string
jeffhao86e46712012-08-08 17:30:59 -07001197 subl %ecx, %eax // return the difference
Ian Rogersaeeada42013-02-13 11:28:34 -08001198 POP edi // pop callee save reg
1199 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001200 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001201END_FUNCTION art_quick_string_compareto
jeffhao86e46712012-08-08 17:30:59 -07001202
Elliott Hughes787ec202012-03-29 17:14:15 -07001203MACRO1(UNIMPLEMENTED,name)
1204 .globl VAR(name, 0)
1205 ALIGN_FUNCTION_ENTRY
1206VAR(name, 0):
Ian Rogers57b86d42012-03-27 16:05:41 -07001207 int3
Elliott Hughes787ec202012-03-29 17:14:15 -07001208END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -07001209
Elliott Hughes787ec202012-03-29 17:14:15 -07001210 // TODO: implement these!
Logan Chien8dbb7082013-01-25 20:31:17 +08001211UNIMPLEMENTED art_quick_memcmp16