blob: 0ff69d9f4c448e1728313d391af3480675890d44 [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
Ian Rogersd36c52e2012-04-09 16:29:25 -0700304MACRO3(NO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800305 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700306 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
307 mov %esp, %edx // remember SP
308 // Outgoing argument set up
309 subl MACRO_LITERAL(8), %esp // push padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800310 .cfi_adjust_cfa_offset 8
311 PUSH edx // pass SP
Ian Rogersd36c52e2012-04-09 16:29:25 -0700312 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800313 .cfi_adjust_cfa_offset 4
Ian Rogersd36c52e2012-04-09 16:29:25 -0700314 call VAR(cxx_name, 1) // cxx_name(Thread*, SP)
315 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800316 .cfi_adjust_cfa_offset -16
Ian Rogersd36c52e2012-04-09 16:29:25 -0700317 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700318 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800319 END_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700320END_MACRO
321
322MACRO3(ONE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800323 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700324 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
325 mov %esp, %edx // remember SP
326 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800327 PUSH eax // push padding
328 PUSH edx // pass SP
Ian Rogersd36c52e2012-04-09 16:29:25 -0700329 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800330 .cfi_adjust_cfa_offset 4
331 PUSH eax // pass arg1
Ian Rogersd36c52e2012-04-09 16:29:25 -0700332 call VAR(cxx_name, 1) // cxx_name(arg1, Thread*, SP)
333 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800334 .cfi_adjust_cfa_offset -16
Ian Rogersd36c52e2012-04-09 16:29:25 -0700335 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700336 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800337 END_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700338END_MACRO
339
340MACRO3(TWO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800341 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700342 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
343 mov %esp, %edx // remember SP
344 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800345 PUSH edx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700346 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800347 .cfi_adjust_cfa_offset 4
348 PUSH ecx // pass arg2
349 PUSH eax // pass arg1
Ian Rogersd36c52e2012-04-09 16:29:25 -0700350 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, Thread*, SP)
Elliott Hughesea944212012-04-05 13:11:53 -0700351 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800352 .cfi_adjust_cfa_offset -16
Ian Rogers7caad772012-03-30 01:07:54 -0700353 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700354 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800355 END_FUNCTION VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700356END_MACRO
357
Ian Rogersd36c52e2012-04-09 16:29:25 -0700358MACRO3(THREE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800359 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700360 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
361 mov %esp, %ebx // remember SP
362 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700363 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800364 .cfi_adjust_cfa_offset 12
365 PUSH ebx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700366 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800367 .cfi_adjust_cfa_offset 4
368 PUSH edx // pass arg3
369 PUSH ecx // pass arg2
370 PUSH eax // pass arg1
Ian Rogersd36c52e2012-04-09 16:29:25 -0700371 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, arg3, Thread*, SP)
Elliott Hughesea944212012-04-05 13:11:53 -0700372 addl MACRO_LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800373 .cfi_adjust_cfa_offset -32
Ian Rogers7caad772012-03-30 01:07:54 -0700374 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700375 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800376 END_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700377END_MACRO
378
379MACRO0(RETURN_IF_EAX_NOT_ZERO)
Ian Rogers7caad772012-03-30 01:07:54 -0700380 testl %eax, %eax // eax == 0 ?
Ian Rogersd36c52e2012-04-09 16:29:25 -0700381 jz 1f // if eax == 0 goto 1
382 ret // return
3831: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700384 DELIVER_PENDING_EXCEPTION
385END_MACRO
386
Ian Rogersd36c52e2012-04-09 16:29:25 -0700387MACRO0(RETURN_IF_EAX_ZERO)
388 testl %eax, %eax // eax == 0 ?
389 jnz 1f // if eax != 0 goto 1
390 ret // return
3911: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700392 DELIVER_PENDING_EXCEPTION
Ian Rogersd36c52e2012-04-09 16:29:25 -0700393END_MACRO
Ian Rogers7caad772012-03-30 01:07:54 -0700394
jeffhaod66a8752012-05-22 15:30:16 -0700395MACRO0(RETURN_OR_DELIVER_PENDING_EXCEPTION)
396 mov %fs:THREAD_EXCEPTION_OFFSET, %ebx // get exception field
397 testl %ebx, %ebx // ebx == 0 ?
398 jnz 1f // if ebx != 0 goto 1
399 ret // return
4001: // deliver exception on current thread
401 DELIVER_PENDING_EXCEPTION
402END_MACRO
403
Logan Chien8dbb7082013-01-25 20:31:17 +0800404TWO_ARG_DOWNCALL art_quick_alloc_object_from_code, artAllocObjectFromCode, RETURN_IF_EAX_NOT_ZERO
405TWO_ARG_DOWNCALL art_quick_alloc_object_from_code_with_access_check, artAllocObjectFromCodeWithAccessCheck, RETURN_IF_EAX_NOT_ZERO
406THREE_ARG_DOWNCALL art_quick_alloc_array_from_code, artAllocArrayFromCode, RETURN_IF_EAX_NOT_ZERO
407THREE_ARG_DOWNCALL art_quick_alloc_array_from_code_with_access_check, artAllocArrayFromCodeWithAccessCheck, RETURN_IF_EAX_NOT_ZERO
408THREE_ARG_DOWNCALL art_quick_check_and_alloc_array_from_code, artCheckAndAllocArrayFromCode, RETURN_IF_EAX_NOT_ZERO
409THREE_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 -0700410
Logan Chien8dbb7082013-01-25 20:31:17 +0800411TWO_ARG_DOWNCALL art_quick_resolve_string_from_code, artResolveStringFromCode, RETURN_IF_EAX_NOT_ZERO
412TWO_ARG_DOWNCALL art_quick_initialize_static_storage_from_code, artInitializeStaticStorageFromCode, RETURN_IF_EAX_NOT_ZERO
413TWO_ARG_DOWNCALL art_quick_initialize_type_from_code, artInitializeTypeFromCode, RETURN_IF_EAX_NOT_ZERO
414TWO_ARG_DOWNCALL art_quick_initialize_type_and_verify_access_from_code, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_EAX_NOT_ZERO
Ian Rogersd36c52e2012-04-09 16:29:25 -0700415
jeffhao7e4fcb82013-01-10 18:11:08 -0800416 /*
417 * On entry, eax and ecx must be preserved, edx is dex PC
418 */
Logan Chien8dbb7082013-01-25 20:31:17 +0800419DEFINE_FUNCTION art_quick_update_debugger
jeffhao7e4fcb82013-01-10 18:11:08 -0800420 mov %eax, %ebx // stash away eax so that it's saved as if it were an argument
jeffhao162fd332013-01-08 16:21:01 -0800421 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
jeffhao7e4fcb82013-01-10 18:11:08 -0800422 subl LITERAL(4), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800423 .cfi_adjust_cfa_offset 4
424 PUSH esp // pass arg2 (sp)
jeffhao162fd332013-01-08 16:21:01 -0800425 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800426 .cfi_adjust_cfa_offset 4
427 PUSH edx // pass arg0 (dex pc)
jeffhao162fd332013-01-08 16:21:01 -0800428 call SYMBOL(artUpdateDebuggerFromCode) // artUpdateDebuggerFromCode(int32_t, Thread*, Method**)
jeffhao7e4fcb82013-01-10 18:11:08 -0800429 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800430 .cfi_adjust_cfa_offset -16
jeffhao162fd332013-01-08 16:21:01 -0800431 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
jeffhao7e4fcb82013-01-10 18:11:08 -0800432 mov %ebx, %eax // restore original eax
jeffhao162fd332013-01-08 16:21:01 -0800433 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800434END_FUNCTION art_quick_update_debugger
jeffhao162fd332013-01-08 16:21:01 -0800435
Logan Chien8dbb7082013-01-25 20:31:17 +0800436ONE_ARG_DOWNCALL art_quick_lock_object_from_code, artLockObjectFromCode, ret
437ONE_ARG_DOWNCALL art_quick_unlock_object_from_code, artUnlockObjectFromCode, RETURN_IF_EAX_ZERO
Ian Rogersd36c52e2012-04-09 16:29:25 -0700438
Logan Chien8dbb7082013-01-25 20:31:17 +0800439TWO_ARG_DOWNCALL art_quick_handle_fill_data_from_code, artHandleFillArrayDataFromCode, RETURN_IF_EAX_ZERO
Ian Rogers7caad772012-03-30 01:07:54 -0700440
Logan Chien8dbb7082013-01-25 20:31:17 +0800441DEFINE_FUNCTION art_quick_is_assignable_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800442 PUSH eax // alignment padding
443 PUSH ecx // pass arg2
444 PUSH eax // pass arg1
Elliott Hughesadc078a2012-04-04 11:39:05 -0700445 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b, Thread*, SP)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700446 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800447 .cfi_adjust_cfa_offset -12
Ian Rogers7caad772012-03-30 01:07:54 -0700448 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800449END_FUNCTION art_quick_is_assignable_from_code
Ian Rogers7caad772012-03-30 01:07:54 -0700450
Logan Chien8dbb7082013-01-25 20:31:17 +0800451DEFINE_FUNCTION art_quick_memcpy
Ian Rogersaeeada42013-02-13 11:28:34 -0800452 PUSH edx // pass arg3
453 PUSH ecx // pass arg2
454 PUSH eax // pass arg1
Elliott Hughesadc078a2012-04-04 11:39:05 -0700455 call SYMBOL(memcpy) // (void*, const void*, size_t)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700456 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800457 .cfi_adjust_cfa_offset -12
Ian Rogers7caad772012-03-30 01:07:54 -0700458 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800459END_FUNCTION art_quick_memcpy
Ian Rogers7caad772012-03-30 01:07:54 -0700460
Logan Chien8dbb7082013-01-25 20:31:17 +0800461TWO_ARG_DOWNCALL art_quick_check_cast_from_code, artCheckCastFromCode, RETURN_IF_EAX_ZERO
462TWO_ARG_DOWNCALL art_quick_can_put_array_element_from_code, artCanPutArrayElementFromCode, RETURN_IF_EAX_ZERO
Ian Rogersd36c52e2012-04-09 16:29:25 -0700463
Logan Chien8dbb7082013-01-25 20:31:17 +0800464NO_ARG_DOWNCALL art_quick_test_suspend, artTestSuspendFromCode, ret
Ian Rogers7caad772012-03-30 01:07:54 -0700465
Logan Chien8dbb7082013-01-25 20:31:17 +0800466DEFINE_FUNCTION art_quick_fmod_from_code
jeffhao1395b1e2012-06-13 18:05:13 -0700467 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800468 .cfi_adjust_cfa_offset 12
469 PUSH ebx // pass arg4 b.hi
470 PUSH edx // pass arg3 b.lo
471 PUSH ecx // pass arg2 a.hi
472 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700473 call SYMBOL(fmod) // (jdouble a, jdouble b)
474 fstpl (%esp) // pop return value off fp stack
475 movsd (%esp), %xmm0 // place into %xmm0
476 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800477 .cfi_adjust_cfa_offset -28
jeffhao292188d2012-05-17 15:45:04 -0700478 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800479END_FUNCTION art_quick_fmod_from_code
jeffhao292188d2012-05-17 15:45:04 -0700480
Logan Chien8dbb7082013-01-25 20:31:17 +0800481DEFINE_FUNCTION art_quick_fmodf_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800482 PUSH eax // alignment padding
483 PUSH ecx // pass arg2 b
484 PUSH eax // pass arg1 a
jeffhao1395b1e2012-06-13 18:05:13 -0700485 call SYMBOL(fmodf) // (jfloat a, jfloat b)
Ian Rogers1b09b092012-08-20 15:35:52 -0700486 fstps (%esp) // pop return value off fp stack
jeffhao1395b1e2012-06-13 18:05:13 -0700487 movss (%esp), %xmm0 // place into %xmm0
488 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800489 .cfi_adjust_cfa_offset -12
jeffhao292188d2012-05-17 15:45:04 -0700490 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800491END_FUNCTION art_quick_fmodf_from_code
jeffhao292188d2012-05-17 15:45:04 -0700492
Logan Chien8dbb7082013-01-25 20:31:17 +0800493DEFINE_FUNCTION art_quick_l2d_from_code
Ian Rogers5793fea2013-02-14 13:33:34 -0800494 PUSH ecx // push arg2 a.hi
495 PUSH eax // push arg1 a.lo
496 fildll (%esp) // load as integer and push into st0
497 fstpl (%esp) // pop value off fp stack as double
jeffhao41005dd2012-05-09 17:58:52 -0700498 movsd (%esp), %xmm0 // place into %xmm0
Ian Rogers5793fea2013-02-14 13:33:34 -0800499 addl LITERAL(8), %esp // pop arguments
500 .cfi_adjust_cfa_offset -8
jeffhao41005dd2012-05-09 17:58:52 -0700501 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800502END_FUNCTION art_quick_l2d_from_code
jeffhao41005dd2012-05-09 17:58:52 -0700503
Logan Chien8dbb7082013-01-25 20:31:17 +0800504DEFINE_FUNCTION art_quick_l2f_from_code
Ian Rogers5793fea2013-02-14 13:33:34 -0800505 PUSH ecx // push arg2 a.hi
506 PUSH eax // push arg1 a.lo
507 fildll (%esp) // load as integer and push into st0
508 fstps (%esp) // pop value off fp stack as a single
jeffhao41005dd2012-05-09 17:58:52 -0700509 movss (%esp), %xmm0 // place into %xmm0
Ian Rogers5793fea2013-02-14 13:33:34 -0800510 addl LITERAL(8), %esp // pop argument
511 .cfi_adjust_cfa_offset -8
jeffhao41005dd2012-05-09 17:58:52 -0700512 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800513END_FUNCTION art_quick_l2f_from_code
jeffhao41005dd2012-05-09 17:58:52 -0700514
Logan Chien8dbb7082013-01-25 20:31:17 +0800515DEFINE_FUNCTION art_quick_d2l_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800516 PUSH eax // alignment padding
517 PUSH ecx // pass arg2 a.hi
518 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700519 call SYMBOL(art_d2l) // (jdouble a)
jeffhao41005dd2012-05-09 17:58:52 -0700520 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800521 .cfi_adjust_cfa_offset -12
jeffhao41005dd2012-05-09 17:58:52 -0700522 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800523END_FUNCTION art_quick_d2l_from_code
jeffhao41005dd2012-05-09 17:58:52 -0700524
Logan Chien8dbb7082013-01-25 20:31:17 +0800525DEFINE_FUNCTION art_quick_f2l_from_code
jeffhao41005dd2012-05-09 17:58:52 -0700526 subl LITERAL(8), %esp // alignment padding
Ian Rogers5793fea2013-02-14 13:33:34 -0800527 .cfi_adjust_cfa_offset 8
Ian Rogersaeeada42013-02-13 11:28:34 -0800528 PUSH eax // pass arg1 a
jeffhao1395b1e2012-06-13 18:05:13 -0700529 call SYMBOL(art_f2l) // (jfloat a)
jeffhao41005dd2012-05-09 17:58:52 -0700530 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800531 .cfi_adjust_cfa_offset -12
jeffhao41005dd2012-05-09 17:58:52 -0700532 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800533END_FUNCTION art_quick_f2l_from_code
jeffhao41005dd2012-05-09 17:58:52 -0700534
Logan Chien8dbb7082013-01-25 20:31:17 +0800535DEFINE_FUNCTION art_quick_idivmod_from_code
jeffhao174651d2012-04-19 15:27:22 -0700536 cmpl LITERAL(0x80000000), %eax
537 je check_arg2 // special case
538args_ok:
Ian Rogers7caad772012-03-30 01:07:54 -0700539 cdq // edx:eax = sign extend eax
540 idiv %ecx // (edx,eax) = (edx:eax % ecx, edx:eax / ecx)
Ian Rogers7caad772012-03-30 01:07:54 -0700541 ret
jeffhao174651d2012-04-19 15:27:22 -0700542check_arg2:
543 cmpl LITERAL(-1), %ecx
544 jne args_ok
545 xorl %edx, %edx
546 ret // eax already holds min int
Ian Rogersaeeada42013-02-13 11:28:34 -0800547END_FUNCTION art_quick_idivmod_from_code
Ian Rogers7caad772012-03-30 01:07:54 -0700548
Logan Chien8dbb7082013-01-25 20:31:17 +0800549DEFINE_FUNCTION art_quick_ldiv_from_code
Ian Rogers141d6222012-04-05 12:23:06 -0700550 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800551 .cfi_adjust_cfa_offset 12
552 PUSH ebx // pass arg4 b.hi
553 PUSH edx // pass arg3 b.lo
554 PUSH ecx // pass arg2 a.hi
555 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700556 call SYMBOL(artLdivFromCode) // (jlong a, jlong b)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700557 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800558 .cfi_adjust_cfa_offset -28
Ian Rogers55bd45f2012-04-04 17:31:20 -0700559 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800560END_FUNCTION art_quick_ldiv_from_code
Ian Rogers55bd45f2012-04-04 17:31:20 -0700561
Logan Chien8dbb7082013-01-25 20:31:17 +0800562DEFINE_FUNCTION art_quick_ldivmod_from_code
Ian Rogers141d6222012-04-05 12:23:06 -0700563 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800564 .cfi_adjust_cfa_offset 12
565 PUSH ebx // pass arg4 b.hi
566 PUSH edx // pass arg3 b.lo
567 PUSH ecx // pass arg2 a.hi
568 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700569 call SYMBOL(artLdivmodFromCode) // (jlong a, jlong b)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700570 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800571 .cfi_adjust_cfa_offset -28
Ian Rogers55bd45f2012-04-04 17:31:20 -0700572 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800573END_FUNCTION art_quick_ldivmod_from_code
Ian Rogers55bd45f2012-04-04 17:31:20 -0700574
Logan Chien8dbb7082013-01-25 20:31:17 +0800575DEFINE_FUNCTION art_quick_lmul_from_code
Ian Rogers5793fea2013-02-14 13:33:34 -0800576 imul %eax, %ebx // ebx = a.lo(eax) * b.hi(ebx)
577 imul %edx, %ecx // ecx = b.lo(edx) * a.hi(ecx)
578 mul %edx // edx:eax = a.lo(eax) * b.lo(edx)
579 add %ebx, %ecx
580 add %ecx, %edx // edx += (a.lo * b.hi) + (b.lo * a.hi)
jeffhao644d5312012-05-03 19:04:49 -0700581 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800582END_FUNCTION art_quick_lmul_from_code
jeffhao644d5312012-05-03 19:04:49 -0700583
Logan Chien8dbb7082013-01-25 20:31:17 +0800584DEFINE_FUNCTION art_quick_lshl_from_code
jeffhao644d5312012-05-03 19:04:49 -0700585 // ecx:eax << edx
Ian Rogers141d6222012-04-05 12:23:06 -0700586 xchg %edx, %ecx
587 shld %cl,%eax,%edx
588 shl %cl,%eax
589 test LITERAL(32), %cl
590 jz 1f
591 mov %eax, %edx
592 xor %eax, %eax
5931:
594 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800595END_FUNCTION art_quick_lshl_from_code
Ian Rogers141d6222012-04-05 12:23:06 -0700596
Logan Chien8dbb7082013-01-25 20:31:17 +0800597DEFINE_FUNCTION art_quick_lshr_from_code
jeffhao644d5312012-05-03 19:04:49 -0700598 // ecx:eax >> edx
Ian Rogers141d6222012-04-05 12:23:06 -0700599 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -0700600 shrd %cl,%edx,%eax
601 sar %cl,%edx
Ian Rogers141d6222012-04-05 12:23:06 -0700602 test LITERAL(32),%cl
603 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -0700604 mov %edx, %eax
605 sar LITERAL(31), %edx
Ian Rogers141d6222012-04-05 12:23:06 -07006061:
607 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800608END_FUNCTION art_quick_lshr_from_code
Ian Rogers141d6222012-04-05 12:23:06 -0700609
Logan Chien8dbb7082013-01-25 20:31:17 +0800610DEFINE_FUNCTION art_quick_lushr_from_code
jeffhao644d5312012-05-03 19:04:49 -0700611 // ecx:eax >>> edx
Ian Rogers141d6222012-04-05 12:23:06 -0700612 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -0700613 shrd %cl,%edx,%eax
614 shr %cl,%edx
615 test LITERAL(32),%cl
Ian Rogers141d6222012-04-05 12:23:06 -0700616 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -0700617 mov %edx, %eax
618 xor %edx, %edx
Ian Rogers141d6222012-04-05 12:23:06 -07006191:
620 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800621END_FUNCTION art_quick_lushr_from_code
Ian Rogers141d6222012-04-05 12:23:06 -0700622
Logan Chien8dbb7082013-01-25 20:31:17 +0800623DEFINE_FUNCTION art_quick_set32_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700624 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
625 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700626 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800627 .cfi_adjust_cfa_offset 8
628 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700629 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800630 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700631 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800632 PUSH ebx // pass referrer
633 PUSH edx // pass new_val
634 PUSH ecx // pass object
635 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700636 call SYMBOL(artSet32InstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700637 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800638 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700639 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
640 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800641END_FUNCTION art_quick_set32_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700642
Logan Chien8dbb7082013-01-25 20:31:17 +0800643DEFINE_FUNCTION art_quick_set64_instance_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800644 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao1ff4cd72012-05-21 11:17:48 -0700645 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800646 .cfi_adjust_cfa_offset 8
647 PUSH esp // pass SP-8
jeffhao1ff4cd72012-05-21 11:17:48 -0700648 addl LITERAL(8), (%esp) // fix SP on stack by adding 8
jeffhao9dbb23e2012-05-18 17:03:57 -0700649 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800650 .cfi_adjust_cfa_offset 4
651 PUSH ebx // pass high half of new_val
652 PUSH edx // pass low half of new_val
653 PUSH ecx // pass object
654 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700655 call SYMBOL(artSet64InstanceFromCode) // (field_idx, Object*, new_val, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700656 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800657 .cfi_adjust_cfa_offset -32
658 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700659 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800660END_FUNCTION art_quick_set64_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700661
Logan Chien8dbb7082013-01-25 20:31:17 +0800662DEFINE_FUNCTION art_quick_set_obj_instance_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800663 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700664 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700665 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800666 .cfi_adjust_cfa_offset 8
667 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700668 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800669 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700670 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800671 PUSH ebx // pass referrer
672 PUSH edx // pass new_val
673 PUSH ecx // pass object
674 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700675 call SYMBOL(artSetObjInstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700676 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800677 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700678 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
679 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800680END_FUNCTION art_quick_set_obj_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700681
Logan Chien8dbb7082013-01-25 20:31:17 +0800682DEFINE_FUNCTION art_quick_get32_instance_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800683 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700684 mov %esp, %ebx // remember SP
685 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700686 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800687 .cfi_adjust_cfa_offset 12
688 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700689 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800690 .cfi_adjust_cfa_offset 4
691 PUSH edx // pass referrer
692 PUSH ecx // pass object
693 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700694 call SYMBOL(artGet32InstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700695 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800696 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700697 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700698 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800699END_FUNCTION art_quick_get32_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700700
Logan Chien8dbb7082013-01-25 20:31:17 +0800701DEFINE_FUNCTION art_quick_get64_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700702 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
703 mov %esp, %ebx // remember SP
704 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700705 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800706 .cfi_adjust_cfa_offset 12
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
710 PUSH edx // pass referrer
711 PUSH ecx // pass object
712 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700713 call SYMBOL(artGet64InstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700714 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800715 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700716 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700717 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800718END_FUNCTION art_quick_get64_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700719
Logan Chien8dbb7082013-01-25 20:31:17 +0800720DEFINE_FUNCTION art_quick_get_obj_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700721 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
722 mov %esp, %ebx // remember SP
723 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700724 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800725 .cfi_adjust_cfa_offset 12
726 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700727 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800728 .cfi_adjust_cfa_offset 4
729 PUSH edx // pass referrer
730 PUSH ecx // pass object
731 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700732 call SYMBOL(artGetObjInstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700733 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800734 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700735 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700736 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800737END_FUNCTION art_quick_get_obj_instance_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700738
Logan Chien8dbb7082013-01-25 20:31:17 +0800739DEFINE_FUNCTION art_quick_set32_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700740 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
741 mov %esp, %ebx // remember SP
742 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700743 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800744 .cfi_adjust_cfa_offset 12
745 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700746 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800747 .cfi_adjust_cfa_offset 4
748 PUSH edx // pass referrer
749 PUSH ecx // pass new_val
750 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700751 call SYMBOL(artSet32StaticFromCode) // (field_idx, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700752 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800753 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700754 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
755 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800756END_FUNCTION art_quick_set32_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700757
Logan Chien8dbb7082013-01-25 20:31:17 +0800758DEFINE_FUNCTION art_quick_set64_static_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800759 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700760 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700761 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800762 .cfi_adjust_cfa_offset 8
763 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700764 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800765 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700766 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800767 PUSH edx // pass high half of new_val
768 PUSH ecx // pass low half of new_val
769 PUSH ebx // pass referrer
770 PUSH eax // pass field_idx
771 call SYMBOL(artSet64StaticFromCode) // (field_idx, referrer, new_val, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700772 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800773 .cfi_adjust_cfa_offset -32
774 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700775 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800776END_FUNCTION art_quick_set64_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700777
Logan Chien8dbb7082013-01-25 20:31:17 +0800778DEFINE_FUNCTION art_quick_set_obj_static_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800779 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700780 mov %esp, %ebx // remember SP
781 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700782 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800783 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700784 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800785 .cfi_adjust_cfa_offset 4
786 PUSH edx // pass referrer
787 PUSH ecx // pass new_val
788 PUSH eax // pass field_idx
789 call SYMBOL(artSetObjStaticFromCode) // (field_idx, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700790 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800791 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700792 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800793END_FUNCTION art_quick_set_obj_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700794
Logan Chien8dbb7082013-01-25 20:31:17 +0800795DEFINE_FUNCTION art_quick_get32_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700796 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
797 mov %esp, %edx // remember SP
798 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800799 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700800 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800801 .cfi_adjust_cfa_offset 4
802 PUSH ecx // pass referrer
803 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700804 call SYMBOL(artGet32StaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700805 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800806 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -0700807 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700808 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800809END_FUNCTION art_quick_get32_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700810
Logan Chien8dbb7082013-01-25 20:31:17 +0800811DEFINE_FUNCTION art_quick_get64_static_from_code
Ian Rogersaeeada42013-02-13 11:28:34 -0800812 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700813 mov %esp, %edx // remember SP
814 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800815 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700816 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800817 .cfi_adjust_cfa_offset 4
818 PUSH ecx // pass referrer
819 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700820 call SYMBOL(artGet64StaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700821 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800822 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -0700823 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700824 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800825END_FUNCTION art_quick_get64_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700826
Logan Chien8dbb7082013-01-25 20:31:17 +0800827DEFINE_FUNCTION art_quick_get_obj_static_from_code
jeffhao9dbb23e2012-05-18 17:03:57 -0700828 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
829 mov %esp, %edx // remember SP
830 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800831 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700832 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800833 .cfi_adjust_cfa_offset 4
834 PUSH ecx // pass referrer
835 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700836 call SYMBOL(artGetObjStaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700837 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800838 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -0700839 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700840 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800841END_FUNCTION art_quick_get_obj_static_from_code
jeffhaod66a8752012-05-22 15:30:16 -0700842
Logan Chien8dbb7082013-01-25 20:31:17 +0800843DEFINE_FUNCTION art_quick_proxy_invoke_handler
Ian Rogers7db619b2013-01-16 18:35:48 -0800844 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save frame and Method*
Ian Rogersaeeada42013-02-13 11:28:34 -0800845 PUSH esp // pass SP
jeffhaod66a8752012-05-22 15:30:16 -0700846 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800847 .cfi_adjust_cfa_offset 4
848 PUSH ecx // pass receiver
849 PUSH eax // pass proxy method
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800850 call SYMBOL(artProxyInvokeHandler) // (proxy method, receiver, Thread*, SP)
851 movd %eax, %xmm0 // place return value also into floating point return value
852 movd %edx, %xmm1
853 punpckldq %xmm1, %xmm0
jeffhaod66a8752012-05-22 15:30:16 -0700854 addl LITERAL(44), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800855 .cfi_adjust_cfa_offset -44
jeffhaod66a8752012-05-22 15:30:16 -0700856 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800857END_FUNCTION art_quick_proxy_invoke_handler
jeffhao9dbb23e2012-05-18 17:03:57 -0700858
Logan Chien8dbb7082013-01-25 20:31:17 +0800859DEFINE_FUNCTION art_quick_interpreter_entry
Ian Rogers7db619b2013-01-16 18:35:48 -0800860 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save frame and Method*
Ian Rogersaeeada42013-02-13 11:28:34 -0800861 mov %esp, %edx // remember SP
862 PUSH eax // alignment padding
863 PUSH edx // pass SP
Ian Rogers7db619b2013-01-16 18:35:48 -0800864 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800865 .cfi_adjust_cfa_offset 4
866 PUSH eax // pass method
Ian Rogers7db619b2013-01-16 18:35:48 -0800867 call SYMBOL(artInterpreterEntry) // (method, Thread*, SP)
868 movd %eax, %xmm0 // place return value also into floating point return value
869 movd %edx, %xmm1
870 punpckldq %xmm1, %xmm0
871 addl LITERAL(44), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800872 .cfi_adjust_cfa_offset -44
Ian Rogers7db619b2013-01-16 18:35:48 -0800873 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800874END_FUNCTION art_quick_interpreter_entry
Ian Rogers7db619b2013-01-16 18:35:48 -0800875
jeffhao7e4fcb82013-01-10 18:11:08 -0800876 /*
877 * Routine that intercepts method calls and returns.
878 */
Logan Chien8dbb7082013-01-25 20:31:17 +0800879DEFINE_FUNCTION art_quick_instrumentation_entry_from_code
jeffhao7e4fcb82013-01-10 18:11:08 -0800880 xchgl %eax, (%esp) // place LR in eax, save eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800881 PUSH ecx // save ecx
882 PUSH edx // save edx
883 PUSH ebx // save ebx
jeffhao7e4fcb82013-01-10 18:11:08 -0800884 lea 16(%esp), %edx // remember bottom of caller's frame
Ian Rogersaeeada42013-02-13 11:28:34 -0800885 PUSH eax // pass LR
886 PUSH edx // pass SP
jeffhao7e4fcb82013-01-10 18:11:08 -0800887 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800888 .cfi_adjust_cfa_offset 4
jeffhao7e4fcb82013-01-10 18:11:08 -0800889 pushl 24(%esp) // pass Method*
Ian Rogersaeeada42013-02-13 11:28:34 -0800890 .cfi_adjust_cfa_offset 4
jeffhao7e4fcb82013-01-10 18:11:08 -0800891 call SYMBOL(artInstrumentationMethodEntryFromCode) // (Method*, Thread*, SP, LR)
892 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800893 POP ebx // restore ebx
894 POP edx // restore edx
jeffhao7e4fcb82013-01-10 18:11:08 -0800895 movl (%esp), %ecx // restore ecx (without popping)
896 movl %eax, (%esp) // place method's code pointer on stack
897 movl 4(%esp), %eax // restore eax (without popping)
Logan Chien8dbb7082013-01-25 20:31:17 +0800898 movl LITERAL(SYMBOL(art_quick_instrumentation_exit_from_code)), 4(%esp)
jeffhao7e4fcb82013-01-10 18:11:08 -0800899 // place instrumentation exit as return pc
900 ret // call method (and pop)
Ian Rogersaeeada42013-02-13 11:28:34 -0800901END_FUNCTION art_quick_instrumentation_entry_from_code
Logan Chien8dbb7082013-01-25 20:31:17 +0800902DEFINE_FUNCTION art_quick_instrumentation_exit_from_code
jeffhao7e4fcb82013-01-10 18:11:08 -0800903 mov %esp, %ecx // remember bottom of caller's frame
Ian Rogersaeeada42013-02-13 11:28:34 -0800904 PUSH edx // save return value
905 PUSH eax // save other half of return value
906 PUSH ecx // pass SP
jeffhao7e4fcb82013-01-10 18:11:08 -0800907 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current
Ian Rogersaeeada42013-02-13 11:28:34 -0800908 .cfi_adjust_cfa_offset 4
jeffhao7e4fcb82013-01-10 18:11:08 -0800909 call SYMBOL(artInstrumentationMethodExitFromCode) // (Thread*, SP)
910 mov %eax, %ecx // move returned link register
911 // TODO: Set link register for deopt
Ian Rogers5793fea2013-02-14 13:33:34 -0800912 addl LITERAL(8), %esp // pop arguments
913 .cfi_adjust_cfa_offset -8
Ian Rogersaeeada42013-02-13 11:28:34 -0800914 POP eax // restore return value
915 POP edx // restore other half of return value
jeffhao7e4fcb82013-01-10 18:11:08 -0800916 jmp *%ecx // return
Ian Rogersaeeada42013-02-13 11:28:34 -0800917END_FUNCTION art_quick_instrumentation_exit_from_code
jeffhao162fd332013-01-08 16:21:01 -0800918
jeffhao7e4fcb82013-01-10 18:11:08 -0800919 /*
920 * The thread's enter interpreter flag is set and so we should transition to the interpreter
921 * rather than allow execution to continue in the frame below. There may be live results in
922 * registers depending on how complete the operation is when we safepoint - for example, a
923 * set operation may have completed while a get operation needs writing back into the vregs.
924 */
Logan Chien8dbb7082013-01-25 20:31:17 +0800925DEFINE_FUNCTION art_quick_deoptimize
jeffhao7e4fcb82013-01-10 18:11:08 -0800926 SETUP_REF_ONLY_CALLEE_SAVE_FRAME
Ian Rogersaeeada42013-02-13 11:28:34 -0800927 PUSH esp // pass SP
jeffhao7e4fcb82013-01-10 18:11:08 -0800928 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800929 .cfi_adjust_cfa_offset 4
930 PUSH edx // push half of return value
931 PUSH eax // push other half of return value
jeffhao7e4fcb82013-01-10 18:11:08 -0800932 call SYMBOL(artDeoptimize) // artDeoptimize(return value, Thread*, SP)
933 // Returns caller method's frame size.
934 addl LITERAL(16), %esp // pop arguments
935 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
936 testl %eax, %eax // Was the caller an upcall?
937 jz 1f // Return if caller was upcall.
938 lea (%esp, %eax), %edx // edx == bottom of caller's frame.
939 mov %edx, %esp // Remove frame.
940 SETUP_REF_ONLY_CALLEE_SAVE_FRAME
941 call SYMBOL(artEnterInterpreterFromDeoptimize) // Enter interpreter, callee-save ends stack fragment.
942 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
9431:
944 ret // Return to caller.
Ian Rogersaeeada42013-02-13 11:28:34 -0800945END_FUNCTION art_quick_deoptimize
jeffhao162fd332013-01-08 16:21:01 -0800946
jeffhao86e46712012-08-08 17:30:59 -0700947 /*
948 * String's indexOf.
949 *
950 * On entry:
951 * eax: string object (known non-null)
952 * ecx: char to match (known <= 0xFFFF)
953 * edx: Starting offset in string data
954 */
Logan Chien8dbb7082013-01-25 20:31:17 +0800955DEFINE_FUNCTION art_quick_indexof
Ian Rogersaeeada42013-02-13 11:28:34 -0800956 PUSH edi // push callee save reg
jeffhao86e46712012-08-08 17:30:59 -0700957 mov STRING_COUNT_OFFSET(%eax), %ebx
958 mov STRING_VALUE_OFFSET(%eax), %edi
959 mov STRING_OFFSET_OFFSET(%eax), %eax
960 testl %edx, %edx // check if start < 0
961 jl clamp_min
962clamp_done:
963 cmpl %ebx, %edx // check if start >= count
964 jge not_found
965 lea STRING_DATA_OFFSET(%edi, %eax, 2), %edi // build a pointer to the start of string data
966 mov %edi, %eax // save a copy in eax to later compute result
967 lea (%edi, %edx, 2), %edi // build pointer to start of data to compare
968 subl %edx, %ebx // compute iteration count
969 /*
970 * At this point we have:
971 * eax: original start of string data
972 * ecx: char to compare
973 * ebx: length to compare
974 * edi: start of data to test
975 */
976 mov %eax, %edx
977 mov %ecx, %eax // put char to match in %eax
978 mov %ebx, %ecx // put length to compare in %ecx
979 repne scasw // find %ax, starting at [%edi], up to length %ecx
980 jne not_found
981 subl %edx, %edi
982 sar LITERAL(1), %edi
983 decl %edi // index = ((curr_ptr - orig_ptr) / 2) - 1
984 mov %edi, %eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800985 POP edi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -0700986 ret
987 .balign 16
988not_found:
989 mov LITERAL(-1), %eax // return -1 (not found)
Ian Rogersaeeada42013-02-13 11:28:34 -0800990 POP edi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -0700991 ret
992clamp_min:
993 xor %edx, %edx // clamp start to 0
994 jmp clamp_done
Ian Rogersaeeada42013-02-13 11:28:34 -0800995END_FUNCTION art_quick_indexof
jeffhao86e46712012-08-08 17:30:59 -0700996
997 /*
998 * String's compareTo.
999 *
1000 * On entry:
1001 * eax: this string object (known non-null)
1002 * ecx: comp string object (known non-null)
1003 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001004DEFINE_FUNCTION art_quick_string_compareto
Ian Rogersaeeada42013-02-13 11:28:34 -08001005 PUSH esi // push callee save reg
1006 PUSH edi // push callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001007 mov STRING_COUNT_OFFSET(%eax), %edx
1008 mov STRING_COUNT_OFFSET(%ecx), %ebx
1009 mov STRING_VALUE_OFFSET(%eax), %esi
1010 mov STRING_VALUE_OFFSET(%ecx), %edi
1011 mov STRING_OFFSET_OFFSET(%eax), %eax
1012 mov STRING_OFFSET_OFFSET(%ecx), %ecx
1013 /* Build pointers to the start of string data */
1014 lea STRING_DATA_OFFSET(%esi, %eax, 2), %esi
1015 lea STRING_DATA_OFFSET(%edi, %ecx, 2), %edi
1016 /* Calculate min length and count diff */
1017 mov %edx, %ecx
1018 mov %edx, %eax
1019 subl %ebx, %eax
1020 cmovg %ebx, %ecx
1021 /*
1022 * At this point we have:
1023 * eax: value to return if first part of strings are equal
1024 * ecx: minimum among the lengths of the two strings
1025 * esi: pointer to this string data
1026 * edi: pointer to comp string data
1027 */
1028 repe cmpsw // find nonmatching chars in [%esi] and [%edi], up to length %ecx
1029 jne not_equal
Ian Rogersaeeada42013-02-13 11:28:34 -08001030 POP edi // pop callee save reg
1031 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001032 ret
1033 .balign 16
1034not_equal:
Ian Rogers1b09b092012-08-20 15:35:52 -07001035 movzwl -2(%esi), %eax // get last compared char from this string
1036 movzwl -2(%edi), %ecx // get last compared char from comp string
jeffhao86e46712012-08-08 17:30:59 -07001037 subl %ecx, %eax // return the difference
Ian Rogersaeeada42013-02-13 11:28:34 -08001038 POP edi // pop callee save reg
1039 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001040 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001041END_FUNCTION art_quick_string_compareto
jeffhao86e46712012-08-08 17:30:59 -07001042
Elliott Hughes787ec202012-03-29 17:14:15 -07001043MACRO1(UNIMPLEMENTED,name)
1044 .globl VAR(name, 0)
1045 ALIGN_FUNCTION_ENTRY
1046VAR(name, 0):
Ian Rogers57b86d42012-03-27 16:05:41 -07001047 int3
Elliott Hughes787ec202012-03-29 17:14:15 -07001048END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -07001049
Elliott Hughes787ec202012-03-29 17:14:15 -07001050 // TODO: implement these!
Logan Chien8dbb7082013-01-25 20:31:17 +08001051UNIMPLEMENTED art_quick_memcmp16