blob: d8098b672f0ebd5e38c4c0c884e6d7f7a2f5afc6 [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)
Elliott Hughes754caaa2012-04-10 10:57:36 -070032 #define CALL_MACRO(name,index) $index
Elliott Hughesea944212012-04-05 13:11:53 -070033 #define LITERAL(value) $value
34 #define MACRO_LITERAL(value) $$value
Elliott Hughes787ec202012-03-29 17:14:15 -070035#else
36 // Regular gas(1) lets you name macro parameters.
37 #define MACRO0(macro_name) .macro macro_name
38 #define MACRO1(macro_name, macro_arg1) .macro macro_name macro_arg1
39 #define MACRO2(macro_name, macro_arg1, macro_arg2) .macro macro_name macro_arg1, macro_arg2
Ian Rogersd36c52e2012-04-09 16:29:25 -070040 #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 -070041 #define END_MACRO .endm
42
43 // Regular gas(1) uses \argument_name for macro arguments.
44 // We need to turn on alternate macro syntax so we can use & instead or the preprocessor
45 // will screw us by inserting a space between the \ and the name. Even in this mode there's
46 // no special meaning to $, so literals are still just $x.
47 .altmacro
Elliott Hughesadc078a2012-04-04 11:39:05 -070048 #define SYMBOL(name) name
Elliott Hughes787ec202012-03-29 17:14:15 -070049 #define VAR(name,index) name&
Elliott Hughes754caaa2012-04-10 10:57:36 -070050 #define CALL_MACRO(name,index) name&
Elliott Hughes787ec202012-03-29 17:14:15 -070051 #define LITERAL(value) $value
Elliott Hughesea944212012-04-05 13:11:53 -070052 #define MACRO_LITERAL(value) $value
Ian Rogers57b86d42012-03-27 16:05:41 -070053#endif
54
Ian Rogers57b86d42012-03-27 16:05:41 -070055 /* Cache alignment for function entry */
Elliott Hughes787ec202012-03-29 17:14:15 -070056MACRO0(ALIGN_FUNCTION_ENTRY)
Ian Rogers57b86d42012-03-27 16:05:41 -070057 .balign 16
Elliott Hughes787ec202012-03-29 17:14:15 -070058END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070059
Elliott Hughes5e284222012-04-04 13:38:03 -070060MACRO1(DEFINE_FUNCTION,c_name)
61 .globl VAR(c_name, 0)
62 ALIGN_FUNCTION_ENTRY
63VAR(c_name, 0):
64END_MACRO
65
Ian Rogers57b86d42012-03-27 16:05:41 -070066 /*
67 * Macro that sets up the callee save frame to conform with
Ian Rogers7caad772012-03-30 01:07:54 -070068 * Runtime::CreateCalleeSaveMethod(kSaveAll)
Ian Rogers57b86d42012-03-27 16:05:41 -070069 */
Elliott Hughes787ec202012-03-29 17:14:15 -070070MACRO0(SETUP_SAVE_ALL_CALLEE_SAVE_FRAME)
Ian Rogers57b86d42012-03-27 16:05:41 -070071 pushl %edi // Save callee saves (ebx is saved/restored by the upcall)
72 pushl %esi
73 pushl %ebp
Elliott Hughesea944212012-04-05 13:11:53 -070074 subl MACRO_LITERAL(16), %esp // Grow stack by 4 words, bottom word will hold Method*
Elliott Hughes787ec202012-03-29 17:14:15 -070075END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070076
Ian Rogers7caad772012-03-30 01:07:54 -070077 /*
78 * Macro that sets up the callee save frame to conform with
79 * Runtime::CreateCalleeSaveMethod(kRefsOnly)
80 */
81MACRO0(SETUP_REF_ONLY_CALLEE_SAVE_FRAME)
82 pushl %edi // Save callee saves (ebx is saved/restored by the upcall)
83 pushl %esi
84 pushl %ebp
Elliott Hughesea944212012-04-05 13:11:53 -070085 subl MACRO_LITERAL(16), %esp // Grow stack by 4 words, bottom word will hold Method*
Ian Rogers7caad772012-03-30 01:07:54 -070086END_MACRO
87
88MACRO0(RESTORE_REF_ONLY_CALLEE_SAVE_FRAME)
Elliott Hughesea944212012-04-05 13:11:53 -070089 addl MACRO_LITERAL(28), %esp // Unwind stack up to return address
Elliott Hughes787ec202012-03-29 17:14:15 -070090END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070091
92 /*
93 * Macro that sets up the callee save frame to conform with
Ian Rogers7caad772012-03-30 01:07:54 -070094 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs)
Ian Rogers57b86d42012-03-27 16:05:41 -070095 */
jeffhao9dbb23e2012-05-18 17:03:57 -070096MACRO0(SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME)
Ian Rogers57b86d42012-03-27 16:05:41 -070097 pushl %edi // Save callee saves
98 pushl %esi
99 pushl %ebp
100 pushl %ebx // Save args
101 pushl %edx
102 pushl %ecx
103 pushl %eax // Align stack, eax will be clobbered by Method*
Elliott Hughes787ec202012-03-29 17:14:15 -0700104END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700105
jeffhao9dbb23e2012-05-18 17:03:57 -0700106MACRO0(RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME)
Elliott Hughesea944212012-04-05 13:11:53 -0700107 addl MACRO_LITERAL(4), %esp // Remove padding
Ian Rogers7caad772012-03-30 01:07:54 -0700108 popl %ecx // Restore args except eax
109 popl %edx
110 popl %ebx
Ian Rogers57b86d42012-03-27 16:05:41 -0700111 popl %ebp // Restore callee saves
112 popl %esi
113 popl %edi
Elliott Hughes787ec202012-03-29 17:14:15 -0700114END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700115
116 /*
117 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
118 * exception is Thread::Current()->exception_.
119 */
Elliott Hughes787ec202012-03-29 17:14:15 -0700120MACRO0(DELIVER_PENDING_EXCEPTION)
Ian Rogers57b86d42012-03-27 16:05:41 -0700121 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save callee saves for throw
122 mov %esp, %ecx
123 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700124 subl MACRO_LITERAL(8), %esp // Alignment padding
Ian Rogers57b86d42012-03-27 16:05:41 -0700125 pushl %ecx // pass SP
126 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
jeffhao9dbb23e2012-05-18 17:03:57 -0700127 call SYMBOL(artDeliverPendingExceptionFromCode) // artDeliverPendingExceptionFromCode(Thread*, SP)
128 int3 // unreached
Elliott Hughes787ec202012-03-29 17:14:15 -0700129END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700130
Elliott Hughes787ec202012-03-29 17:14:15 -0700131MACRO2(NO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
132 .globl VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700133 ALIGN_FUNCTION_ENTRY
Elliott Hughes787ec202012-03-29 17:14:15 -0700134VAR(c_name, 0):
Ian Rogers57b86d42012-03-27 16:05:41 -0700135 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
136 mov %esp, %ecx
137 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700138 subl MACRO_LITERAL(8), %esp // alignment padding
Ian Rogers57b86d42012-03-27 16:05:41 -0700139 pushl %ecx // pass SP
Ian Rogers55bd45f2012-04-04 17:31:20 -0700140 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Elliott Hughes787ec202012-03-29 17:14:15 -0700141 call VAR(cxx_name, 1) // cxx_name(Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700142 int3 // unreached
Elliott Hughes787ec202012-03-29 17:14:15 -0700143END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700144
Elliott Hughes787ec202012-03-29 17:14:15 -0700145MACRO2(ONE_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
146 .globl VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700147 ALIGN_FUNCTION_ENTRY
Elliott Hughes787ec202012-03-29 17:14:15 -0700148VAR(c_name, 0):
Ian Rogers57b86d42012-03-27 16:05:41 -0700149 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
150 mov %esp, %ecx
151 // Outgoing argument set up
Ian Rogers55bd45f2012-04-04 17:31:20 -0700152 pushl %eax // alignment padding
Ian Rogers57b86d42012-03-27 16:05:41 -0700153 pushl %ecx // pass SP
154 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
155 pushl %eax // pass arg1
Elliott Hughes787ec202012-03-29 17:14:15 -0700156 call VAR(cxx_name, 1) // cxx_name(arg1, Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700157 int3 // unreached
Elliott Hughes787ec202012-03-29 17:14:15 -0700158END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700159
Elliott Hughes787ec202012-03-29 17:14:15 -0700160MACRO2(TWO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
161 .globl VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700162 ALIGN_FUNCTION_ENTRY
Elliott Hughes787ec202012-03-29 17:14:15 -0700163VAR(c_name, 0):
Ian Rogers57b86d42012-03-27 16:05:41 -0700164 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
165 mov %esp, %edx
166 // Outgoing argument set up
167 pushl %edx // pass SP
168 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogers57b86d42012-03-27 16:05:41 -0700169 pushl %ecx // pass arg2
Ian Rogers7caad772012-03-30 01:07:54 -0700170 pushl %eax // pass arg1
171 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700172 int3 // unreached
Elliott Hughes787ec202012-03-29 17:14:15 -0700173END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700174
175 /*
176 * Called by managed code to create and deliver a NullPointerException.
177 */
178NO_ARG_RUNTIME_EXCEPTION art_throw_null_pointer_exception_from_code, artThrowNullPointerExceptionFromCode
179
180 /*
181 * Called by managed code to create and deliver an ArithmeticException.
182 */
183NO_ARG_RUNTIME_EXCEPTION art_throw_div_zero_from_code, artThrowDivZeroFromCode
184
185 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700186 * Called by managed code to create and deliver a StackOverflowError.
187 */
188NO_ARG_RUNTIME_EXCEPTION art_throw_stack_overflow_from_code, artThrowStackOverflowFromCode
189
190 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700191 * Called by managed code, saves callee saves and then calls artThrowException
192 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
193 */
194ONE_ARG_RUNTIME_EXCEPTION art_deliver_exception_from_code, artDeliverExceptionFromCode
195
196 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700197 * Called by managed code to create and deliver a NoSuchMethodError.
198 */
199ONE_ARG_RUNTIME_EXCEPTION art_throw_no_such_method_from_code, artThrowNoSuchMethodFromCode
200
201 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700202 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
203 * index, arg2 holds limit.
204 */
205TWO_ARG_RUNTIME_EXCEPTION art_throw_array_bounds_from_code, artThrowArrayBoundsFromCode
206
207 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700208 * Called by managed code to create and deliver verification errors. Arg1 is kind, arg2 is ref.
209 */
210TWO_ARG_RUNTIME_EXCEPTION art_throw_verification_error_from_code, artThrowVerificationErrorFromCode
211
212 /*
213 * All generated callsites for interface invokes and invocation slow paths will load arguments
214 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
215 * the method_idx. This wrapper will save arg1-arg3, load the caller's Method*, align the
216 * stack and call the appropriate C helper.
217 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
218 *
219 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
220 * of the target Method* in r0 and method->code_ in r1.
221 *
222 * If unsuccessful, the helper will return NULL/NULL. There will bea pending exception in the
223 * thread and we branch to another stub to deliver it.
224 *
225 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
226 * pointing back to the original caller.
227 */
Elliott Hughes787ec202012-03-29 17:14:15 -0700228MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name)
229 .globl VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700230 ALIGN_FUNCTION_ENTRY
Elliott Hughes787ec202012-03-29 17:14:15 -0700231VAR(c_name, 0):
Ian Rogers7caad772012-03-30 01:07:54 -0700232 // Set up the callee save frame to conform with Runtime::CreateCalleeSaveMethod(kRefsAndArgs)
233 // return address
234 pushl %edi
235 pushl %esi
236 pushl %ebp
237 pushl %ebx
238 pushl %edx
239 pushl %ecx
240 pushl %eax // <-- callee save Method* to go here
241 movl %esp, %edx // remember SP
242 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700243 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers7caad772012-03-30 01:07:54 -0700244 pushl %edx // pass SP
245 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
246 pushl 32(%edx) // pass caller Method*
247 pushl %ecx // pass arg2
248 pushl %eax // pass arg1
249 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, arg3, Thread*, SP)
250 movl %edx, %edi // save code pointer in EDI
Elliott Hughesea944212012-04-05 13:11:53 -0700251 addl MACRO_LITERAL(36), %esp // Pop arguments skip eax
Ian Rogers7caad772012-03-30 01:07:54 -0700252 popl %ecx // Restore args
253 popl %edx
254 popl %ebx
255 popl %ebp // Restore callee saves.
256 popl %esi
257 // Swap EDI callee save with code pointer.
258 xchgl %edi, (%esp)
259 testl %eax, %eax // Branch forward if exception pending.
260 jz 1f
261 // Tail call to intended method.
262 ret
2631:
jeffhao20b5c6c2012-05-21 14:15:18 -0700264 addl MACRO_LITERAL(4), %esp // Pop code pointer off stack
Ian Rogers7caad772012-03-30 01:07:54 -0700265 DELIVER_PENDING_EXCEPTION
Elliott Hughes787ec202012-03-29 17:14:15 -0700266END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700267
268INVOKE_TRAMPOLINE art_invoke_interface_trampoline, artInvokeInterfaceTrampoline
269INVOKE_TRAMPOLINE art_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
270
271INVOKE_TRAMPOLINE art_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
272INVOKE_TRAMPOLINE art_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
273INVOKE_TRAMPOLINE art_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
274INVOKE_TRAMPOLINE art_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
275
Ian Rogersd36c52e2012-04-09 16:29:25 -0700276MACRO3(NO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
277 .globl VAR(c_name, 0)
278 ALIGN_FUNCTION_ENTRY
279VAR(c_name, 0):
280 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
281 mov %esp, %edx // remember SP
282 // Outgoing argument set up
283 subl MACRO_LITERAL(8), %esp // push padding
284 pushl %edx // pass SP
285 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
286 call VAR(cxx_name, 1) // cxx_name(Thread*, SP)
287 addl MACRO_LITERAL(16), %esp // pop arguments
288 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700289 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersd36c52e2012-04-09 16:29:25 -0700290END_MACRO
291
292MACRO3(ONE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
293 .globl VAR(c_name, 0)
294 ALIGN_FUNCTION_ENTRY
295VAR(c_name, 0):
296 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
297 mov %esp, %edx // remember SP
298 // Outgoing argument set up
299 pushl %eax // push padding
300 pushl %edx // pass SP
301 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
302 pushl %eax // pass arg1
303 call VAR(cxx_name, 1) // cxx_name(arg1, Thread*, SP)
304 addl MACRO_LITERAL(16), %esp // pop arguments
305 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700306 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersd36c52e2012-04-09 16:29:25 -0700307END_MACRO
308
309MACRO3(TWO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogers7caad772012-03-30 01:07:54 -0700310 .globl VAR(c_name, 0)
311 ALIGN_FUNCTION_ENTRY
312VAR(c_name, 0):
313 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
314 mov %esp, %edx // remember SP
315 // Outgoing argument set up
316 pushl %edx // pass SP
317 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
318 pushl %ecx // pass arg2
319 pushl %eax // pass arg1
Ian Rogersd36c52e2012-04-09 16:29:25 -0700320 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, Thread*, SP)
Elliott Hughesea944212012-04-05 13:11:53 -0700321 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogers7caad772012-03-30 01:07:54 -0700322 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700323 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogers7caad772012-03-30 01:07:54 -0700324END_MACRO
325
Ian Rogersd36c52e2012-04-09 16:29:25 -0700326MACRO3(THREE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogers7caad772012-03-30 01:07:54 -0700327 .globl VAR(c_name, 0)
328 ALIGN_FUNCTION_ENTRY
329VAR(c_name, 0):
330 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
331 mov %esp, %ebx // remember SP
332 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700333 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers7caad772012-03-30 01:07:54 -0700334 pushl %ebx // pass SP
335 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
336 pushl %edx // pass arg3
337 pushl %ecx // pass arg2
338 pushl %eax // pass arg1
Ian Rogersd36c52e2012-04-09 16:29:25 -0700339 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, arg3, Thread*, SP)
Elliott Hughesea944212012-04-05 13:11:53 -0700340 addl MACRO_LITERAL(32), %esp // pop arguments
Ian Rogers7caad772012-03-30 01:07:54 -0700341 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700342 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersd36c52e2012-04-09 16:29:25 -0700343END_MACRO
344
345MACRO0(RETURN_IF_EAX_NOT_ZERO)
Ian Rogers7caad772012-03-30 01:07:54 -0700346 testl %eax, %eax // eax == 0 ?
Ian Rogersd36c52e2012-04-09 16:29:25 -0700347 jz 1f // if eax == 0 goto 1
348 ret // return
3491: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700350 DELIVER_PENDING_EXCEPTION
351END_MACRO
352
Ian Rogersd36c52e2012-04-09 16:29:25 -0700353MACRO0(RETURN_IF_EAX_ZERO)
354 testl %eax, %eax // eax == 0 ?
355 jnz 1f // if eax != 0 goto 1
356 ret // return
3571: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700358 DELIVER_PENDING_EXCEPTION
Ian Rogersd36c52e2012-04-09 16:29:25 -0700359END_MACRO
Ian Rogers7caad772012-03-30 01:07:54 -0700360
jeffhaod66a8752012-05-22 15:30:16 -0700361MACRO0(RETURN_OR_DELIVER_PENDING_EXCEPTION)
362 mov %fs:THREAD_EXCEPTION_OFFSET, %ebx // get exception field
363 testl %ebx, %ebx // ebx == 0 ?
364 jnz 1f // if ebx != 0 goto 1
365 ret // return
3661: // deliver exception on current thread
367 DELIVER_PENDING_EXCEPTION
368END_MACRO
369
Ian Rogersd36c52e2012-04-09 16:29:25 -0700370TWO_ARG_DOWNCALL art_alloc_object_from_code, artAllocObjectFromCode, RETURN_IF_EAX_NOT_ZERO
371TWO_ARG_DOWNCALL art_alloc_object_from_code_with_access_check, artAllocObjectFromCodeWithAccessCheck, RETURN_IF_EAX_NOT_ZERO
372THREE_ARG_DOWNCALL art_alloc_array_from_code, artAllocArrayFromCode, RETURN_IF_EAX_NOT_ZERO
373THREE_ARG_DOWNCALL art_alloc_array_from_code_with_access_check, artAllocArrayFromCodeWithAccessCheck, RETURN_IF_EAX_NOT_ZERO
374THREE_ARG_DOWNCALL art_check_and_alloc_array_from_code, artCheckAndAllocArrayFromCode, RETURN_IF_EAX_NOT_ZERO
375THREE_ARG_DOWNCALL art_check_and_alloc_array_from_code_with_access_check, artCheckAndAllocArrayFromCodeWithAccessCheck, RETURN_IF_EAX_NOT_ZERO
376
377TWO_ARG_DOWNCALL art_resolve_string_from_code, artResolveStringFromCode, RETURN_IF_EAX_NOT_ZERO
378TWO_ARG_DOWNCALL art_initialize_static_storage_from_code, artInitializeStaticStorageFromCode, RETURN_IF_EAX_NOT_ZERO
Elliott Hughese87c7bc2012-04-16 20:42:34 -0700379TWO_ARG_DOWNCALL art_initialize_type_from_code, artInitializeTypeFromCode, RETURN_IF_EAX_NOT_ZERO
380TWO_ARG_DOWNCALL art_initialize_type_and_verify_access_from_code, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_EAX_NOT_ZERO
Ian Rogersd36c52e2012-04-09 16:29:25 -0700381
382ONE_ARG_DOWNCALL art_lock_object_from_code, artLockObjectFromCode, ret
383ONE_ARG_DOWNCALL art_unlock_object_from_code, artUnlockObjectFromCode, RETURN_IF_EAX_ZERO
384
385TWO_ARG_DOWNCALL art_handle_fill_data_from_code, artHandleFillArrayDataFromCode, RETURN_IF_EAX_ZERO
Ian Rogers7caad772012-03-30 01:07:54 -0700386
Elliott Hughes5e284222012-04-04 13:38:03 -0700387DEFINE_FUNCTION art_is_assignable_from_code
Ian Rogers7caad772012-03-30 01:07:54 -0700388 pushl %eax // alignment padding
389 pushl %ecx // pass arg2
390 pushl %eax // pass arg1
Elliott Hughesadc078a2012-04-04 11:39:05 -0700391 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b, Thread*, SP)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700392 addl LITERAL(12), %esp // pop arguments
Ian Rogers7caad772012-03-30 01:07:54 -0700393 ret
394
Elliott Hughes5e284222012-04-04 13:38:03 -0700395DEFINE_FUNCTION art_memcpy
Ian Rogers7caad772012-03-30 01:07:54 -0700396 pushl %edx // pass arg3
397 pushl %ecx // pass arg2
398 pushl %eax // pass arg1
Elliott Hughesadc078a2012-04-04 11:39:05 -0700399 call SYMBOL(memcpy) // (void*, const void*, size_t)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700400 addl LITERAL(12), %esp // pop arguments
Ian Rogers7caad772012-03-30 01:07:54 -0700401 ret
402
Ian Rogersd36c52e2012-04-09 16:29:25 -0700403TWO_ARG_DOWNCALL art_check_cast_from_code, artCheckCastFromCode, RETURN_IF_EAX_ZERO
404TWO_ARG_DOWNCALL art_can_put_array_element_from_code, artCanPutArrayElementFromCode, RETURN_IF_EAX_ZERO
405
406NO_ARG_DOWNCALL art_test_suspend, artTestSuspendFromCode, ret
Ian Rogers7caad772012-03-30 01:07:54 -0700407
jeffhao292188d2012-05-17 15:45:04 -0700408DEFINE_FUNCTION art_fmod_from_code
jeffhao1395b1e2012-06-13 18:05:13 -0700409 subl LITERAL(12), %esp // alignment padding
410 pushl %ebx // pass arg4 b.hi
411 pushl %edx // pass arg3 b.lo
412 pushl %ecx // pass arg2 a.hi
413 pushl %eax // pass arg1 a.lo
414 call SYMBOL(fmod) // (jdouble a, jdouble b)
415 fstpl (%esp) // pop return value off fp stack
416 movsd (%esp), %xmm0 // place into %xmm0
417 addl LITERAL(28), %esp // pop arguments
jeffhao292188d2012-05-17 15:45:04 -0700418 ret
419
420DEFINE_FUNCTION art_fmodf_from_code
jeffhao1395b1e2012-06-13 18:05:13 -0700421 pushl %eax // alignment padding
422 pushl %ecx // pass arg2 b
423 pushl %eax // pass arg1 a
424 call SYMBOL(fmodf) // (jfloat a, jfloat b)
425 fstp (%esp) // pop return value off fp stack
426 movss (%esp), %xmm0 // place into %xmm0
427 addl LITERAL(12), %esp // pop arguments
jeffhao292188d2012-05-17 15:45:04 -0700428 ret
429
jeffhao41005dd2012-05-09 17:58:52 -0700430DEFINE_FUNCTION art_l2d_from_code
431 pushl %eax // alignment padding
jeffhao1395b1e2012-06-13 18:05:13 -0700432 pushl %ecx // pass arg2 a.hi
433 pushl %eax // pass arg1 a.lo
434 call SYMBOL(art_l2d) // (jlong a)
jeffhao292188d2012-05-17 15:45:04 -0700435 fstpl (%esp) // pop return value off fp stack
jeffhao41005dd2012-05-09 17:58:52 -0700436 movsd (%esp), %xmm0 // place into %xmm0
437 addl LITERAL(12), %esp // pop arguments
438 ret
439
440DEFINE_FUNCTION art_l2f_from_code
441 pushl %eax // alignment padding
jeffhao1395b1e2012-06-13 18:05:13 -0700442 pushl %ecx // pass arg2 a.hi
443 pushl %eax // pass arg1 a.lo
444 call SYMBOL(art_l2f) // (jlong a)
jeffhao292188d2012-05-17 15:45:04 -0700445 fstp (%esp) // pop return value off fp stack
jeffhao41005dd2012-05-09 17:58:52 -0700446 movss (%esp), %xmm0 // place into %xmm0
447 addl LITERAL(12), %esp // pop arguments
448 ret
449
450DEFINE_FUNCTION art_d2l_from_code
451 pushl %eax // alignment padding
jeffhao1395b1e2012-06-13 18:05:13 -0700452 pushl %ecx // pass arg2 a.hi
453 pushl %eax // pass arg1 a.lo
454 call SYMBOL(art_d2l) // (jdouble a)
jeffhao41005dd2012-05-09 17:58:52 -0700455 addl LITERAL(12), %esp // pop arguments
456 ret
457
458DEFINE_FUNCTION art_f2l_from_code
459 subl LITERAL(8), %esp // alignment padding
jeffhao1395b1e2012-06-13 18:05:13 -0700460 pushl %eax // pass arg1 a
461 call SYMBOL(art_f2l) // (jfloat a)
jeffhao41005dd2012-05-09 17:58:52 -0700462 addl LITERAL(12), %esp // pop arguments
463 ret
464
Elliott Hughes5e284222012-04-04 13:38:03 -0700465DEFINE_FUNCTION art_idivmod_from_code
jeffhao174651d2012-04-19 15:27:22 -0700466 cmpl LITERAL(0x80000000), %eax
467 je check_arg2 // special case
468args_ok:
Ian Rogers7caad772012-03-30 01:07:54 -0700469 cdq // edx:eax = sign extend eax
470 idiv %ecx // (edx,eax) = (edx:eax % ecx, edx:eax / ecx)
Ian Rogers7caad772012-03-30 01:07:54 -0700471 ret
jeffhao174651d2012-04-19 15:27:22 -0700472check_arg2:
473 cmpl LITERAL(-1), %ecx
474 jne args_ok
475 xorl %edx, %edx
476 ret // eax already holds min int
Ian Rogers7caad772012-03-30 01:07:54 -0700477
Ian Rogers55bd45f2012-04-04 17:31:20 -0700478DEFINE_FUNCTION art_ldiv_from_code
Ian Rogers141d6222012-04-05 12:23:06 -0700479 subl LITERAL(12), %esp // alignment padding
jeffhao1395b1e2012-06-13 18:05:13 -0700480 pushl %ebx // pass arg4 b.hi
481 pushl %edx // pass arg3 b.lo
482 pushl %ecx // pass arg2 a.hi
483 pushl %eax // pass arg1 a.lo
484 call SYMBOL(artLdivFromCode) // (jlong a, jlong b)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700485 addl LITERAL(28), %esp // pop arguments
486 ret
487
488DEFINE_FUNCTION art_ldivmod_from_code
Ian Rogers141d6222012-04-05 12:23:06 -0700489 subl LITERAL(12), %esp // alignment padding
jeffhao1395b1e2012-06-13 18:05:13 -0700490 pushl %ebx // pass arg4 b.hi
491 pushl %edx // pass arg3 b.lo
492 pushl %ecx // pass arg2 a.hi
493 pushl %eax // pass arg1 a.lo
494 call SYMBOL(artLdivmodFromCode) // (jlong a, jlong b)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700495 addl LITERAL(28), %esp // pop arguments
496 ret
497
jeffhao644d5312012-05-03 19:04:49 -0700498DEFINE_FUNCTION art_lmul_from_code
499 subl LITERAL(12), %esp // alignment padding
jeffhao1395b1e2012-06-13 18:05:13 -0700500 pushl %ebx // pass arg4 b.hi
501 pushl %edx // pass arg3 b.lo
502 pushl %ecx // pass arg2 a.hi
503 pushl %eax // pass arg1 a.lo
504 call SYMBOL(artLmulFromCode) // (jlong a, jlong b)
jeffhao644d5312012-05-03 19:04:49 -0700505 addl LITERAL(28), %esp // pop arguments
506 ret
507
Ian Rogers141d6222012-04-05 12:23:06 -0700508DEFINE_FUNCTION art_lshl_from_code
jeffhao644d5312012-05-03 19:04:49 -0700509 // ecx:eax << edx
Ian Rogers141d6222012-04-05 12:23:06 -0700510 xchg %edx, %ecx
511 shld %cl,%eax,%edx
512 shl %cl,%eax
513 test LITERAL(32), %cl
514 jz 1f
515 mov %eax, %edx
516 xor %eax, %eax
5171:
518 ret
519
520DEFINE_FUNCTION art_lshr_from_code
jeffhao644d5312012-05-03 19:04:49 -0700521 // ecx:eax >> edx
Ian Rogers141d6222012-04-05 12:23:06 -0700522 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -0700523 shrd %cl,%edx,%eax
524 sar %cl,%edx
Ian Rogers141d6222012-04-05 12:23:06 -0700525 test LITERAL(32),%cl
526 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -0700527 mov %edx, %eax
528 sar LITERAL(31), %edx
Ian Rogers141d6222012-04-05 12:23:06 -07005291:
530 ret
531
532DEFINE_FUNCTION art_lushr_from_code
jeffhao644d5312012-05-03 19:04:49 -0700533 // ecx:eax >>> edx
Ian Rogers141d6222012-04-05 12:23:06 -0700534 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -0700535 shrd %cl,%edx,%eax
536 shr %cl,%edx
537 test LITERAL(32),%cl
Ian Rogers141d6222012-04-05 12:23:06 -0700538 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -0700539 mov %edx, %eax
540 xor %edx, %edx
Ian Rogers141d6222012-04-05 12:23:06 -07005411:
542 ret
543
jeffhao9dbb23e2012-05-18 17:03:57 -0700544DEFINE_FUNCTION art_set32_instance_from_code
545 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
546 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700547 subl LITERAL(8), %esp // alignment padding
jeffhao9dbb23e2012-05-18 17:03:57 -0700548 pushl %ebx // pass SP
549 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
550 mov 32(%ebx), %ebx // get referrer
551 pushl %ebx // pass referrer
552 pushl %edx // pass new_val
553 pushl %ecx // pass object
554 pushl %eax // pass field_idx
555 call SYMBOL(artSet32InstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700556 addl LITERAL(32), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700557 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
558 RETURN_IF_EAX_ZERO // return or deliver exception
559
560DEFINE_FUNCTION art_set64_instance_from_code
561 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao1ff4cd72012-05-21 11:17:48 -0700562 subl LITERAL(8), %esp // alignment padding
jeffhao9dbb23e2012-05-18 17:03:57 -0700563 pushl %esp // pass SP-8
jeffhao1ff4cd72012-05-21 11:17:48 -0700564 addl LITERAL(8), (%esp) // fix SP on stack by adding 8
jeffhao9dbb23e2012-05-18 17:03:57 -0700565 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
566 pushl %ebx // pass high half of new_val
567 pushl %edx // pass low half of new_val
568 pushl %ecx // pass object
569 pushl %eax // pass field_idx
570 call SYMBOL(artSet64InstanceFromCode) // (field_idx, Object*, new_val, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700571 addl LITERAL(32), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700572 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
573 RETURN_IF_EAX_ZERO // return or deliver exception
574
575DEFINE_FUNCTION art_set_obj_instance_from_code
576 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
577 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700578 subl LITERAL(8), %esp // alignment padding
jeffhao9dbb23e2012-05-18 17:03:57 -0700579 pushl %ebx // pass SP
580 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
581 mov 32(%ebx), %ebx // get referrer
582 pushl %ebx // pass referrer
583 pushl %edx // pass new_val
584 pushl %ecx // pass object
585 pushl %eax // pass field_idx
586 call SYMBOL(artSetObjInstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700587 addl LITERAL(32), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700588 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
589 RETURN_IF_EAX_ZERO // return or deliver exception
590
591DEFINE_FUNCTION art_get32_instance_from_code
592 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
593 mov %esp, %ebx // remember SP
594 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700595 subl LITERAL(12), %esp // alignment padding
jeffhao9dbb23e2012-05-18 17:03:57 -0700596 pushl %ebx // pass SP
597 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
598 pushl %edx // pass referrer
599 pushl %ecx // pass object
600 pushl %eax // pass field_idx
601 call SYMBOL(artGet32InstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700602 addl LITERAL(32), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700603 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700604 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
jeffhao9dbb23e2012-05-18 17:03:57 -0700605
606DEFINE_FUNCTION art_get64_instance_from_code
607 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
608 mov %esp, %ebx // remember SP
609 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700610 subl LITERAL(12), %esp // alignment padding
jeffhao9dbb23e2012-05-18 17:03:57 -0700611 pushl %ebx // pass SP
612 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
613 pushl %edx // pass referrer
614 pushl %ecx // pass object
615 pushl %eax // pass field_idx
616 call SYMBOL(artGet64InstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700617 addl LITERAL(32), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700618 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700619 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
jeffhao9dbb23e2012-05-18 17:03:57 -0700620
621DEFINE_FUNCTION art_get_obj_instance_from_code
622 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
623 mov %esp, %ebx // remember SP
624 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700625 subl LITERAL(12), %esp // alignment padding
jeffhao9dbb23e2012-05-18 17:03:57 -0700626 pushl %ebx // pass SP
627 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
628 pushl %edx // pass referrer
629 pushl %ecx // pass object
630 pushl %eax // pass field_idx
631 call SYMBOL(artGetObjInstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700632 addl LITERAL(32), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700633 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700634 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
jeffhao9dbb23e2012-05-18 17:03:57 -0700635
636DEFINE_FUNCTION art_set32_static_from_code
637 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
638 mov %esp, %ebx // remember SP
639 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700640 subl LITERAL(12), %esp // alignment padding
jeffhao9dbb23e2012-05-18 17:03:57 -0700641 pushl %ebx // pass SP
642 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
643 pushl %edx // pass referrer
644 pushl %ecx // pass new_val
645 pushl %eax // pass field_idx
646 call SYMBOL(artSet32StaticFromCode) // (field_idx, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700647 addl LITERAL(32), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700648 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
649 RETURN_IF_EAX_ZERO // return or deliver exception
650
651DEFINE_FUNCTION art_set64_static_from_code
652 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
653 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700654 subl LITERAL(8), %esp // alignment padding
jeffhao9dbb23e2012-05-18 17:03:57 -0700655 pushl %ebx // pass SP
656 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
657 mov 32(%ebx), %ebx // get referrer
658 pushl %edx // pass high half of new_val
659 pushl %ecx // pass low half of new_val
660 pushl %ebx // pass referrer
661 pushl %eax // pass field_idx
662 call SYMBOL(artSet64StaticFromCode) // (field_idx, referrer, new_val, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700663 addl LITERAL(32), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700664 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
665 RETURN_IF_EAX_ZERO // return or deliver exception
666
667DEFINE_FUNCTION art_set_obj_static_from_code
668 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
669 mov %esp, %ebx // remember SP
670 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700671 subl LITERAL(12), %esp // alignment padding
jeffhao9dbb23e2012-05-18 17:03:57 -0700672 pushl %ebx // pass SP
673 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
674 pushl %edx // pass referrer
675 pushl %ecx // pass new_val
676 pushl %eax // pass field_idx
677 call SYMBOL(artSetObjStaticFromCode) // (field_idx, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700678 addl LITERAL(32), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700679 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
680 RETURN_IF_EAX_ZERO // return or deliver exception
681
682DEFINE_FUNCTION art_get32_static_from_code
683 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
684 mov %esp, %edx // remember SP
685 mov 32(%esp), %ecx // get referrer
686 pushl %edx // pass SP
687 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
688 pushl %ecx // pass referrer
689 pushl %eax // pass field_idx
690 call SYMBOL(artGet32StaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700691 addl LITERAL(16), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700692 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700693 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
jeffhao9dbb23e2012-05-18 17:03:57 -0700694
695DEFINE_FUNCTION art_get64_static_from_code
696 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
697 mov %esp, %edx // remember SP
698 mov 32(%esp), %ecx // get referrer
699 pushl %edx // pass SP
700 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
701 pushl %ecx // pass referrer
702 pushl %eax // pass field_idx
703 call SYMBOL(artGet64StaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700704 addl LITERAL(16), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700705 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700706 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
jeffhao9dbb23e2012-05-18 17:03:57 -0700707
708DEFINE_FUNCTION art_get_obj_static_from_code
709 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
710 mov %esp, %edx // remember SP
711 mov 32(%esp), %ecx // get referrer
712 pushl %edx // pass SP
713 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
714 pushl %ecx // pass referrer
715 pushl %eax // pass field_idx
716 call SYMBOL(artGetObjStaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700717 addl LITERAL(16), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700718 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700719 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
720
721DEFINE_FUNCTION art_proxy_invoke_handler
722 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save frame
723 lea 8(%esp), %ebx // pointer to r2/r3/LR/caller's Method**/out-args as second arg
724 pushl %ebx // pass args
725 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
726 pushl %ecx // pass receiver
727 pushl %eax // pass proxy method
728 call SYMBOL(artProxyInvokeHandler) // (proxy method, receiver, Thread*, args...)
729 mov 24(%esp), %eax // get ret0 which was written into r2 on the stack
730 mov 28(%esp), %edx // get ret1 which was written into r3 on the stack
jeffhao5d05c752012-05-23 10:57:48 -0700731 movsd 24(%esp), %xmm0 // get ret0/ret1 from stack for floating point
jeffhaod66a8752012-05-22 15:30:16 -0700732 addl LITERAL(44), %esp // pop arguments
733 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
jeffhao9dbb23e2012-05-18 17:03:57 -0700734
jeffhao86e46712012-08-08 17:30:59 -0700735 /*
736 * String's indexOf.
737 *
738 * On entry:
739 * eax: string object (known non-null)
740 * ecx: char to match (known <= 0xFFFF)
741 * edx: Starting offset in string data
742 */
743DEFINE_FUNCTION art_indexof
744 pushl %edi // push callee save reg
745 mov STRING_COUNT_OFFSET(%eax), %ebx
746 mov STRING_VALUE_OFFSET(%eax), %edi
747 mov STRING_OFFSET_OFFSET(%eax), %eax
748 testl %edx, %edx // check if start < 0
749 jl clamp_min
750clamp_done:
751 cmpl %ebx, %edx // check if start >= count
752 jge not_found
753 lea STRING_DATA_OFFSET(%edi, %eax, 2), %edi // build a pointer to the start of string data
754 mov %edi, %eax // save a copy in eax to later compute result
755 lea (%edi, %edx, 2), %edi // build pointer to start of data to compare
756 subl %edx, %ebx // compute iteration count
757 /*
758 * At this point we have:
759 * eax: original start of string data
760 * ecx: char to compare
761 * ebx: length to compare
762 * edi: start of data to test
763 */
764 mov %eax, %edx
765 mov %ecx, %eax // put char to match in %eax
766 mov %ebx, %ecx // put length to compare in %ecx
767 repne scasw // find %ax, starting at [%edi], up to length %ecx
768 jne not_found
769 subl %edx, %edi
770 sar LITERAL(1), %edi
771 decl %edi // index = ((curr_ptr - orig_ptr) / 2) - 1
772 mov %edi, %eax
773 popl %edi // pop callee save reg
774 ret
775 .balign 16
776not_found:
777 mov LITERAL(-1), %eax // return -1 (not found)
778 popl %edi // pop callee save reg
779 ret
780clamp_min:
781 xor %edx, %edx // clamp start to 0
782 jmp clamp_done
783
784 /*
785 * String's compareTo.
786 *
787 * On entry:
788 * eax: this string object (known non-null)
789 * ecx: comp string object (known non-null)
790 */
791DEFINE_FUNCTION art_string_compareto
792 pushl %esi // push callee save reg
793 pushl %edi // push callee save reg
794 mov STRING_COUNT_OFFSET(%eax), %edx
795 mov STRING_COUNT_OFFSET(%ecx), %ebx
796 mov STRING_VALUE_OFFSET(%eax), %esi
797 mov STRING_VALUE_OFFSET(%ecx), %edi
798 mov STRING_OFFSET_OFFSET(%eax), %eax
799 mov STRING_OFFSET_OFFSET(%ecx), %ecx
800 /* Build pointers to the start of string data */
801 lea STRING_DATA_OFFSET(%esi, %eax, 2), %esi
802 lea STRING_DATA_OFFSET(%edi, %ecx, 2), %edi
803 /* Calculate min length and count diff */
804 mov %edx, %ecx
805 mov %edx, %eax
806 subl %ebx, %eax
807 cmovg %ebx, %ecx
808 /*
809 * At this point we have:
810 * eax: value to return if first part of strings are equal
811 * ecx: minimum among the lengths of the two strings
812 * esi: pointer to this string data
813 * edi: pointer to comp string data
814 */
815 repe cmpsw // find nonmatching chars in [%esi] and [%edi], up to length %ecx
816 jne not_equal
817 popl %edi // pop callee save reg
818 popl %esi // pop callee save reg
819 ret
820 .balign 16
821not_equal:
822 movzxw -2(%esi), %eax // get last compared char from this string
823 movzxw -2(%edi), %ecx // get last compared char from comp string
824 subl %ecx, %eax // return the difference
825 popl %edi // pop callee save reg
826 popl %esi // pop callee save reg
827 ret
828
Elliott Hughes787ec202012-03-29 17:14:15 -0700829MACRO1(UNIMPLEMENTED,name)
830 .globl VAR(name, 0)
831 ALIGN_FUNCTION_ENTRY
832VAR(name, 0):
Ian Rogers57b86d42012-03-27 16:05:41 -0700833 int3
Elliott Hughes787ec202012-03-29 17:14:15 -0700834END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700835
Elliott Hughes787ec202012-03-29 17:14:15 -0700836 // TODO: implement these!
Elliott Hughes787ec202012-03-29 17:14:15 -0700837UNIMPLEMENTED art_update_debugger
Ian Rogers7caad772012-03-30 01:07:54 -0700838UNIMPLEMENTED art_memcmp16